@retion-miniapp/react-native 0.13.5 → 0.14.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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -9
- package/dist/index.mjs +12 -9
- package/docs/NATIVE_APIS.md +10 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -711,6 +711,8 @@ interface ScannerOptions {
|
|
|
711
711
|
hint?: string;
|
|
712
712
|
/** Quét liên tiếp: camera ở trên web (top, mặc định) hoặc phủ kín (full). */
|
|
713
713
|
layout?: ScannerLayout;
|
|
714
|
+
/** Layout top: camera nằm đè lên web, web giữ nguyên kích thước (web tự chừa chỗ theo chiều cao host báo). */
|
|
715
|
+
absolute?: boolean;
|
|
714
716
|
}
|
|
715
717
|
interface ScannerResult {
|
|
716
718
|
value: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -711,6 +711,8 @@ interface ScannerOptions {
|
|
|
711
711
|
hint?: string;
|
|
712
712
|
/** Quét liên tiếp: camera ở trên web (top, mặc định) hoặc phủ kín (full). */
|
|
713
713
|
layout?: ScannerLayout;
|
|
714
|
+
/** Layout top: camera nằm đè lên web, web giữ nguyên kích thước (web tự chừa chỗ theo chiều cao host báo). */
|
|
715
|
+
absolute?: boolean;
|
|
714
716
|
}
|
|
715
717
|
interface ScannerResult {
|
|
716
718
|
value: string;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var tr=Object.create;var ut=Object.defineProperty;var nr=Object.getOwnPropertyDescriptor;var or=Object.getOwnPropertyNames;var rr=Object.getPrototypeOf,ir=Object.prototype.hasOwnProperty;var sr=(e,t)=>{for(var n in t)ut(e,n,{get:t[n],enumerable:!0})},fn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of or(t))!ir.call(e,r)&&r!==n&&ut(e,r,{get:()=>t[r],enumerable:!(o=nr(t,r))||o.enumerable});return e};var se=(e,t,n)=>(n=e!=null?tr(rr(e)):{},fn(t||!e||!e.__esModule?ut(n,"default",{value:e,enumerable:!0}):n,e)),ar=e=>fn(ut({},"__esModule",{value:!0}),e);var si={};sr(si,{CodeType:()=>Q,DefaultMiniAppSplash:()=>dn,MINIAPP_PLATFORM_URL:()=>dt,MiniAppHost:()=>er,MiniAppHostError:()=>g,ScannerEndReason:()=>qe,ScannerEvent:()=>_t,ScannerLayout:()=>Me,ScannerMethod:()=>We,ToastType:()=>de,closeMiniApp:()=>Je,configureMiniApp:()=>yn,createMmkvStorage:()=>bn,createReactNativeBiometrics:()=>Ut,createRnfsFileSystem:()=>_n,ensureMiniApp:()=>lt,getLocalMiniApp:()=>B,getMiniAppCatalog:()=>Yo,getMiniAppCatalogEntry:()=>Ge,getMiniAppStatuses:()=>qo,getMiniAppUpdate:()=>pn,installBundledMiniApp:()=>vo,onMiniAppEvent:()=>Bo,openMiniApp:()=>Lo,pauseMiniApp:()=>jo,pauseMiniAppDownloads:()=>Jo,preloadMiniApp:()=>Fo,releaseSpeechFor:()=>ve,restoreMiniApp:()=>Wo,resumeMiniApp:()=>Ho,resumeMiniAppDownloads:()=>Go,sendEventToWeb:()=>Eo,syncMiniAppCatalog:()=>Lt,uninstallMiniApp:()=>zo,updateMiniApp:()=>Ko,uploadToUrl:()=>$t,useMiniAppDownload:()=>kt,useMiniAppDownloadsPaused:()=>Vo});module.exports=ar(si);var dt="https://retion-miniapp-platform.vercel.app",Ue=null,hn=new Set,yn=e=>{Ue=e,hn.forEach(t=>t())},q=()=>{if(!Ue)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ue},wn=e=>{hn.add(e),Ue&&e()},ue=(...e)=>{Ue!=null&&Ue.debug&&console.log("[miniapp]",...e)};var _n=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:c})=>r==null?void 0:r(l,c)});return{promise:a.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),bn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var A=se(require("react")),L=require("react-native"),Qo=se(require("react-native-webview"));var nt=require("react-native");var Ut=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),gt,Vt=()=>(gt||(gt=import("react-native-biometrics").then(({default:e})=>Ut(new e({allowDeviceCredentials:!1}))).catch(e=>{throw gt=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),gt);var Se=require("react-native");var An=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,l]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let c=t[i];if(c!==void 0&&(typeof c!="number"||!Number.isFinite(c)||c<a||c>l))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Sn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(c,s)=>{r||(r=!0,clearTimeout(a),c?o(c):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),l=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!l())return;let c;try{c=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(l()){if(Se.Platform.OS==="android"){let s=Se.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=Se.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,m=await Se.PermissionsAndroid.check(s);if(!l())return;let h=m||await Se.PermissionsAndroid.check(d);if(!l())return;if(!m&&!h){let p=await Se.PermissionsAndroid.requestMultiple([s,d]);if(!l())return;if(p[s]!==Se.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==Se.PermissionsAndroid.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}l()&&c.getCurrentPosition(s=>{l()&&i(void 0,s)},s=>{var m;if(!l())return;let d=(m={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?m:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(c=>i(c))});var qt=require("react-native");var Bt=20,vn=20,Pn=/^[a-z][a-z0-9_-]{0,31}$/,cr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,lr=["low","medium","high"],Ce=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Y=e=>new g("INVALID_PARAMS",e),Qe=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Mn=(e,t)=>{if(e===void 0)return{};if(!Ce(e)||Object.keys(e).length>vn||Object.values(e).some(n=>typeof n!="string"))throw Y(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${vn} key)`);return e},Cn=e=>{var n,o,r,i;if(e!==void 0&&!Ce(e))throw Y("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Pn.test(t.source)))throw Y("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!cr.test(a))))throw Y("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!Qe(t.max_count,1,Bt))throw Y(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Bt}`);if(t.max_size!==void 0&&!Qe(t.max_size,1,Number.MAX_SAFE_INTEGER))throw Y("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Qe(t.concurrency,1,5))throw Y("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:pr(t.process),target:ur(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},pr=e=>{if(e===void 0)return{};if(!Ce(e))throw Y("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Ce(n))throw Y("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!Qe(n[o],1,1e4))throw Y(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw Y("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!Ce(n))throw Y("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!Qe(n.max_duration,1,3600))throw Y("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!lr.includes(n.quality))throw Y("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},ur=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Ce(e))throw Y("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Pn.test(t))throw Y("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Ce(e.params))throw Y("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw Y("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw Y(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Mn(e.headers,"upload.headers"),form_data:Mn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},On=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},dr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=On(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},gr=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},Ye,mr=()=>(Ye!=null||(Ye=import("react-native-image-picker").catch(e=>{throw Ye=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Ye),xn=e=>async({accept:t,max_count:n,process:o})=>{var c,s,d,m,h,p,y,C,R;let r=await mr(),i=gr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(c=o.image)==null?void 0:c.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(m=(d=o.image)==null?void 0:d.quality)!=null?m:.8,videoQuality:(p=(h=o.video)==null?void 0:h.quality)!=null?p:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let T=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(T,(C=l.errorMessage)!=null?C:l.errorCode)}return((R=l.assets)!=null?R:[]).filter(T=>T.uri).map((T,M)=>{var b,K,te;return{uri:T.uri,name:(b=T.fileName)!=null?b:`file_${M+1}`,mime_type:(K=T.type)!=null?K:"application/octet-stream",size:T.fileSize,width:T.width,height:T.height,duration:T.duration,processed:!((te=T.type)!=null&&te.startsWith("video/"))||qt.Platform.OS==="ios"}})},fr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},hr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},yr=e=>async({accept:t,max_count:n})=>{var i,a,l,c;let o=t.map(s=>{var d;return(d=fr[s])!=null?d:hr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,y)=>{var C,R,T;return{uri:p.uri,name:(C=p.name)!=null?C:`file_${y+1}`,mime_type:(R=p.type)!=null?R:"application/octet-stream",size:(T=p.size)!=null?T:void 0}});if(qt.Platform.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let m=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),h=new Map(m.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var y;return{...p,uri:(y=h.get(p.uri))!=null?y:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((c=(l=e.errorCodes)==null?void 0:l.IN_PROGRESS)!=null?c:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},Xe,wr=async e=>(Xe!=null||(Xe=import("@react-native-documents/picker").then(t=>yr(t)).catch(t=>{throw Xe=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await Xe)(e)),kn={library:xn("library"),camera:xn("camera"),document:wr},En={type:"image",label:"\u1EA2nh",accept:["image/*"]},Rn={type:"video",label:"Video",accept:["video/*"]},Tn={library:[En,Rn],camera:[En,Rn],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},Ze,In=()=>(Ze!=null||(Ze=import("react-native-compressor").catch(()=>(Ze=void 0,null))),Ze),Ln=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},_r=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),br={low:640,medium:1280,high:1920},Ar=async(e,{image:t})=>{var o;if(!t||!_r.has(e.mime_type.toLowerCase()))return e;let n=await In();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await Ln(n,r,e.size),processed:!0}}catch{return e}},Sr=async(e,{video:t})=>{var o;let n=await In();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:br[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Ln(n,r,e.size),processed:!0}}catch{return e}},vr={image:Ar,video:Sr},Mr=(e,t)=>t.split(".").reduce((n,o)=>Ce(n)?n[o]:void 0,e),$t=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let l=new XMLHttpRequest,c=new FormData;Object.entries(a.form_data).forEach(([m,h])=>c.append(m,h)),c.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();o.addEventListener("abort",s);let d=m=>{o.removeEventListener("abort",s),m()};l.open("POST",a.url),Object.entries(a.headers).forEach(([m,h])=>l.setRequestHeader(m,h)),l.upload.onprogress=m=>n(m.loaded,m.total||e.size||0),l.onload=()=>d(()=>{let m=l.responseText;try{m=JSON.parse(l.responseText)}catch{}if(l.status<200||l.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${l.status}`));return}let h=Mr(m,a.url_field);if(typeof h!="string"||!h){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:h,response:m})}),l.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),l.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),l.send(c)}),Fn=e=>{var o,r;let t={...kn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:$t};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},Dn=e=>{let{sources:t,targets:n}=Fn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===kn[i]&&Tn[i]).map(i=>[i,Tn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Bt}},ft=new Map,Nn=(e,t)=>`${e}:${t}`,xr=0,Un=(e,t)=>{var n;typeof t=="string"&&((n=ft.get(Nn(e,t)))==null||n.abort())},Ve=e=>{for(let[t,n]of ft)t.startsWith(`${e}:`)&&n.abort()},mt=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Er=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},Vn=async(e,t)=>{var c;let{sources:n,targets:o}=Fn(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,l=Nn(t.instance_id,(c=t.task_id)!=null?c:`auto-${++xr}`);ft.set(l,a);try{return await Rr(e,t,r,i,a.signal)}finally{ft.delete(l)}},Rr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:l=m=>m()},c,s,d)=>{var w,x,J;let m={app_id:n!=null?n:"",instance_id:t,context:{...(w=o==null?void 0:o())!=null?w:{}}},h=(await l(()=>c({accept:e.accept,max_count:e.max_count,process:e.process,caller:m}))).slice(0,e.max_count);if(d.aborted)throw mt();if(!h.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],y=h.filter(P=>dr(P,e.accept)?!0:(p.push({name:P.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${P.mime_type||On(P.name)}`}),!1)),C=y.map(()=>0),R=y.map(P=>{var F;return(F=P.size)!=null?F:0}),T=0,M=0,b=(P=!1)=>{if(!a||!r)return;let F=Date.now();if(!P&&F-M<200)return;M=F;let N=R.reduce((U,ne)=>U+ne,0),z=C.reduce((U,ne)=>U+ne,0);a("upload.progress",{task_id:r,loaded:z,total:N,percent:N?Math.min(100,Math.round(z/N*100)):0,done_count:T,count:y.length})},K=[],te=0,re=async()=>{var P,F,N;for(;te<y.length;){let z=te++,U=y[z];try{if(d.aborted)throw mt();let ne=U.mime_type.startsWith("image/")?"image":U.mime_type.startsWith("video/")?"video":void 0,De=ne&&!U.processed?(F=(P=i==null?void 0:i.processors)==null?void 0:P[ne])!=null?F:vr[ne]:void 0;if(De&&(U=await De(U,e.process),R[z]=(N=U.size)!=null?N:R[z],d.aborted))throw mt();if(e.max_size&&U.size&&U.size>e.max_size)throw new g("FILE_TOO_LARGE",`File ${U.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let ye=(Ee,Re)=>{C[z]=Ee,Re&&(R[z]=Re),b()},ie=await s({file:U,target:e.target,onProgress:ye,signal:d,caller:m});if(typeof(ie==null?void 0:ie.url)!="string"||!ie.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Ne,...xe}=ie;K[z]={url:Ne,name:U.name,mime_type:U.mime_type,size:U.size,width:U.width,height:U.height,duration:U.duration,...Object.keys(xe).length?{response:"response"in xe?xe.response:xe}:{}},C[z]=R[z]}catch(ne){p.push(Er(y[z].name,ne))}finally{T++,b(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},re)),d.aborted)throw mt();let Ae=K.filter(P=>!!P);if(!Ae.length){let P=p[0];throw new g((x=P==null?void 0:P.code)!=null?x:"UPLOAD_FAILED",(J=P==null?void 0:P.message)!=null?J:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:Ae,failed:p}};var ht=require("react"),Oe=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},j=(e,t,n=Object.is)=>{let o=(0,ht.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let l=t(i),c=a&&n(a.value,l)?a.value:l;return o.current={state:i,selector:t,value:c},c};return(0,ht.useSyncExternalStore)(e.subscribe,r)};var de={info:"info",success:"success",error:"error"},Tr=200,Bn={info:2e3,success:2e3,error:3e3},et=Oe({message:"",type:de.info,tick:0}),qn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Tr);return o?{message:o,type:Object.values(de).includes(n)?n:de.info}:null},$n=(e,t=de.info)=>{et.setState(n=>({message:e,type:t,tick:n.tick+1}))};var me=require("react-native");var Be=require("react-native");var ge,zn=()=>Be.Platform.OS==="android"&&!!(ge!=null&&ge.requesting_permission),Pr=1500,yt=()=>new Promise(e=>{if(Be.Platform.OS!=="android"||Be.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Pr),o=Be.AppState.addEventListener("change",r=>{r==="active"&&t()})}),zt=e=>{var t;if(ge===e&&(ge=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Be.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Wn=async(e,t,n,o=()=>!0)=>{var i,a,l,c,s;if(ge)throw new g("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};ge=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let m=d.ExpoSpeechRecognitionModule;if(r.native=m,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let h;try{h=await m.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await yt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!h.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await m.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(m.addListener("result",p=>{var y,C;ge!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(C=(y=p.results[0])==null?void 0:y.transcript)!=null?C:""})}),m.addListener("error",p=>{ge===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),m.addListener("end",()=>{ge===r&&(zt(r),n("speech.end"))})),r.started=!0,m.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(l=t.interimResults)!=null?l:!0,addsPunctuation:(c=t.addsPunctuation)!=null?c:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw zt(r),d}},jn=e=>{let t=ge;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},ve=e=>{let t=ge;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{zt(t)}};var Hn={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},Q={...Hn,all:Object.values(Hn)},We={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},_t={result:"scanner.result",end:"scanner.end"},qe={user:"user",web:"web",closed:"closed",error:"error"},Me={top:"top",full:"full"},$e={once:"once",continuous:"continuous"},Cr=1500,Jn=6e4,V,X=Oe({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Kn=()=>me.Platform.OS==="android"&&!!(V!=null&&V.requesting_permission),jt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r}=e!=null?e:{},i={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(a=>Q.all.includes(a)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");i.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>Jn)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Jn}`);i.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");i.hint=o}if(r!==void 0){if(!Object.values(Me).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},Ht=e=>V!==e?!1:(V=void 0,X.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Or=()=>me.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{me.Linking.openSettings().catch(()=>{})}}]),Yn=async(e,t)=>{if(V)throw new g("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");V=e;let n=()=>{if(e.cancelled||!t())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=me.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let l;try{l=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await yt(),n(),l!=="granted")throw a&&Or(),new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new g("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Jt();n(),X.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw Ht(e),o}},wt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{wt=e==null?void 0:e.insets}).catch(()=>{});var bt=()=>{var e;return wt!=null?wt:{top:me.Platform.OS==="ios"?54:(e=me.StatusBar.currentHeight)!=null?e:0,bottom:me.Platform.OS==="ios"?34:48}},Jt=async()=>{if(me.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},Xn=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:Q.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Cr,hint:n.hint,layout:t===$e.once?Me.full:(i=n.layout)!=null?i:Me.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},Zn=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=Xn(e,$e.once,t);a.onHit=o,a.resolve=r,a.reject=i,Yn(a,n).catch(i)}),Qn=(e,t,n,o=()=>!0,r)=>{let i=Xn(e,$e.continuous,t);return i.emit=n,i.onHit=r,Yn(i,o)},At=(e,t,n)=>{var o,r;if(!X.getState().active){e.cancelled=!0;return}if(Ht(e)){if(e.mode===$e.once){(o=e.reject)==null||o.call(e,t===qe.error?new g("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new g("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,_t.end,n?{reason:t,message:n}:{reason:t})}},eo=e=>{(V==null?void 0:V.owner)===e&&At(V,qe.web)},ke=e=>{(V==null?void 0:V.owner)===e&&At(V,qe.closed)},Gt=()=>{V&&At(V,qe.user)},to=e=>{V&&At(V,qe.error,e)},Kt=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=V;if(!(!o||!X.getState().active))for(let{value:l,type:c}of e){if(!l)continue;let s=o.last_seen.get(l);if(o.last_seen.set(l,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===$e.once){Ht(o),(i=o.resolve)==null||i.call(o,{value:l,type:c});return}X.setState(d=>({last_value:l,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,_t.result,{value:l,type:c})}}},kr={1:Q.code128,2:Q.code39,4:Q.code93,8:Q.codabar,16:Q.dataMatrix,32:Q.ean13,64:Q.ean8,128:Q.itf,256:Q.qr,512:Q.upcA,1024:Q.upcE,2048:Q.pdf417,4096:Q.aztec},Ir=2500,Gn=2e3,Wt=e=>{X.setState({notice:e}),setTimeout(()=>{X.getState().notice===e&&X.setState({notice:null})},Ir)},no=async()=>{var t,n;let e=V;if(!(!e||X.getState().is_picking)){e.requesting_permission=!0,X.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:Gn,maxHeight:Gn}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||V!==e)return;if(r.errorCode||!i){Wt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),l=await a.scan(i);if(V!==e)return;let c=l.map(({value:s,format:d})=>({value:s,code_type:kr[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!c.length){Wt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Kt(c,Date.now(),!0)}catch{V===e&&Wt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await yt(),e.requesting_permission=!1,V===e&&X.setState({is_picking:!1})}}};var vt=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},oo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===vt&&typeof t.method=="string"?t:null}catch{return null}},ot=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,ro=(e,t)=>ot({id:e,result:t}),io=(e,t)=>ot({id:e,error:{code:t.code,message:t.message}}),so=(e,t)=>ot({event:e,data:t}),Xt=e=>ot({event:"context",data:e});var ao=()=>`(function () {
|
|
1
|
+
"use strict";var ar=Object.create;var ht=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var lr=Object.getOwnPropertyNames;var pr=Object.getPrototypeOf,ur=Object.prototype.hasOwnProperty;var dr=(e,t)=>{for(var n in t)ht(e,n,{get:t[n],enumerable:!0})},An=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of lr(t))!ur.call(e,r)&&r!==n&&ht(e,r,{get:()=>t[r],enumerable:!(o=cr(t,r))||o.enumerable});return e};var le=(e,t,n)=>(n=e!=null?ar(pr(e)):{},An(t||!e||!e.__esModule?ht(n,"default",{value:e,enumerable:!0}):n,e)),gr=e=>An(ht({},"__esModule",{value:!0}),e);var gi={};dr(gi,{CodeType:()=>Q,DefaultMiniAppSplash:()=>wn,MINIAPP_PLATFORM_URL:()=>yt,MiniAppHost:()=>sr,MiniAppHostError:()=>m,ScannerEndReason:()=>ze,ScannerEvent:()=>Mt,ScannerLayout:()=>pe,ScannerMethod:()=>He,ToastType:()=>fe,closeMiniApp:()=>Ke,configureMiniApp:()=>vn,createMmkvStorage:()=>En,createReactNativeBiometrics:()=>zt,createRnfsFileSystem:()=>xn,ensureMiniApp:()=>gt,getLocalMiniApp:()=>B,getMiniAppCatalog:()=>nr,getMiniAppCatalogEntry:()=>Ye,getMiniAppStatuses:()=>Jo,getMiniAppUpdate:()=>hn,installBundledMiniApp:()=>Po,onMiniAppEvent:()=>Ho,openMiniApp:()=>Bo,pauseMiniApp:()=>Xo,pauseMiniAppDownloads:()=>Qo,preloadMiniApp:()=>qo,releaseSpeechFor:()=>Re,restoreMiniApp:()=>Yo,resumeMiniApp:()=>Zo,resumeMiniAppDownloads:()=>er,sendEventToWeb:()=>ko,syncMiniAppCatalog:()=>Vt,uninstallMiniApp:()=>Ko,updateMiniApp:()=>tr,uploadToUrl:()=>Jt,useMiniAppDownload:()=>Nt,useMiniAppDownloadsPaused:()=>jo});module.exports=gr(gi);var yt="https://retion-miniapp-platform.vercel.app",Be=null,Sn=new Set,vn=e=>{Be=e,Sn.forEach(t=>t())},q=()=>{if(!Be)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Be},Mn=e=>{Sn.add(e),Be&&e()},me=(...e)=>{Be!=null&&Be.debug&&console.log("[miniapp]",...e)};var xn=(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)}}}),En=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var A=le(require("react")),L=require("react-native"),ir=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,Wt=()=>(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 Rn=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 Ht=require("react-native");var jt=20,Pn=20,Fn=/^[a-z][a-z0-9_-]{0,31}$/,mr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,fr=["low","medium","high"],ke=e=>!!e&&typeof e=="object"&&!Array.isArray(e),K=e=>new m("INVALID_PARAMS",e),ot=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Cn=(e,t)=>{if(e===void 0)return{};if(!ke(e)||Object.keys(e).length>Pn||Object.values(e).some(n=>typeof n!="string"))throw K(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Pn} key)`);return e},Dn=e=>{var n,o,r,i;if(e!==void 0&&!ke(e))throw K("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Fn.test(t.source)))throw K("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"||!mr.test(a))))throw K("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,jt))throw K(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${jt}`);if(t.max_size!==void 0&&!ot(t.max_size,1,Number.MAX_SAFE_INTEGER))throw K("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!ot(t.concurrency,1,5))throw K("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:hr(t.process),target:yr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},hr=e=>{if(e===void 0)return{};if(!ke(e))throw K("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!ke(n))throw K("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 K(`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 K("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 K("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!ot(n.max_duration,1,3600))throw K("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!fr.includes(n.quality))throw K("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},yr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!ke(e))throw K("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Fn.test(t))throw K("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 K("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 K("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 K(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Cn(e.headers,"upload.headers"),form_data:Cn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Nn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},wr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Nn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},br=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,_r=()=>(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),On=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,y,u,w,I,T;let r=await _r(),i=br(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(y=o.video)==null?void 0:y.quality)!=null?u:"medium",durationLimit:(w=o.video)==null?void 0:w.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let E=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(E,(I=c.errorMessage)!=null?I:c.errorCode)}return((T=c.assets)!=null?T:[]).filter(E=>E.uri).map((E,M)=>{var N,$,te;return{uri:E.uri,name:(N=E.fileName)!=null?N:`file_${M+1}`,mime_type:($=E.type)!=null?$:"application/octet-stream",size:E.fileSize,width:E.width,height:E.height,duration:E.duration,processed:!((te=E.type)!=null&&te.startsWith("video/"))||Ht.Platform.OS==="ios"}})},Ar={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},Sr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},vr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=Ar[s])!=null?g:Sr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,w)=>{var I,T,E;return{uri:u.uri,name:(I=u.name)!=null?I:`file_${w+1}`,mime_type:(T=u.type)!=null?T:"application/octet-stream",size:(E=u.size)!=null?E:void 0}});if(Ht.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,Mr=async e=>(tt!=null||(tt=import("@react-native-documents/picker").then(t=>vr(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)),Un={library:On("library"),camera:On("camera"),document:Mr},kn={type:"image",label:"\u1EA2nh",accept:["image/*"]},In={type:"video",label:"Video",accept:["video/*"]},Ln={library:[kn,In],camera:[kn,In],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},nt,Vn=()=>(nt!=null||(nt=import("react-native-compressor").catch(()=>(nt=void 0,null))),nt),Bn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},xr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Er={low:640,medium:1280,high:1920},Rr=async(e,{image:t})=>{var o;if(!t||!xr.has(e.mime_type.toLowerCase()))return e;let n=await Vn();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 Bn(n,r,e.size),processed:!0}}catch{return e}},Tr=async(e,{video:t})=>{var o;let n=await Vn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Er[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Bn(n,r,e.size),processed:!0}}catch{return e}},Pr={image:Rr,video:Tr},Cr=(e,t)=>t.split(".").reduce((n,o)=>ke(n)?n[o]:void 0,e),Jt=({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=Cr(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)}),qn=e=>{var o,r;let t={...Un};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:Jt};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}},$n=e=>{let{sources:t,targets:n}=qn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Un[i]&&Ln[i]).map(i=>[i,Ln[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:jt}},_t=new Map,zn=(e,t)=>`${e}:${t}`,Or=0,Wn=(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"),kr=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},jn=async(e,t)=>{var l;let{sources:n,targets:o}=qn(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-${++Or}`);_t.set(c,a);try{return await Ir(e,t,r,i,a.signal)}finally{_t.delete(c)}},Ir=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,ne;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(P=>wr(P,e.accept)?!0:(u.push({name:P.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${P.mime_type||Nn(P.name)}`}),!1)),I=w.map(()=>0),T=w.map(P=>{var ce;return(ce=P.size)!=null?ce:0}),E=0,M=0,N=(P=!1)=>{if(!a||!r)return;let ce=Date.now();if(!P&&ce-M<200)return;M=ce;let _e=T.reduce((O,oe)=>O+oe,0),G=I.reduce((O,oe)=>O+oe,0);a("upload.progress",{task_id:r,loaded:G,total:_e,percent:_e?Math.min(100,Math.round(G/_e*100)):0,done_count:E,count:w.length})},$=[],te=0,Te=async()=>{var P,ce,_e;for(;te<w.length;){let G=te++,O=w[G];try{if(g.aborted)throw bt();let oe=O.mime_type.startsWith("image/")?"image":O.mime_type.startsWith("video/")?"video":void 0,H=oe&&!O.processed?(ce=(P=i==null?void 0:i.processors)==null?void 0:P[oe])!=null?ce:Pr[oe]:void 0;if(H&&(O=await H(O,e.process),T[G]=(_e=O.size)!=null?_e:T[G],g.aborted))throw bt();if(e.max_size&&O.size&&O.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${O.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Z=(je,xe)=>{I[G]=je,xe&&(T[G]=xe),N()},re=await s({file:O,target:e.target,onProgress:Z,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;$[G]={url:ve,name:O.name,mime_type:O.mime_type,size:O.size,width:O.width,height:O.height,duration:O.duration,...Object.keys(Me).length?{response:"response"in Me?Me.response:Me}:{}},I[G]=T[G]}catch(oe){u.push(kr(w[G].name,oe))}finally{E++,N(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,w.length)},Te)),g.aborted)throw bt();let ae=$.filter(P=>!!P);if(!ae.length){let P=u[0];throw new m((x=P==null?void 0:P.code)!=null?x:"UPLOAD_FAILED",(ne=P==null?void 0:P.message)!=null?ne:"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)})}},W=(e,t,n=Object.is)=>{let o=(0,At.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return(0,At.useSyncExternalStore)(e.subscribe,r)};var fe={info:"info",success:"success",error:"error"},Lr=200,Hn={info:2e3,success:2e3,error:3e3},rt=Ie({message:"",type:fe.info,tick:0}),Jn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Lr);return o?{message:o,type:Object.values(fe).includes(n)?n:fe.info}:null},Gn=(e,t=fe.info)=>{rt.setState(n=>({message:e,type:t,tick:n.tick+1}))};var ye=require("react-native");var $e=require("react-native");var he,Kn=()=>$e.Platform.OS==="android"&&!!(he!=null&&he.requesting_permission),Fr=1500,St=()=>new Promise(e=>{if($e.Platform.OS!=="android"||$e.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Fr),o=$e.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Gt=e=>{var t;if(he===e&&(he=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&$e.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Yn=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(he)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};he=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await St(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var w,I;he!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(I=(w=u.results[0])==null?void 0:w.transcript)!=null?I:""})}),d.addListener("error",u=>{he===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{he===r&&(Gt(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 Gt(r),g}},Xn=e=>{let t=he;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{let t=he;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Gt(t)}};var Zn={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},Q={...Zn,all:Object.values(Zn)},He={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Mt={result:"scanner.result",end:"scanner.end"},ze={user:"user",web:"web",closed:"closed",error:"error"},pe={top:"top",full:"full"},Le={once:"once",continuous:"continuous"},Dr=1500,Qn=6e4,V,Y=Ie({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),to=()=>ye.Platform.OS==="android"&&!!(V!=null&&V.requesting_permission),Yt=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=>Q.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>Qn)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Qn}`);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},Xt=e=>V!==e?!1:(V=void 0,Y.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Nr=()=>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(()=>{})}}]),no=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 St(),n(),c!=="granted")throw a&&Nr(),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 Zt();n(),Y.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 Xt(e),o}},vt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{vt=e==null?void 0:e.insets}).catch(()=>{});var xt=()=>{var e;return vt!=null?vt:{top:ye.Platform.OS==="ios"?54:(e=ye.StatusBar.currentHeight)!=null?e:0,bottom:ye.Platform.OS==="ios"?34:48}},Zt=async()=>{if(ye.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},oo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:Q.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Dr,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}},ro=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=oo(e,Le.once,t);a.onHit=o,a.resolve=r,a.reject=i,no(a,n).catch(i)}),io=(e,t,n,o=()=>!0,r)=>{let i=oo(e,Le.continuous,t);return i.emit=n,i.onHit=r,no(i,o)},Et=(e,t,n)=>{var o,r;if(!Y.getState().active){e.cancelled=!0;return}if(Xt(e)){if(e.mode===Le.once){(o=e.reject)==null||o.call(e,t===ze.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Mt.end,n?{reason:t,message:n}:{reason:t})}},so=e=>{(V==null?void 0:V.owner)===e&&Et(V,ze.web)},Fe=e=>{(V==null?void 0:V.owner)===e&&Et(V,ze.closed)},Qt=()=>{V&&Et(V,ze.user)},ao=e=>{V&&Et(V,ze.error,e)},en=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=V;if(!(!o||!Y.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){Xt(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}Y.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,Mt.result,{value:c,type:l})}}},Ur={1:Q.code128,2:Q.code39,4:Q.code93,8:Q.codabar,16:Q.dataMatrix,32:Q.ean13,64:Q.ean8,128:Q.itf,256:Q.qr,512:Q.upcA,1024:Q.upcE,2048:Q.pdf417,4096:Q.aztec},Vr=2500,eo=2e3,Kt=e=>{Y.setState({notice:e}),setTimeout(()=>{Y.getState().notice===e&&Y.setState({notice:null})},Vr)},co=async()=>{var t,n;let e=V;if(!(!e||Y.getState().is_picking)){e.requesting_permission=!0,Y.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:eo,maxHeight:eo}),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){Kt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(V!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:Ur[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){Kt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}en(l,Date.now(),!0)}catch{V===e&&Kt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await St(),e.requesting_permission=!1,V===e&&Y.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},lo=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;`,po=(e,t)=>at({id:e,result:t}),uo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),go=(e,t)=>at({event:e,data:t}),nn=e=>at({event:"context",data:e});var mo=()=>`(function () {
|
|
2
2
|
var post = function (level, args) {
|
|
3
3
|
try {
|
|
4
4
|
var parts = [];
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
else if (typeof a === 'object') { try { parts.push(JSON.stringify(a).slice(0, 800)); } catch (e) { parts.push(String(a)); } }
|
|
9
9
|
else { parts.push(String(a)); }
|
|
10
10
|
}
|
|
11
|
-
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${
|
|
11
|
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'log', level: level, text: parts.join(' ') }));
|
|
12
12
|
} catch (e) {}
|
|
13
13
|
};
|
|
14
14
|
['log', 'info', 'warn', 'error'].forEach(function (level) {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
window.addEventListener('unhandledrejection', function (e) { post('error', ['[unhandledrejection]', e.reason]); });
|
|
20
20
|
// Kh\xF4ng log query (c\xF3 th\u1EC3 ch\u1EE9a token) \u2014 ch\u1EC9 \u0111\u01B0\u1EDDng d\u1EABn + route.
|
|
21
21
|
post('info', ['[page] ' + location.pathname + location.hash]);
|
|
22
|
-
})(); true;`,
|
|
22
|
+
})(); true;`,fo=()=>`(function () {
|
|
23
23
|
function atTop(el) {
|
|
24
24
|
for (var n = el; n && n !== document.documentElement; n = n.parentElement) {
|
|
25
25
|
if (n.scrollTop > 0) { return false; }
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
function report(at_top) {
|
|
31
31
|
if (at_top === last) { return; }
|
|
32
32
|
last = at_top;
|
|
33
|
-
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${
|
|
33
|
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'touchAtTop', at_top: at_top }));
|
|
34
34
|
}
|
|
35
35
|
document.addEventListener('touchstart', function (e) { report(atTop(e.target)); }, { capture: true, passive: true });
|
|
36
36
|
// Cu\u1ED9n r\u1EDDi \u0111\u1EA7u trang \u2192 b\xE1o ngay, kh\xF4ng \u0111\u1EE3i l\u1EA7n ch\u1EA1m sau (tr\xE1nh host d\xF9ng gi\xE1 tr\u1ECB c\u0169 "\u0111ang \u1EDF \u0111\u1EA7u").
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
var el = e.target === document ? document.documentElement : e.target;
|
|
39
39
|
if (el && el.scrollTop > 0) { report(false); }
|
|
40
40
|
}, { capture: true, passive: true });
|
|
41
|
-
})(); true;`,
|
|
41
|
+
})(); true;`,ho=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,11 +59,14 @@
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,yo=e=>at({event:e}),wo=(e,t)=>{let n=bo(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${nn(e)}`},bo=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),_o=(e,t={})=>{let n=bo(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;`},Ao={partner:"partner_token",chatbox:"chatbox_token"},So=(e,t)=>{let n={...e};for(let o of Object.values(Ao))t.includes(o)||delete n[o];return n},tn=new Set,it=async(e,t)=>{if(tn.has(e))throw new m("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);tn.add(e);try{return await t()}finally{tn.delete(e)}},on=e=>`(function () {
|
|
67
|
+
window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
|
|
68
|
+
window.dispatchEvent(new Event('retionscannerheight'));
|
|
69
|
+
})(); true;`,vo=()=>`(function () {
|
|
67
70
|
try {
|
|
68
71
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
69
72
|
if (!AudioCtx) { return; }
|
|
@@ -82,4 +85,4 @@
|
|
|
82
85
|
// iOS c\xF3 th\u1EC3 \u0111\u1EC3 context \u1EDF suspended / interrupted (vd. khi camera m\u1EDF phi\xEAn quay): ch\u1EA1y l\u1EA1i xong m\u1EDBi ph\xE1t.
|
|
83
86
|
if (ctx.state === 'running') { play(); } else { ctx.resume().then(play).catch(function () {}); }
|
|
84
87
|
} catch (e) {}
|
|
85
|
-
})(); true;`,Lr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),St=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},wo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:l,instance_id:c,options:s,emit:d,isActive:m,playBeep:h})=>{var T,M,b,K,te,re,Ae;let p=s==null?void 0:s.handlers,y={app_id:l,instance_id:c,close:a},C=()=>{var w;(w=s==null?void 0:s.haptic)==null||w.call(s,"impactLight"),h==null||h()},R=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let w=An(t);return tt(e,()=>Sn(w,m))}case"speech.start":{if(!d)throw R();let w={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new g("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");w.lang=t.lang}for(let x of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[x])!==void 0){if(typeof t[x]!="boolean")throw new g("INVALID_PARAMS",`${x} ph\u1EA3i l\xE0 boolean`);w[x]=t[x]}return Wn(c,w,d,m)}case"speech.stop":return jn(c);case We.scan:return Zn(c,jt(t),m,C);case We.start:{if(!d)throw R();return Qn(c,jt(t),d,m,C)}case We.stop:return eo(c);case"uploadFiles":{let{task_id:w,...x}=t!=null?t:{};if(w!==void 0&&(typeof w!="string"||!w))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Vn(Cn(x),{instance_id:c,app_id:l,getContext:r,task_id:w,config:s==null?void 0:s.upload,emit:d,exclusivePick:J=>tt("uploadFiles.pick",J)})}case"uploadFiles.cancel":Un(c,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Dn(s==null?void 0:s.upload);case"getBiometricAvailability":return((T=s==null?void 0:s.biometrics)!=null?T:await Vt()).getAvailability();case"authenticateBiometric":{let w=St(t==null?void 0:t.reason,"reason").trim();if(!w||w.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let x=t==null?void 0:t.cancelButtonText;if(x!==void 0&&(typeof x!="string"||!x.trim()||x.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return tt(e,async()=>{var P;return((P=s==null?void 0:s.biometrics)!=null?P:await Vt()).authenticate({reason:w,cancelButtonText:x})})}case"requestPayment":{let w=p==null?void 0:p.requestPayment;if(!w)throw R();let x=t==null?void 0:t.amount;if(typeof x!="number"||!Number.isFinite(x)||x<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let J={...t,amount:x,currency:St(t==null?void 0:t.currency,"currency")};return tt(e,()=>w(J,y))}case"printImage":{let w=p==null?void 0:p.printImage;if(!w)throw R();let x=St(t==null?void 0:t.image,"image");await tt(e,()=>w({image:x},y));return}case"openScreen":if(!(p!=null&&p.openScreen))throw R();await p.openScreen({screen:St(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let w=String((M=t==null?void 0:t.url)!=null?M:"");if(!/^https?:\/\//i.test(w))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(w):nt.Linking.openURL(w));return}case"openLink":{let w=String((b=t==null?void 0:t.url)!=null?b:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(w)||/^(javascript|file|data|about|blob):/i.test(w))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(w):nt.Linking.openURL(w))}catch(x){throw new g("NOT_SUPPORTED",String((te=(K=x==null?void 0:x.message)!=null?K:x)!=null?te:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let w=qn(t);if(!w||(m==null?void 0:m())===!1)return;s!=null&&s.showToast?s.showToast(w.message,{type:w.type}):$n(w.message,w.type);return}case"haptic":{let w=Lr.has(t==null?void 0:t.type)?t.type:"selection";(re=s==null?void 0:s.haptic)==null||re.call(s,w);return}case"getSystemInfo":return{platform:nt.Platform.OS==="ios"?"ios":"android",appVersion:(Ae=s==null?void 0:s.app_version)!=null?Ae:"",theme:i?"dark":"light"};case"getAccessToken":{let w=n().access_token;if(!w)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return w}case"getToken":{let w=t==null?void 0:t.type;if(w==="access"){let P=n().access_token;if(!P)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return P}if(w!=="partner"&&w!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(w)}`);let x=fo[w];if(!o().includes(x))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${x} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let J=w==="partner"?n().partner_token:n().chatbox_token;if(!J)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${x}`);return J}case"getUserInfo":{let w=n().user;if(!w)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return w}case"getPageInfo":{let w=n().page;if(!w)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return w}case"sendMessage":case"insertText":throw new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new g("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var Qt=e=>`bundle:${e}`,en=()=>`${q().file_system.document_dir}/miniapps`,tn=en,nn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${tn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},Zt=e=>{var t;q().storage.setString(Qt(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Fr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,B=e=>{let t=q().storage.getString(Qt(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return nn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Te=e=>q().file_system.exists(e.entry_uri.replace("file://","")),on=async e=>{let t=B(e.app_id);return(t==null?void 0:t.version)===e.version&&await Te(t)},bo=async(e,t)=>{let n=q().file_system,o=`${tn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Ao=async e=>{var t;await((t=it[e])==null?void 0:t.catch(()=>{})),q().storage.setString(Qt(e),""),await q().file_system.remove(`${tn()}/${e}`).catch(()=>{})},je=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},it={},So=(e,t)=>{var i;let o=((i=it[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return it[e]=r,r.then(()=>{it[e]===r&&delete it[e]}),o},Dr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let l=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(l)return l}return 0},vo=({manifest:e,zip_path:t})=>So(e.app_id,async()=>{var i;let n=q().file_system,o=B(e.app_id);if(o&&Dr(o.version,e.version)>=0&&await Te(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=nn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),Zt(e),ue("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),bo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),rn=(e,{base_url:t,onProgress:n}={})=>{let o=q().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new je},c=async()=>{var m;l();let s=B(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Zt(e),B(e.app_id);l();let d=o.download({url:t?Fr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(h,p)=>{var C;let y=p>0?p:(C=e.size)!=null?C:0;y>0&&(n==null||n(Math.min(1,h/y)))}});r=d;try{let{status:h}=await d.promise;if(l(),h!==200)throw new Error(`bundle ${h}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ue("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let p=nn(e.app_id,e.version,e.entry,!!e.context_update,(m=e.permissions)!=null?m:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),Zt(e),bo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(h){throw i?new je:h}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:So(e.app_id,c),cancel:()=>{i=!0,r==null||r.cancel()}}},rt={},Nr=__DEV__?0:60*1e3,_o={},Mo=(e,t)=>{var o,r;let n=B(e);return n&&Date.now()-((o=_o[t])!=null?o:0)<Nr?Promise.resolve(n):((r=rt[e])!=null||(rt[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),l=await rn(a,{base_url:t}).promise;return _o[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),B(e))).finally(()=>{rt[e]=void 0})),rt[e])};var Mt=new Map,xo=(e,t)=>(Mt.set(e,t),()=>{Mt.get(e)===t&&Mt.delete(e)}),Eo=(e,t)=>{let n=Mt.get(e);return n?n(t):!1};var $=require("react"),_=require("react-native");var S=require("react/jsx-runtime"),st="#22C55E",Ur="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Vr=2,Et=18,Br=1600,at=14,qr=2e3,Po=.38,$r=40,Ro=2,zr=8,Wr=2e3,He=2e3,jr=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:at},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:at},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:at},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:at}],To=({color:e})=>(0,S.jsx)(S.Fragment,{children:jr.map((t,n)=>(0,S.jsx)(_.View,{style:[v.corner,t,{borderColor:e}]},n))}),xt=({style:e,children:t,...n})=>{let o=(0,$.useRef)(new _.Animated.Value(1)).current,r=i=>_.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,S.jsx)(_.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,S.jsx)(_.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},an=({scanner:e})=>{var Ke,f;let{vision:t,types:n,mode:o,layout:r,hint:i,glass_view:a}=e,l=r===Me.top,c=t.useCameraDevice("back"),s=(0,$.useRef)(new _.Animated.Value(1)).current,[d,m]=(0,$.useState)(!1),[h,p]=(0,$.useState)(1),y=(0,$.useRef)(null),[C,R]=(0,$.useState)(()=>{let{width:u,height:I}=_.Dimensions.get("window");return{width:u,height:l?I*Po:I,window_y:0}}),T=j(X,u=>u.last_value),M=j(X,u=>u.hit_tick),b=j(X,u=>u.scan_count),K=j(X,u=>u.notice),te=j(X,u=>u.is_picking),re=(0,$.useRef)(null),Ae=bt(),w=Ae.top,x=(0,$.useRef)(new _.Animated.Value(0)).current,J=(0,$.useRef)(new _.Animated.Value(0)).current,P=(0,$.useRef)(new _.Animated.Value(0)).current,F=Math.round(C.width*(l?.8:.78)),N=Math.round(l?C.height*.46:F*.78),z=Math.round((C.height-N)/2),U=Math.round((C.width-F)/2),ne=t.useCodeScanner({codeTypes:n,onCodeScanned:(0,$.useCallback)(u=>Kt(u),[])});(0,$.useEffect)(()=>{let u=_.BackHandler.addEventListener("hardwareBackPress",()=>(Gt(),!0));return()=>u.remove()},[]);let De=(0,$.useRef)(M);(0,$.useEffect)(()=>{if(M===De.current)return;x.setValue(1),P.setValue(1);let u=_.Animated.parallel([_.Animated.timing(x,{toValue:0,duration:450,useNativeDriver:!0}),_.Animated.sequence([_.Animated.delay(qr),_.Animated.timing(P,{toValue:0,duration:250,useNativeDriver:!0})])]);return u.start(),()=>u.stop()},[M,x,P]),(0,$.useEffect)(()=>{let u=oe=>_.Animated.timing(J,{toValue:oe,duration:Br,easing:_.Easing.inOut(_.Easing.quad),useNativeDriver:!0}),I=_.Animated.loop(_.Animated.sequence([u(1),u(0)]));return I.start(),()=>I.stop()},[J]);let ye=(0,$.useCallback)(()=>{_.Animated.timing(s,{toValue:0,duration:220,useNativeDriver:!0}).start()},[s]);(0,$.useEffect)(()=>{let u=setTimeout(ye,Wr);return()=>clearTimeout(u)},[ye]);let[ie,Ne]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let u=requestAnimationFrame(()=>{u=requestAnimationFrame(()=>Ne(!0))});return()=>cancelAnimationFrame(u)},[]);let xe=!!(c!=null&&c.hasTorch),Ee=(Ke=c==null?void 0:c.neutralZoom)!=null?Ke:1,Re=c?Math.min(c.maxZoom/Ee,zr):1,Ft=Ee*Math.min(h,Re),Dt=u=>{var le;let{touches:I}=u.nativeEvent;if(I.length!==2){y.current=null;return}let oe=Math.hypot(I[0].pageX-I[1].pageX,I[0].pageY-I[1].pageY);(le=y.current)!=null||(y.current={distance:oe,level:h}),p(Math.max(1,Math.min(Re,y.current.level*(oe/y.current.distance))))},pt=(0,S.jsx)(_.Text,{style:[v.hint,!!K&&v.hint_notice],numberOfLines:1,children:(f=K!=null?K:i)!=null?f:Ur});return(0,S.jsx)(_.View,{ref:re,onTouchMove:Dt,onTouchEnd:()=>{y.current=null},style:l?v.top:v.full,onLayout:({nativeEvent:{layout:u}})=>{var I;(I=re.current)==null||I.measureInWindow((oe,le)=>{R({width:u.width,height:u.height,window_y:le||0})})},children:(0,S.jsxs)(_.View,{style:v.content,children:[c&&ie&&(0,S.jsx)(t.Camera,{style:_.StyleSheet.absoluteFill,device:c,isActive:!te,codeScanner:ne,torch:d&&xe?"on":"off",zoom:Ft,onPreviewStarted:ye,onError:u=>to(u.message)}),(0,S.jsx)(_.Animated.View,{style:[v.preview_cover,{opacity:s}],pointerEvents:"none"}),C.height>0&&(0,S.jsxs)(_.View,{style:v.overlay,pointerEvents:"none",children:[(0,S.jsx)(_.View,{style:[v.dim_ring,{top:z-He,left:U-He,width:F+He*2,height:N+He*2}]}),(0,S.jsxs)(_.View,{style:{position:"absolute",top:z,left:U,width:F,height:N},children:[(0,S.jsx)(To,{color:"#FFFFFF"}),(0,S.jsx)(_.Animated.View,{style:[_.StyleSheet.absoluteFill,{opacity:x}],children:(0,S.jsx)(To,{color:st})}),(0,S.jsxs)(_.Animated.View,{style:[v.scan_line_wrap,{transform:[{translateY:J.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,N-Et)]})}]}],children:[(0,S.jsx)(_.View,{style:v.scan_glow_outer}),(0,S.jsx)(_.View,{style:v.scan_glow_inner}),(0,S.jsx)(_.View,{style:v.scan_line})]})]}),(0,S.jsx)(_.View,{style:[v.hint_slot,l?{top:0,height:z-6,justifyContent:"flex-end"}:{top:z+N+20}],children:pt}),o===$e.continuous&&!!T&&(0,S.jsx)(_.Animated.View,{style:[v.result_slot,{top:l?z+N-$r:z+N+52},{opacity:P}],children:(0,S.jsxs)(_.View,{style:v.result,children:[(0,S.jsx)(_.View,{style:v.check_badge,children:(0,S.jsx)(_.View,{style:v.check_mark})}),(0,S.jsx)(_.Text,{style:v.result_text,numberOfLines:1,children:T}),(0,S.jsxs)(_.Text,{style:v.result_count,children:["\xB7 ",b," m\xE3"]})]})})]}),C.height>0&&(0,S.jsx)(_.View,{style:[v.close_slot,l?v.close_slot_top:{top:Math.max(12,w-C.window_y+12)}],children:(0,S.jsxs)(xt,{style:[v.close_button,!!a&&v.glass_surface],onPress:Gt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[a&&(0,S.jsx)(a,{style:v.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,S.jsx)(_.View,{style:[v.close_bar,v.close_bar_a]}),(0,S.jsx)(_.View,{style:[v.close_bar,v.close_bar_b]})]})}),(0,S.jsx)(_.View,{style:[v.toolbar_wrap,!l&&{bottom:Ae.bottom+20}],pointerEvents:"box-none",children:(0,S.jsxs)(_.View,{style:[v.toolbar,!!a&&v.glass_surface],children:[a&&(0,S.jsx)(a,{style:v.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,S.jsx)(xt,{style:v.tool,onPress:no,disabled:te,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,S.jsxs)(_.View,{style:v.image_icon,children:[(0,S.jsx)(_.View,{style:v.image_icon_dot}),(0,S.jsx)(_.View,{style:v.image_icon_hill})]})}),!!c&&Re>=Ro&&(0,S.jsx)(xt,{style:[v.tool,h>1&&v.tool_on],onPress:()=>p(u=>u>1?1:Ro),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,S.jsxs)(_.Text,{style:[v.zoom_text,h>1&&v.zoom_text_on],children:[Math.round(h*10)/10,"x"]})}),xe&&(0,S.jsx)(xt,{style:[v.tool,d&&v.tool_on],onPress:()=>m(u=>!u),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:d},children:(0,S.jsx)(_.Text,{style:[v.torch_icon,d&&v.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},Hr="rgba(0,0,0,0.5)",sn=50,v=_.StyleSheet.create({top:{height:`${Po*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:He,borderColor:Hr,borderRadius:He+at},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:Et,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Et,borderRadius:Et/2,backgroundColor:st,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:st,opacity:.2},scan_line:{height:Vr,borderRadius:1,backgroundColor:st},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:sn,height:sn,borderRadius:sn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:st},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var fe=require("react"),E=require("react-native");var H=require("react/jsx-runtime"),cn={[de.info]:"#3B82F6",[de.success]:"#22C55E",[de.error]:"#EF4444"},Co=-120,Rt=E.Platform.OS==="android",Oo=({type:e})=>e===de.success?(0,H.jsx)(E.View,{style:ee.check_mark}):e===de.error?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(E.View,{style:[ee.cross_bar,ee.cross_a]}),(0,H.jsx)(E.View,{style:[ee.cross_bar,ee.cross_b]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(E.View,{style:ee.info_dot}),(0,H.jsx)(E.View,{style:ee.info_bar})]}),ko=()=>{let e=j(et,h=>h.message),t=j(et,h=>h.type),n=j(et,h=>h.tick),o=(0,fe.useRef)(new E.Animated.Value(Co)).current,r=(0,fe.useRef)(new E.Animated.Value(0)).current,i=(0,fe.useRef)(new E.Animated.Value(.92)).current,a=(0,fe.useRef)(new E.Animated.Value(0)).current,[l,c]=(0,fe.useState)(),[s,d]=(0,fe.useState)(!1);(0,fe.useEffect)(()=>{let h=!0;return Jt().then(p=>{h&&p&&c(()=>p)}),()=>{h=!1}},[]);let m=(0,fe.useRef)(n);return(0,fe.useEffect)(()=>{if(n===m.current)return;E.AccessibilityInfo.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let h=E.Animated.sequence([E.Animated.parallel([E.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),E.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),E.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),E.Animated.sequence([E.Animated.delay(90),E.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),E.Animated.delay(Bn[t]),E.Animated.parallel([E.Animated.timing(o,{toValue:Co,duration:240,useNativeDriver:!0}),E.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return h.start(({finished:p})=>{p&&d(!1)}),()=>h.stop()},[n]),s?(0,H.jsx)(E.View,{style:[ee.layer,{top:bt().top+(Rt?12:8)}],pointerEvents:"none",children:(0,H.jsxs)(E.Animated.View,{style:[ee.toast,Rt&&ee.toast_android,!!l&&ee.toast_glass,{opacity:l?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[l&&(0,H.jsx)(l,{style:ee.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Rt?(0,H.jsx)(E.Animated.View,{style:[ee.badge_halo,{backgroundColor:`${cn[t]}33`,transform:[{scale:a}]}],children:(0,H.jsx)(E.View,{style:[ee.badge,{backgroundColor:cn[t]}],children:(0,H.jsx)(Oo,{type:t})})}):(0,H.jsx)(E.Animated.View,{style:[ee.badge,{backgroundColor:cn[t],transform:[{scale:a}]}],children:(0,H.jsx)(Oo,{type:t})}),(0,H.jsx)(E.Text,{style:[ee.message,Rt&&ee.message_android],numberOfLines:2,children:e})]})}):null},ee=E.StyleSheet.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:E.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ae=Oe({active_key:null,instances:{}}),Io=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var l;let a=(l=q().keep_alive)==null?void 0:l.max_webviews;ae.setState(c=>{let s=t!=null?t:e.app_id,d={...c.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},m=Object.keys(d);return a&&a>0&&m.length>a&&m.filter(h=>h!==s).sort((h,p)=>d[h].last_used_at-d[p].last_used_at).slice(0,m.length-a).forEach(h=>{delete d[h]}),i?{active_key:s,instances:d}:{instances:d}})},Lo=e=>Io(e,!0),Fo=e=>Io(e,!1),Je=()=>ae.setState({active_key:null}),Tt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var Do="catalog",Jr="paused_apps",Gr="removed_apps",Kr=10*1e3,Yr=2,Xr=3e3,Zr=()=>{var e;try{return JSON.parse((e=q().storage.getString(Do))!=null?e:"{}")}catch{return{}}},D=Oe({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),No=e=>{var t;return!!((t=q().manual_update)!=null&&t.includes(e))},Ot=new Set,Uo=e=>{let t=new Set,n=()=>q().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=q().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},be=Uo(Jr),Fe=Uo(Gr);wn(()=>{be.load(),Fe.load();let e=Zr(),t={};Object.keys(e).filter(n=>!Fe.has(n)).forEach(n=>{let o=B(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:be.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),D.setState({catalog:e,downloads:t})});var kt=e=>j(D,t=>e?t.downloads[e]:void 0),Vo=()=>j(D,e=>e.pause_reasons.length>0),_e=(...e)=>ue("queue",...e),Z=[],Pe={},O=null,Pt=new Set,ze={},ln=new Set,Ie=e=>{ln.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Bo=e=>(ln.add(e),()=>{ln.delete(e)}),qo=()=>D.getState().downloads,ce=(e,t)=>{let n=!!B(e),o=D.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};D.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Ie({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ie({type:"progress",app_id:e,progress:i.progress,version:i.version})},Ct=(e,t)=>{var n;(n=ze[e])==null||n.forEach(o=>o(t)),delete ze[e]},Qr=()=>D.getState().pause_reasons.length>0,Le=e=>{var l;if(O)return;let t=e?Z.indexOf(e):Qr()?-1:Z.findIndex(c=>!be.has(c));if(t<0||t>=Z.length)return;let[n]=Z.splice(t,1),o=D.getState().catalog[n];if(!o){Ct(n,B(n)),Le();return}let r=Date.now();Pe[n]=((l=Pe[n])!=null?l:0)+1,ce(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=rn(o,{onProgress:c=>{let s=Math.floor(c*100);s!==i&&(i=s,ce(n,{progress:s/100,version:o.version}))}});O={app_id:n,handle:a,forced:!!e},_e("start",n,o.version,e?"(forced)":""),a.promise.then(c=>{_e("installed",n,o.version,`${Date.now()-r}ms`),ce(n,{status:"installed",progress:1,version:o.version}),Ct(n,c)}).catch(c=>{var d;if(c instanceof je){if(Pt.has(n))return;_e("paused",n),Pe[n]-=1,Z.unshift(n),ce(n,{status:be.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=c==null?void 0:c.message)!=null?d:c);if(console.warn("[miniapp-queue] failed",n,s),Pe[n]<Yr){ce(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var m;Z.includes(n)||(O==null?void 0:O.app_id)===n||(Z.push(n),Le((m=ze[n])!=null&&m.length?n:void 0))},Xr);return}ce(n,{status:"failed",progress:0,version:o.version,error:s}),Ct(n,B(n))}).finally(()=>{O=null;let c=Z.find(s=>{var d;return(d=ze[s])==null?void 0:d.length});Le(c)})},It=(e,{front:t=!1}={})=>{if((O==null?void 0:O.app_id)===e)return;let n=Z.indexOf(e);if(n>=0){if(!t)return;Z.splice(n,1)}t?Z.unshift(e):Z.push(e)},ei=async e=>{let{host_id:t,client_token:n}=q(),o=new AbortController,r=setTimeout(()=>o.abort(),Kr);try{let i=`${dt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(c=>({...c,channel:e}))}finally{clearTimeout(r)}},ct=null,Lt=()=>(ct!=null||(ct=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(q().channels.map(ei)),o={};[...n].reverse().flat().forEach(c=>{o[c.app_id]=c});let r=Object.keys(D.getState().catalog).filter(c=>!o[c]);q().storage.setString(Do,JSON.stringify(o)),D.setState({catalog:o}),await Promise.all(r.map(c=>$o(c,{by_user:!1}))),r.forEach(c=>Fe.delete(c));let i=Object.keys(o).filter(c=>!Fe.has(c)),a=[],l={};for(let c of i.map(s=>o[s])){if(await on(c)){ce(c.app_id,{status:"installed",progress:1,version:c.version});continue}let s=B(c.app_id);if(No(c.app_id)&&!Ot.has(c.app_id)&&s&&await Te(s)){ce(c.app_id,{status:"installed",progress:1,version:s.version}),l[c.app_id]={app_id:c.app_id,current_version:s.version,next_version:c.version};continue}a.push(c)}return D.setState({updates:l}),a.forEach(c=>{Pe[c.app_id]=0,ce(c.app_id,{status:be.has(c.app_id)?"paused":"queued",progress:0,version:c.version,error:void 0}),It(c.app_id)}),_e("catalog",i.length,"apps, outdated",a.map(c=>c.app_id),"removed",r,`${Date.now()-e}ms`),Ie({type:"sync_complete",app_ids:i,removed:r}),Object.values(l).forEach(c=>Ie({type:"update_available",...c})),Le(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Ie({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ct=null}})()),ct),$o=async(e,{by_user:t})=>{var r,i,a,l;if(t&&Fe.add(e),Pt.has(e))return;Pt.add(e),be.delete(e);let n=Z.indexOf(e);n>=0&&Z.splice(n,1),(O==null?void 0:O.app_id)===e&&O.handle.cancel();let o=(l=(a=(r=D.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=B(e))==null?void 0:i.version)!=null?l:"";ce(e,{status:"uninstalling",progress:0,version:o}),await Ao(e),Tt(e),D.setState(c=>{let s={...c.downloads};return delete s[e],{downloads:s}}),delete Pe[e],Pt.delete(e),Ct(e,null),_e("uninstalled",e,t?"(user)":"(not in list)"),Ie({type:"uninstalled",app_id:e})},zo=e=>$o(e,{by_user:!0}),Wo=e=>{let t=Ge(e);return t?(Fe.delete(e),(O==null?void 0:O.app_id)===e||Z.includes(e)||(Pe[e]=0,ce(e,{status:be.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),It(e),Le(),_e("restore",e)),!0):!1},jo=e=>{if(be.has(e))return;if(be.add(e),_e("pause app",e),(O==null?void 0:O.app_id)===e&&!O.forced){O.handle.cancel();return}let t=D.getState().downloads[e];Z.includes(e)&&t&&ce(e,{status:"paused",progress:0,version:t.version})},Ho=e=>{if(!be.delete(e))return;_e("resume app",e);let t=D.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!Z.includes(e)&&Ge(e)&&(Pe[e]=0,It(e)),Z.includes(e)&&t&&ce(e,{status:"queued",progress:0,version:t.version}),Le()},Jo=e=>{let{pause_reasons:t}=D.getState();t.includes(e)||(D.setState({pause_reasons:[...t,e]}),_e("pause",e),t.length===0&&Ie({type:"pause_change",paused:!0,reasons:[e]}),O&&!O.forced&&O.handle.cancel())},Go=e=>{let{pause_reasons:t}=D.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);D.setState({pause_reasons:n}),_e("resume",e),n.length===0&&Ie({type:"pause_change",paused:!1,reasons:n}),Le()},pn=e=>D.getState().updates[e],Ko=async e=>{var n,o;let t=pn(e);Ot.add(e);try{let r=await lt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ge(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(D.setState(a=>{var c;let l={...a.updates};return delete l[e],{updates:l,apply_ticks:{...a.apply_ticks,[e]:((c=a.apply_ticks[e])!=null?c:0)+1}}}),_e("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Ot.delete(e)}},Yo=()=>Object.values(D.getState().catalog).map(e=>({...e,installed:!!B(e.app_id),removed_by_user:Fe.has(e.app_id)})),Ge=e=>D.getState().catalog[e],lt=async e=>{let t=Ge(e);if(!t)return;if(be.delete(e),Fe.delete(e),await on(t))return B(e);let n=B(e);if(No(e)&&!Ot.has(e)&&n&&await Te(n))return n;let o=new Promise(r=>{var i;((i=ze[e])!=null?i:ze[e]=[]).push(r)});return(O==null?void 0:O.app_id)===e?O.forced=!0:(Pe[e]=0,It(e,{front:!0}),O&&!O.forced?O.handle.cancel():Le(e)),o};var k=require("react/jsx-runtime"),un=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Xo=0,ti=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},ni=A.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:l,opaque_background:c,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var pt,Ke;let m=(0,A.useRef)(null),h=(0,A.useRef)(!1),p=j(ae,f=>f.instances[e]),y=p==null?void 0:p.app.app_id,C=p==null?void 0:p.app.manifest_url,R=p==null?void 0:p.context,T=p==null?void 0:p.url_params,M=j(X,f=>{var u;return((u=f.active)==null?void 0:u.owner)===e?f.active:null}),[b,K]=(0,A.useState)(()=>y?B(y):null),[te,re]=(0,A.useState)(!1),[Ae,w]=(0,A.useState)(0),[x,J]=(0,A.useState)(0),[P,F]=(0,A.useState)(!1),N=(0,A.useRef)(null),z=f=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{N.current=null,F(!0)},f)};(0,A.useEffect)(()=>()=>{N.current&&clearTimeout(N.current)},[]),(0,A.useEffect)(()=>{if(!y||!t&&b)return;let f=!0;return re(!1),(async()=>{let u=B(y),I=u?await Te(u):!1;if(!f||(K(I?we=>!we||we.version!==u.version||we.permissions.join(",")!==u.permissions.join(",")?u:we:null),__DEV__&&Date.now()-Xo>1e4&&(Xo=Date.now(),await Lt()),!f))return;let oe=await lt(y),le=oe!==void 0?oe:C?await Mo(y,C):B(y);if(f){if(!le){re(!0);return}K(we=>we!=null?we:le)}})(),()=>{f=!1}},[t,y,C,Ae]),(0,A.useEffect)(()=>xo(e,f=>m.current?(m.current.postMessage(f),!0):!1),[e]);let U=j(D,f=>{let u=y?f.downloads[y]:void 0;return(u==null?void 0:u.status)==="installed"?u.version:void 0});(0,A.useEffect)(()=>{if(t||!y||!b)return;let f=B(y);if(!f||f.version===b.version)return;let u=!0;return Te(f).then(I=>{!u||!I||(ue(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",b.version,"\u2192",f.version),K(f))}),()=>{u=!1}},[t,y,U,b==null?void 0:b.version]);let ne=j(D,f=>{var u;return y&&(u=f.apply_ticks[y])!=null?u:0});(0,A.useEffect)(()=>{if(!ne||!y)return;let f=B(y);if(!f||f.version===(b==null?void 0:b.version))return;let u=!0;return Te(f).then(I=>{!u||!I||(ue(`webview:${e}`,"c\u1EADp nh\u1EADt",b==null?void 0:b.version,"\u2192",f.version),F(!1),K(f))}),()=>{u=!1}},[ne]),(0,A.useEffect)(()=>{var I;let f=(I=q().keep_alive)==null?void 0:I.idle_close_ms;if(t||!f||f<=0)return;let u=setTimeout(()=>{Tt(e)},f);return()=>clearTimeout(u)},[t,e]),(0,A.useEffect)(()=>{r>0&&(re(!1),F(!1),J(f=>f+1),w(f=>f+1))},[r]);let De=(0,A.useRef)(t);(0,A.useEffect)(()=>{var f;De.current!==t&&(De.current=t,h.current&&((f=m.current)==null||f.injectJavaScript(po(t?"resumed":"paused"))))},[t]);let ye=`${(pt=b==null?void 0:b.version)!=null?pt:"none"}:${(Ke=b==null?void 0:b.permissions.join(","))!=null?Ke:""}:${x}`,ie=(0,A.useMemo)(()=>JSON.stringify([R!=null?R:{},T!=null?T:{}]),[R,T]),Ne=(0,A.useMemo)(()=>{var f;return ho(T!=null?T:{},(f=b==null?void 0:b.permissions)!=null?f:[])},[ie,b==null?void 0:b.permissions]),xe=(0,A.useMemo)(()=>mo(R!=null?R:{},Ne)+co()+lo()+(q().debug?ao():""),[Ne]),Ee=(0,A.useRef)(null),Re=(0,A.useRef)(null);(0,A.useEffect)(()=>{var u,I,oe;if(!b)return;if(Re.current!==ye){Re.current=ye,Ee.current=ie;return}if(Ee.current===ie)return;let f=((I=JSON.parse((u=Ee.current)!=null?u:"[]")[0])!=null?I:{}).org_id;if(Ee.current=ie,f===(R==null?void 0:R.org_id)&&h.current){F(!1),z(1500),(oe=m.current)==null||oe.injectJavaScript(uo(R!=null?R:{},Ne));return}F(!1),J(le=>le+1)},[ie,b,ye]),(0,A.useEffect)(()=>(t||(ve(e),ke(e),Ve(e)),()=>{ve(e),ke(e),Ve(e)}),[t,e,ye,r]),(0,A.useEffect)(()=>{let f=L.AppState.addEventListener("change",u=>{u==="background"&&!zn()&&ve(e),u==="background"&&!Kn()&&ke(e)});return()=>f.remove()},[e]);let Ft=(0,A.useCallback)(async f=>{var I,oe,le,we,Nt,gn;let u=oo(f.nativeEvent.data);if(!u){if(y&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(W=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,W)})}catch(W){console.warn("[miniapp] onWebEvent l\u1ED7i",y,W)}return}if(u.method==="log"){let{level:W,text:G}=u;ue(`web:${e}`,W!=null?W:"log",G!=null?G:"");return}if(u.method==="pong"){N.current||F(!0);return}if(u.method==="touchAtTop"){i.emit(!!u.at_top);return}if(u.method==="contextApplied"){N.current&&clearTimeout(N.current),N.current=null,F(!0);return}if(u.method==="ready"){h.current=!0,F(!0);let W=(I=ae.getState().instances[e])==null?void 0:I.context;W&&((oe=m.current)==null||oe.injectJavaScript(Xt(W)));return}try{let W=await wo(u,{getHostData:()=>{var G,pe;return(pe=(G=ae.getState().instances[e])==null?void 0:G.host_data)!=null?pe:{}},getPermissions:()=>{var G,pe;return y?(pe=(G=B(y))==null?void 0:G.permissions)!=null?pe:[]:[]},getContext:()=>{var G,pe;return(pe=(G=ae.getState().instances[e])==null?void 0:G.context)!=null?pe:{}},is_dark:o,close:Je,app_id:y!=null?y:"",instance_id:e,options:l,emit:(G,pe)=>{var mn;(mn=m.current)==null||mn.injectJavaScript(so(G,pe))},playBeep:(le=l==null?void 0:l.playScannerBeep)!=null?le:(()=>{var G;(G=m.current)==null||G.injectJavaScript(yo())}),isActive:()=>ae.getState().active_key===e&&L.AppState.currentState!=="background"});u.id&&((we=m.current)==null||we.injectJavaScript(ro(u.id,W)))}catch(W){if(!u.id)return;let G=W==null?void 0:W.code,pe=W instanceof g?W:new g(typeof G=="string"?G:"HOST_ERROR",String((Nt=W==null?void 0:W.message)!=null?Nt:W));(gn=m.current)==null||gn.injectJavaScript(io(u.id,pe))}},[e,o,y,i,l]),Dt=(0,A.useCallback)(()=>{re(!1),J(f=>f+1),w(f=>f+1)},[]);return(0,k.jsxs)(L.View,{style:[L.StyleSheet.absoluteFill,c&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&he.behind],pointerEvents:t?"auto":"none",children:[(M==null?void 0:M.layout)===Me.top&&(0,k.jsx)(an,{scanner:M}),b?(0,k.jsx)(Qo.default,{ref:m,source:{uri:b.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?en():b.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:xe,onMessage:Ft,bounces:!1,overScrollMode:"never",onLoadStart:f=>{ve(e),ke(e),Ve(e),ue(`webview:${e}`,"load start",un(f.nativeEvent.url)),h.current=!1,F(!1)},onError:f=>{ve(e),ke(e),Ve(e),ue(`webview:${e}`,"load error",un(f.nativeEvent.url),f.nativeEvent.description),re(!0),F(!1)},onLoadEnd:f=>{let u=f.nativeEvent.url;ue(`webview:${e}`,"load end",un(u)),y&&(d==null||d({app_id:y,instance_id:e,url:u})),z(1500)},onContentProcessDidTerminate:()=>{ve(e),ke(e),Ve(e),h.current=!1,F(!1),J(f=>f+1)},onRenderProcessGone:()=>(ve(e),ke(e),Ve(e),h.current=!1,F(!1),J(f=>f+1),!0),style:he.webview},ye):null,(M==null?void 0:M.layout)===Me.full&&(0,k.jsx)(an,{scanner:M}),p&&(0,k.jsx)(ri,{visible:!b||!P,interactive:te,children:(0,k.jsx)(oi,{splash:a,app:p.app,is_dark:o,error:te,has_bundle:!!b,retry:Dt})})]})}),oi=A.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,l=kt(t.app_id),c=o?"error":!r&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return(0,k.jsx)(a,{app:t,is_dark:n,status:c,progress:c==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),ri=({visible:e,interactive:t,children:n})=>{let o=(0,A.useRef)(new L.Animated.Value(e?1:0)).current,[r,i]=(0,A.useState)(e);return(0,A.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=L.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:l})=>{l&&i(!1)}),()=>a.stop()},[e,o]),r?(0,k.jsx)(L.Animated.View,{style:[L.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},dn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,k.jsxs)(L.View,{style:[he.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,k.jsx)(L.View,{style:[he.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,k.jsx)(L.Image,{source:{uri:e.icon},style:he.splash_icon_image}):(0,k.jsx)(L.Text,{style:he.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,k.jsx)(L.Text,{style:[he.splash_name,{color:i}],children:e.name}),n==="error"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.Text,{style:he.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,k.jsx)(L.TouchableOpacity,{activeOpacity:.7,style:[he.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,k.jsx)(L.Text,{style:[he.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.ActivityIndicator,{style:he.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,k.jsxs)(L.Text,{style:he.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},Zo=(e,t)=>{let n=(0,A.useRef)(t),o=(0,A.useRef)(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},ii=({container:e,splash:t=dn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:l})=>{Zo("container",e),Zo("splash",t);let c=e,s=j(ae,M=>M.active_key),d=(0,A.useRef)(s);s&&(d.current=s);let m=j(ae,M=>Object.keys(M.instances).join("|")),h=j(ae,M=>{var b;return M.active_key?(b=M.instances[M.active_key])==null?void 0:b.app.name:void 0}),p=(0,A.useMemo)(()=>m?m.split("|"):[],[m]),[y,C]=(0,A.useState)({}),R=(0,A.useRef)(ti()).current;(0,A.useEffect)(()=>{if(!s||!r)return;let M=L.BackHandler.addEventListener("hardwareBackPress",()=>(Je(),!0));return()=>M.remove()},[s,r]);let T=(0,A.useCallback)(()=>{let M=ae.getState().active_key;M&&C(b=>({...b,[M]:(b[M]||0)+1}))},[]);return p.length?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(c,{visible:!!s,title:h!=null?h:"",is_dark:n,close:Je,reload:T,subscribeWebAtTop:R.subscribe,children:p.map(M=>(0,k.jsx)(ni,{instance_key:M,is_active:s===M,is_front:(s!=null?s:d.current)===M,is_dark:n,reload_tick:y[M]||0,web_at_top:R,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:l},M))}),(0,k.jsx)(ko,{})]}):null},he=L.StyleSheet.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),er=A.default.memo(ii);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppStatuses,getMiniAppUpdate,installBundledMiniApp,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppDownload,useMiniAppDownloadsPaused});
|
|
88
|
+
})(); true;`,Br=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Rt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Mo=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,$,te,Te,ae;let u=s==null?void 0:s.handlers,w={app_id:c,instance_id:l,close:a},I=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),y==null||y()},T=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Rn(t);return it(e,()=>Tn(p,d))}case"speech.start":{if(!g)throw T();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 x of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[x])!==void 0){if(typeof t[x]!="boolean")throw new m("INVALID_PARAMS",`${x} ph\u1EA3i l\xE0 boolean`);p[x]=t[x]}return Yn(l,p,g,d)}case"speech.stop":return Xn(l);case He.scan:return ro(l,Yt(t),d,I);case He.start:{if(!g)throw T();return io(l,Yt(t),g,d,I)}case He.stop:return so(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 jn(Dn(x),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:ne=>it("uploadFiles.pick",ne)})}case"uploadFiles.cancel":Wn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return $n(s==null?void 0:s.upload);case"getBiometricAvailability":return((E=s==null?void 0:s.biometrics)!=null?E:await Wt()).getAvailability();case"authenticateBiometric":{let p=Rt(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 P;return((P=s==null?void 0:s.biometrics)!=null?P:await Wt()).authenticate({reason:p,cancelButtonText:x})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw T();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 ne={...t,amount:x,currency:Rt(t==null?void 0:t.currency,"currency")};return it(e,()=>p(ne,w))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw T();let x=Rt(t==null?void 0:t.image,"image");await it(e,()=>p({image:x},w));return}case"openScreen":if(!(u!=null&&u.openScreen))throw T();await u.openScreen({screen:Rt(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((te=($=x==null?void 0:x.message)!=null?$:x)!=null?te:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=Jn(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):Gn(p.message,p.type);return}case"haptic":{let p=Br.has(t==null?void 0:t.type)?t.type:"selection";(Te=s==null?void 0:s.haptic)==null||Te.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 P=n().access_token;if(!P)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return P}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let x=Ao[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 ne=p==="partner"?n().partner_token:n().chatbox_token;if(!ne)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${x}`);return ne}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 sn=e=>`bundle:${e}`,an=()=>`${q().file_system.document_dir}/miniapps`,cn=an,ln=(e,t,n="index.html",o=!1,r=[])=>{let i=`${cn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},rn=e=>{var t;q().storage.setString(sn(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},qr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,B=e=>{let t=q().storage.getString(sn(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return ln(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Ce=e=>q().file_system.exists(e.entry_uri.replace("file://","")),pn=async e=>{let t=B(e.app_id);return(t==null?void 0:t.version)===e.version&&await Ce(t)},Eo=async(e,t)=>{let n=q().file_system,o=`${cn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Ro=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),q().storage.setString(sn(e),""),await q().file_system.remove(`${cn()}/${e}`).catch(()=>{})},Je=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},To=(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},$r=(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},Po=({manifest:e,zip_path:t})=>To(e.app_id,async()=>{var i;let n=q().file_system,o=B(e.app_id);if(o&&$r(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=ln(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),rn(e),me("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Eo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),un=(e,{base_url:t,onProgress:n}={})=>{let o=q().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,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 rn(e),B(e.app_id);c();let g=o.download({url:t?qr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,u)=>{var I;let w=u>0?u:(I=e.size)!=null?I:0;w>0&&(n==null||n(Math.min(1,y/w)))}});r=g;try{let{status:y}=await g.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else me("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=ln(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),rn(e),Eo(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:To(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},zr=__DEV__?0:60*1e3,xo={},Co=(e,t)=>{var o,r;let n=B(e);return n&&Date.now()-((o=xo[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 un(a,{base_url:t}).promise;return xo[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 Pt=new Map,Oo=(e,t)=>(Pt.set(e,t),()=>{Pt.get(e)===t&&Pt.delete(e)}),ko=(e,t)=>{let n=Pt.get(e);return n?n(t):!1};var F=require("react"),h=require("react-native");var v=require("react/jsx-runtime"),pt="#22C55E",Wr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",jr=2,Ot=18,Hr=1600,ut=14,Jr=2e3,Fo=.38,Gr=40,Io=2,Kr=8,Yr=2e3,Xr=250,Ge=2e3,Zr=[{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}],Lo=({color:e})=>(0,v.jsx)(v.Fragment,{children:Zr.map((t,n)=>(0,v.jsx)(h.View,{style:[S.corner,t,{borderColor:e}]},n))}),Ct=({style:e,children:t,...n})=>{let o=(0,F.useRef)(new h.Animated.Value(1)).current,r=i=>h.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,v.jsx)(h.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,v.jsx)(h.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},gn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var f,_;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===pe.top,y=(0,F.useRef)(new h.Animated.Value(0)).current,u=r.useCameraDevice("back"),w=(0,F.useRef)(new h.Animated.Value(1)).current,[I,T]=(0,F.useState)(!1),[E,M]=(0,F.useState)(1),N=(0,F.useRef)(null),[$,te]=(0,F.useState)(()=>{let{width:b,height:U}=h.Dimensions.get("window");return{width:b,height:d?U*Fo:U,window_y:0}}),Te=W(Y,b=>b.last_value),ae=W(Y,b=>b.hit_tick),p=W(Y,b=>b.scan_count),x=W(Y,b=>b.notice),ne=W(Y,b=>b.is_picking),P=(0,F.useRef)(null),ce=xt(),_e=ce.top,G=(0,F.useRef)(new h.Animated.Value(0)).current,O=(0,F.useRef)(new h.Animated.Value(0)).current,oe=(0,F.useRef)(new h.Animated.Value(0)).current,H=(0,F.useRef)(n);H.current=n,(0,F.useEffect)(()=>{if(!t)return;y.setValue($.height);let b=h.Animated.timing(y,{toValue:0,duration:Xr,easing:h.Easing.out(h.Easing.cubic),useNativeDriver:!1});return b.start(({finished:U})=>{var ie;U&&((ie=H.current)==null||ie.call(H))}),()=>b.stop()},[t,y]);let Z=Math.round($.width*(d?.8:.78)),re=Math.round(d?$.height*.46:Z*.78),ve=Math.round(($.height-re)/2),Me=Math.round(($.width-Z)/2),je=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,F.useCallback)(b=>en(b),[])});(0,F.useEffect)(()=>{let b=h.BackHandler.addEventListener("hardwareBackPress",()=>(Qt(),!0));return()=>b.remove()},[]);let xe=(0,F.useRef)(ae);(0,F.useEffect)(()=>{if(ae===xe.current)return;G.setValue(1),oe.setValue(1);let b=h.Animated.parallel([h.Animated.timing(G,{toValue:0,duration:450,useNativeDriver:!0}),h.Animated.sequence([h.Animated.delay(Jr),h.Animated.timing(oe,{toValue:0,duration:250,useNativeDriver:!0})])]);return b.start(),()=>b.stop()},[ae,G,oe]),(0,F.useEffect)(()=>{let b=ie=>h.Animated.timing(O,{toValue:ie,duration:Hr,easing:h.Easing.inOut(h.Easing.quad),useNativeDriver:!0}),U=h.Animated.loop(h.Animated.sequence([b(1),b(0)]));return U.start(),()=>U.stop()},[O]);let Pe=(0,F.useCallback)(()=>{h.Animated.timing(w,{toValue:0,duration:220,useNativeDriver:!0}).start()},[w]);(0,F.useEffect)(()=>{let b=setTimeout(Pe,Yr);return()=>clearTimeout(b)},[Pe]);let[Xe,Bt]=(0,F.useState)(!1);(0,F.useEffect)(()=>{let b=requestAnimationFrame(()=>{b=requestAnimationFrame(()=>Bt(!0))});return()=>cancelAnimationFrame(b)},[]);let Ve=!!(u!=null&&u.hasTorch),Ze=(f=u==null?void 0:u.neutralZoom)!=null?f:1,Qe=u?Math.min(u.maxZoom/Ze,Kr):1,qt=Ze*Math.min(E,Qe),mt=b=>{var se;let{touches:U}=b.nativeEvent;if(U.length!==2){N.current=null;return}let ie=Math.hypot(U[0].pageX-U[1].pageX,U[0].pageY-U[1].pageY);(se=N.current)!=null||(N.current={distance:ie,level:E}),M(Math.max(1,Math.min(Qe,N.current.level*(ie/N.current.distance))))},ft=(0,v.jsx)(h.Text,{style:[S.hint,!!x&&S.hint_notice],numberOfLines:1,children:(_=x!=null?x:l)!=null?_:Wr});return(0,v.jsx)(h.Animated.View,{ref:P,onTouchMove:mt,onTouchEnd:()=>{N.current=null},pointerEvents:t?"none":"auto",style:d?[S.top,g&&S.top_absolute,t&&{height:y}]:S.full,onLayout:({nativeEvent:{layout:b}})=>{var U;t||(o==null||o(b.height),(U=P.current)==null||U.measureInWindow((ie,se)=>{te({width:b.width,height:b.height,window_y:se||0})}))},children:(0,v.jsxs)(h.View,{style:t?[S.content_closing,{height:$.height}]:S.content,children:[u&&Xe&&(0,v.jsx)(r.Camera,{style:h.StyleSheet.absoluteFill,device:u,isActive:!ne,codeScanner:je,torch:I&&Ve?"on":"off",zoom:qt,onPreviewStarted:Pe,onError:b=>ao(b.message)}),(0,v.jsx)(h.Animated.View,{style:[S.preview_cover,{opacity:w}],pointerEvents:"none"}),$.height>0&&(0,v.jsxs)(h.View,{style:S.overlay,pointerEvents:"none",children:[(0,v.jsx)(h.View,{style:[S.dim_ring,{top:ve-Ge,left:Me-Ge,width:Z+Ge*2,height:re+Ge*2}]}),(0,v.jsxs)(h.View,{style:{position:"absolute",top:ve,left:Me,width:Z,height:re},children:[(0,v.jsx)(Lo,{color:"#FFFFFF"}),(0,v.jsx)(h.Animated.View,{style:[h.StyleSheet.absoluteFill,{opacity:G}],children:(0,v.jsx)(Lo,{color:pt})}),(0,v.jsxs)(h.Animated.View,{style:[S.scan_line_wrap,{transform:[{translateY:O.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,re-Ot)]})}]}],children:[(0,v.jsx)(h.View,{style:S.scan_glow_outer}),(0,v.jsx)(h.View,{style:S.scan_glow_inner}),(0,v.jsx)(h.View,{style:S.scan_line})]})]}),(0,v.jsx)(h.View,{style:[S.hint_slot,d?{top:0,height:ve-6,justifyContent:"flex-end"}:{top:ve+re+20}],children:ft}),a===Le.continuous&&!!Te&&(0,v.jsx)(h.Animated.View,{style:[S.result_slot,{top:d?ve+re-Gr:ve+re+52},{opacity:oe}],children:(0,v.jsxs)(h.View,{style:S.result,children:[(0,v.jsx)(h.View,{style:S.check_badge,children:(0,v.jsx)(h.View,{style:S.check_mark})}),(0,v.jsx)(h.Text,{style:S.result_text,numberOfLines:1,children:Te}),(0,v.jsxs)(h.Text,{style:S.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),$.height>0&&(0,v.jsx)(h.View,{style:[S.close_slot,d?S.close_slot_top:{top:Math.max(12,_e-$.window_y+12)}],children:(0,v.jsxs)(Ct,{style:[S.close_button,!!s&&S.glass_surface],onPress:Qt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_a]}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_b]})]})}),(0,v.jsx)(h.View,{style:[S.toolbar_wrap,!d&&{bottom:ce.bottom+20}],pointerEvents:"box-none",children:(0,v.jsxs)(h.View,{style:[S.toolbar,!!s&&S.glass_surface],children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(Ct,{style:S.tool,onPress:co,disabled:ne,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,v.jsxs)(h.View,{style:S.image_icon,children:[(0,v.jsx)(h.View,{style:S.image_icon_dot}),(0,v.jsx)(h.View,{style:S.image_icon_hill})]})}),!!u&&Qe>=Io&&(0,v.jsx)(Ct,{style:[S.tool,E>1&&S.tool_on],onPress:()=>M(b=>b>1?1:Io),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,v.jsxs)(h.Text,{style:[S.zoom_text,E>1&&S.zoom_text_on],children:[Math.round(E*10)/10,"x"]})}),Ve&&(0,v.jsx)(Ct,{style:[S.tool,I&&S.tool_on],onPress:()=>T(b=>!b),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:I},children:(0,v.jsx)(h.Text,{style:[S.torch_icon,I&&S.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},Qr="rgba(0,0,0,0.5)",dn=50,S=h.StyleSheet.create({top:{height:`${Fo*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:Qr,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:Ot,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Ot,borderRadius:Ot/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:jr,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:dn,height:dn,borderRadius:dn/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 j=require("react/jsx-runtime"),mn={[fe.info]:"#3B82F6",[fe.success]:"#22C55E",[fe.error]:"#EF4444"},Do=-120,kt=R.Platform.OS==="android",No=({type:e})=>e===fe.success?(0,j.jsx)(R.View,{style:ee.check_mark}):e===fe.error?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(R.View,{style:[ee.cross_bar,ee.cross_a]}),(0,j.jsx)(R.View,{style:[ee.cross_bar,ee.cross_b]})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(R.View,{style:ee.info_dot}),(0,j.jsx)(R.View,{style:ee.info_bar})]}),Uo=()=>{let e=W(rt,y=>y.message),t=W(rt,y=>y.type),n=W(rt,y=>y.tick),o=(0,we.useRef)(new R.Animated.Value(Do)).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 Zt().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(Hn[t]),R.Animated.parallel([R.Animated.timing(o,{toValue:Do,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,j.jsx)(R.View,{style:[ee.layer,{top:xt().top+(kt?12:8)}],pointerEvents:"none",children:(0,j.jsxs)(R.Animated.View,{style:[ee.toast,kt&&ee.toast_android,!!c&&ee.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,j.jsx)(c,{style:ee.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),kt?(0,j.jsx)(R.Animated.View,{style:[ee.badge_halo,{backgroundColor:`${mn[t]}33`,transform:[{scale:a}]}],children:(0,j.jsx)(R.View,{style:[ee.badge,{backgroundColor:mn[t]}],children:(0,j.jsx)(No,{type:t})})}):(0,j.jsx)(R.Animated.View,{style:[ee.badge,{backgroundColor:mn[t],transform:[{scale:a}]}],children:(0,j.jsx)(No,{type:t})}),(0,j.jsx)(R.Text,{style:[ee.message,kt&&ee.message_android],numberOfLines:2,children:e})]})}):null},ee=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:{}}),Vo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=q().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}})},Bo=e=>Vo(e,!0),qo=e=>Vo(e,!1),Ke=()=>ue.setState({active_key:null}),It=e=>{ue.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var $o="catalog",ei="paused_apps",ti="removed_apps",ni=10*1e3,oi=2,ri=3e3,ii=()=>{var e;try{return JSON.parse((e=q().storage.getString($o))!=null?e:"{}")}catch{return{}}},D=Ie({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),zo=e=>{var t;return!!((t=q().manual_update)!=null&&t.includes(e))},Dt=new Set,Wo=e=>{let t=new Set,n=()=>q().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=q().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},Se=Wo(ei),Ue=Wo(ti);Mn(()=>{Se.load(),Ue.load();let e=ii(),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 Nt=e=>W(D,t=>e?t.downloads[e]:void 0),jo=()=>W(D,e=>e.pause_reasons.length>0),Ae=(...e)=>me("queue",...e),X=[],Oe={},C=null,Lt=new Set,We={},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)}})},Ho=e=>(fn.add(e),()=>{fn.delete(e)}),Jo=()=>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})},Ft=(e,t)=>{var n;(n=We[e])==null||n.forEach(o=>o(t)),delete We[e]},si=()=>D.getState().pause_reasons.length>0,Ne=e=>{var c;if(C)return;let t=e?X.indexOf(e):si()?-1:X.findIndex(l=>!Se.has(l));if(t<0||t>=X.length)return;let[n]=X.splice(t,1),o=D.getState().catalog[n];if(!o){Ft(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=un(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}),Ft(n,l)}).catch(l=>{var g;if(l instanceof Je){if(Lt.has(n))return;Ae("paused",n),Oe[n]-=1,X.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]<oi){de(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;X.includes(n)||(C==null?void 0:C.app_id)===n||(X.push(n),Ne((d=We[n])!=null&&d.length?n:void 0))},ri);return}de(n,{status:"failed",progress:0,version:o.version,error:s}),Ft(n,B(n))}).finally(()=>{C=null;let l=X.find(s=>{var g;return(g=We[s])==null?void 0:g.length});Ne(l)})},Ut=(e,{front:t=!1}={})=>{if((C==null?void 0:C.app_id)===e)return;let n=X.indexOf(e);if(n>=0){if(!t)return;X.splice(n,1)}t?X.unshift(e):X.push(e)},ai=async e=>{let{host_id:t,client_token:n}=q(),o=new AbortController,r=setTimeout(()=>o.abort(),ni);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,Vt=()=>(dt!=null||(dt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(q().channels.map(ai)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(D.getState().catalog).filter(l=>!o[l]);q().storage.setString($o,JSON.stringify(o)),D.setState({catalog:o}),await Promise.all(r.map(l=>Go(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 pn(l)){de(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=B(l.app_id);if(zo(l.app_id)&&!Dt.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}),Ut(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),Go=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ue.add(e),Lt.has(e))return;Lt.add(e),Se.delete(e);let n=X.indexOf(e);n>=0&&X.splice(n,1),(C==null?void 0:C.app_id)===e&&C.handle.cancel();let o=(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 Ro(e),It(e),D.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Oe[e],Lt.delete(e),Ft(e,null),Ae("uninstalled",e,t?"(user)":"(not in list)"),De({type:"uninstalled",app_id:e})},Ko=e=>Go(e,{by_user:!0}),Yo=e=>{let t=Ye(e);return t?(Ue.delete(e),(C==null?void 0:C.app_id)===e||X.includes(e)||(Oe[e]=0,de(e,{status:Se.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Ut(e),Ne(),Ae("restore",e)),!0):!1},Xo=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];X.includes(e)&&t&&de(e,{status:"paused",progress:0,version:t.version})},Zo=e=>{if(!Se.delete(e))return;Ae("resume app",e);let t=D.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!X.includes(e)&&Ye(e)&&(Oe[e]=0,Ut(e)),X.includes(e)&&t&&de(e,{status:"queued",progress:0,version:t.version}),Ne()},Qo=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())},er=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()},hn=e=>D.getState().updates[e],tr=async e=>{var n,o;let t=hn(e);Dt.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{Dt.delete(e)}},nr=()=>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 pn(t))return B(e);let n=B(e);if(zo(e)&&!Dt.has(e)&&n&&await Ce(n))return n;let o=new Promise(r=>{var i;((i=We[e])!=null?i:We[e]=[]).push(r)});return(C==null?void 0:C.app_id)===e?C.forced=!0:(Oe[e]=0,Ut(e,{front:!0}),C&&!C.forced?C.handle.cancel():Ne(e)),o};var k=require("react/jsx-runtime"),yn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),or=0,ci=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},li=A.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var mt,ft;let d=(0,A.useRef)(null),y=(0,A.useRef)(!1),u=W(ue,f=>f.instances[e]),w=u==null?void 0:u.app.app_id,I=u==null?void 0:u.app.manifest_url,T=u==null?void 0:u.context,E=u==null?void 0:u.url_params,M=W(Y,f=>{var _;return((_=f.active)==null?void 0:_.owner)===e?f.active:null}),[N,$]=(0,A.useState)(null),[te,Te]=(0,A.useState)(M);M!==te&&(Te(M),M?$(null):(te==null?void 0:te.layout)===pe.top&&$(te));let ae=(M==null?void 0:M.layout)===pe.top?M:N,[p,x]=(0,A.useState)(()=>w?B(w):null),[ne,P]=(0,A.useState)(!1),[ce,_e]=(0,A.useState)(0),[G,O]=(0,A.useState)(0),[oe,H]=(0,A.useState)(!1),Z=(0,A.useRef)(null),re=f=>{Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{Z.current=null,H(!0)},f)};(0,A.useEffect)(()=>()=>{Z.current&&clearTimeout(Z.current)},[]),(0,A.useEffect)(()=>{if(!w||!t&&p)return;let f=!0;return P(!1),(async()=>{let _=B(w),b=_?await Ce(_):!1;if(!f||(x(b?se=>!se||se.version!==_.version||se.permissions.join(",")!==_.permissions.join(",")?_:se:null),__DEV__&&Date.now()-or>1e4&&(or=Date.now(),await Vt()),!f))return;let U=await gt(w),ie=U!==void 0?U:I?await Co(w,I):B(w);if(f){if(!ie){P(!0);return}x(se=>se!=null?se:ie)}})(),()=>{f=!1}},[t,w,I,ce]),(0,A.useEffect)(()=>Oo(e,f=>d.current?(d.current.postMessage(f),!0):!1),[e]);let ve=W(D,f=>{let _=w?f.downloads[w]:void 0;return(_==null?void 0:_.status)==="installed"?_.version:void 0});(0,A.useEffect)(()=>{if(t||!w||!p)return;let f=B(w);if(!f||f.version===p.version)return;let _=!0;return Ce(f).then(b=>{!_||!b||(me(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",f.version),x(f))}),()=>{_=!1}},[t,w,ve,p==null?void 0:p.version]);let Me=W(D,f=>{var _;return w&&(_=f.apply_ticks[w])!=null?_:0});(0,A.useEffect)(()=>{if(!Me||!w)return;let f=B(w);if(!f||f.version===(p==null?void 0:p.version))return;let _=!0;return Ce(f).then(b=>{!_||!b||(me(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",f.version),H(!1),x(f))}),()=>{_=!1}},[Me]),(0,A.useEffect)(()=>{var b;let f=(b=q().keep_alive)==null?void 0:b.idle_close_ms;if(t||!f||f<=0)return;let _=setTimeout(()=>{It(e)},f);return()=>clearTimeout(_)},[t,e]),(0,A.useEffect)(()=>{r>0&&(P(!1),H(!1),O(f=>f+1),_e(f=>f+1))},[r]);let je=(0,A.useRef)(t);(0,A.useEffect)(()=>{var f;je.current!==t&&(je.current=t,y.current&&((f=d.current)==null||f.injectJavaScript(yo(t?"resumed":"paused"))))},[t]);let xe=`${(mt=p==null?void 0:p.version)!=null?mt:"none"}:${(ft=p==null?void 0:p.permissions.join(","))!=null?ft:""}:${G}`,Pe=(0,A.useMemo)(()=>JSON.stringify([T!=null?T:{},E!=null?E:{}]),[T,E]),Xe=(0,A.useMemo)(()=>{var f;return So(E!=null?E:{},(f=p==null?void 0:p.permissions)!=null?f:[])},[Pe,p==null?void 0:p.permissions]),Bt=(0,A.useMemo)(()=>_o(T!=null?T:{},Xe)+fo()+ho()+(q().debug?mo():""),[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=Pe;return}if(Ve.current===Pe)return;let f=((b=JSON.parse((_=Ve.current)!=null?_:"[]")[0])!=null?b:{}).org_id;if(Ve.current=Pe,f===(T==null?void 0:T.org_id)&&y.current){H(!1),re(1500),(U=d.current)==null||U.injectJavaScript(wo(T!=null?T:{},Xe));return}H(!1),O(ie=>ie+1)},[Pe,p,xe]),(0,A.useEffect)(()=>(t||(Re(e),Fe(e),qe(e)),()=>{Re(e),Fe(e),qe(e)}),[t,e,xe,r]),(0,A.useEffect)(()=>{let f=L.AppState.addEventListener("change",_=>{_==="background"&&!Kn()&&Re(e),_==="background"&&!to()&&Fe(e)});return()=>f.remove()},[e]);let Qe=(0,A.useCallback)(async f=>{var b,U,ie,se,$t,bn;let _=lo(f.nativeEvent.data);if(!_){if(w&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:w,instance_id:e})).catch(z=>{console.warn("[miniapp] onWebEvent l\u1ED7i",w,z)})}catch(z){console.warn("[miniapp] onWebEvent l\u1ED7i",w,z)}return}if(_.method==="log"){let{level:z,text:J}=_;me(`web:${e}`,z!=null?z:"log",J!=null?J:"");return}if(_.method==="pong"){Z.current||H(!0);return}if(_.method==="touchAtTop"){i.emit(!!_.at_top);return}if(_.method==="contextApplied"){Z.current&&clearTimeout(Z.current),Z.current=null,H(!0);return}if(_.method==="ready"){y.current=!0,H(!0);let z=(b=ue.getState().instances[e])==null?void 0:b.context;z&&((U=d.current)==null||U.injectJavaScript(nn(z)));return}try{let z=await Mo(_,{getHostData:()=>{var J,ge;return(ge=(J=ue.getState().instances[e])==null?void 0:J.host_data)!=null?ge:{}},getPermissions:()=>{var J,ge;return w?(ge=(J=B(w))==null?void 0:J.permissions)!=null?ge:[]:[]},getContext:()=>{var J,ge;return(ge=(J=ue.getState().instances[e])==null?void 0:J.context)!=null?ge:{}},is_dark:o,close:Ke,app_id:w!=null?w:"",instance_id:e,options:c,emit:(J,ge)=>{var _n;(_n=d.current)==null||_n.injectJavaScript(go(J,ge))},playBeep:(ie=c==null?void 0:c.playScannerBeep)!=null?ie:(()=>{var J;(J=d.current)==null||J.injectJavaScript(vo())}),isActive:()=>ue.getState().active_key===e&&L.AppState.currentState!=="background"});_.id&&((se=d.current)==null||se.injectJavaScript(po(_.id,z)))}catch(z){if(!_.id)return;let J=z==null?void 0:z.code,ge=z instanceof m?z:new m(typeof J=="string"?J:"HOST_ERROR",String(($t=z==null?void 0:z.message)!=null?$t:z));(bn=d.current)==null||bn.injectJavaScript(uo(_.id,ge))}},[e,o,w,i,c]),qt=(0,A.useCallback)(()=>{P(!1),O(f=>f+1),_e(f=>f+1)},[]);return(0,k.jsxs)(L.View,{style:[L.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&be.behind],pointerEvents:t?"auto":"none",children:[ae&&(0,k.jsx)(gn,{scanner:ae,closing:ae===N,onClosed:()=>{var f;$(null),ae.absolute&&((f=d.current)==null||f.injectJavaScript(on(0)))},onHeight:ae.absolute?f=>{var _;return(_=d.current)==null?void 0:_.injectJavaScript(on(f))}:void 0}),p?(0,k.jsx)(ir.default,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?an():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:Bt,onMessage:Qe,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load start",yn(f.nativeEvent.url)),y.current=!1,H(!1)},onError:f=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load error",yn(f.nativeEvent.url),f.nativeEvent.description),P(!0),H(!1)},onLoadEnd:f=>{let _=f.nativeEvent.url;me(`webview:${e}`,"load end",yn(_)),w&&(g==null||g({app_id:w,instance_id:e,url:_})),re(1500)},onContentProcessDidTerminate:()=>{Re(e),Fe(e),qe(e),y.current=!1,H(!1),O(f=>f+1)},onRenderProcessGone:()=>(Re(e),Fe(e),qe(e),y.current=!1,H(!1),O(f=>f+1),!0),style:be.webview},xe):null,(M==null?void 0:M.layout)===pe.full&&(0,k.jsx)(gn,{scanner:M}),u&&(0,k.jsx)(ui,{visible:!p||!oe,interactive:ne,children:(0,k.jsx)(pi,{splash:a,app:u.app,is_dark:o,error:ne,has_bundle:!!p,retry:qt})})]})}),pi=A.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Nt(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,k.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),ui=({visible:e,interactive:t,children:n})=>{let o=(0,A.useRef)(new L.Animated.Value(e?1:0)).current,[r,i]=(0,A.useState)(e);return(0,A.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=L.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,k.jsx)(L.Animated.View,{style:[L.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},wn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,k.jsxs)(L.View,{style:[be.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,k.jsx)(L.View,{style:[be.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,k.jsx)(L.Image,{source:{uri:e.icon},style:be.splash_icon_image}):(0,k.jsx)(L.Text,{style:be.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,k.jsx)(L.Text,{style:[be.splash_name,{color:i}],children:e.name}),n==="error"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.Text,{style:be.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,k.jsx)(L.TouchableOpacity,{activeOpacity:.7,style:[be.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,k.jsx)(L.Text,{style:[be.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.ActivityIndicator,{style:be.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,k.jsxs)(L.Text,{style:be.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},rr=(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.`))},di=({container:e,splash:t=wn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{rr("container",e),rr("splash",t);let l=e,s=W(ue,M=>M.active_key),g=(0,A.useRef)(s);s&&(g.current=s);let d=W(ue,M=>Object.keys(M.instances).join("|")),y=W(ue,M=>{var N;return M.active_key?(N=M.instances[M.active_key])==null?void 0:N.app.name:void 0}),u=(0,A.useMemo)(()=>d?d.split("|"):[],[d]),[w,I]=(0,A.useState)({}),T=(0,A.useRef)(ci()).current;(0,A.useEffect)(()=>{if(!s||!r)return;let M=L.BackHandler.addEventListener("hardwareBackPress",()=>(Ke(),!0));return()=>M.remove()},[s,r]);let E=(0,A.useCallback)(()=>{let M=ue.getState().active_key;M&&I(N=>({...N,[M]:(N[M]||0)+1}))},[]);return u.length?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:Ke,reload:E,subscribeWebAtTop:T.subscribe,children:u.map(M=>(0,k.jsx)(li,{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:T,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},M))}),(0,k.jsx)(Uo,{})]}):null},be=L.StyleSheet.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),sr=A.default.memo(di);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppStatuses,getMiniAppUpdate,installBundledMiniApp,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppDownload,useMiniAppDownloadsPaused});
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De=e,Mn.forEach(t=>t())},D=()=>{if(!De)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return De},xn=e=>{Mn.add(e),De&&e()},le=(...e)=>{De!=null&&De.debug&&console.log("[miniapp]",...e)};var rr=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:c})=>r==null?void 0:r(l,c)});return{promise:a.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),ir=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import bn,{useCallback as yn,useEffect as se,useMemo as Ft,useRef as ye,useState as $e}from"react";import{AppState as Qo,ActivityIndicator as Ti,Animated as fn,BackHandler as Pi,Image as Ci,StyleSheet as An,Text as gt,TouchableOpacity as Oi,View as wn}from"react-native";import ki from"react-native-webview";import{Linking as go,Platform as Ur}from"react-native";var En=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),ft,Bt=()=>(ft||(ft=import("react-native-biometrics").then(({default:e})=>En(new e({allowDeviceCredentials:!1}))).catch(e=>{throw ft=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),ft);import{PermissionsAndroid as Ne,Platform as sr}from"react-native";var Rn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,l]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let c=t[i];if(c!==void 0&&(typeof c!="number"||!Number.isFinite(c)||c<a||c>l))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Tn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(c,s)=>{r||(r=!0,clearTimeout(a),c?o(c):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),l=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!l())return;let c;try{c=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(l()){if(sr.OS==="android"){let s=Ne.PERMISSIONS.ACCESS_FINE_LOCATION,d=Ne.PERMISSIONS.ACCESS_COARSE_LOCATION,m=await Ne.check(s);if(!l())return;let h=m||await Ne.check(d);if(!l())return;if(!m&&!h){let p=await Ne.requestMultiple([s,d]);if(!l())return;if(p[s]!==Ne.RESULTS.GRANTED&&p[d]!==Ne.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}l()&&c.getCurrentPosition(s=>{l()&&i(void 0,s)},s=>{var m;if(!l())return;let d=(m={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?m:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(c=>i(c))});import{Platform as Fn}from"react-native";var qt=20,Pn=20,Dn=/^[a-z][a-z0-9_-]{0,31}$/,ar=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,cr=["low","medium","high"],Re=e=>!!e&&typeof e=="object"&&!Array.isArray(e),j=e=>new g("INVALID_PARAMS",e),Xe=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Cn=(e,t)=>{if(e===void 0)return{};if(!Re(e)||Object.keys(e).length>Pn||Object.values(e).some(n=>typeof n!="string"))throw j(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Pn} key)`);return e},Nn=e=>{var n,o,r,i;if(e!==void 0&&!Re(e))throw j("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Dn.test(t.source)))throw j("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!ar.test(a))))throw j("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!Xe(t.max_count,1,qt))throw j(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${qt}`);if(t.max_size!==void 0&&!Xe(t.max_size,1,Number.MAX_SAFE_INTEGER))throw j("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Xe(t.concurrency,1,5))throw j("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:lr(t.process),target:pr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},lr=e=>{if(e===void 0)return{};if(!Re(e))throw j("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Re(n))throw j("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!Xe(n[o],1,1e4))throw j(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw j("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!Re(n))throw j("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!Xe(n.max_duration,1,3600))throw j("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!cr.includes(n.quality))throw j("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},pr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Re(e))throw j("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Dn.test(t))throw j("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Re(e.params))throw j("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw j("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw j(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Cn(e.headers,"upload.headers"),form_data:Cn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Un=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},ur=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Un(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},dr=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},Ge,gr=()=>(Ge!=null||(Ge=import("react-native-image-picker").catch(e=>{throw Ge=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Ge),On=e=>async({accept:t,max_count:n,process:o})=>{var c,s,d,m,h,p,y,E,v;let r=await gr(),i=dr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(c=o.image)==null?void 0:c.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(m=(d=o.image)==null?void 0:d.quality)!=null?m:.8,videoQuality:(p=(h=o.video)==null?void 0:h.quality)!=null?p:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let M=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(M,(E=l.errorMessage)!=null?E:l.errorCode)}return((v=l.assets)!=null?v:[]).filter(M=>M.uri).map((M,A)=>{var _,W,Z;return{uri:M.uri,name:(_=M.fileName)!=null?_:`file_${A+1}`,mime_type:(W=M.type)!=null?W:"application/octet-stream",size:M.fileSize,width:M.width,height:M.height,duration:M.duration,processed:!((Z=M.type)!=null&&Z.startsWith("video/"))||Fn.OS==="ios"}})},mr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},fr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},hr=e=>async({accept:t,max_count:n})=>{var i,a,l,c;let o=t.map(s=>{var d;return(d=mr[s])!=null?d:fr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,y)=>{var E,v,M;return{uri:p.uri,name:(E=p.name)!=null?E:`file_${y+1}`,mime_type:(v=p.type)!=null?v:"application/octet-stream",size:(M=p.size)!=null?M:void 0}});if(Fn.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let m=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),h=new Map(m.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var y;return{...p,uri:(y=h.get(p.uri))!=null?y:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((c=(l=e.errorCodes)==null?void 0:l.IN_PROGRESS)!=null?c:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},Ke,yr=async e=>(Ke!=null||(Ke=import("@react-native-documents/picker").then(t=>hr(t)).catch(t=>{throw Ke=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await Ke)(e)),Vn={library:On("library"),camera:On("camera"),document:yr},kn={type:"image",label:"\u1EA2nh",accept:["image/*"]},In={type:"video",label:"Video",accept:["video/*"]},Ln={library:[kn,In],camera:[kn,In],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},Ye,Bn=()=>(Ye!=null||(Ye=import("react-native-compressor").catch(()=>(Ye=void 0,null))),Ye),qn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},wr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),_r={low:640,medium:1280,high:1920},br=async(e,{image:t})=>{var o;if(!t||!wr.has(e.mime_type.toLowerCase()))return e;let n=await Bn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await qn(n,r,e.size),processed:!0}}catch{return e}},Ar=async(e,{video:t})=>{var o;let n=await Bn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:_r[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await qn(n,r,e.size),processed:!0}}catch{return e}},Sr={image:br,video:Ar},vr=(e,t)=>t.split(".").reduce((n,o)=>Re(n)?n[o]:void 0,e),$n=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let l=new XMLHttpRequest,c=new FormData;Object.entries(a.form_data).forEach(([m,h])=>c.append(m,h)),c.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();o.addEventListener("abort",s);let d=m=>{o.removeEventListener("abort",s),m()};l.open("POST",a.url),Object.entries(a.headers).forEach(([m,h])=>l.setRequestHeader(m,h)),l.upload.onprogress=m=>n(m.loaded,m.total||e.size||0),l.onload=()=>d(()=>{let m=l.responseText;try{m=JSON.parse(l.responseText)}catch{}if(l.status<200||l.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${l.status}`));return}let h=vr(m,a.url_field);if(typeof h!="string"||!h){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:h,response:m})}),l.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),l.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),l.send(c)}),zn=e=>{var o,r;let t={...Vn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:$n};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},Wn=e=>{let{sources:t,targets:n}=zn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Vn[i]&&Ln[i]).map(i=>[i,Ln[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:qt}},yt=new Map,jn=(e,t)=>`${e}:${t}`,Mr=0,Hn=(e,t)=>{var n;typeof t=="string"&&((n=yt.get(jn(e,t)))==null||n.abort())},Ue=e=>{for(let[t,n]of yt)t.startsWith(`${e}:`)&&n.abort()},ht=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),xr=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},Jn=async(e,t)=>{var c;let{sources:n,targets:o}=zn(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,l=jn(t.instance_id,(c=t.task_id)!=null?c:`auto-${++Mr}`);yt.set(l,a);try{return await Er(e,t,r,i,a.signal)}finally{yt.delete(l)}},Er=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:l=m=>m()},c,s,d)=>{var w,S,q;let m={app_id:n!=null?n:"",instance_id:t,context:{...(w=o==null?void 0:o())!=null?w:{}}},h=(await l(()=>c({accept:e.accept,max_count:e.max_count,process:e.process,caller:m}))).slice(0,e.max_count);if(d.aborted)throw ht();if(!h.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],y=h.filter(x=>ur(x,e.accept)?!0:(p.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||Un(x.name)}`}),!1)),E=y.map(()=>0),v=y.map(x=>{var C;return(C=x.size)!=null?C:0}),M=0,A=0,_=(x=!1)=>{if(!a||!r)return;let C=Date.now();if(!x&&C-A<200)return;A=C;let k=v.reduce((I,Q)=>I+Q,0),N=E.reduce((I,Q)=>I+Q,0);a("upload.progress",{task_id:r,loaded:N,total:k,percent:k?Math.min(100,Math.round(N/k*100)):0,done_count:M,count:y.length})},W=[],Z=0,te=async()=>{var x,C,k;for(;Z<y.length;){let N=Z++,I=y[N];try{if(d.aborted)throw ht();let Q=I.mime_type.startsWith("image/")?"image":I.mime_type.startsWith("video/")?"video":void 0,Le=Q&&!I.processed?(C=(x=i==null?void 0:i.processors)==null?void 0:x[Q])!=null?C:Sr[Q]:void 0;if(Le&&(I=await Le(I,e.process),v[N]=(k=I.size)!=null?k:v[N],d.aborted))throw ht();if(e.max_size&&I.size&&I.size>e.max_size)throw new g("FILE_TOO_LARGE",`File ${I.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let de=(Ae,Se)=>{E[N]=Ae,Se&&(v[N]=Se),_()},ne=await s({file:I,target:e.target,onProgress:de,signal:d,caller:m});if(typeof(ne==null?void 0:ne.url)!="string"||!ne.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Fe,...be}=ne;W[N]={url:Fe,name:I.name,mime_type:I.mime_type,size:I.size,width:I.width,height:I.height,duration:I.duration,...Object.keys(be).length?{response:"response"in be?be.response:be}:{}},E[N]=v[N]}catch(Q){p.push(xr(y[N].name,Q))}finally{M++,_(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},te)),d.aborted)throw ht();let we=W.filter(x=>!!x);if(!we.length){let x=p[0];throw new g((S=x==null?void 0:x.code)!=null?S:"UPLOAD_FAILED",(q=x==null?void 0:x.message)!=null?q:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:we,failed:p}};import{useRef as Rr,useSyncExternalStore as Tr}from"react";var Te=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},V=(e,t,n=Object.is)=>{let o=Rr(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let l=t(i),c=a&&n(a.value,l)?a.value:l;return o.current={state:i,selector:t,value:c},c};return Tr(e.subscribe,r)};var me={info:"info",success:"success",error:"error"},Pr=200,Gn={info:2e3,success:2e3,error:3e3},Ze=Te({message:"",type:me.info,tick:0}),Kn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Pr);return o?{message:o,type:Object.values(me).includes(n)?n:me.info}:null},Yn=(e,t=me.info)=>{Ze.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Alert as Or,Linking as kr,Platform as Qe,StatusBar as Ir}from"react-native";import{AppState as Xn,Platform as zt}from"react-native";var pe,Zn=()=>zt.OS==="android"&&!!(pe!=null&&pe.requesting_permission),Cr=1500,wt=()=>new Promise(e=>{if(zt.OS!=="android"||Xn.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Cr),o=Xn.addEventListener("change",r=>{r==="active"&&t()})}),$t=e=>{var t;if(pe===e&&(pe=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&zt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Qn=async(e,t,n,o=()=>!0)=>{var i,a,l,c,s;if(pe)throw new g("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};pe=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let m=d.ExpoSpeechRecognitionModule;if(r.native=m,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let h;try{h=await m.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await wt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!h.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await m.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(m.addListener("result",p=>{var y,E;pe!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(E=(y=p.results[0])==null?void 0:y.transcript)!=null?E:""})}),m.addListener("error",p=>{pe===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),m.addListener("end",()=>{pe===r&&($t(r),n("speech.end"))})),r.started=!0,m.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(l=t.interimResults)!=null?l:!0,addsPunctuation:(c=t.addsPunctuation)!=null?c:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw $t(r),d}},eo=e=>{let t=pe;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},ve=e=>{let t=pe;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{$t(t)}};var to={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},X={...to,all:Object.values(to)},et={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},jt={result:"scanner.result",end:"scanner.end"},ze={user:"user",web:"web",closed:"closed",error:"error"},Me={top:"top",full:"full"},Ve={once:"once",continuous:"continuous"},Lr=1500,no=6e4,L,H=Te({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),ro=()=>Qe.OS==="android"&&!!(L!=null&&L.requesting_permission),Ht=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r}=e!=null?e:{},i={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(a=>X.all.includes(a)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");i.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>no)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${no}`);i.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");i.hint=o}if(r!==void 0){if(!Object.values(Me).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},Jt=e=>L!==e?!1:(L=void 0,H.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Fr=()=>Or.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{kr.openSettings().catch(()=>{})}}]),io=async(e,t)=>{if(L)throw new g("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");L=e;let n=()=>{if(e.cancelled||!t())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=Qe.OS==="ios"&&r==="denied";e.requesting_permission=!0;let l;try{l=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await wt(),n(),l!=="granted")throw a&&Fr(),new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new g("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Gt();n(),H.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw Jt(e),o}},_t;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{_t=e==null?void 0:e.insets}).catch(()=>{});var bt=()=>{var e;return _t!=null?_t:{top:Qe.OS==="ios"?54:(e=Ir.currentHeight)!=null?e:0,bottom:Qe.OS==="ios"?34:48}},Gt=async()=>{if(Qe.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},so=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:X.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Lr,hint:n.hint,layout:t===Ve.once?Me.full:(i=n.layout)!=null?i:Me.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},ao=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=so(e,Ve.once,t);a.onHit=o,a.resolve=r,a.reject=i,io(a,n).catch(i)}),co=(e,t,n,o=()=>!0,r)=>{let i=so(e,Ve.continuous,t);return i.emit=n,i.onHit=r,io(i,o)},At=(e,t,n)=>{var o,r;if(!H.getState().active){e.cancelled=!0;return}if(Jt(e)){if(e.mode===Ve.once){(o=e.reject)==null||o.call(e,t===ze.error?new g("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new g("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,jt.end,n?{reason:t,message:n}:{reason:t})}},lo=e=>{(L==null?void 0:L.owner)===e&&At(L,ze.web)},Pe=e=>{(L==null?void 0:L.owner)===e&&At(L,ze.closed)},Kt=()=>{L&&At(L,ze.user)},po=e=>{L&&At(L,ze.error,e)},Yt=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=L;if(!(!o||!H.getState().active))for(let{value:l,type:c}of e){if(!l)continue;let s=o.last_seen.get(l);if(o.last_seen.set(l,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Ve.once){Jt(o),(i=o.resolve)==null||i.call(o,{value:l,type:c});return}H.setState(d=>({last_value:l,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,jt.result,{value:l,type:c})}}},Dr={1:X.code128,2:X.code39,4:X.code93,8:X.codabar,16:X.dataMatrix,32:X.ean13,64:X.ean8,128:X.itf,256:X.qr,512:X.upcA,1024:X.upcE,2048:X.pdf417,4096:X.aztec},Nr=2500,oo=2e3,Wt=e=>{H.setState({notice:e}),setTimeout(()=>{H.getState().notice===e&&H.setState({notice:null})},Nr)},uo=async()=>{var t,n;let e=L;if(!(!e||H.getState().is_picking)){e.requesting_permission=!0,H.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:oo,maxHeight:oo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||L!==e)return;if(r.errorCode||!i){Wt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),l=await a.scan(i);if(L!==e)return;let c=l.map(({value:s,format:d})=>({value:s,code_type:Dr[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!c.length){Wt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Yt(c,Date.now(),!0)}catch{L===e&&Wt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await wt(),e.requesting_permission=!1,L===e&&H.setState({is_picking:!1})}}};var vt=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},mo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===vt&&typeof t.method=="string"?t:null}catch{return null}},nt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,fo=(e,t)=>nt({id:e,result:t}),ho=(e,t)=>nt({id:e,error:{code:t.code,message:t.message}}),yo=(e,t)=>nt({event:e,data:t}),Zt=e=>nt({event:"context",data:e});var wo=()=>`(function () {
|
|
1
|
+
var jt="https://retion-miniapp-platform.vercel.app",Ve=null,On=new Set,lr=e=>{Ve=e,On.forEach(t=>t())},F=()=>{if(!Ve)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ve},kn=e=>{On.add(e),Ve&&e()},ue=(...e)=>{Ve!=null&&Ve.debug&&console.log("[miniapp]",...e)};var pr=(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)}}}),ur=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import Rn,{useCallback as Mn,useEffect as le,useMemo as qt,useRef as be,useState as Ce}from"react";import{AppState as ir,ActivityIndicator as Fi,Animated as Sn,BackHandler as Di,Image as Ni,StyleSheet as Tn,Text as yt,TouchableOpacity as Ui,View as xn}from"react-native";import Vi from"react-native-webview";import{Linking as _o,Platform as Wr}from"react-native";var In=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),_t,Ht=()=>(_t||(_t=import("react-native-biometrics").then(({default:e})=>In(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 dr}from"react-native";var Ln=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}},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 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(dr.OS==="android"){let s=Be.PERMISSIONS.ACCESS_FINE_LOCATION,g=Be.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Be.check(s);if(!c())return;let h=d||await Be.check(g);if(!c())return;if(!d&&!h){let u=await Be.requestMultiple([s,g]);if(!c())return;if(u[s]!==Be.RESULTS.GRANTED&&u[g]!==Be.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});import{Platform as $n}from"react-native";var Jt=20,Dn=20,zn=/^[a-z][a-z0-9_-]{0,31}$/,gr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,mr=["low","medium","high"],Oe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),W=e=>new m("INVALID_PARAMS",e),nt=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Nn=(e,t)=>{if(e===void 0)return{};if(!Oe(e)||Object.keys(e).length>Dn||Object.values(e).some(n=>typeof n!="string"))throw W(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Dn} key)`);return e},Wn=e=>{var n,o,r,i;if(e!==void 0&&!Oe(e))throw W("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 W("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"||!gr.test(a))))throw W("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,Jt))throw W(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Jt}`);if(t.max_size!==void 0&&!nt(t.max_size,1,Number.MAX_SAFE_INTEGER))throw W("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!nt(t.concurrency,1,5))throw W("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:fr(t.process),target:hr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},fr=e=>{if(e===void 0)return{};if(!Oe(e))throw W("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Oe(n))throw W("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 W(`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 W("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 W("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!nt(n.max_duration,1,3600))throw W("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!mr.includes(n.quality))throw W("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},hr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Oe(e))throw W("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!zn.test(t))throw W("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 W("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 W("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 W(`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"}},jn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},yr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=jn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},wr=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,br=()=>(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),Un=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,h,u,y,P,M;let r=await br(),i=wr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(h=o.video)==null?void 0:h.quality)!=null?u:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let v=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(v,(P=c.errorMessage)!=null?P:c.errorCode)}return((M=c.assets)!=null?M:[]).filter(v=>v.uri).map((v,A)=>{var O,N,X;return{uri:v.uri,name:(O=v.fileName)!=null?O:`file_${A+1}`,mime_type:(N=v.type)!=null?N:"application/octet-stream",size:v.fileSize,width:v.width,height:v.height,duration:v.duration,processed:!((X=v.type)!=null&&X.startsWith("video/"))||$n.OS==="ios"}})},_r={"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"},Ar={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Sr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=_r[s])!=null?g:Ar[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 P,M,v;return{uri:u.uri,name:(P=u.name)!=null?P:`file_${y+1}`,mime_type:(M=u.type)!=null?M:"application/octet-stream",size:(v=u.size)!=null?v:void 0}});if($n.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),h=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var y;return{...u,uri:(y=h.get(u.uri))!=null?y:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},et,vr=async e=>(et!=null||(et=import("@react-native-documents/picker").then(t=>Sr(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)),Hn={library:Un("library"),camera:Un("camera"),document:vr},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"]}]},tt,Jn=()=>(tt!=null||(tt=import("react-native-compressor").catch(()=>(tt=void 0,null))),tt),Gn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Mr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),xr={low:640,medium:1280,high:1920},Er=async(e,{image:t})=>{var o;if(!t||!Mr.has(e.mime_type.toLowerCase()))return e;let n=await Jn();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 Gn(n,r,e.size),processed:!0}}catch{return e}},Rr=async(e,{video:t})=>{var o;let n=await Jn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:xr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Gn(n,r,e.size),processed:!0}}catch{return e}},Tr={image:Er,video:Rr},Pr=(e,t)=>t.split(".").reduce((n,o)=>Oe(n)?n[o]:void 0,e),Kn=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,h])=>l.append(d,h)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,h])=>c.setRequestHeader(d,h)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let h=Pr(d,a.url_field);if(typeof h!="string"||!h){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:h,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),Yn=e=>{var o,r;let t={...Hn};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:Kn};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}},Xn=e=>{let{sources:t,targets:n}=Yn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Hn[i]&&qn[i]).map(i=>[i,qn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Jt}},St=new Map,Zn=(e,t)=>`${e}:${t}`,Cr=0,Qn=(e,t)=>{var n;typeof t=="string"&&((n=St.get(Zn(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"),Or=(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)}},eo=async(e,t)=>{var l;let{sources:n,targets:o}=Yn(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-${++Cr}`);St.set(c,a);try{return await kr(e,t,r,i,a.signal)}finally{St.delete(c)}},kr=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,Z;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},h=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw At();if(!h.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],y=h.filter(x=>yr(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||jn(x.name)}`}),!1)),P=y.map(()=>0),M=y.map(x=>{var ie;return(ie=x.size)!=null?ie:0}),v=0,A=0,O=(x=!1)=>{if(!a||!r)return;let ie=Date.now();if(!x&&ie-A<200)return;A=ie;let fe=M.reduce((T,Q)=>T+Q,0),z=P.reduce((T,Q)=>T+Q,0);a("upload.progress",{task_id:r,loaded:z,total:fe,percent:fe?Math.min(100,Math.round(z/fe*100)):0,done_count:v,count:y.length})},N=[],X=0,xe=async()=>{var x,ie,fe;for(;X<y.length;){let z=X++,T=y[z];try{if(g.aborted)throw At();let Q=T.mime_type.startsWith("image/")?"image":T.mime_type.startsWith("video/")?"video":void 0,B=Q&&!T.processed?(ie=(x=i==null?void 0:i.processors)==null?void 0:x[Q])!=null?ie:Tr[Q]:void 0;if(B&&(T=await B(T,e.process),M[z]=(fe=T.size)!=null?fe:M[z],g.aborted))throw At();if(e.max_size&&T.size&&T.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${T.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let K=(We,Se)=>{P[z]=We,Se&&(M[z]=Se),O()},ee=await s({file:T,target:e.target,onProgress:K,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;N[z]={url:_e,name:T.name,mime_type:T.mime_type,size:T.size,width:T.width,height:T.height,duration:T.duration,...Object.keys(Ae).length?{response:"response"in Ae?Ae.response:Ae}:{}},P[z]=M[z]}catch(Q){u.push(Or(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=N.filter(x=>!!x);if(!re.length){let x=u[0];throw new m((S=x==null?void 0:x.code)!=null?S:"UPLOAD_FAILED",(Z=x==null?void 0:x.message)!=null?Z:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:re,failed:u}};import{useRef as Ir,useSyncExternalStore as Lr}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)})}},V=(e,t,n=Object.is)=>{let o=Ir(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 Lr(e.subscribe,r)};var he={info:"info",success:"success",error:"error"},Fr=200,to={info:2e3,success:2e3,error:3e3},ot=ke({message:"",type:he.info,tick:0}),no=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Fr);return o?{message:o,type:Object.values(he).includes(n)?n:he.info}:null},oo=(e,t=he.info)=>{ot.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Alert as Nr,Linking as Ur,Platform as rt,StatusBar as Vr}from"react-native";import{AppState as ro,Platform as Kt}from"react-native";var de,io=()=>Kt.OS==="android"&&!!(de!=null&&de.requesting_permission),Dr=1500,vt=()=>new Promise(e=>{if(Kt.OS!=="android"||ro.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Dr),o=ro.addEventListener("change",r=>{r==="active"&&t()})}),Gt=e=>{var t;if(de===e&&(de=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Kt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},so=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(de)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};de=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let h;try{h=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await vt(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!h.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var y,P;de!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(P=(y=u.results[0])==null?void 0:y.transcript)!=null?P:""})}),d.addListener("error",u=>{de===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{de===r&&(Gt(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 Gt(r),g}},ao=e=>{let t=de;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{let t=de;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Gt(t)}};var co={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={...co,all:Object.values(co)},it={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Xt={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"},Br=1500,lo=6e4,I,j=ke({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),uo=()=>rt.OS==="android"&&!!(I!=null&&I.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=>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>lo)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${lo}`);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},Qt=e=>I!==e?!1:(I=void 0,j.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),qr=()=>Nr.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:()=>{Ur.openSettings().catch(()=>{})}}]),go=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 vt(),n(),c!=="granted")throw a&&qr(),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 en();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 Qt(e),o}},Mt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Mt=e==null?void 0:e.insets}).catch(()=>{});var xt=()=>{var e;return Mt!=null?Mt:{top:rt.OS==="ios"?54:(e=Vr.currentHeight)!=null?e:0,bottom:rt.OS==="ios"?34:48}},en=async()=>{if(rt.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:oe.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Br,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}},fo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=mo(e,Ie.once,t);a.onHit=o,a.resolve=r,a.reject=i,go(a,n).catch(i)}),ho=(e,t,n,o=()=>!0,r)=>{let i=mo(e,Ie.continuous,t);return i.emit=n,i.onHit=r,go(i,o)},Et=(e,t,n)=>{var o,r;if(!j.getState().active){e.cancelled=!0;return}if(Qt(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,Xt.end,n?{reason:t,message:n}:{reason:t})}},yo=e=>{(I==null?void 0:I.owner)===e&&Et(I,je.web)},Le=e=>{(I==null?void 0:I.owner)===e&&Et(I,je.closed)},tn=()=>{I&&Et(I,je.user)},wo=e=>{I&&Et(I,je.error,e)},nn=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=I;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){Qt(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}j.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})}}},$r={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},zr=2500,po=2e3,Yt=e=>{j.setState({notice:e}),setTimeout(()=>{j.getState().notice===e&&j.setState({notice:null})},zr)},bo=async()=>{var t,n;let e=I;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:po,maxHeight:po}),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){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(I!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:$r[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}nn(l,Date.now(),!0)}catch{I===e&&Yt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await vt(),e.requesting_permission=!1,I===e&&j.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},Ao=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,So=(e,t)=>at({id:e,result:t}),vo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),Mo=(e,t)=>at({event:e,data:t}),rn=e=>at({event:"context",data:e});var xo=()=>`(function () {
|
|
2
2
|
var post = function (level, args) {
|
|
3
3
|
try {
|
|
4
4
|
var parts = [];
|
|
@@ -8,7 +8,7 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
8
8
|
else if (typeof a === 'object') { try { parts.push(JSON.stringify(a).slice(0, 800)); } catch (e) { parts.push(String(a)); } }
|
|
9
9
|
else { parts.push(String(a)); }
|
|
10
10
|
}
|
|
11
|
-
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${
|
|
11
|
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'log', level: level, text: parts.join(' ') }));
|
|
12
12
|
} catch (e) {}
|
|
13
13
|
};
|
|
14
14
|
['log', 'info', 'warn', 'error'].forEach(function (level) {
|
|
@@ -19,7 +19,7 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
19
19
|
window.addEventListener('unhandledrejection', function (e) { post('error', ['[unhandledrejection]', e.reason]); });
|
|
20
20
|
// Kh\xF4ng log query (c\xF3 th\u1EC3 ch\u1EE9a token) \u2014 ch\u1EC9 \u0111\u01B0\u1EDDng d\u1EABn + route.
|
|
21
21
|
post('info', ['[page] ' + location.pathname + location.hash]);
|
|
22
|
-
})(); true;`,
|
|
22
|
+
})(); true;`,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; }
|
|
@@ -30,7 +30,7 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
30
30
|
function report(at_top) {
|
|
31
31
|
if (at_top === last) { return; }
|
|
32
32
|
last = at_top;
|
|
33
|
-
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${
|
|
33
|
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'touchAtTop', at_top: at_top }));
|
|
34
34
|
}
|
|
35
35
|
document.addEventListener('touchstart', function (e) { report(atTop(e.target)); }, { capture: true, passive: true });
|
|
36
36
|
// Cu\u1ED9n r\u1EDDi \u0111\u1EA7u trang \u2192 b\xE1o ngay, kh\xF4ng \u0111\u1EE3i l\u1EA7n ch\u1EA1m sau (tr\xE1nh host d\xF9ng gi\xE1 tr\u1ECB c\u0169 "\u0111ang \u1EDF \u0111\u1EA7u").
|
|
@@ -38,7 +38,7 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
38
38
|
var el = e.target === document ? document.documentElement : e.target;
|
|
39
39
|
if (el && el.scrollTop > 0) { report(false); }
|
|
40
40
|
}, { capture: true, passive: true });
|
|
41
|
-
})(); true;`,
|
|
41
|
+
})(); true;`,Ro=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,11 +59,14 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,To=e=>at({event:e}),Po=(e,t)=>{let n=Co(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${rn(e)}`},Co=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Oo=(e,t={})=>{let n=Co(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},on=new Set,st=async(e,t)=>{if(on.has(e))throw new m("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);on.add(e);try{return await t()}finally{on.delete(e)}},sn=e=>`(function () {
|
|
67
|
+
window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
|
|
68
|
+
window.dispatchEvent(new Event('retionscannerheight'));
|
|
69
|
+
})(); true;`,Lo=()=>`(function () {
|
|
67
70
|
try {
|
|
68
71
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
69
72
|
if (!AudioCtx) { return; }
|
|
@@ -82,4 +85,4 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
82
85
|
// iOS c\xF3 th\u1EC3 \u0111\u1EC3 context \u1EDF suspended / interrupted (vd. khi camera m\u1EDF phi\xEAn quay): ch\u1EA1y l\u1EA1i xong m\u1EDBi ph\xE1t.
|
|
83
86
|
if (ctx.state === 'running') { play(); } else { ctx.resume().then(play).catch(function () {}); }
|
|
84
87
|
} catch (e) {}
|
|
85
|
-
})(); true;`,Vr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),St=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},To=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:l,instance_id:c,options:s,emit:d,isActive:m,playBeep:h})=>{var M,A,_,W,Z,te,we;let p=s==null?void 0:s.handlers,y={app_id:l,instance_id:c,close:a},E=()=>{var w;(w=s==null?void 0:s.haptic)==null||w.call(s,"impactLight"),h==null||h()},v=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let w=Rn(t);return tt(e,()=>Tn(w,m))}case"speech.start":{if(!d)throw v();let w={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new g("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");w.lang=t.lang}for(let S of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[S])!==void 0){if(typeof t[S]!="boolean")throw new g("INVALID_PARAMS",`${S} ph\u1EA3i l\xE0 boolean`);w[S]=t[S]}return Qn(c,w,d,m)}case"speech.stop":return eo(c);case et.scan:return ao(c,Ht(t),m,E);case et.start:{if(!d)throw v();return co(c,Ht(t),d,m,E)}case et.stop:return lo(c);case"uploadFiles":{let{task_id:w,...S}=t!=null?t:{};if(w!==void 0&&(typeof w!="string"||!w))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Jn(Nn(S),{instance_id:c,app_id:l,getContext:r,task_id:w,config:s==null?void 0:s.upload,emit:d,exclusivePick:q=>tt("uploadFiles.pick",q)})}case"uploadFiles.cancel":Hn(c,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Wn(s==null?void 0:s.upload);case"getBiometricAvailability":return((M=s==null?void 0:s.biometrics)!=null?M:await Bt()).getAvailability();case"authenticateBiometric":{let w=St(t==null?void 0:t.reason,"reason").trim();if(!w||w.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let S=t==null?void 0:t.cancelButtonText;if(S!==void 0&&(typeof S!="string"||!S.trim()||S.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return tt(e,async()=>{var x;return((x=s==null?void 0:s.biometrics)!=null?x:await Bt()).authenticate({reason:w,cancelButtonText:S})})}case"requestPayment":{let w=p==null?void 0:p.requestPayment;if(!w)throw v();let S=t==null?void 0:t.amount;if(typeof S!="number"||!Number.isFinite(S)||S<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let q={...t,amount:S,currency:St(t==null?void 0:t.currency,"currency")};return tt(e,()=>w(q,y))}case"printImage":{let w=p==null?void 0:p.printImage;if(!w)throw v();let S=St(t==null?void 0:t.image,"image");await tt(e,()=>w({image:S},y));return}case"openScreen":if(!(p!=null&&p.openScreen))throw v();await p.openScreen({screen:St(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let w=String((A=t==null?void 0:t.url)!=null?A:"");if(!/^https?:\/\//i.test(w))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(w):go.openURL(w));return}case"openLink":{let w=String((_=t==null?void 0:t.url)!=null?_:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(w)||/^(javascript|file|data|about|blob):/i.test(w))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(w):go.openURL(w))}catch(S){throw new g("NOT_SUPPORTED",String((Z=(W=S==null?void 0:S.message)!=null?W:S)!=null?Z:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let w=Kn(t);if(!w||(m==null?void 0:m())===!1)return;s!=null&&s.showToast?s.showToast(w.message,{type:w.type}):Yn(w.message,w.type);return}case"haptic":{let w=Vr.has(t==null?void 0:t.type)?t.type:"selection";(te=s==null?void 0:s.haptic)==null||te.call(s,w);return}case"getSystemInfo":return{platform:Ur.OS==="ios"?"ios":"android",appVersion:(we=s==null?void 0:s.app_version)!=null?we:"",theme:i?"dark":"light"};case"getAccessToken":{let w=n().access_token;if(!w)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return w}case"getToken":{let w=t==null?void 0:t.type;if(w==="access"){let x=n().access_token;if(!x)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return x}if(w!=="partner"&&w!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(w)}`);let S=xo[w];if(!o().includes(S))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${S} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let q=w==="partner"?n().partner_token:n().chatbox_token;if(!q)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${S}`);return q}case"getUserInfo":{let w=n().user;if(!w)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return w}case"getPageInfo":{let w=n().page;if(!w)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return w}case"sendMessage":case"insertText":throw new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new g("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var en=e=>`bundle:${e}`,tn=()=>`${D().file_system.document_dir}/miniapps`,nn=tn,on=(e,t,n="index.html",o=!1,r=[])=>{let i=`${nn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},Qt=e=>{var t;D().storage.setString(en(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Br=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,F=e=>{let t=D().storage.getString(en(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return on(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},xe=e=>D().file_system.exists(e.entry_uri.replace("file://","")),rn=async e=>{let t=F(e.app_id);return(t==null?void 0:t.version)===e.version&&await xe(t)},Co=async(e,t)=>{let n=D().file_system,o=`${nn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Oo=async e=>{var t;await((t=rt[e])==null?void 0:t.catch(()=>{})),D().storage.setString(en(e),""),await D().file_system.remove(`${nn()}/${e}`).catch(()=>{})},We=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},rt={},ko=(e,t)=>{var i;let o=((i=rt[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return rt[e]=r,r.then(()=>{rt[e]===r&&delete rt[e]}),o},qr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let l=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(l)return l}return 0},$r=({manifest:e,zip_path:t})=>ko(e.app_id,async()=>{var i;let n=D().file_system,o=F(e.app_id);if(o&&qr(o.version,e.version)>=0&&await xe(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=on(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),Qt(e),le("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Co(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),sn=(e,{base_url:t,onProgress:n}={})=>{let o=D().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new We},c=async()=>{var m;l();let s=F(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Qt(e),F(e.app_id);l();let d=o.download({url:t?Br(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(h,p)=>{var E;let y=p>0?p:(E=e.size)!=null?E:0;y>0&&(n==null||n(Math.min(1,h/y)))}});r=d;try{let{status:h}=await d.promise;if(l(),h!==200)throw new Error(`bundle ${h}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else le("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let p=on(e.app_id,e.version,e.entry,!!e.context_update,(m=e.permissions)!=null?m:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),Qt(e),Co(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(h){throw i?new We:h}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:ko(e.app_id,c),cancel:()=>{i=!0,r==null||r.cancel()}}},ot={},zr=__DEV__?0:60*1e3,Po={},Io=(e,t)=>{var o,r;let n=F(e);return n&&Date.now()-((o=Po[t])!=null?o:0)<zr?Promise.resolve(n):((r=ot[e])!=null||(ot[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),l=await sn(a,{base_url:t}).promise;return Po[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),F(e))).finally(()=>{ot[e]=void 0})),ot[e])};var Mt=new Map,Lo=(e,t)=>(Mt.set(e,t),()=>{Mt.get(e)===t&&Mt.delete(e)}),Wr=(e,t)=>{let n=Mt.get(e);return n?n(t):!1};import{useCallback as Fo,useEffect as it,useRef as Ce,useState as xt}from"react";import{Animated as z,BackHandler as jr,Dimensions as Hr,Easing as Do,Pressable as Jr,StyleSheet as cn,Text as st,View as B}from"react-native";import{Fragment as oi,jsx as R,jsxs as _e}from"react/jsx-runtime";var at="#22C55E",Gr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Kr=2,Rt=18,Yr=1600,ct=14,Xr=2e3,Vo=.38,Zr=40,No=2,Qr=8,ei=2e3,je=2e3,ti=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ct},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ct},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ct},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ct}],Uo=({color:e})=>R(oi,{children:ti.map((t,n)=>R(B,{style:[b.corner,t,{borderColor:e}]},n))}),Et=({style:e,children:t,...n})=>{let o=Ce(new z.Value(1)).current,r=i=>z.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return R(Jr,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:R(z.View,{style:[e,{transform:[{scale:o}]}],children:t})})},ln=({scanner:e})=>{var Je,f;let{vision:t,types:n,mode:o,layout:r,hint:i,glass_view:a}=e,l=r===Me.top,c=t.useCameraDevice("back"),s=Ce(new z.Value(1)).current,[d,m]=xt(!1),[h,p]=xt(1),y=Ce(null),[E,v]=xt(()=>{let{width:u,height:P}=Hr.get("window");return{width:u,height:l?P*Vo:P,window_y:0}}),M=V(H,u=>u.last_value),A=V(H,u=>u.hit_tick),_=V(H,u=>u.scan_count),W=V(H,u=>u.notice),Z=V(H,u=>u.is_picking),te=Ce(null),we=bt(),w=we.top,S=Ce(new z.Value(0)).current,q=Ce(new z.Value(0)).current,x=Ce(new z.Value(0)).current,C=Math.round(E.width*(l?.8:.78)),k=Math.round(l?E.height*.46:C*.78),N=Math.round((E.height-k)/2),I=Math.round((E.width-C)/2),Q=t.useCodeScanner({codeTypes:n,onCodeScanned:Fo(u=>Yt(u),[])});it(()=>{let u=jr.addEventListener("hardwareBackPress",()=>(Kt(),!0));return()=>u.remove()},[]);let Le=Ce(A);it(()=>{if(A===Le.current)return;S.setValue(1),x.setValue(1);let u=z.parallel([z.timing(S,{toValue:0,duration:450,useNativeDriver:!0}),z.sequence([z.delay(Xr),z.timing(x,{toValue:0,duration:250,useNativeDriver:!0})])]);return u.start(),()=>u.stop()},[A,S,x]),it(()=>{let u=ee=>z.timing(q,{toValue:ee,duration:Yr,easing:Do.inOut(Do.quad),useNativeDriver:!0}),P=z.loop(z.sequence([u(1),u(0)]));return P.start(),()=>P.stop()},[q]);let de=Fo(()=>{z.timing(s,{toValue:0,duration:220,useNativeDriver:!0}).start()},[s]);it(()=>{let u=setTimeout(de,ei);return()=>clearTimeout(u)},[de]);let[ne,Fe]=xt(!1);it(()=>{let u=requestAnimationFrame(()=>{u=requestAnimationFrame(()=>Fe(!0))});return()=>cancelAnimationFrame(u)},[]);let be=!!(c!=null&&c.hasTorch),Ae=(Je=c==null?void 0:c.neutralZoom)!=null?Je:1,Se=c?Math.min(c.maxZoom/Ae,Qr):1,Dt=Ae*Math.min(h,Se),Nt=u=>{var ae;let{touches:P}=u.nativeEvent;if(P.length!==2){y.current=null;return}let ee=Math.hypot(P[0].pageX-P[1].pageX,P[0].pageY-P[1].pageY);(ae=y.current)!=null||(y.current={distance:ee,level:h}),p(Math.max(1,Math.min(Se,y.current.level*(ee/y.current.distance))))},mt=R(st,{style:[b.hint,!!W&&b.hint_notice],numberOfLines:1,children:(f=W!=null?W:i)!=null?f:Gr});return R(B,{ref:te,onTouchMove:Nt,onTouchEnd:()=>{y.current=null},style:l?b.top:b.full,onLayout:({nativeEvent:{layout:u}})=>{var P;(P=te.current)==null||P.measureInWindow((ee,ae)=>{v({width:u.width,height:u.height,window_y:ae||0})})},children:_e(B,{style:b.content,children:[c&&ne&&R(t.Camera,{style:cn.absoluteFill,device:c,isActive:!Z,codeScanner:Q,torch:d&&be?"on":"off",zoom:Dt,onPreviewStarted:de,onError:u=>po(u.message)}),R(z.View,{style:[b.preview_cover,{opacity:s}],pointerEvents:"none"}),E.height>0&&_e(B,{style:b.overlay,pointerEvents:"none",children:[R(B,{style:[b.dim_ring,{top:N-je,left:I-je,width:C+je*2,height:k+je*2}]}),_e(B,{style:{position:"absolute",top:N,left:I,width:C,height:k},children:[R(Uo,{color:"#FFFFFF"}),R(z.View,{style:[cn.absoluteFill,{opacity:S}],children:R(Uo,{color:at})}),_e(z.View,{style:[b.scan_line_wrap,{transform:[{translateY:q.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,k-Rt)]})}]}],children:[R(B,{style:b.scan_glow_outer}),R(B,{style:b.scan_glow_inner}),R(B,{style:b.scan_line})]})]}),R(B,{style:[b.hint_slot,l?{top:0,height:N-6,justifyContent:"flex-end"}:{top:N+k+20}],children:mt}),o===Ve.continuous&&!!M&&R(z.View,{style:[b.result_slot,{top:l?N+k-Zr:N+k+52},{opacity:x}],children:_e(B,{style:b.result,children:[R(B,{style:b.check_badge,children:R(B,{style:b.check_mark})}),R(st,{style:b.result_text,numberOfLines:1,children:M}),_e(st,{style:b.result_count,children:["\xB7 ",_," m\xE3"]})]})})]}),E.height>0&&R(B,{style:[b.close_slot,l?b.close_slot_top:{top:Math.max(12,w-E.window_y+12)}],children:_e(Et,{style:[b.close_button,!!a&&b.glass_surface],onPress:Kt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[a&&R(a,{style:b.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),R(B,{style:[b.close_bar,b.close_bar_a]}),R(B,{style:[b.close_bar,b.close_bar_b]})]})}),R(B,{style:[b.toolbar_wrap,!l&&{bottom:we.bottom+20}],pointerEvents:"box-none",children:_e(B,{style:[b.toolbar,!!a&&b.glass_surface],children:[a&&R(a,{style:b.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),R(Et,{style:b.tool,onPress:uo,disabled:Z,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:_e(B,{style:b.image_icon,children:[R(B,{style:b.image_icon_dot}),R(B,{style:b.image_icon_hill})]})}),!!c&&Se>=No&&R(Et,{style:[b.tool,h>1&&b.tool_on],onPress:()=>p(u=>u>1?1:No),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:_e(st,{style:[b.zoom_text,h>1&&b.zoom_text_on],children:[Math.round(h*10)/10,"x"]})}),be&&R(Et,{style:[b.tool,d&&b.tool_on],onPress:()=>m(u=>!u),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:d},children:R(st,{style:[b.torch_icon,d&&b.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},ni="rgba(0,0,0,0.5)",an=50,b=cn.create({top:{height:`${Vo*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:je,borderColor:ni,borderRadius:je+ct},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:Rt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Rt,borderRadius:Rt/2,backgroundColor:at,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:at,opacity:.2},scan_line:{height:Kr,borderRadius:1,backgroundColor:at},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:an,height:an,borderRadius:an/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:at},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});import{useEffect as Bo,useRef as lt,useState as qo}from"react";import{AccessibilityInfo as ri,Animated as J,Platform as ii,StyleSheet as $o,Text as si,View as Be}from"react-native";import{Fragment as jo,jsx as oe,jsxs as un}from"react/jsx-runtime";var pn={[me.info]:"#3B82F6",[me.success]:"#22C55E",[me.error]:"#EF4444"},zo=-120,Tt=ii.OS==="android",Wo=({type:e})=>e===me.success?oe(Be,{style:Y.check_mark}):e===me.error?un(jo,{children:[oe(Be,{style:[Y.cross_bar,Y.cross_a]}),oe(Be,{style:[Y.cross_bar,Y.cross_b]})]}):un(jo,{children:[oe(Be,{style:Y.info_dot}),oe(Be,{style:Y.info_bar})]}),Ho=()=>{let e=V(Ze,h=>h.message),t=V(Ze,h=>h.type),n=V(Ze,h=>h.tick),o=lt(new J.Value(zo)).current,r=lt(new J.Value(0)).current,i=lt(new J.Value(.92)).current,a=lt(new J.Value(0)).current,[l,c]=qo(),[s,d]=qo(!1);Bo(()=>{let h=!0;return Gt().then(p=>{h&&p&&c(()=>p)}),()=>{h=!1}},[]);let m=lt(n);return Bo(()=>{if(n===m.current)return;ri.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let h=J.sequence([J.parallel([J.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),J.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),J.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),J.sequence([J.delay(90),J.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),J.delay(Gn[t]),J.parallel([J.timing(o,{toValue:zo,duration:240,useNativeDriver:!0}),J.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return h.start(({finished:p})=>{p&&d(!1)}),()=>h.stop()},[n]),s?oe(Be,{style:[Y.layer,{top:bt().top+(Tt?12:8)}],pointerEvents:"none",children:un(J.View,{style:[Y.toast,Tt&&Y.toast_android,!!l&&Y.toast_glass,{opacity:l?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[l&&oe(l,{style:Y.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Tt?oe(J.View,{style:[Y.badge_halo,{backgroundColor:`${pn[t]}33`,transform:[{scale:a}]}],children:oe(Be,{style:[Y.badge,{backgroundColor:pn[t]}],children:oe(Wo,{type:t})})}):oe(J.View,{style:[Y.badge,{backgroundColor:pn[t],transform:[{scale:a}]}],children:oe(Wo,{type:t})}),oe(si,{style:[Y.message,Tt&&Y.message_android],numberOfLines:2,children:e})]})}):null},Y=$o.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:$o.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var re=Te({active_key:null,instances:{}}),Jo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var l;let a=(l=D().keep_alive)==null?void 0:l.max_webviews;re.setState(c=>{let s=t!=null?t:e.app_id,d={...c.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},m=Object.keys(d);return a&&a>0&&m.length>a&&m.filter(h=>h!==s).sort((h,p)=>d[h].last_used_at-d[p].last_used_at).slice(0,m.length-a).forEach(h=>{delete d[h]}),i?{active_key:s,instances:d}:{instances:d}})},ai=e=>Jo(e,!0),ci=e=>Jo(e,!1),pt=()=>re.setState({active_key:null}),Pt=e=>{re.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var Go="catalog",li="paused_apps",pi="removed_apps",ui=10*1e3,di=2,gi=3e3,mi=()=>{var e;try{return JSON.parse((e=D().storage.getString(Go))!=null?e:"{}")}catch{return{}}},O=Te({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Ko=e=>{var t;return!!((t=D().manual_update)!=null&&t.includes(e))},kt=new Set,Yo=e=>{let t=new Set,n=()=>D().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=D().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},he=Yo(li),Ie=Yo(pi);xn(()=>{he.load(),Ie.load();let e=mi(),t={};Object.keys(e).filter(n=>!Ie.has(n)).forEach(n=>{let o=F(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:he.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),O.setState({catalog:e,downloads:t})});var gn=e=>V(O,t=>e?t.downloads[e]:void 0),fi=()=>V(O,e=>e.pause_reasons.length>0),fe=(...e)=>le("queue",...e),G=[],Ee={},T=null,Ct=new Set,qe={},dn=new Set,Oe=e=>{dn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},hi=e=>(dn.add(e),()=>{dn.delete(e)}),yi=()=>O.getState().downloads,ie=(e,t)=>{let n=!!F(e),o=O.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};O.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Oe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Oe({type:"progress",app_id:e,progress:i.progress,version:i.version})},Ot=(e,t)=>{var n;(n=qe[e])==null||n.forEach(o=>o(t)),delete qe[e]},wi=()=>O.getState().pause_reasons.length>0,ke=e=>{var l;if(T)return;let t=e?G.indexOf(e):wi()?-1:G.findIndex(c=>!he.has(c));if(t<0||t>=G.length)return;let[n]=G.splice(t,1),o=O.getState().catalog[n];if(!o){Ot(n,F(n)),ke();return}let r=Date.now();Ee[n]=((l=Ee[n])!=null?l:0)+1,ie(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=sn(o,{onProgress:c=>{let s=Math.floor(c*100);s!==i&&(i=s,ie(n,{progress:s/100,version:o.version}))}});T={app_id:n,handle:a,forced:!!e},fe("start",n,o.version,e?"(forced)":""),a.promise.then(c=>{fe("installed",n,o.version,`${Date.now()-r}ms`),ie(n,{status:"installed",progress:1,version:o.version}),Ot(n,c)}).catch(c=>{var d;if(c instanceof We){if(Ct.has(n))return;fe("paused",n),Ee[n]-=1,G.unshift(n),ie(n,{status:he.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=c==null?void 0:c.message)!=null?d:c);if(console.warn("[miniapp-queue] failed",n,s),Ee[n]<di){ie(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var m;G.includes(n)||(T==null?void 0:T.app_id)===n||(G.push(n),ke((m=qe[n])!=null&&m.length?n:void 0))},gi);return}ie(n,{status:"failed",progress:0,version:o.version,error:s}),Ot(n,F(n))}).finally(()=>{T=null;let c=G.find(s=>{var d;return(d=qe[s])==null?void 0:d.length});ke(c)})},It=(e,{front:t=!1}={})=>{if((T==null?void 0:T.app_id)===e)return;let n=G.indexOf(e);if(n>=0){if(!t)return;G.splice(n,1)}t?G.unshift(e):G.push(e)},_i=async e=>{let{host_id:t,client_token:n}=D(),o=new AbortController,r=setTimeout(()=>o.abort(),ui);try{let i=`${Vt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(c=>({...c,channel:e}))}finally{clearTimeout(r)}},ut=null,mn=()=>(ut!=null||(ut=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(D().channels.map(_i)),o={};[...n].reverse().flat().forEach(c=>{o[c.app_id]=c});let r=Object.keys(O.getState().catalog).filter(c=>!o[c]);D().storage.setString(Go,JSON.stringify(o)),O.setState({catalog:o}),await Promise.all(r.map(c=>Xo(c,{by_user:!1}))),r.forEach(c=>Ie.delete(c));let i=Object.keys(o).filter(c=>!Ie.has(c)),a=[],l={};for(let c of i.map(s=>o[s])){if(await rn(c)){ie(c.app_id,{status:"installed",progress:1,version:c.version});continue}let s=F(c.app_id);if(Ko(c.app_id)&&!kt.has(c.app_id)&&s&&await xe(s)){ie(c.app_id,{status:"installed",progress:1,version:s.version}),l[c.app_id]={app_id:c.app_id,current_version:s.version,next_version:c.version};continue}a.push(c)}return O.setState({updates:l}),a.forEach(c=>{Ee[c.app_id]=0,ie(c.app_id,{status:he.has(c.app_id)?"paused":"queued",progress:0,version:c.version,error:void 0}),It(c.app_id)}),fe("catalog",i.length,"apps, outdated",a.map(c=>c.app_id),"removed",r,`${Date.now()-e}ms`),Oe({type:"sync_complete",app_ids:i,removed:r}),Object.values(l).forEach(c=>Oe({type:"update_available",...c})),ke(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Oe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ut=null}})()),ut),Xo=async(e,{by_user:t})=>{var r,i,a,l;if(t&&Ie.add(e),Ct.has(e))return;Ct.add(e),he.delete(e);let n=G.indexOf(e);n>=0&&G.splice(n,1),(T==null?void 0:T.app_id)===e&&T.handle.cancel();let o=(l=(a=(r=O.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=F(e))==null?void 0:i.version)!=null?l:"";ie(e,{status:"uninstalling",progress:0,version:o}),await Oo(e),Pt(e),O.setState(c=>{let s={...c.downloads};return delete s[e],{downloads:s}}),delete Ee[e],Ct.delete(e),Ot(e,null),fe("uninstalled",e,t?"(user)":"(not in list)"),Oe({type:"uninstalled",app_id:e})},bi=e=>Xo(e,{by_user:!0}),Ai=e=>{let t=dt(e);return t?(Ie.delete(e),(T==null?void 0:T.app_id)===e||G.includes(e)||(Ee[e]=0,ie(e,{status:he.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),It(e),ke(),fe("restore",e)),!0):!1},Si=e=>{if(he.has(e))return;if(he.add(e),fe("pause app",e),(T==null?void 0:T.app_id)===e&&!T.forced){T.handle.cancel();return}let t=O.getState().downloads[e];G.includes(e)&&t&&ie(e,{status:"paused",progress:0,version:t.version})},vi=e=>{if(!he.delete(e))return;fe("resume app",e);let t=O.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!G.includes(e)&&dt(e)&&(Ee[e]=0,It(e)),G.includes(e)&&t&&ie(e,{status:"queued",progress:0,version:t.version}),ke()},Mi=e=>{let{pause_reasons:t}=O.getState();t.includes(e)||(O.setState({pause_reasons:[...t,e]}),fe("pause",e),t.length===0&&Oe({type:"pause_change",paused:!0,reasons:[e]}),T&&!T.forced&&T.handle.cancel())},xi=e=>{let{pause_reasons:t}=O.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);O.setState({pause_reasons:n}),fe("resume",e),n.length===0&&Oe({type:"pause_change",paused:!1,reasons:n}),ke()},Zo=e=>O.getState().updates[e],Ei=async e=>{var n,o;let t=Zo(e);kt.add(e);try{let r=await Lt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=dt(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(O.setState(a=>{var c;let l={...a.updates};return delete l[e],{updates:l,apply_ticks:{...a.apply_ticks,[e]:((c=a.apply_ticks[e])!=null?c:0)+1}}}),fe("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{kt.delete(e)}},Ri=()=>Object.values(O.getState().catalog).map(e=>({...e,installed:!!F(e.app_id),removed_by_user:Ie.has(e.app_id)})),dt=e=>O.getState().catalog[e],Lt=async e=>{let t=dt(e);if(!t)return;if(he.delete(e),Ie.delete(e),await rn(t))return F(e);let n=F(e);if(Ko(e)&&!kt.has(e)&&n&&await xe(n))return n;let o=new Promise(r=>{var i;((i=qe[e])!=null?i:qe[e]=[]).push(r)});return(T==null?void 0:T.app_id)===e?T.forced=!0:(Ee[e]=0,It(e,{front:!0}),T&&!T.forced?T.handle.cancel():ke(e)),o};import{Fragment as _n,jsx as K,jsxs as He}from"react/jsx-runtime";var hn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),er=0,Ii=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Li=bn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:l,opaque_background:c,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var mt,Je;let m=ye(null),h=ye(!1),p=V(re,f=>f.instances[e]),y=p==null?void 0:p.app.app_id,E=p==null?void 0:p.app.manifest_url,v=p==null?void 0:p.context,M=p==null?void 0:p.url_params,A=V(H,f=>{var u;return((u=f.active)==null?void 0:u.owner)===e?f.active:null}),[_,W]=$e(()=>y?F(y):null),[Z,te]=$e(!1),[we,w]=$e(0),[S,q]=$e(0),[x,C]=$e(!1),k=ye(null),N=f=>{k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{k.current=null,C(!0)},f)};se(()=>()=>{k.current&&clearTimeout(k.current)},[]),se(()=>{if(!y||!t&&_)return;let f=!0;return te(!1),(async()=>{let u=F(y),P=u?await xe(u):!1;if(!f||(W(P?ge=>!ge||ge.version!==u.version||ge.permissions.join(",")!==u.permissions.join(",")?u:ge:null),__DEV__&&Date.now()-er>1e4&&(er=Date.now(),await mn()),!f))return;let ee=await Lt(y),ae=ee!==void 0?ee:E?await Io(y,E):F(y);if(f){if(!ae){te(!0);return}W(ge=>ge!=null?ge:ae)}})(),()=>{f=!1}},[t,y,E,we]),se(()=>Lo(e,f=>m.current?(m.current.postMessage(f),!0):!1),[e]);let I=V(O,f=>{let u=y?f.downloads[y]:void 0;return(u==null?void 0:u.status)==="installed"?u.version:void 0});se(()=>{if(t||!y||!_)return;let f=F(y);if(!f||f.version===_.version)return;let u=!0;return xe(f).then(P=>{!u||!P||(le(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",_.version,"\u2192",f.version),W(f))}),()=>{u=!1}},[t,y,I,_==null?void 0:_.version]);let Q=V(O,f=>{var u;return y&&(u=f.apply_ticks[y])!=null?u:0});se(()=>{if(!Q||!y)return;let f=F(y);if(!f||f.version===(_==null?void 0:_.version))return;let u=!0;return xe(f).then(P=>{!u||!P||(le(`webview:${e}`,"c\u1EADp nh\u1EADt",_==null?void 0:_.version,"\u2192",f.version),C(!1),W(f))}),()=>{u=!1}},[Q]),se(()=>{var P;let f=(P=D().keep_alive)==null?void 0:P.idle_close_ms;if(t||!f||f<=0)return;let u=setTimeout(()=>{Pt(e)},f);return()=>clearTimeout(u)},[t,e]),se(()=>{r>0&&(te(!1),C(!1),q(f=>f+1),w(f=>f+1))},[r]);let Le=ye(t);se(()=>{var f;Le.current!==t&&(Le.current=t,h.current&&((f=m.current)==null||f.injectJavaScript(Ao(t?"resumed":"paused"))))},[t]);let de=`${(mt=_==null?void 0:_.version)!=null?mt:"none"}:${(Je=_==null?void 0:_.permissions.join(","))!=null?Je:""}:${S}`,ne=Ft(()=>JSON.stringify([v!=null?v:{},M!=null?M:{}]),[v,M]),Fe=Ft(()=>{var f;return Eo(M!=null?M:{},(f=_==null?void 0:_.permissions)!=null?f:[])},[ne,_==null?void 0:_.permissions]),be=Ft(()=>Mo(v!=null?v:{},Fe)+_o()+bo()+(D().debug?wo():""),[Fe]),Ae=ye(null),Se=ye(null);se(()=>{var u,P,ee;if(!_)return;if(Se.current!==de){Se.current=de,Ae.current=ne;return}if(Ae.current===ne)return;let f=((P=JSON.parse((u=Ae.current)!=null?u:"[]")[0])!=null?P:{}).org_id;if(Ae.current=ne,f===(v==null?void 0:v.org_id)&&h.current){C(!1),N(1500),(ee=m.current)==null||ee.injectJavaScript(So(v!=null?v:{},Fe));return}C(!1),q(ae=>ae+1)},[ne,_,de]),se(()=>(t||(ve(e),Pe(e),Ue(e)),()=>{ve(e),Pe(e),Ue(e)}),[t,e,de,r]),se(()=>{let f=Qo.addEventListener("change",u=>{u==="background"&&!Zn()&&ve(e),u==="background"&&!ro()&&Pe(e)});return()=>f.remove()},[e]);let Dt=yn(async f=>{var P,ee,ae,ge,Ut,Sn;let u=mo(f.nativeEvent.data);if(!u){if(y&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(U=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,U)})}catch(U){console.warn("[miniapp] onWebEvent l\u1ED7i",y,U)}return}if(u.method==="log"){let{level:U,text:$}=u;le(`web:${e}`,U!=null?U:"log",$!=null?$:"");return}if(u.method==="pong"){k.current||C(!0);return}if(u.method==="touchAtTop"){i.emit(!!u.at_top);return}if(u.method==="contextApplied"){k.current&&clearTimeout(k.current),k.current=null,C(!0);return}if(u.method==="ready"){h.current=!0,C(!0);let U=(P=re.getState().instances[e])==null?void 0:P.context;U&&((ee=m.current)==null||ee.injectJavaScript(Zt(U)));return}try{let U=await To(u,{getHostData:()=>{var $,ce;return(ce=($=re.getState().instances[e])==null?void 0:$.host_data)!=null?ce:{}},getPermissions:()=>{var $,ce;return y?(ce=($=F(y))==null?void 0:$.permissions)!=null?ce:[]:[]},getContext:()=>{var $,ce;return(ce=($=re.getState().instances[e])==null?void 0:$.context)!=null?ce:{}},is_dark:o,close:pt,app_id:y!=null?y:"",instance_id:e,options:l,emit:($,ce)=>{var vn;(vn=m.current)==null||vn.injectJavaScript(yo($,ce))},playBeep:(ae=l==null?void 0:l.playScannerBeep)!=null?ae:(()=>{var $;($=m.current)==null||$.injectJavaScript(Ro())}),isActive:()=>re.getState().active_key===e&&Qo.currentState!=="background"});u.id&&((ge=m.current)==null||ge.injectJavaScript(fo(u.id,U)))}catch(U){if(!u.id)return;let $=U==null?void 0:U.code,ce=U instanceof g?U:new g(typeof $=="string"?$:"HOST_ERROR",String((Ut=U==null?void 0:U.message)!=null?Ut:U));(Sn=m.current)==null||Sn.injectJavaScript(ho(u.id,ce))}},[e,o,y,i,l]),Nt=yn(()=>{te(!1),q(f=>f+1),w(f=>f+1)},[]);return He(wn,{style:[An.absoluteFill,c&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&ue.behind],pointerEvents:t?"auto":"none",children:[(A==null?void 0:A.layout)===Me.top&&K(ln,{scanner:A}),_?K(ki,{ref:m,source:{uri:_.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?tn():_.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:be,onMessage:Dt,bounces:!1,overScrollMode:"never",onLoadStart:f=>{ve(e),Pe(e),Ue(e),le(`webview:${e}`,"load start",hn(f.nativeEvent.url)),h.current=!1,C(!1)},onError:f=>{ve(e),Pe(e),Ue(e),le(`webview:${e}`,"load error",hn(f.nativeEvent.url),f.nativeEvent.description),te(!0),C(!1)},onLoadEnd:f=>{let u=f.nativeEvent.url;le(`webview:${e}`,"load end",hn(u)),y&&(d==null||d({app_id:y,instance_id:e,url:u})),N(1500)},onContentProcessDidTerminate:()=>{ve(e),Pe(e),Ue(e),h.current=!1,C(!1),q(f=>f+1)},onRenderProcessGone:()=>(ve(e),Pe(e),Ue(e),h.current=!1,C(!1),q(f=>f+1),!0),style:ue.webview},de):null,(A==null?void 0:A.layout)===Me.full&&K(ln,{scanner:A}),p&&K(Di,{visible:!_||!x,interactive:Z,children:K(Fi,{splash:a,app:p.app,is_dark:o,error:Z,has_bundle:!!_,retry:Nt})})]})}),Fi=bn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,l=gn(t.app_id),c=o?"error":!r&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return K(a,{app:t,is_dark:n,status:c,progress:c==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),Di=({visible:e,interactive:t,children:n})=>{let o=ye(new fn.Value(e?1:0)).current,[r,i]=$e(e);return se(()=>{if(e){i(!0),o.setValue(1);return}let a=fn.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:l})=>{l&&i(!1)}),()=>a.stop()},[e,o]),r?K(fn.View,{style:[An.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},nr=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return He(wn,{style:[ue.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[K(wn,{style:[ue.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?K(Ci,{source:{uri:e.icon},style:ue.splash_icon_image}):K(gt,{style:ue.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),K(gt,{style:[ue.splash_name,{color:i}],children:e.name}),n==="error"?He(_n,{children:[K(gt,{style:ue.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),K(Oi,{activeOpacity:.7,style:[ue.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:K(gt,{style:[ue.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):He(_n,{children:[K(Ti,{style:ue.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&He(gt,{style:ue.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},tr=(e,t)=>{let n=ye(t),o=ye(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},Ni=({container:e,splash:t=nr,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:l})=>{tr("container",e),tr("splash",t);let c=e,s=V(re,A=>A.active_key),d=ye(s);s&&(d.current=s);let m=V(re,A=>Object.keys(A.instances).join("|")),h=V(re,A=>{var _;return A.active_key?(_=A.instances[A.active_key])==null?void 0:_.app.name:void 0}),p=Ft(()=>m?m.split("|"):[],[m]),[y,E]=$e({}),v=ye(Ii()).current;se(()=>{if(!s||!r)return;let A=Pi.addEventListener("hardwareBackPress",()=>(pt(),!0));return()=>A.remove()},[s,r]);let M=yn(()=>{let A=re.getState().active_key;A&&E(_=>({..._,[A]:(_[A]||0)+1}))},[]);return p.length?He(_n,{children:[K(c,{visible:!!s,title:h!=null?h:"",is_dark:n,close:pt,reload:M,subscribeWebAtTop:v.subscribe,children:p.map(A=>K(Li,{instance_key:A,is_active:s===A,is_front:(s!=null?s:d.current)===A,is_dark:n,reload_tick:y[A]||0,web_at_top:v,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:l},A))}),K(Ho,{})]}):null},ue=An.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),Ui=bn.memo(Ni);export{X as CodeType,nr as DefaultMiniAppSplash,Vt as MINIAPP_PLATFORM_URL,Ui as MiniAppHost,g as MiniAppHostError,ze as ScannerEndReason,jt as ScannerEvent,Me as ScannerLayout,et as ScannerMethod,me as ToastType,pt as closeMiniApp,or as configureMiniApp,ir as createMmkvStorage,En as createReactNativeBiometrics,rr as createRnfsFileSystem,Lt as ensureMiniApp,F as getLocalMiniApp,Ri as getMiniAppCatalog,dt as getMiniAppCatalogEntry,yi as getMiniAppStatuses,Zo as getMiniAppUpdate,$r as installBundledMiniApp,hi as onMiniAppEvent,ai as openMiniApp,Si as pauseMiniApp,Mi as pauseMiniAppDownloads,ci as preloadMiniApp,ve as releaseSpeechFor,Ai as restoreMiniApp,vi as resumeMiniApp,xi as resumeMiniAppDownloads,Wr as sendEventToWeb,mn as syncMiniAppCatalog,bi as uninstallMiniApp,Ei as updateMiniApp,$n as uploadToUrl,gn as useMiniAppDownload,fi as useMiniAppDownloadsPaused};
|
|
88
|
+
})(); true;`,jr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Rt=(e,t)=>{if(typeof e!="string"||!e)throw new m("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:g,isActive:d,playBeep:h})=>{var v,A,O,N,X,xe,re;let u=s==null?void 0:s.handlers,y={app_id:c,instance_id:l,close:a},P=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),h==null||h()},M=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Ln(t);return st(e,()=>Fn(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 S of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[S])!==void 0){if(typeof t[S]!="boolean")throw new m("INVALID_PARAMS",`${S} ph\u1EA3i l\xE0 boolean`);p[S]=t[S]}return so(l,p,g,d)}case"speech.stop":return ao(l);case it.scan:return fo(l,Zt(t),d,P);case it.start:{if(!g)throw M();return ho(l,Zt(t),g,d,P)}case it.stop:return yo(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 eo(Wn(S),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:Z=>st("uploadFiles.pick",Z)})}case"uploadFiles.cancel":Qn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Xn(s==null?void 0:s.upload);case"getBiometricAvailability":return((v=s==null?void 0:s.biometrics)!=null?v:await Ht()).getAvailability();case"authenticateBiometric":{let p=Rt(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 Ht()).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 Z={...t,amount:S,currency:Rt(t==null?void 0:t.currency,"currency")};return st(e,()=>p(Z,y))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw M();let S=Rt(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:Rt(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):_o.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):_o.openURL(p))}catch(S){throw new m("NOT_SUPPORTED",String((X=(N=S==null?void 0:S.message)!=null?N:S)!=null?X:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=no(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):oo(p.message,p.type);return}case"haptic":{let p=jr.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:Wr.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=ko[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 Z=p==="partner"?n().partner_token:n().chatbox_token;if(!Z)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${S}`);return Z}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 cn=e=>`bundle:${e}`,ln=()=>`${F().file_system.document_dir}/miniapps`,pn=ln,un=(e,t,n="index.html",o=!1,r=[])=>{let i=`${pn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},an=e=>{var t;F().storage.setString(cn(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Hr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,L=e=>{let t=F().storage.getString(cn(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return un(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Te=e=>F().file_system.exists(e.entry_uri.replace("file://","")),dn=async e=>{let t=L(e.app_id);return(t==null?void 0:t.version)===e.version&&await Te(t)},No=async(e,t)=>{let n=F().file_system,o=`${pn()}/${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=lt[e])==null?void 0:t.catch(()=>{})),F().storage.setString(cn(e),""),await F().file_system.remove(`${pn()}/${e}`).catch(()=>{})},He=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},Vo=(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},Gr=({manifest:e,zip_path:t})=>Vo(e.app_id,async()=>{var i;let n=F().file_system,o=L(e.app_id);if(o&&Jr(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=un(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),an(e),ue("\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}),gn=(e,{base_url:t,onProgress:n}={})=>{let o=F().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new He},l=async()=>{var d;c();let s=L(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return an(e),L(e.app_id);c();let g=o.download({url:t?Hr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(h,u)=>{var P;let y=u>0?u:(P=e.size)!=null?P:0;y>0&&(n==null||n(Math.min(1,h/y)))}});r=g;try{let{status:h}=await g.promise;if(c(),h!==200)throw new Error(`bundle ${h}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ue("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=un(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),an(e),No(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(h){throw i?new He:h}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Vo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},Kr=__DEV__?0:60*1e3,Do={},Bo=(e,t)=>{var o,r;let n=L(e);return n&&Date.now()-((o=Do[t])!=null?o:0)<Kr?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 gn(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),L(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Pt=new Map,qo=(e,t)=>(Pt.set(e,t),()=>{Pt.get(e)===t&&Pt.delete(e)}),Yr=(e,t)=>{let n=Pt.get(e);return n?n(t):!1};import{useCallback as $o,useEffect as Je,useRef as Me,useState as Ct}from"react";import{Animated as D,BackHandler as Xr,Dimensions as Zr,Easing as Ot,Pressable as Qr,StyleSheet as fn,Text as pt,View as $}from"react-native";import{Fragment as pi,jsx as E,jsxs as ve}from"react/jsx-runtime";var ut="#22C55E",ei="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",ti=2,It=18,ni=1600,dt=14,oi=2e3,jo=.38,ri=40,zo=2,ii=8,si=2e3,ai=250,Ge=2e3,ci=[{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}],Wo=({color:e})=>E(pi,{children:ci.map((t,n)=>E($,{style:[_.corner,t,{borderColor:e}]},n))}),kt=({style:e,children:t,...n})=>{let o=Me(new D.Value(1)).current,r=i=>D.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return E(Qr,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:E(D.View,{style:[e,{transform:[{scale:o}]}],children:t})})},hn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var f,b;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===ge.top,h=Me(new D.Value(0)).current,u=r.useCameraDevice("back"),y=Me(new D.Value(1)).current,[P,M]=Ct(!1),[v,A]=Ct(1),O=Me(null),[N,X]=Ct(()=>{let{width:w,height:k}=Zr.get("window");return{width:w,height:d?k*jo:k,window_y:0}}),xe=V(j,w=>w.last_value),re=V(j,w=>w.hit_tick),p=V(j,w=>w.scan_count),S=V(j,w=>w.notice),Z=V(j,w=>w.is_picking),x=Me(null),ie=xt(),fe=ie.top,z=Me(new D.Value(0)).current,T=Me(new D.Value(0)).current,Q=Me(new D.Value(0)).current,B=Me(n);B.current=n,Je(()=>{if(!t)return;h.setValue(N.height);let w=D.timing(h,{toValue:0,duration:ai,easing:Ot.out(Ot.cubic),useNativeDriver:!1});return w.start(({finished:k})=>{var te;k&&((te=B.current)==null||te.call(B))}),()=>w.stop()},[t,h]);let K=Math.round(N.width*(d?.8:.78)),ee=Math.round(d?N.height*.46:K*.78),_e=Math.round((N.height-ee)/2),Ae=Math.round((N.width-K)/2),We=r.useCodeScanner({codeTypes:i,onCodeScanned:$o(w=>nn(w),[])});Je(()=>{let w=Xr.addEventListener("hardwareBackPress",()=>(tn(),!0));return()=>w.remove()},[]);let Se=Me(re);Je(()=>{if(re===Se.current)return;z.setValue(1),Q.setValue(1);let w=D.parallel([D.timing(z,{toValue:0,duration:450,useNativeDriver:!0}),D.sequence([D.delay(oi),D.timing(Q,{toValue:0,duration:250,useNativeDriver:!0})])]);return w.start(),()=>w.stop()},[re,z,Q]),Je(()=>{let w=te=>D.timing(T,{toValue:te,duration:ni,easing:Ot.inOut(Ot.quad),useNativeDriver:!0}),k=D.loop(D.sequence([w(1),w(0)]));return k.start(),()=>k.stop()},[T]);let Ee=$o(()=>{D.timing(y,{toValue:0,duration:220,useNativeDriver:!0}).start()},[y]);Je(()=>{let w=setTimeout(Ee,si);return()=>clearTimeout(w)},[Ee]);let[Ye,$t]=Ct(!1);Je(()=>{let w=requestAnimationFrame(()=>{w=requestAnimationFrame(()=>$t(!0))});return()=>cancelAnimationFrame(w)},[]);let Ue=!!(u!=null&&u.hasTorch),Xe=(f=u==null?void 0:u.neutralZoom)!=null?f:1,Ze=u?Math.min(u.maxZoom/Xe,ii):1,zt=Xe*Math.min(v,Ze),wt=w=>{var ne;let{touches:k}=w.nativeEvent;if(k.length!==2){O.current=null;return}let te=Math.hypot(k[0].pageX-k[1].pageX,k[0].pageY-k[1].pageY);(ne=O.current)!=null||(O.current={distance:te,level:v}),A(Math.max(1,Math.min(Ze,O.current.level*(te/O.current.distance))))},bt=E(pt,{style:[_.hint,!!S&&_.hint_notice],numberOfLines:1,children:(b=S!=null?S:l)!=null?b:ei});return E(D.View,{ref:x,onTouchMove:wt,onTouchEnd:()=>{O.current=null},pointerEvents:t?"none":"auto",style:d?[_.top,g&&_.top_absolute,t&&{height:h}]:_.full,onLayout:({nativeEvent:{layout:w}})=>{var k;t||(o==null||o(w.height),(k=x.current)==null||k.measureInWindow((te,ne)=>{X({width:w.width,height:w.height,window_y:ne||0})}))},children:ve($,{style:t?[_.content_closing,{height:N.height}]:_.content,children:[u&&Ye&&E(r.Camera,{style:fn.absoluteFill,device:u,isActive:!Z,codeScanner:We,torch:P&&Ue?"on":"off",zoom:zt,onPreviewStarted:Ee,onError:w=>wo(w.message)}),E(D.View,{style:[_.preview_cover,{opacity:y}],pointerEvents:"none"}),N.height>0&&ve($,{style:_.overlay,pointerEvents:"none",children:[E($,{style:[_.dim_ring,{top:_e-Ge,left:Ae-Ge,width:K+Ge*2,height:ee+Ge*2}]}),ve($,{style:{position:"absolute",top:_e,left:Ae,width:K,height:ee},children:[E(Wo,{color:"#FFFFFF"}),E(D.View,{style:[fn.absoluteFill,{opacity:z}],children:E(Wo,{color:ut})}),ve(D.View,{style:[_.scan_line_wrap,{transform:[{translateY:T.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,ee-It)]})}]}],children:[E($,{style:_.scan_glow_outer}),E($,{style:_.scan_glow_inner}),E($,{style:_.scan_line})]})]}),E($,{style:[_.hint_slot,d?{top:0,height:_e-6,justifyContent:"flex-end"}:{top:_e+ee+20}],children:bt}),a===Ie.continuous&&!!xe&&E(D.View,{style:[_.result_slot,{top:d?_e+ee-ri:_e+ee+52},{opacity:Q}],children:ve($,{style:_.result,children:[E($,{style:_.check_badge,children:E($,{style:_.check_mark})}),E(pt,{style:_.result_text,numberOfLines:1,children:xe}),ve(pt,{style:_.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),N.height>0&&E($,{style:[_.close_slot,d?_.close_slot_top:{top:Math.max(12,fe-N.window_y+12)}],children:ve(kt,{style:[_.close_button,!!s&&_.glass_surface],onPress:tn,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($,{style:[_.close_bar,_.close_bar_a]}),E($,{style:[_.close_bar,_.close_bar_b]})]})}),E($,{style:[_.toolbar_wrap,!d&&{bottom:ie.bottom+20}],pointerEvents:"box-none",children:ve($,{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(kt,{style:_.tool,onPress:bo,disabled:Z,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:ve($,{style:_.image_icon,children:[E($,{style:_.image_icon_dot}),E($,{style:_.image_icon_hill})]})}),!!u&&Ze>=zo&&E(kt,{style:[_.tool,v>1&&_.tool_on],onPress:()=>A(w=>w>1?1:zo),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(kt,{style:[_.tool,P&&_.tool_on],onPress:()=>M(w=>!w),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:P},children:E(pt,{style:[_.torch_icon,P&&_.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},li="rgba(0,0,0,0.5)",mn=50,_=fn.create({top:{height:`${jo*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:li,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:It,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:It,borderRadius:It/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:ti,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:mn,height:mn,borderRadius:mn/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 Ho,useRef as gt,useState as Jo}from"react";import{AccessibilityInfo as ui,Animated as H,Platform as di,StyleSheet as Go,Text as gi,View as $e}from"react-native";import{Fragment as Xo,jsx as se,jsxs as wn}from"react/jsx-runtime";var yn={[he.info]:"#3B82F6",[he.success]:"#22C55E",[he.error]:"#EF4444"},Ko=-120,Lt=di.OS==="android",Yo=({type:e})=>e===he.success?se($e,{style:Y.check_mark}):e===he.error?wn(Xo,{children:[se($e,{style:[Y.cross_bar,Y.cross_a]}),se($e,{style:[Y.cross_bar,Y.cross_b]})]}):wn(Xo,{children:[se($e,{style:Y.info_dot}),se($e,{style:Y.info_bar})]}),Zo=()=>{let e=V(ot,h=>h.message),t=V(ot,h=>h.type),n=V(ot,h=>h.tick),o=gt(new H.Value(Ko)).current,r=gt(new H.Value(0)).current,i=gt(new H.Value(.92)).current,a=gt(new H.Value(0)).current,[c,l]=Jo(),[s,g]=Jo(!1);Ho(()=>{let h=!0;return en().then(u=>{h&&u&&l(()=>u)}),()=>{h=!1}},[]);let d=gt(n);return Ho(()=>{if(n===d.current)return;ui.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let h=H.sequence([H.parallel([H.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),H.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),H.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),H.sequence([H.delay(90),H.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),H.delay(to[t]),H.parallel([H.timing(o,{toValue:Ko,duration:240,useNativeDriver:!0}),H.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return h.start(({finished:u})=>{u&&g(!1)}),()=>h.stop()},[n]),s?se($e,{style:[Y.layer,{top:xt().top+(Lt?12:8)}],pointerEvents:"none",children:wn(H.View,{style:[Y.toast,Lt&&Y.toast_android,!!c&&Y.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&se(c,{style:Y.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Lt?se(H.View,{style:[Y.badge_halo,{backgroundColor:`${yn[t]}33`,transform:[{scale:a}]}],children:se($e,{style:[Y.badge,{backgroundColor:yn[t]}],children:se(Yo,{type:t})})}):se(H.View,{style:[Y.badge,{backgroundColor:yn[t],transform:[{scale:a}]}],children:se(Yo,{type:t})}),se(gi,{style:[Y.message,Lt&&Y.message_android],numberOfLines:2,children:e})]})}):null},Y=Go.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:Go.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:{}}),Qo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=F().keep_alive)==null?void 0:c.max_webviews;ae.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(h=>h!==s).sort((h,u)=>g[h].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(h=>{delete g[h]}),i?{active_key:s,instances:g}:{instances:g}})},mi=e=>Qo(e,!0),fi=e=>Qo(e,!1),mt=()=>ae.setState({active_key:null}),Ft=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var er="catalog",hi="paused_apps",yi="removed_apps",wi=10*1e3,bi=2,_i=3e3,Ai=()=>{var e;try{return JSON.parse((e=F().storage.getString(er))!=null?e:"{}")}catch{return{}}},C=ke({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),tr=e=>{var t;return!!((t=F().manual_update)!=null&&t.includes(e))},Ut=new Set,nr=e=>{let t=new Set,n=()=>F().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=F().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},we=nr(hi),Ne=nr(yi);kn(()=>{we.load(),Ne.load();let e=Ai(),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})}),C.setState({catalog:e,downloads:t})});var _n=e=>V(C,t=>e?t.downloads[e]:void 0),Si=()=>V(C,e=>e.pause_reasons.length>0),ye=(...e)=>ue("queue",...e),J=[],Pe={},R=null,Dt=new Set,ze={},bn=new Set,Fe=e=>{bn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},vi=e=>(bn.add(e),()=>{bn.delete(e)}),Mi=()=>C.getState().downloads,ce=(e,t)=>{let n=!!L(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})},Nt=(e,t)=>{var n;(n=ze[e])==null||n.forEach(o=>o(t)),delete ze[e]},xi=()=>C.getState().pause_reasons.length>0,De=e=>{var c;if(R)return;let t=e?J.indexOf(e):xi()?-1:J.findIndex(l=>!we.has(l));if(t<0||t>=J.length)return;let[n]=J.splice(t,1),o=C.getState().catalog[n];if(!o){Nt(n,L(n)),De();return}let r=Date.now();Pe[n]=((c=Pe[n])!=null?c:0)+1,ce(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=gn(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}),Nt(n,l)}).catch(l=>{var g;if(l instanceof He){if(Dt.has(n))return;ye("paused",n),Pe[n]-=1,J.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),Pe[n]<bi){ce(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;J.includes(n)||(R==null?void 0:R.app_id)===n||(J.push(n),De((d=ze[n])!=null&&d.length?n:void 0))},_i);return}ce(n,{status:"failed",progress:0,version:o.version,error:s}),Nt(n,L(n))}).finally(()=>{R=null;let l=J.find(s=>{var g;return(g=ze[s])==null?void 0:g.length});De(l)})},Vt=(e,{front:t=!1}={})=>{if((R==null?void 0:R.app_id)===e)return;let n=J.indexOf(e);if(n>=0){if(!t)return;J.splice(n,1)}t?J.unshift(e):J.push(e)},Ei=async e=>{let{host_id:t,client_token:n}=F(),o=new AbortController,r=setTimeout(()=>o.abort(),wi);try{let i=`${jt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},ft=null,An=()=>(ft!=null||(ft=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(F().channels.map(Ei)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(C.getState().catalog).filter(l=>!o[l]);F().storage.setString(er,JSON.stringify(o)),C.setState({catalog:o}),await Promise.all(r.map(l=>or(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 dn(l)){ce(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=L(l.app_id);if(tr(l.app_id)&&!Ut.has(l.app_id)&&s&&await Te(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=>{Pe[l.app_id]=0,ce(l.app_id,{status:we.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Vt(l.app_id)}),ye("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Fe({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Fe({type:"update_available",...l})),De(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Fe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ft=null}})()),ft),or=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ne.add(e),Dt.has(e))return;Dt.add(e),we.delete(e);let n=J.indexOf(e);n>=0&&J.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=L(e))==null?void 0:i.version)!=null?c:"";ce(e,{status:"uninstalling",progress:0,version:o}),await Uo(e),Ft(e),C.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Pe[e],Dt.delete(e),Nt(e,null),ye("uninstalled",e,t?"(user)":"(not in list)"),Fe({type:"uninstalled",app_id:e})},Ri=e=>or(e,{by_user:!0}),Ti=e=>{let t=ht(e);return t?(Ne.delete(e),(R==null?void 0:R.app_id)===e||J.includes(e)||(Pe[e]=0,ce(e,{status:we.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Vt(e),De(),ye("restore",e)),!0):!1},Pi=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];J.includes(e)&&t&&ce(e,{status:"paused",progress:0,version:t.version})},Ci=e=>{if(!we.delete(e))return;ye("resume app",e);let t=C.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!J.includes(e)&&ht(e)&&(Pe[e]=0,Vt(e)),J.includes(e)&&t&&ce(e,{status:"queued",progress:0,version:t.version}),De()},Oi=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())},ki=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()},rr=e=>C.getState().updates[e],Ii=async e=>{var n,o;let t=rr(e);Ut.add(e);try{let r=await Bt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=ht(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(C.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),ye("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Ut.delete(e)}},Li=()=>Object.values(C.getState().catalog).map(e=>({...e,installed:!!L(e.app_id),removed_by_user:Ne.has(e.app_id)})),ht=e=>C.getState().catalog[e],Bt=async e=>{let t=ht(e);if(!t)return;if(we.delete(e),Ne.delete(e),await dn(t))return L(e);let n=L(e);if(tr(e)&&!Ut.has(e)&&n&&await Te(n))return n;let o=new Promise(r=>{var i;((i=ze[e])!=null?i:ze[e]=[]).push(r)});return(R==null?void 0:R.app_id)===e?R.forced=!0:(Pe[e]=0,Vt(e,{front:!0}),R&&!R.forced?R.handle.cancel():De(e)),o};import{Fragment as En,jsx as G,jsxs as Ke}from"react/jsx-runtime";var vn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),sr=0,Bi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},qi=Rn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var wt,bt;let d=be(null),h=be(!1),u=V(ae,f=>f.instances[e]),y=u==null?void 0:u.app.app_id,P=u==null?void 0:u.app.manifest_url,M=u==null?void 0:u.context,v=u==null?void 0:u.url_params,A=V(j,f=>{var b;return((b=f.active)==null?void 0:b.owner)===e?f.active:null}),[O,N]=Ce(null),[X,xe]=Ce(A);A!==X&&(xe(A),A?N(null):(X==null?void 0:X.layout)===ge.top&&N(X));let re=(A==null?void 0:A.layout)===ge.top?A:O,[p,S]=Ce(()=>y?L(y):null),[Z,x]=Ce(!1),[ie,fe]=Ce(0),[z,T]=Ce(0),[Q,B]=Ce(!1),K=be(null),ee=f=>{K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{K.current=null,B(!0)},f)};le(()=>()=>{K.current&&clearTimeout(K.current)},[]),le(()=>{if(!y||!t&&p)return;let f=!0;return x(!1),(async()=>{let b=L(y),w=b?await Te(b):!1;if(!f||(S(w?ne=>!ne||ne.version!==b.version||ne.permissions.join(",")!==b.permissions.join(",")?b:ne:null),__DEV__&&Date.now()-sr>1e4&&(sr=Date.now(),await An()),!f))return;let k=await Bt(y),te=k!==void 0?k:P?await Bo(y,P):L(y);if(f){if(!te){x(!0);return}S(ne=>ne!=null?ne:te)}})(),()=>{f=!1}},[t,y,P,ie]),le(()=>qo(e,f=>d.current?(d.current.postMessage(f),!0):!1),[e]);let _e=V(C,f=>{let b=y?f.downloads[y]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});le(()=>{if(t||!y||!p)return;let f=L(y);if(!f||f.version===p.version)return;let b=!0;return Te(f).then(w=>{!b||!w||(ue(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",f.version),S(f))}),()=>{b=!1}},[t,y,_e,p==null?void 0:p.version]);let Ae=V(C,f=>{var b;return y&&(b=f.apply_ticks[y])!=null?b:0});le(()=>{if(!Ae||!y)return;let f=L(y);if(!f||f.version===(p==null?void 0:p.version))return;let b=!0;return Te(f).then(w=>{!b||!w||(ue(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",f.version),B(!1),S(f))}),()=>{b=!1}},[Ae]),le(()=>{var w;let f=(w=F().keep_alive)==null?void 0:w.idle_close_ms;if(t||!f||f<=0)return;let b=setTimeout(()=>{Ft(e)},f);return()=>clearTimeout(b)},[t,e]),le(()=>{r>0&&(x(!1),B(!1),T(f=>f+1),fe(f=>f+1))},[r]);let We=be(t);le(()=>{var f;We.current!==t&&(We.current=t,h.current&&((f=d.current)==null||f.injectJavaScript(To(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=qt(()=>JSON.stringify([M!=null?M:{},v!=null?v:{}]),[M,v]),Ye=qt(()=>{var f;return Io(v!=null?v:{},(f=p==null?void 0:p.permissions)!=null?f:[])},[Ee,p==null?void 0:p.permissions]),$t=qt(()=>Oo(M!=null?M:{},Ye)+Eo()+Ro()+(F().debug?xo():""),[Ye]),Ue=be(null),Xe=be(null);le(()=>{var b,w,k;if(!p)return;if(Xe.current!==Se){Xe.current=Se,Ue.current=Ee;return}if(Ue.current===Ee)return;let f=((w=JSON.parse((b=Ue.current)!=null?b:"[]")[0])!=null?w:{}).org_id;if(Ue.current=Ee,f===(M==null?void 0:M.org_id)&&h.current){B(!1),ee(1500),(k=d.current)==null||k.injectJavaScript(Po(M!=null?M:{},Ye));return}B(!1),T(te=>te+1)},[Ee,p,Se]),le(()=>(t||(Re(e),Le(e),qe(e)),()=>{Re(e),Le(e),qe(e)}),[t,e,Se,r]),le(()=>{let f=ir.addEventListener("change",b=>{b==="background"&&!io()&&Re(e),b==="background"&&!uo()&&Le(e)});return()=>f.remove()},[e]);let Ze=Mn(async f=>{var w,k,te,ne,Wt,Pn;let b=Ao(f.nativeEvent.data);if(!b){if(y&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(U=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,U)})}catch(U){console.warn("[miniapp] onWebEvent l\u1ED7i",y,U)}return}if(b.method==="log"){let{level:U,text:q}=b;ue(`web:${e}`,U!=null?U:"log",q!=null?q:"");return}if(b.method==="pong"){K.current||B(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){K.current&&clearTimeout(K.current),K.current=null,B(!0);return}if(b.method==="ready"){h.current=!0,B(!0);let U=(w=ae.getState().instances[e])==null?void 0:w.context;U&&((k=d.current)==null||k.injectJavaScript(rn(U)));return}try{let U=await Fo(b,{getHostData:()=>{var q,pe;return(pe=(q=ae.getState().instances[e])==null?void 0:q.host_data)!=null?pe:{}},getPermissions:()=>{var q,pe;return y?(pe=(q=L(y))==null?void 0:q.permissions)!=null?pe:[]:[]},getContext:()=>{var q,pe;return(pe=(q=ae.getState().instances[e])==null?void 0:q.context)!=null?pe:{}},is_dark:o,close:mt,app_id:y!=null?y:"",instance_id:e,options:c,emit:(q,pe)=>{var Cn;(Cn=d.current)==null||Cn.injectJavaScript(Mo(q,pe))},playBeep:(te=c==null?void 0:c.playScannerBeep)!=null?te:(()=>{var q;(q=d.current)==null||q.injectJavaScript(Lo())}),isActive:()=>ae.getState().active_key===e&&ir.currentState!=="background"});b.id&&((ne=d.current)==null||ne.injectJavaScript(So(b.id,U)))}catch(U){if(!b.id)return;let q=U==null?void 0:U.code,pe=U instanceof m?U:new m(typeof q=="string"?q:"HOST_ERROR",String((Wt=U==null?void 0:U.message)!=null?Wt:U));(Pn=d.current)==null||Pn.injectJavaScript(vo(b.id,pe))}},[e,o,y,i,c]),zt=Mn(()=>{x(!1),T(f=>f+1),fe(f=>f+1)},[]);return Ke(xn,{style:[Tn.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&me.behind],pointerEvents:t?"auto":"none",children:[re&&G(hn,{scanner:re,closing:re===O,onClosed:()=>{var f;N(null),re.absolute&&((f=d.current)==null||f.injectJavaScript(sn(0)))},onHeight:re.absolute?f=>{var b;return(b=d.current)==null?void 0:b.injectJavaScript(sn(f))}:void 0}),p?G(Vi,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?ln():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:$t,onMessage:Ze,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load start",vn(f.nativeEvent.url)),h.current=!1,B(!1)},onError:f=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load error",vn(f.nativeEvent.url),f.nativeEvent.description),x(!0),B(!1)},onLoadEnd:f=>{let b=f.nativeEvent.url;ue(`webview:${e}`,"load end",vn(b)),y&&(g==null||g({app_id:y,instance_id:e,url:b})),ee(1500)},onContentProcessDidTerminate:()=>{Re(e),Le(e),qe(e),h.current=!1,B(!1),T(f=>f+1)},onRenderProcessGone:()=>(Re(e),Le(e),qe(e),h.current=!1,B(!1),T(f=>f+1),!0),style:me.webview},Se):null,(A==null?void 0:A.layout)===ge.full&&G(hn,{scanner:A}),u&&G(zi,{visible:!p||!Q,interactive:Z,children:G($i,{splash:a,app:u.app,is_dark:o,error:Z,has_bundle:!!p,retry:zt})})]})}),$i=Rn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=_n(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return G(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),zi=({visible:e,interactive:t,children:n})=>{let o=be(new Sn.Value(e?1:0)).current,[r,i]=Ce(e);return le(()=>{if(e){i(!0),o.setValue(1);return}let a=Sn.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?G(Sn.View,{style:[Tn.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},cr=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return Ke(xn,{style:[me.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[G(xn,{style:[me.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?G(Ni,{source:{uri:e.icon},style:me.splash_icon_image}):G(yt,{style:me.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),G(yt,{style:[me.splash_name,{color:i}],children:e.name}),n==="error"?Ke(En,{children:[G(yt,{style:me.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),G(Ui,{activeOpacity:.7,style:[me.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:G(yt,{style:[me.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):Ke(En,{children:[G(Fi,{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"]})]})]})},ar=(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.`))},Wi=({container:e,splash:t=cr,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=V(ae,A=>A.active_key),g=be(s);s&&(g.current=s);let d=V(ae,A=>Object.keys(A.instances).join("|")),h=V(ae,A=>{var O;return A.active_key?(O=A.instances[A.active_key])==null?void 0:O.app.name:void 0}),u=qt(()=>d?d.split("|"):[],[d]),[y,P]=Ce({}),M=be(Bi()).current;le(()=>{if(!s||!r)return;let A=Di.addEventListener("hardwareBackPress",()=>(mt(),!0));return()=>A.remove()},[s,r]);let v=Mn(()=>{let A=ae.getState().active_key;A&&P(O=>({...O,[A]:(O[A]||0)+1}))},[]);return u.length?Ke(En,{children:[G(l,{visible:!!s,title:h!=null?h:"",is_dark:n,close:mt,reload:v,subscribeWebAtTop:M.subscribe,children:u.map(A=>G(qi,{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))}),G(Zo,{})]}):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"}}),ji=Rn.memo(Wi);export{oe as CodeType,cr as DefaultMiniAppSplash,jt as MINIAPP_PLATFORM_URL,ji as MiniAppHost,m as MiniAppHostError,je as ScannerEndReason,Xt as ScannerEvent,ge as ScannerLayout,it as ScannerMethod,he as ToastType,mt as closeMiniApp,lr as configureMiniApp,ur as createMmkvStorage,In as createReactNativeBiometrics,pr as createRnfsFileSystem,Bt as ensureMiniApp,L as getLocalMiniApp,Li as getMiniAppCatalog,ht as getMiniAppCatalogEntry,Mi as getMiniAppStatuses,rr as getMiniAppUpdate,Gr as installBundledMiniApp,vi as onMiniAppEvent,mi as openMiniApp,Pi as pauseMiniApp,Oi as pauseMiniAppDownloads,fi as preloadMiniApp,Re as releaseSpeechFor,Ti as restoreMiniApp,Ci as resumeMiniApp,ki as resumeMiniAppDownloads,Yr as sendEventToWeb,An as syncMiniAppCatalog,Ri as uninstallMiniApp,Ii as updateMiniApp,Kn as uploadToUrl,_n as useMiniAppDownload,Si as useMiniAppDownloadsPaused};
|
package/docs/NATIVE_APIS.md
CHANGED
|
@@ -285,7 +285,15 @@ await stopScanner();
|
|
|
285
285
|
```
|
|
286
286
|
|
|
287
287
|
- `scanCode`: camera phủ kín vùng mini app, trả một mã rồi tự đóng.
|
|
288
|
-
- `startScanner`: mặc định (`ScannerLayout.top`) camera chiếm khoảng 38% phía trên, web thu lại ở phần dưới và vẫn thao tác được, phù hợp quầy thu ngân cần thấy giỏ hàng cập nhật. `ScannerLayout.full` phủ kín vùng mini app, thẻ trên camera hiện mã vừa quét và số mã đã quét. Camera mở đến khi người dùng bấm Đóng hoặc web gọi `stopScanner()`.
|
|
288
|
+
- `startScanner`: mặc định (`ScannerLayout.top`) camera chiếm khoảng 38% phía trên, web thu lại ở phần dưới và vẫn thao tác được, phù hợp quầy thu ngân cần thấy giỏ hàng cập nhật. `ScannerLayout.full` phủ kín vùng mini app, thẻ trên camera hiện mã vừa quét và số mã đã quét. Camera mở đến khi người dùng bấm Đóng hoặc web gọi `stopScanner()`. Đóng camera `top` thì panel thu gọn dần lên trên.
|
|
289
|
+
- `startScanner({ layout: ScannerLayout.top, absolute: true })`: camera nằm đè lên phần trên web thay vì đẩy web xuống, WebView giữ nguyên kích thước nên web không phải co / giãn lại khi mở, đóng camera. Web tự chừa chỗ theo chiều cao camera host báo:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
// px theo WebView; 0 khi camera đã đóng. Mini app nằm trong iframe cùng origin thì đọc ở window.top
|
|
293
|
+
const onHeight = () => setCameraTop(window.__retionScannerHeight ?? 0);
|
|
294
|
+
window.addEventListener('retionscannerheight', onHeight);
|
|
295
|
+
await startScanner({ layout: ScannerLayout.top, absolute: true });
|
|
296
|
+
```
|
|
289
297
|
- Camera có nút Đóng, quét từ ảnh, zoom 1x/2x (chụm 2 ngón để zoom tự do), đèn pin (nếu máy có) và nháy khung xanh khi nhận mã.
|
|
290
298
|
- Kết hợp với toast: khi nhận mã, web gọi `showToast(...)` để báo kết quả xử lý; toast nổi trên cả camera.
|
|
291
299
|
- Nút trên camera dùng Liquid Glass trên iOS 26+ nếu app đã cài `expo-glass-effect` (tuỳ chọn); còn lại dùng nền tối. Host không dùng `expo/metro-config` mà chưa cài thư viện này phải bật `transformer.allowOptionalDependencies: true` trong `metro.config.js`, nếu không bundle sẽ báo thiếu module.
|
|
@@ -303,6 +311,7 @@ await stopScanner();
|
|
|
303
311
|
| --- | --- | --- |
|
|
304
312
|
| `types` | `CodeType.all` | Loại mã cần quét; quét ít loại hơn thì nhanh và ít nhận nhầm hơn |
|
|
305
313
|
| `layout` | `ScannerLayout.top` | Chỉ `startScanner`: `top` hoặc `full` |
|
|
314
|
+
| `absolute` | `false` | Chỉ `startScanner` với `top`: camera nằm đè lên web, web không đổi kích thước; chiều cao camera ở `window.__retionScannerHeight` (event `retionscannerheight`) |
|
|
306
315
|
| `hint` | `Đưa mã vào khung để quét` | Chữ hướng dẫn trên camera, 1–80 ký tự; truyền theo ngôn ngữ của mini app |
|
|
307
316
|
| `cooldown_ms` | `1500` | Chỉ `startScanner`, 0–60000 ms: **cùng một mã** phải rời khung đủ thời gian này mới được nhận lại, nên giữ nguyên mã trước camera không bị đếm thêm. Mã khác nhận ngay |
|
|
308
317
|
|