Sub-Store/backend/sub-store.min.js

2 lines
96 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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

// UPDATED AT: 2022年 3月11日 星期五 23时04分15秒 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")}function u(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":null}async function f(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 d({type:e,item:t,platform:r,useCache:s,noProcessor:o}={platform:"JSON",useCache:!1,noProcessor:!1}){if("subscription"===e){const e=t,n=await f(e.url,s,e.ua);let i=ProxyUtils.parse(n);o||(i=await ProxyUtils.process(i,e.process||[]));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<a.length;t++){const n=e[a[t]];$.info(`正在处理子订阅:${n.name},进度--${100*((t+1)/a.length).toFixed(1)}% `);try{const e=await f(n.url,s,n.ua);let t=ProxyUtils.parse(e);o||(t=await ProxyUtils.process(t,n.process||[])),c=c.concat(t)}catch(e){$.error(`处理组合订阅中的子订阅: ${n.name}时出现错误:${e}! 该订阅已被跳过。`)}}if(o||(c=await ProxyUtils.process(c,i.process||[])),0===c.length)throw new Error("组合订阅中不含有效节点!");const l={};return c.forEach(e=>{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;t<e.urls.length;t++){const r=e.urls[t];$.info(`正在处理URL${r},进度--${100*((t+1)/e.urls.length).toFixed(1)}% `);try{const{body:e}=await $.http.get(r),t=RuleUtils.parse(e);n=n.concat(t)}catch(e){$.error(`处理分流订阅中的URL: ${r}时出现错误:${e}! 该订阅已被跳过。`)}}return n=await RuleUtils.process(n,[{type:"Remove Duplicate Filter"}]),RuleUtils.produce(n,r)}}$.read(n)||$.write({},n),$.read(r)||$.write({},r),$.read(t)||$.write({},t),$.read(s)||$.write({},s),$.read(i)||$.write({},i),$.write({rules:getBuiltInRules()},o),e.get("/download/collection/:name",async function(e,t){const{name:n}=e.params,{cache:s}=e.query||"false",{raw:o}=e.query||"false",i=e.query.target||u(e.headers)||"JSON",a=void 0===s?"JSON"===i||"URI"===i:s,c=$.read(r)[n];if($.info(`正在下载组合订阅:${n}`),c)try{const e=await d({type:"collection",item:c,platform:i,useCache:a,noProcessor:o});"JSON"===i?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 下载组合订阅错误:${n}`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 未找到组合订阅:${n}`),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||u(e.headers)||"JSON",a=void 0===s?"JSON"===i||"URI"===i:s;$.info(`正在下载订阅:${r}`);const c=$.read(n)[r];if(c)try{const n=await d({type:"subscription",item:c,platform:i,useCache:a,noProcessor:o});if(-1!==["QX","Surge","Loon"].indexOf(u(e.headers))){const{headers:e}=await $.http.get({url:c.url,headers:{"User-Agent":"Quantumult/1.0.13 (iPhone10,3; iOS 14.0)"}}),n=Object.keys(e).filter(e=>/SUBSCRIPTION-USERINFO/i.test(e))[0],r=e[n];t.set("subscription-userinfo",r)}"JSON"===i?t.set("Content-Type","application/json;charset=utf-8").send(n):t.send(n)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}`,`🤔 原因:${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||u(e.headers)||"Surge";let i;$.info(`正在下载${r?"内置":""}分流订阅:${n}...`),r&&(i=$.read(o).rules[n]);if(i){const e=await d({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 d({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 f(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=[];for(const e of Object.values(o))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 d({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=>/^<!DOCTYPE html>/.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<i.length;e++){let n=i[e];s=n.encryption?n.encryption:s,o=n.password?n.password:o;let a=Base64.safeEncode(s+":"+o),c=n.server;r=n.port?n.port:r;let l=n.remarks?n.remarks:e,p=n.plugin_options?"/?plugin="+encodeURIComponent(n.plugin+";"+n.plugin_options):"";t[e]="ss://"+a+"@"+c+":"+r+p+"#"+l}return t.join("\n")}}]}(),PROXY_PARSERS=function(){function e(e){const t=e.split(","),n={},r=["shadowsocks","vmess","http","trojan"];return t.forEach(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<n.length;e++){const r=n[e];if(-1!==r.indexOf("=")){const[e,n]=r.split("=");t[e.trim()]=n.trim()}}return t}return[{name:"URI SS Parser",test: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-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-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-path"]=e.path,r["ws-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-path"]=t["ws-path"];const e=t["ws-headers"].match(/(,|^|\s)*HOST:\s*(.*?)(,|$)/),n=e?e[2]:r.server;r["ws-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-path"]=t.path,n["ws-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-path"]=n["obfs-uri"],r["ws-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++<i;)n=t[0]+n;"front"===s?e.name=n+r+e.name:"back"===s&&(e.name=e.name+r+n)}return e})}}}}function SortOperator(e="asc"){return{name:"Sort Operator",func:t=>{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?r<s?-1:1:!r&&!s||r&&s&&r===s?t.name<n.name?-1:1:void 0}))}}function getRegexOrder(e,t){let n=null;for(let r=0;r<e.length;r++)if(e[r].test(t)){n=r+1;break}return n}function RegexRenameOperator(e){return{name:"Regex Rename Operator",func:t=>t.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){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)}(),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"]:""}${e.tfo?",fast-open=true":",fast-open=false"}${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-path"]?",obfs-uri="+e["ws-path"]:""},tls-verification=${e["skip-cert-verify"]?"false":"true"}`:`,obfs=ws${e["ws-headers"].Host?",obfs-host="+e["ws-headers"].Host:""}${e["ws-path"]?",obfs-uri="+e["ws-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}${e.tfo?",fast-open=true":",fast-open=false"}${e.udp?",udp-relay=true":",udp-relay=false"}`;return 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"}${e.tfo?",fast-open=true":",fast-open=false"}${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}${e.tfo?",fast-open=true":",fast-open=false"},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"}`,void 0!==e["vmess-aead"]&&(r+=`,vmess-aead=${e["vmess-aead"]}`),"ws"===e.network){const t=e["ws-path"]||"/",n=Object.entries(e["ws-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"}`;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"),void 0!==e.tfo&&(s=e.tfo?",fast-open=true":",fast-open=false"),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-headers"].Host||e.server},path:${e["ws-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 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-path"]||"/",t.host=e["ws-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=[]){for(const n of t){let t,r;if(-1!==n.type.indexOf("Script")){const{mode:e,content:r}=n.args;if("link"===e)try{t=await $.http.get(r).then(e=>e.body)}catch(e){$.error(`Error when downloading remote script: ${n.args.content}.\n Reason: ${e}`);continue}else t=r}PROXY_PROCESSORS[n.type]?($.info(`Applying "${n.type}" with arguments:\n >>> ${JSON.stringify(n.args,null,2)||"None"}`),e=ApplyProcessor(r=-1!==n.type.indexOf("Script")?PROXY_PROCESSORS[n.type](t):PROXY_PROCESSORS[n.type](n.args),e)):$.error(`Unknown operator: "${n.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=>/^<!DOCTYPE html>/.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;e<t.length;e++)hash=t[e].split("="),r[hash[0]]=hash[1]}return{path:t,query:r}}(s);let d,h=null,m=0;for(d=t;d<r.length;d++)if("ALL"===r[d].method||n===r[d].method){const{pattern:e}=r[d];l(e,u)&&e.split("/").length>m&&(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<r.length;e++)if(n[e]!==r[e])return!1;return!0}return!!p(e,t)}function p(e,t){if(-1===e.indexOf(":"))return null;{const n={};for(let r=0,s=0;r<e.length;r++,s++)if(":"===e[r]){let o=[],i=[];for(;"/"!==e[++r]&&r<e.length;)o.push(e[r]);for(;"/"!==t[s]&&s<t.length;)i.push(t[s++]);n[o.join("")]=i.join("")}else if(e[r]!==t[s])return null;return n}}}function Base64Code(){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=function(e){const t={};let n=0;const r=e.length;for(;n<r;n++)t[e.charAt(n)]=n;return t}(e),n=String.fromCharCode,r=function(e){let t;return e.length<2?(t=e.charCodeAt(0))<128?e:t<2048?n(192|t>>>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(/&gt;/g,">").replace(/&lt;/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;n<t;n+=1)r+=e;return r},isNegativeZero:function(e){return 0===e&&Number.NEGATIVE_INFINITY===1/e},extend:function(e,t){var n,r,s,o;if(t)for(n=0,r=(o=Object.keys(t)).length;n<r;n+=1)e[s=o[n]]=t[s];return e}};function n(e,t){var n="",r=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+="\n\n"+e.mark.snippet),r+" "+n):r}function r(e,t){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=t,this.message=n(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack||""}r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r.prototype.toString=function(e){return this.name+": "+n(this,e)};var s=r;function o(e,t,n,r,s){var o="",i="",a=Math.floor(s/2)-1;return r-t>a&&(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<t;e+=1)arguments[e].forEach(r);return n}(r.compiledImplicit,r.compiledExplicit),r};var d=f,h=new p("tag:yaml.org,2002:str",{kind:"scalar",construct:function(e){return null!==e?e:""}}),m=new p("tag:yaml.org,2002:seq",{kind:"sequence",construct:function(e){return null!==e?e:[]}}),g=new p("tag:yaml.org,2002:map",{kind:"mapping",construct:function(e){return null!==e?e:{}}}),y=new d({explicit:[h,m,g]});var $=new p("tag:yaml.org,2002:null",{kind:"scalar",resolve:function(e){if(null===e)return!0;var t=e.length;return 1===t&&"~"===e||4===t&&("null"===e||"Null"===e||"NULL"===e)},construct:function(){return null},predicate:function(e){return null===e},represent:{canonical:function(){return"~"},lowercase:function(){return"null"},uppercase:function(){return"NULL"},camelcase:function(){return"Null"},empty:function(){return""}},defaultStyle:"lowercase"});var w=new p("tag:yaml.org,2002:bool",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t=e.length;return 4===t&&("true"===e||"True"===e||"TRUE"===e)||5===t&&("false"===e||"False"===e||"FALSE"===e)},construct:function(e){return"true"===e||"True"===e||"TRUE"===e},predicate:function(e){return"[object Boolean]"===Object.prototype.toString.call(e)},represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"});function b(e){return 48<=e&&e<=55}function v(e){return 48<=e&&e<=57}var S=new p("tag:yaml.org,2002:int",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,r=e.length,s=0,o=!1;if(!r)return!1;if("-"!==(t=e[s])&&"+"!==t||(t=e[++s]),"0"===t){if(s+1===r)return!0;if("b"===(t=e[++s])){for(s++;s<r;s++)if("_"!==(t=e[s])){if("0"!==t&&"1"!==t)return!1;o=!0}return o&&"_"!==t}if("x"===t){for(s++;s<r;s++)if("_"!==(t=e[s])){if(!(48<=(n=e.charCodeAt(s))&&n<=57||65<=n&&n<=70||97<=n&&n<=102))return!1;o=!0}return o&&"_"!==t}if("o"===t){for(s++;s<r;s++)if("_"!==(t=e[s])){if(!b(e.charCodeAt(s)))return!1;o=!0}return o&&"_"!==t}}if("_"===t)return!1;for(;s<r;s++)if("_"!==(t=e[s])){if(!v(e.charCodeAt(s)))return!1;o=!0}return!(!o||"_"===t)},construct:function(e){var t,n=e,r=1;if(-1!==n.indexOf("_")&&(n=n.replace(/_/g,"")),"-"!==(t=n[0])&&"+"!==t||("-"===t&&(r=-1),t=(n=n.slice(1))[0]),"0"===n)return 0;if("0"===t){if("b"===n[1])return r*parseInt(n.slice(2),2);if("x"===n[1])return r*parseInt(n.slice(2),16);if("o"===n[1])return r*parseInt(n.slice(2),8)}return r*parseInt(n,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&e%1==0&&!t.isNegativeZero(e)},represent:{binary:function(e){return 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}}),E="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var P=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=E;for(n=0;n<s;n++)if(!((t=o.indexOf(e.charAt(n)))>64)){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=E,i=0,a=[];for(t=0;t<s;t++)t%4==0&&t&&(a.push(i>>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=E;for(t=0;t<o;t++)t%3==0&&t&&(r+=i[s>>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<n;t+=1){if(r=a[t],o=!1,"[object Object]"!==F.call(r))return!1;for(s in r)if(j.call(r,s)){if(o)return!1;o=!0}if(!o)return!1;if(-1!==i.indexOf(s))return!1;i.push(s)}return!0},construct:function(e){return null!==e?e:[]}}),L=Object.prototype.toString;var U=new p("tag:yaml.org,2002:pairs",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,r,s,o,i=e;for(o=new Array(i.length),t=0,n=i.length;t<n;t+=1){if(r=i[t],"[object Object]"!==L.call(r))return!1;if(1!==(s=Object.keys(r)).length)return!1;o[t]=[s[0],r[s[0]]]}return!0},construct:function(e){if(null===e)return[];var t,n,r,s,o,i=e;for(o=new Array(i.length),t=0,n=i.length;t<n;t+=1)r=i[t],s=Object.keys(r),o[t]=[s[0],r[s[0]]];return o}}),M=Object.prototype.hasOwnProperty;var J=new p("tag:yaml.org,2002:set",{kind:"mapping",resolve:function(e){if(null===e)return!0;var t,n=e;for(t in n)if(M.call(n,t)&&null!==n[t])return!1;return!0},construct:function(e){return null!==e?e:{}}}),_=x.extend({implicit:[N,T],explicit:[P,D,U,J]}),H=Object.prototype.hasOwnProperty,B=1,q=2,Y=3,G=4,K=1,X=2,Q=3,W=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,V=/[\x85\u2028\u2029]/,z=/[,\[\]\{\}]/,Z=/^(?:!|!!|![a-z\-]+!)$/i,ee=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function te(e){return Object.prototype.toString.call(e)}function ne(e){return 10===e||13===e}function re(e){return 9===e||32===e}function se(e){return 9===e||32===e||10===e||13===e}function oe(e){return 44===e||91===e||93===e||123===e||125===e}function ie(e){var t;return 48<=e&&e<=57?e-48:97<=(t=32|e)&&t<=102?t-97+10:-1}function ae(e){return 48===e?"\0":97===e?"":98===e?"\b":116===e?"\t":9===e?"\t":110===e?"\n":118===e?"\v":102===e?"\f":114===e?"\r":101===e?"":32===e?" ":34===e?'"':47===e?"/":92===e?"\\":78===e?"…":95===e?" ":76===e?"\u2028":80===e?"\u2029":""}function ce(e){return e<=65535?String.fromCharCode(e):String.fromCharCode(55296+(e-65536>>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(t<n){if(a=e.input.slice(t,n),r)for(s=0,o=a.length;s<o;s+=1)9===(i=a.charCodeAt(s))||32<=i&&i<=1114111||he(e,"expected valid JSON character");else W.test(a)&&he(e,"the stream contains non-printable characters");e.result+=a}}function $e(e,n,r,s){var o,i,a,c;for(t.isObject(r)||he(e,"cannot merge mappings; the provided source object is unacceptable"),a=0,c=(o=Object.keys(r)).length;a<c;a+=1)i=o[a],H.call(n,i)||(n[i]=r[i],s[i]=!0)}function we(e,t,n,r,s,o,i,a,c){var l,p;if(Array.isArray(s))for(l=0,p=(s=Array.prototype.slice.call(s)).length;l<p;l+=1)Array.isArray(s[l])&&he(e,"nested arrays are not supported inside keys"),"object"==typeof s&&"[object Object]"===te(s[l])&&(s[l]="[object Object]");if("object"==typeof s&&"[object Object]"===te(s)&&(s="[object Object]"),s=String(s),null===t&&(t={}),"tag:yaml.org,2002:merge"===r)if(Array.isArray(o))for(l=0,p=o.length;l<p;l+=1)$e(e,t,o[l],n);else $e(e,t,o,n);else e.json||H.call(n,s)||!H.call(t,s)||(e.line=i||e.line,e.lineStart=a||e.lineStart,e.position=c||e.position,he(e,"duplicated mapping key")),"__proto__"===s?Object.defineProperty(t,s,{configurable:!0,enumerable:!0,writable:!0,value:o}):t[s]=o,delete n[s];return t}function be(e){var t;10===(t=e.input.charCodeAt(e.position))?e.position++:13===t?(e.position++,10===e.input.charCodeAt(e.position)&&e.position++):he(e,"a line break is expected"),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function ve(e,t,n){for(var r=0,s=e.input.charCodeAt(e.position);0!==s;){for(;re(s);)9===s&&-1===e.firstTabInLine&&(e.firstTabInLine=e.position),s=e.input.charCodeAt(++e.position);if(t&&35===s)do{s=e.input.charCodeAt(++e.position)}while(10!==s&&13!==s&&0!==s);if(!ne(s))break;for(be(e),s=e.input.charCodeAt(e.position),r++,e.lineIndent=0;32===s;)e.lineIndent++,s=e.input.charCodeAt(++e.position)}return-1!==n&&0!==r&&e.lineIndent<n&&me(e,"deficient indentation"),r}function Se(e){var t,n=e.position;return!(45!==(t=e.input.charCodeAt(n))&&46!==t||t!==e.input.charCodeAt(n+1)||t!==e.input.charCodeAt(n+2)||(n+=3,0!==(t=e.input.charCodeAt(n))&&!se(t)))}function Oe(e,n){1===n?e.result+=" ":n>1&&(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.lineIndent<t)break;return!!a&&(e.tag=s,e.anchor=o,e.kind="sequence",e.result=i,!0)}function Ce(e){var t,n,r,s,o=!1,i=!1;if(33!==(s=e.input.charCodeAt(e.position)))return!1;if(null!==e.tag&&he(e,"duplication of a tag property"),60===(s=e.input.charCodeAt(++e.position))?(o=!0,s=e.input.charCodeAt(++e.position)):33===s?(i=!0,n="!!",s=e.input.charCodeAt(++e.position)):n="!",t=e.position,o){do{s=e.input.charCodeAt(++e.position)}while(0!==s&&62!==s);e.position<e.length?(r=e.input.slice(t,e.position),s=e.input.charCodeAt(++e.position)):he(e,"unexpected end of the stream within a verbatim tag")}else{for(;0!==s&&!se(s);)33===s&&(i?he(e,"tag suffix cannot contain exclamation marks"):(n=e.input.slice(t-1,e.position+1),Z.test(n)||he(e,"named tag handle cannot contain such characters"),i=!0,t=e.position+1)),s=e.input.charCodeAt(++e.position);r=e.input.slice(t,e.position),z.test(r)&&he(e,"tag suffix cannot contain flow indicator characters")}r&&!ee.test(r)&&he(e,"tag name cannot contain such characters: "+r);try{r=decodeURIComponent(r)}catch(t){he(e,"tag name is malformed: "+r)}return o?e.tag=r:H.call(e.tagMap,n)?e.tag=e.tagMap[n]+r:"!"===n?e.tag="!"+r:"!!"===n?e.tag="tag:yaml.org,2002:"+r:he(e,'undeclared tag handle "'+n+'"'),!0}function ke(e){var t,n;if(38!==(n=e.input.charCodeAt(e.position)))return!1;for(null!==e.anchor&&he(e,"duplication of an anchor property"),n=e.input.charCodeAt(++e.position),t=e.position;0!==n&&!se(n)&&!oe(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&he(e,"name of an anchor node must contain at least one character"),e.anchor=e.input.slice(t,e.position),!0}function xe(e,n,r,s,o){var i,a,c,l,p,u,f,d,h,m=1,g=!1,y=!1;if(null!==e.listener&&e.listener("open",e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,i=a=c=G===r||Y===r,s&&ve(e,!0,-1)&&(g=!0,e.lineIndent>n?m=1:e.lineIndent===n?m=0:e.lineIndent<n&&(m=-1)),1===m)for(;Ce(e)||ke(e);)ve(e,!0,-1)?(g=!0,c=i,e.lineIndent>n?m=1:e.lineIndent===n?m=0:e.lineIndent<n&&(m=-1)):c=!1;if(c&&(c=g||o),1!==m&&G!==r||(d=B===r||q===r?n:n+1,h=e.position-e.lineStart,1===m?c&&(Ae(e,h)||function(e,t,n){var r,s,o,i,a,c,l,p=e.tag,u=e.anchor,f={},d=Object.create(null),h=null,m=null,g=null,y=!1,$=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=f),l=e.input.charCodeAt(e.position);0!==l;){if(y||-1===e.firstTabInLine||(e.position=e.firstTabInLine,he(e,"tab characters must not be used in indentation")),r=e.input.charCodeAt(e.position+1),o=e.line,63!==l&&58!==l||!se(r)){if(i=e.line,a=e.lineStart,c=e.position,!xe(e,n,q,!1,!0))break;if(e.line===o){for(l=e.input.charCodeAt(e.position);re(l);)l=e.input.charCodeAt(++e.position);if(58===l)se(l=e.input.charCodeAt(++e.position))||he(e,"a whitespace character is expected after the key-value separator within a block mapping"),y&&(we(e,f,d,h,m,null,i,a,c),h=m=g=null),$=!0,y=!1,s=!1,h=e.tag,m=e.result;else{if(!$)return e.tag=p,e.anchor=u,!0;he(e,"can not read an implicit mapping pair; a colon is missed")}}else{if(!$)return e.tag=p,e.anchor=u,!0;he(e,"can not read a block mapping entry; a multiline key may not be an implicit key")}}else 63===l?(y&&(we(e,f,d,h,m,null,i,a,c),h=m=g=null),$=!0,y=!0,s=!0):y?(y=!1,s=!0):he(e,"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"),e.position+=1,l=r;if((e.line===o||e.lineIndent>t)&&(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<t)break}return y&&we(e,f,d,h,m,null,i,a,c),$&&(e.tag=p,e.anchor=u,e.kind="mapping",e.result=f),$}(e,h,d))||function(e,t){var n,r,s,o,i,a,c,l,p,u,f,d,h=!0,m=e.tag,g=e.anchor,y=Object.create(null);if(91===(d=e.input.charCodeAt(e.position)))i=93,l=!1,o=[];else{if(123!==d)return!1;i=125,l=!0,o={}}for(null!==e.anchor&&(e.anchorMap[e.anchor]=o),d=e.input.charCodeAt(++e.position);0!==d;){if(ve(e,!0,t),(d=e.input.charCodeAt(e.position))===i)return e.position++,e.tag=m,e.anchor=g,e.kind=l?"mapping":"sequence",e.result=o,!0;h?44===d&&he(e,"expected the node content, but found ','"):he(e,"missed comma between flow collection entries"),f=null,a=c=!1,63===d&&se(e.input.charCodeAt(e.position+1))&&(a=c=!0,e.position++,ve(e,!0,t)),n=e.line,r=e.lineStart,s=e.position,xe(e,t,B,!1,!0),u=e.tag,p=e.result,ve(e,!0,t),d=e.input.charCodeAt(e.position),!c&&e.line!==n||58!==d||(a=!0,d=e.input.charCodeAt(++e.position),ve(e,!0,t),xe(e,t,B,!1,!0),f=e.result),l?we(e,o,y,u,p,f,n,r,s):a?o.push(we(e,null,y,u,p,f,n,r,s)):o.push(p),ve(e,!0,t),44===(d=e.input.charCodeAt(e.position))?(h=!0,d=e.input.charCodeAt(++e.position)):h=!1}he(e,"unexpected end of the stream within a flow collection")}(e,d)?y=!0:(a&&function(e,n){var r,s,o,i,a,c=K,l=!1,p=!1,u=n,f=0,d=!1;if(124===(i=e.input.charCodeAt(e.position)))s=!1;else{if(62!==i)return!1;s=!0}for(e.kind="scalar",e.result="";0!==i;)if(43===(i=e.input.charCodeAt(++e.position))||45===i)K===c?c=43===i?Q:X:he(e,"repeat of a chomping mode identifier");else{if(!((o=48<=(a=i)&&a<=57?a-48:-1)>=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.lineIndent<u)&&32===i;)e.lineIndent++,i=e.input.charCodeAt(++e.position);if(!p&&e.lineIndent>u&&(u=e.lineIndent),ne(i))f++;else{if(e.lineIndent<u){c===Q?e.result+=t.repeat("\n",l?1+f:f):c===K&&l&&(e.result+="\n");break}for(s?re(i)?(d=!0,e.result+=t.repeat("\n",l?1+f:f)):d?(d=!1,e.result+=t.repeat("\n",f+1)):0===f?l&&(e.result+=" "):e.result+=t.repeat("\n",f):e.result+=t.repeat("\n",l?1+f:f),l=!0,p=!0,f=0,r=e.position;!ne(i)&&0!==i;)i=e.input.charCodeAt(++e.position);ye(e,r,e.position,!1)}}return!0}(e,d)||function(e,t){var n,r,s;if(39!==(n=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,r=s=e.position;0!==(n=e.input.charCodeAt(e.position));)if(39===n){if(ye(e,r,e.position,!0),39!==(n=e.input.charCodeAt(++e.position)))return!0;r=e.position,e.position++,s=e.position}else ne(n)?(ye(e,r,s,!0),Oe(e,ve(e,!1,t)),r=s=e.position):e.position===e.lineStart&&Se(e)?he(e,"unexpected end of the document within a single quoted scalar"):(e.position++,s=e.position);he(e,"unexpected end of the stream within a single quoted scalar")}(e,d)||function(e,t){var n,r,s,o,i,a,c;if(34!==(a=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,n=r=e.position;0!==(a=e.input.charCodeAt(e.position));){if(34===a)return ye(e,n,e.position,!0),e.position++,!0;if(92===a){if(ye(e,n,e.position,!0),ne(a=e.input.charCodeAt(++e.position)))ve(e,!1,t);else if(a<256&&le[a])e.result+=pe[a],e.position++;else if((i=120===(c=a)?2:117===c?4:85===c?8:0)>0){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<p;l+=1)if((f=e.implicitTypes[l]).resolve(e.result)){e.result=f.construct(e.result),e.tag=f.tag,null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);break}}else if("!"!==e.tag){if(H.call(e.typeMap[e.kind||"fallback"],e.tag))f=e.typeMap[e.kind||"fallback"][e.tag];else for(f=null,l=0,p=(u=e.typeMap.multi[e.kind||"fallback"]).length;l<p;l+=1)if(e.tag.slice(0,u[l].tag.length)===u[l].tag){f=u[l];break}f||he(e,"unknown tag !<"+e.tag+">"),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<e.length-1&&he(e,"end of the stream or a document separator is expected")}function Ie(e,t){t=t||{},0!==(e=String(e)).length&&(10!==e.charCodeAt(e.length-1)&&13!==e.charCodeAt(e.length-1)&&(e+="\n"),65279===e.charCodeAt(0)&&(e=e.slice(1)));var n=new fe(e,t),r=e.indexOf("\0");for(-1!==r&&(n.position=r,he(n,"null byte is not allowed in input")),n.input+="\0";32===n.input.charCodeAt(n.position);)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)Re(n);return n.documents}var Ne={loadAll:function(e,t,n){null!==t&&"object"==typeof t&&void 0===n&&(n=t,t=null);var r=Ie(e,n);if("function"!=typeof t)return r;for(var s=0,o=r.length;s<o;s+=1)t(r[s])},load:function(e,t){var n=Ie(e,t);if(0!==n.length){if(1===n.length)return n[0];throw new s("expected a single document in the stream, but found more")}}},Te=Object.prototype.toString,Ee=Object.prototype.hasOwnProperty,Pe=65279,je=9,Fe=10,De=13,Le=32,Ue=33,Me=34,Je=35,_e=37,He=38,Be=39,qe=42,Ye=44,Ge=45,Ke=58,Xe=61,Qe=62,We=63,Ve=64,ze=91,Ze=93,et=96,tt=123,nt=124,rt=125,st={0:"\\0",7:"\\a",8:"\\b",9:"\\t",10:"\\n",11:"\\v",12:"\\f",13:"\\r",27:"\\e",34:'\\"',92:"\\\\",133:"\\N",160:"\\_",8232:"\\L",8233:"\\P"},ot=["y","Y","yes","Yes","YES","on","On","ON","n","N","no","No","NO","off","Off","OFF"],it=/^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;function at(e){var n,r,o;if(n=e.toString(16).toUpperCase(),e<=255)r="x",o=2;else if(e<=65535)r="u",o=4;else{if(!(e<=4294967295))throw new s("code point within a string may not be greater than 0xFFFFFFFF");r="U",o=8}return"\\"+r+t.repeat("0",o-n.length)+n}var ct=1,lt=2;function pt(e){this.schema=e.schema||_,this.indent=Math.max(1,e.indent||2),this.noArrayIndent=e.noArrayIndent||!1,this.skipInvalid=e.skipInvalid||!1,this.flowLevel=t.isNothing(e.flowLevel)?-1:e.flowLevel,this.styleMap=function(e,t){var n,r,s,o,i,a,c;if(null===t)return{};for(n={},s=0,o=(r=Object.keys(t)).length;s<o;s+=1)i=r[s],a=String(t[i]),"!!"===i.slice(0,2)&&(i="tag:yaml.org,2002:"+i.slice(2)),(c=e.compiledTypeMap.fallback[i])&&Ee.call(c.styleAliases,a)&&(a=c.styleAliases[a]),n[i]=a;return n}(this.schema,e.styles||null),this.sortKeys=e.sortKeys||!1,this.lineWidth=e.lineWidth||80,this.noRefs=e.noRefs||!1,this.noCompatMode=e.noCompatMode||!1,this.condenseFlow=e.condenseFlow||!1,this.quotingType='"'===e.quotingType?lt:ct,this.forceQuotes=e.forceQuotes||!1,this.replacer="function"==typeof e.replacer?e.replacer:null,this.implicitTypes=this.schema.compiledImplicit,this.explicitTypes=this.schema.compiledExplicit,this.tag=null,this.result="",this.duplicates=[],this.usedDuplicates=null}function ut(e,n){for(var r,s=t.repeat(" ",n),o=0,i=-1,a="",c=e.length;o<c;)-1===(i=e.indexOf("\n",o))?(r=e.slice(o),o=c):(r=e.slice(o,i+1),o=i+1),r.length&&"\n"!==r&&(a+=s),a+=r;return a}function ft(e,n){return"\n"+t.repeat(" ",e.indent*n)}function dt(e){return e===Le||e===je}function ht(e){return 32<=e&&e<=126||161<=e&&e<=55295&&8232!==e&&8233!==e||57344<=e&&e<=65533&&e!==Pe||65536<=e&&e<=1114111}function mt(e){return ht(e)&&e!==Pe&&e!==De&&e!==Fe}function gt(e,t,n){var r=mt(e),s=r&&!dt(e);return(n?r:r&&e!==Ye&&e!==ze&&e!==Ze&&e!==tt&&e!==rt)&&e!==Je&&!(t===Ke&&!s)||mt(t)&&!dt(t)&&e===Je||t===Ke&&s}function yt(e,t){var n,r=e.charCodeAt(t);return r>=55296&&r<=56319&&t+1<e.length&&(n=e.charCodeAt(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!==Pe&&!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<e.length;p>=65536?c+=2:c++){if(!ht(p=yt(e,c)))return Ot;g=g&&gt(p,u,a),u=p}else{for(c=0;c<e.length;p>=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&&gt(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<r;n+=1)if(e.implicitTypes[n].resolve(t))return!0;return!1}(e,t)},e.quotingType,e.forceQuotes&&!r,o)){case wt:return t;case bt:return"'"+t.replace(/'/g,"''")+"'";case vt:return"|"+kt(t,e.indent)+xt(ut(t,i));case St:return">"+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<e.length;r>=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<o;s+=1)i=n[s],e.replacer&&(i=e.replacer.call(n,String(s),i)),(Tt(e,t+1,i,!0,!0,!1,!0)||void 0===i&&Tt(e,t+1,null,!0,!0,!1,!0))&&(r&&""===a||(a+=ft(e,t)),e.dump&&Fe===e.dump.charCodeAt(0)?a+="-":a+="- ",a+=e.dump);e.tag=c,e.dump=a||"[]"}function Nt(e,t,n){var r,o,i,a,c,l;for(i=0,a=(o=n?e.explicitTypes:e.implicitTypes).length;i<a;i+=1)if(((c=o[i]).instanceOf||c.predicate)&&(!c.instanceOf||"object"==typeof t&&t instanceof c.instanceOf)&&(!c.predicate||c.predicate(t))){if(n?c.multi&&c.representName?e.tag=c.representName(t):e.tag=c.tag:e.tag="?",c.represent){if(l=e.styleMap[c.tag]||c.defaultStyle,"[object Function]"===Te.call(c.represent))r=c.represent(t,l);else{if(!Ee.call(c.represent,l))throw new s("!<"+c.tag+'> 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;o<i;o+=1)p="",r&&""===u||(p+=ft(e,t)),c=n[a=d[o]],e.replacer&&(c=e.replacer.call(n,a,c)),Tt(e,t+1,a,!0,!0,!0)&&((l=null!==e.tag&&"?"!==e.tag||e.dump&&e.dump.length>1024)&&(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;r<s;r+=1)a="",""!==c&&(a+=", "),e.condenseFlow&&(a+='"'),i=n[o=p[r]],e.replacer&&(i=e.replacer.call(n,o,i)),Tt(e,t,o,!1,!1)&&(e.dump.length>1024&&(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<s;r+=1)o=n[r],e.replacer&&(o=e.replacer.call(n,String(r),o)),(Tt(e,t,o,!1,!1)||void 0===o&&Tt(e,t,null,!1,!1))&&(""!==i&&(i+=","+(e.condenseFlow?"":" ")),i+=e.dump);e.tag=a,e.dump="["+i+"]"}(e,t,e.dump),f&&(e.dump="&ref_"+u+" "+e.dump));else{if("[object String]"!==l){if("[object Undefined]"===l)return!1;if(e.skipInvalid)return!1;throw new s("unacceptable kind of an object to dump "+l)}"?"!==e.tag&&Ct(e,e.dump,t,i,p)}null!==e.tag&&"?"!==e.tag&&(c=encodeURI("!"===e.tag[0]?e.tag.slice(1):e.tag).replace(/!/g,"%21"),c="!"===e.tag[0]?"!"+c:"tag:yaml.org,2002:"===c.slice(0,18)?"!!"+c.slice(18):"!<"+c+">",e.dump=c+" "+e.dump)}return!0}function Et(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<i;o+=1)e(t[o],n,r);else for(s=Object.keys(t),o=0,i=s.length;o<i;o+=1)e(t[s[o]],n,r)}(e,s,o),n=0,r=o.length;n<r;n+=1)t.duplicates.push(s[o[n]]);t.usedDuplicates=new Array(r)}function Pt(e,t){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+t+" instead, which is now safe by default.")}}return{Type:p,Schema:d,FAILSAFE_SCHEMA:y,JSON_SCHEMA:k,CORE_SCHEMA:x,DEFAULT_SCHEMA:_,load:Ne.load,loadAll:Ne.loadAll,dump:{dump:function(e,t){var n=new pt(t=t||{});n.noRefs||Et(e,n);var r=e;return n.replacer&&(r=n.replacer.call({"":r},"",r)),Tt(n,0,r,!0,!0)?n.dump+"\n":""}}.dump,YAMLException:s,types:{binary:P,float:C,map:g,null:$,pairs:U,set:J,timestamp:N,bool:w,int:S,merge:T,omap:D,seq:m,str:h},safeLoad:Pt("safeLoad","load"),safeLoadAll:Pt("safeLoadAll","loadAll"),safeDump:Pt("safeDump","dump")}}();