ScrapBubble
code:mod.js
var Te,h,wt,ho,le,Et,yt,Lt,we={},Tt=[],bo=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|inech|zoo|^ord|itera/i;function q(e,t){for(var r in t)er=tr;return e}function Nt(e){var t=e.parentNode;t&&t.removeChild(e)}function p(e,t,r){var o,n,s,a={};for(s in t)s=="key"?o=ts:s=="ref"?n=ts:as=ts;if(arguments.length>2&&(a.children=arguments.length>3?Te.call(arguments,2):r),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)as===void 0&&(as=e.defaultPropss);return ke(e,a,o,n,null)}function ke(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??++wt};return n==null&&h.vnode!=null&&h.vnode(s),s}function w(e){return e.children}function ve(e,t){this.props=e,this.context=t}function Q(e,t){if(t==null)return e.__?Q(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"?Q(e):null}function Pt(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 Pt(e)}}function Ve(e){(!e.__d&&(e.__d=!0)&&le.push(e)&&!Ee.__r++||yt!==h.debounceRendering)&&((yt=h.debounceRendering)||Et)(Ee)}function Ee(){for(var e;Ee.__r=le.length;)e=le.sort(function(t,r){return t.__v.__b-r.__v.__b}),le=[],e.some(function(t){var r,o,n,s,a,u;t.__d&&(a=(s=(r=t).__v).__e,(u=r.__P)&&(o=[],(n=q({},s)).__v=s.__v+1,Ye(u,s,n,r.__n,u.ownerSVGElement!==void 0,s.__h!=null?a:null,o,a??Q(s),s.__h),Rt(o,s),s.__e!=a&&Pt(s)))})}function St(e,t,r,o,n,s,a,u,i,l){var c,g,d,f,m,y,b,_=o&&o.__k||Tt,I=_.length;for(r.__k=[],c=0;c<t.length;c++)if((f=r.__kc=(f=tc)==null||typeof f=="boolean"?null:typeof f=="string"||typeof f=="number"||typeof f=="bigint"?ke(null,f,null,null,f):Array.isArray(f)?ke(w,{children:f},null,null,null):f.__b>0?ke(f.type,f.props,f.key,null,f.__v):f)!=null){if(f.__=r,f.__b=r.__b+1,(d=_c)===null||d&&f.key==d.key&&f.type===d.type)_c=void 0;else for(g=0;g<I;g++){if((d=_g)&&f.key==d.key&&f.type===d.type){_g=void 0;break}d=null}Ye(e,f,d=d||we,n,s,a,u,i,l),m=f.__e,(g=f.ref)&&d.ref!=g&&(b||(b=[]),d.ref&&b.push(d.ref,null,f),b.push(g,f.__c||m,f)),m!=null?(y==null&&(y=m),typeof f.type=="function"&&f.__k===d.__k?f.__d=i=Ct(f,i,e):i=It(e,f,d,_,m,i),typeof r.type=="function"&&(r.__d=i)):i&&d.__e==i&&i.parentNode!=e&&(i=Q(d))}for(r.__e=y,c=I;c--;)_c!=null&&(typeof r.type=="function"&&_c.__e!=null&&_c.__e==r.__d&&(r.__d=Q(o,c+1)),jt(_c,_c));if(b)for(c=0;c<b.length;c++)Mt(bc,b++c,b++c)}function Ct(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"?Ct(o,t,r):It(r,o,o,n,o.__e,t));return t}function It(e,t,r,o,n,s){var a,u,i;if(t.__d!==void 0)a=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),a=null;else{for(u=s,i=0;(u=u.nextSibling)&&i<o.length;i+=2)if(u==n)break e;e.insertBefore(n,s),a=s}return a!==void 0?a:n.nextSibling}function xo(e,t,r,o,n){var s;for(s in r)s==="children"||s==="key"||s in t||Le(e,s,null,rs,o);for(s in t)n&&typeof ts!="function"||s==="children"||s==="key"||s==="value"||s==="checked"||rs===ts||Le(e,s,ts,rs,o)}function _t(e,t,r){t0==="-"?e.setProperty(t,r):et=r==null?"":typeof r!="number"||bo.test(t)?r:r+"px"}function Le(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||_t(e.style,t,"");if(r)for(t in r)o&&rt===ot||_t(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?vt:kt,s):e.removeEventListener(t,s?vt:kt,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 kt(e){this.le.type+!1(h.event?h.event(e):e)}function vt(e){this.le.type+!0(h.event?h.event(e):e)}function Ye(e,t,r,o,n,s,a,u,i){var l,c,g,d,f,m,y,b,_,I,Y,H=t.type;if(t.constructor!==void 0)return null;r.__h!=null&&(i=r.__h,u=t.__e=r.__e,t.__h=null,s=u),(l=h.__b)&&l(t);try{e:if(typeof H=="function"){if(b=t.props,_=(l=H.contextType)&&ol.__c,I=l?_?_.props.value:l.__:o,r.__c?y=(c=t.__c=r.__c).__=c.__E:("prototype"in H&&H.prototype.render?t.__c=c=new H(b,I):(t.__c=c=new ve(b,I),c.constructor=H,c.render=_o),_&&_.sub(c),c.props=b,c.state||(c.state={}),c.context=I,c.__n=o,g=c.__d=!0,c.__h=[]),c.__s==null&&(c.__s=c.state),H.getDerivedStateFromProps!=null&&(c.__s==c.state&&(c.__s=q({},c.__s)),q(c.__s,H.getDerivedStateFromProps(b,c.__s))),d=c.props,f=c.state,g)H.getDerivedStateFromProps==null&&c.componentWillMount!=null&&c.componentWillMount(),c.componentDidMount!=null&&c.__h.push(c.componentDidMount);else{if(H.getDerivedStateFromProps==null&&b!==d&&c.componentWillReceiveProps!=null&&c.componentWillReceiveProps(b,I),!c.__e&&c.shouldComponentUpdate!=null&&c.shouldComponentUpdate(b,c.__s,I)===!1||t.__v===r.__v){c.props=b,c.state=c.__s,t.__v!==r.__v&&(c.__d=!1),c.__v=t,t.__e=r.__e,t.__k=r.__k,t.__k.forEach(function(_e){_e&&(_e.__=t)}),c.__h.length&&a.push(c);break e}c.componentWillUpdate!=null&&c.componentWillUpdate(b,c.__s,I),c.componentDidUpdate!=null&&c.__h.push(function(){c.componentDidUpdate(d,f,m)})}c.context=I,c.props=b,c.state=c.__s,(l=h.__r)&&l(t),c.__d=!1,c.__v=t,c.__P=e,l=c.render(c.props,c.state,c.context),c.state=c.__s,c.getChildContext!=null&&(o=q(q({},o),c.getChildContext())),g||c.getSnapshotBeforeUpdate==null||(m=c.getSnapshotBeforeUpdate(d,f)),Y=l!=null&&l.type===w&&l.key==null?l.props.children:l,St(e,Array.isArray(Y)?Y:Y,t,r,o,n,s,a,u,i),c.base=t.__e,t.__h=null,c.__h.length&&a.push(c),y&&(c.__E=c.__=null),c.__e=!1}else s==null&&t.__v===r.__v?(t.__k=r.__k,t.__e=r.__e):t.__e=yo(r.__e,t,r,o,n,s,a,i);(l=h.diffed)&&l(t)}catch(_e){t.__v=null,(i||s!=null)&&(t.__e=u,t.__h=!!i,ss.indexOf(u)=null),h.__e(_e,t,r)}}function Rt(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 yo(e,t,r,o,n,s,a,u){var i,l,c,g=r.props,d=t.props,f=t.type,m=0;if(f==="svg"&&(n=!0),s!=null){for(;m<s.length;m++)if((i=sm)&&"setAttribute"in i==!!f&&(f?i.localName===f:i.nodeType===3)){e=i,sm=null;break}}if(e==null){if(f===null)return document.createTextNode(d);e=n?document.createElementNS("http://www.w3.org/2000/svg",f):document.createElement(f,d.is&&d),s=null,u=!1}if(f===null)g===d||u&&e.data===d||(e.data=d);else{if(s=s&&Te.call(e.childNodes),l=(g=r.props||we).dangerouslySetInnerHTML,c=d.dangerouslySetInnerHTML,!u){if(s!=null)for(g={},m=0;m<e.attributes.length;m++)g[e.attributes[m].name]=e.attributes[m].value;(c||l)&&(c&&(l&&c.__html==l.__html||c.__html===e.innerHTML)||(e.innerHTML=c&&c.__html||""))}if(xo(e,d,g,n,u),c)t.__k=[];else if(m=t.props.children,St(e,Array.isArray(m)?m:m,t,r,o,n&&f!=="foreignObject",s,a,s?s0:r.__k&&Q(r,0),u),s!=null)for(m=s.length;m--;)sm!=null&&Nt(sm);u||("value"in d&&(m=d.value)!==void 0&&(m!==g.value||m!==e.value||f==="progress"&&!m)&&Le(e,"value",m,g.value,!1),"checked"in d&&(m=d.checked)!==void 0&&m!==e.checked&&Le(e,"checked",m,g.checked,!1))}return e}function Mt(e,t,r){try{typeof e=="function"?e(t):e.current=t}catch(o){h.__e(o,r)}}function jt(e,t,r){var o,n;if(h.unmount&&h.unmount(e),(o=e.ref)&&(o.current&&o.current!==e.__e||Mt(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&&jt(on,t,typeof e.type!="function");r||e.__e==null||Nt(e.__e),e.__e=e.__d=void 0}function _o(e,t,r){return this.constructor(e,r)}function Ne(e,t,r){var o,n,s;h.__&&h.__(e,t),n=(o=typeof r=="function")?null:r&&r.__k||t.__k,s=[],Ye(t,e=(!o&&r||t).__k=p(w,null,e),n||we,we,t.ownerSVGElement!==void 0,!o&&r?r:n?null:t.firstChild?Te.call(t.childNodes):null,s,!o&&r?r:n?n.__e:t.firstChild,o),Rt(s,e)}function Qe(e,t){var r={__c:t="__cC"+Lt++,__: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(a){this.props.value!==a.value&&n.some(Ve)},this.sub=function(a){n.push(a);var u=a.componentWillUnmount;a.componentWillUnmount=function(){n.splice(n.indexOf(a),1),u&&u.call(a)}}),o.children}};return r.Provider.__=r.Consumer.contextType=r}Te=Tt.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}},wt=0,ho=function(e){return e!=null&&e.constructor===void 0},ve.prototype.setState=function(e,t){var r;r=this.__s!=null&&this.__s!==this.state?this.__s:this.__s=q({},this.state),typeof e=="function"&&(e=e(q({},r),this.props)),e&&q(r,e),e!=null&&this.__v&&(t&&this.__h.push(t),Ve(this))},ve.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Ve(this))},ve.prototype.render=w,le=[],Et=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Ee.__r=0,Lt=0;var J,M,Bt,pe=0,Je=[],Ot=h.__b,$t=h.__r,Ft=h.diffed,Dt=h.__c,Ht=h.unmount;function ue(e,t){h.__h&&h.__h(M,e,pe||t),pe=0;var r=M.__H||(M.__H={__:[],__h:[]});return e>=r.__.length&&r.__.push({}),r.__e}function R(e){return pe=1,ko(Ut,e)}function ko(e,t,r){var o=ue(J++,2);return o.t=e,o.__c||(o.__=[r?r(t):Ut(void 0,t),function(n){var s=o.t(o.__0,n);o.__0!==s&&(o.__=[s,o.__1],o.__c.setState({}))}],o.__c=M),o.__}function O(e,t){var r=ue(J++,3);!h.__s&&et(r.__H,t)&&(r.__=e,r.__H=t,M.__H.__h.push(r))}function Se(e,t){var r=ue(J++,4);!h.__s&&et(r.__H,t)&&(r.__=e,r.__H=t,M.__h.push(r))}function Z(e){return pe=5,k(function(){return{current:e}},[])}function k(e,t){var r=ue(J++,7);return et(r.__H,t)&&(r.__=e(),r.__H=t,r.__h=e),r.__}function B(e,t){return pe=8,k(function(){return e},t)}function z(e){var t=M.contexte.__c,r=ue(J++,9);return r.c=e,t?(r.__==null&&(r.__=!0,t.sub(M)),t.props.value):e.__}function vo(){var e;for(Je.sort(function(t,r){return t.__v.__b-r.__v.__b});e=Je.pop();)if(e.__P)try{e.__H.__h.forEach(Pe),e.__H.__h.forEach(Ze),e.__H.__h=[]}catch(t){e.__H.__h=[],h.__e(t,e.__v)}}h.__b=function(e){M=null,Ot&&Ot(e)},h.__r=function(e){$t&&$t(e),J=0;var t=(M=e.__c).__H;t&&(t.__h.forEach(Pe),t.__h.forEach(Ze),t.__h=[])},h.diffed=function(e){Ft&&Ft(e);var t=e.__c;t&&t.__H&&t.__H.__h.length&&(Je.push(t)!==1&&Bt===h.requestAnimationFrame||((Bt=h.requestAnimationFrame)||function(r){var o,n=function(){clearTimeout(s),At&&cancelAnimationFrame(o),setTimeout(r)},s=setTimeout(n,100);At&&(o=requestAnimationFrame(n))})(vo)),M=null},h.__c=function(e,t){t.some(function(r){try{r.__h.forEach(Pe),r.__h=r.__h.filter(function(o){return!o.__||Ze(o)})}catch(o){t.some(function(n){n.__h&&(n.__h=[])}),t=[],h.__e(o,r.__v)}}),Dt&&Dt(e,t)},h.unmount=function(e){Ht&&Ht(e);var t,r=e.__c;r&&r.__H&&(r.__H.__.forEach(function(o){try{Pe(o)}catch(n){t=n}}),t&&h.__e(t,r.__v))};var At=typeof requestAnimationFrame=="function";function Pe(e){var t=M,r=e.__c;typeof r=="function"&&(e.__c=void 0,r()),M=t}function Ze(e){var t=M;e.__c=e.__(),M=t}function et(e,t){return!e||e.length!==t.length||t.some(function(r,o){return r!==eo})}function Ut(e,t){return typeof t=="function"?t(e):t}var v=e=>{let{fetch:t=globalThis.fetch,hostName:r="scrapbox.io",...o}=e;return{fetch:t,hostName:r,...o}};var Eo=e=>typeof e=="object"&&e!==null,Lo=e=>Eo(e)?(e.name===void 0||typeof e.name=="string")&&typeof e.message=="string":!1,qt=e=>{try{let t=typeof e=="string"?JSON.parse(e):e;return Lo(t)?t:!1}catch(t){if(t instanceof SyntaxError)return!1;throw t}};var de=class e extends Error{constructor(r){super(${r.status} ${r.statusText} when fetching ${r.url});this.response=r;Error.captureStackTrace&&Error.captureStackTrace(this,e)}name="UnexpectedResponseError"},T=async e=>{let t=e.clone(),r=await t.text(),o=qt(r);if(!o)throw new de(t);return{ok:!1,value:o}};var L=e=>connect.sid=${e};var j=e=>e.replaceAll(" ","_").toLowerCase();var N=e=>...e.map((t,r)=>t===" "?"_":!To.includes(t)||r===e.length-1&&No.includes(t)?encodeURIComponent(t):t).join(""),To='@$&+=:;",',No=':;",';var zt=(e,t,r)=>{let{sid:o,hostName:n,followRename:s,projects:a}=v(r??{}),u=new URLSearchParams;u.append("followRename",${s??!0});for(let l of a??[])u.append("projects",l);let i=https://${n}/api/pages/${e}/${N(t)}?${u.toString()};return new Request(i,o?{headers:{Cookie:L(o)}}:void 0)},Kt=async e=>e.ok?{ok:!0,value:await e.json()}:e.status===414?{ok:!1,value:{name:"TooLongURIError",message:"project ids may be too much."}}:T(e),ee=async(e,t,r)=>{let{fetch:o}=v(r??{}),n=zt(e,t,r),s=await o(n);return await Kt(s)};ee.toRequest=zt;ee.fromResponse=Kt;var Gt=(e,t)=>{let{sid:r,hostName:o,sort:n,limit:s,skip:a}=v(t??{}),u=new URLSearchParams;n!==void 0&&u.append("sort",n),s!==void 0&&u.append("limit",${s}),a!==void 0&&u.append("skip",${a});let i=https://${o}/api/pages/${e}?${u.toString()};return new Request(i,r?{headers:{Cookie:L(r)}}:void 0)},Wt=async e=>e.ok?{ok:!0,value:await e.json()}:T(e),Xt=async(e,t)=>{let{fetch:r}=v(t??{}),o=await r(Gt(e,t));return await Wt(o)};Xt.toRequest=Gt;Xt.fromResponse=Wt;var Vt=(e,t,r,o)=>{let{sid:n,hostName:s}=v(o??{}),a=https://${s}/api/table/${e}/${N(t)}/${encodeURIComponent(r)}.csv;return new Request(a,n?{headers:{Cookie:L(n)}}:void 0)},Yt=async e=>e.ok?{ok:!0,value:await e.text()}:e.status===404?{ok:!1,value:{name:"NotFoundError",message:"Table not found."}}:T(e),Qt=async(e,t,r,o)=>{let{fetch:n}=v(o??{}),s=Vt(e,t,r,o),a=await n(s);return await Yt(a)};Qt.toRequest=Vt;Qt.fromResponse=Yt;var Jt=(e,t)=>{let{sid:r,hostName:o}=v(t??{});return new Request(https://${o}/api/projects/${e},r?{headers:{Cookie:L(r)}}:void 0)},Zt=async e=>e.ok?{ok:!0,value:await e.json()}:T(e),fe=async(e,t)=>{let{fetch:r}=v(t??{}),o=Jt(e,t),n=await r(o);return Zt(n)};fe.toRequest=Jt;fe.fromResponse=Zt;var er=(e,t)=>{let{sid:r,hostName:o}=v(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:L(r)}}:void 0)},tr=async e=>e.ok?{ok:!0,value:await e.json()}:T(e),Ce=async(e,t)=>{let{fetch:r}=v(t??{}),o=await r(er(e,t));return tr(o)};Ce.toRequest=er;Ce.fromResponse=tr;var rr=(e,t,r,o)=>{let{sid:n,hostName:s}=v(o??{}),a=https://${s}/api/code/${e}/${N(t)}/${N(r)};return new Request(a,n?{headers:{Cookie:L(n)}}:void 0)},or=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"}}:T(e),nr=async(e,t,r,o)=>{let{fetch:n}=v(o??{}),s=rr(e,t,r,o),a=await n(s);return await or(a)};nr.toRequest=rr;nr.fromResponse=or;var rc=new TextEncoder().encode("0123456789abcdef");var X=e=>new Promise(t=>setTimeout(()=>t(),e));var Co=/https?:\/\/(?:www\.|music\.|)youtube\.com\/watch/,Io=/https?:\/\/youtu\.be\/(a-zA-Z\d_-+)(?:\?(^\s{0,100})|)/,Ro=/https?:\/\/(?:www\.|)youtube\.com\/shorts\/(a-zA-Z\d_-+)(?:\?(^\s+)|)/,Mo=/https?:\/\/(?:www\.|music\.|)youtube\.com\/playlist\?((?:^\s+&|)list=(a-zA-Z\d_-+)(?:&^\s+|))/,sr=e=>{if(Co.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(Io);if(t){let,r,o=t;return{videoId:r,params:new URLSearchParams(o),pathType:"dotbe"}}}{let t=e.match(Ro);if(t){let,r,o=t;return{videoId:r,params:new URLSearchParams(o),pathType:"short"}}}{let t=e.match(Mo);if(t){let,r,o=t;return{listId:o,params:new URLSearchParams(r),pathType:"list"}}}};var jo=/https?:\/\/vimeo\.com\/(0-9+)/i,ir=e=>{let t=e.match(jo);if(t)return t1};var Bo=/https?:\/\/open\.spotify\.com\/(track|artist|playlist|album|episode|show)\/(a-zA-Z\d_-+)(?:\?^\s{0,100}|)/,ar=e=>{let t=e.match(Bo);if(!t)return;let,r,o=t;return{videoId:o,pathType:r}};var Oo=/https?:\/\/anchor\.fm\/a-zA-Z\d_-+\/episodes\/(a-zA-Z\d_-+(?:\/a-zA-Z\d_-+)?)(?:\?^\s{0,100}|)/,cr=e=>{let t=e.match(Oo);if(!t)return;let,r=t;return r};var lr=e=>{let{type:t,pathType:r,content:o,href:n,...s}=e;if(o===""){let a=sr(n);if(a)return{type:"youtube",href:n,...a,...s};let u=ir(n);if(u)return{type:"vimeo",videoId:u,href:n,...s};let i=ar(n);if(i)return{type:"spotify",href:n,...i,...s};let l=cr(n);if(l)return{type:"anchor-fm",videoId:l,href:n,...s};if(Fo(n))return{type:"video",href:n,...s}}return $o(n)?{type:"audio",content:o,href:n,...s}:{type:"absoluteLink",content:o,href:n,...s}},$o=e=>/\.(?:mp3|ogg|wav|aac)$/.test(e),Fo=e=>/\.(?:mp4|webm)$/.test(e);var pr=async()=>{let e=localStorage.getItem("projectsLastAccessed");if(!e)return[];try{let t=JSON.parse(e),r=Object.entries(t).sort((,s,,a)=>a-s).map((s)=>s),o=await Ce([]);if(!o.ok)return r;let n=o.value.projects.map(s=>s.id);return r.filter(s=>!n.includes(s))}catch(t){if(!(t instanceof SyntaxError))throw t;return[]}};var Do;(e=>{})(Do||={});var Ho="0.13.3",ur,dr=async(e=Ho)=>{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,ur??=new Promise((o,n)=>{r.onload=()=>o(window.katex),r.onerror=s=>n(s),document.head.append(r)}),ur};var me=(e,t={})=>{let r=Z(null),o,n=R(e),s,a=R("");return O(()=>{(async()=>{let{render:u}=await dr();if(r.current)try{u(o,r.current,t),a("")}catch(i){if(i instanceof Error&&i.name==="ParseError")a(i.message.slice(19));else throw i}})()},o),{ref:r,error:s,setFormula:n}};var te=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 tt=(e,t)=>t.some(r=>{let o=!e.project;switch(r.type){case"hashTag":return o&&j(r.href)===e.titleLc;case"link":{if(r.pathType=="absolute"||r.pathType==="relative"!==o)return!1;let{project:n,title:s=""}=te({pathType:r.pathType,href:r.href});return o?!n&&j(s)===e.titleLc:n===e.project&&j(s)===e.titleLc}case"quote":case"strong":case"decoration":return tt(e,r.nodes)}});var E=(e,t)=>/${e}/${j(t)},Re=e=>{let t=e.match("/(^/+)/(.+)");if(!t)throw SyntaxError("${e}" cannnot match "/([^/]+)/(.+)");return{project:t1,titleLc:t2}};var re=(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 fr=!1;scrapbox.addListener("lines:changed",()=>fr=!1);scrapbox.addListener("layout:changed",()=>fr=!1);var ot=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_${j(e.to.title)}]=r,localStorage.setItem("pageTransitionContext",JSON.stringify(t))};var gr=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 hr=e=>{let t=[],r=new Set,o=n=>{r.delete(n);let s=t.pop();if(!s)return;let a=s0().finally(()=>o(a)).then(u=>s1(u)).catch(u=>s2(u));r.add(a)};return n=>{if(r.size<e){let s=n().finally(()=>o(s));return r.add(s),s}return new Promise((s,a)=>{t.push(n,s,a)})}};var Xo="0.6.5",yr=ScrapBubble-${Xo},br=await globalThis.caches.open(yr);(async()=>{for(let e of await globalThis.caches.keys())e.startsWith("ScrapBubble-")&&e!==yr&&(await globalThis.caches.delete(e),console.log([ScrapBubble] deleted old cache :"${e}"))})();var xr=hr(3);async function*Me(e,t){let r=((t?.saveFailedResponse?br.match(e):void 0)??gr(e,t)).then(a=>"cache",a);{let a=X(1e3).then(()=>"timeout"),u=await Promise.race(r,a);if(u!=="timeout"){u1&&(yield["cache",u1]);let i=await xr(()=>fetch(e));!i.ok&&t?.saveFailedResponse&&await br.put(e,i.clone()),yield"network",i}}let o=xr(()=>fetch(e)).then(a=>"network",a),n,s=await Promise.race(r,o);if(n==="network"){yieldn,s;return}s&&(yieldn,s),yield await o}var _r=(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)}}};var Tr=Symbol.for("immer-nothing"),kr=Symbol.for("immer-draftable"),x=Symbol.for("immer-state");function D(e,...t){throw new Error([Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf)}var oe=Object.getPrototypeOf;function ne(e){return!!e&&!!ex}function U(e){return e?Nr(e)||Array.isArray(e)||!!ekr||!!e.constructor?.kr||De(e)||He(e):!1}var Vo=Object.prototype.constructor.toString();function Nr(e){if(!e||typeof e!="object")return!1;let t=oe(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)===Vo}function ge(e,t){Fe(e)===0?Reflect.ownKeys(e).forEach(r=>{t(r,er,e)}):e.forEach((r,o)=>t(o,r,e))}function Fe(e){let t=ex;return t?t.type_:Array.isArray(e)?1:De(e)?2:He(e)?3:0}function it(e,t){return Fe(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Pr(e,t,r){let o=Fe(e);o===2?e.set(t,r):o===3?e.add(r):et=r}function Yo(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function De(e){return e instanceof Map}function He(e){return e instanceof Set}function P(e){return e.copy_||e.base_}function at(e,t){if(De(e))return new Map(e);if(He(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let r=Nr(e);if(t===!0||t==="class_only"&&!r){let o=Object.getOwnPropertyDescriptors(e);delete ox;let n=Reflect.ownKeys(o);for(let s=0;s<n.length;s++){let a=ns,u=oa;u.writable===!1&&(u.writable=!0,u.configurable=!0),(u.get||u.set)&&(oa={configurable:!0,writable:!0,enumerable:u.enumerable,value:ea})}return Object.create(oe(e),o)}else{let o=oe(e);if(o!==null&&r)return{...e};let n=Object.create(o);return Object.assign(n,e)}}function ut(e,t=!1){return Ae(e)||ne(e)||!U(e)||(Fe(e)>1&&(e.set=e.add=e.clear=e.delete=Qo),Object.freeze(e),t&&Object.entries(e).forEach((r,o)=>ut(o,!0))),e}function Qo(){D(2)}function Ae(e){return Object.isFrozen(e)}var ct={};function V(e){let t=cte;return t||D(0,e),t}function Jo(e,t){cte||(cte=t)}var he;function Be(){return he}function Zo(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function vr(e,t){t&&(V("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function lt(e){pt(e),e.drafts_.forEach(en),e.drafts_=null}function pt(e){e===he&&(he=e.parent_)}function wr(e){return he=Zo(he,e)}function en(e){let t=ex;t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Er(e,t){t.unfinalizedDrafts_=t.drafts_.length;let r=t.drafts_0;return e!==void 0&&e!==r?(rx.modified_&&(lt(t),D(4)),U(e)&&(e=Oe(t,e),t.parent_||$e(t,e)),t.patches_&&V("Patches").generateReplacementPatches_(rx.base_,e,t.patches_,t.inversePatches_)):e=Oe(t,r,[]),lt(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Tr?e:void 0}function Oe(e,t,r){if(Ae(t))return t;let o=tx;if(!o)return ge(t,(n,s)=>Lr(e,o,t,n,s,r)),t;if(o.scope_!==e)return t;if(!o.modified_)return $e(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;let n=o.copy_,s=n,a=!1;o.type_===3&&(s=new Set(n),n.clear(),a=!0),ge(s, (u,i)=>Lr(e,o,n,u,i,r,a)),$e(e,n,!1),r&&e.patches_&&V("Patches").generatePatches_(o,r,e.patches_,e.inversePatches_)}return o.copy_}function Lr(e,t,r,o,n,s,a){if(ne(n)){let u=s&&t&&t.type_!==3&&!it(t.assigned_,o)?s.concat(o):void 0,i=Oe(e,n,u);if(Pr(r,o,i),ne(i))e.canAutoFreeze_=!1;else return}else a&&r.add(n);if(U(n)&&!Ae(n)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;Oe(e,n),(!t||!t.scope_.parent_)&&typeof o!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,o)&&$e(e,n)}}function $e(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&ut(t,r)}function tn(e,t){let r=Array.isArray(e),o={type_:r?1:0,scope_:t?t.scope_:Be(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},n=o,s=dt;r&&(n=o,s=be);let{revoke:a,proxy:u}=Proxy.revocable(n,s);return o.draft_=u,o.revoke_=a,u}var dt={get(e,t){if(t===x)return e;let r=P(e);if(!it(r,t))return rn(e,r,t);let o=rt;return e.finalized_||!U(o)?o:o===nt(e.base_,t)?(st(e),e.copy_t=xe(o,e)):o},has(e,t){return t in P(e)},ownKeys(e){return Reflect.ownKeys(P(e))},set(e,t,r){let o=Sr(P(e),t);if(o?.set)return o.set.call(e.draft_,r),!0;if(!e.modified_){let n=nt(P(e),t),s=n?.x;if(s&&s.base_===r)return e.copy_t=r,e.assigned_t=!1,!0;if(Yo(r,n)&&(r!==void 0||it(e.base_,t)))return!0;st(e),A(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 nt(e.base_,t)!==void 0||t in e.base_?(e.assigned_t=!1,st(e),A(e)):delete e.assigned_t,e.copy_&&delete e.copy_t,!0},getOwnPropertyDescriptor(e,t){let r=P(e),o=Reflect.getOwnPropertyDescriptor(r,t);return o&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:o.enumerable,value:rt}},defineProperty(){D(11)},getPrototypeOf(e){return oe(e.base_)},setPrototypeOf(){D(12)}},be={};ge(dt,(e,t)=>{bee=function(){return arguments0=arguments00,t.apply(this,arguments)}});be.deleteProperty=function(e,t){return be.set.call(this,e,t,void 0)};be.set=function(e,t,r){return dt.set.call(this,e0,t,r,e0)};function nt(e,t){let r=ex;return(r?P(r):e)t}function rn(e,t,r){let o=Sr(t,r);return o?"value"in o?o.value:o.get?.call(e.draft_):void 0}function Sr(e,t){if(!(t in e))return;let r=oe(e);for(;r;){let o=Object.getOwnPropertyDescriptor(r,t);if(o)return o;r=oe(r)}}function A(e){e.modified_||(e.modified_=!0,e.parent_&&A(e.parent_))}function st(e){e.copy_||(e.copy_=at(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var on=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,r,o)=>{if(typeof t=="function"&&typeof r!="function"){let s=r;r=t;let a=this;return function(u=s,...i){return a.produce(u,l=>r.call(this,l,...i))}}typeof r!="function"&&D(6),o!==void 0&&typeof o!="function"&&D(7);let n;if(U(t)){let s=wr(this),a=xe(t,void 0),u=!0;try{n=r(a),u=!1}finally{u?lt(s):pt(s)}return vr(s,o),Er(n,s)}else if(!t||typeof t!="object"){if(n=r(t),n===void 0&&(n=t),n===Tr&&(n=void 0),this.autoFreeze_&&ut(n,!0),o){let s=[],a=[];V("Patches").generateReplacementPatches_(t,n,s,a),o(s,a)}return n}else D(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(s,...a)=>this.produceWithPatches(s,u=>t(u,...a));let o,n;returnthis.produce(t,r,(s,a)=>{o=s,n=a}),o,n},typeof e?.autoFreeze=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){U(e)||D(8),ne(e)&&(e=nn(e));let t=wr(this),r=xe(e,void 0);return rx.isManual_=!0,pt(t),r}finishDraft(e,t){let r=e&&ex;(!r||!r.isManual_)&&D(9);let{scope_:o}=r;return vr(o,t),Er(void 0,o)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){let n=tr;if(n.path.length===0&&n.op==="replace"){e=n.value;break}}r>-1&&(t=t.slice(r+1));let o=V("Patches").applyPatches_;return ne(e)?o(e,t):this.produce(e,n=>o(n,t))}};function xe(e,t){let r=De(e)?V("MapSet").proxyMap_(e,t):He(e)?V("MapSet").proxySet_(e,t):tn(e,t);return(t?t.scope_:Be()).drafts_.push(r),r}function nn(e){return ne(e)||D(10,e),Cr(e)}function Cr(e){if(!U(e)||Ae(e))return e;let t=ex,r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=at(e,t.scope_.immer_.useStrictShallowCopy_)}else r=at(e,!0);return ge(r,(o,n)=>{Pr(r,o,Cr(n))}),t&&(t.finalized_=!1),r}function Ir(){class e extends Map{constructor(i,l){super(),thisx={type_:2,parent_:l,scope_:l?l.scope_:Be(),modified_:!1,finalized_:!1,copy_:void 0,assigned_:void 0,base_:i,draft_:this,isManual_:!1,revoked_:!1}}get size(){return P(thisx).size}has(i){return P(thisx).has(i)}set(i,l){let c=thisx;return a(c),(!P(c).has(i)||P(c).get(i)!==l)&&(r(c),A(c),c.assigned_.set(i,!0),c.copy_.set(i,l),c.assigned_.set(i,!0)),this}delete(i){if(!this.has(i))return!1;let l=thisx;return a(l),r(l),A(l),l.base_.has(i)?l.assigned_.set(i,!1):l.assigned_.delete(i),l.copy_.delete(i),!0}clear(){let i=thisx;a(i),P(i).size&&(r(i),A(i),i.assigned_=new Map,ge(i.base_,l=>{i.assigned_.set(l,!1)}),i.copy_.clear())}forEach(i,l){let c=thisx;P(c).forEach((g,d,f)=>{i.call(l,this.get(d),d,this)})}get(i){let l=thisx;a(l);let c=P(l).get(i);if(l.finalized_||!U(c)||c!==l.base_.get(i))return c;let g=xe(c,l);return r(l),l.copy_.set(i,g),g}keys(){return P(thisx).keys()}values(){let i=this.keys();return{Symbol.iterator:()=>this.values(),next:()=>{let l=i.next();return l.done?l:{done:!1,value:this.get(l.value)}}}}entries(){let i=this.keys();return{Symbol.iterator:()=>this.entries(),next:()=>{let l=i.next();if(l.done)return l;let c=this.get(l.value);return{done:!1,value:l.value,c}}}}Symbol.iterator(){return this.entries()}}function t(u,i){return new e(u,i)}function r(u){u.copy_||(u.assigned_=new Map,u.copy_=new Map(u.base_))}class o extends Set{constructor(i,l){super(),thisx={type_:3,parent_:l,scope_:l?l.scope_:Be(),modified_:!1,finalized_:!1,copy_:void 0,base_:i,draft_:this,drafts_:new Map,revoked_:!1,isManual_:!1}}get size(){return P(thisx).size}has(i){let l=thisx;return a(l),l.copy_?!!(l.copy_.has(i)||l.drafts_.has(i)&&l.copy_.has(l.drafts_.get(i))):l.base_.has(i)}add(i){let l=thisx;return a(l),this.has(i)||(s(l),A(l),l.copy_.add(i)),this}delete(i){if(!this.has(i))return!1;let l=thisx;return a(l),s(l),A(l),l.copy_.delete(i)||(l.drafts_.has(i)?l.copy_.delete(l.drafts_.get(i)):!1)}clear(){let i=thisx;a(i),P(i).size&&(s(i),A(i),i.copy_.clear())}values(){let i=thisx;return a(i),s(i),i.copy_.values()}entries(){let i=thisx;return a(i),s(i),i.copy_.entries()}keys(){return this.values()}Symbol.iterator(){return this.values()}forEach(i,l){let c=this.values(),g=c.next();for(;!g.done;)i.call(l,g.value,g.value,this),g=c.next()}}function n(u,i){return new o(u,i)}function s(u){u.copy_||(u.copy_=new Set,u.base_.forEach(i=>{if(U(i)){let l=xe(i,u);u.drafts_.set(i,l),u.copy_.add(l)}else u.copy_.add(i)}))}function a(u){u.revoked_&&D(3,JSON.stringify(P(u)))}Jo("MapSet",{proxyMap_:t,proxySet_:n})}var $=new on,Ue=$.produce,uu=$.produceWithPatches.bind($),du=$.setAutoFreeze.bind($),fu=$.setUseStrictShallowCopy.bind($),mu=$.applyPatches.bind($),gu=$.createDraft.bind($),hu=$.finishDraft.bind($);Ir();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},Mr=(e,t)=>Ue(e,r=>{if(!r)return t;if(r.updated<t.updated){let{lines:o,linked:n,projectLinked:s,...a}=t;Object.assign(r,a),ft(t)||(r.lines=o),n&&(r.linked??=n),s&&(r.projectLinked??=s);return}ft(r)&&!ft(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)}),ft=e=>e.lines0.id==="dummy";var jr=(e,t)=>{let r=new Map,o=j(t.title);for(let i of t.links){let l=sn(e,i);l.linked=o,r.set(E(e,i),l)}let n=E(e,o),s=t.projectLinks.map(i=>{let l=Re(i);return E(l.project,l.titleLc)}),a={...qe(e,t),linked:[],projectLinked:[]};r.set(n,a);let u=t.links.map(i=>j(i));for(let i of t.relatedPages.links1hop){i.linksLc.includes(o)&&a.linked.push(i.titleLc);for(let d of i.linksLc.filter(f=>u.includes(f))){let f=E(e,d),m=r.get(f);if(!m)throw Error(storage already must have "${f}");if(!m.linked){m.linked=i.titleLc;continue}m.linked.push(i.titleLc)}let l=E(e,i.titleLc),c=qe(e,i),g=r.get(l)?.linked;g&&(c.linked=g),r.set(l,c)}for(let i of t.relatedPages.projectLinks1hop){let l=E(i.projectName,i.titleLc);s.includes(l)||a.projectLinked.push(l);let c=qe(i.projectName,i),g=r.get(l)?.projectLinked;g&&(c.projectLinked=g),r.set(l,c)}a.isLinkedCorrect=!0;for(let i of t.relatedPages.links2hop){for(let d of i.linksLc){let f=E(e,d),m=r.get(f);if(!m)throw Error(storage already must have "${f}");if(!m.linked){m.linked=i.titleLc;continue}m.linked.push(i.titleLc)}let l=E(e,i.titleLc),c=qe(e,i),g=r.get(l)?.linked;g&&(c.linked=g),r.set(l,c)}return r},qe=(e,t)=>({project:e,titleLc:"titleLc"in t?t.titleLc:j(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}),sn=(e,t)=>({project:e,titleLc:j(t),exists:!1,descriptions:[],image:null,lines:{text:t,id:"dummy",userId:"dummy",updated:0,created:0},updated:0,isLinkedCorrect:!1});var F=!1,Br=e=>{F=typeof e=="boolean"?e:new Set(e)},K=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)=>{F!==!0&&(!F||!F.has(e))||r(%c${e},"color: gray",...o)}];case"assert":return[t,(o,...n)=>{F!==!0&&(!F||!F.has(e))||r(o,%c${e},"color: gray",...n)}];case"time":case"timeEnd":return[t,o=>{F!==!0&&(!F||!F.has(e))||r(${e} ${o})}];default:returnt,(...o)=>{if(!(F!==!0&&(!F||!F.has(e))))return r(...o)}}}));var ze=K("ScrapBubble:bubble.ts"),mt=new Map,Ke=new Set,gt=je();function*$r(e){for(let t of e)yield mt.get(t)}var Fr=(e,t)=>gt.on(e,t),Dr=(e,t)=>gt.off(e,t),Hr=async(e,t,r,o)=>{let n=[];for(let s of...t.reverse()){let a=E(s,e);Ke.has(a)||n.push(an(s,e,r,o))}await Promise.all(n)},Or=0,an=async(e,t,r,o)=>{let n=E(e,t);if(Ke.has(n))return;Ke.add(n);let s=Or++,a=[${s}] Check update ${n};ze.time(a);try{let u=ee.toRequest(e,t,{followRename:!0,projects:...r});for await(leti,lof Me(u,{ignoreSearch:!0,saveFailedResponse:!0})){ze.debug([${s}]${i} ${n});let c=await ee.fromResponse(l);if(c.ok){let g=jr(e,c.value);for(letd,fof g){let m=mt.get(d),y=Mr(m,f);y&&m!==y&&(mt.set(d,y),gt.dispatch(d,f))}}if(o?.ignoreFetch===!0||i==="cache"&&!_r(l,o?.maxAge??60))break}}catch(u){ze.error(u)}finally{Ke.delete(n),ze.timeEnd(a),Or--}};var Ar=K("ScrapBubble:useBubbleData.ts"),se=e=>{lett,r=R([]);return Se(()=>{let o=()=>{r(()=>{let a=...$r(e).flatMap(u=>u?u:[]);return Ar.debug(Required: ${e.length} pages, ${a.length} found,a),a})};o();let n,s=()=>{clearTimeout(n),n=setTimeout(()=>{Ar.debug(Update ${e.length} pages),o()},10)};return e.forEach(a=>Fr(a,s)),()=>e.forEach(a=>Dr(a,s))},e),t};var ie=e=>{let{top:t,right:r,left:o,bottom:n}=e.getBoundingClientRect(),s=document.body.getBoundingClientRect(),a=(o-s.left)/s.width>.5;return{top:Math.round(n-s.top),bottom:Math.round(globalThis.innerHeight-globalThis.scrollY-t),...a?{right:Math.round(s.right-r)}:{left:Math.round(o-s.left)},maxWidth:a?r-10:document.documentElement.clientWidth-o-10}};var cn=e=>({type:"title",text:e.rows0.text}),ln=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(a=>a.text.substring(o+1)).join(` )}},S=(e,{parseOnNested:t,parseOnQuoted:r,patterns:o})=>(n,s,a)=>{var u,i,l,c,g,d;if(!t&&s.nested)return(u=a?.())!==null&&u!==void 0?u:[];if(!r&&s.quoted)return(i=a?.())!==null&&i!==void 0?i:[];for(let f of o){let m=f.exec(n);if(m===null)continue;let y=n.substring(0,m.index),b=n.substring(m.index+((c=(l=m[0])===null||l===void 0?void 0:l.length)!==null&&c!==void 0?c:0)),_=e((g=m[0])!==null&&g!==void 0?g:"",s);return[...G(y,s),..._,...G(b,s)]}return(d=a?.())!==null&&d!==void 0?d:[]},C=e=>[{type:"plain",raw:e,text:e}],pn=S(C,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]}),un=/^>.*$/,dn=(e,t)=>t.context==="table"?C(e,t):[{type:"quote",raw:e,nodes:G(e.substring(1),{...t,quoted:!0})}],fn=S(dn,{parseOnNested:!1,parseOnQuoted:!1,patterns:[un]}),mn=/^\? .+$/,gn=(e,t)=>t.context==="table"?C(e,t):[{type:"helpfeel",raw:e,text:e.substring(2)}],hn=S(gn,{parseOnNested:!1,parseOnQuoted:!1,patterns:[mn]}),bn=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,xn=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,yn=(e,t)=>{if(t.context==="table")return C(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}]},_n=S(yn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[bn,xn]}),kn=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;function qr(e){return(t,r)=>{if(e==="strongIcon"&&r.context==="table")return C(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),a=s.startsWith("/")?"root":"relative",u=o.substring(n+5,o.length),i=u.startsWith("*")?parseInt(u.substring(1),10):1;return new Array(i).fill({}).map(()=>({path:s,pathType:a,type:e,raw:t}))}}var vn=qr("icon"),wn=S(vn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[kn]}),En=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,Ln=qr("strongIcon"),Tn=S(Ln,{parseOnNested:!1,parseOnQuoted:!0,patterns:[En]}),Nn=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,Pn=(e,t)=>t.context==="table"?C(e,t):[{type:"strong",raw:e,nodes:G(e.substring(2,e.length-2),{...t,nested:!0})}],Sn=S(Pn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Nn]}),Cn=/\[\$ .+? \]/,In=/\[\$ [^\]]+\]/,Rn=(e,t)=>t.context==="table"?C(e,t):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],Mn=S(Rn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[Cn,In]}),jn=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,Bn=(e,t)=>{if(t.context==="table")return C(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 a=o.split("*").length-1;s.delete("*"),s.add(*-${Math.min(a,10)})}return[{type:"decoration",raw:e,rawDecos:o,decos:Array.from(s),nodes:G(n,{...t,nested:!0})}]},On=S(Bn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[jn]}),$n=/.*?/,Fn=(e,t)=>t.context==="table"?C(e,t):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],Dn=S(Fn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[$n]}),Hn=/^[$%] .+$/,An=(e,t)=>{var r;if(t.context==="table")return C(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}]},Un=S(An,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Hn]}),qn=/\[\s+\]/,zn=(e,t)=>t.context==="table"?C(e,t):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],Kn=S(zn,{parseOnNested:!1,parseOnQuoted:!0,patterns:[qn]}),Gn=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,Wn=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,Xn=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,Vn=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,Yn=e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(e)||Qn(e),Qn=e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),Jn=(e,t)=>{if(t.context==="table")return C(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,a]=Yn(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:a}]},Zn=S(Jn,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Gn,Wn,Xn,Vn]}),es=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,ts=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,rs=/\[https?:\/\/[^\s\]]+\]/,os=/https?:\/\/[^\s]+/,ns=(e,t)=>{if(t.context==="table")return C(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()}]},ss=S(ns,{parseOnNested:!0,parseOnQuoted:!0,patterns:[es,ts,rs,os]}),zr=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,Kr=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,is=e=>{let[t="",r="",o=""]=e.split(","),n=parseFloat(t.replace(/^N/,"").replace(/^S/,"-")),s=parseFloat(r.replace(/^E/,"").replace(/^W/,"-")),a=/^Z\d+$/.test(o)?parseInt(o.replace(/^Z/,""),10):14;return{latitude:n,longitude:s,zoom:a}},as=(e,t)=>{var r;if(t.context==="table")return C(e,t);let o=(r=e.match(zr))!==null&&r!==void 0?r:e.match(Kr);if(o===null)return[];let n=e.startsWith("[N")||e.startsWith("[S"),[,s="",a=""]=n?o:[o[0],o[2],o[1]],{latitude:u,longitude:i,zoom:l}=is(s),c=a!==""?https://www.google.com/maps/place/${encodeURIComponent(a)}/@${u},${i},${l}z:https://www.google.com/maps/@${u},${i},${l}z;return[{type:"googleMap",raw:e,latitude:u,longitude:i,zoom:l,place:a,url:c}]},cs=S(as,{parseOnNested:!1,parseOnQuoted:!0,patterns:[zr,Kr]}),ls=/\[\/?[^[\]]+\]/,ps=e=>{let t=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:t.startsWith("/")?"root":"relative",href:t,content:""}]},us=S(ps,{parseOnNested:!0,parseOnQuoted:!0,patterns:[ls]}),ds=/(?:^|\s)#\S+/,fs=(e,t)=>{if(t.context==="table")return C(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[...C(r,t),{type:"hashTag",raw:o,href:o.substring(1)}]},ms=S(fs,{parseOnNested:!0,parseOnQuoted:!0,patterns:[ds]}),gs=/^[0-9]+\. .*$/,hs=(e,t)=>{if(t.context==="table")return C(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:G(s,{...t,nested:!0})}]},bs=S(hs,{parseOnNested:!1,parseOnQuoted:!1,patterns:[gs]}),xs=(e,t,r)=>{var o;return e===""?[]:(o=r?.())!==null&&o!==void 0?o:[]},ys=(...e)=>(t,r)=>e.reduceRight((o,n)=>()=>n(t,r,o),()=>pn(t,r))(),G=ys(xs,fn,hn,Dn,Un,Mn,Kn,On,_n,Tn,Sn,Zn,ss,wn,cs,us,ms,bs),_s=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(a=>a.text.substring(o+1)).map(a=>a.split(" ").map(u=>G(u,{nested:!1,quoted:!1,context:"table"})))}},ks=e=>{let{indent:t,text:r}=e.rows[0];return{indent:t,type:"line",nodes:G(r.substring(t),{nested:!1,quoted:!1,context:"line"})}},vs=e=>{switch(e.type){case"title":return cn(e);case"codeBlock":return ln(e);case"table":return _s(e);case"line":return ks(e)}},ws=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}}),Es=(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)},Ur=(e,t)=>{let r=e[e.length-1];return r!==void 0&&Es(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)},Ls=(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(Ur,[])]}return e.reduce(Ur,[])},ye=(e,t)=>{var r;let o=ws(e);return Ls(o,{hasTitle:(r=t?.hasTitle)!==null&&r!==void 0?r:!0}).map(vs)};var W=Qe({title:"",project:"",whiteList:new Set,bubble:()=>{},hide:()=>{},delay:0,prefetch:()=>{}}),Wr=({lines:e,project:t,title:r,whiteList:o,noIndent:n,hash:s,linkTo:a,...u})=>{let i=k(()=>e.flatMap(d=>typeof d=="string"?[]:[d.id]),[e]),l=k(()=>{let d=0;return ye(e.map(f=>typeof f=="string"?f:f.text).join(
),{hasTitle:!0}).map(f=>{switch(f.type){case"title":case"line":return{...f,id:i[d++]};case"codeBlock":{let m=d;return d+=f.content.split(
).length+1,{...f,ids:i.slice(m,d)}}case"table":{let m=d;return d+=f.cells.length+1,{...f,ids:i.slice(m,d)}}}})},[e,i]),c=k(()=>{if(s&&i.includes(s))return s;if(a)return l.find(d=>d.type!=="line"?!1:tt(a,d.nodes))?.id},[l,i,s,a?.project,a?.titleLc]),g=Z(null);return O(()=>{if(!c)return;let d=g.current?.querySelector(data-id="${c}"),f=globalThis.scrollY;d?.scrollIntoView?.({block:"center"}),globalThis.scroll(0,f)},[c]),p("div",{className:"lines",ref:g},p(W.Provider,{value:{project:t,title:r,whiteList:o,...u}},l.map(d=>{switch(d.type){case"title":return p(w,null,p(ce,{key:d.id,index:d.id,indent:0,noIndent:n,permalink:d.id===c},d.text),p("hr",null));case"codeBlock":return p(Ts,{key:d.ids[0],block:d,noIndent:n,ids:d.ids,scrollId:c});case"table":return p(Ns,{key:d.ids[0],block:d,noIndent:n,ids:d.ids,scrollId:c});case"line":return p(ce,{key:d.id,index:d.id,indent:d.indent,noIndent:n,permalink:d.id===c},d.nodes.length>0?d.nodes.map(f=>p(ae,{node:f})):p("br",null))}})))},ce=({index:e,indent:t,noIndent:r,children:o,permalink:n})=>p("div",{className:line${n?" permalink":""},"data-id":e,"data-indent":t,style:{"margin-left":r?"":${1*t}em}},o),Ts=({block:{fileName:e,content:t,indent:r},ids:o,scrollId:n})=>{let{project:s,title:a}=z(W),[u,i]=R("��"),l=B(async c=>{c.preventDefault(),c.stopPropagation();try{await navigator.clipboard.writeText(t),i("Copied"),await X(1e3),i("��")}catch(g){alert(Failed to copy the code block Error:${g.message})}},[t]);return p(w,null,p(ce,{index:o[0],indent:r,permalink:o[0]===n},p("span",{className:"code-block"},p("span",{className:"code-block-start"},p("a",{href:/api/code/${s}/${N(a)}/${e},target:"_blank"},e)),p("span",{className:"copy",title:"Copy",onClick:l},u))),p(w,null,t.split(
).map((c,g)=>p(ce,{index:o[g+1],indent:r,permalink:o[g+1]===n},p("code",{className:"code-block"},c)))))},Ns=({block:{fileName:e,cells:t,indent:r},ids:o,scrollId:n})=>{let{project:s,title:a}=z(W);return p(w,null,p(ce,{index:o[0],indent:r,permalink:o[0]===n},p("span",{className:"table-block"},p("span",{className:"table-block-start"},p("a",{href:/api/table/${s}/${N(a)}/${e}.csv,target:"_blank"},e)))),p(w,null,t.map((u,i)=>p(ce,{index:o[i+1],indent:r,permalink:o[i+1]===n},p("span",{className:"table-block table-block-row"},u.map((l,c)=>p("span",{className:cell col-${c}},l.map(g=>p(ae,{node:g})))))))))},ae=({node:e})=>{switch(e.type){case"code":return p("code",{className:"code"},e.text);case"formula":return p(Ps,{node:e});case"commandLine":return p(Cs,{node:e});case"helpfeel":return p("code",{className:"helpfeel"},p("span",{className:"prefix"},"?")," ",p("span",{className:"entry"},e.text));case"quote":return p("blockquote",{className:"quote"},e.nodes.map(t=>p(ae,{node:t})));case"strong":return p("strong",null,e.nodes.map(t=>p(ae,{node:t})));case"decoration":return p(Ss,{node:e});case"plain":case"blank":return p(w,null,e.text);case"hashTag":return p(Ms,{node:e});case"link":return p(js,{node:e});case"googleMap":return p(Is,{node:e});case"icon":return p(Gr,{node:e});case"strongIcon":return p(Gr,{node:e,strong:!0});case"image":return p(Rs,{node:e});case"strongImage":return p("img",{className:"image strong-image",src:e.src});case"numberList":return p(w,null,${e.number}. ,e.nodes.map(t=>p(ae,{node:t})))}},Ps=({node:{formula:e}})=>{let{ref:t,error:r,setFormula:o}=me("");return o(e),p("span",{className:formula ${r?" error":""}},r?p("code",null,e):p("span",{className:"katex-display",ref:t}))},Ss=({node:{decos:e,nodes:t}})=>p("span",{className:e.map(r=>deco-${r}).join(" ")},t.map(r=>p(ae,{node:r}))),Cs=({node:e})=>{let[t,r]=R("��"),o=B(async n=>{n.preventDefault(),n.stopPropagation();try{await navigator.clipboard.writeText(e.text),r("Copied"),await X(1e3),r("��")}catch(s){alert(Failed to copy the code block
Error:${s.message})}},[e.text]);return p(w,null,p("code",{className:"cli"},p("span",{className:"prefix"},e.symbol)," ",p("span",{className:"command"},e.text)),p("span",{className:"tool-buttons"},p("span",{title:"Copy",className:"copy",onClick:o},t)))},Is=({node:{place:e,latitude:t,longitude:r,zoom:o}})=>p("span",{className:"pointing-device-map"},p("a",{href:https://www.google.com/maps/search/${e}/@${t},${r},${o}z,rel:"noopner noreferrer",target:"_blank"},p("img",{className:"google-map",src:/api/google-map/static-map?center=${t}%2C${r}&markers=${e}&zoom=${o}&_csrf=${globalThis._csrf}}))),Gr=({node:{pathType:e,path:t},strong:r})=>{let{project:o}=z(W),[n,s]=e==="relative"?[o,t]:t.match(/\/([\w\-]+)\/(.+)$/)?.slice?.(1)??[o,t],a=N(s);return p("a",{href:/${n}/${a},rel:n===scrapbox.Project.name?"route":"noopener noreferrer",target:n===scrapbox.Project.name?"":"_blank"},p("img",{className:r?"icon strong-icon":"icon",alt:s,src:/api/pages/${n}/${a}/icon},s))},Rs=({node:{link:e,src:t}})=>{let r=e||(/https:\/\/gyazo\.com\/[^\/]+\/thumb\/1000/.test(t)?t.slice(0,-11):t);return p("a",{className:e?"link":"",href:r,rel:"noopner noreferrer",target:"_blank"},p("img",{className:"image",src:t}))},Ms=({node:{href:e}})=>{let{project:t}=z(W),r=Xr(t,e),o=Vr(t,e,"hashtag");return p("a",{href:/${t}/${N(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)},js=({node:{pathType:e,...t}})=>{switch(e){case"relative":case"root":return p(Bs,{pathType:e,href:t.href});case"absolute":{let r=lr({pathType:e,...t});switch(r.type){case"youtube":return p(Os,{...r});case"vimeo":return p($s,{...r});case"spotify":return p(Fs,{...r});case"anchor-fm":return p(Ds,{...r});case"audio":return p(Hs,{...r});case"video":return p(Us,{...r});case"absoluteLink":return p("a",{className:"link",href:r.href,rel:"noopener noreferrer",target:"_blank"},r.content||r.href)}}}},Bs=({pathType:e,href:t})=>{let{project:r}=z(W),{project:o=r,title:n,hash:s=""}=te({pathType:e,href:t}),a=Vr(o,n,"link",s),u=Xr(o,n??"");return p("a",{className:page-link${n!==void 0&&u?" empty-page-link":""},type:"link",href:/${o}${n===void 0?"":/${N(n)}${s===""?"":#${s}}},rel:o===scrapbox.Project.name?"route":"noopener noreferrer",target:o===scrapbox.Project.name?"":"_blank",onPointerEnter:a},t)},Os=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 p("div",{className:"iframe-video-player"},p("iframe",{src:t,allowFullScreen:!0,type:"text/html"}))},$s=({videoId:e})=>p("div",{className:"iframe-video-player"},p("iframe",{src:https://player.vimeo.com/video/${e},allowFullScreen:!0,type:"text/html"})),Fs=e=>p("div",{className:"iframe-video-player"},p("iframe",{className:spotify type-${e.pathType},src:https://open.spotify.com/embed/${e.pathType}/${e.videoId},allowFullScreen:!0,type:"text/html",scrolling:"no"})),Ds=e=>p("div",{className:"iframe-video-player"},p("iframe",{className:"anchor-fm",src:e.href.replace("/episodes/","/embed/episodes/"),allowFullScreen:!0,type:"text/html",scrolling:"no"})),Hs=e=>e.content===""?p("audio",{className:"audio-player",preload:"none",controls:!0,src:e.href}):p(As,{...e}),As=({href:e,content:t})=>{let r=Z(null),o=B(()=>{r.current?.paused?(r.current.currentTime=0,r.current.play()):r.current?.pause?.()},[]);return p("span",{className:"audio-link"},p("a",{href:e,rel:"noopener noreferrer",target:"_blank"},t),p("span",{className:"play",onClick:o},"笙ャ"),p("audio",{preload:"none",src:e,ref:r}))},Us=({href:e})=>p("div",{className:"video-player"},p("video",{class:"video",style:{display:"inline-block"},controls:!0,loop:!0,src:e})),Xr=(e,t)=>{let{whiteList:r}=z(W),o=k(()=>(r.has(e)?[...r]:[e,...r]).map(s=>E(s,t)),[r,e]),n=se(o);return k(()=>Rr(n),n)},Vr=(e,t,r,o)=>{let{delay:n,bubble:s,prefetch:a}=z(W);return B(async({currentTarget:u})=>{t&&(a(e,t),await re(u,n)&&s({project:e,title:t,hash:o,type:r,position:ie(u)}))},[e,t,o,r,n,a,s])};var ht=je(),Ge=new Map,qs=K("ScrapBubble:useProject.ts"),Yr=e=>{let[t,r]=R();return O(()=>{ht.on(e,r);let o=Ge.get(e);return o?r(o.loading?void 0:o.value):(Ge.set(e,{loading:!0}),r(void 0),(async()=>{try{let n=fe.toRequest(e);for await(let[,s]of Me(n)){let a=await fe.fromResponse(s);Ge.set(e,{loading:!1,value:a}),ht.dispatch(e,a);break}}catch(n){qs.error(n),Ge.delete(e)}})()),()=>ht.off(e,r)},[e]),t};var zs=["default-light","default-dark","default-minimal"],Ks=["paper-light","paper-dark-dark","paper-dark"],Qr=["blue","purple","green","orange","red"],Gs=["hacker1","hacker2"],Jr=["winter","spring","summer","automn"],Zr=["tropical"],eo=["kyoto","newyork","paris"],to=["mred","lgreen"],Td=["default-light","default-minimal","paper-light",...Qr,...Jr,...Zr,...eo,...to];var Ws=[...zs,...Ks,...Qr,...Gs,...Jr,...Zr,...eo,...to];function ro(e){return Ws.includes(e)}var oo="default-light",We=e=>{let t=Yr(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:a,prefetch:u})=>{let i=k(()=>o?[]:ye(r.join( ),{hasTitle:!1}),[o,r]),l=We(e),c=B(async({currentTarget:d})=>{u(e,t),await re(d,a)&&s({project:e,title:t,linkTo:n,type:"link",position:ie(d)})},[e,t,a,n?.project,n?.titleLc]),g=k(()=>n?()=>{ot({type:"page",from:{project:n.project??e,title:n.titleLc},to:{project:e,title:t}})}:()=>{},[e,t,n?.project,n?.titleLc]);return p("a",{className:"related-page-card page-link",type:"link","data-theme":l,href:/${e}/${N(t)},rel:e===scrapbox.Project.name?"route":"noopner noreferrer",target:e!==scrapbox.Project.name?"_blank":"",onPointerEnter:c,onClick:g},p("div",{class:"hover"}),p("div",{class:"content"},p("div",{class:"header"},p("div",{class:"title"},t)),o?p("div",{class:"thumbnail"},p("img",{src:o})):p("div",{class:"description"},i.flatMap((d,f)=>d.type==="line"?[p("p",{key:f},d.nodes.map(m=>p(so,{node:m,project:e})))]:[]))))},so=({node:e,project:t})=>{switch(e.type){case"code":return p("code",null,e.text);case"formula":return p(Xs,{node:e});case"commandLine":return p("code",null,e.symbol," $",e.text);case"helpfeel":return p("code",null,"? ",e.text);case"quote":case"strong":case"decoration":return p(w,null,e.nodes.map(r=>p(so,{node:r,project:t})));case"icon":case"strongIcon":return p(Vs,{node:e,project:t});case"hashTag":return p(Ys,{node:e});case"link":return p(Qs,{node:e});case"plain":case"blank":return p(w,null,e.text);default:return p(w,null)}},Xs=({node:{formula:e}})=>{let{ref:t,error:r,setFormula:o}=me("");return o(e),p("span",{className:formula ${r?" error":""}},r?p("code",null,e):p("span",{className:"katex-display",ref:t}))},Vs=({node:{pathType:e,path:t},project:r})=>{let[o,n]=e==="relative"?[r,t]:t.match(/\/([\w\-]+)\/(.+)$/)?.slice?.(1)??[r,t];return p("img",{class:"icon",src:/api/pages/${o}/${N(n)}/icon})},Ys=({node:{href:e}})=>p("span",{class:"page-link"},"#",e),Qs=({node:{pathType:e,href:t,content:r}})=>e!=="absolute"?p("span",{class:"page-link"},t):p("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]),a=se(s),u=k(()=>[...o],[o]),i=k(()=>{let c=(g,d)=>{let f=u.indexOf(g.project),m=u.indexOf(d.project);return f===m?d.updated-g.updated:f<0?1:m<0?-1:f-m};return[...a].sort(c)},[a,u]),l=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 p("ul",{className:"card-bubble",style:l,onClick:n.onClick},i.map(({project:c,titleLc:g,lines:[{text:d}],descriptions:f,image:m})=>{let y=E(c,g),b=t.get(y)??r.get(y);return p("li",{key:y},p(no,{project:c,title:d,linkTo:b,descriptions:f,thumbnail:m??"",...n}))}))};var ao=K("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,a,u]=Js(e,n,r,t),i=B(()=>o.hide(),[o.hide]),l=We(u[0]?.project??e.project),c=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 p(w,null,u.length>0&&p("div",{className:"text-bubble",style:c,"data-theme":l,onClick:i},p(Zs,null,u[0].project!==scrapbox.Project.name&&p(ei,{project:u[0].project,title:u[0].lines[0].text})),p(Wr,{lines:u[0].lines,project:u[0].project,title:u[0].lines[0].text,hash:e.hash,linkTo:e.linkTo,whiteList:r,...o})),p(io,{linked:s,externalLinked:a,onClick:i,source:e,projectsForSort:n,...o}))},Js=(e,t,r,o)=>{let[[n,s,a],u]=R([new Map,new Map,[]]),i=k(()=>{let g=[...t].map(d=>E(d,e.title));return ao.debug("projects",g),g},[t,e.title]),l=se(i),c=k(()=>o.map(g=>j(g)),[o]);return Se(()=>{let g=new Map,d=new Map,f=[];for(let m of l){let y={project:m.project,titleLc:m.titleLc};for(let _ of m.projectLinked??[]){let{project:I,titleLc:Y}=Re(_);c.includes(Y)&&r.has(I)||d.has(_)||d.set(_,y)}if(!r.has(m.project))continue;let b={titleLc:m.titleLc};for(let _ of m.linked??[]){if(c.includes(_))continue;let I=E(m.project,_);g.has(I)||g.set(I,b)}c.includes(m.titleLc)||m.exists&&f.push(m)}u(Ue(m=>{ao.debug(depth: ${c.length}, bubbled from ${E(e.project,e.title)}, bubbles,,l,"before",m[0],"internal cards,",g,"external cards",d);for(let y of m[0].keys())g.has(y)||m[0].delete(y);for(let[y,b]of g)m[0].set(y,b);for(let y of m[1].keys())d.has(y)||m[1].delete(y);for(let[y,b]of d)m[1].set(y,b);m[2]=f}))},[l,r,c]),[n,s,a]},Zs=({children:e})=>p("div",{className:"status-bar top-right"},e),ei=({project:e,title:t})=>p("a",{href:/${e}/${N(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 p(w,null,t!==""&&(t instanceof URL?p("link",{rel:"stylesheet",href:t.href}):p("style",null,t)))};var uo=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(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}.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{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]=R([]),r=B((s,a)=>t(u=>a?[...u.slice(0,s),a]:[...u.slice(0,s)]),[]),[o,n]=R([{bubble:s=>r(0,s),hide:()=>r(0)}]);return O(()=>{n(([s,...a])=>[s,...e.map((u,i)=>u===a.at(i)?.source?a.at(i):{source:u,parentTitles:[scrapbox.Page.title??"",...e.slice(0,i).map(l=>l.title)],bubble:l=>r(i+1,l),hide:()=>r(i+1)})])},[e]),o};var bt=(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"),Xe=e=>e instanceof HTMLAnchorElement&&e.classList.contains("page-link");var xt="scrap-bubble",go=({delay:e,whiteList:t,watchList:r,style:o})=>{let[{bubble:n,hide:s},...a]=fo(),u=B((i,l)=>Hr(l,t.has(i)?t:new Set([i]),r),[t,r]);return bt(document,"pointerenter",async i=>{let l=i.target;if(!Xe(l)&&!mo(l))return;let{project:c=scrapbox.Project.name,title:g,hash:d=""}=Xe(l)?te({pathType:"root",href:${new URL(l.href).pathname}${new URL(l.href).hash}`}):{project:scrapbox.Project.name,title:scrapbox.Page.title};if(c==="")return;let f=decodeURIComponent(g??"");u(c,f),await re(l,e)&&n({project:c,title:f,hash:d,position:ie(l),type:ti(l)})},{capture:!0},e,t,r),bt(document,"click",i=>{i.target.dataset.userscriptName!==xt&&s()},{capture:!0},s),O(()=>(scrapbox.addListener("page:changed",s),()=>scrapbox.removeListener("page:changed",s)),s),p(w,null,p("link",{rel:"stylesheet",href:"https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.12.0/katex.min.css"}),p("style",null,uo),p(po,{style:o}),a.map(i=>p(co,{key:E(i.source.project,i.source.title),...i,whiteList:t,delay:e,prefetch:u})))},ti=e=>Xe(e)?e.type==="link"?"link":"hashtag":"title";var Of=async e=>{let{delay:t=500,whiteList:r=[],watchList:o=(await pr()).slice(0,100),style:n="",debug:s=!1}=e??{};Br(s);let a=document.createElement("div");a.dataset.userscriptName=xt,document.body.append(a);let u=a.attachShadow({mode:"open"});Ne(p(go,{delay:t,whiteList:new Set(scrapbox.Project.name,...r),watchList:new Set(o),style:n}),u)};export{Of as mount};