pin-diary
code:example.ts
import { launch } from "jsr:@takker/pin-diary@0.1";
launch("motoso", { project: "motoso", title: "pin-diary%2Ftemplate" });
code:script.js
var ts=Object.defineProperty;var rs=(e,t)=>{for(var r in t)ts(e,r,{get:tr,enumerable:!0})};function we(e){return Array.isArray(e)}function z(e){return typeof e=="string"}var zt=(e,t)=>{if(!(e instanceof HTMLDivElement))throw new TypeError("${t}" must be HTMLDivElememt but actual is "${e}")};var Vt=()=>os(document.getElementsByClassName("status-bar")?.0,"div.status-bar"),os=(e,t)=>{if(e)return zt(e,t),e};function te(e,t={}){let{signal:r,persistent:o=!0}=t;return r?.aborted?Promise.reject(r.reason):new Promise((n,s)=>{let i=()=>{clearTimeout(c),s(r?.reason)},c=setTimeout(()=>{r?.removeEventListener("abort",i),n()},e);if(r?.addEventListener("abort",i,{once:!0}),o===!1)try{Deno.unrefTimer(c)}catch(u){if(!(u instanceof ReferenceError))throw u;console.error("persistent option is only available in Deno")}})}var Qt=()=>{let e=Vt();if(!e)throw new Error("div.status-bar can't be found");let t=document.createElement("div");return e.append(t),{render:(...r)=>{t.textContent="";let o=Xt(...r);o&&t.append(o)},dispose:()=>t.remove()}},Xt=(...e)=>{let t=e.flatMap(o=>{switch(o.type){case"spinner":returnus();case"check-circle":returnls();case"exclamation-triangle":returnfs();case"text":returnPe(o.text);case"group":{let n=Xt(...o.items);return n?n:[]}}});if(t.length===0)return;if(t.length===1)return t0;let r=document.createElement("span");return r.classList.add("item-group"),r.append(...t),r},Pe=e=>{let t=document.createElement("span");return t.classList.add("item"),t.append(e),t},us=()=>{let e=document.createElement("i");return e.classList.add("fa","fa-spinner"),Pe(e)},ls=()=>{let e=document.createElement("i");return e.classList.add("kamon","kamon-check-circle"),Pe(e)},fs=()=>{let e=document.createElement("i");return e.classList.add("fas","fa-exclamation-triangle"),Pe(e)};var K=e=>e.replaceAll(" ","_").toLowerCase();var re=e=>...e.map((t,r)=>t===" "?"_":!ds.includes(t)||r===e.length-1&&ms.includes(t)?encodeURIComponent(t):t).join(""),ds='@$&+=:;",',ms=':;",';var tt={};rs(tt,{Decoder:()=>Ns,Encoder:()=>Ts,PacketType:()=>h,protocol:()=>er});function A(e){if(e)return gs(e)}function gs(e){for(var t in A.prototype)et=A.prototypet;return e}A.prototype.on=A.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks"$"+e=this._callbacks"$"+e||[]).push(t),this};A.prototype.once=function(e,t){function r(){this.off(e,r),t.apply(this,arguments)}return r.fn=t,this.on(e,r),this};A.prototype.off=A.prototype.removeListener=A.prototype.removeAllListeners=A.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var r=this._callbacks"$"+e;if(!r)return this;if(arguments.length==1)return delete this._callbacks"$"+e,this;for(var o,n=0;n<r.length;n++)if(o=rn,o===t||o.fn===t){r.splice(n,1);break}return r.length===0&&delete this._callbacks"$"+e,this};A.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),r=this._callbacks"$"+e,o=1;o<arguments.length;o++)to-1=argumentso;if(r){r=r.slice(0);for(var o=0,n=r.length;o<n;++o)ro.apply(this,t)}return this};A.prototype.emitReserved=A.prototype.emit;A.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks"$"+e||[]};A.prototype.hasListeners=function(e){return!!this.listeners(e).length};var ys=typeof ArrayBuffer=="function",xs=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,Zt=Object.prototype.toString,Es=typeof Blob=="function"||typeof Blob<"u"&&Zt.call(Blob)==="object BlobConstructor",bs=typeof File=="function"||typeof File<"u"&&Zt.call(File)==="object FileConstructor";function et(e){return ys&&(e instanceof ArrayBuffer||xs(e))||Es&&e instanceof Blob||bs&&e instanceof File}function Te(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let r=0,o=e.length;r<o;r++)if(Te(er))return!0;return!1}if(et(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return Te(e.toJSON(),!0);for(let r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&Te(er))return!0;return!1}function ws(e){let t=[],r=e.data,o=e;return o.data=Je(r,t),o.attachments=t.length,{packet:o,buffers:t}}function Je(e,t){if(!e)return e;if(et(e)){let r={_placeholder:!0,num:t.length};return t.push(e),r}else if(Array.isArray(e)){let r=new Array(e.length);for(let o=0;o<e.length;o++)ro=Je(eo,t);return r}else if(typeof e=="object"&&!(e instanceof Date)){let r={};for(let o in e)Object.prototype.hasOwnProperty.call(e,o)&&(ro=Je(eo,t));return r}return e}function ks(e,t){return e.data=Ze(e.data,t),delete e.attachments,e}function Ze(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num=="number"&&e.num>=0&&e.num<t.length)return te.num;throw new Error("illegal attachments")}else if(Array.isArray(e))for(let r=0;r<e.length;r++)er=Ze(er,t);else if(typeof e=="object")for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(er=Ze(er,t));return e}var Ps="connect","connect_error","disconnect","disconnecting","newListener","removeListener",er=5,h;(function(e){ee.CONNECT=0="CONNECT",ee.DISCONNECT=1="DISCONNECT",ee.EVENT=2="EVENT",ee.ACK=3="ACK",ee.CONNECT_ERROR=4="CONNECT_ERROR",ee.BINARY_EVENT=5="BINARY_EVENT",ee.BINARY_ACK=6="BINARY_ACK"})(h||(h={}));var Ts=class{constructor(e){this.replacer=e}encode(e){return(e.type===h.EVENT||e.type===h.ACK)&&Te(e)?this.encodeAsBinary({type:e.type===h.EVENT?h.BINARY_EVENT:h.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):this.encodeAsString(e)}encodeAsString(e){let t=""+e.type;return(e.type===h.BINARY_EVENT||e.type===h.BINARY_ACK)&&(t+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(t+=e.nsp+","),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){let t=ws(e),r=this.encodeAsString(t.packet),o=t.buffers;return o.unshift(r),o}};function Jt(e){return Object.prototype.toString.call(e)==="object Object"}var Ns=class tr extends A{constructor(t){super(),this.reviver=t}add(t){let r;if(typeof t=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");r=this.decodeString(t);let o=r.type===h.BINARY_EVENT;o||r.type===h.BINARY_ACK?(r.type=o?h.EVENT:h.ACK,this.reconstructor=new Rs(r),r.attachments===0&&super.emitReserved("decoded",r)):super.emitReserved("decoded",r)}else if(et(t)||t.base64)if(this.reconstructor)r=this.reconstructor.takeBinaryData(t),r&&(this.reconstructor=null,super.emitReserved("decoded",r));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+t)}decodeString(t){let r=0,o={type:Number(t.charAt(0))};if(ho.type===void 0)throw new Error("unknown packet type "+o.type);if(o.type===h.BINARY_EVENT||o.type===h.BINARY_ACK){let s=r+1;for(;t.charAt(++r)!=="-"&&r!=t.length;);let i=t.substring(s,r);if(i!=Number(i)||t.charAt(r)!=="-")throw new Error("Illegal attachments");o.attachments=Number(i)}if(t.charAt(r+1)==="/"){let s=r+1;for(;++r&&!(t.charAt(r)===","||r===t.length););o.nsp=t.substring(s,r)}else o.nsp="/";let n=t.charAt(r+1);if(n!==""&&Number(n)==n){let s=r+1;for(;++r;){let i=t.charAt(r);if(i==null||Number(i)!=i){--r;break}if(r===t.length)break}o.id=Number(t.substring(s,r+1))}if(t.charAt(++r)){let s=this.tryParse(t.substr(r));if(tr.isPayloadValid(o.type,s))o.data=s;else throw new Error("invalid payload")}return o}tryParse(t){try{return JSON.parse(t,this.reviver)}catch{return!1}}static isPayloadValid(t,r){switch(t){case h.CONNECT:return Jt(r);case h.DISCONNECT:return r===void 0;case h.CONNECT_ERROR:return typeof r=="string"||Jt(r);case h.EVENT:case h.BINARY_EVENT:return Array.isArray(r)&&(typeof r0=="number"||typeof r0=="string"&&Ps.indexOf(r0)===-1);case h.ACK:case h.BINARY_ACK:return Array.isArray(r)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}},Rs=class{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){let t=ks(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};var G=Object.create(null);G.open="0";G.close="1";G.ping="2";G.pong="3";G.message="4";G.upgrade="5";G.noop="6";var ve=Object.create(null);Object.keys(G).forEach(e=>{ve[Ge]=e});var nt={type:"error",data:"parser error"},sr=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="object BlobConstructor",ir=typeof ArrayBuffer=="function",ar=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,Le=({type:e,data:t},r,o)=>sr&&t instanceof Blob?r?o(t):rr(t,o):ir&&(t instanceof ArrayBuffer||ar(t))?r?o(t):rr(new Blob(t),o):o(Ge+(t||"")),rr=(e,t)=>{let r=new FileReader;return r.onload=function(){let o=r.result.split(",")1;t("b"+(o||""))},r.readAsDataURL(e)};function or(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var rt;function vs(e,t){if(sr&&e.data instanceof Blob)return e.data.arrayBuffer().then(or).then(t);if(ir&&(e.data instanceof ArrayBuffer||ar(e.data)))return t(or(e.data));Le(e,!1,r=>{rt||(rt=new TextEncoder),t(rt.encode(r))})}var nr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",le=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e<nr.length;e++)lenr.charCodeAt(e)=e;var Ls=e=>{let t=e.length*.75,r=e.length,o,n=0,s,i,a,c;ee.length-1==="="&&(t--,ee.length-2==="="&&t--);let u=new ArrayBuffer(t),l=new Uint8Array(u);for(o=0;o<r;o+=4)s=lee.charCodeAt(o),i=lee.charCodeAt(o+1),a=lee.charCodeAt(o+2),c=lee.charCodeAt(o+3),ln++=s<<2|i>>4,ln++=(i&15)<<4|a>>2,ln++=(a&3)<<6|c&63;return u},Cs=typeof ArrayBuffer=="function",Ce=(e,t)=>{if(typeof e!="string")return{type:"message",data:cr(e,t)};let r=e.charAt(0);return r==="b"?{type:"message",data:Is(e.substring(1),t)}:ver?e.length>1?{type:ver,data:e.substring(1)}:{type:ver}:nt},Is=(e,t)=>{if(Cs){let r=Ls(e);return cr(r,t)}else return{base64:!0,data:e}},cr=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob(e);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},pr="",ur=(e,t)=>{let r=e.length,o=new Array(r),n=0;e.forEach((s,i)=>{Le(s,!1,a=>{oi=a,++n===r&&t(o.join(pr))})})},lr=(e,t)=>{let r=e.split(pr),o=[];for(let n=0;n<r.length;n++){let s=Ce(rn,t);if(o.push(s),s.type==="error")break}return o};function fr(){return new TransformStream({transform(e,t){vs(e,r=>{let o=r.length,n;if(o<126)n=new Uint8Array(1),new DataView(n.buffer).setUint8(0,o);else if(o<65536){n=new Uint8Array(3);let s=new DataView(n.buffer);s.setUint8(0,126),s.setUint16(1,o)}else{n=new Uint8Array(9);let s=new DataView(n.buffer);s.setUint8(0,127),s.setBigUint64(1,BigInt(o))}e.data&&typeof e.data!="string"&&(n0|=128),t.enqueue(n),t.enqueue(r)})}})}var ot;function Ne(e){return e.reduce((t,r)=>t+r.length,0)}function Re(e,t){if(e0.length===t)return e.shift();let r=new Uint8Array(t),o=0;for(let n=0;n<t;n++)rn=e0o++,o===e0.length&&(e.shift(),o=0);return e.length&&o<e0.length&&(e0=e0.slice(o)),r}function dr(e,t){ot||(ot=new TextDecoder);let r=[],o=0,n=-1,s=!1;return new TransformStream({transform(i,a){for(r.push(i);;){if(o===0){if(Ne(r)<1)break;let c=Re(r,1);s=(c0&128)===128,n=c0&127,n<126?o=3:n===126?o=1:o=2}else if(o===1){if(Ne(r)<2)break;let c=Re(r,2);n=new DataView(c.buffer,c.byteOffset,c.length).getUint16(0),o=3}else if(o===2){if(Ne(r)<8)break;let c=Re(r,8),u=new DataView(c.buffer,c.byteOffset,c.length),l=u.getUint32(0);if(l>Math.pow(2,21)-1){a.enqueue(nt);break}n=l*Math.pow(2,32)+u.getUint32(4),o=3}else{if(Ne(r)<n)break;let c=Re(r,n);a.enqueue(Ce(s?c:ot.decode(c),t)),o=0}if(n===0||n>e){a.enqueue(nt);break}}}})}var st=4;function k(e){if(e)return Os(e)}function Os(e){for(var t in k.prototype)et=k.prototypet;return e}k.prototype.on=k.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks"$"+e=this._callbacks"$"+e||[]).push(t),this};k.prototype.once=function(e,t){function r(){this.off(e,r),t.apply(this,arguments)}return r.fn=t,this.on(e,r),this};k.prototype.off=k.prototype.removeListener=k.prototype.removeAllListeners=k.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var r=this._callbacks"$"+e;if(!r)return this;if(arguments.length==1)return delete this._callbacks"$"+e,this;for(var o,n=0;n<r.length;n++)if(o=rn,o===t||o.fn===t){r.splice(n,1);break}return r.length===0&&delete this._callbacks"$"+e,this};k.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),r=this._callbacks"$"+e,o=1;o<arguments.length;o++)to-1=argumentso;if(r){r=r.slice(0);for(var o=0,n=r.length;o<n;++o)ro.apply(this,t)}return this};k.prototype.emitReserved=k.prototype.emit;k.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks"$"+e||[]};k.prototype.hasListeners=function(e){return!!this.listeners(e).length};var fe=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,t)=>t(e,0),H=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),Ss="arraybuffer";function hr(e,...t){return t.reduce((r,o)=>(e.hasOwnProperty(o)&&(ro=eo),r),{})}var As=H.setTimeout,Fs=H.clearTimeout;function de(e,t){t.useNativeTimers?(e.setTimeoutFn=As.bind(H),e.clearTimeoutFn=Fs.bind(H)):(e.setTimeoutFn=H.setTimeout.bind(H),e.clearTimeoutFn=H.clearTimeout.bind(H))}var Ms=1.33;function _s(e){return typeof e=="string"?Ds(e):Math.ceil((e.byteLength||e.size)*Ms)}function Ds(e){let t=0,r=0;for(let o=0,n=e.length;o<n;o++)t=e.charCodeAt(o),t<128?r+=1:t<2048?r+=2:t<55296||t>=57344?r+=3:(o++,r+=4);return r}function gr(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Bs(e){let t="";for(let r in e)e.hasOwnProperty(r)&&(t.length&&(t+="&"),t+=encodeURIComponent(r)+"="+encodeURIComponent(er));return t}function Hs(e){let t={},r=e.split("&");for(let o=0,n=r.length;o<n;o++){let s=ro.split("=");t[decodeURIComponent(s0)]=decodeURIComponent(s1)}return t}var js=class extends Error{constructor(e,t,r){super(e),this.description=t,this.context=r,this.type="TransportError"}},ct=class extends k{constructor(e){super(),this.writable=!1,de(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,r){return super.emitReserved("error",new js(e,t,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){let t=Ce(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(":")===-1?e:""+e+""}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){let t=Bs(e);return t.length?"?"+t:""}},$s=class extends ct{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(e){this.readyState="pausing";let t=()=>{this.readyState="paused",e()};if(this._polling||!this.writable){let r=0;this._polling&&(r++,this.once("pollComplete",function(){--r||t()})),this.writable||(r++,this.once("drain",function(){--r||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){let t=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};lr(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){let e=()=>{this.write({type:"close"})};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,ur(e,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==!1&&(tthis.opts.timestampParam=gr()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}},yr=!1;try{yr=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var Us=yr;function qs(){}var Ks=class extends $s{constructor(e){if(super(e),typeof location<"u"){let t=location.protocol==="https:",r=location.port;r||(r=t?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||r!==e.port}}doWrite(e,t){let r=this.request({method:"POST",data:e});r.on("success",t),r.on("error",(o,n)=>{this.onError("xhr post error",o,n)})}doPoll(){let e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,r)=>{this.onError("xhr poll error",t,r)}),this.pollXhr=e}},ie=class Ie extends k{constructor(t,r,o){super(),this.createRequest=t,de(this,o),this._opts=o,this._method=o.method||"GET",this._uri=r,this._data=o.data!==void 0?o.data:null,this._create()}_create(){var t;let r=hr(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");r.xdomain=!!this._opts.xd;let o=this._xhr=this.createRequest(r);try{o.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){o.setDisableHeaderCheck&&o.setDisableHeaderCheck(!0);for(let n in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(n)&&o.setRequestHeader(n,this._opts.extraHeadersn)}}catch{}if(this._method==="POST")try{o.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{o.setRequestHeader("Accept","*/*")}catch{}(t=this._opts.cookieJar)===null||t===void 0||t.addCookies(o),"withCredentials"in o&&(o.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(o.timeout=this._opts.requestTimeout),o.onreadystatechange=()=>{var n;o.readyState===3&&((n=this._opts.cookieJar)===null||n===void 0||n.parseCookies(o.getResponseHeader("set-cookie"))),o.readyState===4&&(o.status===200||o.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof o.status=="number"?o.status:0)},0))},o.send(this._data)}catch(n){this.setTimeoutFn(()=>{this._onError(n)},0);return}typeof document<"u"&&(this._index=Ie.requestsCount++,Ie.requeststhis._index=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=qs,t)try{this._xhr.abort()}catch{}typeof document<"u"&&delete Ie.requeststhis._index,this._xhr=null}}_onLoad(){let t=this._xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};ie.requestsCount=0;ie.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",mr);else if(typeof addEventListener=="function"){let e="onpagehide"in H?"pagehide":"unload";addEventListener(e,mr,!1)}}function mr(){for(let e in ie.requests)ie.requests.hasOwnProperty(e)&&ie.requestse.abort()}var Gs=function(){let e=xr({xdomain:!1});return e&&e.responseType!==null}(),pt=class extends Ks{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Gs&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new ie(xr,this.uri(),e)}};function xr(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!t||Us))return new XMLHttpRequest}catch{}if(!t)try{return new H["Active".concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}var Er=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",Ws=class extends ct{get name(){return"websocket"}doOpen(){let e=this.uri(),t=this.opts.protocols,r=Er?{}:hr(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,r)}catch(o){return this.emitReserved("error",o)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let r=et,o=t===e.length-1;Le(r,this.supportsBinary,n=>{try{this.doWrite(r,n)}catch{}o&&fe(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){let e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(tthis.opts.timestampParam=gr()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},it=H.WebSocket||H.MozWebSocket,ut=class extends Ws{createSocket(e,t,r){return Er?new it(e,t,r):t?new it(e,t):new it(e)}doWrite(e,t){this.ws.send(t)}},br=class extends ct{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptionsthis.name)}catch(e){return this.emitReserved("error",e)}this._transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(e=>{let t=dr(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=e.readable.pipeThrough(t).getReader(),o=fr();o.readable.pipeTo(e.writable),this._writer=o.writable.getWriter();let n=()=>{r.read().then(({done:i,value:a})=>{i||(this.onPacket(a),n())}).catch(i=>{})};n();let s={type:"open"};this.query.sid&&(s.data={"sid":"${this.query.sid}"}),this._writer.write(s).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let r=et,o=t===e.length-1;this._writer.write(r).then(()=>{o&&fe(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close()}},Ys={websocket:ut,webtransport:br,polling:pt},zs=/^(?:(?!^:@\/?#+:^:@\/*@)(http|https|ws|wss):\/\/)?((?:((^:@\/?#*)(?::(^:@\/?#*))?)?@)?((?:a-f0-9{0,4}:){2,7}a-f0-9{0,4}|^:\/?#*)(?::(\d*))?)(((\/(?:^?#(?!^?#\/*\.^?#\/.+(?:?#|$)))*\/?)?(^?#\/*))(?:\?(^#*))?(?:#(.*))?)/,Vs="source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor";function Fe(e){if(e.length>8e3)throw"URI too long";let t=e,r=e.indexOf(""),o=e.indexOf("");r!=-1&&o!=-1&&(e=e.substring(0,r)+e.substring(r,o).replace(/:/g,";")+e.substring(o,e.length));let n=zs.exec(e||""),s={},i=14;for(;i--;)s[Vsi]=ni||"";return r!=-1&&o!=-1&&(s.source=t,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("","").replace("","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=Qs(s,s.path),s.queryKey=Xs(s,s.query),s}function Qs(e,t){let r=/\/{2,9}/g,o=t.replace(r,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&o.splice(0,1),t.slice(-1)=="/"&&o.splice(o.length-1,1),o}function Xs(e,t){let r={};return t.replace(/(?:^|&)(^&=*)=?(^&*)/g,function(o,n,s){n&&(rn=s)}),r}var at=typeof addEventListener=="function"&&typeof removeEventListener=="function",Oe=[];at&&addEventListener("offline",()=>{Oe.forEach(e=>e())},!1);var Se=class Ae extends k{constructor(t,r){if(super(),this.binaryType=Ss,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&typeof t=="object"&&(r=t,t=null),t){let o=Fe(t);r.hostname=o.host,r.secure=o.protocol==="https"||o.protocol==="wss",r.port=o.port,o.query&&(r.query=o.query)}else r.host&&(r.hostname=Fe(r.host).host);de(this,r),this.secure=r.secure!=null?r.secure:typeof location<"u"&&location.protocol==="https:",r.hostname&&!r.port&&(r.port=this.secure?"443":"80"),this.hostname=r.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=r.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},r.transports.forEach(o=>{let n=o.prototype.name;this.transports.push(n),this._transportsByNamen=o}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},r),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Hs(this.opts.query)),at&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},Oe.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){let r=Object.assign({},this.opts.query);r.EIO=st,r.transport=t,this.id&&(r.sid=this.id);let o=Object.assign({},this.opts,{query:r,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptionst);return new this._transportsByNamet(o)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let t=this.opts.rememberUpgrade&&Ae.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports0;this.readyState="opening";let r=this.createTransport(t);r.open(),this.setTransport(r)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",r=>this._onClose("transport close",r))}onOpen(){this.readyState="open",Ae.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let r=new Error("server error");r.code=t.data,this._onError(r);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data);break}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){let t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let r=0;r<this.writeBuffer.length;r++){let o=this.writeBufferr.data;if(o&&(t+=_s(o)),r>0&&t>this._maxPayload)return this.writeBuffer.slice(0,r);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,fe(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,r,o){return this._sendPacket("message",t,r,o),this}send(t,r,o){return this._sendPacket("message",t,r,o),this}_sendPacket(t,r,o,n){if(typeof r=="function"&&(n=r,r=void 0),typeof o=="function"&&(n=o,o=null),this.readyState==="closing"||this.readyState==="closed")return;o=o||{},o.compress=o.compress!==!1;let s={type:t,data:r,options:o};this.emitReserved("packetCreate",s),this.writeBuffer.push(s),n&&this.once("flush",n),this.flush()}close(){let t=()=>{this._onClose("forced close"),this.transport.close()},r=()=>{this.off("upgrade",r),this.off("upgradeError",r),t()},o=()=>{this.once("upgrade",r),this.once("upgradeError",r)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?o():t()}):this.upgrading?o():t()),this}_onError(t){if(Ae.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,r){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),at&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let o=Oe.indexOf(this._offlineEventListener);o!==-1&&Oe.splice(o,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,r),this.writeBuffer=[],this._prevBufferLen=0}}};Se.protocol=st;var Js=class extends Se{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgradese)}_probe(e){let t=this.createTransport(e),r=!1;Se.priorWebsocketSuccess=!1;let o=()=>{r||(t.send({type:"ping",data:"probe"}),t.once("packet",l=>{if(!r)if(l.type==="pong"&&l.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;Se.priorWebsocketSuccess=t.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(u(),this.setTransport(t),t.send({type:"upgrade"}),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{let d=new Error("probe error");d.transport=t.name,this.emitReserved("upgradeError",d)}}))};function n(){r||(r=!0,u(),t.close(),t=null)}let s=l=>{let d=new Error("probe error: "+l);d.transport=t.name,n(),this.emitReserved("upgradeError",d)};function i(){s("transport closed")}function a(){s("socket closed")}function c(l){t&&l.name!==t.name&&n()}let u=()=>{t.removeListener("open",o),t.removeListener("error",s),t.removeListener("close",i),this.off("close",a),this.off("upgrading",c)};t.once("open",o),t.once("error",s),t.once("close",i),this.once("close",a),this.once("upgrading",c),this._upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{r||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){let t=[];for(let r=0;r<e.length;r++)~this.transports.indexOf(er)&&t.push(er);return t}},lt=class extends Js{constructor(e,t={}){let r=typeof e=="object"?e:t;(!r.transports||r.transports&&typeof r.transports0=="string")&&(r.transports=(r.transports||"polling","websocket","webtransport").map(o=>Yso).filter(o=>!!o)),super(e,r)}};var Df=lt.protocol;function Zs(e,t="",r){let o=e;r=r||typeof location<"u"&&location,e==null&&(e=r.protocol+"//"+r.host),typeof e=="string"&&(e.charAt(0)==="/"&&(e.charAt(1)==="/"?e=r.protocol+e:e=r.host+e),/^(https?|wss?):\/\//.test(e)||(typeof r<"u"?e=r.protocol+"//"+e:e="https://"+e),o=Fe(e)),o.port||(/^(http|ws)$/.test(o.protocol)?o.port="80":/^(http|ws)s$/.test(o.protocol)&&(o.port="443")),o.path=o.path||"/";let n=o.host.indexOf(":")!==-1?""+o.host+"":o.host;return o.id=o.protocol+"://"+n+":"+o.port+t,o.href=o.protocol+"://"+n+(r&&r.port===o.port?"":":"+o.port),o}function q(e,t,r){return e.on(t,r),function(){e.off(t,r)}}var ei=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),wr=class extends k{constructor(e,t,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let e=this.io;this.subs=q(e,"open",this.onopen.bind(this)),q(e,"packet",this.onpacket.bind(this)),q(e,"error",this.onerror.bind(this)),q(e,"close",this.onclose.bind(this))}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){var r,o,n;if(ei.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;let s={type:h.EVENT,data:t};if(s.options={},s.options.compress=this.flags.compress!==!1,typeof tt.length-1=="function"){let c=this.ids++,u=t.pop();this._registerAckCallback(c,u),s.id=c}let i=(o=(r=this.io.engine)===null||r===void 0?void 0:r.transport)===null||o===void 0?void 0:o.writable,a=this.connected&&!(!((n=this.io.engine)===null||n===void 0)&&n._hasPingExpired());return this.flags.volatile&&!i||(a?(this.notifyOutgoingListeners(s),this.packet(s)):this.sendBuffer.push(s)),this.flags={},this}_registerAckCallback(e,t){var r;let o=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(o===void 0){this.ackse=t;return}let n=this.io.setTimeoutFn(()=>{delete this.ackse;for(let i=0;i<this.sendBuffer.length;i++)this.sendBufferi.id===e&&this.sendBuffer.splice(i,1);t.call(this,new Error("operation has timed out"))},o),s=(...i)=>{this.io.clearTimeoutFn(n),t.apply(this,i)};s.withError=!0,this.ackse=s}emitWithAck(e,...t){return new Promise((r,o)=>{let n=(s,i)=>s?o(s):r(i);n.withError=!0,t.push(n),this.emit(e,...t)})}_addToQueue(e){let t;typeof ee.length-1=="function"&&(t=e.pop());let r={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((o,...n)=>r!==this._queue0?void 0:(o!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(o)):(this._queue.shift(),t&&t(null,...n)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;let t=this._queue0;t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:h.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(e=>{if(!this.sendBuffer.some(t=>String(t.id)===e)){let t=this.ackse;delete this.ackse,t.withError&&t.call(this,new Error("socket has been disconnected"))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case h.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case h.EVENT:case h.BINARY_EVENT:this.onevent(e);break;case h.ACK:case h.BINARY_ACK:this.onack(e);break;case h.DISCONNECT:this.ondisconnect();break;case h.CONNECT_ERROR:this.destroy();let t=new Error(e.data.message);t.data=e.data.data,this.emitReserved("connect_error",t);break}}onevent(e){let t=e.data||[];e.id!=null&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){let t=this._anyListeners.slice();for(let r of t)r.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof ee.length-1=="string"&&(this._lastOffset=ee.length-1)}ack(e){let t=this,r=!1;return function(...o){r||(r=!0,t.packet({type:h.ACK,id:e,data:o}))}}onack(e){let t=this.ackse.id;typeof t=="function"&&(delete this.ackse.id,t.withError&&e.data.unshift(null),t.apply(this,e.data))}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:h.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){let t=this._anyListeners;for(let r=0;r<t.length;r++)if(e===tr)return t.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){let t=this._anyOutgoingListeners;for(let r=0;r<t.length;r++)if(e===tr)return t.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let t=this._anyOutgoingListeners.slice();for(let r of t)r.apply(this,e.data)}}};function ce(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}ce.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),r=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+r:e-r}return Math.min(e,this.max)|0};ce.prototype.reset=function(){this.attempts=0};ce.prototype.setMin=function(e){this.ms=e};ce.prototype.setMax=function(e){this.max=e};ce.prototype.setJitter=function(e){this.jitter=e};var ft=class extends k{constructor(e,t){var r;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.opts=t,de(this,t),this.reconnection(t.reconnection!==!1),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor((r=t.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new ce({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState="closed",this.uri=e;let o=t.parser||tt;this.encoder=new o.Encoder,this.decoder=new o.Decoder,this._autoConnect=t.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,e||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(t=this.backoff)===null||t===void 0||t.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)===null||t===void 0||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)===null||t===void 0||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new lt(this.uri,this.opts);let t=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;let o=q(t,"open",function(){r.onopen(),e&&e()}),n=i=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",i),e?e(i):this.maybeReconnectOnOpen()},s=q(t,"error",n);if(this._timeout!==!1){let i=this._timeout,a=this.setTimeoutFn(()=>{o(),n(new Error("timeout")),t.close()},i);this.opts.autoUnref&&a.unref(),this.subs.push(()=>{this.clearTimeoutFn(a)})}return this.subs.push(o),this.subs.push(s),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");let e=this.engine;this.subs.push(q(e,"ping",this.onping.bind(this)),q(e,"data",this.ondata.bind(this)),q(e,"error",this.onerror.bind(this)),q(e,"close",this.onclose.bind(this)),q(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(t){this.onclose("parse error",t)}}ondecoded(e){fe(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let r=this.nspse;return r?this._autoConnect&&!r.active&&r.connect():(r=new wr(this,e,t),this.nspse=r),r}_destroy(e){let t=Object.keys(this.nsps);for(let r of t)if(this.nspsr.active)return;this._close()}_packet(e){let t=this.encoder.encode(e);for(let r=0;r<t.length;r++)this.engine.write(tr,e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(e,t){var r;this.cleanup(),(r=this.engine)===null||r===void 0||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let t=this.backoff.duration();this._reconnecting=!0;let r=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(o=>{o?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",o)):e.onreconnect()}))},t);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){let e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}},me={};function ae(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};let r=Zs(e,t.path||"/socket.io"),o=r.source,n=r.id,s=r.path,i=men&&s in men.nsps,a=t.forceNew||t"force new connection"||t.multiplex===!1||i,c;return a?c=new ft(o,t):(men||(men=new ft(o,t)),c=men),r.query&&!t.query&&(t.query=r.queryKey),c.socket(r.path,t)}Object.assign(ae,{Manager:ft,Socket:wr,io:ae,connect:ae});var kr=" must not return ",ti="transformer",ri="recoverer",oi="defaultValue",fd=ti+kr,Pr="called with ",dd=oi+" must not be ",md=ri+kr,ni="Ok",Tr="Err",si=Pr+Tr,ii=Pr+ni,hd="Carrying E in "+Tr+" instead of throwing it directly. See .cause",dt="an instance of Error of the current realm.",gd="The thrown value is not "+dt,yd="The contained E should be "+dt,xd="This .cause is not "+dt;function Me(e){return e.ok}function E(e){return{ok:!0,val:e,err:null}}function x(e){return!e.ok}function R(e){return{ok:!1,val:null,err:e}}function b(e){return ai(e,si)}function mt(e){return ci(e,ii)}function ai(e,t){if(x(e))throw new TypeError(t);return e.val}function ci(e,t){if(Me(e))throw new TypeError(t);return e.err}function ht(e){return e.val}function pi(e){return e.err}async function gt(e,t){if(x(e))return e;let r=ht(e);return await t(r)}function _e(e,t){if(x(e))return e;let r=ht(e),o=t(r);return E(o)}async function v(e,t){if(x(e))return e;let r=ht(e),o=await t(r);return E(o)}async function I(e,t){if(Me(e))return e;let r=pi(e),o=await t(r);return R(o)}var De=e=>{if(e?.connected)return Promise.resolve(E(e));e??=ae("https://scrapbox.io",{reconnectionDelay:5e3,transports:["websocket"]});let t=new Promise(r=>{let o=n=>r(R(n));e.once("connect",()=>{e.off("disconnect",o),r(E(e))}),e.once("disconnect",o)});return e.connect(),t},he=e=>{if(e.disconnected)return Promise.resolve(E(void 0));let t=new Promise(r=>{let o=n=>{if(n!=="io client disconnect"){r(R(n));return}r(E(void 0)),e.off("disconnect",o)};e.on("disconnect",o)});return e.disconnect(),t};var Nr=e=>ui.includes(e.name),ui="SocketIOError","DuplicateTitleError","NotFastForwardError";var Rr=(e,t,r,o)=>{if(t==="cursor")return e.emit(t,r),Promise.resolve(E(void 0));let{resolve:n,promise:s,reject:i}=Promise.withResolvers(),a=()=>{e.off("disconnect",c),clearTimeout(l)},c=m=>{if(m==="io client disconnect"){a(),i(new Error("io client disconnect"));return}if(m==="io server disconnect"){a(),n(R({name:"SocketIOError"}));return}};e.on("disconnect",c);let u=o?.timeout??9e4,l=setTimeout(()=>{a(),n(R({name:"TimeoutError",message:exceeded ${u} (ms)}))},u),d=t==="commit"?{method:"commit",data:r}:{method:"room:join",data:r};return e.emit("socket.io-request",d,m=>{if(a(),"error"in m){n(R(Nr(m.error)?m.error:{name:"UnexpectedRequestError",...m}));return}n(E(m.data))}),s};var L=e=>e.ok?E(e):R({name:"HTTPError",message:${e.status} ${e.statusText},response:e});var vr=async(e,t)=>{let r=new Request(e,t);try{return E(await globalThis.fetch(r))}catch(o){if(o instanceof DOMException&&o.name==="AbortError")return R({name:"AbortError",message:o.message,request:r});if(o instanceof TypeError)return R({name:"NetworkError",message:o.message,request:r});throw o}};var P=e=>{let{fetch:t=vr,hostName:r="scrapbox.io",...o}=e;return{fetch:t,hostName:r,...o}};var Lr=e=>{let{sid:t,hostName:r}=P(e??{});return new Request(https://${r}/api/users/me,t?{headers:{Cookie:C(t)}}:void 0)},Cr=e=>v(L(e),async t=>await t.json()),yt=(()=>{let e=async t=>{let{fetch:r,...o}=P(t??{}),n=await r(Lr(o));return x(n)?n:Cr(b(n))};return e.toRequest=Lr,e.fromResponse=Cr,e})();var C=e=>connect.sid=${e};function Be(e,t={}){if(e===null)return"null";if(Array.isArray(e))return li(e,t);switch(typeof e){case"string":return JSON.stringify(e);case"bigint":return${e}n;case"object":return e.constructor?.name!=="Object"?e.constructor?.name:fi(e,t);case"function":return e.name||"(anonymous)"}return e?.toString()??"undefined"}function li(e,t){let{threshold:r=20}=t,o=e.map(i=>Be(i,t)),n=o.join(", ");if(n.length<=r)return[${n}];let s=o.join(`, );return[
${Ir(2,s)}
]}function fi(e,t){let{threshold:r=20}=t,o=[...Object.keys(e),...Object.getOwnPropertySymbols(e)].map(i=>${i.toString()}: ${Be(ei,t)}),n=o.join(", ");if(n.length<=r)return{${n}};let s=o.join(, );return{
${Ir(2,s)}
}}function Ir(e,t){let r=" ".repeat(e);return t.split(
).map(o=>${r}${o}).join(
)}function He(e,t,...r){let o;return Object.defineProperties(e,{name:{get:()=>o||(o=${t}(${r.map(n=>Be(n)).join(", ")}),o)}})}function Or(e){return He(t=>we(t)&&t.every(r=>e(r)),"isArrayOf",e)}function xt(e){let t=new Set(e);return He(r=>t.has(r),"isLiteralOneOf",e)}function Et(e){return e!=null&&!Array.isArray(e)&&typeof e=="object"}var F=async(e,t)=>{let r=e.response.clone(),o=xt(t);try{let n=await r.json();if(!Et(n))return;if(r.status===422){if(!z(n.message))return;for(let s of["NoQueryError","InvalidURLError"])if(t.includes(s))return{name:s,message:n.message}}return!o(n.name)||!z(n.message)?void 0:n.name==="NotLoggedInError"?!Et(n.detals)||!z(n.detals.project)||!Or(di)(n.detals.loginStrategies)?void 0:{name:n.name,message:n.message,details:{project:n.detals.project,loginStrategies:n.detals.loginStrategies}}:{name:n.name,message:n.message}}catch(n){if(n instanceof SyntaxError)return;throw n}},di=xt(["google","github","microsoft","gyazo","email","saml","easy-trial"]);var Sr=" must not return ",mi="transformer",hi="recoverer",gi="defaultValue",yi=mi+Sr,xi="called with ",Ei=gi+" must not be ",bi=hi+Sr,je="null or undefined",om=yi+je,nm=xi+je,wi=Ei+je,sm=bi+je;function Ar(e){return e!=null}function ki(e,t){if(Ar(e))return e;throw new TypeError(t)}function bt(e,t){return Ar(e)?e:ki(t,wi)}var Fr=(e,t,r)=>{let{sid:o,hostName:n,followRename:s,projects:i}=P(r??{}),a=new URLSearchParams([["followRename",${s??!0}],...i?.map?.(c=>["projects",c])??[]]);return new Request(https://${n}/api/pages/${e}/${re(t)}?${a},o?{headers:{Cookie:C(o)}}:void 0)},Mr=async e=>I(await v(L(e),t=>t.json()),async t=>t.response.status===414?{name:"TooLongURIError",message:"project ids may be too much."}:bt(await F(t,["NotFoundError","NotLoggedInError","NotMemberError"]),t)),Br=(()=>{let e=async(t,r,o)=>gt(await P(o??{}).fetch(Fr(t,r,o)),n=>Mr(n));return e.toRequest=Fr,e.fromResponse=Mr,e})(),_r=(e,t)=>{let{sid:r,hostName:o,sort:n,limit:s,skip:i}=P(t??{}),a=new URLSearchParams;return n!==void 0&&a.append("sort",n),s!==void 0&&a.append("limit",${s}),i!==void 0&&a.append("skip",${i}),new Request(https://${o}/api/pages/${e}?${a},r?{headers:{Cookie:C(r)}}:void 0)},Dr=async e=>I(await v(L(e),t=>t.json()),async t=>bt(await F(t,["NotFoundError","NotLoggedInError","NotMemberError"]),t)),Hr=(()=>{let e=async(t,r)=>gt(await P(r??{})?.fetch(_r(t,r)),Dr);return e.toRequest=_r,e.fromResponse=Dr,e})();var jr=(e,t)=>{let{sid:r,hostName:o}=P(t??{});return new Request(https://${o}/api/projects/${e},r?{headers:{Cookie:C(r)}}:void 0)},$r=async e=>v(await I(L(e),async t=>await F(t,["NotFoundError","NotLoggedInError","NotMemberError"])??t),t=>t.json()),Ur=(()=>{let e=async(t,r)=>{let{fetch:o}=P(r??{}),n=jr(t,r),s=await o(n);return x(s)?s:$r(b(s))};return e.toRequest=jr,e.fromResponse=$r,e})();var kt=async(e,t,r)=>{let[o,n,s]=await Promise.all([Br(e,t,r),Pi(r),Ti(e,r)]);return x(o)?o:x(n)?n:x(s)?s:E({...b(o),projectId:b(s),userId:b(n)})},wt,Pi=async e=>{if(wt)return E(wt);let t=await yt(e);if(x(t))return t;let r=b(t);return"id"in r?(wt=r.id,E(r.id)):R({name:"NotLoggedInError",message:"This script cannot be used without login"})},qr=new Map,Ti=async(e,t)=>{let r=qr.get(e);return r?E(r):_e(await Ur(e,t),({id:o})=>(qr.set(e,o),o))};var Q=async(e,t,r,o)=>{let n=await De(o?.socket);if(x(n))return R({name:"UnexpectedRequestError",error:mt(n)});let s=b(n),i=await kt(e,t);if(x(i))return i;let a=b(i);try{let c=0,u=[],l;for(;o?.maxAttempts===void 0||c<o.maxAttempts;){let d=r(a,c,u,l);if(u=d instanceof Promise?await d:d,c++,u.length===0)return E(a.commitId);let m={kind:"page",projectId:a.projectId,pageId:a.id,parentId:a.commitId,userId:a.userId,changes:u,cursor:null,freeze:!0};for(;;){let w=await Rr(s,"commit",m);if(Me(w))return a.commitId=b(w).commitId,E(a.commitId);let f=mt(w),p=f.name;if(p==="SocketIOServerDisconnectError"||p==="UnexpectedRequestError")return R(f);if(p==="TimeoutError"||p==="SocketIOError"){await te(3e3);continue}if(p==="NotFastForwardError"){await te(1e3);let N=await kt(e,t);if(x(N))return N;a=b(N)}l=p;break}}return R({name:"RetryError",attempts:c,message:Retrying exceeded the maxAttempts (${c}).})}finally{o?.socket||await he(s)}};var Pt=(e,t)=>{let r=e.length>t.length,o=r?t:e,n=r?e:t,s=o.length+1,i=o.length+n.length+3,a=new Array(i);a.fill(-1);let c=[];function u(p,N,S){let M=Math.max(N,S),be=M-p;for(;be<o.length&&M<n.length&&o[be]===n[M];)++be,++M;return a[p+s]=c.length,c.push([{x:be,y:M},a[p+(N>S?-1:1)+s]]),M}let l=new Array(i);l.fill(-1);let d=-1,m=n.length-o.length;do{++d;for(let p=-d;p<=m-1;++p)l[p+s]=u(p,l[p-1+s]+1,l[p+1+s]);for(let p=m+d;p>=m+1;--p)l[p+s]=u(p,l[p-1+s]+1,l[p+1+s]);l[m+s]=u(m,l[m-1+s]+1,l[m+1+s])}while(l[m+s]!==n.length);let w=[],f=a[m+s];for(;f!==-1;)w.push(c[f][0]),f=c[f][1];return{from:e,to:t,editDistance:m+d*2,buildSES:function*(){let p=0,N=0;for(let{x:S,y:M}of Ni(w))for(;p<S||N<M;)M-S>N-p?(yield{value:n[N],type:r?"deleted":"added"},++N):M-S<N-p?(yield{value:o[p],type:r?"added":"deleted"},++p):(yield{value:o[p],type:"common"},++p,++N)}}};function*Tt(e){let t=[],r=[];function*o(){if(t.length>r.length){for(let n=0;n<r.length;n++)yield Kr(t[n],r[n]);for(let n=r.length;n<t.length;n++)yield t[n]}else{for(let n=0;n<t.length;n++)yield Kr(t[n],r[n]);for(let n=t.length;n<r.length;n++)yield r[n]}t=[],r=[]}for(let n of e)switch(n.type){case"added":t.push(n);break;case"deleted":r.push(n);break;case"common":yield*o(),yield n;break}yield*o()}var Kr=(e,t)=>({value:e.value,oldValue:t.value,type:"replaced"});function*Ni(e){for(let t=e.length-1;t>=0;t--)yield e[t]}var Gr=e=>e.padStart(8,"0"),Nt=e=>{let t=Math.floor(new Date().getTime()/1e3).toString(16),r=Math.floor(16777214*Math.random()).toString(16);return${Gr(t).slice(-8)}${e.slice(-6)}0000${Gr(r)}};function*Rt(e,t,{userId:r}){let{buildSES:o}=Pt(e.map(({text:i})=>i),t),n=0,s=e[0].id;for(let i of Tt(o())){switch(i.type){case"added":yield{_insert:s,lines:{id:Nt(r),text:i.value}};continue;case"deleted":yield{_delete:s,lines:-1};break;case"replaced":yield{_update:s,lines:{text:i.value}};break}n++,s=e[n]?.id??"_end"}}var Ri=(e,t)=>(e.type==="codeBlock"||e.type==="table")&&t.indent>(e.rows[0]?.indent??0),Wr=(e,t)=>{let r=e[e.length-1];return r!==void 0&&Ri(r,t)?(r.rows.push(t),e):(e.push({type:/^\s*code:/.test(t.text)?"codeBlock":/^\s*table:/.test(t.text)?"table":"line",rows:[t]}),e)},Yr=(e,t)=>{if(t.hasTitle??!0){let[r,...o]=e;return r===void 0?[]:[{type:"title",rows:[r]},...o.reduce(Wr,[])]}return e.reduce(Wr,[])};var zr=e=>e.split( ).map(t=>({indent:/^\s+/.exec(t)?.[0]?.length??0,text:t}));var Vr=e=>{let{rows:[t,...r]}=e,{indent:o=0,text:n=""}=t??{},s=n.replace(/^\s*code:/,"");return{indent:o,type:"codeBlock",fileName:s,content:r.map(i=>i.text.substring(o+1)).join(
)}};var g=(e,{parseOnNested:t,parseOnQuoted:r,patterns:o})=>(n,s,i)=>{if(!t&&s.nested)return i?.()??[];if(!r&&s.quoted)return i?.()??[];for(let a of o){let c=a.exec(n);if(c===null)continue;let u=n.substring(0,c.index),l=n.substring(c.index+(c[0]?.length??0)),d=e(c[0]??"",s);return[..._(u,s),...d,..._(l,s)]}return i?.()??[]};var y=e=>[{type:"plain",raw:e,text:e}],Qr=g(y,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]});var vi=/\[\s+\]/,Li=(e,t)=>t.context==="table"?y(e,t):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],Xr=g(Li,{parseOnNested:!1,parseOnQuoted:!0,patterns:[vi]});var Ci=/.*?/,Ii=(e,t)=>t.context==="table"?y(e,t):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],Jr=g(Ii,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ci]});var Oi=/^[$%] .+$/,Si=(e,t)=>{if(t.context==="table")return y(e,t);let r=e[0]??"",o=e.substring(2);return[{type:"commandLine",raw:e,symbol:r,text:o}]},Zr=g(Si,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Oi]});var Ai=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,Fi=(e,t)=>{if(t.context==="table")return y(e,t);let r=e.indexOf(" "),o=e.substring(1,r),n=e.substring(r+1,e.length-1),s=new Set(o);if(s.has("*")){let i=o.split("*").length-1;s.delete("*"),s.add(*-${Math.min(i,10)})}return[{type:"decoration",raw:e,rawDecos:o,decos:Array.from(s),nodes:_(n,{...t,nested:!0})}]},eo=g(Fi,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ai]});var Mi=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,_i=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,Di=/\[https?:\/\/[^\s\]]+\]/,Bi=/https?:\/\/[^\s]+/,Hi=(e,t)=>{if(t.context==="table")return y(e,t);let r=e.startsWith("[")&&e.endsWith("]")?e.substring(1,e.length-1):e,o=/^https?:\/\/[^\s\]]/.test(r),n=(o?/^https?:\/\/[^\s\]]+/:/https?:\/\/[^\s\]]+$/).exec(r);if(n?.[0]===void 0)return[];let s=o?r.substring(n[0].length):r.substring(0,n.index-1);return[{type:"link",raw:e,pathType:"absolute",href:n[0],content:s.trim()}]},to=g(Hi,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Mi,_i,Di,Bi]});var ji=/\[\$ .+? \]/,$i=/\[\$ [^\]]+\]/,Ui=(e,t)=>t.context==="table"?y(e,t):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],ro=g(Ui,{parseOnNested:!1,parseOnQuoted:!0,patterns:[ji,$i]});var oo=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,no=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,qi=e=>{let[t="",r="",o=""]=e.split(","),n=Number.parseFloat(t.replace(/^N/,"").replace(/^S/,"-")),s=Number.parseFloat(r.replace(/^E/,"").replace(/^W/,"-")),i=/^Z\d+$/.test(o)?Number.parseInt(o.replace(/^Z/,""),10):14;return{latitude:n,longitude:s,zoom:i}},Ki=(e,t)=>{if(t.context==="table")return y(e,t);let r=e.match(oo)??e.match(no);if(r===null)return[];let o=e.startsWith("[N")||e.startsWith("[S"),[,n="",s=""]=o?r:[r[0],r[2],r[1]],{latitude:i,longitude:a,zoom:c}=qi(n),u=s!==""?https://www.google.com/maps/place/${encodeURIComponent(s)}/@${i},${a},${c}z:https://www.google.com/maps/@${i},${a},${c}z;return[{type:"googleMap",raw:e,latitude:i,longitude:a,zoom:c,place:s,url:u}]},so=g(Ki,{parseOnNested:!1,parseOnQuoted:!0,patterns:[oo,no]});var Gi=/(?:^|\s)#\S+/,Wi=(e,t)=>{if(t.context==="table")return y(e,t);if(e.startsWith("#"))return[{type:"hashTag",raw:e,href:e.substring(1)}];let r=e.substring(0,1),o=e.substring(1);return[...y(r,t),{type:"hashTag",raw:o,href:o.substring(1)}]},io=g(Wi,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Gi]});var Yi=/^\? .+$/,zi=(e,t)=>t.context==="table"?y(e,t):[{type:"helpfeel",raw:e,text:e.substring(2)}],ao=g(zi,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Yi]});var Vi=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/,Qi=e=>{let t=e.substring(1,e.length-1),r=t.lastIndexOf(".icon"),o=t.substring(0,r),n=o.startsWith("/")?"root":"relative",s=t.substring(r+5,t.length),i=s.startsWith("*")?Number.parseInt(s.substring(1),10):1;return new Array(i).fill({}).map(()=>({path:o,pathType:n,type:"icon",raw:e}))},co=g(Qi,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Vi]});var Xi=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg|webp)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,Ji=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg|webp)(?:\?[^\]\s]+)?\]/i,Zi=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,ea=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,ta=e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg|webp)(\?[^\]\s]+)?$/i.test(e)||ra(e),ra=e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),oa=(e,t)=>{if(t.context==="table")return y(e,t);let r=e.search(/\s/),o=r!==-1?e.substring(1,r):e.substring(1,e.length-1),n=r!==-1?e.substring(r,e.length-1).replace(/^\s+/,""):"",[s,i]=ta(n)?[n,o]:[o,n];return[{type:"image",raw:e,src:/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(s)?${s}/thumb/1000:s,link:i}]},po=g(oa,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Xi,Ji,Zi,ea]});var na=/\[\/?[^[\]]+\]/,sa=e=>{let t=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:t.startsWith("/")?"root":"relative",href:t,content:""}]},uo=g(sa,{parseOnNested:!0,parseOnQuoted:!0,patterns:[na]});var ia=/^[0-9]+\. .*$/,aa=(e,t)=>{if(t.context==="table")return y(e,t);let r=e.indexOf(" "),o=e.substring(0,r-1),n=Number.parseInt(o,10),s=e.substring(r+1,e.length);return[{type:"numberList",raw:e,rawNumber:o,number:n,nodes:_(s,{...t,nested:!1})}]},lo=g(aa,{parseOnNested:!1,parseOnQuoted:!1,patterns:[ia]});var ca=/^>.*$/,pa=(e,t)=>t.context==="table"?y(e,t):[{type:"quote",raw:e,nodes:_(e.substring(1),{...t,quoted:!0})}],fo=g(pa,{parseOnNested:!1,parseOnQuoted:!1,patterns:[ca]});var ua=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,la=(e,t)=>{if(t.context==="table")return y(e,t);let r=e.substring(2,e.length-2),o=r.lastIndexOf(".icon"),n=r.substring(0,o),s=n.startsWith("/")?"root":"relative",i=r.substring(o+5,r.length),a=i.startsWith("*")?Number.parseInt(i.substring(1),10):1;return new Array(a).fill({}).map(()=>({path:n,pathType:s,type:"strongIcon",raw:e}))},mo=g(la,{parseOnNested:!1,parseOnQuoted:!0,patterns:[ua]});var fa=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg|webp)\]\]/i,da=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,ma=(e,t)=>{if(t.context==="table")return y(e,t);let r=e.substring(2,e.length-2),o=/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(r);return[{type:"strongImage",raw:e,src:o?${r}/thumb/1000:r}]},ho=g(ma,{parseOnNested:!1,parseOnQuoted:!0,patterns:[fa,da]});var ha=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,ga=(e,t)=>t.context==="table"?y(e,t):[{type:"strong",raw:e,nodes:_(e.substring(2,e.length-2),{...t,nested:!0})}],go=g(ga,{parseOnNested:!1,parseOnQuoted:!0,patterns:[ha]});var ya=(e,t,r)=>e===""?[]:r?.()??[],xa=(...e)=>(t,r)=>e.reduceRight((o,n)=>()=>n(t,r,o),()=>Qr(t,r))(),_=xa(ya,fo,ao,lo,Jr,Zr,ro,Xr,eo,ho,mo,go,po,to,co,so,uo,io);var yo=e=>{let{indent:t,text:r}=e.rows[0];return{indent:t,type:"line",nodes:_(r.substring(t),{nested:!1,quoted:!1,context:"line"})}};var xo=e=>{let{rows:[t,...r]}=e,{indent:o=0,text:n=""}=t??{},s=n.replace(/^\s*table:/,"");return{indent:o,type:"table",fileName:s,cells:r.map(i=>i.text.substring(o+1)).map(i=>i.split(" ").map(a=>_(a,{nested:!1,quoted:!1,context:"table"})))}};var Eo=e=>({type:"title",text:e.rows[0].text});var bo=e=>{switch(e.type){case"title":return Eo(e);case"codeBlock":return Vr(e);case"table":return xo(e);case"line":return yo(e)}};var vt=(e,t)=>{let r=zr(e);return Yr(r,{hasTitle:t?.hasTitle??!0}).map(bo)};var Ea=/https?:\/\/(?:www\.|music\.|)youtube\.com\/watch/,ba=/https?:\/\/youtu\.be\/([a-zA-Z\d_-]+)(?:\?([^\s]{0,100})|)/,wa=/https?:\/\/(?:www\.|)youtube\.com\/shorts\/([a-zA-Z\d_-]+)(?:\?([^\s]+)|)/,ka=/https?:\/\/(?:www\.|music\.|)youtube\.com\/playlist\?((?:[^\s]+&|)list=([a-zA-Z\d_-]+)(?:&[^\s]+|))/,wo=e=>{if(Ea.test(e)){let t=new URL(e).searchParams,r=t.get("v");if(r)return{pathType:"com",videoId:r,params:t}}{let t=e.match(ba);if(t){let[,r,o]=t;return{videoId:r,params:new URLSearchParams(o),pathType:"dotbe"}}}{let t=e.match(wa);if(t){let[,r,o]=t;return{videoId:r,params:new URLSearchParams(o),pathType:"short"}}}{let t=e.match(ka);if(t){let[,r,o]=t;return{listId:o,params:new URLSearchParams(r),pathType:"list"}}}};var Po=e=>{let t=vt(e,{hasTitle:!0}).flatMap(f=>{switch(f.type){case"codeBlock":case"title":return[];case"line":case"table":return f}}),r=new Map,o=[],n=new Set,s=[],i=new Set,a=[],c=null,u=new Set,l=new Set,d=new RegExp(${location?.origin??"https://scrapbox.io"}/files/([a-z0-9]{24})(?:|\\.[a-zA-Z0-9]+)(?:|\\?[^\\s]*)$),m=f=>{switch(f.type){case"hashTag":if(r.has(K(f.href)))return;r.set(K(f.href),!1),o.push(f.href);return;case"link":switch(f.pathType){case"relative":{let p=ko(f.href);if(r.get(K(p)))return;r.set(K(p),!0),o.push(p);return}case"root":{let p=ko(f.href);if(/^\/[\w\d-]+\/?$/.test(p)||n.has(K(p)))return;n.add(K(p)),s.push(p);return}case"absolute":{if(f.content)return;let p=wo(f.href);if(p&&p.pathType!=="list"){c??=https://i.ytimg.com/vi/${p.videoId}/mqdefault.jpg;return}let N=f.href.match(d)?.[1];N&&u.add(N);return}default:return}case"icon":case"strongIcon":{if(f.pathType==="root"||i.has(K(f.path)))return;i.add(K(f.path)),a.push(f.path);return}case"image":case"strongImage":{c??=f.src.endsWith("/thumb/1000")?f.src.replace(/\/thumb\/1000$/,"/raw"):f.src;{let p=f.src.match(d)?.[1];p&&u.add(p)}if(f.type==="image"){let p=f.link.match(d)?.[1];p&&u.add(p)}return}case"helpfeel":l.add(f.text);return;case"numberList":case"strong":case"quote":case"decoration":{for(let p of f.nodes)m(p);return}default:return}},w=[];for(let f of t)switch(f.type){case"line":for(let p of f.nodes)m(p);continue;case"table":{for(let p of f.cells)for(let N of p)for(let S of N)m(S);if(!["infobox","cosense"].includes(f.fileName))continue;w.push(...f.cells.map(p=>p.map(N=>N.map(S=>S.raw).join("")).join(" ").trim()));continue}}return[o,s,a,c,[...u],[...l],w]},ko=e=>e.replace(/#[a-f\d]{24,32}$/,""),To=e=>e.flatMap(({text:t})=>/^\s*\? .*$/.test(t)?[t.trimStart().slice(2)]:[]);var oe=(e,t)=>e.length===t.length&&e.every(r=>t.includes(r));function*No(e,t,r){let o=t.flatMap(w=>w.split( ));for(let w of Rt(e.lines,o,{userId:r}))yield w;(e.lines[0].text!==o[0]||!e.persistent)&&(yield{title:o[0]});let n=e.lines.slice(1,6).map(w=>w.text),s=o.slice(1,6);n.join("")!==s.join("")&&(yield{descriptions:s});let[i,a,c,u,l,d,m]=Po(o.join(
));oe(e.links,i)||(yield{links:i}),oe(e.projectLinks,a)||(yield{projectLinks:a}),oe(e.icons,c)||(yield{icons:c}),e.image!==u&&(yield{image:u}),oe(e.files,l)||(yield{files:l}),oe(To(e.lines),d)||(yield{helpfeels:d}),oe(e.infoboxDefinition,m)||(yield{infoboxDefinition:m})}var Ro=e=>{let t=e.match(/(.+?)(?:_(\d+))?$/),r=t?.[1]??e,o=t?.[2]?parseInt(t[2])+1:2;return${r}_${o}};var vo=(e,t,r,o)=>Q(e,t,async(n,s,i,a)=>{if(a==="DuplicateTitleError"){let l=Ro(t);return i.map(d=>("title"in d&&(d.title=l),d))}let c=r(n.lines,{...n,attempts:s}),u=c instanceof Promise?await c:c;return u===void 0?[]:u.length===0?[{deleted:!0}]:[...No(n,u,n.userId)]},o);var Lo=(e,t,r)=>Q(e,t,o=>{if(o.pin>0||!o.persistent&&!(r?.create??!1))return[];let n=[{pin:Pa()}];return o.persistent||n.unshift({title:t}),n},r),Co=(e,t,r)=>Q(e,t,o=>o.pin==0||!o.persistent?[]:[{pin:0}],r),Pa=()=>Number.MAX_SAFE_INTEGER-Math.floor(Date.now()/1e3);var Ra=Math.pow(10,8)*24*60*60*1e3,vy=-Ra,va=3600,Oo=va*24,Ly=Oo*7,La=Oo*365.2425,Ca=La/12,Cy=Ca*3,Io=Symbol.for("constructDateFrom");function Ia(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Io in e?e[Io](t):e instanceof Date?new e.constructor(t):new Date(t)}function Oa(e,t){return Ia(t||e,e)}function Lt(e,t){return Oa(e,t?.in).getFullYear()}var Sa=Math.pow(10,8)*24*60*60*1e3,My=-Sa,Aa=6048e5,Fa=3600,Ao=Fa*24,_y=Ao*7,Ma=Ao*365.2425,_a=Ma/12,Dy=_a*3,So=Symbol.for("constructDateFrom"),Da={};function Ct(){return Da}function $e(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&So in e?e[So](t):e instanceof Date?new e.constructor(t):new Date(t)}function It(e,t){return $e(t||e,e)}function Ue(e,t){let r=Ct(),o=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,n=It(e,t?.in),s=n.getDay(),i=(s<o?7:0)+s-o;return n.setDate(n.getDate()-i),n.setHours(0,0,0,0),n}function Ba(e,t){let r=It(e,t?.in),o=r.getFullYear(),n=Ct(),s=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,i=$e(t?.in||e,0);i.setFullYear(o+1,0,s),i.setHours(0,0,0,0);let a=Ue(i,t),c=$e(t?.in||e,0);c.setFullYear(o,0,s),c.setHours(0,0,0,0);let u=Ue(c,t);return+r>=+a?o+1:+r>=+u?o:o-1}function Ha(e,t){let r=Ct(),o=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??r.firstWeekContainsDate??r.locale?.options?.firstWeekContainsDate??1,n=Ba(e,t),s=$e(t?.in||e,0);return s.setFullYear(n,0,o),s.setHours(0,0,0,0),Ue(s,t)}function ge(e,t){let r=It(e,t?.in),o=+Ue(r,t)-+Ha(r,t);return Math.round(o/Aa)+1}var ja=Math.pow(10,8)*24*60*60*1e3,qy=-ja,$a=3600,Mo=$a*24,Ky=Mo*7,Ua=Mo*365.2425,qa=Ua/12,Gy=qa*3,Fo=Symbol.for("constructDateFrom");function Ka(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Fo in e?e[Fo](t):e instanceof Date?new e.constructor(t):new Date(t)}function Ga(e,t){return Ka(t||e,e)}function _o(e,t){return Ga(e,t?.in).getDate()}var Wa=Math.pow(10,8)*24*60*60*1e3,Xy=-Wa,Ya=3600,Bo=Ya*24,Jy=Bo*7,za=Bo*365.2425,Va=za/12,Zy=Va*3,Do=Symbol.for("constructDateFrom");function Qa(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Do in e?e[Do](t):e instanceof Date?new e.constructor(t):new Date(t)}function Xa(e,t){return Qa(t||e,e)}function Ho(e,t){return Xa(e,t?.in).getMonth()}var Ot=(e,t)=>{let r=0,o=[];for(let n=0;n<t.length;n++){let s=e.findIndex((i,a)=>a>=r&&i.trim()===t[n].trim());if(s<0){o.push(t[n]);continue}o.push(...e.slice(r,s+1)),r=s+1}return o.push(...e.slice(r)),o},St=(e,t)=>{let r=-1;for(let o of t){let n=e.findIndex((s,i)=>i>r&&s.trim()===o.trim());if(n<0)return-1;r=n}return r},V=e=>${e}.padStart(2,"0"),At=e=>${Lt(e)},Ft=(e,t)=>${At(e)}${t}${V(Ho(e)+1)},jo=(e,t)=>${Lt(e)}${t}w${V(ge(e))},qe=(e,t)=>${Ft(e,t)}${t}${V(_o(e))};var Mt=(e,t,r)=>{let o=Ot(Ot(e,t).reverse(),[...r].reverse()).reverse(),n=St(o,t),s=o.length-1-St([...o].reverse(),[...r].reverse());return[...o.slice(0,n+1),"",...o.slice(n+1,s).join(
).trim().split(
),"",...o.slice(s)]};var $o=(e,t,r,o)=>{let{sid:n,hostName:s}=P(o??{});return new Request(https://${s}/api/code/${e}/${re(t)}/${re(r)},n?{headers:{Cookie:C(n)}}:void 0)},Uo=async e=>v(await I(L(e),async t=>t.response.status===404&&t.response.headers.get("Content-Type")?.includes?.("text/plain")?{name:"NotFoundError",message:"Code block is not found"}:await F(t,["NotLoggedInError","NotMemberError"])??t),t=>t.text()),Ge=(()=>{let e=async(t,r,o,n)=>{let s=$o(t,r,o,n),i=await P(n??{}).fetch(s);return x(i)?i:Uo(b(i))};return e.toRequest=$o,e.fromResponse=Uo,e})();var wE=new TextEncoder;var NE=new TextEncoder().encode("0123456789abcdef"),RE=new TextEncoder,vE=new TextDecoder;var qo=" must not return ",Ja="transformer",Za="recoverer",ec="defaultValue",ib=Ja+qo,Ko="called with ",ab=ec+" must not be ",cb=Za+qo,tc="Ok",Go="Err",rc=Ko+Go,oc=Ko+tc,pb="Carrying E in "+Go+" instead of throwing it directly. See .cause",_t="an instance of Error of the current realm.",ub="The thrown value is not "+_t,lb="The contained E should be "+_t,fb="This .cause is not "+_t;function We(e){return e.ok}function Ye(e){return{ok:!0,val:e,err:null}}function j(e){return!e.ok}function X(e){return nc(e,rc)}function Dt(e){return sc(e,oc)}function nc(e,t){if(j(e))throw new TypeError(t);return e.val}function sc(e,t){if(We(e))throw new TypeError(t);return e.err}function ic(e){return e.val}async function Wo(e,t){if(j(e))return e;let r=ic(e);return await t(r)}async function*Yo(e,t){let r=0,o=t?.limit??100;for(;;){let n=await Hr(e,{...t,limit:o,sort:"updated",skip:r});if(j(n))return;let s=X(n).pages;for(let a of s)a.pin!==0&&(yield a);if((s.at(-1)?.pin??0)>0)return;r+=o}}var J=e=>e.ok,ye=e=>!e.ok,Bt=(e,t,r,o)=>({ok:!0,location:e,value:t,furthest:r,expected:o}),ze=(e,t)=>({ok:!1,furthest:e,expected:t});var Ht=e=>({index:e[0],line:e[1],column:e[2]}),$=(e,t,r)=>Bt(zo(e,t),r,[-1,-1,-1],[]),ne=(e,t,r)=>ze(zo(e,t),r),Z=(e,t)=>{let r=t.furthest[0]-e.furthest[0];if(r>0)return t;let o=r<0?e.expected:[...new Set([...e.expected,...t.expected])];return J(t)?Bt(t.location,t.value,e.furthest,o):ze(e.furthest,o)},zo=(e,t,r)=>{let[o,n]=e,[s,i,a]=n;if(t==s)return n;let c=t;if(typeof o=="string"){r??=[ ];let u=o.slice(s,c);for(let l of u)r.includes(l)?(i++,a=1):a++}else for(let u=s;u<c;u++){let l=o[u];r?.includes?.(l)?(i++,a=1):a++}return[t,i,a]};var se=(e,t)=>r=>{let o=e(r);if(ye(o))return o;let n=t(o.value);return Z(o,n([r[0],o.location]))};var O=e=>t=>$(t,t[1][0],e);var D=(e,t)=>se(e,r=>O(t(r)));var Ve=(...e)=>e.reduce((t,r)=>se(t,o=>D(r,n=>[...o,n])),O([]));var W=(e,t)=>r=>{let o=e(r);if(ye(o))return o;r=[r[0],o.location];let n=Z(o,t(r));if(J(n)){let s=[o.value,n.value];return Z(n,$(r,n.location[0],s))}return n};var B=(e,t)=>r=>{let o=e(r);return J(o)?o:Z(o,t(r))};var jt=(...e)=>e.reduce((t,r)=>B(t,r));var Vo="<EOF>",Qo=e=>{let[t,[r]]=e;return r<t.length?ne(e,r,[Vo]):$(e,r,Vo)};var Qe=e=>{for(let r of e.flags)switch(r){case"i":case"s":case"m":case"u":continue;default:throw new Error("only the regexp flags 'imsu' are supported")}let t=new RegExp(e.source,e.flags+"y");return r=>{let[o,[n]]=r;t.lastIndex=n;let s=o.match(t);if(s){let i=n+s[0].length,a=o.slice(n,i);return $(r,i,a)}return ne(r,n,[${e}])}};var Y=(e,t)=>D(W(e,t),([,r])=>r);var $t=(e,t)=>D(W(e,t),([r])=>r);var Xo=(e,t)=>{let r=$t(e,Qo)([t,[0,1,1]]);return r.ok?{ok:!0,value:r.value}:{ok:!1,location:Ht(r.furthest),expected:r.expected}};var T=e=>t=>{let[r,[o]]=t,n=o+e.length;return r.slice(o,n)==e?$(t,n,e):ne(t,o,[e])};var Jo=e=>{switch(e){case"Sun":return 0;case"Mon":return 1;case"Tue":return 2;case"Wed":return 3;case"Thu":return 4;case"Fri":return 5;default:return 6}};var cc=Math.pow(10,8)*24*60*60*1e3,pk=-cc,pc=3600,en=pc*24,uk=en*7,uc=en*365.2425,lc=uc/12,lk=lc*3,Zo=Symbol.for("constructDateFrom");function fc(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Zo in e?e[Zo](t):e instanceof Date?new e.constructor(t):new Date(t)}function dc(e,t){return fc(t||e,e)}function tn(e,t){return dc(e,t?.in).getHours()}var mc=Math.pow(10,8)*24*60*60*1e3,yk=-mc,hc=3600,on=hc*24,xk=on*7,gc=on*365.2425,yc=gc/12,Ek=yc*3,rn=Symbol.for("constructDateFrom");function xc(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&rn in e?e[rn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Ec(e,t){return xc(t||e,e)}function nn(e,t){return Ec(e,t?.in).getMinutes()}var bc=Math.pow(10,8)*24*60*60*1e3,Nk=-bc,wc=3600,an=wc*24,Rk=an*7,kc=an*365.2425,Pc=kc/12,vk=Pc*3,sn=Symbol.for("constructDateFrom");function Tc(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&sn in e?e[sn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Nc(e,t){return Tc(t||e,e)}function cn(e){return Nc(e).getSeconds()}var Rc=Math.pow(10,8)*24*60*60*1e3,Ak=-Rc,vc=3600,un=vc*24,Fk=un*7,Lc=un*365.2425,Cc=Lc/12,Mk=Cc*3,pn=Symbol.for("constructDateFrom");function ln(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&pn in e?e[pn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Ic(e,t){return ln(t||e,e)}function Ut(e,t,r){let o=Ic(e,r?.in);return isNaN(t)?ln(r?.in||e,NaN):(t&&o.setDate(o.getDate()+t),o)}var Oc=Math.pow(10,8)*24*60*60*1e3,$k=-Oc,Sc=3600,dn=Sc*24,Uk=dn*7,Ac=dn*365.2425,Fc=Ac/12,qk=Fc*3,fn=Symbol.for("constructDateFrom");function qt(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&fn in e?e[fn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Mc(e,t){return qt(t||e,e)}function mn(e,t,r){let o=Mc(e,r?.in);if(isNaN(t))return qt(r?.in||e,NaN);if(!t)return o;let n=o.getDate(),s=qt(r?.in||e,o.getTime());s.setMonth(o.getMonth()+t+1,0);let i=s.getDate();return n>=i?s:(o.setFullYear(s.getFullYear(),s.getMonth(),n),o)}var _c=Math.pow(10,8)*24*60*60*1e3,Vk=-_c,Dc=3600,gn=Dc*24,Qk=gn*7,Bc=gn*365.2425,Hc=Bc/12,Xk=Hc*3,hn=Symbol.for("constructDateFrom");function yn(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&hn in e?e[hn](t):e instanceof Date?new e.constructor(t):new Date(t)}function jc(e,t){return yn(t||e,e)}function $c(e,t,r){let o=jc(e,r?.in);return isNaN(t)?yn(r?.in||e,NaN):(t&&o.setDate(o.getDate()+t),o)}function xn(e,t,r){return $c(e,t*7,r)}var Uc=Math.pow(10,8)*24*60*60*1e3,o0=-Uc,qc=3600,bn=qc*24,n0=bn*7,Kc=bn*365.2425,Gc=Kc/12,s0=Gc*3,En=Symbol.for("constructDateFrom");function Kt(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&En in e?e[En](t):e instanceof Date?new e.constructor(t):new Date(t)}function Wc(e,t){return Kt(t||e,e)}function Yc(e,t,r){let o=Wc(e,r?.in);if(isNaN(t))return Kt(r?.in||e,NaN);if(!t)return o;let n=o.getDate(),s=Kt(r?.in||e,o.getTime());s.setMonth(o.getMonth()+t+1,0);let i=s.getDate();return n>=i?s:(o.setFullYear(s.getFullYear(),s.getMonth(),n),o)}function wn(e,t,r){return Yc(e,t*12,r)}var zc={};function Vc(){return zc}var Qc=Math.pow(10,8)*24*60*60*1e3,l0=-Qc,Xc=3600,Pn=Xc*24,f0=Pn*7,Jc=Pn*365.2425,Zc=Jc/12,d0=Zc*3,kn=Symbol.for("constructDateFrom");function ep(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&kn in e?e[kn](t):e instanceof Date?new e.constructor(t):new Date(t)}function tp(e,t){return ep(t||e,e)}function Tn(e,t){let r=Vc(),o=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,n=tp(e,t?.in),s=n.getDay(),i=(s<o?7:0)+s-o;return n.setDate(n.getDate()-i),n.setHours(0,0,0,0),n}var Rn=e=>${V(tn(e))},vn=e=>${Rn(e)}:${V(nn(e))},rp=e=>${vn(e)}:${V(cn(e))},op=T("yyyy"),np=T("MM"),sp=T("dd"),ip=T("ww"),ap=T("HH"),cp=T("mm"),pp=T("ss"),up=Qe(/\s/),lp=Qe(/[^Mw]?/),Nn=T(":"),fp=Y(ap,B(Y(W(Nn,cp),B(Y(W(Nn,pp),O(rp)),O(vn))),O(Rn))),dp=D(Qe(/[-+]\d+/),e=>parseInt(e)),mp=jt(T("y"),T("m"),T("d"),T("w"),T("")),hp=W(dp,mp),gp=T("("),yp=T(")"),xp=D(Ve(gp,jt(T("Sun"),T("Mon"),T("Tue"),T("Wed"),T("Thu"),T("Fri"),T("Sat")),yp),([,e])=>Jo(e)),Ep=Y(op,B(se(lp,e=>{let t=T(e);return B(Y(np,B(Y(W(t,sp),O(r=>qe(r,e))),O(r=>Ft(r,e)))),Y(ip,O(r=>jo(r,e))))}),O(At))),Ln=e=>Xo(D(Ve(Ep,D(B(hp,O([0,"d"])),([t,r])=>o=>bp(o,t,r)),B(xp,O(void 0)),B(W(up,fp),O(["",()=>""]))),([t,r,o,[n,s]])=>i=>{let a=r(i),c=o!==void 0?Ut(Tn(a),o):a;return${t(c)}${n}${s(c)}}),e.slice(1,-1)),bp=(e,t,r)=>{switch(r){case"y":return wn(e,t);case"m":return mn(e,t);case"w":return xn(e,t);case"d":case"":return Ut(e,t)}};var wp=Math.pow(10,8)*24*60*60*1e3,O0=-wp,kp=864e5,Pp=3600,Sn=Pp*24,S0=Sn*7,Tp=Sn*365.2425,Np=Tp/12,A0=Np*3,Cn=Symbol.for("constructDateFrom");function An(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Cn in e?e[Cn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Xe(e,t){return An(t||e,e)}function In(e){let t=Xe(e),r=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return r.setUTCFullYear(t.getFullYear()),+e-+r}function Rp(e,...t){let r=An.bind(null,e||t.find(o=>typeof o=="object"));return t.map(r)}function On(e,t){let r=Xe(e,t?.in);return r.setHours(0,0,0,0),r}function vp(e,t,r){let[o,n]=Rp(r?.in,e,t),s=On(o),i=On(n),a=+s-In(s),c=+i-In(i);return Math.round((a-c)/kp)}function Lp(e,t){let r=Xe(e,t?.in);return r.setFullYear(r.getFullYear(),0,1),r.setHours(0,0,0,0),r}function Fn(e,t){let r=Xe(e,t?.in);return vp(r,Lp(r))+1}var Cp=Math.pow(10,8)*24*60*60*1e3,H0=-Cp,Ip=3600,_n=Ip*24,j0=_n*7,Op=_n*365.2425,Sp=Op/12,$0=Sp*3,Mn=Symbol.for("constructDateFrom");function Ap(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Mn in e?e[Mn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Dn(e,t){return Ap(t||e,e)}function Fp(e,t){let r=Dn(e,t?.in).getFullYear();return r%400===0||r%4===0&&r%100!==0}function Bn(e,t){let r=Dn(e,t?.in);return Number.isNaN(+r)?NaN:Fp(r)?366:365}var Mp=Math.pow(10,8)*24*60*60*1e3,Y0=-Mp,_p=864e5,Dp=6e4,Bp=36e5,Hp=3600,qn=Hp*24,z0=qn*7,jp=qn*365.2425,$p=jp/12,V0=$p*3,Hn=Symbol.for("constructDateFrom");function pe(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Hn in e?e[Hn](t):e instanceof Date?new e.constructor(t):new Date(t)}function ee(e,...t){let r=pe.bind(null,e||t.find(o=>typeof o=="object"));return t.map(r)}function Up(e,t){let[r,o]=ee(e,t.start,t.end);return{start:r,end:o}}function U(e,t){return pe(t||e,e)}function qp(e,t,r){let o=U(e,r?.in);return isNaN(t)?pe(r?.in||e,NaN):(t&&o.setDate(o.getDate()+t),o)}function Kp(e,t,r){let o=U(e,r?.in);if(isNaN(t))return pe(r?.in||e,NaN);if(!t)return o;let n=o.getDate(),s=pe(r?.in||e,o.getTime());s.setMonth(o.getMonth()+t+1,0);let i=s.getDate();return n>=i?s:(o.setFullYear(s.getFullYear(),s.getMonth(),n),o)}function xe(e,t,r){let{years:o=0,months:n=0,weeks:s=0,days:i=0,hours:a=0,minutes:c=0,seconds:u=0}=t,l=U(e,r?.in),d=n||o?Kp(l,n+o*12):l,m=i||s?qp(d,i+s*7):d,w=c+a*60,f=(u+w*60)*1e3;return pe(r?.in||e,+m+f)}function jn(e){let t=U(e),r=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return r.setUTCFullYear(t.getFullYear()),+e-+r}function $n(e,t){let r=U(e,t?.in);return r.setHours(0,0,0,0),r}function Gp(e,t,r){let[o,n]=ee(r?.in,e,t),s=$n(o),i=$n(n),a=+s-jn(s),c=+i-jn(i);return Math.round((a-c)/_p)}function Wp(e,t,r){let[o,n]=ee(r?.in,e,t),s=Un(o,n),i=Math.abs(Gp(o,n));o.setDate(o.getDate()-s*i);let a=+(Un(o,n)===-s),c=s*(i-a);return c===0?0:c}function Un(e,t){let r=e.getFullYear()-t.getFullYear()||e.getMonth()-t.getMonth()||e.getDate()-t.getDate()||e.getHours()-t.getHours()||e.getMinutes()-t.getMinutes()||e.getSeconds()-t.getSeconds()||e.getMilliseconds()-t.getMilliseconds();return r<0?-1:r>0?1:r}function Gt(e){return t=>{let r=(e?Math[e]:Math.trunc)(t);return r===0?0:r}}function Yp(e,t,r){let[o,n]=ee(r?.in,e,t),s=(+o-+n)/Bp;return Gt(r?.roundingMethod)(s)}function Kn(e,t){return+U(e)-+U(t)}function zp(e,t,r){let o=Kn(e,t)/Dp;return Gt(r?.roundingMethod)(o)}function Ee(e,t){let r=+U(e)-+U(t);return r<0?-1:r>0?1:r}function Vp(e,t,r){let[o,n]=ee(r?.in,e,t),s=o.getFullYear()-n.getFullYear(),i=o.getMonth()-n.getMonth();return s*12+i}function Qp(e,t){let r=U(e,t?.in);return r.setHours(23,59,59,999),r}function Xp(e,t){let r=U(e,t?.in),o=r.getMonth();return r.setFullYear(r.getFullYear(),o+1,0),r.setHours(23,59,59,999),r}function Jp(e,t){let r=U(e,t?.in);return+Qp(r,t)==+Xp(r,t)}function Zp(e,t,r){let[o,n,s]=ee(r?.in,e,e,t),i=Ee(n,s),a=Math.abs(Vp(n,s));if(a<1)return 0;n.getMonth()===1&&n.getDate()>27&&n.setDate(30),n.setMonth(n.getMonth()-i*a);let c=Ee(n,s)===-i;Jp(o)&&a===1&&Ee(o,s)===1&&(c=!1);let u=i*(a-+c);return u===0?0:u}function eu(e,t,r){let o=Kn(e,t)/1e3;return Gt(r?.roundingMethod)(o)}function tu(e,t,r){let[o,n]=ee(r?.in,e,t);return o.getFullYear()-n.getFullYear()}function ru(e,t,r){let[o,n]=ee(r?.in,e,t),s=Ee(o,n),i=Math.abs(tu(o,n));o.setFullYear(1584),n.setFullYear(1584);let a=Ee(o,n)===-s,c=s*(i-+a);return c===0?0:c}function Gn(e,t){let{start:r,end:o}=Up(t?.in,e),n={},s=ru(o,r);s&&(n.years=s);let i=xe(r,{years:n.years}),a=Zp(o,i);a&&(n.months=a);let c=xe(i,{months:n.months}),u=Wp(o,c);u&&(n.days=u);let l=xe(c,{days:n.days}),d=Yp(o,l);d&&(n.hours=d);let m=xe(l,{hours:n.hours}),w=zp(o,m);w&&(n.minutes=w);let f=xe(m,{minutes:n.minutes}),p=eu(o,f);return p&&(n.seconds=p),n}var ou=Math.pow(10,8)*24*60*60*1e3,tP=-ou,nu=3600,Yn=nu*24,rP=Yn*7,su=Yn*365.2425,iu=su/12,oP=iu*3,Wn=Symbol.for("constructDateFrom");function Wt(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Wn in e?e[Wn](t):e instanceof Date?new e.constructor(t):new Date(t)}function au(e,t){return Wt(t||e,e)}function cu(e,t,r){let o=au(e,r?.in);if(isNaN(t))return Wt(r?.in||e,NaN);if(!t)return o;let n=o.getDate(),s=Wt(r?.in||e,o.getTime());s.setMonth(o.getMonth()+t+1,0);let i=s.getDate();return n>=i?s:(o.setFullYear(s.getFullYear(),s.getMonth(),n),o)}function pu(e,t,r){return cu(e,t*12,r)}function zn(e,t,r){return pu(e,-t,r)}var uu=Math.pow(10,8)*24*60*60*1e3,pP=-uu,lu=3600,Qn=lu*24,uP=Qn*7,fu=Qn*365.2425,du=fu/12,lP=du*3,Vn=Symbol.for("constructDateFrom");function mu(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Vn in e?e[Vn](t):e instanceof Date?new e.constructor(t):new Date(t)}function hu(e,t){return mu(t||e,e)}function Xn(e,t){return hu(e,t?.in).getDay()}var ue=(e,t)=>t.split(
).flatMap(r=>r.replaceAll("@w@",${ge(e)}).replaceAll("@ww@",${V(ge(e))}).replaceAll("@day_indicator@",${gu(e)}).replaceAll("@progress@",${(Fn(e)*100/Bn(e)).toFixed(2)}).replace(/^(\s*)@\[from_(\d{4})(\D?)(\d{2})(\D?)(\d{2})\]@\s*/,(o,n,s,i,a,c,u)=>{let l=new Date(parseInt(s),parseInt(a)-1,parseInt(u)),d=Gn({start:l,end:e}).years??0;return[...Array(d).keys()].map(m=>${n}${qe(zn(e,m+1),i??c??"")}).join( )}).replace(/@[^@]+@/g,o=>{let n=Ln(o);return n.ok?n.value(e):o}).split(
)),gu=e=>{let t=Xn(e);return[..."日月火水木金土"].map((r,o)=>o===t?${r}:r).join("")};var Jn=async(e,t)=>{let r=await Ge(e,t,"title");if(j(r))return r;let o=await Ge(e,t,"header");if(j(o))return o;let n=await Ge(e,t,"footer");return j(n)?n:Ye({title:X(r),header:X(o),footer:X(n)})},Yt=e=>({makeDiary:t=>({title:ue(t,e.title)[0],header:ue(t,e.header),footer:ue(t,e.footer)}),isOldDiary:(t,r)=>ue(r,t)[0]!==t});var es=(e,t)=>{let r=t.interval??864e5,o,n=async()=>{s(),await Zn(e,new Date,t),o=setInterval(()=>Zn(e,new Date,t),r)},s=()=>clearInterval(o),i=()=>scrapbox.Project.name===e?n():s();return i(),scrapbox.addListener("project:changed",i),()=>{s(),scrapbox.removeListener("project:changed",i)}},Zn=async(e,t,r)=>{let{render:o,dispose:n}=Qt(),s;try{let i;if("title"in r)if("header"in r)i=Yt(r);else{let d=await Jn(r.project??e,r.title);if(We(d))i=Yt(X(d));else{let m=Dt(d),w=Failed to load template from /${r.project??e}/${r.title}.
Please make sure this page includes the following 3 code blocks: "title", "header", and "footer".;o({type:"exclamation-triangle"},{type:"text",text:w}),console.error(w,m);return}}else i=r;let{makeDiary:a,isOldDiary:c}=i,u=await Wo(await De(),async d=>{s=d,o({type:"spinner"},{type:"text",text:"unpin other diary pages..."});for await(let{title:S}of Yo(e)){if(!c(S,t))continue;let M=await Co(e,S,{socket:s});if(j(M))return M}let{title:m,header:w,footer:f}=a(t);o({type:"spinner"},{type:"text",text:pin "/${e}/${m}"...});let p=await Lo(e,m,{socket:s,create:!0});if(j(p))return p;o({type:"spinner"},{type:"text",text:format "/${e}/${m}"...});let N=await vo(e,m,S=>[S[0].text,...Mt(S.slice(1).map(M=>M.text),w,f)],{socket:s});return j(N)?N:(o({type:"check-circle"},{type:"text",text:Pinned "/${e}/${m}".}),await he(s),Ye(void 0))});if(We(u))return;let l=Dt(u);o({type:"exclamation-triangle"},{type:"text",text:z(l)?SocketIO error: ${l}:${l.name}${"message"in l&&: ${l.message}}}),console.error(l)}catch(i){o({type:"exclamation-triangle"},{type:"text",text:i instanceof Error?${i.name} ${i.message}`:"Unknown error! (see developper console)"}),console.error(i)}finally{s&&await he(s),await te(1e3),n()}};es("motoso",{project:"motoso",title:"pin-diary%2Ftemplate"});