2 lines
54 KiB
JavaScript
2 lines
54 KiB
JavaScript
var nt=Object.defineProperty,st=Object.defineProperties;var ot=Object.getOwnPropertyDescriptors;var Le=Object.getOwnPropertySymbols;var at=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable;var Re=(n,t,s)=>t in n?nt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[t]=s,N=(n,t)=>{for(var s in t||(t={}))at.call(t,s)&&Re(n,s,t[s]);if(Le)for(var s of Le(t))lt.call(t,s)&&Re(n,s,t[s]);return n},I=(n,t)=>st(n,ot(t));import{R as e,c as g,f as rt,r as m,a as se,E as Me,b as ct,d as Y,e as we,u as Ee,g as Ce,h as _,i as ze,j as be,k as Q,l as He,m as it,n as he,o as ut,p as Ne,q as mt,s as Pe,t as dt,v as pt,w as ft,x as Et,y as ht,z as yt,A as xt,B as gt,C as vt,D as wt,F as Ct,G as bt,H as Nt,N as Pt,O as St,I as kt,J as pe,K as Dt,L as Ft,M as At}from"./vendor.91f359a7.js";const $t=function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))o(a);new MutationObserver(a=>{for(const l of a)if(l.type==="childList")for(const r of l.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&o(r)}).observe(document,{childList:!0,subtree:!0});function s(a){const l={};return a.integrity&&(l.integrity=a.integrity),a.referrerpolicy&&(l.referrerPolicy=a.referrerpolicy),a.crossorigin==="use-credentials"?l.credentials="include":a.crossorigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function o(a){if(a.ep)return;a.ep=!0;const l=s(a);fetch(a.href,l)}};$t();function te(){return navigator.userAgent==="ClashX Runtime"}let P=null;class Lt{constructor(t){this.instance=null,window.WebViewJavascriptBridge!=null&&(this.instance=window.WebViewJavascriptBridge),this.initBridge(s=>{this.instance=s,t()})}initBridge(t){if(!te())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 s=document.createElement("iframe");s.style.display="none",s.src="https://__bridge_loaded__",document.documentElement.appendChild(s),setTimeout(()=>document.documentElement.removeChild(s),0)}async callHandler(t,s){return await new Promise(o=>{var a;(a=this.instance)==null||a.callHandler(t,s,o)})}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 Rt(n){if(P!=null){n();return}P=new Lt(n)}function q(n){const{title:t,children:s,className:o,style:a}=n;return e.createElement("header",{className:g("header",o),style:a},e.createElement("h1",{className:"md:text-xl"},t),e.createElement("div",{className:"flex flex-auto items-center justify-end"},s))}function M(n){const{type:t,size:s=14,className:o,style:a}=n,l=g("clash-iconfont",`icon-${t}`,o),r=N({fontSize:s},a),c=I(N({},n),{className:l,style:r});return e.createElement("i",N({},c))}function W(){}function Tt(n,t){const s=[],o=[];for(const a of n)t(a)?s.push(a):o.push(a);return[s,o]}function j(n){var o;const t=["B","KB","MB","GB","TB"],s=Math.floor(Math.log(n||1)/Math.log(1024));return`${rt(n/Math.pow(1024,s),2).toFixed(2)} ${(o=t==null?void 0:t[s])!=null?o:""}`}function Oe(n){return n.replace(/.*[/\\]/,"")}function fe(n){const{className:t,checked:s=!1,disabled:o=!1,onChange:a=W}=n,l=g("switch",{checked:s,disabled:o},t);function r(){o||a(!s)}return e.createElement("div",{className:l,onClick:r},e.createElement(M,{className:"switch-icon font-bold",type:"check",size:20}))}const G=m.exports.forwardRef((n,t)=>{const{className:s,style:o,children:a}=n;return e.createElement("div",{className:g("card",s),style:o,ref:t},a)});function Te(n){const{options:t,value:s,onSelect:o}=n;return e.createElement("div",{className:"button-select"},t.map(a=>e.createElement("button",{value:a.value,key:a.value,className:g("button-select-options",{actived:s===a.value}),onClick:()=>o==null?void 0:o(a.value)},a.label)))}const It={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:"\u4E2D\u6587",en:"English",global:"Global",rules:"Rules",direct:"Direct",script:"Script"},versionString:"Current ClashX is the latest version\uFF1A{{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"}},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:"Upload",download:"Download",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"}},Bt={SideBar:{Proxies:"\u4EE3\u7406",Overview:"\u603B\u89C8",Logs:"\u65E5\u5FD7",Rules:"\u89C4\u5219",Settings:"\u8BBE\u7F6E",Connections:"\u8FDE\u63A5",Version:"\u7248\u672C"},Settings:{title:"\u8BBE\u7F6E",labels:{startAtLogin:"\u5F00\u673A\u65F6\u542F\u52A8",language:"\u8BED\u8A00",setAsSystemProxy:"\u8BBE\u7F6E\u4E3A\u7CFB\u7EDF\u4EE3\u7406",allowConnectFromLan:"\u5141\u8BB8\u6765\u81EA\u5C40\u57DF\u7F51\u7684\u8FDE\u63A5",proxyMode:"\u4EE3\u7406\u6A21\u5F0F",socks5ProxyPort:"Socks5 \u4EE3\u7406\u7AEF\u53E3",httpProxyPort:"HTTP \u4EE3\u7406\u7AEF\u53E3",mixedProxyPort:"\u6DF7\u5408\u4EE3\u7406\u7AEF\u53E3",externalController:"\u5916\u90E8\u63A7\u5236\u8BBE\u7F6E"},values:{cn:"\u4E2D\u6587",en:"English",global:"\u5168\u5C40",rules:"\u89C4\u5219",direct:"\u76F4\u8FDE",script:"\u811A\u672C"},versionString:"\u5F53\u524D ClashX \u5DF2\u662F\u6700\u65B0\u7248\u672C\uFF1A{{version}}",checkUpdate:"\u68C0\u67E5\u66F4\u65B0",externalControllerSetting:{title:"\u7F16\u8F91\u5916\u90E8\u63A7\u5236\u8BBE\u7F6E",note:"\u8BF7\u6CE8\u610F\uFF0C\u4FEE\u6539\u8BE5\u914D\u7F6E\u9879\u5E76\u4E0D\u4F1A\u4FEE\u6539\u4F60\u7684 Clash \u914D\u7F6E\u6587\u4EF6\uFF0C\u8BF7\u786E\u8BA4\u4FEE\u6539\u540E\u7684\u5916\u90E8\u63A7\u5236\u5730\u5740\u548C Clash \u914D\u7F6E\u6587\u4EF6\u5185\u7684\u5730\u5740\u4E00\u81F4\uFF0C\u5426\u5219\u4F1A\u5BFC\u81F4 Dashboard \u65E0\u6CD5\u8FDE\u63A5\u3002",host:"Host",port:"\u7AEF\u53E3",secret:"\u5BC6\u94A5"}},Logs:{title:"\u65E5\u5FD7",levelLabel:"\u65E5\u5FD7\u7B49\u7EA7"},Rules:{title:"\u89C4\u5219",providerTitle:"\u89C4\u5219\u96C6",providerUpdateTime:"\u6700\u540E\u66F4\u65B0\u4E8E",ruleCount:"\u89C4\u5219\u6761\u6570"},Connections:{title:"\u8FDE\u63A5",keepClosed:"\u4FDD\u7559\u5173\u95ED\u8FDE\u63A5",total:{text:"\u603B\u91CF",upload:"\u4E0A\u4F20",download:"\u4E0B\u8F7D"},closeAll:{title:"\u8B66\u544A",content:"\u5C06\u4F1A\u5173\u95ED\u6240\u6709\u8FDE\u63A5"},filter:{all:"\u5168\u90E8"},columns:{host:"\u57DF\u540D",network:"\u7F51\u7EDC",process:"\u8FDB\u7A0B",type:"\u7C7B\u578B",chains:"\u8282\u70B9\u94FE",rule:"\u89C4\u5219",time:"\u8FDE\u63A5\u65F6\u95F4",speed:"\u901F\u7387",upload:"\u4E0A\u4F20",download:"\u4E0B\u8F7D",sourceIP:"\u6765\u6E90 IP"},info:{title:"\u8FDE\u63A5\u4FE1\u606F",id:"ID",host:"\u57DF\u540D",hostEmpty:"\u7A7A",dstIP:"IP",dstIPEmpty:"\u7A7A",srcIP:"\u6765\u6E90",upload:"\u4E0A\u4F20",download:"\u4E0B\u8F7D",network:"\u7F51\u7EDC",process:"\u8FDB\u7A0B",processPath:"\u8DEF\u5F84",inbound:"\u5165\u53E3",rule:"\u89C4\u5219",chains:"\u4EE3\u7406",status:"\u72B6\u6001",opening:"\u8FDE\u63A5\u4E2D",closed:"\u5DF2\u5173\u95ED",closeConnection:"\u5173\u95ED\u8FDE\u63A5"}},Proxies:{title:"\u4EE3\u7406",editDialog:{title:"\u7F16\u8F91\u4EE3\u7406",color:"\u989C\u8272",name:"\u540D\u5B57",type:"\u7C7B\u578B",server:"\u670D\u52A1\u5668",port:"\u7AEF\u53E3",password:"\u5BC6\u7801",cipher:"\u52A0\u5BC6\u65B9\u5F0F",obfs:"Obfs","obfs-host":"Obfs-host",uuid:"UUID",alterId:"AlterId",tls:"TLS"},groupTitle:"\u7B56\u7565\u7EC4",providerTitle:"\u4EE3\u7406\u96C6",providerUpdateTime:"\u6700\u540E\u66F4\u65B0\u4E8E",expandText:"\u5C55\u5F00",collapseText:"\u6536\u8D77",speedTestText:"\u6D4B\u901F",breakConnectionsText:"\u5207\u6362\u65F6\u6253\u65AD\u5305\u542B\u7B56\u7565\u7EC4\u7684\u8FDE\u63A5"},Modal:{ok:"\u786E \u5B9A",cancel:"\u53D6 \u6D88"}},Ue={en_US:It,zh_CN:Bt},Mt=Object.keys(Ue);function zt(){for(const n of window.navigator.languages){if(n.includes("zh"))return"zh_CN";if(n.includes("us"))return"en_US"}return"en_US"}function Se(n){return m.exports.useMemo(()=>{function s(o,a){if(typeof o=="string")n(l=>{const r=o,c=a;l[r]=c});else if(typeof o=="function"){const l=o;n(r=>l(r))}else typeof o=="object"&&n(l=>se(l,r=>{const c=o;for(const i of Object.keys(c)){const h=i;r[h]=c[h]}}))}return s},[n])}class je{constructor(t){this.EE=new Me,this.innerBuffer=[],this.url="",this.connection=null,this.config=Object.assign({bufferLength:0,retryInterval:5e3},t)}connectWebsocket(){const t=new URL(this.url);this.connection=new WebSocket(t.toString()),this.connection.addEventListener("message",s=>{const o=JSON.parse(s.data);this.EE.emit("data",[o]),this.config.bufferLength>0&&(this.innerBuffer.push(o),this.innerBuffer.length>this.config.bufferLength&&this.innerBuffer.splice(0,this.innerBuffer.length-this.config.bufferLength))}),this.connection.addEventListener("error",s=>{var o;this.EE.emit("error",s),(o=this.connection)==null||o.close(),setTimeout(this.connectWebsocket,this.config.retryInterval)})}connect(t){var s;this.url===t&&this.connection||(this.url=t,(s=this.connection)==null||s.close(),this.connectWebsocket())}subscribe(t,s){this.EE.addListener(t,s)}unsubscribe(t,s){this.EE.removeListener(t,s)}buffer(){return this.innerBuffer.slice()}destory(){var t;this.EE.removeAllListeners(),(t=this.connection)==null||t.close(),this.connection=null}}class Ht{constructor(t,s){this.axiosClient=ct.create({baseURL:t,headers:s?{Authorization:`Bearer ${s}`}:{}})}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(s){return s>=200&&s<300||s===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,s){return await this.axiosClient.put(`proxies/${encodeURIComponent(t)}`,{name:s})}}const Ot=Y(async()=>{if(!te())return null;const n=await P.getAPIInfo();return{hostname:n.host,port:n.port,secret:n.secret,protocol:"http:"}}),We=we("externalControllers",[]);function oe(){var h,p,f,d,E,v,w,$,D,F,S,A,Z,z,V;const n=Ee(Ot),t=Ce(),s=Ee(We);if(n!=null)return n;let o;{const J=document.querySelector('meta[name="external-controller"]');((h=J==null?void 0:J.content)==null?void 0:h.match(/^https?:/))!=null&&(o=new URL(J.content))}const a=new URLSearchParams(t.search),l=(E=(d=(f=a.get("host"))!=null?f:(p=s==null?void 0:s[0])==null?void 0:p.hostname)!=null?d:o==null?void 0:o.hostname)!=null?E:"127.0.0.1",r=(D=($=(w=a.get("port"))!=null?w:(v=s==null?void 0:s[0])==null?void 0:v.port)!=null?$:o==null?void 0:o.port)!=null?D:"9090",c=(Z=(A=(S=a.get("secret"))!=null?S:(F=s==null?void 0:s[0])==null?void 0:F.secret)!=null?A:o==null?void 0:o.username)!=null?Z:"",i=((z=a.get("protocol"))!=null?z:l==="127.0.0.1")?"http:":(V=o==null?void 0:o.protocol)!=null?V:window.location.protocol;return{hostname:l,port:r,secret:c,protocol:i}}const Ut=Y({key:"",instance:null});function B(){const{hostname:n,port:t,secret:s,protocol:o}=oe(),[a,l]=_(Ut),r=`${o}//${n}:${t}?secret=${s}`;if(a.key===r)return a.instance;const c=new Ht(`${o}//${n}:${t}`,s);return l({key:r,instance:c}),c}const ke=Y(!0),jt=we("language",void 0);function k(){const[n,t]=_(jt),s=m.exports.useMemo(()=>n!=null?n:zt(),[n]),o=m.exports.useCallback(function(a){function l(r){return ut(Ue[s][a],r)}return{t:l}},[s]);return{lang:s,locales:Mt,setLang:t,translation:o}}const _e=Y({version:"",premium:!1});function Ge(){const[n,t]=_(_e),s=B(),o=be(ke);return Q([s],async function(){const a=await He.fromPromise(s.getVersion(),l=>l);o(a.isOk()),t(a.isErr()?{version:"",premium:!1}:{version:a.value.data.version,premium:!!a.value.data.premium})}),n}function Ve(){const[{premium:n}]=_(_e),t=B(),{data:s,mutate:o}=Q(["/providers/rule",t,n],async()=>{if(!n)return[];const a=await t.getRuleProviders();return Object.keys(a.data.providers).map(l=>a.data.providers[l])});return{providers:s!=null?s:[],update:o}}const Wt=we("profile",{breakConnections:!1,logLevel:""});function ce(){const[n,t]=_(Wt),s=m.exports.useCallback(o=>{t(se(n,o))},[n,t]);return{data:n,set:Se(s)}}const Je=Y([]);function Xe(){const[n,t]=_(Je),s=B(),{data:o,mutate:a}=Q(["/providers/proxy",s],async()=>{const l=await s.getProxyProviders();return Object.keys(l.data.providers).map(r=>l.data.providers[r]).filter(r=>r.name!=="default").filter(r=>r.vehicleType!=="Compatible")});return m.exports.useEffect(()=>{t(o!=null?o:[])},[o,t]),{providers:n,update:a}}function De(){const n=B(),{data:t,mutate:s}=Q(["/config",n],async()=>{var l;const a=(await n.getConfig()).data;return{port:a.port,socksPort:a["socks-port"],mixedPort:(l=a["mixed-port"])!=null?l:0,redirPort:a["redir-port"],mode:a.mode.toLowerCase(),logLevel:a["log-level"],allowLan:a["allow-lan"]}});return{general:t!=null?t:{},update:s}}const qe=ze({proxies:[],groups:[],global:{name:"GLOBAL",type:"Selector",now:"",history:[],all:[]}});function ie(){const[n,t]=_(qe),s=Se(t),o=B(),{mutate:a}=Q(["/proxies",o],async()=>{const r=await o.getProxies(),c=r.data.proxies.GLOBAL;c.name="GLOBAL";const i=new Set(["Selector","URLTest","Fallback","LoadBalance"]),h=new Set(["DIRECT","REJECT","GLOBAL"]),p=c.all.filter(E=>!h.has(E)).map(E=>I(N({},r.data.proxies[E]),{name:E})),[f,d]=Tt(p,E=>!i.has(E.type));s({proxies:f,groups:d,global:c})}),l=m.exports.useCallback((r,c)=>{s(i=>{r==="GLOBAL"&&(i.global.now=c);for(const h of i.groups)h.name===r&&(h.now=c)})},[s]);return{proxies:n.proxies,groups:n.groups,global:n.global,update:a,markProxySelected:l,set:s}}const _t=Y(n=>{const t=n(qe),s=n(Je),o=new Map;for(const a of t.proxies)o.set(a.name,a);for(const a of s)for(const l of a.proxies)o.set(l.name,l);return o});function Ke(){const{data:n,mutate:t}=Q("/clashx",async()=>{var a,l;if(!te())return{isClashX:!1,startAtLogin:!1,systemProxy:!1};const s=(a=await(P==null?void 0:P.getStartAtLogin()))!=null?a:!1,o=(l=await(P==null?void 0:P.isSystemProxySet()))!=null?l:!1;return{startAtLogin:s,systemProxy:o,isClashX:!0}});return{data:n,update:t}}const Gt=ze([]);function Vt(){const[n,t]=_(Gt),s=Se(t),o=B();async function a(){const l=await o.getRules();s(l.data.rules)}return{rules:n,update:a}}const Jt=Y(new je({bufferLength:200}));function Ye(){const n=oe(),{general:t}=De(),{data:{logLevel:s}}=ce(),o=Ee(Jt),a=s||t.logLevel,l=it(`${n.protocol}//${n.hostname}:${n.port}/logs?level=${a}&secret=${n.secret}`),r=he(n);return m.exports.useEffect(()=>{if(a){const c=r.current,h=`${c.protocol==="http:"?"ws:":"wss:"}//${c.hostname}:${c.port}/logs?level=${a}&token=${c.secret}`;o.connect(h)}},[r,o,a,l]),o}function Xt(){const n=oe(),t=m.exports.useRef(new je({bufferLength:200})),o=`${n.protocol==="http:"?"ws:":"wss:"}//${n.hostname}:${n.port}/connections?token=${n.secret}`;return m.exports.useEffect(()=>{t.current.connect(o)},[o]),t.current}function qt(n){const{className:t,data:s,onClick:o,select:a,canClick:l,errSet:r,rowHeight:c}=n,{translation:i}=k(),{t:h}=i("Proxies"),[p,f]=m.exports.useState(!1),[d,E]=m.exports.useState(!1),v=m.exports.useRef(null);m.exports.useLayoutEffect(()=>{var S,A;E(((A=(S=v==null?void 0:v.current)==null?void 0:S.offsetHeight)!=null?A:0)>30)},[]);const w=p?"auto":c,$=l?o:W;function D(){f(!p)}const F=s.map(S=>{const A=g({"tags-selected":a===S,"cursor-pointer":l,error:r==null?void 0:r.has(S)});return e.createElement("li",{className:A,key:S,onClick:()=>$(S)},S)});return e.createElement("div",{className:g("flex items-start overflow-y-hidden",t),style:{height:w}},e.createElement("ul",{ref:v,className:g("tags",{expand:p})},F),d&&e.createElement("span",{className:"h-7 px-5 select-none cursor-pointer leading-7",onClick:D},h(p?"collapseText":"expandText")))}function ee(n){const{className:t,style:s,value:o="",align:a="center",inside:l=!1,autoFocus:r=!1,type:c="text",disabled:i=!1,onChange:h=W,onBlur:p=W,onEnter:f=W}=n,d=g("input",`text-${a}`,{"focus:shadow-none":l},t);function E(v){v.code==="Enter"&&f(v)}return e.createElement("input",{disabled:i,className:d,style:s,value:o,autoFocus:r,type:c,onChange:v=>h(v.target.value,v),onBlur:p,onKeyDown:E})}function Kt(n){const{value:t,options:s,onSelect:o,className:a,style:l}=n,r=m.exports.useRef(document.createElement("div")),c=m.exports.useRef(null),[i,h]=m.exports.useState(!1),[p,f]=m.exports.useState({});m.exports.useLayoutEffect(()=>{const w=c.current.getBoundingClientRect();f({top:Math.floor(w.top+w.height)+6,left:Math.floor(w.left)-10})},[]),m.exports.useLayoutEffect(()=>{const w=r.current;return document.body.appendChild(w),()=>{document.body.removeChild(w)}},[]);function d(){h(!i)}const E=m.exports.useMemo(()=>s.find(w=>w.value===t),[t,s]),v=e.createElement("div",{className:g("select-list",{"select-list-show":i}),style:p},e.createElement("ul",{className:"list"},s.map(w=>{var $;return e.createElement(Yt,{className:g({selected:w.value===t}),onClick:D=>{o==null||o(w.value,D),h(!1)},disabled:w.disabled,key:($=w.key)!=null?$:w.value,value:w.value},w.label)})));return e.createElement(e.Fragment,null,e.createElement("div",{className:g("select",a),style:l,ref:c,onClick:d},E==null?void 0:E.label,e.createElement(M,{type:"triangle-down"})),Ne.exports.createPortal(v,r.current))}function Yt(n){const{className:t,style:s,disabled:o=!1,children:a,onClick:l=W}=n,r=g("option",{disabled:o},t);return e.createElement("li",{className:r,style:s,onClick:l},a)}function Qe(n){const{show:t=!0,title:s="Modal",size:o="small",footer:a=!0,onOk:l=W,onClose:r=W,bodyClassName:c,bodyStyle:i,className:h,style:p,children:f}=n,{translation:d}=k(),{t:E}=d("Modal"),v=m.exports.useRef(document.createElement("div")),w=m.exports.useRef(null);m.exports.useLayoutEffect(()=>{const F=v.current;return document.body.appendChild(F),()=>{document.body.removeChild(F)}},[]);function $(F){F.target===w.current&&r()}const D=e.createElement("div",{className:g("modal-mask",{"modal-show":t}),ref:w,onMouseDown:$},e.createElement("div",{className:g("modal",`modal-${o}`,h),style:p},e.createElement("div",{className:"modal-title"},s),e.createElement("div",{className:g("modal-body",c),style:i},f),a&&e.createElement("div",{className:"footer"},e.createElement(ye,{onClick:()=>r()},E("cancel")),e.createElement(ye,{type:"primary",onClick:()=>l()},E("ok")))));return Ne.exports.createPortal(D,v.current)}const Qt={success:"check",info:"info",warning:"info",error:"close"};function Zt(n){const{message:t="",type:s="info",inside:o=!1,children:a,className:l,style:r}=n,c=g("alert",`alert-${o?"note":"box"}-${s}`,l);return e.createElement("div",{className:c,style:r},e.createElement("span",{className:"alert-icon"},e.createElement(M,{type:Qt[s],size:26})),t?e.createElement("p",{className:"alert-message"},t):e.createElement("div",{className:"alert-message"},a))}function ye(n){const{type:t="normal",onClick:s=W,children:o,className:a,style:l,disiabled:r}=n,c=g("button",`button-${t}`,a,{"button-disabled":r});return e.createElement("button",{className:c,style:l,onClick:s,disabled:r},o)}function le(n){const[t,s]=mt(n),o=m.exports.useMemo(()=>{function a(l,r){typeof l=="string"?s(c=>{const i=l,h=r;c[i]=h}):typeof l=="function"?s(l):typeof l=="object"&&s(c=>{const i=l;for(const h of Object.keys(i)){const p=h;c[p]=i[p]}})}return a},[s]);return[t,o]}function en(n,t=0){if(n.length<2)throw new Error("List requires at least two elements");const[s,o]=m.exports.useState(t);function a(){o((s+1)%n.length)}return{current:m.exports.useMemo(()=>n[s],[n,s]),next:a}}function Fe(n=!1){const[t,s]=m.exports.useState(n);function o(){s(!1)}function a(){s(!0)}return{visible:t,hide:o,show:a}}function Ze(n){const{className:t,checked:s=!1,onChange:o=W}=n,a=g("checkbox",{checked:s},t);function l(){o(!s)}return e.createElement("div",{className:a,onClick:l},e.createElement(M,{className:"checkbox-icon",type:"check",size:18}),e.createElement("div",null,n.children))}function re(n){const{color:t,className:s,style:o}=n,a=g("tag",s),l=N({color:t},o),r=I(N({},n),{className:a,style:l});return e.createElement("span",N({},r),n.children)}function tn(n){const t=g("spinner",n.className);return e.createElement("div",{className:t},e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})),e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})),e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})),e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})),e.createElement("div",{className:"spinner-circle"},e.createElement("div",{className:"spinner-inner"})))}function et(n){const t=g("loading","visible",n.className);return n.visible?e.createElement("div",{className:t},e.createElement(tn,{className:n.spinnerClassName})):null}function nn(n){var a,l,r;const t=m.exports.useRef(document.createElement("div"));m.exports.useLayoutEffect(()=>{const c=t.current;return document.body.appendChild(c),()=>{document.body.removeChild(c)}},[]);const s="absolute h-full right-0 transition-transform transform translate-x-full duration-100 pointer-events-auto",o=e.createElement("div",{className:g(n.className,"absolute inset-0 pointer-events-none z-9999")},e.createElement(G,{className:g(s,n.bodyClassName,{"translate-x-0":n.visible}),style:{width:(a=n.width)!=null?a:400}},n.children));return Ne.exports.createPortal(o,(r=(l=n.containerRef)==null?void 0:l.current)!=null?r:t.current)}Pe.extend(dt);function Ae(n,t){const s=t==="en_US"?"en":"zh-cn";return Pe().locale(s).from(n)}function sn(n){const{translation:t}=k(),s=m.exports.useMemo(()=>t("Connections").t,[t]),{className:o,style:a}=n,l=g("flex flex-wrap px-1",o);function r(c){var i;(i=n.onChange)==null||i.call(n,c)}return e.createElement("div",{className:l,style:a},e.createElement("div",{className:g("connections-devices-item pt-2 mb-2",{selected:n.selected===""}),onClick:()=>r("")},s("filter.all")),n.devices.map(c=>e.createElement("div",{key:c.label,className:g("connections-devices-item pt-2 mb-2",{selected:n.selected===c.label}),onClick:()=>r(c.label)},c.label," (",c.number,")")))}function on(n){var o,a,l,r,c,i,h,p,f,d,E,v,w;const{translation:t}=k(),s=m.exports.useMemo(()=>t("Connections").t,[t]);return e.createElement("div",{className:g(n.className,"text-sm flex flex-col overflow-y-auto")},e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.id")),e.createElement("span",{className:"font-mono"},n.connection.id)),e.createElement("div",{className:"flex my-3 justify-between"},e.createElement("div",{className:"flex flex-1"},e.createElement("span",{className:"font-bold w-20"},s("info.network")),e.createElement("span",{className:"font-mono"},(o=n.connection.metadata)==null?void 0:o.network)),e.createElement("div",{className:"flex flex-1"},e.createElement("span",{className:"font-bold w-20"},s("info.inbound")),e.createElement("span",{className:"font-mono"},(a=n.connection.metadata)==null?void 0:a.type))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.host")),e.createElement("span",{className:"font-mono flex-1 break-all"},(l=n.connection.metadata)!=null&&l.host?`${n.connection.metadata.host}:${(r=n.connection.metadata)==null?void 0:r.destinationPort}`:s("info.hostEmpty"))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.dstIP")),e.createElement("span",{className:"font-mono"},(c=n.connection.metadata)!=null&&c.destinationIP?`${n.connection.metadata.destinationIP}:${(i=n.connection.metadata)==null?void 0:i.destinationPort}`:s("info.hostEmpty"))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.srcIP")),e.createElement("span",{className:"font-mono"},`${(h=n.connection.metadata)==null?void 0:h.sourceIP}:${(p=n.connection.metadata)==null?void 0:p.sourcePort}`)),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.process")),e.createElement("span",{className:"font-mono"},(f=n.connection.metadata)!=null&&f.processPath?`${Oe(n.connection.metadata.processPath)}`:s("info.hostEmpty"))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.processPath")),e.createElement("span",{className:"font-mono flex-1 break-all"},(d=n.connection.metadata)!=null&&d.processPath?`${n.connection.metadata.processPath}`:s("info.hostEmpty"))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.rule")),e.createElement("span",{className:"font-mono"},n.connection.rule&&`${n.connection.rule}${n.connection.rulePayload&&` :: ${n.connection.rulePayload}`}`)),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.chains")),e.createElement("span",{className:"font-mono flex-1 break-all"},(E=n.connection.chains)==null?void 0:E.slice().reverse().join(" / "))),e.createElement("div",{className:"flex my-3 justify-between"},e.createElement("div",{className:"flex flex-1"},e.createElement("span",{className:"font-bold w-20"},s("info.upload")),e.createElement("span",{className:"font-mono"},j((v=n.connection.upload)!=null?v:0))),e.createElement("div",{className:"flex flex-1"},e.createElement("span",{className:"font-bold w-20"},s("info.download")),e.createElement("span",{className:"font-mono"},j((w=n.connection.download)!=null?w:0)))),e.createElement("div",{className:"flex my-3"},e.createElement("span",{className:"font-bold w-20"},s("info.status")),e.createElement("span",{className:"font-mono"},n.connection.completed?e.createElement("span",{className:"text-red"},s("info.closed")):e.createElement("span",{className:"text-green"},s("info.opening")))))}class an{constructor(){this.connections=new Map,this.saveDisconnection=!1}appendToSet(t){var o;const s=t.reduce((a,l)=>a.set(l.id,l),new Map);for(const a of this.connections.keys())if(!s.has(a))if(!this.saveDisconnection)this.connections.delete(a);else{const l=this.connections.get(a);l!=null&&this.connections.set(a,se(l,r=>{r.completed=!0,r.uploadSpeed=0,r.downloadSpeed=0}))}for(const a of s.keys()){if(!this.connections.has(a)){this.connections.set(a,I(N({},s.get(a)),{uploadSpeed:0,downloadSpeed:0}));continue}const l=this.connections.get(a),r=s.get(a);(o=this.connections)==null||o.set(a,I(N({},r),{uploadSpeed:r.upload-l.upload,downloadSpeed:r.download-l.download}))}}toggleSave(){var t,s;if(this.saveDisconnection){this.saveDisconnection=!1;for(const o of this.connections.keys())(s=(t=this.connections)==null?void 0:t.get(o))!=null&&s.completed&&this.connections.delete(o)}else this.saveDisconnection=!0;return this.saveDisconnection}getConnections(){return[...this.connections.values()]}}function ln(){const n=m.exports.useMemo(()=>new an,[]),t=m.exports.useRef(!0),[s,o]=m.exports.useState([]),[a,l]=m.exports.useState(!1),r=m.exports.useCallback(function(i){n.appendToSet(i),t.current&&o(n.getConnections()),t.current=!t.current},[n]),c=m.exports.useCallback(function(){const i=n.toggleSave();l(i),i||o(n.getConnections()),t.current=!0},[n]);return{connections:s,feed:r,toggleSave:c,save:a}}const x={Host:"host",Network:"network",Process:"process",Type:"type",Chains:"chains",Rule:"rule",Speed:"speed",Upload:"upload",Download:"download",SourceIP:"sourceIP",Time:"time"},rn=new Set([x.Network,x.Type,x.Speed,x.Upload,x.Download,x.SourceIP,x.Time,x.Process]);function cn(n,t){switch(!0){case(n===0&&t===0):return"-";case(n!==0&&t!==0):return`\u2191 ${j(n)}/s \u2193 ${j(t)}/s`;case n!==0:return`\u2191 ${j(n)}/s`;default:return`\u2193 ${j(t)}/s`}}const R=pt().setRowType();function un(){const{translation:n,lang:t}=k(),s=m.exports.useMemo(()=>n("Connections").t,[n]),o=Xt(),a=he(o),l=B(),r=m.exports.useRef(null),[c,i]=le({uploadTotal:0,downloadTotal:0}),{visible:h,show:p,hide:f}=Fe();function d(){l.closeAllConnections().finally(()=>f())}const{connections:E,feed:v,save:w,toggleSave:$}=ln(),D=m.exports.useMemo(()=>E.map(u=>({id:u.id,host:`${u.metadata.host||u.metadata.destinationIP}:${u.metadata.destinationPort}`,chains:u.chains.slice().reverse().join(" / "),rule:u.rulePayload?`${u.rule} :: ${u.rulePayload}`:u.rule,time:new Date(u.start).getTime(),upload:u.upload,download:u.download,sourceIP:u.metadata.sourceIP,type:u.metadata.type,network:u.metadata.network.toUpperCase(),process:u.metadata.processPath,speed:{upload:u.uploadSpeed,download:u.downloadSpeed},completed:!!u.completed,original:u})),[E]),F=m.exports.useMemo(()=>{const u=ft(E,"metadata.sourceIP");return Object.keys(u).map(b=>({label:b,number:u[b].length})).sort((b,y)=>b.label.localeCompare(y.label))},[E]),S=m.exports.useRef(null),A=Et(S,{threshold:[1]}),Z=m.exports.useMemo(()=>R.createColumns([R.createDataColumn(x.Host,{minSize:260,size:260,header:s(`columns.${x.Host}`)}),R.createDataColumn(x.Network,{minSize:80,size:80,header:s(`columns.${x.Network}`)}),R.createDataColumn(x.Type,{minSize:100,size:100,header:s(`columns.${x.Type}`)}),R.createDataColumn(x.Chains,{minSize:200,size:200,header:s(`columns.${x.Chains}`)}),R.createDataColumn(x.Rule,{minSize:140,size:140,header:s(`columns.${x.Rule}`)}),R.createDataColumn(x.Process,{minSize:100,size:100,header:s(`columns.${x.Process}`),cell:u=>u.value?Oe(u.value):"-"}),R.createDataColumn(u=>[u.speed.upload,u.speed.download],{id:x.Speed,header:s(`columns.${x.Speed}`),minSize:200,size:200,sortDescFirst:!0,sortingFn(u,b){var U,T,K,$e;const y=(T=(U=u.original)==null?void 0:U.speed)!=null?T:{upload:0,download:0},O=($e=(K=b.original)==null?void 0:K.speed)!=null?$e:{upload:0,download:0};return y.download===O.download?y.upload-O.upload:y.download-O.download},cell:u=>cn(u.value[0],u.value[1])}),R.createDataColumn(x.Upload,{minSize:100,size:100,header:s(`columns.${x.Upload}`),cell:u=>j(u.value)}),R.createDataColumn(x.Download,{minSize:100,size:100,header:s(`columns.${x.Download}`),cell:u=>j(u.value)}),R.createDataColumn(x.SourceIP,{minSize:140,size:140,header:s(`columns.${x.SourceIP}`),filterFn:"equals"}),R.createDataColumn(x.Time,{minSize:120,size:120,header:s(`columns.${x.Time}`),cell:u=>Ae(new Date(u.value),t),sortingFn:(u,b)=>{var y,O,U,T;return((O=(y=b.original)==null?void 0:y.time)!=null?O:0)-((T=(U=u.original)==null?void 0:U.time)!=null?T:0)}})]),[t,s]);m.exports.useLayoutEffect(()=>{function u(b){for(const y of b)i({uploadTotal:y.uploadTotal,downloadTotal:y.downloadTotal}),v(y.connections)}return o==null||o.subscribe("data",u),()=>{o==null||o.unsubscribe("data",u)}},[o,v,i]),ht(()=>{var u;(u=a.current)==null||u.destory()});const z=yt(R,{data:D,columns:Z,getCoreRowModel:xt(),getSortedRowModel:gt(),getColumnFilteredRowModel:vt(),initialState:{sorting:[{id:x.Time,desc:!1}]},columnResizeMode:"onChange",enableColumnResizing:!0,autoResetSorting:!1,autoResetColumnFilters:!1}),V=z.getHeaderGroups()[0],[J,ue]=m.exports.useState("");function me(u){ue(u),z.setColumnFilterValue(x.SourceIP,u||void 0)}const[H,L]=le({visible:!1,selectedID:"",connection:{}});function de(){L(u=>{u.connection.completed=!0}),l.closeConnection(H.selectedID)}const X=he(H.connection);m.exports.useEffect(()=>{var b;const u=(b=D.find(y=>y.id===H.selectedID))==null?void 0:b.original;u?L(y=>{y.connection=N({},u),H.selectedID===X.current.id&&(y.connection.completed=X.current.completed)}):Object.keys(X.current).length!==0&&!X.current.completed&&L(y=>{y.connection.completed=!0})},[D,H.selectedID,X,L]);const ne=m.exports.useMemo(()=>{var u;return((u=A==null?void 0:A.intersectionRatio)!=null?u:0)<1},[A]),ae=V.headers.map((u,b)=>{const y=u.column,O=y.id;return e.createElement("th",I(N({},u.getHeaderProps(U=>se(U,T=>{T.className=g("connections-th",{resizing:y.getIsResizing(),fixed:y.id===x.Host,shadow:ne&&y.id===x.Host}),!T.style&&(T.style={}),T.style.width=u.getSize()}))),{ref:y.id===x.Host?S:void 0,key:O}),e.createElement("div",N({},y.getToggleSortingProps()),u.renderHeader(),y.getIsSorted()!==!1?y.getIsSorted()==="desc"?" \u2193":" \u2191":null),b!==V.headers.length-1&&e.createElement("div",I(N({},u.getResizerProps()),{className:"connections-resizer"})))}),C=z.getRowModel().rows.map(u=>{var b;return e.createElement("tr",I(N({},u.getRowProps()),{className:"cursor-default select-none",key:(b=u.original)==null?void 0:b.id,onClick:()=>{var y;return L({visible:!0,selectedID:(y=u.original)==null?void 0:y.id})}}),u.getAllCells().map(y=>{var U;const O=g("connections-block",{"text-center":rn.has(y.column.id),completed:(U=u.original)==null?void 0:U.completed},{fixed:y.column.id===x.Host,shadow:ne&&y.column.id===x.Host});return e.createElement("td",I(N({},y.getCellProps(T=>se(T,K=>{!K.style&&(K.style={}),K.className=O,K.style.width=y.column.getSize()}))),{key:y.column.id}),y.renderCell())}))});return e.createElement("div",{className:"page !h-100vh"},e.createElement(q,{title:s("title")},e.createElement("span",{className:"cursor-default flex-1 connections-filter"},`(${s("total.text")}: ${s("total.upload")} ${j(c.uploadTotal)} ${s("total.download")} ${j(c.downloadTotal)})`),e.createElement(Ze,{className:"connections-filter",checked:w,onChange:$},s("keepClosed")),e.createElement(M,{className:"connections-filter dangerous",onClick:p,type:"close-all",size:20})),F.length>1&&e.createElement(sn,{devices:F,selected:J,onChange:me}),e.createElement(G,{ref:r,className:"connections-card relative"},e.createElement("div",{className:"overflow-auto min-h-full min-w-full"},e.createElement("table",N({},z.getTableProps()),e.createElement("thead",null,e.createElement("tr",I(N({},V.getHeaderGroupProps()),{className:"connections-header"}),ae)),e.createElement("tbody",N({},z.getTableBodyProps()),C)))),e.createElement(Qe,{title:s("closeAll.title"),show:h,onClose:f,onOk:d},s("closeAll.content")),e.createElement(nn,{containerRef:r,bodyClassName:"flex flex-col",visible:H.visible,width:450},e.createElement("div",{className:"flex h-8 justify-between items-center"},e.createElement("span",{className:"font-bold pl-3"},s("info.title")),e.createElement(M,{type:"close",size:16,className:"cursor-pointer",onClick:()=>L("visible",!1)})),e.createElement(on,{className:"mt-3 px-5",connection:H.connection}),e.createElement("div",{className:"flex mt-3 pr-3 justify-end"},e.createElement(ye,{type:"danger",disiabled:H.connection.completed,onClick:()=>de()},s("info.closeConnection")))))}function mn(){const{translation:n}=k(),{t}=n("Settings"),{hostname:s,port:o,secret:a}=oe(),[l,r]=_(ke),[c,i]=le({hostname:"",port:"",secret:""});m.exports.useEffect(()=>{i({hostname:s,port:o,secret:a})},[s,o,a,i]);const h=be(We);function p(){const{hostname:f,port:d,secret:E}=c;h([{hostname:f,port:d,secret:E}])}return e.createElement(Qe,{show:!l,title:t("externalControllerSetting.title"),bodyClassName:"external-controller",onClose:()=>r(!0),onOk:p},e.createElement(Zt,{type:"info",inside:!0},e.createElement("p",null,t("externalControllerSetting.note"))),e.createElement("div",{className:"flex items-center"},e.createElement("span",{className:"font-bold my-1 w-14 md:my-3"},t("externalControllerSetting.host")),e.createElement(ee,{className:"flex-1 my-1 md:my-3",align:"left",inside:!0,value:c.hostname,onChange:f=>i("hostname",f),onEnter:p})),e.createElement("div",{className:"flex items-center"},e.createElement("div",{className:"font-bold my-1 w-14 md:my-3"},t("externalControllerSetting.port")),e.createElement(ee,{className:"flex-1 my-1 w-14 md:my-3",align:"left",inside:!0,value:c.port,onChange:f=>i("port",f),onEnter:p})),e.createElement("div",{className:"flex items-center"},e.createElement("div",{className:"font-bold my-1 w-14 md:my-3"},t("externalControllerSetting.secret")),e.createElement(ee,{className:"flex-1 my-1 w-14 md:my-3",align:"left",inside:!0,value:c.secret,onChange:f=>i("secret",f),onEnter:p})))}const dn=[{label:"Default",value:""},{label:"Debug",value:"debug"},{label:"Info",value:"info"},{label:"Warn",value:"warning"},{label:"Error",value:"error"},{label:"Silent",value:"silent"}],pn=new Map([["debug","text-teal-500"],["info","text-sky-500"],["warning","text-pink-500"],["error","text-rose-500"]]);function fn(){var p,f;const n=m.exports.useRef(null),t=m.exports.useRef([]),[s,o]=m.exports.useState([]),{translation:a}=k(),{data:{logLevel:l},set:r}=ce(),{t:c}=a("Logs"),i=Ye(),h=m.exports.useRef((f=(p=n.current)==null?void 0:p.scrollHeight)!=null?f:0);return m.exports.useLayoutEffect(()=>{var E;const d=n.current;d!=null&&h.current===d.scrollTop+d.clientHeight&&(d.scrollTop=d.scrollHeight-d.clientHeight),h.current=(E=d==null?void 0:d.scrollHeight)!=null?E:0}),m.exports.useEffect(()=>{function d(E){t.current=t.current.slice().concat(E.map(v=>I(N({},v),{time:new Date}))),o(t.current)}return i!=null&&(i.subscribe("data",d),t.current=i.buffer(),o(t.current)),()=>i==null?void 0:i.unsubscribe("data",d)},[i]),e.createElement("div",{className:"page"},e.createElement(q,{title:c("title")},e.createElement("span",{className:"text-sm text-primary-darken mr-2"},c("levelLabel"),":"),e.createElement(Kt,{options:dn,value:wt(l),onSelect:d=>r(E=>{E.logLevel=d})})),e.createElement(G,{className:"flex flex-col flex-1 mt-2.5 md:mt-4"},e.createElement("ul",{className:"logs-panel",ref:n},s.map((d,E)=>e.createElement("li",{className:"leading-5 inline-block text-[11px]",key:E},e.createElement("span",{className:"mr-2 text-orange-400"},"[",Pe(d.time).format("YYYY-MM-DD HH:mm:ss"),"]"),e.createElement("span",{className:pn.get(d.type)},"[",d.type.toUpperCase(),"]"),e.createElement("span",null," ",d.payload))))))}var xe=(n=>(n.SPEED_NOTIFY="speed-notify",n))(xe||{});class En{constructor(){this.EE=new Me}notifySpeedTest(){this.EE.emit("speed-notify")}subscribe(t,s){this.EE.addListener(t,s)}unsubscribe(t,s){this.EE.removeListener(t,s)}}var ge=new En;const Ie={"#909399":0,"#00c520":260,"#ff9a28":600,"#ff3e5e":1/0};function tt(n){const{config:t,className:s}=n,{set:o}=ie(),a=B(),l=m.exports.useCallback(async f=>{var E;if(te())return(E=await(P==null?void 0:P.getProxyDelay(f)))!=null?E:0;const{data:{delay:d}}=await a.getProxyDelay(f);return d},[a]),r=m.exports.useCallback(async function(){const f=await He.fromPromise(l(t.name),E=>E),d=f.isErr()?0:f.value;o(E=>{const v=E.proxies.find(w=>w.name===t.name);v!=null&&v.history.push({time:Date.now().toString(),delay:d})})},[t.name,l,o]),c=m.exports.useMemo(()=>{var f;return(f=t.history)!=null&&f.length?t.history.slice(-1)[0].delay:0},[t]);m.exports.useLayoutEffect(()=>{const f=()=>{r()};return ge.subscribe(xe.SPEED_NOTIFY,f),()=>ge.unsubscribe(xe.SPEED_NOTIFY,f)},[r]);const i=m.exports.useMemo(()=>c===0,[c]),h=m.exports.useMemo(()=>Object.keys(Ie).find(f=>c<=Ie[f]),[c]),p=i?void 0:h;return e.createElement("div",{className:g("proxy-item",{"proxy-error":i},s)},e.createElement("span",{className:"proxy-type",style:{backgroundColor:p}},t.type),e.createElement("p",{className:"proxy-name"},t.name),e.createElement("p",{className:"proxy-delay"},c===0?"-":`${c}ms`))}function hn(n){const{markProxySelected:t}=ie(),[s]=_(_t),{data:o}=ce(),a=B(),{config:l}=n;async function r(h){if(await a.changeProxySelected(n.config.name,h),t(n.config.name,h),o.breakConnections){const p=[],f=await a.getConnections();for(const d of f.data.connections)d.chains.includes(n.config.name)&&p.push(d.id);await Promise.all(p.map(d=>a.closeConnection(d)))}}const c=m.exports.useMemo(()=>{var p;const h=new Set;for(const f of l.all){const d=(p=s.get(f))==null?void 0:p.history;(d==null?void 0:d.length)&&d.slice(-1)[0].delay===0&&h.add(f)}return h},[l.all,s]),i=l.type==="Selector";return e.createElement("div",{className:"proxy-group"},e.createElement("div",{className:"flex h-10 mt-4 w-full items-center justify-between md:h-15 md:mt-0 md:w-auto "},e.createElement("span",{className:"h-6 px-5 w-35 overflow-hidden overflow-ellipsis whitespace-nowrap md:w-30"},l.name),e.createElement(re,{className:"mr-5 md:mr-0"},l.type)),e.createElement("div",{className:"flex-1 py-2 md:py-4"},e.createElement(qt,{className:"ml-5 md:ml-8",data:l.all,onClick:r,errSet:c,select:l.now,canClick:i,rowHeight:30})))}function yn(n){const{update:t}=Xe(),{translation:s,lang:o}=k(),a=B(),{provider:l}=n,{t:r}=s("Proxies"),{visible:c,hide:i,show:h}=Fe();function p(){h(),a.healthCheckProvider(l.name).then(async()=>await t()).finally(()=>i())}function f(){h(),a.updateProvider(l.name).then(async()=>await t()).finally(()=>i())}const d=m.exports.useMemo(()=>l.proxies.slice().sort((E,v)=>-1*ve(E,v)),[l.proxies]);return e.createElement(G,{className:"proxy-provider"},e.createElement(et,{visible:c}),e.createElement("div",{className:"flex flex-col justify-between md:flex-row md:items-center "},e.createElement("div",{className:"flex items-center"},e.createElement("span",{className:"mr-6"},l.name),e.createElement(re,null,l.vehicleType)),e.createElement("div",{className:"flex pt-3 items-center md:pt-0"},l.updatedAt&&e.createElement("span",{className:"text-sm"},`${r("providerUpdateTime")}: ${Ae(new Date(l.updatedAt),o)}`),e.createElement(M,{className:"cursor-pointer text-red pl-5",type:"healthcheck",size:18,onClick:p}),e.createElement(M,{className:"cursor-pointer pl-5",type:"update",size:18,onClick:f}))),e.createElement("ul",{className:"proxies-list"},d.map(E=>e.createElement("li",{key:E.name},e.createElement(tt,{className:"proxy-provider-item",config:E})))))}const xn={[0]:"sort",[1]:"sort-ascending",[2]:"sort-descending"};function ve(n,t){const s=n.history.length>0?n.history.slice(-1)[0].delay:0;return((t.history.length>0?t.history.slice(-1)[0].delay:0)||Number.MAX_SAFE_INTEGER)-(s||Number.MAX_SAFE_INTEGER)}function gn(){const{groups:n,global:t}=ie(),{data:s,set:o}=ce(),{general:a}=De(),{translation:l}=k(),{t:r}=l("Proxies"),c=m.exports.useMemo(()=>a.mode==="global"?[t,...n]:n,[a,n,t]);return e.createElement(e.Fragment,null,c.length!==0&&e.createElement("div",{className:"flex flex-col"},e.createElement(q,{title:r("groupTitle")},e.createElement(Ze,{className:"cursor-pointer text-sm text-shadow-primary text-primary-600",checked:s.breakConnections,onChange:i=>o("breakConnections",i)},r("breakConnectionsText"))),e.createElement(G,{className:"my-2.5 p-0 md:my-4"},e.createElement("ul",{className:"list-none divide-y divide-gray-300"},c.map(i=>e.createElement("li",{key:i.name},e.createElement(hn,{config:i})))))))}function vn(){const{providers:n}=Xe(),{translation:t}=k(),{t:s}=t("Proxies");return e.createElement(e.Fragment,null,n.length!==0&&e.createElement("div",{className:"flex flex-col"},e.createElement(q,{title:s("providerTitle")}),e.createElement("ul",{className:"list-none"},n.map(o=>e.createElement("li",{className:"my-2.5 md:my-4",key:o.name},e.createElement(yn,{provider:o}))))))}function wn(){const{proxies:n}=ie(),{translation:t}=k(),{t:s}=t("Proxies");function o(){ge.notifySpeedTest()}const{current:a,next:l}=en([1,2,0]),r=m.exports.useMemo(()=>{switch(a){case 2:return n.slice().sort((i,h)=>ve(i,h));case 1:return n.slice().sort((i,h)=>-1*ve(i,h));default:return n.slice()}},[a,n]),c=l;return e.createElement(e.Fragment,null,r.length!==0&&e.createElement("div",{className:"flex flex-col"},e.createElement(q,{title:s("title")},e.createElement(M,{className:"ml-3",type:xn[a],onClick:c,size:20}),e.createElement(M,{className:"ml-3",type:"speed",size:20}),e.createElement("span",{className:"proxies-speed-test",onClick:o},s("speedTestText"))),e.createElement("ul",{className:"proxies-list"},r.map(i=>e.createElement("li",{key:i.name},e.createElement(tt,{config:i}))))))}function Cn(){return e.createElement("div",{className:"page"},e.createElement(gn,null),e.createElement(vn,null),e.createElement(wn,null))}function bn(n){const{update:t}=Ve(),{translation:s,lang:o}=k(),a=B(),{provider:l}=n,{t:r}=s("Rules"),{visible:c,hide:i,show:h}=Fe();function p(){h(),a.updateRuleProvider(l.name).then(async()=>await t()).finally(()=>i())}const f=g("rule-provider-icon",{"rule-provider-loading":c});return e.createElement("div",{className:"rule-provider"},e.createElement("div",{className:"rule-provider-header"},e.createElement("div",{className:"rule-provider-header-part"},e.createElement("span",{className:"rule-provider-name"},l.name),e.createElement(re,null,l.vehicleType),e.createElement(re,{className:"rule-provider-behavior"},l.behavior),e.createElement("span",{className:"rule-provider-update"},`${r("ruleCount")}: ${l.ruleCount}`)),e.createElement("div",{className:"rule-provider-header-part"},l.updatedAt&&e.createElement("span",{className:"rule-provider-update"},`${r("providerUpdateTime")}: ${Ae(new Date(l.updatedAt),o)}`),e.createElement(M,{className:f,type:"update",size:18,onClick:p}))))}function Nn(){const{providers:n}=Ve(),{translation:t}=k(),{t:s}=t("Rules");return e.createElement(e.Fragment,null,n.length!==0&&e.createElement("div",{className:"flex flex-col"},e.createElement(q,{title:s("providerTitle")}),e.createElement(G,{className:"divide-y rounded shadow-primary mt-4 p-0"},n.map(o=>e.createElement(bn,{key:o.name,provider:o})))))}function Pn(){const{rules:n,update:t}=Vt(),{translation:s}=k(),{t:o}=s("Rules");Q("rules",t);function a({index:l,style:r}){const c=n[l];return e.createElement("li",{className:"rule-item",style:r},e.createElement("div",{className:"flex py-1"},e.createElement("div",{className:"text-center w-40 rule-type"},c.type),e.createElement("div",{className:"flex-1 text-center payload"},c.payload),e.createElement("div",{className:"text-center w-40 rule-proxy"},c.proxy)))}return e.createElement("div",{className:"page"},e.createElement(Nn,null),e.createElement(q,{className:"not-first:mt-7.5",title:o("title")}),e.createElement(G,{className:"flex flex-col flex-1 mt-2.5 p-0 md:mt-4 focus:outline-none"},e.createElement(Ct,{className:"min-h-120"},({height:l,width:r})=>e.createElement(bt,{height:l,width:r,itemCount:n.length,itemSize:50},a))))}const Sn=[{label:"\u4E2D\u6587",value:"zh_CN"},{label:"English",value:"en_US"}];function kn(){var X,ne,ae;const{premium:n}=Ge(),{data:t,update:s}=Ke(),{general:o,update:a}=De(),l=be(ke),r=oe(),{translation:c,setLang:i,lang:h}=k(),{t:p}=c("Settings"),f=B(),[d,E]=le({socks5ProxyPort:7891,httpProxyPort:7890,mixedProxyPort:0});m.exports.useEffect(()=>{var C,u,b;E("socks5ProxyPort",(C=o==null?void 0:o.socksPort)!=null?C:0),E("httpProxyPort",(u=o==null?void 0:o.port)!=null?u:0),E("mixedProxyPort",(b=o==null?void 0:o.mixedPort)!=null?b:0)},[o,E]);async function v(C){await f.updateConfig({mode:C}),await a()}async function w(C){await(P==null?void 0:P.setStartAtLogin(C)),await s()}async function $(C){await(P==null?void 0:P.setSystemProxy(C)),await s()}function D(C){i(C)}async function F(){await f.updateConfig({port:d.httpProxyPort}),await a()}async function S(){await f.updateConfig({"socks-port":d.socks5ProxyPort}),await a()}async function A(){await f.updateConfig({"mixed-port":d.mixedProxyPort}),await a()}async function Z(C){await f.updateConfig({"allow-lan":C}),await a()}const{hostname:z,port:V}=r,{allowLan:J,mode:ue}=o,me=(X=t==null?void 0:t.startAtLogin)!=null?X:!1,H=(ne=t==null?void 0:t.systemProxy)!=null?ne:!1,L=(ae=t==null?void 0:t.isClashX)!=null?ae:!1,de=m.exports.useMemo(()=>{const C=[{label:p("values.global"),value:"Global"},{label:p("values.rules"),value:"Rule"},{label:p("values.direct"),value:"Direct"}];return n&&C.push({label:p("values.script"),value:"Script"}),C},[p,n]);return e.createElement("div",{className:"page"},e.createElement(q,{title:p("title")}),e.createElement(G,{className:"settings-card"},e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.startAtLogin")),e.createElement(fe,{disabled:!(t!=null&&t.isClashX),checked:me,onChange:w})),e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.language")),e.createElement(Te,{options:Sn,value:h,onSelect:C=>D(C)}))),e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.setAsSystemProxy")),e.createElement(fe,{disabled:!L,checked:H,onChange:$})),e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.allowConnectFromLan")),e.createElement(fe,{checked:J,onChange:Z})))),e.createElement(G,{className:"settings-card"},e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.proxyMode")),e.createElement(Te,{options:de,value:Nt(ue),onSelect:v})),e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.socks5ProxyPort")),e.createElement(ee,{className:"w-28",disabled:L,value:d.socks5ProxyPort,onChange:C=>E("socks5ProxyPort",+C),onBlur:S}))),e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.httpProxyPort")),e.createElement(ee,{className:"w-28",disabled:L,value:d.httpProxyPort,onChange:C=>E("httpProxyPort",+C),onBlur:F})),e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.mixedProxyPort")),e.createElement(ee,{className:"w-28",disabled:L,value:d.mixedProxyPort,onChange:C=>E("mixedProxyPort",+C),onBlur:A}))),e.createElement("div",{className:"flex flex-wrap"},e.createElement("div",{className:"flex w-full py-3 px-8 items-center justify-between md:w-1/2"},e.createElement("span",{className:"font-bold label"},p("labels.externalController")),e.createElement("span",{className:g({"modify-btn":!L},"external-controller"),onClick:()=>!L&&l(!1)},`${z}:${V}`)),e.createElement("div",{className:"px-8 w-1/2"}))))}var Dn="./assets/logo.b453e72f.png";function Fn(n){const{routes:t}=n,{translation:s}=k(),{version:o,premium:a}=Ge(),{data:l}=Ke(),{t:r}=s("SideBar"),c=Ce(),i=t.map(({path:h,name:p,noMobile:f})=>e.createElement("li",{className:g("item",{"no-mobile":f}),key:p},e.createElement(Pt,{to:{pathname:h,search:c.search},className:({isActive:d})=>g({active:d})},r(p))));return e.createElement("div",{className:"sidebar"},e.createElement("img",{src:Dn,alt:"logo",className:"sidebar-logo"}),e.createElement("ul",{className:"sidebar-menu"},i),e.createElement("div",{className:"sidebar-version"},e.createElement("span",{className:"sidebar-version-label"},"Clash",(l==null?void 0:l.isClashX)&&"X"," ",r("Version")),e.createElement("span",{className:"sidebar-version-text"},o),a&&e.createElement("span",{className:"sidebar-version-label"},"Premium")))}function An(){Ye();const n=Ce(),t=[{path:"/proxies",name:"Proxies",element:e.createElement(Cn,null)},{path:"/logs",name:"Logs",element:e.createElement(fn,null)},{path:"/rules",name:"Rules",element:e.createElement(Pn,null),noMobile:!0},{path:"/connections",name:"Connections",element:e.createElement(un,null),noMobile:!0},{path:"/settings",name:"Settings",element:e.createElement(kn,null)}],s=e.createElement("div",{className:g("app",{"not-clashx":!te()})},e.createElement(Fn,{routes:t}),e.createElement("div",{className:"page-container"},e.createElement(St,null)),e.createElement(mn,null));return e.createElement(kt,null,e.createElement(pe,{path:"/",element:s},e.createElement(pe,{path:"/",element:e.createElement(Dt,{to:{pathname:"/proxies",search:n.search},replace:!0})}),t.map(o=>e.createElement(pe,{path:o.path,key:o.path,element:o.element}))))}function Be(){const n=document.getElementById("root"),t=e.createElement(m.exports.StrictMode,null,e.createElement(At,null,e.createElement(m.exports.Suspense,{fallback:e.createElement(et,{visible:!0})},e.createElement(An,null))));Ft(n).render(t)}te()?Rt(()=>Be()):Be();
|