var ie=Object.defineProperty;var ue=(i,u,g)=>u in i?ie(i,u,{enumerable:!0,configurable:!0,writable:!0,value:g}):i[u]=g;var e=(i,u,g)=>ue(i,typeof u!="symbol"?u+"":u,g);import{Y as le,b as W,a as de}from"./DeZP0Ku-.js";import{u as j}from"./B1vCTw51.js";import{u as J}from"./C4eI3NdQ.js";import{p as Q}from"./Cs-ImY69.js";import{W as pe,ay as fe}from"./CFkWy_uK.js";import{u as me}from"./CnR9GRLV.js";const he=()=>{const i=_=>{try{if(u(_))return le.parse(_)}catch{}},u=_=>!!(_&&_.includes(`
`)&&_.split(`
`).filter(y=>y).filter(y=>y.trim()).every(y=>y.includes("#")||y.includes(":")||y.includes(" - ")||y.includes("#")));return{isYaml:u,isValid:_=>!!i(_),toObj:i}};function we(){function i(g){if(!g)return!1;try{JSON.parse(g)}catch{return!1}return!0}function u(g){if(g)try{return JSON.parse(g)}catch{}}return{isJson:i,toJson:u}}function ye(){function i(u){if(u)return Number.parseInt(u)}return{strToInt:i}}const L=()=>{const i=(s,r,n,f)=>{n(s===r?f:s)},u=(s,r,n)=>{if(n!==void 0)return s[r]=n,s},g=(s,r,n)=>{const f=s.get(r);f&&n(f)},_=(s,r,n,f,p)=>{s.has(r)?n[f]=s.get(r):p&&(n[f]=p)},y=(s,r)=>{const n=s.get(r);if(n)return n},S=(s,r,n,f,p)=>{const w=r.map(k=>s.get(k)).filter(k=>k);w.length!==0?n[f]=w[0]:n[f]=p},x=(s,r)=>{const n=s.getAll(r);if(n.length!==0)return n},N=(s,...r)=>{for(const n of r)for(const f of Object.keys(n)){const p=n[f];p!==void 0&&(s[f]=p)}return s};function R(s,r,n){return s.some(p=>p===r)?r:n||"dummy"}const P=s=>s.includes("/?")?s.replace("/?","?"):s,$=(s,r,n)=>s?r:n,b=(s,r,n)=>{s&&Object.keys(s).length!==0&&(r[n]=s)};function h(s){return!!(s&&Object.keys(s).length!==0&&JSON.stringify(s)!=="{}")}const d=s=>s&&s.includes("#")?decodeURIComponent(s.split("#")[1]):"default_name",l=s=>s&&s.includes("#")?s.split("#")[0]:s;function c(s){if(h(s))return s}function a(s,r,n,f){return n&&n!=="undefined"?`${s}${r}=${n}`:f?`${s}${r}=${f}`:""}function o(s,r,n,f){n.has(f)&&(s[r]=n.get(f))}function t(s,r,n=""){const f=s();f?r(f):n&&r(n)}return{ifEqualGetPredictElseDefault:$,isNotNullGetString:a,ifObjectNotEmptySet:b,urlMultipleVal:S,urlArray:x,funcSet:t,ifNotEmptySet:o,excludeName:l,getShareName:d,ifContainsOrDefault:R,ifEqualDefaultOrVal:i,ifParamNotNullSet:u,ifOptNotEmptySet:c,searchAndSet:_,urlGetAndSet:g,quesReplace:P,objectCopy:N,urlGet:y}};var C=(i=>(i.VMESS="vmess",i.VLESS="vless",i.TROJAN="trojan",i.HYSTERIA2="hysteria2",i.HYSTERIA="hysteria",i.HY="hy",i.TUIC="tuic",i.SS="ss",i.SSR="ssr",i.SOCKS5="socks5",i.HTTP="http",i.HTTPS="https",i))(C||{});class D{constructor(){e(this,"custom");e(this,"host");e(this,"connection")}}class v{constructor(){e(this,"path");e(this,"headers");e(this,"max-early-data");e(this,"early-data-header-name")}}class oe{constructor(){e(this,"grpc-service-name")}}class _e{constructor(){e(this,"public-key");e(this,"short-id")}}class ne{constructor(){e(this,"mode");e(this,"host");e(this,"path");e(this,"mux")}}class be extends ne{}class ge extends ne{constructor(){super(...arguments);e(this,"tls");e(this,"fingerprint");e(this,"skip-cert-verify");e(this,"headers");e(this,"v2ray-http-upgrade")}}class E{constructor(){e(this,"id");e(this,"name");e(this,"port");e(this,"server");e(this,"type");e(this,"network");e(this,"tls");e(this,"udp");e(this,"sni");e(this,"obfs");e(this,"version");e(this,"servername");e(this,"username");e(this,"password");e(this,"protocol");e(this,"skip-cert-verify");e(this,"http-opts");e(this,"h2-opts");e(this,"ws-opts");e(this,"grpc-opts");e(this,"reality-opts");e(this,"ports");e(this,"auth-str");e(this,"up");e(this,"down");e(this,"recv-window-conn");e(this,"recv-window");e(this,"ca");e(this,"ca-str");e(this,"disable_mtu_discovery");e(this,"fast-open");e(this,"obfs-password");e(this,"private-key");e(this,"private-key-passphrase");e(this,"host-key");e(this,"host-key-algorithms");e(this,"public-key");e(this,"allowed-ips");e(this,"pre-shared-key");e(this,"reserved");e(this,"mtu");e(this,"dialer-proxy");e(this,"remote-dns-resolve");e(this,"dns");e(this,"peers");e(this,"token");e(this,"ip");e(this,"ipv6");e(this,"heartbeat-interval");e(this,"disable-sni");e(this,"reduce-rtt");e(this,"request-timeout");e(this,"udp-relay-mode");e(this,"congestion-controller");e(this,"max-udp-relay-packet-size");e(this,"max-open-streams");e(this,"packet-encoding");e(this,"global-padding");e(this,"authenticated-length");e(this,"alpn");e(this,"udp-over-tcp");e(this,"udp-over-tcp-version");e(this,"ip-version");e(this,"smux");e(this,"plugin");e(this,"plugin-opts");e(this,"cipher");e(this,"uuid");e(this,"alterId");e(this,"flow");e(this,"fingerprint");e(this,"client-fingerprint");e(this,"group");e(this,"obfsparam");e(this,"protocol-param")}valid(){return this.server&&this.type&&this.port!==void 0}static fromVPN(u){return Q(E,u)}singBoxNetwork(){return this.network==="h2"?"http":this.network==="tcp"?void 0:this.network}}const Se=()=>{const{subBefore:i,subBetween:u,subAfter:g,replaceQues:_}=j(),{bDecode:y,bEncode:S}=J(),{toJson:x}=we(),{strToInt:N}=ye(),{urlGetAndSet:R,urlGet:P,ifParamNotNullSet:$,ifOptNotEmptySet:b,searchAndSet:h}=L(),d=o=>{const t={};if(t.ps=o.name||"",t.add=o.server||"",t.aid=o.alterId||0,t.id=o.uuid||"",t.net=o.network||"",t.scy=o.cipher,t.port=o.port||0,t.tls=o.tls?"tls":"",t.scy==="zero"&&(t.scy="auto"),o["ws-opts"]){const s=o["ws-opts"];t.path=s.path,t.net="ws",s.headers&&(t.host=s.headers.host,t.sni=s.headers.host)}if(o["h2-opts"]){const s=o["h2-opts"];t.path=s.path,t.net="h2",s.host&&(t.host=s.host.join(","))}if(o["grpc-opts"]){const s=o["grpc-opts"];t.net="tcp",t.path=s==null?void 0:s["grpc-service-name"]}return`vmess://${S(JSON.stringify(t))}`},l=o=>{const t=new E;t.type=C.VMESS;const s=y(o);if(s){const r=JSON.parse(s);t.name=r.ps,t.server=r.add;const n=r.scy;if(t.cipher=n==="zero"||!n?"auto":n,t.alterId=Number.parseInt(r.aid),t.uuid=r.id,t["skip-cert-verify"]=!0,t.network=r.net,t.port=Number.parseInt(r.port),t.tls=r.tls==="tls",t.version=r.v,t.servername=r.sni,t.network==="ws"){const f=new v;f.path=r.path,f.headers=$(new D,"host",r.host),t["ws-opts"]=b(f)}}else if(o.includes("@")&&o.includes(":"))if(o=_(o),o.includes("?")){const r=i(o,"?",!1);if(c(r,t),o.includes("#")){const n=u(o,"?","#");a(n,t),t.name=decodeURIComponent(g(o,"#",!0))}else{const n=g(o,"?",!1);a(n,t)}}else c(o,t);else if(o.includes("?")){const r=o.split("?"),n=y(r[0]);if(n&&n.includes("@")&&n.includes(":")){t.cipher=i(n,":",!1),t.uuid=u(n,":","@"),t.server=u(n,"@",":");const f=g(n,":",!0);f&&(t.port=Number.parseInt(f))}a(r[1],t)}return t},c=(o,t)=>{t.uuid=i(o,"@",!1),t.server=u(o,"@",":"),t.port=parseInt(g(o,":",!0))},a=(o,t)=>{const s=new URLSearchParams(o);R(s,"remarks",r=>t.name=decodeURIComponent(r)),R(s,"alterId",r=>t.alterId=N(r)),R(s,"peer",r=>t.servername=r),R(s,"obfs",r=>{if(r==="websocket"){const n=new v;n.path=P(s,"path"),R(s,"obfsParam",f=>{const p=decodeURIComponent(f),w=x(p);w?w.hasOwnProperty("host")?n.headers=$(new D,"host",w.host):w.hasOwnProperty("Host")&&(n.headers=$(new D,"host",w.Host)):n.headers=$(new D,"host",p)}),t["ws-opts"]=b(n)}}),R(s,"insecure",r=>{r==="1"&&(t["skip-cert-verify"]=!0)}),h(s,"encryption",t,"cipher","auto")};return{vMessVPN:l,vMessShare:d}},Ne=()=>{const{quesReplace:i,getShareName:u,excludeName:g,urlGet:_,urlArray:y}=L(),{subBefore:S,subBetween:x,subAfter:N}=j(),R=h=>{const d=new E;if(d.type=C.TUIC,h.includes("?")){h=i(h),d.name=u(h),h=g(h);const l=h.split("?");$(l[0],d),b(l[1],d)}return d},P=h=>{const d=new E;d.type=C.TUIC,d.name="default_name";const l=h.relay;d.password=l.password,d.uuid=l.uuid,d.sni=l.ip,d["congestion-controller"]=l.congestion_control,d.alpn=l.alpn;const c=l.server;if(c.includes(":")){const a=c.split(":");d.server=a[0],d.port=parseInt(a[1])}return d},$=(h,d)=>{d.password=S(h,":",!1),d.uuid=x(h,":","@"),d.server=x(h,"@",":"),d.port=parseInt(N(h,":",!0))},b=(h,d)=>{const l=new URLSearchParams(h);d["congestion-controller"]=_(l,"congestion_control"),d["udp-relay-mode"]=_(l,"udp_relay_mode"),d.sni=_(l,"sni"),d.alpn=y(l,"alpn")};return{tuicVPN:R,jsonVPN:P}},X="reject",G="direct",Y="proxy_dns",q="local_dns",Z="url-test",M="select",te="fake_ip",ae="dns_out",se="geosite-category-ads-all",re="geoip-cn",K="geosite-cn",z="geosite-geolocation-!cn";class ke{constructor(){e(this,"disabled",!1);e(this,"level","info");e(this,"output");e(this,"timestamp",!0)}}class xe{constructor(){e(this,"listen");e(this,"listen_port");e(this,"tcp_fast_open");e(this,"tcp_multi_path");e(this,"udp_fragment");e(this,"udp_timeout");e(this,"detour");e(this,"sniff");e(this,"sniff_override_destination");e(this,"sniff_timeout");e(this,"domain_strategy");e(this,"udp_disable_domain_unmapping")}}class Oe{constructor(){e(this,"enabled",!0);e(this,"fingerprint")}}class Re{constructor(){e(this,"enabled",!0);e(this,"public_key");e(this,"short_id")}}class $e extends xe{constructor(){super(...arguments);e(this,"type");e(this,"tag")}}class Ae{constructor(){e(this,"enabled",!0);e(this,"inet4_range","198.18.0.0/15");e(this,"inet6_range","fc00::/18")}}class ce{constructor(){e(this,"detour");e(this,"bind_interface");e(this,"inet4_bind_address");e(this,"inet6_bind_address");e(this,"routing_mark");e(this,"reuse_addr");e(this,"connect_timeout");e(this,"tcp_fast_open");e(this,"tcp_multi_path");e(this,"udp_fragment");e(this,"domain_strategy");e(this,"fallback_delay")}}class Ie extends ce{constructor(){super(...arguments);e(this,"enabled",!0);e(this,"server","time.apple.com");e(this,"server_port",123);e(this,"interval","30m");e(this,"detour",G)}}class T extends ce{constructor(){super(...arguments);e(this,"type");e(this,"tag");e(this,"server");e(this,"server_port")}}class Pe{constructor(){e(this,"enabled",!0);e(this,"path","cache.db");e(this,"cache_id");e(this,"store_fakeip");e(this,"store_rdrc");e(this,"rdrc_timeout")}}class Ee{constructor(){e(this,"external_controller","127.0.0.1:9090");e(this,"external_ui");e(this,"external_ui_download_url");e(this,"external_ui_download_detour");e(this,"secret");e(this,"default_mode")}}class Ce extends T{constructor(){super(...arguments);e(this,"type","direct");e(this,"tag",G);e(this,"override_address");e(this,"override_port");e(this,"proxy_protocol")}}class Ve{constructor(){e(this,"type");e(this,"host");e(this,"path");e(this,"method");e(this,"headers");e(this,"idle_timeout");e(this,"ping_timeout");e(this,"max_early_data");e(this,"early_data_header_name");e(this,"service_name");e(this,"permit_without_stream")}}class Te{constructor(){e(this,"type","salamander");e(this,"password")}}class je{constructor(){e(this,"enabled",!0);e(this,"protocol");e(this,"max_connections");e(this,"min_streams");e(this,"max_streams");e(this,"padding");e(this,"brutal")}}class Le extends $e{constructor(){super(...arguments);e(this,"type","tun");e(this,"interface_name");e(this,"inet4_address");e(this,"inet6_address");e(this,"mtu",9e3);e(this,"gso");e(this,"auto_route");e(this,"strict_route");e(this,"inet4_route_address");e(this,"inet6_route_address");e(this,"inet4_route_exclude_address");e(this,"inet6_route_exclude_address");e(this,"endpoint_independent_nat");e(this,"stack");e(this,"include_interface");e(this,"exclude_interface");e(this,"include_uid");e(this,"include_uid_range");e(this,"exclude_uid");e(this,"exclude_uid_range");e(this,"include_android_user");e(this,"include_package");e(this,"exclude_package");e(this,"platform")}}class H{constructor(){e(this,"enabled",!0);e(this,"disable_sni");e(this,"server_name");e(this,"insecure");e(this,"alpn");e(this,"min_version");e(this,"max_version");e(this,"cipher_suites");e(this,"certificate");e(this,"certificate_path");e(this,"ech");e(this,"utls");e(this,"reality")}}class Ue extends T{constructor(){super(...arguments);e(this,"type","socks");e(this,"version");e(this,"username");e(this,"password");e(this,"network");e(this,"udp_over_tcp")}}class Ge extends T{constructor(){super(...arguments);e(this,"type","shadowsocks");e(this,"method");e(this,"password");e(this,"plugin");e(this,"plugin_opts");e(this,"network");e(this,"udp_over_tcp");e(this,"multiplex")}}class De extends T{constructor(){super(...arguments);e(this,"type","vmess");e(this,"uuid");e(this,"security","auto");e(this,"alter_id",0);e(this,"global_padding");e(this,"authenticated_length");e(this,"network");e(this,"tls");e(this,"packet_encoding");e(this,"multiplex");e(this,"transport")}}class Be extends T{constructor(){super(...arguments);e(this,"type","trojan");e(this,"password");e(this,"network");e(this,"tls");e(this,"multiplex");e(this,"transport")}}class Me extends T{constructor(){super(...arguments);e(this,"type","vless");e(this,"uuid");e(this,"flow");e(this,"network");e(this,"tls");e(this,"packet_encoding");e(this,"multiplex");e(this,"transport")}}class He extends T{constructor(){super(...arguments);e(this,"type","tuic");e(this,"uuid");e(this,"password");e(this,"congestion_control","cubic");e(this,"udp_relay_mode");e(this,"udp_over_stream");e(this,"zero_rtt_handshake");e(this,"heartbeat");e(this,"network");e(this,"tls")}}class ve extends T{constructor(){super(...arguments);e(this,"type","hysteria2");e(this,"up_mbps");e(this,"down_mbps");e(this,"obfs");e(this,"password");e(this,"network");e(this,"tls");e(this,"brutal_debug")}}class Je extends T{constructor(){super(...arguments);e(this,"type","selector");e(this,"tag",M);e(this,"outbounds");e(this,"default");e(this,"interrupt_exist_connections")}}class Ye extends T{constructor(){super(...arguments);e(this,"type","urltest");e(this,"tag",Z);e(this,"outbounds");e(this,"url","https://www.gstatic.com/generate_204");e(this,"interval","3m");e(this,"tolerance",50);e(this,"idle_timeout");e(this,"interrupt_exist_connections")}}class qe extends T{constructor(){super(...arguments);e(this,"type","block");e(this,"tag",X)}}class ze extends T{constructor(){super(...arguments);e(this,"type","dns");e(this,"tag",ae)}}class Fe{constructor(){e(this,"type");e(this,"tag");e(this,"format")}}class We extends Fe{constructor(){super(...arguments);e(this,"type","remote");e(this,"url");e(this,"download_detour",M);e(this,"update_interval","1d")}}const F=(i,u,g="binary")=>{const _=new We;return _.tag=i,_.format=g,_.url=u,_};class Ke{constructor(){e(this,"servers");e(this,"rules");e(this,"final");e(this,"strategy");e(this,"disable_cache");e(this,"disable_expire");e(this,"independent_cache");e(this,"reverse_mapping");e(this,"client_subnet");e(this,"fakeip")}}class Qe{constructor(){e(this,"geoip");e(this,"geosite");e(this,"rules");e(this,"rule_set");e(this,"final");e(this,"auto_detect_interface");e(this,"override_android_vpn");e(this,"default_interface");e(this,"default_mark")}}class Xe{constructor(){e(this,"cache_file");e(this,"clash_api");e(this,"v2ray_api")}}class Ze{constructor(){e(this,"log");e(this,"dns");e(this,"ntp");e(this,"inbounds");e(this,"outbounds");e(this,"route");e(this,"experimental")}}const et=()=>{const{ifObjectNotEmptySet:i}=L(),u=(t,s="windows")=>{const r=t.map(p=>R(p)).filter(p=>p),n=r.map(p=>p.tag).filter(p=>p),f=new Ze;return g(f,r,n),JSON.stringify(f,null,2)},g=(t,s,r)=>{t.log=new ke,t.ntp=new Ie,t.dns=S(),t.inbounds=y(),t.outbounds=N(s,r),t.route=x(),t.experimental=_()},_=()=>{const t=new Xe;return t.cache_file=new Pe,t.clash_api=new Ee,t},y=()=>{const t=new Le;return t.inet4_address="172.16.0.1/30",t.inet6_address="2001:0470:f9da:fdfa::1/64",t.mtu=9e3,t.auto_route=!0,t.strict_route=!0,t.sniff=!0,t.sniff_override_destination=!0,t.domain_strategy="prefer_ipv4",t.endpoint_independent_nat=!0,[t]},S=()=>{const t=new Ke;t.fakeip=new Ae;const s={tag:Y,address:"tls://8.8.8.8/dns-query",detour:M},r={tag:q,address:"h3://223.5.5.5/dns-query",detour:G},n={tag:X,address:"rcode://refused"},f={tag:te,address:"fakeip"};t.servers=[s,r,n,f];const p={outbound:"any",server:q,disable_cache:!0},w={clash_mode:"Global",server:Y},k={clash_mode:"Direct",server:q},A={rule_set:K,server:q},m={rule_set:z,server:Y},O={rule_set:z,query_type:["A","AAAA"],server:te};return t.rules=[p,w,k,A,m,O],t.independent_cache=!0,t.final=Y,t},x=()=>{const t=new Qe,s=F(se,"https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-category-ads-all.srs"),r=F(re,"https://raw.githubusercontent.com/SagerNet/sing-geoip/rule-set/geoip-cn.srs"),n=F(K,"https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/geosite-cn.srs"),f=F(z,"https://cdn.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/geolocation-!cn.srs");t.rule_set=[r,n,f,s];const p={protocol:"dns",outbound:ae},w={clash_mode:"Global",outbound:M},k={clash_mode:"Direct",outbound:G},A={rule_set:se,outbound:X},m={rule_set:re,outbound:G},O={rule_set:K,outbound:G},V={ip_is_private:!0,outbound:G},I={rule_set:z,outbound:M};return t.rules=[w,k,p,A,m,O,V,I],t.auto_detect_interface=!0,t.final=M,t},N=(t,s)=>{const r=new Ce,n=new qe,f=new ze,p=new Ye;p.outbounds=s;const w=new Je;return w.default=Z,w.outbounds=[Z].concat(s),[w,p].concat(t).concat([r,n,f])},R=t=>{if(t&&t.type){const s=t.type.toString();let r;if(s==="ss"?r=P:s==="vmess"?r=$:s==="vless"?r=b:s==="trojan"?r=h:s==="hysteria2"?r=d:s==="tuic"?r=l:s==="ssr"||s==="socks5"&&(r=c),r){const n=r(t);if(n&&(n.server=t.server,n.server_port=t.port,n.tag=t.name,n.server))return n}}},P=t=>{const s=new Ge;s.method=t.cipher,s.password=t.password,s.plugin=t.plugin,s.method&&(s.multiplex=new je);const r=t["plugin-opts"];return r&&(s.plugin_opts=Object.keys(r).map(n=>`${n}=${r[n]}`).join(";")),s},$=t=>{const s=new De;if(s.uuid=t.uuid,s.security=t.cipher,s.alter_id=t.alterId,i(o(t),s,"transport"),t.tls){const r=new H;r.server_name=t.sni,i(r,s,"tls")}return s},b=t=>{const s=new Me;s.uuid=t.uuid,s.flow=t.flow;const r=new H,n=t["reality-opts"];if(n){const p=new Re;p.public_key=n["public-key"],p.short_id=n["short-id"],r.reality=p}const f=t["client-fingerprint"];if(f){const p=new Oe;p.fingerprint=f,r.utls=p}return i(r,s,"tls"),i(o(t),s,"transport"),s},h=t=>{const s=new Be;s.password=t.password;const r=new H;return r.alpn=t.alpn,r.server_name=t.servername,r.insecure=t["skip-cert-verify"],s.tls=r,i(o(t),s,"transport"),s},d=t=>{const s=new ve;if(s.password=t.password,t.alpn){const r=new H;r.alpn=t.alpn,s.tls=r}if(t.obfs==="salamander"){const r=new Te;r.password=t["obfs-password"],s.obfs=r}if(t.up&&typeof t.up=="string"){const r=t.up.toLowerCase();r.includes("mbs")&&(s.up_mbps=Number.parseInt(r.replace("mbs","").trim()))}if(t.down&&t.down==="string"){const r=t.down.toLowerCase();r.includes("mbs")&&(s.down_mbps=Number.parseInt(r.replace("mbs","").trim()))}return s},l=t=>{const s=new He;s.uuid=t.uuid;const r=a(t);return i(r,s,"tls"),s.congestion_control=t["congestion-controller"],s.udp_relay_mode=t["udp-relay-mode"],s.zero_rtt_handshake=t["reduce-rtt"],s},c=t=>{const s=new Ue;return s.username=t.username,s.password=t.password,s},a=t=>{if(t.alpn){const s=new H;return s.alpn=t.alpn,s.server_name=t.servername,s}},o=t=>{if(t.singBoxNetwork()){const s=new Ve;s.type=t.singBoxNetwork();const r=t["ws-opts"],n=t["grpc-opts"];return r?(s.path=r.path,s.early_data_header_name=r["early-data-header-name"],s.max_early_data=r["max-early-data"],s.headers=r.headers):n&&(s.service_name=n["grpc-service-name"]),s}};return{toSingBox:u}},ht=()=>{const{toProxy:i,toShare:u,isValidV2:g,allowType:_}=ct(),{randomStr:y}=j(),{warning:S}=pe(),{isValid:x,toObj:N}=he(),{strToArray:R,isNotEmpty:P,isArray:$}=W(),{bValid:b,bDecode:h,bEncode:d,validBase64:l}=J(),{getClashTemplate:c}=de(),{toSingBox:a}=et(),{t:o}=fe(),{selectedRef:t}=me(),s=w=>{var A;let k;if(l(w)&&(w=h(w)),g(w))k=f(w);else if($(w))k=Q(E,w);else{const m=N(w);m&&((A=m.proxies)==null?void 0:A.length)!==0&&(k=Q(E,m.proxies))}return k&&k.length!==0&&k.filter(m=>!m.id).forEach(m=>m.id=y(10)),k},r=async(w,k="clash",A="windows")=>{let m;const O=s(w);if(O){O.map(I=>(I.name||(I.name="defaultName"),I)).forEach(I=>{I.name.includes("\r")&&(I.name=I.name.replace("\r","")),I.udp=!0});const V=[...new Set(O.map(I=>I.name).filter((I,B,U)=>U.indexOf(I)!==B))].map(I=>({value:I,index:1}));if(V&&V.length!==0&&O.forEach(I=>{const B=V.find(U=>U.value===I.name);B&&(I.name=`${I.name}_${B.index++}`),I.udp=!0}),k==="mihomo")m=(await c()).toConfig(O,!1,t);else if(k==="clash"){const I=await c(),B=O.filter(U=>U.type!=="vless");O.some(U=>U.type==="vless")&&setTimeout(()=>{S(o("tip.mihohoCheck"))},1e3),m=I.toConfig(B,!1,t)}else k==="v2ray"?m=u(O):k==="singbox"?m=a(O,A):k==="base64"&&(typeof w=="string"?m=d(w):m=d(u(O)))}return m};function n(w){return w.v2ray?w.v2ray:u([w])}const f=w=>i(w);return{vpnToV2ray:n,hasValidNode:w=>{if(w){if(b(w)&&(w=h(w)),x(w))return N(w).proxies;const k=R(w);if(P(k)){const A=k.filter(m=>_.some(O=>m.startsWith(O))).join(`
`);return f(A)}}},convert:r,toVPN:s}},ee=()=>{const{subAfter:i}=j();return{shadowSocksEncryptMethods:["aes-128-gcm","aes-192-gcm","aes-256-gcm","aes-128-cfb","aes-192-cfb","aes-256-cfb","aes-128-ctr","aes-192-ctr","aes-256-ctr","rc4-md5","chacha20-ietf","xchacha20","xchacha20-ietf-poly1305","chacha20-ietf-poly1305"],shadowSocksREncryptMethods:["aes-128-cfb","aes-192-cfb","aes-256-cfb","aes-128-ctr","aes-192-ctr","aes-256-ctr","rc4-md5","chacha20-ietf","xchacha20"],shadowSocksRObfses:["plain","http_simple","http_post","random_head","tls1.2_ticket_auth","tls1.2_ticket_fastauth"],shadowSocksRProtocols:["origin","auth_sha1_v4","auth_aes128_md5","auth_aes128_sha1","auth_chain_a","auth_chain_b"],vmessCipher:["auto","aes-128-gcm","chacha20-poly1305","none"],vpnName:N=>{if(N=decodeURIComponent(N),N.includes("#"))return i(N,"#",!0)}}},tt=()=>{const{quesReplace:i,urlGet:u,urlMultipleVal:g,isNotNullGetString:_,ifOptNotEmptySet:y}=L(),{isNotEmpty:S}=W(),{vpnName:x}=ee(),{subBefore:N,subBetween:R,notEmpty:P,shareAfterSub:$,subAfterNumber:b}=j(),h=a=>{const o=new E;if(o.type=C.TROJAN,o.name=x(a),a.includes("?")){a=i(a);const t=N(a,"?",!1);c(t,o);const s=$(a);l(s,o)}else c(a,o);return o.udp=!0,o},d=a=>{var n;const o=`${a.password}@${a.server}:${a.port}`;let t="";P(a.network)?t+=`?type=${a.network}`:t+="?type=tcp&security=tls",t+=_("&","sni",a.sni),a["skip-cert-verify"]&&(t+="&allowInsecure=1");const s=a["ws-opts"];if(s){t+=_("&","path",s.path);const f=s.headers;f&&(t+=_("&","host",f.host))}S(a.alpn)&&(t+=(n=a.alpn)==null?void 0:n.join(","));const r=a["grpc-opts"];return r&&(t+=_("&","serviceName",r["grpc-service-name"])),`trojan://${o}${t}#${encodeURIComponent(a.name?a.name:"default_name")}`},l=(a,o)=>{const t=new URLSearchParams(a),s=u(t,"alpn");if(s&&(o.alpn=[s]),o.network=u(t,"type"),u(t,"path"),o.network==="grpc"){const r=new oe;r["grpc-service-name"]=u(t,"serviceName"),o["grpc-opts"]=y(r)}else if(o.network==="ws"){const r=new v;r.path=u(t,"path"),r.path&&!r.path.startsWith("/")&&(r.path=`/${r.path}`);const n=new D;n.host=u(t,"host"),r.headers=y(n),o["ws-opts"]=y(r)}return o["skip-cert-verify"]=u(t,"allowInsecure")==="1",o["client-fingerprint"]=u(t,"fp"),g(t,["sni","peer"],o,"sni"),o},c=(a,o)=>(a.includes("@")&&a.includes(":")&&(o.password=N(a,"@",!0),o.server=R(a,"@",":"),o.port=b(a,":",!0)),o);return{trojanVPN:h,trojanShare:d}},st=()=>{const{objectCopy:i,urlGet:u,ifOptNotEmptySet:g,ifEqualGetPredictElseDefault:_,isNotNullGetString:y}=L(),{subBefore:S,subBetween:x,subAfter:N,shareAfterSub:R,ipv6:P}=j(),{bDecode:$}=J(),b=c=>{let a=new E;if(a.type=C.VLESS,c=decodeURIComponent(c),c&&c.includes("#")&&(a.name=N(c,"#",!0),c=S(c,"#",!0)),c.includes("?")){const o=S(c,"?",!1),t=l(o),s=d(R(c));a=i(a,t,s)}return a.port===443&&(a.tls=!0),a},h=c=>{var t,s;const a=`${c.uuid}@${P(c.server)}:${c.port}`;let o="";if(c.tls?c["reality-opts"]?o+="?security=reality":o+="?security=tls":o+="?security=none",o+=y("&","flow",c.flow),o+=y("&","type",c.network),o+=y("&","sni",c.servername),o+=y("&","host",(s=(t=c["ws-opts"])==null?void 0:t.headers)==null?void 0:s.host),o+=y("&","encryption",c.cipher,"none"),o+=y("&","fp",c["client-fingerprint"]),c.alpn&&(o+=y("&","alpn",c.alpn.join(","))),c["reality-opts"]){const r=c["reality-opts"];o+=y("&","pbk",r==null?void 0:r["public-key"]),o+=y("&","sid",r==null?void 0:r["short-id"])}if(c["ws-opts"]){o+="&type=ws";const r=c["ws-opts"],n=r.headers;r.path&&(o+=y("&","path",encodeURIComponent(r.path))),n&&!o.includes("sni")&&(o+=y("&","sni",n.host))}return o+="&headerType=none",`vless://${a}${o}#${encodeURIComponent(c.name?c.name:"default_name")}`},d=c=>{const a=new E,o=new URLSearchParams(c);a.flow=u(o,"flow"),a.network=u(o,"type"),a.servername=u(o,"sni");const t=u(o,"alpn");t&&(a.alpn=[t]);const s=u(o,"remarks");s&&(a.name=s),a["client-fingerprint"]=u(o,"fp");const r=u(o,"obfs");if(r&&r==="websocket"){const p=new v,w=u(o,"obfsParam");if(w){const k=new D;k.host=w,p.headers=k}p.path=u(o,"path"),a.servername=u(o,"peer"),a["ws-opts"]=p}const n=u(o,"security");if(u(o,"tls")==="1"&&(a.tls=!0),n){if(n==="tls"&&(a.tls=!0),a.network==="grpc"){const p=new oe;p["grpc-service-name"]=u(o,"path"),a["grpc-opts"]=p}else if(a.network==="ws"){const p=new v;p.path=u(o,"path");const w=u(o,"host");if(w){const k=new D;k.host=w,p.headers=k}a["ws-opts"]=p}if(n==="reality"){const p=new _e;p["public-key"]=u(o,"pbk");const w=u(o,"sid");w&&(p["short-id"]=w.replaceAll(".","")),a["reality-opts"]=g(p),a["reality-opts"]&&(a.udp=!0),a.network=_(!a.network,"tcp",a.network)}a["skip-cert-verify"]=!0}return a},l=c=>{var o,t,s,r;const a=new E;if(c!=null&&c.includes("@")&&(c!=null&&c.includes(":")))a.uuid=S(c,"@",!1),a.server=(t=(o=x(c,"@",":"))==null?void 0:o.replace("[",""))==null?void 0:t.replace("]",""),a.port=Number.parseInt(N(c,":",!0));else{const n=$(c);n&&(a.cipher=S(n,":",!1),a.uuid=x(n,":","@"),a.server=(r=(s=x(n,"@",":"))==null?void 0:s.replace("[",""))==null?void 0:r.replace("]",""),a.port=Number.parseInt(N(n,":",!0)))}return a};return{vlessVPN:b,vLessShare:h}},rt=()=>{const{vpnName:i}=ee(),{objectCopy:u,isNotNullGetString:g,urlGetAndSet:_,ifObjectNotEmptySet:y}=L(),{subBefore:S,subBetween:x,subAfterNumber:N,subAfter:R,replaceQues:P,notEmpty:$}=j(),{bDecode:b,bEncode:h}=J(),d=o=>{const s=`${h(`${o.cipher}:${o.password}`)}@${o.server}:${o.port}`;let r="";if($(o.plugin)&&(r+=`?plugin=${o.plugin}`),o["plugin-opts"]){const n=o["plugin-opts"];r+=g(";","mode",n.mode),r+=g(";","path",n.path),r+=g(";","mux",`${n.mux}`),r+=g(";","host",n.host)}return o.name&&(r+=`#${encodeURIComponent(o.name)}`),`ss://${s}${r}`},l=o=>{const t=new E;if(o.includes("#")){t.name=i(o);const s=S(o,"#",!1),r=c(s);return u(t,r)}return t},c=o=>{const t=b(o),s=new E;if(s.type=C.SS,o=P(o),o.includes("?")){const r=o.split("?");o=r[0],a(r[1],s)}if(o.includes("@")&&o.includes(":")){const r=b(S(o,"@",!1)),n=R(o,"@",!0);r.includes(":")&&(s.cipher=S(r,":",!1),s.password=R(r,":",!1)),s.server=S(n,":",!0),s.port=N(n,":",!0)}else t&&t.includes(":")&&t.includes("@")&&(s.cipher=S(t,":",!1),s.password=x(t,":","@"),s.server=x(t,"@",":"),s.port=N(t,":",!0));return s},a=(o,t)=>{if(o&&o.includes("plugin=")&&o.includes(";")){const s=new URLSearchParams(o.replaceAll(";","&")),r=s.get("plugin");if(r){if(t.plugin=r,r==="v2ray-plugin"){const n=s.get("tls"),f=new ge;n!==null&&(f.tls=n===""||n==="true"),_(s,"mux",p=>f.mux=p==="true"),_(s,"host",p=>f.host=p),_(s,"path",p=>f.path=p),_(s,"mode",p=>f.mode=p),y(f,t,"plugin-opts")}else if(r.includes("obfs")){const n=new be;n.mode=s.get("obfs"),n.host=s.get("obfs-host"),n.path=s.get("obfs-uri"),y(n,t,"plugin-opts")}}}};return{shadowsocksVPN:l,ssToShare:d}},ot=()=>{const{bDecode:i,bEncode:u}=J(),{subAfter:g,subBefore:_}=j(),{ifContainsOrDefault:y,urlGet:S,objectCopy:x,isNotNullGetString:N}=L(),{shadowSocksREncryptMethods:R}=ee(),P=d=>{const l=new E;l.type=C.SSR;const c=i(d);if(c&&c.includes("/?")){const a=_(c,"/?",!1),o=b(a),t=g(c,"/?",!0),s=h(t);return x(l,o,s)}return l};function $(d){const l=`${d.server}:${d.port}:${d.protocol}:${d.cipher==="dummy"?"auto":d.cipher}:${d.obfs}:${u(d.password)}`;let c=`remark=${u(d.name?d.name:"default_name")}`;return d.group&&(c+=N("&","group",u(d.group))),d.obfsparam&&(c+=N("&","obfsparam",u(d.obfsparam))),d["protocol-param"]&&(c+=N("&","protoparam",u(d["protocol-param"]))),`ssr://${u(`${l}/?${c}`)}`}const b=d=>{const l=new E;if(d.includes(":")){const c=d.split(":");c.length===6&&(l.server=c[0],l.port=Number.parseInt(c[1]),l.protocol=c[2],l.cipher=y(R,c[3],"dummy"),l.obfs=c[4],l.password=i(c[5]))}return l},h=d=>{const l=new E,c=new URLSearchParams(d);return l["protocol-param"]=i(S(c,"protoparam")),l.obfsparam=i(S(c,"obfsparam")),l.group=i(S(c,"group")),l.name=i(S(c,"remarks")),l.name||(l.name=i(S(c,"remark"))),l};return{ssrVPN:P,ssrShare:$}},nt=()=>{const{subBefore:i,subBetween:u,subAfter:g,notEmpty:_,toArray:y}=j(),{funcSet:S,ifNotEmptySet:x,isNotNullGetString:N}=L(),{isNotEmpty:R}=W();function P(b){var l;const h=`${b.server}:${b.port}`;let d=`?protocol=${b.protocol?b.protocol:"udp"}`;return d+=N("&","auth",b["auth-str"]),b.obfsparam&&(d+=`&obfs=xplus&obfsParam=${b.obfsparam}`),d+=N("&","peer",b.sni),b["skip-cert-verify"]===!0&&(d+="&insecure=1"),d+=N("&","upmbps",`${b.up}`),d+=N("&","downmbps",`${b.down}`),R(b.alpn)&&(d+=`&alpn=${(l=b.alpn)==null?void 0:l.join(",")}`),`hysteria://${h}${d}#${encodeURIComponent(b.name?b.name:"default_name")}`}return{hyVPN:b=>{const h=new E;h.type=C.HYSTERIA,h.server=i(b,":",!1),h.port=Number.parseInt(u(b,":","?"));let d="";if(b.includes("#")?(d=u(b,"?","#"),h.name=encodeURIComponent(g(b,"#",!0))):d=g(b,"?",!1),_(d)){const l=new URLSearchParams(d);x(h,"authStr",l,"auth");const c=l.get("obfsParam");c&&(h.obfs="xplus",h.obfsparam=c),S(()=>l.get("alpn"),a=>h.alpn=y(a,",")),S(()=>l.get("protocol"),a=>h.protocol=a),S(()=>l.get("peer"),a=>h.sni=a),S(()=>l.get("auth"),a=>h["auth-str"]=a),S(()=>l.get("upmbps"),a=>h.up=Number.parseInt(a)),S(()=>l.get("downmbps"),a=>h.down=Number.parseInt(a)),S(()=>l.get("insecure"),a=>h["skip-cert-verify"]=a==="1")}return h},hyShare:P}},at=()=>{const{quesReplace:i,getShareName:u,excludeName:g,urlMultipleVal:_,urlGetAndSet:y,urlArray:S,isNotNullGetString:x}=L(),{subBefore:N,subBetween:R,subAfter:P}=j(),$=l=>{const c=new E;if(c.name=u(l),c.type=C.HYSTERIA2,l=g(l),l=i(l),l.includes("?")){const a=l.split("?");h(a[0],c),d(a[1],c)}return c["skip-cert-verify"]=!0,c},b=l=>{let c=`${l.server}:${l.port}`;l.password&&(c=`${l.password}@${c}`);let a="/?insecure=1";return a+=x("&","obfs",`${l.obfs}`),a+=x("&","obfs-password",`${l["obfs-password"]}`),a+=x("&","pinSHA256",`${l.fingerprint}`),a+=x("&","sni",`${l.sni}`),l.name&&(a+=`#${l.name}`),`hysteria2://${c}${a}`},h=(l,c)=>{c.password=N(l,"@",!1),c.server=R(l,"@",":"),c.port=parseInt(P(l,":",!0))},d=(l,c)=>{const a=new URLSearchParams(l);_(a,["peer","sni"],c,"sni"),c.alpn=S(a,"alpn"),y(a,"obfs",o=>c.obfs=o),y(a,"obfs-password",o=>c["obfs-password"]=o)};return{hy2VPN:$,h2Share:b}},ct=()=>{const{strToArray:i}=W(),{subBefore:u,toArray:g,subAfter:_}=j(),{vMessVPN:y,vMessShare:S}=Se(),{tuicVPN:x,jsonVPN:N}=Ne(),{trojanVPN:R,trojanShare:P}=tt(),{vlessVPN:$,vLessShare:b}=st(),{shadowsocksVPN:h,ssToShare:d}=rt(),{ssrVPN:l,ssrShare:c}=ot(),{hyVPN:a,hyShare:o}=nt(),{hy2VPN:t,h2Share:s}=at(),r=A=>i(A).filter(m=>m.includes("://")).map(m=>p(m)).filter(m=>m).filter(m=>m.valid()),n=["vless","vmess","trojan","ss","ssr","hy","hy2","tuic","hysteria","hysteria2"],f=A=>A&&typeof A=="string"?g(A).filter(m=>m).some(m=>n.some(O=>m.startsWith(O))):!1,p=A=>{const m=u(A,"://",!1),O=A.split("://")[1];let V;if(m==="vmess"?V=y:m==="tuic"?V=x:m==="trojan"?V=R:m==="vless"?V=$:m==="ss"?V=h:m==="ssr"?V=l:m==="hy"||m==="hysteria"?V=a:(m==="hy2"||m==="hysteria2")&&(V=t),V)return V(O)},w=A=>A.map(m=>k(m)).filter(m=>m).join(`
`),k=A=>{const m=A.type;let O;if(m===C.SS?O=d:m===C.SSR?O=c:m===C.VMESS?O=S:m===C.TROJAN?O=P:m===C.VLESS?O=b:m===C.HYSTERIA?O=o:m===C.HYSTERIA2&&(O=s),O)return O(A)};return{toProxy:r,route:p,isValidV2:f,allowType:n,toShare:w}};export{ct as a,he as b,we as c,ht as u};
