small-package/luci-app-openclash/root/usr/share/openclash/ui/dashboard/assets/index-a1967476.js

13 lines
55 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{j as e,c as j,f as st,r as h,p as Ne,e as Me,a as nt,b as W,d as ae,u as Z,g as Ce,h as T,i as Ae,k as ze,l as G,R as He,m as ot,n as ve,o as at,q as le,s as lt,t as Oe,v as se,w as ct,x as it,y as rt,z as dt,A as ut,B as Te,C as mt,D as ht,E as xt,F as ft,G as pt,$ as yt,H as gt,I as vt,N as wt,O as jt,J as bt,K as ye,L as Nt,M as Ct}from"./vendor-0606363c.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))a(o);new MutationObserver(o=>{for(const l of o)if(l.type==="childList")for(const c of l.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&a(c)}).observe(document,{childList:!0,subtree:!0});function n(o){const l={};return o.integrity&&(l.integrity=o.integrity),o.referrerPolicy&&(l.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?l.credentials="include":o.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function a(o){if(o.ep)return;o.ep=!0;const l=n(o);fetch(o.href,l)}})();function Y(){return navigator.userAgent==="ClashX Runtime"}let $=null;class Pt{constructor(t){this.instance=null,window.WebViewJavascriptBridge!=null&&(this.instance=window.WebViewJavascriptBridge),this.initBridge(n=>{this.instance=n,t()})}initBridge(t){if(!Y())return t==null?void 0:t(null);if(window.WebViewJavascriptBridge!=null)return t(window.WebViewJavascriptBridge);if(window.WVJBCallbacks!=null)return window.WVJBCallbacks.push(t);window.WVJBCallbacks=[t];const n=document.createElement("iframe");n.style.display="none",n.src="https://__bridge_loaded__",document.documentElement.appendChild(n),setTimeout(()=>document.documentElement.removeChild(n),0)}async callHandler(t,n){return await new Promise(a=>{var o;(o=this.instance)==null||o.callHandler(t,n,a)})}async ping(){return await this.callHandler("ping")}async readConfigString(){return await this.callHandler("readConfigString")}async getPasteboard(){return await this.callHandler("getPasteboard")}async getAPIInfo(){return await this.callHandler("apiInfo")}async setPasteboard(t){return await this.callHandler("setPasteboard",t)}async writeConfigWithString(t){return await this.callHandler("writeConfigWithString",t)}async setSystemProxy(t){return await this.callHandler("setSystemProxy",t)}async getStartAtLogin(){return await this.callHandler("getStartAtLogin")}async getProxyDelay(t){return await this.callHandler("speedTest",t)}async setStartAtLogin(t){return await this.callHandler("setStartAtLogin",t)}async isSystemProxySet(){return await this.callHandler("isSystemProxySet")}}function St(s){if($!=null){s();return}$=new Pt(s)}function V(s){const{title:t,children:n,className:a,style:o}=s;return e.jsxs("header",{className:j("header",a),style:o,children:[e.jsx("h1",{className:"md:text-xl",children:t}),e.jsx("div",{className:"flex flex-auto items-center justify-end",children:n})]})}function I(s){const{type:t,size:n=14,className:a,style:o}=s,l=j("clash-iconfont",`icon-${t}`,a),c={fontSize:n,...o},i={...s,className:l,style:c};return e.jsx("i",{...i})}function R(){}function kt(s,t){const n=[],a=[];for(const o of s)t(o)?n.push(o):a.push(o);return[n,a]}function O(s){const t=["B","KiB","MiB","GiB","TiB"],n=Math.floor(Math.log(s||1)/Math.log(1024));return`${st(s/Math.pow(1024,n),2).toFixed(2)} ${(t==null?void 0:t[n])??""}`}function Ue(s){return s.replace(/.*[/\\]/,"")}function ge(s){const{className:t,checked:n=!1,disabled:a=!1,onChange:o=R}=s,l=j("switch",{checked:n,disabled:a},t);function c(){a||o(!n)}return e.jsx("div",{className:l,onClick:c,children:e.jsx(I,{className:"switch-icon font-bold",type:"check",size:20})})}const U=h.forwardRef((s,t)=>{const{className:n,style:a,children:o}=s;return e.jsx("div",{className:j("card",n),style:a,ref:t,children:o})});function Ie(s){const{options:t,value:n,onSelect:a}=s;return e.jsx("div",{className:"button-select",children:t.map(o=>e.jsx("button",{value:o.value,className:j("button-select-options",{actived:n===o.value}),onClick:()=>a==null?void 0:a(o.value),children:o.label},o.value))})}const $t={SideBar:{Proxies:"Proxies",Overview:"Overview",Logs:"Logs",Rules:"Rules",Settings:"Setting",Connections:"Connections",Version:"Version"},Settings:{title:"Settings",labels:{startAtLogin:"Start at login",language:"language",setAsSystemProxy:"Set as system proxy",allowConnectFromLan:"Allow connect from Lan",proxyMode:"Mode",socks5ProxyPort:"Socks5 proxy port",httpProxyPort:"HTTP proxy port",mixedProxyPort:"Mixed proxy port",externalController:"External controller"},values:{cn:"中文",en:"English",global:"Global",rules:"Rules",direct:"Direct",script:"Script"},versionString:"Current ClashX is the latest version{{version}}",checkUpdate:"Check Update",externalControllerSetting:{title:"External Controller",note:"Please note that modifying this configuration will only configure Dashboard. Will not modify your Clash configuration file. Please make sure that the external controller address matches the address in the Clash configuration file, otherwise, Dashboard will not be able to connect to Clash.",host:"Host",port:"Port",secret:"Secret",addText:"Add",deleteText:"Delete",deleteErrorText:"Host not found"}},Logs:{title:"Logs",levelLabel:"Log level"},Rules:{title:"Rules",providerTitle:"Providers",providerUpdateTime:"Last updated at",ruleCount:"Rule count"},Connections:{title:"Connections",keepClosed:"Keep closed connections",total:{text:"total",upload:"upload",download:"download"},closeAll:{title:"Warning",content:"This would close all connections"},filter:{all:"All"},columns:{host:"Host",network:"Network",type:"Type",chains:"Chains",process:"Process",rule:"Rule",time:"Time",speed:"Speed",upload:"Upload",download:"Download",sourceIP:"Source IP"},info:{title:"Connection",id:"ID",host:"Host",hostEmpty:"Empty",dstIP:"IP",dstIPEmpty:"Empty",srcIP:"Source",upload:"Up",download:"Down",network:"Network",process:"Process",processPath:"Path",inbound:"Inbound",rule:"Rule",chains:"Chains",status:"Status",opening:"Open",closed:"Closed",closeConnection:"Close"}},Proxies:{title:"Proxies",editDialog:{title:"Edit Proxy",color:"Color",name:"Name",type:"Type",server:"Server",port:"Port",password:"Password",cipher:"Cipher",obfs:"Obfs","obfs-host":"Obfs-host",uuid:"UUID",alterId:"AlterId",tls:"TLS"},groupTitle:"Policy Group",providerTitle:"Providers",providerUpdateTime:"Last updated at",expandText:"Expand",collapseText:"Collapse",speedTestText:"Speed Test",breakConnectionsText:"Close connections which include the group"},Modal:{ok:"Ok",cancel:"Cancel"}},Et={SideBar:{Proxies:"代理",Overview:"总览",Logs:"日志",Rules:"规则",Settings:"设置",Connections:"连接",Version:"版本"},Settings:{title:"设置",labels:{startAtLogin:"开机时启动",language:"语言",setAsSystemProxy:"设置为系统代理",allowConnectFromLan:"允许来自局域网的连接",proxyMode:"代理模式",socks5ProxyPort:"Socks5 代理端口",httpProxyPort:"HTTP 代理端口",mixedProxyPort:"混合代理端口",externalController:"外部控制设置"},values:{cn:"中文",en:"English",global:"全局",rules:"规则",direct:"直连",script:"脚本"},versionString:"当前 ClashX 已是最新版本:{{version}}",checkUpdate:"检查更新",externalControllerSetting:{title:"编辑外部控制设置",note:"请注意,修改该配置项并不会修改你的 Clash 配置文件,请确认修改后的外部控制地址和 Clash 配置文件内的地址一致,否则会导致 Dashboard 无法连接。",host:"Host",port:"端口",secret:"密钥",addText:"添 加",deleteText:"删 除",deleteErrorText:"没有找到该 Host"}},Logs:{title:"日志",levelLabel:"日志等级"},Rules:{title:"规则",providerTitle:"规则集",providerUpdateTime:"最后更新于",ruleCount:"规则条数"},Connections:{title:"连接",keepClosed:"保留关闭连接",total:{text:"总量",upload:"上传",download:"下载"},closeAll:{title:"警告",content:"将会关闭所有连接"},filter:{all:"全部"},columns:{host:"域名",network:"网络",process:"进程",type:"类型",chains:"节点链",rule:"规则",time:"连接时间",speed:"速率",upload:"上传",download:"下载",sourceIP:"来源 IP"},info:{title:"连接信息",id:"ID",host:"域名",hostEmpty:"空",dstIP:"IP",dstIPEmpty:"空",srcIP:"来源",upload:"上传",download:"下载",network:"网络",process:"进程",processPath:"路径",inbound:"入口",rule:"规则",chains:"代理",status:"状态",opening:"连接中",closed:"已关闭",closeConnection:"关闭连接"}},Proxies:{title:"代理",editDialog:{title:"编辑代理",color:"颜色",name:"名字",type:"类型",server:"服务器",port:"端口",password:"密码",cipher:"加密方式",obfs:"Obfs","obfs-host":"Obfs-host",uuid:"UUID",alterId:"AlterId",tls:"TLS"},groupTitle:"策略组",providerTitle:"代理集",providerUpdateTime:"最后更新于",expandText:"展开",collapseText:"收起",speedTestText:"测速",breakConnectionsText:"切换时打断包含策略组的连接"},Modal:{ok:"确 定",cancel:"取 消"}},Be={en_US:$t,zh_CN:Et},Lt=Object.keys(Be);function Tt(){for(const s of window.navigator.languages){if(s.includes("zh"))return"zh_CN";if(s.includes("us"))return"en_US"}return"en_US"}function Pe(s){return h.useMemo(()=>{function n(a,o){if(typeof a=="string")s(l=>{const c=a,i=o;l[c]=i});else if(typeof a=="function"){const l=a;s(c=>l(c))}else typeof a=="object"&&s(l=>Ne(l,c=>{const i=a;for(const r of Object.keys(i)){const u=r;c[u]=i[u]}}))}return n},[s])}class Fe{constructor(t){this.EE=new Me,this.innerBuffer=[],this.url="",this.connection=null,this.config=Object.assign({bufferLength:0,retryInterval:5e3},t)}connectWebsocket(){if(!this.url)return;const t=new URL(this.url);this.connection=new WebSocket(t.toString()),this.connection.addEventListener("message",n=>{const a=JSON.parse(n.data);this.EE.emit("data",[a]),this.config.bufferLength>0&&(this.innerBuffer.push(a),this.innerBuffer.length>this.config.bufferLength&&this.innerBuffer.splice(0,this.innerBuffer.length-this.config.bufferLength))}),this.connection.addEventListener("error",n=>{var a;this.EE.emit("error",n),(a=this.connection)==null||a.close(),setTimeout(this.connectWebsocket,this.config.retryInterval)})}connect(t){var n;this.url===t&&this.connection||(this.url=t,(n=this.connection)==null||n.close(),this.connectWebsocket())}subscribe(t,n){this.EE.addListener(t,n)}unsubscribe(t,n){this.EE.removeListener(t,n)}buffer(){return this.innerBuffer.slice()}destory(){var t;this.EE.removeAllListeners(),(t=this.connection)==null||t.close(),this.connection=null}}const F="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",S="[a-fA-F\\d]{1,4}",It=`
(?:
(?:${S}:){7}(?:${S}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
(?:${S}:){6}(?:${F}|:${S}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
(?:${S}:){5}(?::${F}|(?::${S}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
(?:${S}:){4}(?:(?::${S}){0,1}:${F}|(?::${S}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
(?:${S}:){3}(?:(?::${S}){0,2}:${F}|(?::${S}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
(?:${S}:){2}(?:(?::${S}){0,3}:${F}|(?::${S}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
(?:${S}:){1}(?:(?::${S}){0,4}:${F}|(?::${S}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
(?::(?:(?::${S}){0,5}:${F}|(?::${S}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),Rt=new RegExp(`(?:^${F}$)|(?:^${It}$)`);function Dt(s){return Rt.test(s)}class Mt{constructor(t,n){this.axiosClient=nt.create({baseURL:t,headers:n?{Authorization:`Bearer ${n}`}:{}})}async getConfig(){return await this.axiosClient.get("configs")}async updateConfig(t){return await this.axiosClient.patch("configs",t)}async getRules(){return await this.axiosClient.get("rules")}async getProxyProviders(){const t=await this.axiosClient.get("providers/proxies",{validateStatus(n){return n>=200&&n<300||n===404}});return t.status===404&&(t.data={providers:{}}),t}async getRuleProviders(){return await this.axiosClient.get("providers/rules")}async updateProvider(t){return await this.axiosClient.put(`providers/proxies/${encodeURIComponent(t)}`)}async updateRuleProvider(t){return await this.axiosClient.put(`providers/rules/${encodeURIComponent(t)}`)}async healthCheckProvider(t){return await this.axiosClient.get(`providers/proxies/${encodeURIComponent(t)}/healthcheck`)}async getProxies(){return await this.axiosClient.get("proxies")}async getProxy(t){return await this.axiosClient.get(`proxies/${encodeURIComponent(t)}`)}async getVersion(){return await this.axiosClient.get("version")}async getProxyDelay(t){return await this.axiosClient.get(`proxies/${encodeURIComponent(t)}/delay`,{params:{timeout:5e3,url:"http://www.gstatic.com/generate_204"}})}async closeAllConnections(){return await this.axiosClient.delete("connections")}async closeConnection(t){return await this.axiosClient.delete(`connections/${t}`)}async getConnections(){return await this.axiosClient.get("connections")}async changeProxySelected(t,n){return await this.axiosClient.put(`proxies/${encodeURIComponent(t)}`,{name:n})}}const At=W(async()=>{if(!Y())return null;const s=await $.getAPIInfo();return{hostname:s.host,port:s.port,secret:s.secret,protocol:"http:"}});function zt(){if(!Dt(location.hostname))return null;if(location.port!=="")return JSON.stringify([{hostname:location.hostname,port:+location.port,secret:""}]);const s=location.protocol==="https:"?443:80;return JSON.stringify([{hostname:location.hostname,port:s,secret:""}])}const Ht=localStorage.getItem("externalControllers")??zt()??'[{ "hostname": "127.0.0.1", "port": 7890, "secret": "" }]',Ot=localStorage.getItem("externalControllerIndex")??"0",Se=ae("externalControllers",JSON.parse(Ht)),ke=ae("externalControllerIndex",parseInt(Ot));function ee(){var x,w,g,d;const s=Z(At),t=Ce(),n=Z(ke),a=Z(Se);if(s!=null)return s;let o;{const p=document.querySelector('meta[name="external-controller"]');((x=p==null?void 0:p.content)==null?void 0:x.match(/^https?:/))!=null&&(o=new URL(p.content))}const l=new URLSearchParams(t.search),c=l.get("host")??((w=a==null?void 0:a[n])==null?void 0:w.hostname)??(o==null?void 0:o.hostname)??"127.0.0.1",i=l.get("port")??((g=a==null?void 0:a[n])==null?void 0:g.port)??(o==null?void 0:o.port)??"9090",r=l.get("secret")??((d=a==null?void 0:a[n])==null?void 0:d.secret)??(o==null?void 0:o.username)??"",u=l.get("protocol")??c==="127.0.0.1"?"http:":(o==null?void 0:o.protocol)??window.location.protocol;return{hostname:c,port:i,secret:r,protocol:u}}const Ut=W({key:"",instance:null});function D(){const{hostname:s,port:t,secret:n,protocol:a}=ee(),[o,l]=T(Ut),c=`${a}//${s}:${t}?secret=${n}`;if(o.key===c)return o.instance;const i=new Mt(`${a}//${s}:${t}`,n);return l({key:c,instance:i}),i}const $e=W(!0),Bt=ae("language",void 0);function E(){const[s,t]=T(Bt),n=h.useMemo(()=>s??Tt(),[s]),a=h.useCallback(function(o){function l(c){return at(Be[n][o],c)}return{t:l}},[n]);return{lang:n,locales:Lt,setLang:t,translation:a}}const Ve=W({version:"",premium:!1});function _e(){const[s,t]=T(Ve),n=D(),a=ze($e);return G([n],async function(){const o=await He.fromPromise(n.getVersion(),l=>l);a(o.isOk()),t(o.isErr()?{version:"",premium:!1}:{version:o.value.data.version,premium:!!o.value.data.premium})}),s}function We(){const[{premium:s}]=T(Ve),t=D(),{data:n,mutate:a}=G(["/providers/rule",t,s],async()=>{if(!s)return[];const o=await t.getRuleProviders();return Object.keys(o.data.providers).map(l=>o.data.providers[l])});return{providers:n??[],update:a}}const Ft=ae("profile",{breakConnections:!1,logLevel:""});function ce(){const[s,t]=T(Ft),n=h.useCallback(a=>{t(Ne(s,a))},[s,t]);return{data:s,set:Pe(n)}}const Ge=W([]);function Je(){const[s,t]=T(Ge),n=D(),{data:a,mutate:o}=G(["/providers/proxy",n],async()=>{const l=await n.getProxyProviders();return Object.keys(l.data.providers).map(c=>l.data.providers[c]).filter(c=>c.name!=="default").filter(c=>c.vehicleType!=="Compatible")});return h.useEffect(()=>{t(a??[])},[a,t]),{providers:s,update:o}}function ie(){const s=D(),{data:t,mutate:n}=G(["/config",s],async()=>{const o=(await s.getConfig()).data;return{port:o.port,socksPort:o["socks-port"],mixedPort:o["mixed-port"]??0,redirPort:o["redir-port"],mode:o.mode.toLowerCase(),logLevel:o["log-level"],allowLan:o["allow-lan"]}});return{general:t??{},update:n}}const Xe=Ae({proxies:[],groups:[],global:{name:"GLOBAL",type:"Selector",now:"",history:[],all:[]}});function re(){const[s,t]=T(Xe),n=Pe(t),a=D(),{mutate:o}=G(["/proxies",a],async()=>{const c=await a.getProxies(),i=c.data.proxies.GLOBAL;i.name="GLOBAL";const r=new Set(["Selector","URLTest","Fallback","LoadBalance"]),u=new Set(["DIRECT","REJECT","GLOBAL"]),x=i.all.filter(d=>!u.has(d)).map(d=>({...c.data.proxies[d],name:d})),[w,g]=kt(x,d=>!r.has(d.type));n({proxies:w,groups:g,global:i})}),l=h.useCallback((c,i)=>{n(r=>{c==="GLOBAL"&&(r.global.now=i);for(const u of r.groups)u.name===c&&(u.now=i)})},[n]);return{proxies:s.proxies,groups:s.groups,global:s.global,update:o,markProxySelected:l,set:n}}const Vt=W(s=>{const t=s(Xe),n=s(Ge),a=new Map;for(const o of t.proxies)a.set(o.name,o);for(const o of n)for(const l of o.proxies)a.set(l.name,l);return a});function Ye(){const{data:s,mutate:t}=G("/clashx",async()=>{if(!Y())return{isClashX:!1,startAtLogin:!1,systemProxy:!1};const n=await($==null?void 0:$.getStartAtLogin())??!1,a=await($==null?void 0:$.isSystemProxySet())??!1;return{startAtLogin:n,systemProxy:a,isClashX:!0}});return{data:s,update:t}}const _t=Ae([]);function Wt(){const[s,t]=T(_t),n=Pe(t),a=D();async function o(){const l=await a.getRules();n(l.data.rules)}return{rules:s,update:o}}const Gt=W(new Fe({bufferLength:200}));function qe(){const s=ee(),{general:t}=ie(),{data:{logLevel:n}}=ce(),a=Z(Gt),o=n||t.logLevel,l=ot(`${s.protocol}//${s.hostname}:${s.port}/logs?level=${o}&secret=${encodeURIComponent(s.secret)}`),c=ve(s);return h.useEffect(()=>{if(o){const i=c.current,u=`${i.protocol==="http:"?"ws:":"wss:"}//${i.hostname}:${i.port}/logs?level=${o}&token=${encodeURIComponent(i.secret)}`;a.connect(u)}},[c,a,o,l]),a}function Jt(){const s=ee(),t=h.useRef(new Fe({bufferLength:200})),a=`${s.protocol==="http:"?"ws:":"wss:"}//${s.hostname}:${s.port}/connections?token=${encodeURIComponent(s.secret)}`;return h.useEffect(()=>{t.current.connect(a)},[a]),t.current}function Xt(s){const{className:t,data:n,onClick:a,select:o,canClick:l,errSet:c,rowHeight:i}=s,{translation:r}=E(),{t:u}=r("Proxies"),[x,w]=h.useState(!1),[g,d]=h.useState(!1),p=h.useRef(null);h.useLayoutEffect(()=>{var N;d((((N=p==null?void 0:p.current)==null?void 0:N.offsetHeight)??0)>30)},[]);const P=x?"auto":i,y=l?a:R;function C(){w(!x)}const k=n.map(N=>{const L=j({"tags-selected":o===N,"cursor-pointer":l,error:c==null?void 0:c.has(N)});return e.jsx("li",{className:L,onClick:()=>y(N),children:N},N)});return e.jsxs("div",{className:j("flex items-start overflow-y-hidden",t),style:{height:P},children:[e.jsx("ul",{ref:p,className:j("tags",{expand:x}),children:k}),g&&e.jsx("span",{className:"h-7 cursor-pointer select-none px-5 leading-7",onClick:C,children:u(x?"collapseText":"expandText")})]})}function X(s){const{className:t,style:n,value:a="",align:o="center",inside:l=!1,autoFocus:c=!1,type:i="text",disabled:r=!1,onChange:u=R,onBlur:x=R,onEnter:w=R}=s,g=j("input",`text-${o}`,{"focus:shadow-none":l},t);function d(p){p.code==="Enter"&&w(p)}return e.jsx("input",{disabled:r,className:g,style:n,value:a,autoFocus:c,type:i,onChange:p=>u(p.target.value,p),onBlur:x,onKeyDown:d})}function Ke(s){const{value:t,options:n,onSelect:a,disabled:o,className:l,style:c}=s,i=h.useRef(document.createElement("div")),r=h.useRef(null),[u,x]=h.useState(!1),[w,g]=h.useState({});h.useLayoutEffect(()=>{const y=i.current;return document.body.appendChild(y),()=>{document.body.removeChild(y)}},[]);function d(){if(!o){if(!u){const y=r.current.getBoundingClientRect();g({top:Math.floor(y.top+y.height)+6,left:Math.floor(y.left)-10})}x(!u)}}const p=h.useMemo(()=>n.find(y=>y.value===t),[t,n]),P=e.jsx("div",{className:j("select-list",{"select-list-show":u}),style:w,children:e.jsx("ul",{className:"list",children:n.map(y=>e.jsx(Yt,{className:j({selected:y.value===t}),onClick:C=>{a==null||a(y.value,C),x(!1)},disabled:y.disabled,value:y.value,children:y.label},y.key??y.value))})});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:j("select",{disabled:o},l),style:c,ref:r,onClick:d,children:[e.jsx("span",{className:"select-none",children:p==null?void 0:p.label}),e.jsx(I,{type:"triangle-down"})]}),le.createPortal(P,i.current)]})}function Yt(s){const{className:t,style:n,disabled:a=!1,children:o,onClick:l=R}=s,c=j("option",{disabled:a},t);return e.jsx("li",{className:c,style:n,onClick:l,children:o})}function Ze(s){const{show:t=!0,title:n="Modal",size:a="small",footer:o=!0,onOk:l=R,onClose:c=R,bodyClassName:i,bodyStyle:r,className:u,footerExtra:x,style:w,children:g}=s,{translation:d}=E(),{t:p}=d("Modal"),P=h.useRef(document.createElement("div")),y=h.useRef(null);h.useLayoutEffect(()=>{const N=P.current;return document.body.appendChild(N),()=>{document.body.removeChild(N)}},[]);function C(N){N.target===y.current&&c()}const k=e.jsx("div",{className:j("modal-mask",{"modal-show":t}),ref:y,onMouseDown:C,children:e.jsxs("div",{className:j("modal",`modal-${a}`,u),style:w,children:[e.jsx("div",{className:"modal-title",children:n}),e.jsx("div",{className:j("modal-body",i),style:r,children:g}),o&&e.jsxs("div",{className:"flex items-center justify-between",children:[x,e.jsxs("div",{className:"flex flex-1 justify-end space-x-3",children:[e.jsx(Q,{onClick:()=>c(),children:p("cancel")}),e.jsx(Q,{type:"primary",onClick:()=>l(),children:p("ok")})]})]})]})});return le.createPortal(k,P.current)}const qt={success:"check",info:"info",warning:"info",error:"close"};function Kt(s){const{message:t="",type:n="info",inside:a=!1,children:o,className:l,style:c}=s,i=j("alert",`alert-${a?"note":"box"}-${n}`,l);return e.jsxs("div",{className:i,style:c,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{type:qt[n],size:26})}),t?e.jsx("p",{className:"alert-message",children:t}):e.jsx("div",{className:"alert-message",children:o})]})}function Q(s){const{type:t="normal",onClick:n=R,children:a,className:o,style:l,disabled:c}=s,i=j("button",`button-${t}`,o,{"button-disabled":c});return e.jsx("button",{className:i,style:l,onClick:n,disabled:c,children:a})}function ne(s){const[t,n]=lt(s),a=h.useMemo(()=>{function o(l,c){typeof l=="string"?n(i=>{const r=l,u=c;i[r]=u}):typeof l=="function"?n(l):typeof l=="object"&&n(i=>{const r=l;for(const u of Object.keys(r)){const x=u;i[x]=r[x]}})}return o},[n]);return[t,a]}function Zt(s,t=0){if(s.length<2)throw new Error("List requires at least two elements");const[n,a]=h.useState(t);function o(){a((n+1)%s.length)}return{current:h.useMemo(()=>s[n],[s,n]),next:o}}function de(s=!1){const[t,n]=h.useState(s);function a(){n(!1)}function o(){n(!0)}return{visible:t,hide:a,show:o}}const Qt={info:"info",success:"check",warning:"info-o",error:"close"};function es(s){const{removeComponent:t=R,onClose:n=R,icon:a=e.jsx(I,{type:"info",size:16}),content:o="",type:l="info",duration:c=1500}=s,{visible:i,show:r,hide:u}=de();return h.useLayoutEffect(()=>{window.setTimeout(()=>r(),0);const x=window.setTimeout(()=>{u(),n()},c);return()=>window.clearTimeout(x)},[c,u,n,r]),e.jsxs("div",{className:j("message",`message-${l}`,{"message-show":i}),onTransitionEnd:()=>!i&&t(),children:[e.jsx("span",{className:"message-icon",children:a}),e.jsx("span",{className:"message-content",children:o})]})}function ts(s){const t=document.createElement("div");document.body.appendChild(t);const n=()=>{le.unmountComponentAtNode(t)&&document.body.removeChild(t)},a=e.jsx(I,{type:Qt[s.type],size:16}),{type:o,content:l,duration:c,onClose:i}=s,r={icon:a,type:o,content:l,removeComponent:n,duration:c,onClose:i};Oe(t).render(e.jsx(es,{...r}))}const ss=(s,t,n)=>ts({type:"error",content:s,duration:t,onClose:n});function Qe(s){const{className:t,checked:n=!1,onChange:a=R}=s,o=j("checkbox",{checked:n},t);function l(){a(!n)}return e.jsxs("div",{className:o,onClick:l,children:[e.jsx(I,{className:"checkbox-icon",type:"check",size:18}),e.jsx("div",{children:s.children})]})}function oe(s){const{color:t,className:n,style:a}=s,o=j("tag",n),l={color:t,...a},c={...s,className:o,style:l};return e.jsx("span",{...c,children:s.children})}function ns(s){const t=j("spinner",s.className);return e.jsxs("div",{className:t,children:[e.jsx("div",{className:"spinner-circle",children:e.jsx("div",{className:"spinner-inner"})}),e.jsx("div",{className:"spinner-circle",children:e.jsx("div",{className:"spinner-inner"})}),e.jsx("div",{className:"spinner-circle",children:e.jsx("div",{className:"spinner-inner"})}),e.jsx("div",{className:"spinner-circle",children:e.jsx("div",{className:"spinner-inner"})}),e.jsx("div",{className:"spinner-circle",children:e.jsx("div",{className:"spinner-inner"})})]})}function et(s){const t=j("loading","visible",s.className);return s.visible?e.jsx("div",{className:t,children:e.jsx(ns,{className:s.spinnerClassName})}):null}function os(s){var o;const t=h.useRef(document.createElement("div"));h.useLayoutEffect(()=>{const l=t.current;return document.body.appendChild(l),()=>{document.body.removeChild(l)}},[]);const n="absolute h-full right-0 transition-transform transform duration-100 pointer-events-auto",a=e.jsx("div",{className:j(s.className,"z-9999 pointer-events-none absolute inset-0"),children:e.jsx(U,{className:j(n,s.bodyClassName,{"translate-x-0":s.visible,"translate-x-full":!s.visible}),style:{width:s.width??400},children:s.children})});return le.createPortal(a,((o=s.containerRef)==null?void 0:o.current)??t.current)}se.extend(ct);function Ee(s,t){const n=t==="en_US"?"en":"zh-cn";return se(s).locale(n).from(se())}function as(s){const{translation:t}=E(),n=h.useMemo(()=>t("Connections").t,[t]),{className:a,style:o}=s,l=j("flex flex-wrap px-1",a);function c(i){var r;(r=s.onChange)==null||r.call(s,i)}return e.jsxs("div",{className:l,style:o,children:[e.jsx("div",{className:j("connections-devices-item mb-2 pt-2",{selected:s.selected===""}),onClick:()=>c(""),children:n("filter.all")}),s.devices.map(i=>e.jsxs("div",{className:j("connections-devices-item mb-2 pt-2",{selected:s.selected===i.label}),onClick:()=>c(i.label),children:[i.label," (",i.number,")"]},i.label))]})}function ls(s){var a,o,l,c,i,r,u,x,w,g,d;const{translation:t}=E(),n=h.useMemo(()=>t("Connections").t,[t]);return e.jsxs("div",{className:j(s.className,"flex flex-col overflow-y-auto text-sm"),children:[e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.id")}),e.jsx("span",{className:"font-mono",children:s.connection.id})]}),e.jsxs("div",{className:"my-3 flex justify-between",children:[e.jsxs("div",{className:"flex flex-1",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.network")}),e.jsx("span",{className:"font-mono",children:(a=s.connection.metadata)==null?void 0:a.network})]}),e.jsxs("div",{className:"flex flex-1",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.inbound")}),e.jsx("span",{className:"font-mono",children:(o=s.connection.metadata)==null?void 0:o.type})]})]}),e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.host")}),e.jsx("span",{className:"flex-1 break-all font-mono",children:(l=s.connection.metadata)!=null&&l.host?`${s.connection.metadata.host}:${(c=s.connection.metadata)==null?void 0:c.destinationPort}`:n("info.hostEmpty")})]}),e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.dstIP")}),e.jsx("span",{className:"font-mono",children:(i=s.connection.metadata)!=null&&i.destinationIP?`${s.connection.metadata.destinationIP}:${(r=s.connection.metadata)==null?void 0:r.destinationPort}`:n("info.hostEmpty")})]}),e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.srcIP")}),e.jsx("span",{className:"font-mono",children:`${(u=s.connection.metadata)==null?void 0:u.sourceIP}:${(x=s.connection.metadata)==null?void 0:x.sourcePort}`})]}),e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.process")}),e.jsx("span",{className:"flex-1 break-all font-mono",children:(w=s.connection.metadata)!=null&&w.processPath?`${Ue(s.connection.metadata.processPath)}`:n("info.hostEmpty")})]}),e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.processPath")}),e.jsx("span",{className:"flex-1 break-all font-mono",children:(g=s.connection.metadata)!=null&&g.processPath?`${s.connection.metadata.processPath}`:n("info.hostEmpty")})]}),e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.rule")}),e.jsx("span",{className:"font-mono",children:s.connection.rule&&`${s.connection.rule}${s.connection.rulePayload&&` :: ${s.connection.rulePayload}`}`})]}),e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.chains")}),e.jsx("span",{className:"flex-1 break-all font-mono",children:(d=s.connection.chains)==null?void 0:d.slice().reverse().join(" / ")})]}),e.jsxs("div",{className:"my-3 flex justify-between",children:[e.jsxs("div",{className:"flex flex-1",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.upload")}),e.jsx("span",{className:"font-mono",children:O(s.connection.upload??0)})]}),e.jsxs("div",{className:"flex flex-1",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.download")}),e.jsx("span",{className:"font-mono",children:O(s.connection.download??0)})]})]}),e.jsxs("div",{className:"my-3 flex",children:[e.jsx("span",{className:"w-20 font-bold",children:n("info.status")}),e.jsx("span",{className:"font-mono",children:s.connection.completed?e.jsx("span",{className:"text-red",children:n("info.closed")}):e.jsx("span",{className:"text-green",children:n("info.opening")})})]})]})}class cs{constructor(){this.connections=new Map,this.saveDisconnection=!1}appendToSet(t){var a;const n=t.reduce((o,l)=>o.set(l.id,l),new Map);for(const o of this.connections.keys())if(!n.has(o))if(!this.saveDisconnection)this.connections.delete(o);else{const l=this.connections.get(o);l!=null&&this.connections.set(o,Ne(l,c=>{c.completed=!0,c.uploadSpeed=0,c.downloadSpeed=0}))}for(const o of n.keys()){if(!this.connections.has(o)){this.connections.set(o,{...n.get(o),uploadSpeed:0,downloadSpeed:0});continue}const l=this.connections.get(o),c=n.get(o);(a=this.connections)==null||a.set(o,{...c,uploadSpeed:c.upload-l.upload,downloadSpeed:c.download-l.download})}}toggleSave(){var t,n;if(this.saveDisconnection){this.saveDisconnection=!1;for(const a of this.connections.keys())(n=(t=this.connections)==null?void 0:t.get(a))!=null&&n.completed&&this.connections.delete(a)}else this.saveDisconnection=!0;return this.saveDisconnection}getConnections(){return[...this.connections.values()]}}function is(){const s=h.useMemo(()=>new cs,[]),t=h.useRef(!0),[n,a]=h.useState([]),[o,l]=h.useState(!1),c=h.useCallback(function(r){s.appendToSet(r),t.current&&a(s.getConnections()),t.current=!t.current},[s]),i=h.useCallback(function(){const r=s.toggleSave();l(r),r||a(s.getConnections()),t.current=!0},[s]);return{connections:n,feed:c,toggleSave:i,save:o}}const b={Host:"host",Network:"network",Process:"process",Type:"type",Chains:"chains",Rule:"rule",Speed:"speed",Upload:"upload",Download:"download",SourceIP:"sourceIP",Time:"time"},rs=new Set([b.Network,b.Type,b.Speed,b.Upload,b.Download,b.SourceIP,b.Time,b.Process]);function ds(s,t){switch(!0){case(s===0&&t===0):return"-";case(s!==0&&t!==0):return`${O(s)}/s ↓ ${O(t)}/s`;case s!==0:return`${O(s)}/s`;default:return`${O(t)}/s`}}const A=mt();function us(){const{translation:s,lang:t}=E(),n=h.useMemo(()=>s("Connections").t,[s]),a=Jt(),o=ve(a),l=D(),c=h.useRef(null),[i,r]=ne({uploadTotal:0,downloadTotal:0}),{visible:u,show:x,hide:w}=de();function g(){l.closeAllConnections().finally(()=>w())}const{connections:d,feed:p,save:P,toggleSave:y}=is(),C=h.useMemo(()=>d.map(m=>({id:m.id,host:`${m.metadata.host||m.metadata.destinationIP}:${m.metadata.destinationPort}`,chains:m.chains.slice().reverse().join(" / "),rule:m.rulePayload?`${m.rule} :: ${m.rulePayload}`:m.rule,time:new Date(m.start).getTime(),upload:m.upload,download:m.download,sourceIP:m.metadata.sourceIP,type:m.metadata.type,network:m.metadata.network.toUpperCase(),process:m.metadata.processPath,speed:{upload:m.uploadSpeed,download:m.downloadSpeed},completed:!!m.completed,original:m})),[d]),k=h.useMemo(()=>{const m=it(d,"metadata.sourceIP");return Object.keys(m).map(f=>({label:f,number:m[f].length})).sort((f,v)=>f.label.localeCompare(v.label))},[d]),N=h.useRef(null),L=rt(N,{threshold:[1]}),J=h.useMemo(()=>[A.accessor(b.Host,{minSize:260,size:260,header:n(`columns.${b.Host}`)}),A.accessor(b.Network,{minSize:80,size:80,header:n(`columns.${b.Network}`)}),A.accessor(b.Type,{minSize:100,size:100,header:n(`columns.${b.Type}`)}),A.accessor(b.Chains,{minSize:200,size:200,header:n(`columns.${b.Chains}`)}),A.accessor(b.Rule,{minSize:140,size:140,header:n(`columns.${b.Rule}`)}),A.accessor(b.Process,{minSize:100,size:100,header:n(`columns.${b.Process}`),cell:m=>m.getValue()?Ue(m.getValue()):"-"}),A.accessor(m=>[m.speed.upload,m.speed.download],{id:b.Speed,header:n(`columns.${b.Speed}`),minSize:200,size:200,sortDescFirst:!0,sortingFn(m,f){var K,Le;const v=((K=m.original)==null?void 0:K.speed)??{upload:0,download:0},H=((Le=f.original)==null?void 0:Le.speed)??{upload:0,download:0};return v.download===H.download?v.upload-H.upload:v.download-H.download},cell:m=>ds(m.getValue()[0],m.getValue()[1])}),A.accessor(b.Upload,{minSize:100,size:100,header:n(`columns.${b.Upload}`),cell:m=>O(m.getValue())}),A.accessor(b.Download,{minSize:100,size:100,header:n(`columns.${b.Download}`),cell:m=>O(m.getValue())}),A.accessor(b.SourceIP,{minSize:140,size:140,header:n(`columns.${b.SourceIP}`),filterFn:"equals"}),A.accessor(b.Time,{minSize:120,size:120,header:n(`columns.${b.Time}`),cell:m=>Ee(new Date(m.getValue()),t),sortingFn:(m,f)=>{var v,H;return(((v=f.original)==null?void 0:v.time)??0)-(((H=m.original)==null?void 0:H.time)??0)}})],[t,n]);h.useLayoutEffect(()=>{function m(f){for(const v of f)r({uploadTotal:v.uploadTotal,downloadTotal:v.downloadTotal}),p(v.connections)}return a==null||a.subscribe("data",m),()=>{a==null||a.unsubscribe("data",m)}},[a,p,r]),dt(()=>{var m;(m=o.current)==null||m.destory()});const q=ut({data:C,columns:J,getCoreRowModel:ht(),getSortedRowModel:xt(),getFilteredRowModel:ft(),initialState:{sorting:[{id:b.Time,desc:!1}]},columnResizeMode:"onChange",enableColumnResizing:!0}),te=q.getHeaderGroups()[0],[ue,me]=h.useState("");function he(m){var f;me(m),(f=q.getColumn(b.SourceIP))==null||f.setFilterValue(m||void 0)}const[z,B]=ne({visible:!1,selectedID:"",connection:{}});function xe(){B(m=>{m.connection.completed=!0}),l.closeConnection(z.selectedID)}const _=ve(z.connection);h.useEffect(()=>{var f;const m=(f=C.find(v=>v.id===z.selectedID))==null?void 0:f.original;m?B(v=>{v.connection={...m},z.selectedID===_.current.id&&(v.connection.completed=_.current.completed)}):Object.keys(_.current).length!==0&&!_.current.completed&&B(v=>{v.connection.completed=!0})},[C,z.selectedID,_,B]);const M=h.useMemo(()=>((L==null?void 0:L.intersectionRatio)??0)<1,[L]),fe=te.headers.map((m,f)=>{const v=m.column,H=v.id;return e.jsxs("th",{className:j("connections-th",{resizing:v.getIsResizing(),fixed:v.id===b.Host,shadow:M&&v.id===b.Host}),style:{width:m.getSize()},ref:v.id===b.Host?N:void 0,children:[e.jsxs("div",{onClick:v.getToggleSortingHandler(),children:[Te(m.column.columnDef.header,m.getContext()),v.getIsSorted()!==!1?v.getIsSorted()==="desc"?" ↓":" ↑":null]}),f!==te.headers.length-1&&e.jsx("div",{onMouseDown:m.getResizeHandler(),onTouchStart:m.getResizeHandler(),className:"connections-resizer"})]},H)}),pe=q.getRowModel().rows.map(m=>{var f;return e.jsx("tr",{className:"cursor-default select-none",onClick:()=>{var v;return B({visible:!0,selectedID:(v=m.original)==null?void 0:v.id})},children:m.getAllCells().map(v=>{var K;const H=j("connections-block",{"text-center":rs.has(v.column.id),completed:(K=m.original)==null?void 0:K.completed},{fixed:v.column.id===b.Host,shadow:M&&v.column.id===b.Host});return e.jsx("td",{className:H,style:{width:v.column.getSize()},children:Te(v.column.columnDef.cell,v.getContext())},v.column.id)})},(f=m.original)==null?void 0:f.id)});return e.jsxs("div",{className:"page !h-100vh",children:[e.jsxs(V,{title:n("title"),children:[e.jsx("span",{className:"connections-filter flex-1 cursor-default",children:`(${n("total.text")}: ${n("total.upload")} ${O(i.uploadTotal)} ${n("total.download")} ${O(i.downloadTotal)})`}),e.jsx(Qe,{className:"connections-filter",checked:P,onChange:y,children:n("keepClosed")}),e.jsx(I,{className:"connections-filter dangerous",onClick:x,type:"close-all",size:20})]}),k.length>1&&e.jsx(as,{devices:k,selected:ue,onChange:he}),e.jsx(U,{ref:c,className:"connections-card relative",children:e.jsx("div",{className:"min-h-full min-w-full overflow-auto",children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsx("tr",{className:"connections-header",children:fe})}),e.jsx("tbody",{children:pe})]})})}),e.jsx(Ze,{title:n("closeAll.title"),show:u,onClose:w,onOk:g,children:n("closeAll.content")}),e.jsxs(os,{containerRef:c,bodyClassName:"flex flex-col",visible:z.visible,width:450,children:[e.jsxs("div",{className:"h-8 flex items-center justify-between",children:[e.jsx("span",{className:"pl-3 font-bold",children:n("info.title")}),e.jsx(I,{type:"close",size:16,className:"cursor-pointer",onClick:()=>B("visible",!1)})]}),e.jsx(ls,{className:"mt-3 px-5",connection:z.connection}),e.jsx("div",{className:"mt-3 flex justify-end pr-3",children:e.jsx(Q,{type:"danger",disabled:z.connection.completed,onClick:()=>xe(),children:n("info.closeConnection")})})]})]})}function ms(){const{translation:s}=E(),{t}=s("Settings"),{hostname:n,port:a,secret:o}=ee(),[l,c]=T($e),[i,r]=ne({hostname:"",port:"",secret:""});h.useEffect(()=>{r({hostname:n,port:a,secret:o})},[n,a,o,r]);const[u,x]=T(Se),[w,g]=T(ke);function d(){const{hostname:C,port:k,secret:N}=i;x([{hostname:C,port:k,secret:N}])}function p(){const{hostname:C,port:k,secret:N}=i,L=[...u,{hostname:C,port:k,secret:N}];x(L),g(L.length-1)}function P(){const{hostname:C,port:k}=i,N=u.findIndex(J=>J.hostname===C&&J.port===k);if(N===-1){ss(t("externalControllerSetting.deleteErrorText"));return}const L=[...u.slice(0,N),...u.slice(N+1)];x(L),w>=N&&g(0)}const y=e.jsxs("div",{className:"space-x-3",children:[e.jsx(Q,{type:"primary",onClick:()=>p(),children:t("externalControllerSetting.addText")}),e.jsx(Q,{type:"danger",disabled:u.length<2,onClick:()=>P(),children:t("externalControllerSetting.deleteText")})]});return e.jsxs(Ze,{className:"!w-105 !<sm:w-84",show:!l,title:t("externalControllerSetting.title"),bodyClassName:"external-controller",footerExtra:y,onClose:()=>c(!0),onOk:d,children:[e.jsx(Kt,{type:"info",inside:!0,children:e.jsx("p",{children:t("externalControllerSetting.note")})}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"my-1 w-14 font-bold md:my-3",children:t("externalControllerSetting.host")}),e.jsx(X,{className:"my-1 flex-1 md:my-3",align:"left",inside:!0,value:i.hostname,onChange:C=>r("hostname",C),onEnter:d})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"my-1 w-14 font-bold md:my-3",children:t("externalControllerSetting.port")}),e.jsx(X,{className:"my-1 w-14 flex-1 md:my-3",align:"left",inside:!0,value:i.port,onChange:C=>r("port",C),onEnter:d})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"my-1 w-14 font-bold md:my-3",children:t("externalControllerSetting.secret")}),e.jsx(X,{className:"my-1 w-14 flex-1 md:my-3",align:"left",inside:!0,value:i.secret,onChange:C=>r("secret",C),onEnter:d})]})]})}const hs=[{label:"Default",value:""},{label:"Debug",value:"debug"},{label:"Info",value:"info"},{label:"Warn",value:"warning"},{label:"Error",value:"error"},{label:"Silent",value:"silent"}],xs=new Map([["debug","text-teal-500"],["info","text-sky-500"],["warning","text-pink-500"],["error","text-rose-500"]]);function fs(){var g;const s=h.useRef(null),t=h.useRef([]),[n,a]=h.useState([]),{translation:o}=E(),{data:{logLevel:l},set:c}=ce(),{general:{logLevel:i}}=ie(),{t:r}=o("Logs"),u=qe(),x=h.useRef(((g=s.current)==null?void 0:g.scrollHeight)??0),w=pt(i)==="silent";return h.useLayoutEffect(()=>{const d=s.current;d!=null&&x.current===d.scrollTop+d.clientHeight&&(d.scrollTop=d.scrollHeight-d.clientHeight),x.current=(d==null?void 0:d.scrollHeight)??0}),h.useEffect(()=>{function d(p){t.current=t.current.slice().concat(p.map(P=>({...P,time:new Date}))),a(t.current)}return u!=null&&(u.subscribe("data",d),t.current=u.buffer(),a(t.current)),()=>u==null?void 0:u.unsubscribe("data",d)},[u]),e.jsxs("div",{className:"page",children:[e.jsxs(V,{title:r("title"),children:[e.jsxs("span",{className:"mr-2 text-sm text-primary-darken",children:[r("levelLabel"),":"]}),e.jsx(Ke,{disabled:w,options:hs,value:w?"silent":l,onSelect:d=>c(p=>{p.logLevel=d})})]}),e.jsx(U,{className:"mt-2.5 flex flex-1 flex-col md:mt-4",children:e.jsx("ul",{className:"logs-panel",ref:s,children:n.map((d,p)=>e.jsxs("li",{className:"inline-block text-[11px] leading-5",children:[e.jsxs("span",{className:"mr-2 text-orange-400",children:["[",se(d.time).format("YYYY-MM-DD HH:mm:ss"),"]"]}),e.jsxs("span",{className:xs.get(d.type),children:["[",d.type.toUpperCase(),"]"]}),e.jsxs("span",{children:[" ",d.payload]})]},p))})})]})}var we=(s=>(s.SPEED_NOTIFY="speed-notify",s))(we||{});class ps{constructor(){this.EE=new Me}notifySpeedTest(){this.EE.emit("speed-notify")}subscribe(t,n){this.EE.addListener(t,n)}unsubscribe(t,n){this.EE.removeListener(t,n)}}const je=new ps;const Re={"#909399":0,"#00c520":260,"#ff9a28":600,"#ff3e5e":1/0};function tt(s){var p,P;const{config:t,className:n}=s,{set:a}=re(),o=D(),l=h.useCallback(async y=>{if(Y())return await($==null?void 0:$.getProxyDelay(y))??0;const{data:{delay:C}}=await o.getProxyDelay(y);return C},[o]),c=h.useCallback(async function(){const y=await He.fromPromise(l(t.name),k=>k),C=y.isErr()?0:y.value;a(k=>{const N=k.proxies.find(L=>L.name===t.name);N!=null&&N.history.push({time:Date.now().toString(),delay:C})})},[t.name,l,a]),i=(p=t.history)!=null&&p.length?t.history.slice(-1)[0].delay:0,r=(P=t.history)!=null&&P.length?t.history.slice(-1)[0].meanDelay:void 0,u=i===0?"-":`${i}ms`,x=r?`(${r}ms)`:"";h.useLayoutEffect(()=>{const y=()=>{c()};return je.subscribe(we.SPEED_NOTIFY,y),()=>je.unsubscribe(we.SPEED_NOTIFY,y)},[c]);const w=h.useMemo(()=>i===0,[i]),g=h.useMemo(()=>Object.keys(Re).find(y=>(r||i)<=Re[y]),[i,r]),d=w?"#E5E7EB":g;return e.jsxs("div",{className:j("proxy-item",{"opacity-50":w},n),children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:j("rounded-sm py-[3px] px-1 text-[10px] text-white",{"text-gray-600":w}),style:{backgroundColor:d},children:t.type}),e.jsx("p",{className:"proxy-name",children:t.name})]}),e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-[10px] md:h-[18px] md:flex-row md:justify-between space-y-3 md:space-y-0",children:[e.jsxs("p",{children:[u,x]}),t.udp&&e.jsx("p",{className:"rounded bg-gray-200 p-[3px] text-gray-600",children:"UDP"})]})]})}function ys(s){const{markProxySelected:t}=re(),[n]=T(Vt),{data:a}=ce(),o=D(),{config:l}=s;async function c(u){if(await o.changeProxySelected(s.config.name,u),t(s.config.name,u),a.breakConnections){const x=[],w=await o.getConnections();for(const g of w.data.connections)g.chains.includes(s.config.name)&&x.push(g.id);await Promise.all(x.map(g=>o.closeConnection(g)))}}const i=h.useMemo(()=>{var x;const u=new Set;for(const w of l.all){const g=(x=n.get(w))==null?void 0:x.history;g!=null&&g.length&&g.slice(-1)[0].delay===0&&u.add(w)}return u},[l.all,n]),r=l.type==="Selector";return e.jsxs("div",{className:"proxy-group",children:[e.jsxs("div",{className:"mt-4 h-10 w-full flex items-center justify-between md:mt-0 md:h-15 md:w-auto",children:[e.jsx("span",{className:"overflow-ellipsis h-6 w-35 overflow-hidden whitespace-nowrap px-5 md:w-30",children:l.name}),e.jsx(oe,{className:"mr-5 md:mr-0",children:l.type})]}),e.jsx("div",{className:"flex-1 py-2 md:py-4",children:e.jsx(Xt,{className:"ml-5 md:ml-8",data:l.all,onClick:c,errSet:i,select:l.now,canClick:r,rowHeight:30})})]})}function gs(s){const{update:t}=Je(),{translation:n,lang:a}=E(),o=D(),{provider:l}=s,{t:c}=n("Proxies"),{visible:i,hide:r,show:u}=de();function x(){u(),o.healthCheckProvider(l.name).then(async()=>await t()).finally(()=>r())}function w(){u(),o.updateProvider(l.name).then(async()=>await t()).finally(()=>r())}const g=h.useMemo(()=>l.proxies.slice().sort((d,p)=>-1*be(d,p)),[l.proxies]);return e.jsxs(U,{className:"proxy-provider",children:[e.jsx(et,{visible:i}),e.jsxs("div",{className:"flex flex-col justify-between md:flex-row md:items-center",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"mr-6",children:l.name}),e.jsx(oe,{children:l.vehicleType})]}),e.jsxs("div",{className:"flex items-center pt-3 md:pt-0",children:[l.updatedAt&&e.jsx("span",{className:"text-sm",children:`${c("providerUpdateTime")}: ${Ee(new Date(l.updatedAt),a)}`}),e.jsx(I,{className:"cursor-pointer pl-5 text-red",type:"healthcheck",size:18,onClick:x}),e.jsx(I,{className:"cursor-pointer pl-5",type:"update",size:18,onClick:w})]})]}),e.jsx("ul",{className:"proxies-list",children:g.map(d=>e.jsx("li",{children:e.jsx(tt,{className:"proxy-provider-item",config:d})},d.name))})]})}const vs={[0]:"sort",[1]:"sort-ascending",[2]:"sort-descending"};function be(s,t){const n=s.history.length>0?s.history.slice(-1)[0].delay:0;return((t.history.length>0?t.history.slice(-1)[0].delay:0)||Number.MAX_SAFE_INTEGER)-(n||Number.MAX_SAFE_INTEGER)}function ws(){const{groups:s,global:t}=re(),{data:n,set:a}=ce(),{general:o}=ie(),{translation:l}=E(),{t:c}=l("Proxies"),i=h.useMemo(()=>o.mode==="global"?[t,...s]:s,[o,s,t]);return e.jsx(e.Fragment,{children:i.length!==0&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx(V,{title:c("groupTitle"),children:e.jsx(Qe,{className:"cursor-pointer text-sm text-primary-600 text-shadow-primary",checked:n.breakConnections,onChange:r=>a("breakConnections",r),children:c("breakConnectionsText")})}),e.jsx(U,{className:"my-2.5 p-0 md:my-4",children:e.jsx("ul",{className:"list-none divide-y divide-gray-300",children:i.map(r=>e.jsx("li",{children:e.jsx(ys,{config:r})},r.name))})})]})})}function js(){const{providers:s}=Je(),{translation:t}=E(),{t:n}=t("Proxies");return e.jsx(e.Fragment,{children:s.length!==0&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx(V,{title:n("providerTitle")}),e.jsx("ul",{className:"list-none",children:s.map(a=>e.jsx("li",{className:"my-2.5 md:my-4",children:e.jsx(gs,{provider:a})},a.name))})]})})}function bs(){const{proxies:s}=re(),{translation:t}=E(),{t:n}=t("Proxies");function a(){je.notifySpeedTest()}const{current:o,next:l}=Zt([1,2,0]),c=h.useMemo(()=>{switch(o){case 2:return s.slice().sort((r,u)=>be(r,u));case 1:return s.slice().sort((r,u)=>-1*be(r,u));default:return s.slice()}},[o,s]),i=l;return e.jsx(e.Fragment,{children:c.length!==0&&e.jsxs("div",{className:"flex flex-col",children:[e.jsxs(V,{title:n("title"),children:[e.jsx(I,{className:"ml-3",type:vs[o],onClick:i,size:20}),e.jsx(I,{className:"ml-3",type:"speed",size:20}),e.jsx("span",{className:"proxies-speed-test",onClick:a,children:n("speedTestText")})]}),e.jsx("ul",{className:"proxies-list",children:c.map(r=>e.jsx("li",{children:e.jsx(tt,{config:r})},r.name))})]})})}function Ns(){return e.jsxs("div",{className:"page",children:[e.jsx(ws,{}),e.jsx(js,{}),e.jsx(bs,{})]})}function Cs(s){const{update:t}=We(),{translation:n,lang:a}=E(),o=D(),{provider:l}=s,{t:c}=n("Rules"),{visible:i,hide:r,show:u}=de();function x(){u(),o.updateRuleProvider(l.name).then(async()=>await t()).finally(()=>r())}const w=j("rule-provider-icon",{"rule-provider-loading":i});return e.jsx("div",{className:"rule-provider",children:e.jsxs("div",{className:"rule-provider-header",children:[e.jsxs("div",{className:"rule-provider-header-part",children:[e.jsx("span",{className:"rule-provider-name",children:l.name}),e.jsx(oe,{children:l.vehicleType}),e.jsx(oe,{className:"rule-provider-behavior",children:l.behavior}),e.jsx("span",{className:"rule-provider-update",children:`${c("ruleCount")}: ${l.ruleCount}`})]}),e.jsxs("div",{className:"rule-provider-header-part",children:[l.updatedAt&&e.jsx("span",{className:"rule-provider-update",children:`${c("providerUpdateTime")}: ${Ee(new Date(l.updatedAt),a)}`}),e.jsx(I,{className:w,type:"update",size:18,onClick:x})]})]})})}function Ps(){const{providers:s}=We(),{translation:t}=E(),{t:n}=t("Rules");return e.jsx(e.Fragment,{children:s.length!==0&&e.jsxs("div",{className:"flex flex-col",children:[e.jsx(V,{title:n("providerTitle")}),e.jsx(U,{className:"mt-4 rounded p-0 shadow-primary divide-y",children:s.map(a=>e.jsx(Cs,{provider:a},a.name))})]})})}function Ss(){const{rules:s,update:t}=Wt(),{translation:n}=E(),{t:a}=n("Rules");G("rules",t);function o({index:l,style:c}){const i=s[l];return e.jsx("li",{className:"rule-item",style:c,children:e.jsxs("div",{className:"flex py-1",children:[e.jsx("div",{className:"rule-type w-40 text-center",children:i.type}),e.jsx("div",{className:"payload flex-1 text-center",children:i.payload}),e.jsx("div",{className:"rule-proxy w-40 text-center",children:i.proxy})]})})}return e.jsxs("div",{className:"page",children:[e.jsx(Ps,{}),e.jsx(V,{className:"not-first:mt-7.5",title:a("title")}),e.jsx(U,{className:"mt-2.5 flex flex-1 flex-col p-0 md:mt-4 focus:outline-none",children:e.jsx(yt,{className:"min-h-120",children:({height:l,width:c})=>e.jsx(gt,{height:l??0,width:c??0,itemCount:s.length,itemSize:50,children:o})})})]})}const ks=[{label:"中文",value:"zh_CN"},{label:"English",value:"en_US"}];function $s(){const{premium:s}=_e(),{data:t,update:n}=Ye(),{general:a,update:o}=ie(),l=ze($e),[c,i]=T(ke),r=Z(Se),u=ee(),{translation:x,setLang:w,lang:g}=E(),{t:d}=x("Settings"),p=D(),[P,y]=ne({socks5ProxyPort:7891,httpProxyPort:7890,mixedProxyPort:0});h.useEffect(()=>{y("socks5ProxyPort",(a==null?void 0:a.socksPort)??0),y("httpProxyPort",(a==null?void 0:a.port)??0),y("mixedProxyPort",(a==null?void 0:a.mixedPort)??0)},[a,y]);async function C(f){await p.updateConfig({mode:f}),await o()}async function k(f){await($==null?void 0:$.setStartAtLogin(f)),await n()}async function N(f){await($==null?void 0:$.setSystemProxy(f)),await n()}function L(f){w(f)}async function J(){await p.updateConfig({port:P.httpProxyPort}),await o()}async function q(){await p.updateConfig({"socks-port":P.socks5ProxyPort}),await o()}async function te(){await p.updateConfig({"mixed-port":P.mixedProxyPort}),await o()}async function ue(f){await p.updateConfig({"allow-lan":f}),await o()}const{hostname:me,port:he}=u,{allowLan:z,mode:B}=a,xe=(t==null?void 0:t.startAtLogin)??!1,_=(t==null?void 0:t.systemProxy)??!1,M=(t==null?void 0:t.isClashX)??!1,fe=h.useMemo(()=>{const f=[{label:d("values.global"),value:"Global"},{label:d("values.rules"),value:"Rule"},{label:d("values.direct"),value:"Direct"}];return s&&f.push({label:d("values.script"),value:"Script"}),f},[d,s]),pe=r.map((f,v)=>({value:v,label:e.jsx("span",{className:"truncate text-right",children:f.hostname})})),m=M?e.jsx("span",{className:"text-sm text-primary-darken",children:`${me}:${he}`}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{disabled:r.length<2&&!M,options:pe,value:c,onSelect:f=>i(f)}),e.jsx("span",{className:j({"modify-btn":!M},"external-controller"),onClick:()=>!M&&l(!1),children:"编辑"})]});return e.jsxs("div",{className:"page",children:[e.jsx(V,{title:d("title")}),e.jsxs(U,{className:"settings-card",children:[e.jsxs("div",{className:"flex flex-wrap",children:[e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.startAtLogin")}),e.jsx(ge,{disabled:!(t!=null&&t.isClashX),checked:xe,onChange:k})]}),e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.language")}),e.jsx(Ie,{options:ks,value:g,onSelect:f=>L(f)})]})]}),e.jsxs("div",{className:"flex flex-wrap",children:[e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.setAsSystemProxy")}),e.jsx(ge,{disabled:!M,checked:_,onChange:N})]}),e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.allowConnectFromLan")}),e.jsx(ge,{checked:z,onChange:ue})]})]})]}),e.jsxs(U,{className:"settings-card",children:[e.jsxs("div",{className:"flex flex-wrap",children:[e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.proxyMode")}),e.jsx(Ie,{options:fe,value:vt(B),onSelect:C})]}),e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.socks5ProxyPort")}),e.jsx(X,{className:"w-28",disabled:M,value:P.socks5ProxyPort,onChange:f=>y("socks5ProxyPort",+f),onBlur:q})]})]}),e.jsxs("div",{className:"flex flex-wrap",children:[e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.httpProxyPort")}),e.jsx(X,{className:"w-28",disabled:M,value:P.httpProxyPort,onChange:f=>y("httpProxyPort",+f),onBlur:J})]}),e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.mixedProxyPort")}),e.jsx(X,{className:"w-28",disabled:M,value:P.mixedProxyPort,onChange:f=>y("mixedProxyPort",+f),onBlur:te})]})]}),e.jsxs("div",{className:"flex flex-wrap",children:[e.jsxs("div",{className:"w-full flex items-center justify-between px-8 py-3 md:w-1/2",children:[e.jsx("span",{className:"label font-bold",children:d("labels.externalController")}),e.jsx("div",{className:"flex items-center space-x-2",children:m})]}),e.jsx("div",{className:"w-1/2 px-8"})]})]})]})}const Es=""+new URL("logo-b453e72f.png",import.meta.url).href;function Ls(s){const{routes:t}=s,{translation:n}=E(),{version:a,premium:o}=_e(),{data:l}=Ye(),{t:c}=n("SideBar"),i=Ce(),r=t.map(({path:u,name:x,noMobile:w})=>e.jsx("li",{className:j("item",{"no-mobile":w}),children:e.jsx(wt,{to:{pathname:u,search:i.search},className:({isActive:g})=>j({active:g}),children:c(x)})},x));return e.jsxs("div",{className:"sidebar",children:[e.jsx("img",{src:Es,alt:"logo",className:"sidebar-logo"}),e.jsx("ul",{className:"sidebar-menu",children:r}),e.jsxs("div",{className:"sidebar-version",children:[e.jsxs("span",{className:"sidebar-version-label",children:["Clash",(l==null?void 0:l.isClashX)&&"X"," ",c("Version")]}),e.jsx("span",{className:"sidebar-version-text",children:a}),o&&e.jsx("span",{className:"sidebar-version-label",children:"Premium"})]})]})}function Ts(){qe();const s=Ce(),t=[{path:"/proxies",name:"Proxies",element:e.jsx(Ns,{})},{path:"/logs",name:"Logs",element:e.jsx(fs,{})},{path:"/rules",name:"Rules",element:e.jsx(Ss,{}),noMobile:!0},{path:"/connections",name:"Connections",element:e.jsx(us,{}),noMobile:!0},{path:"/settings",name:"Settings",element:e.jsx($s,{})}],n=e.jsxs("div",{className:j("app",{"not-clashx":!Y()}),children:[e.jsx(Ls,{routes:t}),e.jsx("div",{className:"page-container",children:e.jsx(jt,{})}),e.jsx(ms,{})]});return e.jsx(bt,{children:e.jsxs(ye,{path:"/",element:n,children:[e.jsx(ye,{path:"/",element:e.jsx(Nt,{to:{pathname:"/proxies",search:s.search},replace:!0})}),t.map(a=>e.jsx(ye,{path:a.path,element:a.element},a.path))]})})}function De(){const s=document.getElementById("root"),t=e.jsx(h.StrictMode,{children:e.jsx(Ct,{children:e.jsx(h.Suspense,{fallback:e.jsx(et,{visible:!0}),children:e.jsx(Ts,{})})})});Oe(s).render(t)}Y()?St(()=>De()):De();