pin-diary-6-min
code: script.js
var ye=(e,r)=>{let t=0,n=[];for(let o=0;o<r.length;o++){let s=e.findIndex((a,i)=>i>=t&&a.trim()===ro.trim());if(s<0){n.push(ro);continue}n.push(...e.slice(t,s+1)),t=s+1}return n.push(...e.slice(t)),n},be=(e,r)=>{let t=-1;for(let n of r){let o=e.findIndex((s,a)=>a>t&&s.trim()===n.trim());if(o<0)return-1;t=o}return t};var Ee=(e,r,t)=>{let n=ye(ye(e,r).reverse(),...t.reverse()).reverse(),o=be(n,r),s=n.length-1-be(...n.reverse(),...t.reverse());return[...n.slice(0,o+1),"",...n.slice(o+1,s).join(` ).trim().split(
),"",...n.slice(s)]};var b=e=>{let{fetch:r=globalThis.fetch,hostName:t="scrapbox.io",...n}=e;return{fetch:r,hostName:t,...n}};var tr=e=>typeof e=="object"&&e!==null,rr=e=>tr(e)?(e.name===void 0||typeof e.name=="string")&&typeof e.message=="string":!1,ot=e=>{try{let r=typeof e=="string"?JSON.parse(e):e;return rr(r)?r:!1}catch(r){if(r instanceof SyntaxError)return!1;throw r}};var q=class extends Error{constructor(r){super(${r.status} ${r.statusText} when fetching ${r.url});this.response=r;this.name="UnexpectedResponseError";Error.captureStackTrace&&Error.captureStackTrace(this,q)}},L=async e=>{let r=e.clone(),t=await r.text(),n=ot(t);if(!n)throw new q(r);return{ok:!1,value:n}};var we=async e=>{let{sid:r,hostName:t,fetch:n}=b(e??{}),o=new Request(https://${t}/api/users/me,r?{headers:{Cookie:k(r)}}:void 0),s=await n(o);if(!s.ok)throw new q(s);return await s.json()};var k=e=>connect.sid=${e};var C=e=>e.replaceAll(" ","_").toLowerCase();var N=e=>[...e].map((r,t)=>r===" "?"_":!nr.includes(r)||t===e.length-1&&or.includes(r)?encodeURIComponent(r):r).join(""),nr='@$&+=:;",',or=':;",';var st=(e,r,t)=>{let{sid:n,hostName:o,followRename:s,projects:a}=b(t??{}),i=new URLSearchParams;i.append("followRename",${s??!0});for(let m of a??[])i.append("projects",m);let d=https://${o}/api/pages/${e}/${N(r)}?${i.toString()};return new Request(d,n?{headers:{Cookie:k(n)}}:void 0)},it=async e=>{if(!e.ok)return e.status===414?{ok:!1,value:{name:"TooLongURIError",message:"project ids may be too much."}}:L(e);let r=await e.json();return{ok:!0,value:r}},oe=async(e,r,t)=>{let{fetch:n}=b(t??{}),o=st(e,r,t),s=await n(o);return await it(s)};oe.toRequest=st;oe.fromResponse=it;var at=(e,r)=>{let{sid:t,hostName:n,sort:o,limit:s,skip:a}=b(r??{}),i=new URLSearchParams;o!==void 0&&i.append("sort",o),s!==void 0&&i.append("limit",${s}),a!==void 0&&i.append("skip",${a});let d=https://${n}/api/pages/${e}?${i.toString()};return new Request(d,t?{headers:{Cookie:k(t)}}:void 0)},ct=async e=>{if(!e.ok)return L(e);let r=await e.json();return{ok:!0,value:r}},Q=async(e,r)=>{let{fetch:t}=b(r??{}),n=await t(at(e,r));return await ct(n)};Q.toRequest=at;Q.fromResponse=ct;var dt=(e,r,t,n)=>{let{sid:o,hostName:s}=b(n??{}),a=https://${s}/api/table/${e}/${N(r)}/${encodeURIComponent(t)}.csv;return new Request(a,o?{headers:{Cookie:k(o)}}:void 0)},lt=async e=>e.ok?{ok:!0,value:await e.text()}:e.status===404?{ok:!1,value:{name:"NotFoundError",message:"Table not found."}}:L(e),ut=async(e,r,t,n)=>{let{fetch:o}=b(n??{}),s=dt(e,r,t,n),a=await o(s);return await lt(a)};ut.toRequest=dt;ut.fromResponse=lt;var pt=(e,r)=>{let{sid:t,hostName:n}=b(r??{});return new Request(https://${n}/api/projects/${e},t?{headers:{Cookie:k(t)}}:void 0)},mt=async e=>{if(!e.ok)return L(e);let r=await e.json();return{ok:!0,value:r}},se=async(e,r)=>{let{fetch:t}=b(r??{}),n=pt(e,r),o=await t(n);return mt(o)};se.toRequest=pt;se.fromResponse=mt;var ft=(e,r)=>{let{sid:t,hostName:n}=b(r??{}),o=new URLSearchParams;for(let s of e)o.append("ids",s);return new Request(https://${n}/api/projects?${o.toString()},t?{headers:{Cookie:k(t)}}:void 0)},gt=async e=>{if(!e.ok)return L(e);let r=await e.json();return{ok:!0,value:r}},ht=async(e,r)=>{let{fetch:t}=b(r??{}),n=await t(ft(e,r));return gt(n)};ht.toRequest=ft;ht.fromResponse=gt;var ae=async(e,r)=>{let t=await oe(e,r);if(!t.ok)throw new Error(You have no privilege of editing "/${e}/${r}".);return t.value};var xt=(e,r,t,n)=>{let{sid:o,hostName:s}=b(n??{}),a=https://${s}/api/code/${e}/${N(r)}/${N(t)};return new Request(a,o?{headers:{Cookie:k(o)}}:void 0)},yt=async e=>e.ok?{ok:!0,value:await e.text()}:e.status===404&&e.headers.get("Content-Type")?.includes?.("text/plain")?{ok:!1,value:{name:"NotFoundError",message:"Code block is not found"}}:L(e),bt=async(e,r,t,n)=>{let{fetch:o}=b(n??{}),s=xt(e,r,t,n),a=await o(s);return await yt(a)};bt.toRequest=xt;bt.fromResponse=yt;var Et=new TextEncoder().encode("0123456789abcdef");function wt(e){let r=new Uint8Array(e.length*2);for(let t=0;t<r.length;t++){let n=e[t];r[t*2]=Et[n>>4],r[t*2+1]=Et[n&15]}return r}var kt="md5: data is invalid type",B=64,ke=class{#e;#t;#r;#n;#o;#i;#s;#a;constructor(){this.#e=1732584193,this.#t=4023233417,this.#r=2562383102,this.#n=271733878,this.#o=new Uint8Array(B),this.#i=0,this.#s=0,this.#a=0}#d(r){let t=this.#s;t+=r,t>4294967295&&(this.#a+=1),this.#s=t>>>0}#c(r){let t=this.#e,n=this.#t,o=this.#r,s=this.#n,a=F=>r[F]|r[F+1]<<8|r[F+2]<<16|r[F+3]<<24,i=(F,nt)=>F<<nt|F>>>32-nt,d=a(0),m=a(4),u=a(8),g=a(12),x=a(16),E=a(20),f=a(24),p=a(28),y=a(32),w=a(36),v=a(40),P=a(44),ee=a(48),te=a(52),re=a(56),ne=a(60);t=n+i(((o^s)&n^s)+t+d+3614090360,7),s=t+i(((n^o)&t^o)+s+m+3905402710,12),o=s+i(((t^n)&s^n)+o+u+606105819,17),n=o+i(((s^t)&o^t)+n+g+3250441966,22),t=n+i(((o^s)&n^s)+t+x+4118548399,7),s=t+i(((n^o)&t^o)+s+E+1200080426,12),o=s+i(((t^n)&s^n)+o+f+2821735955,17),n=o+i(((s^t)&o^t)+n+p+4249261313,22),t=n+i(((o^s)&n^s)+t+y+1770035416,7),s=t+i(((n^o)&t^o)+s+w+2336552879,12),o=s+i(((t^n)&s^n)+o+v+4294925233,17),n=o+i(((s^t)&o^t)+n+P+2304563134,22),t=n+i(((o^s)&n^s)+t+ee+1804603682,7),s=t+i(((n^o)&t^o)+s+te+4254626195,12),o=s+i(((t^n)&s^n)+o+re+2792965006,17),n=o+i(((s^t)&o^t)+n+ne+1236535329,22),t=n+i(((n^o)&s^o)+t+m+4129170786,5),s=t+i(((t^n)&o^n)+s+f+3225465664,9),o=s+i(((s^t)&n^t)+o+P+643717713,14),n=o+i(((o^s)&t^s)+n+d+3921069994,20),t=n+i(((n^o)&s^o)+t+E+3593408605,5),s=t+i(((t^n)&o^n)+s+v+38016083,9),o=s+i(((s^t)&n^t)+o+ne+3634488961,14),n=o+i(((o^s)&t^s)+n+x+3889429448,20),t=n+i(((n^o)&s^o)+t+w+568446438,5),s=t+i(((t^n)&o^n)+s+re+3275163606,9),o=s+i(((s^t)&n^t)+o+g+4107603335,14),n=o+i(((o^s)&t^s)+n+y+1163531501,20),t=n+i(((n^o)&s^o)+t+te+2850285829,5),s=t+i(((t^n)&o^n)+s+u+4243563512,9),o=s+i(((s^t)&n^t)+o+p+1735328473,14),n=o+i(((o^s)&t^s)+n+ee+2368359562,20),t=n+i((n^o^s)+t+E+4294588738,4),s=t+i((t^n^o)+s+y+2272392833,11),o=s+i((s^t^n)+o+P+1839030562,16),n=o+i((o^s^t)+n+re+4259657740,23),t=n+i((n^o^s)+t+m+2763975236,4),s=t+i((t^n^o)+s+x+1272893353,11),o=s+i((s^t^n)+o+p+4139469664,16),n=o+i((o^s^t)+n+v+3200236656,23),t=n+i((n^o^s)+t+te+681279174,4),s=t+i((t^n^o)+s+d+3936430074,11),o=s+i((s^t^n)+o+g+3572445317,16),n=o+i((o^s^t)+n+f+76029189,23),t=n+i((n^o^s)+t+w+3654602809,4),s=t+i((t^n^o)+s+ee+3873151461,11),o=s+i((s^t^n)+o+ne+530742520,16),n=o+i((o^s^t)+n+u+3299628645,23),t=n+i((o^(n|~s))+t+d+4096336452,6),s=t+i((n^(t|~o))+s+p+1126891415,10),o=s+i((t^(s|~n))+o+re+2878612391,15),n=o+i((s^(o|~t))+n+E+4237533241,21),t=n+i((o^(n|~s))+t+ee+1700485571,6),s=t+i((n^(t|~o))+s+g+2399980690,10),o=s+i((t^(s|~n))+o+v+4293915773,15),n=o+i((s^(o|~t))+n+m+2240044497,21),t=n+i((o^(n|~s))+t+y+1873313359,6),s=t+i((n^(t|~o))+s+ne+4264355552,10),o=s+i((t^(s|~n))+o+f+2734768916,15),n=o+i((s^(o|~t))+n+te+1309151649,21),t=n+i((o^(n|~s))+t+x+4149444226,6),s=t+i((n^(t|~o))+s+P+3174756917,10),o=s+i((t^(s|~n))+o+u+718787259,15),n=o+i((s^(o|~t))+n+w+3951481745,21),this.#e=this.#e+t>>>0,this.#t=this.#t+n>>>0,this.#r=this.#r+o>>>0,this.#n=this.#n+s>>>0}update(r){let t;if(typeof r=="string")t=new TextEncoder().encode(r);else if(typeof r=="object")if(r instanceof ArrayBuffer||ArrayBuffer.isView(r))t=new Uint8Array(r);else throw new TypeError(kt);else throw new TypeError(kt);let n=this.#i,o=B-n;if(t.length<o)this.#o.set(t,n),n+=t.length;else{this.#o.set(t.slice(0,o),n),this.#c(this.#o);let s=o;for(;s+B<=t.length;)this.#c(t.slice(s,s+B)),s+=B;this.#o.fill(0).set(t.slice(s),0),n=t.length-s}return this.#i=n,this.#d(t.length),this}digest(){let r=B-this.#i;r<9&&(r+=B);let t=new Uint8Array(r);t[0]=128;let n=this.#s<<3,o=this.#a<<3|this.#s>>>29;t[t.length-8]=n&255,t[t.length-7]=n>>>8&255,t[t.length-6]=n>>>16&255,t[t.length-5]=n>>>24&255,t[t.length-4]=o&255,t[t.length-3]=o>>>8&255,t[t.length-2]=o>>>16&255,t[t.length-1]=o>>>24&255,this.update(t.buffer);let s=new ArrayBuffer(16),a=new DataView(s);return a.setUint32(0,this.#e,!0),a.setUint32(4,this.#t,!0),a.setUint32(8,this.#r,!0),a.setUint32(12,this.#n,!0),s}toString(r="hex"){let t=this.digest();switch(r){case"hex":return new TextDecoder().decode(wt(new Uint8Array(t)));case"base64":{let n=new Uint8Array(t),o="";for(let s=0;s<n.length;++s)o+=String.fromCharCode(n[s]);return btoa(o)}default:throw new Error("md5: invalid format")}}};var vt=!1;scrapbox.addListener("lines:changed",()=>vt=!1);scrapbox.addListener("layout:changed",()=>vt=!1);var Lt=(e,r)=>{if(!(e instanceof HTMLDivElement))throw new TypeError("${r}" must be HTMLDivElememt but actual is "${e}")};var Tt=(e,r)=>{if(!(e instanceof HTMLTextAreaElement))throw new TypeError("${r}" must be HTMLTextAreaElement but actual is "${e}")};var H=()=>{let e=document.getElementById("text-input");if(!!e)return Tt(e,"textarea#text-input"),e};var It=()=>ir(document.getElementsByClassName("status-bar")?.[0],"div.status-bar"),ir=(e,r)=>{if(!!e)return Lt(e,r),e};var j=e=>new Promise(r=>setTimeout(()=>r(),e));var ve=()=>{let e=It();if(!e)throw new Error("div.status-bar can't be found");let r=document.createElement("div");return e.append(r),{render:(...t)=>{r.textContent="";let n=Dt(...t);n&&r.append(n)},dispose:()=>r.remove()}},Dt=(...e)=>{let r=e.flatMap(n=>{switch(n.type){case"spinner":return[pr()];case"check-circle":return[mr()];case"exclamation-triangle":return[fr()];case"text":return[ce(n.text)];case"group":{let o=Dt(...n.items);return o?[o]:[]}}});if(r.length===0)return;if(r.length===1)return r[0];let t=document.createElement("span");return t.classList.add("item-group"),t.append(...r),t},ce=e=>{let r=document.createElement("span");return r.classList.add("item"),r.append(e),r},pr=()=>{let e=document.createElement("i");return e.classList.add("fa","fa-spinner"),ce(e)},mr=()=>{let e=document.createElement("i");return e.classList.add("kamon","kamon-check-circle"),ce(e)},fr=()=>{let e=document.createElement("i");return e.classList.add("fas","fa-exclamation-triangle"),ce(e)};var Mt=e=>{if(e===0)return;let r={};return e&1&&(r.capture=!0),e&2&&(r.once=!0),e&4&&(r.passive=!0),r};var hr=new Map,ic=new Map;scrapbox.on("layout:changed",()=>{let e=H();if(!!e)for(let[r,t]of hr)for(let[n,o]of t)for(let s of o)e.addEventListener(r,n,Mt(s))});var Pt=e=>xr.includes(e.name),xr=["SocketIOError","DuplicateTitleError","NotFastForwardError"];var V=async()=>{let r=(await br())("https://scrapbox.io",{reconnectionDelay:5e3,transports:["websocket"]});return await new Promise((t,n)=>{let o=s=>n(s);r.once("connect",()=>{r.off("disconnect",o),t()}),r.once("disconnect",o)}),r},yr="4.2.0",Rt=https://cdnjs.cloudflare.com/ajax/libs/socket.io/${yr}/socket.io.min.js,Le,br=async()=>{if(Le)throw Le;if(!document.querySelector(scriptsrc="${Rt}")){let e=document.createElement("script");e.src=Rt,await new Promise((r,t)=>{e.onload=()=>r(),e.onerror=n=>{Le=n,t(n)},document.head.append(e)})}return new Promise(e=>{let r=setInterval(()=>{!io||(clearInterval(r),e(io))},500)})};var Te=(e,r=9e4)=>{let t=(o,s)=>{let a;return new Promise((i,d)=>{let m=u=>{clearTimeout(a),d(new Error(u))};e.emit(o,s,u=>{switch(clearTimeout(a),e.off("disconnect",m),o){case"socket.io-request":"error"in u?typeof u.error=="object"&&u.error&&"name"in u.error&&typeof u.error.name=="string"&&Pt({name:u.error.name})?i({ok:!1,value:u.error}):i({ok:!1,value:{name:"UnexpectedError",value:u.error}}):"data"in u&&i({ok:!0,value:u.data});break;case"cursor":"error"in u?i({ok:!1,value:{name:"UnexpectedError",value:u.error}}):"data"in u&&i({ok:!0,value:u.data});break}d(new Error('Invalid response: missing "data" or "error" field'))}),a=setTimeout(()=>{e.off("disconnect",m),i({ok:!1,value:{name:"TimeoutError",message:Timeout: exceeded ${r}ms}})},r),e.once("disconnect",m)})};async function*n(...o){let s,a=()=>new Promise(d=>s=d),i=d=>{s?.(d)};for(let d of o)e.on(d,i);try{for(;;)yield await a()}finally{for(let d of o)e.off(d,i)}}return{request:t,response:n}};var Ie=()=>V(),Ce=async e=>{if(e.connected)return;let r=new Promise(t=>e.once("connect",()=>t()));e.connect(),await r},Y=async e=>{if(e.disconnected)return;let r=new Promise(t=>{let n=o=>{o==="io client disconnect"&&(t(),e.off("disconnect",n))};e.on("disconnect",n)});e.disconnect(),await r};var De=(e,r)=>{let t=e.length>r.length,n=t?r:e,o=t?e:r,s=n.length+1,a=n.length+o.length+3,i=new Array(a);i.fill(-1);let d=[];function m(p,y,w){let v=Math.max(y,w),P=v-p;for(;P<n.length&&v<o.length&&n[P]===o[v];)++P,++v;return i[p+s]=d.length,d.push([{x:P,y:v},i[p+(y>w?-1:1)+s]]),v}let u=new Array(a);u.fill(-1);let g=-1,x=o.length-n.length;do{++g;for(let p=-g;p<=x-1;++p)u[p+s]=m(p,u[p-1+s]+1,u[p+1+s]);for(let p=x+g;p>=x+1;--p)u[p+s]=m(p,u[p-1+s]+1,u[p+1+s]);u[x+s]=m(x,u[x-1+s]+1,u[x+1+s])}while(u[x+s]!==o.length);let E=[],f=i[x+s];for(;f!==-1;)E.push(d[f][0]),f=d[f][1];return{from:e,to:r,editDistance:x+g*2,buildSES:function*(){let p=0,y=0;for(let{x:w,y:v}of Er(E))for(;p<w||y<v;)v-w>y-p?(yield{value:o[y],type:t?"deleted":"added"},++y):v-w<y-p?(yield{value:n[p],type:t?"added":"deleted"},++p):(yield{value:n[p],type:"common"},++p,++y)}}};function*Me(e){let r=[],t=[];function*n(){if(r.length>t.length){for(let o=0;o<t.length;o++)yield Nt(r[o],t[o]);for(let o=t.length;o<r.length;o++)yield r[o]}else{for(let o=0;o<r.length;o++)yield Nt(r[o],t[o]);for(let o=r.length;o<t.length;o++)yield t[o]}r=[],t=[]}for(let o of e)switch(o.type){case"added":r.push(o);break;case"deleted":t.push(o);break;case"common":yield*n(),yield o;break}yield*n()}var Nt=(e,r)=>({value:e.value,oldValue:r.value,type:"replaced"});function*Er(e){for(let r=e.length-1;r>=0;r--)yield e[r]}var de,St=async()=>{if(de!==void 0)return de;let e=await we();if(e.isGuest)throw new Error("this script can only be executed by Logged in users");return de=e.id,de},Ot=new Map,Pe=async e=>{let r=Ot.get(e);if(r!==void 0)return r;let t=await se(e);if(!t.ok){let{name:o,message:s}=t.value;throw new Error(${o} ${s})}let{id:n}=t.value;return Ot.set(e,n),n},At=e=>e.padStart(8,"0"),Re=e=>{let r=Math.floor(new Date().getTime()/1e3).toString(16),t=Math.floor(16777214*Math.random()).toString(16);return${At(r).slice(-8)}${e.slice(-6)}0000${At(t)}};function*Ne(e,r,{userId:t}){let{buildSES:n}=De(e.map(({text:a})=>a),r),o=0,s=e[0].id;for(let a of Me(n())){switch(a.type){case"added":yield{_insert:s,lines:{id:Re(t),text:a.value}};continue;case"deleted":yield{_delete:s,lines:-1};break;case"replaced":yield{_update:s,lines:{text:a.value}};break}o++,s=e[o]?.id??"_end"}}var wr=e=>({type:"title",text:e.rows[0].text}),kr=e=>{let{rows:[r,...t]}=e,{indent:n=0,text:o=""}=r??{},s=o.replace(/^\s*code:/,"");return{indent:n,type:"codeBlock",fileName:s,content:t.map(a=>a.text.substring(n+1)).join( )}},T=(e,{parseOnNested:r,parseOnQuoted:t,patterns:n})=>(o,s,a)=>{var i,d,m,u,g,x;if(!r&&s.nested)return(i=a?.())!==null&&i!==void 0?i:[];if(!t&&s.quoted)return(d=a?.())!==null&&d!==void 0?d:[];for(let E of n){let f=E.exec(o);if(f===null)continue;let p=o.substring(0,f.index),y=o.substring(f.index+((u=(m=f[0])===null||m===void 0?void 0:m.length)!==null&&u!==void 0?u:0)),w=e((g=f[0])!==null&&g!==void 0?g:"",s);return[...S(p,s),...w,...S(y,s)]}return(x=a?.())!==null&&x!==void 0?x:[]},I=e=>[{type:"plain",raw:e,text:e}],vr=T(I,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]}),Lr=/^>.*$/,Tr=(e,r)=>r.context==="table"?I(e,r):[{type:"quote",raw:e,nodes:S(e.substring(1),{...r,quoted:!0})}],Ir=T(Tr,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Lr]}),Cr=/^\? .+$/,Dr=(e,r)=>r.context==="table"?I(e,r):[{type:"helpfeel",raw:e,text:e.substring(2)}],Mr=T(Dr,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Cr]}),Pr=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,Rr=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,Nr=(e,r)=>{if(r.context==="table")return I(e,r);let t=e.substring(2,e.length-2),n=/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(t);return[{type:"strongImage",raw:e,src:n?${t}/thumb/1000:t}]},Sr=T(Nr,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Pr,Rr]}),Or=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;function Ft(e){return(r,t)=>{if(e==="strongIcon"&&t.context==="table")return I(r,t);let n=e==="icon"?r.substring(1,r.length-1):r.substring(2,r.length-2),o=n.lastIndexOf(".icon"),s=n.substring(0,o),a=s.startsWith("/")?"root":"relative",i=n.substring(o+5,n.length),d=i.startsWith("*")?parseInt(i.substring(1),10):1;return new Array(d).fill({}).map(()=>({path:s,pathType:a,type:e,raw:r}))}}var Ar=Ft("icon"),Fr=T(Ar,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Or]}),qr=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,Br=Ft("strongIcon"),jr=T(Br,{parseOnNested:!1,parseOnQuoted:!0,patterns:[qr]}),_r=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,Ur=(e,r)=>r.context==="table"?I(e,r):[{type:"strong",raw:e,nodes:S(e.substring(2,e.length-2),{...r,nested:!0})}],$r=T(Ur,{parseOnNested:!1,parseOnQuoted:!0,patterns:[_r]}),Hr=/\[\$ .+? \]/,Yr=/\[\$ [^\]]+\]/,Wr=(e,r)=>r.context==="table"?I(e,r):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],Gr=T(Wr,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Hr,Yr]}),Kr=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,zr=(e,r)=>{if(r.context==="table")return I(e,r);let t=e.indexOf(" "),n=e.substring(1,t),o=e.substring(t+1,e.length-1),s=new Set(n);if(s.has("*")){let a=n.split("*").length-1;s.delete("*"),s.add(*-${Math.min(a,10)})}return[{type:"decoration",raw:e,rawDecos:n,decos:Array.from(s),nodes:S(o,{...r,nested:!0})}]},Qr=T(zr,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Kr]}),Vr=/.*?/,Jr=(e,r)=>r.context==="table"?I(e,r):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],Xr=T(Jr,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Vr]}),Zr=/^[$%] .+$/,en=(e,r)=>{var t;if(r.context==="table")return I(e,r);let n=(t=e[0])!==null&&t!==void 0?t:"",o=e.substring(2);return[{type:"commandLine",raw:e,symbol:n,text:o}]},tn=T(en,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Zr]}),rn=/\[\s+\]/,nn=(e,r)=>r.context==="table"?I(e,r):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],on=T(nn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[rn]}),sn=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,an=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,cn=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,dn=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,ln=e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(e)||un(e),un=e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),pn=(e,r)=>{if(r.context==="table")return I(e,r);let t=e.search(/\s/),n=t!==-1?e.substring(1,t):e.substring(1,e.length-1),o=t!==-1?e.substring(t,e.length-1).trimLeft():"",[s,a]=ln(o)?[o,n]:[n,o];return[{type:"image",raw:e,src:/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(s)?${s}/thumb/1000:s,link:a}]},mn=T(pn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[sn,an,cn,dn]}),fn=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,gn=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,hn=/\[https?:\/\/[^\s\]]+\]/,xn=/https?:\/\/[^\s]+/,yn=(e,r)=>{if(r.context==="table")return I(e,r);let t=e.startsWith("[")&&e.endsWith("]")?e.substring(1,e.length-1):e,n=/^https?:\/\/[^\s\]]/.test(t),o=(n?/^https?:\/\/[^\s\]]+/:/https?:\/\/[^\s\]]+$/).exec(t);if(o?.[0]===void 0)return[];let s=n?t.substring(o[0].length):t.substring(0,o.index-1);return[{type:"link",raw:e,pathType:"absolute",href:o[0],content:s.trim()}]},bn=T(yn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[fn,gn,hn,xn]}),qt=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,Bt=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,En=e=>{let[r="",t="",n=""]=e.split(","),o=parseFloat(r.replace(/^N/,"").replace(/^S/,"-")),s=parseFloat(t.replace(/^E/,"").replace(/^W/,"-")),a=/^Z\d+$/.test(n)?parseInt(n.replace(/^Z/,""),10):14;return{latitude:o,longitude:s,zoom:a}},wn=(e,r)=>{var t;if(r.context==="table")return I(e,r);let n=(t=e.match(qt))!==null&&t!==void 0?t:e.match(Bt);if(n===null)return[];let o=e.startsWith("[N")||e.startsWith("[S"),[,s="",a=""]=o?n:[n[0],n[2],n[1]],{latitude:i,longitude:d,zoom:m}=En(s),u=a!==""?https://www.google.com/maps/place/${encodeURIComponent(a)}/@${i},${d},${m}z:https://www.google.com/maps/@${i},${d},${m}z;return[{type:"googleMap",raw:e,latitude:i,longitude:d,zoom:m,place:a,url:u}]},kn=T(wn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[qt,Bt]}),vn=/\[\/?[^[\]]+\]/,Ln=e=>{let r=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:r.startsWith("/")?"root":"relative",href:r,content:""}]},Tn=T(Ln,{parseOnNested:!0,parseOnQuoted:!0,patterns:[vn]}),In=/(?:^|\s)#\S+/,Cn=(e,r)=>{if(r.context==="table")return I(e,r);if(e.startsWith("#"))return[{type:"hashTag",raw:e,href:e.substring(1)}];let t=e.substring(0,1),n=e.substring(1);return[...I(t,r),{type:"hashTag",raw:n,href:n.substring(1)}]},Dn=T(Cn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[In]}),Mn=/^[0-9]+\. .*$/,Pn=(e,r)=>{if(r.context==="table")return I(e,r);let t=e.indexOf(" "),n=e.substring(0,t-1),o=parseInt(n,10),s=e.substring(t+1,e.length);return[{type:"numberList",raw:e,rawNumber:n,number:o,nodes:S(s,{...r,nested:!0})}]},Rn=T(Pn,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Mn]}),Nn=(e,r,t)=>{var n;return e===""?[]:(n=t?.())!==null&&n!==void 0?n:[]},Sn=(...e)=>(r,t)=>e.reduceRight((n,o)=>()=>o(r,t,n),()=>vr(r,t))(),S=Sn(Nn,Ir,Mr,Xr,tn,Gr,on,Qr,Sr,jr,$r,mn,bn,Fr,kn,Tn,Dn,Rn),On=e=>{let{rows:[r,...t]}=e,{indent:n=0,text:o=""}=r??{},s=o.replace(/^\s*table:/,"");return{indent:n,type:"table",fileName:s,cells:t.map(a=>a.text.substring(n+1)).map(a=>a.split(" ").map(i=>S(i,{nested:!1,quoted:!1,context:"table"})))}},An=e=>{let{indent:r,text:t}=e.rows[0];return{indent:r,type:"line",nodes:S(t.substring(r),{nested:!1,quoted:!1,context:"line"})}},Fn=e=>{switch(e.type){case"title":return wr(e);case"codeBlock":return kr(e);case"table":return On(e);case"line":return An(e)}},qn=e=>e.split( ).map(r=>{var t,n,o;return{indent:(o=(n=(t=/^\s+/.exec(r))===null||t===void 0?void 0:t[0])===null||n===void 0?void 0:n.length)!==null&&o!==void 0?o:0,text:r}}),Bn=(e,r)=>{var t,n;return(e.type==="codeBlock"||e.type==="table")&&r.indent>((n=(t=e.rows[0])===null||t===void 0?void 0:t.indent)!==null&&n!==void 0?n:0)},jt=(e,r)=>{let t=e[e.length-1];return t!==void 0&&Bn(t,r)?(t.rows.push(r),e):(e.push({type:/^\s*code:/.test(r.text)?"codeBlock":/^\s*table:/.test(r.text)?"table":"line",rows:[r]}),e)},jn=(e,r)=>{var t;if(!((t=r.hasTitle)!==null&&t!==void 0)||t){let[n,...o]=e;return n===void 0?[]:[{type:"title",rows:[n]},...o.reduce(jt,[])]}return e.reduce(jt,[])},_t=(e,r)=>{var t;let n=qn(e);return jn(n,{hasTitle:(t=r?.hasTitle)!==null&&t!==void 0?t:!0}).map(Fn)};var _n=/https?:\/\/(?:www\.|music\.|)youtube\.com\/watch/,Un=/https?:\/\/youtu\.be\/([a-zA-Z\d_-]+)(?:\?([^\s]{0,100})|)/,$n=/https?:\/\/(?:www\.|)youtube\.com\/shorts\/([a-zA-Z\d_-]+)(?:\?([^\s]+)|)/,Hn=/https?:\/\/(?:www\.|music\.|)youtube\.com\/playlist\?((?:[^\s]+&|)list=([a-zA-Z\d_-]+)(?:&[^\s]+|))/,Se=e=>{if(_n.test(e)){let r=new URL(e).searchParams,t=r.get("v");if(t)return{pathType:"com",videoId:t,params:r}}{let r=e.match(Un);if(r){let[,t,n]=r;return{videoId:t,params:new URLSearchParams(n),pathType:"dotbe"}}}{let r=e.match($n);if(r){let[,t,n]=r;return{videoId:t,params:new URLSearchParams(n),pathType:"short"}}}{let r=e.match(Hn);if(r){let[,t,n]=r;return{listId:n,params:new URLSearchParams(t),pathType:"list"}}}};var Ut=e=>{let r=_t(e,{hasTitle:!0}).flatMap(f=>{switch(f.type){case"codeBlock":case"title":return[];case"line":case"table":return f}}),t=new Map,n=[],o=new Set,s=[],a=new Set,i=[],d=null,m=new Set,u=new Set,g=new RegExp(${location?.origin??"https://scrapbox.io"}/files/([a-z0-9]{24})(?:|\\.[a-zA-Z0-9]+)(?:|\\?[^\\s]*)$),x=f=>{switch(f.type){case"hashTag":if(t.has(C(f.href)))return;t.set(C(f.href),!1),n.push(f.href);return;case"link":switch(f.pathType){case"relative":{let p=$t(f.href);if(t.get(C(p)))return;t.set(C(p),!0),n.push(p);return}case"root":{let p=$t(f.href);if(/^\/[\w\d-]+\/?$/.test(p)||o.has(C(p)))return;o.add(C(p)),s.push(p);return}case"absolute":{if(f.content)return;let p=Se(f.href);if(p&&p.pathType!=="list"){d??=https://i.ytimg.com/vi/${p.videoId}/mqdefault.jpg;return}let y=f.href.match(g)?.[1];y&&m.add(y);return}default:return}case"icon":case"strongIcon":{if(f.pathType==="root"||a.has(C(f.path)))return;a.add(C(f.path)),i.push(f.path);return}case"image":case"strongImage":{d??=f.src.endsWith("/thumb/1000")?f.src.replace(/\/thumb\/1000$/,"/raw"):f.src;{let p=f.src.match(g)?.[1];p&&m.add(p)}if(f.type==="image"){let p=f.link.match(g)?.[1];p&&m.add(p)}return}case"helpfeel":u.add(f.text);return;case"numberList":case"strong":case"quote":case"decoration":{for(let p of f.nodes)x(p);return}default:return}},E=[];for(let f of r)switch(f.type){case"line":for(let p of f.nodes)x(p);continue;case"table":{for(let p of f.cells)for(let y of p)for(let w of y)x(w);if(!["infobox","cosense"].includes(f.fileName))continue;E.push(...f.cells.map(p=>p.map(y=>y.map(w=>w.raw).join("")).join(" ").trim()));continue}}return[n,s,i,d,[...m],[...u],E]},$t=e=>e.replace(/#[a-f\d]{24,32}$/,""),Ht=e=>e.flatMap(({text:r})=>/^\s*\? .*$/.test(r)?[r.trimStart().slice(2)]:[]);var _=(e,r)=>e.length===r.length&&e.every(t=>r.includes(t));function*Yt(e,r,t){let n=r.flatMap(E=>E.split( ));for(let E of Ne(e.lines,n,{userId:t}))yield E;(e.lines[0].text!==n[0]||!e.persistent)&&(yield{title:n[0]});let o=e.lines.slice(1,6).map(E=>E.text),s=n.slice(1,6);o.join("")!==s.join("")&&(yield{descriptions:s});let[a,i,d,m,u,g,x]=Ut(n.join(
));_(e.links,a)||(yield{links:a}),_(e.projectLinks,i)||(yield{projectLinks:i}),_(e.icons,d)||(yield{icons:d}),e.image!==m&&(yield{image:m}),_(e.files,u)||(yield{files:u}),_(Ht(e.lines),g)||(yield{helpfeels:g}),_(e.infoboxDefinition,x)||(yield{infoboxDefinition:x})}var O=async(e,r,t,n)=>{let[o,s,a]=await Promise.all([ae(e,r),Pe(e),St()]),i={...o,projectId:s,userId:a},d=n?.socket,m=d??await V();await Ce(m);try{let{request:u}=Te(m),g=0,x=[],E;for(;n?.maxAttempts===void 0||g<n.maxAttempts;){let f=t(i,g,x,E);if(x=f instanceof Promise?await f:f,g++,x.length===0)return{ok:!0,value:i.commitId};let p={kind:"page",projectId:s,pageId:i.id,parentId:i.commitId,userId:a,changes:x,cursor:null,freeze:!0};for(;;){let y=await u("socket.io-request",{method:"commit",data:p});if(y.ok)return i.commitId=y.value.commitId,{ok:!0,value:i.commitId};let w=y.value.name;if(w==="UnexpectedError"){let v=new Error;throw v.name=y.value.name,v.message=JSON.stringify(y.value),v}if(w==="TimeoutError"||w==="SocketIOError"){await j(3e3);break}w==="NotFastForwardError"&&(i={...await ae(e,r),projectId:s,userId:a}),E=w}}return{ok:!1,value:{name:"RetryError",attempts:g,message:Retrying exceeded the maxAttempts (${g}).}}}finally{d||await Y(m)}};var Wt=e=>{let r=e.match(/(.+?)(?:_(\d+))?$/),t=r?.[1]??e,n=r?.[2]?parseInt(r[2])+1:2;return${t}_${n}};var Oe=(e,r,t,n)=>O(e,r,async(o,s,a,i)=>{if(i==="DuplicateTitleError"){let u=Wt(r);return a.map(g=>("title"in g&&(g.title=u),g))}let d=t(o.lines,{...o,attempts:s}),m=d instanceof Promise?await d:d;return m===void 0?[]:m.length===0?[{deleted:!0}]:[...Yt(o,m,o.userId)]},n);var Ae=(e,r,t)=>O(e,r,n=>{if(n.pin>0||!n.persistent&&!(t?.create??!1))return[];let o=[{pin:Yn()}];return n.persistent||o.unshift({title:r}),o},t),Fe=(e,r,t)=>O(e,r,n=>n.pin==0||!n.persistent?[]:[{pin:0}],t),Yn=()=>Number.MAX_SAFE_INTEGER-Math.floor(Date.now()/1e3);async function*qe(e,r=0){let{count:t,pages:n}=await Gn(e,r);for(let o of n)o.pin!==0&&(yield o);(n.at(-1)?.pin??0)!==0&&(yield*qe(e,r+1e3))}var Gn=async(e,r)=>{let t=await Q(e,{limit:1e3,skip:r});if(!t.ok){let n=new Error;throw n.name=t.value.name,n.message=t.value.message,n}return t.value};var Gt=(e,r)=>{let t=r.interval??24*3600*1e3,n=()=>scrapbox.Project.name===e?Kn(e,t,r):zt();n(),scrapbox.addListener("project:changed",n)},Kt,Kn=async(e,r,t)=>{zt(),await Qt(e,new Date,t),Kt=setInterval(()=>Qt(e,new Date,t),r)},zt=()=>clearInterval(Kt),Qt=async(e,r,{makeDiary:t,isOldDiary:n})=>{let{render:o,dispose:s}=ve(),a;try{o({type:"spinner"},{type:"text",text:"unpin other diary pages..."}),a=await Ie();for await(let{title:u}of qe(e))!n(u,r)||await Fe(e,u,{socket:a});let{title:i,header:d,footer:m}=t(r);o({type:"spinner"},{type:"text",text:pin "/${e}/${i}"...}),await Ae(e,i,{socket:a,create:!0}),o({type:"spinner"},{type:"text",text:format "/${e}/${i}"...}),await Oe(e,i,u=>[u[0].text,...Ee(u.slice(1).map(g=>g.text),d,m)],{socket:a}),o({type:"check-circle"},{type:"text",text:Pinned "/${e}/${i}".})}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{a&&await Y(a),await j(1e3),s()}};function c(e,r){if(r.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+r.length+" present")}function l(e){c(1,arguments);let r=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&r==="[object Date]"?new Date(e.getTime()):typeof e=="number"||r==="[object Number]"?new Date(e):((typeof e=="string"||r==="[object String]")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use parseISO to parse strings. See: https://git.io/fjule"),console.warn(new Error().stack)),new Date(NaN))}function Be(e){c(1,arguments);let t=l(e).getFullYear();return t%400==0||t%4==0&&t%100!=0}function le(e){c(1,arguments);let r=l(e);return String(new Date(r))==="Invalid Date"?NaN:Be(r)?366:365}function je(e){c(1,arguments);let r=l(e),t=new Date(0);return t.setFullYear(r.getFullYear(),0,1),t.setHours(0,0,0,0),t}function W(e){let r=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return r.setUTCFullYear(e.getFullYear()),e.getTime()-r.getTime()}function ue(e){c(1,arguments);let r=l(e);return r.setHours(0,0,0,0),r}var zn=864e5;function J(e,r){c(2,arguments);let t=ue(e),n=ue(r),o=t.getTime()-W(t),s=n.getTime()-W(n);return Math.round((o-s)/zn)}function pe(e){c(1,arguments);let r=l(e);return J(r,je(r))+1}function h(e){if(e===null||e===!0||e===!1)return NaN;let r=Number(e);return isNaN(r)?r:r<0?Math.ceil(r):Math.floor(r)}function G(e,r){c(2,arguments);let t=l(e),n=h(r);return isNaN(n)?new Date(NaN):(n&&t.setDate(t.getDate()+n),t)}function K(e,r){c(2,arguments);let t=h(r);return G(e,-t)}function A(e,r){c(1,arguments);let t=r||{},n=t.locale,o=n&&n.options&&n.options.weekStartsOn,s=o==null?0:h(o),a=t.weekStartsOn==null?s:h(t.weekStartsOn);if(!(a>=0&&a<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");let i=l(e),d=i.getDay(),m=(d<a?7:0)+d-a;return i.setDate(i.getDate()-m),i.setHours(0,0,0,0),i}function _e(e,r){c(1,arguments);let t=l(e),n=t.getFullYear(),o=r?.locale?.options?.firstWeekContainsDate,s=o==null?1:h(o),a=r?.firstWeekContainsDate==null?s:h(r.firstWeekContainsDate);if(!(a>=1&&a<=7))throw new RangeError("firstWeekContainsDate must be between 1 and 7 inclusively");let i=new Date(0);i.setFullYear(n+1,0,a),i.setHours(0,0,0,0);let d=A(i,r),m=new Date(0);m.setFullYear(n,0,a),m.setHours(0,0,0,0);let u=A(m,r);return t.getTime()>=d.getTime()?n+1:t.getTime()>=u.getTime()?n:n-1}function Ue(e,r){c(1,arguments);var t=r||{},n=t.locale,o=n&&n.options&&n.options.firstWeekContainsDate,s=o==null?1:h(o),a=t.firstWeekContainsDate==null?s:h(t.firstWeekContainsDate),i=_e(e,r),d=new Date(0);d.setFullYear(i,0,a),d.setHours(0,0,0,0);var m=A(d,r);return m}var Qn=6048e5;function me(e,r){c(1,arguments);let t=l(e),n=A(t,r).getTime()-Ue(t,r).getTime();return Math.round(n/Qn)+1}function X(e,r){c(2,arguments);let t=l(e),n=h(r);if(isNaN(n))return new Date(NaN);if(!n)return t;let o=t.getDate(),s=new Date(t.getTime());s.setMonth(t.getMonth()+n+1,0);let a=s.getDate();return o>=a?s:(t.setFullYear(s.getFullYear(),s.getMonth(),o),t)}function $e(e,r){c(2,arguments);let t=h(r);return X(e,t*12)}function fe(e,r){c(2,arguments);let t=h(r);return $e(e,-t)}function ge(e){return c(1,arguments),l(e).getDay()}function he(e){return c(1,arguments),l(e).getFullYear()}function D(e,r){for(var t=e<0?"-":"",n=Math.abs(e).toString();n.length<r;)n="0"+n;return t+n}var Vn={y(e,r){let t=e.getUTCFullYear(),n=t>0?t:1-t;return D(r==="yy"?n%100:n,r.length)},M(e,r){let t=e.getUTCMonth();return r==="M"?String(t+1):D(t+1,2)},d(e,r){return D(e.getUTCDate(),r.length)},a(e,r){let t=e.getUTCHours()/12>=1?"pm":"am";switch(r){case"a":case"aa":return t.toUpperCase();case"aaa":return t;case"aaaaa":return t[0];case"aaaa":default:return t==="am"?"a.m.":"p.m."}},h(e,r){return D(e.getUTCHours()%12||12,r.length)},H(e,r){return D(e.getUTCHours(),r.length)},m(e,r){return D(e.getUTCMinutes(),r.length)},s(e,r){return D(e.getUTCSeconds(),r.length)},S(e,r){let t=r.length,n=e.getUTCMilliseconds(),o=Math.floor(n*Math.pow(10,t-3));return D(o,r.length)}},Vt=Vn;function z(e){c(1,arguments);var r=l(e);return!isNaN(r)}function He(e,r){c(2,arguments);let t=l(e).getTime(),n=h(r);return new Date(t+n)}function Ye(e,r){c(2,arguments);let t=h(r);return He(e,-t)}var Jn=/(\w)\1*|''|'(''|[^'])+('|$)|./g,Xn=/^'([^]*?)'?$/,Zn=/''/g,eo=/[a-zA-Z]/;function R(e,r){c(2,arguments);let t=l(e);if(!z(t))throw new RangeError("Invalid time value");let n=W(t),o=Ye(t,n),s=r.match(Jn);return s?s.map(i=>{if(i==="''")return"'";let d=i[0];if(d==="'")return to(i);let m=Vt[d];if(m)return m(o,i);if(d.match(eo))throw new RangeError("Format string contains an unescaped latin alphabet character "+d+"");return i}).join(""):""}function to(e){let r=e.match(Xn);return r?r[1].replace(Zn,"'"):e}function M(e,r){c(2,arguments);let t=l(e),n=l(r),o=t.getTime()-n.getTime();return o<0?-1:o>0?1:o}function We(e,r){c(2,arguments);let t=l(e),n=l(r);return t.getFullYear()-n.getFullYear()}function Ge(e,r){c(2,arguments);let t=l(e),n=l(r),o=M(t,n),s=Math.abs(We(t,n));t.setFullYear(1584),n.setFullYear(1584);let a=M(t,n)===-o,i=o*(s-Number(a));return i===0?0:i}function Ke(e,r){c(2,arguments);let t=l(e),n=l(r),o=t.getFullYear()-n.getFullYear(),s=t.getMonth()-n.getMonth();return o*12+s}function ze(e){c(1,arguments);let r=l(e);return r.setHours(23,59,59,999),r}function Qe(e){c(1,arguments);let r=l(e),t=r.getMonth();return r.setFullYear(r.getFullYear(),t+1,0),r.setHours(23,59,59,999),r}function Ve(e){c(1,arguments);let r=l(e);return ze(r).getTime()===Qe(r).getTime()}function Je(e,r){c(2,arguments);let t=l(e),n=l(r),o=M(t,n),s=Math.abs(Ke(t,n)),a;if(s<1)a=0;else{t.getMonth()===1&&t.getDate()>27&&t.setDate(30),t.setMonth(t.getMonth()-o*s);let i=M(t,n)===-o;Ve(l(e))&&s===1&&M(e,n)===1&&(i=!1),a=o*(s-Number(i))}return a===0?0:a}function Jt(e,r){let t=e.getFullYear()-r.getFullYear()||e.getMonth()-r.getMonth()||e.getDate()-r.getDate()||e.getHours()-r.getHours()||e.getMinutes()-r.getMinutes()||e.getSeconds()-r.getSeconds()||e.getMilliseconds()-r.getMilliseconds();return t<0?-1:t>0?1:t}function Xe(e,r){c(2,arguments);let t=l(e),n=l(r),o=Jt(t,n),s=Math.abs(J(t,n));t.setDate(t.getDate()-o*s);let a=Number(Jt(t,n)===-o),i=o*(s-a);return i===0?0:i}function U(e,r){c(2,arguments);let t=l(e),n=l(r);return t.getTime()-n.getTime()}var ro=36e5;function Ze(e,r){c(2,arguments);let t=U(e,r)/ro;return t>0?Math.floor(t):Math.ceil(t)}var no=6e4;function et(e,r){c(2,arguments);var t=U(e,r)/no;return t>0?Math.floor(t):Math.ceil(t)}function tt(e,r){c(2,arguments);let t=U(e,r)/1e3;return t>0?Math.floor(t):Math.ceil(t)}function rt(e,r){c(2,arguments);let t=h(r);return X(e,-t)}function $(e,r){if(c(2,arguments),!r||typeof r!="object")return new Date(NaN);let t="years"in r?h(r.years):0,n="months"in r?h(r.months):0,o="weeks"in r?h(r.weeks):0,s="days"in r?h(r.days):0,a="hours"in r?h(r.hours):0,i="minutes"in r?h(r.minutes):0,d="seconds"in r?h(r.seconds):0,m=rt(l(e),n+t*12),u=K(m,s+o*7),g=i+a*60,E=(d+g*60)*1e3;return new Date(u.getTime()-E)}function xe({start:e,end:r}){c(1,arguments);let t=l(e),n=l(r);if(!z(t))throw new RangeError("Start Date is invalid");if(!z(n))throw new RangeError("End Date is invalid");let o={years:0,months:0,days:0,hours:0,minutes:0,seconds:0},s=M(t,n);o.years=Math.abs(Ge(t,n));let a=$(t,{years:s*o.years});o.months=Math.abs(Je(a,n));let i=$(a,{months:s*o.months});o.days=Math.abs(Xe(i,n));let d=$(i,{days:s*o.days});o.hours=Math.abs(Ze(d,n));let m=$(d,{hours:s*o.hours});o.minutes=Math.abs(et(m,n));let u=$(m,{minutes:s*o.minutes});return o.seconds=Math.abs(tt(u,n)),o}var Z="yyyy/MM/dd",Xt=e=>{let r=xe({start:new Date(2020,9,9),end:e}).years;return{title:er(e),header:[第${me(e)}週: ${oo(e)},${he(e)}年 ${(pe(e)*100/le(e)).toFixed(2)}%経過,"","今日のn年前",...[...Array(r).keys()].map(t=> ${R(fe(e,t+1),Z)})],footer:[${R(K(e,1),Z)}←${R(e,Z)}→${R(G(e,1),Z)},${R(e,"yyyy/MM")}.icon]}},oo=e=>{let r=ge(e);return[..."日月火水木金土"].map((t,n)=>n===r?${t}`:t).join("")},so=/^\d{4}\/\d{2}\/\d{2}$/,Zt=(e,r)=>so.test(e)?er(r)!==e:!1,er=e=>R(e,Z);Gt("villagepump",{makeDiary:Xt,isOldDiary:Zt});