SharedUserScripts-PC-min
全プロジェクトで使うUserScript for PC
code:script.js
var Gt={left:"ArrowLeft",right:"ArrowRight",up:"ArrowUp",down:"ArrowDown",bs:"Backspace",menu:"ContextMenu",apps:"ContextMenu",del:"Delete",return:"Enter",cr:"Enter",esc:"Escape",pgup:"PageUp",pgdn:"PageDown",lt:"<",less:"<",lesser:"<",gt:">",greater:">"},Wt={Backquote:["","~"],Digit1:["1","!"],Digit2:["2","@"],Digit3:["3","#"],Digit4:["4","$"],Digit5:["5","%"],Digit6:["6","^"],Digit7:["7","&"],Digit8:["8","*"],Digit9:["9","("],Digit0:["0",")"],Minus:["-","_"],Equal:["=","+"],Backslash:["\\","|"],BracketLeft:["[","{"],BracketRight:["]","}"],Semicolon:[";",":"],Quote:["'",'"'],Comma:[",","<"],Period:[".",">"],Slash:["/","?"]},Xt={a:"altKey",c:"ctrlKey",m:"metaKey",s:"shiftKey"},Yt={"<":"lt",">":"gt"},ko=/^($|Unidentified$|Dead$|Alt|Control|Hyper|Meta|Shift|Super|OS)/,Re=(e,t)=>Object.hasOwn(e,t),Vt=e=>{let t=e.toLowerCase();return Re(Gt,t)?Gt[t]:e},wo=(e,t)=>{if(e.startsWith("Key")){let r=e.slice(3);return t||(r=r.toLowerCase()),r}return Re(Wt,e)?Wt[e][t?1:0]:e},mt=e=>{let t=e.shiftKey,r=e.key||"Unidentified";if(r==="Unidentified"?r=wo(e.code||"",t):(r=Vt(r),r===" "&&(r="Space")),ko.test(r))return"";r.length===1?t=!1:r=r.toLowerCase();let n="";return e.altKey&&(n+="a-"),e.ctrlKey&&(n+="c-"),e.metaKey&&(n+="m-"),t&&(n+="s-"),Re(Yt,r)&&(r=Yt[r]),n||r.length>1?<${n}${r}>:r},Lo=e=>{if(e.length===1)return/\s/.test(e)?{ok:!1,value:{name:"InvalidKeyError",key:e,message:Invalid key: ${e}}}:{ok:!0,value:{key:e}};let t=e.match(/^<((?:[a-z]-)*)([a-z\d]+|[^<>\s])>$/i);if(!t)return{ok:!1,value:{name:"InvalidKeyError",key:e,message:Invalid key: ${e}}};let[,r,n]=t,s={key:Vt(n)};for(let o of r.split("-").slice(0,-1)){let c=o.toLowerCase();if(!Re(Xt,c))return{ok:!1,value:{name:"UnknownModifierError",modifier:o,context:e,message:${e}: Unknown modifier: ${o}}};let a=Xt[c];if(s[a]!==void 0)return{ok:!1,value:{name:"DuplicateModifierError",modifier:o,context:e,message:${e}: Duplicate modifier: ${o}}};if(s[a]=!0,s.key.length===1&&s.shiftKey)return{ok:!1,value:{name:"DisallowedModifierError",modifier:o,context:e,message:${e}: Unusable modifier with single-character keys: ${o}}}}return{ok:!0,value:s}},Qt=e=>{let t=Lo(e);return t.ok?{ok:!0,value:mt(t.value)}:t},Jt=e=>e.match(/<[^<>\s]+>|[\s\S]|^$/g);var F=!1;var Zt=e=>Object.fromEntries([...Object.entries(console)].map(([t,r])=>{if(typeof r!="function")return[t,r];switch(t){case"warn":case"error":return[t,(...n)=>r(%c${e},"color: gray",...n)];case"log":case"info":case"debug":return[t,(...n)=>{F!==!0&&(!F||!F.has(e))||r(%c${e},"color: gray",...n)}];case"assert":return[t,(n,...s)=>{F!==!0&&(!F||!F.has(e))||r(n,%c${e},"color: gray",...s)}];case"time":case"timeEnd":return[t,n=>{F!==!0&&(!F||!F.has(e))||r(${e} ${n})}];default:return[t,(...n)=>{if(!(F!==!0&&(!F||!F.has(e))))return r(...n)}]}}));var ee=Zt("ScrapBindings:mod.ts"),ft=class{constructor(t,r){this.target=t;this.bindings=new Map;this._sequence="";this.filtered=new Set;this.backToInitial=()=>{clearTimeout(this.timer),this.currentSequence="",this.prevBestMatchCommand=void 0,this.filtered=new Set(this.bindings.keys()),ee.debug("reset the sequence")};this.handleKeydown=t=>{if(!t.isTrusted)return;let r=mt(t);if(!r)return;if(clearTimeout(this.timer),t.isComposing||t.key==="Process"){this.backToInitial();return}this.currentSequence+=r,ee.debug("sequence",this.currentSequence);let n;for(let o of this.filtered){if(o.startsWith(this.currentSequence)||this.filtered.delete(o),this.currentSequence!==o)continue;let c=this.bindings.get(o);if(!c){this.filtered.delete(o);continue}n=()=>{ee.debug(run ${o});try{c(t)}catch(a){ee.error(a)}finally{this.backToInitial()}}}let s=this.filtered.size;if(ee.debug(${s} candidates: ${...this.filtered.keys().join(", ")}),s>0&&(this.prevBestMatchCommand=n),this.prevBestMatchCommand&&s<2){if(this.prevBestMatchCommand(),s===0){this.handleKeydown(t);return}return}if(s===0){this.backToInitial();return}t.preventDefault(),t.stopPropagation(),this.timer=setTimeout(this.prevBestMatchCommand??this.backToInitial,this.flushInterval)};this.emitChange=()=>{if(this.bindings.size===0){this.backToInitial(),this.target.removeEventListener("keydown",this.handleKeydown);return}this.target.addEventListener("keydown",this.handleKeydown)};this.onSequenceUpdate=r?.onSequenceUpdate,this.flushInterval=r?.flushInterval??1e3}bind(t,r){let n=new Map,s=[];for(let[o,c]of t instanceof Map?t.entries():typeof t=="string"?[[t,r]]:Object.entries(t)){let a=er(o);if(!a.ok){for(let p of a.value)ee.error(${o}: ${p.message});n.set(o,a.value);continue}let i=a.value;this.bindings.set(i,c),i.startsWith(this.currentSequence)&&this.filtered.add(i),s.push(i)}return ee.debug("Binded the following commands:",s),this.emitChange(),n}unbind(...t){for(let r of t){let n=er(r);if(!n.ok)continue;let s=n.value;this.bindings.delete(s),this.filtered.delete(s)}this.emitChange()}reset(){this.bindings.clear(),this.emitChange()}set currentSequence(t){let r=this._sequence!==t;this._sequence=t,r&&this.onSequenceUpdate?.(t)}get currentSequence(){return this._sequence}},_o={name:"InvalidSequenceError",message:"cannot parse the sequence"},er=e=>{let t=Jt(e);if(!t)return{ok:!1,value:[_o]};let r="",n=[];for(let s of t){let o=Qt(s);if(!o.ok){n.push(o.value);continue}r+=o.value}return n.length>0?{ok:!1,value:n}:{ok:!0,value:r}};var tr=!1;scrapbox.addListener("lines:changed",()=>tr=!1);scrapbox.addListener("layout:changed",()=>tr=!1);var rr=(e,t)=>{if(!(e instanceof HTMLDivElement))throw new TypeError("${t}" must be HTMLDivElememt but actual is "${e}")};var nr=(e,t)=>{if(!(e instanceof HTMLTextAreaElement))throw new TypeError("${t}" must be HTMLTextAreaElement but actual is "${e}")};var D=()=>{let e=document.getElementById("text-input");if(!!e)return nr(e,"textarea#text-input"),e};var or=()=>ir(document.getElementsByClassName("popup-menu")?.[0],"div.popup-menu");var sr=()=>ir(document.getElementsByClassName("status-bar")?.[0],"div.status-bar"),ir=(e,t)=>{if(!!e)return rr(e,t),e};var z=(e,t)=>{let{noModifiedKeys:r=!1,...n}=t??{},s={bubbles:!0,cancelable:!0,keyCode:Co[e],...r?{}:{...n}},o=D();if(!o)throw Error("#text-input must exist.");o.dispatchEvent(new KeyboardEvent("keydown",s)),o.dispatchEvent(new KeyboardEvent("keyup",s))},Co={Backspace:8,Tab:9,Enter:13,Delete:46,Escape:27," ":32,PageUp:33,PageDown:34,End:35,Home:36,ArrowLeft:37,ArrowUp:38,ArrowRight:39,ArrowDown:40,a:65,A:65,b:66,B:66,c:67,C:67,d:68,D:68,e:69,E:69,f:70,F:70,g:71,G:71,h:72,H:72,i:73,I:73,j:74,J:74,k:75,K:75,l:76,L:76,m:77,M:77,n:78,N:78,o:79,O:79,p:80,P:80,q:81,Q:81,r:82,R:82,s:83,S:83,t:84,T:84,u:85,U:85,v:86,V:86,w:87,W:87,x:88,X:88,y:89,Y:89,z:90,Z:90,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,F1:113,F2:114,F3:115,F4:116,F5:117,F6:118,F7:119,F8:120,F9:121,F10:122,F11:123,F12:124,":":186,"*":186,";":187,"+":187,"-":189,"=":189,".":190,">":190,"/":191,"?":191,"@":192,"":192,"":219,"{":219,"\\":220,"|":220,"":221,"}":221,"^":222,"~":222,_:226};var gt=e=>new Promise(t=>setTimeout(()=>t(),e));var ye=async e=>{let t=D();if(!t)throw Error("#text-input is not ditected.");t.focus(),t.value=e;let r=new InputEvent("input",{bubbles:!0});t.dispatchEvent(r),await gt(1)};var cr=()=>{let e=sr();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=lr(...r);n&&t.append(n)},dispose:()=>t.remove()}},lr=(...e)=>{let t=e.flatMap(n=>{switch(n.type){case"spinner":returnSo();case"check-circle":returnIo();case"exclamation-triangle":returnRo();case"text":returnBe(n.text);case"group":{let s=lr(...n.items);return s?s:[]}}});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},Be=e=>{let t=document.createElement("span");return t.classList.add("item"),t.append(e),t},So=()=>{let e=document.createElement("i");return e.classList.add("fa","fa-spinner"),Be(e)},Io=()=>{let e=document.createElement("i");return e.classList.add("kamon","kamon-check-circle"),Be(e)},Ro=()=>{let e=document.createElement("i");return e.classList.add("fas","fa-exclamation-triangle"),Be(e)};var ht=()=>{let e=D();if(!e)throw Error("#text-input is not found.");let t=Object.keys(e).find(o=>o.startsWith("__reactFiber"));if(!t)throw Error('#text-input must has the property whose name starts with "__reactFiber"');let r=et.return.return.stateNode._stores,n=r.find(o=>o.constructor.name==="Cursor");if(!n)throw Error('#text-input must has a "Cursor" store.');let s=r.find(o=>o.constructor.name==="Selection");if(!s)throw Error('#text-input must has a "Selection" store.');return{cursor:n,selection:s}};var pr=()=>ht().cursor;var ve=e=>e===void 0?0:typeof e=="boolean"?Number(e):(e.capture?1:0)|(e.once?2:0)|(e.passive?4:0),dr=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 He=new Map,bt=new Map,Oe=(e,t,r)=>{let n=He.get(e)??new Map,s=n.get(t)??new Set;if(s.has(ve(r)))return;if(s.add(ve(r)),n.set(t,s),He.set(e,n),typeof r=="object"&&r?.once){let c=bt.get(t)??new Map,a=ve(r),i=function(l){return xt(e,t,r),c.delete(a),t.call(this,l)};c.set(a,i),bt.set(t,c);let p=D();if(!p)return;p.addEventListener(e,i,r)}let o=D();!o||o.addEventListener(e,t,r)};scrapbox.on("layout:changed",()=>{let e=D();if(!!e)for(lett,rof He)for(letn,sof r)for(let o of s)e.addEventListener(t,n,dr(o))});var xt=(e,t,r)=>{let n=He.get(e);if(!n)return;let s=n.get(t);if(!s)return;let o=ve(r);if(s.delete(o),typeof r=="object"&&r?.once){let a=bt.get(t);if(!a)return;let i=a.get(o);if(!i)return;let p=D();if(!p)return;p.removeEventListener(e,i,r),a.delete(o);return}let c=D();!c||c.removeEventListener(e,t,r)};Oe("keydown",async e=>{e.key!=="Enter"||e.metaKey||e.altKey||!e.ctrlKey||e.shiftKey||await yt()});async function yt(){if(scrapbox.Layout!=="page")return;let e=pr(),t=e.getPosition().line,r=scrapbox.Page.linest;!("codeBlock"in r)||r.codeBlock.start||r.codeBlock.end||(z("End"),z("Enter"),e.setPosition({line:e.getPosition().line,char:r.codeBlock.indent-1}),z("End",{shiftKey:!0}),await ye(code:${r.codeBlock.filename??""}),z("Home"),z("Enter"),z("ArrowUp"))}var De=e=>e.preventDefault(),je=e=>e.stopPropagation(),$e=(e,t)=>{let r=or()?.getElementsByClassName?.("button");if(!r)return;let n=...r.find(s=>t instanceof RegExp?t.test(s.textContent??""):s.textContent===t);n instanceof HTMLDivElement&&e.target===document.activeElement&&(De(e),je(e),n.click())},ur={u:e=>$e(e,"URL"),う:e=>$e(e,"URL"),"4":e=>$e(e,"$"),l:e=>$e(e,"link authors"),"<A-q>":e=>{De(e),je(e),ye("todo.icon")},"<A-w>":e=>{De(e),je(e),ye("done.icon")},"<C-Enter>":e=>{De(e),je(e),yt()}};var{render:Bo}=cr(),vt,Ho=e=>{vt!==void 0&&cancelAnimationFrame(vt),vt=requestAnimationFrame(()=>Bo({type:"text",text:e}))},mr=new ft({addEventListener:Oe,removeEventListener:xt},{onSequenceUpdate:Ho}),fr=mr.bind(ur);fr.size>0&&alert(...fr.entries().map((e,t)=>`${e}: ${t.map(r=>- ${r}).join(`
)}).join(`
));var Ae,h,gr,Oo,Ee,hr,br,xr,Fe={},yr=[],Do=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function X(e,t){for(var r in t)e[r]=t[r];return e}function vr(e){var t=e.parentNode;t&&t.removeChild(e)}function d(e,t,r){var n,s,o,c={};for(o in t)o=="key"?n=t[o]:o=="ref"?s=t[o]:c[o]=t[o];if(arguments.length>2&&(c.children=arguments.length>3?Ae.call(arguments,2):r),typeof e=="function"&&e.defaultProps!=null)for(o in e.defaultProps)c[o]===void 0&&(c[o]=e.defaultProps[o]);return Ue(e,c,n,s,null)}function Ue(e,t,r,n,s){var o={type:e,props:t,key:r,ref:n,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:s??++gr};return s==null&&h.vnode!=null&&h.vnode(o),o}function L(e){return e.children}function Ke(e,t){this.props=e,this.context=t}function se(e,t){if(t==null)return e.__?se(e.__,e.__.__k.indexOf(e)+1):null;for(var r;t<e.__k.length;t++)if((r=e.__k[t])!=null&&r.__e!=null)return r.__e;return typeof e.type=="function"?se(e):null}function Er(e){var t,r;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((r=e.__k[t])!=null&&r.__e!=null){e.__e=e.__c.base=r.__e;break}return Er(e)}}function Et(e){(!e.__d&&(e.__d=!0)&&Ee.push(e)&&!qe.__r++||br!==h.debounceRendering)&&((br=h.debounceRendering)||hr)(qe)}function qe(){for(var e;qe.__r=Ee.length;)e=Ee.sort(function(t,r){return t.__v.__b-r.__v.__b}),Ee=[],e.some(function(t){var r,n,s,o,c,a;t.__d&&(c=(o=(r=t).__v).__e,(a=r.__P)&&(n=[],(s=X({},o)).__v=o.__v+1,kt(a,o,s,r.__n,a.ownerSVGElement!==void 0,o.__h!=null?[c]:null,n,c??se(o),o.__h),Cr(n,o),o.__e!=c&&Er(o)))})}function kr(e,t,r,n,s,o,c,a,i,p){var l,f,g,u,m,b,x,y=n&&n.__k||yr,_=y.length;for(r.__k=[],l=0;l<t.length;l++)if((u=r.__k[l]=(u=t[l])==null||typeof u=="boolean"?null:typeof u=="string"||typeof u=="number"||typeof u=="bigint"?Ue(null,u,null,null,u):Array.isArray(u)?Ue(L,{children:u},null,null,null):u.__b>0?Ue(u.type,u.props,u.key,null,u.__v):u)!=null){if(u.__=r,u.__b=r.__b+1,(g=y[l])===null||g&&u.key==g.key&&u.type===g.type)y[l]=void 0;else for(f=0;f<_;f++){if((g=y[f])&&u.key==g.key&&u.type===g.type){y[f]=void 0;break}g=null}kt(e,u,g=g||Fe,s,o,c,a,i,p),m=u.__e,(f=u.ref)&&g.ref!=f&&(x||(x=[]),g.ref&&x.push(g.ref,null,u),x.push(f,u.__c||m,u)),m!=null?(b==null&&(b=m),typeof u.type=="function"&&u.__k===g.__k?u.__d=i=wr(u,i,e):i=Lr(e,u,g,y,m,i),typeof r.type=="function"&&(r.__d=i)):i&&g.__e==i&&i.parentNode!=e&&(i=se(g))}for(r.__e=b,l=_;l--;)y[l]!=null&&(typeof r.type=="function"&&y[l].__e!=null&&y[l].__e==r.__d&&(r.__d=se(n,l+1)),Nr(y[l],y[l]));if(x)for(l=0;l<x.length;l++)Pr(x[l],x[++l],x[++l])}function wr(e,t,r){for(var n,s=e.__k,o=0;s&&o<s.length;o++)(n=s[o])&&(n.__=e,t=typeof n.type=="function"?wr(n,t,r):Lr(r,n,n,s,n.__e,t));return t}function Lr(e,t,r,n,s,o){var c,a,i;if(t.__d!==void 0)c=t.__d,t.__d=void 0;else if(r==null||s!=o||s.parentNode==null)e:if(o==null||o.parentNode!==e)e.appendChild(s),c=null;else{for(a=o,i=0;(a=a.nextSibling)&&i<n.length;i+=2)if(a==s)break e;e.insertBefore(s,o),c=o}return c!==void 0?c:s.nextSibling}function jo(e,t,r,n,s){var o;for(o in r)o==="children"||o==="key"||o in t||ze(e,o,null,r[o],n);for(o in t)s&&typeof t[o]!="function"||o==="children"||o==="key"||o==="value"||o==="checked"||r[o]===t[o]||ze(e,o,t[o],r[o],n)}function _r(e,t,r){t[0]==="-"?e.setProperty(t,r):e[t]=r==null?"":typeof r!="number"||Do.test(t)?r:r+"px"}function ze(e,t,r,n,s){var o;e:if(t==="style")if(typeof r=="string")e.style.cssText=r;else{if(typeof n=="string"&&(e.style.cssText=n=""),n)for(t in n)r&&t in r||_r(e.style,t,"");if(r)for(t in r)n&&r[t]===n[t]||_r(e.style,t,r[t])}else if(t[0]==="o"&&t[1]==="n")o=t!==(t=t.replace(/Capture$/,"")),t=t.toLowerCase()in e?t.toLowerCase().slice(2):t.slice(2),e.l||(e.l={}),e.l[t+o]=r,r?n||e.addEventListener(t,o?Mr:Tr,o):e.removeEventListener(t,o?Mr:Tr,o);else if(t!=="dangerouslySetInnerHTML"){if(s)t=t.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if(t!=="href"&&t!=="list"&&t!=="form"&&t!=="tabIndex"&&t!=="download"&&t in e)try{e[t]=r??"";break e}catch{}typeof r=="function"||(r!=null&&(r!==!1||t[0]==="a"&&t[1]==="r")?e.setAttribute(t,r):e.removeAttribute(t))}}function Tr(e){this.l[e.type+!1](h.event?h.event(e):e)}function Mr(e){this.l[e.type+!0](h.event?h.event(e):e)}function kt(e,t,r,n,s,o,c,a,i){var p,l,f,g,u,m,b,x,y,_,K,R=t.type;if(t.constructor!==void 0)return null;r.__h!=null&&(i=r.__h,a=t.__e=r.__e,t.__h=null,o=[a]),(p=h.__b)&&p(t);try{e:if(typeof R=="function"){if(x=t.props,y=(p=R.contextType)&&n[p.__c],_=p?y?y.props.value:p.__:n,r.__c?b=(l=t.__c=r.__c).__=l.__E:("prototype"in R&&R.prototype.render?t.__c=l=new R(x,_):(t.__c=l=new Ke(x,_),l.constructor=R,l.render=Ao),y&&y.sub(l),l.props=x,l.state||(l.state={}),l.context=_,l.__n=n,f=l.__d=!0,l.__h=[]),l.__s==null&&(l.__s=l.state),R.getDerivedStateFromProps!=null&&(l.__s==l.state&&(l.__s=X({},l.__s)),X(l.__s,R.getDerivedStateFromProps(x,l.__s))),g=l.props,u=l.state,f)R.getDerivedStateFromProps==null&&l.componentWillMount!=null&&l.componentWillMount(),l.componentDidMount!=null&&l.__h.push(l.componentDidMount);else{if(R.getDerivedStateFromProps==null&&x!==g&&l.componentWillReceiveProps!=null&&l.componentWillReceiveProps(x,_),!l.__e&&l.shouldComponentUpdate!=null&&l.shouldComponentUpdate(x,l.__s,_)===!1||t.__v===r.__v){l.props=x,l.state=l.__s,t.__v!==r.__v&&(l.__d=!1),l.__v=t,t.__e=r.__e,t.__k=r.__k,t.__k.forEach(function(q){q&&(q.__=t)}),l.__h.length&&c.push(l);break e}l.componentWillUpdate!=null&&l.componentWillUpdate(x,l.__s,_),l.componentDidUpdate!=null&&l.__h.push(function(){l.componentDidUpdate(g,u,m)})}l.context=_,l.props=x,l.state=l.__s,(p=h.__r)&&p(t),l.__d=!1,l.__v=t,l.__P=e,p=l.render(l.props,l.state,l.context),l.state=l.__s,l.getChildContext!=null&&(n=X(X({},n),l.getChildContext())),f||l.getSnapshotBeforeUpdate==null||(m=l.getSnapshotBeforeUpdate(g,u)),K=p!=null&&p.type===L&&p.key==null?p.props.children:p,kr(e,Array.isArray(K)?K:[K],t,r,n,s,o,c,a,i),l.base=t.__e,t.__h=null,l.__h.length&&c.push(l),b&&(l.__E=l.__=null),l.__e=!1}else o==null&&t.__v===r.__v?(t.__k=r.__k,t.__e=r.__e):t.__e=$o(r.__e,t,r,n,s,o,c,i);(p=h.diffed)&&p(t)}catch(q){t.__v=null,(i||o!=null)&&(t.__e=a,t.__h=!!i,o[o.indexOf(a)]=null),h.__e(q,t,r)}}function Cr(e,t){h.__c&&h.__c(t,e),e.some(function(r){try{e=r.__h,r.__h=[],e.some(function(n){n.call(r)})}catch(n){h.__e(n,r.__v)}})}function $o(e,t,r,n,s,o,c,a){var i,p,l,f=r.props,g=t.props,u=t.type,m=0;if(u==="svg"&&(s=!0),o!=null){for(;m<o.length;m++)if((i=o[m])&&"setAttribute"in i==!!u&&(u?i.localName===u:i.nodeType===3)){e=i,o[m]=null;break}}if(e==null){if(u===null)return document.createTextNode(g);e=s?document.createElementNS("http://www.w3.org/2000/svg",u):document.createElement(u,g.is&&g),o=null,a=!1}if(u===null)f===g||a&&e.data===g||(e.data=g);else{if(o=o&&Ae.call(e.childNodes),p=(f=r.props||Fe).dangerouslySetInnerHTML,l=g.dangerouslySetInnerHTML,!a){if(o!=null)for(f={},m=0;m<e.attributes.length;m++)f[e.attributes[m].name]=e.attributes[m].value;(l||p)&&(l&&(p&&l.__html==p.__html||l.__html===e.innerHTML)||(e.innerHTML=l&&l.__html||""))}if(jo(e,g,f,s,a),l)t.__k=[];else if(m=t.props.children,kr(e,Array.isArray(m)?m:[m],t,r,n,s&&u!=="foreignObject",o,c,o?o[0]:r.__k&&se(r,0),a),o!=null)for(m=o.length;m--;)o[m]!=null&&vr(o[m]);a||("value"in g&&(m=g.value)!==void 0&&(m!==f.value||m!==e.value||u==="progress"&&!m)&&ze(e,"value",m,f.value,!1),"checked"in g&&(m=g.checked)!==void 0&&m!==e.checked&&ze(e,"checked",m,f.checked,!1))}return e}function Pr(e,t,r){try{typeof e=="function"?e(t):e.current=t}catch(n){h.__e(n,r)}}function Nr(e,t,r){var n,s;if(h.unmount&&h.unmount(e),(n=e.ref)&&(n.current&&n.current!==e.__e||Pr(n,null,t)),(n=e.__c)!=null){if(n.componentWillUnmount)try{n.componentWillUnmount()}catch(o){h.__e(o,t)}n.base=n.__P=null}if(n=e.__k)for(s=0;s<n.length;s++)n[s]&&Nr(n[s],t,typeof e.type!="function");r||e.__e==null||vr(e.__e),e.__e=e.__d=void 0}function Ao(e,t,r){return this.constructor(e,r)}function Ge(e,t,r){var n,s,o;h.__&&h.__(e,t),s=(n=typeof r=="function")?null:r&&r.__k||t.__k,o=[],kt(t,e=(!n&&r||t).__k=d(L,null,[e]),s||Fe,Fe,t.ownerSVGElement!==void 0,!n&&r?[r]:s?null:t.firstChild?Ae.call(t.childNodes):null,o,!n&&r?r:s?s.__e:t.firstChild,n),Cr(o,e)}function wt(e,t){var r={__c:t="__cC"+xr++,__:e,Consumer:function(n,s){return n.children(s)},Provider:function(n){var s,o;return this.getChildContext||(s=[],(o={})[t]=this,this.getChildContext=function(){return o},this.shouldComponentUpdate=function(c){this.props.value!==c.value&&s.some(Et)},this.sub=function(c){s.push(c);var a=c.componentWillUnmount;c.componentWillUnmount=function(){s.splice(s.indexOf(c),1),a&&a.call(c)}}),n.children}};return r.Provider.__=r.Consumer.contextType=r}Ae=yr.slice,h={__e:function(e,t){for(var r,n,s;t=t.__;)if((r=t.__c)&&!r.__)try{if((n=r.constructor)&&n.getDerivedStateFromError!=null&&(r.setState(n.getDerivedStateFromError(e)),s=r.__d),r.componentDidCatch!=null&&(r.componentDidCatch(e),s=r.__d),s)return r.__E=r}catch(o){e=o}throw e}},gr=0,Oo=function(e){return e!=null&&e.constructor===void 0},Ke.prototype.setState=function(e,t){var r;r=this.__s!=null&&this.__s!==this.state?this.__s:this.__s=X({},this.state),typeof e=="function"&&(e=e(X({},r),this.props)),e&&X(r,e),e!=null&&this.__v&&(t&&this.__h.push(t),Et(this))},Ke.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Et(this))},Ke.prototype.render=L,Ee=[],hr=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,qe.__r=0,xr=0;var ie,B,Sr,ke=0,Lt=[],Ir=h.__b,Rr=h.__r,Br=h.diffed,Hr=h.__c,Or=h.unmount;function we(e,t){h.__h&&h.__h(B,e,ke||t),ke=0;var r=B.__H||(B.__H={__:[],__h:[]});return e>=r.__.length&&r.__.push({}),r.__[e]}function C(e){return ke=1,Fo(jr,e)}function Fo(e,t,r){var n=we(ie++,2);return n.t=e,n.__c||(n.__=[r?r(t):jr(void 0,t),function(s){var o=n.t(n.__[0],s);n.__[0]!==o&&(n.__=[o,n.__[1]],n.__c.setState({}))}],n.__c=B),n.__}function j(e,t){var r=we(ie++,3);!h.__s&&Tt(r.__H,t)&&(r.__=e,r.__H=t,B.__H.__h.push(r))}function We(e,t){var r=we(ie++,4);!h.__s&&Tt(r.__H,t)&&(r.__=e,r.__H=t,B.__h.push(r))}function ae(e){return ke=5,k(function(){return{current:e}},[])}function k(e,t){var r=we(ie++,7);return Tt(r.__H,t)&&(r.__=e(),r.__H=t,r.__h=e),r.__}function O(e,t){return ke=8,k(function(){return e},t)}function Y(e){var t=B.context[e.__c],r=we(ie++,9);return r.c=e,t?(r.__==null&&(r.__=!0,t.sub(B)),t.props.value):e.__}function Uo(){var e;for(Lt.sort(function(t,r){return t.__v.__b-r.__v.__b});e=Lt.pop();)if(e.__P)try{e.__H.__h.forEach(Xe),e.__H.__h.forEach(_t),e.__H.__h=[]}catch(t){e.__H.__h=[],h.__e(t,e.__v)}}h.__b=function(e){B=null,Ir&&Ir(e)},h.__r=function(e){Rr&&Rr(e),ie=0;var t=(B=e.__c).__H;t&&(t.__h.forEach(Xe),t.__h.forEach(_t),t.__h=[])},h.diffed=function(e){Br&&Br(e);var t=e.__c;t&&t.__H&&t.__H.__h.length&&(Lt.push(t)!==1&&Sr===h.requestAnimationFrame||((Sr=h.requestAnimationFrame)||function(r){var n,s=function(){clearTimeout(o),Dr&&cancelAnimationFrame(n),setTimeout(r)},o=setTimeout(s,100);Dr&&(n=requestAnimationFrame(s))})(Uo)),B=null},h.__c=function(e,t){t.some(function(r){try{r.__h.forEach(Xe),r.__h=r.__h.filter(function(n){return!n.__||_t(n)})}catch(n){t.some(function(s){s.__h&&(s.__h=[])}),t=[],h.__e(n,r.__v)}}),Hr&&Hr(e,t)},h.unmount=function(e){Or&&Or(e);var t,r=e.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{Xe(n)}catch(s){t=s}}),t&&h.__e(t,r.__v))};var Dr=typeof requestAnimationFrame=="function";function Xe(e){var t=B,r=e.__c;typeof r=="function"&&(e.__c=void 0,r()),B=t}function _t(e){var t=B;e.__c=e.__(),B=t}function Tt(e,t){return!e||e.length!==t.length||t.some(function(r,n){return r!==e[n]})}function jr(e,t){return typeof t=="function"?t(e):t}var w=e=>{let{fetch:t=globalThis.fetch,hostName:r="scrapbox.io",...n}=e;return{fetch:t,hostName:r,...n}};var qo=e=>typeof e=="object"&&e!==null,zo=e=>qo(e)?(e.name===void 0||typeof e.name=="string")&&typeof e.message=="string":!1,$r=e=>{try{let t=typeof e=="string"?JSON.parse(e):e;return zo(t)?t:!1}catch(t){if(t instanceof SyntaxError)return!1;throw t}};var ce=class extends Error{constructor(t){super(${t.status} ${t.statusText} when fetching ${t.url});this.response=t;this.name="UnexpectedResponseError";Error.captureStackTrace&&Error.captureStackTrace(this,ce)}},M=async e=>{let t=e.clone(),r=await t.text(),n=$r(r);if(!n)throw new ce(t);return{ok:!1,value:n}};var T=e=>connect.sid=${e};var H=e=>e.replaceAll(" ","_").toLowerCase();var P=e=>[...e].map((t,r)=>t===" "?"_":!Go.includes(t)||r===e.length-1&&Wo.includes(t)?encodeURIComponent(t):t).join(""),Go='@$&+=:;",',Wo=':;",';var Ar=(e,t,r)=>{let{sid:n,hostName:s,followRename:o,projects:c}=w(r??{}),a=new URLSearchParams;a.append("followRename",${o??!0});for(let p of c??[])a.append("projects",p);let i=https://${s}/api/pages/${e}/${P(t)}?${a.toString()};return new Request(i,n?{headers:{Cookie:T(n)}}:void 0)},Fr=async e=>{if(!e.ok)return e.status===414?{ok:!1,value:{name:"TooLongURIError",message:"project ids may be too much."}}:M(e);let t=await e.json();return{ok:!0,value:t}},le=async(e,t,r)=>{let{fetch:n}=w(r??{}),s=Ar(e,t,r),o=await n(s);return await Fr(o)};le.toRequest=Ar;le.fromResponse=Fr;var Ur=(e,t)=>{let{sid:r,hostName:n,sort:s,limit:o,skip:c}=w(t??{}),a=new URLSearchParams;s!==void 0&&a.append("sort",s),o!==void 0&&a.append("limit",${o}),c!==void 0&&a.append("skip",${c});let i=https://${n}/api/pages/${e}?${a.toString()};return new Request(i,r?{headers:{Cookie:T(r)}}:void 0)},Kr=async e=>{if(!e.ok)return M(e);let t=await e.json();return{ok:!0,value:t}},qr=async(e,t)=>{let{fetch:r}=w(t??{}),n=await r(Ur(e,t));return await Kr(n)};qr.toRequest=Ur;qr.fromResponse=Kr;var zr=(e,t,r,n)=>{let{sid:s,hostName:o}=w(n??{}),c=https://${o}/api/table/${e}/${P(t)}/${encodeURIComponent(r)}.csv;return new Request(c,s?{headers:{Cookie:T(s)}}:void 0)},Gr=async e=>e.ok?{ok:!0,value:await e.text()}:e.status===404?{ok:!1,value:{name:"NotFoundError",message:"Table not found."}}:M(e),Wr=async(e,t,r,n)=>{let{fetch:s}=w(n??{}),o=zr(e,t,r,n),c=await s(o);return await Gr(c)};Wr.toRequest=zr;Wr.fromResponse=Gr;var Xr=(e,t)=>{let{sid:r,hostName:n}=w(t??{});return new Request(https://${n}/api/projects/${e},r?{headers:{Cookie:T(r)}}:void 0)},Yr=async e=>{if(!e.ok)return M(e);let t=await e.json();return{ok:!0,value:t}},Le=async(e,t)=>{let{fetch:r}=w(t??{}),n=Xr(e,t),s=await r(n);return Yr(s)};Le.toRequest=Xr;Le.fromResponse=Yr;var Vr=(e,t)=>{let{sid:r,hostName:n}=w(t??{}),s=new URLSearchParams;for(let o of e)s.append("ids",o);return new Request(https://${n}/api/projects?${s.toString()},r?{headers:{Cookie:T(r)}}:void 0)},Qr=async e=>{if(!e.ok)return M(e);let t=await e.json();return{ok:!0,value:t}},Ye=async(e,t)=>{let{fetch:r}=w(t??{}),n=await r(Vr(e,t));return Qr(n)};Ye.toRequest=Vr;Ye.fromResponse=Qr;var Jr=(e,t,r,n)=>{let{sid:s,hostName:o}=w(n??{}),c=https://${o}/api/code/${e}/${P(t)}/${P(r)};return new Request(c,s?{headers:{Cookie:T(s)}}:void 0)},Zr=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"}}:M(e),en=async(e,t,r,n)=>{let{fetch:s}=w(n??{}),o=Jr(e,t,r,n),c=await s(o);return await Zr(c)};en.toRequest=Jr;en.fromResponse=Zr;var tn=new TextEncoder().encode("0123456789abcdef");function rn(e){let t=new Uint8Array(e.length*2);for(let r=0;r<t.length;r++){let n=e[r];t[r*2]=tn[n>>4],t[r*2+1]=tn[n&15]}return t}var nn="md5: data is invalid type",te=64,Mt=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(te),this.#i=0,this.#s=0,this.#a=0}#l(t){let r=this.#s;r+=t,r>4294967295&&(this.#a+=1),this.#s=r>>>0}#c(t){let r=this.#e,n=this.#t,s=this.#r,o=this.#n,c=Z=>t[Z]|t[Z+1]<<8|t[Z+2]<<16|t[Z+3]<<24,a=(Z,zt)=>Z<<zt|Z>>>32-zt,i=c(0),p=c(4),l=c(8),f=c(12),g=c(16),u=c(20),m=c(24),b=c(28),x=c(32),y=c(36),_=c(40),K=c(44),R=c(48),q=c(52),Se=c(56),Ie=c(60);r=n+a(((s^o)&n^o)+r+i+3614090360,7),o=r+a(((n^s)&r^s)+o+p+3905402710,12),s=o+a(((r^n)&o^n)+s+l+606105819,17),n=s+a(((o^r)&s^r)+n+f+3250441966,22),r=n+a(((s^o)&n^o)+r+g+4118548399,7),o=r+a(((n^s)&r^s)+o+u+1200080426,12),s=o+a(((r^n)&o^n)+s+m+2821735955,17),n=s+a(((o^r)&s^r)+n+b+4249261313,22),r=n+a(((s^o)&n^o)+r+x+1770035416,7),o=r+a(((n^s)&r^s)+o+y+2336552879,12),s=o+a(((r^n)&o^n)+s+_+4294925233,17),n=s+a(((o^r)&s^r)+n+K+2304563134,22),r=n+a(((s^o)&n^o)+r+R+1804603682,7),o=r+a(((n^s)&r^s)+o+q+4254626195,12),s=o+a(((r^n)&o^n)+s+Se+2792965006,17),n=s+a(((o^r)&s^r)+n+Ie+1236535329,22),r=n+a(((n^s)&o^s)+r+p+4129170786,5),o=r+a(((r^n)&s^n)+o+m+3225465664,9),s=o+a(((o^r)&n^r)+s+K+643717713,14),n=s+a(((s^o)&r^o)+n+i+3921069994,20),r=n+a(((n^s)&o^s)+r+u+3593408605,5),o=r+a(((r^n)&s^n)+o+_+38016083,9),s=o+a(((o^r)&n^r)+s+Ie+3634488961,14),n=s+a(((s^o)&r^o)+n+g+3889429448,20),r=n+a(((n^s)&o^s)+r+y+568446438,5),o=r+a(((r^n)&s^n)+o+Se+3275163606,9),s=o+a(((o^r)&n^r)+s+f+4107603335,14),n=s+a(((s^o)&r^o)+n+x+1163531501,20),r=n+a(((n^s)&o^s)+r+q+2850285829,5),o=r+a(((r^n)&s^n)+o+l+4243563512,9),s=o+a(((o^r)&n^r)+s+b+1735328473,14),n=s+a(((s^o)&r^o)+n+R+2368359562,20),r=n+a((n^s^o)+r+u+4294588738,4),o=r+a((r^n^s)+o+x+2272392833,11),s=o+a((o^r^n)+s+K+1839030562,16),n=s+a((s^o^r)+n+Se+4259657740,23),r=n+a((n^s^o)+r+p+2763975236,4),o=r+a((r^n^s)+o+g+1272893353,11),s=o+a((o^r^n)+s+b+4139469664,16),n=s+a((s^o^r)+n+_+3200236656,23),r=n+a((n^s^o)+r+q+681279174,4),o=r+a((r^n^s)+o+i+3936430074,11),s=o+a((o^r^n)+s+f+3572445317,16),n=s+a((s^o^r)+n+m+76029189,23),r=n+a((n^s^o)+r+y+3654602809,4),o=r+a((r^n^s)+o+R+3873151461,11),s=o+a((o^r^n)+s+Ie+530742520,16),n=s+a((s^o^r)+n+l+3299628645,23),r=n+a((s^(n|~o))+r+i+4096336452,6),o=r+a((n^(r|~s))+o+b+1126891415,10),s=o+a((r^(o|~n))+s+Se+2878612391,15),n=s+a((o^(s|~r))+n+u+4237533241,21),r=n+a((s^(n|~o))+r+R+1700485571,6),o=r+a((n^(r|~s))+o+f+2399980690,10),s=o+a((r^(o|~n))+s+_+4293915773,15),n=s+a((o^(s|~r))+n+p+2240044497,21),r=n+a((s^(n|~o))+r+x+1873313359,6),o=r+a((n^(r|~s))+o+Ie+4264355552,10),s=o+a((r^(o|~n))+s+m+2734768916,15),n=s+a((o^(s|~r))+n+q+1309151649,21),r=n+a((s^(n|~o))+r+g+4149444226,6),o=r+a((n^(r|~s))+o+K+3174756917,10),s=o+a((r^(o|~n))+s+l+718787259,15),n=s+a((o^(s|~r))+n+y+3951481745,21),this.#e=this.#e+r>>>0,this.#t=this.#t+n>>>0,this.#r=this.#r+s>>>0,this.#n=this.#n+o>>>0}update(t){let r;if(typeof t=="string")r=new TextEncoder().encode(t);else if(typeof t=="object")if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))r=new Uint8Array(t);else throw new TypeError(nn);else throw new TypeError(nn);let n=this.#i,s=te-n;if(r.length<s)this.#o.set(r,n),n+=r.length;else{this.#o.set(r.slice(0,s),n),this.#c(this.#o);let o=s;for(;o+te<=r.length;)this.#c(r.slice(o,o+te)),o+=te;this.#o.fill(0).set(r.slice(o),0),n=r.length-o}return this.#i=n,this.#l(r.length),this}digest(){let t=te-this.#i;t<9&&(t+=te);let r=new Uint8Array(t);r[0]=128;let n=this.#s<<3,s=this.#a<<3|this.#s>>>29;r[r.length-8]=n&255,r[r.length-7]=n>>>8&255,r[r.length-6]=n>>>16&255,r[r.length-5]=n>>>24&255,r[r.length-4]=s&255,r[r.length-3]=s>>>8&255,r[r.length-2]=s>>>16&255,r[r.length-1]=s>>>24&255,this.update(r.buffer);let o=new ArrayBuffer(16),c=new DataView(o);return c.setUint32(0,this.#e,!0),c.setUint32(4,this.#t,!0),c.setUint32(8,this.#r,!0),c.setUint32(12,this.#n,!0),o}toString(t="hex"){let r=this.digest();switch(t){case"hex":return new TextDecoder().decode(rn(new Uint8Array(r)));case"base64":{let n=new Uint8Array(r),s="";for(let o=0;o<n.length;++o)s+=String.fromCharCode(n[o]);return btoa(s)}default:throw new Error("md5: invalid format")}}};var re=e=>new Promise(t=>setTimeout(()=>t(),e));var Xo=/https?:\/\/(?:www\.|music\.|)youtube\.com\/watch/,Yo=/https?:\/\/youtu\.be\/([a-zA-Z\d_-]+)(?:\?([^\s]{0,100})|)/,Vo=/https?:\/\/(?:www\.|)youtube\.com\/shorts\/([a-zA-Z\d_-]+)(?:\?([^\s]+)|)/,Qo=/https?:\/\/(?:www\.|music\.|)youtube\.com\/playlist\?((?:[^\s]+&|)list=([a-zA-Z\d_-]+)(?:&[^\s]+|))/,on=e=>{if(Xo.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(Yo);if(t){let[,r,n]=t;return{videoId:r,params:new URLSearchParams(n),pathType:"dotbe"}}}{let t=e.match(Vo);if(t){let[,r,n]=t;return{videoId:r,params:new URLSearchParams(n),pathType:"short"}}}{let t=e.match(Qo);if(t){let[,r,n]=t;return{listId:n,params:new URLSearchParams(r),pathType:"list"}}}};var Jo=/https?:\/\/vimeo\.com\/([0-9]+)/i,sn=e=>{let t=e.match(Jo);if(!!t)return t[1]};var Zo=/https?:\/\/open\.spotify\.com\/(track|artist|playlist|album|episode|show)\/([a-zA-Z\d_-]+)(?:\?[^\s]{0,100}|)/,an=e=>{let t=e.match(Zo);if(!t)return;let[,r,n]=t;return{videoId:n,pathType:r}};var es=/https?:\/\/anchor\.fm\/[a-zA-Z\d_-]+\/episodes\/([a-zA-Z\d_-]+(?:\/[a-zA-Z\d_-]+)?)(?:\?[^\s]{0,100}|)/,cn=e=>{let t=e.match(es);if(!t)return;let[,r]=t;return r};var ln=e=>{let{type:t,pathType:r,content:n,href:s,...o}=e;if(n===""){let c=on(s);if(c)return{type:"youtube",href:s,...c,...o};let a=sn(s);if(a)return{type:"vimeo",videoId:a,href:s,...o};let i=an(s);if(i)return{type:"spotify",href:s,...i,...o};let p=cn(s);if(p)return{type:"anchor-fm",videoId:p,href:s,...o};if(rs(s))return{type:"video",href:s,...o}}return ts(s)?{type:"audio",content:n,href:s,...o}:{type:"absoluteLink",content:n,href:s,...o}},ts=e=>/\.(?:mp3|ogg|wav|aac)$/.test(e),rs=e=>/\.(?:mp4|webm)$/.test(e);var pn=async()=>{let e=localStorage.getItem("projectsLastAccessed");if(!e)return[];try{let t=JSON.parse(e),r=Object.entries(t).sort(([,o],[,c])=>c-o).map(([o])=>o),n=await Ye([]);if(!n.ok)return r;let s=n.value.projects.map(o=>o.id);return r.filter(o=>!s.includes(o))}catch(t){if(!(t instanceof SyntaxError))throw t;return[]}};var dn;(function(e){})(dn||(dn={}));var ns="0.13.3",un,mn=async(e=ns)=>{let t=https://cdnjs.cloudflare.com/ajax/libs/KaTeX/${e}/katex.min.js;if(document.querySelector(scriptsrc="${t}"))return window.katex!==void 0?Promise.resolve(window.katex):await new Promise(n=>{let s=setInterval(()=>{window.katex!==void 0&&(clearInterval(s),n(window.katex))},500)});let r=document.createElement("script");return r.src=t,un??=new Promise((n,s)=>{r.onload=()=>n(window.katex),r.onerror=o=>s(o),document.head.append(r)}),un};var _e=(e,t={})=>{let r=ae(null),[n,s]=C(e),[o,c]=C("");return j(()=>{(async()=>{let{render:a}=await mn();if(!!r.current)try{a(n,r.current,t),c("")}catch(i){if(i instanceof Error&&i.name==="ParseError")c(i.message.slice("KaTeX parse error: ".length));else throw i}})()},[n]),{ref:r,error:o,setFormula:s}};var fn=!1;scrapbox.addListener("lines:changed",()=>fn=!1);scrapbox.addListener("layout:changed",()=>fn=!1);var gn=(e,t)=>{if(!(e instanceof HTMLTextAreaElement))throw new TypeError("${t}" must be HTMLTextAreaElement but actual is "${e}")};var pe=()=>{let e=document.getElementById("text-input");if(!!e)return gn(e,"textarea#text-input"),e};var Ct=e=>{let t=JSON.parse(localStorage.getItem("pageTransitionContext")??""),r=e.type==="page"?e.from.project===e.to.project?e.from.title===e.to.title?{titleHint:e.to.title}:{linkFrom:e.from.title}:{linkFrom:/${e.from.project}/${e.from.title}}:{searchQuery:e.query};t[page_${H(e.to.title)}]=r,localStorage.setItem("pageTransitionContext",JSON.stringify(t))};var bn=async(e,t)=>{let r=await globalThis.caches.keys();for(let n of r.sort().reverse()){let o=await(await caches.open(n)).match(e,t);if(o)return o}};var xn=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 ps=new Map,If=new Map;scrapbox.on("layout:changed",()=>{let e=pe();if(!!e)for(let[t,r]of ps)for(let[n,s]of r)for(let o of s)e.addEventListener(t,n,xn(o))});var ds=e=>({type:"title",text:e.rows[0].text}),us=e=>{let{rows:[t,...r]}=e,{indent:n=0,text:s=""}=t??{},o=s.replace(/^\s*code:/,"");return{indent:n,type:"codeBlock",fileName:o,content:r.map(c=>c.text.substring(n+1)).join( )}},N=(e,{parseOnNested:t,parseOnQuoted:r,patterns:n})=>(s,o,c)=>{var a,i,p,l,f,g;if(!t&&o.nested)return(a=c?.())!==null&&a!==void 0?a:[];if(!r&&o.quoted)return(i=c?.())!==null&&i!==void 0?i:[];for(let u of n){let m=u.exec(s);if(m===null)continue;let b=s.substring(0,m.index),x=s.substring(m.index+((l=(p=m[0])===null||p===void 0?void 0:p.length)!==null&&l!==void 0?l:0)),y=e((f=m[0])!==null&&f!==void 0?f:"",o);return[...V(b,o),...y,...V(x,o)]}return(g=c?.())!==null&&g!==void 0?g:[]},I=e=>[{type:"plain",raw:e,text:e}],ms=N(I,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]}),fs=/^>.*$/,gs=(e,t)=>t.context==="table"?I(e,t):[{type:"quote",raw:e,nodes:V(e.substring(1),{...t,quoted:!0})}],hs=N(gs,{parseOnNested:!1,parseOnQuoted:!1,patterns:[fs]}),bs=/^\? .+$/,xs=(e,t)=>t.context==="table"?I(e,t):[{type:"helpfeel",raw:e,text:e.substring(2)}],ys=N(xs,{parseOnNested:!1,parseOnQuoted:!1,patterns:[bs]}),vs=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,Es=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,ks=(e,t)=>{if(t.context==="table")return I(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}]},ws=N(ks,{parseOnNested:!1,parseOnQuoted:!0,patterns:[vs,Es]}),Ls=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;function yn(e){return(t,r)=>{if(e==="strongIcon"&&r.context==="table")return I(t,r);let n=e==="icon"?t.substring(1,t.length-1):t.substring(2,t.length-2),s=n.lastIndexOf(".icon"),o=n.substring(0,s),c=o.startsWith("/")?"root":"relative",a=n.substring(s+5,n.length),i=a.startsWith("*")?parseInt(a.substring(1),10):1;return new Array(i).fill({}).map(()=>({path:o,pathType:c,type:e,raw:t}))}}var _s=yn("icon"),Ts=N(_s,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Ls]}),Ms=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,Cs=yn("strongIcon"),Ps=N(Cs,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ms]}),Ns=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,Ss=(e,t)=>t.context==="table"?I(e,t):[{type:"strong",raw:e,nodes:V(e.substring(2,e.length-2),{...t,nested:!0})}],Is=N(Ss,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ns]}),Rs=/\[\$ .+? \]/,Bs=/\[\$ [^\]]+\]/,Hs=(e,t)=>t.context==="table"?I(e,t):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],Os=N(Hs,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Rs,Bs]}),Ds=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,js=(e,t)=>{if(t.context==="table")return I(e,t);let r=e.indexOf(" "),n=e.substring(1,r),s=e.substring(r+1,e.length-1),o=new Set(n);if(o.has("*")){let c=n.split("*").length-1;o.delete("*"),o.add(*-${Math.min(c,10)})}return[{type:"decoration",raw:e,rawDecos:n,decos:Array.from(o),nodes:V(s,{...t,nested:!0})}]},$s=N(js,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ds]}),As=/.*?/,Fs=(e,t)=>t.context==="table"?I(e,t):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],Us=N(Fs,{parseOnNested:!1,parseOnQuoted:!0,patterns:[As]}),Ks=/^[$%] .+$/,qs=(e,t)=>{var r;if(t.context==="table")return I(e,t);let n=(r=e[0])!==null&&r!==void 0?r:"",s=e.substring(2);return[{type:"commandLine",raw:e,symbol:n,text:s}]},zs=N(qs,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Ks]}),Gs=/\[\s+\]/,Ws=(e,t)=>t.context==="table"?I(e,t):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],Xs=N(Ws,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Gs]}),Ys=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,Vs=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,Qs=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,Js=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,Zs=e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(e)||ei(e),ei=e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),ti=(e,t)=>{if(t.context==="table")return I(e,t);let r=e.search(/\s/),n=r!==-1?e.substring(1,r):e.substring(1,e.length-1),s=r!==-1?e.substring(r,e.length-1).trimLeft():"",[o,c]=Zs(s)?[s,n]:[n,s];return[{type:"image",raw:e,src:/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(o)?${o}/thumb/1000:o,link:c}]},ri=N(ti,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Ys,Vs,Qs,Js]}),ni=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,oi=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,si=/\[https?:\/\/[^\s\]]+\]/,ii=/https?:\/\/[^\s]+/,ai=(e,t)=>{if(t.context==="table")return I(e,t);let r=e.startsWith("[")&&e.endsWith("]")?e.substring(1,e.length-1):e,n=/^https?:\/\/[^\s\]]/.test(r),s=(n?/^https?:\/\/[^\s\]]+/:/https?:\/\/[^\s\]]+$/).exec(r);if(s?.[0]===void 0)return[];let o=n?r.substring(s[0].length):r.substring(0,s.index-1);return[{type:"link",raw:e,pathType:"absolute",href:s[0],content:o.trim()}]},ci=N(ai,{parseOnNested:!0,parseOnQuoted:!0,patterns:[ni,oi,si,ii]}),vn=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,En=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,li=e=>{let[t="",r="",n=""]=e.split(","),s=parseFloat(t.replace(/^N/,"").replace(/^S/,"-")),o=parseFloat(r.replace(/^E/,"").replace(/^W/,"-")),c=/^Z\d+$/.test(n)?parseInt(n.replace(/^Z/,""),10):14;return{latitude:s,longitude:o,zoom:c}},pi=(e,t)=>{var r;if(t.context==="table")return I(e,t);let n=(r=e.match(vn))!==null&&r!==void 0?r:e.match(En);if(n===null)return[];let s=e.startsWith("[N")||e.startsWith("[S"),[,o="",c=""]=s?n:[n[0],n[2],n[1]],{latitude:a,longitude:i,zoom:p}=li(o),l=c!==""?https://www.google.com/maps/place/${encodeURIComponent(c)}/@${a},${i},${p}z:https://www.google.com/maps/@${a},${i},${p}z;return[{type:"googleMap",raw:e,latitude:a,longitude:i,zoom:p,place:c,url:l}]},di=N(pi,{parseOnNested:!1,parseOnQuoted:!0,patterns:[vn,En]}),ui=/\[\/?[^[\]]+\]/,mi=e=>{let t=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:t.startsWith("/")?"root":"relative",href:t,content:""}]},fi=N(mi,{parseOnNested:!0,parseOnQuoted:!0,patterns:[ui]}),gi=/(?:^|\s)#\S+/,hi=(e,t)=>{if(t.context==="table")return I(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[...I(r,t),{type:"hashTag",raw:n,href:n.substring(1)}]},bi=N(hi,{parseOnNested:!0,parseOnQuoted:!0,patterns:[gi]}),xi=/^[0-9]+\. .*$/,yi=(e,t)=>{if(t.context==="table")return I(e,t);let r=e.indexOf(" "),n=e.substring(0,r-1),s=parseInt(n,10),o=e.substring(r+1,e.length);return[{type:"numberList",raw:e,rawNumber:n,number:s,nodes:V(o,{...t,nested:!0})}]},vi=N(yi,{parseOnNested:!1,parseOnQuoted:!1,patterns:[xi]}),Ei=(e,t,r)=>{var n;return e===""?[]:(n=r?.())!==null&&n!==void 0?n:[]},ki=(...e)=>(t,r)=>e.reduceRight((n,s)=>()=>s(t,r,n),()=>ms(t,r))(),V=ki(Ei,hs,ys,Us,zs,Os,Xs,$s,ws,Ps,Is,ri,ci,Ts,di,fi,bi,vi),wi=e=>{let{rows:[t,...r]}=e,{indent:n=0,text:s=""}=t??{},o=s.replace(/^\s*table:/,"");return{indent:n,type:"table",fileName:o,cells:r.map(c=>c.text.substring(n+1)).map(c=>c.split(" ").map(a=>V(a,{nested:!1,quoted:!1,context:"table"})))}},Li=e=>{let{indent:t,text:r}=e.rows[0];return{indent:t,type:"line",nodes:V(r.substring(t),{nested:!1,quoted:!1,context:"line"})}},_i=e=>{switch(e.type){case"title":return ds(e);case"codeBlock":return us(e);case"table":return wi(e);case"line":return Li(e)}},Ti=e=>e.split( ).map(t=>{var r,n,s;return{indent:(s=(n=(r=/^\s+/.exec(t))===null||r===void 0?void 0:r[0])===null||n===void 0?void 0:n.length)!==null&&s!==void 0?s:0,text:t}}),Mi=(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)},kn=(e,t)=>{let r=e[e.length-1];return r!==void 0&&Mi(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)},Ci=(e,t)=>{var r;if(!((r=t.hasTitle)!==null&&r!==void 0)||r){let[n,...s]=e;return n===void 0?[]:[{type:"title",rows:[n]},...s.reduce(kn,[])]}return e.reduce(kn,[])},Te=(e,t)=>{var r;let n=Ti(e);return Ci(n,{hasTitle:(r=t?.hasTitle)!==null&&r!==void 0?r:!0}).map(_i)};var wn=e=>{let t=[],r=new Set,n=s=>{r.delete(s);let o=t.pop();if(!o)return;let c=o[0]().finally(()=>n(c)).then(a=>o[1](a)).catch(a=>o[2](a));r.add(c)};return s=>{if(r.size<e){let o=s().finally(()=>n(o));return r.add(o),o}return new Promise((o,c)=>{t.push([s,o,c])})}};var Pi="0.6.5",Ln=ScrapBubble-${Pi},_n=await globalThis.caches.open(Ln);(async()=>{for(let e of await globalThis.caches.keys())e.startsWith("ScrapBubble-")&&e!==Ln&&(await globalThis.caches.delete(e),console.log(ScrapBubble deleted old cache :"${e}"))})();var Tn=wn(3);async function*Qe(e,t){let r=((t?.saveFailedResponse?_n.match(e):void 0)??bn(e,t)).then(c=>["cache",c]);{let c=re(1e3).then(()=>"timeout"),a=await Promise.race([r,c]);if(a!=="timeout"){a[1]&&(yield["cache",a[1]]);let i=await Tn(()=>fetch(e));!i.ok&&t?.saveFailedResponse&&await _n.put(e,i.clone()),yield["network",i]}}let n=Tn(()=>fetch(e)).then(c=>["network",c]),[s,o]=await Promise.race([r,n]);if(s==="network"){yield[s,o];return}o&&(yield[s,o]),yield await n}var Mn=(e,t)=>new Date(e.headers.get("Date")??0).getTime()/1e3+t<new Date().getTime()/1e3;var Je=()=>{let e=new Map;return{dispatch:(t,r)=>{let n=e.get(t);if(!!n)for(let s of n)s(r)},on:(t,r)=>{let n=e.get(t)??new Set;n.add(r),e.set(t,n)},off:(t,r)=>{let n=e.get(t);!n||n.delete(r)}}};var $=!1,Cn=e=>{$=typeof e=="boolean"?e:new Set(e)},Q=e=>Object.fromEntries([...Object.entries(console)].map(([t,r])=>{if(typeof r!="function")return[t,r];switch(t){case"warn":case"error":return[t,(...n)=>r(%c${e},"color: gray",...n)];case"log":case"info":case"debug":return[t,(...n)=>{$!==!0&&(!$||!$.has(e))||r(%c${e},"color: gray",...n)}];case"assert":return[t,(n,...s)=>{$!==!0&&(!$||!$.has(e))||r(n,%c${e},"color: gray",...s)}];case"time":case"timeEnd":return[t,n=>{$!==!0&&(!$||!$.has(e))||r(${e} ${n})}];default:return[t,(...n)=>{if(!($!==!0&&(!$||!$.has(e))))return r(...n)}]}}));var Pt=Je(),Ze=new Map,Ni=Q("ScrapBubble:useProject.ts"),Pn=e=>{let[t,r]=C();return j(()=>{Pt.on(e,r);let n=Ze.get(e);return n?r(n.loading?void 0:n.value):(Ze.set(e,{loading:!0}),r(void 0),(async()=>{try{let s=Le.toRequest(e);for await(let[,o]of Qe(s)){let c=await Le.fromResponse(o);Ze.set(e,{loading:!1,value:c}),Pt.dispatch(e,c);break}}catch(s){Ni.error(s),Ze.delete(e)}})()),()=>Pt.off(e,r)},[e]),t};var Si=["default-light","default-dark","default-minimal"],Ii=["paper-light","paper-dark-dark","paper-dark"],Nn=["blue","purple","green","orange","red"],Ri=["hacker1","hacker2"],Sn=["winter","spring","summer","automn"],In=["tropical"],Rn=["kyoto","newyork","paris"],Bn=["mred","lgreen"],yg=["default-light","default-minimal","paper-light",...Nn,...Sn,...In,...Rn,...Bn];var Bi=[...Si,...Ii,...Nn,...Ri,...Sn,...In,...Rn,...Bn];function Hn(e){return Bi.includes(e)}var On="default-light",ne=e=>{let t=Pn(e);return k(()=>{if(!t||!t.ok)return On;let r=t.value.theme;return Hn(r)?r:On},[t])};var de=(e,t)=>new Promise(r=>{let n=!1,s=()=>{n=!0,r(!1)};e.addEventListener("click",s),e.addEventListener("pointerleave",s),setTimeout(()=>{n||r(!0),e.removeEventListener("click",s),e.removeEventListener("pointerleave",s),r(!1)},t)});var ue=e=>{let{top:t,right:r,left:n,bottom:s}=e.getBoundingClientRect(),o=document.body.getBoundingClientRect(),c=(n-o.left)/o.width>.5;return{top:Math.round(s-o.top),bottom:Math.round(globalThis.innerHeight-globalThis.scrollY-t),...c?{right:Math.round(o.right-r)}:{left:Math.round(n-o.left)},maxWidth:c?r-10:document.documentElement.clientWidth-n-10}};var Dn=({project:e,title:t,descriptions:r,thumbnail:n,linkTo:s,bubble:o,delay:c,prefetch:a})=>{let i=k(()=>n?[]:Te(r.join( ),{hasTitle:!1}),[n,r]),p=ne(e),l=O(async({currentTarget:g})=>{a(e,t),!!await de(g,c)&&o({project:e,title:t,linkTo:s,type:"link",position:ue(g)})},[e,t,c,s?.project,s?.titleLc]),f=k(()=>s?()=>{Ct({type:"page",from:{project:s.project??e,title:s.titleLc},to:{project:e,title:t}})}:()=>{},[e,t,s?.project,s?.titleLc]);return d("a",{className:"related-page-card page-link",type:"link","data-theme":p,href:/${e}/${P(t)},rel:e===scrapbox.Project.name?"route":"noopner noreferrer",target:e!==scrapbox.Project.name?"_blank":"",onPointerEnter:l,onClick:f},d("div",{class:"hover"}),d("div",{class:"content"},d("div",{class:"header"},d("div",{class:"title"},t)),n?d("div",{class:"thumbnail"},d("img",{src:n})):d("div",{class:"description"},i.flatMap((g,u)=>g.type==="line"?[d("p",{key:u},g.nodes.map(m=>d(jn,{node:m,project:e})))]:[]))))},jn=({node:e,project:t})=>{switch(e.type){case"code":return d("code",null,e.text);case"formula":return d(Hi,{node:e});case"commandLine":return d("code",null,e.symbol," $",e.text);case"helpfeel":return d("code",null,"? ",e.text);case"quote":case"strong":case"decoration":return d(L,null,e.nodes.map(r=>d(jn,{node:r,project:t})));case"icon":case"strongIcon":return d(Oi,{node:e,project:t});case"hashTag":return d(Di,{node:e});case"link":return d(ji,{node:e});case"plain":case"blank":return d(L,null,e.text);default:return d(L,null)}},Hi=({node:{formula:e}})=>{let{ref:t,error:r,setFormula:n}=_e("");return n(e),d("span",{className:formula ${r?" error":""}},r?d("code",null,e):d("span",{className:"katex-display",ref:t}))},Oi=({node:{pathType:e,path:t},project:r})=>{let[n,s]=e==="relative"?[r,t]:t.match(/\/([\w\-]+)\/(.+)$/)?.slice?.(1)??[r,t];return d("img",{class:"icon",src:/api/pages/${n}/${P(s)}/icon})},Di=({node:{href:e}})=>d("span",{class:"page-link"},"#",e),ji=({node:{pathType:e,href:t,content:r}})=>e!=="absolute"?d("span",{class:"page-link"},t):d("span",{class:"link"},r||t);var E=(e,t)=>/${e}/${H(t)},et=e=>{let t=e.match("/([^/]+)/(.+)");if(!t)throw SyntaxError("${e}" cannnot match "/(^/+)/(.+)");return{project:t[1],titleLc:t[2]}};var $n=Symbol.for("immer-nothing"),An=Symbol.for("immer-draftable"),v=Symbol.for("immer-state");function U(e,...t){throw new Error(Immer minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf)}var me=Object.getPrototypeOf;function fe(e){return!!e&&!!e[v]}function G(e){return e?Fn(e)||Array.isArray(e)||!!e[An]||!!e.constructor?.[An]||rt(e)||nt(e):!1}var $i=Object.prototype.constructor.toString();function Fn(e){if(!e||typeof e!="object")return!1;let t=me(e);if(t===null)return!0;let r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object?!0:typeof r=="function"&&Function.toString.call(r)===$i}function Me(e,t){tt(e)===0?Reflect.ownKeys(e).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function tt(e){let t=e[v];return t?t.type_:Array.isArray(e)?1:rt(e)?2:nt(e)?3:0}function Nt(e,t){return tt(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Un(e,t,r){let n=tt(e);n===2?e.set(t,r):n===3?e.add(r):e[t]=r}function Ai(e,t){return e===t?e!==0||1/e==1/t:e!==e&&t!==t}function rt(e){return e instanceof Map}function nt(e){return e instanceof Set}function S(e){return e.copy_||e.base_}function St(e,t){if(rt(e))return new Map(e);if(nt(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let r=Fn(e);if(t===!0||t==="class_only"&&!r){let n=Object.getOwnPropertyDescriptors(e);delete n[v];let s=Reflect.ownKeys(n);for(let o=0;o<s.length;o++){let c=s[o],a=n[c];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(n[c]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[c]})}return Object.create(me(e),n)}else{let n=me(e);if(n!==null&&r)return{...e};let s=Object.create(n);return Object.assign(s,e)}}function It(e,t=!1){return ot(e)||fe(e)||!G(e)||(tt(e)>1&&(e.set=e.add=e.clear=e.delete=Fi),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>It(n,!0))),e}function Fi(){U(2)}function ot(e){return Object.isFrozen(e)}var Rt={};function oe(e){let t=Rt[e];return t||U(0,e),t}function Ui(e,t){Rt[e]||(Rt[e]=t)}var Ce;function st(){return Ce}function Ki(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Kn(e,t){t&&(oe("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function Bt(e){Ht(e),e.drafts_.forEach(qi),e.drafts_=null}function Ht(e){e===Ce&&(Ce=e.parent_)}function qn(e){return Ce=Ki(Ce,e)}function qi(e){let t=e[v];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function zn(e,t){t.unfinalizedDrafts_=t.drafts_.length;let r=t.drafts_[0];return e!==void 0&&e!==r?(r[v].modified_&&(Bt(t),U(4)),G(e)&&(e=it(t,e),t.parent_||at(t,e)),t.patches_&&oe("Patches").generateReplacementPatches_(r[v].base_,e,t.patches_,t.inversePatches_)):e=it(t,r,[]),Bt(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==$n?e:void 0}function it(e,t,r){if(ot(t))return t;let n=t[v];if(!n)return Me(t,(s,o)=>Gn(e,n,t,s,o,r)),t;if(n.scope_!==e)return t;if(!n.modified_)return at(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;let s=n.copy_,o=s,c=!1;n.type_===3&&(o=new Set(s),s.clear(),c=!0),Me(o,(a,i)=>Gn(e,n,s,a,i,r,c)),at(e,s,!1),r&&e.patches_&&oe("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function Gn(e,t,r,n,s,o,c){if(fe(s)){let a=o&&t&&t.type_!==3&&!Nt(t.assigned_,n)?o.concat(n):void 0,i=it(e,s,a);if(Un(r,n,i),fe(i))e.canAutoFreeze_=!1;else return}else c&&r.add(s);if(G(s)&&!ot(s)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;it(e,s),(!t||!t.scope_.parent_)&&typeof n!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,n)&&at(e,s)}}function at(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&It(t,r)}function zi(e,t){let r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:st(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},s=n,o=Ot;r&&(s=[n],o=Pe);let{revoke:c,proxy:a}=Proxy.revocable(s,o);return n.draft_=a,n.revoke_=c,a}var Ot={get(e,t){if(t===v)return e;let r=S(e);if(!Nt(r,t))return Gi(e,r,t);let n=r[t];return e.finalized_||!G(n)?n:n===Dt(e.base_,t)?(jt(e),e.copy_[t]=Ne(n,e)):n},has(e,t){return t in S(e)},ownKeys(e){return Reflect.ownKeys(S(e))},set(e,t,r){let n=Wn(S(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){let s=Dt(S(e),t),o=s?.[v];if(o&&o.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(Ai(r,s)&&(r!==void 0||Nt(e.base_,t)))return!0;jt(e),W(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty(e,t){return Dt(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,jt(e),W(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let r=S(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty(){U(11)},getPrototypeOf(e){return me(e.base_)},setPrototypeOf(){U(12)}},Pe={};Me(Ot,(e,t)=>{Pe[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});Pe.deleteProperty=function(e,t){return Pe.set.call(this,e,t,void 0)};Pe.set=function(e,t,r){return Ot.set.call(this,e[0],t,r,e[0])};function Dt(e,t){let r=e[v];return(r?S(r):e)[t]}function Gi(e,t,r){let n=Wn(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}function Wn(e,t){if(!(t in e))return;let r=me(e);for(;r;){let n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=me(r)}}function W(e){e.modified_||(e.modified_=!0,e.parent_&&W(e.parent_))}function jt(e){e.copy_||(e.copy_=St(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Wi=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,r,n)=>{if(typeof t=="function"&&typeof r!="function"){let o=r;r=t;let c=this;return function(a=o,...i){return c.produce(a,p=>r.call(this,p,...i))}}typeof r!="function"&&U(6),n!==void 0&&typeof n!="function"&&U(7);let s;if(G(t)){let o=qn(this),c=Ne(t,void 0),a=!0;try{s=r(c),a=!1}finally{a?Bt(o):Ht(o)}return Kn(o,n),zn(s,o)}else if(!t||typeof t!="object"){if(s=r(t),s===void 0&&(s=t),s===$n&&(s=void 0),this.autoFreeze_&&It(s,!0),n){let o=[],c=[];oe("Patches").generateReplacementPatches_(t,s,o,c),n(o,c)}return s}else U(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(o,...c)=>this.produceWithPatches(o,a=>t(a,...c));let n,s;return[this.produce(t,r,(o,c)=>{n=o,s=c}),n,s]},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){G(e)||U(8),fe(e)&&(e=Xi(e));let t=qn(this),r=Ne(e,void 0);return r[v].isManual_=!0,Ht(t),r}finishDraft(e,t){let r=e&&e[v];(!r||!r.isManual_)&&U(9);let{scope_:n}=r;return Kn(n,t),zn(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){let s=t[r];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}r>-1&&(t=t.slice(r+1));let n=oe("Patches").applyPatches_;return fe(e)?n(e,t):this.produce(e,s=>n(s,t))}};function Ne(e,t){let r=rt(e)?oe("MapSet").proxyMap_(e,t):nt(e)?oe("MapSet").proxySet_(e,t):zi(e,t);return(t?t.scope_:st()).drafts_.push(r),r}function Xi(e){return fe(e)||U(10,e),Xn(e)}function Xn(e){if(!G(e)||ot(e))return e;let t=e[v],r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=St(e,t.scope_.immer_.useStrictShallowCopy_)}else r=St(e,!0);return Me(r,(n,s)=>{Un(r,n,Xn(s))}),t&&(t.finalized_=!1),r}function Yn(){class e extends Map{constructor(i,p){super(),this[v]={type_:2,parent_:p,scope_:p?p.scope_:st(),modified_:!1,finalized_:!1,copy_:void 0,assigned_:void 0,base_:i,draft_:this,isManual_:!1,revoked_:!1}}get size(){return S(this[v]).size}has(i){return S(this[v]).has(i)}set(i,p){let l=this[v];return c(l),(!S(l).has(i)||S(l).get(i)!==p)&&(r(l),W(l),l.assigned_.set(i,!0),l.copy_.set(i,p),l.assigned_.set(i,!0)),this}delete(i){if(!this.has(i))return!1;let p=this[v];return c(p),r(p),W(p),p.base_.has(i)?p.assigned_.set(i,!1):p.assigned_.delete(i),p.copy_.delete(i),!0}clear(){let i=this[v];c(i),S(i).size&&(r(i),W(i),i.assigned_=new Map,Me(i.base_,p=>{i.assigned_.set(p,!1)}),i.copy_.clear())}forEach(i,p){let l=this[v];S(l).forEach((f,g,u)=>{i.call(p,this.get(g),g,this)})}get(i){let p=this[v];c(p);let l=S(p).get(i);if(p.finalized_||!G(l)||l!==p.base_.get(i))return l;let f=Ne(l,p);return r(p),p.copy_.set(i,f),f}keys(){return S(this[v]).keys()}values(){let i=this.keys();return{[Symbol.iterator]:()=>this.values(),next:()=>{let p=i.next();return p.done?p:{done:!1,value:this.get(p.value)}}}}entries(){let i=this.keys();return{[Symbol.iterator]:()=>this.entries(),next:()=>{let p=i.next();if(p.done)return p;let l=this.get(p.value);return{done:!1,value:[p.value,l]}}}}[Symbol.iterator](){return this.entries()}}function t(a,i){return new e(a,i)}function r(a){a.copy_||(a.assigned_=new Map,a.copy_=new Map(a.base_))}class n extends Set{constructor(i,p){super(),this[v]={type_:3,parent_:p,scope_:p?p.scope_:st(),modified_:!1,finalized_:!1,copy_:void 0,base_:i,draft_:this,drafts_:new Map,revoked_:!1,isManual_:!1}}get size(){return S(this[v]).size}has(i){let p=this[v];return c(p),p.copy_?!!(p.copy_.has(i)||p.drafts_.has(i)&&p.copy_.has(p.drafts_.get(i))):p.base_.has(i)}add(i){let p=this[v];return c(p),this.has(i)||(o(p),W(p),p.copy_.add(i)),this}delete(i){if(!this.has(i))return!1;let p=this[v];return c(p),o(p),W(p),p.copy_.delete(i)||(p.drafts_.has(i)?p.copy_.delete(p.drafts_.get(i)):!1)}clear(){let i=this[v];c(i),S(i).size&&(o(i),W(i),i.copy_.clear())}values(){let i=this[v];return c(i),o(i),i.copy_.values()}entries(){let i=this[v];return c(i),o(i),i.copy_.entries()}keys(){return this.values()}[Symbol.iterator](){return this.values()}forEach(i,p){let l=this.values(),f=l.next();for(;!f.done;)i.call(p,f.value,f.value,this),f=l.next()}}function s(a,i){return new n(a,i)}function o(a){a.copy_||(a.copy_=new Set,a.base_.forEach(i=>{if(G(i)){let p=Ne(i,a);a.drafts_.set(i,p),a.copy_.add(p)}else a.copy_.add(i)}))}function c(a){a.revoked_&&U(3,JSON.stringify(S(a)))}Ui("MapSet",{proxyMap_:t,proxySet_:s})}var A=new Wi,ct=A.produce,$g=A.produceWithPatches.bind(A),Ag=A.setAutoFreeze.bind(A),Fg=A.setUseStrictShallowCopy.bind(A),Ug=A.applyPatches.bind(A),Kg=A.createDraft.bind(A),qg=A.finishDraft.bind(A);Yn();var Vn=e=>{let t=0;for(let r of e)if(!!r&&(r.exists||(t+=(r.linked?.length??0)+(r.projectLinked?.length??0),t>1)))return!1;return t<2},Qn=(e,t)=>ct(e,r=>{if(!r)return t;if(r.updated<t.updated){let{lines:n,linked:s,projectLinked:o,...c}=t;Object.assign(r,c),$t(t)||(r.lines=n),s&&(r.linked??=s),o&&(r.projectLinked??=o);return}$t(r)&&!$t(t)&&(r.lines=t.lines),t.linked&&(t.isLinkedCorrect||!r.isLinkedCorrect&&(r.linked?.length??0)<=t.linked.length)&&(r.linked=t.linked),t.projectLinked&&(r.projectLinked=t.projectLinked)}),$t=e=>e.lines[0].id==="dummy";var Jn=(e,t)=>{let r=new Map,n=H(t.title);for(let i of t.links){let p=Yi(e,i);p.linked=[n],r.set(E(e,i),p)}let s=E(e,n),o=t.projectLinks.map(i=>{let p=et(i);return E(p.project,p.titleLc)}),c={...lt(e,t),linked:[],projectLinked:[]};r.set(s,c);let a=t.links.map(i=>H(i));for(let i of t.relatedPages.links1hop){i.linksLc.includes(n)&&c.linked.push(i.titleLc);for(let g of i.linksLc.filter(u=>a.includes(u))){let u=E(e,g),m=r.get(u);if(!m)throw Error(storage already must have "${u}");if(!m.linked){m.linked=[i.titleLc];continue}m.linked.push(i.titleLc)}let p=E(e,i.titleLc),l=lt(e,i),f=r.get(p)?.linked;f&&(l.linked=f),r.set(p,l)}for(let i of t.relatedPages.projectLinks1hop){let p=E(i.projectName,i.titleLc);o.includes(p)||c.projectLinked.push(p);let l=lt(i.projectName,i),f=r.get(p)?.projectLinked;f&&(l.projectLinked=f),r.set(p,l)}c.isLinkedCorrect=!0;for(let i of t.relatedPages.links2hop){for(let g of i.linksLc){let u=E(e,g),m=r.get(u);if(!m)throw Error(storage already must have "${u}");if(!m.linked){m.linked=[i.titleLc];continue}m.linked.push(i.titleLc)}let p=E(e,i.titleLc),l=lt(e,i),f=r.get(p)?.linked;f&&(l.linked=f),r.set(p,l)}return r},lt=(e,t)=>({project:e,titleLc:"titleLc"in t?t.titleLc:H(t.title),exists:"persistent"in t?t.persistent:!0,descriptions:t.descriptions,image:t.image,lines:"lines"in t?t.lines:[t.title,...t.descriptions].map(r=>({text:r,id:"dummy",userId:"dummy",updated:t.updated,created:t.updated})),updated:t.updated,isLinkedCorrect:!1}),Yi=(e,t)=>({project:e,titleLc:H(t),exists:!1,descriptions:[],image:null,lines:[{text:t,id:"dummy",userId:"dummy",updated:0,created:0}],updated:0,isLinkedCorrect:!1});var pt=Q("ScrapBubble:bubble.ts"),At=new Map,dt=new Set,Ft=Je();function*Zn(e){for(let t of e)yield At.get(t)}var eo=(e,t)=>Ft.on(e,t),to=(e,t)=>Ft.off(e,t),ro=async(e,t,r,n)=>{let s=[];for(let o of[...t].reverse()){let c=E(o,e);dt.has(c)||s.push(Vi(o,e,r,n))}await Promise.all(s)},no=0,Vi=async(e,t,r,n)=>{let s=E(e,t);if(dt.has(s))return;dt.add(s);let o=no++,c=${o} Check update ${s};pt.time(c);try{let a=le.toRequest(e,t,{followRename:!0,projects:[...r]});for await(let[i,p]of Qe(a,{ignoreSearch:!0,saveFailedResponse:!0})){pt.debug(${o}${i} ${s});let l=await le.fromResponse(p);if(l.ok){let f=Jn(e,l.value);for(let[g,u]of f){let m=At.get(g),b=Qn(m,u);!b||m!==b&&(At.set(g,b),Ft.dispatch(g,u))}}if(n?.ignoreFetch===!0||i==="cache"&&!Mn(p,n?.maxAge??60))break}}catch(a){pt.error(a)}finally{dt.delete(s),pt.timeEnd(c),no--}};var oo=Q("ScrapBubble:useBubbleData.ts"),ge=e=>{let[t,r]=C([]);return We(()=>{let n=()=>{r(()=>{let c=[...Zn(e)].flatMap(a=>a?[a]:[]);return oo.debug(Required: ${e.length} pages, ${c.length} found,c),c})};n();let s,o=()=>{clearTimeout(s),s=setTimeout(()=>{oo.debug(Update ${e.length} pages),n()},10)};return e.forEach(c=>eo(c,o)),()=>e.forEach(c=>to(c,o))},e),t};var so=({source:e,linked:t,externalLinked:r,projectsForSort:n,...s})=>{let o=k(()=>[...t.keys(),...r.keys()],[t,r]),c=ge(o),a=k(()=>[...n],[n]),i=k(()=>{let l=(f,g)=>{let u=a.indexOf(f.project),m=a.indexOf(g.project);return u===m?g.updated-f.updated:u<0?1:m<0?-1:u-m};return[...c].sort(l)},[c,a]),p=k(()=>({bottom:${e.position.bottom}px,maxWidth:${e.position.maxWidth}px,..."left"in e.position?{left:${e.position.left}px}:{right:${e.position.right}px}}),[e.position]);return d("ul",{className:"card-bubble",style:p,onClick:s.onClick},i.map(({project:l,titleLc:f,lines:[{text:g}],descriptions:u,image:m})=>{let b=E(l,f),x=t.get(b)??r.get(b);return d("li",{key:b},d(Dn,{project:l,title:g,linkTo:x,descriptions:u,thumbnail:m??"",...s}))}))};var he=e=>{if(e.pathType==="root"){let[,t="",r=""]=e.href.match(/\/([\w\-]+)(?:\/?|\/(.*))$/)??["","",""];if(t==="")throw SyntaxError(Failed to get a project name from "${e.href}");let[,n]=r?.match?.(/#([a-f\d]{24,32})$/)??["",""];return r===""?{project:t}:n===""?{project:t,title:r}:{project:t,title:r.slice(0,-1-n.length),hash:n}}else{let[,t]=e.href.match(/#([a-f\d]{24,32})$/)??["",""];return t===""?{title:e.href}:{title:e.href.slice(0,-1-t.length),hash:t}}};var Ut=(e,t)=>t.some(r=>{let n=!e.project;switch(r.type){case"hashTag":return n&&H(r.href)===e.titleLc;case"link":{if(r.pathType=="absolute"||r.pathType==="relative"!==n)return!1;let{project:s,title:o=""}=he({pathType:r.pathType,href:r.href});return n?!s&&H(o)===e.titleLc:s===e.project&&H(o)===e.titleLc}case"quote":case"strong":case"decoration":return Ut(e,r.nodes)}});var J=wt({title:"",project:"",whiteList:new Set,bubble:()=>{},hide:()=>{},delay:0,prefetch:()=>{}}),io=({lines:e,project:t,title:r,whiteList:n,noIndent:s,hash:o,linkTo:c,...a})=>{let i=k(()=>e.flatMap(u=>typeof u=="string"?[]:[u.id]),[e]),p=k(()=>{let u=0;return Te(e.map(m=>typeof m=="string"?m:m.text).join( ),{hasTitle:!0}).map(m=>{switch(m.type){case"title":case"line":return{...m,id:i[u++]};case"codeBlock":{let b=u;return u+=m.content.split(
).length+1,{...m,ids:i.slice(b,u)}}case"table":{let b=u;return u+=m.cells.length+1,{...m,ids:i.slice(b,u)}}}})},[e,i]),l=k(()=>{if(o&&i.includes(o))return o;if(!!c)return p.find(u=>u.type!=="line"?!1:Ut(c,u.nodes))?.id},[p,i,o,c?.project,c?.titleLc]),f=ae(null);j(()=>{if(!l)return;let u=f.current?.querySelector(data-id="${l}"),m=globalThis.scrollY;u?.scrollIntoView?.({block:"center"}),globalThis.scroll(0,m)},[l]);let g=ne(t);return d("div",{className:"lines","data-theme":g,ref:f},d(J.Provider,{value:{project:t,title:r,whiteList:n,...a}},p.map(u=>{switch(u.type){case"title":return d(L,null,d(be,{key:u.id,index:u.id,indent:0,noIndent:s,permalink:u.id===l},d("a",{className:"page-link",type:"link",href:/${t}/${P(u.text)},rel:t===scrapbox.Project.name?"route":"noopener noreferrer",target:t===scrapbox.Project.name?"":"_blank"},u.text)),d("hr",null));case"codeBlock":return d(Qi,{key:u.ids[0],block:u,noIndent:s,ids:u.ids,scrollId:l});case"table":return d(Ji,{key:u.ids[0],block:u,noIndent:s,ids:u.ids,scrollId:l});case"line":return d(be,{key:u.id,index:u.id,indent:u.indent,noIndent:s,permalink:u.id===l},u.nodes.length>0?u.nodes.map(m=>d(xe,{node:m})):d("br",null))}})))},be=({index:e,indent:t,noIndent:r,children:n,permalink:s})=>d("div",{className:line${s?" permalink":""},"data-id":e,"data-indent":t,style:{"margin-left":r?"":${1*t}em}},n),Qi=({block:{fileName:e,content:t,indent:r},ids:n,scrollId:s})=>{let{project:o,title:c}=Y(J),[a,i]=C(""),p=O(async l=>{l.preventDefault(),l.stopPropagation();try{await navigator.clipboard.writeText(t),i("Copied"),await re(1e3),i("")}catch(f){alert(Failed to copy the code block Error:${f.message})}},[t]);return d(L,null,d(be,{index:n[0],indent:r,permalink:n[0]===s},d("span",{className:"code-block"},d("span",{className:"code-block-start"},d("a",{href:/api/code/${o}/${P(c)}/${e},target:"_blank"},e)),d("span",{className:"copy",title:"Copy",onClick:p},a))),d(L,null,t.split(
).map((l,f)=>d(be,{index:n[f+1],indent:r,permalink:n[f+1]===s},d("code",{className:"code-block"},l)))))},Ji=({block:{fileName:e,cells:t,indent:r},ids:n,scrollId:s})=>{let{project:o,title:c}=Y(J);return d(L,null,d(be,{index:n[0],indent:r,permalink:n[0]===s},d("span",{className:"table-block"},d("span",{className:"table-block-start"},d("a",{href:/api/table/${o}/${P(c)}/${e}.csv,target:"_blank"},e)))),d(L,null,t.map((a,i)=>d(be,{index:n[i+1],indent:r,permalink:n[i+1]===s},d("span",{className:"table-block table-block-row"},a.map((p,l)=>d("span",{className:cell col-${l}},p.map(f=>d(xe,{node:f})))))))))},xe=({node:e})=>{switch(e.type){case"code":return d("code",{className:"code"},e.text);case"formula":return d(Zi,{node:e});case"commandLine":return d(ta,{node:e});case"helpfeel":return d("code",{className:"helpfeel"},d("span",{className:"prefix"},"?")," ",d("span",{className:"entry"},e.text));case"quote":return d("blockquote",{className:"quote"},e.nodes.map(t=>d(xe,{node:t})));case"strong":return d("strong",null,e.nodes.map(t=>d(xe,{node:t})));case"decoration":return d(ea,{node:e});case"plain":case"blank":return d(L,null,e.text);case"hashTag":return d(oa,{node:e});case"link":return d(sa,{node:e});case"googleMap":return d(ra,{node:e});case"icon":return d(ao,{node:e});case"strongIcon":return d(ao,{node:e,strong:!0});case"image":return d(na,{node:e});case"strongImage":return d("img",{className:"image strong-image",src:e.src});case"numberList":return d(L,null,${e.number}. ,e.nodes.map(t=>d(xe,{node:t})))}},Zi=({node:{formula:e}})=>{let{ref:t,error:r,setFormula:n}=_e("");return n(e),d("span",{className:formula ${r?" error":""}},r?d("code",null,e):d("span",{className:"katex-display",ref:t}))},ea=({node:{decos:e,nodes:t}})=>d("span",{className:e.map(r=>deco-${r}).join(" ")},t.map(r=>d(xe,{node:r}))),ta=({node:e})=>{let[t,r]=C(""),n=O(async s=>{s.preventDefault(),s.stopPropagation();try{await navigator.clipboard.writeText(e.text),r("Copied"),await re(1e3),r("")}catch(o){alert(Failed to copy the code block
Error:${o.message})}},[e.text]);return d(L,null,d("code",{className:"cli"},d("span",{className:"prefix"},e.symbol)," ",d("span",{className:"command"},e.text)),d("span",{className:"tool-buttons"},d("span",{title:"Copy",className:"copy",onClick:n},t)))},ra=({node:{place:e,latitude:t,longitude:r,zoom:n}})=>d("span",{className:"pointing-device-map"},d("a",{href:https://www.google.com/maps/search/${e}/@${t},${r},${n}z,rel:"noopner noreferrer",target:"_blank"},d("img",{className:"google-map",src:/api/google-map/static-map?center=${t}%2C${r}&markers=${e}&zoom=${n}&_csrf=${globalThis._csrf}}))),ao=({node:{pathType:e,path:t},strong:r})=>{let{project:n}=Y(J),[s,o]=e==="relative"?[n,t]:t.match(/\/([\w\-]+)\/(.+)$/)?.slice?.(1)??[n,t],c=P(o);return d("a",{href:/${s}/${c},rel:s===scrapbox.Project.name?"route":"noopener noreferrer",target:s===scrapbox.Project.name?"":"_blank"},d("img",{className:r?"icon strong-icon":"icon",alt:o,src:/api/pages/${s}/${c}/icon},o))},na=({node:{link:e,src:t}})=>{let r=e||(/https:\/\/gyazo\.com\/[^\/]+\/thumb\/1000/.test(t)?t.slice(0,-"/thumb/1000".length):t);return d("a",{className:e?"link":"",href:r,rel:"noopner noreferrer",target:"_blank"},d("img",{className:"image",src:t}))},oa=({node:{href:e}})=>{let{project:t}=Y(J),r=co(t,e),n=lo(t,e,"hashtag");return d("a",{href:/${t}/${P(e)},className:page-link${r?" empty-page-link":""},type:"hashTag",rel:t===scrapbox.Project.name?"route":"noopener noreferrer",target:t===scrapbox.Project.name?"":"_blank",onPointerEnter:n},"#",e)},sa=({node:{pathType:e,...t}})=>{switch(e){case"relative":case"root":return d(ia,{pathType:e,href:t.href});case"absolute":{let r=ln({pathType:e,...t});switch(r.type){case"youtube":return d(aa,{...r});case"vimeo":return d(ca,{...r});case"spotify":return d(la,{...r});case"anchor-fm":return d(pa,{...r});case"audio":return d(da,{...r});case"video":return d(ma,{...r});case"absoluteLink":return d("a",{className:"link",href:r.href,rel:"noopener noreferrer",target:"_blank"},r.content||r.href)}}}},ia=({pathType:e,href:t})=>{let{project:r}=Y(J),{project:n=r,title:s,hash:o=""}=he({pathType:e,href:t}),c=lo(n,s,"link",o),a=co(n,s??"");return d("a",{className:page-link${s!==void 0&&a?" empty-page-link":""},type:"link",href:/${n}${s===void 0?"":/${P(s)}${o===""?"":#${o}}},rel:n===scrapbox.Project.name?"route":"noopener noreferrer",target:n===scrapbox.Project.name?"":"_blank",onPointerEnter:c},t)},aa=e=>{e.params.append("autoplay","0");let t=e.pathType==="list"?https://www.youtube.com/embed/?${e.params.toString()}&list=${e.listId}:https://www.youtube.com/embed/${e.videoId}?${e.params.toString()};return d("div",{className:"iframe-video-player"},d("iframe",{src:t,allowFullScreen:!0,type:"text/html"}))},ca=({videoId:e})=>d("div",{className:"iframe-video-player"},d("iframe",{src:https://player.vimeo.com/video/${e},allowFullScreen:!0,type:"text/html"})),la=e=>d("div",{className:"iframe-video-player"},d("iframe",{className:spotify type-${e.pathType},src:https://open.spotify.com/embed/${e.pathType}/${e.videoId},allowFullScreen:!0,type:"text/html",scrolling:"no"})),pa=e=>d("div",{className:"iframe-video-player"},d("iframe",{className:"anchor-fm",src:e.href.replace("/episodes/","/embed/episodes/"),allowFullScreen:!0,type:"text/html",scrolling:"no"})),da=e=>e.content===""?d("audio",{className:"audio-player",preload:"none",controls:!0,src:e.href}):d(ua,{...e}),ua=({href:e,content:t})=>{let r=ae(null),n=O(()=>{r.current?.paused?(r.current.currentTime=0,r.current.play()):r.current?.pause?.()},[]);return d("span",{className:"audio-link"},d("a",{href:e,rel:"noopener noreferrer",target:"_blank"},t),d("span",{className:"play",onClick:n},"♬"),d("audio",{preload:"none",src:e,ref:r}))},ma=({href:e})=>d("div",{className:"video-player"},d("video",{class:"video",style:{display:"inline-block"},controls:!0,loop:!0,src:e})),co=(e,t)=>{let{whiteList:r}=Y(J),n=k(()=>(r.has(e)?[...r]:[e,...r]).map(o=>E(o,t)),[r,e]),s=ge(n);return k(()=>Vn(s),s)},lo=(e,t,r,n)=>{let{delay:s,bubble:o,prefetch:c}=Y(J);return O(async({currentTarget:a})=>{!t||(c(e,t),!!await de(a,s)&&o({project:e,title:t,hash:n,type:r,position:ue(a)}))},[e,t,n,r,s,c,o])};var po=({pages:e,onClick:t,source:r,whiteList:n,...s})=>{let[o,c]=C(E(e[0].project,e[0].titleLc)),a=k(()=>({top:${r.position.top}px,maxWidth:${r.position.maxWidth}px,..."left"in r.position?{left:${r.position.left}px}:{right:${r.position.right}px}}),[r.position]);return d("div",{className:"text-bubble",style:a,onClick:t},e.length>1&&d("div",{role:"tablist"},e.map(i=>d(fa,{key:E(i.project,i.titleLc),project:i.project,titleLc:i.titleLc,selected:o===E(i.project,i.titleLc),tabSelector:c}))),e.map(i=>d(ga,{key:E(i.project,i.titleLc),selected:o===E(i.project,i.titleLc),...i,title:i.lines[0].text,hash:r.hash,linkTo:r.linkTo,whiteList:n,...s})))},fa=({project:e,titleLc:t,tabSelector:r,selected:n})=>{let s=O(()=>r(E(e,t)),[e,t]),o=ne(e);return d("button",{role:"tab","aria-selected":n,"data-theme":o,tabIndex:-1,onClick:s},e)},ga=({selected:e,...t})=>{let r=ne(t.project);return d("div",{role:"tabpanel","data-theme":r,hidden:!e},d(io,{...t}))};var uo=Q("ScrapBubble:Bubble.tsx"),mo=({source:e,parentTitles:t,whiteList:r,...n})=>{let s=k(()=>r.has(e.project)?new Set([e.project,...r]):new Set([e.project]),[r,e.project]),[o,c,a]=ba(e,s,r,t);return d(L,null,ha(a)&&d(po,{pages:a,source:e,whiteList:r,onClick:n.hide,...n}),d(so,{linked:o,externalLinked:c,onClick:n.hide,source:e,projectsForSort:s,...n}))},ha=e=>e.length>0,ba=(e,t,r,n)=>{let[[s,o,c],a]=C([new Map,new Map,[]]),i=k(()=>{let f=[...t].map(g=>E(g,e.title));return uo.debug("projects",f),f},[t,e.title]),p=ge(i),l=k(()=>n.map(f=>H(f)),[n]);return We(()=>{let f=new Map,g=new Map,u=[];for(let m of p){let b={project:m.project,titleLc:m.titleLc};for(let y of m.projectLinked??[]){let{project:_,titleLc:K}=et(y);l.includes(K)&&r.has(_)||g.has(y)||g.set(y,b)}if(!r.has(m.project))continue;let x={titleLc:m.titleLc};for(let y of m.linked??[]){if(l.includes(y))continue;let _=E(m.project,y);f.has(_)||f.set(_,x)}l.includes(m.titleLc)||!m.exists||u.push(m)}a(ct(m=>{uo.debug(depth: ${l.length}, bubbled from ${E(e.project,e.title)}, bubbles,,p,"before",m[0],"internal cards,",f,"external cards",g);for(let b of m[0].keys())f.has(b)||m[0].delete(b);for(let[b,x]of f)m[0].set(b,x);for(let b of m[1].keys())g.has(b)||m[1].delete(b);for(let[b,x]of g)m[1].set(b,x);m[2]=u}))},[p,r,l]),[s,o,c]};var fo=(e,t)=>{if(e instanceof URL)return e;try{return new URL(e)}catch(r){if(!(r instanceof TypeError))throw r;if(!t||!/^\.\/|^\.\.\/|^\//.test(e))return e;try{return new URL(e,t)}catch(n){if(!(n instanceof TypeError))throw n;return e}}};var go=e=>{let t=k(()=>fo(e.style,import.meta.url),[e.style]);return d(L,null,t!==""&&(t instanceof URL?d("link",{rel:"stylesheet",href:t.href}):d("style",null,t)))};var ho=String.raw*{box-sizing:border-box}a{background-color:transparent;text-decoration:none;cursor:pointer}img{display:inline-block;max-width:100%;max-height:100px}code{font-family:var(--code-text-font, Menlo, Monaco, Consolas, "Courier New", monospace);font-size:90%;color:var(--code-color, #342d9c);background-color:var(--code-bg, rgba(0,0,0,.04));padding:0;white-space:pre-wrap;word-wrap:break-word}blockquote{background-color:var(--quote-bg-color, rgba(0,0,0,.05));display:block;border-left:solid 4px #a0a0a0;padding-left:4px;margin:0}strong{font-weight:700}iframe{display:inline-block;margin:3px 0;vertical-align:middle;max-width:100%;width:640px;height:360px;border:0}audio{display:inline-block;vertical-align:middle;white-space:initial;max-width:100%}.formula{margin:auto 6px}.formula.error code{color:#fd7373}.katex-display{display:inline-block!important;margin:0!important;text-align:inherit!important}.error .katex-display{display:none}.cli{border-radius:4px}.cli .prefix{color:#9c6248}.helpfeel{background-color:#fbebdd;border-radius:4px;padding:3px!important}.helpfeel .prefix{color:#f17c00}.helpfeel .entry{color:#cc5020}.code-block{display:block;line-height:1.7em;background-color:var(--code-bg, rgba(0,0,0,.04))}.code-block-start{font-family:Menlo,Monaco,Consolas,Courier New,monospace;color:#342d9c;background-color:#ffcfc6;font-size:.9em;padding:1px 2px}.code-block-start a{color:#342d9c;text-decoration:underline}code.code-block,.table-block.table-block-row{padding-left:1em}.copy{font-family:"Font Awesome 5 Free";cursor:pointer}.table-block{white-space:nowrap}.table-block-start{padding:1px 2px;font-size:.9em;background-color:#ffcfc6}.table-block-start a{color:#342d9c;text-decoration:underline}.cell{margin:0;padding:0 2px 0 8px;box-sizing:content-box;display:inline-block;white-space:pre}.cell:nth-child(odd){background-color:#0000000a}.cell:nth-child(2n){background-color:#0000000f}.strong-image{max-height:100%}.icon{height:11px;vertical-align:middle}.strong-icon{height:13.2px}.tool-button{margin-left:1em;cursor:pointer;font-size:.9em}.deco-\/{font-style:italic}.deco-\*-1{font-weight:700}.deco-\*-2{font-weight:700;font-size:1.2em}.deco-\*-3{font-weight:700;font-size:1.44em}.deco-\*-4{font-weight:700;font-size:1.73em}.deco-\*-5{font-weight:700;font-size:2.07em}.deco-\*-6{font-weight:700;font-size:2.49em}.deco-\*-7{font-weight:700;font-size:3em}.deco-\*-8{font-weight:700;font-size:3.58em}.deco-\*-9{font-weight:700;font-size:4.3em}.deco-\*-10{font-weight:700;font-size:5.16em}.deco--{text-decoration:line-through}.deco-_{text-decoration:underline}.page-link{color:var(--page-link-color, #5e8af7)}a.page-link:hover{color:var(--page-link-hover-color, #2d67f5)}.empty-page-link{color:var(--empty-page-link-color, #fd7373)}a.empty-page-link:hover{color:var(--empty-page-link-hover-color, #fd7373)}.link{color:var(--page-link-color, #5e8af7);text-decoration:underline}a.link:hover{color:var(--page-link-color-hover-color, #2d67f5)}.link img{padding-bottom:3px;border-style:none none solid;border-width:1.5px;border-color:#8fadf9}.permalink{background-color:var(--line-permalink-color, rgba(234,218,74,.75))}.status-bar{display:inline-block;position:absolute;background-color:var(--page-bg, #fefefe);cursor:default}.status-bar>*{border:1px solid var(--status-bar-border-color, #a9aaaf)}.status-bar.top-left{top:0;left:0}.status-bar.top-left>*{border-top:none;border-left:none}.status-bar.top-left :last-of-type{border-bottom-right-radius:3px}.status-bar.top-right{top:0;right:0}.status-bar.top-right>*{border-top:none;border-right:none}.status-bar.top-right :last-of-type{border-bottom-left-radius:3px}.status-bar.bottom-right{bottom:0;right:0}.status-bar.bottom-right>*{border-bottom:none;border-right:none}.status-bar.bottom-right :last-of-type{border-top-left-radius:3px}.status-bar.bottom-left{bottom:0;left:0}.status-bar.bottom-left>*{border-bottom:none;border-left:none}.status-bar.bottom-left :last-of-type{border-top-right-radius:3px}.text-bubble{font-size:11px;line-height:1.42857;user-select:text;position:absolute;color:var(--page-text-color, #4a4a4a);box-shadow:0 6px 12px #0000002d;display:flex;flex-direction:column;z-index:9000;&.no-scroll{overflow-y:hidden}data-theme=default-dark{--text-bubble-border-color: hsl(0, 0%, 39%)}data-theme=default-minimal{--text-bubble-border-color: hsl(0, 0%, 89%)}data-theme=paper-light{--text-bubble-border-color: hsl(53, 8%, 58%)}data-theme=paper-dark-dark{--text-bubble-border-color: hsl(203, 42%, 17%)}data-theme=blue{--text-bubble-border-color: hsl(227, 68%, 62%)}data-theme=purple{--text-bubble-border-color: hsl(267, 39%, 60%)}data-theme=green{--text-bubble-border-color: hsl(136, 29%, 50%)}data-theme=orange{--text-bubble-border-color: hsl(43, 71%, 51%)}data-theme=red{--text-bubble-border-color: hsl(4, 58%, 56%)}data-theme=spring{--text-bubble-border-color: hsl(72, 64%, 57%)}data-theme=kyoto{--text-bubble-border-color: hsl(331, 21%, 26%)}data-theme=newyork{--text-bubble-border-color: hsl(176, 29%, 67%)}role=tabpanel{padding:5px 0 5px 5px;border-radius:4px;background-color:var(--page-bg, #fefefe);max-height:80vh;overflow-y:auto}role=tabpanel,button{border:1px solid var(--text-bubble-border-color, hsl(221, 15%, 25%))}button{cursor:default;color:inherit;font-size:inherit;line-height:inherit;background-color:var(--page-bg, #fefefe);border-radius:4px 4px 0 0}buttonaria-selected=true{background-color:var(--text-bubble-border-color, hsl(221, 15%, 25%))}}.project-badge{text-decoration:none;color:var(--tool-text-color, #363c49)}.related-page-carddata-theme=default-dark{--card-title-bg: hsl(0, 0%, 39%)}.related-page-carddata-theme=default-minimal{--card-title-bg: hsl(0, 0%, 89%)}.related-page-carddata-theme=paper-light{--card-title-bg: hsl(53, 8%, 58%)}.related-page-carddata-theme=paper-dark-dark{--card-title-bg: hsl(203, 42%, 17%)}.related-page-carddata-theme=blue{--card-title-bg: hsl(227, 68%, 62%)}.related-page-carddata-theme=purple{--card-title-bg: hsl(267, 39%, 60%)}.text-bubbledata-theme=green{--card-title-bg: hsl(136, 29%, 50%)}.related-page-carddata-theme=orange{--card-title-bg: hsl(43, 71%, 51%)}.related-page-carddata-theme=red{--card-title-bg: hsl(4, 58%, 56%)}.related-page-carddata-theme=spring{--card-title-bg: hsl(72, 64%, 57%)}.related-page-carddata-theme=kyoto{--card-title-bg: hsl(331, 21%, 26%)}.related-page-carddata-theme=newyork{--card-title-bg: hsl(176, 29%, 67%)}.related-page-card{display:block;position:relative;height:inherit;width:inherit;overflow:hidden;text-overflow:ellipsis;font-family:Roboto,Helvetica,Arial,Hiragino Sans,sans-serif;background-color:var(--card-bg, #fff);color:var(--card-title-color, #555);word-break:break-word;text-decoration:none}.related-page-card:hover{box-shadow:var(--card-box-hover-shadow, 0 2px 0 rgba(0,0,0,.23))}.related-page-card:focus{outline:0;box-shadow:0 0 0 3px #66afe999;border-color:#66afe9;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s}.related-page-card.hover{opacity:0;position:absolute;width:100%;height:100%;top:0;left:0;background-color:var(--card-hover-bg, rgba(0,0,0,.05));mix-blend-mode:multiply;z-index:1;transition:background-color .1s}.related-page-card:hover .hover{opacity:1}.related-page-card:active .hover{opacity:1;background-color:var(--card-active-bg, rgba(0,0,0,.1))}.related-page-card .content{height:calc(100% - 5px);width:inherit;display:flex;flex-direction:column;overflow:hidden}.related-page-card .content .header{width:100%;color:#396bdd;text-overflow:ellipsis;border-top:var(--card-title-bg, #f2f2f3) solid 10px;padding:8px 10px}.related-page-card .content .header .title{font-size:11px;line-height:16px;font-weight:700;max-height:48px;color:var(--card-title-color, #363c49);margin:0;overflow:hidden;display:block;-webkit-line-clamp:3;-webkit-box-orient:vertical;text-overflow:ellipsis}.related-page-card .content .description{line-height:16px;padding:8px 10px 0;font-size:10px;white-space:pre-line;column-count:1;column-gap:2em;column-width:10em;height:inherit;color:var(--card-description-color, gray);flex-shrink:16;overflow:hidden}.related-page-card .content .thumbnail{display:block;width:100%;margin:0 auto;padding:0 5px}.related-page-card .content .description p{margin:0;display:block}.related-page-card .content .description code{font-family:Menlo,Monaco,Consolas,Courier New,monospace;font-size:90%;color:var(--code-color, #342d9c);background-color:var(--code-bg, rgba(0,0,0,.04));padding:0;white-space:pre-wrap;word-wrap:break-word}.related-page-card .content .description .icon{height:9px;vertical-align:middle}.related-page-card .content .description .page-link{background-color:transparent;text-decoration:none;cursor:pointer;color:var(--page-link-color, #5e8af7)}.card-bubble{background-color:var(--page-bg, #FFF);box-shadow:0 2px 2px #00000024,0 3px 1px -2px #0003,0 1px 5px #0000001f;position:absolute;max-width:80vw;box-sizing:content-box;z-index:9000;font-size:11px;line-height:1.42857;display:flex;padding:0;margin:0;list-style:none;overflow-x:auto;overflow-y:visible}.card-bubble li{display:block;position:relative;float:none;margin:5px;box-sizing:border-box;box-shadow:var(--card-box-shadow, 0 2px 0 rgba(0,0,0,.12));border-radius:2px;width:120px;height:120px} ;var bo=()=>{let[e,t]=C([]),r=O((o,c)=>t(a=>c?[...a.slice(0,o),c]:[...a.slice(0,o)]),[]),[n,s]=C([{bubble:o=>r(0,o),hide:()=>r(0)}]);return j(()=>{s(([o,...c])=>[o,...e.map((a,i)=>a===c.at(i)?.source?c.at(i):{source:a,parentTitles:[scrapbox.Page.title??"",...e.slice(0,i).map(p=>p.title)],bubble:p=>r(i+1,p),hide:()=>r(i+1)})])},[e]),n};var Kt=(e,t,r,n,s)=>{j(()=>(e.addEventListener(t,r,n),()=>e.removeEventListener(t,r,n)),[e,t,n,...s??[]])};var xo=e=>e instanceof HTMLSpanElement&&e.matches(".line-title .text"),ut=e=>e instanceof HTMLAnchorElement&&e.classList.contains("page-link");var qt="scrap-bubble",yo=({delay:e,whiteList:t,watchList:r,style:n})=>{let[{bubble:s,hide:o},...c]=bo(),a=O((i,p)=>ro(p,t.has(i)?t:new Set([i]),r),[t,r]);return Kt(document,"pointerenter",async i=>{let p=i.target;if(!ut(p)&&!xo(p))return;let{project:l=scrapbox.Project.name,title:f,hash:g=""}=ut(p)?he({pathType:"root",href:${new URL(p.href).pathname}${new URL(p.href).hash}}):{project:scrapbox.Project.name,title:scrapbox.Page.title};if(l==="")return;let u=decodeURIComponent(f??"");a(l,u),!!await de(p,e)&&s({project:l,title:u,hash:g,position:ue(p),type:xa(p)})},{capture:!0},[e,t,r]),Kt(document,"click",i=>{i.target.dataset.userscriptName!==qt&&o()},{capture:!0},[o]),j(()=>(scrapbox.addListener("page:changed",o),()=>scrapbox.removeListener("page:changed",o)),[o]),d(L,null,d("link",{rel:"stylesheet",href:"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.12.0/katex.min.css"}),d("style",null,ho),d(go,{style:n}),c.map(i=>d(mo,{key:E(i.source.project,i.source.title),...i,whiteList:t,delay:e,prefetch:a})))},xa=e=>ut(e)?e.type==="link"?"link":"hashtag":"title";var vo=async e=>{let{delay:t=500,whiteList:r=[],watchList:n=(await pn()).slice(0,100),style:s="",debug:o=!1}=e??{};Cn(o);let c=document.createElement("div");c.dataset.userscriptName=qt,document.body.append(c);let a=c.attachShadow({mode:"open"});Ge(d(yo,{delay:t,whiteList:new Set([scrapbox.Project.name,...r]),watchList:new Set(n),style:s}),a)};vo({whiteList:["yosider-private","villagepump","shokai","arpla","nishio","motoso","takker","sta"]});var Eo="Jump to an unread page";scrapbox.PageMenu.addMenu({title:Eo,image:"https://gyazo.com/f74d4fc373248fb2abac31ff1f69b482/raw",onClick:async()=>{let e=scrapbox.Project.name,t=scrapbox.Project.pages.filter(o=>o.exists&&o.title!==scrapbox.Page.title),r=async()=>{let o=t[Math.floor(Math.random()*t.length)].title;return await(await fetch(/api/pages/${e}/${encodeURIComponent(o)})).json()},n=scrapbox.PageMenu(Eo);n.removeAllItems(),n.emitChange();let s=0;for(;;){let o=await r(),c=${++s}: /${e}/${o.title};n.addItem({title:c,onClick:()=>{}}),console.log(c);let a=o.lines.find(i=>o.lastAccessed<i.updated);if(a){let i=document.createElement("a");i.href=./${encodeURIComponent(o.title)}#${a.id}`,i.rel="route",document.body.appendChild(i),i.click(),i.remove();return}}}});export{mr as scrapBindings};