kitten-cloud-function
Version:
用于编程猫源码云功能(云变量、云列表等)的客户端工具
6 lines • 99.6 kB
JavaScript
/**
* @name 源码云功能
* @author SLIGHTNING
* @version 1.2.0
* @license AGPL-3.0
*/!function(){"use strict";var e,t,i={976:function(e,t,i){var r={};i.r(r),i.d(r,{CodemaoUser:function(){return re},CodemaoUserInfo:function(){return te},CodemaoUserSex:function(){return B},CodemaoWork:function(){return me},CodemaoWorkEditor:function(){return ne},CodemaoWorkInfo:function(){return he},KittenCloudData:function(){return Ke},KittenCloudDataGroup:function(){return et},KittenCloudDataType:function(){return Le},KittenCloudDataUpdateSource:function(){return Se},KittenCloudFunction:function(){return Ct},KittenCloudFunctionConfigLayer:function(){return Oe},KittenCloudList:function(){return Rt},KittenCloudListGroup:function(){return Lt},KittenCloudOnlineUserNumber:function(){return ge},KittenCloudPrivateVariable:function(){return st},KittenCloudPrivateVariableGroup:function(){return ct},KittenCloudPublicVariable:function(){return Ye},KittenCloudPublicVariableGroup:function(){return rt},KittenCloudVariable:function(){return Ge},KittenCloudVariableGroup:function(){return tt},Signal:function(){return pe},SingleConfig:function(){return Te},__diff:function(){return jt},getCalibratedTimestamp:function(){return U},getClientID:function(){return S},getCurrentTime:function(){return R},getKittenNWorkPublicResource:function(){return J},getKittenWorkPublicResource:function(){return K},getNemoWorkPublicResource:function(){return $},getSignUUID:function(){return j},getThisUserDetail:function(){return I},getTimeDifference:function(){return L},getUserDetail:function(){return x},getUserHonor:function(){return D},getUserProfile:function(){return A},getWorkDetail:function(){return V},getWorkInfo:function(){return M},setXCreationToolsDeviceAuth:function(){return C}});const o=null;function n(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(e.constructor!=t.constructor)return!1;if(Array.isArray(e)){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(!n(e[i],t[i]))return!1;return!0}let i=Object.keys(e);if(i.length!=Object.keys(t).length)return!1;for(const r of i)if(!(r in t)||!n(e[r],t[r]))return!1;return!0}return!1}function s(e){return function(t,i,r){r.enumerable=e}}const a="0123456789",c="abcdefghijklmnopqrstuvwxyz",u=c.concat("ABCDEFGHIJKLMNOPQRSTUVWXYZ");function l(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}const h=!1,d="object"==typeof window,m=d&&location.hostname.endsWith("codemao.cn"),f=h?Object(function(){var e=new Error("Cannot find module 'appdirsjs'");throw e.code="MODULE_NOT_FOUND",e}())({appName:"SLIGHTNING/Codemao-Community"}):null;async function p(){if(null==f)throw new Error("当前环境不支持该方法");try{return String(await(await Promise.resolve().then((function(){var e=new Error("Cannot find module 'fs'");throw e.code="MODULE_NOT_FOUND",e}))).promises.readFile((await Promise.resolve().then((function(){var e=new Error("Cannot find module 'path'");throw e.code="MODULE_NOT_FOUND",e}))).resolve(f.config,"authorization.txt")))}catch(e){if(e instanceof Error&&"code"in e&&"ENOENT"==e.code)return null;throw e}}let v=null,g=null;function w(){return v}function y(){return null!=g?g:g=new Promise(((e,t)=>{function i(i){null!=i?(window.addEventListener("message",(function t(r){const{data:o}=r;null!=o&&"object"==typeof o&&/^https?:\/\/coco\.codemao\.cn$/.test(r.origin)&&"COCO_CODEMAO_ENVIRONMENT_SERVER_INIT"==o.type&&(window.removeEventListener("message",t),e(i))})),i.addEventListener("beforeunload",(()=>{v=null,i=null,t(new Error("编程猫环境服务连接失败:窗口已被关闭"))})),window.addEventListener("beforeunload",(()=>{var e;null===(e=i)||void 0===e||e.close(),v=null,i=null}))):t(new Error("编程猫环境服务连接失败:窗口为空"))}if("file:"==location.protocol)v=document.createElement("iframe"),v.src="https://coco.codemao.cn/editor/player/255051613?channel=h5",v.style.display="none",document.body.appendChild(v),i(v.contentWindow);else{const e=document.createElement("div");e.innerText="点击打开编程猫环境服务\n打开后请不要关闭编程猫环境服务页面",e.style.width="100%",e.style.height="100%",e.style.fontSize="2em",e.style.position="fixed",e.style.left="0px",e.style.top="0px",e.style.right="0px",e.style.bottom="0px",e.style.backgroundColor="white",e.style.cursor="pointer",e.style.zIndex="10000",e.addEventListener("click",(()=>{i(open("https://coco.codemao.cn/editor/player/255051613?channel=h5")),e.remove()})),document.body.appendChild(e)}}))}const b=new Set;async function _(e){let t;do{t=Math.floor(9e7*Math.random())+1e7}while(b.has(t));return b.add(t),new Promise(((i,r)=>{window.addEventListener("message",(function e(o){const{data:n}=o;null!=n&&"object"==typeof n&&"CODEMAO_ENVIRONMENT_AXIOS_RESULT"==n.type&&n.id==t&&(b.delete(t),window.removeEventListener("message",e),n.success?i(n.response):r(n.error))})),y().then((i=>{i.postMessage({type:"CODEMAO_ENVIRONMENT_AXIOS",id:t,argument:e},"https://coco.codemao.cn")})).catch(r)}))}const E=new Set;class P{constructor(e){l(this,"url",void 0),l(this,"id",void 0),this.url=e;do{this.id=Math.floor(9e7*Math.random())+1e7}while(E.has(this.id));E.add(this.id);const t=e=>{const{data:i}=e;var r;null!=i&&"object"==typeof i&&("CODEMAO_ENVIRONMENT_WEB_SOCKET_OPEN"==i.type&&i.id==this.id&&this.onopen(i.event),"CODEMAO_ENVIRONMENT_WEB_SOCKET_MESSAGE"==i.type&&i.id==this.id&&this.onmessage(i.event),"CODEMAO_ENVIRONMENT_WEB_SOCKET_CLOSE"==i.type&&i.id==this.id&&(this.onclose(i.event),E.delete(this.id),window.removeEventListener("message",t)),"CODEMAO_ENVIRONMENT_WEB_SOCKET_ERROR"==i.type&&i.id==this.id&&this.onerror(null!==(r=i.error)&&void 0!==r?r:i.event))};window.addEventListener("message",t),y().then((t=>{t.postMessage({type:"CODEMAO_ENVIRONMENT_WEB_SOCKET",id:this.id,url:e},"https://coco.codemao.cn")})).catch(this.onerror)}send(e){y().then((t=>{t.postMessage({type:"CODEMAO_ENVIRONMENT_WEB_SOCKET_SEND",id:this.id,data:e},"https://coco.codemao.cn")})).catch(this.onerror)}close(){y().then((e=>{e.postMessage({type:"CODEMAO_ENVIRONMENT_WEB_SOCKET_CLOSE",id:this.id},"https://coco.codemao.cn")})).catch(this.onerror)}onopen(e){}onmessage(e){}onclose(e){}onerror(e){}}const T=(()=>{if(h)return new class{constructor(){l(this,"filePath",void 0),l(this,"store",void 0),this.filePath=Object(function(){var e=new Error("Cannot find module 'path'");throw e.code="MODULE_NOT_FOUND",e}())(f.config,"local-storage.json");try{this.store=JSON.parse(String(Object(function(){var e=new Error("Cannot find module 'fs'");throw e.code="MODULE_NOT_FOUND",e}())(this.filePath)))}catch(e){if(!(e instanceof Error&&"code"in e&&"ENOENT"==e.code))throw e;this.store={}}}save(){(async()=>{(await Promise.resolve().then((function(){var e=new Error("Cannot find module 'fs'");throw e.code="MODULE_NOT_FOUND",e}))).promises.writeFile(this.filePath,JSON.stringify(this.store))})()}get length(){return Object.keys(this.store).length}clear(){this.store={},this.save()}getItem(e){var t;return null!==(t=this.store[e])&&void 0!==t?t:null}key(e){var t;return null!==(t=Object.values(this.store)[e])&&void 0!==t?t:null}removeItem(e){delete this.store[e],this.save()}setItem(e,t){this.store[e]=t,this.save()}};if(d)return localStorage;throw new Error("未知的运行平台")})();async function k(e){const t=await Promise.resolve().then(i.t.bind(i,719,23)),r=h||m?t.default:_;if(h&&e.withCredentials){const t=await p();var o,n,s;if(null!=t)null!==(o=e.headers)&&void 0!==o||(e.headers={}),null!==(s=(n=e.headers)["Cookie"])&&void 0!==s||(n.Cookie=""),e.headers.Cookie+=`Authorization=${t};`}const a=await r(e);let{data:c}=a;if(null!=c&&"object"==typeof c&&"status"in c&&"number"==typeof c.status&&"text"in c&&"string"==typeof c.text&&(c=JSON.parse(c.text)),null!=c&&"object"==typeof c&&"code"in c&&"number"==typeof c.code&&"msg"in c&&"string"==typeof c.msg&&"data"in c){if(200!=c.code)throw new t.AxiosError(c.msg,c.code.toString(),a.config,a.request,a);return c.data}return c}async function O(e){if(h){const t=(await Promise.resolve().then((function(){var e=new Error("Cannot find module 'websocket'");throw e.code="MODULE_NOT_FOUND",e}))).w3cwebsocket,i=await p();return null==i?new t(e):new t(e,void 0,void 0,{Cookie:`Authorization=${i};`})}if(m)return new WebSocket(e);if(d)return new P(e);throw new Error("未知的运行平台")}async function R(){return k({method:"GET",url:"https://api.codemao.cn/coconut/clouddb/currentTime"})}let N=null;async function L(){return null==N&&(N=Math.round(Date.now()/1e3)-await R()),N}async function U(){return Math.round(Date.now()/1e3)-await L()}function j(){var e;let t=null!==(e=T.getItem("sign_uuid"))&&void 0!==e?e:function(e=32,t=a.concat(u)){let i="";for(let r=0;r<e;r++)i+=t[Math.floor(Math.random()*t.length)];return i}(8,a.concat(c));return T.setItem("sign_uuid",t),t}function S(){return j()}async function C(e){var t;let r=await U(),o=S();return null!==(t=e.headers)&&void 0!==t||(e.headers={}),e.headers["X-Creation-Tools-Device-Auth"]=JSON.stringify({sign:(await Promise.resolve().then(i.t.bind(i,846,23))).SHA256("pBlYqXbJDu"+r+o).toString().toLocaleUpperCase(),timestamp:r,client_id:o}),e}async function A(e){return k({method:"GET",url:"https://api.codemao.cn/tiger/v3/web/accounts/profile",withCredentials:!0,headers:null==e?{}:{Cookie:`Authorization=${e}`}})}function I(e){return k({method:"GET",url:"https://api.codemao.cn/web/users/details",withCredentials:!0,headers:null==e?{}:{Cookie:`Authorization=${e}`}})}async function x(e){return(await k({method:"GET",url:`https://api.codemao.cn/api/user/info/detail/${e}`,withCredentials:!0})).userInfo}function D(e){return k({method:"GET",url:`https://api.codemao.cn/creation-tools/v1/user/center/honor?user_id=${e}`})}function M(e){return k({method:"GET",url:`https://api.codemao.cn/creation-tools/v1/works/${e}`})}async function V(e){return(await k({method:"GET",url:`https://api.codemao.cn/api/work/info/${e}`})).workDetail}function $(e){return k({method:"GET",url:`https://api.codemao.cn/creation-tools/v1/works/${e}/source/public`})}function K(e){return k({method:"GET",url:`https://api-creation.codemao.cn/kitten/r2/work/player/load/${e}`})}async function J(e){return k(await C({method:"GET",url:`https://api-creation.codemao.cn/neko/community/player/published-work-detail/${e}`}))}const G=(Promise.any||function(e){return new Promise((function(t,i,r,o){r=[],o=e.map((function(e,n){return Promise.resolve(e).then(t,(function(e){return r[n]=e,--o||i({errors:r})}))})).length}))}).bind(Promise);var W;function H(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class B{static from(e){return e instanceof B?e:B.parse(e)}static parse(e){if("number"==typeof e&&(e=e.toString()),!((e=e.toUpperCase())in F))throw new Error(`无法识别的用户性别:${e}`);return F[e]}constructor(e){H(this,"name",void 0),H(this,"symbol",void 0),this.name=e,this.symbol=Symbol(e)}toString(){return this.name}}H(B,"MALE",new(W=B)("男")),H(B,"FEMALE",new W("女"));const F={1:B.MALE,MALE:B.MALE,0:B.FEMALE,FEMALE:B.FEMALE};var z;function X(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class q{static from(e){return e instanceof q?e:q.parse(e)}static parse(e){if(!(e in Q))throw new Error(`无法识别的创作者勋章:${e}`);return Q[e]}constructor({name:e,shortName:t,color:i,description:r,imageURL:o,shortImageURL:n,iconURL:s}){X(this,"name",void 0),X(this,"shortName",void 0),X(this,"color",void 0),X(this,"description",void 0),X(this,"imageURL",void 0),X(this,"shortImageURL",void 0),X(this,"iconURL",void 0),X(this,"symbol",void 0),this.name=e,this.shortName=null!=t?t:e,this.color=i,this.description=r,this.imageURL=o,this.shortImageURL=n,this.iconURL=s,this.symbol=Symbol(r)}}X(q,"QUASI_CREATOR",new(z=q)({name:"准创作者"})),X(q,"BLOCK_BEGINNER",new z({name:"积木小白",shortName:"小白"})),X(q,"PROMISING_NEW_STAR",new z({name:"⭐ 潜力新星",shortName:"⭐ 新星",color:"#35699F",description:"恭喜你在源码世界中崭露头角\n加油,未来可期",imageURL:"https://cdn-community.codemao.cn/community_frontend/asset/badge1_6c95b.png",shortImageURL:"https://cdn-community.codemao.cn/community_frontend/asset/badge1-lite_7b1a1.png",iconURL:"https://cdn-community.codemao.cn/community_frontend/asset/step_1_a2963.png"})),X(q,"ADVANCED_MASTER",new z({name:"💎 进阶高手",shortName:"💎 高手",color:"#206ACB",description:"领先源码世界90%的创作者\n拥有卓尔不凡的编程水平",imageURL:"https://cdn-community.codemao.cn/community_frontend/asset/badge2_92044.png",shortImageURL:"https://cdn-community.codemao.cn/community_frontend/asset/badge2-lite_ad3f7.png",iconURL:"https://cdn-community.codemao.cn/community_frontend/asset/step_2_ef50a.png"})),X(q,"PROGRAMMING_BIG_SHOT",new z({name:"👑 编程大佬",shortName:"👑 大佬",color:"#DA6627",description:"领先源码世界99%的创作者\n拥有出神入化的编程水平",imageURL:"https://cdn-community.codemao.cn/community_frontend/asset/badge3_09b3a.png",shortImageURL:"https://cdn-community.codemao.cn/community_frontend/asset/dalao_13224.gif",iconURL:"https://cdn-community.codemao.cn/community_frontend/asset/step_3_11280.png"})),X(q,"CODE_LEGEND",new z({name:"👑 源码传说",shortName:"👑 传说",color:"#9F3DCF",description:"源码世界巅峰\n传说级别人物",imageURL:"https://cdn-community.codemao.cn/community_frontend/asset/badge4_3d2da.png",shortImageURL:"https://cdn-community.codemao.cn/community_frontend/asset/chuanshuo_8a57e.gif",iconURL:"https://cdn-community.codemao.cn/community_frontend/asset/step_4_4a172.png"}));const Q={0:q.QUASI_CREATOR,1:q.BLOCK_BEGINNER,2:q.PROMISING_NEW_STAR,3:q.ADVANCED_MASTER,4:q.PROGRAMMING_BIG_SHOT,5:q.CODE_LEGEND};function Y(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var Z,ee=function(e,t,i,r){var o,n=arguments.length,s=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(n<3?o(s):n>3?o(t,i,s):o(t,i))||s);return n>3&&s&&Object.defineProperty(t,i,s),s};class te{get profile(){return(async()=>(null==this.__profile&&(Object.defineProperty(this,"__profile",{value:(async()=>{const e=await A(await this.authorization);return{id:e.id,nickname:e.nickname,avatarURL:e.avatar_url,description:e.description,grade:e.grade,birthday:new Date(1e3*e.birthday)}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__profile)),this.__profile))()}get thisDetail(){return(async()=>(null==this.__thisDetail&&(Object.defineProperty(this,"__thisDetail",{value:(async()=>{const e=await I(await this.authorization);return{id:parseInt(e.id),username:e.username,nickname:e.nickname,realname:e.real_name,avatarURL:e.avatar_url,description:e.description,email:e.email,badge:q.parse(e.author_level),birthday:new Date(1e3*e.birthday),sex:B.from(e.sex)}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__thisDetail)),this.__thisDetail))()}get detail(){return(async()=>(null==this.__detail&&(Object.defineProperty(this,"__detail",{value:(async()=>{const e=await x(await this.id);return{id:e.user.id,nickname:e.user.nickname,avatarURL:e.user.avatar,description:e.user.description,doing:e.user.doing,sex:B.from(e.user.sex),viewTimes:e.viewTimes,praiseTimes:e.praiseTimes,forkTimes:e.forkedTimes}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__detail)),this.__detail))()}get honor(){return(async()=>(null==this.__honor&&(Object.defineProperty(this,"__honor",{value:(async()=>{const e=await D(await this.id);return{id:e.user_id,nickname:e.nickname,avatarURL:e.avatar_url,coverURL:e.user_cover,description:e.user_description,doing:e.doing,badge:q.parse(e.author_level),viewTimes:e.view_times,praiseTimes:e.liked_total,collectTimes:e.collect_times,forkTimes:e.re_created_total}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__honor)),this.__honor))()}get authorization(){return null==this.__authorization&&(this.__authorization=Promise.reject(new Error("没有提供身份信息"))),this.__authorization.catch((e=>Promise.reject(["获取用户身份信息失败",e])))}get id(){return null==this.__id&&(this.__id=G([Promise.reject(new Error("没有提供用户ID")),this.profile.catch((e=>this.thisDetail.catch((t=>Promise.reject([e,t]))))).then((e=>e.id))]).catch((({errors:e})=>Promise.reject(["获取用户ID失败",e[0],...e[1]])))),this.__id}get username(){return null==this.__username&&(this.__username=G([Promise.reject(new Error("没有提供用户名")),this.thisDetail.then((e=>e.username))]).catch((({errors:e})=>Promise.reject(["获取用户名失败",...e])))),this.__username}get nickname(){return null==this.__nickname&&(this.__nickname=G([Promise.reject(new Error("没有提供用户昵称")),this.profile.catch((e=>this.thisDetail.catch((t=>this.detail.catch((i=>this.honor.catch((r=>Promise.reject([e,t,i,r]))))))))).then((e=>e.nickname))]).catch((({errors:e})=>Promise.reject(["获取用户昵称失败",e[0],...e[1]])))),this.__nickname}get realname(){return null==this.__realname&&(this.__realname=G([Promise.reject(new Error("没有提供用户真实姓名")),this.thisDetail.then((e=>e.realname))]).catch((({errors:e})=>Promise.reject(["获取用户真实姓名失败",...e])))),this.__realname}get avatarURL(){return null==this.__avatarURL&&(this.__avatarURL=G([Promise.reject(new Error("没有提供用户头像地址")),this.profile.catch((e=>this.thisDetail.catch((t=>this.detail.catch((i=>this.honor.catch((r=>Promise.reject([e,t,i,r]))))))))).then((e=>e.avatarURL))]).catch((({errors:e})=>Promise.reject(["获取用户头像地址失败",e[0],...e[1]])))),this.__avatarURL}get coverURL(){return null==this.__coverURL&&(this.__coverURL=G([Promise.reject(new Error("没有提供用户背景图片地址")),this.honor.then((e=>e.coverURL))]).catch((({errors:e})=>Promise.reject(["获取用户背景图片地址失败",...e])))),this.__coverURL}get description(){return null==this.__description&&(this.__description=G([Promise.reject(new Error("没有提供用户描述")),this.profile.catch((e=>this.thisDetail.catch((t=>this.detail.catch((i=>this.honor.catch((r=>Promise.reject([e,t,i,r]))))))))).then((e=>e.description))]).catch((({errors:e})=>Promise.reject(["获取用户描述失败",e[0],...e[1]])))),this.__description}get doing(){return null==this.__doing&&(this.__doing=G([Promise.reject(new Error("没有提供用户正在做什么")),this.detail.then((e=>e.doing))]).catch((({errors:e})=>Promise.reject(["获取用户正在做什么失败",...e])))),this.__doing}get email(){return null==this.__email&&(this.__email=G([Promise.reject(new Error("没有提供用户邮箱")),this.thisDetail.then((e=>e.email))]).catch((({errors:e})=>Promise.reject(["获取用户邮箱失败",...e])))),this.__email}get badge(){return null==this.__badge&&(this.__badge=G([Promise.reject(new Error("没有提供用户创作者勋章")),this.thisDetail.catch((e=>this.honor.catch((t=>Promise.reject([e,t]))))).then((e=>e.badge))]).catch((({errors:e})=>Promise.reject(["获取用户创作者勋章",e[0],...e[1]])))),this.__badge}get grade(){return null==this.__grade&&(this.__grade=G([Promise.reject(new Error("没有提供用户等级")),this.profile.then((e=>e.grade))]).catch((({errors:e})=>Promise.reject(["获取用户等级失败",...e])))),this.__grade}get birthday(){return null==this.__birthday&&(this.__birthday=G([Promise.reject(new Error("没有提供用户生日")),this.profile.catch((e=>this.thisDetail.catch((t=>Promise.reject([e,t]))))).then((e=>e.birthday))]).catch((({errors:e})=>Promise.reject(["获取用户生日失败",e[0],...e[1]])))),this.__birthday}get sex(){return null==this.__sex&&(this.__sex=G([Promise.reject(new Error("没有提供用户性别")),this.thisDetail.catch((e=>this.detail.catch((t=>Promise.reject([e,t]))))).then((e=>e.sex))]).catch((({errors:e})=>Promise.reject(["获取用户性别失败",e[0],...e[1]])))),this.__sex}get viewTimes(){return null==this.__viewTimes&&(this.__viewTimes=G([Promise.reject(new Error("没有提供用户被浏览次数")),this.detail.catch((e=>this.honor.catch((t=>Promise.reject([e,t]))))).then((e=>e.viewTimes))]).catch((({errors:e})=>Promise.reject(["获取用户被浏览次数失败",e[0],...e[1]])))),this.__viewTimes}get praiseTimes(){return null==this.__praiseTimes&&(this.__praiseTimes=G([Promise.reject(new Error("没有提供用户被点赞次数")),this.detail.catch((e=>this.honor.catch((t=>Promise.reject([e,t]))))).then((e=>e.praiseTimes))]).catch((({errors:e})=>Promise.reject(["获取用户被点赞次数失败",e[0],...e[1]])))),this.__praiseTimes}get collectTimes(){return null==this.__collectTimes&&(this.__collectTimes=G([Promise.reject(new Error("没有提供用户被收藏次数")),this.honor.then((e=>e.collectTimes))]).catch((({errors:e})=>Promise.reject(["获取用户被收藏次数失败",...e])))),this.__collectTimes}get forkTimes(){return null==this.__forkTimes&&(this.__forkTimes=G([Promise.reject(new Error("没有提供用户被再创作次数")),this.honor.catch((e=>this.detail.catch((t=>Promise.reject([e,t]))))).then((e=>e.forkTimes))]).catch((({errors:e})=>Promise.reject(["获取用户被再创作次数失败",e[0],...e[1]])))),this.__forkTimes}constructor(e){Y(this,"__profile",void 0),Y(this,"__thisDetail",void 0),Y(this,"__detail",void 0),Y(this,"__honor",void 0),Y(this,"__authorization",void 0),Y(this,"__id",void 0),Y(this,"__username",void 0),Y(this,"__nickname",void 0),Y(this,"__realname",void 0),Y(this,"__avatarURL",void 0),Y(this,"__coverURL",void 0),Y(this,"__description",void 0),Y(this,"__doing",void 0),Y(this,"__email",void 0),Y(this,"__badge",void 0),Y(this,"__grade",void 0),Y(this,"__birthday",void 0),Y(this,"__sex",void 0),Y(this,"__viewTimes",void 0),Y(this,"__praiseTimes",void 0),Y(this,"__collectTimes",void 0),Y(this,"__forkTimes",void 0);for(const e in this)e.startsWith("__")&&this[e]==Node&&Object.defineProperty(this,e,{value:void 0,enumerable:!1,configurable:!0});0==Object.keys(e).length?this.__authorization=Promise.resolve(null):this.setCache(e)}setCache(e){for(let t in e){let i=e[t];null!=i&&Object.defineProperty(this,`__${t}`,{value:Promise.resolve(i),enumerable:!1,configurable:!0})}}}function ie(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}ee([s(!0)],te.prototype,"authorization",null),ee([s(!0)],te.prototype,"id",null),ee([s(!0)],te.prototype,"username",null),ee([s(!0)],te.prototype,"nickname",null),ee([s(!0)],te.prototype,"realname",null),ee([s(!0)],te.prototype,"avatarURL",null),ee([s(!0)],te.prototype,"coverURL",null),ee([s(!0)],te.prototype,"description",null),ee([s(!0)],te.prototype,"doing",null),ee([s(!0)],te.prototype,"email",null),ee([s(!0)],te.prototype,"badge",null),ee([s(!0)],te.prototype,"grade",null),ee([s(!0)],te.prototype,"birthday",null),ee([s(!0)],te.prototype,"sex",null),ee([s(!0)],te.prototype,"viewTimes",null),ee([s(!0)],te.prototype,"praiseTimes",null),ee([s(!0)],te.prototype,"collectTimes",null),ee([s(!0)],te.prototype,"forkTimes",null);class re{static async setAuthorization(e){const t=await Promise.resolve().then((function(){var e=new Error("Cannot find module 'path'");throw e.code="MODULE_NOT_FOUND",e})),{mkdir:i,writeFile:r}=(await Promise.resolve().then((function(){var e=new Error("Cannot find module 'fs'");throw e.code="MODULE_NOT_FOUND",e}))).promises,o=(0,(await Promise.resolve().then((function(){var e=new Error("Cannot find module 'appdirsjs'");throw e.code="MODULE_NOT_FOUND",e}))).default)({appName:"SLIGHTNING/Codemao-Community"}).config;await i(o,{recursive:!0}),await r(t.resolve(o,"authorization.txt"),e)}static async userLogInInBrowser(){return m&&location.replace("https://shequ.codemao.cn/mobile/login"),new Promise(((e,t)=>{(async()=>{const t=await y(),i=w();null!=i&&(i.style.width="100%",i.style.height="100%",i.style.display="block",i.style.position="fixed",i.style.left="0px",i.style.top="0px",i.style.right="0px",i.style.bottom="0px",i.style.border="none",i.style.backgroundColor="white",i.style.cursor="pointer",i.style.zIndex="10000"),t.postMessage({type:"CODEMAO_ENVIRONMENT_LOGIN"},"https://coco.codemao.cn"),window.addEventListener("message",(function t(r){const{data:o}=r;null!=o&&"object"==typeof o&&/^https?:\/\/coco\.codemao\.cn$/.test(r.origin)&&"COCO_CODEMAO_API_ENVIRONMENT_SERVER_INIT"==o.type&&(window.removeEventListener("message",t),null!=i&&(i.style.display="none"),e(!0))}))})().catch(t)}))}constructor(e={}){ie(this,"info",void 0),this.info=new te(e)}}function oe(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ne{static from(e){return e instanceof ne?e:ne.parse(e)}static parse(e){if(!((e=e.toUpperCase())in se))throw new Error(`无法识别的作品类型:${e}`);return se[e]}constructor(e,t){oe(this,"name",void 0),oe(this,"code",void 0),oe(this,"symbol",void 0),this.name=e,this.code=t,this.symbol=Symbol(e)}toString(){return this.name}}oe(ne,"NEMO",new(Z=ne)("Nemo","NEMO")),oe(ne,"KITTEN",new Z("Kitten","KITTEN")),oe(ne,"KITTEN_N",new Z("Kitten·N","NEKO")),oe(ne,"KITTENN",Z.KITTEN_N),oe(ne,"NEKO",Z.KITTEN_N),oe(ne,"COCO",new Z("CoCo","COCO"));const se={NEMO:ne.NEMO,KITTEN:ne.KITTEN,KITTEN2:ne.KITTEN,KITTEN3:ne.KITTEN,KITTEN4:ne.KITTEN,NEKO:ne.KITTEN_N,COCO:ne.COCO};function ae(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var ce,ue=function(e,t,i,r){var o,n=arguments.length,s=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(n<3?o(s):n>3?o(t,i,s):o(t,i))||s);return n>3&&s&&Object.defineProperty(t,i,s),s};async function le(e,t){const i={[ne.NEMO.symbol]:{authorization_type:5,stag:2,EIO:3,transport:"websocket"},[ne.KITTEN.symbol]:{authorization_type:1,stag:1,EIO:3,transport:"websocket"},[ne.KITTEN_N.symbol]:{authorization_type:5,stag:3,token:"",EIO:3,transport:"websocket"}},r=await(async()=>{const r="http:"!=window.location.protocol?"wss":"ws",o=["socketcv","codemao","cn"].join("."),n=i[t.symbol];if(null==n)throw new Error(`不支持的作品类型: ${t.name}`);return`${r}://${o}:9096/cloudstorage/?${`session_id=${await e.id}&${Object.entries(n).map((([e,t])=>`${e}=${t}`)).join("&")}`}`})(),o=await O(r);return new Promise(((i,r)=>{o.onopen=()=>{try{o.close()}catch(e){console.error(e)}i({editor:t})},o.onerror=async()=>{r(new Error(`通过云功能连接试探作品 ${await e.id} 编辑器类型为 ${t.name} 失败:WebSocket 出错`))}}))}class he{get workInfo(){return(async()=>(null==this.__workInfo&&(Object.defineProperty(this,"__workInfo",{value:(async()=>{const e=await M(await this.id);return{id:e.id,name:e.work_name,author:new re({id:e.user_info.id,nickname:e.user_info.nickname,avatarURL:e.user_info.avatar,description:e.user_info.description,badge:q.parse(e.user_info.author_level)}),editor:ne.parse(e.type),description:e.description,operationInstruction:e.operation,publishTime:new Date(1e3*e.publish_time),playerURL:e.player_url,shareURL:e.share_url,coverURL:e.preview,previewURL:e.screenshot_cover_url,viewTimes:e.view_times,likeTimes:e.praise_times,collectTimes:e.collect_times,shareTimes:e.share_times,commentTimes:e.comment_times,openResource:e.fork_enable}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__workInfo)),await this.__workInfo))()}get workDetail(){return(async()=>(null==this.__workDetail&&(Object.defineProperty(this,"__workDetail",{value:(async()=>{const{workInfo:e,userInfo:t,qrcodeUrl:i,allowFork:r}=await V(await this.id);return{id:e.id,name:e.name,author:new re({id:t.id,nickname:t.nickname,avatarURL:t.avatar,description:t.description,sex:B.parse(t.sex)}),description:e.description,publishTime:new Date(1e3*e.publish_time),shareURL:i,previewURL:e.preview,viewTimes:e.view_times,likeTimes:e.praise_times,collectTimes:e.collection_times,openResource:Boolean(r)}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__workDetail)),await this.__workDetail))()}get nemoWorkPublicResource(){return(async()=>(null==this.__nemoPublicResource&&(Object.defineProperty(this,"__nemoPublicResource",{value:(async()=>{const e=await $(await this.id);return{id:e.work_id,name:e.name,author:new re({id:e.user.id,nickname:e.user.nickname,avatarURL:e.user.avatar_url}),editor:ne.NEMO,coverURL:e.preview,previewURL:e.preview,viewTimes:e.view_times,likeTimes:e.n_likes}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__nemoPublicResource)),await this.__nemoPublicResource))()}get kittenWorkPublicResource(){return(async()=>(null==this.__kittenPublicResource&&(Object.defineProperty(this,"__kittenPublicResource",{value:(async()=>{const e=await K(await this.id);return{name:e.name,editor:ne.KITTEN,publishTime:new Date(1e3*e.updated_time)}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__kittenPublicResource)),await this.__kittenPublicResource))()}get kitten_NWorkPublicResource(){return(async()=>(null==this.__kittenNPublicResource&&(Object.defineProperty(this,"__kittenNPublicResource",{value:(async()=>{const e=await J(await this.id);return{name:e.name,author:new re({id:parseInt(e.author_id)}),editor:ne.KITTEN_N,publishTime:new Date(1e3*e.update_time),previewURL:e.preview_url}})(),enumerable:!1,configurable:!0}),this.setCache(await this.__kittenNPublicResource)),await this.__kittenNPublicResource))()}get id(){return null==this.__id&&(this.__id=Promise.reject(["获取作品ID失败",new Error("没有提供作品ID")])),this.__id}get name(){return null==this.__name&&(this.__name=G([Promise.reject(new Error("没有提供作品名称")),this.workInfo.catch((e=>this.workDetail.catch((t=>Promise.reject([e,t]))))).catch((e=>G([this.nemoWorkPublicResource,this.kittenWorkPublicResource,this.kitten_NWorkPublicResource]).catch((t=>Promise.reject([...e,...t.errors]))))).then((e=>e.name))]).catch((({errors:e})=>Promise.reject(["获取作品名称失败",e[0],...e[1]])))),this.__name}get author(){return null==this.__author&&(this.__author=G([Promise.reject(new Error("没有提供作品作者")),this.workInfo.catch((e=>this.workDetail.catch((t=>G([this.nemoWorkPublicResource,this.kitten_NWorkPublicResource]).catch((i=>Promise.reject([e,t,...i.errors]))))))).then((e=>e.author))]).catch((({errors:e})=>Promise.reject(["获取作品作者失败",e[0],...e[1]])))),this.__author}get editor(){return null==this.__editor&&(this.__editor=G([Promise.reject(new Error("没有提供作品类型")),this.workInfo.catch((e=>G([this.nemoWorkPublicResource,this.kittenWorkPublicResource,this.kitten_NWorkPublicResource]).catch((t=>G([le(this,ne.NEMO),le(this,ne.KITTEN),le(this,ne.KITTENN)]).catch((i=>Promise.reject([e,...t.errors,...i.errors]))))))).then((e=>e.editor))]).catch((({errors:e})=>Promise.reject(["获取作品类型失败",e[0],...e[1]])))),this.__editor}get description(){return null==this.__description&&(this.__description=G([Promise.reject(new Error("没有提供作品描述")),this.workInfo.catch((e=>this.workDetail.catch((t=>Promise.reject([e,t]))))).then((e=>e.description))]).catch((({errors:e})=>Promise.reject(["获取作品描述失败",e[0],...e[1]])))),this.__description}get operationInstruction(){return null==this.__operationInstruction&&(this.__operationInstruction=G([Promise.reject(new Error("没有提供作品操作说明")),this.workInfo.then((e=>e.operationInstruction))]).catch((({errors:e})=>Promise.reject(["获取作品操作说明失败",...e])))),this.__operationInstruction}get publishTime(){return null==this.__publishTime&&(this.__publishTime=G([Promise.reject(new Error("没有提供作品发布时间")),this.workInfo.catch((e=>G([this.kittenWorkPublicResource,this.kitten_NWorkPublicResource]).catch((t=>Promise.reject([e,...t.errors]))))).then((e=>e.publishTime))]).catch((({errors:e})=>Promise.reject(["获取作品发布时间失败",e[0],...e[1]])))),this.__publishTime}get playerURL(){return null==this.__playerURL&&(this.__playerURL=G([Promise.reject(new Error("没有提供作品运行器地址")),this.workInfo.then((e=>e.playerURL))]).catch((({errors:e})=>Promise.reject(["获取作品运行器地址失败",...e])))),this.__playerURL}get shareURL(){return null==this.__shareURL&&(this.__shareURL=G([Promise.reject(new Error("没有提供作品分享地址")),this.workInfo.catch((e=>this.workDetail.catch((t=>Promise.reject([e,t]))))).then((e=>e.shareURL))]).catch((({errors:e})=>Promise.reject(["获取作品分享地址失败",e[0],...e[1]])))),this.__shareURL}get coverURL(){return null==this.__coverURL&&(this.__coverURL=G([Promise.reject(new Error("没有提供作品封面地址")),this.workInfo.catch((e=>this.nemoWorkPublicResource.catch((t=>Promise.reject([e,t]))))).then((e=>e.coverURL))]).catch((({errors:e})=>Promise.reject(["获取作品封面地址失败",e[0],...e[1]])))),this.__coverURL}get previewURL(){return null==this.__previewURL&&(this.__previewURL=G([Promise.reject(new Error("没有提供作品预览地址")),this.workInfo.catch((e=>this.workDetail.catch((t=>Promise.reject([e,t]))))).catch((e=>G([this.nemoWorkPublicResource,this.kitten_NWorkPublicResource]).catch((t=>Promise.reject([...e,...t.errors]))))).then((e=>e.previewURL))]).catch((({errors:e})=>Promise.reject(["获取作品预览地址失败",e[0],...e[1]])))),this.__previewURL}get viewTimes(){return null==this.__viewTimes&&(this.__viewTimes=G([Promise.reject(new Error("没有提供作品浏览次数")),this.workInfo.catch((e=>this.workDetail.catch((t=>Promise.reject([e,t]))))).catch((e=>this.nemoWorkPublicResource.catch((t=>Promise.reject([...e,t]))))).then((e=>e.viewTimes))]).catch((({errors:e})=>Promise.reject(["获取作品浏览次数失败",e[0],...e[1]])))),this.__viewTimes}get likeTimes(){return null==this.__likeTimes&&(this.__likeTimes=G([Promise.reject(new Error("没有提供作品点赞次数")),this.workInfo.catch((e=>this.workDetail.catch((t=>Promise.reject([e,t]))))).catch((e=>this.nemoWorkPublicResource.catch((t=>Promise.reject([...e,t]))))).then((e=>e.likeTimes))]).catch((({errors:e})=>Promise.reject(["获取作品点赞次数失败",e[0],...e[1]])))),this.__likeTimes}get collectTimes(){return null==this.__collectTimes&&(this.__collectTimes=G([Promise.reject(new Error("没有提供作品收藏次数")),this.workInfo.catch((e=>this.workDetail.catch((t=>Promise.reject([e,t]))))).then((e=>e.collectTimes))]).catch((({errors:e})=>Promise.reject(["获取作品收藏次数失败",e[0],...e[1]])))),this.__collectTimes}get shareTimes(){return null==this.__shareTimes&&(this.__shareTimes=G([Promise.reject(new Error("没有提供作品分享次数")),this.workInfo.then((e=>e.shareTimes))]).catch((({errors:e})=>Promise.reject(["获取作品分享次数失败",...e])))),this.__shareTimes}get commentTimes(){return null==this.__commentTimes&&(this.__commentTimes=G([Promise.reject(new Error("没有提供作品评论次数")),this.workInfo.then((e=>e.commentTimes))]).catch((({errors:e})=>Promise.reject(["获取作品分享次数失败",...e])))),this.__commentTimes}get openResource(){return null==this.__openResource&&(this.__openResource=G([Promise.reject(new Error("没有提供作品开源状态")),this.workInfo.catch((e=>this.workDetail.catch((t=>Promise.reject([e,t]))))).then((e=>e.openResource))]).catch((({errors:e})=>Promise.reject(["获取作品分享次数失败",e[0],...e[1]])))),this.__openResource}constructor(e){ae(this,"__workInfo",void 0),ae(this,"__workDetail",void 0),ae(this,"__nemoPublicResource",void 0),ae(this,"__kittenPublicResource",void 0),ae(this,"__kittenNPublicResource",void 0),ae(this,"__id",void 0),ae(this,"__name",void 0),ae(this,"__author",void 0),ae(this,"__editor",void 0),ae(this,"__description",void 0),ae(this,"__operationInstruction",void 0),ae(this,"__publishTime",void 0),ae(this,"__playerURL",void 0),ae(this,"__shareURL",void 0),ae(this,"__coverURL",void 0),ae(this,"__previewURL",void 0),ae(this,"__viewTimes",void 0),ae(this,"__likeTimes",void 0),ae(this,"__collectTimes",void 0),ae(this,"__shareTimes",void 0),ae(this,"__commentTimes",void 0),ae(this,"__openResource",void 0);for(const e in this)e.startsWith("__")&&this[e]==Node&&Object.defineProperty(this,e,{value:void 0,enumerable:!1,configurable:!0});this.setCache(e)}async setCache(e){for(let t in e){let i=e[t];if(null!=i)if(i instanceof re){null==this.__author&&(this.__author=Promise.resolve(new re));const e={};for(const t in i.info)if(`__${t}`in i.info)try{e[t]=await i.info[`__${t}`]}catch(e){console.error(e)}(await this.__author).info.setCache(e)}else Object.defineProperty(this,`__${t}`,{value:Promise.resolve(i),enumerable:!1,configurable:!0})}}}function de(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}ue([s(!1)],he.prototype,"workInfo",null),ue([s(!1)],he.prototype,"workDetail",null),ue([s(!1)],he.prototype,"nemoWorkPublicResource",null),ue([s(!1)],he.prototype,"kittenWorkPublicResource",null),ue([s(!1)],he.prototype,"kitten_NWorkPublicResource",null),ue([s(!0)],he.prototype,"id",null),ue([s(!0)],he.prototype,"name",null),ue([s(!0)],he.prototype,"author",null),ue([s(!0)],he.prototype,"editor",null),ue([s(!0)],he.prototype,"description",null),ue([s(!0)],he.prototype,"operationInstruction",null),ue([s(!0)],he.prototype,"publishTime",null),ue([s(!0)],he.prototype,"playerURL",null),ue([s(!0)],he.prototype,"shareURL",null),ue([s(!0)],he.prototype,"coverURL",null),ue([s(!0)],he.prototype,"previewURL",null),ue([s(!0)],he.prototype,"viewTimes",null),ue([s(!0)],he.prototype,"likeTimes",null),ue([s(!0)],he.prototype,"collectTimes",null),ue([s(!0)],he.prototype,"shareTimes",null),ue([s(!0)],he.prototype,"commentTimes",null),ue([s(!0)],he.prototype,"openResource",null);class me{constructor(e){de(this,"info",void 0),this.info=new he(e)}}function fe(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class pe{constructor(){fe(this,"slots",void 0),this.slots=[]}connect(e){this.slots.push(e)}disconnect(e){const t=this.slots.indexOf(e);t>=0&&this.slots.splice(t,1)}clear(){this.slots=[]}isEmpty(){return 0==this.slots.length}emit(e){this.slots.slice().forEach((t=>{t(e)}))}wait(e=0){return new Promise(((t,i)=>{const r=e=>{this.disconnect(r),t(e)};this.connect(r),e>0&&setTimeout((()=>{this.disconnect(r),i(new Error("Timeout"))}),e)}))}}function ve(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ge{constructor(e){ve(this,"value",void 0),ve(this,"changed",void 0),this.value=e,this.changed=new pe}update({total:e}){const t=this.value,i=e;this.value=i,this.changed.emit({originalNumber:t,newNumber:i})}}function we(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ye{constructor(e){var t,i,r,o;we(this,"socket",void 0),we(this,"url",void 0),we(this,"beforeSend",void 0),we(this,"sended",void 0),we(this,"opened",void 0),we(this,"received",void 0),we(this,"errored",void 0),we(this,"closed",void 0),this.url=e.url,this.socket=e,this.beforeSend=new pe,this.sended=new pe,this.opened=new pe,this.received=new pe,this.errored=new pe,this.closed=new pe;const n=this.socket.send,s=null!==(t=this.socket.onopen)&&void 0!==t?t:()=>{},a=null!==(i=this.socket.onmessage)&&void 0!==i?i:()=>{},c=null!==(r=this.socket.onerror)&&void 0!==r?r:()=>{},u=null!==(o=this.socket.onclose)&&void 0!==o?o:()=>{};this.socket.send=e=>{const t={data:e};this.beforeSend.emit(t),n.call(this.socket,t.data),this.sended.emit(t.data)},this.socket.onopen=e=>{s.call(this.socket,e),this.opened.emit(e)},this.socket.onmessage=e=>{a.call(this.socket,e),this.received.emit(e)},this.socket.onerror=e=>{c.call(this.socket,e),this.errored.emit(e)},this.socket.onclose=e=>{u.call(this.socket,e),this.closed.emit(e)}}send(e){this.socket.send(e)}close(){this.socket.close()}}function be(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}!function(e){e[e.UPGRADE=0]="UPGRADE",e[e.ERROR=1]="ERROR",e[e.PING=2]="PING",e[e.PONG=3]="PONG",e[e.CONNECT=40]="CONNECT",e[e.CLOSE=41]="CLOSE",e[e.MESSAGE=42]="MESSAGE"}(ce||(ce={}));const _e={[ne.NEMO.symbol]:{authorization_type:5,stag:2,EIO:3,transport:"websocket"},[ne.KITTEN.symbol]:{authorization_type:1,stag:1,EIO:3,transport:"websocket"},[ne.KITTEN_N.symbol]:{authorization_type:5,stag:3,token:"",EIO:3,transport:"websocket"}};class Ee{constructor(e){var t;(be(this,"work",void 0),be(this,"socket",void 0),be(this,"manage",void 0),be(this,"autoReconnect",!0),be(this,"autoReconnectIntervalTime",8e3),be(this,"isOpened",!1),be(this,"socketResolve",o),be(this,"beforeSend",new pe),be(this,"sended",void 0),be(this,"opened",void 0),be(this,"disconnected",void 0),be(this,"received",void 0),be(this,"errored",void 0),be(this,"closed",void 0),be(this,"pingHandler",void 0),be(this,"pingHandlerArray",void 0),this.manage=e instanceof me,this.beforeSend=new pe,this.sended=new pe,this.opened=new pe,this.disconnected=new pe,this.received=new pe,this.errored=new pe,this.closed=new pe,this.pingHandlerArray=[],e instanceof me)?this.work=e:this.work=new me({id:parseInt(null!==(t=new URL(e.url).searchParams.get("session_id"))&&void 0!==t?t:"0")});this.setSocket(e)}changeWebSocket(e){this.setSocket(e)}setSocket(e){this.socket=this.getSocket(e),this.socketResolve!=o&&(this.socketResolve(this.socket),this.socketResolve=o),this.socket.then((e=>{e.beforeSend.connect((e=>{this.beforeSend.emit(e)})),e.sended.connect((e=>{this.sended.emit(e)})),e.received.connect((e=>{this.handleReceived(e.data)})),e.errored.connect((e=>{this.errored.emit(e)})),e.closed.connect((e=>{this.handleClose(e)}))})).catch((e=>{this.errored.emit(e)}))}async getSocket(e){if("string"==typeof e)return new ye(await O(e));if(e instanceof me){const t=await(async()=>{const t="http:"!=window.location.protocol?"wss":"ws",i=["socketcv","codemao","cn"].join("."),r=_e[(await e.info.editor).symbol];if(r==o)throw new Error(`不支持的作品类型: ${(await e.info.editor).name}`);return`${t}://${i}:9096/cloudstorage/?${`session_id=${await e.info.id}&${Object.entries(r).map((([e,t])=>`${e}=${t}`)).join("&")}`}`})();return new ye(await O(t))}return e instanceof WebSocket?new ye(e):e}handleReceived(e){try{var t,i;const r=parseInt(null!==(t=null===(i=/^[0-9]+/.exec(e))||void 0===i?void 0:i[0])&&void 0!==t?t:"-1"),n=e.length==r.toString().length?o:JSON.parse(e.slice(r.toString().length));if(!this.manage&&r!=ce.MESSAGE)return;switch(r){case ce.UPGRADE:if(n==o)throw new Error("升级数据为空");if("object"!=typeof n||!("pingInterval"in n)||!("pingTimeout"in n)||"number"!=typeof n.pingInterval||"number"!=typeof n.pingTimeout)throw new Error("无法识别的升级数据格式");this.startPing(n.pingInterval,n.pingTimeout);break;case ce.ERROR:this.handleServerError();break;case ce.PONG:clearTimeout(this.pingHandlerArray.shift());break;case ce.CONNECT:this.opened.emit();break;case ce.CLOSE:this.handleServerClose();break;case ce.MESSAGE:if(n==o)throw new Error("消息数据为空");if(!Array.isArray(n)||2!=n.length||"string"!=typeof n[0])throw new Error("无法识别的消息格式");if("string"==typeof n[1])try{n[1]=JSON.parse(n[1])}catch(e){}this.received.emit(n);break;default:throw new Error(`未知消息类型: ${r}`)}}catch(e){this.errored.emit(e)}}startPing(e,t){this.pingHandler!=o&&this.stopPing(),this.pingHandlerArray=[],this.pingHandler=setInterval((()=>{this.socket.then((e=>{e.send(ce.PING.toString()),this.pingHandlerArray.push(setTimeout((()=>{this.clientErrorClose(new Error("保活超时"))}),t))}))}),e)}stopPing(){this.pingHandler!=o&&clearInterval(this.pingHandler);for(const e of this.pingHandlerArray)clearTimeout(e)}send(e){this.socket.then((t=>{"string"!=typeof e&&(e=JSON.stringify(e)),t.send(`${ce.MESSAGE.toString()}${e}`)})).catch((e=>{this.errored.emit(e)}))}handleClose(e){if(this.disconnected.emit(),this.isOpened&&this.autoReconnect)if(this.isOpened=!1,this.manage){let e;this.socket.then((t=>{e=t.url})),this.socket=new Promise((t=>{setTimeout((()=>{this.socketResolve=t,this.setSocket(e)}),this.autoReconnectIntervalTime)}))}else this.socket=new Promise(((t,i)=>{this.socketResolve=t,setTimeout((()=>{this.closed.emit(e),i(new Error("重连等待超时"))}))}));else this.closed.emit(e)}handleServerError(){this.errored.emit(new Error("服务器错误")),this.socket.then((e=>{try{e.close()}catch(e){}}))}clientErrorClose(e){this.errored.emit(e),this.socket.then((e=>{e.send(ce.ERROR.toString()),e.close()}))}handleServerClose(){this.socket.then((e=>{try{e.close()}catch(e){}}))}close(){this.socket.then((e=>{e.send(ce.CLOSE.toString()),this.isOpened=!1,e.close()})).catch((e=>{this.errored.emit(e)}))}}function Pe(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class Te{get config(){return this.store}set config(e){const t=this.getValue();this.store=e;const i=this.getValue();t!=i&&(this.cache=i,this.changed.emit({originalValue:t,newValue:i}))}get value(){return this.cache}set value(e){this.config=e}getValue(){return this.store!=o?this.store:this.upper instanceof Te?this.upper.value:this.upper}constructor(e,t){Pe(this,"upper",void 0),Pe(this,"store",void 0),Pe(this,"cache",void 0),Pe(this,"changed",new pe),this.upper=e,this.store=t,this.cache=this.getValue(),e instanceof Te&&e.changed.connect((t=>{this.store==o&&(this.cache=e.value,this.changed.emit(t))}))}}function ke(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class Oe{constructor(e=null,{autoReconnectIntervalTime:t,localPreupdate:i,cacheTime:r,uploadIntervalTime:o,uploadTimeout:n,stringLengthLimit:s,listLengthLimit:a}={}){var c,u,l,h,d,m,f,p,v,g,w,y,b,_;ke(this,"autoReconnectIntervalTime",void 0),ke(this,"localPreupdate",void 0),ke(this,"cacheTime",void 0),ke(this,"uploadIntervalTime",void 0),ke(this,"uploadTimeout",void 0),ke(this,"stringLengthLimit",void 0),ke(this,"listLengthLimit",void 0),this.autoReconnectIntervalTime=new Te(null!==(c=null!==(u=null==e?void 0:e.autoReconnectIntervalTime)&&void 0!==u?u:t)&&void 0!==c?c:8e3,t),this.localPreupdate=new Te(null===(l=null!==(h=null==e?void 0:e.localPreupdate)&&void 0!==h?h:i)||void 0===l||l,i),this.cacheTime=new Te(null!==(d=null!==(m=null==e?void 0:e.cacheTime)&&void 0!==m?m:r)&&void 0!==d?d:0,r),this.uploadIntervalTime=new Te(null!==(f=null!==(p=null==e?void 0:e.uploadIntervalTime)&&void 0!==p?p:o)&&void 0!==f?f:0,o),this.uploadTimeout=new Te(null!==(v=null!==(g=null==e?void 0:e.uploadTimeout)&&void 0!==g?g:n)&&void 0!==v?v:4e3,n),this.stringLengthLimit=new Te(null!==(w=null!==(y=null==e?void 0:e.stringLengthLimit)&&void 0!==y?y:s)&&void 0!==w?w:1024,s),this.listLengthLimit=new Te(null!==(b=null!==(_=null==e?void 0:e.listLengthLimit)&&void 0!==_?_:a)&&void 0!==b?b:1e3,a)}}var Re,Ne,Le,Ue;function je(e,t,i){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")