Scrapbubble
code:script.js
var _e,h,Et,bo,de,Lt,Tt,Pt,Ee={},Nt=[],xo=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|inech|zoo|^ord|itera/i;function z(e,t){for(var r in t)er=tr;return e}function St(e){var t=e.parentNode;t&&t.removeChild(e)}function u(e,t,r){var o,n,s,c={};for(s in t)s=="key"?o=ts:s=="ref"?n=ts:cs=ts;if(arguments.length>2&&(c.children=arguments.length>3?_e.call(arguments,2):r),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)cs===void 0&&(cs=e.defaultPropss);return Le(e,c,o,n,null)}function Le(e,t,r,o,n){var s={type:e,props:t,key:r,ref:o,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:n??++Et};return n==null&&h.vnode!=null&&h.vnode(s),s}function w(e){return e.children}function Te(e,t){this.props=e,this.context=t}function J(e,t){if(t==null)return e.__?J(e.__,e.__.__k.indexOf(e)+1):null;for(var r;t<e.__k.length;t++)if((r=e.__kt)!=null&&r.__e!=null)return r.__e;return typeof e.type=="function"?J(e):null}function It(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.__kt)!=null&&r.__e!=null){e.__e=e.__c.base=r.__e;break}return It(e)}}function Ge(e){(!e.__d&&(e.__d=!0)&&de.push(e)&&!Pe.__r++||Tt!==h.debounceRendering)&&((Tt=h.debounceRendering)||Lt)(Pe)}function Pe(){for(var e;Pe.__r=de.length;)e=de.sort(function(t,r){return t.__v.__b-r.__v.__b}),de=[],e.some(function(t){var r,o,n,s,c,p;t.__d&&(c=(s=(r=t).__v).__e,(p=r.__P)&&(o=[],(n=z({},s)).__v=s.__v+1,Xe(p,s,n,r.__n,p.ownerSVGElement!==void 0,s.__h!=null?c:null,o,c??J(s),s.__h),$t(o,s),s.__e!=c&&It(s)))})}function Mt(e,t,r,o,n,s,c,p,l,a){var i,f,d,m,g,b,x,y=o&&o.__k||Nt,E=y.length;for(r.__k=[],i=0;i<t.length;i++)if((m=r.__ki=(m=ti)==null||typeof m=="boolean"?null:typeof m=="string"||typeof m=="number"||typeof m=="bigint"?Le(null,m,null,null,m):Array.isArray(m)?Le(w,{children:m},null,null,null):m.__b>0?Le(m.type,m.props,m.key,null,m.__v):m)!=null){if(m.__=r,m.__b=r.__b+1,(d=yi)===null||d&&m.key==d.key&&m.type===d.type)yi=void 0;else for(f=0;f<E;f++){if((d=yf)&&m.key==d.key&&m.type===d.type){yf=void 0;break}d=null}Xe(e,m,d=d||Ee,n,s,c,p,l,a),g=m.__e,(f=m.ref)&&d.ref!=f&&(x||(x=[]),d.ref&&x.push(d.ref,null,m),x.push(f,m.__c||g,m)),g!=null?(b==null&&(b=g),typeof m.type=="function"&&m.__k===d.__k?m.__d=l=Rt(m,l,e):l=Ct(e,m,d,y,g,l),typeof r.type=="function"&&(r.__d=l)):l&&d.__e==l&&l.parentNode!=e&&(l=J(d))}for(r.__e=b,i=E;i--;)yi!=null&&(typeof r.type=="function"&&yi.__e!=null&&yi.__e==r.__d&&(r.__d=J(o,i+1)),Ht(yi,yi));if(x)for(i=0;i<x.length;i++)Dt(xi,x++i,x++i)}function Rt(e,t,r){for(var o,n=e.__k,s=0;n&&s<n.length;s++)(o=ns)&&(o.__=e,t=typeof o.type=="function"?Rt(o,t,r):Ct(r,o,o,n,o.__e,t));return t}function Ct(e,t,r,o,n,s){var c,p,l;if(t.__d!==void 0)c=t.__d,t.__d=void 0;else if(r==null||n!=s||n.parentNode==null)e:if(s==null||s.parentNode!==e)e.appendChild(n),c=null;else{for(p=s,l=0;(p=p.nextSibling)&&l<o.length;l+=2)if(p==n)break e;e.insertBefore(n,s),c=s}return c!==void 0?c:n.nextSibling}function yo(e,t,r,o,n){var s;for(s in r)s==="children"||s==="key"||s in t||Ne(e,s,null,rs,o);for(s in t)n&&typeof ts!="function"||s==="children"||s==="key"||s==="value"||s==="checked"||rs===ts||Ne(e,s,ts,rs,o)}function jt(e,t,r){t0==="-"?e.setProperty(t,r):et=r==null?"":typeof r!="number"||xo.test(t)?r:r+"px"}function Ne(e,t,r,o,n){var s;e:if(t==="style")if(typeof r=="string")e.style.cssText=r;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)r&&t in r||jt(e.style,t,"");if(r)for(t in r)o&&rt===ot||jt(e.style,t,rt)}else if(t0==="o"&&t1==="n")s=t!==(t=t.replace(/Capture$/,"")),t=t.toLowerCase()in e?t.toLowerCase().slice(2):t.slice(2),e.l||(e.l={}),e.lt+s=r,r?o||e.addEventListener(t,s?Bt:Ot,s):e.removeEventListener(t,s?Bt:Ot,s);else if(t!=="dangerouslySetInnerHTML"){if(n)t=t.replace(/xlinkH:h/,"h").replace(/sName$/,"s");else if(t!=="href"&&t!=="list"&&t!=="form"&&t!=="tabIndex"&&t!=="download"&&t in e)try{et=r??"";break e}catch{}typeof r=="function"||(r!=null&&(r!==!1||t0==="a"&&t1==="r")?e.setAttribute(t,r):e.removeAttribute(t))}}function Ot(e){this.le.type+!1(h.event?h.event(e):e)}function Bt(e){this.le.type+!0(h.event?h.event(e):e)}function Xe(e,t,r,o,n,s,c,p,l){var a,i,f,d,m,g,b,x,y,E,F,H=t.type;if(t.constructor!==void 0)return null;r.__h!=null&&(l=r.__h,p=t.__e=r.__e,t.__h=null,s=p),(a=h.__b)&&a(t);try{e:if(typeof H=="function"){if(x=t.props,y=(a=H.contextType)&&oa.__c,E=a?y?y.props.value:a.__:o,r.__c?b=(i=t.__c=r.__c).__=i.__E:("prototype"in H&&H.prototype.render?t.__c=i=new H(x,E):(t.__c=i=new Te(x,E),i.constructor=H,i.render=ko),y&&y.sub(i),i.props=x,i.state||(i.state={}),i.context=E,i.__n=o,f=i.__d=!0,i.__h=[]),i.__s==null&&(i.__s=i.state),H.getDerivedStateFromProps!=null&&(i.__s==i.state&&(i.__s=z({},i.__s)),z(i.__s,H.getDerivedStateFromProps(x,i.__s))),d=i.props,m=i.state,f)H.getDerivedStateFromProps==null&&i.componentWillMount!=null&&i.componentWillMount(),i.componentDidMount!=null&&i.__h.push(i.componentDidMount);else{if(H.getDerivedStateFromProps==null&&x!==d&&i.componentWillReceiveProps!=null&&i.componentWillReceiveProps(x,E),!i.__e&&i.shouldComponentUpdate!=null&&i.shouldComponentUpdate(x,i.__s,E)===!1||t.__v===r.__v){i.props=x,i.state=i.__s,t.__v!==r.__v&&(i.__d=!1),i.__v=t,t.__e=r.__e,t.__k=r.__k,t.__k.forEach(function(Q){Q&&(Q.__=t)}),i.__h.length&&c.push(i);break e}i.componentWillUpdate!=null&&i.componentWillUpdate(x,i.__s,E),i.componentDidUpdate!=null&&i.__h.push(function(){i.componentDidUpdate(d,m,g)})}i.context=E,i.props=x,i.state=i.__s,(a=h.__r)&&a(t),i.__d=!1,i.__v=t,i.__P=e,a=i.render(i.props,i.state,i.context),i.state=i.__s,i.getChildContext!=null&&(o=z(z({},o),i.getChildContext())),f||i.getSnapshotBeforeUpdate==null||(g=i.getSnapshotBeforeUpdate(d,m)),F=a!=null&&a.type===w&&a.key==null?a.props.children:a,Mt(e,Array.isArray(F)?F:F,t,r,o,n,s,c,p,l),i.base=t.__e,t.__h=null,i.__h.length&&c.push(i),b&&(i.__E=i.__=null),i.__e=!1}else s==null&&t.__v===r.__v?(t.__k=r.__k,t.__e=r.__e):t.__e=vo(r.__e,t,r,o,n,s,c,l);(a=h.diffed)&&a(t)}catch(Q){t.__v=null,(l||s!=null)&&(t.__e=p,t.__h=!!l,ss.indexOf(p)=null),h.__e(Q,t,r)}}function $t(e,t){h.__c&&h.__c(t,e),e.some(function(r){try{e=r.__h,r.__h=[],e.some(function(o){o.call(r)})}catch(o){h.__e(o,r.__v)}})}function vo(e,t,r,o,n,s,c,p){var l,a,i,f=r.props,d=t.props,m=t.type,g=0;if(m==="svg"&&(n=!0),s!=null){for(;g<s.length;g++)if((l=sg)&&"setAttribute"in l==!!m&&(m?l.localName===m:l.nodeType===3)){e=l,sg=null;break}}if(e==null){if(m===null)return document.createTextNode(d);e=n?document.createElementNS("http://www.w3.org/2000/svg",m):document.createElement(m,d.is&&d),s=null,p=!1}if(m===null)f===d||p&&e.data===d||(e.data=d);else{if(s=s&&_e.call(e.childNodes),a=(f=r.props||Ee).dangerouslySetInnerHTML,i=d.dangerouslySetInnerHTML,!p){if(s!=null)for(f={},g=0;g<e.attributes.length;g++)f[e.attributes[g].name]=e.attributes[g].value;(i||a)&&(i&&(a&&i.__html==a.__html||i.__html===e.innerHTML)||(e.innerHTML=i&&i.__html||""))}if(yo(e,d,f,n,p),i)t.__k=[];else if(g=t.props.children,Mt(e,Array.isArray(g)?g:g,t,r,o,n&&m!=="foreignObject",s,c,s?s0:r.__k&&J(r,0),p),s!=null)for(g=s.length;g--;)sg!=null&&St(sg);p||("value"in d&&(g=d.value)!==void 0&&(g!==f.value||g!==e.value||m==="progress"&&!g)&&Ne(e,"value",g,f.value,!1),"checked"in d&&(g=d.checked)!==void 0&&g!==e.checked&&Ne(e,"checked",g,f.checked,!1))}return e}function Dt(e,t,r){try{typeof e=="function"?e(t):e.current=t}catch(o){h.__e(o,r)}}function Ht(e,t,r){var o,n;if(h.unmount&&h.unmount(e),(o=e.ref)&&(o.current&&o.current!==e.__e||Dt(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){h.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(n=0;n<o.length;n++)on&&Ht(on,t,typeof e.type!="function");r||e.__e==null||St(e.__e),e.__e=e.__d=void 0}function ko(e,t,r){return this.constructor(e,r)}function Se(e,t,r){var o,n,s;h.__&&h.__(e,t),n=(o=typeof r=="function")?null:r&&r.__k||t.__k,s=[],Xe(t,e=(!o&&r||t).__k=u(w,null,e),n||Ee,Ee,t.ownerSVGElement!==void 0,!o&&r?r:n?null:t.firstChild?_e.call(t.childNodes):null,s,!o&&r?r:n?n.__e:t.firstChild,o),$t(s,e)}function Ve(e,t){var r={__c:t="__cC"+Pt++,__:e,Consumer:function(o,n){return o.children(n)},Provider:function(o){var n,s;return this.getChildContext||(n=[],(s={})t=this,this.getChildContext=function(){return s},this.shouldComponentUpdate=function(c){this.props.value!==c.value&&n.some(Ge)},this.sub=function(c){n.push(c);var p=c.componentWillUnmount;c.componentWillUnmount=function(){n.splice(n.indexOf(c),1),p&&p.call(c)}}),o.children}};return r.Provider.__=r.Consumer.contextType=r}_e=Nt.slice,h={__e:function(e,t){for(var r,o,n;t=t.__;)if((r=t.__c)&&!r.__)try{if((o=r.constructor)&&o.getDerivedStateFromError!=null&&(r.setState(o.getDerivedStateFromError(e)),n=r.__d),r.componentDidCatch!=null&&(r.componentDidCatch(e),n=r.__d),n)return r.__E=r}catch(s){e=s}throw e}},Et=0,bo=function(e){return e!=null&&e.constructor===void 0},Te.prototype.setState=function(e,t){var r;r=this.__s!=null&&this.__s!==this.state?this.__s:this.__s=z({},this.state),typeof e=="function"&&(e=e(z({},r),this.props)),e&&z(r,e),e!=null&&this.__v&&(t&&this.__h.push(t),Ge(this))},Te.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Ge(this))},Te.prototype.render=w,de=[],Lt=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Pe.__r=0,Pt=0;var Z,S,At,fe=0,Qe=[],Ft=h.__b,Ut=h.__r,qt=h.diffed,Kt=h.__c,zt=h.unmount;function me(e,t){h.__h&&h.__h(S,e,fe||t),fe=0;var r=S.__H||(S.__H={__:[],__h:[]});return e>=r.__.length&&r.__.push({}),r.__e}function I(e){return fe=1,wo(Gt,e)}function wo(e,t,r){var o=me(Z++,2);return o.t=e,o.__c||(o.__=[r?r(t):Gt(void 0,t),function(n){var s=o.t(o.__0,n);o.__0!==s&&(o.__=[s,o.__1],o.__c.setState({}))}],o.__c=S),o.__}function O(e,t){var r=me(Z++,3);!h.__s&&Je(r.__H,t)&&(r.__=e,r.__H=t,S.__H.__h.push(r))}function Ie(e,t){var r=me(Z++,4);!h.__s&&Je(r.__H,t)&&(r.__=e,r.__H=t,S.__h.push(r))}function ee(e){return fe=5,k(function(){return{current:e}},[])}function k(e,t){var r=me(Z++,7);return Je(r.__H,t)&&(r.__=e(),r.__H=t,r.__h=e),r.__}function B(e,t){return fe=8,k(function(){return e},t)}function W(e){var t=S.contexte.__c,r=me(Z++,9);return r.c=e,t?(r.__==null&&(r.__=!0,t.sub(S)),t.props.value):e.__}function _o(){var e;for(Qe.sort(function(t,r){return t.__v.__b-r.__v.__b});e=Qe.pop();)if(e.__P)try{e.__H.__h.forEach(Me),e.__H.__h.forEach(Ye),e.__H.__h=[]}catch(t){e.__H.__h=[],h.__e(t,e.__v)}}h.__b=function(e){S=null,Ft&&Ft(e)},h.__r=function(e){Ut&&Ut(e),Z=0;var t=(S=e.__c).__H;t&&(t.__h.forEach(Me),t.__h.forEach(Ye),t.__h=[])},h.diffed=function(e){qt&&qt(e);var t=e.__c;t&&t.__H&&t.__H.__h.length&&(Qe.push(t)!==1&&At===h.requestAnimationFrame||((At=h.requestAnimationFrame)||function(r){var o,n=function(){clearTimeout(s),Wt&&cancelAnimationFrame(o),setTimeout(r)},s=setTimeout(n,100);Wt&&(o=requestAnimationFrame(n))})(_o)),S=null},h.__c=function(e,t){t.some(function(r){try{r.__h.forEach(Me),r.__h=r.__h.filter(function(o){return!o.__||Ye(o)})}catch(o){t.some(function(n){n.__h&&(n.__h=[])}),t=[],h.__e(o,r.__v)}}),Kt&&Kt(e,t)},h.unmount=function(e){zt&&zt(e);var t,r=e.__c;r&&r.__H&&(r.__H.__.forEach(function(o){try{Me(o)}catch(n){t=n}}),t&&h.__e(t,r.__v))};var Wt=typeof requestAnimationFrame=="function";function Me(e){var t=S,r=e.__c;typeof r=="function"&&(e.__c=void 0,r()),S=t}function Ye(e){var t=S;e.__c=e.__(),S=t}function Je(e,t){return!e||e.length!==t.length||t.some(function(r,o){return r!==eo})}function Gt(e,t){return typeof t=="function"?t(e):t}var Y=(e,t)=>{if(!(e instanceof HTMLDivElement))throw Error(${t??"value"} must be HTMLDivElement)};var Xt=()=>{let e=localStorage.getItem("projectsLastAccessed");if(!e)return[];try{let t=JSON.parse(e);return Object.entries(t).sort((,r,,o)=>o-r).map((r)=>r)}catch(t){if(!(t instanceof SyntaxError))throw t;return[]}};var Lo=e=>typeof e=="object"&&e!==null,To=e=>Lo(e)?(e.name===void 0||typeof e.name=="string")&&typeof e.message=="string":!1,Vt=e=>{try{let t=typeof e=="string"?JSON.parse(e):e;return To(t)?t:!1}catch(t){if(t instanceof SyntaxError)return!1;throw t}};var Qt=(e,t)=>{if(!(e instanceof HTMLDivElement))throw new TypeError("${t}" must be HTMLDivElememt but actual is "${e}")};var te=()=>Po(document.getElementById("editor"),"div#editor");var Po=(e,t)=>{if(!!e)return Qt(e,t),e};var re=e=>new Promise(t=>setTimeout(()=>t(),e));var M=e=>e.replaceAll(" ","_").toLowerCase();var C=e=>...e.map((t,r)=>t===" "?"_":!Ro.includes(t)||r===e.length-1&&Co.includes(t)?encodeURIComponent(t):t).join(""),Ro='@$&+=:;",',Co=':;",';var et=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_${M(e.to.title)}]=r,localStorage.setItem("pageTransitionContext",JSON.stringify(t))};var Jt=async(e,t)=>{let r=await globalThis.caches.keys();for(let o of r.sort().reverse()){let s=await(await caches.open(o)).match(e,t);if(s)return s}};var L=e=>{let{fetch:t=globalThis.fetch,hostName:r="scrapbox.io",...o}=e;return{fetch:t,hostName:r,...o}};var ge=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,ge)}},j=async e=>{let t=e.clone(),r=await t.text(),o=Vt(r);if(!o)throw new ge(t);return{ok:!1,value:o}};var R=e=>connect.sid=${e};var Zt=(e,t,r)=>{let{sid:o,hostName:n,followRename:s,projects:c}=L(r??{}),p=new URLSearchParams;p.append("followRename",${s??!0});for(let a of c??[])p.append("projects",a);let l=https://${n}/api/pages/${e}/${C(t)}?${p.toString()};return new Request(l,o?{headers:{Cookie:R(o)}}:void 0)},er=async e=>{if(!e.ok)return e.status===414?{ok:!1,value:{name:"TooLongURIError",message:"project ids may be too much."}}:j(e);let t=await e.json();return{ok:!0,value:t}},he=async(e,t,r)=>{let{fetch:o}=L(r??{}),n=Zt(e,t,r),s=await o(n);return await er(s)};he.toRequest=Zt;he.fromResponse=er;var tr=(e,t)=>{let{sid:r,hostName:o,sort:n,limit:s,skip:c}=L(t??{}),p=new URLSearchParams;n!==void 0&&p.append("sort",n),s!==void 0&&p.append("limit",${s}),c!==void 0&&p.append("skip",${c});let l=https://${o}/api/pages/${e}?${p.toString()};return new Request(l,r?{headers:{Cookie:R(r)}}:void 0)},rr=async e=>{if(!e.ok)return j(e);let t=await e.json();return{ok:!0,value:t}},or=async(e,t)=>{let{fetch:r}=L(t??{}),o=await r(tr(e,t));return await rr(o)};or.toRequest=tr;or.fromResponse=rr;var nr=(e,t)=>{let{sid:r,hostName:o}=L(t??{});return new Request(https://${o}/api/projects/${e},r?{headers:{Cookie:R(r)}}:void 0)},sr=async e=> {if(!e.ok)return j(e);let t=await e.json();return{ok:!0,value:t}},be=async(e,t)=>{let{fetch:r}=L(t??{}),o=nr(e,t),n=await r(o);return sr(n)};be.toRequest=nr;be.fromResponse=sr;var ir=(e,t)=>{let{sid:r,hostName:o}=L(t??{}),n=new URLSearchParams;for(let s of e)n.append("ids",s);return new Request(https://${o}/api/projects?${n.toString()},r?{headers:{Cookie:R(r)}}:void 0)},ar=async e=>{if(!e.ok)return j(e);let t=await e.json();return{ok:!0,value:t}},cr=async(e,t)=>{let{fetch:r}=L(t??{}),o=await r(ir(e,t));return ar(o)};cr.toRequest=ir;cr.fromResponse=ar;var Oo=/https?:\/\/(?:www\.|music\.|)youtube\.com\/watch/,Bo=/https?:\/\/youtu\.be\/(a-zA-Z\d_-+)(?:\?(^\s{0,100})|)/,$o=/https?:\/\/(?:www\.|)youtube\.com\/shorts\/(a-zA-Z\d_-+)(?:\?(^\s+)|)/,Do=/https?:\/\/(?:www\.|music\.|)youtube\.com\/playlist\?((?:^\s+&|)list=(a-zA-Z\d_-+)(?:&^\s+|))/,lr=e=>{if(Oo.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(Bo);if(t){let,r,o=t;return{videoId:r,params:new URLSearchParams(o),pathType:"dotbe"}}}{let t=e.match($o);if(t){let,r,o=t;return{videoId:r,params:new URLSearchParams(o),pathType:"short"}}}{let t=e.match(Do);if(t){let,r,o=t;return{listId:o,params:new URLSearchParams(r),pathType:"list"}}}};var Ho=/https?:\/\/vimeo\.com\/(0-9+)/i,pr=e=>{let t=e.match(Ho);if(!!t)return t1};var Ao=/https?:\/\/open\.spotify\.com\/(track|artist|playlist|album|episode|show)\/(a-zA-Z\d_-+)(?:\?^\s{0,100}|)/,ur=e=>{let t=e.match(Ao);if(!t)return;let,r,o=t;return{videoId:o,pathType:r}};var Fo=/https?:\/\/anchor\.fm\/a-zA-Z\d_-+\/episodes\/(a-zA-Z\d_-+(?:\/a-zA-Z\d_-+)?)(?:\?^\s{0,100}|)/,dr=e=>{let t=e.match(Fo);if(!t)return;let,r=t;return r};var fr=e=>{let{type:t,pathType:r,content:o,href:n,...s}=e;if(o===""){let c=lr(n);if(c)return{type:"youtube",href:n,...c,...s};let p=pr(n);if(p)return{type:"vimeo",videoId:p,href:n,...s};let l=ur(n);if(l)return{type:"spotify",href:n,...l,...s};let a=dr(n);if(a)return{type:"anchor-fm",videoId:a,href:n,...s};if(qo(n))return{type:"video",href:n,...s}}return Uo(n)?{type:"audio",content:o,href:n,...s}:{type:"absoluteLink",content:o,href:n,...s}},Uo=e=>/\.(?:mp3|ogg|wav|aac)$/.test(e),qo=e=>/\.(?:mp4|webm)$/.test(e);var mr;(function(e){})(mr||(mr={}));var Ko="0.13.3",gr,hr=async(e=Ko)=>{let t=https://cdnjs.cloudflare.com/ajax/libs/KaTeX/${e}/katex.min.js;if(document.querySelector(script[src="${t}"]))return window.katex!==void 0?Promise.resolve(window.katex):await new Promise(o=>{let n=setInterval(()=>{window.katex!==void 0&&(clearInterval(n),o(window.katex))},500)});let r=document.createElement("script");return r.src=t,gr??=new Promise((o,n)=>{r.onload=()=>o(window.katex),r.onerror=s=>n(s),document.head.append(r)}),gr};var xe=(e,t={})=>{let r=ee(null),o,n=I(e),s,c=I("");return O(()=>{(async()=>{let{render:p}=await hr();if(!!r.current)try{p(o,r.current,t),c("")}catch(l){if(l instanceof Error&&l.name==="ParseError")c(l.message.slice("KaTeX parse error: ".length));else throw l}})()},o),{ref:r,error:s,setFormula:n}};var oe=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,o=r?.match?.(/#(a-f\d{24,32})$/)??"","";return r===""?{project:t}:o===""?{project:t,title:r}:{project:t,title:r.slice(0,-1-o.length),hash:o}}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 rt=(e,t)=>t.some(r=>{let o=!e.project;switch(r.type){case"hashTag":return o&&M(r.href)===e.titleLc;case"link":{if(r.pathType=="absolute"||r.pathType==="relative"!==o)return!1;let{project:n,title:s=""}=oe({pathType:r.pathType,href:r.href});return o?!n&&M(s)===e.titleLc:n===e.project&&M(s)===e.titleLc}case"quote":case"strong":case"decoration":return rt(e,r.nodes)}});var _=(e,t)=>/${e}/${M(t)},Re=e=>{let t=e.match("/(^/+)/(.+)");if(!t)throw SyntaxError("${e}" cannnot match "/([^/]+)/(.+)");return{project:t1,titleLc:t2}};var ne=(e,t)=>new Promise(r=>{let o=!1,n=()=>{o=!0,r(!1)};e.addEventListener("click",n),e.addEventListener("pointerleave",n),setTimeout(()=>{o||r(!0),e.removeEventListener("click",n),e.removeEventListener("pointerleave",n),r(!1)},t)});var br=e=>{let t=[],r=new Set,o=n=>{r.delete(n);let s=t.shift();if(!s)return;let c=s0().then(p=>s1(p)).catch(p=>s2(p));r.add(c),c.finally(()=>o(c))};return n=>{if(r.size<e){let s=n();return r.add(s),s.finally(()=>o(s)),s}return new Promise((s,c)=>{t.push(n,s,c)})}};var zo="0.6.5",xr=ScrapBubble-${zo},yr=await globalThis.caches.open(xr);(async()=>{for(let e of await globalThis.caches.keys())e.startsWith("ScrapBubble-")&&e!==xr&&(await globalThis.caches.delete(e),console.log([ScrapBubble] deleted old cache :"${e}"))})();var vr=br(3);async function*Ce(e,t){let r=((t?.saveFailedResponse?yr.match(e):void 0)??Jt(e,t)).then(c=>"cache",c);{let c=re(1e3).then(()=>"timeout"),p=await Promise.race(r,c);if(p!=="timeout"){p1&&(yield["cache",p1]);let l=await vr(()=>fetch(e));!l.ok&&t?.saveFailedResponse&&await yr.put(e,l.clone()),yield"network",l}}let o=vr(()=>fetch(e)).then(c=>"network",c),n,s=await Promise.race(r,o);if(n==="network"){yieldn,s;return}s&&(yieldn,s),yield await o}var kr=(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 o=e.get(t);if(!!o)for(let n of o)n(r)},on:(t,r)=>{let o=e.get(t)??new Set;o.add(r),e.set(t,o)},off:(t,r)=>{let o=e.get(t);!o||o.delete(r)}}};function A(e){for(var t=arguments.length,r=Array(t>1?t-1:0),o=1;o<t;o++)ro-1=argumentso;if(!1)var n,s;throw Error("Immer minified error nr: "+e+(r.length?" "+r.map(function(c){return"'"+c+"'"}).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function se(e){return!!e&&!!ev}function q(e){var t;return!!e&&(function(r){if(!r||typeof r!="object")return!1;var o=Object.getPrototypeOf(r);if(o===null)return!0;var n=Object.hasOwnProperty.call(o,"constructor")&&o.constructor;return n===Object||typeof n=="function"&&Function.toString.call(n)===en}(e)||Array.isArray(e)||!!eMr||!!(!((t=e.constructor)===null||t===void 0)&&tMr)||nt(e)||st(e))}function ie(e,t,r){r===void 0&&(r=!1),ae(e)===0?(r?Object.keys:gt)(e).forEach(function(o){r&&typeof o=="symbol"||t(o,eo,e)}):e.forEach(function(o,n){return t(n,o,e)})}function ae(e){var t=ev;return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:nt(e)?2:st(e)?3:0}function ot(e,t){return ae(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Wo(e,t){return ae(e)===2?e.get(t):et}function wr(e,t,r){var o=ae(e);o===2?e.set(t,r):o===3?(e.delete(t),e.add(r)):et=r}function Go(e,t){return e===t?e!==0||1/e==1/t:e!=e&&t!=t}function nt(e){return Jo&&e instanceof Map}function st(e){return Zo&&e instanceof Set}function T(e){return e.o||e.t}function it(e){if(Array.isArray(e))return Array.prototype.slice.call(e);var t=tn(e);delete tv;for(var r=gt(t),o=0;o<r.length;o++){var n=ro,s=tn;s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(tn={configurable:!0,writable:!0,enumerable:s.enumerable,value:en})}return Object.create(Object.getPrototypeOf(e),t)}function at(e,t){return t===void 0&&(t=!1),ct(e)||se(e)||!q(e)||(ae(e)>1&&(e.set=e.add=e.clear=e.delete=Xo),Object.freeze(e),t&&ie(e,function(r,o){return at(o,!0)},!0)),e}function Xo(){A(2)}function ct(e){return e==null||typeof e!="object"||Object.isFrozen(e)}function U(e){var t=hte;return t||A(18,e),t}function Vo(e,t){hte||(hte=t)}function Oe(){return ve}function lt(e,t){t&&(U("Patches"),e.u=[],e.s=[],e.v=t)}function Be(e){pt(e),e.p.forEach(Qo),e.p=null}function pt(e){e===ve&&(ve=e.l)}function _r(e){return ve={p:[],l:ve,h:e,m:!0,_:0}}function Qo(e){var t=ev;t.i===0||t.i===1?t.j():t.O=!0}function ut(e,t){t._=t.p.length;var r=t.p0,o=e!==void 0&&e!==r;return t.h.g||U("ES5").S(t,e,o),o?(rv.P&&(Be(t),A(4)),q(e)&&(e=$e(t,e),t.l||De(t,e)),t.u&&U("Patches").M(rv.t,e,t.u,t.s)):e=$e(t,r,[]),Be(t),t.u&&t.v(t.u,t.s),e!==Ir?e:void 0}function $e(e,t,r){if(ct(t))return t;var o=tv;if(!o)return ie(t,function(s,c){return Er(e,o,t,s,c,r)},!0),t;if(o.A!==e)return t;if(!o.P)return De(e,o.t,!0),o.t;if(!o.I){o.I=!0,o.A._--;var n=o.i===4||o.i===5?o.o=it(o.k):o.o;ie(o.i===3?new Set(n):n,function(s,c){return Er(e,o,n,s,c,r)}),De(e,n,!1),r&&e.u&&U("Patches").N(o,r,e.u,e.s)}return o.o}function Er(e,t,r,o,n,s){if(se(n)){var c=$e(e,n,s&&t&&t.i!==3&&!ot(t.R,o)?s.concat(o):void 0);if(wr(r,o,c),!se(c))return;e.m=!1}if(q(n)&&!ct(n)){if(!e.h.D&&e._<1)return;$e(e,n),t&&t.A.l||De(e,n)}}function De(e,t,r){r===void 0&&(r=!1),e.h.D&&e.m&&at(t,r)}function dt(e,t){var r=ev;return(r?T(r):e)t}function Lr(e,t){if(t in e)for(var r=Object.getPrototypeOf(e);r;){var o=Object.getOwnPropertyDescriptor(r,t);if(o)return o;r=Object.getPrototypeOf(r)}}function K(e){e.P||(e.P=!0,e.l&&K(e.l))}function ft(e){e.o||(e.o=it(e.t))}function ye(e,t,r){var o=nt(t)?U("MapSet").F(t,r):st(t)?U("MapSet").T(t,r):e.g?function(n,s){var c=Array.isArray(n),p={i:c?1:0,A:s?s.A:Oe(),P:!1,I:!1,R:{},l:s,t:n,k:null,o:null,j:null,C:!1},l=p,a=bt;c&&(l=p,a=ke);var i=Proxy.revocable(l,a),f=i.revoke,d=i.proxy;return p.k=d,p.j=f,d}(t,r):U("ES5").J(t,r);return(r?r.A:Oe()).p.push(o),o}function Yo(e){return se(e)||A(22,e),function t(r){if(!q(r))return r;var o,n=rv,s=ae(r);if(n){if(!n.P&&(n.i<4||!U("ES5").K(n)))return n.t;n.I=!0,o=Tr(r,s),n.I=!1}else o=Tr(r,s);return ie(o,function(c,p){n&&Wo(n.t,c)===p||wr(o,c,t(p))}),s===3?new Set(o):o}(e)}function Tr(e,t){switch(t){case 2:return new Map(e);case 3:return Array.from(e)}return it(e)}function Pr(){function e(p,l){function a(){this.constructor=p}n(p,l),p.prototype=(a.prototype=l.prototype,new a)}function t(p){p.o||(p.R=new Map,p.o=new Map(p.t))}function r(p){p.o||(p.o=new Set,p.t.forEach(function(l){if(q(l)){var a=ye(p.A.h,l,p);p.p.set(l,a),p.o.add(a)}else p.o.add(l)}))}function o(p){p.O&&A(3,JSON.stringify(T(p)))}var n=function(p,l){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,i){a.__proto__=i}||function(a,i){for(var f in i)i.hasOwnProperty(f)&&(af=if)})(p,l)},s=function(){function p(a,i){return thisv={i:2,l:i,A:i?i.A:Oe(),P:!1,I:!1,o:void 0,R:void 0,t:a,k:this,C:!1,O:!1},this}e(p,Map);var l=p.prototype;return Object.defineProperty(l,"size",{get:function(){return T(thisv).size}}),l.has=function(a){return T(thisv).has(a)},l.set=function(a,i){var f=thisv;return o(f),T(f).has(a)&&T(f).get(a)===i||(t(f),K(f),f.R.set(a,!0),f.o.set(a,i),f.R.set(a,!0)),this},l.delete=function(a){if(!this.has(a))return!1;var i=thisv;return o(i),t(i),K(i),i.t.has(a)?i.R.set(a,!1):i.R.delete(a),i.o.delete(a),!0},l.clear=function(){var a=thisv;o(a),T(a).size&&(t(a),K(a),a.R=new Map,ie(a.t,function(i){a.R.set(i,!1)}),a.o.clear())},l.forEach=function(a,i){var f=this;T(thisv).forEach(function(d,m){a.call(i,f.get(m),m,f)})},l.get=function(a){var i=thisv;o(i);var f=T(i).get(a);if(i.I||!q(f)||f!==i.t.get(a))return f;var d=ye(i.A.h,f,i);return t(i),i.o.set(a,d),d},l.keys=function(){return T(thisv).keys()},l.values=function(){var a,i=this,f=this.keys();return(a={})He=function(){return i.values()},a.next=function(){var d=f.next();return d.done?d:{done:!1,value:i.get(d.value)}},a},l.entries=function(){var a,i=this,f=this.keys();return(a={})He=function(){return i.entries()},a.next=function(){var d=f.next();if(d.done)return d;var m=i.get(d.value);return{done:!1,value:d.value,m}},a},lHe=function(){return this.entries()},p}(),c=function(){function p(a,i){return thisv={i:3,l:i,A:i?i.A:Oe(),P:!1,I:!1,o:void 0,t:a,k:this,p:new Map,O:!1,C:!1},this}e(p,Set);var l=p.prototype;return Object.defineProperty(l,"size",{get:function(){return T(thisv).size}}),l.has=function(a){var i=thisv;return o(i),i.o?!!i.o.has(a)||!(!i.p.has(a)||!i.o.has(i.p.get(a))):i.t.has(a)},l.add=function(a){var i=thisv;return o(i),this.has(a)||(r(i),K(i),i.o.add(a)),this},l.delete=function(a){if(!this.has(a))return!1;var i=thisv;return o(i),r(i),K(i),i.o.delete(a)||!!i.p.has(a)&&i.o.delete(i.p.get(a))},l.clear=function(){var a=thisv;o(a),T(a).size&&(r(a),K(a),a.o.clear())},l.values=function(){var a=thisv;return o(a),r(a),a.o.values()},l.entries=function(){var a=thisv;return o(a),r(a),a.o.entries()},l.keys=function(){return this.values()},lHe=function(){return this.values()},l.forEach=function(a,i){for(var f=this.values(),d=f.next();!d.done;)a.call(i,d.value,d.value,this),d=f.next()},p}();Vo("MapSet",{F:function(p,l){return new s(p,l)},T:function(p,l){return new c(p,l)}})}var Nr,ve,mt=typeof Symbol<"u"&&typeof Symbol("x")=="symbol",Jo=typeof Map<"u",Zo=typeof Set<"u",Sr=typeof Proxy<"u"&&Proxy.revocable!==void 0&&typeof Reflect<"u",Ir=mt?Symbol.for("immer-nothing"):((Nr={})"immer-nothing"=!0,Nr),Mr=mt?Symbol.for("immer-draftable"):"__$immer_draftable",v=mt?Symbol.for("immer-state"):"__$immer_state",He=typeof Symbol<"u"&&Symbol.iterator||"@@iterator",en=""+Object.prototype.constructor,gt=typeof Reflect<"u"&&Reflect.ownKeys?Reflect.ownKeys:Object.getOwnPropertySymbols!==void 0?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,tn=Object.getOwnPropertyDescriptors||function(e){var t={};return gt(e).forEach(function(r){tr=Object.getOwnPropertyDescriptor(e,r)}),t},ht={},bt={get:function(e,t){if(t===v)return e;var r=T(e);if(!ot(r,t))return function(n,s,c){var p,l=Lr(s,c);return l?"value"in l?l.value:(p=l.get)===null||p===void 0?void 0:p.call(n.k):void 0}(e,r,t);var o=rt;return e.I||!q(o)?o:o===dt(e.t,t)?(ft(e),e.ot=ye(e.A.h,o,e)):o},has:function(e,t){return t in T(e)},ownKeys:function(e){return Reflect.ownKeys(T(e))},set:function(e,t,r){var o=Lr(T(e),t);if(o?.set)return o.set.call(e.k,r),!0;if(!e.P){var n=dt(T(e),t),s=n?.v;if(s&&s.t===r)return e.ot=r,e.Rt=!1,!0;if(Go(r,n)&&(r!==void 0||ot(e.t,t)))return!0;ft(e),K(e)}return e.ot===r&&(r!==void 0||t in e.o)||Number.isNaN(r)&&Number.isNaN(e.ot)||(e.ot=r,e.Rt=!0),!0},deleteProperty:function(e,t){return dt(e.t,t)!==void 0||t in e.t?(e.Rt=!1,ft(e),K(e)):delete e.Rt,e.o&&delete e.ot,!0},getOwnPropertyDescriptor:function(e,t){var r=T(e),o=Reflect.getOwnPropertyDescriptor(r,t);return o&&{writable:!0,configurable:e.i!==1||t!=="length",enumerable:o.enumerable,value:rt}},defineProperty:function(){A(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){A(12)}},ke={};ie(bt,function(e,t){kee=function(){return arguments0=arguments00,t.apply(this,arguments)}}),ke.deleteProperty=function(e,t){return ke.set.call(this,e,t,void 0)},ke.set=function(e,t,r){return bt.set.call(this,e0,t,r,e0)};var rn=function(){function e(r){var o=this;this.g=Sr,this.D=!0,this.produce=function(n,s,c){if(typeof n=="function"&&typeof s!="function"){var p=s;s=n;var l=o;return function(b){var x=this;b===void 0&&(b=p);for(var y=arguments.length,E=Array(y>1?y-1:0),F=1;F<y;F++)EF-1=argumentsF;return l.produce(b,function(H){var Q;return(Q=s).call.apply(Q,x,H.concat(E))})}}var a;if(typeof s!="function"&&A(6),c!==void 0&&typeof c!="function"&&A(7),q(n)){var i=_r(o),f=ye(o,n,void 0),d=!0;try{a=s(f),d=!1}finally{d?Be(i):pt(i)}return typeof Promise<"u"&&a instanceof Promise?a.then(function(b){return lt(i,c),ut(b,i)},function(b){throw Be(i),b}):(lt(i,c),ut(a,i))}if(!n||typeof n!="object"){if((a=s(n))===void 0&&(a=n),a===Ir&&(a=void 0),o.D&&at(a,!0),c){var m=[],g=[];U("Patches").M(n,a,m,g),c(m,g)}return a}A(21,n)},this.produceWithPatches=function(n,s){if(typeof n=="function")return function(a){for(var i=arguments.length,f=Array(i>1?i-1:0),d=1;d<i;d++)fd-1=argumentsd;return o.produceWithPatches(a,function(m){return n.apply(void 0,m.concat(f))})};var c,p,l=o.produce(n,s,function(a,i){c=a,p=i});return typeof Promise<"u"&&l instanceof Promise?l.then(function(a){returna,c,p}):l,c,p},typeof r?.useProxies=="boolean"&&this.setUseProxies(r.useProxies),typeof r?.autoFreeze=="boolean"&&this.setAutoFreeze(r.autoFreeze)}var t=e.prototype;return t.createDraft=function(r){q(r)||A(8),se(r)&&(r=Yo(r));var o=_r(this),n=ye(this,r,void 0);return nv.C=!0,pt(o),n},t.finishDraft=function(r,o){var n=r&&rv,s=n.A;return lt(s,o),ut(void 0,s)},t.setAutoFreeze=function(r){this.D=r},t.setUseProxies=function(r){r&&!Sr&&A(20),this.g=r},t.applyPatches=function(r,o){var n;for(n=o.length-1;n>=0;n--){var s=on;if(s.path.length===0&&s.op==="replace"){r=s.value;break}}n>-1&&(o=o.slice(n+1));var c=U("Patches").$;return se(r)?c(r,o):this.produce(r,function(p){return c(p,o)})},e}(),$=new rn,Ae=$.produce,gp=$.produceWithPatches.bind($),hp=$.setAutoFreeze.bind($),bp=$.setUseProxies.bind($),xp=$.applyPatches.bind($),yp=$.createDraft.bind($),vp=$.finishDraft.bind($);Pr();var Rr=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},Cr=(e,t)=>Ae(e,r=>{if(!r)return t;if(r.updated<t.updated){let{lines:o,linked:n,projectLinked:s,...c}=t;Object.assign(r,c),xt(t)||(r.lines=o),n&&(r.linked??=n),s&&(r.projectLinked??=s);return}xt(r)&&!xt(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)}),xt=e=>e.lines0.id==="dummy";var jr=(e,t)=>{let r=new Map,o=M(t.title);for(let l of t.links){let a=on(e,l);a.linked=o,r.set(_(e,l),a)}let n=_(e,o),s=t.projectLinks.map(l=>{let a=Re(l);return _(a.project,a.titleLc)}),c={...Fe(e,t),linked:[],projectLinked:[]};r.set(n,c);let p=t.links.map(l=>M(l));for(let l of t.relatedPages.links1hop){l.linksLc.includes(o)&&c.linked.push(l.titleLc);for(let d of l.linksLc.filter(m=>p.includes(m))){let m=_(e,d),g=r.get(m);if(!g)throw Error(storage already must have "${m}");if(!g.linked){g.linked=l.titleLc;continue}g.linked.push(l.titleLc)}let a=_(e,l.titleLc),i=Fe(e,l),f=r.get(a)?.linked;f&&(i.linked=f),r.set(a,i)}for(let l of t.relatedPages.projectLinks1hop){let a=_(l.projectName,l.titleLc);s.includes(a)||c.projectLinked.push(a);let i=Fe(l.projectName,l),f=r.get(a)?.projectLinked;f&&(i.projectLinked=f),r.set(a,i)}c.isLinkedCorrect=!0;for(let l of t.relatedPages.links2hop){for(let d of l.linksLc){let m=_(e,d),g=r.get(m);if(!g)throw Error(storage already must have "${m}");if(!g.linked){g.linked=l.titleLc;continue}g.linked.push(l.titleLc)}let a=_(e,l.titleLc),i=Fe(e,l),f=r.get(a)?.linked;f&&(i.linked=f),r.set(a,i)}return r},Fe=(e,t)=>({project:e,titleLc:"titleLc"in t?t.titleLc:M(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}),on=(e,t)=>({project:e,titleLc:M(t),exists:!1,descriptions:[],image:null,lines:{text:t,id:"dummy",userId:"dummy",updated:0,created:0},updated:0,isLinkedCorrect:!1});var D=!1,Or=e=>{D=typeof e=="boolean"?e:new Set(e)},G=e=>Object.fromEntries(...Object.entries(console).map((t,r)=>{if(typeof r!="function")returnt,r;switch(t){case"warn":case"error":return[t,(...o)=>r(%c${e},"color: gray",...o)];case"log":case"info":case"debug":return[t,(...o)=>{D!==!0&&(!D||!D.has(e))||r(%c${e},"color: gray",...o)}];case"assert":return[t,(o,...n)=>{D!==!0&&(!D||!D.has(e))||r(o,%c${e},"color: gray",...n)}];case"time":case"timeEnd":return[t,o=>{D!==!0&&(!D||!D.has(e))||r(${e} ${o})}];default:returnt,(...o)=>{if(!(D!==!0&&(!D||!D.has(e))))return r(...o)}}}));var Ue=G("ScrapBubble:bubble.ts"),yt=new Map,qe=new Set,vt=je();function*Br(e){for(let t of e)yield yt.get(t)}var $r=(e,t)=>vt.on(e,t),Dr=(e,t)=>vt.off(e,t),Hr=async(e,t,r,o)=>{let n=[];for(let s of t){let c=_(s,e);qe.has(c)||n.push(nn(s,e,r,o))}await Promise.all(n)},Ar=0,nn=async(e,t,r,o)=>{let n=_(e,t);if(qe.has(n))return;qe.add(n);let s=Ar++,c=[${s}] Check update ${n};Ue.time(c);try{let p=he.toRequest(e,t,{followRename:!0,projects:...r});for await(letl,aof Ce(p,{ignoreSearch:!0,saveFailedResponse:!0})){Ue.debug([${s}]${l} ${n});let i=await he.fromResponse(a);if(i.ok){let f=jr(e,i.value);for(letd,mof f){let g=yt.get(d),b=Cr(g,m);!b||g!==b&&(yt.set(d,b),vt.dispatch(d,m))}}if(o?.ignoreFetch===!0||l==="cache"&&!kr(a,o?.maxAge??60))break}}catch(p){Ue.error(p)}finally{qe.delete(n),Ue.timeEnd(c),Ar--}};var Fr=G("ScrapBubble:useBubbleData.ts"),ce=e=>{lett,r=I([]);return Ie(()=>{let o=()=>{r(()=>{let c=...Br(e).flatMap(p=>p?p:[]);return Fr.debug(Required: ${e.length} pages, ${c.length} found,c),c})};o();let n,s=()=>{clearTimeout(n),n=setTimeout(()=>{Fr.debug(Update ${e.length} pages),o()},10)};return e.forEach(c=>$r(c,s)),()=>e.forEach(c=>Dr(c,s))},e),t};var le=e=>{let t=te();Y(t,"#editor");let{top:r,right:o,left:n,bottom:s}=e.getBoundingClientRect(),c=t.getBoundingClientRect(),p=(n-c.left)/c.width>.5;return{top:Math.round(s-c.top),bottom:Math.round(c.bottom-r),...p?{right:Math.round(c.right-o)}:{left:Math.round(n-c.left)},maxWidth:p?o-10:document.documentElement.clientWidth-n-10}};var sn=e=>({type:"title",text:e.rows0.text}),an=e=>{let{rows:t,...r}=e,{indent:o=0,text:n=""}=t??{},s=n.replace(/^\s*code:/,"");return{indent:o,type:"codeBlock",fileName:s,content:r.map(c=>c.text.substring(o+1)).join(` )}},P=(e,{parseOnNested:t,parseOnQuoted:r,patterns:o})=>(n,s,c)=>{var p,l,a,i,f,d;if(!t&&s.nested)return(p=c?.())!==null&&p!==void 0?p:[];if(!r&&s.quoted)return(l=c?.())!==null&&l!==void 0?l:[];for(let m of o){let g=m.exec(n);if(g===null)continue;let b=n.substring(0,g.index),x=n.substring(g.index+((i=(a=g[0])===null||a===void 0?void 0:a.length)!==null&&i!==void 0?i:0)),y=e((f=g[0])!==null&&f!==void 0?f:"",s);return[...X(b,s),...y,...X(x,s)]}return(d=c?.())!==null&&d!==void 0?d:[]},N=e=>[{type:"plain",raw:e,text:e}],cn=P(N,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]}),ln=/^>.*$/,pn=(e,t)=>t.context==="table"?N(e,t):[{type:"quote",raw:e,nodes:X(e.substring(1),{...t,quoted:!0})}],un=P(pn,{parseOnNested:!1,parseOnQuoted:!1,patterns:[ln]}),dn=/^\? .+$/,fn=(e,t)=>t.context==="table"?N(e,t):[{type:"helpfeel",raw:e,text:e.substring(2)}],mn=P(fn,{parseOnNested:!1,parseOnQuoted:!1,patterns:[dn]}),gn=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,hn=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,bn=(e,t)=>{if(t.context==="table")return N(e,t);let r=e.substring(2,e.length-2),o=/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(r);return[{type:"strongImage",raw:e,src:o?${r}/thumb/1000:r}]},xn=P(bn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[gn,hn]}),yn=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;function Ur(e){return(t,r)=>{if(e==="strongIcon"&&r.context==="table")return N(t,r);let o=e==="icon"?t.substring(1,t.length-1):t.substring(2,t.length-2),n=o.lastIndexOf(".icon"),s=o.substring(0,n),c=s.startsWith("/")?"root":"relative",p=o.substring(n+5,o.length),l=p.startsWith("*")?parseInt(p.substring(1),10):1;return new Array(l).fill({}).map(()=>({path:s,pathType:c,type:e,raw:t}))}}var vn=Ur("icon"),kn=P(vn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[yn]}),wn=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,_n=Ur("strongIcon"),En=P(_n,{parseOnNested:!1,parseOnQuoted:!0,patterns:[wn]}),Ln=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,Tn=(e,t)=>t.context==="table"?N(e,t):[{type:"strong",raw:e,nodes:X(e.substring(2,e.length-2),{...t,nested:!0})}],Pn=P(Tn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Ln]}),Nn=/\[\$ .+? \]/,Sn=/\[\$ [^\]]+\]/,In=(e,t)=>t.context==="table"?N(e,t):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],Mn=P(In,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Nn,Sn]}),Rn=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,Cn=(e,t)=>{if(t.context==="table")return N(e,t);let r=e.indexOf(" "),o=e.substring(1,r),n=e.substring(r+1,e.length-1),s=new Set(o);if(s.has("*")){let c=o.split("*").length-1;s.delete("*"),s.add(*-${Math.min(c,10)})}return[{type:"decoration",raw:e,rawDecos:o,decos:Array.from(s),nodes:X(n,{...t,nested:!0})}]},jn=P(Cn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Rn]}),On=/.*?/,Bn=(e,t)=>t.context==="table"?N(e,t):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],$n=P(Bn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[On]}),Dn=/^[$%] .+$/,Hn=(e,t)=>{var r;if(t.context==="table")return N(e,t);let o=(r=e[0])!==null&&r!==void 0?r:"",n=e.substring(2);return[{type:"commandLine",raw:e,symbol:o,text:n}]},An=P(Hn,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Dn]}),Fn=/\[\s+\]/,Un=(e,t)=>t.context==="table"?N(e,t):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],qn=P(Un,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Fn]}),Kn=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,zn=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,Wn=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,Gn=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,Xn=e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(e)||Vn(e),Vn=e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),Qn=(e,t)=>{if(t.context==="table")return N(e,t);let r=e.search(/\s/),o=r!==-1?e.substring(1,r):e.substring(1,e.length-1),n=r!==-1?e.substring(r,e.length-1).trimLeft():"",[s,c]=Xn(n)?[n,o]:[o,n];return[{type:"image",raw:e,src:/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(s)?${s}/thumb/1000:s,link:c}]},Yn=P(Qn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Kn,zn,Wn,Gn]}),Jn=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,Zn=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,es=/\[https?:\/\/[^\s\]]+\]/,ts=/https?:\/\/[^\s]+/,rs=(e,t)=>{if(t.context==="table")return N(e,t);let r=e.startsWith("[")&&e.endsWith("]")?e.substring(1,e.length-1):e,o=/^https?:\/\/[^\s\]]/.test(r),n=(o?/^https?:\/\/[^\s\]]+/:/https?:\/\/[^\s\]]+$/).exec(r);if(n?.[0]===void 0)return[];let s=o?r.substring(n[0].length):r.substring(0,n.index-1);return[{type:"link",raw:e,pathType:"absolute",href:n[0],content:s.trim()}]},os=P(rs,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Jn,Zn,es,ts]}),qr=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,Kr=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,ns=e=>{let[t="",r="",o=""]=e.split(","),n=parseFloat(t.replace(/^N/,"").replace(/^S/,"-")),s=parseFloat(r.replace(/^E/,"").replace(/^W/,"-")),c=/^Z\d+$/.test(o)?parseInt(o.replace(/^Z/,""),10):14;return{latitude:n,longitude:s,zoom:c}},ss=(e,t)=>{var r;if(t.context==="table")return N(e,t);let o=(r=e.match(qr))!==null&&r!==void 0?r:e.match(Kr);if(o===null)return[];let n=e.startsWith("[N")||e.startsWith("[S"),[,s="",c=""]=n?o:[o[0],o[2],o[1]],{latitude:p,longitude:l,zoom:a}=ns(s),i=c!==""?https://www.google.com/maps/place/${encodeURIComponent(c)}/@${p},${l},${a}z:https://www.google.com/maps/@${p},${l},${a}z;return[{type:"googleMap",raw:e,latitude:p,longitude:l,zoom:a,place:c,url:i}]},is=P(ss,{parseOnNested:!1,parseOnQuoted:!0,patterns:[qr,Kr]}),as=/\[\/?[^[\]]+\]/,cs=e=>{let t=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:t.startsWith("/")?"root":"relative",href:t,content:""}]},ls=P(cs,{parseOnNested:!0,parseOnQuoted:!0,patterns:[as]}),ps=/(?:^|\s)#\S+/,us=(e,t)=>{if(t.context==="table")return N(e,t);if(e.startsWith("#"))return[{type:"hashTag",raw:e,href:e.substring(1)}];let r=e.substring(0,1),o=e.substring(1);return[...N(r,t),{type:"hashTag",raw:o,href:o.substring(1)}]},ds=P(us,{parseOnNested:!0,parseOnQuoted:!0,patterns:[ps]}),fs=/^[0-9]+\. .*$/,ms=(e,t)=>{if(t.context==="table")return N(e,t);let r=e.indexOf(" "),o=e.substring(0,r-1),n=parseInt(o,10),s=e.substring(r+1,e.length);return[{type:"numberList",raw:e,rawNumber:o,number:n,nodes:X(s,{...t,nested:!0})}]},gs=P(ms,{parseOnNested:!1,parseOnQuoted:!1,patterns:[fs]}),hs=(e,t,r)=>{var o;return e===""?[]:(o=r?.())!==null&&o!==void 0?o:[]},bs=(...e)=>(t,r)=>e.reduceRight((o,n)=>()=>n(t,r,o),()=>cn(t,r))(),X=bs(hs,un,mn,$n,An,Mn,qn,jn,xn,En,Pn,Yn,os,kn,is,ls,ds,gs),xs=e=>{let{rows:[t,...r]}=e,{indent:o=0,text:n=""}=t??{},s=n.replace(/^\s*table:/,"");return{indent:o,type:"table",fileName:s,cells:r.map(c=>c.text.substring(o+1)).map(c=>c.split(" ").map(p=>X(p,{nested:!1,quoted:!1,context:"table"})))}},ys=e=>{let{indent:t,text:r}=e.rows[0];return{indent:t,type:"line",nodes:X(r.substring(t),{nested:!1,quoted:!1,context:"line"})}},vs=e=>{switch(e.type){case"title":return sn(e);case"codeBlock":return an(e);case"table":return xs(e);case"line":return ys(e)}},ks=e=>e.split( ).map(t=>{var r,o,n;return{indent:(n=(o=(r=/^\s+/.exec(t))===null||r===void 0?void 0:r[0])===null||o===void 0?void 0:o.length)!==null&&n!==void 0?n:0,text:t}}),ws=(e,t)=>{var r,o;return(e.type==="codeBlock"||e.type==="table")&&t.indent>((o=(r=e.rows[0])===null||r===void 0?void 0:r.indent)!==null&&o!==void 0?o:0)},zr=(e,t)=>{let r=e[e.length-1];return r!==void 0&&ws(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)},_s=(e,t)=>{var r;if(!((r=t.hasTitle)!==null&&r!==void 0)||r){let[o,...n]=e;return o===void 0?[]:[{type:"title",rows:[o]},...n.reduce(zr,[])]}return e.reduce(zr,[])},we=(e,t)=>{var r;let o=ks(e);return _s(o,{hasTitle:(r=t?.hasTitle)!==null&&r!==void 0?r:!0}).map(vs)};var V=Ve({title:"",project:"",whiteList:new Set,bubble:()=>{},hide:()=>{},delay:0,prefetch:()=>{}}),Wr=({lines:e,project:t,title:r,whiteList:o,noIndent:n,hash:s,linkTo:c,...p})=>{let l=k(()=>e.flatMap(d=>typeof d=="string"?[]:[d.id]),[e]),a=k(()=>{let d=0;return we(e.map(m=>typeof m=="string"?m:m.text).join(
),{hasTitle:!0}).map(m=>{switch(m.type){case"title":case"line":return{...m,id:l[d++]};case"codeBlock":{let g=d;return d+=m.content.split(
).length+1,{...m,ids:l.slice(g,d)}}case"table":{let g=d;return d+=m.cells.length+1,{...m,ids:l.slice(g,d)}}}})},[e,l]),i=k(()=>{if(s&&l.includes(s))return s;if(!!c)return a.find(d=>d.type!=="line"?!1:rt(c,d.nodes))?.id},[a,l,s,c?.project,c?.titleLc]),f=ee(null);return O(()=>{if(!i)return;let d=f.current?.querySelector(data-id="${i}"),m=window.scrollY;d?.scrollIntoView?.({block:"center"}),window.scroll(0,m)},[i]),u("div",{className:"lines",ref:f},u(V.Provider,{value:{project:t,title:r,whiteList:o,...p}},a.map(d=>{switch(d.type){case"title":return u(w,null,u(pe,{key:d.id,index:d.id,indent:0,noIndent:n,permalink:d.id===i},d.text),u("hr",null));case"codeBlock":return u(Es,{key:d.ids[0],block:d,noIndent:n,ids:d.ids,scrollId:i});case"table":return u(Ls,{key:d.ids[0],block:d,noIndent:n,ids:d.ids,scrollId:i});case"line":return u(pe,{key:d.id,index:d.id,indent:d.indent,noIndent:n,permalink:d.id===i},d.nodes.length>0?d.nodes.map(m=>u(ue,{node:m})):u("br",null))}})))},pe=({index:e,indent:t,noIndent:r,children:o,permalink:n})=>u("div",{className:line${n?" permalink":""},"data-id":e,"data-indent":t,style:{"margin-left":r?"":${1*t}em}},o),Es=({block:{fileName:e,content:t,indent:r},ids:o,scrollId:n})=>{let{project:s,title:c}=W(V),[p,l]=I(""),a=B(async i=>{i.preventDefault(),i.stopPropagation();try{await navigator.clipboard.writeText(t),l("Copied"),await re(1e3),l("")}catch(f){alert(Failed to copy the code block Error:${f.message})}},[t]);return u(w,null,u(pe,{index:o[0],indent:r,permalink:o[0]===n},u("span",{className:"code-block"},u("span",{className:"code-block-start"},e.includes(".")?u("a",{href:/api/code/${s}/${C(c)}/${e},target:"_blank"},e):e),u("span",{className:"copy",title:"Copy",onClick:a},p))),u(w,null,t.split(
).map((i,f)=>u(pe,{index:o[f+1],indent:r,permalink:o[f+1]===n},u("code",{className:"code-block"},i)))))},Ls=({block:{fileName:e,cells:t,indent:r},ids:o,scrollId:n})=>{let{project:s,title:c}=W(V);return u(w,null,u(pe,{index:o[0],indent:r,permalink:o[0]===n},u("span",{className:"table-block"},u("span",{className:"table-block-start"},u("a",{href:/api/table/${s}/${C(c)}/${e}.csv,target:"_blank"},e)))),u(w,null,t.map((p,l)=>u(pe,{index:o[l+1],indent:r,permalink:o[l+1]===n},u("span",{className:"table-block table-block-row"},p.map((a,i)=>u("span",{className:cell col-${i}},a.map(f=>u(ue,{node:f})))))))))},ue=({node:e})=>{switch(e.type){case"code":return u("code",{className:"code"},e.text);case"formula":return u(Ts,{node:e});case"commandLine":return u("code",{className:"cli"},u("span",{className:"prefix"},e.symbol)," ",u("span",{className:"command"},e.text));case"helpfeel":return u("code",{className:"helpfeel"},u("span",{className:"prefix"},"?")," ",u("span",{className:"entry"},e.text));case"quote":return u("blockquote",{className:"quote"},e.nodes.map(t=>u(ue,{node:t})));case"strong":return u("strong",null,e.nodes.map(t=>u(ue,{node:t})));case"decoration":return u(Ps,{node:e});case"plain":case"blank":return u(w,null,e.text);case"hashTag":return u(Is,{node:e});case"link":return u(Ms,{node:e});case"googleMap":return u(Ns,{node:e});case"icon":return u(Gr,{node:e});case"strongIcon":return u(Gr,{node:e,strong:!0});case"image":return u(Ss,{node:e});case"strongImage":return u("img",{className:"image strong-image",src:e.src});case"numberList":return u(w,null,${e.number}. ,e.nodes.map(t=>u(ue,{node:t})))}},Ts=({node:{formula:e}})=>{let{ref:t,error:r,setFormula:o}=xe("");return o(e),u("span",{className:formula ${r?" error":""}},r?u("code",null,e):u("span",{className:"katex-display",ref:t}))},Ps=({node:{decos:e,nodes:t}})=>u("span",{className:e.map(r=>deco-${r}).join(" ")},t.map(r=>u(ue,{node:r}))),Ns=({node:{place:e,latitude:t,longitude:r,zoom:o}})=>u("span",{className:"pointing-device-map"},u("a",{href:https://www.google.com/maps/search/${e}/@${t},${r},${o}z,rel:"noopner noreferrer",target:"_blank"},u("img",{className:"google-map",src:/api/google-map/static-map?center=${t}%2C${r}&markers=${e}&zoom=${o}&_csrf=${window._csrf}}))),Gr=({node:{pathType:e,path:t},strong:r})=>{let{project:o}=W(V),[n,s]=e==="relative"?[o,t]:t.match(/\/([\w\-]+)\/(.+)$/)?.slice?.(1)??[o,t],c=C(s);return u("a",{href:/${n}/${c},rel:n===scrapbox.Project.name?"route":"noopener noreferrer",target:n===scrapbox.Project.name?"":"_blank"},u("img",{className:r?"icon strong-icon":"icon",alt:s,src:/api/pages/${n}/${c}/icon`},s))},Ss=({node:{link:e,src:t}})=>{let r=e||(/https:\/\/gyazo\.com\/^\/+\/thumb\/1000/.test(t)?t.slice(0,-"/thumb/1000".length):t);return u("a",{className:e?"link":"",href:r,rel:"noopner noreferrer",target:"_blank"},u("img",{className:"image",src:t}))},Is=({node:{href:e}})=> {let{project:t}=W(V),r=Xr(t,e),o=Vr(t,e,"hashtag");return u("a",{href:/${t}/${C(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:o},"#",e)},Ms=({node:{pathType:e,...t}})=>{switch(e){case"relative":case"root":return u(Rs,{pathType:e,href:t.href});case"absolute":{let r=fr({pathType:e,...t});switch(r.type){case"youtube":return u(Cs,{...r});case"vimeo":return u(js,{...r});case"spotify":return u(Os,{...r});case"anchor-fm":return u(Bs,{...r});case"audio":return u($s,{...r});case"video":return u(Hs,{...r});case"absoluteLink":return u("a",{className:"link",href:r.href,rel:"noopener noreferrer",target:"_blank"},r.content||r.href)}}}},Rs=({pathType:e,href:t})=>{let{project:r}=W(V),{project:o=r,title:n,hash:s=""}=oe({pathType:e,href:t}),c=Vr(o,n,"link",s),p=Xr(o,n??"");return u("a",{className:page-link${n!==void 0&&p?" empty-page-link":""},type:"link",href:/${o}${n===void 0?"":/${C(n)}${s===""?"":#${s}}},rel:o===scrapbox.Project.name?"route":"noopener noreferrer",target:o===scrapbox.Project.name?"":"_blank",onPointerEnter:c},t)},Cs=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 u("div",{className:"iframe-video-player"},u("iframe",{src:t,allowFullScreen:!0,type:"text/html"}))},js=({videoId:e})=>u("div",{className:"iframe-video-player"},u("iframe",{src:https://player.vimeo.com/video/${e},allowFullScreen:!0,type:"text/html"})),Os=e=>u("div",{className:"iframe-video-player"},u("iframe",{className:spotify type-${e.pathType},src:https://open.spotify.com/embed/${e.pathType}/${e.videoId},allowFullScreen:!0,type:"text/html",scrolling:"no"})),Bs=e=>u("div",{className:"iframe-video-player"},u("iframe",{className:"anchor-fm",src:e.href.replace("/episodes/","/embed/episodes/"),allowFullScreen:!0,type:"text/html",scrolling:"no"})),$s=e=>e.content===""?u("audio",{className:"audio-player",preload:"none",controls:!0,src:e.href}):u(Ds,{...e}),Ds=({href:e,content:t})=>{let r=ee(null),o=B(()=>{r.current?.paused?(r.current.currentTime=0,r.current.play()):r.current?.pause?.()},[]);return u("span",{className:"audio-link"},u("a",{href:e,rel:"noopener noreferrer",target:"_blank"},t),u("span",{className:"play",onClick:o},"♬"),u("audio",{preload:"none",src:e,ref:r}))},Hs=({href:e})=>u("div",{className:"video-player"},u("video",{class:"video",style:{display:"inline-block"},controls:!0,loop:!0,src:e})),Xr=(e,t)=>{let{whiteList:r}=W(V),o=k(()=>(r.has(e)?...r:e,...r).map(s=>_(s,t)),r,e),n=ce(o);return k(()=>Rr(n),n)},Vr=(e,t,r,o)=>{let{delay:n,bubble:s,prefetch:c}=W(V);return B(async({currentTarget:p})=>{!t||(c(e,t),!!await ne(p,n)&&s({project:e,title:t,hash:o,type:r,position:le(p)}))},e,t,o,r,n,c,s)};var kt=je(),Ke=new Map,As=G("ScrapBubble:useProject.ts"),Qr=e=>{lett,r=I();return O(()=>{kt.on(e,r);let o=Ke.get(e);return o?r(o.loading?void 0:o.value):(Ke.set(e,{loading:!0}),r(void 0),(async()=>{try{let n=be.toRequest(e);for await(let,sof Ce(n)){let c=await be.fromResponse(s);Ke.set(e,{loading:!1,value:c}),kt.dispatch(e,c);break}}catch(n){As.error(n),Ke.delete(e)}})()),()=>kt.off(e,r)},e),t};var Fs="default-light","default-dark","default-minimal",Us="paper-light","paper-dark-dark","paper-dark",Yr="blue","purple","green","orange","red",qs="hacker1","hacker2",Jr="winter","spring","summer","automn",Zr="tropical",eo="kyoto","newyork","paris",to="mred","lgreen",Cu="default-light","default-minimal","paper-light",...Yr,...Jr,...Zr,...eo,...to;var Ks=...Fs,...Us,...Yr,...qs,...Jr,...Zr,...eo,...to;function ro(e){return Ks.includes(e)}var oo="default-light",ze=e=>{let t=Qr(e);return k(()=>{if(!t||!t.ok)return oo;let r=t.value.theme;return ro(r)?r:oo},t)};var no=({project:e,title:t,descriptions:r,thumbnail:o,linkTo:n,bubble:s,delay:c,prefetch:p})=>{let l=k(()=>o?[]:we(r.join(` ),{hasTitle:!1}),[o,r]),a=ze(e),i=B(async({currentTarget:d})=>{p(e,t),!!await ne(d,c)&&s({project:e,title:t,linkTo:n,type:"link",position:le(d)})},[e,t,c,n?.project,n?.titleLc]),f=k(()=>n?()=>{et({type:"page",from:{project:n.project??e,title:n.titleLc},to:{project:e,title:t}})}:()=>{},[e,t,n?.project,n?.titleLc]);return u("a",{className:"related-page-card page-link",type:"link","data-theme":a,href:/${e}/${C(t)},rel:e===scrapbox.Project.name?"route":"noopner noreferrer",target:e!==scrapbox.Project.name?"_blank":"",onPointerEnter:i,onClick:f},u("div",{class:"hover"}),u("div",{class:"content"},u("div",{class:"header"},u("div",{class:"title"},t)),o?u("div",{class:"thumbnail"},u("img",{src:o})):u("div",{class:"description"},l.flatMap((d,m)=>d.type==="line"?[u("p",{key:m},d.nodes.map(g=>u(so,{node:g,project:e})))]:[]))))},so=({node:e,project:t})=>{switch(e.type){case"code":return u("code",null,e.text);case"formula":return u(zs,{node:e});case"commandLine":return u("code",null,e.symbol," $",e.text);case"helpfeel":return u("code",null,"? ",e.text);case"quote":case"strong":case"decoration":return u(w,null,e.nodes.map(r=>u(so,{node:r,project:t})));case"icon":case"strongIcon":return u(Ws,{node:e,project:t});case"hashTag":return u(Gs,{node:e});case"link":return u(Xs,{node:e});case"plain":case"blank":return u(w,null,e.text);default:return u(w,null)}},zs=({node:{formula:e}})=>{let{ref:t,error:r,setFormula:o}=xe("");return o(e),u("span",{className:formula ${r?" error":""}},r?u("code",null,e):u("span",{className:"katex-display",ref:t}))},Ws=({node:{pathType:e,path:t},project:r})=>{let[o,n]=e==="relative"?[r,t]:t.match(/\/([\w\-]+)\/(.+)$/)?.slice?.(1)??[r,t];return u("img",{class:"icon",src:/api/pages/${o}/${C(n)}/icon})},Gs=({node:{href:e}})=>u("span",{class:"page-link"},"#",e),Xs=({node:{pathType:e,href:t,content:r}})=>e!=="absolute"?u("span",{class:"page-link"},t):u("span",{class:"link"},r||t);var io=({source:e,linked:t,externalLinked:r,projectsForSort:o,...n})=>{let s=k(()=>[...t.keys(),...r.keys()],[t,r]),c=ce(s),p=k(()=>[...o],[o]),l=k(()=>{let i=(f,d)=>{let m=p.indexOf(f.project),g=p.indexOf(d.project);return m===g?d.updated-f.updated:m<0?1:g<0?-1:m-g};return[...c].sort(i)},[c,p]),a=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 u("ul",{className:"card-bubble",style:a,onClick:n.onClick},l.map(({project:i,titleLc:f,lines:[{text:d}],descriptions:m,image:g})=>{let b=_(i,f),x=t.get(b)??r.get(b);return u("li",{key:b},u(no,{project:i,title:d,linkTo:x,descriptions:m,thumbnail:g??"",...n}))}))};var ao=G("ScrapBubble:Bubble.tsx"),co=({source:e,parentTitles:t,whiteList:r,...o})=>{let n=k(()=>r.has(e.project)?new Set([e.project,...r]):new Set([e.project]),[r,e.project]),[s,c,p]=Vs(e,n,r,t),l=B(()=>o.hide(),[o.hide]),a=ze(p[0]?.project??e.project),i=k(()=>({top:${e.position.top}px,maxWidth:${e.position.maxWidth}px,..."left"in e.position?{left:${e.position.left}px}:{right:${e.position.right}px}}),[e.position]);return u(w,null,p.length>0&&u("div",{className:"text-bubble",style:i,"data-theme":a,onClick:l},u(Qs,null,p[0].project!==scrapbox.Project.name&&u(Ys,{project:p[0].project,title:p[0].lines[0].text})),u(Wr,{lines:p[0].lines,project:p[0].project,title:p[0].lines[0].text,hash:e.hash,linkTo:e.linkTo,whiteList:r,...o})),u(io,{linked:s,externalLinked:c,onClick:l,source:e,projectsForSort:n,...o}))},Vs=(e,t,r,o)=>{let[[n,s,c],p]=I([new Map,new Map,[]]),l=k(()=>{let f=[...t].map(d=>_(d,e.title));return ao.debug("projects",f),f},[t,e.title]),a=ce(l),i=k(()=>o.map(f=>M(f)),[o]);return Ie(()=>{let f=new Map,d=new Map,m=[];for(let g of a){let b={project:g.project,titleLc:g.titleLc};for(let y of g.projectLinked??[]){let{project:E,titleLc:F}=Re(y);i.includes(F)&&r.has(E)||d.has(y)||d.set(y,b)}if(!r.has(g.project))continue;let x={titleLc:g.titleLc};for(let y of g.linked??[]){if(i.includes(y))continue;let E=_(g.project,y);f.has(E)||f.set(E,x)}i.includes(g.titleLc)||!g.exists||m.push(g)}p(Ae(g=>{ao.debug(depth: ${i.length}, bubbled from ${_(e.project,e.title)}, bubbles,,a,"before",g[0],"internal cards,",f,"external cards",d);for(let b of g[0].keys())f.has(b)||g[0].delete(b);for(let[b,x]of f)g[0].set(b,x);for(let b of g[1].keys())d.has(b)||g[1].delete(b);for(let[b,x]of d)g[1].set(b,x);g[2]=m}))},[a,r,i]),[n,s,c]},Qs=({children:e})=>u("div",{className:"status-bar top-right"},e),Ys=({project:e,title:t})=>u("a",{href:/${e}/${C(t)},target:"_blank",rel:"noopener noreferrer"},e);var lo=(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(o){if(!(o instanceof TypeError))throw o;return e}}};var po=e=>{let t=k(()=>lo(e.style,import.meta.url),[e.style]);return u(w,null,t!==""&&(t instanceof URL?u("link",{rel:"stylesheet",href:t.href}):u("style",null,t)))};var uo=*{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(2n+1){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}.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)}.page-link:hover{color:var(--page-link-hover-color, #2d67f5)}.empty-page-link{color:var(--empty-page-link-color, #fd7373)}.empty-page-link:hover{color:var(--empty-page-link-hover-color, #fd7373)}.link{color:var(--page-link-color, #5e8af7);text-decoration:underline}.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{padding:5px 0 5px 5px;font-size:11px;line-height:1.42857;user-select:text;position:absolute;max-height:80vh;overflow-y:auto;background-color:var(--page-bg, #fefefe);color:var(--page-text-color, #4a4a4a);border-radius:4px;--text-bubble-border-color: hsl(221, 15%, 25%);border:1px solid var(--text-bubble-border-color, #f2f2f3);--status-bar-border-color: var(--text-bubble-border-color, #f2f2f3);box-shadow:0 6px 12px #0000002d;z-index:9000}.text-bubble.no-scroll{overflow-y:hidden}.text-bubbledata-theme=default-dark{--text-bubble-border-color: hsl(0, 0%, 39%)}.text-bubbledata-theme=default-minimal{--text-bubble-border-color: hsl(0, 0%, 89%)}.text-bubbledata-theme=paper-light{--text-bubble-border-color: hsl(53, 8%, 58%)}.text-bubbledata-theme=paper-dark-dark{--text-bubble-border-color: hsl(203, 42%, 17%)}.text-bubbledata-theme=blue{--text-bubble-border-color: hsl(227, 68%, 62%)}.text-bubbledata-theme=purple{--text-bubble-border-color: hsl(267, 39%, 60%)}.text-bubbledata-theme=green{--text-bubble-border-color: hsl(136, 29%, 50%)}.text-bubbledata-theme=orange{--text-bubble-border-color: hsl(43, 71%, 51%)}.text-bubbledata-theme=red{--text-bubble-border-color: hsl(4, 58%, 56%)}.text-bubbledata-theme=spring{--text-bubble-border-color: hsl(72, 64%, 57%)}.text-bubbledata-theme=kyoto{--text-bubble-border-color: hsl(331, 21%, 26%)}.text-bubbledata-theme=newyork{--text-bubble-border-color: hsl(176, 29%, 67%)}.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 fo=()=>{let[e,t]=I([]),r=B((s,c)=>t(p=>c?[...p.slice(0,s),c]:[...p.slice(0,s)]),[]),[o,n]=I([{bubble:s=>r(0,s),hide:()=>r(0)}]);return O(()=>{n(([s,...c])=>[s,...e.map((p,l)=>p===c.at(l)?.source?c.at(l):{source:p,parentTitles:[scrapbox.Page.title??"",...e.slice(0,l).map(a=>a.title)],bubble:a=>r(l+1,a),hide:()=>r(l+1)})])},[e]),o};var wt=(e,t,r,o,n)=>{O(()=>(e.addEventListener(t,r,o),()=>e.removeEventListener(t,r,o)),[e,t,o,...n??[]])};var mo=e=>e instanceof HTMLSpanElement&&e.matches(".line-title .text"),We=e=>e instanceof HTMLAnchorElement&&e.classList.contains("page-link");var _t="scrap-bubble",go=te();Y(go,"#editor");var ho=({delay:e,whiteList:t,watchList:r,style:o})=>{let[{bubble:n,hide:s},...c]=fo(),p=B((l,a)=>Hr(a,t.has(l)?t:new Set([l]),r),[t,r]);return wt(go,"pointerenter",async l=>{Y(l.currentTarget,"event.currentTarget");let a=l.target;if(!We(a)&&!mo(a))return;let{project:i=scrapbox.Project.name,title:f,hash:d=""}=We(a)?oe({pathType:"root",href:${new URL(a.href).pathname}${new URL(a.href).hash}`}):{project:scrapbox.Project.name,title:scrapbox.Page.title};if(i==="")return;let m=decodeURIComponent(f??"");p(i,m),!!await ne(a,e)&&n({project:i,title:m,hash:d,position:le(a),type:Js(a)})},{capture:!0},e,t,r),wt(document,"click",l=>{l.target.dataset.userscriptName!==_t&&s()},{capture:!0},s),O(()=>(scrapbox.addListener("page:changed",s),()=>scrapbox.removeListener("page:changed",s)),s),u(w,null,u("link",{rel:"stylesheet",href:"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.12.0/katex.min.css"}),u("style",null,uo),u(po,{style:o}),c.map(l=>u(co,{key:_(l.source.project,l.source.title),...l,whiteList:t,delay:e,prefetch:p})))},Js=e=>We(e)?e.type==="link"?"link":"hashtag":"title";var zd=e=>{let{delay:t=500,whiteList:r=[],watchList:o=Xt().slice(0,100),style:n="",debug:s=!1}=e??{};Or(s);let c=document.createElement("div");c.dataset.userscriptName=_t;let p=te();Y(p,"#editor"),p.append(c);let l=c.attachShadow({mode:"open"});Se(u(ho,{delay:t,whiteList:new Set(scrapbox.Project.name,...r),watchList:new Set(o),style:n}),l)};export{zd as mount};