pin-diary-7
code:script.ts
import { launch } from "jsr:@takker/pin-diary@0.1";
launch("caki", { project: "caki", title: "pin-diary-template" });
code:code.js
var Zn=Object.defineProperty;var es=(e,t)=>{for(var r in t)Zn(e,r,{get:tr,enumerable:!0})};function Ne(e){return Array.isArray(e)}function W(e){return typeof e=="string"}var Ut=!1;scrapbox.addListener("lines:changed",()=>Ut=!1);scrapbox.addListener("layout:changed",()=>Ut=!1);var qt=(e,t)=>{if(!(e instanceof HTMLDivElement))throw new TypeError("${t}" must be HTMLDivElememt but actual is "${e}")};var Kt=(e,t)=>{if(!(e instanceof HTMLTextAreaElement))throw new TypeError("${t}" must be HTMLTextAreaElement but actual is "${e}")};var ne=()=>{let e=document.getElementById("text-input");if(e)return Kt(e,"textarea#text-input"),e};var Gt=()=>ts(document.getElementsByClassName("status-bar")?.0,"div.status-bar"),ts=(e,t)=>{if(e)return qt(e,t),e};function ee(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 Yt=()=>{let e=Gt();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=Wt(...r);o&&t.append(o)},dispose:()=>t.remove()}},Wt=(...e)=>{let t=e.flatMap(o=>{switch(o.type){case"spinner":returncs();case"check-circle":returnps();case"exclamation-triangle":returnus();case"text":returnve(o.text);case"group":{let n=Wt(...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},ve=e=>{let t=document.createElement("span");return t.classList.add("item"),t.append(e),t},cs=()=>{let e=document.createElement("i");return e.classList.add("fa","fa-spinner"),ve(e)},ps=()=>{let e=document.createElement("i");return e.classList.add("kamon","kamon-check-circle"),ve(e)},us=()=>{let e=document.createElement("i");return e.classList.add("fas","fa-exclamation-triangle"),ve(e)};var q=e=>e.replaceAll(" ","_").toLowerCase();var V=e=>...e.map((t,r)=>t===" "?"_":!ls.includes(t)||r===e.length-1&&ds.includes(t)?encodeURIComponent(t):t).join(""),ls='@$&+=:;",',ds=':;",';var zt=e=>{if(e===0)return;let t={};return e&1&&(t.capture=!0),e&2&&(t.once=!0),e&4&&(t.passive=!0),t};var fs=new Map;scrapbox.on("layout:changed",()=>{let e=ne();if(e)for(lett,rof fs)for(leto,nof r)for(let s of n)e.addEventListener(t,o,zt(s))});var ot={};es(ot,{Decoder:()=>Ts,Encoder:()=>Ps,PacketType:()=>y,protocol:()=>Jt});function F(e){if(e)return hs(e)}function hs(e){for(var t in F.prototype)et=F.prototypet;return e}F.prototype.on=F.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks"$"+e=this._callbacks"$"+e||[]).push(t),this};F.prototype.once=function(e,t){function r(){this.off(e,r),t.apply(this,arguments)}return r.fn=t,this.on(e,r),this};F.prototype.off=F.prototype.removeListener=F.prototype.removeAllListeners=F.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};F.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};F.prototype.emitReserved=F.prototype.emit;F.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks"$"+e||[]};F.prototype.hasListeners=function(e){return!!this.listeners(e).length};var gs=typeof ArrayBuffer=="function",ys=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,Qt=Object.prototype.toString,xs=typeof Blob=="function"||typeof Blob<"u"&&Qt.call(Blob)==="object BlobConstructor",Es=typeof File=="function"||typeof File<"u"&&Qt.call(File)==="object FileConstructor";function rt(e){return gs&&(e instanceof ArrayBuffer||ys(e))||xs&&e instanceof Blob||Es&&e instanceof File}function Re(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let r=0,o=e.length;r<o;r++)if(Re(er))return!0;return!1}if(rt(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return Re(e.toJSON(),!0);for(let r in e)if(Object.prototype.hasOwnProperty.call(e,r)&&Re(er))return!0;return!1}function bs(e){let t=[],r=e.data,o=e;return o.data=et(r,t),o.attachments=t.length,{packet:o,buffers:t}}function et(e,t){if(!e)return e;if(rt(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=et(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=et(eo,t));return r}return e}function ks(e,t){return e.data=tt(e.data,t),delete e.attachments,e}function tt(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=tt(er,t);else if(typeof e=="object")for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(er=tt(er,t));return e}var ws="connect","connect_error","disconnect","disconnecting","newListener","removeListener",Jt=5,y;(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"})(y||(y={}));var Ps=class{constructor(e){this.replacer=e}encode(e){return(e.type===y.EVENT||e.type===y.ACK)&&Re(e)?this.encodeAsBinary({type:e.type===y.EVENT?y.BINARY_EVENT:y.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):this.encodeAsString(e)}encodeAsString(e){let t=""+e.type;return(e.type===y.BINARY_EVENT||e.type===y.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=bs(e),r=this.encodeAsString(t.packet),o=t.buffers;return o.unshift(r),o}};function Vt(e){return Object.prototype.toString.call(e)==="object Object"}var Ts=class Xt extends F{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===y.BINARY_EVENT;o||r.type===y.BINARY_ACK?(r.type=o?y.EVENT:y.ACK,this.reconstructor=new Ns(r),r.attachments===0&&super.emitReserved("decoded",r)):super.emitReserved("decoded",r)}else if(rt(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(yo.type===void 0)throw new Error("unknown packet type "+o.type);if(o.type===y.BINARY_EVENT||o.type===y.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(Xt.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 y.CONNECT:return Vt(r);case y.DISCONNECT:return r===void 0;case y.CONNECT_ERROR:return typeof r=="string"||Vt(r);case y.EVENT:case y.BINARY_EVENT:return Array.isArray(r)&&(typeof r0=="number"||typeof r0=="string"&&ws.indexOf(r0)===-1);case y.ACK:case y.BINARY_ACK:return Array.isArray(r)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}},Ns=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 K=Object.create(null);K.open="0";K.close="1";K.ping="2";K.pong="3";K.message="4";K.upgrade="5";K.noop="6";var Ie=Object.create(null);Object.keys(K).forEach(e=>{Ie[Ke]=e});var it={type:"error",data:"parser error"},rr=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="object BlobConstructor",or=typeof ArrayBuffer=="function",nr=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,Oe=({type:e,data:t},r,o)=>rr&&t instanceof Blob?r?o(t):Zt(t,o):or&&(t instanceof ArrayBuffer||nr(t))?r?o(t):Zt(new Blob(t),o):o(Ke+(t||"")),Zt=(e,t)=>{let r=new FileReader;return r.onload=function(){let o=r.result.split(",")1;t("b"+(o||""))},r.readAsDataURL(e)};function er(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var nt;function vs(e,t){if(rr&&e.data instanceof Blob)return e.data.arrayBuffer().then(er).then(t);if(or&&(e.data instanceof ArrayBuffer||nr(e.data)))return t(er(e.data));Oe(e,!1,r=>{nt||(nt=new TextEncoder),t(nt.encode(r))})}var tr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",me=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e<tr.length;e++)metr.charCodeAt(e)=e;var Rs=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=mee.charCodeAt(o),i=mee.charCodeAt(o+1),a=mee.charCodeAt(o+2),c=mee.charCodeAt(o+3),ln++=s<<2|i>>4,ln++=(i&15)<<4|a>>2,ln++=(a&3)<<6|c&63;return u},Ls=typeof ArrayBuffer=="function",Se=(e,t)=>{if(typeof e!="string")return{type:"message",data:sr(e,t)};let r=e.charAt(0);return r==="b"?{type:"message",data:Cs(e.substring(1),t)}:Ier?e.length>1?{type:Ier,data:e.substring(1)}:{type:Ier}:it},Cs=(e,t)=>{if(Ls){let r=Rs(e);return sr(r,t)}else return{base64:!0,data:e}},sr=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob(e);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}},ir="",ar=(e,t)=>{let r=e.length,o=new Array(r),n=0;e.forEach((s,i)=>{Oe(s,!1,a=>{oi=a,++n===r&&t(o.join(ir))})})},cr=(e,t)=>{let r=e.split(ir),o=[];for(let n=0;n<r.length;n++){let s=Se(rn,t);if(o.push(s),s.type==="error")break}return o};function pr(){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 st;function Le(e){return e.reduce((t,r)=>t+r.length,0)}function Ce(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 ur(e,t){st||(st=new TextDecoder);let r=[],o=0,n=-1,s=!1;return new TransformStream({transform(i,a){for(r.push(i);;){if(o===0){if(Le(r)<1)break;let c=Ce(r,1);s=(c0&128)===128,n=c0&127,n<126?o=3:n===126?o=1:o=2}else if(o===1){if(Le(r)<2)break;let c=Ce(r,2);n=new DataView(c.buffer,c.byteOffset,c.length).getUint16(0),o=3}else if(o===2){if(Le(r)<8)break;let c=Ce(r,8),u=new DataView(c.buffer,c.byteOffset,c.length),l=u.getUint32(0);if(l>Math.pow(2,21)-1){a.enqueue(it);break}n=l*Math.pow(2,32)+u.getUint32(4),o=3}else{if(Le(r)<n)break;let c=Ce(r,n);a.enqueue(Se(s?c:st.decode(c),t)),o=0}if(n===0||n>e){a.enqueue(it);break}}}})}var at=4;function P(e){if(e)return Is(e)}function Is(e){for(var t in P.prototype)et=P.prototypet;return e}P.prototype.on=P.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks"$"+e=this._callbacks"$"+e||[]).push(t),this};P.prototype.once=function(e,t){function r(){this.off(e,r),t.apply(this,arguments)}return r.fn=t,this.on(e,r),this};P.prototype.off=P.prototype.removeListener=P.prototype.removeAllListeners=P.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};P.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};P.prototype.emitReserved=P.prototype.emit;P.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks"$"+e||[]};P.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")(),Os="arraybuffer";function dr(e,...t){return t.reduce((r,o)=>(e.hasOwnProperty(o)&&(ro=eo),r),{})}var Ss=H.setTimeout,As=H.clearTimeout;function he(e,t){t.useNativeTimers?(e.setTimeoutFn=Ss.bind(H),e.clearTimeoutFn=As.bind(H)):(e.setTimeoutFn=H.setTimeout.bind(H),e.clearTimeoutFn=H.clearTimeout.bind(H))}var Fs=1.33;function Ms(e){return typeof e=="string"?_s(e):Math.ceil((e.byteLength||e.size)*Fs)}function _s(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 mr(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Ds(e){let t="";for(let r in e)e.hasOwnProperty(r)&&(t.length&&(t+="&"),t+=encodeURIComponent(r)+"="+encodeURIComponent(er));return t}function Bs(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 Hs=class extends Error{constructor(e,t,r){super(e),this.description=t,this.context=r,this.type="TransportError"}},ut=class extends P{constructor(e){super(),this.writable=!1,he(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 Hs(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=Se(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=Ds(e);return t.length?"?"+t:""}},js=class extends ut{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)};cr(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,ar(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=mr()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}},fr=!1;try{fr=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var $s=fr;function Us(){}var qs=class extends js{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}},se=class Ae extends P{constructor(t,r,o){super(),this.createRequest=t,he(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=dr(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=Ae.requestsCount++,Ae.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=Us,t)try{this._xhr.abort()}catch{}typeof document<"u"&&delete Ae.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()}};se.requestsCount=0;se.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",lr);else if(typeof addEventListener=="function"){let e="onpagehide"in H?"pagehide":"unload";addEventListener(e,lr,!1)}}function lr(){for(let e in se.requests)se.requests.hasOwnProperty(e)&&se.requestse.abort()}var Ks=function(){let e=hr({xdomain:!1});return e&&e.responseType!==null}(),Gs=class extends qs{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Ks&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new se(hr,this.uri(),e)}};function hr(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!t||$s))return new XMLHttpRequest}catch{}if(!t)try{return new H["Active".concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}var gr=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",Ys=class extends ut{get name(){return"websocket"}doOpen(){let e=this.uri(),t=this.opts.protocols,r=gr?{}:dr(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;Oe(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=mr()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},ct=H.WebSocket||H.MozWebSocket,Ws=class extends Ys{createSocket(e,t,r){return gr?new ct(e,t,r):t?new ct(e,t):new ct(e)}doWrite(e,t){this.ws.send(t)}},zs=class extends ut{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=ur(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=e.readable.pipeThrough(t).getReader(),o=pr();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()}},Vs={websocket:Ws,webtransport:zs,polling:Gs},Qs=/^(?:(?!^:@\/?#+:^:@\/*@)(http|https|ws|wss):\/\/)?((?:((^:@\/?#*)(?::(^:@\/?#*))?)?@)?((?:a-f0-9{0,4}:){2,7}a-f0-9{0,4}|^:\/?#*)(?::(\d*))?)(((\/(?:^?#(?!^?#\/*\.^?#\/.+(?:?#|$)))*\/?)?(^?#\/*))(?:\?(^#*))?(?:#(.*))?)/,Js="source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor";function De(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=Qs.exec(e||""),s={},i=14;for(;i--;)s[Jsi]=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=Xs(s,s.path),s.queryKey=Zs(s,s.query),s}function Xs(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 Zs(e,t){let r={};return t.replace(/(?:^|&)(^&=*)=?(^&*)/g,function(o,n,s){n&&(rn=s)}),r}var pt=typeof addEventListener=="function"&&typeof removeEventListener=="function",Fe=[];pt&&addEventListener("offline",()=>{Fe.forEach(e=>e())},!1);var Me=class _e extends P{constructor(t,r){if(super(),this.binaryType=Os,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=De(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=De(r.host).host);he(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=Bs(this.opts.query)),pt&&(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"})},Fe.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){let r=Object.assign({},this.opts.query);r.EIO=at,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&&_e.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",_e.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+=Ms(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(_e.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(),pt&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let o=Fe.indexOf(this._offlineEventListener);o!==-1&&Fe.splice(o,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,r),this.writeBuffer=[],this._prevBufferLen=0}}};Me.protocol=at;var ei=class extends Me{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;Me.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;Me.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 m=new Error("probe error");m.transport=t.name,this.emitReserved("upgradeError",m)}}))};function n(){r||(r=!0,u(),t.close(),t=null)}let s=l=>{let m=new Error("probe error: "+l);m.transport=t.name,n(),this.emitReserved("upgradeError",m)};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 ei{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=>Vso).filter(o=>!!o)),super(e,r)}};var vd=lt.protocol;function ti(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=De(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 U(e,t,r){return e.on(t,r),function(){e.off(t,r)}}var ri=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),yr=class extends P{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=U(e,"open",this.onopen.bind(this)),U(e,"packet",this.onpacket.bind(this)),U(e,"error",this.onerror.bind(this)),U(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(ri.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:y.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:y.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 y.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 y.EVENT:case y.BINARY_EVENT:this.onevent(e);break;case y.ACK:case y.BINARY_ACK:this.onack(e);break;case y.DISCONNECT:this.ondisconnect();break;case y.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:y.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:y.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 ae(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}ae.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};ae.prototype.reset=function(){this.attempts=0};ae.prototype.setMin=function(e){this.ms=e};ae.prototype.setMax=function(e){this.max=e};ae.prototype.setJitter=function(e){this.jitter=e};var dt=class extends P{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,he(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 ae({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||ot;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=U(t,"open",function(){r.onopen(),e&&e()}),n=i=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",i),e?e(i):this.maybeReconnectOnOpen()},s=U(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(U(e,"ping",this.onping.bind(this)),U(e,"data",this.ondata.bind(this)),U(e,"error",this.onerror.bind(this)),U(e,"close",this.onclose.bind(this)),U(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 yr(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)}},ge={};function ie(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};let r=ti(e,t.path||"/socket.io"),o=r.source,n=r.id,s=r.path,i=gen&&s in gen.nsps,a=t.forceNew||t"force new connection"||t.multiplex===!1||i,c;return a?c=new dt(o,t):(gen||(gen=new dt(o,t)),c=gen),r.query&&!t.query&&(t.query=r.queryKey),c.socket(r.path,t)}Object.assign(ie,{Manager:dt,Socket:yr,io:ie,connect:ie});var xr=" must not return ",oi="transformer",ni="recoverer",si="defaultValue",Zd=oi+xr,Er="called with ",em=si+" must not be ",tm=ni+xr,ii="Ok",br="Err",ai=Er+br,ci=Er+ii,rm="Carrying E in "+br+" instead of throwing it directly. See .cause",mt="an instance of Error of the current realm.",om="The thrown value is not "+mt,nm="The contained E should be "+mt,sm="This .cause is not "+mt;function ce(e){return e.ok}function b(e){return{ok:!0,val:e,err:null}}function h(e){return!e.ok}function I(e){return{ok:!1,val:null,err:e}}function g(e){return pi(e,ai)}function pe(e){return ui(e,ci)}function pi(e,t){if(!e.ok)throw new TypeError(t);return e.val}function ui(e,t){if(e.ok)throw new TypeError(t);return e.err}async function ye(e,t){if(h(e))return e;let r=g(e);return await t(r)}function Be(e,t){if(!e.ok)return e;let r=t(e.val);return b(r)}async function v(e,t){if(h(e))return e;let r=g(e),o=await t(r);return b(o)}async function C(e,t){if(ce(e))return e;let r=await t(e.err);return I(r)}var He=e=>{if(e?.connected)return Promise.resolve(b(e));e??=ie("https://scrapbox.io",{reconnectionDelay:5e3,transports:["websocket"]});let t=new Promise(r=>{let o=n=>r(I(n));e.once("connect",()=>{e.off("disconnect",o),r(b(e))}),e.once("disconnect",o)});return e.connect(),t},xe=e=>{if(e.disconnected)return Promise.resolve(b(void 0));let t=new Promise(r=>{let o=n=>{if(n!=="io client disconnect"){r(I(n));return}r(b(void 0)),e.off("disconnect",o)};e.on("disconnect",o)});return e.disconnect(),t};var kr=e=>li.includes(e.name),li="SocketIOError","DuplicateTitleError","NotFastForwardError";var wr=(e,t,r,o)=>{if(t==="cursor")return e.emit(t,r),Promise.resolve(b(void 0));let{resolve:n,promise:s,reject:i}=Promise.withResolvers(),a=()=>{e.off("disconnect",c),clearTimeout(l)},c=f=>{if(f==="io client disconnect"){a(),i(new Error("io client disconnect"));return}if(f==="io server disconnect"){a(),n(I({name:"SocketIOError"}));return}};e.on("disconnect",c);let u=o?.timeout??9e4,l=setTimeout(()=>{a(),n(I({name:"TimeoutError",message:exceeded ${u} (ms)}))},u),m=t==="commit"?{method:"commit",data:r}:{method:"room:join",data:r};return e.emit("socket.io-request",m,f=>{if(a(),"error"in f){n(I(kr(f.error)?f.error:{name:"UnexpectedRequestError",...f}));return}n(b(f.data))}),s};var R=e=>e.ok?b(e):I({name:"HTTPError",message:${e.status} ${e.statusText},response:e});var Pr=async(e,t)=>{let r=new Request(e,t);try{return b(await globalThis.fetch(r))}catch(o){if(o instanceof DOMException&&o.name==="AbortError")return I({name:"AbortError",message:o.message,request:r});if(o instanceof TypeError)return I({name:"NetworkError",message:o.message,request:r});throw o}};var k=e=>{let{fetch:t=Pr,hostName:r="scrapbox.io",...o}=e;return{fetch:t,hostName:r,...o}};var Tr=e=>{let{sid:t,hostName:r}=k(e??{});return new Request(https://${r}/api/users/me,t?{headers:{Cookie:L(t)}}:void 0)},Nr=e=>v(R(e),async t=>await t.json()),Ee=async e=>{let{fetch:t,...r}=k(e??{}),o=await t(Tr(r));return h(o)?o:Nr(g(o))};Ee.toRequest=Tr;Ee.fromResponse=Nr;var L=e=>connect.sid=${e};function je(e,t={}){if(e===null)return"null";if(Array.isArray(e))return di(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:mi(e,t);case"function":return e.name||"(anonymous)"}return e?.toString()??"undefined"}function di(e,t){let{threshold:r=20}=t,o=e.map(i=>je(i,t)),n=o.join(", ");if(n.length<=r)return[${n}];let s=o.join(`, );return[
${vr(2,s)}
]}function mi(e,t){let{threshold:r=20}=t,o=[...Object.keys(e),...Object.getOwnPropertySymbols(e)].map(i=>${i.toString()}: ${je(ei,t)}),n=o.join(", ");if(n.length<=r)return{${n}};let s=o.join(, );return{
${vr(2,s)}
}}function vr(e,t){let r=" ".repeat(e);return t.split(
).map(o=>${r}${o}).join(
)}function $e(e,t,...r){let o;return Object.defineProperties(e,{name:{get:()=>o||(o=${t}(${r.map(n=>je(n)).join(", ")}),o)}})}function Rr(e){return $e(t=>Ne(t)&&t.every(r=>e(r)),"isArrayOf",e)}function ft(e){let t=new Set(e);return $e(r=>t.has(r),"isLiteralOneOf",e)}function ht(e){return e!=null&&!Array.isArray(e)&&typeof e=="object"}var O=async(e,t)=>{let r=e.response.clone(),o=ft(t);try{let n=await r.json();if(!ht(n))return;if(r.status===422){if(!W(n.message))return;for(let s of["NoQueryError","InvalidURLError"])if(t.includes(s))return{name:s,message:n.message}}return!o(n.name)||!W(n.message)?void 0:n.name==="NotLoggedInError"?!ht(n.detals)||!W(n.detals.project)||!Rr(fi)(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}},fi=ft(["google","github","microsoft","gyazo","email","saml","easy-trial"]);var Lr=" must not return ",hi="transformer",gi="recoverer",yi="defaultValue",xi=hi+Lr,Ei="called with ",bi=yi+" must not be ",ki=gi+Lr,Ue="null or undefined",Km=xi+Ue,Gm=Ei+Ue,wi=bi+Ue,Ym=ki+Ue;function Cr(e){return e!=null}function Pi(e,t){if(Cr(e))return e;throw new TypeError(t)}function gt(e,t){return Cr(e)?e:Pi(t,wi)}var Ir=(e,t,r)=>{let{sid:o,hostName:n,followRename:s,projects:i}=k(r??{}),a=new URLSearchParams([["followRename",${s??!0}],...i?.map?.(c=>["projects",c])??[]]);return new Request(https://${n}/api/pages/${e}/${V(t)}?${a},o?{headers:{Cookie:L(o)}}:void 0)},Or=async e=>C(await v(R(e),t=>t.json()),async t=>t.response.status===414?{name:"TooLongURIError",message:"project ids may be too much."}:gt(await O(t,["NotFoundError","NotLoggedInError","NotMemberError"]),t)),qe=async(e,t,r)=>ye(await k(r??{}).fetch(Ir(e,t,r)),o=>Or(o));qe.toRequest=Ir;qe.fromResponse=Or;var Sr=(e,t)=>{let{sid:r,hostName:o,sort:n,limit:s,skip:i}=k(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:L(r)}}:void 0)},Ar=async e=>C(await v(R(e),t=>t.json()),async t=>gt(await O(t,["NotFoundError","NotLoggedInError","NotMemberError"]),t)),Ke=async(e,t)=>ye(await k(t??{})?.fetch(Sr(e,t)),Ar);Ke.toRequest=Sr;Ke.fromResponse=Ar;var Fr=(e,t)=>{let{sid:r,hostName:o}=k(t??{});return new Request(https://${o}/api/projects/${e},r?{headers:{Cookie:L(r)}}:void 0)},Mr=async e=>v(await C(R(e),async t=>await O(t,["NotFoundError","NotLoggedInError","NotMemberError"])??t),t=>t.json()),Ge=async(e,t)=>{let{fetch:r}=k(t??{}),o=Fr(e,t),n=await r(o);return h(n)?n:Mr(g(n))};Ge.toRequest=Fr;Ge.fromResponse=Mr;var _r=(e,t)=>{let{sid:r,hostName:o}=k(t??{}),n=new URLSearchParams(e.map(s=>["ids",s]));return new Request(https://${o}/api/projects?${n},r?{headers:{Cookie:L(r)}}:void 0)},Dr=async e=>v(await C(R(e),async t=>await O(t,["NotLoggedInError"])??t),t=>t.json()),Br=async(e,t)=>{let{fetch:r}=k(t??{}),o=await r(_r(e,t));return h(o)?o:Dr(g(o))};Br.toRequest=_r;Br.fromResponse=Dr;var xt=async(e,t,r)=>{let[o,n,s]=await Promise.all([qe(e,t,r),Ti(r),Ni(e,r)]);return h(o)?o:h(n)?n:h(s)?s:b({...g(o),projectId:g(s),userId:g(n)})},yt,Ti=async e=>{if(yt)return b(yt);let t=await Ee(e);if(h(t))return t;let r=g(t);return"id"in r?(yt=r.id,b(r.id)):I({name:"NotLoggedInError",message:"This script cannot be used without login"})},Hr=new Map,Ni=async(e,t)=>{let r=Hr.get(e);return r?b(r):Be(await Ge(e,t),({id:o})=>(Hr.set(e,o),o))};var Q=async(e,t,r,o)=>{let n=await He(o?.socket);if(h(n))return I({name:"UnexpectedRequestError",error:pe(n)});let s=g(n),i=await xt(e,t);if(h(i))return i;let a=g(i);try{let c=0,u=[],l;for(;o?.maxAttempts===void 0||c<o.maxAttempts;){let m=r(a,c,u,l);if(u=m instanceof Promise?await m:m,c++,u.length===0)return b(a.commitId);let f={kind:"page",projectId:a.projectId,pageId:a.id,parentId:a.commitId,userId:a.userId,changes:u,cursor:null,freeze:!0};for(;;){let w=await wr(s,"commit",f);if(ce(w))return a.commitId=g(w).commitId,b(a.commitId);let d=pe(w),p=d.name;if(p==="SocketIOServerDisconnectError"||p==="UnexpectedRequestError")return I(d);if(p==="TimeoutError"||p==="SocketIOError"){await ee(3e3);continue}if(p==="NotFastForwardError"){await ee(1e3);let N=await xt(e,t);if(h(N))return N;a=g(N)}l=p;break}}return I({name:"RetryError",attempts:c,message:Retrying exceeded the maxAttempts (${c}).`})}finally{o?.socket||await xe(s)}};var Et=(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,A){let M=Math.max(N,A),Te=M-p;for(;Te<o.length&&M<n.length&&oTe===nM;)++Te,++M;return ap+s=c.length,c.push([{x:Te,y:M},ap+(N>A?-1:1)+s]),M}let l=new Array(i);l.fill(-1);let m=-1,f=n.length-o.length;do{++m;for(let p=-m;p<=f-1;++p)lp+s=u(p,lp-1+s+1,lp+1+s);for(let p=f+m;p>=f+1;--p)lp+s=u(p,lp-1+s+1,lp+1+s);lf+s=u(f,lf-1+s+1,lf+1+s)}while(lf+s!==n.length);let w=[],d=af+s;for(;d!==-1;)w.push(cd0),d=cd 1;return{from:e,to:t,editDistance:f+m*2,buildSES:function*(){let p=0,N=0;for(let{x:A,y:M}of vi(w))for(;p<A||N<M;)M-A>N-p?(yield{value:nN,type:r?"deleted":"added"},++N):M-A<N-p?(yield{value:op,type:r?"added":"deleted"},++p):(yield{value:op,type:"common"},++p,++N)}}};function*bt(e){let t=[],r=[];function*o(){if(t.length>r.length){for(let n=0;n<r.length;n++)yield jr(tn,rn);for(let n=r.length;n<t.length;n++)yield tn}else{for(let n=0;n<t.length;n++)yield jr(tn,rn);for(let n=t.length;n<r.length;n++)yield rn}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 jr=(e,t)=>({value:e.value,oldValue:t.value,type:"replaced"});function*vi(e){for(let t=e.length-1;t>=0;t--)yield et}var $r=e=>e.padStart(8,"0"),kt=e=>{let t=Math.floor(new Date().getTime()/1e3).toString(16),r=Math.floor(16777214*Math.random()).toString(16);return${$r(t).slice(-8)}${e.slice(-6)}0000${$r(r)}};function*wt(e,t,{userId:r}){let{buildSES:o}=Et(e.map(({text:i})=>i),t),n=0,s=e0.id;for(let i of bt(o())){switch(i.type){case"added":yield{_insert:s,lines:{id:kt(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=en?.id??"_end"}}var Ri=(e,t)=>(e.type==="codeBlock"||e.type==="table")&&t.indent>(e.rows0?.indent??0),Ur=(e,t)=>{let r=ee.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)},qr=(e,t)=>{if(t.hasTitle??!0){letr,...o=e;return r===void 0?[]:[{type:"title",rows:r},...o.reduce(Ur,[])]}return e.reduce(Ur,[])};var Kr=e=>e.split(` ).map(t=>({indent:/^\s+/.exec(t)?.[0]?.length??0,text:t}));var Gr=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 x=(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)),m=e(c[0]??"",s);return[..._(u,s),...m,..._(l,s)]}return i?.()??[]};var E=e=>[{type:"plain",raw:e,text:e}],Yr=x(E,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]});var Li=/\[\s+\]/,Ci=(e,t)=>t.context==="table"?E(e,t):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],Wr=x(Ci,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Li]});var Ii=/.*?/,Oi=(e,t)=>t.context==="table"?E(e,t):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],zr=x(Oi,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ii]});var Si=/^[$%] .+$/,Ai=(e,t)=>{if(t.context==="table")return E(e,t);let r=e[0]??"",o=e.substring(2);return[{type:"commandLine",raw:e,symbol:r,text:o}]},Vr=x(Ai,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Si]});var Fi=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,Mi=(e,t)=>{if(t.context==="table")return E(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})}]},Qr=x(Mi,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Fi]});var _i=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,Di=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,Bi=/\[https?:\/\/[^\s\]]+\]/,Hi=/https?:\/\/[^\s]+/,ji=(e,t)=>{if(t.context==="table")return E(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()}]},Jr=x(ji,{parseOnNested:!0,parseOnQuoted:!0,patterns:[_i,Di,Bi,Hi]});var $i=/\[\$ .+? \]/,Ui=/\[\$ [^\]]+\]/,qi=(e,t)=>t.context==="table"?E(e,t):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],Xr=x(qi,{parseOnNested:!1,parseOnQuoted:!0,patterns:[$i,Ui]});var Zr=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,eo=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,Ki=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}},Gi=(e,t)=>{if(t.context==="table")return E(e,t);let r=e.match(Zr)??e.match(eo);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}=Ki(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}]},to=x(Gi,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Zr,eo]});var Yi=/(?:^|\s)#\S+/,Wi=(e,t)=>{if(t.context==="table")return E(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[...E(r,t),{type:"hashTag",raw:o,href:o.substring(1)}]},ro=x(Wi,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Yi]});var zi=/^\? .+$/,Vi=(e,t)=>t.context==="table"?E(e,t):[{type:"helpfeel",raw:e,text:e.substring(2)}],oo=x(Vi,{parseOnNested:!1,parseOnQuoted:!1,patterns:[zi]});var Qi=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/,Ji=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}))},no=x(Ji,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Qi]});var Xi=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,Zi=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,ea=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,ta=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,ra=e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(e)||oa(e),oa=e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),na=(e,t)=>{if(t.context==="table")return E(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]=ra(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}]},so=x(na,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Xi,Zi,ea,ta]});var sa=/\[\/?[^[\]]+\]/,ia=e=>{let t=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:t.startsWith("/")?"root":"relative",href:t,content:""}]},io=x(ia,{parseOnNested:!0,parseOnQuoted:!0,patterns:[sa]});var aa=/^[0-9]+\. .*$/,ca=(e,t)=>{if(t.context==="table")return E(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})}]},ao=x(ca,{parseOnNested:!1,parseOnQuoted:!1,patterns:[aa]});var pa=/^>.*$/,ua=(e,t)=>t.context==="table"?E(e,t):[{type:"quote",raw:e,nodes:_(e.substring(1),{...t,quoted:!0})}],co=x(ua,{parseOnNested:!1,parseOnQuoted:!1,patterns:[pa]});var la=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,da=(e,t)=>{if(t.context==="table")return E(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}))},po=x(da,{parseOnNested:!1,parseOnQuoted:!0,patterns:[la]});var ma=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,fa=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,ha=(e,t)=>{if(t.context==="table")return E(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}]},uo=x(ha,{parseOnNested:!1,parseOnQuoted:!0,patterns:[ma,fa]});var ga=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,ya=(e,t)=>t.context==="table"?E(e,t):[{type:"strong",raw:e,nodes:_(e.substring(2,e.length-2),{...t,nested:!0})}],lo=x(ya,{parseOnNested:!1,parseOnQuoted:!0,patterns:[ga]});var xa=(e,t,r)=>e===""?[]:r?.()??[],Ea=(...e)=>(t,r)=>e.reduceRight((o,n)=>()=>n(t,r,o),()=>Yr(t,r))(),_=Ea(xa,co,oo,ao,zr,Vr,Xr,Wr,Qr,uo,po,lo,so,Jr,no,to,io,ro);var mo=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 fo=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 ho=e=>({type:"title",text:e.rows[0].text});var go=e=>{switch(e.type){case"title":return ho(e);case"codeBlock":return Gr(e);case"table":return fo(e);case"line":return mo(e)}};var Pt=(e,t)=>{let r=Kr(e);return qr(r,{hasTitle:t?.hasTitle??!0}).map(go)};var ba=/https?:\/\/(?:www\.|music\.|)youtube\.com\/watch/,ka=/https?:\/\/youtu\.be\/([a-zA-Z\d_-]+)(?:\?([^\s]{0,100})|)/,wa=/https?:\/\/(?:www\.|)youtube\.com\/shorts\/([a-zA-Z\d_-]+)(?:\?([^\s]+)|)/,Pa=/https?:\/\/(?:www\.|music\.|)youtube\.com\/playlist\?((?:[^\s]+&|)list=([a-zA-Z\d_-]+)(?:&[^\s]+|))/,yo=e=>{if(ba.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(ka);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(Pa);if(t){let[,r,o]=t;return{listId:o,params:new URLSearchParams(r),pathType:"list"}}}};var Eo=e=>{let t=Pt(e,{hasTitle:!0}).flatMap(d=>{switch(d.type){case"codeBlock":case"title":return[];case"line":case"table":return d}}),r=new Map,o=[],n=new Set,s=[],i=new Set,a=[],c=null,u=new Set,l=new Set,m=new RegExp(${location?.origin??"https://scrapbox.io"}/files/([a-z0-9]{24})(?:|\\.[a-zA-Z0-9]+)(?:|\\?[^\\s]*)$),f=d=>{switch(d.type){case"hashTag":if(r.has(q(d.href)))return;r.set(q(d.href),!1),o.push(d.href);return;case"link":switch(d.pathType){case"relative":{let p=xo(d.href);if(r.get(q(p)))return;r.set(q(p),!0),o.push(p);return}case"root":{let p=xo(d.href);if(/^\/[\w\d-]+\/?$/.test(p)||n.has(q(p)))return;n.add(q(p)),s.push(p);return}case"absolute":{if(d.content)return;let p=yo(d.href);if(p&&p.pathType!=="list"){c??=https://i.ytimg.com/vi/${p.videoId}/mqdefault.jpg;return}let N=d.href.match(m)?.[1];N&&u.add(N);return}default:return}case"icon":case"strongIcon":{if(d.pathType==="root"||i.has(q(d.path)))return;i.add(q(d.path)),a.push(d.path);return}case"image":case"strongImage":{c??=d.src.endsWith("/thumb/1000")?d.src.replace(/\/thumb\/1000$/,"/raw"):d.src;{let p=d.src.match(m)?.[1];p&&u.add(p)}if(d.type==="image"){let p=d.link.match(m)?.[1];p&&u.add(p)}return}case"helpfeel":l.add(d.text);return;case"numberList":case"strong":case"quote":case"decoration":{for(let p of d.nodes)f(p);return}default:return}},w=[];for(let d of t)switch(d.type){case"line":for(let p of d.nodes)f(p);continue;case"table":{for(let p of d.cells)for(let N of p)for(let A of N)f(A);if(!["infobox","cosense"].includes(d.fileName))continue;w.push(...d.cells.map(p=>p.map(N=>N.map(A=>A.raw).join("")).join(" ").trim()));continue}}return[o,s,a,c,[...u],[...l],w]},xo=e=>e.replace(/#[a-f\d]{24,32}$/,""),bo=e=>e.flatMap(({text:t})=>/^\s*\? .*$/.test(t)?[t.trimStart().slice(2)]:[]);var te=(e,t)=>e.length===t.length&&e.every(r=>t.includes(r));function*ko(e,t,r){let o=t.flatMap(w=>w.split( ));for(let w of wt(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,m,f]=Eo(o.join(
));te(e.links,i)||(yield{links:i}),te(e.projectLinks,a)||(yield{projectLinks:a}),te(e.icons,c)||(yield{icons:c}),e.image!==u&&(yield{image:u}),te(e.files,l)||(yield{files:l}),te(bo(e.lines),m)||(yield{helpfeels:m}),te(e.infoboxDefinition,f)||(yield{infoboxDefinition:f})}var wo=e=>{let t=e.match(/(.+?)(?:_(\d+))?$/),r=t?.[1]??e,o=t?.[2]?parseInt(t[2])+1:2;return${r}_${o}};var Po=(e,t,r,o)=>Q(e,t,async(n,s,i,a)=>{if(a==="DuplicateTitleError"){let l=wo(t);return i.map(m=>("title"in m&&(m.title=l),m))}let c=r(n.lines,{...n,attempts:s}),u=c instanceof Promise?await c:c;return u===void 0?[]:u.length===0?[{deleted:!0}]:[...ko(n,u,n.userId)]},o);var To=(e,t,r)=>Q(e,t,o=>{if(o.pin>0||!o.persistent&&!(r?.create??!1))return[];let n=[{pin:Ta()}];return o.persistent||n.unshift({title:t}),n},r),No=(e,t,r)=>Q(e,t,o=>o.pin==0||!o.persistent?[]:[{pin:0}],r),Ta=()=>Number.MAX_SAFE_INTEGER-Math.floor(Date.now()/1e3);var Ra=Math.pow(10,8)*24*60*60*1e3,hy=-Ra,La=3600,Ro=La*24,gy=Ro*7,Ca=Ro*365.2425,Ia=Ca/12,yy=Ia*3,vo=Symbol.for("constructDateFrom");function Oa(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&vo in e?e[vo](t):e instanceof Date?new e.constructor(t):new Date(t)}function Sa(e,t){return Oa(t||e,e)}function Tt(e,t){return Sa(e,t?.in).getFullYear()}var Aa=Math.pow(10,8)*24*60*60*1e3,Py=-Aa,Fa=6048e5,Ma=3600,Co=Ma*24,Ty=Co*7,_a=Co*365.2425,Da=_a/12,Ny=Da*3,Lo=Symbol.for("constructDateFrom"),Ba={};function Nt(){return Ba}function Ye(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Lo in e?e[Lo](t):e instanceof Date?new e.constructor(t):new Date(t)}function vt(e,t){return Ye(t||e,e)}function We(e,t){let r=Nt(),o=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,n=vt(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 Ha(e,t){let r=vt(e,t?.in),o=r.getFullYear(),n=Nt(),s=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,i=Ye(t?.in||e,0);i.setFullYear(o+1,0,s),i.setHours(0,0,0,0);let a=We(i,t),c=Ye(t?.in||e,0);c.setFullYear(o,0,s),c.setHours(0,0,0,0);let u=We(c,t);return+r>=+a?o+1:+r>=+u?o:o-1}function ja(e,t){let r=Nt(),o=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??r.firstWeekContainsDate??r.locale?.options?.firstWeekContainsDate??1,n=Ha(e,t),s=Ye(t?.in||e,0);return s.setFullYear(n,0,o),s.setHours(0,0,0,0),We(s,t)}function be(e,t){let r=vt(e,t?.in),o=+We(r,t)-+ja(r,t);return Math.round(o/Fa)+1}var $a=Math.pow(10,8)*24*60*60*1e3,Oy=-$a,Ua=3600,Oo=Ua*24,Sy=Oo*7,qa=Oo*365.2425,Ka=qa/12,Ay=Ka*3,Io=Symbol.for("constructDateFrom");function Ga(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 Ya(e,t){return Ga(t||e,e)}function So(e,t){return Ya(e,t?.in).getDate()}var Wa=Math.pow(10,8)*24*60*60*1e3,Hy=-Wa,za=3600,Fo=za*24,jy=Fo*7,Va=Fo*365.2425,Qa=Va/12,$y=Qa*3,Ao=Symbol.for("constructDateFrom");function Ja(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Ao in e?e[Ao](t):e instanceof Date?new e.constructor(t):new Date(t)}function Xa(e,t){return Ja(t||e,e)}function Mo(e,t){return Xa(e,t?.in).getMonth()}var Rt=(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},Lt=(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},z=e=>${e}.padStart(2,"0"),Ct=e=>${Tt(e)},It=(e,t)=>${Ct(e)}${t}${z(Mo(e)+1)},_o=(e,t)=>${Tt(e)}${t}w${z(be(e))},ze=(e,t)=>${It(e,t)}${t}${z(So(e))};var Ot=(e,t,r)=>{let o=Rt(Rt(e,t).reverse(),[...r].reverse()).reverse(),n=Lt(o,t),s=o.length-1-Lt([...o].reverse(),[...r].reverse());return[...o.slice(0,n+1),"",...o.slice(n+1,s).join(
).trim().split(
),"",...o.slice(s)]};var Do=(e,t,r,o)=>{let{sid:n,hostName:s}=k(o??{}),i=https://${s}/api/table/${e}/${V(t)}/${encodeURIComponent(r)}.csv;return new Request(i,n?{headers:{Cookie:L(n)}}:void 0)},Bo=async e=>v(await C(R(e),async t=>t.response.status===404?{name:"NotFoundError",message:"Table not found."}:await O(t,["NotLoggedInError","NotMemberError"])??t),t=>t.text()),Ho=async(e,t,r,o)=>{let{fetch:n}=k(o??{}),s=Do(e,t,r,o),i=await n(s);return h(i)?i:await Bo(g(i))};Ho.toRequest=Do;Ho.fromResponse=Bo;var jo=(e,t)=>{let{sid:r,hostName:o,followingId:n}=k(t??{});return new Request(https://${o}/api/pages/${e}/search/titles${n??followingId=${n}:""},r?{headers:{Cookie:L(r)}}:void 0)},$o=async e=>v(await C(R(e),async t=>t.response.status===422?{name:"InvalidFollowingIdError",message:await t.response.text()}:await O(t,["NotFoundError","NotLoggedInError"])??t),t=>t.json().then(r=>({pages:r,followingId:t.headers.get("X-following-id")??""}))),Uo=async(e,t)=>{let r=await k(t??{}).fetch(jo(e,t));return h(r)?r:$o(g(r))};Uo.toRequest=jo;Uo.fromResponse=$o;var qo=(e,t,r,o)=>{let{sid:n,hostName:s}=k(o??{});return new Request(https://${s}/api/code/${e}/${V(t)}/${V(r)},n?{headers:{Cookie:L(n)}}:void 0)},Ko=async e=>v(await C(R(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 O(t,["NotLoggedInError","NotMemberError"])??t),t=>t.text()),ue=async(e,t,r,o)=>{let n=qo(e,t,r,o),s=await k(o??{}).fetch(n);return h(s)?s:Ko(g(s))};ue.toRequest=qo;ue.fromResponse=Ko;var pE=new TextEncoder;var mE=new TextEncoder().encode("0123456789abcdef"),fE=new TextEncoder,hE=new TextDecoder;async function*Go(e,t){let r=0,o=t?.limit??100;for(;;){let n=await Ke(e,{...t,limit:o,sort:"updated",skip:r});if(h(n))return;let s=g(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,ke=e=>!e.ok,St=(e,t,r,o)=>({ok:!0,location:e,value:t,furthest:r,expected:o}),Qe=(e,t)=>({ok:!1,furthest:e,expected:t});var At=e=>({index:e[0],line:e[1],column:e[2]}),j=(e,t,r)=>St(Yo(e,t),r,[-1,-1,-1],[]),re=(e,t,r)=>Qe(Yo(e,t),r),X=(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)?St(t.location,t.value,e.furthest,o):Qe(e.furthest,o)},Yo=(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 oe=(e,t)=>r=>{let o=e(r);if(ke(o))return o;let n=t(o.value);return X(o,n([r[0],o.location]))};var S=e=>t=>j(t,t[1][0],e);var D=(e,t)=>oe(e,r=>S(t(r)));var Je=(...e)=>e.reduce((t,r)=>oe(t,o=>D(r,n=>[...o,n])),S([]));var G=(e,t)=>r=>{let o=e(r);if(ke(o))return o;r=[r[0],o.location];let n=X(o,t(r));if(J(n)){let s=[o.value,n.value];return X(n,j(r,n.location[0],s))}return n};var B=(e,t)=>r=>{let o=e(r);return J(o)?o:X(o,t(r))};var Ft=(...e)=>e.reduce((t,r)=>B(t,r));var Wo="<EOF>",zo=e=>{let[t,[r]]=e;return r<t.length?re(e,r,[Wo]):j(e,r,Wo)};var Xe=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 j(r,i,a)}return re(r,n,[${e}])}};var Y=(e,t)=>D(G(e,t),([,r])=>r);var Mt=(e,t)=>D(G(e,t),([r])=>r);var Vo=(e,t)=>{let r=Mt(e,zo)([t,[0,1,1]]);return r.ok?{ok:!0,value:r.value}:{ok:!1,location:At(r.furthest),expected:r.expected}};var T=e=>t=>{let[r,[o]]=t,n=o+e.length;return r.slice(o,n)==e?j(t,n,e):re(t,o,[e])};var Qo=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 ec=Math.pow(10,8)*24*60*60*1e3,$k=-ec,tc=3600,Xo=tc*24,Uk=Xo*7,rc=Xo*365.2425,oc=rc/12,qk=oc*3,Jo=Symbol.for("constructDateFrom");function nc(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Jo in e?e[Jo](t):e instanceof Date?new e.constructor(t):new Date(t)}function sc(e,t){return nc(t||e,e)}function Zo(e,t){return sc(e,t?.in).getHours()}var ic=Math.pow(10,8)*24*60*60*1e3,Vk=-ic,ac=3600,tn=ac*24,Qk=tn*7,cc=tn*365.2425,pc=cc/12,Jk=pc*3,en=Symbol.for("constructDateFrom");function uc(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 lc(e,t){return uc(t||e,e)}function rn(e,t){return lc(e,t?.in).getMinutes()}var dc=Math.pow(10,8)*24*60*60*1e3,ow=-dc,mc=3600,nn=mc*24,nw=nn*7,fc=nn*365.2425,hc=fc/12,sw=hc*3,on=Symbol.for("constructDateFrom");function gc(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&on in e?e[on](t):e instanceof Date?new e.constructor(t):new Date(t)}function yc(e,t){return gc(t||e,e)}function sn(e){return yc(e).getSeconds()}var xc=Math.pow(10,8)*24*60*60*1e3,lw=-xc,Ec=3600,cn=Ec*24,dw=cn*7,bc=cn*365.2425,kc=bc/12,mw=kc*3,an=Symbol.for("constructDateFrom");function pn(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&an in e?e[an](t):e instanceof Date?new e.constructor(t):new Date(t)}function wc(e,t){return pn(t||e,e)}function _t(e,t,r){let o=wc(e,r?.in);return isNaN(t)?pn(r?.in||e,NaN):(t&&o.setDate(o.getDate()+t),o)}var Pc=Math.pow(10,8)*24*60*60*1e3,Ew=-Pc,Tc=3600,ln=Tc*24,bw=ln*7,Nc=ln*365.2425,vc=Nc/12,kw=vc*3,un=Symbol.for("constructDateFrom");function Dt(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&un in e?e[un](t):e instanceof Date?new e.constructor(t):new Date(t)}function Rc(e,t){return Dt(t||e,e)}function dn(e,t,r){let o=Rc(e,r?.in);if(isNaN(t))return Dt(r?.in||e,NaN);if(!t)return o;let n=o.getDate(),s=Dt(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 Lc=Math.pow(10,8)*24*60*60*1e3,Rw=-Lc,Cc=3600,fn=Cc*24,Lw=fn*7,Ic=fn*365.2425,Oc=Ic/12,Cw=Oc*3,mn=Symbol.for("constructDateFrom");function hn(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 Sc(e,t){return hn(t||e,e)}function Ac(e,t,r){let o=Sc(e,r?.in);return isNaN(t)?hn(r?.in||e,NaN):(t&&o.setDate(o.getDate()+t),o)}function gn(e,t,r){return Ac(e,t*7,r)}var Fc=Math.pow(10,8)*24*60*60*1e3,Mw=-Fc,Mc=3600,xn=Mc*24,_w=xn*7,_c=xn*365.2425,Dc=_c/12,Dw=Dc*3,yn=Symbol.for("constructDateFrom");function Bt(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&yn in e?e[yn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Bc(e,t){return Bt(t||e,e)}function Hc(e,t,r){let o=Bc(e,r?.in);if(isNaN(t))return Bt(r?.in||e,NaN);if(!t)return o;let n=o.getDate(),s=Bt(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 En(e,t,r){return Hc(e,t*12,r)}var jc={};function $c(){return jc}var Uc=Math.pow(10,8)*24*60*60*1e3,qw=-Uc,qc=3600,kn=qc*24,Kw=kn*7,Kc=kn*365.2425,Gc=Kc/12,Gw=Gc*3,bn=Symbol.for("constructDateFrom");function Yc(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&bn in e?e[bn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Wc(e,t){return Yc(t||e,e)}function wn(e,t){let r=$c(),o=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,n=Wc(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 Tn=e=>${z(Zo(e))},Nn=e=>${Tn(e)}:${z(rn(e))},zc=e=>${Nn(e)}:${z(sn(e))},Vc=T("yyyy"),Qc=T("MM"),Jc=T("dd"),Xc=T("ww"),Zc=T("HH"),ep=T("mm"),tp=T("ss"),rp=Xe(/\s/),op=Xe(/[^Mw]?/),Pn=T(":"),np=Y(Zc,B(Y(G(Pn,ep),B(Y(G(Pn,tp),S(zc)),S(Nn))),S(Tn))),sp=D(Xe(/[-+]\d+/),e=>parseInt(e)),ip=Ft(T("y"),T("m"),T("d"),T("w"),T("")),ap=G(sp,ip),cp=T("("),pp=T(")"),up=D(Je(cp,Ft(T("Sun"),T("Mon"),T("Tue"),T("Wed"),T("Thu"),T("Fri"),T("Sat")),pp),([,e])=>Qo(e)),lp=Y(Vc,B(oe(op,e=>{let t=T(e);return B(Y(Qc,B(Y(G(t,Jc),S(r=>ze(r,e))),S(r=>It(r,e)))),Y(Xc,S(r=>_o(r,e))))}),S(Ct))),vn=e=>Vo(D(Je(lp,D(B(ap,S([0,"d"])),([t,r])=>o=>dp(o,t,r)),B(up,S(void 0)),B(G(rp,np),S(["",()=>""]))),([t,r,o,[n,s]])=>i=>{let a=r(i),c=o!==void 0?_t(wn(a),o):a;return${t(c)}${n}${s(c)}}),e.slice(1,-1)),dp=(e,t,r)=>{switch(r){case"y":return En(e,t);case"m":return dn(e,t);case"w":return gn(e,t);case"d":case"":return _t(e,t)}};var mp=Math.pow(10,8)*24*60*60*1e3,p0=-mp,fp=864e5,hp=3600,In=hp*24,u0=In*7,gp=In*365.2425,yp=gp/12,l0=yp*3,Rn=Symbol.for("constructDateFrom");function On(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 Ze(e,t){return On(t||e,e)}function Ln(e){let t=Ze(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 xp(e,...t){let r=On.bind(null,e||t.find(o=>typeof o=="object"));return t.map(r)}function Cn(e,t){let r=Ze(e,t?.in);return r.setHours(0,0,0,0),r}function Ep(e,t,r){let[o,n]=xp(r?.in,e,t),s=Cn(o),i=Cn(n),a=+s-Ln(s),c=+i-Ln(i);return Math.round((a-c)/fp)}function bp(e,t){let r=Ze(e,t?.in);return r.setFullYear(r.getFullYear(),0,1),r.setHours(0,0,0,0),r}function Sn(e,t){let r=Ze(e,t?.in);return Ep(r,bp(r))+1}var kp=Math.pow(10,8)*24*60*60*1e3,y0=-kp,wp=3600,Fn=wp*24,x0=Fn*7,Pp=Fn*365.2425,Tp=Pp/12,E0=Tp*3,An=Symbol.for("constructDateFrom");function Np(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&An in e?e[An](t):e instanceof Date?new e.constructor(t):new Date(t)}function Mn(e,t){return Np(t||e,e)}function vp(e,t){let r=Mn(e,t?.in).getFullYear();return r%400===0||r%4===0&&r%100!==0}function _n(e,t){let r=Mn(e,t?.in);return Number.isNaN(+r)?NaN:vp(r)?366:365}var Rp=Math.pow(10,8)*24*60*60*1e3,N0=-Rp,Lp=864e5,Cp=6e4,Ip=36e5,Op=3600,$n=Op*24,v0=$n*7,Sp=$n*365.2425,Ap=Sp/12,R0=Ap*3,Dn=Symbol.for("constructDateFrom");function le(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Dn in e?e[Dn](t):e instanceof Date?new e.constructor(t):new Date(t)}function Z(e,...t){let r=le.bind(null,e||t.find(o=>typeof o=="object"));return t.map(r)}function Fp(e,t){let[r,o]=Z(e,t.start,t.end);return{start:r,end:o}}function $(e,t){return le(t||e,e)}function Mp(e,t,r){let o=$(e,r?.in);return isNaN(t)?le(r?.in||e,NaN):(t&&o.setDate(o.getDate()+t),o)}function _p(e,t,r){let o=$(e,r?.in);if(isNaN(t))return le(r?.in||e,NaN);if(!t)return o;let n=o.getDate(),s=le(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 we(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=$(e,r?.in),m=n||o?_p(l,n+o*12):l,f=i||s?Mp(m,i+s*7):m,w=c+a*60,d=(u+w*60)*1e3;return le(r?.in||e,+f+d)}function Bn(e){let t=$(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 Hn(e,t){let r=$(e,t?.in);return r.setHours(0,0,0,0),r}function Dp(e,t,r){let[o,n]=Z(r?.in,e,t),s=Hn(o),i=Hn(n),a=+s-Bn(s),c=+i-Bn(i);return Math.round((a-c)/Lp)}function Bp(e,t,r){let[o,n]=Z(r?.in,e,t),s=jn(o,n),i=Math.abs(Dp(o,n));o.setDate(o.getDate()-s*i);let a=+(jn(o,n)===-s),c=s*(i-a);return c===0?0:c}function jn(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 Ht(e){return t=>{let r=(e?Math[e]:Math.trunc)(t);return r===0?0:r}}function Hp(e,t,r){let[o,n]=Z(r?.in,e,t),s=(+o-+n)/Ip;return Ht(r?.roundingMethod)(s)}function Un(e,t){return+$(e)-+$(t)}function jp(e,t,r){let o=Un(e,t)/Cp;return Ht(r?.roundingMethod)(o)}function Pe(e,t){let r=+$(e)-+$(t);return r<0?-1:r>0?1:r}function $p(e,t,r){let[o,n]=Z(r?.in,e,t),s=o.getFullYear()-n.getFullYear(),i=o.getMonth()-n.getMonth();return s*12+i}function Up(e,t){let r=$(e,t?.in);return r.setHours(23,59,59,999),r}function qp(e,t){let r=$(e,t?.in),o=r.getMonth();return r.setFullYear(r.getFullYear(),o+1,0),r.setHours(23,59,59,999),r}function Kp(e,t){let r=$(e,t?.in);return+Up(r,t)==+qp(r,t)}function Gp(e,t,r){let[o,n,s]=Z(r?.in,e,e,t),i=Pe(n,s),a=Math.abs($p(n,s));if(a<1)return 0;n.getMonth()===1&&n.getDate()>27&&n.setDate(30),n.setMonth(n.getMonth()-i*a);let c=Pe(n,s)===-i;Kp(o)&&a===1&&Pe(o,s)===1&&(c=!1);let u=i*(a-+c);return u===0?0:u}function Yp(e,t,r){let o=Un(e,t)/1e3;return Ht(r?.roundingMethod)(o)}function Wp(e,t,r){let[o,n]=Z(r?.in,e,t);return o.getFullYear()-n.getFullYear()}function zp(e,t,r){let[o,n]=Z(r?.in,e,t),s=Pe(o,n),i=Math.abs(Wp(o,n));o.setFullYear(1584),n.setFullYear(1584);let a=Pe(o,n)===-s,c=s*(i-+a);return c===0?0:c}function qn(e,t){let{start:r,end:o}=Fp(t?.in,e),n={},s=zp(o,r);s&&(n.years=s);let i=we(r,{years:n.years}),a=Gp(o,i);a&&(n.months=a);let c=we(i,{months:n.months}),u=Bp(o,c);u&&(n.days=u);let l=we(c,{days:n.days}),m=Hp(o,l);m&&(n.hours=m);let f=we(l,{hours:n.hours}),w=jp(o,f);w&&(n.minutes=w);let d=we(f,{minutes:n.minutes}),p=Yp(o,d);return p&&(n.seconds=p),n}var Vp=Math.pow(10,8)*24*60*60*1e3,A0=-Vp,Qp=3600,Gn=Qp*24,F0=Gn*7,Jp=Gn*365.2425,Xp=Jp/12,M0=Xp*3,Kn=Symbol.for("constructDateFrom");function jt(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 Zp(e,t){return jt(t||e,e)}function eu(e,t,r){let o=Zp(e,r?.in);if(isNaN(t))return jt(r?.in||e,NaN);if(!t)return o;let n=o.getDate(),s=jt(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 tu(e,t,r){return eu(e,t*12,r)}function Yn(e,t,r){return tu(e,-t,r)}var ru=Math.pow(10,8)*24*60*60*1e3,$0=-ru,ou=3600,zn=ou*24,U0=zn*7,nu=zn*365.2425,su=nu/12,q0=su*3,Wn=Symbol.for("constructDateFrom");function iu(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 iu(t||e,e)}function Vn(e,t){return au(e,t?.in).getDay()}var de=(e,t)=>t.split(
).flatMap(r=>r.replaceAll("@w@",${be(e)}).replaceAll("@ww@",${z(be(e))}).replaceAll("@day_indicator@",${cu(e)}).replaceAll("@progress@",${(Sn(e)*100/_n(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)),m=qn({start:l,end:e}).years??0;return[...Array(m).keys()].map(f=>${n}${ze(Yn(e,f+1),i??c??"")}).join( )}).replace(/@[^@]+@/g,o=>{let n=vn(o);return n.ok?n.value(e):o}).split(
)),cu=e=>{let t=Vn(e);return[..."日月火水木金土"].map((r,o)=>o===t?${r}:r).join("")};var Qn=async(e,t)=>{let r=await ue(e,t,"title");if(h(r))return r;let o=await ue(e,t,"header");if(h(o))return o;let n=await ue(e,t,"footer");return h(n)?n:b({title:g(r),header:g(o),footer:g(n)})},$t=e=>({makeDiary:t=>({title:de(t,e.title)[0],header:de(t,e.header),footer:de(t,e.footer)}),isOldDiary:(t,r)=>de(r,t)[0]!==t});var Xn=(e,t)=>{let r=t.interval??864e5,o,n=async()=>{s(),await Jn(e,new Date,t),o=setInterval(()=>Jn(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)}},Jn=async(e,t,r)=>{let{render:o,dispose:n}=Yt(),s;try{let i;if("title"in r)if("header"in r)i=$t(r);else{let m=await Qn(r.project??e,r.title);if(ce(m))i=$t(g(m));else{let f=pe(m),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,f);return}}else i=r;let{makeDiary:a,isOldDiary:c}=i,u=await ye(await He(),async m=>{s=m,o({type:"spinner"},{type:"text",text:"unpin other diary pages..."});for await(let{title:A}of Go(e)){if(!c(A,t))continue;let M=await No(e,A,{socket:s});if(h(M))return M}let{title:f,header:w,footer:d}=a(t);o({type:"spinner"},{type:"text",text:pin "/${e}/${f}"...});let p=await To(e,f,{socket:s,create:!0});if(h(p))return p;o({type:"spinner"},{type:"text",text:format "/${e}/${f}"...});let N=await Po(e,f,A=>[A[0].text,...Ot(A.slice(1).map(M=>M.text),w,d)],{socket:s});return h(N)?N:(o({type:"check-circle"},{type:"text",text:Pinned "/${e}/${f}".}),await xe(s),b(void 0))});if(ce(u))return;let l=pe(u);o({type:"exclamation-triangle"},{type:"text",text:W(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 xe(s),await ee(1e3),n()}};Xn("caki",{project:"caki",title:"pin-diary-template"});