diff --git a/backend/sub-store.js b/backend/sub-store.js index b681470..18bc00d 100755 --- a/backend/sub-store.js +++ b/backend/sub-store.js @@ -681,6 +681,7 @@ function service() { type: artifact.type, item, platform: artifact.platform, + useCache: true }); const resp = await syncArtifact({ filename: artifact.name, diff --git a/backend/sub-store.min.js b/backend/sub-store.min.js index dba83fb..bd6b9ab 100644 --- a/backend/sub-store.min.js +++ b/backend/sub-store.min.js @@ -1,2 +1,2 @@ -// UPDATED AT: 2022年 4月30日 星期六 11时28分51秒 CST -const $=API("sub-store"),Base64=new Base64Code;function service(){console.log("\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 © 𝑷𝒆𝒏𝒈-𝒀𝑴\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n");const e=express(),t="settings",n="subs",r="collections",s="rules",o="builtin",i="artifacts",a="Auto Generated Sub-Store Backup",c="Sub-Store",l="Sub-Store Artifacts Repository";async function p({filename:e,content:n}){const{gistToken:r}=$.read(t);return r?new Gist({token:r,key:l}).upload({filename:e,content:n}):Promise.reject("未设置Gist Token!")}async function u(e){const{headers:t}=await $.http.get({url:e,headers:{"User-Agent":"Quantumult/1.0.13 (iPhone10,3; iOS 14.0)"}});return t[Object.keys(t).filter(e=>/SUBSCRIPTION-USERINFO/i.test(e))[0]]}function f(e){const t=Object.keys(e);let n="";for(let r of t)if(/USER-AGENT/i.test(r)){n=e[r];break}return-1!==n.indexOf("Quantumult%20X")?"QX":-1!==n.indexOf("Surge")?"Surge":-1!==n.indexOf("Decar")||-1!==n.indexOf("Loon")?"Loon":-1!==n.indexOf("Stash")?"Clash":null}async function d(e,t=!0,n){let r=n;void 0!==n&&null!=n&&0!=n.trim().length||(r="Quantumult%20X");const s=HTTP({headers:{"User-Agent":r}}),o="#"+Base64.safeEncode(e),i=$.read(o),a=`#TIME-${Base64.safeEncode(e)}`,c=(new Date).getTime()-$.read(a)>36e5;if(t&&i&&!c)return $.log(`Use cached for resource: ${e}`),i;let l="";try{l=(await s.get(e)).body}catch(e){throw new Error(e)}finally{$.write(l,o),$.write((new Date).getTime(),a)}if(0===l.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return l}async function h({type:e,item:t,platform:r,useCache:s,noProcessor:o}={platform:"JSON",useCache:!1,noProcessor:!1}){if("subscription"===e){const e=t,n=await d(e.url,s,e.ua);let i=ProxyUtils.parse(n);o||(i=await ProxyUtils.process(i,e.process||[],r));const a={};return i.forEach(e=>{a[e.name]&&$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』","⚠️ 订阅包含重复节点!","请仔细检测配置!",{"media-url":"https://cdn3.iconfinder.com/data/icons/seo-outline-1/512/25_code_program_programming_develop_bug_search_developer-512.png"})}),ProxyUtils.produce(i,r)}if("collection"===e){const e=$.read(n),i=t,a=i.subscriptions;let c=[];for(let t=0;t{l[e.name]&&$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』","⚠️ 订阅包含重复节点!","请仔细检测配置!",{"media-url":"https://cdn3.iconfinder.com/data/icons/seo-outline-1/512/25_code_program_programming_develop_bug_search_developer-512.png"})}),ProxyUtils.produce(c,r)}if("rule"===e){const e=t;let n=[];for(let t=0;t0){const e=p[d[0]],n=await u(e.url);n&&t.set("subscription-userinfo",n)}if(l)try{const e=await h({type:"collection",item:l,platform:a,useCache:c,noProcessor:i});"JSON"===a?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 下载组合订阅错误:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(404).json({status:"failed"})}),e.get("/download/:name",async function(e,t){const{name:r}=e.params,{cache:s}=e.query,{raw:o}=e.query||"false",i=e.query.target||f(e.headers)||"JSON",a=void 0===s?"JSON"===i||"URI"===i:s;$.info(`正在下载订阅:${r}`);const c=$.read(n)[r];if(c)try{const e=await h({type:"subscription",item:c,platform:i,useCache:a,noProcessor:o}),n=await u(c.url);n&&t.set("subscription-userinfo",n),"JSON"===i?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${JSON.stringify(e)}`),$.error(JSON.stringify(e)),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 未找到订阅:${r}!`),t.status(404).json({status:"failed"})}),e.route("/api/sub/:name").get(function(e,t){const{name:r}=e.params,s=$.read(n)[r];s?t.json({status:"success",data:s}):t.status(404).json({status:"failed",message:`未找到订阅:${r}!`})}).patch(function(e,t){const{name:s}=e.params;let o=e.body;const i=$.read(n);if(i[s]){const e={...i[s],...o};if($.info(`正在更新订阅: ${s}`),s!==o.name){const t=$.read(r);for(const e of Object.keys(t)){const n=t[e].subscriptions.indexOf(s);-1!==n&&(t[e].subscriptions[n]=o.name)}delete i[s],i[o.name]=e}else i[s]=e;$.write(i,n),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订阅${s}不存在,无法更新!`})}).delete(function(e,t){const{name:s}=e.params;$.info(`删除订阅:${s}...`);let o=$.read(n);delete o[s],$.write(o,n);let i=$.read(r);for(const e of Object.keys(i))i[e].subscriptions=i[e].subscriptions.filter(e=>e!==s);$.write(i,r),t.json({status:"success"})}),e.route("/api/subs").get(function(e,t){const r=$.read(n);t.json({status:"success",data:r})}).post(function(e,t){const r=e.body,s=$.read(n);$.info(`正在创建订阅: ${r.name}`),s[r.name]&&t.status(500).json({status:"failed",message:`订阅${r.name}已存在!`});/^[\w-_]*$/.test(r.name)?(s[r.name]=r,$.write(s,n),t.status(201).json({status:"success",data:r})):t.status(500).json({status:"failed",message:`订阅名称 ${r.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),e.get("/api/sub/statistics/:name"),e.route("/api/collection/:name").get(function(e,t){const{name:n}=e.params,s=$.read(r)[n];s?t.json({status:"success",data:s}):t.status(404).json({status:"failed",message:`未找到订阅集:${n}!`})}).patch(function(e,t){const{name:n}=e.params;let s=e.body;const o=$.read(r);if(o[n]){const e={...o[n],...s};$.info(`正在更新组合订阅:${n}...`),delete o[n],o[s.name||n]=e,$.write(o,r),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订阅集${n}不存在,无法更新!`})}).delete(function(e,t){const{name:n}=e.params;$.info(`正在删除组合订阅:${n}`);let s=$.read(r);delete s[n],$.write(s,r),t.json({status:"success"})}),e.route("/api/collections").get(function(e,t){const n=$.read(r);t.json({status:"success",data:n})}).post(function(e,t){const n=e.body;$.info(`正在创建组合订阅:${n.name}`);const s=$.read(r);s[n.name]&&t.status(500).json({status:"failed",message:`订阅集${n.name}已存在!`});/^[\w-_]*$/.test(n.name)?(s[n.name]=n,$.write(s,r),t.status(201).json({status:"success",data:n})):t.status(500).json({status:"failed",message:`订阅集名称 ${n.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),e.get("/download/rule/:name",async function(e,t){const{name:n}=e.params,{builtin:r}=e.query,s=e.query.target||f(e.headers)||"Surge";let i;$.info(`正在下载${r?"内置":""}分流订阅:${n}...`),r&&(i=$.read(o).rules[n]);if(i){const e=await h({type:"rule",item:i,platform:s});t.send(e)}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载分流订阅失败",`❌ 未找到分流订阅:${n}!`),t.status(404).json({status:"failed"})}),e.route("/api/rules").post(function(e,t){}).get(function(e,t){}),e.route("/api/rule/:name").patch(function(e,t){}).delete(function(e,t){}).get(function(e,t){}),e.route("/api/storage").get((e,t)=>{t.json($.read("#sub-store"))}).post((e,t)=>{const n=e.body;$.write(JSON.stringify(n),"#sub-store"),t.end()}),e.route("/api/settings").get(function(e,n){const r=$.read(t);n.json(r)}).patch(function(e,n){const r=e.body,s=$.read(t);$.write({...s,...r},t),n.json({status:"success"})}),e.route("/api/artifacts").get(function(e,t){const n=$.read(i);t.json({status:"success",data:n})}).post(function(e,t){const n=e.body;$.info(`正在创建远程配置:${n.name}`);const r=$.read(i);r[n.name]?t.status(500).json({status:"failed",message:`远程配置${n.name}已存在!`}):/^[\w-_.]*$/.test(n.name)?(r[n.name]=n,$.write(r,i),t.status(201).json({status:"success",data:n})):t.status(500).json({status:"failed",message:`远程配置名称 ${n.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),e.route("/api/artifact/:name").get(async function(e,t){const o=e.params.name,a=e.query.action,c=$.read(i),l=c[o];if(l)if(a){let e;switch(l.type){case"subscription":e=$.read(n)[l.source];break;case"collection":e=$.read(r)[l.source];break;case"rule":e=$.read(s)[l.source]}const o=await h({type:l.type,item:e,platform:l.platform});if("preview"===a)t.send(o);else if("sync"===a){$.info(`正在上传配置:${l.name}\n>>>`),console.log(JSON.stringify(l,null,2));try{const e=await p({filename:l.name,content:o});l.updated=(new Date).getTime();const n=JSON.parse(e.body);l.url=n.files[l.name].raw_url.replace(/\/raw\/[^\/]*\/(.*)/,"/raw/$1"),$.write(c,i),t.json({status:"success"})}catch(e){t.status(500).json({status:"failed",message:e})}}}else t.json({status:"success",data:l});else t.status(404).json({status:"failed",message:"未找到对应的配置!"})}).patch(function(e,t){const n=$.read(i),r=e.params.name,s=n[r];if(s){$.info(`正在更新远程配置:${s.name}`);const o=e.body;if(void 0===o.name||/^[\w-_.]*$/.test(o.name)){const e={...s,...o};n[e.name]=e,e.name!==r&&delete n[r],$.write(n,i),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`远程配置名称 ${o.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}else t.status(404).json({status:"failed",message:"未找到对应的远程配置!"})}).delete(async function(e,t){const n=e.params.name;$.info(`正在删除远程配置:${n}`);const r=$.read(i);try{const e=r[n];if(!e)throw new Error(`远程配置:${n}不存在!`);e.updated&&await p({filename:n,content:""}),delete r[n],$.write(r,i),t.json({status:"success"})}catch(e){delete r[n],$.write(r,i),t.status(500).json({status:"failed",message:`无法删除远程配置:${n}, 原因:${e}`})}}),e.get("/api/utils/IP_API/:server",async function(e,t){const n=decodeURIComponent(e.params.server),r=await $.http.get(`http://ip-api.com/json/${n}?lang=zh-CN`).then(e=>JSON.parse(e.body));t.json(r)}),e.post("/api/utils/refresh",async function(e,t){const{url:n,ua:r}=e.body;$.info(`Refreshing cache for URL: ${n}`);try{const e=await d(n,!1,r);$.write(e,`#${Base64.safeEncode(n)}`),t.json({status:"success"})}catch(e){t.status(500).json({status:"failed",message:`无法刷新资源 ${n}: ${e}`})}}),e.get("/api/utils/env",function(e,t){const{isNode:n,isQX:r,isLoon:s,isSurge:o}=ENV();let i="Node";n&&(i="Node");r&&(i="QX");s&&(i="Loon");o&&(i="Surge");t.json({backend:i})}),e.get("/api/utils/backup",async function(e,n){const{action:r}=e.query,{gistToken:s}=$.read(t);if(s){const e=new Gist({token:s,key:a});try{let s;switch(r){case"upload":const n=$.read(t);n.syncTime=(new Date).getTime(),$.write(n,t),s=$.read("#sub-store"),$.env.isNode&&(s=JSON.stringify($.cache,null," ")),$.info("上传备份中..."),await e.upload({filename:c,content:s});break;case"download":$.info("还原备份中..."),s=await e.download(c),$.write(s,"#sub-store"),$.env.isNode&&(s=JSON.parse(s),Object.keys(s).forEach(e=>{$.write(s[e],e)}))}n.json({status:"success"})}catch(e){const t=`${"upload"===r?"上传":"下载"}备份失败!${e}`;$.error(t),n.status(500).json({status:"failed",message:t})}}else n.status(500).json({status:"failed",message:"未找到Gist备份Token!"})}),e.get("/api/cron/sync-artifacts",async function(e,t){$.info("开始同步所有远程配置...");const o=$.read(i);let a=[],c=[];await Promise.all(Object.values(o).map(async e=>{if(e.sync){$.info(`正在同步云配置:${e.name}...`);try{let t;switch(e.type){case"subscription":t=$.read(n)[e.source];break;case"collection":t=$.read(r)[e.source];break;case"rule":t=$.read(s)[e.source]}const l=await h({type:e.type,item:t,platform:e.platform}),u=await p({filename:e.name,content:l});e.updated=(new Date).getTime();const f=JSON.parse(u.body);e.url=f.files[e.name].raw_url.replace(/\/raw\/[^\/]*\/(.*)/,"/raw/$1"),$.write(o,i),$.info(`✅ 成功同步云配置:${e.name}`),a.push(e)}catch(t){$.error(`云配置: ${e.name} 同步失败!原因:${t}`),$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 同步订阅失败",`❌ 无法同步订阅:${e.name}!`,`🤔 原因:${t}`),c.push(e)}}})),t.json({success:a,failed:c})}),e.get("/",async(e,t)=>{t.set("location","https://sub-store.vercel.app/").status(302).end()}),ENV().isQX&&e.options("/",async(e,t)=>{t.status(200).end()}),e.all("/",(e,t)=>{t.send("Hello from sub-store, made with ❤️ by Peng-YM")}),e.start()}service();var ProxyUtils=function(){const PROXY_PREPROCESSORS=function(){return[{name:"HTML",test:e=>/^/.test(e),parse:e=>""},function(){const e=["dm1lc3M","c3NyOi8v","dHJvamFu","c3M6Ly","c3NkOi8v","c2hhZG93","aHR0c"];return{name:"Base64 Pre-processor",test:function(t){return e.some(e=>-1!==t.indexOf(e))},parse:function(e){return e=Base64.safeDecode(e)}}}(),{name:"Clash Pre-processor",test:function(e){return/proxies/.test(e)},parse:function(e){return YAML.load(e).proxies.map(e=>JSON.stringify(e)).join("\n")}},{name:"SSD Pre-processor",test:function(e){return 0===e.indexOf("ssd://")},parse:function(e){const t=[];let n=JSON.parse(Base64.safeDecode(e.split("ssd://")[1]));n.traffic_used,n.traffic_total,n.expiry,n.airport;let r=n.port,s=n.encryption,o=n.password,i=n.servers;for(let e=0;e{let[t,s]=e.split("=");if(t=t.trim(),s=s.trim(),-1!==r.indexOf(t)){n.type=t;const e=s.split(":");n.server=e[0],n.port=e[1]}else n[t.trim()]=s.trim()}),n}function t(){return{name:"Loon HTTP Parser",test:e=>/^.*=\s*http/i.test(e.split(",")[0])&&5===e.split(",").length&&-1===e.indexOf("username")&&-1===e.indexOf("password"),parse:e=>{const t=e.split("=")[1].split(","),n={name:e.split("=")[0].trim(),type:"http",server:t[1],port:t[2],tls:"443"===t[2]};return t[3]&&(n.username=t[3]),t[4]&&(n.password=t[4]),n.tls&&(n.sni=t["tls-name"]||n.server,n["skip-cert-verify"]=JSON.parse(t["skip-cert-verify"]||"false")),n}}}function n(e){const t={};t.name=e.split("=")[0].trim();const n=e.split(",");t.server=n[1].trim(),t.port=n[2].trim();for(let e=3;e/^ss:\/\//.test(e),parse:e=>{const t={};let n=e.split("ss://")[1];const r={name:decodeURIComponent(e.split("#")[1]),type:"ss",supported:t},s=(n=n.split("#")[0]).match(/@([^\/]*)(\/|$)/)[1],o=s.lastIndexOf(":");r.server=s.substring(0,o),r.port=s.substring(o+1);const i=Base64.safeDecode(n.split("@")[0]).split(":");if(r.cipher=i[0],r.password=i[1],-1!==n.indexOf("?plugin=")){const e=("plugin="+decodeURIComponent(n.split("?plugin=")[1].split("&")[0])).split(";"),s={};for(const t of e){const[e,n]=t.split("=");e&&(s[e]=n||!0)}switch(s.plugin){case"obfs-local":case"simple-obfs":r.plugin="obfs",r["plugin-opts"]={mode:s.obfs,host:s["obfs-host"]};break;case"v2ray-plugin":r.supported={...t,Loon:!1,Surge:!1},r.obfs="v2ray-plugin",r["plugin-opts"]={mode:"websocket",host:s["obfs-host"],path:s.path||"",tls:s.tls||!1};break;default:throw new Error(`Unsupported plugin option: ${s.plugin}`)}}return r}},function(){const e={Surge:!1};return{name:"URI SSR Parser",test:e=>/^ssr:\/\//.test(e),parse:t=>{let n=(t=Base64.safeDecode(t.split("ssr://")[1])).indexOf(":origin");-1===n&&(n=t.indexOf(":auth_"));const r=t.substring(0,n),s=r.substring(0,r.lastIndexOf(":")),o=r.substring(r.lastIndexOf(":")+1);let i=t.substring(n+1).split("/?")[0].split(":"),a={type:"ssr",server:s,port:o,protocol:i[0],cipher:i[1],obfs:i[2],password:Base64.safeDecode(i[3]),supported:e};const c={};if((t=t.split("/?")[1].split("&")).length>1)for(const e of t){const[t,n]=e.split("=");c[t]=n.trim()}return a={...a,name:c.remarks?Base64.safeDecode(c.remarks):a.server,"protocol-param":Base64.safeDecode(c.protoparam||"").replace(/\s/g,""),"obfs-param":Base64.safeDecode(c.obfsparam||"").replace(/\s/g,"")}}}}(),{name:"URI VMess Parser",test:e=>/^vmess:\/\//.test(e),parse:e=>{const t={};e=e.split("vmess://")[1];const n=Base64.safeDecode(e);if(/=\s*vmess/.test(n)){const e=n.split(",").map(e=>e.trim()),t={};for(const n of e)if(-1!==n.indexOf("=")){const[e,r]=n.split("=");t[e.trim()]=r.trim()}const r={name:e[0].split("=")[0].trim(),type:"vmess",server:e[1],port:e[2],cipher:e[3],uuid:e[4].match(/^"(.*)"$/)[1],tls:"over-tls"===t.obfs||"wss"===t.obfs};if(void 0!==t["udp-relay"]&&(r.udp=JSON.parse(t["udp-relay"])),void 0!==t["fast-open"]&&(r.udp=JSON.parse(t["fast-open"])),"ws"===t.obfs||"wss"===t.obfs){r.network="ws",r["ws-opts"].path=(t["obfs-path"]||'"/"').match(/^"(.*)"$/)[1];let e=t["obfs-header"];e&&-1!==e.indexOf("Host")&&(e=e.match(/Host:\s*([a-zA-Z0-9-.]*)/)[1]),r["ws-opts"].headers={Host:e||r.server}}return r.tls&&"false"===t['"tls-verification"']&&(r["skip-cert-verify"]=!0),r.tls&&t["obfs-host"]&&(r.sni=t["obfs-host"]),r}{const e=JSON.parse(n),r={name:e.ps,type:"vmess",server:e.add,port:e.port,cipher:"auto",uuid:e.id,alterId:e.aid||0,tls:"tls"===e.tls||!0===e.tls,supported:t};return"ws"===e.net&&(r.network="ws",r["ws-opts"]={path:e.path,headers:{Host:e.host||e.add}},r.tls&&e.host&&(r.sni=e.host)),!1===e.verify_cert&&(r["skip-cert-verify"]=!0),r}}},{name:"URI Trojan Parser",test:e=>/^trojan:\/\//.test(e),parse:e=>{e=e.split("trojan://")[1];const[t,n]=e.split("@")[1].split("?")[0].split(":"),r=decodeURIComponent(e.split("#")[1].trim());let s=e.split("?"),o=null;return s.length>1&&(s=s[1].split("#")[0].split("&"),o=new Map(s.map(e=>e.split("="))).get("sni")),{name:r||`[Trojan] ${t}`,type:"trojan",server:t,port:n,password:e.split("@")[0],sni:o,supported:{}}}},{name:"Clash Parser",test:e=>{try{JSON.parse(e)}catch(e){return!1}return!0},parse:e=>JSON.parse(e)},{name:"Surge SS Parser",test:e=>/^.*=\s*ss/.test(e.split(",")[0]),parse:e=>{const t=n(e),r={name:t.name,type:"ss",server:t.server,port:t.port,cipher:t["encrypt-method"],password:t.password,tfo:JSON.parse(t.tfo||"false"),udp:JSON.parse(t["udp-relay"]||"false")};return t.obfs&&(r.plugin="obfs",r["plugin-opts"]={mode:t.obfs,host:t["obfs-host"]}),r}},{name:"Surge VMess Parser",test:e=>/^.*=\s*vmess/.test(e.split(",")[0])&&-1!==e.indexOf("username"),parse:e=>{const t=n(e),r={name:t.name,type:"vmess",server:t.server,port:t.port,uuid:t.username,alterId:0,cipher:"none",tls:JSON.parse(t.tls||"false"),tfo:JSON.parse(t.tfo||"false")};if(r.tls&&(void 0!==t["skip-cert-verify"]&&(r["skip-cert-verify"]=!0===t["skip-cert-verify"]||"1"===t["skip-cert-verify"]),r.sni=t.sni||t.server),JSON.parse(t.ws||"false")){r.network="ws",r["ws-opts"]={path:t["ws-path"]};const e=t["ws-headers"].match(/(,|^|\s)*HOST:\s*(.*?)(,|$)/),n=e?e[2]:r.server;r["ws-opts"].headers={Host:n||t.server}}return r}},{name:"Surge Trojan Parser",test:e=>/^.*=\s*trojan/.test(e.split(",")[0])&&-1!==e.indexOf("sni"),parse:e=>{const t=n(e),r={name:t.name,type:"trojan",server:t.server,port:t.port,password:t.password,sni:t.sni||t.server,tfo:JSON.parse(t.tfo||"false")};return void 0!==t["skip-cert-verify"]&&(r["skip-cert-verify"]=!0===t["skip-cert-verify"]||"1"===t["skip-cert-verify"]),r}},{name:"Surge HTTP Parser",test:e=>/^.*=\s*http/.test(e.split(",")[0])&&!t().test(e),parse:e=>{const t=n(e),r={name:t.name,type:"http",server:t.server,port:t.port,tls:JSON.parse(t.tls||"false"),tfo:JSON.parse(t.tfo||"false")};return r.tls&&(void 0!==t["skip-cert-verify"]&&(r["skip-cert-verify"]=!0===t["skip-cert-verify"]||"1"===t["skip-cert-verify"]),r.sni=t.sni||t.server),t.username&&"none"!==t.username&&(r.username=t.username),t.password&&"none"!==t.password&&(r.password=t.password),r}},{name:"Loon SS Parser",test:e=>"shadowsocks"===e.split(",")[0].split("=")[1].trim().toLowerCase(),parse:e=>{const t=e.split("=")[1].split(","),n={name:e.split("=")[0].trim(),type:"ss",server:t[1],port:t[2],cipher:t[3],password:t[4].replace(/"/g,"")};return t.length>5&&(n.plugin="obfs",n["plugin-opts"]={mode:t[5],host:t[6]}),n}},{name:"Loon SSR Parser",test:e=>"shadowsocksr"===e.split(",")[0].split("=")[1].trim().toLowerCase(),parse:e=>{const t=e.split("=")[1].split(",");return{name:e.split("=")[0].trim(),type:"ssr",server:t[1],port:t[2],cipher:t[3],password:t[4].replace(/"/g,""),protocol:t[5],"protocol-param":t[6].match(/{(.*)}/)[1],supported:{Surge:!1},obfs:t[7],"obfs-param":t[8].match(/{(.*)}/)[1]}}},{name:"Loon VMess Parser",test:e=>/^.*=\s*vmess/i.test(e.split(",")[0])&&-1===e.indexOf("username"),parse:e=>{let t=e.split("=")[1].split(",");const n={name:e.split("=")[0].trim(),type:"vmess",server:t[1],port:t[2],cipher:t[3]||"none",uuid:t[4].replace(/"/g,""),alterId:0};t=t.splice(5);for(const e of t){const[n,r]=e.split(":");t[n]=r}switch(n.tls=JSON.parse(t["over-tls"]||"false"),n.tls&&(n.sni=t["tls-name"]||n.server,n["skip-cert-verify"]=JSON.parse(t["skip-cert-verify"]||"false")),t.transport){case"tcp":break;case"ws":n.network=t.transport,n["ws-opts"]={path:t.path,headers:{Host:t.host}}}return n.tls&&(n["skip-cert-verify"]=JSON.parse(t["skip-cert-verify"]||"false")),n}},{name:"Loon Trojan Parser",test:e=>/^.*=\s*trojan/i.test(e.split(",")[0])&&-1===e.indexOf("password"),parse:e=>{const t=e.split("=")[1].split(","),n={name:e.split("=")[0].trim(),type:"trojan",server:t[1],port:t[2],password:t[3].replace(/"/g,""),sni:t[1],"skip-cert-verify":JSON.parse(t["skip-cert-verify"]||"false")};if(t.length>4){const[r,s]=t[4].split(":");if("tls-name"!==r)throw new Error(`Unknown option ${r} for line: \n${e}`);n.sni=s}return n}},t(),{name:"QX SS Parser",test:e=>/^shadowsocks\s*=/.test(e.split(",")[0].trim())&&-1===e.indexOf("ssr-protocol"),parse:t=>{const n=e(t),r={name:n.tag,type:"ss",server:n.server,port:n.port,cipher:n.method,password:n.password,udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false"),supported:{}};if(n.obfs)switch(r["plugin-opts"]={host:n["obfs-host"]||r.server},n.obfs){case"http":case"tls":r.plugin="obfs",r["plugin-opts"].mode=n.obfs;break;case"ws":case"wss":r["plugin-opts"]={...r["plugin-opts"],mode:"websocket",path:n["obfs-uri"]||"/",tls:"wss"===n.obfs},r["plugin-opts"].tls&&void 0!==n["tls-verification"]&&(r["plugin-opts"]["skip-cert-verify"]=n["tls-verification"]),r.plugin="v2ray-plugin",r.supported.Surge=!1,r.supported.Loon=!1}return r}},{name:"QX SSR Parser",test:e=>/^shadowsocks\s*=/.test(e.split(",")[0].trim())&&-1!==e.indexOf("ssr-protocol"),parse:t=>{const n=e(t),r={name:n.tag,type:"ssr",server:n.server,port:n.port,cipher:n.method,password:n.password,protocol:n["ssr-protocol"],obfs:"plain","protocol-param":n["ssr-protocol-param"],udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false"),supported:{Surge:!1}};return n.obfs&&(r.obfs=n.obfs,r["obfs-param"]=n["obfs-host"]),r}},{name:"QX VMess Parser",test:e=>/^vmess\s*=/.test(e.split(",")[0].trim()),parse:t=>{const n=e(t),r={type:"vmess",name:n.tag,server:n.server,port:n.port,cipher:n.method||"none",uuid:n.password,alterId:0,tls:"over-tls"===n.obfs||"wss"===n.obfs,udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false")};return r.tls&&(r.sni=n["obfs-host"]||n.server,r["skip-cert-verify"]=!JSON.parse(n["tls-verification"]||"true")),"ws"!==n.obfs&&"wss"!==n.obfs||(r.network="ws",r["ws-opts"]={path:n["obfs-uri"],headers:{Host:n["obfs-host"]||n.server}}),r}},{name:"QX Trojan Parser",test:e=>/^trojan\s*=/.test(e.split(",")[0].trim()),parse:t=>{const n=e(t),r={type:"trojan",name:n.tag,server:n.server,port:n.port,password:n.password,sni:n["tls-host"]||n.server,udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false")};return r["skip-cert-verify"]=!JSON.parse(n["tls-verification"]||"true"),r}},{name:"QX HTTP Parser",test:e=>/^http\s*=/.test(e.split(",")[0].trim()),parse:t=>{const n=e(t),r={type:"http",name:n.tag,server:n.server,port:n.port,tls:JSON.parse(n["over-tls"]||"false"),udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false")};return n.username&&"none"!==n.username&&(r.username=n.username),n.password&&"none"!==n.password&&(r.password=n.password),r.tls&&(r.sni=n["tls-host"]||r.server,r["skip-cert-verify"]=!JSON.parse(n["tls-verification"]||"true")),r}}]}(),PROXY_PROCESSORS=function(){function SetPropertyOperator({key:e,value:t}){return{name:"Set Property Operator",func:n=>n.map(n=>(n[e]=t,n))}}function FlagOperator(e=!0){return{name:"Flag Operator",func:t=>t.map(t=>{if(e){const e=getFlag(t.name);t.name=removeFlag(t.name),t.name=e+" "+t.name,t.name=t.name.replace(/🇹🇼/g,"🇨🇳")}else t.name=removeFlag(t.name);return t})}}function HandleDuplicateOperator(e){const{action:t,template:n,link:r,position:s}={action:"rename",template:"0 1 2 3 4 5 6 7 8 9",link:"-",position:"back",...e};return{name:"Handle Duplicate Operator",func:e=>{if("delete"===t){const t={};return e.filter(e=>!t[e.name]&&(t[e.name]=!0,!0))}if("rename"===t){const t=n.split(" "),o={};let i=0;e.forEach(e=>{void 0===o[e.name]?o[e.name]=1:o[e.name]++,i=Math.max(o[e.name].toString().length,i)});const a={};return e.map(e=>{if(o[e.name]>1){void 0===a[e.name]&&(a[e.name]=1);let n="",o=a[e.name]++,c=0;for(;o>0;)n=t[o%10]+n,o=parseInt(o/10),c++;for(;c++{switch(e){case"asc":case"desc":return t.sort((t,n)=>{let r=t.name>n.name?1:-1;return r*="desc"===e?-1:1});case"random":return shuffle(t);default:throw new Error("Unknown sort option: "+e)}}}}function RegexSortOperator(e){return{name:"Regex Sort Operator",func:t=>(e=e.map(e=>buildRegex(e)),t.sort((t,n)=>{const r=getRegexOrder(e,t.name),s=getRegexOrder(e,n.name);return r&&!s?-1:s&&!r?1:r&&s?rt.map(t=>{for(const{expr:n,now:r}of e)t.name=t.name.replace(buildRegex(n,"g"),r).trim();return t})}}function RegexDeleteOperator(e){return{name:"Regex Delete Operator",func:RegexRenameOperator(e.map(e=>({expr:e,now:""}))).func}}function ScriptOperator(script,targetPlatform){return{name:"Script Operator",func:proxies=>{let output=proxies;return function(){const $get=(e,t)=>{return(0,PROXY_PROCESSORS[e])(t)},$process=ApplyProcessor;eval(script),output=operator(proxies,targetPlatform)}(),output}}}function UselessFilter(){return{name:"Useless Filter",func:RegexFilter({regex:["网址","流量","时间","应急","过期","Bandwidth","expire"],keep:!1}).func}}function RegionFilter(e){const t={HK:"🇭🇰",TW:"🇹🇼",US:"🇺🇸",SG:"🇸🇬",JP:"🇯🇵",UK:"🇬🇧"};return{name:"Region Filter",func:n=>n.map(n=>{const r=getFlag(n.name);return e.some(e=>t[e]===r)})}}function RegexFilter({regex:e=[],keep:t=!0}){return{name:"Regex Filter",func:n=>n.map(n=>{const r=e.some(e=>buildRegex(e).test(n.name));return t?r:!r})}}function TypeFilter(e){return{name:"Type Filter",func:t=>t.map(t=>e.some(e=>t.type===e))}}function ScriptFilter(script){return{name:"Script Filter",func:proxies=>{let output=FULL(proxies.length,!0);return function(){eval(script),output=filter(proxies)}(),output}}}function getFlag(e){const t={"🇦🇿":["阿塞拜疆"],"🇦🇹":["奥地利","奧地利","Austria","维也纳"],"🇦🇺":["AU","Australia","Sydney","澳大利亚","澳洲","墨尔本","悉尼","土澳","京澳","廣澳","滬澳","沪澳","广澳"],"🇧🇪":["BE","比利時","比利时"],"🇧🇬":["保加利亚","保加利亞","Bulgaria"],"🇵🇰":["巴基斯坦"],"🇰🇭":["柬埔寨"],"🇺🇦":["烏克蘭","乌克兰"],"🇭🇷":["克罗地亚","HR","克羅地亞"],"🇨🇦":["Canada","CANADA","CAN","Waterloo","加拿大","蒙特利尔","温哥华","楓葉","枫叶","滑铁卢","多伦多"],"🇨🇭":["瑞士","苏黎世","Switzerland"],"🇳🇬":["尼日利亚","NG","尼日利亞"],"🇨🇿":["Czechia","捷克"],"🇸🇰":["斯洛伐克","SK"],"🇷🇸":["RS","塞尔维亚"],"🇲🇩":["摩爾多瓦","MD","摩尔多瓦"],"🇩🇪":["DE","German","GERMAN","德国","德國","法兰克福","京德","滬德","廣德","沪德","广德"],"🇩🇰":["DK","DNK","丹麦","丹麥"],"🇪🇸":["ES","西班牙","Spain"],"🇪🇺":["EU","欧盟","欧罗巴"],"🇫🇮":["Finland","芬兰","芬蘭","赫尔辛基"],"🇫🇷":["FR","France","法国","法國","巴黎"],"🇬🇧":["UK","GB","England","United Kingdom","英国","伦敦","英"],"🇲🇴":["MO","Macao","澳门","澳門","CTM"],"🇰🇿":["哈萨克斯坦","哈萨克"],"🇭🇺":["匈牙利","Hungary"],"🇭🇰":["HK","Hongkong","Hong Kong","HongKong","HONG KONG","香港","深港","沪港","呼港","HKT","HKBN","HGC","WTT","CMI","穗港","京港","港"],"🇮🇩":["Indonesia","印尼","印度尼西亚","雅加达"],"🇮🇪":["Ireland","IRELAND","爱尔兰","愛爾蘭","都柏林"],"🇮🇱":["Israel","以色列"],"🇮🇳":["India","IND","INDIA","印度","孟买","Mumbai"],"🇮🇸":["IS","ISL","冰岛","冰島"],"🇰🇵":["KP","朝鲜"],"🇰🇷":["KR","Korea","KOR","韩国","首尔","韩","韓","春川"],"🇱🇺":["卢森堡"],"🇱🇻":["Latvia","Latvija","拉脱维亚"],"🇲🇽️":["MEX","MX","墨西哥"],"🇲🇾":["MY","Malaysia","MALAYSIA","马来西亚","大馬","馬來西亞","吉隆坡"],"🇳🇱":["NL","Netherlands","荷兰","荷蘭","尼德蘭","阿姆斯特丹"],"🇵🇭":["PH","Philippines","菲律宾","菲律賓"],"🇷🇴":["RO","罗马尼亚"],"🇷🇺":["RU","Russia","俄罗斯","俄国","俄羅斯","伯力","莫斯科","圣彼得堡","西伯利亚","新西伯利亚","京俄","杭俄","廣俄","滬俄","广俄","沪俄"],"🇸🇦":["沙特","迪拜"],"🇸🇪":["SE","Sweden"],"🇸🇬":["SG","Singapore","SINGAPORE","新加坡","狮城","沪新","京新","泉新","穗新","深新","杭新","广新","廣新","滬新"],"🇹🇭":["TH","Thailand","泰国","泰國","曼谷"],"🇹🇷":["TR","Turkey","土耳其","伊斯坦布尔"],"🇹🇼":["TW","Taiwan","TAIWAN","台湾","台北","台中","新北","彰化","CHT","台","HINET"],"🇺🇸":["US","USA","America","United States","美国","美","京美","波特兰","达拉斯","俄勒冈","凤凰城","费利蒙","硅谷","矽谷","拉斯维加斯","洛杉矶","圣何塞","圣克拉拉","西雅图","芝加哥","沪美","哥伦布","纽约"],"🇻🇳":["VN","越南","胡志明市"],"🇮🇹":["Italy","IT","Nachash","意大利","米兰","義大利"],"🇿🇦":["South Africa","南非"],"🇦🇪":["United Arab Emirates","阿联酋"],"🇧🇷":["BR","Brazil","巴西","圣保罗"],"🇯🇵":["JP","Japan","JAPAN","日本","东京","大阪","埼玉","沪日","穗日","川日","中日","泉日","杭日","深日","辽日","广日"],"🇦🇷":["AR","阿根廷"],"🇳🇴":["Norway","挪威","NO"],"🇨🇳":["CN","China","回国","中国","中國","江苏","北京","上海","广州","深圳","杭州","徐州","青岛","宁波","镇江","back"],"🇵🇱":["PL","POL","波兰","波蘭"],"🇨🇱":["智利"],"🇳🇿":["新西蘭","新西兰"],"🇬🇷":["希腊","希臘"],"🇪🇬":["埃及"],"🇨🇾":["CY","塞浦路斯"],"🇨🇷":["CR","哥斯达黎加"],"🇸🇮":["SI","斯洛文尼亚"],"🇱🇹":["LT","立陶宛"],"🇵🇦":["PA","巴拿马"],"🇹🇳":["TN","突尼斯"],"🇮🇲":["马恩岛","馬恩島"],"🇧🇾":["BY","白俄罗斯"],"🇵🇹":["葡萄牙"],"🇰🇪":["KE","肯尼亚"],"🇰🇬":["KG","吉尔吉斯坦"],"🇯🇴":["JO","约旦"],"🇺🇾":["UY","乌拉圭"],"🇲🇳":["蒙古"],"🇮🇷":["IR","伊朗"],"🇵🇪":["秘鲁","祕魯"],"🇨🇴":["哥伦比亚"],"🇪🇪":["爱沙尼亚"],"🇲🇰":["马其顿","馬其頓"],"🇧🇦":["波黑共和国","波黑"],"🇬🇪":["格魯吉亞","格鲁吉亚"],"🇦🇱":["阿爾巴尼亞","阿尔巴尼亚"],"🏳️‍🌈":["流量","时间","应急","过期","Bandwidth","expire"]};for(let n of Object.keys(t))if(t[n].some(t=>-1!==e.indexOf(t)))return n;return(e.match(/[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]/)||[])[0]||"🏴‍☠️"}function removeFlag(e){return e.replace(/[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]/g,"").trim()}function shuffle(e){let t,n,r=e.length;for(;0!==r;)n=Math.floor(Math.random()*r),t=e[r-=1],e[r]=e[n],e[n]=t;return e}return{"Useless Filter":UselessFilter,"Region Filter":RegionFilter,"Regex Filter":RegexFilter,"Type Filter":TypeFilter,"Script Filter":ScriptFilter,"Set Property Operator":SetPropertyOperator,"Flag Operator":FlagOperator,"Sort Operator":SortOperator,"Regex Sort Operator":RegexSortOperator,"Regex Rename Operator":RegexRenameOperator,"Regex Delete Operator":RegexDeleteOperator,"Script Operator":ScriptOperator,"Handle Duplicate Operator":HandleDuplicateOperator}}(),PROXY_PRODUCERS=function(){return{QX:{produce:e=>{let t,n;switch(e.type){case"ss":if(t="","obfs"===e.plugin){const{host:n,mode:r}=e["plugin-opts"];t=`,obfs=${r}${n?",obfs-host="+n:""}`}if("v2ray-plugin"===e.plugin){const{tls:n,host:r,path:s}=e["plugin-opts"];t=`,obfs=${n?"wss":"ws"}${r?",obfs-host="+r:""}${s?",obfs-uri="+s:""}`}return`shadowsocks=${e.server}:${e.port},method=${e.cipher},password=${e.password}${t}${e.tfo?",fast-open=true":",fast-open=false"}${e.udp?",udp-relay=true":",udp-relay=false"},tag=${e.name}`;case"ssr":return`shadowsocks=${e.server}:${e.port},method=${e.cipher},password=${e.password},ssr-protocol=${e.protocol}${e["protocol-param"]?",ssr-protocol-param="+e["protocol-param"]:""}${e.obfs?",obfs="+e.obfs:""}${e["obfs-param"]?",obfs-host="+e["obfs-param"]:""},fast-open=${e.tfo||!1}${e.udp?",udp-relay=true":",udp-relay=false"},tag=${e.name}`;case"vmess":t="","ws"===e.network?t=e.tls?`,obfs=wss${e.sni?",obfs-host="+e.sni:""}${e["ws-opts"].path?",obfs-uri="+e["ws-opts"].path:""},tls-verification=${e["skip-cert-verify"]?"false":"true"}`:`,obfs=ws${e["ws-opts"].headers.Host?",obfs-host="+e["ws-opts"].headers.Host:""}${e["ws-opts"].path?",obfs-uri="+e["ws-opts"].path:""}`:e.tls&&(t=`,obfs=over-tls${e.sni?",obfs-host="+e.sni:""},tls-verification=${e["skip-cert-verify"]?"false":"true"}`);let r=`vmess=${e.server}:${e.port},method=${"auto"===e.cipher?"none":e.cipher},password=${e.uuid}${t},fast-open=${e.tfo||!1}${e.udp?",udp-relay=true":",udp-relay=false"}`;return 0===e.alterId&&(e["vmess-aead"]=!0),void 0!==e["vmess-aead"]&&(r+=`,aead=${e["vmess-aead"]}`),r+=`,tag=${e.name}`;case"trojan":return`trojan=${e.server}:${e.port},password=${e.password}${e.sni?",tls-host="+e.sni:""},over-tls=true,tls-verification=${e["skip-cert-verify"]?"false":"true"},fast-open=${e.tfo||!1}${e.udp?",udp-relay=true":",udp-relay=false"},tag=${e.name}`;case"http":return n="",e.tls&&(n=`,over-tls=true,tls-verification=${e["skip-cert-verify"]?"false":"true"}${e.sni?",tls-host="+e.sni:""}`),`http=${e.server}:${e.port},username=${e.username},password=${e.password}${n},fast-open=${e.tfo||!1},tag=${e.name}`}throw new Error(`Platform QX does not support proxy type: ${e.type}`)}},Surge:{produce:e=>{let t,n,r="";switch(e.type){case"ss":if(t="",e.plugin){const{host:n,mode:r}=e["plugin-opts"];if("obfs"!==e.plugin)throw new Error(`Platform Surge does not support obfs option: ${e.obfs}`);t=`,obfs=${r}${n?",obfs-host="+n:""}`}r=`${e.name}=ss,${e.server}, ${e.port},encrypt-method=${e.cipher},password=${e.password}${t},tfo=${e.tfo||"false"},udp-relay=${e.udp||"false"}`;break;case"vmess":if(n="",r=`${e.name}=vmess,${e.server},${e.port},username=${e.uuid},tls=${e.tls||"false"},tfo=${e.tfo||"false"}`,0===e.alterId&&(e["vmess-aead"]=!0),void 0!==e["vmess-aead"]&&(r+=`,vmess-aead=${e["vmess-aead"]}`),"ws"===e.network){const t=e["ws-opts"].path||"/",n=Object.entries(e["ws-opts"].headers).map(([e,t])=>`${e}:"${t}"`).join("|");r+=`,ws=true${t?",ws-path="+t:""}${n?",ws-headers="+n:""}`}e.tls&&(r+=`${void 0!==e["skip-cert-verify"]?",skip-cert-verify="+e["skip-cert-verify"]:""}`,r+=e.sni?`,sni=${e.sni}`:"");break;case"trojan":r=`${e.name}=trojan,${e.server},${e.port},password=${e.password}${void 0!==e["skip-cert-verify"]?",skip-cert-verify="+e["skip-cert-verify"]:""}${e.sni?",sni="+e.sni:""},tfo=${e.tfo||"false"},udp-relay=${e.udp||"false"}`;break;case"http":n=", tls=false",e.tls&&(n=`,tls=true,skip-cert-verify=${e["skip-cert-verify"]},sni=${e.sni}`),r=`${e.name}=http, ${e.server}, ${e.port}${e.username?",username="+e.username:""}${e.password?",password="+e.password:""}${n},tfo=${e.tfo||"false"}`;break;default:throw new Error(`Platform Surge does not support proxy type: ${e.type}`)}return r+=void 0!==e["surge-hybrid"]?`,hybrid=${e["surge-hybrid"]}`:""}},Loon:{produce:e=>{let t="",n="",r="",s="";switch(void 0!==e.udp&&(r=e.udp?",udp=true":",udp=false"),s=`,fast-open=${e.tfo||!1}`,e.type){case"ss":if(t=",,",e.plugin){if("obfs"!==e.plugin)throw new Error(`Platform Loon does not support obfs option: ${e.obfs}`);{const{mode:n,host:r}=e["plugin-opts"];t=`,${n},${r||""}`}}return`${e.name}=shadowsocks,${e.server},${e.port},${e.cipher},"${e.password}"${t}${r}${s}`;case"ssr":return`${e.name}=shadowsocksr,${e.server},${e.port},${e.cipher},"${e.password}",${e.protocol},{${e["protocol-param"]||""}},${e.obfs},{${e["obfs-param"]||""}}${r}${s}`;case"vmess":t="",t="ws"===e.network?`,transport:ws,host:${e["ws-opts"].headers.Host||e.server},path:${e["ws-opts"].path||"/"}`:",transport:tcp",e.tls&&(t+=`${e.sni?",tls-name:"+e.sni:""},skip-cert-verify:${e["skip-cert-verify"]||"false"}`);let o=`${e.name}=vmess,${e.server},${e.port},${"auto"===e.cipher?"none":e.cipher},"${e.uuid}",over-tls:${e.tls||"false"}${t}`;return 0===e.alterId&&(e["vmess-aead"]=!0),void 0!==e["vmess-aead"]&&(o+=`,vmess-aead=${e["vmess-aead"]}`),o;case"trojan":return`${e.name}=trojan,${e.server},${e.port},"${e.password}"${e.sni?",tls-name:"+e.sni:""},skip-cert-verify:${e["skip-cert-verify"]||"false"}${r}`;case"http":n="";const i=`${e.name}=${e.tls?"http":"https"},${e.server},${e.port},${e.username||""},${e.password||""}`;return e.tls?i+(n=`${e.sni?",tls-name:"+e.sni:""},skip-cert-verify:${e["skip-cert-verify"]}`):i}throw new Error(`Platform Loon does not support proxy type: ${e.type}`)}},Clash:{type:"ALL",produce:e=>"proxies:\n"+e.map(e=>(delete e.supported," - "+JSON.stringify(e)+"\n")).join("")},URI:{type:"SINGLE",produce:e=>{let t="";switch(e.type){case"ss":const n=`${e.cipher}:${e.password}`;if(t=`ss://${Base64.safeEncode(n)}@${e.server}:${e.port}/`,e.plugin){t+="?plugin=";const n=e["plugin-opts"];switch(e.plugin){case"obfs":t+=encodeURIComponent(`simple-obfs;obfs=${n.mode}${n.host?";obfs-host="+n.host:""}`);break;case"v2ray-plugin":t+=encodeURIComponent(`v2ray-plugin;obfs=${n.mode}${n.host?";obfs-host"+n.host:""}${n.tls?";tls":""}`);break;default:throw new Error(`Unsupported plugin option: ${e.plugin}`)}}t+=`#${encodeURIComponent(e.name)}`;break;case"ssr":t=`${e.server}:${e.port}:${e.protocol}:${e.cipher}:${e.obfs}:${Base64.safeEncode(e.password)}/`,t+=`?remarks=${Base64.safeEncode(e.name)}${e["obfs-param"]?"&obfsparam="+Base64.safeEncode(e["obfs-param"]):""}${e["protocol-param"]?"&protocolparam="+Base64.safeEncode(e["protocol-param"]):""}`,t="ssr://"+Base64.safeEncode(t);break;case"vmess":t={ps:e.name,add:e.server,port:e.port,id:e.uuid,type:"",aid:0,net:e.network||"tcp",tls:e.tls?"tls":""},"ws"===e.network&&(t.path=e["ws-opts"].path||"/",t.host=e["ws-opts"].headers.Host||e.server),t="vmess://"+Base64.safeEncode(JSON.stringify(t));break;case"trojan":t=`trojan://${e.password}@${e.server}:${e.port}#${encodeURIComponent(e.name)}`;break;default:throw new Error(`Cannot handle proxy type: ${e.type}`)}return t}},JSON:{type:"ALL",produce:e=>JSON.stringify(e,null,2)}}}();function preprocess(e){for(const t of PROXY_PREPROCESSORS)try{if(t.test(e))return $.info(`Pre-processor [${t.name}] activated`),t.parse(e)}catch(e){$.error(`Parser [${t.name}] failed\n Reason: ${e}`)}return e}function safeMatch(e,t){let n;try{n=e.test(t)}catch(e){n=!1}return n}function parse(e){const t=(e=preprocess(e)).split("\n"),n=[];let r;for(let e of t){if(0===(e=e.trim()).length)continue;let t=r&&safeMatch(r,e);if(!t)for(const n of PROXY_PARSERS)if(safeMatch(n,e)){r=n,t=!0,$.info(`Proxy parser: ${n.name} is activated`);break}if(t)try{const t=r.parse(e);t||$.error(`Parser ${r.name} return nothing for \n${e}\n`),n.push(t)}catch(t){$.error(`Failed to parse line: \n ${e}\n Reason: ${t.stack}`)}else $.error(`Failed to find a rule to parse line: \n${e}\n`)}return n}async function process(e,t=[],n){for(const r of t){let t,s;if(-1!==r.type.indexOf("Script")){const{mode:e,content:n}=r.args;if("link"===e)try{t=await $.http.get(n).then(e=>e.body)}catch(e){$.error(`Error when downloading remote script: ${r.args.content}.\n Reason: ${e}`);continue}else t=n}PROXY_PROCESSORS[r.type]?($.info(`Applying "${r.type}" with arguments:\n >>> ${JSON.stringify(r.args,null,2)||"None"}`),e=ApplyProcessor(s=-1!==r.type.indexOf("Script")?PROXY_PROCESSORS[r.type](t,n):PROXY_PROCESSORS[r.type](r.args),e)):$.error(`Unknown operator: "${r.type}"`)}return e}function produce(e,t){const n=PROXY_PRODUCERS[t];if(!n)throw new Error(`Target platform: ${t} is not supported!`);return e=e.filter(e=>!(e.supported&&!1===e.supported[t])),$.info(`Producing proxies for target: ${t}`),void 0===n.type||"SINGLE"===n.type?e.map(e=>{try{return n.produce(e)}catch(t){return $.error(`Cannot produce proxy: ${JSON.stringify(e,null,2)}\nReason: ${t}`),""}}).filter(e=>e.length>0).join("\n"):"ALL"===n.type?n.produce(e):void 0}return{parse:parse,process:process,produce:produce}}(),RuleUtils=function(){const e=[[/^(DOMAIN|host|HOST)$/,"DOMAIN"],[/^(DOMAIN-KEYWORD|host-keyword|HOST-KEYWORD)$/,"DOMAIN-KEYWORD"],[/^(DOMAIN-SUFFIX|host-suffix|HOST-SUFFIX)$/,"DOMAIN-SUFFIX"],[/^USER-AGENT$/i,"USER-AGENT"],[/^PROCESS-NAME$/,"PROCESS-NAME"],[/^(DEST-PORT|DST-PORT)$/,"DST-PORT"],[/^SRC-IP(-CIDR)?$/,"SRC-IP"],[/^(IN|SRC)-PORT$/,"IN-PORT"],[/^PROTOCOL$/,"PROTOCOL"],[/^IP-CIDR$/i,"IP-CIDR"],[/^(IP-CIDR6|ip6-cidr|IP6-CIDR)$/]],t=function(){return[{name:"HTML",test:e=>/^/.test(e),parse:e=>""},{name:"Clash Provider",test:e=>0===e.indexOf("payload:"),parse:e=>e.replace("payload:","").replace(/^\s*-\s*/gm,"")}]}(),n=function(){return[{name:"Universal Rule Parser",test:()=>!0,parse:t=>{const n=t.split("\n"),r=[];for(let t of n)if(0!==(t=t.trim()).length&&!/\s*#/.test(t))try{const n=t.split(",").map(e=>e.trim());let s=n[0],o=!1;for(const t of e)if(t[0].test(s)){o=!0;const e={type:t[1],content:n[1]};"IP-CIDR"!==e.type&&"IP-CIDR6"!==e.type||(e.options=n.slice(2)),r.push(e)}if(!o)throw new Error("Invalid rule type: "+s)}catch(e){console.error(`Failed to parse line: ${t}\n Reason: ${e}`)}return r}}]}(),r=function(){return{"Regex Filter":function({regex:e=[],keep:t=!0}){return{name:"Regex Filter",func:n=>n.map(n=>{const r=e.some(e=>(e=new RegExp(e)).test(n));return t?r:!r})}},"Remove Duplicate Filter":function(){return{name:"Remove Duplicate Filter",func:e=>{const t=new Set,n=[];return e.forEach(e=>{const r=e.options||[];r.sort();const s=`${e.type},${e.content},${JSON.stringify(r)}`;t.has(s)||(n.push(e),t.add(s))}),n}}},"Type Filter":function(e){return{name:"Type Filter",func:t=>t.map(t=>e.some(e=>t.type===e))}},"Regex Replace Operator":function(e){return{name:"Regex Rename Operator",func:t=>t.map(t=>{for(const{expr:n,now:r}of e)t.content=t.content.replace(new RegExp(n,"g"),r).trim();return t})}}}}(),s=function(){return{QX:{type:"SINGLE",func:e=>-1!==["URL-REGEX","DEST-PORT","SRC-IP","IN-PORT","PROTOCOL"].indexOf(e.type)?null:`${{"DOMAIN-KEYWORD":"HOST-KEYWORD","DOMAIN-SUFFIX":"HOST-SUFFIX",DOMAIN:"HOST","IP-CIDR6":"IP6-CIDR"}[e.type]||e.type},${e.content},SUB-STORE`},Surge:{type:"SINGLE",func:e=>{let t=`${e.type},${e.content}`;return"IP-CIDR"!==e.type&&"IP-CIDR6"!==e.type||(t+=e.options?`,${e.options[0]}`:""),t}},Loon:{type:"SINGLE",func:e=>-1!==["DEST-PORT","SRC-IP","IN-PORT","PROTOCOL"].indexOf(e.type)?null:(e=>{let t=`${e.type},${e.content}`;return"IP-CIDR"!==e.type&&"IP-CIDR6"!==e.type||(t+=e.options?`,${e.options[0]}`:""),t})(e)},Clash:{type:"ALL",func:e=>{const t={"DEST-PORT":"DST-PORT","SRC-IP":"SRC-IP-CIDR","IN-PORT":"SRC-PORT"},n={payload:e.map(e=>{let n=`${t[e.type]||e.type},${e.content}`;return"IP-CIDR"!==e.type&&"IP-CIDR6"!==e.type||(n+=e.options?`,${e.options[0]}`:""),n})};return YAML.stringify(n)}}}}();return{parse:function(e){e=function(e){for(const n of t)try{if(n.test(e))return $.info(`Pre-processor [${n.name}] activated`),n.parse(e)}catch(e){$.error(`Parser [${n.name}] failed\n Reason: ${e}`)}return e}(e);for(const t of n){let n;try{n=t.test(e)}catch(e){n=!1}if(n)return $.info(`Rule parser [${t.name}] is activated!`),t.parse(e)}},process:async function(e,t){for(const n of t){if(!r[n.type]){console.error(`Unknown operator: ${n.type}!`);continue}const t=r[n.type](n.args);$.info(`Applying "${n.type}" with arguments: \n >>> ${JSON.stringify(n.args)||"None"}`),e=ApplyProcessor(t,e)}return e},produce:function(e,t){const n=s[t];if(!n)throw new Error(`Target platform: ${t} is not supported!`);return void 0===n.type||"SINGLE"===n.type?e.map(e=>{try{return n.func(e)}catch(t){return console.log(`ERROR: cannot produce rule: ${JSON.stringify(e)}\nReason: ${t}`),""}}).filter(e=>e.length>0).join("\n"):"ALL"===n.type?n.func(e):void 0}}}();function getBuiltInRules(){return{AD:{name:"AD",description:"",urls:["https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-surge.txt","https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Providers/BanAD.yaml"]},Global:{name:"Global",description:"",urls:["https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Providers/ProxyGFWlist.yaml","https://raw.githubusercontent.com/DivineEngine/Profiles/master/Quantumult/Filter/Global.list"]},CN:{name:"CN",description:"",urls:["https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Providers/ChinaDomain.yaml","https://raw.githubusercontent.com/DivineEngine/Profiles/master/Quantumult/Filter/China.list"]}}}function ApplyProcessor(e,t){return-1!==e.name.indexOf("Filter")?function(e,t){let n=FULL(t.length,!0);try{n=AND(n,e.func(t))}catch(t){console.log(`Cannot apply filter ${e.name}\n Reason: ${t}`)}return t.filter((e,t)=>n[t])}(e,t):-1!==e.name.indexOf("Operator")?function(e,t){let n=clone(t);try{const t=e.func(n);t&&(n=t)}catch(t){console.log(`Cannot apply operator ${e.name}! Reason: ${t}`)}return n}(e,t):void 0}function AND(...e){return e.reduce((e,t)=>e.map((e,n)=>t[n]&&e))}function OR(...e){return e.reduce((e,t)=>e.map((e,n)=>t[n]||e))}function NOT(e){return e.map(e=>!e)}function FULL(e,t){return[...Array(e).keys()].map(()=>t)}function clone(e){return JSON.parse(JSON.stringify(e))}function buildRegex(e,...t){return t=t.join(""),e.startsWith("(?i)")?(e=e.substr(4),new RegExp(e,"i"+t)):new RegExp(e,t)}function ENV(){const e="undefined"!=typeof $task,t="undefined"!=typeof $loon,n="undefined"!=typeof $httpClient&&!t,r="function"==typeof require&&"undefined"!=typeof $jsbox;return{isQX:e,isLoon:t,isSurge:n,isNode:"function"==typeof require&&!r,isJSBox:r,isRequest:"undefined"!=typeof $request,isScriptable:"undefined"!=typeof importModule}}function HTTP(e={baseURL:""}){const{isQX:t,isLoon:n,isSurge:r,isScriptable:s,isNode:o}=ENV(),i=/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;const a={};return["GET","POST","PUT","DELETE","HEAD","OPTIONS","PATCH"].forEach(c=>a[c.toLowerCase()]=(a=>(function(a,c){c="string"==typeof c?{url:c}:c;const l=e.baseURL;l&&!i.test(c.url||"")&&(c.url=l?l+c.url:c.url);const p=(c={...e,...c}).timeout,u={onRequest:()=>{},onResponse:e=>e,onTimeout:()=>{},...c.events};let f,d;if(u.onRequest(a,c),t)f=$task.fetch({method:a,url:c.url,headers:c.headers,body:c.body});else if(n||r||o)f=new Promise((e,t)=>{(o?require("request"):$httpClient)[a.toLowerCase()](c,(n,r,s)=>{n?t(n):e({statusCode:r.status||r.statusCode,headers:r.headers,body:s})})});else if(s){const e=new Request(c.url);e.method=a,e.headers=c.headers,e.body=c.body,f=new Promise((t,n)=>{e.loadString().then(n=>{t({statusCode:e.response.statusCode,headers:e.response.headers,body:n})}).catch(e=>n(e))})}const h=p?new Promise((e,t)=>{d=setTimeout(()=>(u.onTimeout(),t(`${a} URL: ${c.url} exceeds the timeout ${p} ms`)),p)}):null;return(h?Promise.race([h,f]).then(e=>(clearTimeout(d),e)):f).then(e=>u.onResponse(e))})(c,a))),a}function API(e="untitled",t=!1){const{isQX:n,isLoon:r,isSurge:s,isNode:o,isJSBox:i,isScriptable:a}=ENV();return new class{constructor(e,t){this.name=e,this.debug=t,this.http=HTTP(),this.env=ENV(),this.node=(()=>{if(o){return{fs:require("fs")}}return null})(),this.initCache();Promise.prototype.delay=function(e){return this.then(function(t){return((e,t)=>new Promise(function(n){setTimeout(n.bind(null,t),e)}))(e,t)})}}initCache(){if(n&&(this.cache=JSON.parse($prefs.valueForKey(this.name)||"{}")),(r||s)&&(this.cache=JSON.parse($persistentStore.read(this.name)||"{}")),o){let e="root.json";this.node.fs.existsSync(e)||this.node.fs.writeFileSync(e,JSON.stringify({}),{flag:"wx"},e=>console.log(e)),this.root={},e=`${this.name}.json`,this.node.fs.existsSync(e)?this.cache=JSON.parse(this.node.fs.readFileSync(`${this.name}.json`)):(this.node.fs.writeFileSync(e,JSON.stringify({}),{flag:"wx"},e=>console.log(e)),this.cache={})}}persistCache(){const e=JSON.stringify(this.cache,null,2);n&&$prefs.setValueForKey(e,this.name),(r||s)&&$persistentStore.write(e,this.name),o&&(this.node.fs.writeFileSync(`${this.name}.json`,e,{flag:"w"},e=>console.log(e)),this.node.fs.writeFileSync("root.json",JSON.stringify(this.root,null,2),{flag:"w"},e=>console.log(e)))}write(e,t){if(this.log(`SET ${t}`),-1!==t.indexOf("#")){if(t=t.substr(1),s||r)return $persistentStore.write(e,t);if(n)return $prefs.setValueForKey(e,t);o&&(this.root[t]=e)}else this.cache[t]=e;this.persistCache()}read(e){return this.log(`READ ${e}`),-1===e.indexOf("#")?this.cache[e]:(e=e.substr(1),s||r?$persistentStore.read(e):n?$prefs.valueForKey(e):o?this.root[e]:void 0)}delete(e){if(this.log(`DELETE ${e}`),-1!==e.indexOf("#")){if(e=e.substr(1),s||r)return $persistentStore.write(null,e);if(n)return $prefs.removeValueForKey(e);o&&delete this.root[e]}else delete this.cache[e];this.persistCache()}notify(e,t="",c="",l={}){const p=l["open-url"],u=l["media-url"];if(n&&$notify(e,t,c,l),s&&$notification.post(e,t,c+`${u?"\n多媒体:"+u:""}`,{url:p}),r){let n={};p&&(n.openUrl=p),u&&(n.mediaUrl=u),"{}"===JSON.stringify(n)?$notification.post(e,t,c):$notification.post(e,t,c,n)}if(o||a){const n=c+(p?`\n点击跳转: ${p}`:"")+(u?`\n多媒体: ${u}`:"");if(i){require("push").schedule({title:e,body:(t?t+"\n":"")+n})}else console.log(`${e}\n${t}\n${n}\n\n`)}}log(e){this.debug&&console.log(`[${this.name}] LOG: ${e}`)}info(e){console.log(`[${this.name}] INFO: ${e}`)}error(e){console.log(`[${this.name}] ERROR: ${e}`)}wait(e){return new Promise(t=>setTimeout(t,e))}done(e={}){n||r||s?$done(e):o&&!i&&"undefined"!=typeof $context&&($context.headers=e.headers,$context.statusCode=e.statusCode,$context.body=e.body)}}(e,t)}function Gist({token:e,key:t}){const n=HTTP({baseURL:"https://api.github.com",headers:{Authorization:`token ${e}`,"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.141 Safari/537.36"},events:{onResponse:e=>/^[45]/.test(String(e.statusCode))?Promise.reject(`ERROR: ${JSON.parse(e.body).message}`):e}});async function r(){return n.get("/gists").then(e=>{const n=JSON.parse(e.body);for(let e of n)if(e.description===t)return e.id;return-1})}this.upload=async function({filename:e,content:s}){const o=await r(),i={[e]:{content:s}};return-1===o?n.post({url:"/gists",body:JSON.stringify({description:t,public:!1,files:i})}):n.patch({url:`/gists/${o}`,body:JSON.stringify({files:i})})},this.download=async function(e){const t=await r();if(-1===t)return Promise.reject("未找到Gist备份!");try{const{files:r}=await n.get(`/gists/${t}`).then(e=>JSON.parse(e.body)),s=r[e].raw_url;return await n.get(s).then(e=>e.body)}catch(e){return Promise.reject(e)}}}function express({port:e}={port:3e3}){const{isNode:t}=ENV(),n={"Content-Type":"text/plain;charset=UTF-8","Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST,GET,OPTIONS,PATCH,PUT,DELETE","Access-Control-Allow-Headers":"Origin, X-Requested-With, Content-Type, Accept"};if(t){const t=require("express"),r=require("body-parser"),s=t();return s.use(r.json({verify:a})),s.use(r.urlencoded({verify:a,extended:!0})),s.use(r.raw({verify:a,type:"*/*"})),s.use((e,t,r)=>{t.set(n),r()}),s.start=(()=>{s.listen(e,()=>{$.log(`Express started on port: ${e}`)})}),s}const r=[],s=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD'","ALL"],o=(e,t=0)=>{let{method:n,url:s,headers:i,body:a}=e;/json/i.test(i["Content-Type"])&&(a=JSON.parse(a)),n=n.toUpperCase();const{path:u,query:f}=function(e){const t=(e.match(/https?:\/\/[^\/]+(\/[^?]*)/)||[])[1]||"/",n=e.indexOf("?"),r={};if(-1!==n){let t=e.slice(e.indexOf("?")+1).split("&");for(let e=0;em&&(h=r[d],m=e.split("/").length)}if(h){const e=()=>{o(n,s,d)},t={method:n,url:s,path:u,query:f,params:p(h.pattern,u),headers:i,body:a},r=c(),l=h.callback,m=e=>{r.status(500).json({status:"failed",message:`Internal Server Error: ${e}`})};if("AsyncFunction"===l.constructor.name)l(t,r,e).catch(m);else try{l(t,r,e)}catch(e){m(e)}}else{c().status(404).json({status:"failed",message:"ERROR: 404 not found"})}},i={};return s.forEach(e=>{i[e.toLowerCase()]=((t,n)=>{r.push({method:e,pattern:t,callback:n})})}),i.route=(e=>{const t={};return s.forEach(n=>{t[n.toLowerCase()]=(s=>(r.push({method:n,pattern:e,callback:s}),t))}),t}),i.start=(()=>{o($request)}),i;function a(e,t,n,r){n&&n.length&&(e.rawBody=n.toString(r||"utf8"))}function c(){let e=200;const{isQX:t,isLoon:r,isSurge:s}=ENV(),o=n,i={200:"HTTP/1.1 200 OK",201:"HTTP/1.1 201 Created",302:"HTTP/1.1 302 Found",307:"HTTP/1.1 307 Temporary Redirect",308:"HTTP/1.1 308 Permanent Redirect",404:"HTTP/1.1 404 Not Found",500:"HTTP/1.1 500 Internal Server Error"};return new class{status(t){return e=t,this}send(n=""){const a={status:t?i[e]:e,body:n,headers:o};t?$done(a):(r||s)&&$done({response:a})}end(){this.send()}html(e){this.set("Content-Type","text/html;charset=UTF-8"),this.send(e)}json(e){this.set("Content-Type","application/json;charset=UTF-8"),this.send(JSON.stringify(e))}set(e,t){return o[e]=t,this}}}function l(e,t){if(e instanceof RegExp&&e.test(t))return!0;if("/"===e)return!0;if(-1===e.indexOf(":")){const n=t.split("/"),r=e.split("/");for(let e=0;e>>6)+n(128|63&t):n(224|t>>>12&15)+n(128|t>>>6&63)+n(128|63&t):(t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320),n(240|t>>>18&7)+n(128|t>>>12&63)+n(128|t>>>6&63)+n(128|63&t))},s=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,o=function(t){const n=[0,2,1][t.length%3],r=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[e.charAt(r>>>18),e.charAt(r>>>12&63),n>=2?"=":e.charAt(r>>>6&63),n>=1?"=":e.charAt(63&r)].join("")};this.encode=function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)?e.toString("base64"):function(e){return e.replace(s,r)}(String(e)).replace(/[\s\S]{1,3}/g,o)};const i=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,a=function(e){switch(e.length){case 4:const t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return n(55296+(t>>>10))+n(56320+(1023&t));case 3:return n((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return n((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},c=function(e){const r=e.length,s=r%4,o=(r>0?t[e.charAt(0)]<<18:0)|(r>1?t[e.charAt(1)]<<12:0)|(r>2?t[e.charAt(2)]<<6:0)|(r>3?t[e.charAt(3)]:0),i=[n(o>>>16),n(o>>>8&255),n(255&o)];return i.length-=[0,0,2,1][s],i.join("")},l=function(e){return e.replace(/\S{1,4}/g,c)},p=function(e){return l(e).replace(i,a)};this.decode=function(e){return p(String(e).replace(/[-_]/g,function(e){return"-"===e?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,"")).replace(/>/g,">").replace(/</g,"<")},this.safeEncode=function(e){return this.encode(e.replace(/\+/g,"-").replace(/\//g,"_"))},this.safeDecode=function(e){return this.decode(e.replace(/-/g,"+").replace(/_/g,"/"))}}var YAML=function(){function e(e){return null==e}var t={isNothing:e,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(t){return Array.isArray(t)?t:e(t)?[]:[t]},repeat:function(e,t){var n,r="";for(n=0;na&&(t=r-a+(o=" ... ").length),n-r>a&&(n=r+a-(i=" ...").length),{str:o+e.slice(t,n).replace(/\t/g,"→")+i,pos:r-t+o.length}}function i(e,n){return t.repeat(" ",n-e.length)+e}var a=function(e,n){if(n=Object.create(n||null),!e.buffer)return null;n.maxLength||(n.maxLength=79),"number"!=typeof n.indent&&(n.indent=1),"number"!=typeof n.linesBefore&&(n.linesBefore=3),"number"!=typeof n.linesAfter&&(n.linesAfter=2);for(var r,s=/\r?\n|\r|\0/g,a=[0],c=[],l=-1;r=s.exec(e.buffer);)c.push(r.index),a.push(r.index+r[0].length),e.position<=r.index&&l<0&&(l=a.length-2);l<0&&(l=a.length-1);var p,u,f="",d=Math.min(e.line+n.linesAfter,c.length).toString().length,h=n.maxLength-(n.indent+d+3);for(p=1;p<=n.linesBefore&&!(l-p<0);p++)u=o(e.buffer,a[l-p],c[l-p],e.position-(a[l]-a[l-p]),h),f=t.repeat(" ",n.indent)+i((e.line-p+1).toString(),d)+" | "+u.str+"\n"+f;for(u=o(e.buffer,a[l],c[l],e.position,h),f+=t.repeat(" ",n.indent)+i((e.line+1).toString(),d)+" | "+u.str+"\n",f+=t.repeat("-",n.indent+d+3+u.pos)+"^\n",p=1;p<=n.linesAfter&&!(l+p>=c.length);p++)u=o(e.buffer,a[l+p],c[l+p],e.position-(a[l]-a[l+p]),h),f+=t.repeat(" ",n.indent)+i((e.line+p+1).toString(),d)+" | "+u.str+"\n";return f.replace(/\n$/,"")},c=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],l=["scalar","sequence","mapping"];var p=function(e,t){var n,r;if(t=t||{},Object.keys(t).forEach(function(t){if(-1===c.indexOf(t))throw new s('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')}),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=(n=t.styleAliases||null,r={},null!==n&&Object.keys(n).forEach(function(e){n[e].forEach(function(t){r[String(t)]=e})}),r),-1===l.indexOf(this.kind))throw new s('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function u(e,t){var n=[];return e[t].forEach(function(e){var t=n.length;n.forEach(function(n,r){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=r)}),n[t]=e}),n}function f(e){return this.extend(e)}f.prototype.extend=function(e){var t=[],n=[];if(e instanceof p)n.push(e);else if(Array.isArray(e))n=n.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new s("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit))}t.forEach(function(e){if(!(e instanceof p))throw new s("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new s("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new s("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")}),n.forEach(function(e){if(!(e instanceof p))throw new s("Specified list of YAML types (or a single Type object) contains a non-Type object.")});var r=Object.create(f.prototype);return r.implicit=(this.implicit||[]).concat(t),r.explicit=(this.explicit||[]).concat(n),r.compiledImplicit=u(r,"implicit"),r.compiledExplicit=u(r,"explicit"),r.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function r(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),O=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var A=/^[-+]?[0-9]+e/;var C=new p("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!O.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||t.isNegativeZero(e))},represent:function(e,n){var r;if(isNaN(e))switch(n){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(n){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(n){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(t.isNegativeZero(e))return"-0.0";return r=e.toString(10),A.test(r)?r.replace("e",".e"):r},defaultStyle:"lowercase"}),k=y.extend({implicit:[$,w,S,C]}),x=k,R=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),I=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var N=new p("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==R.exec(e)||null!==I.exec(e))},construct:function(e){var t,n,r,s,o,i,a,c,l=0,p=null;if(null===(t=R.exec(e))&&(t=I.exec(e)),null===t)throw new Error("Date resolve error");if(n=+t[1],r=+t[2]-1,s=+t[3],!t[4])return new Date(Date.UTC(n,r,s));if(o=+t[4],i=+t[5],a=+t[6],t[7]){for(l=t[7].slice(0,3);l.length<3;)l+="0";l=+l}return t[9]&&(p=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(p=-p)),c=new Date(Date.UTC(n,r,s,o,i,a,l)),p&&c.setTime(c.getTime()-p),c},instanceOf:Date,represent:function(e){return e.toISOString()}});var T=new p("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),P="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var E=new p("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,r=0,s=e.length,o=P;for(n=0;n64)){if(t<0)return!1;r+=6}return r%8==0},construct:function(e){var t,n,r=e.replace(/[\r\n=]/g,""),s=r.length,o=P,i=0,a=[];for(t=0;t>16&255),a.push(i>>8&255),a.push(255&i)),i=i<<6|o.indexOf(r.charAt(t));return 0==(n=s%4*6)?(a.push(i>>16&255),a.push(i>>8&255),a.push(255&i)):18===n?(a.push(i>>10&255),a.push(i>>2&255)):12===n&&a.push(i>>4&255),new Uint8Array(a)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,n,r="",s=0,o=e.length,i=P;for(t=0;t>18&63],r+=i[s>>12&63],r+=i[s>>6&63],r+=i[63&s]),s=(s<<8)+e[t];return 0==(n=o%3)?(r+=i[s>>18&63],r+=i[s>>12&63],r+=i[s>>6&63],r+=i[63&s]):2===n?(r+=i[s>>10&63],r+=i[s>>4&63],r+=i[s<<2&63],r+=i[64]):1===n&&(r+=i[s>>2&63],r+=i[s<<4&63],r+=i[64],r+=i[64]),r}}),j=Object.prototype.hasOwnProperty,F=Object.prototype.toString;var D=new p("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,r,s,o,i=[],a=e;for(t=0,n=a.length;t>10),56320+(e-65536&1023))}for(var le=new Array(256),pe=new Array(256),ue=0;ue<256;ue++)le[ue]=ae(ue)?1:0,pe[ue]=ae(ue);function fe(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||_,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function de(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=a(n),new s(t,n)}function he(e,t){throw de(e,t)}function me(e,t){e.onWarning&&e.onWarning.call(null,de(e,t))}var ge={YAML:function(e,t,n){var r,s,o;null!==e.version&&he(e,"duplication of %YAML directive"),1!==n.length&&he(e,"YAML directive accepts exactly one argument"),null===(r=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&he(e,"ill-formed argument of the YAML directive"),s=parseInt(r[1],10),o=parseInt(r[2],10),1!==s&&he(e,"unacceptable YAML version of the document"),e.version=n[0],e.checkLineBreaks=o<2,1!==o&&2!==o&&me(e,"unsupported YAML version of the document")},TAG:function(e,t,n){var r,s;2!==n.length&&he(e,"TAG directive accepts exactly two arguments"),r=n[0],s=n[1],Z.test(r)||he(e,"ill-formed tag handle (first argument) of the TAG directive"),H.call(e.tagMap,r)&&he(e,'there is a previously declared suffix for "'+r+'" tag handle'),ee.test(s)||he(e,"ill-formed tag prefix (second argument) of the TAG directive");try{s=decodeURIComponent(s)}catch(t){he(e,"tag prefix is malformed: "+s)}e.tagMap[r]=s}};function ye(e,t,n,r){var s,o,i,a;if(t1&&(e.result+=t.repeat("\n",n-1))}function Ae(e,t){var n,r,s=e.tag,o=e.anchor,i=[],a=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=i),r=e.input.charCodeAt(e.position);0!==r&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,he(e,"tab characters must not be used in indentation")),45===r)&&se(e.input.charCodeAt(e.position+1));)if(a=!0,e.position++,ve(e,!0,-1)&&e.lineIndent<=t)i.push(null),r=e.input.charCodeAt(e.position);else if(n=e.line,xe(e,t,Y,!1,!0),i.push(e.result),ve(e,!0,-1),r=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==r)he(e,"bad indentation of a sequence entry");else if(e.lineIndentn?m=1:e.lineIndent===n?m=0:e.lineIndentn?m=1:e.lineIndent===n?m=0:e.lineIndentt)&&(y&&(i=e.line,a=e.lineStart,c=e.position),xe(e,t,G,!0,s)&&(y?m=e.result:g=e.result),y||(we(e,f,d,h,m,g,i,a,c),h=m=g=null),ve(e,!0,-1),l=e.input.charCodeAt(e.position)),(e.line===o||e.lineIndent>t)&&0!==l)he(e,"bad indentation of a mapping entry");else if(e.lineIndent=0))break;0===o?he(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):p?he(e,"repeat of an indentation width identifier"):(u=n+o-1,p=!0)}if(re(i)){do{i=e.input.charCodeAt(++e.position)}while(re(i));if(35===i)do{i=e.input.charCodeAt(++e.position)}while(!ne(i)&&0!==i)}for(;0!==i;){for(be(e),e.lineIndent=0,i=e.input.charCodeAt(e.position);(!p||e.lineIndentu&&(u=e.lineIndent),ne(i))f++;else{if(e.lineIndent0){for(s=i,o=0;s>0;s--)(i=ie(a=e.input.charCodeAt(++e.position)))>=0?o=(o<<4)+i:he(e,"expected hexadecimal character");e.result+=ce(o),e.position++}else he(e,"unknown escape sequence");n=r=e.position}else ne(a)?(ye(e,n,r,!0),Oe(e,ve(e,!1,t)),n=r=e.position):e.position===e.lineStart&&Se(e)?he(e,"unexpected end of the document within a double quoted scalar"):(e.position++,r=e.position)}he(e,"unexpected end of the stream within a double quoted scalar")}(e,d)?y=!0:!function(e){var t,n,r;if(42!==(r=e.input.charCodeAt(e.position)))return!1;for(r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!se(r)&&!oe(r);)r=e.input.charCodeAt(++e.position);return e.position===t&&he(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),H.call(e.anchorMap,n)||he(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],ve(e,!0,-1),!0}(e)?function(e,t,n){var r,s,o,i,a,c,l,p,u=e.kind,f=e.result;if(se(p=e.input.charCodeAt(e.position))||oe(p)||35===p||38===p||42===p||33===p||124===p||62===p||39===p||34===p||37===p||64===p||96===p)return!1;if((63===p||45===p)&&(se(r=e.input.charCodeAt(e.position+1))||n&&oe(r)))return!1;for(e.kind="scalar",e.result="",s=o=e.position,i=!1;0!==p;){if(58===p){if(se(r=e.input.charCodeAt(e.position+1))||n&&oe(r))break}else if(35===p){if(se(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&Se(e)||n&&oe(p))break;if(ne(p)){if(a=e.line,c=e.lineStart,l=e.lineIndent,ve(e,!1,-1),e.lineIndent>=t){i=!0,p=e.input.charCodeAt(e.position);continue}e.position=o,e.line=a,e.lineStart=c,e.lineIndent=l;break}}i&&(ye(e,s,o,!1),Oe(e,e.line-a),s=o=e.position,i=!1),re(p)||(o=e.position+1),p=e.input.charCodeAt(++e.position)}return ye(e,s,o,!1),!!e.result||(e.kind=u,e.result=f,!1)}(e,d,B===r)&&(y=!0,null===e.tag&&(e.tag="?")):(y=!0,null===e.tag&&null===e.anchor||he(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===m&&(y=c&&Ae(e,h))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&he(e,'unacceptable node kind for ! tag; it should be "scalar", not "'+e.kind+'"'),l=0,p=e.implicitTypes.length;l"),null!==e.result&&f.kind!==e.kind&&he(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+f.kind+'", not "'+e.kind+'"'),f.resolve(e.result,e.tag)?(e.result=f.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):he(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||y}function Re(e){var t,n,r,s,o=e.position,i=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(s=e.input.charCodeAt(e.position))&&(ve(e,!0,-1),s=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==s));){for(i=!0,s=e.input.charCodeAt(++e.position),t=e.position;0!==s&&!se(s);)s=e.input.charCodeAt(++e.position);for(r=[],(n=e.input.slice(t,e.position)).length<1&&he(e,"directive name must not be less than one character in length");0!==s;){for(;re(s);)s=e.input.charCodeAt(++e.position);if(35===s){do{s=e.input.charCodeAt(++e.position)}while(0!==s&&!ne(s));break}if(ne(s))break;for(t=e.position;0!==s&&!se(s);)s=e.input.charCodeAt(++e.position);r.push(e.input.slice(t,e.position))}0!==s&&be(e),H.call(ge,n)?ge[n](e,n,r):me(e,'unknown document directive "'+n+'"')}ve(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,ve(e,!0,-1)):i&&he(e,"directives end mark is expected"),xe(e,e.lineIndent-1,G,!1,!0),ve(e,!0,-1),e.checkLineBreaks&&V.test(e.input.slice(o,e.position))&&me(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&Se(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,ve(e,!0,-1)):e.position=55296&&r<=56319&&t+1=56320&&n<=57343?1024*(r-55296)+n-56320+65536:r}function $t(e){return/^\n* /.test(e)}var wt=1,bt=2,vt=3,St=4,Ot=5;function At(e,t,n,r,s,o,i,a){var c,l,p=0,u=null,f=!1,d=!1,h=-1!==r,m=-1,g=ht(l=yt(e,0))&&l!==Ee&&!dt(l)&&l!==Ge&&l!==We&&l!==Ke&&l!==Ye&&l!==ze&&l!==Ze&&l!==tt&&l!==rt&&l!==Je&&l!==He&&l!==qe&&l!==Ue&&l!==nt&&l!==Xe&&l!==Qe&&l!==Be&&l!==Me&&l!==_e&&l!==Ve&&l!==et&&function(e){return!dt(e)&&e!==Ke}(yt(e,e.length-1));if(t||i)for(c=0;c=65536?c+=2:c++){if(!ht(p=yt(e,c)))return Ot;g=g&>(p,u,a),u=p}else{for(c=0;c=65536?c+=2:c++){if((p=yt(e,c))===Fe)f=!0,h&&(d=d||c-m-1>r&&" "!==e[m+1],m=c);else if(!ht(p))return Ot;g=g&>(p,u,a),u=p}d=d||h&&c-m-1>r&&" "!==e[m+1]}return f||d?n>9&&$t(e)?Ot:i?o===lt?Ot:bt:d?St:vt:!g||i||s(e)?o===lt?Ot:bt:wt}function Ct(e,t,n,r,o){e.dump=function(){if(0===t.length)return e.quotingType===lt?'""':"''";if(!e.noCompatMode&&(-1!==ot.indexOf(t)||it.test(t)))return e.quotingType===lt?'"'+t+'"':"'"+t+"'";var i=e.indent*Math.max(1,n),a=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-i),c=r||e.flowLevel>-1&&n>=e.flowLevel;switch(At(t,c,e.indent,a,function(t){return function(e,t){var n,r;for(n=0,r=e.implicitTypes.length;n"+kt(t,e.indent)+xt(ut(function(e,t){var n,r,s=/(\n+)([^\n]*)/g,o=(a=e.indexOf("\n"),a=-1!==a?a:e.length,s.lastIndex=a,Rt(e.slice(0,a),t)),i="\n"===e[0]||" "===e[0];var a;for(;r=s.exec(e);){var c=r[1],l=r[2];n=" "===l[0],o+=c+(i||n||""===l?"":"\n")+Rt(l,t),i=n}return o}(t,a),i));case Ot:return'"'+function(e){for(var t,n="",r=0,s=0;s=65536?s+=2:s++)r=yt(e,s),!(t=st[r])&&ht(r)?(n+=e[s],r>=65536&&(n+=e[s+1])):n+=t||at(r);return n}(t)+'"';default:throw new s("impossible error: invalid scalar style")}}()}function kt(e,t){var n=$t(e)?String(t):"",r="\n"===e[e.length-1];return n+(r&&("\n"===e[e.length-2]||"\n"===e)?"+":r?"":"-")+"\n"}function xt(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function Rt(e,t){if(""===e||" "===e[0])return e;for(var n,r,s=/ [^ ]/g,o=0,i=0,a=0,c="";n=s.exec(e);)(a=n.index)-o>t&&(r=i>o?i:a,c+="\n"+e.slice(o,r),o=r+1),i=a;return c+="\n",e.length-o>t&&i>o?c+=e.slice(o,i)+"\n"+e.slice(i+1):c+=e.slice(o),c.slice(1)}function It(e,t,n,r){var s,o,i,a="",c=e.tag;for(s=0,o=n.length;s tag resolver accepts not "'+l+'" style');r=c.represent[l](t,l)}e.dump=r}return!0}return!1}function Tt(e,t,n,r,o,i,a){e.tag=null,e.dump=n,Nt(e,n,!1)||Nt(e,n,!0);var c,l=Te.call(e.dump),p=r;r&&(r=e.flowLevel<0||e.flowLevel>t);var u,f,d="[object Object]"===l||"[object Array]"===l;if(d&&(f=-1!==(u=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||f||2!==e.indent&&t>0)&&(o=!1),f&&e.usedDuplicates[u])e.dump="*ref_"+u;else{if(d&&f&&!e.usedDuplicates[u]&&(e.usedDuplicates[u]=!0),"[object Object]"===l)r&&0!==Object.keys(e.dump).length?(!function(e,t,n,r){var o,i,a,c,l,p,u="",f=e.tag,d=Object.keys(n);if(!0===e.sortKeys)d.sort();else if("function"==typeof e.sortKeys)d.sort(e.sortKeys);else if(e.sortKeys)throw new s("sortKeys must be a boolean or a function");for(o=0,i=d.length;o1024)&&(e.dump&&Fe===e.dump.charCodeAt(0)?p+="?":p+="? "),p+=e.dump,l&&(p+=ft(e,t)),Tt(e,t+1,c,!0,l)&&(e.dump&&Fe===e.dump.charCodeAt(0)?p+=":":p+=": ",u+=p+=e.dump));e.tag=f,e.dump=u||"{}"}(e,t,e.dump,o),f&&(e.dump="&ref_"+u+e.dump)):(!function(e,t,n){var r,s,o,i,a,c="",l=e.tag,p=Object.keys(n);for(r=0,s=p.length;r1024&&(a+="? "),a+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),Tt(e,t,i,!1,!1)&&(c+=a+=e.dump));e.tag=l,e.dump="{"+c+"}"}(e,t,e.dump),f&&(e.dump="&ref_"+u+" "+e.dump));else if("[object Array]"===l)r&&0!==e.dump.length?(e.noArrayIndent&&!a&&t>0?It(e,t-1,e.dump,o):It(e,t,e.dump,o),f&&(e.dump="&ref_"+u+e.dump)):(!function(e,t,n){var r,s,o,i="",a=e.tag;for(r=0,s=n.length;r",e.dump=c+" "+e.dump)}return!0}function Pt(e,t){var n,r,s=[],o=[];for(function e(t,n,r){var s,o,i;if(null!==t&&"object"==typeof t)if(-1!==(o=n.indexOf(t)))-1===r.indexOf(o)&&r.push(o);else if(n.push(t),Array.isArray(t))for(o=0,i=t.length;o/SUBSCRIPTION-USERINFO/i.test(e))[0]]}function f(e){const t=Object.keys(e);let n="";for(let r of t)if(/USER-AGENT/i.test(r)){n=e[r];break}return-1!==n.indexOf("Quantumult%20X")?"QX":-1!==n.indexOf("Surge")?"Surge":-1!==n.indexOf("Decar")||-1!==n.indexOf("Loon")?"Loon":-1!==n.indexOf("Stash")?"Clash":null}async function d(e,t=!0,n){let r=n;void 0!==n&&null!=n&&0!=n.trim().length||(r="Quantumult%20X");const s=HTTP({headers:{"User-Agent":r}}),o="#"+Base64.safeEncode(e),i=$.read(o),a=`#TIME-${Base64.safeEncode(e)}`,c=(new Date).getTime()-$.read(a)>36e5;if(t&&i&&!c)return $.log(`Use cached for resource: ${e}`),i;let l="";try{l=(await s.get(e)).body}catch(e){throw new Error(e)}finally{$.write(l,o),$.write((new Date).getTime(),a)}if(0===l.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return l}async function h({type:e,item:t,platform:r,useCache:s,noProcessor:o}={platform:"JSON",useCache:!1,noProcessor:!1}){if("subscription"===e){const e=t,n=await d(e.url,s,e.ua);let i=ProxyUtils.parse(n);o||(i=await ProxyUtils.process(i,e.process||[],r));const a={};return i.forEach(e=>{a[e.name]&&$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』","⚠️ 订阅包含重复节点!","请仔细检测配置!",{"media-url":"https://cdn3.iconfinder.com/data/icons/seo-outline-1/512/25_code_program_programming_develop_bug_search_developer-512.png"})}),ProxyUtils.produce(i,r)}if("collection"===e){const e=$.read(n),i=t,a=i.subscriptions;let c=[];for(let t=0;t{l[e.name]&&$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』","⚠️ 订阅包含重复节点!","请仔细检测配置!",{"media-url":"https://cdn3.iconfinder.com/data/icons/seo-outline-1/512/25_code_program_programming_develop_bug_search_developer-512.png"})}),ProxyUtils.produce(c,r)}if("rule"===e){const e=t;let n=[];for(let t=0;t0){const e=p[d[0]],n=await u(e.url);n&&t.set("subscription-userinfo",n)}if(l)try{const e=await h({type:"collection",item:l,platform:a,useCache:c,noProcessor:i});"JSON"===a?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 下载组合订阅错误:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(404).json({status:"failed"})}),e.get("/download/:name",async function(e,t){const{name:r}=e.params,{cache:s}=e.query,{raw:o}=e.query||"false",i=e.query.target||f(e.headers)||"JSON",a=void 0===s?"JSON"===i||"URI"===i:s;$.info(`正在下载订阅:${r}`);const c=$.read(n)[r];if(c)try{const e=await h({type:"subscription",item:c,platform:i,useCache:a,noProcessor:o}),n=await u(c.url);n&&t.set("subscription-userinfo",n),"JSON"===i?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${JSON.stringify(e)}`),$.error(JSON.stringify(e)),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 未找到订阅:${r}!`),t.status(404).json({status:"failed"})}),e.route("/api/sub/:name").get(function(e,t){const{name:r}=e.params,s=$.read(n)[r];s?t.json({status:"success",data:s}):t.status(404).json({status:"failed",message:`未找到订阅:${r}!`})}).patch(function(e,t){const{name:s}=e.params;let o=e.body;const i=$.read(n);if(i[s]){const e={...i[s],...o};if($.info(`正在更新订阅: ${s}`),s!==o.name){const t=$.read(r);for(const e of Object.keys(t)){const n=t[e].subscriptions.indexOf(s);-1!==n&&(t[e].subscriptions[n]=o.name)}delete i[s],i[o.name]=e}else i[s]=e;$.write(i,n),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订阅${s}不存在,无法更新!`})}).delete(function(e,t){const{name:s}=e.params;$.info(`删除订阅:${s}...`);let o=$.read(n);delete o[s],$.write(o,n);let i=$.read(r);for(const e of Object.keys(i))i[e].subscriptions=i[e].subscriptions.filter(e=>e!==s);$.write(i,r),t.json({status:"success"})}),e.route("/api/subs").get(function(e,t){const r=$.read(n);t.json({status:"success",data:r})}).post(function(e,t){const r=e.body,s=$.read(n);$.info(`正在创建订阅: ${r.name}`),s[r.name]&&t.status(500).json({status:"failed",message:`订阅${r.name}已存在!`});/^[\w-_]*$/.test(r.name)?(s[r.name]=r,$.write(s,n),t.status(201).json({status:"success",data:r})):t.status(500).json({status:"failed",message:`订阅名称 ${r.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),e.get("/api/sub/statistics/:name"),e.route("/api/collection/:name").get(function(e,t){const{name:n}=e.params,s=$.read(r)[n];s?t.json({status:"success",data:s}):t.status(404).json({status:"failed",message:`未找到订阅集:${n}!`})}).patch(function(e,t){const{name:n}=e.params;let s=e.body;const o=$.read(r);if(o[n]){const e={...o[n],...s};$.info(`正在更新组合订阅:${n}...`),delete o[n],o[s.name||n]=e,$.write(o,r),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订阅集${n}不存在,无法更新!`})}).delete(function(e,t){const{name:n}=e.params;$.info(`正在删除组合订阅:${n}`);let s=$.read(r);delete s[n],$.write(s,r),t.json({status:"success"})}),e.route("/api/collections").get(function(e,t){const n=$.read(r);t.json({status:"success",data:n})}).post(function(e,t){const n=e.body;$.info(`正在创建组合订阅:${n.name}`);const s=$.read(r);s[n.name]&&t.status(500).json({status:"failed",message:`订阅集${n.name}已存在!`});/^[\w-_]*$/.test(n.name)?(s[n.name]=n,$.write(s,r),t.status(201).json({status:"success",data:n})):t.status(500).json({status:"failed",message:`订阅集名称 ${n.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),e.get("/download/rule/:name",async function(e,t){const{name:n}=e.params,{builtin:r}=e.query,s=e.query.target||f(e.headers)||"Surge";let i;$.info(`正在下载${r?"内置":""}分流订阅:${n}...`),r&&(i=$.read(o).rules[n]);if(i){const e=await h({type:"rule",item:i,platform:s});t.send(e)}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载分流订阅失败",`❌ 未找到分流订阅:${n}!`),t.status(404).json({status:"failed"})}),e.route("/api/rules").post(function(e,t){}).get(function(e,t){}),e.route("/api/rule/:name").patch(function(e,t){}).delete(function(e,t){}).get(function(e,t){}),e.route("/api/storage").get((e,t)=>{t.json($.read("#sub-store"))}).post((e,t)=>{const n=e.body;$.write(JSON.stringify(n),"#sub-store"),t.end()}),e.route("/api/settings").get(function(e,n){const r=$.read(t);n.json(r)}).patch(function(e,n){const r=e.body,s=$.read(t);$.write({...s,...r},t),n.json({status:"success"})}),e.route("/api/artifacts").get(function(e,t){const n=$.read(i);t.json({status:"success",data:n})}).post(function(e,t){const n=e.body;$.info(`正在创建远程配置:${n.name}`);const r=$.read(i);r[n.name]?t.status(500).json({status:"failed",message:`远程配置${n.name}已存在!`}):/^[\w-_.]*$/.test(n.name)?(r[n.name]=n,$.write(r,i),t.status(201).json({status:"success",data:n})):t.status(500).json({status:"failed",message:`远程配置名称 ${n.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}),e.route("/api/artifact/:name").get(async function(e,t){const o=e.params.name,a=e.query.action,c=$.read(i),l=c[o];if(l)if(a){let e;switch(l.type){case"subscription":e=$.read(n)[l.source];break;case"collection":e=$.read(r)[l.source];break;case"rule":e=$.read(s)[l.source]}const o=await h({type:l.type,item:e,platform:l.platform});if("preview"===a)t.send(o);else if("sync"===a){$.info(`正在上传配置:${l.name}\n>>>`),console.log(JSON.stringify(l,null,2));try{const e=await p({filename:l.name,content:o});l.updated=(new Date).getTime();const n=JSON.parse(e.body);l.url=n.files[l.name].raw_url.replace(/\/raw\/[^\/]*\/(.*)/,"/raw/$1"),$.write(c,i),t.json({status:"success"})}catch(e){t.status(500).json({status:"failed",message:e})}}}else t.json({status:"success",data:l});else t.status(404).json({status:"failed",message:"未找到对应的配置!"})}).patch(function(e,t){const n=$.read(i),r=e.params.name,s=n[r];if(s){$.info(`正在更新远程配置:${s.name}`);const o=e.body;if(void 0===o.name||/^[\w-_.]*$/.test(o.name)){const e={...s,...o};n[e.name]=e,e.name!==r&&delete n[r],$.write(n,i),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`远程配置名称 ${o.name} 中含有非法字符!名称中只能包含英文字母、数字、下划线、横杠。`})}else t.status(404).json({status:"failed",message:"未找到对应的远程配置!"})}).delete(async function(e,t){const n=e.params.name;$.info(`正在删除远程配置:${n}`);const r=$.read(i);try{const e=r[n];if(!e)throw new Error(`远程配置:${n}不存在!`);e.updated&&await p({filename:n,content:""}),delete r[n],$.write(r,i),t.json({status:"success"})}catch(e){delete r[n],$.write(r,i),t.status(500).json({status:"failed",message:`无法删除远程配置:${n}, 原因:${e}`})}}),e.get("/api/utils/IP_API/:server",async function(e,t){const n=decodeURIComponent(e.params.server),r=await $.http.get(`http://ip-api.com/json/${n}?lang=zh-CN`).then(e=>JSON.parse(e.body));t.json(r)}),e.post("/api/utils/refresh",async function(e,t){const{url:n,ua:r}=e.body;$.info(`Refreshing cache for URL: ${n}`);try{const e=await d(n,!1,r);$.write(e,`#${Base64.safeEncode(n)}`),t.json({status:"success"})}catch(e){t.status(500).json({status:"failed",message:`无法刷新资源 ${n}: ${e}`})}}),e.get("/api/utils/env",function(e,t){const{isNode:n,isQX:r,isLoon:s,isSurge:o}=ENV();let i="Node";n&&(i="Node");r&&(i="QX");s&&(i="Loon");o&&(i="Surge");t.json({backend:i})}),e.get("/api/utils/backup",async function(e,n){const{action:r}=e.query,{gistToken:s}=$.read(t);if(s){const e=new Gist({token:s,key:a});try{let s;switch(r){case"upload":const n=$.read(t);n.syncTime=(new Date).getTime(),$.write(n,t),s=$.read("#sub-store"),$.env.isNode&&(s=JSON.stringify($.cache,null," ")),$.info("上传备份中..."),await e.upload({filename:c,content:s});break;case"download":$.info("还原备份中..."),s=await e.download(c),$.write(s,"#sub-store"),$.env.isNode&&(s=JSON.parse(s),Object.keys(s).forEach(e=>{$.write(s[e],e)}))}n.json({status:"success"})}catch(e){const t=`${"upload"===r?"上传":"下载"}备份失败!${e}`;$.error(t),n.status(500).json({status:"failed",message:t})}}else n.status(500).json({status:"failed",message:"未找到Gist备份Token!"})}),e.get("/api/cron/sync-artifacts",async function(e,t){$.info("开始同步所有远程配置...");const o=$.read(i);let a=[],c=[];await Promise.all(Object.values(o).map(async e=>{if(e.sync){$.info(`正在同步云配置:${e.name}...`);try{let t;switch(e.type){case"subscription":t=$.read(n)[e.source];break;case"collection":t=$.read(r)[e.source];break;case"rule":t=$.read(s)[e.source]}const l=await h({type:e.type,item:t,platform:e.platform,useCache:!0}),u=await p({filename:e.name,content:l});e.updated=(new Date).getTime();const f=JSON.parse(u.body);e.url=f.files[e.name].raw_url.replace(/\/raw\/[^\/]*\/(.*)/,"/raw/$1"),$.write(o,i),$.info(`✅ 成功同步云配置:${e.name}`),a.push(e)}catch(t){$.error(`云配置: ${e.name} 同步失败!原因:${t}`),$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 同步订阅失败",`❌ 无法同步订阅:${e.name}!`,`🤔 原因:${t}`),c.push(e)}}})),t.json({success:a,failed:c})}),e.get("/",async(e,t)=>{t.set("location","https://sub-store.vercel.app/").status(302).end()}),ENV().isQX&&e.options("/",async(e,t)=>{t.status(200).end()}),e.all("/",(e,t)=>{t.send("Hello from sub-store, made with ❤️ by Peng-YM")}),e.start()}service();var ProxyUtils=function(){const PROXY_PREPROCESSORS=function(){return[{name:"HTML",test:e=>/^/.test(e),parse:e=>""},function(){const e=["dm1lc3M","c3NyOi8v","dHJvamFu","c3M6Ly","c3NkOi8v","c2hhZG93","aHR0c"];return{name:"Base64 Pre-processor",test:function(t){return e.some(e=>-1!==t.indexOf(e))},parse:function(e){return e=Base64.safeDecode(e)}}}(),{name:"Clash Pre-processor",test:function(e){return/proxies/.test(e)},parse:function(e){return YAML.load(e).proxies.map(e=>JSON.stringify(e)).join("\n")}},{name:"SSD Pre-processor",test:function(e){return 0===e.indexOf("ssd://")},parse:function(e){const t=[];let n=JSON.parse(Base64.safeDecode(e.split("ssd://")[1]));n.traffic_used,n.traffic_total,n.expiry,n.airport;let r=n.port,s=n.encryption,o=n.password,i=n.servers;for(let e=0;e{let[t,s]=e.split("=");if(t=t.trim(),s=s.trim(),-1!==r.indexOf(t)){n.type=t;const e=s.split(":");n.server=e[0],n.port=e[1]}else n[t.trim()]=s.trim()}),n}function t(){return{name:"Loon HTTP Parser",test:e=>/^.*=\s*http/i.test(e.split(",")[0])&&5===e.split(",").length&&-1===e.indexOf("username")&&-1===e.indexOf("password"),parse:e=>{const t=e.split("=")[1].split(","),n={name:e.split("=")[0].trim(),type:"http",server:t[1],port:t[2],tls:"443"===t[2]};return t[3]&&(n.username=t[3]),t[4]&&(n.password=t[4]),n.tls&&(n.sni=t["tls-name"]||n.server,n["skip-cert-verify"]=JSON.parse(t["skip-cert-verify"]||"false")),n}}}function n(e){const t={};t.name=e.split("=")[0].trim();const n=e.split(",");t.server=n[1].trim(),t.port=n[2].trim();for(let e=3;e/^ss:\/\//.test(e),parse:e=>{const t={};let n=e.split("ss://")[1];const r={name:decodeURIComponent(e.split("#")[1]),type:"ss",supported:t},s=(n=n.split("#")[0]).match(/@([^\/]*)(\/|$)/)[1],o=s.lastIndexOf(":");r.server=s.substring(0,o),r.port=s.substring(o+1);const i=Base64.safeDecode(n.split("@")[0]).split(":");if(r.cipher=i[0],r.password=i[1],-1!==n.indexOf("?plugin=")){const e=("plugin="+decodeURIComponent(n.split("?plugin=")[1].split("&")[0])).split(";"),s={};for(const t of e){const[e,n]=t.split("=");e&&(s[e]=n||!0)}switch(s.plugin){case"obfs-local":case"simple-obfs":r.plugin="obfs",r["plugin-opts"]={mode:s.obfs,host:s["obfs-host"]};break;case"v2ray-plugin":r.supported={...t,Loon:!1,Surge:!1},r.obfs="v2ray-plugin",r["plugin-opts"]={mode:"websocket",host:s["obfs-host"],path:s.path||"",tls:s.tls||!1};break;default:throw new Error(`Unsupported plugin option: ${s.plugin}`)}}return r}},function(){const e={Surge:!1};return{name:"URI SSR Parser",test:e=>/^ssr:\/\//.test(e),parse:t=>{let n=(t=Base64.safeDecode(t.split("ssr://")[1])).indexOf(":origin");-1===n&&(n=t.indexOf(":auth_"));const r=t.substring(0,n),s=r.substring(0,r.lastIndexOf(":")),o=r.substring(r.lastIndexOf(":")+1);let i=t.substring(n+1).split("/?")[0].split(":"),a={type:"ssr",server:s,port:o,protocol:i[0],cipher:i[1],obfs:i[2],password:Base64.safeDecode(i[3]),supported:e};const c={};if((t=t.split("/?")[1].split("&")).length>1)for(const e of t){const[t,n]=e.split("=");c[t]=n.trim()}return a={...a,name:c.remarks?Base64.safeDecode(c.remarks):a.server,"protocol-param":Base64.safeDecode(c.protoparam||"").replace(/\s/g,""),"obfs-param":Base64.safeDecode(c.obfsparam||"").replace(/\s/g,"")}}}}(),{name:"URI VMess Parser",test:e=>/^vmess:\/\//.test(e),parse:e=>{const t={};e=e.split("vmess://")[1];const n=Base64.safeDecode(e);if(/=\s*vmess/.test(n)){const e=n.split(",").map(e=>e.trim()),t={};for(const n of e)if(-1!==n.indexOf("=")){const[e,r]=n.split("=");t[e.trim()]=r.trim()}const r={name:e[0].split("=")[0].trim(),type:"vmess",server:e[1],port:e[2],cipher:e[3],uuid:e[4].match(/^"(.*)"$/)[1],tls:"over-tls"===t.obfs||"wss"===t.obfs};if(void 0!==t["udp-relay"]&&(r.udp=JSON.parse(t["udp-relay"])),void 0!==t["fast-open"]&&(r.udp=JSON.parse(t["fast-open"])),"ws"===t.obfs||"wss"===t.obfs){r.network="ws",r["ws-opts"].path=(t["obfs-path"]||'"/"').match(/^"(.*)"$/)[1];let e=t["obfs-header"];e&&-1!==e.indexOf("Host")&&(e=e.match(/Host:\s*([a-zA-Z0-9-.]*)/)[1]),r["ws-opts"].headers={Host:e||r.server}}return r.tls&&"false"===t['"tls-verification"']&&(r["skip-cert-verify"]=!0),r.tls&&t["obfs-host"]&&(r.sni=t["obfs-host"]),r}{const e=JSON.parse(n),r={name:e.ps,type:"vmess",server:e.add,port:e.port,cipher:"auto",uuid:e.id,alterId:e.aid||0,tls:"tls"===e.tls||!0===e.tls,supported:t};return"ws"===e.net&&(r.network="ws",r["ws-opts"]={path:e.path,headers:{Host:e.host||e.add}},r.tls&&e.host&&(r.sni=e.host)),!1===e.verify_cert&&(r["skip-cert-verify"]=!0),r}}},{name:"URI Trojan Parser",test:e=>/^trojan:\/\//.test(e),parse:e=>{e=e.split("trojan://")[1];const[t,n]=e.split("@")[1].split("?")[0].split(":"),r=decodeURIComponent(e.split("#")[1].trim());let s=e.split("?"),o=null;return s.length>1&&(s=s[1].split("#")[0].split("&"),o=new Map(s.map(e=>e.split("="))).get("sni")),{name:r||`[Trojan] ${t}`,type:"trojan",server:t,port:n,password:e.split("@")[0],sni:o,supported:{}}}},{name:"Clash Parser",test:e=>{try{JSON.parse(e)}catch(e){return!1}return!0},parse:e=>JSON.parse(e)},{name:"Surge SS Parser",test:e=>/^.*=\s*ss/.test(e.split(",")[0]),parse:e=>{const t=n(e),r={name:t.name,type:"ss",server:t.server,port:t.port,cipher:t["encrypt-method"],password:t.password,tfo:JSON.parse(t.tfo||"false"),udp:JSON.parse(t["udp-relay"]||"false")};return t.obfs&&(r.plugin="obfs",r["plugin-opts"]={mode:t.obfs,host:t["obfs-host"]}),r}},{name:"Surge VMess Parser",test:e=>/^.*=\s*vmess/.test(e.split(",")[0])&&-1!==e.indexOf("username"),parse:e=>{const t=n(e),r={name:t.name,type:"vmess",server:t.server,port:t.port,uuid:t.username,alterId:0,cipher:"none",tls:JSON.parse(t.tls||"false"),tfo:JSON.parse(t.tfo||"false")};if(r.tls&&(void 0!==t["skip-cert-verify"]&&(r["skip-cert-verify"]=!0===t["skip-cert-verify"]||"1"===t["skip-cert-verify"]),r.sni=t.sni||t.server),JSON.parse(t.ws||"false")){r.network="ws",r["ws-opts"]={path:t["ws-path"]};const e=t["ws-headers"].match(/(,|^|\s)*HOST:\s*(.*?)(,|$)/),n=e?e[2]:r.server;r["ws-opts"].headers={Host:n||t.server}}return r}},{name:"Surge Trojan Parser",test:e=>/^.*=\s*trojan/.test(e.split(",")[0])&&-1!==e.indexOf("sni"),parse:e=>{const t=n(e),r={name:t.name,type:"trojan",server:t.server,port:t.port,password:t.password,sni:t.sni||t.server,tfo:JSON.parse(t.tfo||"false")};return void 0!==t["skip-cert-verify"]&&(r["skip-cert-verify"]=!0===t["skip-cert-verify"]||"1"===t["skip-cert-verify"]),r}},{name:"Surge HTTP Parser",test:e=>/^.*=\s*http/.test(e.split(",")[0])&&!t().test(e),parse:e=>{const t=n(e),r={name:t.name,type:"http",server:t.server,port:t.port,tls:JSON.parse(t.tls||"false"),tfo:JSON.parse(t.tfo||"false")};return r.tls&&(void 0!==t["skip-cert-verify"]&&(r["skip-cert-verify"]=!0===t["skip-cert-verify"]||"1"===t["skip-cert-verify"]),r.sni=t.sni||t.server),t.username&&"none"!==t.username&&(r.username=t.username),t.password&&"none"!==t.password&&(r.password=t.password),r}},{name:"Loon SS Parser",test:e=>"shadowsocks"===e.split(",")[0].split("=")[1].trim().toLowerCase(),parse:e=>{const t=e.split("=")[1].split(","),n={name:e.split("=")[0].trim(),type:"ss",server:t[1],port:t[2],cipher:t[3],password:t[4].replace(/"/g,"")};return t.length>5&&(n.plugin="obfs",n["plugin-opts"]={mode:t[5],host:t[6]}),n}},{name:"Loon SSR Parser",test:e=>"shadowsocksr"===e.split(",")[0].split("=")[1].trim().toLowerCase(),parse:e=>{const t=e.split("=")[1].split(",");return{name:e.split("=")[0].trim(),type:"ssr",server:t[1],port:t[2],cipher:t[3],password:t[4].replace(/"/g,""),protocol:t[5],"protocol-param":t[6].match(/{(.*)}/)[1],supported:{Surge:!1},obfs:t[7],"obfs-param":t[8].match(/{(.*)}/)[1]}}},{name:"Loon VMess Parser",test:e=>/^.*=\s*vmess/i.test(e.split(",")[0])&&-1===e.indexOf("username"),parse:e=>{let t=e.split("=")[1].split(",");const n={name:e.split("=")[0].trim(),type:"vmess",server:t[1],port:t[2],cipher:t[3]||"none",uuid:t[4].replace(/"/g,""),alterId:0};t=t.splice(5);for(const e of t){const[n,r]=e.split(":");t[n]=r}switch(n.tls=JSON.parse(t["over-tls"]||"false"),n.tls&&(n.sni=t["tls-name"]||n.server,n["skip-cert-verify"]=JSON.parse(t["skip-cert-verify"]||"false")),t.transport){case"tcp":break;case"ws":n.network=t.transport,n["ws-opts"]={path:t.path,headers:{Host:t.host}}}return n.tls&&(n["skip-cert-verify"]=JSON.parse(t["skip-cert-verify"]||"false")),n}},{name:"Loon Trojan Parser",test:e=>/^.*=\s*trojan/i.test(e.split(",")[0])&&-1===e.indexOf("password"),parse:e=>{const t=e.split("=")[1].split(","),n={name:e.split("=")[0].trim(),type:"trojan",server:t[1],port:t[2],password:t[3].replace(/"/g,""),sni:t[1],"skip-cert-verify":JSON.parse(t["skip-cert-verify"]||"false")};if(t.length>4){const[r,s]=t[4].split(":");if("tls-name"!==r)throw new Error(`Unknown option ${r} for line: \n${e}`);n.sni=s}return n}},t(),{name:"QX SS Parser",test:e=>/^shadowsocks\s*=/.test(e.split(",")[0].trim())&&-1===e.indexOf("ssr-protocol"),parse:t=>{const n=e(t),r={name:n.tag,type:"ss",server:n.server,port:n.port,cipher:n.method,password:n.password,udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false"),supported:{}};if(n.obfs)switch(r["plugin-opts"]={host:n["obfs-host"]||r.server},n.obfs){case"http":case"tls":r.plugin="obfs",r["plugin-opts"].mode=n.obfs;break;case"ws":case"wss":r["plugin-opts"]={...r["plugin-opts"],mode:"websocket",path:n["obfs-uri"]||"/",tls:"wss"===n.obfs},r["plugin-opts"].tls&&void 0!==n["tls-verification"]&&(r["plugin-opts"]["skip-cert-verify"]=n["tls-verification"]),r.plugin="v2ray-plugin",r.supported.Surge=!1,r.supported.Loon=!1}return r}},{name:"QX SSR Parser",test:e=>/^shadowsocks\s*=/.test(e.split(",")[0].trim())&&-1!==e.indexOf("ssr-protocol"),parse:t=>{const n=e(t),r={name:n.tag,type:"ssr",server:n.server,port:n.port,cipher:n.method,password:n.password,protocol:n["ssr-protocol"],obfs:"plain","protocol-param":n["ssr-protocol-param"],udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false"),supported:{Surge:!1}};return n.obfs&&(r.obfs=n.obfs,r["obfs-param"]=n["obfs-host"]),r}},{name:"QX VMess Parser",test:e=>/^vmess\s*=/.test(e.split(",")[0].trim()),parse:t=>{const n=e(t),r={type:"vmess",name:n.tag,server:n.server,port:n.port,cipher:n.method||"none",uuid:n.password,alterId:0,tls:"over-tls"===n.obfs||"wss"===n.obfs,udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false")};return r.tls&&(r.sni=n["obfs-host"]||n.server,r["skip-cert-verify"]=!JSON.parse(n["tls-verification"]||"true")),"ws"!==n.obfs&&"wss"!==n.obfs||(r.network="ws",r["ws-opts"]={path:n["obfs-uri"],headers:{Host:n["obfs-host"]||n.server}}),r}},{name:"QX Trojan Parser",test:e=>/^trojan\s*=/.test(e.split(",")[0].trim()),parse:t=>{const n=e(t),r={type:"trojan",name:n.tag,server:n.server,port:n.port,password:n.password,sni:n["tls-host"]||n.server,udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false")};return r["skip-cert-verify"]=!JSON.parse(n["tls-verification"]||"true"),r}},{name:"QX HTTP Parser",test:e=>/^http\s*=/.test(e.split(",")[0].trim()),parse:t=>{const n=e(t),r={type:"http",name:n.tag,server:n.server,port:n.port,tls:JSON.parse(n["over-tls"]||"false"),udp:JSON.parse(n["udp-relay"]||"false"),tfo:JSON.parse(n["fast-open"]||"false")};return n.username&&"none"!==n.username&&(r.username=n.username),n.password&&"none"!==n.password&&(r.password=n.password),r.tls&&(r.sni=n["tls-host"]||r.server,r["skip-cert-verify"]=!JSON.parse(n["tls-verification"]||"true")),r}}]}(),PROXY_PROCESSORS=function(){function SetPropertyOperator({key:e,value:t}){return{name:"Set Property Operator",func:n=>n.map(n=>(n[e]=t,n))}}function FlagOperator(e=!0){return{name:"Flag Operator",func:t=>t.map(t=>{if(e){const e=getFlag(t.name);t.name=removeFlag(t.name),t.name=e+" "+t.name,t.name=t.name.replace(/🇹🇼/g,"🇨🇳")}else t.name=removeFlag(t.name);return t})}}function HandleDuplicateOperator(e){const{action:t,template:n,link:r,position:s}={action:"rename",template:"0 1 2 3 4 5 6 7 8 9",link:"-",position:"back",...e};return{name:"Handle Duplicate Operator",func:e=>{if("delete"===t){const t={};return e.filter(e=>!t[e.name]&&(t[e.name]=!0,!0))}if("rename"===t){const t=n.split(" "),o={};let i=0;e.forEach(e=>{void 0===o[e.name]?o[e.name]=1:o[e.name]++,i=Math.max(o[e.name].toString().length,i)});const a={};return e.map(e=>{if(o[e.name]>1){void 0===a[e.name]&&(a[e.name]=1);let n="",o=a[e.name]++,c=0;for(;o>0;)n=t[o%10]+n,o=parseInt(o/10),c++;for(;c++{switch(e){case"asc":case"desc":return t.sort((t,n)=>{let r=t.name>n.name?1:-1;return r*="desc"===e?-1:1});case"random":return shuffle(t);default:throw new Error("Unknown sort option: "+e)}}}}function RegexSortOperator(e){return{name:"Regex Sort Operator",func:t=>(e=e.map(e=>buildRegex(e)),t.sort((t,n)=>{const r=getRegexOrder(e,t.name),s=getRegexOrder(e,n.name);return r&&!s?-1:s&&!r?1:r&&s?rt.map(t=>{for(const{expr:n,now:r}of e)t.name=t.name.replace(buildRegex(n,"g"),r).trim();return t})}}function RegexDeleteOperator(e){return{name:"Regex Delete Operator",func:RegexRenameOperator(e.map(e=>({expr:e,now:""}))).func}}function ScriptOperator(script,targetPlatform){return{name:"Script Operator",func:proxies=>{let output=proxies;return function(){const $get=(e,t)=>{return(0,PROXY_PROCESSORS[e])(t)},$process=ApplyProcessor;eval(script),output=operator(proxies,targetPlatform)}(),output}}}function UselessFilter(){return{name:"Useless Filter",func:RegexFilter({regex:["网址","流量","时间","应急","过期","Bandwidth","expire"],keep:!1}).func}}function RegionFilter(e){const t={HK:"🇭🇰",TW:"🇹🇼",US:"🇺🇸",SG:"🇸🇬",JP:"🇯🇵",UK:"🇬🇧"};return{name:"Region Filter",func:n=>n.map(n=>{const r=getFlag(n.name);return e.some(e=>t[e]===r)})}}function RegexFilter({regex:e=[],keep:t=!0}){return{name:"Regex Filter",func:n=>n.map(n=>{const r=e.some(e=>buildRegex(e).test(n.name));return t?r:!r})}}function TypeFilter(e){return{name:"Type Filter",func:t=>t.map(t=>e.some(e=>t.type===e))}}function ScriptFilter(script){return{name:"Script Filter",func:proxies=>{let output=FULL(proxies.length,!0);return function(){eval(script),output=filter(proxies)}(),output}}}function getFlag(e){const t={"🇦🇿":["阿塞拜疆"],"🇦🇹":["奥地利","奧地利","Austria","维也纳"],"🇦🇺":["AU","Australia","Sydney","澳大利亚","澳洲","墨尔本","悉尼","土澳","京澳","廣澳","滬澳","沪澳","广澳"],"🇧🇪":["BE","比利時","比利时"],"🇧🇬":["保加利亚","保加利亞","Bulgaria"],"🇵🇰":["巴基斯坦"],"🇰🇭":["柬埔寨"],"🇺🇦":["烏克蘭","乌克兰"],"🇭🇷":["克罗地亚","HR","克羅地亞"],"🇨🇦":["Canada","CANADA","CAN","Waterloo","加拿大","蒙特利尔","温哥华","楓葉","枫叶","滑铁卢","多伦多"],"🇨🇭":["瑞士","苏黎世","Switzerland"],"🇳🇬":["尼日利亚","NG","尼日利亞"],"🇨🇿":["Czechia","捷克"],"🇸🇰":["斯洛伐克","SK"],"🇷🇸":["RS","塞尔维亚"],"🇲🇩":["摩爾多瓦","MD","摩尔多瓦"],"🇩🇪":["DE","German","GERMAN","德国","德國","法兰克福","京德","滬德","廣德","沪德","广德"],"🇩🇰":["DK","DNK","丹麦","丹麥"],"🇪🇸":["ES","西班牙","Spain"],"🇪🇺":["EU","欧盟","欧罗巴"],"🇫🇮":["Finland","芬兰","芬蘭","赫尔辛基"],"🇫🇷":["FR","France","法国","法國","巴黎"],"🇬🇧":["UK","GB","England","United Kingdom","英国","伦敦","英"],"🇲🇴":["MO","Macao","澳门","澳門","CTM"],"🇰🇿":["哈萨克斯坦","哈萨克"],"🇭🇺":["匈牙利","Hungary"],"🇭🇰":["HK","Hongkong","Hong Kong","HongKong","HONG KONG","香港","深港","沪港","呼港","HKT","HKBN","HGC","WTT","CMI","穗港","京港","港"],"🇮🇩":["Indonesia","印尼","印度尼西亚","雅加达"],"🇮🇪":["Ireland","IRELAND","爱尔兰","愛爾蘭","都柏林"],"🇮🇱":["Israel","以色列"],"🇮🇳":["India","IND","INDIA","印度","孟买","Mumbai"],"🇮🇸":["IS","ISL","冰岛","冰島"],"🇰🇵":["KP","朝鲜"],"🇰🇷":["KR","Korea","KOR","韩国","首尔","韩","韓","春川"],"🇱🇺":["卢森堡"],"🇱🇻":["Latvia","Latvija","拉脱维亚"],"🇲🇽️":["MEX","MX","墨西哥"],"🇲🇾":["MY","Malaysia","MALAYSIA","马来西亚","大馬","馬來西亞","吉隆坡"],"🇳🇱":["NL","Netherlands","荷兰","荷蘭","尼德蘭","阿姆斯特丹"],"🇵🇭":["PH","Philippines","菲律宾","菲律賓"],"🇷🇴":["RO","罗马尼亚"],"🇷🇺":["RU","Russia","俄罗斯","俄国","俄羅斯","伯力","莫斯科","圣彼得堡","西伯利亚","新西伯利亚","京俄","杭俄","廣俄","滬俄","广俄","沪俄"],"🇸🇦":["沙特","迪拜"],"🇸🇪":["SE","Sweden"],"🇸🇬":["SG","Singapore","SINGAPORE","新加坡","狮城","沪新","京新","泉新","穗新","深新","杭新","广新","廣新","滬新"],"🇹🇭":["TH","Thailand","泰国","泰國","曼谷"],"🇹🇷":["TR","Turkey","土耳其","伊斯坦布尔"],"🇹🇼":["TW","Taiwan","TAIWAN","台湾","台北","台中","新北","彰化","CHT","台","HINET"],"🇺🇸":["US","USA","America","United States","美国","美","京美","波特兰","达拉斯","俄勒冈","凤凰城","费利蒙","硅谷","矽谷","拉斯维加斯","洛杉矶","圣何塞","圣克拉拉","西雅图","芝加哥","沪美","哥伦布","纽约"],"🇻🇳":["VN","越南","胡志明市"],"🇮🇹":["Italy","IT","Nachash","意大利","米兰","義大利"],"🇿🇦":["South Africa","南非"],"🇦🇪":["United Arab Emirates","阿联酋"],"🇧🇷":["BR","Brazil","巴西","圣保罗"],"🇯🇵":["JP","Japan","JAPAN","日本","东京","大阪","埼玉","沪日","穗日","川日","中日","泉日","杭日","深日","辽日","广日"],"🇦🇷":["AR","阿根廷"],"🇳🇴":["Norway","挪威","NO"],"🇨🇳":["CN","China","回国","中国","中國","江苏","北京","上海","广州","深圳","杭州","徐州","青岛","宁波","镇江","back"],"🇵🇱":["PL","POL","波兰","波蘭"],"🇨🇱":["智利"],"🇳🇿":["新西蘭","新西兰"],"🇬🇷":["希腊","希臘"],"🇪🇬":["埃及"],"🇨🇾":["CY","塞浦路斯"],"🇨🇷":["CR","哥斯达黎加"],"🇸🇮":["SI","斯洛文尼亚"],"🇱🇹":["LT","立陶宛"],"🇵🇦":["PA","巴拿马"],"🇹🇳":["TN","突尼斯"],"🇮🇲":["马恩岛","馬恩島"],"🇧🇾":["BY","白俄罗斯"],"🇵🇹":["葡萄牙"],"🇰🇪":["KE","肯尼亚"],"🇰🇬":["KG","吉尔吉斯坦"],"🇯🇴":["JO","约旦"],"🇺🇾":["UY","乌拉圭"],"🇲🇳":["蒙古"],"🇮🇷":["IR","伊朗"],"🇵🇪":["秘鲁","祕魯"],"🇨🇴":["哥伦比亚"],"🇪🇪":["爱沙尼亚"],"🇲🇰":["马其顿","馬其頓"],"🇧🇦":["波黑共和国","波黑"],"🇬🇪":["格魯吉亞","格鲁吉亚"],"🇦🇱":["阿爾巴尼亞","阿尔巴尼亚"],"🏳️‍🌈":["流量","时间","应急","过期","Bandwidth","expire"]};for(let n of Object.keys(t))if(t[n].some(t=>-1!==e.indexOf(t)))return n;return(e.match(/[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]/)||[])[0]||"🏴‍☠️"}function removeFlag(e){return e.replace(/[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]/g,"").trim()}function shuffle(e){let t,n,r=e.length;for(;0!==r;)n=Math.floor(Math.random()*r),t=e[r-=1],e[r]=e[n],e[n]=t;return e}return{"Useless Filter":UselessFilter,"Region Filter":RegionFilter,"Regex Filter":RegexFilter,"Type Filter":TypeFilter,"Script Filter":ScriptFilter,"Set Property Operator":SetPropertyOperator,"Flag Operator":FlagOperator,"Sort Operator":SortOperator,"Regex Sort Operator":RegexSortOperator,"Regex Rename Operator":RegexRenameOperator,"Regex Delete Operator":RegexDeleteOperator,"Script Operator":ScriptOperator,"Handle Duplicate Operator":HandleDuplicateOperator}}(),PROXY_PRODUCERS=function(){return{QX:{produce:e=>{let t,n;switch(e.type){case"ss":if(t="","obfs"===e.plugin){const{host:n,mode:r}=e["plugin-opts"];t=`,obfs=${r}${n?",obfs-host="+n:""}`}if("v2ray-plugin"===e.plugin){const{tls:n,host:r,path:s}=e["plugin-opts"];t=`,obfs=${n?"wss":"ws"}${r?",obfs-host="+r:""}${s?",obfs-uri="+s:""}`}return`shadowsocks=${e.server}:${e.port},method=${e.cipher},password=${e.password}${t}${e.tfo?",fast-open=true":",fast-open=false"}${e.udp?",udp-relay=true":",udp-relay=false"},tag=${e.name}`;case"ssr":return`shadowsocks=${e.server}:${e.port},method=${e.cipher},password=${e.password},ssr-protocol=${e.protocol}${e["protocol-param"]?",ssr-protocol-param="+e["protocol-param"]:""}${e.obfs?",obfs="+e.obfs:""}${e["obfs-param"]?",obfs-host="+e["obfs-param"]:""},fast-open=${e.tfo||!1}${e.udp?",udp-relay=true":",udp-relay=false"},tag=${e.name}`;case"vmess":t="","ws"===e.network?t=e.tls?`,obfs=wss${e.sni?",obfs-host="+e.sni:""}${e["ws-opts"].path?",obfs-uri="+e["ws-opts"].path:""},tls-verification=${e["skip-cert-verify"]?"false":"true"}`:`,obfs=ws${e["ws-opts"].headers.Host?",obfs-host="+e["ws-opts"].headers.Host:""}${e["ws-opts"].path?",obfs-uri="+e["ws-opts"].path:""}`:e.tls&&(t=`,obfs=over-tls${e.sni?",obfs-host="+e.sni:""},tls-verification=${e["skip-cert-verify"]?"false":"true"}`);let r=`vmess=${e.server}:${e.port},method=${"auto"===e.cipher?"none":e.cipher},password=${e.uuid}${t},fast-open=${e.tfo||!1}${e.udp?",udp-relay=true":",udp-relay=false"}`;return 0===e.alterId&&(e["vmess-aead"]=!0),void 0!==e["vmess-aead"]&&(r+=`,aead=${e["vmess-aead"]}`),r+=`,tag=${e.name}`;case"trojan":return`trojan=${e.server}:${e.port},password=${e.password}${e.sni?",tls-host="+e.sni:""},over-tls=true,tls-verification=${e["skip-cert-verify"]?"false":"true"},fast-open=${e.tfo||!1}${e.udp?",udp-relay=true":",udp-relay=false"},tag=${e.name}`;case"http":return n="",e.tls&&(n=`,over-tls=true,tls-verification=${e["skip-cert-verify"]?"false":"true"}${e.sni?",tls-host="+e.sni:""}`),`http=${e.server}:${e.port},username=${e.username},password=${e.password}${n},fast-open=${e.tfo||!1},tag=${e.name}`}throw new Error(`Platform QX does not support proxy type: ${e.type}`)}},Surge:{produce:e=>{let t,n,r="";switch(e.type){case"ss":if(t="",e.plugin){const{host:n,mode:r}=e["plugin-opts"];if("obfs"!==e.plugin)throw new Error(`Platform Surge does not support obfs option: ${e.obfs}`);t=`,obfs=${r}${n?",obfs-host="+n:""}`}r=`${e.name}=ss,${e.server}, ${e.port},encrypt-method=${e.cipher},password=${e.password}${t},tfo=${e.tfo||"false"},udp-relay=${e.udp||"false"}`;break;case"vmess":if(n="",r=`${e.name}=vmess,${e.server},${e.port},username=${e.uuid},tls=${e.tls||"false"},tfo=${e.tfo||"false"}`,0===e.alterId&&(e["vmess-aead"]=!0),void 0!==e["vmess-aead"]&&(r+=`,vmess-aead=${e["vmess-aead"]}`),"ws"===e.network){const t=e["ws-opts"].path||"/",n=Object.entries(e["ws-opts"].headers).map(([e,t])=>`${e}:"${t}"`).join("|");r+=`,ws=true${t?",ws-path="+t:""}${n?",ws-headers="+n:""}`}e.tls&&(r+=`${void 0!==e["skip-cert-verify"]?",skip-cert-verify="+e["skip-cert-verify"]:""}`,r+=e.sni?`,sni=${e.sni}`:"");break;case"trojan":r=`${e.name}=trojan,${e.server},${e.port},password=${e.password}${void 0!==e["skip-cert-verify"]?",skip-cert-verify="+e["skip-cert-verify"]:""}${e.sni?",sni="+e.sni:""},tfo=${e.tfo||"false"},udp-relay=${e.udp||"false"}`;break;case"http":n=", tls=false",e.tls&&(n=`,tls=true,skip-cert-verify=${e["skip-cert-verify"]},sni=${e.sni}`),r=`${e.name}=http, ${e.server}, ${e.port}${e.username?",username="+e.username:""}${e.password?",password="+e.password:""}${n},tfo=${e.tfo||"false"}`;break;default:throw new Error(`Platform Surge does not support proxy type: ${e.type}`)}return r+=void 0!==e["surge-hybrid"]?`,hybrid=${e["surge-hybrid"]}`:""}},Loon:{produce:e=>{let t="",n="",r="",s="";switch(void 0!==e.udp&&(r=e.udp?",udp=true":",udp=false"),s=`,fast-open=${e.tfo||!1}`,e.type){case"ss":if(t=",,",e.plugin){if("obfs"!==e.plugin)throw new Error(`Platform Loon does not support obfs option: ${e.obfs}`);{const{mode:n,host:r}=e["plugin-opts"];t=`,${n},${r||""}`}}return`${e.name}=shadowsocks,${e.server},${e.port},${e.cipher},"${e.password}"${t}${r}${s}`;case"ssr":return`${e.name}=shadowsocksr,${e.server},${e.port},${e.cipher},"${e.password}",${e.protocol},{${e["protocol-param"]||""}},${e.obfs},{${e["obfs-param"]||""}}${r}${s}`;case"vmess":t="",t="ws"===e.network?`,transport:ws,host:${e["ws-opts"].headers.Host||e.server},path:${e["ws-opts"].path||"/"}`:",transport:tcp",e.tls&&(t+=`${e.sni?",tls-name:"+e.sni:""},skip-cert-verify:${e["skip-cert-verify"]||"false"}`);let o=`${e.name}=vmess,${e.server},${e.port},${"auto"===e.cipher?"none":e.cipher},"${e.uuid}",over-tls:${e.tls||"false"}${t}`;return 0===e.alterId&&(e["vmess-aead"]=!0),void 0!==e["vmess-aead"]&&(o+=`,vmess-aead=${e["vmess-aead"]}`),o;case"trojan":return`${e.name}=trojan,${e.server},${e.port},"${e.password}"${e.sni?",tls-name:"+e.sni:""},skip-cert-verify:${e["skip-cert-verify"]||"false"}${r}`;case"http":n="";const i=`${e.name}=${e.tls?"http":"https"},${e.server},${e.port},${e.username||""},${e.password||""}`;return e.tls?i+(n=`${e.sni?",tls-name:"+e.sni:""},skip-cert-verify:${e["skip-cert-verify"]}`):i}throw new Error(`Platform Loon does not support proxy type: ${e.type}`)}},Clash:{type:"ALL",produce:e=>"proxies:\n"+e.map(e=>(delete e.supported," - "+JSON.stringify(e)+"\n")).join("")},URI:{type:"SINGLE",produce:e=>{let t="";switch(e.type){case"ss":const n=`${e.cipher}:${e.password}`;if(t=`ss://${Base64.safeEncode(n)}@${e.server}:${e.port}/`,e.plugin){t+="?plugin=";const n=e["plugin-opts"];switch(e.plugin){case"obfs":t+=encodeURIComponent(`simple-obfs;obfs=${n.mode}${n.host?";obfs-host="+n.host:""}`);break;case"v2ray-plugin":t+=encodeURIComponent(`v2ray-plugin;obfs=${n.mode}${n.host?";obfs-host"+n.host:""}${n.tls?";tls":""}`);break;default:throw new Error(`Unsupported plugin option: ${e.plugin}`)}}t+=`#${encodeURIComponent(e.name)}`;break;case"ssr":t=`${e.server}:${e.port}:${e.protocol}:${e.cipher}:${e.obfs}:${Base64.safeEncode(e.password)}/`,t+=`?remarks=${Base64.safeEncode(e.name)}${e["obfs-param"]?"&obfsparam="+Base64.safeEncode(e["obfs-param"]):""}${e["protocol-param"]?"&protocolparam="+Base64.safeEncode(e["protocol-param"]):""}`,t="ssr://"+Base64.safeEncode(t);break;case"vmess":t={ps:e.name,add:e.server,port:e.port,id:e.uuid,type:"",aid:0,net:e.network||"tcp",tls:e.tls?"tls":""},"ws"===e.network&&(t.path=e["ws-opts"].path||"/",t.host=e["ws-opts"].headers.Host||e.server),t="vmess://"+Base64.safeEncode(JSON.stringify(t));break;case"trojan":t=`trojan://${e.password}@${e.server}:${e.port}#${encodeURIComponent(e.name)}`;break;default:throw new Error(`Cannot handle proxy type: ${e.type}`)}return t}},JSON:{type:"ALL",produce:e=>JSON.stringify(e,null,2)}}}();function preprocess(e){for(const t of PROXY_PREPROCESSORS)try{if(t.test(e))return $.info(`Pre-processor [${t.name}] activated`),t.parse(e)}catch(e){$.error(`Parser [${t.name}] failed\n Reason: ${e}`)}return e}function safeMatch(e,t){let n;try{n=e.test(t)}catch(e){n=!1}return n}function parse(e){const t=(e=preprocess(e)).split("\n"),n=[];let r;for(let e of t){if(0===(e=e.trim()).length)continue;let t=r&&safeMatch(r,e);if(!t)for(const n of PROXY_PARSERS)if(safeMatch(n,e)){r=n,t=!0,$.info(`Proxy parser: ${n.name} is activated`);break}if(t)try{const t=r.parse(e);t||$.error(`Parser ${r.name} return nothing for \n${e}\n`),n.push(t)}catch(t){$.error(`Failed to parse line: \n ${e}\n Reason: ${t.stack}`)}else $.error(`Failed to find a rule to parse line: \n${e}\n`)}return n}async function process(e,t=[],n){for(const r of t){let t,s;if(-1!==r.type.indexOf("Script")){const{mode:e,content:n}=r.args;if("link"===e)try{t=await $.http.get(n).then(e=>e.body)}catch(e){$.error(`Error when downloading remote script: ${r.args.content}.\n Reason: ${e}`);continue}else t=n}PROXY_PROCESSORS[r.type]?($.info(`Applying "${r.type}" with arguments:\n >>> ${JSON.stringify(r.args,null,2)||"None"}`),e=ApplyProcessor(s=-1!==r.type.indexOf("Script")?PROXY_PROCESSORS[r.type](t,n):PROXY_PROCESSORS[r.type](r.args),e)):$.error(`Unknown operator: "${r.type}"`)}return e}function produce(e,t){const n=PROXY_PRODUCERS[t];if(!n)throw new Error(`Target platform: ${t} is not supported!`);return e=e.filter(e=>!(e.supported&&!1===e.supported[t])),$.info(`Producing proxies for target: ${t}`),void 0===n.type||"SINGLE"===n.type?e.map(e=>{try{return n.produce(e)}catch(t){return $.error(`Cannot produce proxy: ${JSON.stringify(e,null,2)}\nReason: ${t}`),""}}).filter(e=>e.length>0).join("\n"):"ALL"===n.type?n.produce(e):void 0}return{parse:parse,process:process,produce:produce}}(),RuleUtils=function(){const e=[[/^(DOMAIN|host|HOST)$/,"DOMAIN"],[/^(DOMAIN-KEYWORD|host-keyword|HOST-KEYWORD)$/,"DOMAIN-KEYWORD"],[/^(DOMAIN-SUFFIX|host-suffix|HOST-SUFFIX)$/,"DOMAIN-SUFFIX"],[/^USER-AGENT$/i,"USER-AGENT"],[/^PROCESS-NAME$/,"PROCESS-NAME"],[/^(DEST-PORT|DST-PORT)$/,"DST-PORT"],[/^SRC-IP(-CIDR)?$/,"SRC-IP"],[/^(IN|SRC)-PORT$/,"IN-PORT"],[/^PROTOCOL$/,"PROTOCOL"],[/^IP-CIDR$/i,"IP-CIDR"],[/^(IP-CIDR6|ip6-cidr|IP6-CIDR)$/]],t=function(){return[{name:"HTML",test:e=>/^/.test(e),parse:e=>""},{name:"Clash Provider",test:e=>0===e.indexOf("payload:"),parse:e=>e.replace("payload:","").replace(/^\s*-\s*/gm,"")}]}(),n=function(){return[{name:"Universal Rule Parser",test:()=>!0,parse:t=>{const n=t.split("\n"),r=[];for(let t of n)if(0!==(t=t.trim()).length&&!/\s*#/.test(t))try{const n=t.split(",").map(e=>e.trim());let s=n[0],o=!1;for(const t of e)if(t[0].test(s)){o=!0;const e={type:t[1],content:n[1]};"IP-CIDR"!==e.type&&"IP-CIDR6"!==e.type||(e.options=n.slice(2)),r.push(e)}if(!o)throw new Error("Invalid rule type: "+s)}catch(e){console.error(`Failed to parse line: ${t}\n Reason: ${e}`)}return r}}]}(),r=function(){return{"Regex Filter":function({regex:e=[],keep:t=!0}){return{name:"Regex Filter",func:n=>n.map(n=>{const r=e.some(e=>(e=new RegExp(e)).test(n));return t?r:!r})}},"Remove Duplicate Filter":function(){return{name:"Remove Duplicate Filter",func:e=>{const t=new Set,n=[];return e.forEach(e=>{const r=e.options||[];r.sort();const s=`${e.type},${e.content},${JSON.stringify(r)}`;t.has(s)||(n.push(e),t.add(s))}),n}}},"Type Filter":function(e){return{name:"Type Filter",func:t=>t.map(t=>e.some(e=>t.type===e))}},"Regex Replace Operator":function(e){return{name:"Regex Rename Operator",func:t=>t.map(t=>{for(const{expr:n,now:r}of e)t.content=t.content.replace(new RegExp(n,"g"),r).trim();return t})}}}}(),s=function(){return{QX:{type:"SINGLE",func:e=>-1!==["URL-REGEX","DEST-PORT","SRC-IP","IN-PORT","PROTOCOL"].indexOf(e.type)?null:`${{"DOMAIN-KEYWORD":"HOST-KEYWORD","DOMAIN-SUFFIX":"HOST-SUFFIX",DOMAIN:"HOST","IP-CIDR6":"IP6-CIDR"}[e.type]||e.type},${e.content},SUB-STORE`},Surge:{type:"SINGLE",func:e=>{let t=`${e.type},${e.content}`;return"IP-CIDR"!==e.type&&"IP-CIDR6"!==e.type||(t+=e.options?`,${e.options[0]}`:""),t}},Loon:{type:"SINGLE",func:e=>-1!==["DEST-PORT","SRC-IP","IN-PORT","PROTOCOL"].indexOf(e.type)?null:(e=>{let t=`${e.type},${e.content}`;return"IP-CIDR"!==e.type&&"IP-CIDR6"!==e.type||(t+=e.options?`,${e.options[0]}`:""),t})(e)},Clash:{type:"ALL",func:e=>{const t={"DEST-PORT":"DST-PORT","SRC-IP":"SRC-IP-CIDR","IN-PORT":"SRC-PORT"},n={payload:e.map(e=>{let n=`${t[e.type]||e.type},${e.content}`;return"IP-CIDR"!==e.type&&"IP-CIDR6"!==e.type||(n+=e.options?`,${e.options[0]}`:""),n})};return YAML.stringify(n)}}}}();return{parse:function(e){e=function(e){for(const n of t)try{if(n.test(e))return $.info(`Pre-processor [${n.name}] activated`),n.parse(e)}catch(e){$.error(`Parser [${n.name}] failed\n Reason: ${e}`)}return e}(e);for(const t of n){let n;try{n=t.test(e)}catch(e){n=!1}if(n)return $.info(`Rule parser [${t.name}] is activated!`),t.parse(e)}},process:async function(e,t){for(const n of t){if(!r[n.type]){console.error(`Unknown operator: ${n.type}!`);continue}const t=r[n.type](n.args);$.info(`Applying "${n.type}" with arguments: \n >>> ${JSON.stringify(n.args)||"None"}`),e=ApplyProcessor(t,e)}return e},produce:function(e,t){const n=s[t];if(!n)throw new Error(`Target platform: ${t} is not supported!`);return void 0===n.type||"SINGLE"===n.type?e.map(e=>{try{return n.func(e)}catch(t){return console.log(`ERROR: cannot produce rule: ${JSON.stringify(e)}\nReason: ${t}`),""}}).filter(e=>e.length>0).join("\n"):"ALL"===n.type?n.func(e):void 0}}}();function getBuiltInRules(){return{AD:{name:"AD",description:"",urls:["https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-surge.txt","https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Providers/BanAD.yaml"]},Global:{name:"Global",description:"",urls:["https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Providers/ProxyGFWlist.yaml","https://raw.githubusercontent.com/DivineEngine/Profiles/master/Quantumult/Filter/Global.list"]},CN:{name:"CN",description:"",urls:["https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Providers/ChinaDomain.yaml","https://raw.githubusercontent.com/DivineEngine/Profiles/master/Quantumult/Filter/China.list"]}}}function ApplyProcessor(e,t){return-1!==e.name.indexOf("Filter")?function(e,t){let n=FULL(t.length,!0);try{n=AND(n,e.func(t))}catch(t){console.log(`Cannot apply filter ${e.name}\n Reason: ${t}`)}return t.filter((e,t)=>n[t])}(e,t):-1!==e.name.indexOf("Operator")?function(e,t){let n=clone(t);try{const t=e.func(n);t&&(n=t)}catch(t){console.log(`Cannot apply operator ${e.name}! Reason: ${t}`)}return n}(e,t):void 0}function AND(...e){return e.reduce((e,t)=>e.map((e,n)=>t[n]&&e))}function OR(...e){return e.reduce((e,t)=>e.map((e,n)=>t[n]||e))}function NOT(e){return e.map(e=>!e)}function FULL(e,t){return[...Array(e).keys()].map(()=>t)}function clone(e){return JSON.parse(JSON.stringify(e))}function buildRegex(e,...t){return t=t.join(""),e.startsWith("(?i)")?(e=e.substr(4),new RegExp(e,"i"+t)):new RegExp(e,t)}function ENV(){const e="undefined"!=typeof $task,t="undefined"!=typeof $loon,n="undefined"!=typeof $httpClient&&!t,r="function"==typeof require&&"undefined"!=typeof $jsbox;return{isQX:e,isLoon:t,isSurge:n,isNode:"function"==typeof require&&!r,isJSBox:r,isRequest:"undefined"!=typeof $request,isScriptable:"undefined"!=typeof importModule}}function HTTP(e={baseURL:""}){const{isQX:t,isLoon:n,isSurge:r,isScriptable:s,isNode:o}=ENV(),i=/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;const a={};return["GET","POST","PUT","DELETE","HEAD","OPTIONS","PATCH"].forEach(c=>a[c.toLowerCase()]=(a=>(function(a,c){c="string"==typeof c?{url:c}:c;const l=e.baseURL;l&&!i.test(c.url||"")&&(c.url=l?l+c.url:c.url);const p=(c={...e,...c}).timeout,u={onRequest:()=>{},onResponse:e=>e,onTimeout:()=>{},...c.events};let f,d;if(u.onRequest(a,c),t)f=$task.fetch({method:a,url:c.url,headers:c.headers,body:c.body});else if(n||r||o)f=new Promise((e,t)=>{(o?require("request"):$httpClient)[a.toLowerCase()](c,(n,r,s)=>{n?t(n):e({statusCode:r.status||r.statusCode,headers:r.headers,body:s})})});else if(s){const e=new Request(c.url);e.method=a,e.headers=c.headers,e.body=c.body,f=new Promise((t,n)=>{e.loadString().then(n=>{t({statusCode:e.response.statusCode,headers:e.response.headers,body:n})}).catch(e=>n(e))})}const h=p?new Promise((e,t)=>{d=setTimeout(()=>(u.onTimeout(),t(`${a} URL: ${c.url} exceeds the timeout ${p} ms`)),p)}):null;return(h?Promise.race([h,f]).then(e=>(clearTimeout(d),e)):f).then(e=>u.onResponse(e))})(c,a))),a}function API(e="untitled",t=!1){const{isQX:n,isLoon:r,isSurge:s,isNode:o,isJSBox:i,isScriptable:a}=ENV();return new class{constructor(e,t){this.name=e,this.debug=t,this.http=HTTP(),this.env=ENV(),this.node=(()=>{if(o){return{fs:require("fs")}}return null})(),this.initCache();Promise.prototype.delay=function(e){return this.then(function(t){return((e,t)=>new Promise(function(n){setTimeout(n.bind(null,t),e)}))(e,t)})}}initCache(){if(n&&(this.cache=JSON.parse($prefs.valueForKey(this.name)||"{}")),(r||s)&&(this.cache=JSON.parse($persistentStore.read(this.name)||"{}")),o){let e="root.json";this.node.fs.existsSync(e)||this.node.fs.writeFileSync(e,JSON.stringify({}),{flag:"wx"},e=>console.log(e)),this.root={},e=`${this.name}.json`,this.node.fs.existsSync(e)?this.cache=JSON.parse(this.node.fs.readFileSync(`${this.name}.json`)):(this.node.fs.writeFileSync(e,JSON.stringify({}),{flag:"wx"},e=>console.log(e)),this.cache={})}}persistCache(){const e=JSON.stringify(this.cache,null,2);n&&$prefs.setValueForKey(e,this.name),(r||s)&&$persistentStore.write(e,this.name),o&&(this.node.fs.writeFileSync(`${this.name}.json`,e,{flag:"w"},e=>console.log(e)),this.node.fs.writeFileSync("root.json",JSON.stringify(this.root,null,2),{flag:"w"},e=>console.log(e)))}write(e,t){if(this.log(`SET ${t}`),-1!==t.indexOf("#")){if(t=t.substr(1),s||r)return $persistentStore.write(e,t);if(n)return $prefs.setValueForKey(e,t);o&&(this.root[t]=e)}else this.cache[t]=e;this.persistCache()}read(e){return this.log(`READ ${e}`),-1===e.indexOf("#")?this.cache[e]:(e=e.substr(1),s||r?$persistentStore.read(e):n?$prefs.valueForKey(e):o?this.root[e]:void 0)}delete(e){if(this.log(`DELETE ${e}`),-1!==e.indexOf("#")){if(e=e.substr(1),s||r)return $persistentStore.write(null,e);if(n)return $prefs.removeValueForKey(e);o&&delete this.root[e]}else delete this.cache[e];this.persistCache()}notify(e,t="",c="",l={}){const p=l["open-url"],u=l["media-url"];if(n&&$notify(e,t,c,l),s&&$notification.post(e,t,c+`${u?"\n多媒体:"+u:""}`,{url:p}),r){let n={};p&&(n.openUrl=p),u&&(n.mediaUrl=u),"{}"===JSON.stringify(n)?$notification.post(e,t,c):$notification.post(e,t,c,n)}if(o||a){const n=c+(p?`\n点击跳转: ${p}`:"")+(u?`\n多媒体: ${u}`:"");if(i){require("push").schedule({title:e,body:(t?t+"\n":"")+n})}else console.log(`${e}\n${t}\n${n}\n\n`)}}log(e){this.debug&&console.log(`[${this.name}] LOG: ${e}`)}info(e){console.log(`[${this.name}] INFO: ${e}`)}error(e){console.log(`[${this.name}] ERROR: ${e}`)}wait(e){return new Promise(t=>setTimeout(t,e))}done(e={}){n||r||s?$done(e):o&&!i&&"undefined"!=typeof $context&&($context.headers=e.headers,$context.statusCode=e.statusCode,$context.body=e.body)}}(e,t)}function Gist({token:e,key:t}){const n=HTTP({baseURL:"https://api.github.com",headers:{Authorization:`token ${e}`,"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.141 Safari/537.36"},events:{onResponse:e=>/^[45]/.test(String(e.statusCode))?Promise.reject(`ERROR: ${JSON.parse(e.body).message}`):e}});async function r(){return n.get("/gists").then(e=>{const n=JSON.parse(e.body);for(let e of n)if(e.description===t)return e.id;return-1})}this.upload=async function({filename:e,content:s}){const o=await r(),i={[e]:{content:s}};return-1===o?n.post({url:"/gists",body:JSON.stringify({description:t,public:!1,files:i})}):n.patch({url:`/gists/${o}`,body:JSON.stringify({files:i})})},this.download=async function(e){const t=await r();if(-1===t)return Promise.reject("未找到Gist备份!");try{const{files:r}=await n.get(`/gists/${t}`).then(e=>JSON.parse(e.body)),s=r[e].raw_url;return await n.get(s).then(e=>e.body)}catch(e){return Promise.reject(e)}}}function express({port:e}={port:3e3}){const{isNode:t}=ENV(),n={"Content-Type":"text/plain;charset=UTF-8","Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST,GET,OPTIONS,PATCH,PUT,DELETE","Access-Control-Allow-Headers":"Origin, X-Requested-With, Content-Type, Accept"};if(t){const t=require("express"),r=require("body-parser"),s=t();return s.use(r.json({verify:a})),s.use(r.urlencoded({verify:a,extended:!0})),s.use(r.raw({verify:a,type:"*/*"})),s.use((e,t,r)=>{t.set(n),r()}),s.start=(()=>{s.listen(e,()=>{$.log(`Express started on port: ${e}`)})}),s}const r=[],s=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD'","ALL"],o=(e,t=0)=>{let{method:n,url:s,headers:i,body:a}=e;/json/i.test(i["Content-Type"])&&(a=JSON.parse(a)),n=n.toUpperCase();const{path:u,query:f}=function(e){const t=(e.match(/https?:\/\/[^\/]+(\/[^?]*)/)||[])[1]||"/",n=e.indexOf("?"),r={};if(-1!==n){let t=e.slice(e.indexOf("?")+1).split("&");for(let e=0;em&&(h=r[d],m=e.split("/").length)}if(h){const e=()=>{o(n,s,d)},t={method:n,url:s,path:u,query:f,params:p(h.pattern,u),headers:i,body:a},r=c(),l=h.callback,m=e=>{r.status(500).json({status:"failed",message:`Internal Server Error: ${e}`})};if("AsyncFunction"===l.constructor.name)l(t,r,e).catch(m);else try{l(t,r,e)}catch(e){m(e)}}else{c().status(404).json({status:"failed",message:"ERROR: 404 not found"})}},i={};return s.forEach(e=>{i[e.toLowerCase()]=((t,n)=>{r.push({method:e,pattern:t,callback:n})})}),i.route=(e=>{const t={};return s.forEach(n=>{t[n.toLowerCase()]=(s=>(r.push({method:n,pattern:e,callback:s}),t))}),t}),i.start=(()=>{o($request)}),i;function a(e,t,n,r){n&&n.length&&(e.rawBody=n.toString(r||"utf8"))}function c(){let e=200;const{isQX:t,isLoon:r,isSurge:s}=ENV(),o=n,i={200:"HTTP/1.1 200 OK",201:"HTTP/1.1 201 Created",302:"HTTP/1.1 302 Found",307:"HTTP/1.1 307 Temporary Redirect",308:"HTTP/1.1 308 Permanent Redirect",404:"HTTP/1.1 404 Not Found",500:"HTTP/1.1 500 Internal Server Error"};return new class{status(t){return e=t,this}send(n=""){const a={status:t?i[e]:e,body:n,headers:o};t?$done(a):(r||s)&&$done({response:a})}end(){this.send()}html(e){this.set("Content-Type","text/html;charset=UTF-8"),this.send(e)}json(e){this.set("Content-Type","application/json;charset=UTF-8"),this.send(JSON.stringify(e))}set(e,t){return o[e]=t,this}}}function l(e,t){if(e instanceof RegExp&&e.test(t))return!0;if("/"===e)return!0;if(-1===e.indexOf(":")){const n=t.split("/"),r=e.split("/");for(let e=0;e>>6)+n(128|63&t):n(224|t>>>12&15)+n(128|t>>>6&63)+n(128|63&t):(t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320),n(240|t>>>18&7)+n(128|t>>>12&63)+n(128|t>>>6&63)+n(128|63&t))},s=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,o=function(t){const n=[0,2,1][t.length%3],r=t.charCodeAt(0)<<16|(t.length>1?t.charCodeAt(1):0)<<8|(t.length>2?t.charCodeAt(2):0);return[e.charAt(r>>>18),e.charAt(r>>>12&63),n>=2?"=":e.charAt(r>>>6&63),n>=1?"=":e.charAt(63&r)].join("")};this.encode=function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)?e.toString("base64"):function(e){return e.replace(s,r)}(String(e)).replace(/[\s\S]{1,3}/g,o)};const i=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,a=function(e){switch(e.length){case 4:const t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return n(55296+(t>>>10))+n(56320+(1023&t));case 3:return n((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return n((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},c=function(e){const r=e.length,s=r%4,o=(r>0?t[e.charAt(0)]<<18:0)|(r>1?t[e.charAt(1)]<<12:0)|(r>2?t[e.charAt(2)]<<6:0)|(r>3?t[e.charAt(3)]:0),i=[n(o>>>16),n(o>>>8&255),n(255&o)];return i.length-=[0,0,2,1][s],i.join("")},l=function(e){return e.replace(/\S{1,4}/g,c)},p=function(e){return l(e).replace(i,a)};this.decode=function(e){return p(String(e).replace(/[-_]/g,function(e){return"-"===e?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,"")).replace(/>/g,">").replace(/</g,"<")},this.safeEncode=function(e){return this.encode(e.replace(/\+/g,"-").replace(/\//g,"_"))},this.safeDecode=function(e){return this.decode(e.replace(/-/g,"+").replace(/_/g,"/"))}}var YAML=function(){function e(e){return null==e}var t={isNothing:e,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(t){return Array.isArray(t)?t:e(t)?[]:[t]},repeat:function(e,t){var n,r="";for(n=0;na&&(t=r-a+(o=" ... ").length),n-r>a&&(n=r+a-(i=" ...").length),{str:o+e.slice(t,n).replace(/\t/g,"→")+i,pos:r-t+o.length}}function i(e,n){return t.repeat(" ",n-e.length)+e}var a=function(e,n){if(n=Object.create(n||null),!e.buffer)return null;n.maxLength||(n.maxLength=79),"number"!=typeof n.indent&&(n.indent=1),"number"!=typeof n.linesBefore&&(n.linesBefore=3),"number"!=typeof n.linesAfter&&(n.linesAfter=2);for(var r,s=/\r?\n|\r|\0/g,a=[0],c=[],l=-1;r=s.exec(e.buffer);)c.push(r.index),a.push(r.index+r[0].length),e.position<=r.index&&l<0&&(l=a.length-2);l<0&&(l=a.length-1);var p,u,f="",d=Math.min(e.line+n.linesAfter,c.length).toString().length,h=n.maxLength-(n.indent+d+3);for(p=1;p<=n.linesBefore&&!(l-p<0);p++)u=o(e.buffer,a[l-p],c[l-p],e.position-(a[l]-a[l-p]),h),f=t.repeat(" ",n.indent)+i((e.line-p+1).toString(),d)+" | "+u.str+"\n"+f;for(u=o(e.buffer,a[l],c[l],e.position,h),f+=t.repeat(" ",n.indent)+i((e.line+1).toString(),d)+" | "+u.str+"\n",f+=t.repeat("-",n.indent+d+3+u.pos)+"^\n",p=1;p<=n.linesAfter&&!(l+p>=c.length);p++)u=o(e.buffer,a[l+p],c[l+p],e.position-(a[l]-a[l+p]),h),f+=t.repeat(" ",n.indent)+i((e.line+p+1).toString(),d)+" | "+u.str+"\n";return f.replace(/\n$/,"")},c=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],l=["scalar","sequence","mapping"];var p=function(e,t){var n,r;if(t=t||{},Object.keys(t).forEach(function(t){if(-1===c.indexOf(t))throw new s('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')}),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=(n=t.styleAliases||null,r={},null!==n&&Object.keys(n).forEach(function(e){n[e].forEach(function(t){r[String(t)]=e})}),r),-1===l.indexOf(this.kind))throw new s('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function u(e,t){var n=[];return e[t].forEach(function(e){var t=n.length;n.forEach(function(n,r){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=r)}),n[t]=e}),n}function f(e){return this.extend(e)}f.prototype.extend=function(e){var t=[],n=[];if(e instanceof p)n.push(e);else if(Array.isArray(e))n=n.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new s("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit))}t.forEach(function(e){if(!(e instanceof p))throw new s("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new s("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new s("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")}),n.forEach(function(e){if(!(e instanceof p))throw new s("Specified list of YAML types (or a single Type object) contains a non-Type object.")});var r=Object.create(f.prototype);return r.implicit=(this.implicit||[]).concat(t),r.explicit=(this.explicit||[]).concat(n),r.compiledImplicit=u(r,"implicit"),r.compiledExplicit=u(r,"explicit"),r.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function r(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),O=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var A=/^[-+]?[0-9]+e/;var C=new p("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!O.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||t.isNegativeZero(e))},represent:function(e,n){var r;if(isNaN(e))switch(n){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(n){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(n){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(t.isNegativeZero(e))return"-0.0";return r=e.toString(10),A.test(r)?r.replace("e",".e"):r},defaultStyle:"lowercase"}),k=y.extend({implicit:[$,w,S,C]}),x=k,R=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),I=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var N=new p("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==R.exec(e)||null!==I.exec(e))},construct:function(e){var t,n,r,s,o,i,a,c,l=0,p=null;if(null===(t=R.exec(e))&&(t=I.exec(e)),null===t)throw new Error("Date resolve error");if(n=+t[1],r=+t[2]-1,s=+t[3],!t[4])return new Date(Date.UTC(n,r,s));if(o=+t[4],i=+t[5],a=+t[6],t[7]){for(l=t[7].slice(0,3);l.length<3;)l+="0";l=+l}return t[9]&&(p=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(p=-p)),c=new Date(Date.UTC(n,r,s,o,i,a,l)),p&&c.setTime(c.getTime()-p),c},instanceOf:Date,represent:function(e){return e.toISOString()}});var T=new p("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),P="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var E=new p("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,r=0,s=e.length,o=P;for(n=0;n64)){if(t<0)return!1;r+=6}return r%8==0},construct:function(e){var t,n,r=e.replace(/[\r\n=]/g,""),s=r.length,o=P,i=0,a=[];for(t=0;t>16&255),a.push(i>>8&255),a.push(255&i)),i=i<<6|o.indexOf(r.charAt(t));return 0==(n=s%4*6)?(a.push(i>>16&255),a.push(i>>8&255),a.push(255&i)):18===n?(a.push(i>>10&255),a.push(i>>2&255)):12===n&&a.push(i>>4&255),new Uint8Array(a)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,n,r="",s=0,o=e.length,i=P;for(t=0;t>18&63],r+=i[s>>12&63],r+=i[s>>6&63],r+=i[63&s]),s=(s<<8)+e[t];return 0==(n=o%3)?(r+=i[s>>18&63],r+=i[s>>12&63],r+=i[s>>6&63],r+=i[63&s]):2===n?(r+=i[s>>10&63],r+=i[s>>4&63],r+=i[s<<2&63],r+=i[64]):1===n&&(r+=i[s>>2&63],r+=i[s<<4&63],r+=i[64],r+=i[64]),r}}),j=Object.prototype.hasOwnProperty,F=Object.prototype.toString;var D=new p("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,r,s,o,i=[],a=e;for(t=0,n=a.length;t>10),56320+(e-65536&1023))}for(var le=new Array(256),pe=new Array(256),ue=0;ue<256;ue++)le[ue]=ae(ue)?1:0,pe[ue]=ae(ue);function fe(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||_,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function de(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=a(n),new s(t,n)}function he(e,t){throw de(e,t)}function me(e,t){e.onWarning&&e.onWarning.call(null,de(e,t))}var ge={YAML:function(e,t,n){var r,s,o;null!==e.version&&he(e,"duplication of %YAML directive"),1!==n.length&&he(e,"YAML directive accepts exactly one argument"),null===(r=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&he(e,"ill-formed argument of the YAML directive"),s=parseInt(r[1],10),o=parseInt(r[2],10),1!==s&&he(e,"unacceptable YAML version of the document"),e.version=n[0],e.checkLineBreaks=o<2,1!==o&&2!==o&&me(e,"unsupported YAML version of the document")},TAG:function(e,t,n){var r,s;2!==n.length&&he(e,"TAG directive accepts exactly two arguments"),r=n[0],s=n[1],Z.test(r)||he(e,"ill-formed tag handle (first argument) of the TAG directive"),H.call(e.tagMap,r)&&he(e,'there is a previously declared suffix for "'+r+'" tag handle'),ee.test(s)||he(e,"ill-formed tag prefix (second argument) of the TAG directive");try{s=decodeURIComponent(s)}catch(t){he(e,"tag prefix is malformed: "+s)}e.tagMap[r]=s}};function ye(e,t,n,r){var s,o,i,a;if(t1&&(e.result+=t.repeat("\n",n-1))}function Ae(e,t){var n,r,s=e.tag,o=e.anchor,i=[],a=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=i),r=e.input.charCodeAt(e.position);0!==r&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,he(e,"tab characters must not be used in indentation")),45===r)&&se(e.input.charCodeAt(e.position+1));)if(a=!0,e.position++,ve(e,!0,-1)&&e.lineIndent<=t)i.push(null),r=e.input.charCodeAt(e.position);else if(n=e.line,xe(e,t,Y,!1,!0),i.push(e.result),ve(e,!0,-1),r=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==r)he(e,"bad indentation of a sequence entry");else if(e.lineIndentn?m=1:e.lineIndent===n?m=0:e.lineIndentn?m=1:e.lineIndent===n?m=0:e.lineIndentt)&&(y&&(i=e.line,a=e.lineStart,c=e.position),xe(e,t,G,!0,s)&&(y?m=e.result:g=e.result),y||(we(e,f,d,h,m,g,i,a,c),h=m=g=null),ve(e,!0,-1),l=e.input.charCodeAt(e.position)),(e.line===o||e.lineIndent>t)&&0!==l)he(e,"bad indentation of a mapping entry");else if(e.lineIndent=0))break;0===o?he(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):p?he(e,"repeat of an indentation width identifier"):(u=n+o-1,p=!0)}if(re(i)){do{i=e.input.charCodeAt(++e.position)}while(re(i));if(35===i)do{i=e.input.charCodeAt(++e.position)}while(!ne(i)&&0!==i)}for(;0!==i;){for(be(e),e.lineIndent=0,i=e.input.charCodeAt(e.position);(!p||e.lineIndentu&&(u=e.lineIndent),ne(i))f++;else{if(e.lineIndent0){for(s=i,o=0;s>0;s--)(i=ie(a=e.input.charCodeAt(++e.position)))>=0?o=(o<<4)+i:he(e,"expected hexadecimal character");e.result+=ce(o),e.position++}else he(e,"unknown escape sequence");n=r=e.position}else ne(a)?(ye(e,n,r,!0),Oe(e,ve(e,!1,t)),n=r=e.position):e.position===e.lineStart&&Se(e)?he(e,"unexpected end of the document within a double quoted scalar"):(e.position++,r=e.position)}he(e,"unexpected end of the stream within a double quoted scalar")}(e,d)?y=!0:!function(e){var t,n,r;if(42!==(r=e.input.charCodeAt(e.position)))return!1;for(r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!se(r)&&!oe(r);)r=e.input.charCodeAt(++e.position);return e.position===t&&he(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),H.call(e.anchorMap,n)||he(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],ve(e,!0,-1),!0}(e)?function(e,t,n){var r,s,o,i,a,c,l,p,u=e.kind,f=e.result;if(se(p=e.input.charCodeAt(e.position))||oe(p)||35===p||38===p||42===p||33===p||124===p||62===p||39===p||34===p||37===p||64===p||96===p)return!1;if((63===p||45===p)&&(se(r=e.input.charCodeAt(e.position+1))||n&&oe(r)))return!1;for(e.kind="scalar",e.result="",s=o=e.position,i=!1;0!==p;){if(58===p){if(se(r=e.input.charCodeAt(e.position+1))||n&&oe(r))break}else if(35===p){if(se(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&Se(e)||n&&oe(p))break;if(ne(p)){if(a=e.line,c=e.lineStart,l=e.lineIndent,ve(e,!1,-1),e.lineIndent>=t){i=!0,p=e.input.charCodeAt(e.position);continue}e.position=o,e.line=a,e.lineStart=c,e.lineIndent=l;break}}i&&(ye(e,s,o,!1),Oe(e,e.line-a),s=o=e.position,i=!1),re(p)||(o=e.position+1),p=e.input.charCodeAt(++e.position)}return ye(e,s,o,!1),!!e.result||(e.kind=u,e.result=f,!1)}(e,d,B===r)&&(y=!0,null===e.tag&&(e.tag="?")):(y=!0,null===e.tag&&null===e.anchor||he(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===m&&(y=c&&Ae(e,h))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&he(e,'unacceptable node kind for ! tag; it should be "scalar", not "'+e.kind+'"'),l=0,p=e.implicitTypes.length;l"),null!==e.result&&f.kind!==e.kind&&he(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+f.kind+'", not "'+e.kind+'"'),f.resolve(e.result,e.tag)?(e.result=f.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):he(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||y}function Re(e){var t,n,r,s,o=e.position,i=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(s=e.input.charCodeAt(e.position))&&(ve(e,!0,-1),s=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==s));){for(i=!0,s=e.input.charCodeAt(++e.position),t=e.position;0!==s&&!se(s);)s=e.input.charCodeAt(++e.position);for(r=[],(n=e.input.slice(t,e.position)).length<1&&he(e,"directive name must not be less than one character in length");0!==s;){for(;re(s);)s=e.input.charCodeAt(++e.position);if(35===s){do{s=e.input.charCodeAt(++e.position)}while(0!==s&&!ne(s));break}if(ne(s))break;for(t=e.position;0!==s&&!se(s);)s=e.input.charCodeAt(++e.position);r.push(e.input.slice(t,e.position))}0!==s&&be(e),H.call(ge,n)?ge[n](e,n,r):me(e,'unknown document directive "'+n+'"')}ve(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,ve(e,!0,-1)):i&&he(e,"directives end mark is expected"),xe(e,e.lineIndent-1,G,!1,!0),ve(e,!0,-1),e.checkLineBreaks&&V.test(e.input.slice(o,e.position))&&me(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&Se(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,ve(e,!0,-1)):e.position=55296&&r<=56319&&t+1=56320&&n<=57343?1024*(r-55296)+n-56320+65536:r}function $t(e){return/^\n* /.test(e)}var wt=1,bt=2,vt=3,St=4,Ot=5;function At(e,t,n,r,s,o,i,a){var c,l,p=0,u=null,f=!1,d=!1,h=-1!==r,m=-1,g=ht(l=yt(e,0))&&l!==Ee&&!dt(l)&&l!==Ge&&l!==We&&l!==Ke&&l!==Ye&&l!==ze&&l!==Ze&&l!==tt&&l!==rt&&l!==Je&&l!==He&&l!==qe&&l!==Ue&&l!==nt&&l!==Xe&&l!==Qe&&l!==Be&&l!==Me&&l!==_e&&l!==Ve&&l!==et&&function(e){return!dt(e)&&e!==Ke}(yt(e,e.length-1));if(t||i)for(c=0;c=65536?c+=2:c++){if(!ht(p=yt(e,c)))return Ot;g=g&>(p,u,a),u=p}else{for(c=0;c=65536?c+=2:c++){if((p=yt(e,c))===Fe)f=!0,h&&(d=d||c-m-1>r&&" "!==e[m+1],m=c);else if(!ht(p))return Ot;g=g&>(p,u,a),u=p}d=d||h&&c-m-1>r&&" "!==e[m+1]}return f||d?n>9&&$t(e)?Ot:i?o===lt?Ot:bt:d?St:vt:!g||i||s(e)?o===lt?Ot:bt:wt}function Ct(e,t,n,r,o){e.dump=function(){if(0===t.length)return e.quotingType===lt?'""':"''";if(!e.noCompatMode&&(-1!==ot.indexOf(t)||it.test(t)))return e.quotingType===lt?'"'+t+'"':"'"+t+"'";var i=e.indent*Math.max(1,n),a=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-i),c=r||e.flowLevel>-1&&n>=e.flowLevel;switch(At(t,c,e.indent,a,function(t){return function(e,t){var n,r;for(n=0,r=e.implicitTypes.length;n"+kt(t,e.indent)+xt(ut(function(e,t){var n,r,s=/(\n+)([^\n]*)/g,o=(a=e.indexOf("\n"),a=-1!==a?a:e.length,s.lastIndex=a,Rt(e.slice(0,a),t)),i="\n"===e[0]||" "===e[0];var a;for(;r=s.exec(e);){var c=r[1],l=r[2];n=" "===l[0],o+=c+(i||n||""===l?"":"\n")+Rt(l,t),i=n}return o}(t,a),i));case Ot:return'"'+function(e){for(var t,n="",r=0,s=0;s=65536?s+=2:s++)r=yt(e,s),!(t=st[r])&&ht(r)?(n+=e[s],r>=65536&&(n+=e[s+1])):n+=t||at(r);return n}(t)+'"';default:throw new s("impossible error: invalid scalar style")}}()}function kt(e,t){var n=$t(e)?String(t):"",r="\n"===e[e.length-1];return n+(r&&("\n"===e[e.length-2]||"\n"===e)?"+":r?"":"-")+"\n"}function xt(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function Rt(e,t){if(""===e||" "===e[0])return e;for(var n,r,s=/ [^ ]/g,o=0,i=0,a=0,c="";n=s.exec(e);)(a=n.index)-o>t&&(r=i>o?i:a,c+="\n"+e.slice(o,r),o=r+1),i=a;return c+="\n",e.length-o>t&&i>o?c+=e.slice(o,i)+"\n"+e.slice(i+1):c+=e.slice(o),c.slice(1)}function It(e,t,n,r){var s,o,i,a="",c=e.tag;for(s=0,o=n.length;s tag resolver accepts not "'+l+'" style');r=c.represent[l](t,l)}e.dump=r}return!0}return!1}function Tt(e,t,n,r,o,i,a){e.tag=null,e.dump=n,Nt(e,n,!1)||Nt(e,n,!0);var c,l=Te.call(e.dump),p=r;r&&(r=e.flowLevel<0||e.flowLevel>t);var u,f,d="[object Object]"===l||"[object Array]"===l;if(d&&(f=-1!==(u=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||f||2!==e.indent&&t>0)&&(o=!1),f&&e.usedDuplicates[u])e.dump="*ref_"+u;else{if(d&&f&&!e.usedDuplicates[u]&&(e.usedDuplicates[u]=!0),"[object Object]"===l)r&&0!==Object.keys(e.dump).length?(!function(e,t,n,r){var o,i,a,c,l,p,u="",f=e.tag,d=Object.keys(n);if(!0===e.sortKeys)d.sort();else if("function"==typeof e.sortKeys)d.sort(e.sortKeys);else if(e.sortKeys)throw new s("sortKeys must be a boolean or a function");for(o=0,i=d.length;o1024)&&(e.dump&&Fe===e.dump.charCodeAt(0)?p+="?":p+="? "),p+=e.dump,l&&(p+=ft(e,t)),Tt(e,t+1,c,!0,l)&&(e.dump&&Fe===e.dump.charCodeAt(0)?p+=":":p+=": ",u+=p+=e.dump));e.tag=f,e.dump=u||"{}"}(e,t,e.dump,o),f&&(e.dump="&ref_"+u+e.dump)):(!function(e,t,n){var r,s,o,i,a,c="",l=e.tag,p=Object.keys(n);for(r=0,s=p.length;r1024&&(a+="? "),a+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),Tt(e,t,i,!1,!1)&&(c+=a+=e.dump));e.tag=l,e.dump="{"+c+"}"}(e,t,e.dump),f&&(e.dump="&ref_"+u+" "+e.dump));else if("[object Array]"===l)r&&0!==e.dump.length?(e.noArrayIndent&&!a&&t>0?It(e,t-1,e.dump,o):It(e,t,e.dump,o),f&&(e.dump="&ref_"+u+e.dump)):(!function(e,t,n){var r,s,o,i="",a=e.tag;for(r=0,s=n.length;r",e.dump=c+" "+e.dump)}return!0}function Pt(e,t){var n,r,s=[],o=[];for(function e(t,n,r){var s,o,i;if(null!==t&&"object"==typeof t)if(-1!==(o=n.indexOf(t)))-1===r.indexOf(o)&&r.push(o);else if(n.push(t),Array.isArray(t))for(o=0,i=t.length;o