@retion-miniapp/react-native 0.18.0 → 0.19.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 +33 -5
- package/dist/index.d.ts +33 -5
- package/dist/index.js +11 -11
- package/dist/index.mjs +11 -11
- package/docs/MINIAPP_README.md +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var qr=Object.create;var Pt=Object.defineProperty;var Br=Object.getOwnPropertyDescriptor;var $r=Object.getOwnPropertyNames;var zr=Object.getPrototypeOf,Wr=Object.prototype.hasOwnProperty;var Hr=(e,t)=>{for(var n in t)Pt(e,n,{get:t[n],enumerable:!0})},Kn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of $r(t))!Wr.call(e,r)&&r!==n&&Pt(e,r,{get:()=>t[r],enumerable:!(o=Br(t,r))||o.enumerable});return e};var he=(e,t,n)=>(n=e!=null?qr(zr(e)):{},Kn(t||!e||!e.__esModule?Pt(n,"default",{value:e,enumerable:!0}):n,e)),jr=e=>Kn(Pt({},"__esModule",{value:!0}),e);var Yi={};Hr(Yi,{CodeType:()=>ie,DefaultMiniAppChangelogPrompt:()=>Hn,DefaultMiniAppSplash:()=>Un,DefaultMiniAppUpdatePrompt:()=>jn,MINIAPP_CHANGELOG_KINDS:()=>$n,MINIAPP_PLATFORM_URL:()=>Qe,MiniAppChangelogGroups:()=>rn,MiniAppChangelogHistory:()=>Wn,MiniAppHost:()=>Fr,MiniAppHostError:()=>g,MiniAppUpdates:()=>Ur,ScannerEndReason:()=>Ke,ScannerEvent:()=>Dt,ScannerLayout:()=>fe,ScannerMethod:()=>et,ToastType:()=>be,closeMiniApp:()=>rt,configureMiniApp:()=>Xn,createMmkvStorage:()=>Zn,createReactNativeBiometrics:()=>ln,createRnfsFileSystem:()=>Qn,dismissMiniAppChangelog:()=>nn,ensureMiniApp:()=>vt,fetchMiniAppChangelog:()=>en,getLocalMiniApp:()=>$,getMiniAppCatalog:()=>kr,getMiniAppCatalogEntry:()=>st,getMiniAppChangelogSeen:()=>Zt,getMiniAppStatuses:()=>Mr,getMiniAppUpdate:()=>Nn,getPendingChangelog:()=>Bn,installBundledMiniApp:()=>sr,markMiniAppChangelogSeen:()=>at,mergeMiniAppChangelog:()=>zn,onMiniAppEvent:()=>Gt,openMiniApp:()=>yr,pauseMiniApp:()=>Er,pauseMiniAppDownloads:()=>Tr,preloadMiniApp:()=>wr,releaseSpeechFor:()=>Ie,restoreMiniApp:()=>Cr,resumeMiniApp:()=>Pr,resumeMiniAppDownloads:()=>Rr,sendEventToWeb:()=>lr,showMiniAppChangelog:()=>Qt,syncMiniAppCatalog:()=>Yt,uninstallMiniApp:()=>xr,updateMiniApp:()=>Xt,uploadToUrl:()=>gn,useMiniAppChangelog:()=>tn,useMiniAppChangelogRequest:()=>on,useMiniAppDownload:()=>it,useMiniAppDownloadsPaused:()=>Sr});module.exports=jr(Yi);var Qe="https://retion-miniapp-platform.vercel.app",je=null,Yn=new Set,Xn=e=>{je=e,Yn.forEach(t=>t())},F=()=>{if(!je)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return je},Tt=e=>{Yn.add(e),je&&e()},me=(...e)=>{je!=null&&je.debug&&console.log("[miniapp]",...e)};var Qn=(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)}}}),Zn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var v=he(require("react")),V=require("react-native"),Lr=he(require("react-native-webview"));var yt=require("react-native");var ln=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),Rt,pn=()=>(Rt||(Rt=import("react-native-biometrics").then(({default:e})=>ln(new e({allowDeviceCredentials:!1}))).catch(e=>{throw Rt=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),Rt);var ke=require("react-native");var eo=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},to=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(ke.Platform.OS==="android"){let s=ke.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=ke.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,u=await ke.PermissionsAndroid.check(s);if(!c())return;let y=u||await ke.PermissionsAndroid.check(d);if(!c())return;if(!u&&!y){let p=await ke.PermissionsAndroid.requestMultiple([s,d]);if(!c())return;if(p[s]!==ke.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==ke.PermissionsAndroid.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var u;if(!c())return;let d=(u={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?u:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(l=>i(l))});var dn=require("react-native");var un=20,no=20,co=/^[a-z][a-z0-9_-]{0,31}$/,Jr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Gr=["low","medium","high"],qe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),te=e=>new g("INVALID_PARAMS",e),ht=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,oo=(e,t)=>{if(e===void 0)return{};if(!qe(e)||Object.keys(e).length>no||Object.values(e).some(n=>typeof n!="string"))throw te(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${no} key)`);return e},lo=e=>{var n,o,r,i;if(e!==void 0&&!qe(e))throw te("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!co.test(t.source)))throw te("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"||!Jr.test(a))))throw te("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!ht(t.max_count,1,un))throw te(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${un}`);if(t.max_size!==void 0&&!ht(t.max_size,1,Number.MAX_SAFE_INTEGER))throw te("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!ht(t.concurrency,1,5))throw te("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:Kr(t.process),target:Yr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Kr=e=>{if(e===void 0)return{};if(!qe(e))throw te("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!qe(n))throw te("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!ht(n[o],1,1e4))throw te(`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 te("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(!qe(n))throw te("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!ht(n.max_duration,1,3600))throw te("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Gr.includes(n.quality))throw te("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(!qe(e))throw te("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!co.test(t))throw te("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!qe(e.params))throw te("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 te("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 te(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:oo(e.headers,"upload.headers"),form_data:oo(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},po=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},Xr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=po(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Qr=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"},ut,Zr=()=>(ut!=null||(ut=import("react-native-image-picker").catch(e=>{throw ut=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)}`)})),ut),ro=e=>async({accept:t,max_count:n,process:o})=>{var l,s,d,u,y,p,h,L,k;let r=await Zr(),i=Qr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(u=(d=o.image)==null?void 0:d.quality)!=null?u:.8,videoQuality:(p=(y=o.video)==null?void 0:y.quality)!=null?p:"medium",durationLimit:(h=o.video)==null?void 0:h.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let T=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(T,(L=c.errorMessage)!=null?L:c.errorCode)}return((k=c.assets)!=null?k:[]).filter(T=>T.uri).map((T,_)=>{var B,G,ce;return{uri:T.uri,name:(B=T.fileName)!=null?B:`file_${_+1}`,mime_type:(G=T.type)!=null?G:"application/octet-stream",size:T.fileSize,width:T.width,height:T.height,duration:T.duration,processed:!((ce=T.type)!=null&&ce.startsWith("video/"))||dn.Platform.OS==="ios"}})},ei={"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"},ti={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},ni=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var d;return(d=ei[s])!=null?d:ti[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,h)=>{var L,k,T;return{uri:p.uri,name:(L=p.name)!=null?L:`file_${h+1}`,mime_type:(k=p.type)!=null?k:"application/octet-stream",size:(T=p.size)!=null?T:void 0}});if(dn.Platform.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let u=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),y=new Map(u.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var h;return{...p,uri:(h=y.get(p.uri))!=null?h:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},dt,oi=async e=>(dt!=null||(dt=import("@react-native-documents/picker").then(t=>ni(t)).catch(t=>{throw dt=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 dt)(e)),uo={library:ro("library"),camera:ro("camera"),document:oi},io={type:"image",label:"\u1EA2nh",accept:["image/*"]},so={type:"video",label:"Video",accept:["video/*"]},ao={library:[io,so],camera:[io,so],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"]}]},gt,go=()=>(gt!=null||(gt=import("react-native-compressor").catch(()=>(gt=void 0,null))),gt),ho=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},ri=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),ii={low:640,medium:1280,high:1920},si=async(e,{image:t})=>{var o;if(!t||!ri.has(e.mime_type.toLowerCase()))return e;let n=await go();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 ho(n,r,e.size),processed:!0}}catch{return e}},ai=async(e,{video:t})=>{var o;let n=await go();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:ii[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await ho(n,r,e.size),processed:!0}}catch{return e}},ci={image:si,video:ai},li=(e,t)=>t.split(".").reduce((n,o)=>qe(n)?n[o]:void 0,e),gn=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([u,y])=>l.append(u,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let d=u=>{o.removeEventListener("abort",s),u()};c.open("POST",a.url),Object.entries(a.headers).forEach(([u,y])=>c.setRequestHeader(u,y)),c.upload.onprogress=u=>n(u.loaded,u.total||e.size||0),c.onload=()=>d(()=>{let u=c.responseText;try{u=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=li(u,a.url_field);if(typeof y!="string"||!y){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:u})}),c.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),mo=e=>{var o,r;let t={...uo};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:gn};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}},fo=e=>{let{sources:t,targets:n}=mo(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===uo[i]&&ao[i]).map(i=>[i,ao[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:un}},Ot=new Map,yo=(e,t)=>`${e}:${t}`,pi=0,wo=(e,t)=>{var n;typeof t=="string"&&((n=Ot.get(yo(e,t)))==null||n.abort())},Je=e=>{for(let[t,n]of Ot)t.startsWith(`${e}:`)&&n.abort()},kt=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),ui=(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)}},bo=async(e,t)=>{var l;let{sources:n,targets:o}=mo(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=yo(t.instance_id,(l=t.task_id)!=null?l:`auto-${++pi}`);Ot.set(c,a);try{return await di(e,t,r,i,a.signal)}finally{Ot.delete(c)}},di=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=u=>u()},l,s,d)=>{var R,f,I;let u={app_id:n!=null?n:"",instance_id:t,context:{...(R=o==null?void 0:o())!=null?R:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:u}))).slice(0,e.max_count);if(d.aborted)throw kt();if(!y.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],h=y.filter(P=>Xr(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||po(P.name)}`}),!1)),L=h.map(()=>0),k=h.map(P=>{var z;return(z=P.size)!=null?z:0}),T=0,_=0,B=(P=!1)=>{if(!a||!r)return;let z=Date.now();if(!P&&z-_<200)return;_=z;let xe=k.reduce((U,le)=>U+le,0),ee=L.reduce((U,le)=>U+le,0);a("upload.progress",{task_id:r,loaded:ee,total:xe,percent:xe?Math.min(100,Math.round(ee/xe*100)):0,done_count:T,count:h.length})},G=[],ce=0,Le=async()=>{var P,z,xe;for(;ce<h.length;){let ee=ce++,U=h[ee];try{if(d.aborted)throw kt();let le=U.mime_type.startsWith("image/")?"image":U.mime_type.startsWith("video/")?"video":void 0,X=le&&!U.processed?(z=(P=i==null?void 0:i.processors)==null?void 0:P[le])!=null?z:ci[le]:void 0;if(X&&(U=await X(U,e.process),k[ee]=(xe=U.size)!=null?xe:k[ee],d.aborted))throw kt();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 re=(Xe,Re)=>{L[ee]=Xe,Re&&(k[ee]=Re),B()},pe=await s({file:U,target:e.target,onProgress:re,signal:d,caller:u});if(typeof(pe==null?void 0:pe.url)!="string"||!pe.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Pe,...Te}=pe;G[ee]={url:Pe,name:U.name,mime_type:U.mime_type,size:U.size,width:U.width,height:U.height,duration:U.duration,...Object.keys(Te).length?{response:"response"in Te?Te.response:Te}:{}},L[ee]=k[ee]}catch(le){p.push(ui(h[ee].name,le))}finally{T++,B(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,h.length)},Le)),d.aborted)throw kt();let ge=G.filter(P=>!!P);if(!ge.length){let P=p[0];throw new g((f=P==null?void 0:P.code)!=null?f:"UPLOAD_FAILED",(I=P==null?void 0:P.message)!=null?I:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ge,failed:p}};var It=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,It.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,It.useSyncExternalStore)(e.subscribe,r)};var be={info:"info",success:"success",error:"error"},gi=200,Ao={info:2e3,success:2e3,error:3e3},mt=Oe({message:"",type:be.info,tick:0}),_o=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,gi);return o?{message:o,type:Object.values(be).includes(n)?n:be.info}:null},So=(e,t=be.info)=>{mt.setState(n=>({message:e,type:t,tick:n.tick+1}))};var _e=require("react-native");var Ge=require("react-native");var Ae,Ze=new Map,Mo=(e,t)=>{var o;let n=(o=Ze.get(e))!=null?o:new Set;n.add(t),Ze.set(e,n)},vo=(e,t)=>{let n=Ze.get(e);n&&(t?n.delete(t):n.clear(),n.size===0&&Ze.delete(e))},mn=new Map,xo=(e,t)=>{mn.set(e,t)},Co=e=>mn.get(e),Eo=()=>Ge.Platform.OS==="android"&&!!(Ae!=null&&Ae.requesting_permission),hi=1500,Lt=()=>new Promise(e=>{if(Ge.Platform.OS!=="android"||Ge.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,hi),o=Ge.AppState.addEventListener("change",r=>{r==="active"&&t()})}),hn=e=>{var t;if(Ae===e&&(Ae=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Ge.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Po=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(Ae)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:[]};Ae=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let u=d.ExpoSpeechRecognitionModule;if(r.native=u,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await u.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await Lt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await u.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(u.addListener("result",p=>{var h,L;Ae!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(L=(h=p.results[0])==null?void 0:h.transcript)!=null?L:""})}),u.addListener("error",p=>{Ae===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),u.addListener("end",()=>{Ae===r&&(hn(r),n("speech.end"))})),r.started=!0,u.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw hn(r),d}},To=e=>{let t=Ae;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Ie=e=>{mn.delete(e);let t=Ze.get(e);Ze.delete(e),t==null||t.forEach(o=>{var r;try{(r=o.release)==null||r.call(o,e)}catch{}});let n=Ae;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{hn(n)}};var Ro={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"},ie={...Ro,all:Object.values(Ro)},et={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Dt={result:"scanner.result",end:"scanner.end"},Ke={user:"user",web:"web",closed:"closed",error:"error"},fe={top:"top",full:"full"},Be={once:"once",continuous:"continuous"},mi=1500,ko=6e4,J,ne=Oe({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Io=()=>_e.Platform.OS==="android"&&!!(J!=null&&J.requesting_permission),yn=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=>ie.all.includes(c)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>ko)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${ko}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(fe).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new g("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},wn=e=>J!==e?!1:(J=void 0,ne.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),fi=()=>_e.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:()=>{_e.Linking.openSettings().catch(()=>{})}}]),Lo=async(e,t)=>{if(J)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");J=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=_e.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await Lt(),n(),c!=="granted")throw a&&fi(),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 bn();n(),ne.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 wn(e),o}},Ft;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Ft=e==null?void 0:e.insets}).catch(()=>{});var tt=()=>{var e;return Ft!=null?Ft:{top:_e.Platform.OS==="ios"?54:(e=_e.StatusBar.currentHeight)!=null?e:0,bottom:_e.Platform.OS==="ios"?34:48}},bn=async()=>{if(_e.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},Fo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:ie.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:mi,hint:n.hint,layout:t===Be.once?fe.full:(i=n.layout)!=null?i:fe.top,absolute:t!==Be.once&&((a=n.layout)!=null?a:fe.top)===fe.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},Do=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=Fo(e,Be.once,t);a.onHit=o,a.resolve=r,a.reject=i,Lo(a,n).catch(i)}),No=(e,t,n,o=()=>!0,r)=>{let i=Fo(e,Be.continuous,t);return i.emit=n,i.onHit=r,Lo(i,o)},Nt=(e,t,n)=>{var o,r;if(!ne.getState().active){e.cancelled=!0;return}if(wn(e)){if(e.mode===Be.once){(o=e.reject)==null||o.call(e,t===Ke.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,Dt.end,n?{reason:t,message:n}:{reason:t})}},Vo=e=>{(J==null?void 0:J.owner)===e&&Nt(J,Ke.web)},$e=e=>{(J==null?void 0:J.owner)===e&&Nt(J,Ke.closed)},An=()=>{J&&Nt(J,Ke.user)},Uo=e=>{J&&Nt(J,Ke.error,e)},_n=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=J;if(!(!o||!ne.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===Be.once){wn(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}ne.setState(d=>({last_value:c,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Dt.result,{value:c,type:l})}}},yi={1:ie.code128,2:ie.code39,4:ie.code93,8:ie.codabar,16:ie.dataMatrix,32:ie.ean13,64:ie.ean8,128:ie.itf,256:ie.qr,512:ie.upcA,1024:ie.upcE,2048:ie.pdf417,4096:ie.aztec},wi=2500,Oo=2e3,fn=e=>{ne.setState({notice:e}),setTimeout(()=>{ne.getState().notice===e&&ne.setState({notice:null})},wi)},qo=async()=>{var t,n;let e=J;if(!(!e||ne.getState().is_picking)){e.requesting_permission=!0,ne.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||J!==e)return;if(r.errorCode||!i){fn("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(J!==e)return;let l=c.map(({value:s,format:d})=>({value:s,code_type:yi[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!l.length){fn("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}_n(l,Date.now(),!0)}catch{J===e&&fn("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await Lt(),e.requesting_permission=!1,J===e&&ne.setState({is_picking:!1})}}};var Ut=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},Bo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Ut&&typeof t.method=="string"?t:null}catch{return null}},wt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,$o=(e,t)=>wt({id:e,result:t}),zo=(e,t)=>wt({id:e,error:{code:t.code,message:t.message}}),Wo=(e,t)=>wt({event:e,data:t}),Mn=e=>wt({event:"context",data:e});var Ho=()=>`(function () {
|
|
1
|
+
"use strict";var zr=Object.create;var Rt=Object.defineProperty;var Wr=Object.getOwnPropertyDescriptor;var Hr=Object.getOwnPropertyNames;var jr=Object.getPrototypeOf,Gr=Object.prototype.hasOwnProperty;var Jr=(e,t)=>{for(var n in t)Rt(e,n,{get:t[n],enumerable:!0})},Xn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Hr(t))!Gr.call(e,r)&&r!==n&&Rt(e,r,{get:()=>t[r],enumerable:!(o=Wr(t,r))||o.enumerable});return e};var he=(e,t,n)=>(n=e!=null?zr(jr(e)):{},Xn(t||!e||!e.__esModule?Rt(n,"default",{value:e,enumerable:!0}):n,e)),Kr=e=>Xn(Rt({},"__esModule",{value:!0}),e);var os={};Jr(os,{CodeType:()=>ie,DefaultMiniAppChangelogPrompt:()=>Gn,DefaultMiniAppSplash:()=>Bn,DefaultMiniAppUpdatePrompt:()=>Jn,MINIAPP_CHANGELOG_KINDS:()=>zn,MINIAPP_PLATFORM_URL:()=>Qe,MiniAppChangelogGroups:()=>an,MiniAppChangelogHistory:()=>jn,MiniAppChangelogText:()=>Hn,MiniAppHost:()=>Nr,MiniAppHostError:()=>g,MiniAppUpdates:()=>$r,ScannerEndReason:()=>Ke,ScannerEvent:()=>Vt,ScannerLayout:()=>ye,ScannerMethod:()=>et,ToastType:()=>Ae,closeMiniApp:()=>rt,configureMiniApp:()=>Zn,createMmkvStorage:()=>to,createReactNativeBiometrics:()=>un,createRnfsFileSystem:()=>eo,dismissMiniAppChangelog:()=>rn,ensureMiniApp:()=>xt,fetchMiniAppChangelog:()=>nn,getLocalMiniApp:()=>$,getMiniAppCatalog:()=>Ir,getMiniAppCatalogEntry:()=>st,getMiniAppChangelogSeen:()=>tn,getMiniAppStatuses:()=>xr,getMiniAppUpdate:()=>Vn,getPendingChangelog:()=>$n,installBundledMiniApp:()=>cr,markMiniAppChangelogSeen:()=>at,mergeMiniAppChangelog:()=>Wn,onMiniAppEvent:()=>Yt,openMiniApp:()=>br,parseInlineMarkdown:()=>Et,pauseMiniApp:()=>Tr,pauseMiniAppDownloads:()=>kr,preloadMiniApp:()=>Ar,releaseSpeechFor:()=>Ie,restoreMiniApp:()=>Pr,resumeMiniApp:()=>Rr,resumeMiniAppDownloads:()=>Or,sendEventToWeb:()=>ur,showMiniAppChangelog:()=>en,stripInlineMarkdown:()=>Br,syncMiniAppCatalog:()=>Qt,uninstallMiniApp:()=>Er,updateMiniApp:()=>Zt,uploadToUrl:()=>fn,useMiniAppChangelog:()=>on,useMiniAppChangelogRequest:()=>sn,useMiniAppDownload:()=>it,useMiniAppDownloadsPaused:()=>vr});module.exports=Kr(os);var Qe="https://retion-miniapp-platform.vercel.app",je=null,Qn=new Set,Zn=e=>{je=e,Qn.forEach(t=>t())},F=()=>{if(!je)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return je},kt=e=>{Qn.add(e),je&&e()},fe=(...e)=>{je!=null&&je.debug&&console.log("[miniapp]",...e)};var eo=(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)}}}),to=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var x=he(require("react")),V=require("react-native"),Dr=he(require("react-native-webview"));var wt=require("react-native");var un=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),Ot,dn=()=>(Ot||(Ot=import("react-native-biometrics").then(({default:e})=>un(new e({allowDeviceCredentials:!1}))).catch(e=>{throw Ot=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),Ot);var ke=require("react-native");var no=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},oo=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(ke.Platform.OS==="android"){let s=ke.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=ke.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,u=await ke.PermissionsAndroid.check(s);if(!c())return;let w=u||await ke.PermissionsAndroid.check(d);if(!c())return;if(!u&&!w){let p=await ke.PermissionsAndroid.requestMultiple([s,d]);if(!c())return;if(p[s]!==ke.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==ke.PermissionsAndroid.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var u;if(!c())return;let d=(u={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?u:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(l=>i(l))});var hn=require("react-native");var gn=20,ro=20,po=/^[a-z][a-z0-9_-]{0,31}$/,Yr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Xr=["low","medium","high"],Be=e=>!!e&&typeof e=="object"&&!Array.isArray(e),te=e=>new g("INVALID_PARAMS",e),ht=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,io=(e,t)=>{if(e===void 0)return{};if(!Be(e)||Object.keys(e).length>ro||Object.values(e).some(n=>typeof n!="string"))throw te(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${ro} key)`);return e},uo=e=>{var n,o,r,i;if(e!==void 0&&!Be(e))throw te("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!po.test(t.source)))throw te("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!Yr.test(a))))throw te("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!ht(t.max_count,1,gn))throw te(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${gn}`);if(t.max_size!==void 0&&!ht(t.max_size,1,Number.MAX_SAFE_INTEGER))throw te("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!ht(t.concurrency,1,5))throw te("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:Qr(t.process),target:Zr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Qr=e=>{if(e===void 0)return{};if(!Be(e))throw te("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Be(n))throw te("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!ht(n[o],1,1e4))throw te(`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 te("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(!Be(n))throw te("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!ht(n.max_duration,1,3600))throw te("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Xr.includes(n.quality))throw te("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},Zr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Be(e))throw te("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!po.test(t))throw te("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Be(e.params))throw te("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 te("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 te(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:io(e.headers,"upload.headers"),form_data:io(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},go=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},ei=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=go(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},ti=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"},ut,ni=()=>(ut!=null||(ut=import("react-native-image-picker").catch(e=>{throw ut=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)}`)})),ut),so=e=>async({accept:t,max_count:n,process:o})=>{var l,s,d,u,w,p,f,L,k;let r=await ni(),i=ti(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(u=(d=o.image)==null?void 0:d.quality)!=null?u:.8,videoQuality:(p=(w=o.video)==null?void 0:w.quality)!=null?p:"medium",durationLimit:(f=o.video)==null?void 0:f.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let T=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(T,(L=c.errorMessage)!=null?L:c.errorCode)}return((k=c.assets)!=null?k:[]).filter(T=>T.uri).map((T,_)=>{var q,J,ce;return{uri:T.uri,name:(q=T.fileName)!=null?q:`file_${_+1}`,mime_type:(J=T.type)!=null?J:"application/octet-stream",size:T.fileSize,width:T.width,height:T.height,duration:T.duration,processed:!((ce=T.type)!=null&&ce.startsWith("video/"))||hn.Platform.OS==="ios"}})},oi={"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"},ri={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},ii=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var d;return(d=oi[s])!=null?d:ri[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,f)=>{var L,k,T;return{uri:p.uri,name:(L=p.name)!=null?L:`file_${f+1}`,mime_type:(k=p.type)!=null?k:"application/octet-stream",size:(T=p.size)!=null?T:void 0}});if(hn.Platform.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let u=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),w=new Map(u.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var f;return{...p,uri:(f=w.get(p.uri))!=null?f:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},dt,si=async e=>(dt!=null||(dt=import("@react-native-documents/picker").then(t=>ii(t)).catch(t=>{throw dt=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 dt)(e)),ho={library:so("library"),camera:so("camera"),document:si},ao={type:"image",label:"\u1EA2nh",accept:["image/*"]},co={type:"video",label:"Video",accept:["video/*"]},lo={library:[ao,co],camera:[ao,co],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"]}]},gt,fo=()=>(gt!=null||(gt=import("react-native-compressor").catch(()=>(gt=void 0,null))),gt),mo=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},ai=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),ci={low:640,medium:1280,high:1920},li=async(e,{image:t})=>{var o;if(!t||!ai.has(e.mime_type.toLowerCase()))return e;let n=await fo();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 mo(n,r,e.size),processed:!0}}catch{return e}},pi=async(e,{video:t})=>{var o;let n=await fo();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:ci[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await mo(n,r,e.size),processed:!0}}catch{return e}},ui={image:li,video:pi},di=(e,t)=>t.split(".").reduce((n,o)=>Be(n)?n[o]:void 0,e),fn=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([u,w])=>l.append(u,w)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let d=u=>{o.removeEventListener("abort",s),u()};c.open("POST",a.url),Object.entries(a.headers).forEach(([u,w])=>c.setRequestHeader(u,w)),c.upload.onprogress=u=>n(u.loaded,u.total||e.size||0),c.onload=()=>d(()=>{let u=c.responseText;try{u=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${c.status}`));return}let w=di(u,a.url_field);if(typeof w!="string"||!w){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:w,response:u})}),c.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),yo=e=>{var o,r;let t={...ho};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:fn};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}},wo=e=>{let{sources:t,targets:n}=yo(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===ho[i]&&lo[i]).map(i=>[i,lo[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:gn}},Lt=new Map,bo=(e,t)=>`${e}:${t}`,gi=0,Ao=(e,t)=>{var n;typeof t=="string"&&((n=Lt.get(bo(e,t)))==null||n.abort())},Ge=e=>{for(let[t,n]of Lt)t.startsWith(`${e}:`)&&n.abort()},It=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),hi=(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)}},_o=async(e,t)=>{var l;let{sources:n,targets:o}=yo(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=bo(t.instance_id,(l=t.task_id)!=null?l:`auto-${++gi}`);Lt.set(c,a);try{return await fi(e,t,r,i,a.signal)}finally{Lt.delete(c)}},fi=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=u=>u()},l,s,d)=>{var R,y,I;let u={app_id:n!=null?n:"",instance_id:t,context:{...(R=o==null?void 0:o())!=null?R:{}}},w=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:u}))).slice(0,e.max_count);if(d.aborted)throw It();if(!w.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],f=w.filter(P=>ei(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||go(P.name)}`}),!1)),L=f.map(()=>0),k=f.map(P=>{var z;return(z=P.size)!=null?z:0}),T=0,_=0,q=(P=!1)=>{if(!a||!r)return;let z=Date.now();if(!P&&z-_<200)return;_=z;let xe=k.reduce((U,le)=>U+le,0),ee=L.reduce((U,le)=>U+le,0);a("upload.progress",{task_id:r,loaded:ee,total:xe,percent:xe?Math.min(100,Math.round(ee/xe*100)):0,done_count:T,count:f.length})},J=[],ce=0,Le=async()=>{var P,z,xe;for(;ce<f.length;){let ee=ce++,U=f[ee];try{if(d.aborted)throw It();let le=U.mime_type.startsWith("image/")?"image":U.mime_type.startsWith("video/")?"video":void 0,Q=le&&!U.processed?(z=(P=i==null?void 0:i.processors)==null?void 0:P[le])!=null?z:ui[le]:void 0;if(Q&&(U=await Q(U,e.process),k[ee]=(xe=U.size)!=null?xe:k[ee],d.aborted))throw It();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 re=(Xe,Re)=>{L[ee]=Xe,Re&&(k[ee]=Re),q()},pe=await s({file:U,target:e.target,onProgress:re,signal:d,caller:u});if(typeof(pe==null?void 0:pe.url)!="string"||!pe.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Pe,...Te}=pe;J[ee]={url:Pe,name:U.name,mime_type:U.mime_type,size:U.size,width:U.width,height:U.height,duration:U.duration,...Object.keys(Te).length?{response:"response"in Te?Te.response:Te}:{}},L[ee]=k[ee]}catch(le){p.push(hi(f[ee].name,le))}finally{T++,q(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,f.length)},Le)),d.aborted)throw It();let ge=J.filter(P=>!!P);if(!ge.length){let P=p[0];throw new g((y=P==null?void 0:P.code)!=null?y:"UPLOAD_FAILED",(I=P==null?void 0:P.message)!=null?I:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ge,failed:p}};var Ft=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,Ft.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,Ft.useSyncExternalStore)(e.subscribe,r)};var Ae={info:"info",success:"success",error:"error"},mi=200,So={info:2e3,success:2e3,error:3e3},ft=Oe({message:"",type:Ae.info,tick:0}),Mo=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,mi);return o?{message:o,type:Object.values(Ae).includes(n)?n:Ae.info}:null},vo=(e,t=Ae.info)=>{ft.setState(n=>({message:e,type:t,tick:n.tick+1}))};var Se=require("react-native");var Je=require("react-native");var _e,Ze=new Map,xo=(e,t)=>{var o;let n=(o=Ze.get(e))!=null?o:new Set;n.add(t),Ze.set(e,n)},Co=(e,t)=>{let n=Ze.get(e);n&&(t?n.delete(t):n.clear(),n.size===0&&Ze.delete(e))},yn=new Map,Eo=(e,t)=>{yn.set(e,t)},Po=e=>yn.get(e),To=()=>Je.Platform.OS==="android"&&!!(_e!=null&&_e.requesting_permission),yi=1500,Dt=()=>new Promise(e=>{if(Je.Platform.OS!=="android"||Je.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,yi),o=Je.AppState.addEventListener("change",r=>{r==="active"&&t()})}),mn=e=>{var t;if(_e===e&&(_e=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Je.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Ro=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(_e)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:[]};_e=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let u=d.ExpoSpeechRecognitionModule;if(r.native=u,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let w;try{w=await u.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await Dt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!w.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await u.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(u.addListener("result",p=>{var f,L;_e!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(L=(f=p.results[0])==null?void 0:f.transcript)!=null?L:""})}),u.addListener("error",p=>{_e===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),u.addListener("end",()=>{_e===r&&(mn(r),n("speech.end"))})),r.started=!0,u.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw mn(r),d}},ko=e=>{let t=_e;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Ie=e=>{yn.delete(e);let t=Ze.get(e);Ze.delete(e),t==null||t.forEach(o=>{var r;try{(r=o.release)==null||r.call(o,e)}catch{}});let n=_e;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{mn(n)}};var Oo={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"},ie={...Oo,all:Object.values(Oo)},et={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Vt={result:"scanner.result",end:"scanner.end"},Ke={user:"user",web:"web",closed:"closed",error:"error"},ye={top:"top",full:"full"},qe={once:"once",continuous:"continuous"},wi=1500,Io=6e4,G,ne=Oe({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Fo=()=>Se.Platform.OS==="android"&&!!(G!=null&&G.requesting_permission),bn=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=>ie.all.includes(c)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>Io)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Io}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(ye).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new g("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},An=e=>G!==e?!1:(G=void 0,ne.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),bi=()=>Se.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:()=>{Se.Linking.openSettings().catch(()=>{})}}]),Do=async(e,t)=>{if(G)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");G=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=Se.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await Dt(),n(),c!=="granted")throw a&&bi(),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 mt();n(),ne.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 An(e),o}},Nt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Nt=e==null?void 0:e.insets}).catch(()=>{});var tt=()=>{var e;return Nt!=null?Nt:{top:Se.Platform.OS==="ios"?54:(e=Se.StatusBar.currentHeight)!=null?e:0,bottom:Se.Platform.OS==="ios"?34:48}},mt=async()=>{if(Se.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},No=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:ie.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:wi,hint:n.hint,layout:t===qe.once?ye.full:(i=n.layout)!=null?i:ye.top,absolute:t!==qe.once&&((a=n.layout)!=null?a:ye.top)===ye.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},Vo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=No(e,qe.once,t);a.onHit=o,a.resolve=r,a.reject=i,Do(a,n).catch(i)}),Uo=(e,t,n,o=()=>!0,r)=>{let i=No(e,qe.continuous,t);return i.emit=n,i.onHit=r,Do(i,o)},Ut=(e,t,n)=>{var o,r;if(!ne.getState().active){e.cancelled=!0;return}if(An(e)){if(e.mode===qe.once){(o=e.reject)==null||o.call(e,t===Ke.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,Vt.end,n?{reason:t,message:n}:{reason:t})}},Bo=e=>{(G==null?void 0:G.owner)===e&&Ut(G,Ke.web)},$e=e=>{(G==null?void 0:G.owner)===e&&Ut(G,Ke.closed)},_n=()=>{G&&Ut(G,Ke.user)},qo=e=>{G&&Ut(G,Ke.error,e)},Sn=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=G;if(!(!o||!ne.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===qe.once){An(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}ne.setState(d=>({last_value:c,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Vt.result,{value:c,type:l})}}},Ai={1:ie.code128,2:ie.code39,4:ie.code93,8:ie.codabar,16:ie.dataMatrix,32:ie.ean13,64:ie.ean8,128:ie.itf,256:ie.qr,512:ie.upcA,1024:ie.upcE,2048:ie.pdf417,4096:ie.aztec},_i=2500,Lo=2e3,wn=e=>{ne.setState({notice:e}),setTimeout(()=>{ne.getState().notice===e&&ne.setState({notice:null})},_i)},$o=async()=>{var t,n;let e=G;if(!(!e||ne.getState().is_picking)){e.requesting_permission=!0,ne.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:Lo,maxHeight:Lo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||G!==e)return;if(r.errorCode||!i){wn("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(G!==e)return;let l=c.map(({value:s,format:d})=>({value:s,code_type:Ai[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!l.length){wn("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Sn(l,Date.now(),!0)}catch{G===e&&wn("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await Dt(),e.requesting_permission=!1,G===e&&ne.setState({is_picking:!1})}}};var qt=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},zo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===qt&&typeof t.method=="string"?t:null}catch{return null}},bt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,Wo=(e,t)=>bt({id:e,result:t}),Ho=(e,t)=>bt({id:e,error:{code:t.code,message:t.message}}),jo=(e,t)=>bt({event:e,data:t}),vn=e=>bt({event:"context",data:e});var Go=()=>`(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: ${qt}, 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;`,Jo=()=>`(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: ${qt}, 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;`,Ko=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,Yo=e=>bt({event:e}),Xo=(e,t)=>{let n=Qo(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${vn(e)}`},Qo=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Zo=(e,t={})=>{let n=Qo(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${qt} };
|
|
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;`},er={partner:"partner_token",chatbox:"chatbox_token"},tr=(e,t)=>{let n={...e};for(let o of Object.values(er))t.includes(o)||delete n[o];return n},Mn=new Set,yt=async(e,t)=>{if(Mn.has(e))throw new g("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);Mn.add(e);try{return await t()}finally{Mn.delete(e)}},xn=e=>`(function () {
|
|
67
67
|
window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
|
|
68
68
|
window.dispatchEvent(new Event('retionscannerheight'));
|
|
69
|
-
})(); true;`,
|
|
69
|
+
})(); true;`,nr=()=>`(function () {
|
|
70
70
|
try {
|
|
71
71
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
72
72
|
if (!AudioCtx) { return; }
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
// iOS c\xF3 th\u1EC3 \u0111\u1EC3 context \u1EDF suspended / interrupted (vd. khi camera m\u1EDF phi\xEAn quay): ch\u1EA1y l\u1EA1i xong m\u1EDBi ph\xE1t.
|
|
86
86
|
if (ctx.state === 'running') { play(); } else { ctx.resume().then(play).catch(function () {}); }
|
|
87
87
|
} catch (e) {}
|
|
88
|
-
})(); true;`,bi=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Vt=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},tr=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:d,isActive:u,playBeep:y})=>{var T,_,B,G,ce,Le,ge,R;let p=s==null?void 0:s.handlers,h={app_id:c,instance_id:l,close:a},L=()=>{var f;(f=s==null?void 0:s.haptic)==null||f.call(s,"impactLight"),y==null||y()},k=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let f=eo(t);return ft(e,()=>to(f,u))}case"speech.start":{if(!d)throw k();let f={};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");f.lang=t.lang}for(let z of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[z])!==void 0){if(typeof t[z]!="boolean")throw new g("INVALID_PARAMS",`${z} ph\u1EA3i l\xE0 boolean`);f[z]=t[z]}if((t==null?void 0:t.mode)!==void 0&&t.mode!=="s2t"&&t.mode!=="voice")throw new g("INVALID_PARAMS","mode ph\u1EA3i l\xE0 's2t' ho\u1EB7c 'voice'");let I=(t==null?void 0:t.mode)==="s2t"?"s2t":"voice",P=I==="voice"?(T=s==null?void 0:s.voice)!=null?T:s==null?void 0:s.speech:void 0;if(xo(l,P),P){Mo(l,P);try{return await P.start({owner:l,app_id:c,mode:I,options:f,emit:d,isActive:u!=null?u:(()=>!0)})}catch(z){throw vo(l,P),z}}return Po(l,f,d,u)}case"speech.stop":{let f=Co(l);return f?f.stop(l):To(l)}case et.scan:return Do(l,yn(t),u,L);case et.start:{if(!d)throw k();return No(l,yn(t),d,u,L)}case et.stop:return Vo(l);case"uploadFiles":{let{task_id:f,...I}=t!=null?t:{};if(f!==void 0&&(typeof f!="string"||!f))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return bo(lo(I),{instance_id:l,app_id:c,getContext:r,task_id:f,config:s==null?void 0:s.upload,emit:d,exclusivePick:P=>ft("uploadFiles.pick",P)})}case"uploadFiles.cancel":wo(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return fo(s==null?void 0:s.upload);case"getBiometricAvailability":return((_=s==null?void 0:s.biometrics)!=null?_:await pn()).getAvailability();case"authenticateBiometric":{let f=Vt(t==null?void 0:t.reason,"reason").trim();if(!f||f.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let I=t==null?void 0:t.cancelButtonText;if(I!==void 0&&(typeof I!="string"||!I.trim()||I.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return ft(e,async()=>{var z;return((z=s==null?void 0:s.biometrics)!=null?z:await pn()).authenticate({reason:f,cancelButtonText:I})})}case"requestPayment":{let f=p==null?void 0:p.requestPayment;if(!f)throw k();let I=t==null?void 0:t.amount;if(typeof I!="number"||!Number.isFinite(I)||I<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let P={...t,amount:I,currency:Vt(t==null?void 0:t.currency,"currency")};return ft(e,()=>f(P,h))}case"printImage":{let f=p==null?void 0:p.printImage;if(!f)throw k();let I=Vt(t==null?void 0:t.image,"image");await ft(e,()=>f({image:I},h));return}case"openScreen":if(!(p!=null&&p.openScreen))throw k();await p.openScreen({screen:Vt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},h);return;case"closeApp":a();return;case"openWebview":{let f=String((B=t==null?void 0:t.url)!=null?B:"");if(!/^https?:\/\//i.test(f))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(f):yt.Linking.openURL(f));return}case"openLink":{let f=String((G=t==null?void 0:t.url)!=null?G:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(f)||/^(javascript|file|data|about|blob):/i.test(f))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(f):yt.Linking.openURL(f))}catch(I){throw new g("NOT_SUPPORTED",String((Le=(ce=I==null?void 0:I.message)!=null?ce:I)!=null?Le:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let f=_o(t);if(!f||(u==null?void 0:u())===!1)return;s!=null&&s.showToast?s.showToast(f.message,{type:f.type}):So(f.message,f.type);return}case"haptic":{let f=bi.has(t==null?void 0:t.type)?t.type:"selection";(ge=s==null?void 0:s.haptic)==null||ge.call(s,f);return}case"getSystemInfo":return{platform:yt.Platform.OS==="ios"?"ios":"android",appVersion:(R=s==null?void 0:s.app_version)!=null?R:"",theme:i?"dark":"light"};case"getAccessToken":{let f=n().access_token;if(!f)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return f}case"getToken":{let f=t==null?void 0:t.type;if(f==="access"){let z=n().access_token;if(!z)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return z}if(f!=="partner"&&f!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(f)}`);let I=Qo[f];if(!o().includes(I))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${I} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let P=f==="partner"?n().partner_token:n().chatbox_token;if(!P)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${I}`);return P}case"getUserInfo":{let f=n().user;if(!f)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return f}case"getPageInfo":{let f=n().page;if(!f)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return f}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 Cn=e=>`bundle:${e}`,En=()=>`${F().file_system.document_dir}/miniapps`,Pn=En,Tn=(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}},xn=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:[]}))},Ai=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,$=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 Tn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},De=e=>F().file_system.exists(e.entry_uri.replace("file://","")),Rn=async e=>{let t=$(e.app_id);return(t==null?void 0:t.version)===e.version&&await De(t)},or=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(()=>{})))},rr=async e=>{var t;await((t=At[e])==null?void 0:t.catch(()=>{})),F().storage.setString(Cn(e),""),await F().file_system.remove(`${Pn()}/${e}`).catch(()=>{})},nt=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},At={},ir=(e,t)=>{var i;let o=((i=At[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return At[e]=r,r.then(()=>{At[e]===r&&delete At[e]}),o},kn=(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},sr=({manifest:e,zip_path:t})=>ir(e.app_id,async()=>{var i;let n=F().file_system,o=$(e.app_id);if(o&&kn(o.version,e.version)>=0&&await De(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=Tn(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),xn(e),me("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),or(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),On=(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 nt},l=async()=>{var u;c();let s=$(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return xn(e),$(e.app_id);c();let d=o.download({url:t?Ai(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,p)=>{var L;let h=p>0?p:(L=e.size)!=null?L:0;h>0&&(n==null||n(Math.min(1,y/h)))}});r=d;try{let{status:y}=await d.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else me("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let p=Tn(e.app_id,e.version,e.entry,!!e.context_update,(u=e.permissions)!=null?u:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),xn(e),or(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(y){throw i?new nt:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:ir(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},bt={},_i=__DEV__?0:60*1e3,nr={},ar=(e,t)=>{var o,r;let n=$(e);return n&&Date.now()-((o=nr[t])!=null?o:0)<_i?Promise.resolve(n):((r=bt[e])!=null||(bt[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 On(a,{base_url:t}).promise;return nr[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),$(e))).finally(()=>{bt[e]=void 0})),bt[e])};var qt=new Map,cr=(e,t)=>(qt.set(e,t),()=>{qt.get(e)===t&&qt.delete(e)}),lr=(e,t)=>{let n=qt.get(e);return n?n(t):!1};var W=require("react"),w=require("react-native");var C=require("react/jsx-runtime"),_t="#22C55E",Si="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Mi=2,$t=18,vi=1600,St=14,xi=2e3,dr=.38,Ci=40,pr=2,Ei=8,Pi=2e3,Ti=250,ot=2e3,Ri=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:St},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:St},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:St},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:St}],ur=({color:e})=>(0,C.jsx)(C.Fragment,{children:Ri.map((t,n)=>(0,C.jsx)(w.View,{style:[x.corner,t,{borderColor:e}]},n))}),Bt=({style:e,children:t,...n})=>{let o=(0,W.useRef)(new w.Animated.Value(1)).current,r=i=>w.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,C.jsx)(w.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,C.jsx)(w.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},Ln=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var m,S;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:d}=e,u=c===fe.top,y=(0,W.useRef)(new w.Animated.Value(0)).current,p=r.useCameraDevice("back"),h=(0,W.useRef)(new w.Animated.Value(1)).current,[L,k]=(0,W.useState)(!1),[T,_]=(0,W.useState)(1),B=(0,W.useRef)(null),[G,ce]=(0,W.useState)(()=>{let{width:M,height:H}=w.Dimensions.get("window");return{width:M,height:u?H*dr:H,window_y:0}}),Le=j(ne,M=>M.last_value),ge=j(ne,M=>M.hit_tick),R=j(ne,M=>M.scan_count),f=j(ne,M=>M.notice),I=j(ne,M=>M.is_picking),P=(0,W.useRef)(null),z=tt(),xe=z.top,ee=(0,W.useRef)(new w.Animated.Value(0)).current,U=(0,W.useRef)(new w.Animated.Value(0)).current,le=(0,W.useRef)(new w.Animated.Value(0)).current,X=(0,W.useRef)(n);X.current=n,(0,W.useEffect)(()=>{if(!t)return;y.setValue(G.height);let M=w.Animated.timing(y,{toValue:0,duration:Ti,easing:w.Easing.out(w.Easing.cubic),useNativeDriver:!1});return M.start(({finished:H})=>{var ue;H&&((ue=X.current)==null||ue.call(X))}),()=>M.stop()},[t,y]);let re=Math.round(G.width*(u?.8:.78)),pe=Math.round(u?G.height*.46:re*.78),Pe=Math.round((G.height-pe)/2),Te=Math.round((G.width-re)/2),Xe=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,W.useCallback)(M=>_n(M),[])});(0,W.useEffect)(()=>{let M=w.BackHandler.addEventListener("hardwareBackPress",()=>(An(),!0));return()=>M.remove()},[]);let Re=(0,W.useRef)(ge);(0,W.useEffect)(()=>{if(ge===Re.current)return;ee.setValue(1),le.setValue(1);let M=w.Animated.parallel([w.Animated.timing(ee,{toValue:0,duration:450,useNativeDriver:!0}),w.Animated.sequence([w.Animated.delay(xi),w.Animated.timing(le,{toValue:0,duration:250,useNativeDriver:!0})])]);return M.start(),()=>M.stop()},[ge,ee,le]),(0,W.useEffect)(()=>{let M=ue=>w.Animated.timing(U,{toValue:ue,duration:vi,easing:w.Easing.inOut(w.Easing.quad),useNativeDriver:!0}),H=w.Animated.loop(w.Animated.sequence([M(1),M(0)]));return H.start(),()=>H.stop()},[U]);let Fe=(0,W.useCallback)(()=>{w.Animated.timing(h,{toValue:0,duration:220,useNativeDriver:!0}).start()},[h]);(0,W.useEffect)(()=>{let M=setTimeout(Fe,Pi);return()=>clearTimeout(M)},[Fe]);let[ct,sn]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let M=requestAnimationFrame(()=>{M=requestAnimationFrame(()=>sn(!0))});return()=>cancelAnimationFrame(M)},[]);let He=!!(p!=null&&p.hasTorch),lt=(m=p==null?void 0:p.neutralZoom)!=null?m:1,pt=p?Math.min(p.maxZoom/lt,Ei):1,an=lt*Math.min(T,pt),Ct=M=>{var de;let{touches:H}=M.nativeEvent;if(H.length!==2){B.current=null;return}let ue=Math.hypot(H[0].pageX-H[1].pageX,H[0].pageY-H[1].pageY);(de=B.current)!=null||(B.current={distance:ue,level:T}),_(Math.max(1,Math.min(pt,B.current.level*(ue/B.current.distance))))},Et=(0,C.jsx)(w.Text,{style:[x.hint,!!f&&x.hint_notice],numberOfLines:1,children:(S=f!=null?f:l)!=null?S:Si});return(0,C.jsx)(w.Animated.View,{ref:P,onTouchMove:Ct,onTouchEnd:()=>{B.current=null},pointerEvents:t?"none":"auto",style:u?[x.top,d&&x.top_absolute,t&&{height:y}]:x.full,onLayout:({nativeEvent:{layout:M}})=>{var H;t||(o==null||o(M.height),(H=P.current)==null||H.measureInWindow((ue,de)=>{ce({width:M.width,height:M.height,window_y:de||0})}))},children:(0,C.jsxs)(w.View,{style:t?[x.content_closing,{height:G.height}]:x.content,children:[p&&ct&&(0,C.jsx)(r.Camera,{style:w.StyleSheet.absoluteFill,device:p,isActive:!I,codeScanner:Xe,torch:L&&He?"on":"off",zoom:an,onPreviewStarted:Fe,onError:M=>Uo(M.message)}),(0,C.jsx)(w.Animated.View,{style:[x.preview_cover,{opacity:h}],pointerEvents:"none"}),G.height>0&&(0,C.jsxs)(w.View,{style:x.overlay,pointerEvents:"none",children:[(0,C.jsx)(w.View,{style:[x.dim_ring,{top:Pe-ot,left:Te-ot,width:re+ot*2,height:pe+ot*2}]}),(0,C.jsxs)(w.View,{style:{position:"absolute",top:Pe,left:Te,width:re,height:pe},children:[(0,C.jsx)(ur,{color:"#FFFFFF"}),(0,C.jsx)(w.Animated.View,{style:[w.StyleSheet.absoluteFill,{opacity:ee}],children:(0,C.jsx)(ur,{color:_t})}),(0,C.jsxs)(w.Animated.View,{style:[x.scan_line_wrap,{transform:[{translateY:U.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,pe-$t)]})}]}],children:[(0,C.jsx)(w.View,{style:x.scan_glow_outer}),(0,C.jsx)(w.View,{style:x.scan_glow_inner}),(0,C.jsx)(w.View,{style:x.scan_line})]})]}),(0,C.jsx)(w.View,{style:[x.hint_slot,u?{top:0,height:Pe-6,justifyContent:"flex-end"}:{top:Pe+pe+20}],children:Et}),a===Be.continuous&&!!Le&&(0,C.jsx)(w.Animated.View,{style:[x.result_slot,{top:u?Pe+pe-Ci:Pe+pe+52},{opacity:le}],children:(0,C.jsxs)(w.View,{style:x.result,children:[(0,C.jsx)(w.View,{style:x.check_badge,children:(0,C.jsx)(w.View,{style:x.check_mark})}),(0,C.jsx)(w.Text,{style:x.result_text,numberOfLines:1,children:Le}),(0,C.jsxs)(w.Text,{style:x.result_count,children:["\xB7 ",R," m\xE3"]})]})})]}),G.height>0&&(0,C.jsx)(w.View,{style:[x.close_slot,u?x.close_slot_top:{top:Math.max(12,xe-G.window_y+12)}],children:(0,C.jsxs)(Bt,{style:[x.close_button,!!s&&x.glass_surface],onPress:An,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,C.jsx)(s,{style:x.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,C.jsx)(w.View,{style:[x.close_bar,x.close_bar_a]}),(0,C.jsx)(w.View,{style:[x.close_bar,x.close_bar_b]})]})}),(0,C.jsx)(w.View,{style:[x.toolbar_wrap,!u&&{bottom:z.bottom+20}],pointerEvents:"box-none",children:(0,C.jsxs)(w.View,{style:[x.toolbar,!!s&&x.glass_surface],children:[s&&(0,C.jsx)(s,{style:x.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,C.jsx)(Bt,{style:x.tool,onPress:qo,disabled:I,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,C.jsxs)(w.View,{style:x.image_icon,children:[(0,C.jsx)(w.View,{style:x.image_icon_dot}),(0,C.jsx)(w.View,{style:x.image_icon_hill})]})}),!!p&&pt>=pr&&(0,C.jsx)(Bt,{style:[x.tool,T>1&&x.tool_on],onPress:()=>_(M=>M>1?1:pr),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,C.jsxs)(w.Text,{style:[x.zoom_text,T>1&&x.zoom_text_on],children:[Math.round(T*10)/10,"x"]})}),He&&(0,C.jsx)(Bt,{style:[x.tool,L&&x.tool_on],onPress:()=>k(M=>!M),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:L},children:(0,C.jsx)(w.Text,{style:[x.torch_icon,L&&x.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},ki="rgba(0,0,0,0.5)",In=50,x=w.StyleSheet.create({top:{height:`${dr*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:ot,borderColor:ki,borderRadius:ot+St},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:$t,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:$t,borderRadius:$t/2,backgroundColor:_t,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:_t,opacity:.2},scan_line:{height:Mi,borderRadius:1,backgroundColor:_t},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:In,height:In,borderRadius:In/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:_t},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 Se=require("react"),O=require("react-native");var Y=require("react/jsx-runtime"),Fn={[be.info]:"#3B82F6",[be.success]:"#22C55E",[be.error]:"#EF4444"},gr=-120,zt=O.Platform.OS==="android",hr=({type:e})=>e===be.success?(0,Y.jsx)(O.View,{style:se.check_mark}):e===be.error?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O.View,{style:[se.cross_bar,se.cross_a]}),(0,Y.jsx)(O.View,{style:[se.cross_bar,se.cross_b]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O.View,{style:se.info_dot}),(0,Y.jsx)(O.View,{style:se.info_bar})]}),mr=()=>{let e=j(mt,y=>y.message),t=j(mt,y=>y.type),n=j(mt,y=>y.tick),o=(0,Se.useRef)(new O.Animated.Value(gr)).current,r=(0,Se.useRef)(new O.Animated.Value(0)).current,i=(0,Se.useRef)(new O.Animated.Value(.92)).current,a=(0,Se.useRef)(new O.Animated.Value(0)).current,[c,l]=(0,Se.useState)(),[s,d]=(0,Se.useState)(!1);(0,Se.useEffect)(()=>{let y=!0;return bn().then(p=>{y&&p&&l(()=>p)}),()=>{y=!1}},[]);let u=(0,Se.useRef)(n);return(0,Se.useEffect)(()=>{if(n===u.current)return;O.AccessibilityInfo.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let y=O.Animated.sequence([O.Animated.parallel([O.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),O.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),O.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),O.Animated.sequence([O.Animated.delay(90),O.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),O.Animated.delay(Ao[t]),O.Animated.parallel([O.Animated.timing(o,{toValue:gr,duration:240,useNativeDriver:!0}),O.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:p})=>{p&&d(!1)}),()=>y.stop()},[n]),s?(0,Y.jsx)(O.View,{style:[se.layer,{top:tt().top+(zt?12:8)}],pointerEvents:"none",children:(0,Y.jsxs)(O.Animated.View,{style:[se.toast,zt&&se.toast_android,!!c&&se.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,Y.jsx)(c,{style:se.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),zt?(0,Y.jsx)(O.Animated.View,{style:[se.badge_halo,{backgroundColor:`${Fn[t]}33`,transform:[{scale:a}]}],children:(0,Y.jsx)(O.View,{style:[se.badge,{backgroundColor:Fn[t]}],children:(0,Y.jsx)(hr,{type:t})})}):(0,Y.jsx)(O.Animated.View,{style:[se.badge,{backgroundColor:Fn[t],transform:[{scale:a}]}],children:(0,Y.jsx)(hr,{type:t})}),(0,Y.jsx)(O.Text,{style:[se.message,zt&&se.message_android],numberOfLines:2,children:e})]})}):null},se=O.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:O.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:{}}),fr=({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,d={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},u=Object.keys(d);return a&&a>0&&u.length>a&&u.filter(y=>y!==s).sort((y,p)=>d[y].last_used_at-d[p].last_used_at).slice(0,u.length-a).forEach(y=>{delete d[y]}),i?{active_key:s,instances:d}:{instances:d}})},yr=e=>fr(e,!0),wr=e=>fr(e,!1),rt=()=>ae.setState({active_key:null}),Wt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var br="catalog",Oi="paused_apps",Ii="removed_apps",Li=10*1e3,Fi=2,Di=3e3,Ni=()=>{var e;try{return JSON.parse((e=F().storage.getString(br))!=null?e:"{}")}catch{return{}}},N=Oe({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Ar=e=>{var t;return!!((t=F().manual_update)!=null&&t.includes(e))},Jt=new Set,_r=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{}}}},Ee=_r(Oi),We=_r(Ii);Tt(()=>{Ee.load(),We.load();let e=Ni(),t={};Object.keys(e).filter(n=>!We.has(n)).forEach(n=>{let o=$(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:Ee.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),N.setState({catalog:e,downloads:t})});var it=e=>j(N,t=>e?t.downloads[e]:void 0),Sr=()=>j(N,e=>e.pause_reasons.length>0),Ce=(...e)=>me("queue",...e),oe=[],Ne={},D=null,Ht=new Set,Ye={},Dn=new Set,Ve=e=>{Dn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Gt=e=>(Dn.add(e),()=>{Dn.delete(e)}),Mr=()=>N.getState().downloads,ye=(e,t)=>{let n=!!$(e),o=N.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};N.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?Ve({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ve({type:"progress",app_id:e,progress:i.progress,version:i.version})},jt=(e,t)=>{var n;(n=Ye[e])==null||n.forEach(o=>o(t)),delete Ye[e]},Vi=()=>N.getState().pause_reasons.length>0,ze=e=>{var c;if(D)return;let t=e?oe.indexOf(e):Vi()?-1:oe.findIndex(l=>!Ee.has(l));if(t<0||t>=oe.length)return;let[n]=oe.splice(t,1),o=N.getState().catalog[n];if(!o){jt(n,$(n)),ze();return}let r=Date.now();Ne[n]=((c=Ne[n])!=null?c:0)+1,ye(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=On(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,ye(n,{progress:s/100,version:o.version}))}});D={app_id:n,handle:a,forced:!!e},Ce("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Ce("installed",n,o.version,`${Date.now()-r}ms`),ye(n,{status:"installed",progress:1,version:o.version}),jt(n,l)}).catch(l=>{var d;if(l instanceof nt){if(Ht.has(n))return;Ce("paused",n),Ne[n]-=1,oe.unshift(n),ye(n,{status:Ee.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=l==null?void 0:l.message)!=null?d:l);if(console.warn("[miniapp-queue] failed",n,s),Ne[n]<Fi){ye(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var u;oe.includes(n)||(D==null?void 0:D.app_id)===n||(oe.push(n),ze((u=Ye[n])!=null&&u.length?n:void 0))},Di);return}ye(n,{status:"failed",progress:0,version:o.version,error:s}),jt(n,$(n))}).finally(()=>{D=null;let l=oe.find(s=>{var d;return(d=Ye[s])==null?void 0:d.length});ze(l)})},Kt=(e,{front:t=!1}={})=>{if((D==null?void 0:D.app_id)===e)return;let n=oe.indexOf(e);if(n>=0){if(!t)return;oe.splice(n,1)}t?oe.unshift(e):oe.push(e)},Ui=async e=>{let{host_id:t,client_token:n}=F(),o=new AbortController,r=setTimeout(()=>o.abort(),Li);try{let i=`${Qe}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},Mt=null,Yt=()=>(Mt!=null||(Mt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(F().channels.map(Ui)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(N.getState().catalog).filter(l=>!o[l]);F().storage.setString(br,JSON.stringify(o)),N.setState({catalog:o}),await Promise.all(r.map(l=>vr(l,{by_user:!1}))),r.forEach(l=>We.delete(l));let i=Object.keys(o).filter(l=>!We.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await Rn(l)){ye(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=$(l.app_id);if(Ar(l.app_id)&&!Jt.has(l.app_id)&&s&&await De(s)){ye(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 N.setState({updates:c}),a.forEach(l=>{Ne[l.app_id]=0,ye(l.app_id,{status:Ee.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Kt(l.app_id)}),Ce("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Ve({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Ve({type:"update_available",...l})),ze(),{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),Ve({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{Mt=null}})()),Mt),vr=async(e,{by_user:t})=>{var r,i,a,c;if(t&&We.add(e),Ht.has(e))return;Ht.add(e),Ee.delete(e);let n=oe.indexOf(e);n>=0&&oe.splice(n,1),(D==null?void 0:D.app_id)===e&&D.handle.cancel();let o=(c=(a=(r=N.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=$(e))==null?void 0:i.version)!=null?c:"";ye(e,{status:"uninstalling",progress:0,version:o}),await rr(e),Wt(e),N.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Ne[e],Ht.delete(e),jt(e,null),Ce("uninstalled",e,t?"(user)":"(not in list)"),Ve({type:"uninstalled",app_id:e})},xr=e=>vr(e,{by_user:!0}),Cr=e=>{let t=st(e);return t?(We.delete(e),(D==null?void 0:D.app_id)===e||oe.includes(e)||(Ne[e]=0,ye(e,{status:Ee.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Kt(e),ze(),Ce("restore",e)),!0):!1},Er=e=>{if(Ee.has(e))return;if(Ee.add(e),Ce("pause app",e),(D==null?void 0:D.app_id)===e&&!D.forced){D.handle.cancel();return}let t=N.getState().downloads[e];oe.includes(e)&&t&&ye(e,{status:"paused",progress:0,version:t.version})},Pr=e=>{if(!Ee.delete(e))return;Ce("resume app",e);let t=N.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!oe.includes(e)&&st(e)&&(Ne[e]=0,Kt(e)),oe.includes(e)&&t&&ye(e,{status:"queued",progress:0,version:t.version}),ze()},Tr=e=>{let{pause_reasons:t}=N.getState();t.includes(e)||(N.setState({pause_reasons:[...t,e]}),Ce("pause",e),t.length===0&&Ve({type:"pause_change",paused:!0,reasons:[e]}),D&&!D.forced&&D.handle.cancel())},Rr=e=>{let{pause_reasons:t}=N.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);N.setState({pause_reasons:n}),Ce("resume",e),n.length===0&&Ve({type:"pause_change",paused:!1,reasons:n}),ze()},Nn=e=>N.getState().updates[e],Xt=async e=>{var n,o;let t=Nn(e);Jt.add(e);try{let r=await vt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=st(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(N.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}}}),Ce("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),Ve({type:"update_applied",app_id:e,version:r.version}),!0)}finally{Jt.delete(e)}},kr=()=>Object.values(N.getState().catalog).map(e=>({...e,installed:!!$(e.app_id),removed_by_user:We.has(e.app_id)})),st=e=>N.getState().catalog[e],vt=async e=>{let t=st(e);if(!t)return;if(Ee.delete(e),We.delete(e),await Rn(t))return $(e);let n=$(e);if(Ar(e)&&!Jt.has(e)&&n&&await De(n))return n;let o=new Promise(r=>{var i;((i=Ye[e])!=null?i:Ye[e]=[]).push(r)});return(D==null?void 0:D.app_id)===e?D.forced=!0:(Ne[e]=0,Kt(e,{front:!0}),D&&!D.forced?D.handle.cancel():ze(e)),o};var q=require("react/jsx-runtime"),Vn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Or=0,qi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Bi=v.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var Ct,Et;let u=(0,v.useRef)(null),y=(0,v.useRef)(!1),p=j(ae,m=>m.instances[e]),h=p==null?void 0:p.app.app_id,L=p==null?void 0:p.app.manifest_url,k=p==null?void 0:p.context,T=p==null?void 0:p.url_params,_=j(ne,m=>{var S;return((S=m.active)==null?void 0:S.owner)===e?m.active:null}),[B,G]=(0,v.useState)(null),[ce,Le]=(0,v.useState)(_);_!==ce&&(Le(_),_?G(null):(ce==null?void 0:ce.layout)===fe.top&&G(ce));let ge=(_==null?void 0:_.layout)===fe.top?_:B,[R,f]=(0,v.useState)(()=>h?$(h):null),[I,P]=(0,v.useState)(!1),[z,xe]=(0,v.useState)(0),[ee,U]=(0,v.useState)(0),[le,X]=(0,v.useState)(!1),re=(0,v.useRef)(null),pe=m=>{re.current&&clearTimeout(re.current),re.current=setTimeout(()=>{re.current=null,X(!0)},m)};(0,v.useEffect)(()=>()=>{re.current&&clearTimeout(re.current)},[]),(0,v.useEffect)(()=>{if(!h||!t&&R)return;let m=!0;return P(!1),(async()=>{let S=$(h),M=S?await De(S):!1;if(!m||(f(M?de=>!de||de.version!==S.version||de.permissions.join(",")!==S.permissions.join(",")?S:de:null),__DEV__&&Date.now()-Or>1e4&&(Or=Date.now(),await Yt()),!m))return;let H=await vt(h),ue=H!==void 0?H:L?await ar(h,L):$(h);if(m){if(!ue){P(!0);return}f(de=>de!=null?de:ue)}})(),()=>{m=!1}},[t,h,L,z]),(0,v.useEffect)(()=>cr(e,m=>u.current?(u.current.postMessage(m),!0):!1),[e]);let Pe=j(N,m=>{let S=h?m.downloads[h]:void 0;return(S==null?void 0:S.status)==="installed"?S.version:void 0});(0,v.useEffect)(()=>{if(t||!h||!R)return;let m=$(h);if(!m||m.version===R.version)return;let S=!0;return De(m).then(M=>{!S||!M||(me(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",R.version,"\u2192",m.version),f(m))}),()=>{S=!1}},[t,h,Pe,R==null?void 0:R.version]);let Te=j(N,m=>{var S;return h&&(S=m.apply_ticks[h])!=null?S:0});(0,v.useEffect)(()=>{if(!Te||!h)return;let m=$(h);if(!m||m.version===(R==null?void 0:R.version))return;let S=!0;return De(m).then(M=>{!S||!M||(me(`webview:${e}`,"c\u1EADp nh\u1EADt",R==null?void 0:R.version,"\u2192",m.version),X(!1),f(m))}),()=>{S=!1}},[Te]),(0,v.useEffect)(()=>{var M;let m=(M=F().keep_alive)==null?void 0:M.idle_close_ms;if(t||!m||m<=0)return;let S=setTimeout(()=>{Wt(e)},m);return()=>clearTimeout(S)},[t,e]),(0,v.useEffect)(()=>{r>0&&(P(!1),X(!1),U(m=>m+1),xe(m=>m+1))},[r]);let Xe=(0,v.useRef)(t);(0,v.useEffect)(()=>{var m;Xe.current!==t&&(Xe.current=t,y.current&&((m=u.current)==null||m.injectJavaScript(Go(t?"resumed":"paused"))))},[t]);let Re=`${(Ct=R==null?void 0:R.version)!=null?Ct:"none"}:${(Et=R==null?void 0:R.permissions.join(","))!=null?Et:""}:${ee}`,Fe=(0,v.useMemo)(()=>JSON.stringify([k!=null?k:{},T!=null?T:{}]),[k,T]),ct=(0,v.useMemo)(()=>{var m;return Zo(T!=null?T:{},(m=R==null?void 0:R.permissions)!=null?m:[])},[Fe,R==null?void 0:R.permissions]),sn=(0,v.useMemo)(()=>Xo(k!=null?k:{},ct)+jo()+Jo()+(F().debug?Ho():""),[ct]),He=(0,v.useRef)(null),lt=(0,v.useRef)(null);(0,v.useEffect)(()=>{var S,M,H;if(!R)return;if(lt.current!==Re){lt.current=Re,He.current=Fe;return}if(He.current===Fe)return;let m=((M=JSON.parse((S=He.current)!=null?S:"[]")[0])!=null?M:{}).org_id;if(He.current=Fe,m===(k==null?void 0:k.org_id)&&y.current){X(!1),pe(1500),(H=u.current)==null||H.injectJavaScript(Ko(k!=null?k:{},ct));return}X(!1),U(ue=>ue+1)},[Fe,R,Re]),(0,v.useEffect)(()=>(t||(Ie(e),$e(e),Je(e)),()=>{Ie(e),$e(e),Je(e)}),[t,e,Re,r]),(0,v.useEffect)(()=>{let m=V.AppState.addEventListener("change",S=>{S==="background"&&!Eo()&&Ie(e),S==="background"&&!Io()&&$e(e)});return()=>m.remove()},[e]);let pt=(0,v.useCallback)(async m=>{var M,H,ue,de,cn,Jn;let S=Bo(m.nativeEvent.data);if(!S){if(h&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(m.nativeEvent.data,{app_id:h,instance_id:e})).catch(K=>{console.warn("[miniapp] onWebEvent l\u1ED7i",h,K)})}catch(K){console.warn("[miniapp] onWebEvent l\u1ED7i",h,K)}return}if(S.method==="log"){let{level:K,text:Q}=S;me(`web:${e}`,K!=null?K:"log",Q!=null?Q:"");return}if(S.method==="pong"){re.current||X(!0);return}if(S.method==="touchAtTop"){i.emit(!!S.at_top);return}if(S.method==="contextApplied"){re.current&&clearTimeout(re.current),re.current=null,X(!0);return}if(S.method==="ready"){y.current=!0,X(!0);let K=(M=ae.getState().instances[e])==null?void 0:M.context;K&&((H=u.current)==null||H.injectJavaScript(Mn(K)));return}try{let K=await tr(S,{getHostData:()=>{var Q,we;return(we=(Q=ae.getState().instances[e])==null?void 0:Q.host_data)!=null?we:{}},getPermissions:()=>{var Q,we;return h?(we=(Q=$(h))==null?void 0:Q.permissions)!=null?we:[]:[]},getContext:()=>{var Q,we;return(we=(Q=ae.getState().instances[e])==null?void 0:Q.context)!=null?we:{}},is_dark:o,close:rt,app_id:h!=null?h:"",instance_id:e,options:c,emit:(Q,we)=>{var Gn;(Gn=u.current)==null||Gn.injectJavaScript(Wo(Q,we))},playBeep:(ue=c==null?void 0:c.playScannerBeep)!=null?ue:(()=>{var Q;(Q=u.current)==null||Q.injectJavaScript(er())}),isActive:()=>ae.getState().active_key===e&&V.AppState.currentState!=="background"});S.id&&((de=u.current)==null||de.injectJavaScript($o(S.id,K)))}catch(K){if(!S.id)return;let Q=K==null?void 0:K.code,we=K instanceof g?K:new g(typeof Q=="string"?Q:"HOST_ERROR",String((cn=K==null?void 0:K.message)!=null?cn:K));(Jn=u.current)==null||Jn.injectJavaScript(zo(S.id,we))}},[e,o,h,i,c]),an=(0,v.useCallback)(()=>{P(!1),U(m=>m+1),xe(m=>m+1)},[]);return(0,q.jsxs)(V.View,{style:[V.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&Me.behind],pointerEvents:t?"auto":"none",children:[ge&&(0,q.jsx)(Ln,{scanner:ge,closing:ge===B,onClosed:()=>{var m;G(null),ge.absolute&&((m=u.current)==null||m.injectJavaScript(vn(0)))},onHeight:ge.absolute?m=>{var S;return(S=u.current)==null?void 0:S.injectJavaScript(vn(m))}:void 0}),R?(0,q.jsx)(Lr.default,{ref:u,source:{uri:R.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?En():R.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:sn,onMessage:pt,onShouldStartLoadWithRequest:m=>{let S=m.url;return m.isTopFrame===!1||!/^https?:\/\//i.test(S)?!0:(Promise.resolve(c!=null&&c.openUrl?c.openUrl(S):V.Linking.openURL(S)).catch(()=>{}),!1)},setSupportMultipleWindows:!1,bounces:!1,overScrollMode:"never",onLoadStart:m=>{Ie(e),$e(e),Je(e),me(`webview:${e}`,"load start",Vn(m.nativeEvent.url)),y.current=!1,X(!1)},onError:m=>{Ie(e),$e(e),Je(e),me(`webview:${e}`,"load error",Vn(m.nativeEvent.url),m.nativeEvent.description),P(!0),X(!1)},onLoadEnd:m=>{let S=m.nativeEvent.url;me(`webview:${e}`,"load end",Vn(S)),h&&(d==null||d({app_id:h,instance_id:e,url:S})),pe(1500)},onContentProcessDidTerminate:()=>{Ie(e),$e(e),Je(e),y.current=!1,X(!1),U(m=>m+1)},onRenderProcessGone:()=>(Ie(e),$e(e),Je(e),y.current=!1,X(!1),U(m=>m+1),!0),style:Me.webview},Re):null,(_==null?void 0:_.layout)===fe.full&&(0,q.jsx)(Ln,{scanner:_}),p&&(0,q.jsx)(zi,{visible:!R||!le,interactive:I,children:(0,q.jsx)($i,{splash:a,app:p.app,is_dark:o,error:I,has_bundle:!!R,retry:an})})]})}),$i=v.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=it(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,q.jsx)(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=(0,v.useRef)(new V.Animated.Value(e?1:0)).current,[r,i]=(0,v.useState)(e);return(0,v.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=V.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,q.jsx)(V.Animated.View,{style:[V.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},Un=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,q.jsxs)(V.View,{style:[Me.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,q.jsx)(V.View,{style:[Me.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,q.jsx)(V.Image,{source:{uri:e.icon},style:Me.splash_icon_image}):(0,q.jsx)(V.Text,{style:Me.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,q.jsx)(V.Text,{style:[Me.splash_name,{color:i}],children:e.name}),n==="error"?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(V.Text,{style:Me.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,q.jsx)(V.TouchableOpacity,{activeOpacity:.7,style:[Me.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,q.jsx)(V.Text,{style:[Me.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(V.ActivityIndicator,{style:Me.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,q.jsxs)(V.Text,{style:Me.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},Ir=(e,t)=>{let n=(0,v.useRef)(t),o=(0,v.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.`))},Wi=({container:e,splash:t=Un,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{Ir("container",e),Ir("splash",t);let l=e,s=j(ae,_=>_.active_key),d=(0,v.useRef)(s);s&&(d.current=s);let u=j(ae,_=>Object.keys(_.instances).join("|")),y=j(ae,_=>{var B;return _.active_key?(B=_.instances[_.active_key])==null?void 0:B.app.name:void 0}),p=(0,v.useMemo)(()=>u?u.split("|"):[],[u]),[h,L]=(0,v.useState)({}),k=(0,v.useRef)(qi()).current;(0,v.useEffect)(()=>{if(!s||!r)return;let _=V.BackHandler.addEventListener("hardwareBackPress",()=>(rt(),!0));return()=>_.remove()},[s,r]);let T=(0,v.useCallback)(()=>{let _=ae.getState().active_key;_&&L(B=>({...B,[_]:(B[_]||0)+1}))},[]);return p.length?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:rt,reload:T,subscribeWebAtTop:k.subscribe,children:p.map(_=>(0,q.jsx)(Bi,{instance_key:_,is_active:s===_,is_front:(s!=null?s:d.current)===_,is_dark:n,reload_tick:h[_]||0,web_at_top:k,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},_))}),(0,q.jsx)(mr,{})]}):null},Me=V.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"}}),Fr=v.default.memo(Wi);var Ue=require("react");var Nr=e=>`changelog_seen:${e}`,Hi=10*1e3,Zt=e=>F().storage.getString(Nr(e))||null,at=(e,t=(n=>(n=$(e))==null?void 0:n.version)())=>{t&&F().storage.setString(Nr(e),t)},Bn=e=>{var o;let t=(o=$(e))==null?void 0:o.version;if(!t)return null;let n=Zt(e);return n?kn(t,n)>0?{app_id:e,from:n,to:t}:null:(at(e,t),null)},ji=e=>{var t,n,o;return(o=(n=(t=N.getState().catalog[e])==null?void 0:t.channel)!=null?n:F().channels[0])!=null?o:"production"},en=async(e,{from:t,to:n,channel:o=ji(e)}={})=>{let{client_token:r}=F(),i=new URLSearchParams({channel:o});t&&i.set("from",t),n&&i.set("to",n);let a=new AbortController,c=setTimeout(()=>a.abort(),Hi);try{let l=await fetch(`${Qe}/api/miniapps/${encodeURIComponent(e)}/changelog?${i}`,{headers:{Authorization:`Bearer ${r}`},signal:a.signal});if(!l.ok)throw new Error(`changelog ${e} ${l.status}`);return(await l.json()).versions}finally{clearTimeout(c)}},tn=(e,{from:t,to:n,enabled:o=!0}={})=>{let[r,i]=(0,Ue.useState)([]),[a,c]=(0,Ue.useState)(!1),[l,s]=(0,Ue.useState)(),[d,u]=(0,Ue.useState)(0),y=(0,Ue.useCallback)(()=>u(p=>p+1),[]);return(0,Ue.useEffect)(()=>{if(!e||!o)return;let p=!0;return c(!0),s(void 0),en(e,{from:t,to:n}).then(h=>{p&&i(h)}).catch(h=>{var L;p&&s(String((h==null?void 0:h.name)==="AbortError"?"timeout":(L=h==null?void 0:h.message)!=null?L:h))}).finally(()=>{p&&c(!1)}),()=>{p=!1}},[e,t,n,o,d]),{versions:r,loading:a,error:l,reload:y}},xt=Oe({request:null}),qn=!1,Ji=e=>{var t,n;return(n=(t=N.getState().catalog[e])==null?void 0:t.name)!=null?n:e},Qt=async(e,{name:t}={})=>{if(xt.getState().request||qn)return!1;let n=Bn(e);if(!n)return!1;qn=!0;try{let o=await en(e,{from:n.from,to:n.to});return o.length?(xt.setState({request:{...n,name:t!=null?t:Ji(e),versions:o}}),!0):(at(e,n.to),!1)}catch(o){return me("changelog failed",e,o),!1}finally{qn=!1}},nn=()=>{let{request:e}=xt.getState();e&&at(e.app_id,e.to),xt.setState({request:null})},on=()=>j(xt,e=>e.request),Dr=!1;Tt(()=>{if(Dr)return;Dr=!0;let e=()=>F().changelog!==!1;Gt(n=>{n.type==="status_change"&&n.state.status==="installed"&&!Zt(n.app_id)&&at(n.app_id,n.state.version),n.type==="update_applied"&&e()&&Qt(n.app_id)});let t=ae.getState().active_key;ae.subscribe(()=>{let{active_key:n,instances:o}=ae.getState();if(n===t)return;t=n;let r=n?o[n]:void 0;r&&e()&&Qt(r.app.app_id,{name:r.app.name})})});var ve=he(require("react")),b=require("react-native");var A=require("react/jsx-runtime"),Z={blue:"#007AFF",track:"#E5E5EA",overlay:"rgba(0, 0, 0, 0.6)",shadow:"#000000",title:"#1A1A1A",sub_title:"#666666",error:"#D92D20",hint:"#C0C0C0",surface:"#FFFFFF",background:"#F2F2F7"},$n=[{key:"new",label:"M\u1EDBi",color:"#007AFF",bg:"#E5F1FF"},{key:"fix",label:"S\u1EEDa l\u1ED7i",color:"#C4320A",bg:"#FFF1EB"},{key:"improve",label:"C\u1EA3i thi\u1EC7n",color:"#067647",bg:"#E7F7EE"}],zn=e=>({new:e.flatMap(t=>t.changelog.new),fix:e.flatMap(t=>t.changelog.fix),improve:e.flatMap(t=>t.changelog.improve)}),Gi=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleDateString("vi-VN")},rn=({changelog:e})=>(0,A.jsx)(b.View,{style:E.groups,children:$n.filter(t=>e[t.key].length).map(t=>(0,A.jsxs)(b.View,{style:E.group,children:[(0,A.jsx)(b.View,{style:[E.badge,{backgroundColor:t.bg}],children:(0,A.jsx)(b.Text,{style:[E.badge_text,{color:t.color}],children:t.label})}),e[t.key].map((n,o)=>(0,A.jsxs)(b.View,{style:E.item,children:[(0,A.jsx)(b.Text,{style:[E.bullet,{color:t.color}],children:"\u2022"}),(0,A.jsx)(b.Text,{style:E.item_text,children:n})]},o))]},t.key))}),Wn=({app_id:e,name:t,onClose:n})=>{let o=tt(),{versions:r,loading:i,error:a,reload:c}=tn(e);return(0,A.jsxs)(b.View,{style:[E.history,{paddingTop:o.top}],children:[(0,A.jsxs)(b.View,{style:E.history_header,children:[(0,A.jsxs)(b.Text,{style:E.history_title,numberOfLines:1,children:["L\u1ECBch s\u1EED c\u1EADp nh\u1EADt \xB7 ",t]}),(0,A.jsx)(b.TouchableOpacity,{onPress:n,hitSlop:12,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:(0,A.jsx)(b.Text,{style:E.link,children:"\u0110\xF3ng"})})]}),i&&!r.length?(0,A.jsx)(b.ActivityIndicator,{style:E.loading,color:Z.blue}):a&&!r.length?(0,A.jsxs)(b.View,{style:E.center,children:[(0,A.jsx)(b.Text,{style:E.sub_title,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c l\u1ECBch s\u1EED c\u1EADp nh\u1EADt."}),(0,A.jsx)(b.TouchableOpacity,{onPress:c,children:(0,A.jsx)(b.Text,{style:E.link,children:"Th\u1EED l\u1EA1i"})})]}):(0,A.jsxs)(b.ScrollView,{contentContainerStyle:[E.history_list,{paddingBottom:o.bottom+24}],children:[r.map(l=>(0,A.jsxs)(b.View,{style:E.card,children:[(0,A.jsxs)(b.View,{style:E.card_head,children:[(0,A.jsxs)(b.Text,{style:E.version,children:["v",l.version]}),(0,A.jsx)(b.Text,{style:E.date,children:Gi(l.created_at)})]}),(0,A.jsx)(rn,{changelog:l.changelog})]},l.version)),!r.length&&(0,A.jsx)(b.Text,{style:[E.sub_title,E.empty],children:"Ch\u01B0a c\xF3 ghi ch\xFA c\u1EADp nh\u1EADt."})]})]})},Hn=({request:e,changelog:t,onClose:n})=>{let[o,r]=(0,ve.useState)(!1);return(0,A.jsx)(b.Modal,{visible:!0,transparent:!o,animationType:o?"slide":"fade",statusBarTranslucent:!0,onRequestClose:n,children:o?(0,A.jsx)(Wn,{app_id:e.app_id,name:e.name,onClose:n}):(0,A.jsx)(b.Pressable,{style:E.overlay,onPress:n,children:(0,A.jsxs)(b.Pressable,{style:E.sheet,onPress:()=>{},children:[(0,A.jsx)(b.Text,{style:E.title,children:"C\xF3 g\xEC m\u1EDBi"}),(0,A.jsx)(b.Text,{style:E.sub_title,children:`${e.name} \xB7 v${e.from} \u2192 v${e.to}`}),(0,A.jsx)(b.ScrollView,{style:E.scroll,children:(0,A.jsx)(rn,{changelog:t})}),(0,A.jsx)(b.TouchableOpacity,{style:E.btn_primary,activeOpacity:.8,onPress:n,children:(0,A.jsx)(b.Text,{style:E.btn_primary_text,children:"\u0110\xE3 hi\u1EC3u"})}),(0,A.jsx)(b.TouchableOpacity,{style:E.btn_secondary,onPress:()=>r(!0),children:(0,A.jsx)(b.Text,{style:E.link,children:"Xem t\u1EA5t c\u1EA3 c\u1EADp nh\u1EADt"})})]})})})},jn=({update:e,is_updating:t,progress:n,has_failed:o,onUpdate:r,logo:i})=>{let a=(0,ve.useRef)(new b.Animated.Value(0)).current,c=(0,ve.useRef)(new b.Animated.Value(30)).current;return(0,ve.useEffect)(()=>{b.Animated.parallel([b.Animated.timing(a,{toValue:1,duration:400,useNativeDriver:!0}),b.Animated.spring(c,{toValue:0,friction:8,tension:40,useNativeDriver:!0})]).start()},[a,c]),(0,A.jsx)(b.Modal,{visible:!0,transparent:!0,animationType:"none",statusBarTranslucent:!0,onRequestClose:()=>{},children:(0,A.jsx)(b.View,{style:E.overlay,children:(0,A.jsxs)(b.Animated.View,{style:[E.container,{opacity:a,transform:[{translateY:c}]}],children:[i&&(0,A.jsx)(b.Image,{source:i,style:E.logo}),(0,A.jsx)(b.Text,{style:E.title,children:t?"\u0110ang c\u1EADp nh\u1EADt\u2026":"\u0110\xE3 c\xF3 b\u1EA3n c\u1EADp nh\u1EADt"}),!t&&(0,A.jsxs)(b.Text,{style:[E.sub_title,E.gap],children:[`Phi\xEAn b\u1EA3n ${e.next_version} \u0111\xE3 s\u1EB5n s\xE0ng (hi\u1EC7n t\u1EA1i ${e.current_version}).`,`
|
|
89
|
-
`,"Vui l\xF2ng c\u1EADp nh\u1EADt \u0111\u1EC3 ti\u1EBFp t\u1EE5c s\u1EED d\u1EE5ng."]}),!t&&o&&(0,
|
|
88
|
+
})(); true;`,Si=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Bt=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},or=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:d,isActive:u,playBeep:w})=>{var T,_,q,J,ce,Le,ge,R;let p=s==null?void 0:s.handlers,f={app_id:c,instance_id:l,close:a},L=()=>{var y;(y=s==null?void 0:s.haptic)==null||y.call(s,"impactLight"),w==null||w()},k=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let y=no(t);return yt(e,()=>oo(y,u))}case"speech.start":{if(!d)throw k();let y={};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");y.lang=t.lang}for(let z of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[z])!==void 0){if(typeof t[z]!="boolean")throw new g("INVALID_PARAMS",`${z} ph\u1EA3i l\xE0 boolean`);y[z]=t[z]}if((t==null?void 0:t.mode)!==void 0&&t.mode!=="s2t"&&t.mode!=="voice")throw new g("INVALID_PARAMS","mode ph\u1EA3i l\xE0 's2t' ho\u1EB7c 'voice'");let I=(t==null?void 0:t.mode)==="s2t"?"s2t":"voice",P=I==="voice"?(T=s==null?void 0:s.voice)!=null?T:s==null?void 0:s.speech:void 0;if(Eo(l,P),P){xo(l,P);try{return await P.start({owner:l,app_id:c,mode:I,options:y,emit:d,isActive:u!=null?u:(()=>!0)})}catch(z){throw Co(l,P),z}}return Ro(l,y,d,u)}case"speech.stop":{let y=Po(l);return y?y.stop(l):ko(l)}case et.scan:return Vo(l,bn(t),u,L);case et.start:{if(!d)throw k();return Uo(l,bn(t),d,u,L)}case et.stop:return Bo(l);case"uploadFiles":{let{task_id:y,...I}=t!=null?t:{};if(y!==void 0&&(typeof y!="string"||!y))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return _o(uo(I),{instance_id:l,app_id:c,getContext:r,task_id:y,config:s==null?void 0:s.upload,emit:d,exclusivePick:P=>yt("uploadFiles.pick",P)})}case"uploadFiles.cancel":Ao(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return wo(s==null?void 0:s.upload);case"getBiometricAvailability":return((_=s==null?void 0:s.biometrics)!=null?_:await dn()).getAvailability();case"authenticateBiometric":{let y=Bt(t==null?void 0:t.reason,"reason").trim();if(!y||y.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let I=t==null?void 0:t.cancelButtonText;if(I!==void 0&&(typeof I!="string"||!I.trim()||I.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return yt(e,async()=>{var z;return((z=s==null?void 0:s.biometrics)!=null?z:await dn()).authenticate({reason:y,cancelButtonText:I})})}case"requestPayment":{let y=p==null?void 0:p.requestPayment;if(!y)throw k();let I=t==null?void 0:t.amount;if(typeof I!="number"||!Number.isFinite(I)||I<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let P={...t,amount:I,currency:Bt(t==null?void 0:t.currency,"currency")};return yt(e,()=>y(P,f))}case"printImage":{let y=p==null?void 0:p.printImage;if(!y)throw k();let I=Bt(t==null?void 0:t.image,"image");await yt(e,()=>y({image:I},f));return}case"openScreen":if(!(p!=null&&p.openScreen))throw k();await p.openScreen({screen:Bt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},f);return;case"closeApp":a();return;case"openWebview":{let y=String((q=t==null?void 0:t.url)!=null?q:"");if(!/^https?:\/\//i.test(y))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(y):wt.Linking.openURL(y));return}case"openLink":{let y=String((J=t==null?void 0:t.url)!=null?J:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(y)||/^(javascript|file|data|about|blob):/i.test(y))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(y):wt.Linking.openURL(y))}catch(I){throw new g("NOT_SUPPORTED",String((Le=(ce=I==null?void 0:I.message)!=null?ce:I)!=null?Le:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let y=Mo(t);if(!y||(u==null?void 0:u())===!1)return;s!=null&&s.showToast?s.showToast(y.message,{type:y.type}):vo(y.message,y.type);return}case"haptic":{let y=Si.has(t==null?void 0:t.type)?t.type:"selection";(ge=s==null?void 0:s.haptic)==null||ge.call(s,y);return}case"getSystemInfo":return{platform:wt.Platform.OS==="ios"?"ios":"android",appVersion:(R=s==null?void 0:s.app_version)!=null?R:"",theme:i?"dark":"light"};case"getAccessToken":{let y=n().access_token;if(!y)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return y}case"getToken":{let y=t==null?void 0:t.type;if(y==="access"){let z=n().access_token;if(!z)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return z}if(y!=="partner"&&y!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(y)}`);let I=er[y];if(!o().includes(I))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${I} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let P=y==="partner"?n().partner_token:n().chatbox_token;if(!P)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${I}`);return P}case"getUserInfo":{let y=n().user;if(!y)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return y}case"getPageInfo":{let y=n().page;if(!y)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return y}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}`,Pn=()=>`${F().file_system.document_dir}/miniapps`,Tn=Pn,Rn=(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}},Cn=e=>{var t;F().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:[]}))},Mi=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,$=e=>{let t=F().storage.getString(En(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return Rn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},De=e=>F().file_system.exists(e.entry_uri.replace("file://","")),kn=async e=>{let t=$(e.app_id);return(t==null?void 0:t.version)===e.version&&await De(t)},ir=async(e,t)=>{let n=F().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(()=>{})))},sr=async e=>{var t;await((t=_t[e])==null?void 0:t.catch(()=>{})),F().storage.setString(En(e),""),await F().file_system.remove(`${Tn()}/${e}`).catch(()=>{})},nt=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},_t={},ar=(e,t)=>{var i;let o=((i=_t[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return _t[e]=r,r.then(()=>{_t[e]===r&&delete _t[e]}),o},On=(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},cr=({manifest:e,zip_path:t})=>ar(e.app_id,async()=>{var i;let n=F().file_system,o=$(e.app_id);if(o&&On(o.version,e.version)>=0&&await De(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=Rn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),Cn(e),fe("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),ir(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),In=(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 nt},l=async()=>{var u;c();let s=$(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Cn(e),$(e.app_id);c();let d=o.download({url:t?Mi(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(w,p)=>{var L;let f=p>0?p:(L=e.size)!=null?L:0;f>0&&(n==null||n(Math.min(1,w/f)))}});r=d;try{let{status:w}=await d.promise;if(c(),w!==200)throw new Error(`bundle ${w}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else fe("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let p=Rn(e.app_id,e.version,e.entry,!!e.context_update,(u=e.permissions)!=null?u:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),Cn(e),ir(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(w){throw i?new nt:w}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:ar(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},At={},vi=__DEV__?0:60*1e3,rr={},lr=(e,t)=>{var o,r;let n=$(e);return n&&Date.now()-((o=rr[t])!=null?o:0)<vi?Promise.resolve(n):((r=At[e])!=null||(At[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 In(a,{base_url:t}).promise;return rr[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),$(e))).finally(()=>{At[e]=void 0})),At[e])};var $t=new Map,pr=(e,t)=>($t.set(e,t),()=>{$t.get(e)===t&&$t.delete(e)}),ur=(e,t)=>{let n=$t.get(e);return n?n(t):!1};var W=require("react"),A=require("react-native");var E=require("react/jsx-runtime"),St="#22C55E",xi="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Ci=2,Wt=18,Ei=1600,Mt=14,Pi=2e3,hr=.38,Ti=40,dr=2,Ri=8,ki=2e3,Oi=250,ot=2e3,Ii=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:Mt},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:Mt},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:Mt},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:Mt}],gr=({color:e})=>(0,E.jsx)(E.Fragment,{children:Ii.map((t,n)=>(0,E.jsx)(A.View,{style:[C.corner,t,{borderColor:e}]},n))}),zt=({style:e,children:t,...n})=>{let o=(0,W.useRef)(new A.Animated.Value(1)).current,r=i=>A.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,E.jsx)(A.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,E.jsx)(A.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},Fn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var m,S;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:d}=e,u=c===ye.top,w=(0,W.useRef)(new A.Animated.Value(0)).current,p=r.useCameraDevice("back"),f=(0,W.useRef)(new A.Animated.Value(1)).current,[L,k]=(0,W.useState)(!1),[T,_]=(0,W.useState)(1),q=(0,W.useRef)(null),[J,ce]=(0,W.useState)(()=>{let{width:M,height:H}=A.Dimensions.get("window");return{width:M,height:u?H*hr:H,window_y:0}}),Le=j(ne,M=>M.last_value),ge=j(ne,M=>M.hit_tick),R=j(ne,M=>M.scan_count),y=j(ne,M=>M.notice),I=j(ne,M=>M.is_picking),P=(0,W.useRef)(null),z=tt(),xe=z.top,ee=(0,W.useRef)(new A.Animated.Value(0)).current,U=(0,W.useRef)(new A.Animated.Value(0)).current,le=(0,W.useRef)(new A.Animated.Value(0)).current,Q=(0,W.useRef)(n);Q.current=n,(0,W.useEffect)(()=>{if(!t)return;w.setValue(J.height);let M=A.Animated.timing(w,{toValue:0,duration:Oi,easing:A.Easing.out(A.Easing.cubic),useNativeDriver:!1});return M.start(({finished:H})=>{var ue;H&&((ue=Q.current)==null||ue.call(Q))}),()=>M.stop()},[t,w]);let re=Math.round(J.width*(u?.8:.78)),pe=Math.round(u?J.height*.46:re*.78),Pe=Math.round((J.height-pe)/2),Te=Math.round((J.width-re)/2),Xe=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,W.useCallback)(M=>Sn(M),[])});(0,W.useEffect)(()=>{let M=A.BackHandler.addEventListener("hardwareBackPress",()=>(_n(),!0));return()=>M.remove()},[]);let Re=(0,W.useRef)(ge);(0,W.useEffect)(()=>{if(ge===Re.current)return;ee.setValue(1),le.setValue(1);let M=A.Animated.parallel([A.Animated.timing(ee,{toValue:0,duration:450,useNativeDriver:!0}),A.Animated.sequence([A.Animated.delay(Pi),A.Animated.timing(le,{toValue:0,duration:250,useNativeDriver:!0})])]);return M.start(),()=>M.stop()},[ge,ee,le]),(0,W.useEffect)(()=>{let M=ue=>A.Animated.timing(U,{toValue:ue,duration:Ei,easing:A.Easing.inOut(A.Easing.quad),useNativeDriver:!0}),H=A.Animated.loop(A.Animated.sequence([M(1),M(0)]));return H.start(),()=>H.stop()},[U]);let Fe=(0,W.useCallback)(()=>{A.Animated.timing(f,{toValue:0,duration:220,useNativeDriver:!0}).start()},[f]);(0,W.useEffect)(()=>{let M=setTimeout(Fe,ki);return()=>clearTimeout(M)},[Fe]);let[ct,cn]=(0,W.useState)(!1);(0,W.useEffect)(()=>{let M=requestAnimationFrame(()=>{M=requestAnimationFrame(()=>cn(!0))});return()=>cancelAnimationFrame(M)},[]);let He=!!(p!=null&&p.hasTorch),lt=(m=p==null?void 0:p.neutralZoom)!=null?m:1,pt=p?Math.min(p.maxZoom/lt,Ri):1,ln=lt*Math.min(T,pt),Pt=M=>{var de;let{touches:H}=M.nativeEvent;if(H.length!==2){q.current=null;return}let ue=Math.hypot(H[0].pageX-H[1].pageX,H[0].pageY-H[1].pageY);(de=q.current)!=null||(q.current={distance:ue,level:T}),_(Math.max(1,Math.min(pt,q.current.level*(ue/q.current.distance))))},Tt=(0,E.jsx)(A.Text,{style:[C.hint,!!y&&C.hint_notice],numberOfLines:1,children:(S=y!=null?y:l)!=null?S:xi});return(0,E.jsx)(A.Animated.View,{ref:P,onTouchMove:Pt,onTouchEnd:()=>{q.current=null},pointerEvents:t?"none":"auto",style:u?[C.top,d&&C.top_absolute,t&&{height:w}]:C.full,onLayout:({nativeEvent:{layout:M}})=>{var H;t||(o==null||o(M.height),(H=P.current)==null||H.measureInWindow((ue,de)=>{ce({width:M.width,height:M.height,window_y:de||0})}))},children:(0,E.jsxs)(A.View,{style:t?[C.content_closing,{height:J.height}]:C.content,children:[p&&ct&&(0,E.jsx)(r.Camera,{style:A.StyleSheet.absoluteFill,device:p,isActive:!I,codeScanner:Xe,torch:L&&He?"on":"off",zoom:ln,onPreviewStarted:Fe,onError:M=>qo(M.message)}),(0,E.jsx)(A.Animated.View,{style:[C.preview_cover,{opacity:f}],pointerEvents:"none"}),J.height>0&&(0,E.jsxs)(A.View,{style:C.overlay,pointerEvents:"none",children:[(0,E.jsx)(A.View,{style:[C.dim_ring,{top:Pe-ot,left:Te-ot,width:re+ot*2,height:pe+ot*2}]}),(0,E.jsxs)(A.View,{style:{position:"absolute",top:Pe,left:Te,width:re,height:pe},children:[(0,E.jsx)(gr,{color:"#FFFFFF"}),(0,E.jsx)(A.Animated.View,{style:[A.StyleSheet.absoluteFill,{opacity:ee}],children:(0,E.jsx)(gr,{color:St})}),(0,E.jsxs)(A.Animated.View,{style:[C.scan_line_wrap,{transform:[{translateY:U.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,pe-Wt)]})}]}],children:[(0,E.jsx)(A.View,{style:C.scan_glow_outer}),(0,E.jsx)(A.View,{style:C.scan_glow_inner}),(0,E.jsx)(A.View,{style:C.scan_line})]})]}),(0,E.jsx)(A.View,{style:[C.hint_slot,u?{top:0,height:Pe-6,justifyContent:"flex-end"}:{top:Pe+pe+20}],children:Tt}),a===qe.continuous&&!!Le&&(0,E.jsx)(A.Animated.View,{style:[C.result_slot,{top:u?Pe+pe-Ti:Pe+pe+52},{opacity:le}],children:(0,E.jsxs)(A.View,{style:C.result,children:[(0,E.jsx)(A.View,{style:C.check_badge,children:(0,E.jsx)(A.View,{style:C.check_mark})}),(0,E.jsx)(A.Text,{style:C.result_text,numberOfLines:1,children:Le}),(0,E.jsxs)(A.Text,{style:C.result_count,children:["\xB7 ",R," m\xE3"]})]})})]}),J.height>0&&(0,E.jsx)(A.View,{style:[C.close_slot,u?C.close_slot_top:{top:Math.max(12,xe-J.window_y+12)}],children:(0,E.jsxs)(zt,{style:[C.close_button,!!s&&C.glass_surface],onPress:_n,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,E.jsx)(s,{style:C.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,E.jsx)(A.View,{style:[C.close_bar,C.close_bar_a]}),(0,E.jsx)(A.View,{style:[C.close_bar,C.close_bar_b]})]})}),(0,E.jsx)(A.View,{style:[C.toolbar_wrap,!u&&{bottom:z.bottom+20}],pointerEvents:"box-none",children:(0,E.jsxs)(A.View,{style:[C.toolbar,!!s&&C.glass_surface],children:[s&&(0,E.jsx)(s,{style:C.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,E.jsx)(zt,{style:C.tool,onPress:$o,disabled:I,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,E.jsxs)(A.View,{style:C.image_icon,children:[(0,E.jsx)(A.View,{style:C.image_icon_dot}),(0,E.jsx)(A.View,{style:C.image_icon_hill})]})}),!!p&&pt>=dr&&(0,E.jsx)(zt,{style:[C.tool,T>1&&C.tool_on],onPress:()=>_(M=>M>1?1:dr),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,E.jsxs)(A.Text,{style:[C.zoom_text,T>1&&C.zoom_text_on],children:[Math.round(T*10)/10,"x"]})}),He&&(0,E.jsx)(zt,{style:[C.tool,L&&C.tool_on],onPress:()=>k(M=>!M),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:L},children:(0,E.jsx)(A.Text,{style:[C.torch_icon,L&&C.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},Li="rgba(0,0,0,0.5)",Ln=50,C=A.StyleSheet.create({top:{height:`${hr*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:ot,borderColor:Li,borderRadius:ot+Mt},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:Wt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Wt,borderRadius:Wt/2,backgroundColor:St,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:St,opacity:.2},scan_line:{height:Ci,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:Ln,height:Ln,borderRadius:Ln/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 Me=require("react"),O=require("react-native");var X=require("react/jsx-runtime"),Dn={[Ae.info]:"#3B82F6",[Ae.success]:"#22C55E",[Ae.error]:"#EF4444"},fr=-120,Ht=O.Platform.OS==="android",mr=({type:e})=>e===Ae.success?(0,X.jsx)(O.View,{style:se.check_mark}):e===Ae.error?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O.View,{style:[se.cross_bar,se.cross_a]}),(0,X.jsx)(O.View,{style:[se.cross_bar,se.cross_b]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O.View,{style:se.info_dot}),(0,X.jsx)(O.View,{style:se.info_bar})]}),yr=()=>{let e=j(ft,w=>w.message),t=j(ft,w=>w.type),n=j(ft,w=>w.tick),o=(0,Me.useRef)(new O.Animated.Value(fr)).current,r=(0,Me.useRef)(new O.Animated.Value(0)).current,i=(0,Me.useRef)(new O.Animated.Value(.92)).current,a=(0,Me.useRef)(new O.Animated.Value(0)).current,[c,l]=(0,Me.useState)(),[s,d]=(0,Me.useState)(!1);(0,Me.useEffect)(()=>{let w=!0;return mt().then(p=>{w&&p&&l(()=>p)}),()=>{w=!1}},[]);let u=(0,Me.useRef)(n);return(0,Me.useEffect)(()=>{if(n===u.current)return;O.AccessibilityInfo.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let w=O.Animated.sequence([O.Animated.parallel([O.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),O.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),O.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),O.Animated.sequence([O.Animated.delay(90),O.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),O.Animated.delay(So[t]),O.Animated.parallel([O.Animated.timing(o,{toValue:fr,duration:240,useNativeDriver:!0}),O.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return w.start(({finished:p})=>{p&&d(!1)}),()=>w.stop()},[n]),s?(0,X.jsx)(O.View,{style:[se.layer,{top:tt().top+(Ht?12:8)}],pointerEvents:"none",children:(0,X.jsxs)(O.Animated.View,{style:[se.toast,Ht&&se.toast_android,!!c&&se.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,X.jsx)(c,{style:se.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Ht?(0,X.jsx)(O.Animated.View,{style:[se.badge_halo,{backgroundColor:`${Dn[t]}33`,transform:[{scale:a}]}],children:(0,X.jsx)(O.View,{style:[se.badge,{backgroundColor:Dn[t]}],children:(0,X.jsx)(mr,{type:t})})}):(0,X.jsx)(O.Animated.View,{style:[se.badge,{backgroundColor:Dn[t],transform:[{scale:a}]}],children:(0,X.jsx)(mr,{type:t})}),(0,X.jsx)(O.Text,{style:[se.message,Ht&&se.message_android],numberOfLines:2,children:e})]})}):null},se=O.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:O.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:{}}),wr=({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,d={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},u=Object.keys(d);return a&&a>0&&u.length>a&&u.filter(w=>w!==s).sort((w,p)=>d[w].last_used_at-d[p].last_used_at).slice(0,u.length-a).forEach(w=>{delete d[w]}),i?{active_key:s,instances:d}:{instances:d}})},br=e=>wr(e,!0),Ar=e=>wr(e,!1),rt=()=>ae.setState({active_key:null}),jt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var _r="catalog",Fi="paused_apps",Di="removed_apps",Ni=10*1e3,Vi=2,Ui=3e3,Bi=()=>{var e;try{return JSON.parse((e=F().storage.getString(_r))!=null?e:"{}")}catch{return{}}},N=Oe({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Sr=e=>{var t;return!!((t=F().manual_update)!=null&&t.includes(e))},Kt=new Set,Mr=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{}}}},Ee=Mr(Fi),We=Mr(Di);kt(()=>{Ee.load(),We.load();let e=Bi(),t={};Object.keys(e).filter(n=>!We.has(n)).forEach(n=>{let o=$(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:Ee.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),N.setState({catalog:e,downloads:t})});var it=e=>j(N,t=>e?t.downloads[e]:void 0),vr=()=>j(N,e=>e.pause_reasons.length>0),Ce=(...e)=>fe("queue",...e),oe=[],Ne={},D=null,Gt=new Set,Ye={},Nn=new Set,Ve=e=>{Nn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Yt=e=>(Nn.add(e),()=>{Nn.delete(e)}),xr=()=>N.getState().downloads,we=(e,t)=>{let n=!!$(e),o=N.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};N.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?Ve({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ve({type:"progress",app_id:e,progress:i.progress,version:i.version})},Jt=(e,t)=>{var n;(n=Ye[e])==null||n.forEach(o=>o(t)),delete Ye[e]},qi=()=>N.getState().pause_reasons.length>0,ze=e=>{var c;if(D)return;let t=e?oe.indexOf(e):qi()?-1:oe.findIndex(l=>!Ee.has(l));if(t<0||t>=oe.length)return;let[n]=oe.splice(t,1),o=N.getState().catalog[n];if(!o){Jt(n,$(n)),ze();return}let r=Date.now();Ne[n]=((c=Ne[n])!=null?c:0)+1,we(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=In(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,we(n,{progress:s/100,version:o.version}))}});D={app_id:n,handle:a,forced:!!e},Ce("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Ce("installed",n,o.version,`${Date.now()-r}ms`),we(n,{status:"installed",progress:1,version:o.version}),Jt(n,l)}).catch(l=>{var d;if(l instanceof nt){if(Gt.has(n))return;Ce("paused",n),Ne[n]-=1,oe.unshift(n),we(n,{status:Ee.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=l==null?void 0:l.message)!=null?d:l);if(console.warn("[miniapp-queue] failed",n,s),Ne[n]<Vi){we(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var u;oe.includes(n)||(D==null?void 0:D.app_id)===n||(oe.push(n),ze((u=Ye[n])!=null&&u.length?n:void 0))},Ui);return}we(n,{status:"failed",progress:0,version:o.version,error:s}),Jt(n,$(n))}).finally(()=>{D=null;let l=oe.find(s=>{var d;return(d=Ye[s])==null?void 0:d.length});ze(l)})},Xt=(e,{front:t=!1}={})=>{if((D==null?void 0:D.app_id)===e)return;let n=oe.indexOf(e);if(n>=0){if(!t)return;oe.splice(n,1)}t?oe.unshift(e):oe.push(e)},$i=async e=>{let{host_id:t,client_token:n}=F(),o=new AbortController,r=setTimeout(()=>o.abort(),Ni);try{let i=`${Qe}/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)}},vt=null,Qt=()=>(vt!=null||(vt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(F().channels.map($i)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(N.getState().catalog).filter(l=>!o[l]);F().storage.setString(_r,JSON.stringify(o)),N.setState({catalog:o}),await Promise.all(r.map(l=>Cr(l,{by_user:!1}))),r.forEach(l=>We.delete(l));let i=Object.keys(o).filter(l=>!We.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await kn(l)){we(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=$(l.app_id);if(Sr(l.app_id)&&!Kt.has(l.app_id)&&s&&await De(s)){we(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 N.setState({updates:c}),a.forEach(l=>{Ne[l.app_id]=0,we(l.app_id,{status:Ee.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Xt(l.app_id)}),Ce("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Ve({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Ve({type:"update_available",...l})),ze(),{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),Ve({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{vt=null}})()),vt),Cr=async(e,{by_user:t})=>{var r,i,a,c;if(t&&We.add(e),Gt.has(e))return;Gt.add(e),Ee.delete(e);let n=oe.indexOf(e);n>=0&&oe.splice(n,1),(D==null?void 0:D.app_id)===e&&D.handle.cancel();let o=(c=(a=(r=N.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=$(e))==null?void 0:i.version)!=null?c:"";we(e,{status:"uninstalling",progress:0,version:o}),await sr(e),jt(e),N.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Ne[e],Gt.delete(e),Jt(e,null),Ce("uninstalled",e,t?"(user)":"(not in list)"),Ve({type:"uninstalled",app_id:e})},Er=e=>Cr(e,{by_user:!0}),Pr=e=>{let t=st(e);return t?(We.delete(e),(D==null?void 0:D.app_id)===e||oe.includes(e)||(Ne[e]=0,we(e,{status:Ee.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Xt(e),ze(),Ce("restore",e)),!0):!1},Tr=e=>{if(Ee.has(e))return;if(Ee.add(e),Ce("pause app",e),(D==null?void 0:D.app_id)===e&&!D.forced){D.handle.cancel();return}let t=N.getState().downloads[e];oe.includes(e)&&t&&we(e,{status:"paused",progress:0,version:t.version})},Rr=e=>{if(!Ee.delete(e))return;Ce("resume app",e);let t=N.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!oe.includes(e)&&st(e)&&(Ne[e]=0,Xt(e)),oe.includes(e)&&t&&we(e,{status:"queued",progress:0,version:t.version}),ze()},kr=e=>{let{pause_reasons:t}=N.getState();t.includes(e)||(N.setState({pause_reasons:[...t,e]}),Ce("pause",e),t.length===0&&Ve({type:"pause_change",paused:!0,reasons:[e]}),D&&!D.forced&&D.handle.cancel())},Or=e=>{let{pause_reasons:t}=N.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);N.setState({pause_reasons:n}),Ce("resume",e),n.length===0&&Ve({type:"pause_change",paused:!1,reasons:n}),ze()},Vn=e=>N.getState().updates[e],Zt=async e=>{var n,o;let t=Vn(e);Kt.add(e);try{let r=await xt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=st(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(N.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}}}),Ce("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),Ve({type:"update_applied",app_id:e,version:r.version}),!0)}finally{Kt.delete(e)}},Ir=()=>Object.values(N.getState().catalog).map(e=>({...e,installed:!!$(e.app_id),removed_by_user:We.has(e.app_id)})),st=e=>N.getState().catalog[e],xt=async e=>{let t=st(e);if(!t)return;if(Ee.delete(e),We.delete(e),await kn(t))return $(e);let n=$(e);if(Sr(e)&&!Kt.has(e)&&n&&await De(n))return n;let o=new Promise(r=>{var i;((i=Ye[e])!=null?i:Ye[e]=[]).push(r)});return(D==null?void 0:D.app_id)===e?D.forced=!0:(Ne[e]=0,Xt(e,{front:!0}),D&&!D.forced?D.handle.cancel():ze(e)),o};var B=require("react/jsx-runtime"),Un=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Lr=0,zi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Wi=x.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var Pt,Tt;let u=(0,x.useRef)(null),w=(0,x.useRef)(!1),p=j(ae,m=>m.instances[e]),f=p==null?void 0:p.app.app_id,L=p==null?void 0:p.app.manifest_url,k=p==null?void 0:p.context,T=p==null?void 0:p.url_params,_=j(ne,m=>{var S;return((S=m.active)==null?void 0:S.owner)===e?m.active:null}),[q,J]=(0,x.useState)(null),[ce,Le]=(0,x.useState)(_);_!==ce&&(Le(_),_?J(null):(ce==null?void 0:ce.layout)===ye.top&&J(ce));let ge=(_==null?void 0:_.layout)===ye.top?_:q,[R,y]=(0,x.useState)(()=>f?$(f):null),[I,P]=(0,x.useState)(!1),[z,xe]=(0,x.useState)(0),[ee,U]=(0,x.useState)(0),[le,Q]=(0,x.useState)(!1),re=(0,x.useRef)(null),pe=m=>{re.current&&clearTimeout(re.current),re.current=setTimeout(()=>{re.current=null,Q(!0)},m)};(0,x.useEffect)(()=>()=>{re.current&&clearTimeout(re.current)},[]),(0,x.useEffect)(()=>{if(!f||!t&&R)return;let m=!0;return P(!1),(async()=>{let S=$(f),M=S?await De(S):!1;if(!m||(y(M?de=>!de||de.version!==S.version||de.permissions.join(",")!==S.permissions.join(",")?S:de:null),__DEV__&&Date.now()-Lr>1e4&&(Lr=Date.now(),await Qt()),!m))return;let H=await xt(f),ue=H!==void 0?H:L?await lr(f,L):$(f);if(m){if(!ue){P(!0);return}y(de=>de!=null?de:ue)}})(),()=>{m=!1}},[t,f,L,z]),(0,x.useEffect)(()=>pr(e,m=>u.current?(u.current.postMessage(m),!0):!1),[e]);let Pe=j(N,m=>{let S=f?m.downloads[f]:void 0;return(S==null?void 0:S.status)==="installed"?S.version:void 0});(0,x.useEffect)(()=>{if(t||!f||!R)return;let m=$(f);if(!m||m.version===R.version)return;let S=!0;return De(m).then(M=>{!S||!M||(fe(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",R.version,"\u2192",m.version),y(m))}),()=>{S=!1}},[t,f,Pe,R==null?void 0:R.version]);let Te=j(N,m=>{var S;return f&&(S=m.apply_ticks[f])!=null?S:0});(0,x.useEffect)(()=>{if(!Te||!f)return;let m=$(f);if(!m||m.version===(R==null?void 0:R.version))return;let S=!0;return De(m).then(M=>{!S||!M||(fe(`webview:${e}`,"c\u1EADp nh\u1EADt",R==null?void 0:R.version,"\u2192",m.version),Q(!1),y(m))}),()=>{S=!1}},[Te]),(0,x.useEffect)(()=>{var M;let m=(M=F().keep_alive)==null?void 0:M.idle_close_ms;if(t||!m||m<=0)return;let S=setTimeout(()=>{jt(e)},m);return()=>clearTimeout(S)},[t,e]),(0,x.useEffect)(()=>{r>0&&(P(!1),Q(!1),U(m=>m+1),xe(m=>m+1))},[r]);let Xe=(0,x.useRef)(t);(0,x.useEffect)(()=>{var m;Xe.current!==t&&(Xe.current=t,w.current&&((m=u.current)==null||m.injectJavaScript(Yo(t?"resumed":"paused"))))},[t]);let Re=`${(Pt=R==null?void 0:R.version)!=null?Pt:"none"}:${(Tt=R==null?void 0:R.permissions.join(","))!=null?Tt:""}:${ee}`,Fe=(0,x.useMemo)(()=>JSON.stringify([k!=null?k:{},T!=null?T:{}]),[k,T]),ct=(0,x.useMemo)(()=>{var m;return tr(T!=null?T:{},(m=R==null?void 0:R.permissions)!=null?m:[])},[Fe,R==null?void 0:R.permissions]),cn=(0,x.useMemo)(()=>Zo(k!=null?k:{},ct)+Jo()+Ko()+(F().debug?Go():""),[ct]),He=(0,x.useRef)(null),lt=(0,x.useRef)(null);(0,x.useEffect)(()=>{var S,M,H;if(!R)return;if(lt.current!==Re){lt.current=Re,He.current=Fe;return}if(He.current===Fe)return;let m=((M=JSON.parse((S=He.current)!=null?S:"[]")[0])!=null?M:{}).org_id;if(He.current=Fe,m===(k==null?void 0:k.org_id)&&w.current){Q(!1),pe(1500),(H=u.current)==null||H.injectJavaScript(Xo(k!=null?k:{},ct));return}Q(!1),U(ue=>ue+1)},[Fe,R,Re]),(0,x.useEffect)(()=>(t||(Ie(e),$e(e),Ge(e)),()=>{Ie(e),$e(e),Ge(e)}),[t,e,Re,r]),(0,x.useEffect)(()=>{let m=V.AppState.addEventListener("change",S=>{S==="background"&&!To()&&Ie(e),S==="background"&&!Fo()&&$e(e)});return()=>m.remove()},[e]);let pt=(0,x.useCallback)(async m=>{var M,H,ue,de,pn,Kn;let S=zo(m.nativeEvent.data);if(!S){if(f&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(m.nativeEvent.data,{app_id:f,instance_id:e})).catch(K=>{console.warn("[miniapp] onWebEvent l\u1ED7i",f,K)})}catch(K){console.warn("[miniapp] onWebEvent l\u1ED7i",f,K)}return}if(S.method==="log"){let{level:K,text:Z}=S;fe(`web:${e}`,K!=null?K:"log",Z!=null?Z:"");return}if(S.method==="pong"){re.current||Q(!0);return}if(S.method==="touchAtTop"){i.emit(!!S.at_top);return}if(S.method==="contextApplied"){re.current&&clearTimeout(re.current),re.current=null,Q(!0);return}if(S.method==="ready"){w.current=!0,Q(!0);let K=(M=ae.getState().instances[e])==null?void 0:M.context;K&&((H=u.current)==null||H.injectJavaScript(vn(K)));return}try{let K=await or(S,{getHostData:()=>{var Z,be;return(be=(Z=ae.getState().instances[e])==null?void 0:Z.host_data)!=null?be:{}},getPermissions:()=>{var Z,be;return f?(be=(Z=$(f))==null?void 0:Z.permissions)!=null?be:[]:[]},getContext:()=>{var Z,be;return(be=(Z=ae.getState().instances[e])==null?void 0:Z.context)!=null?be:{}},is_dark:o,close:rt,app_id:f!=null?f:"",instance_id:e,options:c,emit:(Z,be)=>{var Yn;(Yn=u.current)==null||Yn.injectJavaScript(jo(Z,be))},playBeep:(ue=c==null?void 0:c.playScannerBeep)!=null?ue:(()=>{var Z;(Z=u.current)==null||Z.injectJavaScript(nr())}),isActive:()=>ae.getState().active_key===e&&V.AppState.currentState!=="background"});S.id&&((de=u.current)==null||de.injectJavaScript(Wo(S.id,K)))}catch(K){if(!S.id)return;let Z=K==null?void 0:K.code,be=K instanceof g?K:new g(typeof Z=="string"?Z:"HOST_ERROR",String((pn=K==null?void 0:K.message)!=null?pn:K));(Kn=u.current)==null||Kn.injectJavaScript(Ho(S.id,be))}},[e,o,f,i,c]),ln=(0,x.useCallback)(()=>{P(!1),U(m=>m+1),xe(m=>m+1)},[]);return(0,B.jsxs)(V.View,{style:[V.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&ve.behind],pointerEvents:t?"auto":"none",children:[ge&&(0,B.jsx)(Fn,{scanner:ge,closing:ge===q,onClosed:()=>{var m;J(null),ge.absolute&&((m=u.current)==null||m.injectJavaScript(xn(0)))},onHeight:ge.absolute?m=>{var S;return(S=u.current)==null?void 0:S.injectJavaScript(xn(m))}:void 0}),R?(0,B.jsx)(Dr.default,{ref:u,source:{uri:R.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?Pn():R.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:cn,onMessage:pt,onShouldStartLoadWithRequest:m=>{let S=m.url;return m.isTopFrame===!1||!/^https?:\/\//i.test(S)?!0:(Promise.resolve(c!=null&&c.openUrl?c.openUrl(S):V.Linking.openURL(S)).catch(()=>{}),!1)},setSupportMultipleWindows:!1,bounces:!1,overScrollMode:"never",onLoadStart:m=>{Ie(e),$e(e),Ge(e),fe(`webview:${e}`,"load start",Un(m.nativeEvent.url)),w.current=!1,Q(!1)},onError:m=>{Ie(e),$e(e),Ge(e),fe(`webview:${e}`,"load error",Un(m.nativeEvent.url),m.nativeEvent.description),P(!0),Q(!1)},onLoadEnd:m=>{let S=m.nativeEvent.url;fe(`webview:${e}`,"load end",Un(S)),f&&(d==null||d({app_id:f,instance_id:e,url:S})),pe(1500)},onContentProcessDidTerminate:()=>{Ie(e),$e(e),Ge(e),w.current=!1,Q(!1),U(m=>m+1)},onRenderProcessGone:()=>(Ie(e),$e(e),Ge(e),w.current=!1,Q(!1),U(m=>m+1),!0),style:ve.webview},Re):null,(_==null?void 0:_.layout)===ye.full&&(0,B.jsx)(Fn,{scanner:_}),p&&(0,B.jsx)(ji,{visible:!R||!le,interactive:I,children:(0,B.jsx)(Hi,{splash:a,app:p.app,is_dark:o,error:I,has_bundle:!!R,retry:ln})})]})}),Hi=x.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=it(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,B.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),ji=({visible:e,interactive:t,children:n})=>{let o=(0,x.useRef)(new V.Animated.Value(e?1:0)).current,[r,i]=(0,x.useState)(e);return(0,x.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=V.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,B.jsx)(V.Animated.View,{style:[V.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},Bn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,B.jsxs)(V.View,{style:[ve.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,B.jsx)(V.View,{style:[ve.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,B.jsx)(V.Image,{source:{uri:e.icon},style:ve.splash_icon_image}):(0,B.jsx)(V.Text,{style:ve.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,B.jsx)(V.Text,{style:[ve.splash_name,{color:i}],children:e.name}),n==="error"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(V.Text,{style:ve.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,B.jsx)(V.TouchableOpacity,{activeOpacity:.7,style:[ve.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,B.jsx)(V.Text,{style:[ve.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(V.ActivityIndicator,{style:ve.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,B.jsxs)(V.Text,{style:ve.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},Fr=(e,t)=>{let n=(0,x.useRef)(t),o=(0,x.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.`))},Gi=({container:e,splash:t=Bn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{Fr("container",e),Fr("splash",t);let l=e,s=j(ae,_=>_.active_key),d=(0,x.useRef)(s);s&&(d.current=s);let u=j(ae,_=>Object.keys(_.instances).join("|")),w=j(ae,_=>{var q;return _.active_key?(q=_.instances[_.active_key])==null?void 0:q.app.name:void 0}),p=(0,x.useMemo)(()=>u?u.split("|"):[],[u]),[f,L]=(0,x.useState)({}),k=(0,x.useRef)(zi()).current;(0,x.useEffect)(()=>{if(!s||!r)return;let _=V.BackHandler.addEventListener("hardwareBackPress",()=>(rt(),!0));return()=>_.remove()},[s,r]);let T=(0,x.useCallback)(()=>{let _=ae.getState().active_key;_&&L(q=>({...q,[_]:(q[_]||0)+1}))},[]);return p.length?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(l,{visible:!!s,title:w!=null?w:"",is_dark:n,close:rt,reload:T,subscribeWebAtTop:k.subscribe,children:p.map(_=>(0,B.jsx)(Wi,{instance_key:_,is_active:s===_,is_front:(s!=null?s:d.current)===_,is_dark:n,reload_tick:f[_]||0,web_at_top:k,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},_))}),(0,B.jsx)(yr,{})]}):null},ve=V.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"}}),Nr=x.default.memo(Gi);var Ue=require("react");var Ur=e=>`changelog_seen:${e}`,Ji=10*1e3,tn=e=>F().storage.getString(Ur(e))||null,at=(e,t=(n=>(n=$(e))==null?void 0:n.version)())=>{t&&F().storage.setString(Ur(e),t)},$n=e=>{var o;let t=(o=$(e))==null?void 0:o.version;if(!t)return null;let n=tn(e);return n?On(t,n)>0?{app_id:e,from:n,to:t}:null:(at(e,t),null)},Ki=e=>{var t,n,o;return(o=(n=(t=N.getState().catalog[e])==null?void 0:t.channel)!=null?n:F().channels[0])!=null?o:"production"},nn=async(e,{from:t,to:n,channel:o=Ki(e)}={})=>{let{client_token:r}=F(),i=new URLSearchParams({channel:o});t&&i.set("from",t),n&&i.set("to",n);let a=new AbortController,c=setTimeout(()=>a.abort(),Ji);try{let l=await fetch(`${Qe}/api/miniapps/${encodeURIComponent(e)}/changelog?${i}`,{headers:{Authorization:`Bearer ${r}`},signal:a.signal});if(!l.ok)throw new Error(`changelog ${e} ${l.status}`);return(await l.json()).versions}finally{clearTimeout(c)}},on=(e,{from:t,to:n,enabled:o=!0}={})=>{let[r,i]=(0,Ue.useState)([]),[a,c]=(0,Ue.useState)(!1),[l,s]=(0,Ue.useState)(),[d,u]=(0,Ue.useState)(0),w=(0,Ue.useCallback)(()=>u(p=>p+1),[]);return(0,Ue.useEffect)(()=>{if(!e||!o)return;let p=!0;return c(!0),s(void 0),nn(e,{from:t,to:n}).then(f=>{p&&i(f)}).catch(f=>{var L;p&&s(String((f==null?void 0:f.name)==="AbortError"?"timeout":(L=f==null?void 0:f.message)!=null?L:f))}).finally(()=>{p&&c(!1)}),()=>{p=!1}},[e,t,n,o,d]),{versions:r,loading:a,error:l,reload:w}},Ct=Oe({request:null}),qn=!1,Yi=e=>{var t,n;return(n=(t=N.getState().catalog[e])==null?void 0:t.name)!=null?n:e},en=async(e,{name:t}={})=>{if(Ct.getState().request||qn)return!1;let n=$n(e);if(!n)return!1;qn=!0;try{let o=await nn(e,{from:n.from,to:n.to});return o.length?(Ct.setState({request:{...n,name:t!=null?t:Yi(e),versions:o}}),!0):(at(e,n.to),!1)}catch(o){return fe("changelog failed",e,o),!1}finally{qn=!1}},rn=()=>{let{request:e}=Ct.getState();e&&at(e.app_id,e.to),Ct.setState({request:null})},sn=()=>j(Ct,e=>e.request),Vr=!1;kt(()=>{if(Vr)return;Vr=!0;let e=()=>F().changelog!==!1;Yt(n=>{n.type==="status_change"&&n.state.status==="installed"&&!tn(n.app_id)&&at(n.app_id,n.state.version),n.type==="update_applied"&&e()&&en(n.app_id)});let t=ae.getState().active_key;ae.subscribe(()=>{let{active_key:n,instances:o}=ae.getState();if(n===t)return;t=n;let r=n?o[n]:void 0;r&&e()&&en(r.app.app_id,{name:r.app.name})})});var me=he(require("react")),h=require("react-native");var Xi=/\*\*(.+?)\*\*|`([^`]+)`|\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,Et=e=>{var o;let t=[],n=0;for(let r of e.matchAll(Xi)){let i=(o=r.index)!=null?o:0;i>n&&t.push({type:"text",text:e.slice(n,i)}),r[1]!==void 0?t.push({type:"bold",text:r[1]}):r[2]!==void 0?t.push({type:"code",text:r[2]}):t.push({type:"link",text:r[3],url:r[4]}),n=i+r[0].length}return n<e.length&&t.push({type:"text",text:e.slice(n)}),t},Br=e=>Et(e).map(t=>t.text).join("");var b=require("react/jsx-runtime"),Y={blue:"#007AFF",track:"#E5E5EA",overlay:"rgba(0, 0, 0, 0.6)",shadow:"#000000",title:"#1A1A1A",sub_title:"#666666",error:"#D92D20",hint:"#C0C0C0",surface:"#FFFFFF",background:"#F2F2F7"},zn=[{key:"new",label:"M\u1EDBi",color:"#007AFF",bg:"#E5F1FF"},{key:"fix",label:"S\u1EEDa l\u1ED7i",color:"#C4320A",bg:"#FFF1EB"},{key:"improve",label:"C\u1EA3i thi\u1EC7n",color:"#067647",bg:"#E7F7EE"}],Wn=e=>({new:e.flatMap(t=>t.changelog.new),fix:e.flatMap(t=>t.changelog.fix),improve:e.flatMap(t=>t.changelog.improve)}),Qi=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?"":t.toLocaleDateString("vi-VN")},Hn=({text:e,style:t})=>(0,b.jsx)(h.Text,{style:t,children:Et(e).map((n,o)=>{switch(n.type){case"bold":return(0,b.jsx)(h.Text,{style:v.md_bold,children:n.text},o);case"code":return(0,b.jsx)(h.Text,{style:v.md_code,children:n.text},o);case"link":return(0,b.jsx)(h.Text,{style:v.md_link,accessibilityRole:"link",onPress:()=>{h.Linking.openURL(n.url).catch(()=>{})},children:n.text},o);default:return n.text}})}),an=({changelog:e})=>(0,b.jsx)(h.View,{style:v.groups,children:zn.filter(t=>e[t.key].length).map(t=>(0,b.jsxs)(h.View,{style:v.group,children:[(0,b.jsx)(h.View,{style:[v.badge,{backgroundColor:t.bg}],children:(0,b.jsx)(h.Text,{style:[v.badge_text,{color:t.color}],children:t.label})}),e[t.key].map((n,o)=>(0,b.jsxs)(h.View,{style:v.item,children:[(0,b.jsx)(h.Text,{style:[v.bullet,{color:t.color}],children:"\u2022"}),(0,b.jsx)(Hn,{text:n,style:v.item_text})]},o))]},t.key))}),Zi=()=>{let[e,t]=(0,me.useState)();return(0,me.useEffect)(()=>{let n=!0;return mt().then(o=>{n&&o&&t(()=>o)}),()=>{n=!1}},[]),e},es=({onPress:e,size:t,GlassView:n})=>(0,b.jsxs)(h.Pressable,{onPress:e,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"Quay l\u1EA1i",style:({pressed:o})=>[v.back_btn,{width:t,height:t,borderRadius:t/2},!n&&v.back_btn_fallback,o&&v.pressed],children:[n&&(0,b.jsx)(n,{style:[h.StyleSheet.absoluteFill,{borderRadius:t/2}],glassEffectStyle:"regular",colorScheme:"light",isInteractive:!0}),(0,b.jsx)(h.View,{style:v.chevron})]}),jn=({app_id:e,name:t,onBack:n})=>{let o=tt(),r=Zi(),i=r?46:42,a=o.top+i+10,{versions:c,loading:l,error:s,reload:d}=on(e);return(0,b.jsxs)(h.View,{style:v.history,children:[l&&!c.length?(0,b.jsx)(h.ActivityIndicator,{style:[v.loading,{marginTop:a+40}],color:Y.blue}):s&&!c.length?(0,b.jsxs)(h.View,{style:[v.center,{marginTop:a+40}],children:[(0,b.jsx)(h.Text,{style:v.sub_title,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c l\u1ECBch s\u1EED c\u1EADp nh\u1EADt."}),(0,b.jsx)(h.TouchableOpacity,{onPress:d,children:(0,b.jsx)(h.Text,{style:v.link,children:"Th\u1EED l\u1EA1i"})})]}):(0,b.jsxs)(h.ScrollView,{contentContainerStyle:[v.history_list,{paddingTop:a+8,paddingBottom:o.bottom+24}],scrollIndicatorInsets:{top:a},children:[c.map(u=>(0,b.jsxs)(h.View,{style:v.card,children:[(0,b.jsxs)(h.View,{style:v.card_head,children:[(0,b.jsxs)(h.Text,{style:v.version,children:["v",u.version]}),(0,b.jsx)(h.Text,{style:v.date,children:Qi(u.created_at)})]}),(0,b.jsx)(an,{changelog:u.changelog})]},u.version)),!c.length&&(0,b.jsx)(h.Text,{style:[v.sub_title,v.empty],children:"Ch\u01B0a c\xF3 ghi ch\xFA c\u1EADp nh\u1EADt."})]}),(0,b.jsxs)(h.View,{pointerEvents:"box-none",style:[v.float_header,{paddingTop:o.top}],children:[(0,b.jsx)(h.View,{pointerEvents:"none",style:[h.StyleSheet.absoluteFill,{height:a+24}],children:ts.map((u,w)=>(0,b.jsx)(h.View,{style:{height:w===0?a-12:9,backgroundColor:Y.background,opacity:u}},w))}),(0,b.jsxs)(h.View,{style:v.header_row,children:[(0,b.jsx)(es,{onPress:n,size:i,GlassView:r}),(0,b.jsxs)(h.View,{pointerEvents:"none",style:[v.header_title,{left:i+24,right:i+24}],children:[(0,b.jsx)(h.Text,{style:v.history_title,numberOfLines:1,children:"L\u1ECBch s\u1EED c\u1EADp nh\u1EADt"}),(0,b.jsx)(h.Text,{style:v.history_sub,numberOfLines:1,children:t})]})]})]})]})},ts=[.96,.8,.55,.3,.1],Gn=({request:e,changelog:t,onClose:n})=>{let[o,r]=(0,me.useState)(!1);return(0,b.jsx)(h.Modal,{visible:!0,transparent:!o,animationType:o?"slide":"fade",statusBarTranslucent:!0,onRequestClose:o?()=>r(!1):n,children:o?(0,b.jsx)(jn,{app_id:e.app_id,name:e.name,onBack:()=>r(!1)}):(0,b.jsxs)(h.View,{style:v.overlay,children:[(0,b.jsx)(h.Pressable,{style:h.StyleSheet.absoluteFill,onPress:n,accessibilityLabel:"\u0110\xF3ng"}),(0,b.jsxs)(h.View,{style:v.sheet,children:[(0,b.jsx)(h.Text,{style:v.title,children:"C\xF3 g\xEC m\u1EDBi"}),(0,b.jsx)(h.Text,{style:v.sub_title,children:`${e.name} \xB7 v${e.from} \u2192 v${e.to}`}),(0,b.jsx)(h.ScrollView,{style:v.scroll,contentContainerStyle:v.scroll_content,showsVerticalScrollIndicator:!0,children:(0,b.jsx)(an,{changelog:t})}),(0,b.jsx)(h.TouchableOpacity,{style:v.btn_primary,activeOpacity:.8,onPress:n,children:(0,b.jsx)(h.Text,{style:v.btn_primary_text,children:"\u0110\xE3 hi\u1EC3u"})}),(0,b.jsx)(h.TouchableOpacity,{style:v.btn_secondary,onPress:()=>r(!0),children:(0,b.jsx)(h.Text,{style:v.link,children:"Xem t\u1EA5t c\u1EA3 c\u1EADp nh\u1EADt"})})]})]})})},Jn=({update:e,is_updating:t,progress:n,has_failed:o,onUpdate:r,logo:i})=>{let a=(0,me.useRef)(new h.Animated.Value(0)).current,c=(0,me.useRef)(new h.Animated.Value(30)).current;return(0,me.useEffect)(()=>{h.Animated.parallel([h.Animated.timing(a,{toValue:1,duration:400,useNativeDriver:!0}),h.Animated.spring(c,{toValue:0,friction:8,tension:40,useNativeDriver:!0})]).start()},[a,c]),(0,b.jsx)(h.Modal,{visible:!0,transparent:!0,animationType:"none",statusBarTranslucent:!0,onRequestClose:()=>{},children:(0,b.jsx)(h.View,{style:v.overlay,children:(0,b.jsxs)(h.Animated.View,{style:[v.container,{opacity:a,transform:[{translateY:c}]}],children:[i&&(0,b.jsx)(h.Image,{source:i,style:v.logo}),(0,b.jsx)(h.Text,{style:v.title,children:t?"\u0110ang c\u1EADp nh\u1EADt\u2026":"\u0110\xE3 c\xF3 b\u1EA3n c\u1EADp nh\u1EADt"}),!t&&(0,b.jsxs)(h.Text,{style:[v.sub_title,v.gap],children:[`Phi\xEAn b\u1EA3n ${e.next_version} \u0111\xE3 s\u1EB5n s\xE0ng (hi\u1EC7n t\u1EA1i ${e.current_version}).`,`
|
|
89
|
+
`,"Vui l\xF2ng c\u1EADp nh\u1EADt \u0111\u1EC3 ti\u1EBFp t\u1EE5c s\u1EED d\u1EE5ng."]}),!t&&o&&(0,b.jsx)(h.Text,{style:v.error_text,children:"C\u1EADp nh\u1EADt kh\xF4ng th\xE0nh c\xF4ng. Ki\u1EC3m tra k\u1EBFt n\u1ED1i m\u1EA1ng r\u1ED3i th\u1EED l\u1EA1i."}),t?(0,b.jsxs)(h.View,{style:v.progress_section,children:[(0,b.jsxs)(h.Text,{style:v.progress_text,children:[n,"%"]}),(0,b.jsx)(h.View,{style:v.progress_track,children:(0,b.jsx)(h.View,{style:[v.progress_fill,{width:`${n}%`}]})}),(0,b.jsx)(h.Text,{style:v.loading_hint,children:"Vui l\xF2ng kh\xF4ng t\u1EAFt \u1EE9ng d\u1EE5ng"})]}):(0,b.jsx)(h.TouchableOpacity,{style:[v.btn_primary,v.full],activeOpacity:.8,onPress:r,children:(0,b.jsx)(h.Text,{style:v.btn_primary_text,children:o?"Th\u1EED l\u1EA1i":"C\u1EADp nh\u1EADt ngay"})})]})})})},ns=({app_ids:e,shouldShowUpdate:t,logo:n,renderUpdate:o,renderChangelog:r})=>{var k,T;let i=j(N,_=>_.updates),c=((k=e!=null?e:F().manual_update)!=null?k:[]).map(_=>i[_]).find(_=>!!_&&(!t||t(_))),l=it(c==null?void 0:c.app_id),[s,d]=(0,me.useState)(!1),[u,w]=(0,me.useState)(!1),p=(0,me.useRef)(!1),f=sn(),L=async()=>{if(!c||p.current)return;p.current=!0,d(!0),w(!1);let _=await Zt(c.app_id);p.current=!1,d(!1),w(!_)};if(c){let _=(l==null?void 0:l.status)==="updating"?Math.round(((T=l.progress)!=null?T:0)*100):0,q={update:c,is_updating:s,progress:_,has_failed:u,onUpdate:L};return(0,b.jsx)(b.Fragment,{children:o?o(q):(0,b.jsx)(Jn,{...q,logo:n})})}if(f){let _={request:f,changelog:Wn(f.versions),onClose:rn};return(0,b.jsx)(b.Fragment,{children:r?r(_):(0,b.jsx)(Gn,{..._})})}return null},qr=h.Platform.select({ios:{shadowColor:Y.shadow,shadowOffset:{width:0,height:10},shadowOpacity:.1,shadowRadius:20},android:{elevation:10}}),v=h.StyleSheet.create({overlay:{flex:1,backgroundColor:Y.overlay,justifyContent:"center",alignItems:"center"},container:{width:"85%",maxWidth:340,backgroundColor:Y.surface,padding:24,borderRadius:28,alignItems:"center",...qr},sheet:{width:"88%",maxWidth:380,maxHeight:"80%",backgroundColor:Y.surface,borderRadius:24,padding:22,...qr},logo:{width:64,height:64,borderRadius:16,marginBottom:20},title:{fontSize:20,fontWeight:"700",color:Y.title,textAlign:"center"},sub_title:{fontSize:13,color:Y.sub_title,textAlign:"center",lineHeight:18,marginTop:6},gap:{marginBottom:15},error_text:{fontSize:12,textAlign:"center",color:Y.error,lineHeight:17,marginBottom:15},progress_section:{width:"100%",alignItems:"center",paddingVertical:8,marginTop:8,gap:12},progress_text:{fontSize:18,fontWeight:"700",color:Y.blue},progress_track:{width:"100%",height:6,borderRadius:3,backgroundColor:Y.track,overflow:"hidden"},progress_fill:{height:"100%",borderRadius:3,backgroundColor:Y.blue},loading_hint:{fontSize:12,color:Y.hint,textAlign:"center"},scroll:{marginTop:16,flexGrow:0,flexShrink:1},scroll_content:{paddingBottom:4},groups:{gap:14},group:{gap:6},badge:{alignSelf:"flex-start",paddingHorizontal:10,paddingVertical:3,borderRadius:999},badge_text:{fontSize:12,fontWeight:"700"},item:{flexDirection:"row",gap:8,paddingLeft:4},bullet:{fontSize:15,lineHeight:20},item_text:{flex:1,fontSize:15,lineHeight:20,color:Y.title},md_bold:{fontWeight:"700"},md_code:{fontFamily:h.Platform.select({ios:"Menlo",default:"monospace"}),fontSize:13,backgroundColor:"#F2F2F7",color:"#3A3A3C"},md_link:{color:Y.blue,textDecorationLine:"underline"},full:{width:"100%"},btn_primary:{marginTop:18,backgroundColor:Y.blue,paddingVertical:14,borderRadius:12,alignItems:"center"},btn_primary_text:{color:"white",fontWeight:"600",fontSize:16},btn_secondary:{paddingTop:12,alignItems:"center"},link:{color:Y.blue,fontSize:15,fontWeight:"600"},history:{flex:1,backgroundColor:Y.background},float_header:{position:"absolute",top:0,left:0,right:0},header_row:{flexDirection:"row",alignItems:"center",paddingHorizontal:16,paddingTop:2,paddingBottom:8},header_title:{position:"absolute",top:2,bottom:8,alignItems:"center",justifyContent:"center"},history_title:{fontSize:15,fontWeight:"500",color:"#1C1C1E"},history_sub:{fontSize:11,color:"#71717A",marginTop:1},back_btn:{alignItems:"center",justifyContent:"center",overflow:"hidden"},back_btn_fallback:{backgroundColor:Y.surface,borderWidth:h.StyleSheet.hairlineWidth*2,borderColor:"rgba(0, 0, 0, 0.1)"},chevron:{width:11,height:11,borderLeftWidth:2.2,borderBottomWidth:2.2,borderColor:"#1C1C1E",transform:[{rotate:"45deg"}],marginLeft:4},pressed:{opacity:.6,transform:[{scale:.94}]},history_list:{padding:16,gap:12},card:{backgroundColor:Y.surface,borderRadius:16,padding:16,gap:12},card_head:{flexDirection:"row",justifyContent:"space-between",alignItems:"baseline"},version:{fontSize:16,fontWeight:"700",color:Y.title},date:{fontSize:13,color:Y.sub_title},loading:{marginTop:40},center:{alignItems:"center",marginTop:40,gap:12},empty:{marginTop:40}}),$r=me.default.memo(ns);0&&(module.exports={CodeType,DefaultMiniAppChangelogPrompt,DefaultMiniAppSplash,DefaultMiniAppUpdatePrompt,MINIAPP_CHANGELOG_KINDS,MINIAPP_PLATFORM_URL,MiniAppChangelogGroups,MiniAppChangelogHistory,MiniAppChangelogText,MiniAppHost,MiniAppHostError,MiniAppUpdates,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,dismissMiniAppChangelog,ensureMiniApp,fetchMiniAppChangelog,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppChangelogSeen,getMiniAppStatuses,getMiniAppUpdate,getPendingChangelog,installBundledMiniApp,markMiniAppChangelogSeen,mergeMiniAppChangelog,onMiniAppEvent,openMiniApp,parseInlineMarkdown,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,showMiniAppChangelog,stripInlineMarkdown,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppChangelog,useMiniAppChangelogRequest,useMiniAppDownload,useMiniAppDownloadsPaused});
|