times
code:min.js
function X(e,t){let r=0,n=[];for(let o=0;o<t.length;o++){let s=e.findIndex((a,i)=>i>=r&&a.trim()===to.trim());if(s<0){n.push(to);continue}n.push(...e.slice(r,s+1)),r=s+1}return n.push(...e.slice(r)),n}function V(e,t){let r=-1;for(let n of t){let o=e.findIndex((s,a)=>a>r&&s.trim()===n.trim());if(o<0)return-1;r=o}return r}function J(e,t,r){let n=X(X(e,t).reverse(),...r.reverse()).reverse(),o=V(n,t),s=n.length-1-V(...n.reverse(),...r.reverse());return[...n.slice(0,o+1),"",...n.slice(o+1,s).join(` ).trim().split(
),"",...n.slice(s)]}async function Z(e){let t="https://scrapbox.io/api/users/me",r=await fetch(t,e?.sid?{headers:{Cookie:I(e.sid)}}:void 0);if(!r.ok)throw L("UnexpectedError",Unexpected error has occuerd when fetching "${t}");return await r.json()}var I=e=>connect.sid=${e};function Ye(e){return e!=null}function qe(e){return Ye(e)?(e.name===void 0||typeof e.name=="string")&&typeof e.message=="string":!1}function S(e){try{let t=typeof e=="string"?JSON.parse(e):e;return qe(t)?t:!1}catch(t){if(t instanceof SyntaxError)return!1;throw t}}function L(e,t){let r=new Error;return r.name=e,r.message=t,r}var U=e=>e.replaceAll(" ","_").toLowerCase();var ee=e=>[...e].map((t,r)=>t===" "?"_":!Be.includes(t)||r===e.length-1&&Ke.includes(t)?encodeURIComponent(t):t).join(""),Be='@$&+=:;",',Ke=':;",';async function xe(e,t,r){let n=https://scrapbox.io/api/pages/${e}/${ee(t)}?followRename=${r?.followRename??!0},o=await fetch(n,r?.sid?{headers:{Cookie:I(r.sid)}}:void 0);if(!o.ok){let a=S(await o.text());if(!a)throw L("UnexpectedError",Unexpected error has occuerd when fetching "${n}");return{ok:!1,value:a}}let s=await o.json();return{ok:!0,value:s}}async function te(e,t){let{sort:r,limit:n,skip:o}=t??{},s=new URLSearchParams;r!==void 0&&s.append("sort",r),n!==void 0&&s.append("limit",${n}),o!==void 0&&s.append("skip",${o});let a=https://scrapbox.io/api/pages/${e}?${s.toString()},i=await fetch(a,t?.sid?{headers:{Cookie:I(t.sid)}}:void 0);if(!i.ok){let d=S(await i.text());if(!d)throw L("UnexpectedError",Unexpected error has occuerd when fetching "${a}");return{ok:!1,value:d}}let c=await i.json();return{ok:!0,value:c}}async function he(e,t){let r=https://scrapbox.io/api/projects/${e},n=await fetch(r,t?.sid?{headers:{Cookie:I(t.sid)}}:void 0);if(!n.ok){let s=S(await n.json());if(!s)throw L("UnexpectedError",Unexpected error has occuerd when fetching "${r}");return{ok:!1,value:s}}let o=await n.json();return{ok:!0,value:o}}var ye=(e,t)=>{if(!(e instanceof HTMLDivElement))throw new TypeError("${t}" must be HTMLDivElememt but actual is "${e}")};var be=()=>Qe(document.getElementsByClassName("status-bar")?.[0],"div.status-bar"),Qe=(e,t)=>{if(!!e)return ye(e,t),e};var F=e=>new Promise(t=>setTimeout(()=>t(),e));function re(){let e=be();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 n=Ee(...r);n&&t.append(n)},dispose:()=>t.remove()}}function Ee(...e){let t=e.flatMap(n=>{switch(n.type){case"spinner":return[Ze()];case"check-circle":return[et()];case"exclamation-triangle":return[tt()];case"text":return[B(n.text)];case"group":{let o=Ee(...n.items);return o?[o]:[]}}});if(t.length===0)return;if(t.length===1)return t[0];let r=document.createElement("span");return r.classList.add("item-group"),r.append(...t),r}function B(e){let t=document.createElement("span");return t.classList.add("item"),t.append(e),t}function Ze(){let e=document.createElement("i");return e.classList.add("fa","fa-spinner"),B(e)}function et(){let e=document.createElement("i");return e.classList.add("kamon","kamon-check-circle"),B(e)}function tt(){let e=document.createElement("i");return e.classList.add("fas","fa-exclamation-triangle"),B(e)}var rt="4.2.0";async function M(){let t=(await nt())("https://scrapbox.io",{reconnectionDelay:5e3,transports:["websocket"]});return await new Promise((r,n)=>{let o=s=>n(s);t.once("connect",()=>{t.off("disconnect",o),r()}),t.once("disconnect",o)}),t}function nt(){let e=https://cdnjs.cloudflare.com/ajax/libs/socket.io/${rt}/socket.io.min.js;if(document.querySelector(scriptsrc="${e}"))return Promise.resolve(window.io);let t=document.createElement("script");return t.src=e,new Promise((r,n)=>{t.onload=()=>r(window.io),t.onerror=o=>n(o),document.head.append(t)})}function A(e,t=9e4){function r(o,s){let a;return new Promise((i,c)=>{let d=u=>{clearTimeout(a),c(new Error(u))};e.emit(o,s,u=>{clearTimeout(a),e.off("disconnect",d),u.error&&c(new Error(JSON.stringify(u.error))),"data"in u?i(u?.data):i(void 0)}),a=setTimeout(()=>{e.off("disconnect",d),c(new Error(Timeout: exceeded ${t}ms))},t),e.once("disconnect",d)})}async function*n(...o){let s,a=()=>new Promise(c=>s=c),i=c=>{s?.(c)};for(let c of o)e.on(c,i);try{for(;;)yield await a()}finally{for(let c of o)e.off(c,i)}}return{request:r,response:n}}function ne(){return M()}async function j(e){if(e.connected)return;let t=new Promise(r=>e.once("connect",()=>r()));e.connect(),await t}async function C(e){if(e.disconnected)return;let t=new Promise(r=>{let n=o=>{o==="io client disconnect"&&(r(),e.off("disconnect",n))};e.on("disconnect",n)});e.disconnect(),await t}var K;async function W(){if(K!==void 0)return K;let e=await Z();if(e.isGuest)throw new Error("this script can only be executed by Logged in users");return K=e.id,K}var ve=new Map;async function _(e){let t=ve.get(e);if(t!==void 0)return t;let r=await he(e);if(!r.ok){let{name:o,message:s}=r.value;throw new Error(${o} ${s})}let{id:n}=r.value;return ve.set(e,n),n}function De(e){return e.padStart(8,"0")}function Te(e){let t=Math.floor(new Date().getTime()/1e3).toString(16),r=Math.floor(16777214*Math.random()).toString(16);return${De(t).slice(-8)}${e.slice(-6)}0000${De(r)}}function Ie(e,t){let r=e.length>t.length,n=r?t:e,o=r?e:t,s=n.length+1,a=n.length+o.length+3,i=new Array(a);i.fill(-1);let c=[];function d(m,k,N){let D=Math.max(k,N),q=D-m;for(;q<n.length&&D<o.length&&n[q]===o[D];)++q,++D;return i[m+s]=c.length,c.push([{x:q,y:D},i[m+(k>N?-1:1)+s]]),D}let u=new Array(a);u.fill(-1);let b=-1,g=o.length-n.length;do{++b;for(let m=-b;m<=g-1;++m)u[m+s]=d(m,u[m-1+s]+1,u[m+1+s]);for(let m=g+b;m>=g+1;--m)u[m+s]=d(m,u[m-1+s]+1,u[m+1+s]);u[g+s]=d(g,u[g-1+s]+1,u[g+1+s])}while(u[g+s]!==o.length);let v=[],w=i[g+s];for(;w!==-1;)v.push(c[w][0]),w=c[w][1];return{from:e,to:t,editDistance:g+b*2,buildSES:function*(){let m=0,k=0;for(let{x:N,y:D}of ot(v))for(;m<N||k<D;)D-N>k-m?(yield{value:o[k],type:r?"deleted":"added"},++k):D-N<k-m?(yield{value:n[m],type:r?"added":"deleted"},++m):(yield{value:n[m],type:"common"},++m,++k)}}}function*Le(e){let t=[],r=[];function*n(){if(t.length>r.length){for(let o=0;o<r.length;o++)yield Me(t[o],r[o]);for(let o=r.length;o<t.length;o++)yield t[o]}else{for(let o=0;o<t.length;o++)yield Me(t[o],r[o]);for(let o=t.length;o<r.length;o++)yield r[o]}t=[],r=[]}for(let o of e)switch(o.type){case"added":t.push(o);break;case"deleted":r.push(o);break;case"common":yield*n(),yield o;break}yield*n()}function Me(e,t){return{value:e.value,oldValue:t.value,type:"replaced"}}function*ot(e){for(let t=e.length-1;t>=0;t--)yield e[t]}function*Ce(e,t,{userId:r}){let{buildSES:n}=Ie(e.map(({text:a})=>a),t),o=0,s=e[0].id;for(let a of Le(n())){switch(a.type){case"added":yield{_insert:s,lines:{id:Te(r),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 st=Object.defineProperty,p=(e,t)=>st(e,"name",{value:t,configurable:!0}),it=p(e=>({type:"title",text:e.rows[0].text}),"convertToTitle"),at=p(e=>{let{rows:[t,...r]}=e,{indent:n=0,text:o=""}=t??{},s=o.replace(/^\s*code:/,"");return{indent:n,type:"codeBlock",fileName:s,content:r.map(a=>a.text.substring(n+1)).join( )}},"convertToCodeBlock"),h=p((e,{parseOnNested:t,parseOnQuoted:r,patterns:n})=>(o,s,a)=>{var i,c,d,u,b,g;if(!t&&s.nested)return(i=a?.())!==null&&i!==void 0?i:[];if(!r&&s.quoted)return(c=a?.())!==null&&c!==void 0?c:[];for(let v of n){let w=v.exec(o);if(w===null)continue;let m=o.substring(0,w.index),k=o.substring(w.index+((u=(d=w[0])===null||d===void 0?void 0:d.length)!==null&&u!==void 0?u:0)),N=e((b=w[0])!==null&&b!==void 0?b:"",s);return[...H(m,s),...N,...H(k,s)]}return(g=a?.())!==null&&g!==void 0?g:[]},"createNodeParser"),y=p(e=>[{type:"plain",raw:e,text:e}],"createPlainNode"),ct=h(y,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]}),ut=/^>.*$/,dt=p((e,t)=>t.context==="table"?y(e,t):[{type:"quote",raw:e,nodes:H(e.substring(1),{...t,quoted:!0})}],"createQuoteNode"),pt=h(dt,{parseOnNested:!1,parseOnQuoted:!1,patterns:[ut]}),lt=/^\? .+$/,mt=p((e,t)=>t.context==="table"?y(e,t):[{type:"helpfeel",raw:e,text:e.substring(2)}],"createHelpfeelNode"),ft=h(mt,{parseOnNested:!1,parseOnQuoted:!1,patterns:[lt]}),gt=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,xt=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,ht=p((e,t)=>{if(t.context==="table")return y(e,t);let r=e.substring(2,e.length-2),n=/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(r);return[{type:"strongImage",raw:e,src:n?${r}/thumb/1000:r}]},"createStrongImageNode"),yt=h(ht,{parseOnNested:!1,parseOnQuoted:!0,patterns:[gt,xt]}),bt=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;function oe(e){return(t,r)=>{if(e==="strongIcon"&&r.context==="table")return y(t,r);let n=e==="icon"?t.substring(1,t.length-1):t.substring(2,t.length-2),o=n.lastIndexOf(".icon"),s=n.substring(0,o),a=s.startsWith("/")?"root":"relative",i=n.substring(o+5,n.length),c=i.startsWith("*")?parseInt(i.substring(1),10):1;return new Array(c).fill({}).map(()=>({path:s,pathType:a,type:e,raw:t}))}}p(oe,"generateIconNodeCreator");var wt=oe("icon"),kt=h(wt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[bt]}),Et=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,vt=oe("strongIcon"),Dt=h(vt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Et]}),Tt=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,It=p((e,t)=>t.context==="table"?y(e,t):[{type:"strong",raw:e,nodes:H(e.substring(2,e.length-2),{...t,nested:!0})}],"createStrongNode"),Lt=h(It,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Tt]}),Mt=/\[\$ .+? \]/,Ct=/\[\$ [^\]]+\]/,Nt=p((e,t)=>t.context==="table"?y(e,t):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],"createFormulaNode"),Ot=h(Nt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Mt,Ct]}),Pt=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,St=p((e,t)=>{if(t.context==="table")return y(e,t);let r=e.indexOf(" "),n=e.substring(1,r),o=e.substring(r+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:H(o,{...t,nested:!0})}]},"createDecorationNode"),At=h(St,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Pt]}),Ht=/.*?/,Rt=p((e,t)=>t.context==="table"?y(e,t):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],"createCodeNode"),jt=h(Rt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ht]}),_t=/^[$%] .+$/,$t=p((e,t)=>{var r;if(t.context==="table")return y(e,t);let n=(r=e[0])!==null&&r!==void 0?r:"",o=e.substring(2);return[{type:"commandLine",raw:e,symbol:n,text:o}]},"createCommandLineNode"),Ut=h($t,{parseOnNested:!1,parseOnQuoted:!1,patterns:[_t]}),Ft=/\[\s+\]/,Wt=p((e,t)=>t.context==="table"?y(e,t):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],"createBlankNode"),Yt=h(Wt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ft]}),qt=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,Bt=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,Kt=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,zt=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,Qt=p(e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(e)||Gt(e),"isImageUrl"),Gt=p(e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),"isGyazoImageUrl"),Xt=p((e,t)=>{if(t.context==="table")return y(e,t);let r=e.search(/\s/),n=r!==-1?e.substring(1,r):e.substring(1,e.length-1),o=r!==-1?e.substring(r,e.length-1).trimLeft():"",[s,a]=Qt(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}]},"createImageNode"),Vt=h(Xt,{parseOnNested:!0,parseOnQuoted:!0,patterns:[qt,Bt,Kt,zt]}),Jt=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,Zt=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,er=/\[https?:\/\/[^\s\]]+\]/,tr=/https?:\/\/[^\s]+/,rr=p((e,t)=>{if(t.context==="table")return y(e,t);let r=e.startsWith("[")&&e.endsWith("]")?e.substring(1,e.length-1):e,n=/^https?:\/\/[^\s\]]/.test(r),o=(n?/^https?:\/\/[^\s\]]+/:/https?:\/\/[^\s\]]+$/).exec(r);if(o?.[0]===void 0)return[];let s=n?r.substring(o[0].length):r.substring(0,o.index-1);return[{type:"link",raw:e,pathType:"absolute",href:o[0],content:s.trim()}]},"createExternalLinkNode"),nr=h(rr,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Jt,Zt,er,tr]}),Ne=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,Oe=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,or=p(e=>{let[t="",r="",n=""]=e.split(","),o=parseFloat(t.replace(/^N/,"").replace(/^S/,"-")),s=parseFloat(r.replace(/^E/,"").replace(/^W/,"-")),a=/^Z\d+$/.test(n)?parseInt(n.replace(/^Z/,""),10):14;return{latitude:o,longitude:s,zoom:a}},"parseCoordinate"),sr=p((e,t)=>{var r;if(t.context==="table")return y(e,t);let n=(r=e.match(Ne))!==null&&r!==void 0?r:e.match(Oe);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:c,zoom:d}=or(s),u=a!==""?https://www.google.com/maps/place/${encodeURIComponent(a)}/@${i},${c},${d}z:https://www.google.com/maps/@${i},${c},${d}z;return[{type:"googleMap",raw:e,latitude:i,longitude:c,zoom:d,place:a,url:u}]},"createGoogleMapNode"),ir=h(sr,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ne,Oe]}),ar=/\[\/?[^[\]]+\]/,cr=p(e=>{let t=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:t.startsWith("/")?"root":"relative",href:t,content:""}]},"createInternalLinkNode"),ur=h(cr,{parseOnNested:!0,parseOnQuoted:!0,patterns:[ar]}),dr=/(?:^|\s)#\S+/,pr=p((e,t)=>{if(t.context==="table")return y(e,t);if(e.startsWith("#"))return[{type:"hashTag",raw:e,href:e.substring(1)}];let r=e.substring(0,1),n=e.substring(1);return[...y(r,t),{type:"hashTag",raw:n,href:n.substring(1)}]},"createHashTagNode"),lr=h(pr,{parseOnNested:!0,parseOnQuoted:!0,patterns:[dr]}),mr=p((e,t,r)=>{var n;return e===""?[]:(n=r?.())!==null&&n!==void 0?n:[]},"FalsyEliminator"),fr=p((...e)=>(t,r)=>e.reduceRight((n,o)=>()=>o(t,r,n),()=>ct(t,r))(),"combineNodeParsers"),H=fr(mr,pt,ft,jt,Ut,Ot,Yt,At,yt,Dt,Lt,Vt,nr,kt,ir,ur,lr),gr=p(e=>{let{rows:[t,...r]}=e,{indent:n=0,text:o=""}=t??{},s=o.replace(/^\s*table:/,"");return{indent:n,type:"table",fileName:s,cells:r.map(a=>a.text.substring(n+1)).map(a=>a.split(" ").map(i=>H(i,{nested:!1,quoted:!1,context:"table"})))}},"convertToTable"),xr=p(e=>{let{indent:t,text:r}=e.rows[0];return{indent:t,type:"line",nodes:H(r.substring(t),{nested:!1,quoted:!1,context:"line"})}},"convertToLine"),se=p(e=>{switch(e.type){case"title":return it(e);case"codeBlock":return at(e);case"table":return gr(e);case"line":return xr(e)}},"convertToBlock"),ie=p(e=>e.split( ).map(t=>{var r,n,o;return{indent:(o=(n=(r=/^\s+/.exec(t))===null||r===void 0?void 0:r[0])===null||n===void 0?void 0:n.length)!==null&&o!==void 0?o:0,text:t}}),"parseToRows"),hr=p((e,t)=>{var r,n;return(e.type==="codeBlock"||e.type==="table")&&t.indent>((n=(r=e.rows[0])===null||r===void 0?void 0:r.indent)!==null&&n!==void 0?n:0)},"isChildRowOfPack"),Pe=p((e,t)=>{let r=e[e.length-1];return r!==void 0&&hr(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)},"packing"),ae=p((e,t)=>{var r;if(!((r=t.hasTitle)!==null&&r!==void 0)||r){let[n,...o]=e;return n===void 0?[]:[{type:"title",rows:[n]},...o.reduce(Pe,[])]}return e.reduce(Pe,[])},"packRows"),Ho=p((e,t)=>{var r;let n=ie(e);return ae(n,{hasTitle:(r=t?.hasTitle)!==null&&r!==void 0?r:!0}).map(se)},"parse"),Ro=p(e=>{var t,r;return(r=(t=/^\s*\S.*$/m.exec(e)?.[0])===null||t===void 0?void 0:t.trim())!==null&&r!==void 0?r:"Untitled"},"getTitle");function Se(e,t,{userId:r,head:n}){let o=t.flatMap(u=>u.split(
)),s=[...Ce(e,o,{userId:r})];(e[0].text!==o[0]||!n.persistent)&&s.push({title:o[0]});let a=e.slice(1,6).map(u=>u.text),i=o.slice(1,6);a.join("")!==i.join("")&&s.push({descriptions:i});let[c,d]=yr(o.join(
));return(n.links.length!==c.length||!n.links.every(u=>c.includes(u)))&&s.push({links:c}),n.image!==d&&s.push({image:d}),s}function yr(e){let t=ie(e),r=ae(t,{hasTitle:!0}).flatMap(i=>{switch(i.type){case"codeBlock":case"title":return[];case"line":case"table":return[se(i)]}}),n=new Map,o=[],s=null,a=i=>{switch(i.type){case"hashTag":if(n.has(U(i.href)))return;n.set(U(i.href),!1),o.push(i.href);return;case"link":if(i.pathType!=="relative"||n.get(U(i.href)))return;n.set(U(i.href),!0),o.push(i.href);return;case"image":case"strongImage":{s??=i.src.endsWith("/thumb/1000")?i.src.replace(/\/thumb\/1000$/,"/raw"):i.src;return}case"strong":case"quote":case"decoration":{for(let c of i.nodes)a(c);return}default:return}};for(let i of br(r))a(i);return[o,s]}function*br(e){for(let t of e)switch(t.type){case"codeBlock":case"title":continue;case"line":for(let r of t.nodes)yield r;continue;case"table":{for(let r of t.cells)for(let n of r)for(let o of n)yield o;continue}}}async function O(e,t){let r=await xe(e,t);if(!r.ok)throw new Error(You have no privilege of editing "/${e}/${t}".);let{commitId:n,persistent:o,image:s,links:a,lines:i,id:c,pin:d}=r.value;return{commitId:n,pageId:c,persistent:o,image:s,links:a,pin:d,lines:i}}async function z(e,t,r){return t.length===0?{commitId:r.parentId}:await e("socket.io-request",{method:"commit",data:{kind:"page",...r,changes:t,cursor:null,freeze:!0}})}async function Y(e,t,{project:r,title:n,retry:o=3,parentId:s,...a}){try{s=(await z(e,t,{parentId:s,...a})).commitId}catch{console.log("Faild to push a commit. Retry after pulling new commits");for(let c=0;c<o;c++){let{commitId:d}=await O(r,n);s=d;try{s=(await z(e,t,{parentId:s,...a})).commitId,console.log("Success in retrying");break}catch{continue}}throw Error("Faild to retry pushing.")}return s}async function ce(e,t,r,n){let[o,s,a]=await Promise.all([O(e,t),_(e),W()]),i=o,c=n?.socket,d=c??await M();await j(d);try{let{request:u}=A(d);for(let b=0;b<3;b++)try{let g=r(i.lines,i),v=g instanceof Promise?await g:g;if(!v)return;v.length===0&&await Y(u,[{deleted:!0}],{projectId:s,pageId:i.pageId,parentId:i.commitId,userId:a,project:e,title:t});let w=Se(i.lines,v,{userId:a,head:i});await z(u,w,{parentId:i.commitId,projectId:s,pageId:i.pageId,userId:a});break}catch{if(b===2)throw Error("Faild to retry pushing.");console.log("Faild to push a commit. Retry after pulling new commits");try{i=await O(e,t)}catch(v){throw v}}}finally{c||await C(d)}}async function ue(e,t,r){let[n,o,s]=await Promise.all([O(e,t),_(e),W()]);if(n.pin==0||!n.persistent)return;let a={parentId:n.commitId,projectId:o,pageId:n.pageId,userId:s,project:e,title:t},i=r?.socket,c=i??await M();await j(c);let{request:d}=A(c);try{await Y(d,[{pin:0}],a)}finally{i||await C(c)}}async function*de(e,t=0){let{count:r,pages:n}=await wr(e,t);for(let o of n)o.pin!==0&&(yield o);(n.at(-1)?.pin??0)!==0&&(yield*de(e,t+1e3))}async function wr(e,t){let r=await te(e,{limit:1e3,skip:t});if(!r.ok){let n=new Error;throw n.name=r.value.name,n.message=r.value.message,n}return r.value}function Ae(e,t){let r=t.interval??24*3600*1e3,n=()=>scrapbox.Project.name===e?kr(e,r,t):Re();n(),scrapbox.addListener("project:changed",n)}var He;async function kr(e,t,r){Re(),await je(e,new Date,r),He=setInterval(()=>je(e,new Date,r),t)}function Re(){clearInterval(He)}async function je(e,t,{makeDiary:r,filter:n}){let{render:o,dispose:s}=re(),a;try{o({type:"spinner"},{type:"text",text:"unpin other diary pages..."}),a=await ne();for await(let{title:u}of de(e))n(u,t)||await ue(e,u,{socket:a});let{title:i,header:c,footer:d}=r(t);o({type:"spinner"},{type:"text",text:format "/${e}/${i}"...}),await ce(e,i,u=>[u[0].text,...J(u.slice(1).map(b=>b.text),c,d)],{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 C(a),await F(1e3),s()}}function l(e,t){if(t.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+t.length+" present")}function f(e){l(1,arguments);let t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="[object Date]"?new Date(e.getTime()):typeof e=="number"||t==="[object Number]"?new Date(e):((typeof e=="string"||t==="[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 Q(e){let t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),e.getTime()-t.getTime()}function x(e){if(e===null||e===!0||e===!1)return NaN;let t=Number(e);return isNaN(t)?t:t<0?Math.ceil(t):Math.floor(t)}function $(e,t){l(2,arguments);let r=f(e),n=x(t);return isNaN(n)?new Date(NaN):(n&&r.setDate(r.getDate()+n),r)}function R(e,t){l(2,arguments);let r=x(t);return $(e,-r)}function pe(e,t){l(2,arguments);let r=f(e),n=x(t);if(isNaN(n))return new Date(NaN);if(!n)return r;let o=r.getDate(),s=new Date(r.getTime());s.setMonth(r.getMonth()+n+1,0);let a=s.getDate();return o>=a?s:(r.setFullYear(s.getFullYear(),s.getMonth(),o),r)}function le(e,t){l(2,arguments);let r=x(t);return pe(e,r*12)}function G(e,t){l(2,arguments);let r=x(t);return le(e,-r)}function T(e,t){for(var r=e<0?"-":"",n=Math.abs(e).toString();n.length<t;)n="0"+n;return r+n}var Er={y(e,t){let r=e.getUTCFullYear(),n=r>0?r:1-r;return T(t==="yy"?n%100:n,t.length)},M(e,t){let r=e.getUTCMonth();return t==="M"?String(r+1):T(r+1,2)},d(e,t){return T(e.getUTCDate(),t.length)},a(e,t){let r=e.getUTCHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return r.toUpperCase();case"aaa":return r;case"aaaaa":return r[0];case"aaaa":default:return r==="am"?"a.m.":"p.m."}},h(e,t){return T(e.getUTCHours()%12||12,t.length)},H(e,t){return T(e.getUTCHours(),t.length)},m(e,t){return T(e.getUTCMinutes(),t.length)},s(e,t){return T(e.getUTCSeconds(),t.length)},S(e,t){let r=t.length,n=e.getUTCMilliseconds(),o=Math.floor(n*Math.pow(10,r-3));return T(o,t.length)}},$e=Er;function me(e){l(1,arguments);var t=f(e);return!isNaN(t)}function fe(e,t){l(2,arguments);let r=f(e).getTime(),n=x(t);return new Date(r+n)}function ge(e,t){l(2,arguments);let r=x(t);return fe(e,-r)}var vr=/(\w)\1*|''|'(''|[^'])+('|$)|./g,Dr=/^'([^]*?)'?$/,Tr=/''/g,Ir=/[a-zA-Z]/;function E(e,t){l(2,arguments);let r=f(e);if(!me(r))throw new RangeError("Invalid time value");let n=Q(r),o=ge(r,n),s=t.match(vr);return s?s.map(i=>{if(i==="''")return"'";let c=i[0];if(c==="'")return Lr(i);let d=$e[c];if(d)return d(o,i);if(c.match(Ir))throw new RangeError("Format string contains an unescaped latin alphabet character "+c+"");return i}).join(""):""}function Lr(e){let t=e.match(Dr);return t?t[1].replace(Tr,"'"):e}var P="作業室yyyy-MM-dd",Mr=/^作業室\d{4}-\d{2}-\d{2}$/;function Ue(e){let t=new Date("2022-11-03T00:00:00"),r=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24)),n=[${E(R(e,1),P)}←${E(e,P)}→${E($(e,1),P)}];r>0&&n.push(成果報告会まで後${r}日),n.push("","[* 予定]","",...[...Array(24).keys()].map(s=>${s}:00),"[* 雑談]");let o=[10日前:${E(R(e,10),P)} 30日前:${E(R(e,30),P)},100日前 ${E(R(e,100),P)} 1年前 ${E(G(e,1),P)}`];return{title:We(e),header:n,footer:o}}function Fe(e,t){return Mr.test(e)?We(t)===e:!0}function We(e){return E(e,P)}Ae("mitoujr",{makeDiary:Ue,filter:Fe});