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