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