@retion-miniapp/react-native 0.15.1 → 0.17.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 +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +8 -8
- package/dist/index.mjs +8 -8
- package/docs/MINIAPP_README.md +2 -1
- package/docs/NATIVE_APIS.md +2 -1
- package/docs/SPEECH.md +10 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,17 @@ type MiniAppChannel = 'production' | 'testing';
|
|
|
4
4
|
/** Quyền lấy token nhạy cảm — admin bật trên Console, Platform trả trong manifest. */
|
|
5
5
|
type MiniAppPermission = 'partner_token' | 'chatbox_token';
|
|
6
6
|
/** Manifest Platform trả (API list ứng dụng hoặc manifest lẻ). */
|
|
7
|
+
/** Changelog 1 version (Console / CHANGELOG.md): Mới · Sửa lỗi · Cải thiện. */
|
|
8
|
+
interface MiniAppChangelog {
|
|
9
|
+
new: string[];
|
|
10
|
+
fix: string[];
|
|
11
|
+
improve: string[];
|
|
12
|
+
}
|
|
13
|
+
interface MiniAppChangelogVersion {
|
|
14
|
+
version: string;
|
|
15
|
+
changelog: MiniAppChangelog;
|
|
16
|
+
created_at: string;
|
|
17
|
+
}
|
|
7
18
|
interface MiniAppManifest {
|
|
8
19
|
app_id: string;
|
|
9
20
|
name?: string;
|
|
@@ -15,6 +26,8 @@ interface MiniAppManifest {
|
|
|
15
26
|
/** true: đổi conversation → đẩy context; false: reload với context mới. */
|
|
16
27
|
context_update?: boolean;
|
|
17
28
|
permissions?: MiniAppPermission[];
|
|
29
|
+
/** Changelog version này (null: bản deploy trước khi có changelog). */
|
|
30
|
+
changelog?: MiniAppChangelog | null;
|
|
18
31
|
}
|
|
19
32
|
/** Bundle đã giải nén trong máy. */
|
|
20
33
|
interface MiniAppLocalBundle {
|
|
@@ -276,12 +289,19 @@ interface MiniAppBridgeOptions {
|
|
|
276
289
|
* (không phải cập nhật mini app web). Không truyền → dùng nhận dạng có sẵn.
|
|
277
290
|
*/
|
|
278
291
|
speech?: MiniAppSpeechProvider;
|
|
292
|
+
/**
|
|
293
|
+
* Trợ lý voice AI của app (ưu tiên hơn `speech`). Nhận mọi speech.start trừ khi web gọi `startSpeech({ mode: 's2t' })`
|
|
294
|
+
* — lúc đó luôn dùng nhận dạng có sẵn (expo-speech-recognition), bỏ qua cả `voice` lẫn `speech`.
|
|
295
|
+
*/
|
|
296
|
+
voice?: MiniAppSpeechProvider;
|
|
279
297
|
}
|
|
280
298
|
/** Ngữ cảnh 1 lần web gọi speech.start (provider của app tự quản phiên). */
|
|
281
299
|
interface MiniAppSpeechStartContext {
|
|
282
300
|
/** WebView đang gọi — dùng làm khoá phiên cho stop / release */
|
|
283
301
|
owner: string;
|
|
284
302
|
app_id: string;
|
|
303
|
+
/** Web chọn: 'voice' = trợ lý voice AI (mặc định). Provider chỉ nhận 'voice'; 's2t' luôn đi nhận dạng có sẵn. */
|
|
304
|
+
mode: 's2t' | 'voice';
|
|
285
305
|
/** Tham số web truyền (đã kiểm tra hợp lệ) */
|
|
286
306
|
options: {
|
|
287
307
|
lang?: string;
|
|
@@ -633,6 +653,40 @@ declare const installBundledMiniApp: ({ manifest, zip_path }: {
|
|
|
633
653
|
zip_path: string;
|
|
634
654
|
}) => Promise<MiniAppLocalBundle>;
|
|
635
655
|
|
|
656
|
+
interface MiniAppPendingChangelog {
|
|
657
|
+
app_id: string;
|
|
658
|
+
/** Version đã xem changelog lần trước (loại trừ). */
|
|
659
|
+
from: string;
|
|
660
|
+
/** Version đang có trong máy (bao gồm). */
|
|
661
|
+
to: string;
|
|
662
|
+
}
|
|
663
|
+
declare const getMiniAppChangelogSeen: (app_id: string) => string | null;
|
|
664
|
+
/** Đã xem changelog tới version này (mặc định: bản đang có trong máy). */
|
|
665
|
+
declare const markMiniAppChangelogSeen: (app_id: string, version?: string | undefined) => void;
|
|
666
|
+
/** Gọi khi người dùng bấm mở mini app: có bản mới chưa xem changelog → { from, to }, không thì null. */
|
|
667
|
+
declare const getPendingChangelog: (app_id: string) => MiniAppPendingChangelog | null;
|
|
668
|
+
/**
|
|
669
|
+
* Changelog từ Platform, mới nhất trước. from: loại trừ, to: bao gồm; bỏ trống cả 2 → toàn bộ lịch sử.
|
|
670
|
+
* Reject khi lỗi mạng / API.
|
|
671
|
+
*/
|
|
672
|
+
declare const fetchMiniAppChangelog: (app_id: string, { from, to, channel }?: {
|
|
673
|
+
from?: string;
|
|
674
|
+
to?: string;
|
|
675
|
+
channel?: MiniAppChannel;
|
|
676
|
+
}) => Promise<MiniAppChangelogVersion[]>;
|
|
677
|
+
interface MiniAppChangelogState {
|
|
678
|
+
versions: MiniAppChangelogVersion[];
|
|
679
|
+
loading: boolean;
|
|
680
|
+
error?: string;
|
|
681
|
+
reload: () => void;
|
|
682
|
+
}
|
|
683
|
+
/** Hook lấy changelog (modal "Có gì mới": truyền from/to; màn "Xem tất cả": bỏ trống). enabled=false → không gọi. */
|
|
684
|
+
declare const useMiniAppChangelog: (app_id: string | undefined, { from, to, enabled }?: {
|
|
685
|
+
from?: string;
|
|
686
|
+
to?: string;
|
|
687
|
+
enabled?: boolean;
|
|
688
|
+
}) => MiniAppChangelogState;
|
|
689
|
+
|
|
636
690
|
/**
|
|
637
691
|
* App → web: gửi event xuống web của mini app — web nhận y như `WebView.postMessage` (sự kiện `message`).
|
|
638
692
|
* `instance_id`: instance_id lúc openMiniApp; không dùng instance_id thì truyền app_id.
|
|
@@ -804,4 +858,4 @@ interface UploadCapabilities {
|
|
|
804
858
|
/** 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. */
|
|
805
859
|
declare const uploadToUrl: MiniAppUploader;
|
|
806
860
|
|
|
807
|
-
export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSpeechProvider, type MiniAppSpeechStartContext, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
|
|
861
|
+
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 MiniAppChangelog, type MiniAppChangelogState, type MiniAppChangelogVersion, 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 MiniAppPendingChangelog, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSpeechProvider, type MiniAppSpeechStartContext, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, fetchMiniAppChangelog, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppChangelogSeen, getMiniAppStatuses, getMiniAppUpdate, getPendingChangelog, installBundledMiniApp, markMiniAppChangelogSeen, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppChangelog, useMiniAppDownload, useMiniAppDownloadsPaused };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,17 @@ type MiniAppChannel = 'production' | 'testing';
|
|
|
4
4
|
/** Quyền lấy token nhạy cảm — admin bật trên Console, Platform trả trong manifest. */
|
|
5
5
|
type MiniAppPermission = 'partner_token' | 'chatbox_token';
|
|
6
6
|
/** Manifest Platform trả (API list ứng dụng hoặc manifest lẻ). */
|
|
7
|
+
/** Changelog 1 version (Console / CHANGELOG.md): Mới · Sửa lỗi · Cải thiện. */
|
|
8
|
+
interface MiniAppChangelog {
|
|
9
|
+
new: string[];
|
|
10
|
+
fix: string[];
|
|
11
|
+
improve: string[];
|
|
12
|
+
}
|
|
13
|
+
interface MiniAppChangelogVersion {
|
|
14
|
+
version: string;
|
|
15
|
+
changelog: MiniAppChangelog;
|
|
16
|
+
created_at: string;
|
|
17
|
+
}
|
|
7
18
|
interface MiniAppManifest {
|
|
8
19
|
app_id: string;
|
|
9
20
|
name?: string;
|
|
@@ -15,6 +26,8 @@ interface MiniAppManifest {
|
|
|
15
26
|
/** true: đổi conversation → đẩy context; false: reload với context mới. */
|
|
16
27
|
context_update?: boolean;
|
|
17
28
|
permissions?: MiniAppPermission[];
|
|
29
|
+
/** Changelog version này (null: bản deploy trước khi có changelog). */
|
|
30
|
+
changelog?: MiniAppChangelog | null;
|
|
18
31
|
}
|
|
19
32
|
/** Bundle đã giải nén trong máy. */
|
|
20
33
|
interface MiniAppLocalBundle {
|
|
@@ -276,12 +289,19 @@ interface MiniAppBridgeOptions {
|
|
|
276
289
|
* (không phải cập nhật mini app web). Không truyền → dùng nhận dạng có sẵn.
|
|
277
290
|
*/
|
|
278
291
|
speech?: MiniAppSpeechProvider;
|
|
292
|
+
/**
|
|
293
|
+
* Trợ lý voice AI của app (ưu tiên hơn `speech`). Nhận mọi speech.start trừ khi web gọi `startSpeech({ mode: 's2t' })`
|
|
294
|
+
* — lúc đó luôn dùng nhận dạng có sẵn (expo-speech-recognition), bỏ qua cả `voice` lẫn `speech`.
|
|
295
|
+
*/
|
|
296
|
+
voice?: MiniAppSpeechProvider;
|
|
279
297
|
}
|
|
280
298
|
/** Ngữ cảnh 1 lần web gọi speech.start (provider của app tự quản phiên). */
|
|
281
299
|
interface MiniAppSpeechStartContext {
|
|
282
300
|
/** WebView đang gọi — dùng làm khoá phiên cho stop / release */
|
|
283
301
|
owner: string;
|
|
284
302
|
app_id: string;
|
|
303
|
+
/** Web chọn: 'voice' = trợ lý voice AI (mặc định). Provider chỉ nhận 'voice'; 's2t' luôn đi nhận dạng có sẵn. */
|
|
304
|
+
mode: 's2t' | 'voice';
|
|
285
305
|
/** Tham số web truyền (đã kiểm tra hợp lệ) */
|
|
286
306
|
options: {
|
|
287
307
|
lang?: string;
|
|
@@ -633,6 +653,40 @@ declare const installBundledMiniApp: ({ manifest, zip_path }: {
|
|
|
633
653
|
zip_path: string;
|
|
634
654
|
}) => Promise<MiniAppLocalBundle>;
|
|
635
655
|
|
|
656
|
+
interface MiniAppPendingChangelog {
|
|
657
|
+
app_id: string;
|
|
658
|
+
/** Version đã xem changelog lần trước (loại trừ). */
|
|
659
|
+
from: string;
|
|
660
|
+
/** Version đang có trong máy (bao gồm). */
|
|
661
|
+
to: string;
|
|
662
|
+
}
|
|
663
|
+
declare const getMiniAppChangelogSeen: (app_id: string) => string | null;
|
|
664
|
+
/** Đã xem changelog tới version này (mặc định: bản đang có trong máy). */
|
|
665
|
+
declare const markMiniAppChangelogSeen: (app_id: string, version?: string | undefined) => void;
|
|
666
|
+
/** Gọi khi người dùng bấm mở mini app: có bản mới chưa xem changelog → { from, to }, không thì null. */
|
|
667
|
+
declare const getPendingChangelog: (app_id: string) => MiniAppPendingChangelog | null;
|
|
668
|
+
/**
|
|
669
|
+
* Changelog từ Platform, mới nhất trước. from: loại trừ, to: bao gồm; bỏ trống cả 2 → toàn bộ lịch sử.
|
|
670
|
+
* Reject khi lỗi mạng / API.
|
|
671
|
+
*/
|
|
672
|
+
declare const fetchMiniAppChangelog: (app_id: string, { from, to, channel }?: {
|
|
673
|
+
from?: string;
|
|
674
|
+
to?: string;
|
|
675
|
+
channel?: MiniAppChannel;
|
|
676
|
+
}) => Promise<MiniAppChangelogVersion[]>;
|
|
677
|
+
interface MiniAppChangelogState {
|
|
678
|
+
versions: MiniAppChangelogVersion[];
|
|
679
|
+
loading: boolean;
|
|
680
|
+
error?: string;
|
|
681
|
+
reload: () => void;
|
|
682
|
+
}
|
|
683
|
+
/** Hook lấy changelog (modal "Có gì mới": truyền from/to; màn "Xem tất cả": bỏ trống). enabled=false → không gọi. */
|
|
684
|
+
declare const useMiniAppChangelog: (app_id: string | undefined, { from, to, enabled }?: {
|
|
685
|
+
from?: string;
|
|
686
|
+
to?: string;
|
|
687
|
+
enabled?: boolean;
|
|
688
|
+
}) => MiniAppChangelogState;
|
|
689
|
+
|
|
636
690
|
/**
|
|
637
691
|
* App → web: gửi event xuống web của mini app — web nhận y như `WebView.postMessage` (sự kiện `message`).
|
|
638
692
|
* `instance_id`: instance_id lúc openMiniApp; không dùng instance_id thì truyền app_id.
|
|
@@ -804,4 +858,4 @@ interface UploadCapabilities {
|
|
|
804
858
|
/** 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. */
|
|
805
859
|
declare const uploadToUrl: MiniAppUploader;
|
|
806
860
|
|
|
807
|
-
export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSpeechProvider, type MiniAppSpeechStartContext, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
|
|
861
|
+
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 MiniAppChangelog, type MiniAppChangelogState, type MiniAppChangelogVersion, 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 MiniAppPendingChangelog, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSpeechProvider, type MiniAppSpeechStartContext, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, fetchMiniAppChangelog, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppChangelogSeen, getMiniAppStatuses, getMiniAppUpdate, getPendingChangelog, installBundledMiniApp, markMiniAppChangelogSeen, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppChangelog, useMiniAppDownload, useMiniAppDownloadsPaused };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var pr=Object.create;var ft=Object.defineProperty;var ur=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var gr=Object.getPrototypeOf,mr=Object.prototype.hasOwnProperty;var hr=(e,t)=>{for(var n in t)ft(e,n,{get:t[n],enumerable:!0})},Sn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of dr(t))!mr.call(e,r)&&r!==n&&ft(e,r,{get:()=>t[r],enumerable:!(o=ur(t,r))||o.enumerable});return e};var le=(e,t,n)=>(n=e!=null?pr(gr(e)):{},Sn(t||!e||!e.__esModule?ft(n,"default",{value:e,enumerable:!0}):n,e)),fr=e=>Sn(ft({},"__esModule",{value:!0}),e);var fi={};hr(fi,{CodeType:()=>ee,DefaultMiniAppSplash:()=>bn,MINIAPP_PLATFORM_URL:()=>yt,MiniAppHost:()=>lr,MiniAppHostError:()=>m,ScannerEndReason:()=>We,ScannerEvent:()=>xt,ScannerLayout:()=>pe,ScannerMethod:()=>He,ToastType:()=>he,closeMiniApp:()=>Ke,configureMiniApp:()=>Mn,createMmkvStorage:()=>Rn,createReactNativeBiometrics:()=>zt,createRnfsFileSystem:()=>En,ensureMiniApp:()=>gt,getLocalMiniApp:()=>B,getMiniAppCatalog:()=>ir,getMiniAppCatalogEntry:()=>Ye,getMiniAppStatuses:()=>Yo,getMiniAppUpdate:()=>yn,installBundledMiniApp:()=>ko,onMiniAppEvent:()=>Ko,openMiniApp:()=>Wo,pauseMiniApp:()=>er,pauseMiniAppDownloads:()=>nr,preloadMiniApp:()=>zo,releaseSpeechFor:()=>Re,restoreMiniApp:()=>Qo,resumeMiniApp:()=>tr,resumeMiniAppDownloads:()=>or,sendEventToWeb:()=>Fo,syncMiniAppCatalog:()=>Bt,uninstallMiniApp:()=>Zo,updateMiniApp:()=>rr,uploadToUrl:()=>Gt,useMiniAppDownload:()=>Ut,useMiniAppDownloadsPaused:()=>Go});module.exports=fr(fi);var yt="https://retion-miniapp-platform.vercel.app",Be=null,vn=new Set,Mn=e=>{Be=e,vn.forEach(t=>t())},$=()=>{if(!Be)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Be},xn=e=>{vn.add(e),Be&&e()},me=(...e)=>{Be!=null&&Be.debug&&console.log("[miniapp]",...e)};var En=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),Rn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var A=le(require("react")),O=require("react-native"),cr=le(require("react-native-webview"));var st=require("react-native");var zt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),wt,jt=()=>(wt||(wt=import("react-native-biometrics").then(({default:e})=>zt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw wt=void 0,new m("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),wt);var Ee=require("react-native");var Pn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new m("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new m("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new m("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Tn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new m("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(Ee.Platform.OS==="android"){let s=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,g=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Ee.PermissionsAndroid.check(s);if(!c())return;let y=d||await Ee.PermissionsAndroid.check(g);if(!c())return;if(!d&&!y){let u=await Ee.PermissionsAndroid.requestMultiple([s,g]);if(!c())return;if(u[s]!==Ee.PermissionsAndroid.RESULTS.GRANTED&&u[g]!==Ee.PermissionsAndroid.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});var Jt=require("react-native");var Ht=20,Cn=20,Dn=/^[a-z][a-z0-9_-]{0,31}$/,yr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,wr=["low","medium","high"],ke=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Y=e=>new m("INVALID_PARAMS",e),ot=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,On=(e,t)=>{if(e===void 0)return{};if(!ke(e)||Object.keys(e).length>Cn||Object.values(e).some(n=>typeof n!="string"))throw Y(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Cn} key)`);return e},Nn=e=>{var n,o,r,i;if(e!==void 0&&!ke(e))throw Y("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Dn.test(t.source)))throw Y("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!yr.test(a))))throw Y("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!ot(t.max_count,1,Ht))throw Y(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Ht}`);if(t.max_size!==void 0&&!ot(t.max_size,1,Number.MAX_SAFE_INTEGER))throw Y("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!ot(t.concurrency,1,5))throw Y("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:br(t.process),target:_r(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},br=e=>{if(e===void 0)return{};if(!ke(e))throw Y("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!ke(n))throw Y("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!ot(n[o],1,1e4))throw Y(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw Y("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!ke(n))throw Y("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!ot(n.max_duration,1,3600))throw Y("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!wr.includes(n.quality))throw Y("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},_r=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!ke(e))throw Y("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Dn.test(t))throw Y("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!ke(e.params))throw Y("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw Y("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw Y(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:On(e.headers,"upload.headers"),form_data:On(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Un=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},Ar=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Un(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Sr=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},et,vr=()=>(et!=null||(et=import("react-native-image-picker").catch(e=>{throw et=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),et),kn=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,y,u,w,L,P;let r=await vr(),i=Sr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(y=o.video)==null?void 0:y.quality)!=null?u:"medium",durationLimit:(w=o.video)==null?void 0:w.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let E=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(E,(L=c.errorMessage)!=null?L:c.errorCode)}return((P=c.assets)!=null?P:[]).filter(E=>E.uri).map((E,M)=>{var N,W,ne;return{uri:E.uri,name:(N=E.fileName)!=null?N:`file_${M+1}`,mime_type:(W=E.type)!=null?W:"application/octet-stream",size:E.fileSize,width:E.width,height:E.height,duration:E.duration,processed:!((ne=E.type)!=null&&ne.startsWith("video/"))||Jt.Platform.OS==="ios"}})},Mr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},xr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Er=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=Mr[s])!=null?g:xr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,w)=>{var L,P,E;return{uri:u.uri,name:(L=u.name)!=null?L:`file_${w+1}`,mime_type:(P=u.type)!=null?P:"application/octet-stream",size:(E=u.size)!=null?E:void 0}});if(Jt.Platform.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),y=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var w;return{...u,uri:(w=y.get(u.uri))!=null?w:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},tt,Rr=async e=>(tt!=null||(tt=import("@react-native-documents/picker").then(t=>Er(t)).catch(t=>{throw tt=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await tt)(e)),Vn={library:kn("library"),camera:kn("camera"),document:Rr},In={type:"image",label:"\u1EA2nh",accept:["image/*"]},Ln={type:"video",label:"Video",accept:["video/*"]},Fn={library:[In,Ln],camera:[In,Ln],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},nt,Bn=()=>(nt!=null||(nt=import("react-native-compressor").catch(()=>(nt=void 0,null))),nt),qn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Pr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Tr={low:640,medium:1280,high:1920},Cr=async(e,{image:t})=>{var o;if(!t||!Pr.has(e.mime_type.toLowerCase()))return e;let n=await Bn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await qn(n,r,e.size),processed:!0}}catch{return e}},Or=async(e,{video:t})=>{var o;let n=await Bn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Tr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await qn(n,r,e.size),processed:!0}}catch{return e}},kr={image:Cr,video:Or},Ir=(e,t)=>t.split(".").reduce((n,o)=>ke(n)?n[o]:void 0,e),Gt=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,y])=>l.append(d,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,y])=>c.setRequestHeader(d,y)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=Ir(d,a.url_field);if(typeof y!="string"||!y){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),$n=e=>{var o,r;let t={...Vn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:Gt};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},Wn=e=>{let{sources:t,targets:n}=$n(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Vn[i]&&Fn[i]).map(i=>[i,Fn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Ht}},_t=new Map,zn=(e,t)=>`${e}:${t}`,Lr=0,jn=(e,t)=>{var n;typeof t=="string"&&((n=_t.get(zn(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of _t)t.startsWith(`${e}:`)&&n.abort()},bt=()=>new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Fr=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},Hn=async(e,t)=>{var l;let{sources:n,targets:o}=$n(t.config),r=n[e.source];if(!r)throw new m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=zn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Lr}`);_t.set(c,a);try{return await Dr(e,t,r,i,a.signal)}finally{_t.delete(c)}},Dr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=d=>d()},l,s,g)=>{var p,x,q;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw bt();if(!y.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],w=y.filter(T=>Ar(T,e.accept)?!0:(u.push({name:T.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${T.mime_type||Un(T.name)}`}),!1)),L=w.map(()=>0),P=w.map(T=>{var ce;return(ce=T.size)!=null?ce:0}),E=0,M=0,N=(T=!1)=>{if(!a||!r)return;let ce=Date.now();if(!T&&ce-M<200)return;M=ce;let _e=P.reduce((k,oe)=>k+oe,0),K=L.reduce((k,oe)=>k+oe,0);a("upload.progress",{task_id:r,loaded:K,total:_e,percent:_e?Math.min(100,Math.round(K/_e*100)):0,done_count:E,count:w.length})},W=[],ne=0,Pe=async()=>{var T,ce,_e;for(;ne<w.length;){let K=ne++,k=w[K];try{if(g.aborted)throw bt();let oe=k.mime_type.startsWith("image/")?"image":k.mime_type.startsWith("video/")?"video":void 0,J=oe&&!k.processed?(ce=(T=i==null?void 0:i.processors)==null?void 0:T[oe])!=null?ce:kr[oe]:void 0;if(J&&(k=await J(k,e.process),P[K]=(_e=k.size)!=null?_e:P[K],g.aborted))throw bt();if(e.max_size&&k.size&&k.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${k.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Q=(je,xe)=>{L[K]=je,xe&&(P[K]=xe),N()},re=await s({file:k,target:e.target,onProgress:Q,signal:g,caller:d});if(typeof(re==null?void 0:re.url)!="string"||!re.url)throw new m("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:ve,...Me}=re;W[K]={url:ve,name:k.name,mime_type:k.mime_type,size:k.size,width:k.width,height:k.height,duration:k.duration,...Object.keys(Me).length?{response:"response"in Me?Me.response:Me}:{}},L[K]=P[K]}catch(oe){u.push(Fr(w[K].name,oe))}finally{E++,N(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,w.length)},Pe)),g.aborted)throw bt();let ae=W.filter(T=>!!T);if(!ae.length){let T=u[0];throw new m((x=T==null?void 0:T.code)!=null?x:"UPLOAD_FAILED",(q=T==null?void 0:T.message)!=null?q:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ae,failed:u}};var At=require("react"),Ie=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},j=(e,t,n=Object.is)=>{let o=(0,At.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return(0,At.useSyncExternalStore)(e.subscribe,r)};var he={info:"info",success:"success",error:"error"},Nr=200,Jn={info:2e3,success:2e3,error:3e3},rt=Ie({message:"",type:he.info,tick:0}),Gn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Nr);return o?{message:o,type:Object.values(he).includes(n)?n:he.info}:null},Kn=(e,t=he.info)=>{rt.setState(n=>({message:e,type:t,tick:n.tick+1}))};var ye=require("react-native");var $e=require("react-native");var fe,St=new Map,Yn=(e,t)=>{St.set(e,t)},Xn=e=>{St.delete(e)},Zn=()=>$e.Platform.OS==="android"&&!!(fe!=null&&fe.requesting_permission),Ur=1500,vt=()=>new Promise(e=>{if($e.Platform.OS!=="android"||$e.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Ur),o=$e.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Kt=e=>{var t;if(fe===e&&(fe=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&$e.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Qn=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(fe)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};fe=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await vt(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var w,L;fe!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(L=(w=u.results[0])==null?void 0:w.transcript)!=null?L:""})}),d.addListener("error",u=>{fe===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{fe===r&&(Kt(r),n("speech.end"))})),r.started=!0,d.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:g.AVAudioSessionCategory.playAndRecord,categoryOptions:[g.AVAudioSessionCategoryOptions.defaultToSpeaker,g.AVAudioSessionCategoryOptions.allowBluetooth],mode:g.AVAudioSessionMode.measurement}})}catch(g){throw Kt(r),g}},eo=e=>{let t=fe;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{var o;let t=St.get(e);if(t){St.delete(e);try{(o=t.release)==null||o.call(t,e)}catch{}return}let n=fe;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Kt(n)}};var to={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},ee={...to,all:Object.values(to)},He={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},xt={result:"scanner.result",end:"scanner.end"},We={user:"user",web:"web",closed:"closed",error:"error"},pe={top:"top",full:"full"},Le={once:"once",continuous:"continuous"},Vr=1500,no=6e4,V,X=Ie({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),ro=()=>ye.Platform.OS==="android"&&!!(V!=null&&V.requesting_permission),Xt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>ee.all.includes(c)))throw new m("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>no)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${no}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new m("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(pe).includes(r))throw new m("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new m("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},Zt=e=>V!==e?!1:(V=void 0,X.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Br=()=>ye.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{ye.Linking.openSettings().catch(()=>{})}}]),io=async(e,t)=>{if(V)throw new m("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");V=e;let n=()=>{if(e.cancelled||!t())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=ye.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await vt(),n(),c!=="granted")throw a&&Br(),new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new m("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Qt();n(),X.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw Zt(e),o}},Mt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Mt=e==null?void 0:e.insets}).catch(()=>{});var Et=()=>{var e;return Mt!=null?Mt:{top:ye.Platform.OS==="ios"?54:(e=ye.StatusBar.currentHeight)!=null?e:0,bottom:ye.Platform.OS==="ios"?34:48}},Qt=async()=>{if(ye.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},so=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:ee.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Vr,hint:n.hint,layout:t===Le.once?pe.full:(i=n.layout)!=null?i:pe.top,absolute:t!==Le.once&&((a=n.layout)!=null?a:pe.top)===pe.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},ao=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=so(e,Le.once,t);a.onHit=o,a.resolve=r,a.reject=i,io(a,n).catch(i)}),co=(e,t,n,o=()=>!0,r)=>{let i=so(e,Le.continuous,t);return i.emit=n,i.onHit=r,io(i,o)},Rt=(e,t,n)=>{var o,r;if(!X.getState().active){e.cancelled=!0;return}if(Zt(e)){if(e.mode===Le.once){(o=e.reject)==null||o.call(e,t===We.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,xt.end,n?{reason:t,message:n}:{reason:t})}},lo=e=>{(V==null?void 0:V.owner)===e&&Rt(V,We.web)},Fe=e=>{(V==null?void 0:V.owner)===e&&Rt(V,We.closed)},en=()=>{V&&Rt(V,We.user)},po=e=>{V&&Rt(V,We.error,e)},tn=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=V;if(!(!o||!X.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Le.once){Zt(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}X.setState(g=>({last_value:c,hit_tick:g.hit_tick+1,scan_count:g.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,xt.result,{value:c,type:l})}}},qr={1:ee.code128,2:ee.code39,4:ee.code93,8:ee.codabar,16:ee.dataMatrix,32:ee.ean13,64:ee.ean8,128:ee.itf,256:ee.qr,512:ee.upcA,1024:ee.upcE,2048:ee.pdf417,4096:ee.aztec},$r=2500,oo=2e3,Yt=e=>{X.setState({notice:e}),setTimeout(()=>{X.getState().notice===e&&X.setState({notice:null})},$r)},uo=async()=>{var t,n;let e=V;if(!(!e||X.getState().is_picking)){e.requesting_permission=!0,X.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:oo,maxHeight:oo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||V!==e)return;if(r.errorCode||!i){Yt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(V!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:qr[g]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:g})=>({value:s,type:g!=null?g:"unknown"}));if(!l.length){Yt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}tn(l,Date.now(),!0)}catch{V===e&&Yt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await vt(),e.requesting_permission=!1,V===e&&X.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},go=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,mo=(e,t)=>at({id:e,result:t}),ho=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),fo=(e,t)=>at({event:e,data:t}),on=e=>at({event:"context",data:e});var yo=()=>`(function () {
|
|
1
|
+
"use strict";var Sr=Object.create;var bt=Object.defineProperty;var _r=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var Mr=Object.getPrototypeOf,xr=Object.prototype.hasOwnProperty;var Er=(e,t)=>{for(var n in t)bt(e,n,{get:t[n],enumerable:!0})},Pn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of vr(t))!xr.call(e,r)&&r!==n&&bt(e,r,{get:()=>t[r],enumerable:!(o=_r(t,r))||o.enumerable});return e};var le=(e,t,n)=>(n=e!=null?Sr(Mr(e)):{},Pn(t||!e||!e.__esModule?bt(n,"default",{value:e,enumerable:!0}):n,e)),Cr=e=>Pn(bt({},"__esModule",{value:!0}),e);var Pi={};Er(Pi,{CodeType:()=>te,DefaultMiniAppSplash:()=>_n,MINIAPP_PLATFORM_URL:()=>Je,MiniAppHost:()=>yr,MiniAppHostError:()=>g,ScannerEndReason:()=>We,ScannerEvent:()=>Et,ScannerLayout:()=>pe,ScannerMethod:()=>Ke,ToastType:()=>me,closeMiniApp:()=>Qe,configureMiniApp:()=>Tn,createMmkvStorage:()=>In,createReactNativeBiometrics:()=>jt,createRnfsFileSystem:()=>kn,ensureMiniApp:()=>ft,fetchMiniAppChangelog:()=>xn,getLocalMiniApp:()=>N,getMiniAppCatalog:()=>gr,getMiniAppCatalogEntry:()=>Ze,getMiniAppChangelogSeen:()=>vn,getMiniAppStatuses:()=>rr,getMiniAppUpdate:()=>An,getPendingChangelog:()=>br,installBundledMiniApp:()=>Bo,markMiniAppChangelogSeen:()=>Mn,onMiniAppEvent:()=>or,openMiniApp:()=>Xo,pauseMiniApp:()=>cr,pauseMiniAppDownloads:()=>pr,preloadMiniApp:()=>Qo,releaseSpeechFor:()=>Ce,restoreMiniApp:()=>ar,resumeMiniApp:()=>lr,resumeMiniAppDownloads:()=>ur,sendEventToWeb:()=>zo,syncMiniAppCatalog:()=>qt,uninstallMiniApp:()=>sr,updateMiniApp:()=>dr,uploadToUrl:()=>Kt,useMiniAppChangelog:()=>Ar,useMiniAppDownload:()=>Vt,useMiniAppDownloadsPaused:()=>nr});module.exports=Cr(Pi);var Je="https://retion-miniapp-platform.vercel.app",qe=null,Rn=new Set,Tn=e=>{qe=e,Rn.forEach(t=>t())},D=()=>{if(!qe)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return qe},On=e=>{Rn.add(e),qe&&e()},he=(...e)=>{qe!=null&&qe.debug&&console.log("[miniapp]",...e)};var kn=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),In=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var S=le(require("react")),I=require("react-native"),fr=le(require("react-native-webview"));var lt=require("react-native");var jt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),At,Ht=()=>(At||(At=import("react-native-biometrics").then(({default:e})=>jt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw At=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),At);var Ee=require("react-native");var Ln=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Fn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(Ee.Platform.OS==="android"){let s=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,u=await Ee.PermissionsAndroid.check(s);if(!c())return;let y=u||await Ee.PermissionsAndroid.check(d);if(!c())return;if(!u&&!y){let p=await Ee.PermissionsAndroid.requestMultiple([s,d]);if(!c())return;if(p[s]!==Ee.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==Ee.PermissionsAndroid.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var u;if(!c())return;let d=(u={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?u:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(l=>i(l))});var Gt=require("react-native");var Jt=20,Dn=20,$n=/^[a-z][a-z0-9_-]{0,31}$/,Pr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Rr=["low","medium","high"],Ie=e=>!!e&&typeof e=="object"&&!Array.isArray(e),X=e=>new g("INVALID_PARAMS",e),st=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Nn=(e,t)=>{if(e===void 0)return{};if(!Ie(e)||Object.keys(e).length>Dn||Object.values(e).some(n=>typeof n!="string"))throw X(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Dn} key)`);return e},zn=e=>{var n,o,r,i;if(e!==void 0&&!Ie(e))throw X("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 X("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"||!Pr.test(a))))throw X("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!st(t.max_count,1,Jt))throw X(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Jt}`);if(t.max_size!==void 0&&!st(t.max_size,1,Number.MAX_SAFE_INTEGER))throw X("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!st(t.concurrency,1,5))throw X("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:Tr(t.process),target:Or(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Tr=e=>{if(e===void 0)return{};if(!Ie(e))throw X("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Ie(n))throw X("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!st(n[o],1,1e4))throw X(`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 X("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(!Ie(n))throw X("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!st(n.max_duration,1,3600))throw X("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Rr.includes(n.quality))throw X("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},Or=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Ie(e))throw X("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!$n.test(t))throw X("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Ie(e.params))throw X("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 X("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 X(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Nn(e.headers,"upload.headers"),form_data:Nn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Wn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},kr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Wn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Ir=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"},ot,Lr=()=>(ot!=null||(ot=import("react-native-image-picker").catch(e=>{throw ot=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),ot),Un=e=>async({accept:t,max_count:n,process:o})=>{var l,s,d,u,y,p,f,O,R;let r=await Lr(),i=Ir(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(u=(d=o.image)==null?void 0:d.quality)!=null?u:.8,videoQuality:(p=(y=o.video)==null?void 0:y.quality)!=null?p:"medium",durationLimit:(f=o.video)==null?void 0:f.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let C=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(C,(O=c.errorMessage)!=null?O:c.errorCode)}return((R=c.assets)!=null?R:[]).filter(C=>C.uri).map((C,M)=>{var q,W,oe;return{uri:C.uri,name:(q=C.fileName)!=null?q:`file_${M+1}`,mime_type:(W=C.type)!=null?W:"application/octet-stream",size:C.fileSize,width:C.width,height:C.height,duration:C.duration,processed:!((oe=C.type)!=null&&oe.startsWith("video/"))||Gt.Platform.OS==="ios"}})},Fr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},Dr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Nr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var d;return(d=Fr[s])!=null?d:Dr[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,f)=>{var O,R,C;return{uri:p.uri,name:(O=p.name)!=null?O:`file_${f+1}`,mime_type:(R=p.type)!=null?R:"application/octet-stream",size:(C=p.size)!=null?C:void 0}});if(Gt.Platform.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let u=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),y=new Map(u.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var f;return{...p,uri:(f=y.get(p.uri))!=null?f:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},rt,Ur=async e=>(rt!=null||(rt=import("@react-native-documents/picker").then(t=>Nr(t)).catch(t=>{throw rt=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await rt)(e)),jn={library:Un("library"),camera:Un("camera"),document:Ur},Vn={type:"image",label:"\u1EA2nh",accept:["image/*"]},Bn={type:"video",label:"Video",accept:["video/*"]},qn={library:[Vn,Bn],camera:[Vn,Bn],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"]}]},it,Hn=()=>(it!=null||(it=import("react-native-compressor").catch(()=>(it=void 0,null))),it),Jn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Vr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Br={low:640,medium:1280,high:1920},qr=async(e,{image:t})=>{var o;if(!t||!Vr.has(e.mime_type.toLowerCase()))return e;let n=await Hn();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 Jn(n,r,e.size),processed:!0}}catch{return e}},$r=async(e,{video:t})=>{var o;let n=await Hn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Br[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Jn(n,r,e.size),processed:!0}}catch{return e}},zr={image:qr,video:$r},Wr=(e,t)=>t.split(".").reduce((n,o)=>Ie(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 g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([u,y])=>l.append(u,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let d=u=>{o.removeEventListener("abort",s),u()};c.open("POST",a.url),Object.entries(a.headers).forEach(([u,y])=>c.setRequestHeader(u,y)),c.upload.onprogress=u=>n(u.loaded,u.total||e.size||0),c.onload=()=>d(()=>{let u=c.responseText;try{u=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=Wr(u,a.url_field);if(typeof y!="string"||!y){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:u})}),c.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),Gn=e=>{var o,r;let t={...jn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:Kt};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}},Kn=e=>{let{sources:t,targets:n}=Gn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===jn[i]&&qn[i]).map(i=>[i,qn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Jt}},_t=new Map,Yn=(e,t)=>`${e}:${t}`,jr=0,Xn=(e,t)=>{var n;typeof t=="string"&&((n=_t.get(Yn(e,t)))==null||n.abort())},$e=e=>{for(let[t,n]of _t)t.startsWith(`${e}:`)&&n.abort()},St=()=>new g("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 l;let{sources:n,targets:o}=Gn(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=Yn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++jr}`);_t.set(c,a);try{return await Jr(e,t,r,i,a.signal)}finally{_t.delete(c)}},Jr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=u=>u()},l,s,d)=>{var E,m,T;let u={app_id:n!=null?n:"",instance_id:t,context:{...(E=o==null?void 0:o())!=null?E:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:u}))).slice(0,e.max_count);if(d.aborted)throw St();if(!y.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],f=y.filter(x=>kr(x,e.accept)?!0:(p.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||Wn(x.name)}`}),!1)),O=f.map(()=>0),R=f.map(x=>{var V;return(V=x.size)!=null?V:0}),C=0,M=0,q=(x=!1)=>{if(!a||!r)return;let V=Date.now();if(!x&&V-M<200)return;M=V;let Ae=R.reduce((L,re)=>L+re,0),Y=O.reduce((L,re)=>L+re,0);a("upload.progress",{task_id:r,loaded:Y,total:Ae,percent:Ae?Math.min(100,Math.round(Y/Ae*100)):0,done_count:C,count:f.length})},W=[],oe=0,Pe=async()=>{var x,V,Ae;for(;oe<f.length;){let Y=oe++,L=f[Y];try{if(d.aborted)throw St();let re=L.mime_type.startsWith("image/")?"image":L.mime_type.startsWith("video/")?"video":void 0,G=re&&!L.processed?(V=(x=i==null?void 0:i.processors)==null?void 0:x[re])!=null?V:zr[re]:void 0;if(G&&(L=await G(L,e.process),R[Y]=(Ae=L.size)!=null?Ae:R[Y],d.aborted))throw St();if(e.max_size&&L.size&&L.size>e.max_size)throw new g("FILE_TOO_LARGE",`File ${L.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let ee=(He,xe)=>{O[Y]=He,xe&&(R[Y]=xe),q()},ie=await s({file:L,target:e.target,onProgress:ee,signal:d,caller:u});if(typeof(ie==null?void 0:ie.url)!="string"||!ie.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:ve,...Me}=ie;W[Y]={url:ve,name:L.name,mime_type:L.mime_type,size:L.size,width:L.width,height:L.height,duration:L.duration,...Object.keys(Me).length?{response:"response"in Me?Me.response:Me}:{}},O[Y]=R[Y]}catch(re){p.push(Hr(f[Y].name,re))}finally{C++,q(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,f.length)},Pe)),d.aborted)throw St();let ce=W.filter(x=>!!x);if(!ce.length){let x=p[0];throw new g((m=x==null?void 0:x.code)!=null?m:"UPLOAD_FAILED",(T=x==null?void 0:x.message)!=null?T:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ce,failed:p}};var vt=require("react"),Le=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},H=(e,t,n=Object.is)=>{let o=(0,vt.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return(0,vt.useSyncExternalStore)(e.subscribe,r)};var me={info:"info",success:"success",error:"error"},Gr=200,Zn={info:2e3,success:2e3,error:3e3},at=Le({message:"",type:me.info,tick:0}),eo=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Gr);return o?{message:o,type:Object.values(me).includes(n)?n:me.info}:null},to=(e,t=me.info)=>{at.setState(n=>({message:e,type:t,tick:n.tick+1}))};var ye=require("react-native");var ze=require("react-native");var fe,Ge=new Map,no=(e,t)=>{var o;let n=(o=Ge.get(e))!=null?o:new Set;n.add(t),Ge.set(e,n)},oo=(e,t)=>{let n=Ge.get(e);n&&(t?n.delete(t):n.clear(),n.size===0&&Ge.delete(e))},Xt=new Map,ro=(e,t)=>{Xt.set(e,t)},io=e=>Xt.get(e),so=()=>ze.Platform.OS==="android"&&!!(fe!=null&&fe.requesting_permission),Kr=1500,Mt=()=>new Promise(e=>{if(ze.Platform.OS!=="android"||ze.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Kr),o=ze.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Yt=e=>{var t;if(fe===e&&(fe=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&ze.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},ao=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(fe)throw new g("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};fe=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let u=d.ExpoSpeechRecognitionModule;if(r.native=u,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await u.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await Mt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await u.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(u.addListener("result",p=>{var f,O;fe!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(O=(f=p.results[0])==null?void 0:f.transcript)!=null?O:""})}),u.addListener("error",p=>{fe===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),u.addListener("end",()=>{fe===r&&(Yt(r),n("speech.end"))})),r.started=!0,u.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw Yt(r),d}},co=e=>{let t=fe;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Ce=e=>{Xt.delete(e);let t=Ge.get(e);Ge.delete(e),t==null||t.forEach(o=>{var r;try{(r=o.release)==null||r.call(o,e)}catch{}});let n=fe;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Yt(n)}};var lo={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"},te={...lo,all:Object.values(lo)},Ke={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Et={result:"scanner.result",end:"scanner.end"},We={user:"user",web:"web",closed:"closed",error:"error"},pe={top:"top",full:"full"},Fe={once:"once",continuous:"continuous"},Yr=1500,po=6e4,z,Q=Le({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),go=()=>ye.Platform.OS==="android"&&!!(z!=null&&z.requesting_permission),Zt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>te.all.includes(c)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>po)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${po}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(pe).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new g("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},en=e=>z!==e?!1:(z=void 0,Q.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Xr=()=>ye.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{ye.Linking.openSettings().catch(()=>{})}}]),ho=async(e,t)=>{if(z)throw new g("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");z=e;let n=()=>{if(e.cancelled||!t())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=ye.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await Mt(),n(),c!=="granted")throw a&&Xr(),new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new g("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await tn();n(),Q.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw en(e),o}},xt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{xt=e==null?void 0:e.insets}).catch(()=>{});var Ct=()=>{var e;return xt!=null?xt:{top:ye.Platform.OS==="ios"?54:(e=ye.StatusBar.currentHeight)!=null?e:0,bottom:ye.Platform.OS==="ios"?34:48}},tn=async()=>{if(ye.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},mo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:te.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Yr,hint:n.hint,layout:t===Fe.once?pe.full:(i=n.layout)!=null?i:pe.top,absolute:t!==Fe.once&&((a=n.layout)!=null?a:pe.top)===pe.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},fo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=mo(e,Fe.once,t);a.onHit=o,a.resolve=r,a.reject=i,ho(a,n).catch(i)}),yo=(e,t,n,o=()=>!0,r)=>{let i=mo(e,Fe.continuous,t);return i.emit=n,i.onHit=r,ho(i,o)},Pt=(e,t,n)=>{var o,r;if(!Q.getState().active){e.cancelled=!0;return}if(en(e)){if(e.mode===Fe.once){(o=e.reject)==null||o.call(e,t===We.error?new g("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new g("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Et.end,n?{reason:t,message:n}:{reason:t})}},wo=e=>{(z==null?void 0:z.owner)===e&&Pt(z,We.web)},De=e=>{(z==null?void 0:z.owner)===e&&Pt(z,We.closed)},nn=()=>{z&&Pt(z,We.user)},bo=e=>{z&&Pt(z,We.error,e)},on=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=z;if(!(!o||!Q.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Fe.once){en(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}Q.setState(d=>({last_value:c,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Et.result,{value:c,type:l})}}},Qr={1:te.code128,2:te.code39,4:te.code93,8:te.codabar,16:te.dataMatrix,32:te.ean13,64:te.ean8,128:te.itf,256:te.qr,512:te.upcA,1024:te.upcE,2048:te.pdf417,4096:te.aztec},Zr=2500,uo=2e3,Qt=e=>{Q.setState({notice:e}),setTimeout(()=>{Q.getState().notice===e&&Q.setState({notice:null})},Zr)},Ao=async()=>{var t,n;let e=z;if(!(!e||Q.getState().is_picking)){e.requesting_permission=!0,Q.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:uo,maxHeight:uo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||z!==e)return;if(r.errorCode||!i){Qt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(z!==e)return;let l=c.map(({value:s,format:d})=>({value:s,code_type:Qr[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!l.length){Qt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}on(l,Date.now(),!0)}catch{z===e&&Qt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await Mt(),e.requesting_permission=!1,z===e&&Q.setState({is_picking:!1})}}};var Tt=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},So=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},pt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,_o=(e,t)=>pt({id:e,result:t}),vo=(e,t)=>pt({id:e,error:{code:t.code,message:t.message}}),Mo=(e,t)=>pt({event:e,data:t}),sn=e=>pt({event:"context",data:e});var xo=()=>`(function () {
|
|
2
2
|
var post = function (level, args) {
|
|
3
3
|
try {
|
|
4
4
|
var parts = [];
|
|
@@ -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;`,Eo=()=>`(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; }
|
|
@@ -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;`,Co=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,Po=e=>pt({event:e}),Ro=(e,t)=>{let n=To(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${sn(e)}`},To=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Oo=(e,t={})=>{let n=To(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
|
|
64
64
|
window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
|
|
65
65
|
${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
|
|
66
|
-
true;`},
|
|
66
|
+
true;`},ko={partner:"partner_token",chatbox:"chatbox_token"},Io=(e,t)=>{let n={...e};for(let o of Object.values(ko))t.includes(o)||delete n[o];return n},rn=new Set,ct=async(e,t)=>{if(rn.has(e))throw new g("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);rn.add(e);try{return await t()}finally{rn.delete(e)}},an=e=>`(function () {
|
|
67
67
|
window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
|
|
68
68
|
window.dispatchEvent(new Event('retionscannerheight'));
|
|
69
|
-
})(); true;`,
|
|
69
|
+
})(); true;`,Lo=()=>`(function () {
|
|
70
70
|
try {
|
|
71
71
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
72
72
|
if (!AudioCtx) { return; }
|
|
@@ -85,4 +85,4 @@
|
|
|
85
85
|
// iOS c\xF3 th\u1EC3 \u0111\u1EC3 context \u1EDF suspended / interrupted (vd. khi camera m\u1EDF phi\xEAn quay): ch\u1EA1y l\u1EA1i xong m\u1EDBi ph\xE1t.
|
|
86
86
|
if (ctx.state === 'running') { play(); } else { ctx.resume().then(play).catch(function () {}); }
|
|
87
87
|
} catch (e) {}
|
|
88
|
-
})(); true;`,Wr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Pt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Ro=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:g,isActive:d,playBeep:y})=>{var E,M,N,W,ne,Pe,ae;let u=s==null?void 0:s.handlers,w={app_id:c,instance_id:l,close:a},L=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),y==null||y()},P=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Pn(t);return it(e,()=>Tn(p,d))}case"speech.start":{if(!g)throw P();let p={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new m("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");p.lang=t.lang}for(let q of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[q])!==void 0){if(typeof t[q]!="boolean")throw new m("INVALID_PARAMS",`${q} ph\u1EA3i l\xE0 boolean`);p[q]=t[q]}let x=s==null?void 0:s.speech;if(x){Yn(l,x);try{return await x.start({owner:l,app_id:c,options:p,emit:g,isActive:d!=null?d:(()=>!0)})}catch(q){throw Xn(l),q}}return Qn(l,p,g,d)}case"speech.stop":return s!=null&&s.speech?s.speech.stop(l):eo(l);case He.scan:return ao(l,Xt(t),d,L);case He.start:{if(!g)throw P();return co(l,Xt(t),g,d,L)}case He.stop:return lo(l);case"uploadFiles":{let{task_id:p,...x}=t!=null?t:{};if(p!==void 0&&(typeof p!="string"||!p))throw new m("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Hn(Nn(x),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:q=>it("uploadFiles.pick",q)})}case"uploadFiles.cancel":jn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Wn(s==null?void 0:s.upload);case"getBiometricAvailability":return((E=s==null?void 0:s.biometrics)!=null?E:await jt()).getAvailability();case"authenticateBiometric":{let p=Pt(t==null?void 0:t.reason,"reason").trim();if(!p||p.length>200)throw new m("INVALID_PARAMS","reason must contain 1\u2013200 characters");let x=t==null?void 0:t.cancelButtonText;if(x!==void 0&&(typeof x!="string"||!x.trim()||x.length>80))throw new m("INVALID_PARAMS","Invalid cancelButtonText");return it(e,async()=>{var T;return((T=s==null?void 0:s.biometrics)!=null?T:await jt()).authenticate({reason:p,cancelButtonText:x})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw P();let x=t==null?void 0:t.amount;if(typeof x!="number"||!Number.isFinite(x)||x<=0)throw new m("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let q={...t,amount:x,currency:Pt(t==null?void 0:t.currency,"currency")};return it(e,()=>p(q,w))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw P();let x=Pt(t==null?void 0:t.image,"image");await it(e,()=>p({image:x},w));return}case"openScreen":if(!(u!=null&&u.openScreen))throw P();await u.openScreen({screen:Pt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},w);return;case"closeApp":a();return;case"openWebview":{let p=String((M=t==null?void 0:t.url)!=null?M:"");if(!/^https?:\/\//i.test(p))throw new m("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(p):st.Linking.openURL(p));return}case"openLink":{let p=String((N=t==null?void 0:t.url)!=null?N:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(p)||/^(javascript|file|data|about|blob):/i.test(p))throw new m("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(p):st.Linking.openURL(p))}catch(x){throw new m("NOT_SUPPORTED",String((ne=(W=x==null?void 0:x.message)!=null?W:x)!=null?ne:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=Gn(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):Kn(p.message,p.type);return}case"haptic":{let p=Wr.has(t==null?void 0:t.type)?t.type:"selection";(Pe=s==null?void 0:s.haptic)==null||Pe.call(s,p);return}case"getSystemInfo":return{platform:st.Platform.OS==="ios"?"ios":"android",appVersion:(ae=s==null?void 0:s.app_version)!=null?ae:"",theme:i?"dark":"light"};case"getAccessToken":{let p=n().access_token;if(!p)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return p}case"getToken":{let p=t==null?void 0:t.type;if(p==="access"){let T=n().access_token;if(!T)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return T}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let x=Mo[p];if(!o().includes(x))throw new m("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${x} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let q=p==="partner"?n().partner_token:n().chatbox_token;if(!q)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${x}`);return q}case"getUserInfo":{let p=n().user;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return p}case"getPageInfo":{let p=n().page;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return p}case"sendMessage":case"insertText":throw new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new m("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var an=e=>`bundle:${e}`,cn=()=>`${$().file_system.document_dir}/miniapps`,ln=cn,pn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${ln()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},sn=e=>{var t;$().storage.setString(an(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},zr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,B=e=>{let t=$().storage.getString(an(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return pn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Ce=e=>$().file_system.exists(e.entry_uri.replace("file://","")),un=async e=>{let t=B(e.app_id);return(t==null?void 0:t.version)===e.version&&await Ce(t)},To=async(e,t)=>{let n=$().file_system,o=`${ln()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Co=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),$().storage.setString(an(e),""),await $().file_system.remove(`${ln()}/${e}`).catch(()=>{})},Je=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},Oo=(e,t)=>{var i;let o=((i=lt[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return lt[e]=r,r.then(()=>{lt[e]===r&&delete lt[e]}),o},jr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},ko=({manifest:e,zip_path:t})=>Oo(e.app_id,async()=>{var i;let n=$().file_system,o=B(e.app_id);if(o&&jr(o.version,e.version)>=0&&await Ce(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=pn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),sn(e),me("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),To(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),dn=(e,{base_url:t,onProgress:n}={})=>{let o=$().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Je},l=async()=>{var d;c();let s=B(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return sn(e),B(e.app_id);c();let g=o.download({url:t?zr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,u)=>{var L;let w=u>0?u:(L=e.size)!=null?L:0;w>0&&(n==null||n(Math.min(1,y/w)))}});r=g;try{let{status:y}=await g.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else me("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=pn(e.app_id,e.version,e.entry,!!e.context_update,(d=e.permissions)!=null?d:[]);return await o.remove(u.dir).catch(()=>{}),await o.mkdir(u.dir),await o.unzip(a,u.dir),sn(e),To(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(y){throw i?new Je:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Oo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},Hr=__DEV__?0:60*1e3,Po={},Io=(e,t)=>{var o,r;let n=B(e);return n&&Date.now()-((o=Po[t])!=null?o:0)<Hr?Promise.resolve(n):((r=ct[e])!=null||(ct[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await dn(a,{base_url:t}).promise;return Po[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),B(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Ct=new Map,Lo=(e,t)=>(Ct.set(e,t),()=>{Ct.get(e)===t&&Ct.delete(e)}),Fo=(e,t)=>{let n=Ct.get(e);return n?n(t):!1};var F=require("react"),f=require("react-native");var v=require("react/jsx-runtime"),pt="#22C55E",Jr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Gr=2,kt=18,Kr=1600,ut=14,Yr=2e3,Uo=.38,Xr=40,Do=2,Zr=8,Qr=2e3,ei=250,Ge=2e3,ti=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ut},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ut},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ut},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ut}],No=({color:e})=>(0,v.jsx)(v.Fragment,{children:ti.map((t,n)=>(0,v.jsx)(f.View,{style:[S.corner,t,{borderColor:e}]},n))}),Ot=({style:e,children:t,...n})=>{let o=(0,F.useRef)(new f.Animated.Value(1)).current,r=i=>f.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,v.jsx)(f.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,v.jsx)(f.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},mn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var h,b;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===pe.top,y=(0,F.useRef)(new f.Animated.Value(0)).current,u=r.useCameraDevice("back"),w=(0,F.useRef)(new f.Animated.Value(1)).current,[L,P]=(0,F.useState)(!1),[E,M]=(0,F.useState)(1),N=(0,F.useRef)(null),[W,ne]=(0,F.useState)(()=>{let{width:_,height:U}=f.Dimensions.get("window");return{width:_,height:d?U*Uo:U,window_y:0}}),Pe=j(X,_=>_.last_value),ae=j(X,_=>_.hit_tick),p=j(X,_=>_.scan_count),x=j(X,_=>_.notice),q=j(X,_=>_.is_picking),T=(0,F.useRef)(null),ce=Et(),_e=ce.top,K=(0,F.useRef)(new f.Animated.Value(0)).current,k=(0,F.useRef)(new f.Animated.Value(0)).current,oe=(0,F.useRef)(new f.Animated.Value(0)).current,J=(0,F.useRef)(n);J.current=n,(0,F.useEffect)(()=>{if(!t)return;y.setValue(W.height);let _=f.Animated.timing(y,{toValue:0,duration:ei,easing:f.Easing.out(f.Easing.cubic),useNativeDriver:!1});return _.start(({finished:U})=>{var ie;U&&((ie=J.current)==null||ie.call(J))}),()=>_.stop()},[t,y]);let Q=Math.round(W.width*(d?.8:.78)),re=Math.round(d?W.height*.46:Q*.78),ve=Math.round((W.height-re)/2),Me=Math.round((W.width-Q)/2),je=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,F.useCallback)(_=>tn(_),[])});(0,F.useEffect)(()=>{let _=f.BackHandler.addEventListener("hardwareBackPress",()=>(en(),!0));return()=>_.remove()},[]);let xe=(0,F.useRef)(ae);(0,F.useEffect)(()=>{if(ae===xe.current)return;K.setValue(1),oe.setValue(1);let _=f.Animated.parallel([f.Animated.timing(K,{toValue:0,duration:450,useNativeDriver:!0}),f.Animated.sequence([f.Animated.delay(Yr),f.Animated.timing(oe,{toValue:0,duration:250,useNativeDriver:!0})])]);return _.start(),()=>_.stop()},[ae,K,oe]),(0,F.useEffect)(()=>{let _=ie=>f.Animated.timing(k,{toValue:ie,duration:Kr,easing:f.Easing.inOut(f.Easing.quad),useNativeDriver:!0}),U=f.Animated.loop(f.Animated.sequence([_(1),_(0)]));return U.start(),()=>U.stop()},[k]);let Te=(0,F.useCallback)(()=>{f.Animated.timing(w,{toValue:0,duration:220,useNativeDriver:!0}).start()},[w]);(0,F.useEffect)(()=>{let _=setTimeout(Te,Qr);return()=>clearTimeout(_)},[Te]);let[Xe,qt]=(0,F.useState)(!1);(0,F.useEffect)(()=>{let _=requestAnimationFrame(()=>{_=requestAnimationFrame(()=>qt(!0))});return()=>cancelAnimationFrame(_)},[]);let Ve=!!(u!=null&&u.hasTorch),Ze=(h=u==null?void 0:u.neutralZoom)!=null?h:1,Qe=u?Math.min(u.maxZoom/Ze,Zr):1,$t=Ze*Math.min(E,Qe),mt=_=>{var se;let{touches:U}=_.nativeEvent;if(U.length!==2){N.current=null;return}let ie=Math.hypot(U[0].pageX-U[1].pageX,U[0].pageY-U[1].pageY);(se=N.current)!=null||(N.current={distance:ie,level:E}),M(Math.max(1,Math.min(Qe,N.current.level*(ie/N.current.distance))))},ht=(0,v.jsx)(f.Text,{style:[S.hint,!!x&&S.hint_notice],numberOfLines:1,children:(b=x!=null?x:l)!=null?b:Jr});return(0,v.jsx)(f.Animated.View,{ref:T,onTouchMove:mt,onTouchEnd:()=>{N.current=null},pointerEvents:t?"none":"auto",style:d?[S.top,g&&S.top_absolute,t&&{height:y}]:S.full,onLayout:({nativeEvent:{layout:_}})=>{var U;t||(o==null||o(_.height),(U=T.current)==null||U.measureInWindow((ie,se)=>{ne({width:_.width,height:_.height,window_y:se||0})}))},children:(0,v.jsxs)(f.View,{style:t?[S.content_closing,{height:W.height}]:S.content,children:[u&&Xe&&(0,v.jsx)(r.Camera,{style:f.StyleSheet.absoluteFill,device:u,isActive:!q,codeScanner:je,torch:L&&Ve?"on":"off",zoom:$t,onPreviewStarted:Te,onError:_=>po(_.message)}),(0,v.jsx)(f.Animated.View,{style:[S.preview_cover,{opacity:w}],pointerEvents:"none"}),W.height>0&&(0,v.jsxs)(f.View,{style:S.overlay,pointerEvents:"none",children:[(0,v.jsx)(f.View,{style:[S.dim_ring,{top:ve-Ge,left:Me-Ge,width:Q+Ge*2,height:re+Ge*2}]}),(0,v.jsxs)(f.View,{style:{position:"absolute",top:ve,left:Me,width:Q,height:re},children:[(0,v.jsx)(No,{color:"#FFFFFF"}),(0,v.jsx)(f.Animated.View,{style:[f.StyleSheet.absoluteFill,{opacity:K}],children:(0,v.jsx)(No,{color:pt})}),(0,v.jsxs)(f.Animated.View,{style:[S.scan_line_wrap,{transform:[{translateY:k.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,re-kt)]})}]}],children:[(0,v.jsx)(f.View,{style:S.scan_glow_outer}),(0,v.jsx)(f.View,{style:S.scan_glow_inner}),(0,v.jsx)(f.View,{style:S.scan_line})]})]}),(0,v.jsx)(f.View,{style:[S.hint_slot,d?{top:0,height:ve-6,justifyContent:"flex-end"}:{top:ve+re+20}],children:ht}),a===Le.continuous&&!!Pe&&(0,v.jsx)(f.Animated.View,{style:[S.result_slot,{top:d?ve+re-Xr:ve+re+52},{opacity:oe}],children:(0,v.jsxs)(f.View,{style:S.result,children:[(0,v.jsx)(f.View,{style:S.check_badge,children:(0,v.jsx)(f.View,{style:S.check_mark})}),(0,v.jsx)(f.Text,{style:S.result_text,numberOfLines:1,children:Pe}),(0,v.jsxs)(f.Text,{style:S.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),W.height>0&&(0,v.jsx)(f.View,{style:[S.close_slot,d?S.close_slot_top:{top:Math.max(12,_e-W.window_y+12)}],children:(0,v.jsxs)(Ot,{style:[S.close_button,!!s&&S.glass_surface],onPress:en,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(f.View,{style:[S.close_bar,S.close_bar_a]}),(0,v.jsx)(f.View,{style:[S.close_bar,S.close_bar_b]})]})}),(0,v.jsx)(f.View,{style:[S.toolbar_wrap,!d&&{bottom:ce.bottom+20}],pointerEvents:"box-none",children:(0,v.jsxs)(f.View,{style:[S.toolbar,!!s&&S.glass_surface],children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(Ot,{style:S.tool,onPress:uo,disabled:q,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,v.jsxs)(f.View,{style:S.image_icon,children:[(0,v.jsx)(f.View,{style:S.image_icon_dot}),(0,v.jsx)(f.View,{style:S.image_icon_hill})]})}),!!u&&Qe>=Do&&(0,v.jsx)(Ot,{style:[S.tool,E>1&&S.tool_on],onPress:()=>M(_=>_>1?1:Do),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,v.jsxs)(f.Text,{style:[S.zoom_text,E>1&&S.zoom_text_on],children:[Math.round(E*10)/10,"x"]})}),Ve&&(0,v.jsx)(Ot,{style:[S.tool,L&&S.tool_on],onPress:()=>P(_=>!_),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:L},children:(0,v.jsx)(f.Text,{style:[S.torch_icon,L&&S.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},ni="rgba(0,0,0,0.5)",gn=50,S=f.StyleSheet.create({top:{height:`${Uo*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},top_absolute:{position:"absolute",top:0,left:0,right:0,zIndex:1},content_closing:{position:"absolute",left:0,right:0,bottom:0,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:Ge,borderColor:ni,borderRadius:Ge+ut},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:kt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:kt,borderRadius:kt/2,backgroundColor:pt,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:pt,opacity:.2},scan_line:{height:Gr,borderRadius:1,backgroundColor:pt},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:gn,height:gn,borderRadius:gn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:pt},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var we=require("react"),R=require("react-native");var H=require("react/jsx-runtime"),hn={[he.info]:"#3B82F6",[he.success]:"#22C55E",[he.error]:"#EF4444"},Vo=-120,It=R.Platform.OS==="android",Bo=({type:e})=>e===he.success?(0,H.jsx)(R.View,{style:te.check_mark}):e===he.error?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(R.View,{style:[te.cross_bar,te.cross_a]}),(0,H.jsx)(R.View,{style:[te.cross_bar,te.cross_b]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(R.View,{style:te.info_dot}),(0,H.jsx)(R.View,{style:te.info_bar})]}),qo=()=>{let e=j(rt,y=>y.message),t=j(rt,y=>y.type),n=j(rt,y=>y.tick),o=(0,we.useRef)(new R.Animated.Value(Vo)).current,r=(0,we.useRef)(new R.Animated.Value(0)).current,i=(0,we.useRef)(new R.Animated.Value(.92)).current,a=(0,we.useRef)(new R.Animated.Value(0)).current,[c,l]=(0,we.useState)(),[s,g]=(0,we.useState)(!1);(0,we.useEffect)(()=>{let y=!0;return Qt().then(u=>{y&&u&&l(()=>u)}),()=>{y=!1}},[]);let d=(0,we.useRef)(n);return(0,we.useEffect)(()=>{if(n===d.current)return;R.AccessibilityInfo.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let y=R.Animated.sequence([R.Animated.parallel([R.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),R.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),R.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),R.Animated.sequence([R.Animated.delay(90),R.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),R.Animated.delay(Jn[t]),R.Animated.parallel([R.Animated.timing(o,{toValue:Vo,duration:240,useNativeDriver:!0}),R.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:u})=>{u&&g(!1)}),()=>y.stop()},[n]),s?(0,H.jsx)(R.View,{style:[te.layer,{top:Et().top+(It?12:8)}],pointerEvents:"none",children:(0,H.jsxs)(R.Animated.View,{style:[te.toast,It&&te.toast_android,!!c&&te.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,H.jsx)(c,{style:te.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),It?(0,H.jsx)(R.Animated.View,{style:[te.badge_halo,{backgroundColor:`${hn[t]}33`,transform:[{scale:a}]}],children:(0,H.jsx)(R.View,{style:[te.badge,{backgroundColor:hn[t]}],children:(0,H.jsx)(Bo,{type:t})})}):(0,H.jsx)(R.Animated.View,{style:[te.badge,{backgroundColor:hn[t],transform:[{scale:a}]}],children:(0,H.jsx)(Bo,{type:t})}),(0,H.jsx)(R.Text,{style:[te.message,It&&te.message_android],numberOfLines:2,children:e})]})}):null},te=R.StyleSheet.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:R.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ue=Ie({active_key:null,instances:{}}),$o=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=$().keep_alive)==null?void 0:c.max_webviews;ue.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(y=>y!==s).sort((y,u)=>g[y].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(y=>{delete g[y]}),i?{active_key:s,instances:g}:{instances:g}})},Wo=e=>$o(e,!0),zo=e=>$o(e,!1),Ke=()=>ue.setState({active_key:null}),Lt=e=>{ue.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var jo="catalog",oi="paused_apps",ri="removed_apps",ii=10*1e3,si=2,ai=3e3,ci=()=>{var e;try{return JSON.parse((e=$().storage.getString(jo))!=null?e:"{}")}catch{return{}}},D=Ie({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Ho=e=>{var t;return!!((t=$().manual_update)!=null&&t.includes(e))},Nt=new Set,Jo=e=>{let t=new Set,n=()=>$().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=$().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},Se=Jo(oi),Ue=Jo(ri);xn(()=>{Se.load(),Ue.load();let e=ci(),t={};Object.keys(e).filter(n=>!Ue.has(n)).forEach(n=>{let o=B(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:Se.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),D.setState({catalog:e,downloads:t})});var Ut=e=>j(D,t=>e?t.downloads[e]:void 0),Go=()=>j(D,e=>e.pause_reasons.length>0),Ae=(...e)=>me("queue",...e),Z=[],Oe={},C=null,Ft=new Set,ze={},fn=new Set,De=e=>{fn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Ko=e=>(fn.add(e),()=>{fn.delete(e)}),Yo=()=>D.getState().downloads,de=(e,t)=>{let n=!!B(e),o=D.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};D.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?De({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&De({type:"progress",app_id:e,progress:i.progress,version:i.version})},Dt=(e,t)=>{var n;(n=ze[e])==null||n.forEach(o=>o(t)),delete ze[e]},li=()=>D.getState().pause_reasons.length>0,Ne=e=>{var c;if(C)return;let t=e?Z.indexOf(e):li()?-1:Z.findIndex(l=>!Se.has(l));if(t<0||t>=Z.length)return;let[n]=Z.splice(t,1),o=D.getState().catalog[n];if(!o){Dt(n,B(n)),Ne();return}let r=Date.now();Oe[n]=((c=Oe[n])!=null?c:0)+1,de(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=dn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,de(n,{progress:s/100,version:o.version}))}});C={app_id:n,handle:a,forced:!!e},Ae("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Ae("installed",n,o.version,`${Date.now()-r}ms`),de(n,{status:"installed",progress:1,version:o.version}),Dt(n,l)}).catch(l=>{var g;if(l instanceof Je){if(Ft.has(n))return;Ae("paused",n),Oe[n]-=1,Z.unshift(n),de(n,{status:Se.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((g=l==null?void 0:l.message)!=null?g:l);if(console.warn("[miniapp-queue] failed",n,s),Oe[n]<si){de(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;Z.includes(n)||(C==null?void 0:C.app_id)===n||(Z.push(n),Ne((d=ze[n])!=null&&d.length?n:void 0))},ai);return}de(n,{status:"failed",progress:0,version:o.version,error:s}),Dt(n,B(n))}).finally(()=>{C=null;let l=Z.find(s=>{var g;return(g=ze[s])==null?void 0:g.length});Ne(l)})},Vt=(e,{front:t=!1}={})=>{if((C==null?void 0:C.app_id)===e)return;let n=Z.indexOf(e);if(n>=0){if(!t)return;Z.splice(n,1)}t?Z.unshift(e):Z.push(e)},pi=async e=>{let{host_id:t,client_token:n}=$(),o=new AbortController,r=setTimeout(()=>o.abort(),ii);try{let i=`${yt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},dt=null,Bt=()=>(dt!=null||(dt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all($().channels.map(pi)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(D.getState().catalog).filter(l=>!o[l]);$().storage.setString(jo,JSON.stringify(o)),D.setState({catalog:o}),await Promise.all(r.map(l=>Xo(l,{by_user:!1}))),r.forEach(l=>Ue.delete(l));let i=Object.keys(o).filter(l=>!Ue.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await un(l)){de(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=B(l.app_id);if(Ho(l.app_id)&&!Nt.has(l.app_id)&&s&&await Ce(s)){de(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return D.setState({updates:c}),a.forEach(l=>{Oe[l.app_id]=0,de(l.app_id,{status:Se.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Vt(l.app_id)}),Ae("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),De({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>De({type:"update_available",...l})),Ne(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),De({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{dt=null}})()),dt),Xo=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ue.add(e),Ft.has(e))return;Ft.add(e),Se.delete(e);let n=Z.indexOf(e);n>=0&&Z.splice(n,1),(C==null?void 0:C.app_id)===e&&C.handle.cancel();let o=(c=(a=(r=D.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=B(e))==null?void 0:i.version)!=null?c:"";de(e,{status:"uninstalling",progress:0,version:o}),await Co(e),Lt(e),D.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Oe[e],Ft.delete(e),Dt(e,null),Ae("uninstalled",e,t?"(user)":"(not in list)"),De({type:"uninstalled",app_id:e})},Zo=e=>Xo(e,{by_user:!0}),Qo=e=>{let t=Ye(e);return t?(Ue.delete(e),(C==null?void 0:C.app_id)===e||Z.includes(e)||(Oe[e]=0,de(e,{status:Se.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Vt(e),Ne(),Ae("restore",e)),!0):!1},er=e=>{if(Se.has(e))return;if(Se.add(e),Ae("pause app",e),(C==null?void 0:C.app_id)===e&&!C.forced){C.handle.cancel();return}let t=D.getState().downloads[e];Z.includes(e)&&t&&de(e,{status:"paused",progress:0,version:t.version})},tr=e=>{if(!Se.delete(e))return;Ae("resume app",e);let t=D.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!Z.includes(e)&&Ye(e)&&(Oe[e]=0,Vt(e)),Z.includes(e)&&t&&de(e,{status:"queued",progress:0,version:t.version}),Ne()},nr=e=>{let{pause_reasons:t}=D.getState();t.includes(e)||(D.setState({pause_reasons:[...t,e]}),Ae("pause",e),t.length===0&&De({type:"pause_change",paused:!0,reasons:[e]}),C&&!C.forced&&C.handle.cancel())},or=e=>{let{pause_reasons:t}=D.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);D.setState({pause_reasons:n}),Ae("resume",e),n.length===0&&De({type:"pause_change",paused:!1,reasons:n}),Ne()},yn=e=>D.getState().updates[e],rr=async e=>{var n,o;let t=yn(e);Nt.add(e);try{let r=await gt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ye(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(D.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),Ae("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Nt.delete(e)}},ir=()=>Object.values(D.getState().catalog).map(e=>({...e,installed:!!B(e.app_id),removed_by_user:Ue.has(e.app_id)})),Ye=e=>D.getState().catalog[e],gt=async e=>{let t=Ye(e);if(!t)return;if(Se.delete(e),Ue.delete(e),await un(t))return B(e);let n=B(e);if(Ho(e)&&!Nt.has(e)&&n&&await Ce(n))return n;let o=new Promise(r=>{var i;((i=ze[e])!=null?i:ze[e]=[]).push(r)});return(C==null?void 0:C.app_id)===e?C.forced=!0:(Oe[e]=0,Vt(e,{front:!0}),C&&!C.forced?C.handle.cancel():Ne(e)),o};var I=require("react/jsx-runtime"),wn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),sr=0,ui=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},di=A.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var mt,ht;let d=(0,A.useRef)(null),y=(0,A.useRef)(!1),u=j(ue,h=>h.instances[e]),w=u==null?void 0:u.app.app_id,L=u==null?void 0:u.app.manifest_url,P=u==null?void 0:u.context,E=u==null?void 0:u.url_params,M=j(X,h=>{var b;return((b=h.active)==null?void 0:b.owner)===e?h.active:null}),[N,W]=(0,A.useState)(null),[ne,Pe]=(0,A.useState)(M);M!==ne&&(Pe(M),M?W(null):(ne==null?void 0:ne.layout)===pe.top&&W(ne));let ae=(M==null?void 0:M.layout)===pe.top?M:N,[p,x]=(0,A.useState)(()=>w?B(w):null),[q,T]=(0,A.useState)(!1),[ce,_e]=(0,A.useState)(0),[K,k]=(0,A.useState)(0),[oe,J]=(0,A.useState)(!1),Q=(0,A.useRef)(null),re=h=>{Q.current&&clearTimeout(Q.current),Q.current=setTimeout(()=>{Q.current=null,J(!0)},h)};(0,A.useEffect)(()=>()=>{Q.current&&clearTimeout(Q.current)},[]),(0,A.useEffect)(()=>{if(!w||!t&&p)return;let h=!0;return T(!1),(async()=>{let b=B(w),_=b?await Ce(b):!1;if(!h||(x(_?se=>!se||se.version!==b.version||se.permissions.join(",")!==b.permissions.join(",")?b:se:null),__DEV__&&Date.now()-sr>1e4&&(sr=Date.now(),await Bt()),!h))return;let U=await gt(w),ie=U!==void 0?U:L?await Io(w,L):B(w);if(h){if(!ie){T(!0);return}x(se=>se!=null?se:ie)}})(),()=>{h=!1}},[t,w,L,ce]),(0,A.useEffect)(()=>Lo(e,h=>d.current?(d.current.postMessage(h),!0):!1),[e]);let ve=j(D,h=>{let b=w?h.downloads[w]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});(0,A.useEffect)(()=>{if(t||!w||!p)return;let h=B(w);if(!h||h.version===p.version)return;let b=!0;return Ce(h).then(_=>{!b||!_||(me(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",h.version),x(h))}),()=>{b=!1}},[t,w,ve,p==null?void 0:p.version]);let Me=j(D,h=>{var b;return w&&(b=h.apply_ticks[w])!=null?b:0});(0,A.useEffect)(()=>{if(!Me||!w)return;let h=B(w);if(!h||h.version===(p==null?void 0:p.version))return;let b=!0;return Ce(h).then(_=>{!b||!_||(me(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",h.version),J(!1),x(h))}),()=>{b=!1}},[Me]),(0,A.useEffect)(()=>{var _;let h=(_=$().keep_alive)==null?void 0:_.idle_close_ms;if(t||!h||h<=0)return;let b=setTimeout(()=>{Lt(e)},h);return()=>clearTimeout(b)},[t,e]),(0,A.useEffect)(()=>{r>0&&(T(!1),J(!1),k(h=>h+1),_e(h=>h+1))},[r]);let je=(0,A.useRef)(t);(0,A.useEffect)(()=>{var h;je.current!==t&&(je.current=t,y.current&&((h=d.current)==null||h.injectJavaScript(_o(t?"resumed":"paused"))))},[t]);let xe=`${(mt=p==null?void 0:p.version)!=null?mt:"none"}:${(ht=p==null?void 0:p.permissions.join(","))!=null?ht:""}:${K}`,Te=(0,A.useMemo)(()=>JSON.stringify([P!=null?P:{},E!=null?E:{}]),[P,E]),Xe=(0,A.useMemo)(()=>{var h;return xo(E!=null?E:{},(h=p==null?void 0:p.permissions)!=null?h:[])},[Te,p==null?void 0:p.permissions]),qt=(0,A.useMemo)(()=>vo(P!=null?P:{},Xe)+wo()+bo()+($().debug?yo():""),[Xe]),Ve=(0,A.useRef)(null),Ze=(0,A.useRef)(null);(0,A.useEffect)(()=>{var b,_,U;if(!p)return;if(Ze.current!==xe){Ze.current=xe,Ve.current=Te;return}if(Ve.current===Te)return;let h=((_=JSON.parse((b=Ve.current)!=null?b:"[]")[0])!=null?_:{}).org_id;if(Ve.current=Te,h===(P==null?void 0:P.org_id)&&y.current){J(!1),re(1500),(U=d.current)==null||U.injectJavaScript(Ao(P!=null?P:{},Xe));return}J(!1),k(ie=>ie+1)},[Te,p,xe]),(0,A.useEffect)(()=>(t||(Re(e),Fe(e),qe(e)),()=>{Re(e),Fe(e),qe(e)}),[t,e,xe,r]),(0,A.useEffect)(()=>{let h=O.AppState.addEventListener("change",b=>{b==="background"&&!Zn()&&Re(e),b==="background"&&!ro()&&Fe(e)});return()=>h.remove()},[e]);let Qe=(0,A.useCallback)(async h=>{var _,U,ie,se,Wt,_n;let b=go(h.nativeEvent.data);if(!b){if(w&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(h.nativeEvent.data,{app_id:w,instance_id:e})).catch(z=>{console.warn("[miniapp] onWebEvent l\u1ED7i",w,z)})}catch(z){console.warn("[miniapp] onWebEvent l\u1ED7i",w,z)}return}if(b.method==="log"){let{level:z,text:G}=b;me(`web:${e}`,z!=null?z:"log",G!=null?G:"");return}if(b.method==="pong"){Q.current||J(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){Q.current&&clearTimeout(Q.current),Q.current=null,J(!0);return}if(b.method==="ready"){y.current=!0,J(!0);let z=(_=ue.getState().instances[e])==null?void 0:_.context;z&&((U=d.current)==null||U.injectJavaScript(on(z)));return}try{let z=await Ro(b,{getHostData:()=>{var G,ge;return(ge=(G=ue.getState().instances[e])==null?void 0:G.host_data)!=null?ge:{}},getPermissions:()=>{var G,ge;return w?(ge=(G=B(w))==null?void 0:G.permissions)!=null?ge:[]:[]},getContext:()=>{var G,ge;return(ge=(G=ue.getState().instances[e])==null?void 0:G.context)!=null?ge:{}},is_dark:o,close:Ke,app_id:w!=null?w:"",instance_id:e,options:c,emit:(G,ge)=>{var An;(An=d.current)==null||An.injectJavaScript(fo(G,ge))},playBeep:(ie=c==null?void 0:c.playScannerBeep)!=null?ie:(()=>{var G;(G=d.current)==null||G.injectJavaScript(Eo())}),isActive:()=>ue.getState().active_key===e&&O.AppState.currentState!=="background"});b.id&&((se=d.current)==null||se.injectJavaScript(mo(b.id,z)))}catch(z){if(!b.id)return;let G=z==null?void 0:z.code,ge=z instanceof m?z:new m(typeof G=="string"?G:"HOST_ERROR",String((Wt=z==null?void 0:z.message)!=null?Wt:z));(_n=d.current)==null||_n.injectJavaScript(ho(b.id,ge))}},[e,o,w,i,c]),$t=(0,A.useCallback)(()=>{T(!1),k(h=>h+1),_e(h=>h+1)},[]);return(0,I.jsxs)(O.View,{style:[O.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&be.behind],pointerEvents:t?"auto":"none",children:[ae&&(0,I.jsx)(mn,{scanner:ae,closing:ae===N,onClosed:()=>{var h;W(null),ae.absolute&&((h=d.current)==null||h.injectJavaScript(rn(0)))},onHeight:ae.absolute?h=>{var b;return(b=d.current)==null?void 0:b.injectJavaScript(rn(h))}:void 0}),p?(0,I.jsx)(cr.default,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?cn():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:qt,onMessage:Qe,onShouldStartLoadWithRequest:h=>{let b=h.url;return h.isTopFrame===!1||!/^https?:\/\//i.test(b)?!0:(Promise.resolve(c!=null&&c.openUrl?c.openUrl(b):O.Linking.openURL(b)).catch(()=>{}),!1)},setSupportMultipleWindows:!1,bounces:!1,overScrollMode:"never",onLoadStart:h=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load start",wn(h.nativeEvent.url)),y.current=!1,J(!1)},onError:h=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load error",wn(h.nativeEvent.url),h.nativeEvent.description),T(!0),J(!1)},onLoadEnd:h=>{let b=h.nativeEvent.url;me(`webview:${e}`,"load end",wn(b)),w&&(g==null||g({app_id:w,instance_id:e,url:b})),re(1500)},onContentProcessDidTerminate:()=>{Re(e),Fe(e),qe(e),y.current=!1,J(!1),k(h=>h+1)},onRenderProcessGone:()=>(Re(e),Fe(e),qe(e),y.current=!1,J(!1),k(h=>h+1),!0),style:be.webview},xe):null,(M==null?void 0:M.layout)===pe.full&&(0,I.jsx)(mn,{scanner:M}),u&&(0,I.jsx)(mi,{visible:!p||!oe,interactive:q,children:(0,I.jsx)(gi,{splash:a,app:u.app,is_dark:o,error:q,has_bundle:!!p,retry:$t})})]})}),gi=A.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Ut(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,I.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),mi=({visible:e,interactive:t,children:n})=>{let o=(0,A.useRef)(new 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:c})=>{c&&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},bn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,I.jsxs)(O.View,{style:[be.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,I.jsx)(O.View,{style:[be.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,I.jsx)(O.Image,{source:{uri:e.icon},style:be.splash_icon_image}):(0,I.jsx)(O.Text,{style:be.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,I.jsx)(O.Text,{style:[be.splash_name,{color:i}],children:e.name}),n==="error"?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(O.Text,{style:be.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,I.jsx)(O.TouchableOpacity,{activeOpacity:.7,style:[be.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,I.jsx)(O.Text,{style:[be.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(O.ActivityIndicator,{style:be.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,I.jsxs)(O.Text,{style:be.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},ar=(e,t)=>{let n=(0,A.useRef)(t),o=(0,A.useRef)(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},hi=({container:e,splash:t=bn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{ar("container",e),ar("splash",t);let l=e,s=j(ue,M=>M.active_key),g=(0,A.useRef)(s);s&&(g.current=s);let d=j(ue,M=>Object.keys(M.instances).join("|")),y=j(ue,M=>{var N;return M.active_key?(N=M.instances[M.active_key])==null?void 0:N.app.name:void 0}),u=(0,A.useMemo)(()=>d?d.split("|"):[],[d]),[w,L]=(0,A.useState)({}),P=(0,A.useRef)(ui()).current;(0,A.useEffect)(()=>{if(!s||!r)return;let M=O.BackHandler.addEventListener("hardwareBackPress",()=>(Ke(),!0));return()=>M.remove()},[s,r]);let E=(0,A.useCallback)(()=>{let M=ue.getState().active_key;M&&L(N=>({...N,[M]:(N[M]||0)+1}))},[]);return u.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:Ke,reload:E,subscribeWebAtTop:P.subscribe,children:u.map(M=>(0,I.jsx)(di,{instance_key:M,is_active:s===M,is_front:(s!=null?s:g.current)===M,is_dark:n,reload_tick:w[M]||0,web_at_top:P,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},M))}),(0,I.jsx)(qo,{})]}):null},be=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"}}),lr=A.default.memo(hi);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppStatuses,getMiniAppUpdate,installBundledMiniApp,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppDownload,useMiniAppDownloadsPaused});
|
|
88
|
+
})(); true;`,ei=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Rt=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Fo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:d,isActive:u,playBeep:y})=>{var C,M,q,W,oe,Pe,ce,E;let p=s==null?void 0:s.handlers,f={app_id:c,instance_id:l,close:a},O=()=>{var m;(m=s==null?void 0:s.haptic)==null||m.call(s,"impactLight"),y==null||y()},R=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let m=Ln(t);return ct(e,()=>Fn(m,u))}case"speech.start":{if(!d)throw R();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 g("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 g("INVALID_PARAMS",`${V} ph\u1EA3i l\xE0 boolean`);m[V]=t[V]}if((t==null?void 0:t.mode)!==void 0&&t.mode!=="s2t"&&t.mode!=="voice")throw new g("INVALID_PARAMS","mode ph\u1EA3i l\xE0 's2t' ho\u1EB7c 'voice'");let T=(t==null?void 0:t.mode)==="s2t"?"s2t":"voice",x=T==="voice"?(C=s==null?void 0:s.voice)!=null?C:s==null?void 0:s.speech:void 0;if(ro(l,x),x){no(l,x);try{return await x.start({owner:l,app_id:c,mode:T,options:m,emit:d,isActive:u!=null?u:(()=>!0)})}catch(V){throw oo(l,x),V}}return ao(l,m,d,u)}case"speech.stop":{let m=io(l);return m?m.stop(l):co(l)}case Ke.scan:return fo(l,Zt(t),u,O);case Ke.start:{if(!d)throw R();return yo(l,Zt(t),d,u,O)}case Ke.stop:return wo(l);case"uploadFiles":{let{task_id:m,...T}=t!=null?t:{};if(m!==void 0&&(typeof m!="string"||!m))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Qn(zn(T),{instance_id:l,app_id:c,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:d,exclusivePick:x=>ct("uploadFiles.pick",x)})}case"uploadFiles.cancel":Xn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Kn(s==null?void 0:s.upload);case"getBiometricAvailability":return((M=s==null?void 0:s.biometrics)!=null?M:await Ht()).getAvailability();case"authenticateBiometric":{let m=Rt(t==null?void 0:t.reason,"reason").trim();if(!m||m.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let T=t==null?void 0:t.cancelButtonText;if(T!==void 0&&(typeof T!="string"||!T.trim()||T.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return ct(e,async()=>{var V;return((V=s==null?void 0:s.biometrics)!=null?V:await Ht()).authenticate({reason:m,cancelButtonText:T})})}case"requestPayment":{let m=p==null?void 0:p.requestPayment;if(!m)throw R();let T=t==null?void 0:t.amount;if(typeof T!="number"||!Number.isFinite(T)||T<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let x={...t,amount:T,currency:Rt(t==null?void 0:t.currency,"currency")};return ct(e,()=>m(x,f))}case"printImage":{let m=p==null?void 0:p.printImage;if(!m)throw R();let T=Rt(t==null?void 0:t.image,"image");await ct(e,()=>m({image:T},f));return}case"openScreen":if(!(p!=null&&p.openScreen))throw R();await p.openScreen({screen:Rt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},f);return;case"closeApp":a();return;case"openWebview":{let m=String((q=t==null?void 0:t.url)!=null?q:"");if(!/^https?:\/\//i.test(m))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(m):lt.Linking.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 g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(m):lt.Linking.openURL(m))}catch(T){throw new g("NOT_SUPPORTED",String((Pe=(oe=T==null?void 0:T.message)!=null?oe:T)!=null?Pe:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let m=eo(t);if(!m||(u==null?void 0:u())===!1)return;s!=null&&s.showToast?s.showToast(m.message,{type:m.type}):to(m.message,m.type);return}case"haptic":{let m=ei.has(t==null?void 0:t.type)?t.type:"selection";(ce=s==null?void 0:s.haptic)==null||ce.call(s,m);return}case"getSystemInfo":return{platform:lt.Platform.OS==="ios"?"ios":"android",appVersion:(E=s==null?void 0:s.app_version)!=null?E:"",theme:i?"dark":"light"};case"getAccessToken":{let m=n().access_token;if(!m)throw new g("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 V=n().access_token;if(!V)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return V}if(m!=="partner"&&m!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let T=ko[m];if(!o().includes(T))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${T} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let x=m==="partner"?n().partner_token:n().chatbox_token;if(!x)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${T}`);return x}case"getUserInfo":{let m=n().user;if(!m)throw new g("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 g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return m}case"sendMessage":case"insertText":throw new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new g("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var ln=e=>`bundle:${e}`,pn=()=>`${D().file_system.document_dir}/miniapps`,un=pn,dn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${un()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},cn=e=>{var t;D().storage.setString(ln(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},ti=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,N=e=>{let t=D().storage.getString(ln(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return dn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Te=e=>D().file_system.exists(e.entry_uri.replace("file://","")),gn=async e=>{let t=N(e.app_id);return(t==null?void 0:t.version)===e.version&&await Te(t)},No=async(e,t)=>{let n=D().file_system,o=`${un()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Uo=async e=>{var t;await((t=dt[e])==null?void 0:t.catch(()=>{})),D().storage.setString(ln(e),""),await D().file_system.remove(`${un()}/${e}`).catch(()=>{})},Ye=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},dt={},Vo=(e,t)=>{var i;let o=((i=dt[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return dt[e]=r,r.then(()=>{dt[e]===r&&delete dt[e]}),o},hn=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},Bo=({manifest:e,zip_path:t})=>Vo(e.app_id,async()=>{var i;let n=D().file_system,o=N(e.app_id);if(o&&hn(o.version,e.version)>=0&&await Te(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=dn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),cn(e),he("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),No(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),mn=(e,{base_url:t,onProgress:n}={})=>{let o=D().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Ye},l=async()=>{var u;c();let s=N(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return cn(e),N(e.app_id);c();let d=o.download({url:t?ti(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,p)=>{var O;let f=p>0?p:(O=e.size)!=null?O:0;f>0&&(n==null||n(Math.min(1,y/f)))}});r=d;try{let{status:y}=await d.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else he("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let p=dn(e.app_id,e.version,e.entry,!!e.context_update,(u=e.permissions)!=null?u:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),cn(e),No(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(y){throw i?new Ye:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Vo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ut={},ni=__DEV__?0:60*1e3,Do={},qo=(e,t)=>{var o,r;let n=N(e);return n&&Date.now()-((o=Do[t])!=null?o:0)<ni?Promise.resolve(n):((r=ut[e])!=null||(ut[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await mn(a,{base_url:t}).promise;return Do[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),N(e))).finally(()=>{ut[e]=void 0})),ut[e])};var Ot=new Map,$o=(e,t)=>(Ot.set(e,t),()=>{Ot.get(e)===t&&Ot.delete(e)}),zo=(e,t)=>{let n=Ot.get(e);return n?n(t):!1};var B=require("react"),w=require("react-native");var v=require("react/jsx-runtime"),gt="#22C55E",oi="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",ri=2,It=18,ii=1600,ht=14,si=2e3,Ho=.38,ai=40,Wo=2,ci=8,li=2e3,pi=250,Xe=2e3,ui=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ht},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ht},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ht},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ht}],jo=({color:e})=>(0,v.jsx)(v.Fragment,{children:ui.map((t,n)=>(0,v.jsx)(w.View,{style:[_.corner,t,{borderColor:e}]},n))}),kt=({style:e,children:t,...n})=>{let o=(0,B.useRef)(new w.Animated.Value(1)).current,r=i=>w.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,v.jsx)(w.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,v.jsx)(w.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},yn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var h,b;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:d}=e,u=c===pe.top,y=(0,B.useRef)(new w.Animated.Value(0)).current,p=r.useCameraDevice("back"),f=(0,B.useRef)(new w.Animated.Value(1)).current,[O,R]=(0,B.useState)(!1),[C,M]=(0,B.useState)(1),q=(0,B.useRef)(null),[W,oe]=(0,B.useState)(()=>{let{width:A,height:$}=w.Dimensions.get("window");return{width:A,height:u?$*Ho:$,window_y:0}}),Pe=H(Q,A=>A.last_value),ce=H(Q,A=>A.hit_tick),E=H(Q,A=>A.scan_count),m=H(Q,A=>A.notice),T=H(Q,A=>A.is_picking),x=(0,B.useRef)(null),V=Ct(),Ae=V.top,Y=(0,B.useRef)(new w.Animated.Value(0)).current,L=(0,B.useRef)(new w.Animated.Value(0)).current,re=(0,B.useRef)(new w.Animated.Value(0)).current,G=(0,B.useRef)(n);G.current=n,(0,B.useEffect)(()=>{if(!t)return;y.setValue(W.height);let A=w.Animated.timing(y,{toValue:0,duration:pi,easing:w.Easing.out(w.Easing.cubic),useNativeDriver:!1});return A.start(({finished:$})=>{var se;$&&((se=G.current)==null||se.call(G))}),()=>A.stop()},[t,y]);let ee=Math.round(W.width*(u?.8:.78)),ie=Math.round(u?W.height*.46:ee*.78),ve=Math.round((W.height-ie)/2),Me=Math.round((W.width-ee)/2),He=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,B.useCallback)(A=>on(A),[])});(0,B.useEffect)(()=>{let A=w.BackHandler.addEventListener("hardwareBackPress",()=>(nn(),!0));return()=>A.remove()},[]);let xe=(0,B.useRef)(ce);(0,B.useEffect)(()=>{if(ce===xe.current)return;Y.setValue(1),re.setValue(1);let A=w.Animated.parallel([w.Animated.timing(Y,{toValue:0,duration:450,useNativeDriver:!0}),w.Animated.sequence([w.Animated.delay(si),w.Animated.timing(re,{toValue:0,duration:250,useNativeDriver:!0})])]);return A.start(),()=>A.stop()},[ce,Y,re]),(0,B.useEffect)(()=>{let A=se=>w.Animated.timing(L,{toValue:se,duration:ii,easing:w.Easing.inOut(w.Easing.quad),useNativeDriver:!0}),$=w.Animated.loop(w.Animated.sequence([A(1),A(0)]));return $.start(),()=>$.stop()},[L]);let Re=(0,B.useCallback)(()=>{w.Animated.timing(f,{toValue:0,duration:220,useNativeDriver:!0}).start()},[f]);(0,B.useEffect)(()=>{let A=setTimeout(Re,li);return()=>clearTimeout(A)},[Re]);let[et,$t]=(0,B.useState)(!1);(0,B.useEffect)(()=>{let A=requestAnimationFrame(()=>{A=requestAnimationFrame(()=>$t(!0))});return()=>cancelAnimationFrame(A)},[]);let Be=!!(p!=null&&p.hasTorch),tt=(h=p==null?void 0:p.neutralZoom)!=null?h:1,nt=p?Math.min(p.maxZoom/tt,ci):1,zt=tt*Math.min(C,nt),yt=A=>{var ae;let{touches:$}=A.nativeEvent;if($.length!==2){q.current=null;return}let se=Math.hypot($[0].pageX-$[1].pageX,$[0].pageY-$[1].pageY);(ae=q.current)!=null||(q.current={distance:se,level:C}),M(Math.max(1,Math.min(nt,q.current.level*(se/q.current.distance))))},wt=(0,v.jsx)(w.Text,{style:[_.hint,!!m&&_.hint_notice],numberOfLines:1,children:(b=m!=null?m:l)!=null?b:oi});return(0,v.jsx)(w.Animated.View,{ref:x,onTouchMove:yt,onTouchEnd:()=>{q.current=null},pointerEvents:t?"none":"auto",style:u?[_.top,d&&_.top_absolute,t&&{height:y}]:_.full,onLayout:({nativeEvent:{layout:A}})=>{var $;t||(o==null||o(A.height),($=x.current)==null||$.measureInWindow((se,ae)=>{oe({width:A.width,height:A.height,window_y:ae||0})}))},children:(0,v.jsxs)(w.View,{style:t?[_.content_closing,{height:W.height}]:_.content,children:[p&&et&&(0,v.jsx)(r.Camera,{style:w.StyleSheet.absoluteFill,device:p,isActive:!T,codeScanner:He,torch:O&&Be?"on":"off",zoom:zt,onPreviewStarted:Re,onError:A=>bo(A.message)}),(0,v.jsx)(w.Animated.View,{style:[_.preview_cover,{opacity:f}],pointerEvents:"none"}),W.height>0&&(0,v.jsxs)(w.View,{style:_.overlay,pointerEvents:"none",children:[(0,v.jsx)(w.View,{style:[_.dim_ring,{top:ve-Xe,left:Me-Xe,width:ee+Xe*2,height:ie+Xe*2}]}),(0,v.jsxs)(w.View,{style:{position:"absolute",top:ve,left:Me,width:ee,height:ie},children:[(0,v.jsx)(jo,{color:"#FFFFFF"}),(0,v.jsx)(w.Animated.View,{style:[w.StyleSheet.absoluteFill,{opacity:Y}],children:(0,v.jsx)(jo,{color:gt})}),(0,v.jsxs)(w.Animated.View,{style:[_.scan_line_wrap,{transform:[{translateY:L.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,ie-It)]})}]}],children:[(0,v.jsx)(w.View,{style:_.scan_glow_outer}),(0,v.jsx)(w.View,{style:_.scan_glow_inner}),(0,v.jsx)(w.View,{style:_.scan_line})]})]}),(0,v.jsx)(w.View,{style:[_.hint_slot,u?{top:0,height:ve-6,justifyContent:"flex-end"}:{top:ve+ie+20}],children:wt}),a===Fe.continuous&&!!Pe&&(0,v.jsx)(w.Animated.View,{style:[_.result_slot,{top:u?ve+ie-ai:ve+ie+52},{opacity:re}],children:(0,v.jsxs)(w.View,{style:_.result,children:[(0,v.jsx)(w.View,{style:_.check_badge,children:(0,v.jsx)(w.View,{style:_.check_mark})}),(0,v.jsx)(w.Text,{style:_.result_text,numberOfLines:1,children:Pe}),(0,v.jsxs)(w.Text,{style:_.result_count,children:["\xB7 ",E," m\xE3"]})]})})]}),W.height>0&&(0,v.jsx)(w.View,{style:[_.close_slot,u?_.close_slot_top:{top:Math.max(12,Ae-W.window_y+12)}],children:(0,v.jsxs)(kt,{style:[_.close_button,!!s&&_.glass_surface],onPress:nn,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,v.jsx)(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(w.View,{style:[_.close_bar,_.close_bar_a]}),(0,v.jsx)(w.View,{style:[_.close_bar,_.close_bar_b]})]})}),(0,v.jsx)(w.View,{style:[_.toolbar_wrap,!u&&{bottom:V.bottom+20}],pointerEvents:"box-none",children:(0,v.jsxs)(w.View,{style:[_.toolbar,!!s&&_.glass_surface],children:[s&&(0,v.jsx)(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(kt,{style:_.tool,onPress:Ao,disabled:T,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,v.jsxs)(w.View,{style:_.image_icon,children:[(0,v.jsx)(w.View,{style:_.image_icon_dot}),(0,v.jsx)(w.View,{style:_.image_icon_hill})]})}),!!p&&nt>=Wo&&(0,v.jsx)(kt,{style:[_.tool,C>1&&_.tool_on],onPress:()=>M(A=>A>1?1:Wo),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,v.jsxs)(w.Text,{style:[_.zoom_text,C>1&&_.zoom_text_on],children:[Math.round(C*10)/10,"x"]})}),Be&&(0,v.jsx)(kt,{style:[_.tool,O&&_.tool_on],onPress:()=>R(A=>!A),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:O},children:(0,v.jsx)(w.Text,{style:[_.torch_icon,O&&_.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},di="rgba(0,0,0,0.5)",fn=50,_=w.StyleSheet.create({top:{height:`${Ho*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},top_absolute:{position:"absolute",top:0,left:0,right:0,zIndex:1},content_closing:{position:"absolute",left:0,right:0,bottom:0,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:Xe,borderColor:di,borderRadius:Xe+ht},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:It,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:It,borderRadius:It/2,backgroundColor:gt,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:gt,opacity:.2},scan_line:{height:ri,borderRadius:1,backgroundColor:gt},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:fn,height:fn,borderRadius:fn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:gt},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var we=require("react"),P=require("react-native");var J=require("react/jsx-runtime"),wn={[me.info]:"#3B82F6",[me.success]:"#22C55E",[me.error]:"#EF4444"},Jo=-120,Lt=P.Platform.OS==="android",Go=({type:e})=>e===me.success?(0,J.jsx)(P.View,{style:ne.check_mark}):e===me.error?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(P.View,{style:[ne.cross_bar,ne.cross_a]}),(0,J.jsx)(P.View,{style:[ne.cross_bar,ne.cross_b]})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(P.View,{style:ne.info_dot}),(0,J.jsx)(P.View,{style:ne.info_bar})]}),Ko=()=>{let e=H(at,y=>y.message),t=H(at,y=>y.type),n=H(at,y=>y.tick),o=(0,we.useRef)(new P.Animated.Value(Jo)).current,r=(0,we.useRef)(new P.Animated.Value(0)).current,i=(0,we.useRef)(new P.Animated.Value(.92)).current,a=(0,we.useRef)(new P.Animated.Value(0)).current,[c,l]=(0,we.useState)(),[s,d]=(0,we.useState)(!1);(0,we.useEffect)(()=>{let y=!0;return tn().then(p=>{y&&p&&l(()=>p)}),()=>{y=!1}},[]);let u=(0,we.useRef)(n);return(0,we.useEffect)(()=>{if(n===u.current)return;P.AccessibilityInfo.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let y=P.Animated.sequence([P.Animated.parallel([P.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),P.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),P.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),P.Animated.sequence([P.Animated.delay(90),P.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),P.Animated.delay(Zn[t]),P.Animated.parallel([P.Animated.timing(o,{toValue:Jo,duration:240,useNativeDriver:!0}),P.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:p})=>{p&&d(!1)}),()=>y.stop()},[n]),s?(0,J.jsx)(P.View,{style:[ne.layer,{top:Ct().top+(Lt?12:8)}],pointerEvents:"none",children:(0,J.jsxs)(P.Animated.View,{style:[ne.toast,Lt&&ne.toast_android,!!c&&ne.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,J.jsx)(c,{style:ne.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Lt?(0,J.jsx)(P.Animated.View,{style:[ne.badge_halo,{backgroundColor:`${wn[t]}33`,transform:[{scale:a}]}],children:(0,J.jsx)(P.View,{style:[ne.badge,{backgroundColor:wn[t]}],children:(0,J.jsx)(Go,{type:t})})}):(0,J.jsx)(P.Animated.View,{style:[ne.badge,{backgroundColor:wn[t],transform:[{scale:a}]}],children:(0,J.jsx)(Go,{type:t})}),(0,J.jsx)(P.Text,{style:[ne.message,Lt&&ne.message_android],numberOfLines:2,children:e})]})}):null},ne=P.StyleSheet.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:P.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ue=Le({active_key:null,instances:{}}),Yo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=D().keep_alive)==null?void 0:c.max_webviews;ue.setState(l=>{let s=t!=null?t:e.app_id,d={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},u=Object.keys(d);return a&&a>0&&u.length>a&&u.filter(y=>y!==s).sort((y,p)=>d[y].last_used_at-d[p].last_used_at).slice(0,u.length-a).forEach(y=>{delete d[y]}),i?{active_key:s,instances:d}:{instances:d}})},Xo=e=>Yo(e,!0),Qo=e=>Yo(e,!1),Qe=()=>ue.setState({active_key:null}),Ft=e=>{ue.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var Zo="catalog",gi="paused_apps",hi="removed_apps",mi=10*1e3,fi=2,yi=3e3,wi=()=>{var e;try{return JSON.parse((e=D().storage.getString(Zo))!=null?e:"{}")}catch{return{}}},U=Le({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),er=e=>{var t;return!!((t=D().manual_update)!=null&&t.includes(e))},Ut=new Set,tr=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{}}}},_e=tr(gi),Ve=tr(hi);On(()=>{_e.load(),Ve.load();let e=wi(),t={};Object.keys(e).filter(n=>!Ve.has(n)).forEach(n=>{let o=N(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:_e.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),U.setState({catalog:e,downloads:t})});var Vt=e=>H(U,t=>e?t.downloads[e]:void 0),nr=()=>H(U,e=>e.pause_reasons.length>0),Se=(...e)=>he("queue",...e),Z=[],Oe={},k=null,Dt=new Set,je={},bn=new Set,Ne=e=>{bn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},or=e=>(bn.add(e),()=>{bn.delete(e)}),rr=()=>U.getState().downloads,de=(e,t)=>{let n=!!N(e),o=U.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};U.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?Ne({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ne({type:"progress",app_id:e,progress:i.progress,version:i.version})},Nt=(e,t)=>{var n;(n=je[e])==null||n.forEach(o=>o(t)),delete je[e]},bi=()=>U.getState().pause_reasons.length>0,Ue=e=>{var c;if(k)return;let t=e?Z.indexOf(e):bi()?-1:Z.findIndex(l=>!_e.has(l));if(t<0||t>=Z.length)return;let[n]=Z.splice(t,1),o=U.getState().catalog[n];if(!o){Nt(n,N(n)),Ue();return}let r=Date.now();Oe[n]=((c=Oe[n])!=null?c:0)+1,de(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=mn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,de(n,{progress:s/100,version:o.version}))}});k={app_id:n,handle:a,forced:!!e},Se("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Se("installed",n,o.version,`${Date.now()-r}ms`),de(n,{status:"installed",progress:1,version:o.version}),Nt(n,l)}).catch(l=>{var d;if(l instanceof Ye){if(Dt.has(n))return;Se("paused",n),Oe[n]-=1,Z.unshift(n),de(n,{status:_e.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=l==null?void 0:l.message)!=null?d:l);if(console.warn("[miniapp-queue] failed",n,s),Oe[n]<fi){de(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var u;Z.includes(n)||(k==null?void 0:k.app_id)===n||(Z.push(n),Ue((u=je[n])!=null&&u.length?n:void 0))},yi);return}de(n,{status:"failed",progress:0,version:o.version,error:s}),Nt(n,N(n))}).finally(()=>{k=null;let l=Z.find(s=>{var d;return(d=je[s])==null?void 0:d.length});Ue(l)})},Bt=(e,{front:t=!1}={})=>{if((k==null?void 0:k.app_id)===e)return;let n=Z.indexOf(e);if(n>=0){if(!t)return;Z.splice(n,1)}t?Z.unshift(e):Z.push(e)},Ai=async e=>{let{host_id:t,client_token:n}=D(),o=new AbortController,r=setTimeout(()=>o.abort(),mi);try{let i=`${Je}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},mt=null,qt=()=>(mt!=null||(mt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(D().channels.map(Ai)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(U.getState().catalog).filter(l=>!o[l]);D().storage.setString(Zo,JSON.stringify(o)),U.setState({catalog:o}),await Promise.all(r.map(l=>ir(l,{by_user:!1}))),r.forEach(l=>Ve.delete(l));let i=Object.keys(o).filter(l=>!Ve.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await gn(l)){de(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=N(l.app_id);if(er(l.app_id)&&!Ut.has(l.app_id)&&s&&await Te(s)){de(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return U.setState({updates:c}),a.forEach(l=>{Oe[l.app_id]=0,de(l.app_id,{status:_e.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Bt(l.app_id)}),Se("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Ne({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Ne({type:"update_available",...l})),Ue(),{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),Ne({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{mt=null}})()),mt),ir=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ve.add(e),Dt.has(e))return;Dt.add(e),_e.delete(e);let n=Z.indexOf(e);n>=0&&Z.splice(n,1),(k==null?void 0:k.app_id)===e&&k.handle.cancel();let o=(c=(a=(r=U.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=N(e))==null?void 0:i.version)!=null?c:"";de(e,{status:"uninstalling",progress:0,version:o}),await Uo(e),Ft(e),U.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Oe[e],Dt.delete(e),Nt(e,null),Se("uninstalled",e,t?"(user)":"(not in list)"),Ne({type:"uninstalled",app_id:e})},sr=e=>ir(e,{by_user:!0}),ar=e=>{let t=Ze(e);return t?(Ve.delete(e),(k==null?void 0:k.app_id)===e||Z.includes(e)||(Oe[e]=0,de(e,{status:_e.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Bt(e),Ue(),Se("restore",e)),!0):!1},cr=e=>{if(_e.has(e))return;if(_e.add(e),Se("pause app",e),(k==null?void 0:k.app_id)===e&&!k.forced){k.handle.cancel();return}let t=U.getState().downloads[e];Z.includes(e)&&t&&de(e,{status:"paused",progress:0,version:t.version})},lr=e=>{if(!_e.delete(e))return;Se("resume app",e);let t=U.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!Z.includes(e)&&Ze(e)&&(Oe[e]=0,Bt(e)),Z.includes(e)&&t&&de(e,{status:"queued",progress:0,version:t.version}),Ue()},pr=e=>{let{pause_reasons:t}=U.getState();t.includes(e)||(U.setState({pause_reasons:[...t,e]}),Se("pause",e),t.length===0&&Ne({type:"pause_change",paused:!0,reasons:[e]}),k&&!k.forced&&k.handle.cancel())},ur=e=>{let{pause_reasons:t}=U.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);U.setState({pause_reasons:n}),Se("resume",e),n.length===0&&Ne({type:"pause_change",paused:!1,reasons:n}),Ue()},An=e=>U.getState().updates[e],dr=async e=>{var n,o;let t=An(e);Ut.add(e);try{let r=await ft(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ze(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(U.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),Se("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Ut.delete(e)}},gr=()=>Object.values(U.getState().catalog).map(e=>({...e,installed:!!N(e.app_id),removed_by_user:Ve.has(e.app_id)})),Ze=e=>U.getState().catalog[e],ft=async e=>{let t=Ze(e);if(!t)return;if(_e.delete(e),Ve.delete(e),await gn(t))return N(e);let n=N(e);if(er(e)&&!Ut.has(e)&&n&&await Te(n))return n;let o=new Promise(r=>{var i;((i=je[e])!=null?i:je[e]=[]).push(r)});return(k==null?void 0:k.app_id)===e?k.forced=!0:(Oe[e]=0,Bt(e,{front:!0}),k&&!k.forced?k.handle.cancel():Ue(e)),o};var F=require("react/jsx-runtime"),Sn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),hr=0,Si=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},_i=S.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var yt,wt;let u=(0,S.useRef)(null),y=(0,S.useRef)(!1),p=H(ue,h=>h.instances[e]),f=p==null?void 0:p.app.app_id,O=p==null?void 0:p.app.manifest_url,R=p==null?void 0:p.context,C=p==null?void 0:p.url_params,M=H(Q,h=>{var b;return((b=h.active)==null?void 0:b.owner)===e?h.active:null}),[q,W]=(0,S.useState)(null),[oe,Pe]=(0,S.useState)(M);M!==oe&&(Pe(M),M?W(null):(oe==null?void 0:oe.layout)===pe.top&&W(oe));let ce=(M==null?void 0:M.layout)===pe.top?M:q,[E,m]=(0,S.useState)(()=>f?N(f):null),[T,x]=(0,S.useState)(!1),[V,Ae]=(0,S.useState)(0),[Y,L]=(0,S.useState)(0),[re,G]=(0,S.useState)(!1),ee=(0,S.useRef)(null),ie=h=>{ee.current&&clearTimeout(ee.current),ee.current=setTimeout(()=>{ee.current=null,G(!0)},h)};(0,S.useEffect)(()=>()=>{ee.current&&clearTimeout(ee.current)},[]),(0,S.useEffect)(()=>{if(!f||!t&&E)return;let h=!0;return x(!1),(async()=>{let b=N(f),A=b?await Te(b):!1;if(!h||(m(A?ae=>!ae||ae.version!==b.version||ae.permissions.join(",")!==b.permissions.join(",")?b:ae:null),__DEV__&&Date.now()-hr>1e4&&(hr=Date.now(),await qt()),!h))return;let $=await ft(f),se=$!==void 0?$:O?await qo(f,O):N(f);if(h){if(!se){x(!0);return}m(ae=>ae!=null?ae:se)}})(),()=>{h=!1}},[t,f,O,V]),(0,S.useEffect)(()=>$o(e,h=>u.current?(u.current.postMessage(h),!0):!1),[e]);let ve=H(U,h=>{let b=f?h.downloads[f]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});(0,S.useEffect)(()=>{if(t||!f||!E)return;let h=N(f);if(!h||h.version===E.version)return;let b=!0;return Te(h).then(A=>{!b||!A||(he(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",E.version,"\u2192",h.version),m(h))}),()=>{b=!1}},[t,f,ve,E==null?void 0:E.version]);let Me=H(U,h=>{var b;return f&&(b=h.apply_ticks[f])!=null?b:0});(0,S.useEffect)(()=>{if(!Me||!f)return;let h=N(f);if(!h||h.version===(E==null?void 0:E.version))return;let b=!0;return Te(h).then(A=>{!b||!A||(he(`webview:${e}`,"c\u1EADp nh\u1EADt",E==null?void 0:E.version,"\u2192",h.version),G(!1),m(h))}),()=>{b=!1}},[Me]),(0,S.useEffect)(()=>{var A;let h=(A=D().keep_alive)==null?void 0:A.idle_close_ms;if(t||!h||h<=0)return;let b=setTimeout(()=>{Ft(e)},h);return()=>clearTimeout(b)},[t,e]),(0,S.useEffect)(()=>{r>0&&(x(!1),G(!1),L(h=>h+1),Ae(h=>h+1))},[r]);let He=(0,S.useRef)(t);(0,S.useEffect)(()=>{var h;He.current!==t&&(He.current=t,y.current&&((h=u.current)==null||h.injectJavaScript(Po(t?"resumed":"paused"))))},[t]);let xe=`${(yt=E==null?void 0:E.version)!=null?yt:"none"}:${(wt=E==null?void 0:E.permissions.join(","))!=null?wt:""}:${Y}`,Re=(0,S.useMemo)(()=>JSON.stringify([R!=null?R:{},C!=null?C:{}]),[R,C]),et=(0,S.useMemo)(()=>{var h;return Io(C!=null?C:{},(h=E==null?void 0:E.permissions)!=null?h:[])},[Re,E==null?void 0:E.permissions]),$t=(0,S.useMemo)(()=>Oo(R!=null?R:{},et)+Eo()+Co()+(D().debug?xo():""),[et]),Be=(0,S.useRef)(null),tt=(0,S.useRef)(null);(0,S.useEffect)(()=>{var b,A,$;if(!E)return;if(tt.current!==xe){tt.current=xe,Be.current=Re;return}if(Be.current===Re)return;let h=((A=JSON.parse((b=Be.current)!=null?b:"[]")[0])!=null?A:{}).org_id;if(Be.current=Re,h===(R==null?void 0:R.org_id)&&y.current){G(!1),ie(1500),($=u.current)==null||$.injectJavaScript(Ro(R!=null?R:{},et));return}G(!1),L(se=>se+1)},[Re,E,xe]),(0,S.useEffect)(()=>(t||(Ce(e),De(e),$e(e)),()=>{Ce(e),De(e),$e(e)}),[t,e,xe,r]),(0,S.useEffect)(()=>{let h=I.AppState.addEventListener("change",b=>{b==="background"&&!so()&&Ce(e),b==="background"&&!go()&&De(e)});return()=>h.remove()},[e]);let nt=(0,S.useCallback)(async h=>{var A,$,se,ae,Wt,En;let b=So(h.nativeEvent.data);if(!b){if(f&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(h.nativeEvent.data,{app_id:f,instance_id:e})).catch(j=>{console.warn("[miniapp] onWebEvent l\u1ED7i",f,j)})}catch(j){console.warn("[miniapp] onWebEvent l\u1ED7i",f,j)}return}if(b.method==="log"){let{level:j,text:K}=b;he(`web:${e}`,j!=null?j:"log",K!=null?K:"");return}if(b.method==="pong"){ee.current||G(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){ee.current&&clearTimeout(ee.current),ee.current=null,G(!0);return}if(b.method==="ready"){y.current=!0,G(!0);let j=(A=ue.getState().instances[e])==null?void 0:A.context;j&&(($=u.current)==null||$.injectJavaScript(sn(j)));return}try{let j=await Fo(b,{getHostData:()=>{var K,ge;return(ge=(K=ue.getState().instances[e])==null?void 0:K.host_data)!=null?ge:{}},getPermissions:()=>{var K,ge;return f?(ge=(K=N(f))==null?void 0:K.permissions)!=null?ge:[]:[]},getContext:()=>{var K,ge;return(ge=(K=ue.getState().instances[e])==null?void 0:K.context)!=null?ge:{}},is_dark:o,close:Qe,app_id:f!=null?f:"",instance_id:e,options:c,emit:(K,ge)=>{var Cn;(Cn=u.current)==null||Cn.injectJavaScript(Mo(K,ge))},playBeep:(se=c==null?void 0:c.playScannerBeep)!=null?se:(()=>{var K;(K=u.current)==null||K.injectJavaScript(Lo())}),isActive:()=>ue.getState().active_key===e&&I.AppState.currentState!=="background"});b.id&&((ae=u.current)==null||ae.injectJavaScript(_o(b.id,j)))}catch(j){if(!b.id)return;let K=j==null?void 0:j.code,ge=j instanceof g?j:new g(typeof K=="string"?K:"HOST_ERROR",String((Wt=j==null?void 0:j.message)!=null?Wt:j));(En=u.current)==null||En.injectJavaScript(vo(b.id,ge))}},[e,o,f,i,c]),zt=(0,S.useCallback)(()=>{x(!1),L(h=>h+1),Ae(h=>h+1)},[]);return(0,F.jsxs)(I.View,{style:[I.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&be.behind],pointerEvents:t?"auto":"none",children:[ce&&(0,F.jsx)(yn,{scanner:ce,closing:ce===q,onClosed:()=>{var h;W(null),ce.absolute&&((h=u.current)==null||h.injectJavaScript(an(0)))},onHeight:ce.absolute?h=>{var b;return(b=u.current)==null?void 0:b.injectJavaScript(an(h))}:void 0}),E?(0,F.jsx)(fr.default,{ref:u,source:{uri:E.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?pn():E.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:$t,onMessage:nt,onShouldStartLoadWithRequest:h=>{let b=h.url;return h.isTopFrame===!1||!/^https?:\/\//i.test(b)?!0:(Promise.resolve(c!=null&&c.openUrl?c.openUrl(b):I.Linking.openURL(b)).catch(()=>{}),!1)},setSupportMultipleWindows:!1,bounces:!1,overScrollMode:"never",onLoadStart:h=>{Ce(e),De(e),$e(e),he(`webview:${e}`,"load start",Sn(h.nativeEvent.url)),y.current=!1,G(!1)},onError:h=>{Ce(e),De(e),$e(e),he(`webview:${e}`,"load error",Sn(h.nativeEvent.url),h.nativeEvent.description),x(!0),G(!1)},onLoadEnd:h=>{let b=h.nativeEvent.url;he(`webview:${e}`,"load end",Sn(b)),f&&(d==null||d({app_id:f,instance_id:e,url:b})),ie(1500)},onContentProcessDidTerminate:()=>{Ce(e),De(e),$e(e),y.current=!1,G(!1),L(h=>h+1)},onRenderProcessGone:()=>(Ce(e),De(e),$e(e),y.current=!1,G(!1),L(h=>h+1),!0),style:be.webview},xe):null,(M==null?void 0:M.layout)===pe.full&&(0,F.jsx)(yn,{scanner:M}),p&&(0,F.jsx)(Mi,{visible:!E||!re,interactive:T,children:(0,F.jsx)(vi,{splash:a,app:p.app,is_dark:o,error:T,has_bundle:!!E,retry:zt})})]})}),vi=S.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Vt(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,F.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),Mi=({visible:e,interactive:t,children:n})=>{let o=(0,S.useRef)(new I.Animated.Value(e?1:0)).current,[r,i]=(0,S.useState)(e);return(0,S.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=I.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,F.jsx)(I.Animated.View,{style:[I.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},_n=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,F.jsxs)(I.View,{style:[be.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,F.jsx)(I.View,{style:[be.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,F.jsx)(I.Image,{source:{uri:e.icon},style:be.splash_icon_image}):(0,F.jsx)(I.Text,{style:be.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,F.jsx)(I.Text,{style:[be.splash_name,{color:i}],children:e.name}),n==="error"?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(I.Text,{style:be.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,F.jsx)(I.TouchableOpacity,{activeOpacity:.7,style:[be.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,F.jsx)(I.Text,{style:[be.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(I.ActivityIndicator,{style:be.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,F.jsxs)(I.Text,{style:be.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},mr=(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.`))},xi=({container:e,splash:t=_n,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{mr("container",e),mr("splash",t);let l=e,s=H(ue,M=>M.active_key),d=(0,S.useRef)(s);s&&(d.current=s);let u=H(ue,M=>Object.keys(M.instances).join("|")),y=H(ue,M=>{var q;return M.active_key?(q=M.instances[M.active_key])==null?void 0:q.app.name:void 0}),p=(0,S.useMemo)(()=>u?u.split("|"):[],[u]),[f,O]=(0,S.useState)({}),R=(0,S.useRef)(Si()).current;(0,S.useEffect)(()=>{if(!s||!r)return;let M=I.BackHandler.addEventListener("hardwareBackPress",()=>(Qe(),!0));return()=>M.remove()},[s,r]);let C=(0,S.useCallback)(()=>{let M=ue.getState().active_key;M&&O(q=>({...q,[M]:(q[M]||0)+1}))},[]);return p.length?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:Qe,reload:C,subscribeWebAtTop:R.subscribe,children:p.map(M=>(0,F.jsx)(_i,{instance_key:M,is_active:s===M,is_front:(s!=null?s:d.current)===M,is_dark:n,reload_tick:f[M]||0,web_at_top:R,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},M))}),(0,F.jsx)(Ko,{})]}):null},be=I.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"}}),yr=S.default.memo(xi);var ke=require("react");var wr=e=>`changelog_seen:${e}`,Ei=10*1e3,vn=e=>D().storage.getString(wr(e))||null,Mn=(e,t=(n=>(n=N(e))==null?void 0:n.version)())=>{t&&D().storage.setString(wr(e),t)},br=e=>{var o;let t=(o=N(e))==null?void 0:o.version;if(!t)return null;let n=vn(e);return n?hn(t,n)>0?{app_id:e,from:n,to:t}:null:(Mn(e,t),null)},Ci=e=>{var t,n,o;return(o=(n=(t=U.getState().catalog[e])==null?void 0:t.channel)!=null?n:D().channels[0])!=null?o:"production"},xn=async(e,{from:t,to:n,channel:o=Ci(e)}={})=>{let{client_token:r}=D(),i=new URLSearchParams({channel:o});t&&i.set("from",t),n&&i.set("to",n);let a=new AbortController,c=setTimeout(()=>a.abort(),Ei);try{let l=await fetch(`${Je}/api/miniapps/${encodeURIComponent(e)}/changelog?${i}`,{headers:{Authorization:`Bearer ${r}`},signal:a.signal});if(!l.ok)throw new Error(`changelog ${e} ${l.status}`);return(await l.json()).versions}finally{clearTimeout(c)}},Ar=(e,{from:t,to:n,enabled:o=!0}={})=>{let[r,i]=(0,ke.useState)([]),[a,c]=(0,ke.useState)(!1),[l,s]=(0,ke.useState)(),[d,u]=(0,ke.useState)(0),y=(0,ke.useCallback)(()=>u(p=>p+1),[]);return(0,ke.useEffect)(()=>{if(!e||!o)return;let p=!0;return c(!0),s(void 0),xn(e,{from:t,to:n}).then(f=>{p&&i(f)}).catch(f=>{var O;p&&s(String((f==null?void 0:f.name)==="AbortError"?"timeout":(O=f==null?void 0:f.message)!=null?O:f))}).finally(()=>{p&&c(!1)}),()=>{p=!1}},[e,t,n,o,d]),{versions:r,loading:a,error:l,reload:y}};0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,fetchMiniAppChangelog,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppChangelogSeen,getMiniAppStatuses,getMiniAppUpdate,getPendingChangelog,installBundledMiniApp,markMiniAppChangelogSeen,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppChangelog,useMiniAppDownload,useMiniAppDownloadsPaused});
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Ht="https://retion-miniapp-platform.vercel.app",Ve=null,kn=new Set,dr=e=>{Ve=e,kn.forEach(t=>t())},D=()=>{if(!Ve)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ve},In=e=>{kn.add(e),Ve&&e()},ue=(...e)=>{Ve!=null&&Ve.debug&&console.log("[miniapp]",...e)};var gr=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),mr=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import Pn,{useCallback as xn,useEffect as le,useMemo as $t,useRef as be,useState as Ce}from"react";import{AppState as cr,ActivityIndicator as Ui,Animated as vn,BackHandler as Vi,Image as Bi,Linking as qi,StyleSheet as Tn,Text as yt,TouchableOpacity as $i,View as En}from"react-native";import Wi from"react-native-webview";import{Linking as vo,Platform as Jr}from"react-native";var Ln=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),_t,Jt=()=>(_t||(_t=import("react-native-biometrics").then(({default:e})=>Ln(new e({allowDeviceCredentials:!1}))).catch(e=>{throw _t=void 0,new m("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),_t);import{PermissionsAndroid as Be,Platform as hr}from"react-native";var Fn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new m("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new m("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new m("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Dn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new m("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(hr.OS==="android"){let s=Be.PERMISSIONS.ACCESS_FINE_LOCATION,g=Be.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Be.check(s);if(!c())return;let f=d||await Be.check(g);if(!c())return;if(!d&&!f){let u=await Be.requestMultiple([s,g]);if(!c())return;if(u[s]!==Be.RESULTS.GRANTED&&u[g]!==Be.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});import{Platform as Wn}from"react-native";var Gt=20,Nn=20,zn=/^[a-z][a-z0-9_-]{0,31}$/,fr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,yr=["low","medium","high"],Oe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),j=e=>new m("INVALID_PARAMS",e),nt=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Un=(e,t)=>{if(e===void 0)return{};if(!Oe(e)||Object.keys(e).length>Nn||Object.values(e).some(n=>typeof n!="string"))throw j(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Nn} key)`);return e},jn=e=>{var n,o,r,i;if(e!==void 0&&!Oe(e))throw j("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!zn.test(t.source)))throw j("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!fr.test(a))))throw j("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!nt(t.max_count,1,Gt))throw j(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Gt}`);if(t.max_size!==void 0&&!nt(t.max_size,1,Number.MAX_SAFE_INTEGER))throw j("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!nt(t.concurrency,1,5))throw j("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:wr(t.process),target:br(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},wr=e=>{if(e===void 0)return{};if(!Oe(e))throw j("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Oe(n))throw j("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!nt(n[o],1,1e4))throw j(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw j("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!Oe(n))throw j("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!nt(n.max_duration,1,3600))throw j("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!yr.includes(n.quality))throw j("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},br=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Oe(e))throw j("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!zn.test(t))throw j("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Oe(e.params))throw j("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw j("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw j(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Un(e.headers,"upload.headers"),form_data:Un(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Hn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},_r=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Hn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Ar=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},Qe,Sr=()=>(Qe!=null||(Qe=import("react-native-image-picker").catch(e=>{throw Qe=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Qe),Vn=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,f,u,y,T,M;let r=await Sr(),i=Ar(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(f=o.video)==null?void 0:f.quality)!=null?u:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let v=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(v,(T=c.errorMessage)!=null?T:c.errorCode)}return((M=c.assets)!=null?M:[]).filter(v=>v.uri).map((v,A)=>{var O,U,Z;return{uri:v.uri,name:(O=v.fileName)!=null?O:`file_${A+1}`,mime_type:(U=v.type)!=null?U:"application/octet-stream",size:v.fileSize,width:v.width,height:v.height,duration:v.duration,processed:!((Z=v.type)!=null&&Z.startsWith("video/"))||Wn.OS==="ios"}})},vr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},Mr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},xr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=vr[s])!=null?g:Mr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,y)=>{var T,M,v;return{uri:u.uri,name:(T=u.name)!=null?T:`file_${y+1}`,mime_type:(M=u.type)!=null?M:"application/octet-stream",size:(v=u.size)!=null?v:void 0}});if(Wn.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),f=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var y;return{...u,uri:(y=f.get(u.uri))!=null?y:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},et,Er=async e=>(et!=null||(et=import("@react-native-documents/picker").then(t=>xr(t)).catch(t=>{throw et=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await et)(e)),Jn={library:Vn("library"),camera:Vn("camera"),document:Er},Bn={type:"image",label:"\u1EA2nh",accept:["image/*"]},qn={type:"video",label:"Video",accept:["video/*"]},$n={library:[Bn,qn],camera:[Bn,qn],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},tt,Gn=()=>(tt!=null||(tt=import("react-native-compressor").catch(()=>(tt=void 0,null))),tt),Kn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Rr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Pr={low:640,medium:1280,high:1920},Tr=async(e,{image:t})=>{var o;if(!t||!Rr.has(e.mime_type.toLowerCase()))return e;let n=await Gn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await Kn(n,r,e.size),processed:!0}}catch{return e}},Cr=async(e,{video:t})=>{var o;let n=await Gn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Pr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Kn(n,r,e.size),processed:!0}}catch{return e}},Or={image:Tr,video:Cr},kr=(e,t)=>t.split(".").reduce((n,o)=>Oe(n)?n[o]:void 0,e),Yn=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,f])=>l.append(d,f)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,f])=>c.setRequestHeader(d,f)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let f=kr(d,a.url_field);if(typeof f!="string"||!f){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:f,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),Xn=e=>{var o,r;let t={...Jn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:Yn};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},Zn=e=>{let{sources:t,targets:n}=Xn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Jn[i]&&$n[i]).map(i=>[i,$n[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Gt}},St=new Map,Qn=(e,t)=>`${e}:${t}`,Ir=0,eo=(e,t)=>{var n;typeof t=="string"&&((n=St.get(Qn(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of St)t.startsWith(`${e}:`)&&n.abort()},At=()=>new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Lr=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},to=async(e,t)=>{var l;let{sources:n,targets:o}=Xn(t.config),r=n[e.source];if(!r)throw new m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=Qn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Ir}`);St.set(c,a);try{return await Fr(e,t,r,i,a.signal)}finally{St.delete(c)}},Fr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=d=>d()},l,s,g)=>{var p,S,L;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},f=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw At();if(!f.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],y=f.filter(x=>_r(x,e.accept)?!0:(u.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||Hn(x.name)}`}),!1)),T=y.map(()=>0),M=y.map(x=>{var ie;return(ie=x.size)!=null?ie:0}),v=0,A=0,O=(x=!1)=>{if(!a||!r)return;let ie=Date.now();if(!x&&ie-A<200)return;A=ie;let he=M.reduce((P,Q)=>P+Q,0),z=T.reduce((P,Q)=>P+Q,0);a("upload.progress",{task_id:r,loaded:z,total:he,percent:he?Math.min(100,Math.round(z/he*100)):0,done_count:v,count:y.length})},U=[],Z=0,xe=async()=>{var x,ie,he;for(;Z<y.length;){let z=Z++,P=y[z];try{if(g.aborted)throw At();let Q=P.mime_type.startsWith("image/")?"image":P.mime_type.startsWith("video/")?"video":void 0,q=Q&&!P.processed?(ie=(x=i==null?void 0:i.processors)==null?void 0:x[Q])!=null?ie:Or[Q]:void 0;if(q&&(P=await q(P,e.process),M[z]=(he=P.size)!=null?he:M[z],g.aborted))throw At();if(e.max_size&&P.size&&P.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${P.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Y=(ze,Se)=>{T[z]=ze,Se&&(M[z]=Se),O()},ee=await s({file:P,target:e.target,onProgress:Y,signal:g,caller:d});if(typeof(ee==null?void 0:ee.url)!="string"||!ee.url)throw new m("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:_e,...Ae}=ee;U[z]={url:_e,name:P.name,mime_type:P.mime_type,size:P.size,width:P.width,height:P.height,duration:P.duration,...Object.keys(Ae).length?{response:"response"in Ae?Ae.response:Ae}:{}},T[z]=M[z]}catch(Q){u.push(Lr(y[z].name,Q))}finally{v++,O(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},xe)),g.aborted)throw At();let re=U.filter(x=>!!x);if(!re.length){let x=u[0];throw new m((S=x==null?void 0:x.code)!=null?S:"UPLOAD_FAILED",(L=x==null?void 0:x.message)!=null?L:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:re,failed:u}};import{useRef as Dr,useSyncExternalStore as Nr}from"react";var ke=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},B=(e,t,n=Object.is)=>{let o=Dr(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return Nr(e.subscribe,r)};var fe={info:"info",success:"success",error:"error"},Ur=200,no={info:2e3,success:2e3,error:3e3},ot=ke({message:"",type:fe.info,tick:0}),oo=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Ur);return o?{message:o,type:Object.values(fe).includes(n)?n:fe.info}:null},ro=(e,t=fe.info)=>{ot.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Alert as Br,Linking as qr,Platform as rt,StatusBar as $r}from"react-native";import{AppState as io,Platform as Yt}from"react-native";var de,vt=new Map,so=(e,t)=>{vt.set(e,t)},ao=e=>{vt.delete(e)},co=()=>Yt.OS==="android"&&!!(de!=null&&de.requesting_permission),Vr=1500,Mt=()=>new Promise(e=>{if(Yt.OS!=="android"||io.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Vr),o=io.addEventListener("change",r=>{r==="active"&&t()})}),Kt=e=>{var t;if(de===e&&(de=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Yt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},lo=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(de)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};de=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let f;try{f=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await Mt(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!f.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var y,T;de!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(T=(y=u.results[0])==null?void 0:y.transcript)!=null?T:""})}),d.addListener("error",u=>{de===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{de===r&&(Kt(r),n("speech.end"))})),r.started=!0,d.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:g.AVAudioSessionCategory.playAndRecord,categoryOptions:[g.AVAudioSessionCategoryOptions.defaultToSpeaker,g.AVAudioSessionCategoryOptions.allowBluetooth],mode:g.AVAudioSessionMode.measurement}})}catch(g){throw Kt(r),g}},po=e=>{let t=de;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{var o;let t=vt.get(e);if(t){vt.delete(e);try{(o=t.release)==null||o.call(t,e)}catch{}return}let n=de;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Kt(n)}};var uo={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},oe={...uo,all:Object.values(uo)},it={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Zt={result:"scanner.result",end:"scanner.end"},je={user:"user",web:"web",closed:"closed",error:"error"},ge={top:"top",full:"full"},Ie={once:"once",continuous:"continuous"},Wr=1500,go=6e4,I,H=ke({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),ho=()=>rt.OS==="android"&&!!(I!=null&&I.requesting_permission),Qt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>oe.all.includes(c)))throw new m("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>go)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${go}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new m("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(ge).includes(r))throw new m("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new m("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},en=e=>I!==e?!1:(I=void 0,H.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),zr=()=>Br.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{qr.openSettings().catch(()=>{})}}]),fo=async(e,t)=>{if(I)throw new m("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");I=e;let n=()=>{if(e.cancelled||!t())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=rt.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await Mt(),n(),c!=="granted")throw a&&zr(),new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new m("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await tn();n(),H.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw en(e),o}},xt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{xt=e==null?void 0:e.insets}).catch(()=>{});var Et=()=>{var e;return xt!=null?xt:{top:rt.OS==="ios"?54:(e=$r.currentHeight)!=null?e:0,bottom:rt.OS==="ios"?34:48}},tn=async()=>{if(rt.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},yo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:oe.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Wr,hint:n.hint,layout:t===Ie.once?ge.full:(i=n.layout)!=null?i:ge.top,absolute:t!==Ie.once&&((a=n.layout)!=null?a:ge.top)===ge.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},wo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=yo(e,Ie.once,t);a.onHit=o,a.resolve=r,a.reject=i,fo(a,n).catch(i)}),bo=(e,t,n,o=()=>!0,r)=>{let i=yo(e,Ie.continuous,t);return i.emit=n,i.onHit=r,fo(i,o)},Rt=(e,t,n)=>{var o,r;if(!H.getState().active){e.cancelled=!0;return}if(en(e)){if(e.mode===Ie.once){(o=e.reject)==null||o.call(e,t===je.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Zt.end,n?{reason:t,message:n}:{reason:t})}},_o=e=>{(I==null?void 0:I.owner)===e&&Rt(I,je.web)},Le=e=>{(I==null?void 0:I.owner)===e&&Rt(I,je.closed)},nn=()=>{I&&Rt(I,je.user)},Ao=e=>{I&&Rt(I,je.error,e)},on=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=I;if(!(!o||!H.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Ie.once){en(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}H.setState(g=>({last_value:c,hit_tick:g.hit_tick+1,scan_count:g.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Zt.result,{value:c,type:l})}}},jr={1:oe.code128,2:oe.code39,4:oe.code93,8:oe.codabar,16:oe.dataMatrix,32:oe.ean13,64:oe.ean8,128:oe.itf,256:oe.qr,512:oe.upcA,1024:oe.upcE,2048:oe.pdf417,4096:oe.aztec},Hr=2500,mo=2e3,Xt=e=>{H.setState({notice:e}),setTimeout(()=>{H.getState().notice===e&&H.setState({notice:null})},Hr)},So=async()=>{var t,n;let e=I;if(!(!e||H.getState().is_picking)){e.requesting_permission=!0,H.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:mo,maxHeight:mo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||I!==e)return;if(r.errorCode||!i){Xt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(I!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:jr[g]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:g})=>({value:s,type:g!=null?g:"unknown"}));if(!l.length){Xt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}on(l,Date.now(),!0)}catch{I===e&&Xt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await Mt(),e.requesting_permission=!1,I===e&&H.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},Mo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,xo=(e,t)=>at({id:e,result:t}),Eo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),Ro=(e,t)=>at({event:e,data:t}),sn=e=>at({event:"context",data:e});var Po=()=>`(function () {
|
|
1
|
+
var et="https://retion-miniapp-platform.vercel.app",Ve=null,Fn=new Set,Sr=e=>{Ve=e,Fn.forEach(t=>t())},O=()=>{if(!Ve)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ve},Dn=e=>{Fn.add(e),Ve&&e()},ue=(...e)=>{Ve!=null&&Ve.debug&&console.log("[miniapp]",...e)};var _r=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),vr=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import On,{useCallback as Pn,useEffect as le,useMemo as zt,useRef as be,useState as Te}from"react";import{AppState as gr,ActivityIndicator as Hi,Animated as En,BackHandler as Ji,Image as Gi,Linking as Ki,StyleSheet as kn,Text as bt,TouchableOpacity as Yi,View as Rn}from"react-native";import Xi from"react-native-webview";import{Linking as Po,Platform as ni}from"react-native";var Nn=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),_t,Gt=()=>(_t||(_t=import("react-native-biometrics").then(({default:e})=>Nn(new e({allowDeviceCredentials:!1}))).catch(e=>{throw _t=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),_t);import{PermissionsAndroid as Be,Platform as Mr}from"react-native";var Un=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Vn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(Mr.OS==="android"){let s=Be.PERMISSIONS.ACCESS_FINE_LOCATION,d=Be.PERMISSIONS.ACCESS_COARSE_LOCATION,u=await Be.check(s);if(!c())return;let y=u||await Be.check(d);if(!c())return;if(!u&&!y){let p=await Be.requestMultiple([s,d]);if(!c())return;if(p[s]!==Be.RESULTS.GRANTED&&p[d]!==Be.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var u;if(!c())return;let d=(u={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?u:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(l=>i(l))});import{Platform as Hn}from"react-native";var Kt=20,Bn=20,Jn=/^[a-z][a-z0-9_-]{0,31}$/,xr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Er=["low","medium","high"],Oe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),H=e=>new g("INVALID_PARAMS",e),rt=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,qn=(e,t)=>{if(e===void 0)return{};if(!Oe(e)||Object.keys(e).length>Bn||Object.values(e).some(n=>typeof n!="string"))throw H(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Bn} key)`);return e},Gn=e=>{var n,o,r,i;if(e!==void 0&&!Oe(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"||!Jn.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"||!xr.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&&!rt(t.max_count,1,Kt))throw H(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Kt}`);if(t.max_size!==void 0&&!rt(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&&!rt(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:Cr(t.process),target:Pr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Cr=e=>{if(e===void 0)return{};if(!Oe(e))throw H("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Oe(n))throw H("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!rt(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(!Oe(n))throw H("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!rt(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&&!Er.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},Pr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Oe(e))throw H("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Jn.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&&!Oe(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:qn(e.headers,"upload.headers"),form_data:qn(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():""},Rr=(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)},Tr=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"},tt,Or=()=>(tt!=null||(tt=import("react-native-image-picker").catch(e=>{throw tt=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),tt),$n=e=>async({accept:t,max_count:n,process:o})=>{var l,s,d,u,y,p,f,C,x;let r=await Or(),i=Tr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(u=(d=o.image)==null?void 0:d.quality)!=null?u:.8,videoQuality:(p=(y=o.video)==null?void 0:y.quality)!=null?p:"medium",durationLimit:(f=o.video)==null?void 0:f.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let M=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(M,(C=c.errorMessage)!=null?C:c.errorCode)}return((x=c.assets)!=null?x:[]).filter(M=>M.uri).map((M,S)=>{var F,V,Z;return{uri:M.uri,name:(F=M.fileName)!=null?F:`file_${S+1}`,mime_type:(V=M.type)!=null?V:"application/octet-stream",size:M.fileSize,width:M.width,height:M.height,duration:M.duration,processed:!((Z=M.type)!=null&&Z.startsWith("video/"))||Hn.OS==="ios"}})},kr={"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"},Ir={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Lr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var d;return(d=kr[s])!=null?d:Ir[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,f)=>{var C,x,M;return{uri:p.uri,name:(C=p.name)!=null?C:`file_${f+1}`,mime_type:(x=p.type)!=null?x:"application/octet-stream",size:(M=p.size)!=null?M:void 0}});if(Hn.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let u=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),y=new Map(u.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var f;return{...p,uri:(f=y.get(p.uri))!=null?f:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},nt,Fr=async e=>(nt!=null||(nt=import("@react-native-documents/picker").then(t=>Lr(t)).catch(t=>{throw nt=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await nt)(e)),Yn={library:$n("library"),camera:$n("camera"),document:Fr},zn={type:"image",label:"\u1EA2nh",accept:["image/*"]},Wn={type:"video",label:"Video",accept:["video/*"]},jn={library:[zn,Wn],camera:[zn,Wn],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"]}]},ot,Xn=()=>(ot!=null||(ot=import("react-native-compressor").catch(()=>(ot=void 0,null))),ot),Qn=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"]),Nr={low:640,medium:1280,high:1920},Ur=async(e,{image:t})=>{var o;if(!t||!Dr.has(e.mime_type.toLowerCase()))return e;let n=await Xn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await Qn(n,r,e.size),processed:!0}}catch{return e}},Vr=async(e,{video:t})=>{var o;let n=await Xn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Nr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Qn(n,r,e.size),processed:!0}}catch{return e}},Br={image:Ur,video:Vr},qr=(e,t)=>t.split(".").reduce((n,o)=>Oe(n)?n[o]:void 0,e),Zn=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([u,y])=>l.append(u,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let d=u=>{o.removeEventListener("abort",s),u()};c.open("POST",a.url),Object.entries(a.headers).forEach(([u,y])=>c.setRequestHeader(u,y)),c.upload.onprogress=u=>n(u.loaded,u.total||e.size||0),c.onload=()=>d(()=>{let u=c.responseText;try{u=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=qr(u,a.url_field);if(typeof y!="string"||!y){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:u})}),c.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),eo=e=>{var o,r;let t={...Yn};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:Zn};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}},to=e=>{let{sources:t,targets:n}=eo(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Yn[i]&&jn[i]).map(i=>[i,jn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Kt}},Mt=new Map,no=(e,t)=>`${e}:${t}`,$r=0,oo=(e,t)=>{var n;typeof t=="string"&&((n=Mt.get(no(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of Mt)t.startsWith(`${e}:`)&&n.abort()},vt=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),zr=(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)}},ro=async(e,t)=>{var l;let{sources:n,targets:o}=eo(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=no(t.instance_id,(l=t.task_id)!=null?l:`auto-${++$r}`);Mt.set(c,a);try{return await Wr(e,t,r,i,a.signal)}finally{Mt.delete(c)}},Wr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=u=>u()},l,s,d)=>{var v,m,E;let u={app_id:n!=null?n:"",instance_id:t,context:{...(v=o==null?void 0:o())!=null?v:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:u}))).slice(0,e.max_count);if(d.aborted)throw vt();if(!y.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],f=y.filter(_=>Rr(_,e.accept)?!0:(p.push({name:_.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${_.mime_type||Kn(_.name)}`}),!1)),C=f.map(()=>0),x=f.map(_=>{var I;return(I=_.size)!=null?I:0}),M=0,S=0,F=(_=!1)=>{if(!a||!r)return;let I=Date.now();if(!_&&I-S<200)return;S=I;let me=x.reduce((T,ee)=>T+ee,0),j=C.reduce((T,ee)=>T+ee,0);a("upload.progress",{task_id:r,loaded:j,total:me,percent:me?Math.min(100,Math.round(j/me*100)):0,done_count:M,count:f.length})},V=[],Z=0,xe=async()=>{var _,I,me;for(;Z<f.length;){let j=Z++,T=f[j];try{if(d.aborted)throw vt();let ee=T.mime_type.startsWith("image/")?"image":T.mime_type.startsWith("video/")?"video":void 0,$=ee&&!T.processed?(I=(_=i==null?void 0:i.processors)==null?void 0:_[ee])!=null?I:Br[ee]:void 0;if($&&(T=await $(T,e.process),x[j]=(me=T.size)!=null?me:x[j],d.aborted))throw vt();if(e.max_size&&T.size&&T.size>e.max_size)throw new g("FILE_TOO_LARGE",`File ${T.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let X=(We,_e)=>{C[j]=We,_e&&(x[j]=_e),F()},te=await s({file:T,target:e.target,onProgress:X,signal:d,caller:u});if(typeof(te==null?void 0:te.url)!="string"||!te.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Ae,...Se}=te;V[j]={url:Ae,name:T.name,mime_type:T.mime_type,size:T.size,width:T.width,height:T.height,duration:T.duration,...Object.keys(Se).length?{response:"response"in Se?Se.response:Se}:{}},C[j]=x[j]}catch(ee){p.push(zr(f[j].name,ee))}finally{M++,F(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,f.length)},xe)),d.aborted)throw vt();let ie=V.filter(_=>!!_);if(!ie.length){let _=p[0];throw new g((m=_==null?void 0:_.code)!=null?m:"UPLOAD_FAILED",(E=_==null?void 0:_.message)!=null?E:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ie,failed:p}};import{useRef as jr,useSyncExternalStore as Hr}from"react";var ke=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},q=(e,t,n=Object.is)=>{let o=jr(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return Hr(e.subscribe,r)};var fe={info:"info",success:"success",error:"error"},Jr=200,io={info:2e3,success:2e3,error:3e3},it=ke({message:"",type:fe.info,tick:0}),so=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Jr);return o?{message:o,type:Object.values(fe).includes(n)?n:fe.info}:null},ao=(e,t=fe.info)=>{it.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Alert as Kr,Linking as Yr,Platform as st,StatusBar as Xr}from"react-native";import{AppState as co,Platform as Xt}from"react-native";var de,je=new Map,lo=(e,t)=>{var o;let n=(o=je.get(e))!=null?o:new Set;n.add(t),je.set(e,n)},po=(e,t)=>{let n=je.get(e);n&&(t?n.delete(t):n.clear(),n.size===0&&je.delete(e))},Qt=new Map,uo=(e,t)=>{Qt.set(e,t)},go=e=>Qt.get(e),ho=()=>Xt.OS==="android"&&!!(de!=null&&de.requesting_permission),Gr=1500,xt=()=>new Promise(e=>{if(Xt.OS!=="android"||co.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Gr),o=co.addEventListener("change",r=>{r==="active"&&t()})}),Yt=e=>{var t;if(de===e&&(de=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Xt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},mo=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(de)throw new g("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};de=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let u=d.ExpoSpeechRecognitionModule;if(r.native=u,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await u.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await xt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await u.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(u.addListener("result",p=>{var f,C;de!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(C=(f=p.results[0])==null?void 0:f.transcript)!=null?C:""})}),u.addListener("error",p=>{de===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),u.addListener("end",()=>{de===r&&(Yt(r),n("speech.end"))})),r.started=!0,u.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw Yt(r),d}},fo=e=>{let t=de;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Ce=e=>{Qt.delete(e);let t=je.get(e);je.delete(e),t==null||t.forEach(o=>{var r;try{(r=o.release)==null||r.call(o,e)}catch{}});let n=de;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Yt(n)}};var yo={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"},re={...yo,all:Object.values(yo)},at={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},en={result:"scanner.result",end:"scanner.end"},He={user:"user",web:"web",closed:"closed",error:"error"},ge={top:"top",full:"full"},Ie={once:"once",continuous:"continuous"},Qr=1500,wo=6e4,N,J=ke({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Ao=()=>st.OS==="android"&&!!(N!=null&&N.requesting_permission),tn=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>re.all.includes(c)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>wo)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${wo}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(ge).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new g("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},nn=e=>N!==e?!1:(N=void 0,J.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Zr=()=>Kr.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{Yr.openSettings().catch(()=>{})}}]),So=async(e,t)=>{if(N)throw new g("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");N=e;let n=()=>{if(e.cancelled||!t())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=st.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await xt(),n(),c!=="granted")throw a&&Zr(),new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new g("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await on();n(),J.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw nn(e),o}},Et;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Et=e==null?void 0:e.insets}).catch(()=>{});var Ct=()=>{var e;return Et!=null?Et:{top:st.OS==="ios"?54:(e=Xr.currentHeight)!=null?e:0,bottom:st.OS==="ios"?34:48}},on=async()=>{if(st.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},_o=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:re.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Qr,hint:n.hint,layout:t===Ie.once?ge.full:(i=n.layout)!=null?i:ge.top,absolute:t!==Ie.once&&((a=n.layout)!=null?a:ge.top)===ge.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},vo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=_o(e,Ie.once,t);a.onHit=o,a.resolve=r,a.reject=i,So(a,n).catch(i)}),Mo=(e,t,n,o=()=>!0,r)=>{let i=_o(e,Ie.continuous,t);return i.emit=n,i.onHit=r,So(i,o)},Pt=(e,t,n)=>{var o,r;if(!J.getState().active){e.cancelled=!0;return}if(nn(e)){if(e.mode===Ie.once){(o=e.reject)==null||o.call(e,t===He.error?new g("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new g("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,en.end,n?{reason:t,message:n}:{reason:t})}},xo=e=>{(N==null?void 0:N.owner)===e&&Pt(N,He.web)},Le=e=>{(N==null?void 0:N.owner)===e&&Pt(N,He.closed)},rn=()=>{N&&Pt(N,He.user)},Eo=e=>{N&&Pt(N,He.error,e)},sn=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=N;if(!(!o||!J.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Ie.once){nn(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}J.setState(d=>({last_value:c,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,en.result,{value:c,type:l})}}},ei={1:re.code128,2:re.code39,4:re.code93,8:re.codabar,16:re.dataMatrix,32:re.ean13,64:re.ean8,128:re.itf,256:re.qr,512:re.upcA,1024:re.upcE,2048:re.pdf417,4096:re.aztec},ti=2500,bo=2e3,Zt=e=>{J.setState({notice:e}),setTimeout(()=>{J.getState().notice===e&&J.setState({notice:null})},ti)},Co=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,maxWidth:bo,maxHeight:bo}),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){Zt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(N!==e)return;let l=c.map(({value:s,format:d})=>({value:s,code_type:ei[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!l.length){Zt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}sn(l,Date.now(),!0)}catch{N===e&&Zt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await xt(),e.requesting_permission=!1,N===e&&J.setState({is_picking:!1})}}};var Tt=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},Ro=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},lt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,To=(e,t)=>lt({id:e,result:t}),Oo=(e,t)=>lt({id:e,error:{code:t.code,message:t.message}}),ko=(e,t)=>lt({event:e,data:t}),cn=e=>lt({event:"context",data:e});var Io=()=>`(function () {
|
|
2
2
|
var post = function (level, args) {
|
|
3
3
|
try {
|
|
4
4
|
var parts = [];
|
|
@@ -19,7 +19,7 @@ var Ht="https://retion-miniapp-platform.vercel.app",Ve=null,kn=new Set,dr=e=>{Ve
|
|
|
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;`,Lo=()=>`(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; }
|
|
@@ -38,7 +38,7 @@ var Ht="https://retion-miniapp-platform.vercel.app",Ve=null,kn=new Set,dr=e=>{Ve
|
|
|
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;`,Fo=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,14 +59,14 @@ var Ht="https://retion-miniapp-platform.vercel.app",Ve=null,kn=new Set,dr=e=>{Ve
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,Do=e=>lt({event:e}),No=(e,t)=>{let n=Uo(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${cn(e)}`},Uo=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Vo=(e,t={})=>{let n=Uo(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
|
|
64
64
|
window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
|
|
65
65
|
${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
|
|
66
|
-
true;`},
|
|
66
|
+
true;`},Bo={partner:"partner_token",chatbox:"chatbox_token"},qo=(e,t)=>{let n={...e};for(let o of Object.values(Bo))t.includes(o)||delete n[o];return n},an=new Set,ct=async(e,t)=>{if(an.has(e))throw new g("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);an.add(e);try{return await t()}finally{an.delete(e)}},ln=e=>`(function () {
|
|
67
67
|
window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
|
|
68
68
|
window.dispatchEvent(new Event('retionscannerheight'));
|
|
69
|
-
})(); true
|
|
69
|
+
})(); true;`,$o=()=>`(function () {
|
|
70
70
|
try {
|
|
71
71
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
72
72
|
if (!AudioCtx) { return; }
|
|
@@ -85,4 +85,4 @@ var Ht="https://retion-miniapp-platform.vercel.app",Ve=null,kn=new Set,dr=e=>{Ve
|
|
|
85
85
|
// iOS c\xF3 th\u1EC3 \u0111\u1EC3 context \u1EDF suspended / interrupted (vd. khi camera m\u1EDF phi\xEAn quay): ch\u1EA1y l\u1EA1i xong m\u1EDBi ph\xE1t.
|
|
86
86
|
if (ctx.state === 'running') { play(); } else { ctx.resume().then(play).catch(function () {}); }
|
|
87
87
|
} catch (e) {}
|
|
88
|
-
})(); true;`,Gr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Pt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Uo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:g,isActive:d,playBeep:f})=>{var v,A,O,U,Z,xe,re;let u=s==null?void 0:s.handlers,y={app_id:c,instance_id:l,close:a},T=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),f==null||f()},M=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Fn(t);return st(e,()=>Dn(p,d))}case"speech.start":{if(!g)throw M();let p={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new m("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");p.lang=t.lang}for(let L of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[L])!==void 0){if(typeof t[L]!="boolean")throw new m("INVALID_PARAMS",`${L} ph\u1EA3i l\xE0 boolean`);p[L]=t[L]}let S=s==null?void 0:s.speech;if(S){so(l,S);try{return await S.start({owner:l,app_id:c,options:p,emit:g,isActive:d!=null?d:(()=>!0)})}catch(L){throw ao(l),L}}return lo(l,p,g,d)}case"speech.stop":return s!=null&&s.speech?s.speech.stop(l):po(l);case it.scan:return wo(l,Qt(t),d,T);case it.start:{if(!g)throw M();return bo(l,Qt(t),g,d,T)}case it.stop:return _o(l);case"uploadFiles":{let{task_id:p,...S}=t!=null?t:{};if(p!==void 0&&(typeof p!="string"||!p))throw new m("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return to(jn(S),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:L=>st("uploadFiles.pick",L)})}case"uploadFiles.cancel":eo(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Zn(s==null?void 0:s.upload);case"getBiometricAvailability":return((v=s==null?void 0:s.biometrics)!=null?v:await Jt()).getAvailability();case"authenticateBiometric":{let p=Pt(t==null?void 0:t.reason,"reason").trim();if(!p||p.length>200)throw new m("INVALID_PARAMS","reason must contain 1\u2013200 characters");let S=t==null?void 0:t.cancelButtonText;if(S!==void 0&&(typeof S!="string"||!S.trim()||S.length>80))throw new m("INVALID_PARAMS","Invalid cancelButtonText");return st(e,async()=>{var x;return((x=s==null?void 0:s.biometrics)!=null?x:await Jt()).authenticate({reason:p,cancelButtonText:S})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw M();let S=t==null?void 0:t.amount;if(typeof S!="number"||!Number.isFinite(S)||S<=0)throw new m("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let L={...t,amount:S,currency:Pt(t==null?void 0:t.currency,"currency")};return st(e,()=>p(L,y))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw M();let S=Pt(t==null?void 0:t.image,"image");await st(e,()=>p({image:S},y));return}case"openScreen":if(!(u!=null&&u.openScreen))throw M();await u.openScreen({screen:Pt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let p=String((A=t==null?void 0:t.url)!=null?A:"");if(!/^https?:\/\//i.test(p))throw new m("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(p):vo.openURL(p));return}case"openLink":{let p=String((O=t==null?void 0:t.url)!=null?O:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(p)||/^(javascript|file|data|about|blob):/i.test(p))throw new m("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(p):vo.openURL(p))}catch(S){throw new m("NOT_SUPPORTED",String((Z=(U=S==null?void 0:S.message)!=null?U:S)!=null?Z:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=oo(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):ro(p.message,p.type);return}case"haptic":{let p=Gr.has(t==null?void 0:t.type)?t.type:"selection";(xe=s==null?void 0:s.haptic)==null||xe.call(s,p);return}case"getSystemInfo":return{platform:Jr.OS==="ios"?"ios":"android",appVersion:(re=s==null?void 0:s.app_version)!=null?re:"",theme:i?"dark":"light"};case"getAccessToken":{let p=n().access_token;if(!p)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return p}case"getToken":{let p=t==null?void 0:t.type;if(p==="access"){let x=n().access_token;if(!x)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return x}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let S=Fo[p];if(!o().includes(S))throw new m("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${S} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let L=p==="partner"?n().partner_token:n().chatbox_token;if(!L)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${S}`);return L}case"getUserInfo":{let p=n().user;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return p}case"getPageInfo":{let p=n().page;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return p}case"sendMessage":case"insertText":throw new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new m("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var ln=e=>`bundle:${e}`,pn=()=>`${D().file_system.document_dir}/miniapps`,un=pn,dn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${un()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},cn=e=>{var t;D().storage.setString(ln(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Kr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,F=e=>{let t=D().storage.getString(ln(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return dn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Pe=e=>D().file_system.exists(e.entry_uri.replace("file://","")),gn=async e=>{let t=F(e.app_id);return(t==null?void 0:t.version)===e.version&&await Pe(t)},Bo=async(e,t)=>{let n=D().file_system,o=`${un()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},qo=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),D().storage.setString(ln(e),""),await D().file_system.remove(`${un()}/${e}`).catch(()=>{})},He=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},$o=(e,t)=>{var i;let o=((i=lt[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return lt[e]=r,r.then(()=>{lt[e]===r&&delete lt[e]}),o},Yr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},Xr=({manifest:e,zip_path:t})=>$o(e.app_id,async()=>{var i;let n=D().file_system,o=F(e.app_id);if(o&&Yr(o.version,e.version)>=0&&await Pe(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=dn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),cn(e),ue("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Bo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),mn=(e,{base_url:t,onProgress:n}={})=>{let o=D().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new He},l=async()=>{var d;c();let s=F(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return cn(e),F(e.app_id);c();let g=o.download({url:t?Kr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(f,u)=>{var T;let y=u>0?u:(T=e.size)!=null?T:0;y>0&&(n==null||n(Math.min(1,f/y)))}});r=g;try{let{status:f}=await g.promise;if(c(),f!==200)throw new Error(`bundle ${f}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ue("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=dn(e.app_id,e.version,e.entry,!!e.context_update,(d=e.permissions)!=null?d:[]);return await o.remove(u.dir).catch(()=>{}),await o.mkdir(u.dir),await o.unzip(a,u.dir),cn(e),Bo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(f){throw i?new He:f}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:$o(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},Zr=__DEV__?0:60*1e3,Vo={},Wo=(e,t)=>{var o,r;let n=F(e);return n&&Date.now()-((o=Vo[t])!=null?o:0)<Zr?Promise.resolve(n):((r=ct[e])!=null||(ct[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await mn(a,{base_url:t}).promise;return Vo[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),F(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Ct=new Map,zo=(e,t)=>(Ct.set(e,t),()=>{Ct.get(e)===t&&Ct.delete(e)}),Qr=(e,t)=>{let n=Ct.get(e);return n?n(t):!1};import{useCallback as jo,useEffect as Je,useRef as Me,useState as Ot}from"react";import{Animated as N,BackHandler as ei,Dimensions as ti,Easing as kt,Pressable as ni,StyleSheet as fn,Text as pt,View as W}from"react-native";import{Fragment as gi,jsx as E,jsxs as ve}from"react/jsx-runtime";var ut="#22C55E",oi="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",ri=2,Lt=18,ii=1600,dt=14,si=2e3,Go=.38,ai=40,Ho=2,ci=8,li=2e3,pi=250,Ge=2e3,ui=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:dt},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:dt},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:dt},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:dt}],Jo=({color:e})=>E(gi,{children:ui.map((t,n)=>E(W,{style:[_.corner,t,{borderColor:e}]},n))}),It=({style:e,children:t,...n})=>{let o=Me(new N.Value(1)).current,r=i=>N.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return E(ni,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:E(N.View,{style:[e,{transform:[{scale:o}]}],children:t})})},yn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var h,w;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===ge.top,f=Me(new N.Value(0)).current,u=r.useCameraDevice("back"),y=Me(new N.Value(1)).current,[T,M]=Ot(!1),[v,A]=Ot(1),O=Me(null),[U,Z]=Ot(()=>{let{width:b,height:k}=ti.get("window");return{width:b,height:d?k*Go:k,window_y:0}}),xe=B(H,b=>b.last_value),re=B(H,b=>b.hit_tick),p=B(H,b=>b.scan_count),S=B(H,b=>b.notice),L=B(H,b=>b.is_picking),x=Me(null),ie=Et(),he=ie.top,z=Me(new N.Value(0)).current,P=Me(new N.Value(0)).current,Q=Me(new N.Value(0)).current,q=Me(n);q.current=n,Je(()=>{if(!t)return;f.setValue(U.height);let b=N.timing(f,{toValue:0,duration:pi,easing:kt.out(kt.cubic),useNativeDriver:!1});return b.start(({finished:k})=>{var te;k&&((te=q.current)==null||te.call(q))}),()=>b.stop()},[t,f]);let Y=Math.round(U.width*(d?.8:.78)),ee=Math.round(d?U.height*.46:Y*.78),_e=Math.round((U.height-ee)/2),Ae=Math.round((U.width-Y)/2),ze=r.useCodeScanner({codeTypes:i,onCodeScanned:jo(b=>on(b),[])});Je(()=>{let b=ei.addEventListener("hardwareBackPress",()=>(nn(),!0));return()=>b.remove()},[]);let Se=Me(re);Je(()=>{if(re===Se.current)return;z.setValue(1),Q.setValue(1);let b=N.parallel([N.timing(z,{toValue:0,duration:450,useNativeDriver:!0}),N.sequence([N.delay(si),N.timing(Q,{toValue:0,duration:250,useNativeDriver:!0})])]);return b.start(),()=>b.stop()},[re,z,Q]),Je(()=>{let b=te=>N.timing(P,{toValue:te,duration:ii,easing:kt.inOut(kt.quad),useNativeDriver:!0}),k=N.loop(N.sequence([b(1),b(0)]));return k.start(),()=>k.stop()},[P]);let Ee=jo(()=>{N.timing(y,{toValue:0,duration:220,useNativeDriver:!0}).start()},[y]);Je(()=>{let b=setTimeout(Ee,li);return()=>clearTimeout(b)},[Ee]);let[Ye,Wt]=Ot(!1);Je(()=>{let b=requestAnimationFrame(()=>{b=requestAnimationFrame(()=>Wt(!0))});return()=>cancelAnimationFrame(b)},[]);let Ue=!!(u!=null&&u.hasTorch),Xe=(h=u==null?void 0:u.neutralZoom)!=null?h:1,Ze=u?Math.min(u.maxZoom/Xe,ci):1,zt=Xe*Math.min(v,Ze),wt=b=>{var ne;let{touches:k}=b.nativeEvent;if(k.length!==2){O.current=null;return}let te=Math.hypot(k[0].pageX-k[1].pageX,k[0].pageY-k[1].pageY);(ne=O.current)!=null||(O.current={distance:te,level:v}),A(Math.max(1,Math.min(Ze,O.current.level*(te/O.current.distance))))},bt=E(pt,{style:[_.hint,!!S&&_.hint_notice],numberOfLines:1,children:(w=S!=null?S:l)!=null?w:oi});return E(N.View,{ref:x,onTouchMove:wt,onTouchEnd:()=>{O.current=null},pointerEvents:t?"none":"auto",style:d?[_.top,g&&_.top_absolute,t&&{height:f}]:_.full,onLayout:({nativeEvent:{layout:b}})=>{var k;t||(o==null||o(b.height),(k=x.current)==null||k.measureInWindow((te,ne)=>{Z({width:b.width,height:b.height,window_y:ne||0})}))},children:ve(W,{style:t?[_.content_closing,{height:U.height}]:_.content,children:[u&&Ye&&E(r.Camera,{style:fn.absoluteFill,device:u,isActive:!L,codeScanner:ze,torch:T&&Ue?"on":"off",zoom:zt,onPreviewStarted:Ee,onError:b=>Ao(b.message)}),E(N.View,{style:[_.preview_cover,{opacity:y}],pointerEvents:"none"}),U.height>0&&ve(W,{style:_.overlay,pointerEvents:"none",children:[E(W,{style:[_.dim_ring,{top:_e-Ge,left:Ae-Ge,width:Y+Ge*2,height:ee+Ge*2}]}),ve(W,{style:{position:"absolute",top:_e,left:Ae,width:Y,height:ee},children:[E(Jo,{color:"#FFFFFF"}),E(N.View,{style:[fn.absoluteFill,{opacity:z}],children:E(Jo,{color:ut})}),ve(N.View,{style:[_.scan_line_wrap,{transform:[{translateY:P.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,ee-Lt)]})}]}],children:[E(W,{style:_.scan_glow_outer}),E(W,{style:_.scan_glow_inner}),E(W,{style:_.scan_line})]})]}),E(W,{style:[_.hint_slot,d?{top:0,height:_e-6,justifyContent:"flex-end"}:{top:_e+ee+20}],children:bt}),a===Ie.continuous&&!!xe&&E(N.View,{style:[_.result_slot,{top:d?_e+ee-ai:_e+ee+52},{opacity:Q}],children:ve(W,{style:_.result,children:[E(W,{style:_.check_badge,children:E(W,{style:_.check_mark})}),E(pt,{style:_.result_text,numberOfLines:1,children:xe}),ve(pt,{style:_.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),U.height>0&&E(W,{style:[_.close_slot,d?_.close_slot_top:{top:Math.max(12,he-U.window_y+12)}],children:ve(It,{style:[_.close_button,!!s&&_.glass_surface],onPress:nn,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&E(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),E(W,{style:[_.close_bar,_.close_bar_a]}),E(W,{style:[_.close_bar,_.close_bar_b]})]})}),E(W,{style:[_.toolbar_wrap,!d&&{bottom:ie.bottom+20}],pointerEvents:"box-none",children:ve(W,{style:[_.toolbar,!!s&&_.glass_surface],children:[s&&E(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),E(It,{style:_.tool,onPress:So,disabled:L,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:ve(W,{style:_.image_icon,children:[E(W,{style:_.image_icon_dot}),E(W,{style:_.image_icon_hill})]})}),!!u&&Ze>=Ho&&E(It,{style:[_.tool,v>1&&_.tool_on],onPress:()=>A(b=>b>1?1:Ho),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:ve(pt,{style:[_.zoom_text,v>1&&_.zoom_text_on],children:[Math.round(v*10)/10,"x"]})}),Ue&&E(It,{style:[_.tool,T&&_.tool_on],onPress:()=>M(b=>!b),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:T},children:E(pt,{style:[_.torch_icon,T&&_.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},di="rgba(0,0,0,0.5)",hn=50,_=fn.create({top:{height:`${Go*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},top_absolute:{position:"absolute",top:0,left:0,right:0,zIndex:1},content_closing:{position:"absolute",left:0,right:0,bottom:0,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:Ge,borderColor:di,borderRadius:Ge+dt},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:Lt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Lt,borderRadius:Lt/2,backgroundColor:ut,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:ut,opacity:.2},scan_line:{height:ri,borderRadius:1,backgroundColor:ut},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:hn,height:hn,borderRadius:hn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:ut},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});import{useEffect as Ko,useRef as gt,useState as Yo}from"react";import{AccessibilityInfo as mi,Animated as J,Platform as hi,StyleSheet as Xo,Text as fi,View as $e}from"react-native";import{Fragment as er,jsx as se,jsxs as bn}from"react/jsx-runtime";var wn={[fe.info]:"#3B82F6",[fe.success]:"#22C55E",[fe.error]:"#EF4444"},Zo=-120,Ft=hi.OS==="android",Qo=({type:e})=>e===fe.success?se($e,{style:X.check_mark}):e===fe.error?bn(er,{children:[se($e,{style:[X.cross_bar,X.cross_a]}),se($e,{style:[X.cross_bar,X.cross_b]})]}):bn(er,{children:[se($e,{style:X.info_dot}),se($e,{style:X.info_bar})]}),tr=()=>{let e=B(ot,f=>f.message),t=B(ot,f=>f.type),n=B(ot,f=>f.tick),o=gt(new J.Value(Zo)).current,r=gt(new J.Value(0)).current,i=gt(new J.Value(.92)).current,a=gt(new J.Value(0)).current,[c,l]=Yo(),[s,g]=Yo(!1);Ko(()=>{let f=!0;return tn().then(u=>{f&&u&&l(()=>u)}),()=>{f=!1}},[]);let d=gt(n);return Ko(()=>{if(n===d.current)return;mi.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let f=J.sequence([J.parallel([J.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),J.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),J.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),J.sequence([J.delay(90),J.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),J.delay(no[t]),J.parallel([J.timing(o,{toValue:Zo,duration:240,useNativeDriver:!0}),J.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return f.start(({finished:u})=>{u&&g(!1)}),()=>f.stop()},[n]),s?se($e,{style:[X.layer,{top:Et().top+(Ft?12:8)}],pointerEvents:"none",children:bn(J.View,{style:[X.toast,Ft&&X.toast_android,!!c&&X.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&se(c,{style:X.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Ft?se(J.View,{style:[X.badge_halo,{backgroundColor:`${wn[t]}33`,transform:[{scale:a}]}],children:se($e,{style:[X.badge,{backgroundColor:wn[t]}],children:se(Qo,{type:t})})}):se(J.View,{style:[X.badge,{backgroundColor:wn[t],transform:[{scale:a}]}],children:se(Qo,{type:t})}),se(fi,{style:[X.message,Ft&&X.message_android],numberOfLines:2,children:e})]})}):null},X=Xo.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:Xo.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ae=ke({active_key:null,instances:{}}),nr=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=D().keep_alive)==null?void 0:c.max_webviews;ae.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(f=>f!==s).sort((f,u)=>g[f].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(f=>{delete g[f]}),i?{active_key:s,instances:g}:{instances:g}})},yi=e=>nr(e,!0),wi=e=>nr(e,!1),mt=()=>ae.setState({active_key:null}),Dt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var or="catalog",bi="paused_apps",_i="removed_apps",Ai=10*1e3,Si=2,vi=3e3,Mi=()=>{var e;try{return JSON.parse((e=D().storage.getString(or))!=null?e:"{}")}catch{return{}}},C=ke({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),rr=e=>{var t;return!!((t=D().manual_update)!=null&&t.includes(e))},Vt=new Set,ir=e=>{let t=new Set,n=()=>D().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=D().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},we=ir(bi),Ne=ir(_i);In(()=>{we.load(),Ne.load();let e=Mi(),t={};Object.keys(e).filter(n=>!Ne.has(n)).forEach(n=>{let o=F(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:we.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),C.setState({catalog:e,downloads:t})});var An=e=>B(C,t=>e?t.downloads[e]:void 0),xi=()=>B(C,e=>e.pause_reasons.length>0),ye=(...e)=>ue("queue",...e),G=[],Te={},R=null,Nt=new Set,We={},_n=new Set,Fe=e=>{_n.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Ei=e=>(_n.add(e),()=>{_n.delete(e)}),Ri=()=>C.getState().downloads,ce=(e,t)=>{let n=!!F(e),o=C.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};C.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Fe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Fe({type:"progress",app_id:e,progress:i.progress,version:i.version})},Ut=(e,t)=>{var n;(n=We[e])==null||n.forEach(o=>o(t)),delete We[e]},Pi=()=>C.getState().pause_reasons.length>0,De=e=>{var c;if(R)return;let t=e?G.indexOf(e):Pi()?-1:G.findIndex(l=>!we.has(l));if(t<0||t>=G.length)return;let[n]=G.splice(t,1),o=C.getState().catalog[n];if(!o){Ut(n,F(n)),De();return}let r=Date.now();Te[n]=((c=Te[n])!=null?c:0)+1,ce(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=mn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,ce(n,{progress:s/100,version:o.version}))}});R={app_id:n,handle:a,forced:!!e},ye("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{ye("installed",n,o.version,`${Date.now()-r}ms`),ce(n,{status:"installed",progress:1,version:o.version}),Ut(n,l)}).catch(l=>{var g;if(l instanceof He){if(Nt.has(n))return;ye("paused",n),Te[n]-=1,G.unshift(n),ce(n,{status:we.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((g=l==null?void 0:l.message)!=null?g:l);if(console.warn("[miniapp-queue] failed",n,s),Te[n]<Si){ce(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;G.includes(n)||(R==null?void 0:R.app_id)===n||(G.push(n),De((d=We[n])!=null&&d.length?n:void 0))},vi);return}ce(n,{status:"failed",progress:0,version:o.version,error:s}),Ut(n,F(n))}).finally(()=>{R=null;let l=G.find(s=>{var g;return(g=We[s])==null?void 0:g.length});De(l)})},Bt=(e,{front:t=!1}={})=>{if((R==null?void 0:R.app_id)===e)return;let n=G.indexOf(e);if(n>=0){if(!t)return;G.splice(n,1)}t?G.unshift(e):G.push(e)},Ti=async e=>{let{host_id:t,client_token:n}=D(),o=new AbortController,r=setTimeout(()=>o.abort(),Ai);try{let i=`${Ht}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},ht=null,Sn=()=>(ht!=null||(ht=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(D().channels.map(Ti)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(C.getState().catalog).filter(l=>!o[l]);D().storage.setString(or,JSON.stringify(o)),C.setState({catalog:o}),await Promise.all(r.map(l=>sr(l,{by_user:!1}))),r.forEach(l=>Ne.delete(l));let i=Object.keys(o).filter(l=>!Ne.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await gn(l)){ce(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=F(l.app_id);if(rr(l.app_id)&&!Vt.has(l.app_id)&&s&&await Pe(s)){ce(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return C.setState({updates:c}),a.forEach(l=>{Te[l.app_id]=0,ce(l.app_id,{status:we.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Bt(l.app_id)}),ye("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Fe({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Fe({type:"update_available",...l})),De(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Fe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ht=null}})()),ht),sr=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ne.add(e),Nt.has(e))return;Nt.add(e),we.delete(e);let n=G.indexOf(e);n>=0&&G.splice(n,1),(R==null?void 0:R.app_id)===e&&R.handle.cancel();let o=(c=(a=(r=C.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=F(e))==null?void 0:i.version)!=null?c:"";ce(e,{status:"uninstalling",progress:0,version:o}),await qo(e),Dt(e),C.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Te[e],Nt.delete(e),Ut(e,null),ye("uninstalled",e,t?"(user)":"(not in list)"),Fe({type:"uninstalled",app_id:e})},Ci=e=>sr(e,{by_user:!0}),Oi=e=>{let t=ft(e);return t?(Ne.delete(e),(R==null?void 0:R.app_id)===e||G.includes(e)||(Te[e]=0,ce(e,{status:we.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Bt(e),De(),ye("restore",e)),!0):!1},ki=e=>{if(we.has(e))return;if(we.add(e),ye("pause app",e),(R==null?void 0:R.app_id)===e&&!R.forced){R.handle.cancel();return}let t=C.getState().downloads[e];G.includes(e)&&t&&ce(e,{status:"paused",progress:0,version:t.version})},Ii=e=>{if(!we.delete(e))return;ye("resume app",e);let t=C.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!G.includes(e)&&ft(e)&&(Te[e]=0,Bt(e)),G.includes(e)&&t&&ce(e,{status:"queued",progress:0,version:t.version}),De()},Li=e=>{let{pause_reasons:t}=C.getState();t.includes(e)||(C.setState({pause_reasons:[...t,e]}),ye("pause",e),t.length===0&&Fe({type:"pause_change",paused:!0,reasons:[e]}),R&&!R.forced&&R.handle.cancel())},Fi=e=>{let{pause_reasons:t}=C.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);C.setState({pause_reasons:n}),ye("resume",e),n.length===0&&Fe({type:"pause_change",paused:!1,reasons:n}),De()},ar=e=>C.getState().updates[e],Di=async e=>{var n,o;let t=ar(e);Vt.add(e);try{let r=await qt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=ft(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(C.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),ye("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Vt.delete(e)}},Ni=()=>Object.values(C.getState().catalog).map(e=>({...e,installed:!!F(e.app_id),removed_by_user:Ne.has(e.app_id)})),ft=e=>C.getState().catalog[e],qt=async e=>{let t=ft(e);if(!t)return;if(we.delete(e),Ne.delete(e),await gn(t))return F(e);let n=F(e);if(rr(e)&&!Vt.has(e)&&n&&await Pe(n))return n;let o=new Promise(r=>{var i;((i=We[e])!=null?i:We[e]=[]).push(r)});return(R==null?void 0:R.app_id)===e?R.forced=!0:(Te[e]=0,Bt(e,{front:!0}),R&&!R.forced?R.handle.cancel():De(e)),o};import{Fragment as Rn,jsx as K,jsxs as Ke}from"react/jsx-runtime";var Mn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),lr=0,zi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},ji=Pn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var wt,bt;let d=be(null),f=be(!1),u=B(ae,h=>h.instances[e]),y=u==null?void 0:u.app.app_id,T=u==null?void 0:u.app.manifest_url,M=u==null?void 0:u.context,v=u==null?void 0:u.url_params,A=B(H,h=>{var w;return((w=h.active)==null?void 0:w.owner)===e?h.active:null}),[O,U]=Ce(null),[Z,xe]=Ce(A);A!==Z&&(xe(A),A?U(null):(Z==null?void 0:Z.layout)===ge.top&&U(Z));let re=(A==null?void 0:A.layout)===ge.top?A:O,[p,S]=Ce(()=>y?F(y):null),[L,x]=Ce(!1),[ie,he]=Ce(0),[z,P]=Ce(0),[Q,q]=Ce(!1),Y=be(null),ee=h=>{Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>{Y.current=null,q(!0)},h)};le(()=>()=>{Y.current&&clearTimeout(Y.current)},[]),le(()=>{if(!y||!t&&p)return;let h=!0;return x(!1),(async()=>{let w=F(y),b=w?await Pe(w):!1;if(!h||(S(b?ne=>!ne||ne.version!==w.version||ne.permissions.join(",")!==w.permissions.join(",")?w:ne:null),__DEV__&&Date.now()-lr>1e4&&(lr=Date.now(),await Sn()),!h))return;let k=await qt(y),te=k!==void 0?k:T?await Wo(y,T):F(y);if(h){if(!te){x(!0);return}S(ne=>ne!=null?ne:te)}})(),()=>{h=!1}},[t,y,T,ie]),le(()=>zo(e,h=>d.current?(d.current.postMessage(h),!0):!1),[e]);let _e=B(C,h=>{let w=y?h.downloads[y]:void 0;return(w==null?void 0:w.status)==="installed"?w.version:void 0});le(()=>{if(t||!y||!p)return;let h=F(y);if(!h||h.version===p.version)return;let w=!0;return Pe(h).then(b=>{!w||!b||(ue(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",h.version),S(h))}),()=>{w=!1}},[t,y,_e,p==null?void 0:p.version]);let Ae=B(C,h=>{var w;return y&&(w=h.apply_ticks[y])!=null?w:0});le(()=>{if(!Ae||!y)return;let h=F(y);if(!h||h.version===(p==null?void 0:p.version))return;let w=!0;return Pe(h).then(b=>{!w||!b||(ue(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",h.version),q(!1),S(h))}),()=>{w=!1}},[Ae]),le(()=>{var b;let h=(b=D().keep_alive)==null?void 0:b.idle_close_ms;if(t||!h||h<=0)return;let w=setTimeout(()=>{Dt(e)},h);return()=>clearTimeout(w)},[t,e]),le(()=>{r>0&&(x(!1),q(!1),P(h=>h+1),he(h=>h+1))},[r]);let ze=be(t);le(()=>{var h;ze.current!==t&&(ze.current=t,f.current&&((h=d.current)==null||h.injectJavaScript(Oo(t?"resumed":"paused"))))},[t]);let Se=`${(wt=p==null?void 0:p.version)!=null?wt:"none"}:${(bt=p==null?void 0:p.permissions.join(","))!=null?bt:""}:${z}`,Ee=$t(()=>JSON.stringify([M!=null?M:{},v!=null?v:{}]),[M,v]),Ye=$t(()=>{var h;return Do(v!=null?v:{},(h=p==null?void 0:p.permissions)!=null?h:[])},[Ee,p==null?void 0:p.permissions]),Wt=$t(()=>Lo(M!=null?M:{},Ye)+To()+Co()+(D().debug?Po():""),[Ye]),Ue=be(null),Xe=be(null);le(()=>{var w,b,k;if(!p)return;if(Xe.current!==Se){Xe.current=Se,Ue.current=Ee;return}if(Ue.current===Ee)return;let h=((b=JSON.parse((w=Ue.current)!=null?w:"[]")[0])!=null?b:{}).org_id;if(Ue.current=Ee,h===(M==null?void 0:M.org_id)&&f.current){q(!1),ee(1500),(k=d.current)==null||k.injectJavaScript(ko(M!=null?M:{},Ye));return}q(!1),P(te=>te+1)},[Ee,p,Se]),le(()=>(t||(Re(e),Le(e),qe(e)),()=>{Re(e),Le(e),qe(e)}),[t,e,Se,r]),le(()=>{let h=cr.addEventListener("change",w=>{w==="background"&&!co()&&Re(e),w==="background"&&!ho()&&Le(e)});return()=>h.remove()},[e]);let Ze=xn(async h=>{var b,k,te,ne,jt,Cn;let w=Mo(h.nativeEvent.data);if(!w){if(y&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(h.nativeEvent.data,{app_id:y,instance_id:e})).catch(V=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,V)})}catch(V){console.warn("[miniapp] onWebEvent l\u1ED7i",y,V)}return}if(w.method==="log"){let{level:V,text:$}=w;ue(`web:${e}`,V!=null?V:"log",$!=null?$:"");return}if(w.method==="pong"){Y.current||q(!0);return}if(w.method==="touchAtTop"){i.emit(!!w.at_top);return}if(w.method==="contextApplied"){Y.current&&clearTimeout(Y.current),Y.current=null,q(!0);return}if(w.method==="ready"){f.current=!0,q(!0);let V=(b=ae.getState().instances[e])==null?void 0:b.context;V&&((k=d.current)==null||k.injectJavaScript(sn(V)));return}try{let V=await Uo(w,{getHostData:()=>{var $,pe;return(pe=($=ae.getState().instances[e])==null?void 0:$.host_data)!=null?pe:{}},getPermissions:()=>{var $,pe;return y?(pe=($=F(y))==null?void 0:$.permissions)!=null?pe:[]:[]},getContext:()=>{var $,pe;return(pe=($=ae.getState().instances[e])==null?void 0:$.context)!=null?pe:{}},is_dark:o,close:mt,app_id:y!=null?y:"",instance_id:e,options:c,emit:($,pe)=>{var On;(On=d.current)==null||On.injectJavaScript(Ro($,pe))},playBeep:(te=c==null?void 0:c.playScannerBeep)!=null?te:(()=>{var $;($=d.current)==null||$.injectJavaScript(No())}),isActive:()=>ae.getState().active_key===e&&cr.currentState!=="background"});w.id&&((ne=d.current)==null||ne.injectJavaScript(xo(w.id,V)))}catch(V){if(!w.id)return;let $=V==null?void 0:V.code,pe=V instanceof m?V:new m(typeof $=="string"?$:"HOST_ERROR",String((jt=V==null?void 0:V.message)!=null?jt:V));(Cn=d.current)==null||Cn.injectJavaScript(Eo(w.id,pe))}},[e,o,y,i,c]),zt=xn(()=>{x(!1),P(h=>h+1),he(h=>h+1)},[]);return Ke(En,{style:[Tn.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&me.behind],pointerEvents:t?"auto":"none",children:[re&&K(yn,{scanner:re,closing:re===O,onClosed:()=>{var h;U(null),re.absolute&&((h=d.current)==null||h.injectJavaScript(an(0)))},onHeight:re.absolute?h=>{var w;return(w=d.current)==null?void 0:w.injectJavaScript(an(h))}:void 0}),p?K(Wi,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?pn():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:Wt,onMessage:Ze,onShouldStartLoadWithRequest:h=>{let w=h.url;return h.isTopFrame===!1||!/^https?:\/\//i.test(w)?!0:(Promise.resolve(c!=null&&c.openUrl?c.openUrl(w):qi.openURL(w)).catch(()=>{}),!1)},setSupportMultipleWindows:!1,bounces:!1,overScrollMode:"never",onLoadStart:h=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load start",Mn(h.nativeEvent.url)),f.current=!1,q(!1)},onError:h=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load error",Mn(h.nativeEvent.url),h.nativeEvent.description),x(!0),q(!1)},onLoadEnd:h=>{let w=h.nativeEvent.url;ue(`webview:${e}`,"load end",Mn(w)),y&&(g==null||g({app_id:y,instance_id:e,url:w})),ee(1500)},onContentProcessDidTerminate:()=>{Re(e),Le(e),qe(e),f.current=!1,q(!1),P(h=>h+1)},onRenderProcessGone:()=>(Re(e),Le(e),qe(e),f.current=!1,q(!1),P(h=>h+1),!0),style:me.webview},Se):null,(A==null?void 0:A.layout)===ge.full&&K(yn,{scanner:A}),u&&K(Ji,{visible:!p||!Q,interactive:L,children:K(Hi,{splash:a,app:u.app,is_dark:o,error:L,has_bundle:!!p,retry:zt})})]})}),Hi=Pn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=An(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return K(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),Ji=({visible:e,interactive:t,children:n})=>{let o=be(new vn.Value(e?1:0)).current,[r,i]=Ce(e);return le(()=>{if(e){i(!0),o.setValue(1);return}let a=vn.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?K(vn.View,{style:[Tn.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},ur=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return Ke(En,{style:[me.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[K(En,{style:[me.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?K(Bi,{source:{uri:e.icon},style:me.splash_icon_image}):K(yt,{style:me.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),K(yt,{style:[me.splash_name,{color:i}],children:e.name}),n==="error"?Ke(Rn,{children:[K(yt,{style:me.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),K($i,{activeOpacity:.7,style:[me.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:K(yt,{style:[me.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):Ke(Rn,{children:[K(Ui,{style:me.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&Ke(yt,{style:me.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},pr=(e,t)=>{let n=be(t),o=be(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},Gi=({container:e,splash:t=ur,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{pr("container",e),pr("splash",t);let l=e,s=B(ae,A=>A.active_key),g=be(s);s&&(g.current=s);let d=B(ae,A=>Object.keys(A.instances).join("|")),f=B(ae,A=>{var O;return A.active_key?(O=A.instances[A.active_key])==null?void 0:O.app.name:void 0}),u=$t(()=>d?d.split("|"):[],[d]),[y,T]=Ce({}),M=be(zi()).current;le(()=>{if(!s||!r)return;let A=Vi.addEventListener("hardwareBackPress",()=>(mt(),!0));return()=>A.remove()},[s,r]);let v=xn(()=>{let A=ae.getState().active_key;A&&T(O=>({...O,[A]:(O[A]||0)+1}))},[]);return u.length?Ke(Rn,{children:[K(l,{visible:!!s,title:f!=null?f:"",is_dark:n,close:mt,reload:v,subscribeWebAtTop:M.subscribe,children:u.map(A=>K(ji,{instance_key:A,is_active:s===A,is_front:(s!=null?s:g.current)===A,is_dark:n,reload_tick:y[A]||0,web_at_top:M,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},A))}),K(tr,{})]}):null},me=Tn.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),Ki=Pn.memo(Gi);export{oe as CodeType,ur as DefaultMiniAppSplash,Ht as MINIAPP_PLATFORM_URL,Ki as MiniAppHost,m as MiniAppHostError,je as ScannerEndReason,Zt as ScannerEvent,ge as ScannerLayout,it as ScannerMethod,fe as ToastType,mt as closeMiniApp,dr as configureMiniApp,mr as createMmkvStorage,Ln as createReactNativeBiometrics,gr as createRnfsFileSystem,qt as ensureMiniApp,F as getLocalMiniApp,Ni as getMiniAppCatalog,ft as getMiniAppCatalogEntry,Ri as getMiniAppStatuses,ar as getMiniAppUpdate,Xr as installBundledMiniApp,Ei as onMiniAppEvent,yi as openMiniApp,ki as pauseMiniApp,Li as pauseMiniAppDownloads,wi as preloadMiniApp,Re as releaseSpeechFor,Oi as restoreMiniApp,Ii as resumeMiniApp,Fi as resumeMiniAppDownloads,Qr as sendEventToWeb,Sn as syncMiniAppCatalog,Ci as uninstallMiniApp,Di as updateMiniApp,Yn as uploadToUrl,An as useMiniAppDownload,xi as useMiniAppDownloadsPaused};
|
|
88
|
+
})(); true;`,oi=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Rt=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},zo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:d,isActive:u,playBeep:y})=>{var M,S,F,V,Z,xe,ie,v;let p=s==null?void 0:s.handlers,f={app_id:c,instance_id:l,close:a},C=()=>{var m;(m=s==null?void 0:s.haptic)==null||m.call(s,"impactLight"),y==null||y()},x=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let m=Un(t);return ct(e,()=>Vn(m,u))}case"speech.start":{if(!d)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 g("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");m.lang=t.lang}for(let I of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[I])!==void 0){if(typeof t[I]!="boolean")throw new g("INVALID_PARAMS",`${I} ph\u1EA3i l\xE0 boolean`);m[I]=t[I]}if((t==null?void 0:t.mode)!==void 0&&t.mode!=="s2t"&&t.mode!=="voice")throw new g("INVALID_PARAMS","mode ph\u1EA3i l\xE0 's2t' ho\u1EB7c 'voice'");let E=(t==null?void 0:t.mode)==="s2t"?"s2t":"voice",_=E==="voice"?(M=s==null?void 0:s.voice)!=null?M:s==null?void 0:s.speech:void 0;if(uo(l,_),_){lo(l,_);try{return await _.start({owner:l,app_id:c,mode:E,options:m,emit:d,isActive:u!=null?u:(()=>!0)})}catch(I){throw po(l,_),I}}return mo(l,m,d,u)}case"speech.stop":{let m=go(l);return m?m.stop(l):fo(l)}case at.scan:return vo(l,tn(t),u,C);case at.start:{if(!d)throw x();return Mo(l,tn(t),d,u,C)}case at.stop:return xo(l);case"uploadFiles":{let{task_id:m,...E}=t!=null?t:{};if(m!==void 0&&(typeof m!="string"||!m))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return ro(Gn(E),{instance_id:l,app_id:c,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:d,exclusivePick:_=>ct("uploadFiles.pick",_)})}case"uploadFiles.cancel":oo(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return to(s==null?void 0:s.upload);case"getBiometricAvailability":return((S=s==null?void 0:s.biometrics)!=null?S:await Gt()).getAvailability();case"authenticateBiometric":{let m=Rt(t==null?void 0:t.reason,"reason").trim();if(!m||m.length>200)throw new g("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 g("INVALID_PARAMS","Invalid cancelButtonText");return ct(e,async()=>{var I;return((I=s==null?void 0:s.biometrics)!=null?I:await Gt()).authenticate({reason:m,cancelButtonText:E})})}case"requestPayment":{let m=p==null?void 0:p.requestPayment;if(!m)throw x();let E=t==null?void 0:t.amount;if(typeof E!="number"||!Number.isFinite(E)||E<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let _={...t,amount:E,currency:Rt(t==null?void 0:t.currency,"currency")};return ct(e,()=>m(_,f))}case"printImage":{let m=p==null?void 0:p.printImage;if(!m)throw x();let E=Rt(t==null?void 0:t.image,"image");await ct(e,()=>m({image:E},f));return}case"openScreen":if(!(p!=null&&p.openScreen))throw x();await p.openScreen({screen:Rt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},f);return;case"closeApp":a();return;case"openWebview":{let m=String((F=t==null?void 0:t.url)!=null?F:"");if(!/^https?:\/\//i.test(m))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(m):Po.openURL(m));return}case"openLink":{let m=String((V=t==null?void 0:t.url)!=null?V:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(m)||/^(javascript|file|data|about|blob):/i.test(m))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(m):Po.openURL(m))}catch(E){throw new g("NOT_SUPPORTED",String((xe=(Z=E==null?void 0:E.message)!=null?Z:E)!=null?xe:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let m=so(t);if(!m||(u==null?void 0:u())===!1)return;s!=null&&s.showToast?s.showToast(m.message,{type:m.type}):ao(m.message,m.type);return}case"haptic":{let m=oi.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:ni.OS==="ios"?"ios":"android",appVersion:(v=s==null?void 0:s.app_version)!=null?v:"",theme:i?"dark":"light"};case"getAccessToken":{let m=n().access_token;if(!m)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return m}case"getToken":{let m=t==null?void 0:t.type;if(m==="access"){let I=n().access_token;if(!I)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return I}if(m!=="partner"&&m!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let E=Bo[m];if(!o().includes(E))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${E} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let _=m==="partner"?n().partner_token:n().chatbox_token;if(!_)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${E}`);return _}case"getUserInfo":{let m=n().user;if(!m)throw new g("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 g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return m}case"sendMessage":case"insertText":throw new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new g("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var un=e=>`bundle:${e}`,dn=()=>`${O().file_system.document_dir}/miniapps`,gn=dn,hn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${gn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},pn=e=>{var t;O().storage.setString(un(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},ri=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,L=e=>{let t=O().storage.getString(un(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return hn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Pe=e=>O().file_system.exists(e.entry_uri.replace("file://","")),mn=async e=>{let t=L(e.app_id);return(t==null?void 0:t.version)===e.version&&await Pe(t)},jo=async(e,t)=>{let n=O().file_system,o=`${gn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Ho=async e=>{var t;await((t=ut[e])==null?void 0:t.catch(()=>{})),O().storage.setString(un(e),""),await O().file_system.remove(`${gn()}/${e}`).catch(()=>{})},Je=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},ut={},Jo=(e,t)=>{var i;let o=((i=ut[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return ut[e]=r,r.then(()=>{ut[e]===r&&delete ut[e]}),o},fn=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},ii=({manifest:e,zip_path:t})=>Jo(e.app_id,async()=>{var i;let n=O().file_system,o=L(e.app_id);if(o&&fn(o.version,e.version)>=0&&await Pe(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=hn(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),pn(e),ue("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),jo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),yn=(e,{base_url:t,onProgress:n}={})=>{let o=O().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Je},l=async()=>{var u;c();let s=L(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return pn(e),L(e.app_id);c();let d=o.download({url:t?ri(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,p)=>{var C;let f=p>0?p:(C=e.size)!=null?C:0;f>0&&(n==null||n(Math.min(1,y/f)))}});r=d;try{let{status:y}=await d.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ue("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let p=hn(e.app_id,e.version,e.entry,!!e.context_update,(u=e.permissions)!=null?u:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),pn(e),jo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(y){throw i?new Je:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Jo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},pt={},si=__DEV__?0:60*1e3,Wo={},Go=(e,t)=>{var o,r;let n=L(e);return n&&Date.now()-((o=Wo[t])!=null?o:0)<si?Promise.resolve(n):((r=pt[e])!=null||(pt[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await yn(a,{base_url:t}).promise;return Wo[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),L(e))).finally(()=>{pt[e]=void 0})),pt[e])};var Ot=new Map,Ko=(e,t)=>(Ot.set(e,t),()=>{Ot.get(e)===t&&Ot.delete(e)}),ai=(e,t)=>{let n=Ot.get(e);return n?n(t):!1};import{useCallback as Yo,useEffect as Ge,useRef as Me,useState as kt}from"react";import{Animated as U,BackHandler as ci,Dimensions as li,Easing as It,Pressable as pi,StyleSheet as bn,Text as dt,View as W}from"react-native";import{Fragment as Si,jsx as P,jsxs as ve}from"react/jsx-runtime";var gt="#22C55E",ui="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",di=2,Ft=18,gi=1600,ht=14,hi=2e3,Zo=.38,mi=40,Xo=2,fi=8,yi=2e3,wi=250,Ke=2e3,bi=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ht},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ht},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ht},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ht}],Qo=({color:e})=>P(Si,{children:bi.map((t,n)=>P(W,{style:[A.corner,t,{borderColor:e}]},n))}),Lt=({style:e,children:t,...n})=>{let o=Me(new U.Value(1)).current,r=i=>U.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return P(pi,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:P(U.View,{style:[e,{transform:[{scale:o}]}],children:t})})},An=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var h,w;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:d}=e,u=c===ge.top,y=Me(new U.Value(0)).current,p=r.useCameraDevice("back"),f=Me(new U.Value(1)).current,[C,x]=kt(!1),[M,S]=kt(1),F=Me(null),[V,Z]=kt(()=>{let{width:b,height:D}=li.get("window");return{width:b,height:u?D*Zo:D,window_y:0}}),xe=q(J,b=>b.last_value),ie=q(J,b=>b.hit_tick),v=q(J,b=>b.scan_count),m=q(J,b=>b.notice),E=q(J,b=>b.is_picking),_=Me(null),I=Ct(),me=I.top,j=Me(new U.Value(0)).current,T=Me(new U.Value(0)).current,ee=Me(new U.Value(0)).current,$=Me(n);$.current=n,Ge(()=>{if(!t)return;y.setValue(V.height);let b=U.timing(y,{toValue:0,duration:wi,easing:It.out(It.cubic),useNativeDriver:!1});return b.start(({finished:D})=>{var ne;D&&((ne=$.current)==null||ne.call($))}),()=>b.stop()},[t,y]);let X=Math.round(V.width*(u?.8:.78)),te=Math.round(u?V.height*.46:X*.78),Ae=Math.round((V.height-te)/2),Se=Math.round((V.width-X)/2),We=r.useCodeScanner({codeTypes:i,onCodeScanned:Yo(b=>sn(b),[])});Ge(()=>{let b=ci.addEventListener("hardwareBackPress",()=>(rn(),!0));return()=>b.remove()},[]);let _e=Me(ie);Ge(()=>{if(ie===_e.current)return;j.setValue(1),ee.setValue(1);let b=U.parallel([U.timing(j,{toValue:0,duration:450,useNativeDriver:!0}),U.sequence([U.delay(hi),U.timing(ee,{toValue:0,duration:250,useNativeDriver:!0})])]);return b.start(),()=>b.stop()},[ie,j,ee]),Ge(()=>{let b=ne=>U.timing(T,{toValue:ne,duration:gi,easing:It.inOut(It.quad),useNativeDriver:!0}),D=U.loop(U.sequence([b(1),b(0)]));return D.start(),()=>D.stop()},[T]);let Ee=Yo(()=>{U.timing(f,{toValue:0,duration:220,useNativeDriver:!0}).start()},[f]);Ge(()=>{let b=setTimeout(Ee,yi);return()=>clearTimeout(b)},[Ee]);let[Xe,jt]=kt(!1);Ge(()=>{let b=requestAnimationFrame(()=>{b=requestAnimationFrame(()=>jt(!0))});return()=>cancelAnimationFrame(b)},[]);let Ue=!!(p!=null&&p.hasTorch),Qe=(h=p==null?void 0:p.neutralZoom)!=null?h:1,Ze=p?Math.min(p.maxZoom/Qe,fi):1,Ht=Qe*Math.min(M,Ze),At=b=>{var oe;let{touches:D}=b.nativeEvent;if(D.length!==2){F.current=null;return}let ne=Math.hypot(D[0].pageX-D[1].pageX,D[0].pageY-D[1].pageY);(oe=F.current)!=null||(F.current={distance:ne,level:M}),S(Math.max(1,Math.min(Ze,F.current.level*(ne/F.current.distance))))},St=P(dt,{style:[A.hint,!!m&&A.hint_notice],numberOfLines:1,children:(w=m!=null?m:l)!=null?w:ui});return P(U.View,{ref:_,onTouchMove:At,onTouchEnd:()=>{F.current=null},pointerEvents:t?"none":"auto",style:u?[A.top,d&&A.top_absolute,t&&{height:y}]:A.full,onLayout:({nativeEvent:{layout:b}})=>{var D;t||(o==null||o(b.height),(D=_.current)==null||D.measureInWindow((ne,oe)=>{Z({width:b.width,height:b.height,window_y:oe||0})}))},children:ve(W,{style:t?[A.content_closing,{height:V.height}]:A.content,children:[p&&Xe&&P(r.Camera,{style:bn.absoluteFill,device:p,isActive:!E,codeScanner:We,torch:C&&Ue?"on":"off",zoom:Ht,onPreviewStarted:Ee,onError:b=>Eo(b.message)}),P(U.View,{style:[A.preview_cover,{opacity:f}],pointerEvents:"none"}),V.height>0&&ve(W,{style:A.overlay,pointerEvents:"none",children:[P(W,{style:[A.dim_ring,{top:Ae-Ke,left:Se-Ke,width:X+Ke*2,height:te+Ke*2}]}),ve(W,{style:{position:"absolute",top:Ae,left:Se,width:X,height:te},children:[P(Qo,{color:"#FFFFFF"}),P(U.View,{style:[bn.absoluteFill,{opacity:j}],children:P(Qo,{color:gt})}),ve(U.View,{style:[A.scan_line_wrap,{transform:[{translateY:T.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,te-Ft)]})}]}],children:[P(W,{style:A.scan_glow_outer}),P(W,{style:A.scan_glow_inner}),P(W,{style:A.scan_line})]})]}),P(W,{style:[A.hint_slot,u?{top:0,height:Ae-6,justifyContent:"flex-end"}:{top:Ae+te+20}],children:St}),a===Ie.continuous&&!!xe&&P(U.View,{style:[A.result_slot,{top:u?Ae+te-mi:Ae+te+52},{opacity:ee}],children:ve(W,{style:A.result,children:[P(W,{style:A.check_badge,children:P(W,{style:A.check_mark})}),P(dt,{style:A.result_text,numberOfLines:1,children:xe}),ve(dt,{style:A.result_count,children:["\xB7 ",v," m\xE3"]})]})})]}),V.height>0&&P(W,{style:[A.close_slot,u?A.close_slot_top:{top:Math.max(12,me-V.window_y+12)}],children:ve(Lt,{style:[A.close_button,!!s&&A.glass_surface],onPress:rn,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&P(s,{style:A.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),P(W,{style:[A.close_bar,A.close_bar_a]}),P(W,{style:[A.close_bar,A.close_bar_b]})]})}),P(W,{style:[A.toolbar_wrap,!u&&{bottom:I.bottom+20}],pointerEvents:"box-none",children:ve(W,{style:[A.toolbar,!!s&&A.glass_surface],children:[s&&P(s,{style:A.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),P(Lt,{style:A.tool,onPress:Co,disabled:E,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:ve(W,{style:A.image_icon,children:[P(W,{style:A.image_icon_dot}),P(W,{style:A.image_icon_hill})]})}),!!p&&Ze>=Xo&&P(Lt,{style:[A.tool,M>1&&A.tool_on],onPress:()=>S(b=>b>1?1:Xo),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:ve(dt,{style:[A.zoom_text,M>1&&A.zoom_text_on],children:[Math.round(M*10)/10,"x"]})}),Ue&&P(Lt,{style:[A.tool,C&&A.tool_on],onPress:()=>x(b=>!b),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:C},children:P(dt,{style:[A.torch_icon,C&&A.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},Ai="rgba(0,0,0,0.5)",wn=50,A=bn.create({top:{height:`${Zo*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},top_absolute:{position:"absolute",top:0,left:0,right:0,zIndex:1},content_closing:{position:"absolute",left:0,right:0,bottom:0,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:Ke,borderColor:Ai,borderRadius:Ke+ht},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:Ft,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Ft,borderRadius:Ft/2,backgroundColor:gt,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:gt,opacity:.2},scan_line:{height:di,borderRadius:1,backgroundColor:gt},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:wn,height:wn,borderRadius:wn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:gt},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 er,useRef as mt,useState as tr}from"react";import{AccessibilityInfo as _i,Animated as G,Platform as vi,StyleSheet as nr,Text as Mi,View as $e}from"react-native";import{Fragment as ir,jsx as se,jsxs as _n}from"react/jsx-runtime";var Sn={[fe.info]:"#3B82F6",[fe.success]:"#22C55E",[fe.error]:"#EF4444"},or=-120,Dt=vi.OS==="android",rr=({type:e})=>e===fe.success?se($e,{style:Q.check_mark}):e===fe.error?_n(ir,{children:[se($e,{style:[Q.cross_bar,Q.cross_a]}),se($e,{style:[Q.cross_bar,Q.cross_b]})]}):_n(ir,{children:[se($e,{style:Q.info_dot}),se($e,{style:Q.info_bar})]}),sr=()=>{let e=q(it,y=>y.message),t=q(it,y=>y.type),n=q(it,y=>y.tick),o=mt(new G.Value(or)).current,r=mt(new G.Value(0)).current,i=mt(new G.Value(.92)).current,a=mt(new G.Value(0)).current,[c,l]=tr(),[s,d]=tr(!1);er(()=>{let y=!0;return on().then(p=>{y&&p&&l(()=>p)}),()=>{y=!1}},[]);let u=mt(n);return er(()=>{if(n===u.current)return;_i.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let y=G.sequence([G.parallel([G.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),G.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),G.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),G.sequence([G.delay(90),G.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),G.delay(io[t]),G.parallel([G.timing(o,{toValue:or,duration:240,useNativeDriver:!0}),G.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:p})=>{p&&d(!1)}),()=>y.stop()},[n]),s?se($e,{style:[Q.layer,{top:Ct().top+(Dt?12:8)}],pointerEvents:"none",children:_n(G.View,{style:[Q.toast,Dt&&Q.toast_android,!!c&&Q.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&se(c,{style:Q.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Dt?se(G.View,{style:[Q.badge_halo,{backgroundColor:`${Sn[t]}33`,transform:[{scale:a}]}],children:se($e,{style:[Q.badge,{backgroundColor:Sn[t]}],children:se(rr,{type:t})})}):se(G.View,{style:[Q.badge,{backgroundColor:Sn[t],transform:[{scale:a}]}],children:se(rr,{type:t})}),se(Mi,{style:[Q.message,Dt&&Q.message_android],numberOfLines:2,children:e})]})}):null},Q=nr.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:nr.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ae=ke({active_key:null,instances:{}}),ar=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=O().keep_alive)==null?void 0:c.max_webviews;ae.setState(l=>{let s=t!=null?t:e.app_id,d={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},u=Object.keys(d);return a&&a>0&&u.length>a&&u.filter(y=>y!==s).sort((y,p)=>d[y].last_used_at-d[p].last_used_at).slice(0,u.length-a).forEach(y=>{delete d[y]}),i?{active_key:s,instances:d}:{instances:d}})},xi=e=>ar(e,!0),Ei=e=>ar(e,!1),ft=()=>ae.setState({active_key:null}),Nt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var cr="catalog",Ci="paused_apps",Pi="removed_apps",Ri=10*1e3,Ti=2,Oi=3e3,ki=()=>{var e;try{return JSON.parse((e=O().storage.getString(cr))!=null?e:"{}")}catch{return{}}},k=ke({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),lr=e=>{var t;return!!((t=O().manual_update)!=null&&t.includes(e))},Bt=new Set,pr=e=>{let t=new Set,n=()=>O().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=O().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},we=pr(Ci),Ne=pr(Pi);Dn(()=>{we.load(),Ne.load();let e=ki(),t={};Object.keys(e).filter(n=>!Ne.has(n)).forEach(n=>{let o=L(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:we.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),k.setState({catalog:e,downloads:t})});var Mn=e=>q(k,t=>e?t.downloads[e]:void 0),Ii=()=>q(k,e=>e.pause_reasons.length>0),ye=(...e)=>ue("queue",...e),K=[],Re={},R=null,Ut=new Set,ze={},vn=new Set,Fe=e=>{vn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Li=e=>(vn.add(e),()=>{vn.delete(e)}),Fi=()=>k.getState().downloads,ce=(e,t)=>{let n=!!L(e),o=k.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};k.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Fe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Fe({type:"progress",app_id:e,progress:i.progress,version:i.version})},Vt=(e,t)=>{var n;(n=ze[e])==null||n.forEach(o=>o(t)),delete ze[e]},Di=()=>k.getState().pause_reasons.length>0,De=e=>{var c;if(R)return;let t=e?K.indexOf(e):Di()?-1:K.findIndex(l=>!we.has(l));if(t<0||t>=K.length)return;let[n]=K.splice(t,1),o=k.getState().catalog[n];if(!o){Vt(n,L(n)),De();return}let r=Date.now();Re[n]=((c=Re[n])!=null?c:0)+1,ce(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=yn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,ce(n,{progress:s/100,version:o.version}))}});R={app_id:n,handle:a,forced:!!e},ye("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{ye("installed",n,o.version,`${Date.now()-r}ms`),ce(n,{status:"installed",progress:1,version:o.version}),Vt(n,l)}).catch(l=>{var d;if(l instanceof Je){if(Ut.has(n))return;ye("paused",n),Re[n]-=1,K.unshift(n),ce(n,{status:we.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=l==null?void 0:l.message)!=null?d:l);if(console.warn("[miniapp-queue] failed",n,s),Re[n]<Ti){ce(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var u;K.includes(n)||(R==null?void 0:R.app_id)===n||(K.push(n),De((u=ze[n])!=null&&u.length?n:void 0))},Oi);return}ce(n,{status:"failed",progress:0,version:o.version,error:s}),Vt(n,L(n))}).finally(()=>{R=null;let l=K.find(s=>{var d;return(d=ze[s])==null?void 0:d.length});De(l)})},qt=(e,{front:t=!1}={})=>{if((R==null?void 0:R.app_id)===e)return;let n=K.indexOf(e);if(n>=0){if(!t)return;K.splice(n,1)}t?K.unshift(e):K.push(e)},Ni=async e=>{let{host_id:t,client_token:n}=O(),o=new AbortController,r=setTimeout(()=>o.abort(),Ri);try{let i=`${et}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},yt=null,xn=()=>(yt!=null||(yt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(O().channels.map(Ni)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(k.getState().catalog).filter(l=>!o[l]);O().storage.setString(cr,JSON.stringify(o)),k.setState({catalog:o}),await Promise.all(r.map(l=>ur(l,{by_user:!1}))),r.forEach(l=>Ne.delete(l));let i=Object.keys(o).filter(l=>!Ne.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await mn(l)){ce(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=L(l.app_id);if(lr(l.app_id)&&!Bt.has(l.app_id)&&s&&await Pe(s)){ce(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return k.setState({updates:c}),a.forEach(l=>{Re[l.app_id]=0,ce(l.app_id,{status:we.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),qt(l.app_id)}),ye("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Fe({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Fe({type:"update_available",...l})),De(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Fe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{yt=null}})()),yt),ur=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ne.add(e),Ut.has(e))return;Ut.add(e),we.delete(e);let n=K.indexOf(e);n>=0&&K.splice(n,1),(R==null?void 0:R.app_id)===e&&R.handle.cancel();let o=(c=(a=(r=k.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=L(e))==null?void 0:i.version)!=null?c:"";ce(e,{status:"uninstalling",progress:0,version:o}),await Ho(e),Nt(e),k.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Re[e],Ut.delete(e),Vt(e,null),ye("uninstalled",e,t?"(user)":"(not in list)"),Fe({type:"uninstalled",app_id:e})},Ui=e=>ur(e,{by_user:!0}),Vi=e=>{let t=wt(e);return t?(Ne.delete(e),(R==null?void 0:R.app_id)===e||K.includes(e)||(Re[e]=0,ce(e,{status:we.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),qt(e),De(),ye("restore",e)),!0):!1},Bi=e=>{if(we.has(e))return;if(we.add(e),ye("pause app",e),(R==null?void 0:R.app_id)===e&&!R.forced){R.handle.cancel();return}let t=k.getState().downloads[e];K.includes(e)&&t&&ce(e,{status:"paused",progress:0,version:t.version})},qi=e=>{if(!we.delete(e))return;ye("resume app",e);let t=k.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!K.includes(e)&&wt(e)&&(Re[e]=0,qt(e)),K.includes(e)&&t&&ce(e,{status:"queued",progress:0,version:t.version}),De()},$i=e=>{let{pause_reasons:t}=k.getState();t.includes(e)||(k.setState({pause_reasons:[...t,e]}),ye("pause",e),t.length===0&&Fe({type:"pause_change",paused:!0,reasons:[e]}),R&&!R.forced&&R.handle.cancel())},zi=e=>{let{pause_reasons:t}=k.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);k.setState({pause_reasons:n}),ye("resume",e),n.length===0&&Fe({type:"pause_change",paused:!1,reasons:n}),De()},dr=e=>k.getState().updates[e],Wi=async e=>{var n,o;let t=dr(e);Bt.add(e);try{let r=await $t(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=wt(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(k.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),ye("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Bt.delete(e)}},ji=()=>Object.values(k.getState().catalog).map(e=>({...e,installed:!!L(e.app_id),removed_by_user:Ne.has(e.app_id)})),wt=e=>k.getState().catalog[e],$t=async e=>{let t=wt(e);if(!t)return;if(we.delete(e),Ne.delete(e),await mn(t))return L(e);let n=L(e);if(lr(e)&&!Bt.has(e)&&n&&await Pe(n))return n;let o=new Promise(r=>{var i;((i=ze[e])!=null?i:ze[e]=[]).push(r)});return(R==null?void 0:R.app_id)===e?R.forced=!0:(Re[e]=0,qt(e,{front:!0}),R&&!R.forced?R.handle.cancel():De(e)),o};import{Fragment as Tn,jsx as Y,jsxs as Ye}from"react/jsx-runtime";var Cn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),hr=0,Qi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Zi=On.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var At,St;let u=be(null),y=be(!1),p=q(ae,h=>h.instances[e]),f=p==null?void 0:p.app.app_id,C=p==null?void 0:p.app.manifest_url,x=p==null?void 0:p.context,M=p==null?void 0:p.url_params,S=q(J,h=>{var w;return((w=h.active)==null?void 0:w.owner)===e?h.active:null}),[F,V]=Te(null),[Z,xe]=Te(S);S!==Z&&(xe(S),S?V(null):(Z==null?void 0:Z.layout)===ge.top&&V(Z));let ie=(S==null?void 0:S.layout)===ge.top?S:F,[v,m]=Te(()=>f?L(f):null),[E,_]=Te(!1),[I,me]=Te(0),[j,T]=Te(0),[ee,$]=Te(!1),X=be(null),te=h=>{X.current&&clearTimeout(X.current),X.current=setTimeout(()=>{X.current=null,$(!0)},h)};le(()=>()=>{X.current&&clearTimeout(X.current)},[]),le(()=>{if(!f||!t&&v)return;let h=!0;return _(!1),(async()=>{let w=L(f),b=w?await Pe(w):!1;if(!h||(m(b?oe=>!oe||oe.version!==w.version||oe.permissions.join(",")!==w.permissions.join(",")?w:oe:null),__DEV__&&Date.now()-hr>1e4&&(hr=Date.now(),await xn()),!h))return;let D=await $t(f),ne=D!==void 0?D:C?await Go(f,C):L(f);if(h){if(!ne){_(!0);return}m(oe=>oe!=null?oe:ne)}})(),()=>{h=!1}},[t,f,C,I]),le(()=>Ko(e,h=>u.current?(u.current.postMessage(h),!0):!1),[e]);let Ae=q(k,h=>{let w=f?h.downloads[f]:void 0;return(w==null?void 0:w.status)==="installed"?w.version:void 0});le(()=>{if(t||!f||!v)return;let h=L(f);if(!h||h.version===v.version)return;let w=!0;return Pe(h).then(b=>{!w||!b||(ue(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",v.version,"\u2192",h.version),m(h))}),()=>{w=!1}},[t,f,Ae,v==null?void 0:v.version]);let Se=q(k,h=>{var w;return f&&(w=h.apply_ticks[f])!=null?w:0});le(()=>{if(!Se||!f)return;let h=L(f);if(!h||h.version===(v==null?void 0:v.version))return;let w=!0;return Pe(h).then(b=>{!w||!b||(ue(`webview:${e}`,"c\u1EADp nh\u1EADt",v==null?void 0:v.version,"\u2192",h.version),$(!1),m(h))}),()=>{w=!1}},[Se]),le(()=>{var b;let h=(b=O().keep_alive)==null?void 0:b.idle_close_ms;if(t||!h||h<=0)return;let w=setTimeout(()=>{Nt(e)},h);return()=>clearTimeout(w)},[t,e]),le(()=>{r>0&&(_(!1),$(!1),T(h=>h+1),me(h=>h+1))},[r]);let We=be(t);le(()=>{var h;We.current!==t&&(We.current=t,y.current&&((h=u.current)==null||h.injectJavaScript(Do(t?"resumed":"paused"))))},[t]);let _e=`${(At=v==null?void 0:v.version)!=null?At:"none"}:${(St=v==null?void 0:v.permissions.join(","))!=null?St:""}:${j}`,Ee=zt(()=>JSON.stringify([x!=null?x:{},M!=null?M:{}]),[x,M]),Xe=zt(()=>{var h;return qo(M!=null?M:{},(h=v==null?void 0:v.permissions)!=null?h:[])},[Ee,v==null?void 0:v.permissions]),jt=zt(()=>Vo(x!=null?x:{},Xe)+Lo()+Fo()+(O().debug?Io():""),[Xe]),Ue=be(null),Qe=be(null);le(()=>{var w,b,D;if(!v)return;if(Qe.current!==_e){Qe.current=_e,Ue.current=Ee;return}if(Ue.current===Ee)return;let h=((b=JSON.parse((w=Ue.current)!=null?w:"[]")[0])!=null?b:{}).org_id;if(Ue.current=Ee,h===(x==null?void 0:x.org_id)&&y.current){$(!1),te(1500),(D=u.current)==null||D.injectJavaScript(No(x!=null?x:{},Xe));return}$(!1),T(ne=>ne+1)},[Ee,v,_e]),le(()=>(t||(Ce(e),Le(e),qe(e)),()=>{Ce(e),Le(e),qe(e)}),[t,e,_e,r]),le(()=>{let h=gr.addEventListener("change",w=>{w==="background"&&!ho()&&Ce(e),w==="background"&&!Ao()&&Le(e)});return()=>h.remove()},[e]);let Ze=Pn(async h=>{var b,D,ne,oe,Jt,In;let w=Ro(h.nativeEvent.data);if(!w){if(f&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(h.nativeEvent.data,{app_id:f,instance_id:e})).catch(B=>{console.warn("[miniapp] onWebEvent l\u1ED7i",f,B)})}catch(B){console.warn("[miniapp] onWebEvent l\u1ED7i",f,B)}return}if(w.method==="log"){let{level:B,text:z}=w;ue(`web:${e}`,B!=null?B:"log",z!=null?z:"");return}if(w.method==="pong"){X.current||$(!0);return}if(w.method==="touchAtTop"){i.emit(!!w.at_top);return}if(w.method==="contextApplied"){X.current&&clearTimeout(X.current),X.current=null,$(!0);return}if(w.method==="ready"){y.current=!0,$(!0);let B=(b=ae.getState().instances[e])==null?void 0:b.context;B&&((D=u.current)==null||D.injectJavaScript(cn(B)));return}try{let B=await zo(w,{getHostData:()=>{var z,pe;return(pe=(z=ae.getState().instances[e])==null?void 0:z.host_data)!=null?pe:{}},getPermissions:()=>{var z,pe;return f?(pe=(z=L(f))==null?void 0:z.permissions)!=null?pe:[]:[]},getContext:()=>{var z,pe;return(pe=(z=ae.getState().instances[e])==null?void 0:z.context)!=null?pe:{}},is_dark:o,close:ft,app_id:f!=null?f:"",instance_id:e,options:c,emit:(z,pe)=>{var Ln;(Ln=u.current)==null||Ln.injectJavaScript(ko(z,pe))},playBeep:(ne=c==null?void 0:c.playScannerBeep)!=null?ne:(()=>{var z;(z=u.current)==null||z.injectJavaScript($o())}),isActive:()=>ae.getState().active_key===e&&gr.currentState!=="background"});w.id&&((oe=u.current)==null||oe.injectJavaScript(To(w.id,B)))}catch(B){if(!w.id)return;let z=B==null?void 0:B.code,pe=B instanceof g?B:new g(typeof z=="string"?z:"HOST_ERROR",String((Jt=B==null?void 0:B.message)!=null?Jt:B));(In=u.current)==null||In.injectJavaScript(Oo(w.id,pe))}},[e,o,f,i,c]),Ht=Pn(()=>{_(!1),T(h=>h+1),me(h=>h+1)},[]);return Ye(Rn,{style:[kn.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&he.behind],pointerEvents:t?"auto":"none",children:[ie&&Y(An,{scanner:ie,closing:ie===F,onClosed:()=>{var h;V(null),ie.absolute&&((h=u.current)==null||h.injectJavaScript(ln(0)))},onHeight:ie.absolute?h=>{var w;return(w=u.current)==null?void 0:w.injectJavaScript(ln(h))}:void 0}),v?Y(Xi,{ref:u,source:{uri:v.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?dn():v.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:jt,onMessage:Ze,onShouldStartLoadWithRequest:h=>{let w=h.url;return h.isTopFrame===!1||!/^https?:\/\//i.test(w)?!0:(Promise.resolve(c!=null&&c.openUrl?c.openUrl(w):Ki.openURL(w)).catch(()=>{}),!1)},setSupportMultipleWindows:!1,bounces:!1,overScrollMode:"never",onLoadStart:h=>{Ce(e),Le(e),qe(e),ue(`webview:${e}`,"load start",Cn(h.nativeEvent.url)),y.current=!1,$(!1)},onError:h=>{Ce(e),Le(e),qe(e),ue(`webview:${e}`,"load error",Cn(h.nativeEvent.url),h.nativeEvent.description),_(!0),$(!1)},onLoadEnd:h=>{let w=h.nativeEvent.url;ue(`webview:${e}`,"load end",Cn(w)),f&&(d==null||d({app_id:f,instance_id:e,url:w})),te(1500)},onContentProcessDidTerminate:()=>{Ce(e),Le(e),qe(e),y.current=!1,$(!1),T(h=>h+1)},onRenderProcessGone:()=>(Ce(e),Le(e),qe(e),y.current=!1,$(!1),T(h=>h+1),!0),style:he.webview},_e):null,(S==null?void 0:S.layout)===ge.full&&Y(An,{scanner:S}),p&&Y(ts,{visible:!v||!ee,interactive:E,children:Y(es,{splash:a,app:p.app,is_dark:o,error:E,has_bundle:!!v,retry:Ht})})]})}),es=On.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Mn(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return Y(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),ts=({visible:e,interactive:t,children:n})=>{let o=be(new En.Value(e?1:0)).current,[r,i]=Te(e);return le(()=>{if(e){i(!0),o.setValue(1);return}let a=En.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?Y(En.View,{style:[kn.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},fr=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return Ye(Rn,{style:[he.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[Y(Rn,{style:[he.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?Y(Gi,{source:{uri:e.icon},style:he.splash_icon_image}):Y(bt,{style:he.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),Y(bt,{style:[he.splash_name,{color:i}],children:e.name}),n==="error"?Ye(Tn,{children:[Y(bt,{style:he.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),Y(Yi,{activeOpacity:.7,style:[he.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:Y(bt,{style:[he.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):Ye(Tn,{children:[Y(Hi,{style:he.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&Ye(bt,{style:he.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},mr=(e,t)=>{let n=be(t),o=be(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},ns=({container:e,splash:t=fr,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{mr("container",e),mr("splash",t);let l=e,s=q(ae,S=>S.active_key),d=be(s);s&&(d.current=s);let u=q(ae,S=>Object.keys(S.instances).join("|")),y=q(ae,S=>{var F;return S.active_key?(F=S.instances[S.active_key])==null?void 0:F.app.name:void 0}),p=zt(()=>u?u.split("|"):[],[u]),[f,C]=Te({}),x=be(Qi()).current;le(()=>{if(!s||!r)return;let S=Ji.addEventListener("hardwareBackPress",()=>(ft(),!0));return()=>S.remove()},[s,r]);let M=Pn(()=>{let S=ae.getState().active_key;S&&C(F=>({...F,[S]:(F[S]||0)+1}))},[]);return p.length?Ye(Tn,{children:[Y(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:ft,reload:M,subscribeWebAtTop:x.subscribe,children:p.map(S=>Y(Zi,{instance_key:S,is_active:s===S,is_front:(s!=null?s:d.current)===S,is_dark:n,reload_tick:f[S]||0,web_at_top:x,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},S))}),Y(sr,{})]}):null},he=kn.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"}}),os=On.memo(ns);import{useCallback as rs,useEffect as is,useState as Wt}from"react";var yr=e=>`changelog_seen:${e}`,ss=10*1e3,wr=e=>O().storage.getString(yr(e))||null,br=(e,t=(n=>(n=L(e))==null?void 0:n.version)())=>{t&&O().storage.setString(yr(e),t)},as=e=>{var o;let t=(o=L(e))==null?void 0:o.version;if(!t)return null;let n=wr(e);return n?fn(t,n)>0?{app_id:e,from:n,to:t}:null:(br(e,t),null)},cs=e=>{var t,n,o;return(o=(n=(t=k.getState().catalog[e])==null?void 0:t.channel)!=null?n:O().channels[0])!=null?o:"production"},Ar=async(e,{from:t,to:n,channel:o=cs(e)}={})=>{let{client_token:r}=O(),i=new URLSearchParams({channel:o});t&&i.set("from",t),n&&i.set("to",n);let a=new AbortController,c=setTimeout(()=>a.abort(),ss);try{let l=await fetch(`${et}/api/miniapps/${encodeURIComponent(e)}/changelog?${i}`,{headers:{Authorization:`Bearer ${r}`},signal:a.signal});if(!l.ok)throw new Error(`changelog ${e} ${l.status}`);return(await l.json()).versions}finally{clearTimeout(c)}},ls=(e,{from:t,to:n,enabled:o=!0}={})=>{let[r,i]=Wt([]),[a,c]=Wt(!1),[l,s]=Wt(),[d,u]=Wt(0),y=rs(()=>u(p=>p+1),[]);return is(()=>{if(!e||!o)return;let p=!0;return c(!0),s(void 0),Ar(e,{from:t,to:n}).then(f=>{p&&i(f)}).catch(f=>{var C;p&&s(String((f==null?void 0:f.name)==="AbortError"?"timeout":(C=f==null?void 0:f.message)!=null?C:f))}).finally(()=>{p&&c(!1)}),()=>{p=!1}},[e,t,n,o,d]),{versions:r,loading:a,error:l,reload:y}};export{re as CodeType,fr as DefaultMiniAppSplash,et as MINIAPP_PLATFORM_URL,os as MiniAppHost,g as MiniAppHostError,He as ScannerEndReason,en as ScannerEvent,ge as ScannerLayout,at as ScannerMethod,fe as ToastType,ft as closeMiniApp,Sr as configureMiniApp,vr as createMmkvStorage,Nn as createReactNativeBiometrics,_r as createRnfsFileSystem,$t as ensureMiniApp,Ar as fetchMiniAppChangelog,L as getLocalMiniApp,ji as getMiniAppCatalog,wt as getMiniAppCatalogEntry,wr as getMiniAppChangelogSeen,Fi as getMiniAppStatuses,dr as getMiniAppUpdate,as as getPendingChangelog,ii as installBundledMiniApp,br as markMiniAppChangelogSeen,Li as onMiniAppEvent,xi as openMiniApp,Bi as pauseMiniApp,$i as pauseMiniAppDownloads,Ei as preloadMiniApp,Ce as releaseSpeechFor,Vi as restoreMiniApp,qi as resumeMiniApp,zi as resumeMiniAppDownloads,ai as sendEventToWeb,xn as syncMiniAppCatalog,Ui as uninstallMiniApp,Wi as updateMiniApp,Zn as uploadToUrl,ls as useMiniAppChangelog,Mn as useMiniAppDownload,Ii as useMiniAppDownloadsPaused};
|
package/docs/MINIAPP_README.md
CHANGED
|
@@ -783,7 +783,8 @@ const offError = onSpeech('speech.error', error => console.error(error.code, err
|
|
|
783
783
|
const offEnd = onSpeech('speech.end', () => console.log('Phiên đã kết thúc'));
|
|
784
784
|
|
|
785
785
|
async function startListening() {
|
|
786
|
-
|
|
786
|
+
// mode 's2t': chỉ chuyển giọng nói thành chữ. Bỏ mode (mặc định 'voice') = mở trợ lý voice AI của app chủ.
|
|
787
|
+
try { await startSpeech({ lang: 'vi-VN', mode: 's2t' }); }
|
|
787
788
|
catch (error) { console.error('Không thể bắt đầu:', error); }
|
|
788
789
|
}
|
|
789
790
|
async function stopListening() {
|
package/docs/NATIVE_APIS.md
CHANGED
|
@@ -165,7 +165,8 @@ const offError = onSpeech('speech.error', error => console.error(error.code, err
|
|
|
165
165
|
const offEnd = onSpeech('speech.end', () => console.log('Phiên đã kết thúc'));
|
|
166
166
|
|
|
167
167
|
async function startListening() {
|
|
168
|
-
|
|
168
|
+
// mode 's2t': chỉ chuyển giọng nói thành chữ. Bỏ mode (mặc định 'voice') = mở trợ lý voice AI của app chủ.
|
|
169
|
+
try { await startSpeech({ lang: 'vi-VN', mode: 's2t' }); }
|
|
169
170
|
catch (error) { console.error('Không thể bắt đầu:', error); }
|
|
170
171
|
}
|
|
171
172
|
async function stopListening() {
|
package/docs/SPEECH.md
CHANGED
|
@@ -68,6 +68,14 @@ Package tự gọi xin quyền runtime khi bắt đầu; app chủ không phải
|
|
|
68
68
|
|
|
69
69
|
Giữ cấu hình `configureMiniApp(...)` và mount `MiniAppHost` như [hướng dẫn chính](MINIAPP_README.md#bắt-đầu-nhanh). Không cần thêm `bridge.handlers`, `bridge.onWebEvent` hay tự xin quyền speech. Nếu app có bridge riêng cho thanh toán, toast hoặc event ghi chú thì vẫn giữ các tuỳ chọn đó.
|
|
70
70
|
|
|
71
|
+
### Trợ lý voice AI (`bridge.voice`)
|
|
72
|
+
|
|
73
|
+
App có trợ lý voice riêng thì truyền provider vào `bridge.voice` (bản cũ dùng `bridge.speech` vẫn chạy như nhau; có cả hai thì `voice` được ưu tiên). `startSpeech()` mặc định (`mode: 'voice'`) đi vào provider này. Mini app chỉ cần chuyển giọng nói thành chữ gọi `startSpeech({ mode: 's2t' })`: luôn dùng nhận dạng có sẵn, không bật trợ lý voice. `speech.stop` đi về đúng nơi đã nhận lần `speech.start` gần nhất của mini app đó.
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
<MiniAppHost bridge={{ voice: myVoiceAgentProvider }} />
|
|
77
|
+
```
|
|
78
|
+
|
|
71
79
|
## API phía web
|
|
72
80
|
|
|
73
81
|
Cài `@retion-miniapp/sdk@0.8.0` và đăng ký event **trước** khi bắt đầu nghe:
|
|
@@ -90,7 +98,8 @@ const offEnd = onSpeech('speech.end', () => {
|
|
|
90
98
|
|
|
91
99
|
// Gắn hàm này vào nút bắt đầu; không tự bật micro khi mở trang.
|
|
92
100
|
async function startListening() {
|
|
93
|
-
|
|
101
|
+
// mode 's2t': chỉ chuyển giọng nói thành chữ. Bỏ mode (mặc định 'voice') = mở trợ lý voice AI của app chủ.
|
|
102
|
+
try { await startSpeech({ lang: 'vi-VN', mode: 's2t' }); }
|
|
94
103
|
catch (error) { console.error('Không thể bắt đầu:', error); }
|
|
95
104
|
}
|
|
96
105
|
|