(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[405],{78706:function(e,n,t){"use strict";t.r(n),t.d(n,{Graph:function(){return rt},GraphPage:function(){return tt},default:function(){return nt},getThemeColor:function(){return lt},hexToRGBA:function(){return st},normalizeLinkEnds:function(){return ot}});var r=t(15861),i=t(42982),o=t(4942),l=t(70885),s=t(87757),c=t.n(s),a=t(67294),u=t(9008);function d(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function h(e){for(var n=1;n2&&void 0!==arguments[2]?arguments[2]:{},i=f(e,null!==(t=r.storage)&&void 0!==t?t:localStorage),o=i.get(),l=void 0!==o?o:n,s=null!=o&&"object"===typeof o&&!1===Array.isArray(o)?h(h({},n),o):l;s!==o&&i.update(s);var c=(0,a.useState)(s),u=c[0],d=c[1];(0,a.useEffect)((function(){u!==s&&d(s)}),[e]);var g=function(e){e instanceof Function?d((function(n){var t=e(n);return i.update(t),t})):(d(e),i.update(e))};return[u,g]}function f(e,n){return{get:function(){var t=n.getItem(e);if(t&&"undefined"!==t)return JSON.parse(t)},update:function(t){n.setItem(e,JSON.stringify(t))},remove:function(){n.removeItem(e)}}}var p=t(52596),x=t(45987),j=t(94096),b=t(48420),v=t(47516),m=t(35255),y=t(56884),C=t(85893),k=function(e){var n=e.setJustification,t=e.setIndent,r=e.setFont,i=e.justification;return(0,C.jsxs)(j.k,{py:3,alignItems:"center",justifyContent:"space-between",pr:4,children:[(0,C.jsxs)(j.k,{children:[(0,C.jsx)(b.h,{variant:"ghost",icon:(0,C.jsx)(m.w,{}),"aria-label":"Previous node"}),(0,C.jsx)(b.h,{variant:"ghost",icon:(0,C.jsx)(y.X,{}),"aria-label":"Previous node"})]}),(0,C.jsxs)(j.k,{children:[(0,C.jsx)(b.h,{variant:"ghost","aria-label":"Justify content",icon:[(0,C.jsx)(v.v9V,{},"justify"),(0,C.jsx)(v.YSr,{},"left"),(0,C.jsx)(v.RXA,{},"right"),(0,C.jsx)(v.tr_,{},"center")][i],onClick:function(){return n((function(e){return(e+1)%4}))}}),(0,C.jsx)(b.h,{variant:"ghost","aria-label":"Indent Text",icon:(0,C.jsx)(v.WHD,{}),onClick:function(){t((function(e){return e?0:1}))}}),(0,C.jsx)(b.h,{variant:"ghost","aria-label":"Change font",icon:(0,C.jsx)(v.TlM,{}),onClick:function(){r((function(e){return"sans serif"===e?"serif":"sans serif"}))}})]})]})},w=t(48017),O=t(18835),S=t.n(O),P=t(13816),N=t.n(P),I=t(42728),L=t.n(I),D=t(77890),z=t.n(D),E=t(94986),R=t.n(E),T=t(88541),Z=t.n(T),B=t(71167),F=t.n(B),H=(t(85062),t(27431)),A=t.n(H),V=t(40980),M=t(64115),W=t(45170),X=t(67273),_=t(29356),U={".katex":{overflowX:"scroll"},h1:{color:"black",lineHeight:"1.2",fontSize:"20",fontWeight:"bold",marginBottom:3},h2:{fontSize:"18",marginBottom:2,color:"black"},h3:{fontSize:"16",fontWeight:"600 !important",marginBottom:".5em",color:"black"},h4:{fontSize:"14",fontWeight:"500 !important",marginBottom:".25em",fontStyle:"italic",color:"black"},ol:{paddingLeft:"5"},ul:{paddingLeft:"5"},p:{fontSize:"14",fontWeight:"500 !important",paddingBottom:".5em"},div:{hyphens:"auto !important"},".title":{textAlign:"center",marginBottom:".2em"},".subtitle":{textAlign:"center",fontSize:"medium",fontWeight:"bold",marginTop:0},".todo":{fontFamily:"monospace",color:"red"},".equationContainer":{display:"table",textAlign:"center",width:"100%"},".equation":{verticalAlign:"middle"},".equation-label":{display:"tableCell",textAlign:"right",verticalAlign:"middle"},".inlinetask":{padding:"10px",border:"2px solid gray",margin:"10px",background:"#ffffcc"},"#org-div-home-and-up":{textAlign:"right",fontSize:"70 % ",whiteSpace:"nowrap"},textarea:{overflowX:"auto"},".linenr":{fontSize:"smaller"},".code-highlighted":{backgroundColor:"#ffff00"},".org-info-js_info-navigation":{borderStyle:"none"},"#org-info-js_console-label":{fontSize:"10px",fontWeight:"bold",whiteSpace:"nowrap"},".org-info-js_search-highlight":{backgroundColor:"#ffff00",color:"#000000",fontWeight:"bold"},".org-svg":{width:"90%"},".done":{fontFamily:"monospace",color:"green"},".priority":{fontFamily:"monospace",color:"orange"},".tag":{backgroundColor:"#eee",fontFamily:"monospace",padding:"2px",fontSize:"80%",fontWeight:"normal"},".timestamp":{color:"#bebebe"},".timestamp-kwd":{color:"#5f9ea0"},".org-right":{marginLeft:"auto",marginRight:"0px",textAlign:"right"},".org-left":{marginLeft:"0px",marginRight:"auto",textAlign:"left"},".org-center":{marginLeft:"auto",marginRight:"auto",textAlign:"center"},".underline":{textDecoration:"underline"},"#postamble p":{fontSize:"90%",margin:".2em"},"#preamble p":{fontSize:"90%",margin:".2em"},"p.verse":{marginLeft:"3%"},pre:{border:"1px solid #e6e6e6",borderRadius:"3px",backgroundColor:"#f2f2f2",padding:"8pt",fontFamily:"monospace",overflow:"auto",margin:"1.2em"},"pre.src":{position:"relative",overflow:"auto"},"pre.src:before":{display:"none",position:"absolute",top:"-8px",right:"12px",padding:"3px",color:"#555",backgroundColor:"#f2f2f299"},"caption.t-above":{captionSide:"top"},"caption.t-bottom":{captionSide:"bottom"},"th.org-right":{textAlign:"center"},"th.org-left":{textAlign:"center"},"th.org-center":{textAlign:"center"},"td.org-right":{textAlign:"right"},"td.org-left":{textAlign:"left"},"td.org-center":{textAlign:"center"},".footpara":{display:"inline"},".footdef":{marginBottom:"1em"},".figure":{padding:"1em"},".figure p":{textAlign:"center"}},q=U,Q=t(25675),G=t(62520),J=t.n(G),K=function(e){var n=e.src,t=(e.file,(0,a.useState)(null)),r=(t[0],t[1],J().dirname(n)),i=encodeURIComponent(encodeURIComponent(J().join(r,n)));return(0,C.jsx)(Q.default,{unoptimized:!0,loader:function(e){var n=e.src;e.width,e.quality;return"http://localhost:35901/img/".concat(n)},src:i,alt:"",width:100,height:100})},Y=function(e){var n=e.setSidebarHighlightedNode,t=e.setPreviewNode,r=e.nodeById,o=e.href,s=e.children,c=(0,a.useContext)(_.N).highlightColor,u=lt(c,(0,V.useTheme)()),d=(0,l.Z)((0,i.Z)(o.matchAll(/(.*?)\:(.*)/g))[0],3),h=(d[0],d[1],d[2]);return(0,C.jsx)(M.x,{onMouseEnter:function(){return n(r[h])},onMouseLeave:function(){return n({})},tabIndex:0,display:"inline",overflow:"hidden",fontWeight:500,color:c,textDecoration:"underline",onClick:function(){return t(r[h])},_hover:{textDecoration:"none",cursor:"pointer",bgColor:u+"22"},_focus:{outlineColor:c},children:s})},$=function e(n){var t,r,o,s,c,u=n.href,d=n.children,h=n.nodeById,g=n.setSidebarHighlightedNode,f=(n.previewNode,n.setPreviewNode),p=n.nodeByCite,x=(0,a.useState)(null),j=x[0],b=x[1],v=(0,l.Z)((0,i.Z)(u.matchAll(/(.*?)\:(.*)/g))[0],3),m=(v[0],v[1]),y=v[2],k=(0,a.useState)(!1),O=k[0],P=k[1],I=function(e,n){if("id"===e)return n;if(e.includes("cite")){var t,r=null!==(t=p[n])&&void 0!==t&&t;return r?null!==r&&void 0!==r&&r.properties.FILELESS?"":null===r||void 0===r?void 0:r.id:""}return""}(m,y),D=encodeURIComponent(encodeURIComponent(null===(t=h[I])||void 0===t?void 0:t.file)),z=S()().use(N()).use(L()).use(F()).use(A(),{createElement:a.createElement,components:{a:function(n){n.children;var t,r=n.href;return(0,C.jsx)(e,{nodeByCite:p,setSidebarHighlightedNode:g,href:r,nodeById:h,setPreviewNode:f,children:null===(t=h[I])||void 0===t?void 0:t.title})},img:function(e){var n=e.src;return(0,C.jsx)(K,{src:n,file:D})}}});return(0,a.useEffect)((function(){j||O&&(console.log("gettin text"),fetch("127.0.0.1:35901/file/".concat(D)).then((function(e){return e.text()})).then((function(e){if("error"===e);else{var n=z.processSync(e).result;b(n)}})).catch((function(e){return console.log(e),"Could not fetch the text for some reason, sorry!\n\n This can happen because you have an id with forward slashes (/) in it."})))}),[O,j]),I?(0,C.jsx)(C.Fragment,{children:(0,C.jsxs)(W.J2,{gutter:12,trigger:"hover",placement:"top-start",children:[(0,C.jsx)(W.xo,{children:(0,C.jsx)(w.xu,{display:"inline",onMouseEnter:function(){return P(!0)},onMouseLeave:function(){return P(!1)},children:(0,C.jsx)(Y,{setSidebarHighlightedNode:g,setPreviewNode:f,nodeById:h,href:u,children:d,nodeByCite:p},null!==(r=null===(o=h[I])||void 0===o?void 0:o.title)&&void 0!==r?r:I)})}),(0,C.jsx)(X.h,{children:(0,C.jsxs)(W.yk,{boxShadow:"xl",position:"relative",zIndex:"tooltip",onMouseEnter:function(){var e;g(null!==(e=h[I])&&void 0!==e?e:{})},onMouseLeave:function(){g({})},children:[(0,C.jsx)(W.QH,{}),(0,C.jsx)(W.b,{pb:5,fontSize:"xs",px:5,position:"relative",zIndex:"tooltip",maxHeight:300,overflow:"scroll",children:(0,C.jsx)(w.xu,{sx:q,children:j})})]},null!==(s=null===(c=h[I])||void 0===c?void 0:c.title)&&void 0!==s?s:I)})]})}):(0,C.jsx)(M.x,{display:"inline",color:"base.700",cursor:"not-allowed",children:d})},ee=function(e){var n=e.nodeById,t=e.setSidebarHighlightedNode,r=e.setPreviewNode,i=e.previewText,o=e.nodeByCite,l=e.previewNode,s=S()().use(N()).use(R()).use(Z()).use(z()).use(L()).use(F()).use(A(),{createElement:a.createElement,components:{a:function(e){var i=e.children,l=e.href;return(0,C.jsx)($,{nodeByCite:o,setSidebarHighlightedNode:t,href:"".concat(l),nodeById:n,setPreviewNode:r,children:i})},img:function(e){var n=e.src;return(0,C.jsx)(K,{src:n,file:l.file})}}}),c=(0,a.useMemo)((function(){return s.processSync(i).result}),[i]);return(0,C.jsx)(C.Fragment,{children:c})},ne=function(e){var n=e.setSidebarHighlightedNode,t=e.nodeById,r=e.nodeByCite,i=e.previewNode,o=e.setPreviewNode,l=(0,a.useState)(""),s=l[0],c=l[1],u=encodeURIComponent(encodeURIComponent(i.file));return(0,a.useEffect)((function(){fetch("http://localhost:35901/file/".concat(u)).then((function(e){return e.text()})).then((function(e){"error"!==e&&c(e)})).catch((function(e){return console.log(e),"Could not fetch the text for some reason, sorry!\n\n This can happen because you have an id with forward slashes (/) in it."}))}),[i.id]),(0,a.useEffect)((function(){return console.log("mount"),function(){return console.log("unmount")}}),[]),(0,C.jsx)(C.Fragment,{children:(null===i||void 0===i?void 0:i.id)&&(0,C.jsx)(ee,{nodeById:t,previewNode:i,setPreviewNode:o,previewText:s,nodeByCite:r,setSidebarHighlightedNode:n})})},te=t(336),re=t(72026),ie=function(e){var n,t=e.previewNode,r=e.setPreviewNode,i=e.setSidebarHighlightedNode,o=e.nodeById,s=e.linksByNodeId,c=e.nodeByCite,a=(null!==(n=s[null===t||void 0===t?void 0:t.id])&&void 0!==n?n:[]).filter((function(e){var n=ot(e),r=(0,l.Z)(n,2),i=r[0];r[1];return i!==(null===t||void 0===t?void 0:t.id)})).map((function(e){return e.source}));return(0,C.jsxs)(w.xu,{children:[(0,C.jsx)(te.X,{pt:4,children:"Backlinks (".concat(a.length,")")}),(0,C.jsx)(re.gC,{pt:2,spacing:3,alignItems:"start",divider:(0,C.jsx)(re.cX,{borderColor:"gray.500"}),align:"stretch",color:"gray.800",children:(null===t||void 0===t?void 0:t.id)&&a.map((function(e){var n,t,l;n=null===(t=o[e])||void 0===t?void 0:t.title;return(0,C.jsx)(w.xu,{overflow:"hidden",p:3,bg:"gray.300",width:"100%",children:(0,C.jsx)($,{nodeByCite:c,setSidebarHighlightedNode:i,href:"id:".concat(e),nodeById:o,setPreviewNode:r,children:null===(l=o[e])||void 0===l?void 0:l.title})},e)}))})]})};function oe(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function le(e){for(var n=1;n1,animateOpacity:!0,children:(0,C.jsx)(w.xu,{paddingTop:2,children:(0,C.jsx)(rn,{label:"Label Appearance Scale",value:5*n.labelScale,onChange:function(e){return t(wn(wn({},n),{},{labelScale:e/5}))}})})})]})]})})};function Sn(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function Pn(e){for(var n=1;n2&&void 0!==arguments[2]?arguments[2]:2e3,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:200;if("color"!==e){var l=se.current,s=de.current,c=he.current,a=null!==(t=ie.current[n])&&void 0!==t?t:[],u=Object.fromEntries([n].concat((0,i.Z)(a.flatMap((function(e){return[e.source,e.target]})))).map((function(e){return[e,{}]})));if("zoom"===e)return s.nodeIds.length&&p({nodeIds:[]}),void setTimeout((function(){return l.zoomToFit(r,o,(function(e){return u[e.id]}))}),50);if(!s.nodeIds.length)return p({nodeIds:[n]}),void setTimeout((function(){l.centerAt(0,0,10),l.zoomToFit(1,o)}),50);if("add"!==c.localSame)return p({nodeIds:[n]}),void setTimeout((function(){l.centerAt(0,0,10),l.zoomToFit(1,o)}),50);if(!s.nodeIds.includes(n)||!s.nodeIds.some((function(e){return u[e]})))return p({nodeIds:[n]}),void setTimeout((function(){l.centerAt(0,0,10),l.zoomToFit(1,o)}),50);p((function(e){return Kn(Kn({},e),{},{nodeIds:[].concat((0,i.Z)(e.nodeIds),[n])})})),setTimeout((function(){l.centerAt(0,0,10),l.zoomToFit(1,o)}),50)}};return(0,a.useEffect)((function(){ge.current=new Gn.Z("ws://localhost:35903"),ge.current.addEventListener("open",(function(){console.log("Connection with Emacs established")})),ge.current.addEventListener("message",(function(e){var n=he.current,t=JSON.parse(e.data);switch(t.type){case"graphdata":return function(e){var n,t,r,s=re.current;le.current=null!==(n=e.tags)&&void 0!==n?n:[];var c=null!==(t=e.nodes)&&void 0!==t?t:[],a=null!==(r=e.links)&&void 0!==r?r:[],u=c.reduce((function(e,n){var t;return Kn(Kn({},e),{},(0,o.Z)({},n.file,[].concat((0,i.Z)(null!==(t=e[n.file])&&void 0!==t?t:[]),[n])))}),{}),d=Object.keys(u).flatMap((function(e){var n,t=null!==(n=u[e])&&void 0!==n?n:[],r=t.find((function(e){return 0===e.level})),i=t.filter((function(e){return 0!==e.level}));return r?i.map((function(e){var n=t.filter((function(n){var t;return!(n.level>=e.level||n.pos>=e.pos||null===(t=e.olp)||void 0===t||!t.includes(n.title))})).reduce((function(e,n){return n.level>e.level&&(e=n),e}),r);return{source:e.id,target:(null===n||void 0===n?void 0:n.id)||r.id,type:"heading"}})):[]})),h=Object.keys(u).flatMap((function(e){var n,t=null!==(n=u[e])&&void 0!==n?n:[],r=t.find((function(e){return 0===e.level})),i=t.filter((function(e){return 0!==e.level}));return r?i.map((function(e){return{source:e.id,target:r.id,type:"parent"}})):[]}));re.current=Object.fromEntries(c.map((function(e){return[e.id,e]})));var g=[].concat((0,i.Z)(a),(0,i.Z)(d),(0,i.Z)(h)),f=[],p=g.map((function(e){var n=e.source,t=e.target;return re.current[n]?re.current[t]?e:(f.push({id:t,tags:["bad"],properties:{FILELESS:"yes",bad:"yes"},file:"",title:t,level:0,pos:0,olp:null}),Kn(Kn({},e),{},{type:"bad"})):(f.push({id:n,tags:["bad"],properties:{FILELESS:"yes",bad:"yes"},file:"",title:n,level:0,pos:0,olp:null}),Kn(Kn({},e),{},{type:"bad"}))}));re.current=Kn(Kn({},re.current),Object.fromEntries(f.map((function(e){return[e.id,e]})))),ie.current=p.reduce((function(e,n){var t,r,l;return Kn(Kn({},e),{},(l={},(0,o.Z)(l,n.source,[].concat((0,i.Z)(null!==(t=e[n.source])&&void 0!==t?t:[]),[n])),(0,o.Z)(l,n.target,[].concat((0,i.Z)(null!==(r=e[n.target])&&void 0!==r?r:[]),[n])),l))}),{});var x=[].concat((0,i.Z)(c),f);oe.current=x.reduce((function(e,n){var t,r=null===(t=n.properties)||void 0===t?void 0:t.ROAM_REFS;if(null===r||void 0===r||!r.includes("cite"))return e;var i=r.replaceAll(/cite:(.*)/g,"$1");return i?Kn(Kn({},e),{},(0,o.Z)({},i,n)):e}),{});var j={nodes:x,links:p},b=ce.current;if(0===b.nodes.length){var v=JSON.parse(JSON.stringify(j));return ce.current=v,void R(v)}var m=[].concat((0,i.Z)(b.nodes.flatMap((function(e){var n,t=null!==(n=re.current[null===e||void 0===e?void 0:e.id])&&void 0!==n&&n;return t?[Kn(Kn({},e),t)]:[]}))),(0,i.Z)(Object.keys(re.current).filter((function(e){return!s[e]})).map((function(e){return re.current[e]})))),y=m.reduce((function(e,n,t){var r=null===n||void 0===n?void 0:n.id;return Kn(Kn({},e),{},(0,o.Z)({},r,t))}),{}),C=p.map((function(e){var n=ot(e),t=(0,l.Z)(n,2),r=t[0],i=t[1];return Kn(Kn({},e),{},{source:m[y[r]],target:m[y[i]]})}));R({nodes:m,links:C})}(t.data);case"theme":return ae(t.data);case"command":switch(t.data.commandName){case"local":var r=A.zoomSpeed,s=A.zoomPadding;pe("local",t.data.id,r,s),B(t.data.id);break;case"zoom":var c,a,u=(null===t||void 0===t||null===(c=t.data)||void 0===c?void 0:c.speed)||n.zoomSpeed,d=(null===t||void 0===t||null===(a=t.data)||void 0===a?void 0:a.padding)||n.zoomPadding;pe("zoom",t.data.id,u,d),B(t.data.id);break;case"follow":pe(n.follow,t.data.id,n.zoomSpeed,n.zoomPadding),B(t.data.id);break;default:return console.error("unknown message type",t.type)}}}))}),[]),(0,a.useEffect)((function(){var e=se.current;!e||f.nodeIds.length>1||(f.nodeIds.length||!m.gravityOn?setTimeout((function(){e.zoomToFit(5,200)}),50):e.zoomToFit())}),[f.nodeIds]),E?(0,C.jsxs)(w.xu,{display:"flex",alignItems:"flex-start",flexDirection:"row",height:"100%",overflow:"hidden",children:[(0,C.jsxs)(w.xu,{display:"flex",justifyContent:"space-between",flexDirection:"row",height:"100%",width:"100%",children:[(0,C.jsx)(Zn,{physics:m,setPhysics:y,threeDim:t,setThreeDim:r,filter:S,setFilter:P,visuals:L,setVisuals:D,mouse:X,setMouse:U,behavior:A,setBehavior:V,tagColors:u,setTagColors:d,tags:le.current}),(0,C.jsx)(j.k,{height:"100%",flexDirection:"column",marginLeft:"auto",children:!ee&&(0,C.jsx)(b.h,{icon:(0,C.jsx)(ue.U,{}),"aria-label":"Open org-viewer",zIndex:2,onClick:ne,variant:"ghost",marginTop:10,mr:8})})]}),(0,C.jsxs)(j.k,{position:"absolute",alignItems:"top",overflow:"hidden",children:[(0,C.jsx)(rt,{ref:se,nodeById:re.current,linksByNodeId:ie.current,webSocket:ge.current,physics:m,graphData:E,threeDim:t,emacsNodeId:Z,filter:S,visuals:L,behavior:A,mouse:X,scope:f,setScope:p,tagColors:u,setPreviewNode:G,sidebarHighlightedNode:K}),(0,C.jsx)(fe,{isOpen:ee,onOpen:ne,onClose:te,previewNode:Q,setPreviewNode:G,setSidebarHighlightedNode:Y,nodeById:re.current,linksByNodeId:ie.current,nodeByCite:oe.current})]})]}):null}var rt=(0,a.forwardRef)((function(e,n){var t=e.physics,s=e.graphData,u=e.threeDim,d=e.linksByNodeId,h=e.filter,g=e.emacsNodeId,f=e.nodeById,x=e.visuals,j=e.behavior,b=e.mouse,v=e.scope,m=e.setScope,y=e.webSocket,k=e.tagColors,O=e.setPreviewNode,S=e.sidebarHighlightedNode,P=(0,pe.iP)(),N=(0,l.Z)(P,2),I=(N[0],N[1]),L=(0,a.useState)(null),D=L[0],z=L[1],E=(0,a.useState)(null),R=E[0],T=E[1],Z=(0,a.useState)([0,0]),B=Z[0],F=Z[1],H=(0,V.useTheme)(),A=(0,a.useContext)(_.N).emacsTheme,M=function(e,n){"replace"!==n?v.nodeIds.includes(e.id)||m((function(n){return Kn(Kn({},n),{},{nodeIds:[].concat((0,i.Z)(n.nodeIds),[e.id])})})):m({nodeIds:[e.id]})},W=(0,je.q)(),X=function(e,n,t){switch(e){case b.local:M(n,j.localSame);break;case b.follow:Xn(n,y);break;case b.context:!function(e,n){F([n.pageX,n.pageY]),T(e),W.onOpen()}(n,t);case b.preview:O(n)}},U=(0,a.useRef)(null);(0,a.useEffect)((function(){g&&z(f[g])}),[g]);var q=(0,a.useRef)({}),Q=(0,a.useRef)({}),G=(0,a.useMemo)((function(){var e;Q.current={};var n=null===s||void 0===s||null===(e=s.nodes)||void 0===e?void 0:e.filter((function(e){var n=e;return h.tagsBlacklist.length&&h.tagsBlacklist.some((function(e){return n.tags.indexOf(e)>-1}))||h.tagsWhitelist.length>0&&!h.tagsWhitelist.some((function(e){return n.tags.indexOf(e)>-1}))||h.filelessCites&&n.properties.FILELESS?(Q.current=Kn(Kn({},Q.current),{},(0,o.Z)({},n.id,n)),!1):!h.bad||!n.properties.bad||(Q.current=Kn(Kn({},Q.current),{},(0,o.Z)({},n.id,n)),!1)})).filter((function(e){var n,t=(null!==(n=d[null===e||void 0===e?void 0:e.id])&&void 0!==n?n:[]).filter((function(e){return!Q.current[e.source]&&!Q.current[e.target]}));return!h.orphans||(h.parent?0!==t.length:0!==t.length&&t.some((function(e){return!["parent","heading"].includes(e.type)})))})),t=n.map((function(e){return e.id})),r=s.links.filter((function(e){var n=ot(e),r=(0,l.Z)(n,2),i=r[0],o=r[1];if(!t.includes(i)||!t.includes(o))return!1;var s=e;return h.parent?"heading"===h.parent?"parent"!==s.type:"heading"!==s.type:!["parent","heading"].includes(s.type)}));return q.current=r.reduce((function(e,n){var t,r,s,c=n,a=ot(c),u=(0,l.Z)(a,2),d=u[0],h=u[1];return Kn(Kn({},e),{},(s={},(0,o.Z)(s,d,[].concat((0,i.Z)(null!==(t=e[d])&&void 0!==t?t:[]),[c])),(0,o.Z)(s,h,[].concat((0,i.Z)(null!==(r=e[h])&&void 0!==r?r:[]),[c])),s))}),{}),{nodes:n,links:r}}),[h,s]),J=(0,a.useState)({nodes:[],links:[]}),K=J[0],Y=J[1];(0,a.useEffect)((function(){if(v.nodeIds.length){var e=v.nodeIds.length>1?K.nodes:[],n=e.map((function(e){return e.id})),t=function(e,n){var t=[e[0]],r=[],i=[e[0]];return Array.from({length:n},(function(){t.forEach((function(e){var n;(null!==(n=q.current[e])&&void 0!==n?n:[]).forEach((function(e){var n=ot(e),t=(0,l.Z)(n,2),o=t[0],s=t[1];i.includes(o)?i.includes(s)||r.push(s):r.push(o)}))})),t=r,r.forEach((function(e){return e&&i.push(e)})),r=[]})),i}(v.nodeIds,1),r=G.nodes.filter((function(r){var i;return e.length?!n.includes(r.id)&&(null!==(i=q.current[r.id])&&void 0!==i?i:[]).some((function(e){return v.nodeIds.includes(e.source)||v.nodeIds.includes(e.target)})):t.includes(r.id)})).map((function(e){return Kn(Kn({},e),{},{x:0,y:0,vy:0,vx:0})})),o=[].concat((0,i.Z)(e),(0,i.Z)(r)),s=o.map((function(e){return e.id})),c=v.nodeIds.length>1?K.links:[],a=G.links.filter((function(e){var t=ot(e),r=(0,l.Z)(t,2),i=r[0],o=r[1];return!(c.length&&n.includes(o)&&n.includes(i))&&(s.includes(i)&&s.includes(o))})).map((function(e){var n=ot(e),t=(0,l.Z)(n,2);return{source:t[0],target:t[1]}})),u=[].concat((0,i.Z)(c),(0,i.Z)(a));Y({nodes:o,links:u})}}),[h,v,s]),(0,a.useEffect)((function(){(0,r.Z)(c().mark((function e(){var r,i;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.current,e.next=3,Yn;case 3:i=e.sent,!t.gravityOn||v.nodeIds.length&&!t.gravityLocal?(r.d3Force("x",null),r.d3Force("y",null),u&&r.d3Force("z",null)):(r.d3Force("x",i.forceX().strength(t.gravity)),r.d3Force("y",i.forceY().strength(t.gravity)),u&&r.d3Force("z",i.forceZ().strength(t.gravity))),t.centering?r.d3Force("center",i.forceCenter().strength(t.centeringStrength)):r.d3Force("center",null),t.linkStrength&&r.d3Force("link").strength(t.linkStrength),t.linkIts&&r.d3Force("link").iterations(t.linkIts),t.charge&&r.d3Force("charge").strength(t.charge),r.d3Force("collide",t.collision?i.forceCollide().radius(t.collisionStrength):null);case 10:case"end":return e.stop()}}),e)})))()}),[t,u,v]),(0,a.useEffect)((function(){var e;null===(e=n.current)||void 0===e||e.d3ReheatSimulation()}),[t,v.nodeIds.length]);var $=(0,a.useRef)(0),ee=(0,a.useState)(1),ne=ee[0],te=ee[1],re=(0,xe._7)((function(e){return te(e)}),{duration:x.animationSpeed,algorithm:we[x.algorithmName]}),ie=(0,l.Z)(re,2),oe=ie[0],le=ie[1],se=(0,xe._7)((function(e){return te(Math.min(ne,-1*(e-1)))}),{duration:x.animationSpeed,algorithm:we[x.algorithmName]}),ce=(0,l.Z)(se,2),ae=ce[0],ue=ce[1];(0,a.useEffect)((function(){console.log("aaa"),null!==S&&void 0!==S&&S.id?z(S):z(null)}),[S]);var de=(0,a.useMemo)((function(){if(!U.current)return{};var e=q.current[U.current.id];return e?Object.fromEntries([U.current.id].concat((0,i.Z)(e.flatMap((function(e){return[e.source,e.target]})))).map((function(e){return[e,{}]}))):{}}),[JSON.stringify(U.current),JSON.stringify(q.current)]),he=(0,a.useRef)(null);(0,a.useEffect)((function(){if(U.current=D,D&&(he.current=D),!x.highlightAnim)return te(D?1:0);D?oe():(le(),ne>.5?ae():te(0))}),[D]);var ge=(0,a.useMemo)((function(){return Object.fromEntries(Le.map((function(e){var n=lt(e,H),t=Le.map((function(e){return[e,p.Z(n,lt(e,H))]}));return[e,Object.fromEntries(t)]})))}),[A]),fe=(0,a.useMemo)((function(){var e,n,t,r=null!==(e=q.current[null===(n=he.current)||void 0===n?void 0:n.id])&&void 0!==e?e:[];return Object.fromEntries([null===(t=he.current)||void 0===t?void 0:t.id].concat((0,i.Z)(r.flatMap((function(e){return ot(e)})))).map((function(e){return[e,{}]})))}),[JSON.stringify(D),he.current,q.current]),be=function(e){var n,t,r,i,o,l=null!==(n=null===(t=q.current[e])||void 0===t?void 0:t.length)&&void 0!==n?n:0;return x.nodeColorScheme[(r=l,i=0,o=x.nodeColorScheme.length-1,Math.min(Math.max(r,i),o))]},ve=function(e,n){return q.current[e].length>q.current[n].length?be(e):be(n)},me=(0,a.useMemo)((function(){return lt(x.labelTextColor,H)}),[x.labelTextColor,A]),ye=(0,a.useMemo)((function(){return lt(x.labelBackgroundColor,H)}),[x.labelBackgroundColor,A]),Ce=function(e){var n,t=null!==(n=q.current[e.id])&&void 0!==n?n:[],r=t.length?t.filter((function(e){return"parent"===e.type})).length:0,i=3+t.length*x.nodeSizeLinks-(h.parent?0:r);return 1===x.highlightNodeSize?i:i*(de[e.id]||fe[e.id]?1+ne*(x.highlightNodeSize-1):1)},ke=(0,a.useState)(!1),Oe=ke[0],Se=ke[1],Pe=(0,a.useState)(1),Ne=Pe[0],Ie=Pe[1],De={graphData:v.nodeIds.length?K:G,height:I,backgroundColor:H.colors.gray[x.backgroundColor],warmupTicks:1===v.nodeIds.length?100:v.nodeIds.length>1?20:0,onZoom:function(e){var n=e.k;e.x,e.y;return Ie(n)},nodeLabel:function(e){return e.title},nodeColor:function(e){return function(e,n){var t=de[e.id]||fe[e.id];if(x.emacsNodeColor&&e.id===g)return lt(x.emacsNodeColor,n);if(k&&e.tags.some((function(e){return k[e]}))){var r=k[e.tags.filter((function(e){return k[e]}))[0]];return ge[r][x.backgroundColor](x.highlightFade*ne)}return x.citeNodeColor&&e.properties.ROAM_REFS&&e.properties.FILELESS?t?lt(x.citeNodeColor,n):ge[x.citeNodeColor][x.backgroundColor](x.highlightFade*ne):x.refNodeColor&&e.properties.ROAM_REFS?t?lt(x.refNodeColor,n):ge[x.refNodeColor][x.backgroundColor](x.highlightFade*ne):t?x.nodeHighlight?ge[be(e.id)][x.nodeHighlight](ne):lt(be(e.id),n):ge[be(e.id)][x.backgroundColor](x.highlightFade*ne)}(e,H)},nodeRelSize:x.nodeRel,nodeVal:function(e){return Ce(e)/Math.pow(Ne,x.nodeZoomSize)},nodeCanvasObject:function(e,n,t){if(e&&!Oe&&x.labels){var r=fe[e.id];if(!(t<=x.labelScale||1===x.labels)||de[e.id]||r){var o=e.title,l=o.substring(0,x.labelLength),s=x.labelFontSize/(.75*Math.min(Math.max(.5,t),3)),c=[1.1*n.measureText(l).width,s].map((function(e){return e+.5*s})),a=Math.min(3*(t-x.labelScale)/x.labelScale,1),u=function(){return 1===x.labels||t<=x.labelScale?ne:de[e.id]||fe[e.id]?Math.max(a,ne):1*a*(-1*(x.highlightFade*ne-1))},d=8*Math.cbrt(Ce(e)*x.nodeRel);if(x.labelBackgroundColor&&x.labelBackgroundOpacity){var h=u()*x.labelBackgroundOpacity,g=st(ye,h);n.fillStyle=g,n.fillRect.apply(n,[e.x-c[0]/2,e.y-c[1]/2+d].concat((0,i.Z)(c)))}var f=u();n.textAlign="center",n.textBaseline="middle";var p=st(me,f);n.fillStyle=p,n.font="".concat(s,"px Sans-Serif");var j=Qn()(l,{width:x.labelWordWrap}).split("\n");(o.length>x.labelLength?[].concat((0,i.Z)(j.slice(0,-1)),["".concat(j.slice(-1),"...")]):j).forEach((function(t,r){n.fillText(t,e.x,e.y+d+x.labelLineSpace*s*r)}))}}},nodeCanvasObjectMode:function(){return"after"},linkDirectionalParticles:x.particles?x.particlesNumber:void 0,linkDirectionalArrowLength:x.arrows?x.arrowsLength:void 0,linkDirectionalArrowRelPos:x.arrowsPos,linkDirectionalArrowColor:x.arrowsColor?function(){return lt(x.arrowsColor,H)}:void 0,linkColor:function(e){var n,t="object"===typeof e.source?e.source.id:e.source,r="object"===typeof e.target?e.target.id:e.target,i=it(e,U.current),o=it(e,he.current),l=i||o,s=e;return x.refLinkColor&&"ref"===s.type?l&&(x.refLinkHighlightColor||x.linkHighlight)?ge[x.refLinkColor][x.refLinkHighlightColor||x.linkHighlight](ne):ge[x.refLinkColor][x.backgroundColor](x.highlightFade*ne):x.citeLinkColor&&null!==(n=s.type)&&void 0!==n&&n.includes("cite")?l&&(x.citeLinkHighlightColor||x.linkHighlight)?ge[x.citeLinkColor][x.citeLinkHighlightColor||x.linkHighlight](ne):ge[x.citeLinkColor][x.backgroundColor](x.highlightFade*ne):function(e,n,t,r){if(!x.linkHighlight&&!x.linkColorScheme&&!t)return lt(ve(e,n),r);if(!t&&!x.linkColorScheme){var i=ve(e,n);return ge[i][x.backgroundColor](x.highlightFade*ne)}return t?x.linkHighlight||x.linkColorScheme?x.linkHighlight?x.linkColorScheme?ge[x.linkColorScheme][x.linkHighlight](ne):ge[ve(e,n)][x.linkHighlight](ne):lt(x.linkColorScheme,r):lt(ve(e,n),r):ge[x.linkColorScheme][x.backgroundColor](x.highlightFade*ne)}(t,r,l,H)},linkWidth:function(e){if(1===x.highlightLinkSize)return x.linkWidth;var n=it(e,U.current),t=it(e,he.current);return n||t?x.linkWidth*(1+ne*(x.highlightLinkSize-1)):x.linkWidth},linkDirectionalParticleWidth:x.particlesWidth,d3AlphaDecay:t.alphaDecay,d3AlphaMin:t.alphaMin,d3VelocityDecay:t.velocityDecay,onNodeClick:function(e,n){var t=e;W.onClose();var r=n.timeStamp-$.current<200;if($.current=n.timeStamp,r)return X("double",t,n);var i=$.current;return setTimeout((function(){if($.current===i)return X("click",t,n)}),200)},onBackgroundClick:function(){W.onClose(),z(null),0!==v.nodeIds.length&&m((function(e){return Kn(Kn({},e),{},{nodeIds:[]})}))},onNodeHover:function(e){x.highlight&&(D||(ue(),te(0)),z(e))},onNodeRightClick:function(e,n){X("right",e,n)},onNodeDrag:function(e){W.onClose(),z(e),Se(!0)},onNodeDragEnd:function(){z(null),Se(!1)}};return(0,C.jsxs)(w.xu,{overflow:"hidden",children:[W.isOpen&&(0,C.jsx)(_n,{scope:v,node:R,nodeType:null===R||void 0===R?void 0:R.id,background:!1,coordinates:B,handleLocal:M,menuClose:W.onClose.bind(W),webSocket:y,setPreviewNode:O}),u?(0,C.jsx)(et,Kn(Kn({ref:n},De),{},{nodeThreeObjectExtend:!0,backgroundColor:H.colors.white,nodeOpacity:x.nodeOpacity,nodeResolution:x.nodeResolution,linkOpacity:x.linkOpacity,nodeThreeObject:function(e){if(x.labels&&(!(x.labels<3)||de[e.id])){var n=new Un.Z(e.title.substring(0,40));return n.color=lt(x.labelTextColor,H),n.backgroundColor=lt(x.labelBackgroundColor,H),n.padding=2,n.textHeight=8,n}}})):(0,C.jsx)($n,Kn(Kn({ref:n},De),{},{linkLineDash:function(e){var n,t=e;return x.citeDashes&&null!==(n=t.type)&&void 0!==n&&n.includes("cite")?[x.citeDashLength,x.citeGapLength]:x.refDashes&&"ref"==t.type?[x.refDashLength,x.refGapLength]:null}}))]})}));function it(e,n){var t,r;return(null===(t=e.source)||void 0===t?void 0:t.id)===(null===n||void 0===n?void 0:n.id)||(null===(r=e.target)||void 0===r?void 0:r.id)===(null===n||void 0===n?void 0:n.id)}function ot(e){return["object"===typeof e.source?e.source.id:e.source,"object"===typeof e.target?e.target.id:e.target]}function lt(e,n){return e.split(".").reduce((function(e,n){return e[n]}),n.colors)}function st(e,n){return"rgba("+(e=e.replace("#","")).match(new RegExp("(.{"+e.length/3+"})","g")).map((function(n){return parseInt(e.length%2?n+n:n,16)})).concat(isFinite(n)?n:1).join(",")+")"}},45301:function(e,n,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/",function(){return t(78706)}])}},function(e){e.O(0,[774,737,874,573,446,340,888,179],(function(){return n=45301,e(e.s=n);var n}));var n=e.O();_N_E=n}]);