pi-weave 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,7 +83,7 @@ ${this.parser.parse(t)}</blockquote>
83
83
  ${t}</tr>
84
84
  `}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
85
85
  `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${Qe(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){let r=this.parser.parseInline(n),i=$l(t);if(i===null)return r;t=i;let o='<a href="'+t+'"';return e&&(o+=' title="'+Qe(e)+'"'),o+=">"+r+"</a>",o}image({href:t,title:e,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=$l(t);if(i===null)return Qe(n);t=i;let o=`<img src="${t}" alt="${Qe(n)}"`;return e&&(o+=` title="${Qe(e)}"`),o+=">",o}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:Qe(t.text)}},vo=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},He=class lo{options;renderer;textRenderer;constructor(e){this.options=e||At,this.options.renderer=this.options.renderer||new Sr,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new vo}static parse(e,n){return new lo(n).parse(e)}static parseInline(e,n){return new lo(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let a=i,s=this.options.extensions.renderers[a.type].call({parser:this},a);if(s!==!1||!["space","hr","heading","code","table","blockquote","list","checkbox","html","def","paragraph","text"].includes(a.type)){n+=s||"";continue}}let o=i;switch(o.type){case"space":{n+=this.renderer.space(o);break}case"hr":{n+=this.renderer.hr(o);break}case"heading":{n+=this.renderer.heading(o);break}case"code":{n+=this.renderer.code(o);break}case"table":{n+=this.renderer.table(o);break}case"blockquote":{n+=this.renderer.blockquote(o);break}case"list":{n+=this.renderer.list(o);break}case"checkbox":{n+=this.renderer.checkbox(o);break}case"html":{n+=this.renderer.html(o);break}case"def":{n+=this.renderer.def(o);break}case"paragraph":{n+=this.renderer.paragraph(o);break}case"text":{n+=this.renderer.text(o);break}default:{let a='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let r="";for(let i=0;i<e.length;i++){let o=e[i];if(this.options.extensions?.renderers?.[o.type]){let s=this.options.extensions.renderers[o.type].call({parser:this},o);if(s!==!1||!["escape","html","link","image","checkbox","strong","em","codespan","br","del","text"].includes(o.type)){r+=s||"";continue}}let a=o;switch(a.type){case"escape":{r+=n.text(a);break}case"html":{r+=n.html(a);break}case"link":{r+=n.link(a);break}case"image":{r+=n.image(a);break}case"checkbox":{r+=n.checkbox(a);break}case"strong":{r+=n.strong(a);break}case"em":{r+=n.em(a);break}case"codespan":{r+=n.codespan(a);break}case"br":{r+=n.br(a);break}case"del":{r+=n.del(a);break}case"text":{r+=n.text(a);break}default:{let s='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return r}},bn=class{options;block;constructor(t){this.options=t||At}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?Ue.lex:Ue.lexInline}provideParser(t=this.block){return t?He.parse:He.parseInline}},yo=class{defaults=uo();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=He;Renderer=Sr;TextRenderer=vo;Lexer=Ue;Tokenizer=Er;Hooks=bn;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let r of t)switch(n=n.concat(e.call(this,r)),r.type){case"table":{let i=r;for(let o of i.header)n=n.concat(this.walkTokens(o.tokens,e));for(let o of i.rows)for(let a of o)n=n.concat(this.walkTokens(a.tokens,e));break}case"list":{let i=r;n=n.concat(this.walkTokens(i.items,e));break}default:{let i=r;this.defaults.extensions?.childTokens?.[i.type]?this.defaults.extensions.childTokens[i.type].forEach(o=>{let a=i[o].flat(1/0);n=n.concat(this.walkTokens(a,e))}):i.tokens&&(n=n.concat(this.walkTokens(i.tokens,e)))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(i=>{if(!i.name)throw new Error("extension name required");if("renderer"in i){let o=e.renderers[i.name];o?e.renderers[i.name]=function(...a){let s=i.renderer.apply(this,a);return s===!1&&(s=o.apply(this,a)),s}:e.renderers[i.name]=i.renderer}if("tokenizer"in i){if(!i.level||i.level!=="block"&&i.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let o=e[i.level];o?o.unshift(i.tokenizer):e[i.level]=[i.tokenizer],i.start&&(i.level==="block"?e.startBlock?e.startBlock.push(i.start):e.startBlock=[i.start]:i.level==="inline"&&(e.startInline?e.startInline.push(i.start):e.startInline=[i.start]))}"childTokens"in i&&i.childTokens&&(e.childTokens[i.name]=i.childTokens)}),r.extensions=e),n.renderer){let i=this.defaults.renderer||new Sr(this.defaults);for(let o in n.renderer){if(!(o in i))throw new Error(`renderer '${o}' does not exist`);if(["options","parser"].includes(o))continue;let a=o,s=n.renderer[a],l=i[a];i[a]=(...u)=>{let c=s.apply(i,u);return c===!1&&(c=l.apply(i,u)),c||""}}r.renderer=i}if(n.tokenizer){let i=this.defaults.tokenizer||new Er(this.defaults);for(let o in n.tokenizer){if(!(o in i))throw new Error(`tokenizer '${o}' does not exist`);if(["options","rules","lexer"].includes(o))continue;let a=o,s=n.tokenizer[a],l=i[a];i[a]=(...u)=>{let c=s.apply(i,u);return c===!1&&(c=l.apply(i,u)),c}}r.tokenizer=i}if(n.hooks){let i=this.defaults.hooks||new bn;for(let o in n.hooks){if(!(o in i))throw new Error(`hook '${o}' does not exist`);if(["options","block"].includes(o))continue;let a=o,s=n.hooks[a],l=i[a];bn.passThroughHooks.has(o)?i[a]=u=>{if(this.defaults.async&&bn.passThroughHooksRespectAsync.has(o))return(async()=>{let h=await s.call(i,u);return l.call(i,h)})();let c=s.call(i,u);return l.call(i,c)}:i[a]=(...u)=>{if(this.defaults.async)return(async()=>{let h=await s.apply(i,u);return h===!1&&(h=await l.apply(i,u)),h})();let c=s.apply(i,u);return c===!1&&(c=l.apply(i,u)),c}}r.hooks=i}if(n.walkTokens){let i=this.defaults.walkTokens,o=n.walkTokens;r.walkTokens=function(a){let s=[];return s.push(o.call(this,a)),i&&(s=s.concat(i.call(this,a))),s}}this.defaults={...this.defaults,...r}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return Ue.lex(t,e??this.defaults)}parser(t,e){return He.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let r={...n},i={...this.defaults,...r},o=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return o(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(i.hooks&&(i.hooks.options=i,i.hooks.block=t),i.async)return(async()=>{let a=i.hooks?await i.hooks.preprocess(e):e,s=await(i.hooks?await i.hooks.provideLexer(t):t?Ue.lex:Ue.lexInline)(a,i),l=i.hooks?await i.hooks.processAllTokens(s):s;i.walkTokens&&await Promise.all(this.walkTokens(l,i.walkTokens));let u=await(i.hooks?await i.hooks.provideParser(t):t?He.parse:He.parseInline)(l,i);return i.hooks?await i.hooks.postprocess(u):u})().catch(o);try{i.hooks&&(e=i.hooks.preprocess(e));let a=(i.hooks?i.hooks.provideLexer(t):t?Ue.lex:Ue.lexInline)(e,i);i.hooks&&(a=i.hooks.processAllTokens(a)),i.walkTokens&&this.walkTokens(a,i.walkTokens);let s=(i.hooks?i.hooks.provideParser(t):t?He.parse:He.parseInline)(a,i);return i.hooks&&(s=i.hooks.postprocess(s)),s}catch(a){return o(a)}}}onError(t,e){return n=>{if(n.message+=`
86
- Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+Qe(n.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},Tt=new yo;function Y(t,e){return Tt.parse(t,e)}Y.options=Y.setOptions=function(t){return Tt.setOptions(t),Y.defaults=Tt.defaults,Wl(Y.defaults),Y};Y.getDefaults=uo;Y.defaults=At;function em(...t){return Tt.use(...t),Y.defaults=Tt.defaults,Wl(Y.defaults),Y}Y.use=em;Y.walkTokens=function(t,e){return Tt.walkTokens(t,e)};Y.parseInline=Tt.parseInline;Y.Parser=He;Y.parser=He.parse;Y.Renderer=Sr;Y.TextRenderer=vo;Y.Lexer=Ue;Y.lexer=Ue.lex;Y.Tokenizer=Er;Y.Hooks=bn;Y.parse=Y;var _k=Y.options,kk=Y.setOptions,Ek=Y.walkTokens,Sk=Y.parseInline;var Tk=He.parse,Ak=Ue.lex;function Re(t){if(t.kind==="external"&&t.detail.url){let e=t.detail.url.replace(/^[a-z]+:\/\//,"").replace(/^[^@\/]+@/,"").replace(/\.git$/,"").replace(/\/+$/,"");if(e)return e}return t.kind==="package"&&t.detail.manifest?`${t.label} (${t.detail.manifest})`:t.label}function tm(t){let e=new Map;for(let l of t.nodes)e.set(l.id,l);let n=new Map,r=new Map,i=new Set;for(let l of t.edges){if(l.kind==="contains"){let u=n.get(l.source);u?u.push(l.target):n.set(l.source,[l.target])}if(l.kind==="contains"||l.kind==="anchored-at"){let u=r.get(l.source);u?u.push(l.target):r.set(l.source,[l.target]),i.add(l.target)}}let o=l=>{if(!l.detail.path)return null;let u=l.detail.path,c=null,h=0,d=n.get("repository")??[];for(let f of d){let v=e.get(f);if(v&&v.kind==="module"&&v.detail.path){let m=v.detail.path;u.startsWith(m+"/")&&m.length>h&&(c=f,h=m.length)}}return c},a=new Map;for(let l of t.nodes){if(l.kind!=="entryPoint")continue;let u=o(l);if(u){let c=a.get(u);c?c.push(l.id):a.set(u,[l.id])}}let s=t.nodes.filter(l=>!i.has(l.id)).map(l=>l.id);return{byId:e,contains:n,tree:r,incoming:i,moduleEntries:a,roots:s}}function nu(t){let e=new Set;for(let n of t.edges)(n.kind==="contains"||n.kind==="anchored-at")&&e.add(n.target);return t.nodes.filter(n=>!e.has(n.id)).map(n=>n.id)}function nm(t){return t==="gitState"||t==="external"||t==="package"||t==="entryPoint"}function eu(t){return t?t.kind==="module"||t.id.startsWith("vfolder:"):!1}function rm(t,e){return t.slice().sort((n,r)=>{let i=e.get(n),o=e.get(r),a=eu(i),s=eu(o);if(a!==s)return a?-1:1;let l=Re(i),u=Re(o);return l.localeCompare(u)})}function tu(t,e,n){let r=Number(t);return Number.isFinite(r)?{kind:"count",n:r,unit:e,phrasing:n}:{kind:"text",text:n==="attribute"?`${e}=${t}`:`${t} ${e}`}}function im(t){switch(t.kind){case"note":return t.detail.updated?{kind:"relTime",iso:t.detail.updated}:null;case"module":return t.detail.files?tu(t.detail.files,"files","attribute"):null;case"gitState":return t.detail.commit?{kind:"commit",sha:t.detail.commit}:null;case"repository":return t.detail.files?tu(t.detail.files,"files","prose"):null;case"package":return t.detail.kind?{kind:"text",text:t.detail.kind}:null;case"entryPoint":return t.detail.summary?{kind:"text",text:"summary"}:null;default:return null}}function wo(t,e){let n=tm(t),{byId:r,tree:i,moduleEntries:o,roots:a}=n,s=v=>{let w=(i.get(v)??[]).filter(y=>{let _=r.get(y);if(!_||_.kind!=="entryPoint")return!0;for(let[,k]of o)if(k.includes(y))return!1;return!0}).concat(o.get(v)??[]);return w=w.filter(y=>r.has(y)),e.showInternals||(w=w.filter(y=>{let _=r.get(y);return!(_&&nm(_.kind))})),rm(w,r)},l=e.provFilter!==null||e.query.length>0,u=v=>!(e.provFilter!==null&&v.provenance!==e.provFilter||e.query.length>0&&!Re(v).toLowerCase().includes(e.query.toLowerCase())),c=new Set,h=v=>{let m=r.get(v),g=!1;for(let y of s(v))h(y)&&(g=!0);let w=u(m)||g;return w&&c.add(v),w};for(let v of a)h(v);let d=[],f=(v,m)=>{if(!c.has(v))return;let g=r.get(v),w=s(v),y=w.filter(k=>c.has(k)),_=l?y.length>0:e.expanded.has(v);if(d.push({id:v,depth:m,hasKids:w.length>0,expanded:_,label:Re(g),kind:g.kind,provenance:g.provenance,meta:im(g)}),_)for(let k of y)f(k,m+1)};for(let v of a)f(v,0);return d}function bo(t){if(!t.nodes.find(i=>i.kind==="vault"))return null;let n=t.nodes.some(i=>i.kind==="note"),r=t.nodes.some(i=>i.kind==="repository");return!n&&!r?"no notes yet — add one with the weave_note tool":null}function kn(t,e){if(!t)return"";let n=Date.parse(t);if(Number.isNaN(n))return"";let r=Math.max(0,Math.floor((e-n)/1e3));if(r<60)return"just now";let i=Math.floor(r/60);if(i<60)return`${i}m ago`;let o=Math.floor(i/60);if(o<24)return`${o}h ago`;let a=Math.floor(o/24);if(a<30)return`${a}d ago`;let s=Math.floor(a/30);return s<12?`${s}mo ago`:`${Math.floor(s/12)}y ago`}var om=7;function xo(t,e){if(t===null)return"";switch(t.kind){case"relTime":return kn(t.iso,e);case"count":return t.phrasing==="attribute"?`${t.unit}=${t.n}`:`${t.n} ${t.unit}`;case"commit":return t.sha.slice(0,om);case"text":return t.text}}var am=["title","description","path","size","slug","source","updated","created","tags","files","languages","branch","commit","uncommitted changes","captured","manifest","kind","url","summarized files","summarized by","summarized at","summary","dangling links","link references","warning","stale","preview","root","notes","state"];function _o(t,e){let n=new Map;for(let s of t.nodes)n.set(s.id,s);let r=n.get(e);if(!r)return null;let i=[];for(let s of am){let l=r.detail[s];l===void 0||l===""||i.push({id:`meta:${s}`,label:s,value:l})}let o=[];for(let s of t.edges){if(s.source!==e)continue;let l=n.get(s.target);l&&o.push({id:`link:${s.kind}:${s.target}`,target:s.target,label:`${s.kind} → ${Re(l)}`,kind:l.kind,provenance:l.provenance,direction:"link"})}let a=[];for(let s of t.edges){if(s.kind!=="links-to"||s.target!==e)continue;let l=n.get(s.source);l&&a.push({id:`backlink:${s.source}`,target:s.source,label:`← ${Re(l)}`,kind:l.kind,provenance:l.provenance,direction:"backlink"})}return{id:e,label:Re(r),kind:r.kind,provenance:r.provenance,meta:i,links:o,backlinks:a}}function Ar(t,e){let n=new Set([t]);for(let r of e)r.source===t&&n.add(r.target),r.target===t&&n.add(r.source);return n}var sm=["contains","anchored-at"];function lm(t){return sm.includes(t)}function Rr(t,e){let n=new Map;for(let d of t.nodes)n.set(d.id,d);let r=um(t,n),i=nu(t),o=new Set,a=d=>{if(!o.has(d)&&(o.add(d),!!e.has(d)))for(let f of r.get(d)??[])a(f)};for(let d of i)a(d);let s=new Map;for(let d of r.keys())s.set(d,cm(d,r));let l=new Map;for(let d of t.nodes)if(!(!o.has(d.id)||e.has(d.id)))for(let f of s.get(d.id)??[])!o.has(f)&&!l.has(f)&&l.set(f,d.id);for(let d of t.nodes)!o.has(d.id)&&!l.has(d.id)&&o.add(d.id);let u=new Map;for(let[d,f]of r){let v=s.get(d);u.set(d,{children:f,descendants:v,members:v.filter(m=>l.get(m)===d),provenance:dm(v,n),expanded:e.has(d)})}let c=new Set,h=[];for(let d of t.nodes)o.has(d.id)?h.push(d):c.add(d.id);return{nodes:h,edges:hm(t.edges,o,l),clusters:u,hidden:c,representative:l,roots:i}}function um(t,e){let n=new Map;for(let r of t.edges){if(!lm(r.kind)||!e.has(r.source)||!e.has(r.target))continue;let i=n.get(r.source);i===void 0?n.set(r.source,[r.target]):i.includes(r.target)||i.push(r.target)}return n}function cm(t,e){let n=[],r=new Set([t]),i=o=>{for(let a of e.get(o)??[])r.has(a)||(r.add(a),n.push(a),i(a))};return i(t),n}function dm(t,e){let n={human:0,agent:0,generated:0,none:0};for(let r of t){let i=e.get(r)?.provenance??null;i===null?n.none++:n[i]++}return n}function hm(t,e,n){let r=a=>e.has(a)?a:n.get(a),i=[],o=new Set;for(let a of t){let s=r(a.source),l=r(a.target);if(s===void 0||l===void 0||s===l)continue;let u=`${s}\0${l}\0${a.kind}`;o.has(u)||(o.add(u),i.push({source:s,target:l,kind:a.kind}))}return i}function ko(t){let e=new Map;for(let n of t){if(n.kind!=="links-to")continue;let r=e.get(n.target);r?r.push(n.source):e.set(n.target,[n.source])}return e}var Vt=[null,"human","agent","generated"];function ru(t=["vault","repository"]){return{expanded:new Set(t),showInternals:!1,provFilter:null,query:""}}function Rt(t){return{...t.model,danglingLinks:t.dangling}}function iu(t,e){return t===null?[]:wo(Rt(t),e)}var jt="vfolder:\0draft";function ou(t){return t.type==="vault"?"":t.type==="folder"?t.path:t.path.split("/").slice(0,-1).join("/")}function au(t,e){let n=e.trim();return n===""?null:t===""?n:`${t}/${n}`}function su(t,e){if(e===null)return[...t];let n={id:jt,depth:e===""?1:e.split("/").length+1,hasKids:!1,expanded:!1,label:"",kind:"module",provenance:null,meta:null};if(e==="")return[...t,n];let r=t.findIndex(o=>o.id===`vfolder:${e}`);if(r===-1)return[...t,n];let i=r+1;for(;i<t.length&&t[i].depth>t[r].depth;)i++;return[...t.slice(0,i),n,...t.slice(i)]}function To(t,e){let n=new Set(t.expanded);return n.delete(e)||n.add(e),{...t,expanded:n}}function Ao(t,e){if(t.expanded.has(e))return t;let n=new Set(t.expanded);return n.add(e),{...t,expanded:n}}function fm(t,e){if(!t.expanded.has(e))return t;let n=new Set(t.expanded);return n.delete(e),{...t,expanded:n}}function Ro(t){return t==="vault"?null:t.startsWith("vfolder:")?t.slice(8):void 0}function En(t){return t==="vault"?{type:"vault",path:""}:t.startsWith("note:")?{type:"note",path:t.slice(5)}:t.startsWith("vfolder:")?{type:"folder",path:t.slice(8)}:null}function Lr(t,e){return t===null?!1:e.type==="note"?t===`note:${e.path}`:e.type==="folder"?t===`vfolder:${e.path}`||t.startsWith(`vfolder:${e.path}/`)||t.startsWith(`note:${e.path}/`):!1}function Co(t){return t.type==="folder"}function lu(t,e,n){return Co(t)?n?`Delete “${e}” and everything in it`:"Delete…":"Delete"}function uu(t,e){return t.query===e?t:{...t,query:e}}function cu(t){let e=Vt.indexOf(t.provFilter),n=Vt[(e+1)%Vt.length]??null;return{...t,provFilter:n}}function du(t){return{...t,showInternals:!t.showInternals}}function Nr(t,e){return e===null?-1:t.findIndex(n=>n.id===e)}function So(t,e){return t[e]?.id??null}function Eo(t,e,n){if(t.length===0)return null;let r=Nr(t,e),i=r===-1?n>0?-1:t.length:r;return So(t,Math.min(t.length-1,Math.max(0,i+n)))}function pm(t,e){let n=Nr(t,e),r=n<=0?void 0:t[n];if(r===void 0)return null;for(let i of t.slice(0,n).reverse())if(i.depth<r.depth)return i.id;return null}var gm={j:"ArrowDown",k:"ArrowUp"};function mm(t){return gm[t]??t}function hu(t,e,n,r,i=!1){let o={state:e,selectedId:n,handled:!1};if(i)return o;let a=h=>({state:e,selectedId:h,handled:!0}),s=mm(r);if(s==="ArrowDown")return a(Eo(t,n,1));if(s==="ArrowUp")return a(Eo(t,n,-1));if(s==="Home")return a(So(t,0));if(s==="End")return a(So(t,t.length-1));if(s!=="ArrowRight"&&s!=="ArrowLeft")return o;let l=Nr(t,n),u=l===-1?void 0:t[l];if(u===void 0||n===null)return o;if(s==="ArrowRight")return u.hasKids?u.expanded?a(Eo(t,n,1)):{state:Ao(e,n),selectedId:n,handled:!0}:o;if(u.hasKids&&u.expanded)return{state:fm(e,n),selectedId:n,handled:!0};let c=pm(t,n);return c===null?o:a(c)}var vm={vault:"vault",note:"note",repository:"repository",module:"module",package:"package",entryPoint:"entryPoint",gitState:"gitState",external:"external",file:"file"};function Lo(t){return vm[t]}var ym={human:"●",agent:"◐",generated:"○"};function Ct(t){return t===null?"":ym[t]}function qt(t){return t===null?"":`${t}-authored`}function fu(t){return`weave-row-${t.replace(/[^A-Za-z0-9_-]/g,"-")}`}function wm(t){let e=t.map(()=>({posinset:1,setsize:1})),n=[],r=i=>{for(let o of n.splice(i+1))for(let[a,s]of o.entries())e[s]={posinset:a+1,setsize:o.length}};for(let[i,o]of t.entries()){r(o.depth);let a=n[o.depth];if(a===void 0){for(a=[];n.length<o.depth;)n.push([]);n.push(a)}a.push(i)}return r(-1),e}function bm(t,e,n,r={posinset:1,setsize:1}){let i=t.hasKids?t.expanded?"open":"closed":"leaf";return{id:t.id,domId:fu(t.id),posinset:r.posinset,setsize:r.setsize,depth:t.depth,label:t.label,kind:t.kind,kindIcon:Lo(t.kind),provenance:t.provenance,provenanceGlyph:Ct(t.provenance),provenanceTitle:qt(t.provenance),twisty:i,hasKids:t.hasKids,expanded:t.expanded,selected:t.id===e,meta:xo(t.meta,n),level:t.depth+1}}function pu(t,e,n){let r=wm(t);return t.map((i,o)=>bm(i,e,n,r[o]))}function gu(t,e){return Nr(t,e)===-1?null:fu(e)}function mu(t){return{"--weave-depth":String(Math.max(0,t))}}function Cr(t){return t===null?"all":t}function vu(t){let e=Vt.indexOf(t),n=Vt[(e+1)%Vt.length]??null;return`provenance filter: ${Cr(t)} — click for ${Cr(n)}`}function yu(t){return t?"internals":"knowledge"}function wu(t){return t?"showing git state, packages, externals and entry points — click to hide":"hiding git state, packages, externals and entry points — click to show"}var bu="filter…",xu="Vault and repository",_u="Filter the tree",ku="Filter the tree (/)";function Eu(t,e,n){if(t===null)return"loading…";let r=bo(Rt(t));return r!==null?r:e.length>0?null:n.query.length>0||n.provFilter!==null?"nothing matches this filter — clear it to see the whole vault":"nothing to show"}function Su(t){return t.length===1?"1 row":`${t.length} rows`}var Au={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},xm=new RegExp(`[${Object.keys(Au).join("")}]`,"g");function Ce(t){return t.replace(xm,e=>Au[e])}var _m=["http:","https:","mailto:"],Ru=/^[a-z][a-z0-9+.-]*:/i,Cu=/[\u0000-\u0020\u00a0\u1680\u180e\u2000-\u2029\u205f\u3000]/g;function Tu(t){let e=t.replace(Cu,""),n=Ru.exec(e);return n===null?e===""?null:t:_m.includes(n[0].toLowerCase())?t:null}var rt="data-weave-target",Dr="note:",km={bySpelling:new Map,hasGhosts:!1,currentSlug:null};function Em(t){if(t.kind!=="note"||!t.id.startsWith(Dr))return null;let e=t.id.slice(Dr.length);return e===""?null:e}function Lu(t){if(t.kind!=="file"||!t.id.startsWith("artifact:"))return null;let e=t.detail.path;return e!==void 0&&/\.html?$/i.test(e)?e:null}function Nu(t){let e=Lu(t);return e===null?null:`${e}:${t.detail.updated??""}`}function Du(t,e){if(t===null||e===null)return null;let n=t.model.nodes.find(r=>r.id===e);return n===void 0?null:Lu(n)}function Pu(t,e){if(t===null)return km;let n=new Map;for(let i of t.model.nodes){let o=Em(i);if(o!==null)for(let a of[o,i.label])n.set(a,o),n.set(a.toLowerCase(),o)}let r=e!==null&&(t.dangling[e]?.length??0)>0;return{bySpelling:n,hasGhosts:r,currentSlug:e}}function Iu(t,e){let n=e.trim();return t.bySpelling.get(n)??t.bySpelling.get(n.toLowerCase())??null}function Sm(t,e){if(t.currentSlug===null||Ru.test(e.replace(Cu,"")))return null;try{let n=new URL(e,`https://weave.invalid/${t.currentSlug}.md`);return n.origin!=="https://weave.invalid"||!n.pathname.toLowerCase().endsWith(".md")?null:Iu(t,decodeURIComponent(n.pathname.slice(1,-3)))}catch{return null}}function Tm(t){return t.hasGhosts}var Am=/^\[\[([^\][|]+)(?:\|([^\]]*))?\]\]/;function Rm(t){let e=t.indexOf("[[");return e===-1?void 0:e}function Cm(t){return{name:"wikilink",level:"inline",start:Rm,tokenizer(e){return Nm(e)},renderer(e){return Lm(t,e)}}}function Lm(t,e){let n=typeof e.target=="string"?e.target:"",r=typeof e.alias=="string"?e.alias:"";return Dm(t,n,r)}function Nm(t){let e=Am.exec(t);if(e!==null)return{type:"wikilink",raw:e[0],target:e[1],alias:e[2]??""}}function Dm(t,e,n){let r=Ce((n===""?e:n).trim());if(r==="")return"";let i=Iu(t,e);return i!==null?`<a class="weave-wiki" ${rt}="${Ce(i)}" role="link" tabindex="0" title="${Ce(e.trim())}">${r}</a>`:Tm(t)?`<span class="weave-wiki weave-wiki-ghost" title="no note named ${Ce(e.trim())}">${r}</span>`:r}function Pm(t){return new yo({gfm:!0,async:!1,extensions:[Cm(t)],renderer:{html({text:e}){return/^\s*<!--[\s\S]*?-->\s*$/.test(e)?"":Ce(e)},link({href:e,title:n,tokens:r}){let i=Tu(e),o=this.parser.parseInline(r),a=i===null?null:Sm(t,i);if(a!==null){let l=n==null||n===""?"":` title="${Ce(n)}"`;return`<a class="weave-wiki" ${rt}="${Ce(a)}" role="link" tabindex="0"${l}>${o}</a>`}return`<a${[i===null?"":` href="${Ce(i)}"`,n==null||n===""?"":` title="${Ce(n)}"`,i===null?"":' rel="noreferrer noopener" target="_blank"'].join("")}>${o}</a>`},image({href:e,title:n,text:r}){let i=Tu(e);if(i===null)return Ce(r);let o=n==null||n===""?"":` title="${Ce(n)}"`;return`<img src="${Ce(i)}" alt="${Ce(r)}"${o}>`}}})}function Im(t,e){return Pm(e).parse(t,{async:!1})}function Sn(t){return Object.freeze(t)}var Mm=Sn({ALLOWED_TAGS:Sn(["p","br","hr","h1","h2","h3","h4","h5","h6","em","strong","del","code","pre","blockquote","ul","ol","li","a","span","img","table","thead","tbody","tr","th","td","input"]),ALLOWED_ATTR:Sn(["href","src","alt","title","class","role","tabindex","colspan","rowspan","align","type","checked","disabled","start",rt]),ADD_URI_SAFE_ATTR:Sn([rt]),ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1,USE_PROFILES:Sn({html:!0})});function Mu(t,e,n){return t.sanitize(Im(e,n),Mm)}var Gu=32;function No(t){let e=t;for(let n=0;e!==null&&n<Gu;n++){let r=e.getAttribute(rt);if(r!==null&&r!=="")return`${Dr}${r}`;e=e.parentElement}return null}function Fu(t){if(!t||t.isCollapsed===!0)return!1;let e=t.toString;return(typeof e=="function"&&e!==Object.prototype.toString?e.call(t):"").length>0}var Ou="edited",zu="created",$u="Done",Uu="Save",Hu="Saving…",Bu="Note body",Ir="Discard unsaved changes to this note?";function Wu(t,e){return t!==e}function Ku(t,e){return t?"ignore":e===null?"edit":"navigate"}function Vu(t,e){return t===e}function ju(t,e){return e!==null&&e!==t}function qu(t,e){return{title:t.title,slug:t.slug,provenance:t.source,provenanceGlyph:Ct(t.source),provenanceTitle:qt(t.source),updated:kn(t.updated,e),updatedIso:t.updated,created:kn(t.created,e),createdIso:t.created,tags:t.tags}}function Yu(t){return`#${t}`}var Gm=200,Fm=8,Om="no note",Do="weave-preview";function Po(t){let e=t;for(let n=0;e!==null&&n<Gu;n++){let r=e.getAttribute(rt);if(r!==null&&r!=="")return{slug:r,text:(e.textContent??"").trim()};if((e.className??"").split(/\s+/).includes("weave-wiki-ghost"))return{slug:null,text:(e.textContent??"").trim()};e=e.parentElement}return null}function zm(t){return t.replace(/```[\s\S]*?(?:```|$)/g," ").replace(/~~~[\s\S]*?(?:~~~|$)/g," ").replace(/`([^`]*)`/g,"$1").replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[\[([^\]|]*)(?:\|([^\]]*))?\]\]/g,(e,n,r)=>r??n).replace(/<[^>]*>/g," ").replace(/^\s{0,3}#{1,6}\s+/gm,"").replace(/^\s{0,3}>\s?/gm,"").replace(/^\s{0,3}([-*_][ \t]?){3,}$/gm," ").replace(/^\s{0,3}[-*+]\s+/gm,"").replace(/^\s{0,3}\d+[.)]\s+/gm,"").replace(/[*_~]{1,3}([^*_~]*)[*_~]{1,3}/g,"$1").replace(/\s+/g," ").trim()}function $m(t,e=Gm){let n=zm(t);if(n.length<=e)return n;let r=n.lastIndexOf(" ",e);return`${r>0?n.slice(0,r):n.slice(0,e)}…`}function Xu(t,e){if(e.slug===null){let i=e.text===""?"this link":e.text;return{ghost:!0,title:i,kind:Om,text:`no note named “${i}” yet`}}let n=t?.model.nodes.find(i=>i.id===`note:${e.slug}`&&i.kind==="note");if(n===void 0)return null;let r=n.provenance===null?n.kind:`${n.kind} · ${qt(n.provenance)}`;return{ghost:!1,title:n.label,kind:r,text:$m(n.detail.preview??"")}}function Zu(t,e,n,r,i,o,a=Fm){let s=t+a,l=e+a;return s+n>i-a&&(s=t-a-n),l+r>o-a&&(l=e-a-r),s=Math.min(Math.max(s,a),Math.max(a,i-a-n)),l=Math.min(Math.max(l,a),Math.max(a,o-a-r)),{x:s,y:l}}var Pr={anchor:null,pointerX:0,pointerY:0};function Qu(t,e){switch(e.type){case"show":return e.anchor.slug===null&&e.anchor.text===""?t:{anchor:e.anchor,pointerX:e.x,pointerY:e.y};case"hide":return t.anchor===null?t:Pr;case"dismiss":return Pr}}function Ju(t,e){return e!==null?null:t===null?"Nothing open — search with ⌘K, or walk the tree with j and k.":t.startsWith(Dr)?"Loading…":"This node has no note body — see the context rail for what it connects to."}var ec="(prefers-color-scheme: light)";function Mr(t){return t==null||typeof t.matchMedia!="function"?"dark":t.matchMedia(ec).matches?"light":"dark"}function tc(t,e){if(typeof t.matchMedia!="function")return()=>{};let n=t.matchMedia(ec);if(typeof n.addEventListener!="function")return()=>{};let r=()=>e(n.matches?"light":"dark");return n.addEventListener("change",r),()=>n.removeEventListener("change",r)}function Um(t,e){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function Nt(t){var e=Um(t,"string");return typeof e=="symbol"?e:e+""}function le(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function nc(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Nt(r.key),r)}}function ue(t,e,n){return e&&nc(t.prototype,e),n&&nc(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function Lt(t){return Lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Lt(t)}function rc(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(rc=function(){return!!t})()}function Hm(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Bm(t,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Hm(t)}function _e(t,e,n){return e=Lt(e),Bm(t,rc()?Reflect.construct(e,n||[],Lt(t).constructor):e.apply(t,n))}function Io(t,e){return Io=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},Io(t,e)}function ke(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Io(t,e)}function Wm(t){if(Array.isArray(t))return t}function Km(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,i,o,a,s=[],l=!0,u=!1;try{if(o=(n=n.call(t)).next,e===0){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=o.call(n)).done)&&(s.push(r.value),s.length!==e);l=!0);}catch(c){u=!0,i=c}finally{try{if(!l&&n.return!=null&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw i}}return s}}function Gr(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function Oo(t,e){if(t){if(typeof t=="string")return Gr(t,e);var n={}.toString.call(t).slice(8,-1);return n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set"?Array.from(t):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Gr(t,e):void 0}}function Vm(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
86
+ Please report this to https://github.com/markedjs/marked.`,t){let r="<p>An error occurred:</p><pre>"+Qe(n.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(n);throw n}}},Tt=new yo;function Y(t,e){return Tt.parse(t,e)}Y.options=Y.setOptions=function(t){return Tt.setOptions(t),Y.defaults=Tt.defaults,Wl(Y.defaults),Y};Y.getDefaults=uo;Y.defaults=At;function em(...t){return Tt.use(...t),Y.defaults=Tt.defaults,Wl(Y.defaults),Y}Y.use=em;Y.walkTokens=function(t,e){return Tt.walkTokens(t,e)};Y.parseInline=Tt.parseInline;Y.Parser=He;Y.parser=He.parse;Y.Renderer=Sr;Y.TextRenderer=vo;Y.Lexer=Ue;Y.lexer=Ue.lex;Y.Tokenizer=Er;Y.Hooks=bn;Y.parse=Y;var _k=Y.options,kk=Y.setOptions,Ek=Y.walkTokens,Sk=Y.parseInline;var Tk=He.parse,Ak=Ue.lex;function Re(t){if(t.kind==="external"&&t.detail.url){let e=t.detail.url.replace(/^[a-z]+:\/\//,"").replace(/^[^@\/]+@/,"").replace(/\.git$/,"").replace(/\/+$/,"");if(e)return e}return t.kind==="package"&&t.detail.manifest?`${t.label} (${t.detail.manifest})`:t.label}function tm(t){let e=new Map;for(let l of t.nodes)e.set(l.id,l);let n=new Map,r=new Map,i=new Set;for(let l of t.edges){if(l.kind==="contains"){let u=n.get(l.source);u?u.push(l.target):n.set(l.source,[l.target])}if(l.kind==="contains"||l.kind==="anchored-at"){let u=r.get(l.source);u?u.push(l.target):r.set(l.source,[l.target]),i.add(l.target)}}let o=l=>{if(!l.detail.path)return null;let u=l.detail.path,c=null,h=0,d=n.get("repository")??[];for(let f of d){let v=e.get(f);if(v&&v.kind==="module"&&v.detail.path){let m=v.detail.path;u.startsWith(m+"/")&&m.length>h&&(c=f,h=m.length)}}return c},a=new Map;for(let l of t.nodes){if(l.kind!=="entryPoint")continue;let u=o(l);if(u){let c=a.get(u);c?c.push(l.id):a.set(u,[l.id])}}let s=t.nodes.filter(l=>!i.has(l.id)).map(l=>l.id);return{byId:e,contains:n,tree:r,incoming:i,moduleEntries:a,roots:s}}function nu(t){let e=new Set;for(let n of t.edges)(n.kind==="contains"||n.kind==="anchored-at")&&e.add(n.target);return t.nodes.filter(n=>!e.has(n.id)).map(n=>n.id)}function nm(t){return t==="gitState"||t==="external"||t==="package"||t==="entryPoint"}function eu(t){return t?t.kind==="module"||t.id.startsWith("vfolder:"):!1}function rm(t,e){return t.slice().sort((n,r)=>{let i=e.get(n),o=e.get(r),a=eu(i),s=eu(o);if(a!==s)return a?-1:1;let l=Re(i),u=Re(o);return l.localeCompare(u)})}function tu(t,e,n){let r=Number(t);return Number.isFinite(r)?{kind:"count",n:r,unit:e,phrasing:n}:{kind:"text",text:n==="attribute"?`${e}=${t}`:`${t} ${e}`}}function im(t){switch(t.kind){case"note":return t.detail.updated?{kind:"relTime",iso:t.detail.updated}:null;case"module":return t.detail.files?tu(t.detail.files,"files","attribute"):null;case"gitState":return t.detail.commit?{kind:"commit",sha:t.detail.commit}:null;case"repository":return t.detail.files?tu(t.detail.files,"files","prose"):null;case"package":return t.detail.kind?{kind:"text",text:t.detail.kind}:null;case"entryPoint":return t.detail.summary?{kind:"text",text:"summary"}:null;default:return null}}function wo(t,e){let n=tm(t),{byId:r,tree:i,moduleEntries:o,roots:a}=n,s=v=>{let w=(i.get(v)??[]).filter(y=>{let _=r.get(y);if(!_||_.kind!=="entryPoint")return!0;for(let[,k]of o)if(k.includes(y))return!1;return!0}).concat(o.get(v)??[]);return w=w.filter(y=>r.has(y)),e.showInternals||(w=w.filter(y=>{let _=r.get(y);return!(_&&nm(_.kind))})),rm(w,r)},l=e.provFilter!==null||e.query.length>0,u=v=>!(e.provFilter!==null&&v.provenance!==e.provFilter||e.query.length>0&&!Re(v).toLowerCase().includes(e.query.toLowerCase())),c=new Set,h=v=>{let m=r.get(v),g=!1;for(let y of s(v))h(y)&&(g=!0);let w=u(m)||g;return w&&c.add(v),w};for(let v of a)h(v);let d=[],f=(v,m)=>{if(!c.has(v))return;let g=r.get(v),w=s(v),y=w.filter(k=>c.has(k)),_=l?y.length>0:e.expanded.has(v);if(d.push({id:v,depth:m,hasKids:w.length>0,expanded:_,label:Re(g),kind:g.kind,provenance:g.provenance,meta:im(g)}),_)for(let k of y)f(k,m+1)};for(let v of a)f(v,0);return d}function bo(t){if(!t.nodes.find(i=>i.kind==="vault"))return null;let n=t.nodes.some(i=>i.kind==="note"),r=t.nodes.some(i=>i.kind==="repository");return!n&&!r?"no notes yet — add one with the weave_note tool":null}function kn(t,e){if(!t)return"";let n=Date.parse(t);if(Number.isNaN(n))return"";let r=Math.max(0,Math.floor((e-n)/1e3));if(r<60)return"just now";let i=Math.floor(r/60);if(i<60)return`${i}m ago`;let o=Math.floor(i/60);if(o<24)return`${o}h ago`;let a=Math.floor(o/24);if(a<30)return`${a}d ago`;let s=Math.floor(a/30);return s<12?`${s}mo ago`:`${Math.floor(s/12)}y ago`}var om=7;function xo(t,e){if(t===null)return"";switch(t.kind){case"relTime":return kn(t.iso,e);case"count":return t.phrasing==="attribute"?`${t.unit}=${t.n}`:`${t.n} ${t.unit}`;case"commit":return t.sha.slice(0,om);case"text":return t.text}}var am=["title","description","path","size","slug","source","updated","created","tags","files","languages","branch","commit","uncommitted changes","captured","manifest","kind","url","summarized files","summarized by","summarized at","summary","dangling links","link references","warning","stale","preview","root","notes","state"];function _o(t,e){let n=new Map;for(let s of t.nodes)n.set(s.id,s);let r=n.get(e);if(!r)return null;let i=[];for(let s of am){let l=r.detail[s];l===void 0||l===""||i.push({id:`meta:${s}`,label:s,value:l})}let o=[];for(let s of t.edges){if(s.source!==e)continue;let l=n.get(s.target);l&&o.push({id:`link:${s.kind}:${s.target}`,target:s.target,label:`${s.kind} → ${Re(l)}`,kind:l.kind,provenance:l.provenance,direction:"link"})}let a=[];for(let s of t.edges){if(s.kind!=="links-to"||s.target!==e)continue;let l=n.get(s.source);l&&a.push({id:`backlink:${s.source}`,target:s.source,label:`← ${Re(l)}`,kind:l.kind,provenance:l.provenance,direction:"backlink"})}return{id:e,label:Re(r),kind:r.kind,provenance:r.provenance,meta:i,links:o,backlinks:a}}function Ar(t,e){let n=new Set([t]);for(let r of e)r.source===t&&n.add(r.target),r.target===t&&n.add(r.source);return n}var sm=["contains","anchored-at"];function lm(t){return sm.includes(t)}function Rr(t,e){let n=new Map;for(let d of t.nodes)n.set(d.id,d);let r=um(t,n),i=nu(t),o=new Set,a=d=>{if(!o.has(d)&&(o.add(d),!!e.has(d)))for(let f of r.get(d)??[])a(f)};for(let d of i)a(d);let s=new Map;for(let d of r.keys())s.set(d,cm(d,r));let l=new Map;for(let d of t.nodes)if(!(!o.has(d.id)||e.has(d.id)))for(let f of s.get(d.id)??[])!o.has(f)&&!l.has(f)&&l.set(f,d.id);for(let d of t.nodes)!o.has(d.id)&&!l.has(d.id)&&o.add(d.id);let u=new Map;for(let[d,f]of r){let v=s.get(d);u.set(d,{children:f,descendants:v,members:v.filter(m=>l.get(m)===d),provenance:dm(v,n),expanded:e.has(d)})}let c=new Set,h=[];for(let d of t.nodes)o.has(d.id)?h.push(d):c.add(d.id);return{nodes:h,edges:hm(t.edges,o,l),clusters:u,hidden:c,representative:l,roots:i}}function um(t,e){let n=new Map;for(let r of t.edges){if(!lm(r.kind)||!e.has(r.source)||!e.has(r.target))continue;let i=n.get(r.source);i===void 0?n.set(r.source,[r.target]):i.includes(r.target)||i.push(r.target)}return n}function cm(t,e){let n=[],r=new Set([t]),i=o=>{for(let a of e.get(o)??[])r.has(a)||(r.add(a),n.push(a),i(a))};return i(t),n}function dm(t,e){let n={human:0,agent:0,generated:0,none:0};for(let r of t){let i=e.get(r)?.provenance??null;i===null?n.none++:n[i]++}return n}function hm(t,e,n){let r=a=>e.has(a)?a:n.get(a),i=[],o=new Set;for(let a of t){let s=r(a.source),l=r(a.target);if(s===void 0||l===void 0||s===l)continue;let u=`${s}\0${l}\0${a.kind}`;o.has(u)||(o.add(u),i.push({source:s,target:l,kind:a.kind}))}return i}function ko(t){let e=new Map;for(let n of t){if(n.kind!=="links-to")continue;let r=e.get(n.target);r?r.push(n.source):e.set(n.target,[n.source])}return e}var Vt=[null,"human","agent","generated"];function ru(t=["vault","repository"]){return{expanded:new Set(t),showInternals:!1,provFilter:null,query:""}}function Rt(t){return{...t.model,danglingLinks:t.dangling}}function iu(t,e){return t===null?[]:wo(Rt(t),e)}var jt="vfolder:\0draft";function ou(t){return t.type==="vault"?"":t.type==="folder"?t.path:t.path.split("/").slice(0,-1).join("/")}function au(t,e){let n=e.trim();return n===""?null:t===""?n:`${t}/${n}`}function su(t,e){if(e===null)return[...t];let n={id:jt,depth:e===""?1:e.split("/").length+1,hasKids:!1,expanded:!1,label:"",kind:"module",provenance:null,meta:null};if(e==="")return[...t,n];let r=t.findIndex(o=>o.id===`vfolder:${e}`);if(r===-1)return[...t,n];let i=r+1;for(;i<t.length&&t[i].depth>t[r].depth;)i++;return[...t.slice(0,i),n,...t.slice(i)]}function To(t,e){let n=new Set(t.expanded);return n.delete(e)||n.add(e),{...t,expanded:n}}function Ao(t,e){if(t.expanded.has(e))return t;let n=new Set(t.expanded);return n.add(e),{...t,expanded:n}}function fm(t,e){if(!t.expanded.has(e))return t;let n=new Set(t.expanded);return n.delete(e),{...t,expanded:n}}function Ro(t){return t==="vault"?null:t.startsWith("vfolder:")?t.slice(8):void 0}function En(t){return t==="vault"?{type:"vault",path:""}:t.startsWith("note:")?{type:"note",path:t.slice(5)}:t.startsWith("vfolder:")?{type:"folder",path:t.slice(8)}:null}function Lr(t,e){return t===null?!1:e.type==="note"?t===`note:${e.path}`:e.type==="folder"?t===`vfolder:${e.path}`||t.startsWith(`vfolder:${e.path}/`)||t.startsWith(`note:${e.path}/`):!1}function Co(t){return t.type==="folder"}function lu(t,e,n){return Co(t)?n?`Delete “${e}” and everything in it`:"Delete…":"Delete"}function uu(t,e){return t.query===e?t:{...t,query:e}}function cu(t){let e=Vt.indexOf(t.provFilter),n=Vt[(e+1)%Vt.length]??null;return{...t,provFilter:n}}function du(t){return{...t,showInternals:!t.showInternals}}function Nr(t,e){return e===null?-1:t.findIndex(n=>n.id===e)}function So(t,e){return t[e]?.id??null}function Eo(t,e,n){if(t.length===0)return null;let r=Nr(t,e),i=r===-1?n>0?-1:t.length:r;return So(t,Math.min(t.length-1,Math.max(0,i+n)))}function pm(t,e){let n=Nr(t,e),r=n<=0?void 0:t[n];if(r===void 0)return null;for(let i of t.slice(0,n).reverse())if(i.depth<r.depth)return i.id;return null}var gm={j:"ArrowDown",k:"ArrowUp"};function mm(t){return gm[t]??t}function hu(t,e,n,r,i=!1){let o={state:e,selectedId:n,handled:!1};if(i)return o;let a=h=>({state:e,selectedId:h,handled:!0}),s=mm(r);if(s==="ArrowDown")return a(Eo(t,n,1));if(s==="ArrowUp")return a(Eo(t,n,-1));if(s==="Home")return a(So(t,0));if(s==="End")return a(So(t,t.length-1));if(s!=="ArrowRight"&&s!=="ArrowLeft")return o;let l=Nr(t,n),u=l===-1?void 0:t[l];if(u===void 0||n===null)return o;if(s==="ArrowRight")return u.hasKids?u.expanded?a(Eo(t,n,1)):{state:Ao(e,n),selectedId:n,handled:!0}:o;if(u.hasKids&&u.expanded)return{state:fm(e,n),selectedId:n,handled:!0};let c=pm(t,n);return c===null?o:a(c)}var vm={vault:"vault",note:"note",repository:"repository",module:"module",package:"package",entryPoint:"entryPoint",gitState:"gitState",external:"external",file:"file"};function Lo(t){return vm[t]}var ym={human:"●",agent:"◐",generated:"○"};function Ct(t){return t===null?"":ym[t]}function qt(t){return t===null?"":`${t}-authored`}function fu(t){return`weave-row-${t.replace(/[^A-Za-z0-9_-]/g,"-")}`}function wm(t){let e=t.map(()=>({posinset:1,setsize:1})),n=[],r=i=>{for(let o of n.splice(i+1))for(let[a,s]of o.entries())e[s]={posinset:a+1,setsize:o.length}};for(let[i,o]of t.entries()){r(o.depth);let a=n[o.depth];if(a===void 0){for(a=[];n.length<o.depth;)n.push([]);n.push(a)}a.push(i)}return r(-1),e}function bm(t,e,n,r={posinset:1,setsize:1}){let i=t.hasKids?t.expanded?"open":"closed":"leaf";return{id:t.id,domId:fu(t.id),posinset:r.posinset,setsize:r.setsize,depth:t.depth,label:t.label,kind:t.kind,kindIcon:Lo(t.kind),provenance:t.provenance,provenanceGlyph:Ct(t.provenance),provenanceTitle:qt(t.provenance),twisty:i,hasKids:t.hasKids,expanded:t.expanded,selected:t.id===e,meta:xo(t.meta,n),level:t.depth+1}}function pu(t,e,n){let r=wm(t);return t.map((i,o)=>bm(i,e,n,r[o]))}function gu(t,e){return Nr(t,e)===-1?null:fu(e)}function mu(t){return{"--weave-depth":String(Math.max(0,t))}}function Cr(t){return t===null?"all":t}function vu(t){let e=Vt.indexOf(t),n=Vt[(e+1)%Vt.length]??null;return`provenance filter: ${Cr(t)} — click for ${Cr(n)}`}function yu(t){return t?"internals":"knowledge"}function wu(t){return t?"showing git state, packages, externals and entry points — click to hide":"hiding git state, packages, externals and entry points — click to show"}var bu="filter…",xu="Vault and repository",_u="Filter the tree",ku="Filter the tree (/)";function Eu(t,e,n){if(t===null)return"loading…";let r=bo(Rt(t));return r!==null?r:e.length>0?null:n.query.length>0||n.provFilter!==null?"nothing matches this filter — clear it to see the whole vault":"nothing to show"}function Su(t){return t.length===1?"1 row":`${t.length} rows`}var Au={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},xm=new RegExp(`[${Object.keys(Au).join("")}]`,"g");function Ce(t){return t.replace(xm,e=>Au[e])}var _m=["http:","https:","mailto:"],Ru=/^[a-z][a-z0-9+.-]*:/i,Cu=/[\u0000-\u0020\u00a0\u1680\u180e\u2000-\u2029\u205f\u3000]/g;function Tu(t){let e=t.replace(Cu,""),n=Ru.exec(e);return n===null?e===""?null:t:_m.includes(n[0].toLowerCase())?t:null}var rt="data-weave-target",Dr="note:",km={bySpelling:new Map,hasGhosts:!1,currentSlug:null};function Em(t){if(t.kind!=="note"||!t.id.startsWith(Dr))return null;let e=t.id.slice(Dr.length);return e===""?null:e}function Lu(t){if(t.kind!=="file"||!t.id.startsWith("artifact:"))return null;let e=t.detail.path;return e!==void 0&&/\.html?$/i.test(e)?e:null}function Nu(t){let e=Lu(t);return e===null?null:`${e}:${t.detail.updated??""}`}function Du(t,e){if(t===null||e===null)return null;let n=t.model.nodes.find(r=>r.id===e);return n===void 0?null:Lu(n)}function Pu(t,e){if(t===null)return km;let n=new Map;for(let i of t.model.nodes){let o=Em(i);if(o!==null)for(let a of[o,i.label])n.set(a,o),n.set(a.toLowerCase(),o)}let r=e!==null&&(t.dangling[e]?.length??0)>0;return{bySpelling:n,hasGhosts:r,currentSlug:e}}function Iu(t,e){let n=e.trim();return t.bySpelling.get(n)??t.bySpelling.get(n.toLowerCase())??null}function Sm(t,e){if(t.currentSlug===null||Ru.test(e.replace(Cu,"")))return null;try{let n=new URL(e,`https://weave.invalid/${t.currentSlug}.md`);return n.origin!=="https://weave.invalid"||!n.pathname.toLowerCase().endsWith(".md")?null:Iu(t,decodeURIComponent(n.pathname.slice(1,-3)))}catch{return null}}function Tm(t){return t.hasGhosts}var Am=/^\[\[([^\][|]+)(?:\|([^\]]*))?\]\]/;function Rm(t){let e=t.indexOf("[[");return e===-1?void 0:e}function Cm(t){return{name:"wikilink",level:"inline",start:Rm,tokenizer(e){return Nm(e)},renderer(e){return Lm(t,e)}}}function Lm(t,e){let n=typeof e.target=="string"?e.target:"",r=typeof e.alias=="string"?e.alias:"";return Dm(t,n,r)}function Nm(t){let e=Am.exec(t);if(e!==null)return{type:"wikilink",raw:e[0],target:e[1],alias:e[2]??""}}function Dm(t,e,n){let r=Ce((n===""?e:n).trim());if(r==="")return"";let i=Iu(t,e);return i!==null?`<a class="weave-wiki" ${rt}="${Ce(i)}" role="link" tabindex="0" title="${Ce(e.trim())}">${r}</a>`:Tm(t)?`<span class="weave-wiki weave-wiki-ghost" title="no note named ${Ce(e.trim())}">${r}</span>`:r}function Pm(t){return new yo({gfm:!0,async:!1,extensions:[Cm(t)],renderer:{html({text:e}){return/^\s*<!--[\s\S]*?-->\s*$/.test(e)?"":Ce(e)},link({href:e,title:n,tokens:r}){let i=Tu(e),o=this.parser.parseInline(r),a=i===null?null:Sm(t,i);if(a!==null){let l=n==null||n===""?"":` title="${Ce(n)}"`;return`<a class="weave-wiki" ${rt}="${Ce(a)}" role="link" tabindex="0"${l}>${o}</a>`}return`<a${[i===null?"":` href="${Ce(i)}"`,n==null||n===""?"":` title="${Ce(n)}"`,i===null?"":' rel="noreferrer noopener" target="_blank"'].join("")}>${o}</a>`},image({href:e,title:n,text:r}){let i=Tu(e);if(i===null)return Ce(r);let o=n==null||n===""?"":` title="${Ce(n)}"`;return`<img src="${Ce(i)}" alt="${Ce(r)}"${o}>`}}})}function Im(t,e){return Pm(e).parse(t,{async:!1})}function Sn(t){return Object.freeze(t)}var Mm=Sn({ALLOWED_TAGS:Sn(["p","br","hr","h1","h2","h3","h4","h5","h6","em","strong","del","code","pre","blockquote","ul","ol","li","a","span","img","table","thead","tbody","tr","th","td","input"]),ALLOWED_ATTR:Sn(["href","src","alt","title","class","role","tabindex","colspan","rowspan","align","type","checked","disabled","start",rt]),ADD_URI_SAFE_ATTR:Sn([rt]),ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!1,ALLOW_UNKNOWN_PROTOCOLS:!1,USE_PROFILES:Sn({html:!0})});function Mu(t,e,n){return t.sanitize(Im(e,n),Mm)}var Gu=32;function No(t){let e=t;for(let n=0;e!==null&&n<Gu;n++){let r=e.getAttribute(rt);if(r!==null&&r!=="")return`${Dr}${r}`;e=e.parentElement}return null}function Fu(t){if(!t||t.isCollapsed===!0)return!1;let e=t.toString;return(typeof e=="function"&&e!==Object.prototype.toString?e.call(t):"").length>0}var Ou="edited",zu="created",$u="Done",Uu="Save",Hu="Saving…",Bu="Note body",Ir="Discard unsaved changes to this note?";function Wu(t,e){return t!==e}function Ku(t,e){return t?"ignore":e===null?"edit":"navigate"}function Vu(t,e){return t===e}function ju(t,e){return e!==null&&e!==t}function qu(t,e){return{title:t.title,slug:t.slug,provenance:t.source,provenanceGlyph:Ct(t.source),provenanceTitle:qt(t.source),updated:kn(t.updated,e),updatedIso:t.updated,created:kn(t.created,e),createdIso:t.created,tags:t.tags}}function Yu(t){return`#${t}`}var Gm=200,Fm=8,Om="no note",Do="weave-preview";function Po(t){let e=t;for(let n=0;e!==null&&n<Gu;n++){let r=e.getAttribute(rt);if(r!==null&&r!=="")return{slug:r,text:(e.textContent??"").trim()};if((e.className??"").split(/\s+/).includes("weave-wiki-ghost"))return{slug:null,text:(e.textContent??"").trim()};e=e.parentElement}return null}function zm(t){return t.replace(/```[\s\S]*?(?:```|$)/g," ").replace(/~~~[\s\S]*?(?:~~~|$)/g," ").replace(/`([^`]*)`/g,"$1").replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[\[([^\]|]*)(?:\|([^\]]*))?\]\]/g,(e,n,r)=>r??n).replace(/<[^>]*>/g," ").replace(/^\s{0,3}#{1,6}\s+/gm,"").replace(/^\s{0,3}>\s?/gm,"").replace(/^\s{0,3}([-*_][ \t]?){3,}$/gm," ").replace(/^\s{0,3}[-*+]\s+/gm,"").replace(/^\s{0,3}\d+[.)]\s+/gm,"").replace(/[*_~]{1,3}([^*_~]*)[*_~]{1,3}/g,"$1").replace(/\s+/g," ").trim()}function $m(t,e=Gm){let n=zm(t);if(n.length<=e)return n;let r=n.lastIndexOf(" ",e);return`${r>0?n.slice(0,r):n.slice(0,e)}…`}function Xu(t,e){if(e.slug===null){let i=e.text===""?"this link":e.text;return{ghost:!0,title:i,kind:Om,text:`no note named “${i}” yet`}}let n=t?.model.nodes.find(i=>i.id===`note:${e.slug}`&&i.kind==="note");if(n===void 0)return null;let r=n.provenance===null?n.kind:`${n.kind} · ${qt(n.provenance)}`;return{ghost:!1,title:n.label,kind:r,text:$m(n.detail.preview??"")}}function Zu(t,e,n,r,i,o,a=Fm){let s=t+a,l=e+a;return s+n>i-a&&(s=t-a-n),l+r>o-a&&(l=e-a-r),s=Math.min(Math.max(s,a),Math.max(a,i-a-n)),l=Math.min(Math.max(l,a),Math.max(a,o-a-r)),{x:s,y:l}}var Pr={anchor:null,pointerX:0,pointerY:0};function Qu(t,e){switch(e.type){case"show":return e.anchor.slug===null&&e.anchor.text===""?t:{anchor:e.anchor,pointerX:e.x,pointerY:e.y};case"hide":return t.anchor===null?t:Pr;case"dismiss":return Pr}}function Ju(t,e,n=!1){return e!==null?null:t===null?"Nothing open — search with ⌘K, or walk the tree with j and k.":n?"Couldn’t load this note — retrying…":t.startsWith(Dr)?"Loading…":"This node has no note body — see the context rail for what it connects to."}var ec="(prefers-color-scheme: light)";function Mr(t){return t==null||typeof t.matchMedia!="function"?"dark":t.matchMedia(ec).matches?"light":"dark"}function tc(t,e){if(typeof t.matchMedia!="function")return()=>{};let n=t.matchMedia(ec);if(typeof n.addEventListener!="function")return()=>{};let r=()=>e(n.matches?"light":"dark");return n.addEventListener("change",r),()=>n.removeEventListener("change",r)}function Um(t,e){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function Nt(t){var e=Um(t,"string");return typeof e=="symbol"?e:e+""}function le(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function nc(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Nt(r.key),r)}}function ue(t,e,n){return e&&nc(t.prototype,e),n&&nc(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function Lt(t){return Lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Lt(t)}function rc(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(rc=function(){return!!t})()}function Hm(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Bm(t,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Hm(t)}function _e(t,e,n){return e=Lt(e),Bm(t,rc()?Reflect.construct(e,n||[],Lt(t).constructor):e.apply(t,n))}function Io(t,e){return Io=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},Io(t,e)}function ke(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Io(t,e)}function Wm(t){if(Array.isArray(t))return t}function Km(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,i,o,a,s=[],l=!0,u=!1;try{if(o=(n=n.call(t)).next,e===0){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=o.call(n)).done)&&(s.push(r.value),s.length!==e);l=!0);}catch(c){u=!0,i=c}finally{try{if(!l&&n.return!=null&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw i}}return s}}function Gr(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function Oo(t,e){if(t){if(typeof t=="string")return Gr(t,e);var n={}.toString.call(t).slice(8,-1);return n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set"?Array.from(t):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Gr(t,e):void 0}}function Vm(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
87
87
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ft(t,e){return Wm(t)||Km(t,e)||Oo(t,e)||Vm()}var Mo={black:"#000000",silver:"#C0C0C0",gray:"#808080",grey:"#808080",white:"#FFFFFF",maroon:"#800000",red:"#FF0000",purple:"#800080",fuchsia:"#FF00FF",green:"#008000",lime:"#00FF00",olive:"#808000",yellow:"#FFFF00",navy:"#000080",blue:"#0000FF",teal:"#008080",aqua:"#00FFFF",darkblue:"#00008B",mediumblue:"#0000CD",darkgreen:"#006400",darkcyan:"#008B8B",deepskyblue:"#00BFFF",darkturquoise:"#00CED1",mediumspringgreen:"#00FA9A",springgreen:"#00FF7F",cyan:"#00FFFF",midnightblue:"#191970",dodgerblue:"#1E90FF",lightseagreen:"#20B2AA",forestgreen:"#228B22",seagreen:"#2E8B57",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",limegreen:"#32CD32",mediumseagreen:"#3CB371",turquoise:"#40E0D0",royalblue:"#4169E1",steelblue:"#4682B4",darkslateblue:"#483D8B",mediumturquoise:"#48D1CC",indigo:"#4B0082",darkolivegreen:"#556B2F",cadetblue:"#5F9EA0",cornflowerblue:"#6495ED",rebeccapurple:"#663399",mediumaquamarine:"#66CDAA",dimgray:"#696969",dimgrey:"#696969",slateblue:"#6A5ACD",olivedrab:"#6B8E23",slategray:"#708090",slategrey:"#708090",lightslategray:"#778899",lightslategrey:"#778899",mediumslateblue:"#7B68EE",lawngreen:"#7CFC00",chartreuse:"#7FFF00",aquamarine:"#7FFFD4",skyblue:"#87CEEB",lightskyblue:"#87CEFA",blueviolet:"#8A2BE2",darkred:"#8B0000",darkmagenta:"#8B008B",saddlebrown:"#8B4513",darkseagreen:"#8FBC8F",lightgreen:"#90EE90",mediumpurple:"#9370DB",darkviolet:"#9400D3",palegreen:"#98FB98",darkorchid:"#9932CC",yellowgreen:"#9ACD32",sienna:"#A0522D",brown:"#A52A2A",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",lightblue:"#ADD8E6",greenyellow:"#ADFF2F",paleturquoise:"#AFEEEE",lightsteelblue:"#B0C4DE",powderblue:"#B0E0E6",firebrick:"#B22222",darkgoldenrod:"#B8860B",mediumorchid:"#BA55D3",rosybrown:"#BC8F8F",darkkhaki:"#BDB76B",mediumvioletred:"#C71585",indianred:"#CD5C5C",peru:"#CD853F",chocolate:"#D2691E",tan:"#D2B48C",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",thistle:"#D8BFD8",orchid:"#DA70D6",goldenrod:"#DAA520",palevioletred:"#DB7093",crimson:"#DC143C",gainsboro:"#DCDCDC",plum:"#DDA0DD",burlywood:"#DEB887",lightcyan:"#E0FFFF",lavender:"#E6E6FA",darksalmon:"#E9967A",violet:"#EE82EE",palegoldenrod:"#EEE8AA",lightcoral:"#F08080",khaki:"#F0E68C",aliceblue:"#F0F8FF",honeydew:"#F0FFF0",azure:"#F0FFFF",sandybrown:"#F4A460",wheat:"#F5DEB3",beige:"#F5F5DC",whitesmoke:"#F5F5F5",mintcream:"#F5FFFA",ghostwhite:"#F8F8FF",salmon:"#FA8072",antiquewhite:"#FAEBD7",linen:"#FAF0E6",lightgoldenrodyellow:"#FAFAD2",oldlace:"#FDF5E6",magenta:"#FF00FF",deeppink:"#FF1493",orangered:"#FF4500",tomato:"#FF6347",hotpink:"#FF69B4",coral:"#FF7F50",darkorange:"#FF8C00",lightsalmon:"#FFA07A",orange:"#FFA500",lightpink:"#FFB6C1",pink:"#FFC0CB",gold:"#FFD700",peachpuff:"#FFDAB9",navajowhite:"#FFDEAD",moccasin:"#FFE4B5",bisque:"#FFE4C4",mistyrose:"#FFE4E1",blanchedalmond:"#FFEBCD",papayawhip:"#FFEFD5",lavenderblush:"#FFF0F5",seashell:"#FFF5EE",cornsilk:"#FFF8DC",lemonchiffon:"#FFFACD",floralwhite:"#FFFAF0",snow:"#FFFAFA",lightyellow:"#FFFFE0",ivory:"#FFFFF0"};var ic=new Int8Array(4),Go=new Int32Array(ic.buffer,0,1),jm=new Float32Array(ic.buffer,0,1),qm=/^\s*rgba?\s*\(/,Ym=/^\s*rgba?\s*\(\s*([0-9]*)\s*,\s*([0-9]*)\s*,\s*([0-9]*)(?:\s*,\s*(.*)?)?\)\s*$/;function Xm(t){var e=0,n=0,r=0,i=1;if(t[0]==="#")t.length===4?(e=parseInt(t.charAt(1)+t.charAt(1),16),n=parseInt(t.charAt(2)+t.charAt(2),16),r=parseInt(t.charAt(3)+t.charAt(3),16)):(e=parseInt(t.charAt(1)+t.charAt(2),16),n=parseInt(t.charAt(3)+t.charAt(4),16),r=parseInt(t.charAt(5)+t.charAt(6),16)),t.length===9&&(i=parseInt(t.charAt(7)+t.charAt(8),16)/255);else if(qm.test(t)){var o=t.match(Ym);o&&(e=+o[1],n=+o[2],r=+o[3],o[4]&&(i=+o[4]))}return{r:e,g:n,b:r,a:i}}var Yt={};for(Tn in Mo)Yt[Tn]=Xt(Mo[Tn]),Yt[Mo[Tn]]=Yt[Tn];var Tn;function oc(t,e,n,r,i){return Go[0]=r<<24|n<<16|e<<8|t,i&&(Go[0]=Go[0]&4278190079),jm[0]}function Xt(t){if(t=t.toLowerCase(),typeof Yt[t]<"u")return Yt[t];var e=Xm(t),n=e.r,r=e.g,i=e.b,o=e.a;o=o*255|0;var a=oc(n,r,i,o,!0);return Yt[t]=a,a}var Fo={};function zo(t){if(typeof Fo[t]<"u")return Fo[t];var e=(t&16711680)>>>16,n=(t&65280)>>>8,r=t&255,i=255,o=oc(e,n,r,i,!0);return Fo[t]=o,o}function $o(t,e,n,r){return n+(e<<8)+(t<<16)}function Uo(t,e,n,r,i,o){var a=Math.floor(n/o*i),s=Math.floor(t.drawingBufferHeight/o-r/o*i),l=new Uint8Array(4);t.bindFramebuffer(t.FRAMEBUFFER,e),t.readPixels(a,s,1,1,t.RGBA,t.UNSIGNED_BYTE,l);var u=ft(l,4),c=u[0],h=u[1],d=u[2],f=u[3];return[c,h,d,f]}function T(t,e,n){return(e=Nt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ac(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function G(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?ac(Object(n),!0).forEach(function(r){T(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ac(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Zm(t,e){for(;!{}.hasOwnProperty.call(t,e)&&(t=Lt(t))!==null;);return t}function Wo(){return Wo=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(t,e,n){var r=Zm(t,e);if(r){var i=Object.getOwnPropertyDescriptor(r,e);return i.get?i.get.call(arguments.length<3?t:n):i.value}},Wo.apply(null,arguments)}function fc(t,e,n,r){var i=Wo(Lt(1&r?t.prototype:t),e,n);return 2&r&&typeof i=="function"?function(o){return i.apply(n,o)}:i}function Qm(t){return t.normalized?1:t.size}function Ho(t){var e=0;return t.forEach(function(n){return e+=Qm(n)}),e}function pc(t,e,n){var r=t==="VERTEX"?e.VERTEX_SHADER:e.FRAGMENT_SHADER,i=e.createShader(r);if(i===null)throw new Error("loadShader: error while creating the shader");e.shaderSource(i,n),e.compileShader(i);var o=e.getShaderParameter(i,e.COMPILE_STATUS);if(!o){var a=e.getShaderInfoLog(i);throw e.deleteShader(i),new Error(`loadShader: error while compiling the shader:
88
88
  `.concat(a,`
89
89
  `).concat(n))}return i}function Jm(t,e){return pc("VERTEX",t,e)}function ev(t,e){return pc("FRAGMENT",t,e)}function tv(t,e){var n=t.createProgram();if(n===null)throw new Error("loadProgram: error while creating the program.");var r,i;for(r=0,i=e.length;r<i;r++)t.attachShader(n,e[r]);t.linkProgram(n);var o=t.getProgramParameter(n,t.LINK_STATUS);if(!o){var a=t.getProgramInfoLog(n);throw t.deleteProgram(n),new Error("loadProgram: error while linking the program: ".concat(a))}return n}function sc(t){var e=t.gl,n=t.buffer,r=t.program,i=t.vertexShader,o=t.fragmentShader;e.deleteShader(i),e.deleteShader(o),e.deleteProgram(r),e.deleteBuffer(n)}var lc=`#define PICKING_MODE
@@ -394,9 +394,9 @@ void main() {
394
394
  v_color.a *= bias;
395
395
  }
396
396
  `,kv=_v,Tc=WebGLRenderingContext,hc=Tc.UNSIGNED_BYTE,An=Tc.FLOAT,Ev=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness"],Ac=(function(t){function e(){return le(this,e),_e(this,e,arguments)}return ke(e,t),ue(e,[{key:"getDefinition",value:function(){return{VERTICES:6,VERTEX_SHADER_SOURCE:kv,FRAGMENT_SHADER_SOURCE:_c,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Ev,ATTRIBUTES:[{name:"a_positionStart",size:2,type:An},{name:"a_positionEnd",size:2,type:An},{name:"a_normal",size:2,type:An},{name:"a_color",size:4,type:hc,normalized:!0},{name:"a_id",size:4,type:hc,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:An},{name:"a_normalCoef",size:1,type:An}],CONSTANT_DATA:[[0,1],[0,-1],[1,1],[1,1],[0,-1],[1,-1]]}}},{key:"processVisibleItem",value:function(r,i,o,a,s){var l=s.size||1,u=o.x,c=o.y,h=a.x,d=a.y,f=Xt(s.color),v=h-u,m=d-c,g=v*v+m*m,w=0,y=0;g&&(g=1/Math.sqrt(g),w=-m*g*l,y=v*g*l);var _=this.array;_[i++]=u,_[i++]=c,_[i++]=h,_[i++]=d,_[i++]=w,_[i++]=y,_[i++]=f,_[i++]=r}},{key:"setUniforms",value:function(r,i){var o=i.gl,a=i.uniformLocations,s=a.u_matrix,l=a.u_zoomRatio,u=a.u_feather,c=a.u_pixelRatio,h=a.u_correctionRatio,d=a.u_sizeRatio,f=a.u_minEdgeThickness;o.uniformMatrix3fv(s,!1,r.matrix),o.uniform1f(l,r.zoomRatio),o.uniform1f(d,r.sizeRatio),o.uniform1f(h,r.correctionRatio),o.uniform1f(c,r.pixelRatio),o.uniform1f(u,r.antiAliasingFeather),o.uniform1f(f,r.minEdgeThickness)}}])})(Ko);var Oc=dn($r()),Ur=(function(t){function e(){var n;return le(this,e),n=_e(this,e),n.rawEmitter=n,n}return ke(e,t),ue(e)})(Oc.EventEmitter);var Hc=dn(qo());var Nv=function(e){return e},Dv=function(e){return e*e},Pv=function(e){return e*(2-e)},Iv=function(e){return(e*=2)<1?.5*e*e:-.5*(--e*(e-2)-1)},Mv=function(e){return e*e*e},Gv=function(e){return--e*e*e+1},Fv=function(e){return(e*=2)<1?.5*e*e*e:.5*((e-=2)*e*e+2)},Bc={linear:Nv,quadraticIn:Dv,quadraticOut:Pv,quadraticInOut:Iv,cubicIn:Mv,cubicOut:Gv,cubicInOut:Fv},Wc={easing:"quadraticInOut",duration:150};function Ie(){return Float32Array.of(1,0,0,0,1,0,0,0,1)}function Hr(t,e,n){return t[0]=e,t[4]=typeof n=="number"?n:e,t}function $c(t,e){var n=Math.sin(e),r=Math.cos(e);return t[0]=r,t[1]=n,t[3]=-n,t[4]=r,t}function Uc(t,e,n){return t[6]=e,t[7]=n,t}function pt(t,e){var n=t[0],r=t[1],i=t[2],o=t[3],a=t[4],s=t[5],l=t[6],u=t[7],c=t[8],h=e[0],d=e[1],f=e[2],v=e[3],m=e[4],g=e[5],w=e[6],y=e[7],_=e[8];return t[0]=h*n+d*o+f*l,t[1]=h*r+d*a+f*u,t[2]=h*i+d*s+f*c,t[3]=v*n+m*o+g*l,t[4]=v*r+m*a+g*u,t[5]=v*i+m*s+g*c,t[6]=w*n+y*o+_*l,t[7]=w*r+y*a+_*u,t[8]=w*i+y*s+_*c,t}function Br(t,e){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1,r=t[0],i=t[1],o=t[3],a=t[4],s=t[6],l=t[7],u=e.x,c=e.y;return{x:u*r+c*o+s*n,y:u*i+c*a+l*n}}function Ov(t,e){var n=t.height/t.width,r=e.height/e.width;return n<1&&r>1||n>1&&r<1?1:Math.min(Math.max(r,1/r),Math.max(1/n,n))}function Qt(t,e,n,r,i){var o=t.angle,a=t.ratio,s=t.x,l=t.y,u=e.width,c=e.height,h=Ie(),d=Math.min(u,c)-2*r,f=Ov(e,n);return i?(pt(h,Uc(Ie(),s,l)),pt(h,Hr(Ie(),a)),pt(h,$c(Ie(),o)),pt(h,Hr(Ie(),u/d/2/f,c/d/2/f))):(pt(h,Hr(Ie(),2*(d/u)*f,2*(d/c)*f)),pt(h,$c(Ie(),-o)),pt(h,Hr(Ie(),1/a)),pt(h,Uc(Ie(),-s,-l))),h}function Kc(t,e,n){var r=Br(t,{x:Math.cos(e.angle),y:Math.sin(e.angle)},0),i=r.x,o=r.y;return 1/Math.sqrt(Math.pow(i,2)+Math.pow(o,2))/n.width}function Vc(t){if(!t.order)return{x:[0,1],y:[0,1]};var e=1/0,n=-1/0,r=1/0,i=-1/0;return t.forEachNode(function(o,a){var s=a.x,l=a.y;s<e&&(e=s),s>n&&(n=s),l<r&&(r=l),l>i&&(i=l)}),{x:[e,n],y:[r,i]}}function jc(t){if(!(0,Hc.default)(t))throw new Error("Sigma: invalid graph instance.");t.forEachNode(function(e,n){if(!Number.isFinite(n.x)||!Number.isFinite(n.y))throw new Error("Sigma: Coordinates of node ".concat(e," are invalid. A node must have a numeric 'x' and 'y' attribute."))})}function qc(t,e,n){var r=document.createElement(t);if(e)for(var i in e)r.style[i]=e[i];if(n)for(var o in n)r.setAttribute(o,n[o]);return r}function Yo(){return typeof window.devicePixelRatio<"u"?window.devicePixelRatio:1}function Xo(t,e,n){return n.sort(function(r,i){var o=e(r)||0,a=e(i)||0;return o<a?-1:o>a?1:0})}function Zo(t){var e=ft(t.x,2),n=e[0],r=e[1],i=ft(t.y,2),o=i[0],a=i[1],s=Math.max(r-n,a-o),l=(r+n)/2,u=(a+o)/2;(s===0||Math.abs(s)===1/0||isNaN(s))&&(s=1),isNaN(l)&&(l=0),isNaN(u)&&(u=0);var c=function(d){return{x:.5+(d.x-l)/s,y:.5+(d.y-u)/s}};return c.applyTo=function(h){h.x=.5+(h.x-l)/s,h.y=.5+(h.y-u)/s},c.inverse=function(h){return{x:l+s*(h.x-.5),y:u+s*(h.y-.5)}},c.ratio=s,c}function Wr(t){"@babel/helpers - typeof";return Wr=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Wr(t)}function Qo(t,e){var n=e.size;if(n!==0){var r=t.length;t.length+=n;var i=0;e.forEach(function(o){t[r+i]=o,i++})}}function Kr(t){t=t||{};for(var e=0,n=arguments.length<=1?0:arguments.length-1;e<n;e++){var r=e+1<1||arguments.length<=e+1?void 0:arguments[e+1];r&&Object.assign(t,r)}return t}var Vr={hideEdgesOnMove:!1,hideLabelsOnMove:!1,renderLabels:!0,renderEdgeLabels:!1,enableEdgeEvents:!1,defaultNodeColor:"#999",defaultNodeType:"circle",defaultEdgeColor:"#ccc",defaultEdgeType:"line",labelFont:"Arial",labelSize:14,labelWeight:"normal",labelColor:{color:"#000"},edgeLabelFont:"Arial",edgeLabelSize:14,edgeLabelWeight:"normal",edgeLabelColor:{attribute:"color"},stagePadding:30,defaultDrawEdgeLabel:mc,defaultDrawNodeLabel:Vo,defaultDrawNodeHover:vc,minEdgeThickness:1.7,antiAliasingFeather:1,dragTimeout:100,draggedEventsTolerance:3,inertiaDuration:200,inertiaRatio:3,zoomDuration:250,zoomingRatio:1.7,doubleClickTimeout:300,doubleClickZoomingRatio:2.2,doubleClickZoomingDuration:200,tapMoveTolerance:10,zoomToSizeRatioFunction:Math.sqrt,itemSizesReference:"screen",autoRescale:!0,autoCenter:!0,labelDensity:1,labelGridCellSize:100,labelRenderedSizeThreshold:6,nodeReducer:null,edgeReducer:null,zIndex:!1,minCameraRatio:null,maxCameraRatio:null,enableCameraZooming:!0,enableCameraPanning:!0,enableCameraRotation:!0,cameraPanBoundaries:null,allowInvalidContainer:!1,nodeProgramClasses:{},nodeHoverProgramClasses:{},edgeProgramClasses:{}},zv={circle:Rn},$v={arrow:Sc,line:Ac};function jr(t){if(typeof t.labelDensity!="number"||t.labelDensity<0)throw new Error("Settings: invalid `labelDensity`. Expecting a positive number.");var e=t.minCameraRatio,n=t.maxCameraRatio;if(typeof e=="number"&&typeof n=="number"&&n<e)throw new Error("Settings: invalid camera ratio boundaries. Expecting `maxCameraRatio` to be greater than `minCameraRatio`.")}function Yc(t){var e=Kr({},Vr,t);return e.nodeProgramClasses=Kr({},zv,e.nodeProgramClasses),e.edgeProgramClasses=Kr({},$v,e.edgeProgramClasses),e}var AE=dn($r()),RE=dn(qo()),qr=1.5,Xc=(function(t){function e(){var n;return le(this,e),n=_e(this,e),T(n,"x",.5),T(n,"y",.5),T(n,"angle",0),T(n,"ratio",1),T(n,"minRatio",null),T(n,"maxRatio",null),T(n,"enabledZooming",!0),T(n,"enabledPanning",!0),T(n,"enabledRotation",!0),T(n,"clean",null),T(n,"nextFrame",null),T(n,"previousState",null),T(n,"enabled",!0),n.previousState=n.getState(),n}return ke(e,t),ue(e,[{key:"enable",value:function(){return this.enabled=!0,this}},{key:"disable",value:function(){return this.enabled=!1,this}},{key:"getState",value:function(){return{x:this.x,y:this.y,angle:this.angle,ratio:this.ratio}}},{key:"hasState",value:function(r){return this.x===r.x&&this.y===r.y&&this.ratio===r.ratio&&this.angle===r.angle}},{key:"getPreviousState",value:function(){var r=this.previousState;return r?{x:r.x,y:r.y,angle:r.angle,ratio:r.ratio}:null}},{key:"getBoundedRatio",value:function(r){var i=r;return typeof this.minRatio=="number"&&(i=Math.max(i,this.minRatio)),typeof this.maxRatio=="number"&&(i=Math.min(i,this.maxRatio)),i}},{key:"validateState",value:function(r){var i={};return this.enabledPanning&&typeof r.x=="number"&&(i.x=r.x),this.enabledPanning&&typeof r.y=="number"&&(i.y=r.y),this.enabledZooming&&typeof r.ratio=="number"&&(i.ratio=this.getBoundedRatio(r.ratio)),this.enabledRotation&&typeof r.angle=="number"&&(i.angle=r.angle),this.clean?this.clean(G(G({},this.getState()),i)):i}},{key:"isAnimated",value:function(){return!!this.nextFrame}},{key:"setState",value:function(r){if(!this.enabled)return this;this.previousState=this.getState();var i=this.validateState(r);return typeof i.x=="number"&&(this.x=i.x),typeof i.y=="number"&&(this.y=i.y),typeof i.ratio=="number"&&(this.ratio=i.ratio),typeof i.angle=="number"&&(this.angle=i.angle),this.hasState(this.previousState)||this.emit("updated",this.getState()),this}},{key:"updateState",value:function(r){return this.setState(r(this.getState())),this}},{key:"animate",value:function(r){var i=this,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=arguments.length>2?arguments[2]:void 0;if(!a)return new Promise(function(f){return i.animate(r,o,f)});if(this.enabled){var s=G(G({},Wc),o),l=this.validateState(r),u=typeof s.easing=="function"?s.easing:Bc[s.easing],c=Date.now(),h=this.getState(),d=function(){var v=(Date.now()-c)/s.duration;if(v>=1){i.nextFrame=null,i.setState(l),i.animationCallback&&(i.animationCallback.call(null),i.animationCallback=void 0);return}var m=u(v),g={};typeof l.x=="number"&&(g.x=h.x+(l.x-h.x)*m),typeof l.y=="number"&&(g.y=h.y+(l.y-h.y)*m),i.enabledRotation&&typeof l.angle=="number"&&(g.angle=h.angle+(l.angle-h.angle)*m),typeof l.ratio=="number"&&(g.ratio=h.ratio+(l.ratio-h.ratio)*m),i.setState(g),i.nextFrame=requestAnimationFrame(d)};this.nextFrame?(cancelAnimationFrame(this.nextFrame),this.animationCallback&&this.animationCallback.call(null),this.nextFrame=requestAnimationFrame(d)):d(),this.animationCallback=a}}},{key:"animatedZoom",value:function(r){return r?typeof r=="number"?this.animate({ratio:this.ratio/r}):this.animate({ratio:this.ratio/(r.factor||qr)},r):this.animate({ratio:this.ratio/qr})}},{key:"animatedUnzoom",value:function(r){return r?typeof r=="number"?this.animate({ratio:this.ratio*r}):this.animate({ratio:this.ratio*(r.factor||qr)},r):this.animate({ratio:this.ratio*qr})}},{key:"animatedReset",value:function(r){return this.animate({x:.5,y:.5,ratio:1,angle:0},r)}},{key:"copy",value:function(){return e.from(this.getState())}}],[{key:"from",value:function(r){var i=new e;return i.setState(r)}}])})(Ur);function Be(t,e){var n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}}function it(t,e){var n=G(G({},Be(t,e)),{},{sigmaDefaultPrevented:!1,preventSigmaDefault:function(){n.sigmaDefaultPrevented=!0},original:t});return n}function Cn(t){var e="x"in t?t:G(G({},t.touches[0]||t.previousTouches[0]),{},{original:t.original,sigmaDefaultPrevented:t.sigmaDefaultPrevented,preventSigmaDefault:function(){t.sigmaDefaultPrevented=!0,e.sigmaDefaultPrevented=!0}});return e}function Uv(t,e){return G(G({},it(t,e)),{},{delta:nd(t)})}var Hv=2;function Yr(t){for(var e=[],n=0,r=Math.min(t.length,Hv);n<r;n++)e.push(t[n]);return e}function Ln(t,e,n){var r={touches:Yr(t.touches).map(function(i){return Be(i,n)}),previousTouches:e.map(function(i){return Be(i,n)}),sigmaDefaultPrevented:!1,preventSigmaDefault:function(){r.sigmaDefaultPrevented=!0},original:t};return r}function nd(t){if(typeof t.deltaY<"u")return t.deltaY*-3/360;if(typeof t.detail<"u")return t.detail/-9;throw new Error("Captor: could not extract delta from event.")}var rd=(function(t){function e(n,r){var i;return le(this,e),i=_e(this,e),i.container=n,i.renderer=r,i}return ke(e,t),ue(e)})(Ur),Bv=["doubleClickTimeout","doubleClickZoomingDuration","doubleClickZoomingRatio","dragTimeout","draggedEventsTolerance","inertiaDuration","inertiaRatio","zoomDuration","zoomingRatio"],Wv=Bv.reduce(function(t,e){return G(G({},t),{},T({},e,Vr[e]))},{}),Kv=(function(t){function e(n,r){var i;return le(this,e),i=_e(this,e,[n,r]),T(i,"enabled",!0),T(i,"draggedEvents",0),T(i,"downStartTime",null),T(i,"lastMouseX",null),T(i,"lastMouseY",null),T(i,"isMouseDown",!1),T(i,"isMoving",!1),T(i,"movingTimeout",null),T(i,"startCameraState",null),T(i,"clicks",0),T(i,"doubleClickTimeout",null),T(i,"currentWheelDirection",0),T(i,"settings",Wv),i.handleClick=i.handleClick.bind(i),i.handleRightClick=i.handleRightClick.bind(i),i.handleDown=i.handleDown.bind(i),i.handleUp=i.handleUp.bind(i),i.handleMove=i.handleMove.bind(i),i.handleWheel=i.handleWheel.bind(i),i.handleLeave=i.handleLeave.bind(i),i.handleEnter=i.handleEnter.bind(i),n.addEventListener("click",i.handleClick,{capture:!1}),n.addEventListener("contextmenu",i.handleRightClick,{capture:!1}),n.addEventListener("mousedown",i.handleDown,{capture:!1}),n.addEventListener("wheel",i.handleWheel,{capture:!1}),n.addEventListener("mouseleave",i.handleLeave,{capture:!1}),n.addEventListener("mouseenter",i.handleEnter,{capture:!1}),document.addEventListener("mousemove",i.handleMove,{capture:!1}),document.addEventListener("mouseup",i.handleUp,{capture:!1}),i}return ke(e,t),ue(e,[{key:"kill",value:function(){var r=this.container;r.removeEventListener("click",this.handleClick),r.removeEventListener("contextmenu",this.handleRightClick),r.removeEventListener("mousedown",this.handleDown),r.removeEventListener("wheel",this.handleWheel),r.removeEventListener("mouseleave",this.handleLeave),r.removeEventListener("mouseenter",this.handleEnter),document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp)}},{key:"handleClick",value:function(r){var i=this;if(this.enabled){if(this.clicks++,this.clicks===2)return this.clicks=0,typeof this.doubleClickTimeout=="number"&&(clearTimeout(this.doubleClickTimeout),this.doubleClickTimeout=null),this.handleDoubleClick(r);setTimeout(function(){i.clicks=0,i.doubleClickTimeout=null},this.settings.doubleClickTimeout),this.draggedEvents<this.settings.draggedEventsTolerance&&this.emit("click",it(r,this.container))}}},{key:"handleRightClick",value:function(r){this.enabled&&this.emit("rightClick",it(r,this.container))}},{key:"handleDoubleClick",value:function(r){if(this.enabled){r.preventDefault(),r.stopPropagation();var i=it(r,this.container);if(this.emit("doubleClick",i),!i.sigmaDefaultPrevented){var o=this.renderer.getCamera(),a=o.getBoundedRatio(o.getState().ratio/this.settings.doubleClickZoomingRatio);o.animate(this.renderer.getViewportZoomedState(Be(r,this.container),a),{easing:"quadraticInOut",duration:this.settings.doubleClickZoomingDuration})}}}},{key:"handleDown",value:function(r){if(this.enabled){if(r.button===0){this.startCameraState=this.renderer.getCamera().getState();var i=Be(r,this.container),o=i.x,a=i.y;this.lastMouseX=o,this.lastMouseY=a,this.draggedEvents=0,this.downStartTime=Date.now(),this.isMouseDown=!0}this.emit("mousedown",it(r,this.container))}}},{key:"handleUp",value:function(r){var i=this;if(!(!this.enabled||!this.isMouseDown)){var o=this.renderer.getCamera();this.isMouseDown=!1,typeof this.movingTimeout=="number"&&(clearTimeout(this.movingTimeout),this.movingTimeout=null);var a=Be(r,this.container),s=a.x,l=a.y,u=o.getState(),c=o.getPreviousState()||{x:0,y:0};this.isMoving?o.animate({x:u.x+this.settings.inertiaRatio*(u.x-c.x),y:u.y+this.settings.inertiaRatio*(u.y-c.y)},{duration:this.settings.inertiaDuration,easing:"quadraticOut"}):(this.lastMouseX!==s||this.lastMouseY!==l)&&o.setState({x:u.x,y:u.y}),this.isMoving=!1,setTimeout(function(){var h=i.draggedEvents>0;i.draggedEvents=0,h&&i.renderer.getSetting("hideEdgesOnMove")&&i.renderer.refresh()},0),this.emit("mouseup",it(r,this.container))}}},{key:"handleMove",value:function(r){var i=this;if(this.enabled){var o=it(r,this.container);if(this.emit("mousemovebody",o),(r.target===this.container||r.composedPath()[0]===this.container)&&this.emit("mousemove",o),!o.sigmaDefaultPrevented&&this.isMouseDown){this.isMoving=!0,this.draggedEvents++,typeof this.movingTimeout=="number"&&clearTimeout(this.movingTimeout),this.movingTimeout=window.setTimeout(function(){i.movingTimeout=null,i.isMoving=!1},this.settings.dragTimeout);var a=this.renderer.getCamera(),s=Be(r,this.container),l=s.x,u=s.y,c=this.renderer.viewportToFramedGraph({x:this.lastMouseX,y:this.lastMouseY}),h=this.renderer.viewportToFramedGraph({x:l,y:u}),d=c.x-h.x,f=c.y-h.y,v=a.getState(),m=v.x+d,g=v.y+f;a.setState({x:m,y:g}),this.lastMouseX=l,this.lastMouseY=u,r.preventDefault(),r.stopPropagation()}}}},{key:"handleLeave",value:function(r){this.emit("mouseleave",it(r,this.container))}},{key:"handleEnter",value:function(r){this.emit("mouseenter",it(r,this.container))}},{key:"handleWheel",value:function(r){var i=this,o=this.renderer.getCamera();if(!(!this.enabled||!o.enabledZooming)){var a=nd(r);if(a){var s=Uv(r,this.container);if(this.emit("wheel",s),s.sigmaDefaultPrevented){r.preventDefault(),r.stopPropagation();return}var l=o.getState().ratio,u=a>0?1/this.settings.zoomingRatio:this.settings.zoomingRatio,c=o.getBoundedRatio(l*u),h=a>0?1:-1,d=Date.now();l!==c&&(r.preventDefault(),r.stopPropagation(),!(this.currentWheelDirection===h&&this.lastWheelTriggerTime&&d-this.lastWheelTriggerTime<this.settings.zoomDuration/5)&&(o.animate(this.renderer.getViewportZoomedState(Be(r,this.container),c),{easing:"quadraticOut",duration:this.settings.zoomDuration},function(){i.currentWheelDirection=0}),this.currentWheelDirection=h,this.lastWheelTriggerTime=d))}}}},{key:"setSettings",value:function(r){this.settings=r}}])})(rd),Vv=["dragTimeout","inertiaDuration","inertiaRatio","doubleClickTimeout","doubleClickZoomingRatio","doubleClickZoomingDuration","tapMoveTolerance"],jv=Vv.reduce(function(t,e){return G(G({},t),{},T({},e,Vr[e]))},{}),qv=(function(t){function e(n,r){var i;return le(this,e),i=_e(this,e,[n,r]),T(i,"enabled",!0),T(i,"isMoving",!1),T(i,"hasMoved",!1),T(i,"touchMode",0),T(i,"startTouchesPositions",[]),T(i,"lastTouches",[]),T(i,"lastTap",null),T(i,"settings",jv),i.handleStart=i.handleStart.bind(i),i.handleLeave=i.handleLeave.bind(i),i.handleMove=i.handleMove.bind(i),n.addEventListener("touchstart",i.handleStart,{capture:!1}),n.addEventListener("touchcancel",i.handleLeave,{capture:!1}),document.addEventListener("touchend",i.handleLeave,{capture:!1,passive:!1}),document.addEventListener("touchmove",i.handleMove,{capture:!1,passive:!1}),i}return ke(e,t),ue(e,[{key:"kill",value:function(){var r=this.container;r.removeEventListener("touchstart",this.handleStart),r.removeEventListener("touchcancel",this.handleLeave),document.removeEventListener("touchend",this.handleLeave),document.removeEventListener("touchmove",this.handleMove)}},{key:"getDimensions",value:function(){return{width:this.container.offsetWidth,height:this.container.offsetHeight}}},{key:"handleStart",value:function(r){var i=this;if(this.enabled){r.preventDefault();var o=Yr(r.touches);if(this.touchMode=o.length,this.startCameraState=this.renderer.getCamera().getState(),this.startTouchesPositions=o.map(function(f){return Be(f,i.container)}),this.touchMode===2){var a=ft(this.startTouchesPositions,2),s=a[0],l=s.x,u=s.y,c=a[1],h=c.x,d=c.y;this.startTouchesAngle=Math.atan2(d-u,h-l),this.startTouchesDistance=Math.sqrt(Math.pow(h-l,2)+Math.pow(d-u,2))}this.emit("touchdown",Ln(r,this.lastTouches,this.container)),this.lastTouches=o,this.lastTouchesPositions=this.startTouchesPositions}}},{key:"handleLeave",value:function(r){if(!(!this.enabled||!this.startTouchesPositions.length)){switch(r.cancelable&&r.preventDefault(),this.movingTimeout&&(this.isMoving=!1,clearTimeout(this.movingTimeout)),this.touchMode){case 2:if(r.touches.length===1){this.handleStart(r),r.preventDefault();break}case 1:if(this.isMoving){var i=this.renderer.getCamera(),o=i.getState(),a=i.getPreviousState()||{x:0,y:0};i.animate({x:o.x+this.settings.inertiaRatio*(o.x-a.x),y:o.y+this.settings.inertiaRatio*(o.y-a.y)},{duration:this.settings.inertiaDuration,easing:"quadraticOut"})}this.hasMoved=!1,this.isMoving=!1,this.touchMode=0;break}if(this.emit("touchup",Ln(r,this.lastTouches,this.container)),!r.touches.length){var s=Be(this.lastTouches[0],this.container),l=this.startTouchesPositions[0],u=Math.pow(s.x-l.x,2)+Math.pow(s.y-l.y,2);if(!r.touches.length&&u<Math.pow(this.settings.tapMoveTolerance,2))if(this.lastTap&&Date.now()-this.lastTap.time<this.settings.doubleClickTimeout){var c=Ln(r,this.lastTouches,this.container);if(this.emit("doubletap",c),this.lastTap=null,!c.sigmaDefaultPrevented){var h=this.renderer.getCamera(),d=h.getBoundedRatio(h.getState().ratio/this.settings.doubleClickZoomingRatio);h.animate(this.renderer.getViewportZoomedState(s,d),{easing:"quadraticInOut",duration:this.settings.doubleClickZoomingDuration})}}else{var f=Ln(r,this.lastTouches,this.container);this.emit("tap",f),this.lastTap={time:Date.now(),position:f.touches[0]||f.previousTouches[0]}}}this.lastTouches=Yr(r.touches),this.startTouchesPositions=[]}}},{key:"handleMove",value:function(r){var i=this;if(!(!this.enabled||!this.startTouchesPositions.length)){r.preventDefault();var o=Yr(r.touches),a=o.map(function(je){return Be(je,i.container)}),s=this.lastTouches;this.lastTouches=o,this.lastTouchesPositions=a;var l=Ln(r,s,this.container);if(this.emit("touchmove",l),!l.sigmaDefaultPrevented&&(this.hasMoved||(this.hasMoved=a.some(function(je,an){var De=i.startTouchesPositions[an];return De&&(je.x!==De.x||je.y!==De.y)})),!!this.hasMoved)){this.isMoving=!0,this.movingTimeout&&clearTimeout(this.movingTimeout),this.movingTimeout=window.setTimeout(function(){i.isMoving=!1},this.settings.dragTimeout);var u=this.renderer.getCamera(),c=this.startCameraState,h=this.renderer.getSetting("stagePadding");switch(this.touchMode){case 1:{var d=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0]),f=d.x,v=d.y,m=this.renderer.viewportToFramedGraph(a[0]),g=m.x,w=m.y;u.setState({x:c.x+f-g,y:c.y+v-w});break}case 2:{var y={x:.5,y:.5,angle:0,ratio:1},_=a[0],k=_.x,A=_.y,R=a[1],M=R.x,L=R.y,S=Math.atan2(L-A,M-k)-this.startTouchesAngle,D=Math.hypot(L-A,M-k)/this.startTouchesDistance,$=u.getBoundedRatio(c.ratio/D);y.ratio=$,y.angle=c.angle+S;var W=this.getDimensions(),te=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0],{cameraState:c}),ge=Math.min(W.width,W.height)-2*h,he=ge/W.width,Ve=ge/W.height,Mt=$/ge,Fe=k-ge/2/he,Oe=A-ge/2/Ve,ze=[Fe*Math.cos(-y.angle)-Oe*Math.sin(-y.angle),Oe*Math.cos(-y.angle)+Fe*Math.sin(-y.angle)];Fe=ze[0],Oe=ze[1],y.x=te.x-Fe*Mt,y.y=te.y+Oe*Mt,u.setState(y);break}}}}}},{key:"setSettings",value:function(r){this.settings=r}}])})(rd);function Yv(t){if(Array.isArray(t))return Gr(t)}function Xv(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function Zv(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
397
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Zc(t){return Yv(t)||Xv(t)||Oo(t)||Zv()}function Qv(t,e){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.indexOf(r)!==-1)continue;n[r]=t[r]}return n}function Jo(t,e){if(t==null)return{};var n,r,i=Qv(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}var Qc=(function(){function t(e,n){le(this,t),this.key=e,this.size=n}return ue(t,null,[{key:"compare",value:function(n,r){return n.size>r.size?-1:n.size<r.size||n.key>r.key?1:-1}}])})(),Jc=(function(){function t(){le(this,t),T(this,"width",0),T(this,"height",0),T(this,"cellSize",0),T(this,"columns",0),T(this,"rows",0),T(this,"cells",{})}return ue(t,[{key:"resizeAndClear",value:function(n,r){this.width=n.width,this.height=n.height,this.cellSize=r,this.columns=Math.ceil(n.width/r),this.rows=Math.ceil(n.height/r),this.cells={}}},{key:"getIndex",value:function(n){var r=Math.floor(n.x/this.cellSize),i=Math.floor(n.y/this.cellSize);return i*this.columns+r}},{key:"add",value:function(n,r,i){var o=new Qc(n,r),a=this.getIndex(i),s=this.cells[a];s||(s=[],this.cells[a]=s),s.push(o)}},{key:"organize",value:function(){for(var n in this.cells){var r=this.cells[n];r.sort(Qc.compare)}}},{key:"getLabelsToDisplay",value:function(n,r){var i=this.cellSize*this.cellSize,o=i/n/n,a=o*r/i,s=Math.ceil(a),l=[];for(var u in this.cells)for(var c=this.cells[u],h=0;h<Math.min(s,c.length);h++)l.push(c[h].key);return l}}])})();function Jv(t){var e=t.graph,n=t.hoveredNode,r=t.highlightedNodes,i=t.displayedNodeLabels,o=[];return e.forEachEdge(function(a,s,l,u){(l===n||u===n||r.has(l)||r.has(u)||i.has(l)&&i.has(u))&&o.push(a)}),o}var ed=150,td=50,ot=Object.prototype.hasOwnProperty;function ey(t,e,n){if(!ot.call(n,"x")||!ot.call(n,"y"))throw new Error('Sigma: could not find a valid position (x, y) for node "'.concat(e,'". All your nodes must have a number "x" and "y". Maybe your forgot to apply a layout or your "nodeReducer" is not returning the correct data?'));return n.color||(n.color=t.defaultNodeColor),!n.label&&n.label!==""&&(n.label=null),n.label!==void 0&&n.label!==null?n.label=""+n.label:n.label=null,n.size||(n.size=2),ot.call(n,"hidden")||(n.hidden=!1),ot.call(n,"highlighted")||(n.highlighted=!1),ot.call(n,"forceLabel")||(n.forceLabel=!1),(!n.type||n.type==="")&&(n.type=t.defaultNodeType),n.zIndex||(n.zIndex=0),n}function ty(t,e,n){return n.color||(n.color=t.defaultEdgeColor),n.label||(n.label=""),n.size||(n.size=.5),ot.call(n,"hidden")||(n.hidden=!1),ot.call(n,"forceLabel")||(n.forceLabel=!1),(!n.type||n.type==="")&&(n.type=t.defaultEdgeType),n.zIndex||(n.zIndex=0),n}var ny=(function(t){function e(n,r){var i,o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(le(this,e),i=_e(this,e),T(i,"elements",{}),T(i,"canvasContexts",{}),T(i,"webGLContexts",{}),T(i,"pickingLayers",new Set),T(i,"textures",{}),T(i,"frameBuffers",{}),T(i,"activeListeners",{}),T(i,"labelGrid",new Jc),T(i,"nodeDataCache",{}),T(i,"edgeDataCache",{}),T(i,"nodeProgramIndex",{}),T(i,"edgeProgramIndex",{}),T(i,"nodesWithForcedLabels",new Set),T(i,"edgesWithForcedLabels",new Set),T(i,"nodeExtent",{x:[0,1],y:[0,1]}),T(i,"nodeZExtent",[1/0,-1/0]),T(i,"edgeZExtent",[1/0,-1/0]),T(i,"matrix",Ie()),T(i,"invMatrix",Ie()),T(i,"correctionRatio",1),T(i,"customBBox",null),T(i,"normalizationFunction",Zo({x:[0,1],y:[0,1]})),T(i,"graphToViewportRatio",1),T(i,"itemIDsIndex",{}),T(i,"nodeIndices",{}),T(i,"edgeIndices",{}),T(i,"width",0),T(i,"height",0),T(i,"pixelRatio",Yo()),T(i,"pickingDownSizingRatio",2*i.pixelRatio),T(i,"displayedNodeLabels",new Set),T(i,"displayedEdgeLabels",new Set),T(i,"highlightedNodes",new Set),T(i,"hoveredNode",null),T(i,"hoveredEdge",null),T(i,"renderFrame",null),T(i,"renderHighlightedNodesFrame",null),T(i,"needToProcess",!1),T(i,"checkEdgesEventsFrame",null),T(i,"nodePrograms",{}),T(i,"nodeHoverPrograms",{}),T(i,"edgePrograms",{}),i.settings=Yc(o),jr(i.settings),jc(n),!(r instanceof HTMLElement))throw new Error("Sigma: container should be an html element.");i.graph=n,i.container=r,i.createWebGLContext("edges",{picking:o.enableEdgeEvents}),i.createCanvasContext("edgeLabels"),i.createWebGLContext("nodes",{picking:!0}),i.createCanvasContext("labels"),i.createCanvasContext("hovers"),i.createWebGLContext("hoverNodes"),i.createCanvasContext("mouse",{style:{touchAction:"none",userSelect:"none"}}),i.resize();for(var a in i.settings.nodeProgramClasses)i.registerNodeProgram(a,i.settings.nodeProgramClasses[a],i.settings.nodeHoverProgramClasses[a]);for(var s in i.settings.edgeProgramClasses)i.registerEdgeProgram(s,i.settings.edgeProgramClasses[s]);return i.camera=new Xc,i.bindCameraHandlers(),i.mouseCaptor=new Kv(i.elements.mouse,i),i.mouseCaptor.setSettings(i.settings),i.touchCaptor=new qv(i.elements.mouse,i),i.touchCaptor.setSettings(i.settings),i.bindEventHandlers(),i.bindGraphHandlers(),i.handleSettingsUpdate(),i.refresh(),i}return ke(e,t),ue(e,[{key:"registerNodeProgram",value:function(r,i,o){return this.nodePrograms[r]&&this.nodePrograms[r].kill(),this.nodeHoverPrograms[r]&&this.nodeHoverPrograms[r].kill(),this.nodePrograms[r]=new i(this.webGLContexts.nodes,this.frameBuffers.nodes,this),this.nodeHoverPrograms[r]=new(o||i)(this.webGLContexts.hoverNodes,null,this),this}},{key:"registerEdgeProgram",value:function(r,i){return this.edgePrograms[r]&&this.edgePrograms[r].kill(),this.edgePrograms[r]=new i(this.webGLContexts.edges,this.frameBuffers.edges,this),this}},{key:"unregisterNodeProgram",value:function(r){if(this.nodePrograms[r]){var i=this.nodePrograms,o=i[r],a=Jo(i,[r].map(Nt));o.kill(),this.nodePrograms=a}if(this.nodeHoverPrograms[r]){var s=this.nodeHoverPrograms,l=s[r],u=Jo(s,[r].map(Nt));l.kill(),this.nodePrograms=u}return this}},{key:"unregisterEdgeProgram",value:function(r){if(this.edgePrograms[r]){var i=this.edgePrograms,o=i[r],a=Jo(i,[r].map(Nt));o.kill(),this.edgePrograms=a}return this}},{key:"resetWebGLTexture",value:function(r){var i=this.webGLContexts[r],o=this.frameBuffers[r],a=this.textures[r];a&&i.deleteTexture(a);var s=i.createTexture();return i.bindFramebuffer(i.FRAMEBUFFER,o),i.bindTexture(i.TEXTURE_2D,s),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,this.width,this.height,0,i.RGBA,i.UNSIGNED_BYTE,null),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,s,0),this.textures[r]=s,this}},{key:"bindCameraHandlers",value:function(){var r=this;return this.activeListeners.camera=function(){r.scheduleRender()},this.camera.on("updated",this.activeListeners.camera),this}},{key:"unbindCameraHandlers",value:function(){return this.camera.removeListener("updated",this.activeListeners.camera),this}},{key:"getNodeAtPosition",value:function(r){var i=r.x,o=r.y,a=Uo(this.webGLContexts.nodes,this.frameBuffers.nodes,i,o,this.pixelRatio,this.pickingDownSizingRatio),s=$o.apply(void 0,Zc(a)),l=this.itemIDsIndex[s];return l&&l.type==="node"?l.id:null}},{key:"bindEventHandlers",value:function(){var r=this;this.activeListeners.handleResize=function(){r.scheduleRefresh()},window.addEventListener("resize",this.activeListeners.handleResize),this.activeListeners.handleMove=function(o){var a=Cn(o),s={event:a,preventSigmaDefault:function(){a.preventSigmaDefault()}},l=r.getNodeAtPosition(a);if(l&&r.hoveredNode!==l&&!r.nodeDataCache[l].hidden){r.hoveredNode&&r.emit("leaveNode",G(G({},s),{},{node:r.hoveredNode})),r.hoveredNode=l,r.emit("enterNode",G(G({},s),{},{node:l})),r.scheduleHighlightedNodesRender();return}if(r.hoveredNode&&r.getNodeAtPosition(a)!==r.hoveredNode){var u=r.hoveredNode;r.hoveredNode=null,r.emit("leaveNode",G(G({},s),{},{node:u})),r.scheduleHighlightedNodesRender();return}if(r.settings.enableEdgeEvents){var c=r.hoveredNode?null:r.getEdgeAtPoint(s.event.x,s.event.y);c!==r.hoveredEdge&&(r.hoveredEdge&&r.emit("leaveEdge",G(G({},s),{},{edge:r.hoveredEdge})),c&&r.emit("enterEdge",G(G({},s),{},{edge:c})),r.hoveredEdge=c)}},this.activeListeners.handleMoveBody=function(o){var a=Cn(o);r.emit("moveBody",{event:a,preventSigmaDefault:function(){a.preventSigmaDefault()}})},this.activeListeners.handleLeave=function(o){var a=Cn(o),s={event:a,preventSigmaDefault:function(){a.preventSigmaDefault()}};r.hoveredNode&&(r.emit("leaveNode",G(G({},s),{},{node:r.hoveredNode})),r.scheduleHighlightedNodesRender()),r.settings.enableEdgeEvents&&r.hoveredEdge&&(r.emit("leaveEdge",G(G({},s),{},{edge:r.hoveredEdge})),r.scheduleHighlightedNodesRender()),r.emit("leaveStage",G({},s))},this.activeListeners.handleEnter=function(o){var a=Cn(o),s={event:a,preventSigmaDefault:function(){a.preventSigmaDefault()}};r.emit("enterStage",G({},s))};var i=function(a){return function(s){var l=Cn(s),u={event:l,preventSigmaDefault:function(){l.preventSigmaDefault()}},c=r.getNodeAtPosition(l);if(c)return r.emit("".concat(a,"Node"),G(G({},u),{},{node:c}));if(r.settings.enableEdgeEvents){var h=r.getEdgeAtPoint(l.x,l.y);if(h)return r.emit("".concat(a,"Edge"),G(G({},u),{},{edge:h}))}return r.emit("".concat(a,"Stage"),u)}};return this.activeListeners.handleClick=i("click"),this.activeListeners.handleRightClick=i("rightClick"),this.activeListeners.handleDoubleClick=i("doubleClick"),this.activeListeners.handleWheel=i("wheel"),this.activeListeners.handleDown=i("down"),this.activeListeners.handleUp=i("up"),this.mouseCaptor.on("mousemove",this.activeListeners.handleMove),this.mouseCaptor.on("mousemovebody",this.activeListeners.handleMoveBody),this.mouseCaptor.on("click",this.activeListeners.handleClick),this.mouseCaptor.on("rightClick",this.activeListeners.handleRightClick),this.mouseCaptor.on("doubleClick",this.activeListeners.handleDoubleClick),this.mouseCaptor.on("wheel",this.activeListeners.handleWheel),this.mouseCaptor.on("mousedown",this.activeListeners.handleDown),this.mouseCaptor.on("mouseup",this.activeListeners.handleUp),this.mouseCaptor.on("mouseleave",this.activeListeners.handleLeave),this.mouseCaptor.on("mouseenter",this.activeListeners.handleEnter),this.touchCaptor.on("touchdown",this.activeListeners.handleDown),this.touchCaptor.on("touchdown",this.activeListeners.handleMove),this.touchCaptor.on("touchup",this.activeListeners.handleUp),this.touchCaptor.on("touchmove",this.activeListeners.handleMove),this.touchCaptor.on("tap",this.activeListeners.handleClick),this.touchCaptor.on("doubletap",this.activeListeners.handleDoubleClick),this.touchCaptor.on("touchmove",this.activeListeners.handleMoveBody),this}},{key:"bindGraphHandlers",value:function(){var r=this,i=this.graph,o=new Set(["x","y","zIndex","type"]);return this.activeListeners.eachNodeAttributesUpdatedGraphUpdate=function(a){var s,l=(s=a.hints)===null||s===void 0?void 0:s.attributes;r.graph.forEachNode(function(c){return r.updateNode(c)});var u=!l||l.some(function(c){return o.has(c)});r.refresh({partialGraph:{nodes:i.nodes()},skipIndexation:!u,schedule:!0})},this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate=function(a){var s,l=(s=a.hints)===null||s===void 0?void 0:s.attributes;r.graph.forEachEdge(function(c){return r.updateEdge(c)});var u=l&&["zIndex","type"].some(function(c){return l?.includes(c)});r.refresh({partialGraph:{edges:i.edges()},skipIndexation:!u,schedule:!0})},this.activeListeners.addNodeGraphUpdate=function(a){var s=a.key;r.addNode(s),r.refresh({partialGraph:{nodes:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.updateNodeGraphUpdate=function(a){var s=a.key;r.refresh({partialGraph:{nodes:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropNodeGraphUpdate=function(a){var s=a.key;r.removeNode(s),r.refresh({schedule:!0})},this.activeListeners.addEdgeGraphUpdate=function(a){var s=a.key;r.addEdge(s),r.refresh({partialGraph:{edges:[s]},schedule:!0})},this.activeListeners.updateEdgeGraphUpdate=function(a){var s=a.key;r.refresh({partialGraph:{edges:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropEdgeGraphUpdate=function(a){var s=a.key;r.removeEdge(s),r.refresh({schedule:!0})},this.activeListeners.clearEdgesGraphUpdate=function(){r.clearEdgeState(),r.clearEdgeIndices(),r.refresh({schedule:!0})},this.activeListeners.clearGraphUpdate=function(){r.clearEdgeState(),r.clearNodeState(),r.clearEdgeIndices(),r.clearNodeIndices(),r.refresh({schedule:!0})},i.on("nodeAdded",this.activeListeners.addNodeGraphUpdate),i.on("nodeDropped",this.activeListeners.dropNodeGraphUpdate),i.on("nodeAttributesUpdated",this.activeListeners.updateNodeGraphUpdate),i.on("eachNodeAttributesUpdated",this.activeListeners.eachNodeAttributesUpdatedGraphUpdate),i.on("edgeAdded",this.activeListeners.addEdgeGraphUpdate),i.on("edgeDropped",this.activeListeners.dropEdgeGraphUpdate),i.on("edgeAttributesUpdated",this.activeListeners.updateEdgeGraphUpdate),i.on("eachEdgeAttributesUpdated",this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate),i.on("edgesCleared",this.activeListeners.clearEdgesGraphUpdate),i.on("cleared",this.activeListeners.clearGraphUpdate),this}},{key:"unbindGraphHandlers",value:function(){var r=this.graph;r.removeListener("nodeAdded",this.activeListeners.addNodeGraphUpdate),r.removeListener("nodeDropped",this.activeListeners.dropNodeGraphUpdate),r.removeListener("nodeAttributesUpdated",this.activeListeners.updateNodeGraphUpdate),r.removeListener("eachNodeAttributesUpdated",this.activeListeners.eachNodeAttributesUpdatedGraphUpdate),r.removeListener("edgeAdded",this.activeListeners.addEdgeGraphUpdate),r.removeListener("edgeDropped",this.activeListeners.dropEdgeGraphUpdate),r.removeListener("edgeAttributesUpdated",this.activeListeners.updateEdgeGraphUpdate),r.removeListener("eachEdgeAttributesUpdated",this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate),r.removeListener("edgesCleared",this.activeListeners.clearEdgesGraphUpdate),r.removeListener("cleared",this.activeListeners.clearGraphUpdate)}},{key:"getEdgeAtPoint",value:function(r,i){var o=Uo(this.webGLContexts.edges,this.frameBuffers.edges,r,i,this.pixelRatio,this.pickingDownSizingRatio),a=$o.apply(void 0,Zc(o)),s=this.itemIDsIndex[a];return s&&s.type==="edge"?s.id:null}},{key:"process",value:function(){var r=this;this.emit("beforeProcess");var i=this.graph,o=this.settings,a=this.getDimensions();if(this.nodeExtent=Vc(this.graph),!this.settings.autoRescale){var s=a.width,l=a.height,u=this.nodeExtent,c=u.x,h=u.y;this.nodeExtent={x:[(c[0]+c[1])/2-s/2,(c[0]+c[1])/2+s/2],y:[(h[0]+h[1])/2-l/2,(h[0]+h[1])/2+l/2]}}this.normalizationFunction=Zo(this.customBBox||this.nodeExtent);var d=new Xc,f=Qt(d.getState(),a,this.getGraphDimensions(),this.getStagePadding());this.labelGrid.resizeAndClear(a,o.labelGridCellSize);for(var v={},m={},g={},w={},y=1,_=i.nodes(),k=0,A=_.length;k<A;k++){var R=_[k],M=this.nodeDataCache[R],L=i.getNodeAttributes(R);M.x=L.x,M.y=L.y,this.normalizationFunction.applyTo(M),typeof M.label=="string"&&!M.hidden&&this.labelGrid.add(R,M.size,this.framedGraphToViewport(M,{matrix:f})),v[M.type]=(v[M.type]||0)+1}this.labelGrid.organize();for(var S in this.nodePrograms){if(!ot.call(this.nodePrograms,S))throw new Error('Sigma: could not find a suitable program for node type "'.concat(S,'"!'));this.nodePrograms[S].reallocate(v[S]||0),v[S]=0}this.settings.zIndex&&this.nodeZExtent[0]!==this.nodeZExtent[1]&&(_=Xo(this.nodeZExtent,function(sn){return r.nodeDataCache[sn].zIndex},_));for(var D=0,$=_.length;D<$;D++){var W=_[D];m[W]=y,w[m[W]]={type:"node",id:W},y++;var te=this.nodeDataCache[W];this.addNodeToProgram(W,m[W],v[te.type]++)}for(var ge={},he=i.edges(),Ve=0,Mt=he.length;Ve<Mt;Ve++){var Fe=he[Ve],Oe=this.edgeDataCache[Fe];ge[Oe.type]=(ge[Oe.type]||0)+1}this.settings.zIndex&&this.edgeZExtent[0]!==this.edgeZExtent[1]&&(he=Xo(this.edgeZExtent,function(sn){return r.edgeDataCache[sn].zIndex},he));for(var ze in this.edgePrograms){if(!ot.call(this.edgePrograms,ze))throw new Error('Sigma: could not find a suitable program for edge type "'.concat(ze,'"!'));this.edgePrograms[ze].reallocate(ge[ze]||0),ge[ze]=0}for(var je=0,an=he.length;je<an;je++){var De=he[je];g[De]=y,w[g[De]]={type:"edge",id:De},y++;var X=this.edgeDataCache[De];this.addEdgeToProgram(De,g[De],ge[X.type]++)}return this.itemIDsIndex=w,this.nodeIndices=m,this.edgeIndices=g,this.emit("afterProcess"),this}},{key:"handleSettingsUpdate",value:function(r){var i=this,o=this.settings;if(this.camera.minRatio=o.minCameraRatio,this.camera.maxRatio=o.maxCameraRatio,this.camera.enabledZooming=o.enableCameraZooming,this.camera.enabledPanning=o.enableCameraPanning,this.camera.enabledRotation=o.enableCameraRotation,o.cameraPanBoundaries?this.camera.clean=function(c){return i.cleanCameraState(c,o.cameraPanBoundaries&&Wr(o.cameraPanBoundaries)==="object"?o.cameraPanBoundaries:{})}:this.camera.clean=null,this.camera.setState(this.camera.validateState(this.camera.getState())),r){if(r.edgeProgramClasses!==o.edgeProgramClasses){for(var a in o.edgeProgramClasses)o.edgeProgramClasses[a]!==r.edgeProgramClasses[a]&&this.registerEdgeProgram(a,o.edgeProgramClasses[a]);for(var s in r.edgeProgramClasses)o.edgeProgramClasses[s]||this.unregisterEdgeProgram(s)}if(r.nodeProgramClasses!==o.nodeProgramClasses||r.nodeHoverProgramClasses!==o.nodeHoverProgramClasses){for(var l in o.nodeProgramClasses)(o.nodeProgramClasses[l]!==r.nodeProgramClasses[l]||o.nodeHoverProgramClasses[l]!==r.nodeHoverProgramClasses[l])&&this.registerNodeProgram(l,o.nodeProgramClasses[l],o.nodeHoverProgramClasses[l]);for(var u in r.nodeProgramClasses)o.nodeProgramClasses[u]||this.unregisterNodeProgram(u)}}return this.mouseCaptor.setSettings(this.settings),this.touchCaptor.setSettings(this.settings),this}},{key:"cleanCameraState",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=i.tolerance,a=o===void 0?0:o,s=i.boundaries,l=G({},r),u=s||this.nodeExtent,c=ft(u.x,2),h=c[0],d=c[1],f=ft(u.y,2),v=f[0],m=f[1],g=[this.graphToViewport({x:h,y:v},{cameraState:r}),this.graphToViewport({x:d,y:v},{cameraState:r}),this.graphToViewport({x:h,y:m},{cameraState:r}),this.graphToViewport({x:d,y:m},{cameraState:r})],w=1/0,y=-1/0,_=1/0,k=-1/0;g.forEach(function(ge){var he=ge.x,Ve=ge.y;w=Math.min(w,he),y=Math.max(y,he),_=Math.min(_,Ve),k=Math.max(k,Ve)});var A=y-w,R=k-_,M=this.getDimensions(),L=M.width,S=M.height,D=0,$=0;if(A>=L?y<L-a?D=y-(L-a):w>a&&(D=w-a):y>L+a?D=y-(L+a):w<-a&&(D=w+a),R>=S?k<S-a?$=k-(S-a):_>a&&($=_-a):k>S+a?$=k-(S+a):_<-a&&($=_+a),D||$){var W=this.viewportToFramedGraph({x:0,y:0},{cameraState:r}),te=this.viewportToFramedGraph({x:D,y:$},{cameraState:r});D=te.x-W.x,$=te.y-W.y,l.x+=D,l.y+=$}return l}},{key:"renderLabels",value:function(){if(!this.settings.renderLabels)return this;var r=this.camera.getState(),i=this.labelGrid.getLabelsToDisplay(r.ratio,this.settings.labelDensity);Qo(i,this.nodesWithForcedLabels),this.displayedNodeLabels=new Set;for(var o=this.canvasContexts.labels,a=0,s=i.length;a<s;a++){var l=i[a],u=this.nodeDataCache[l];if(!this.displayedNodeLabels.has(l)&&!u.hidden){var c=this.framedGraphToViewport(u),h=c.x,d=c.y,f=this.scaleSize(u.size);if(!(!u.forceLabel&&f<this.settings.labelRenderedSizeThreshold)&&!(h<-ed||h>this.width+ed||d<-td||d>this.height+td)){this.displayedNodeLabels.add(l);var v=this.settings.defaultDrawNodeLabel,m=this.nodePrograms[u.type],g=m?.drawLabel||v;g(o,G(G({key:l},u),{},{size:f,x:h,y:d}),this.settings)}}}return this}},{key:"renderEdgeLabels",value:function(){if(!this.settings.renderEdgeLabels)return this;var r=this.canvasContexts.edgeLabels;r.clearRect(0,0,this.width,this.height);var i=Jv({graph:this.graph,hoveredNode:this.hoveredNode,displayedNodeLabels:this.displayedNodeLabels,highlightedNodes:this.highlightedNodes});Qo(i,this.edgesWithForcedLabels);for(var o=new Set,a=0,s=i.length;a<s;a++){var l=i[a],u=this.graph.extremities(l),c=this.nodeDataCache[u[0]],h=this.nodeDataCache[u[1]],d=this.edgeDataCache[l];if(!o.has(l)&&!(d.hidden||c.hidden||h.hidden)){var f=this.settings.defaultDrawEdgeLabel,v=this.edgePrograms[d.type],m=v?.drawLabel||f;m(r,G(G({key:l},d),{},{size:this.scaleSize(d.size)}),G(G(G({key:u[0]},c),this.framedGraphToViewport(c)),{},{size:this.scaleSize(c.size)}),G(G(G({key:u[1]},h),this.framedGraphToViewport(h)),{},{size:this.scaleSize(h.size)}),this.settings),o.add(l)}}return this.displayedEdgeLabels=o,this}},{key:"renderHighlightedNodes",value:function(){var r=this,i=this.canvasContexts.hovers;i.clearRect(0,0,this.width,this.height);var o=function(f){var v=r.nodeDataCache[f],m=r.framedGraphToViewport(v),g=m.x,w=m.y,y=r.scaleSize(v.size),_=r.settings.defaultDrawNodeHover,k=r.nodePrograms[v.type],A=k?.drawHover||_;A(i,G(G({key:f},v),{},{size:y,x:g,y:w}),r.settings)},a=[];this.hoveredNode&&!this.nodeDataCache[this.hoveredNode].hidden&&a.push(this.hoveredNode),this.highlightedNodes.forEach(function(d){d!==r.hoveredNode&&a.push(d)}),a.forEach(function(d){return o(d)});var s={};a.forEach(function(d){var f=r.nodeDataCache[d].type;s[f]=(s[f]||0)+1});for(var l in this.nodeHoverPrograms)this.nodeHoverPrograms[l].reallocate(s[l]||0),s[l]=0;a.forEach(function(d){var f=r.nodeDataCache[d];r.nodeHoverPrograms[f.type].process(0,s[f.type]++,f)}),this.webGLContexts.hoverNodes.clear(this.webGLContexts.hoverNodes.COLOR_BUFFER_BIT);var u=this.getRenderParams();for(var c in this.nodeHoverPrograms){var h=this.nodeHoverPrograms[c];h.render(u)}}},{key:"scheduleHighlightedNodesRender",value:function(){var r=this;this.renderHighlightedNodesFrame||this.renderFrame||(this.renderHighlightedNodesFrame=requestAnimationFrame(function(){r.renderHighlightedNodesFrame=null,r.renderHighlightedNodes(),r.renderEdgeLabels()}))}},{key:"render",value:function(){var r=this;this.emit("beforeRender");var i=function(){return r.emit("afterRender"),r};if(this.renderFrame&&(cancelAnimationFrame(this.renderFrame),this.renderFrame=null),this.resize(),this.needToProcess&&this.process(),this.needToProcess=!1,this.clear(),this.pickingLayers.forEach(function(g){return r.resetWebGLTexture(g)}),!this.graph.order)return i();var o=this.mouseCaptor,a=this.camera.isAnimated()||o.isMoving||o.draggedEvents||o.currentWheelDirection,s=this.camera.getState(),l=this.getDimensions(),u=this.getGraphDimensions(),c=this.getStagePadding();this.matrix=Qt(s,l,u,c),this.invMatrix=Qt(s,l,u,c,!0),this.correctionRatio=Kc(this.matrix,s,l),this.graphToViewportRatio=this.getGraphToViewportRatio();var h=this.getRenderParams();for(var d in this.nodePrograms){var f=this.nodePrograms[d];f.render(h)}if(!this.settings.hideEdgesOnMove||!a)for(var v in this.edgePrograms){var m=this.edgePrograms[v];m.render(h)}return this.settings.hideLabelsOnMove&&a||(this.renderLabels(),this.renderEdgeLabels(),this.renderHighlightedNodes()),i()}},{key:"addNode",value:function(r){var i=Object.assign({},this.graph.getNodeAttributes(r));this.settings.nodeReducer&&(i=this.settings.nodeReducer(r,i));var o=ey(this.settings,r,i);this.nodeDataCache[r]=o,this.nodesWithForcedLabels.delete(r),o.forceLabel&&!o.hidden&&this.nodesWithForcedLabels.add(r),this.highlightedNodes.delete(r),o.highlighted&&!o.hidden&&this.highlightedNodes.add(r),this.settings.zIndex&&(o.zIndex<this.nodeZExtent[0]&&(this.nodeZExtent[0]=o.zIndex),o.zIndex>this.nodeZExtent[1]&&(this.nodeZExtent[1]=o.zIndex))}},{key:"updateNode",value:function(r){this.addNode(r);var i=this.nodeDataCache[r];this.normalizationFunction.applyTo(i)}},{key:"removeNode",value:function(r){delete this.nodeDataCache[r],delete this.nodeProgramIndex[r],this.highlightedNodes.delete(r),this.hoveredNode===r&&(this.hoveredNode=null),this.nodesWithForcedLabels.delete(r)}},{key:"addEdge",value:function(r){var i=Object.assign({},this.graph.getEdgeAttributes(r));this.settings.edgeReducer&&(i=this.settings.edgeReducer(r,i));var o=ty(this.settings,r,i);this.edgeDataCache[r]=o,this.edgesWithForcedLabels.delete(r),o.forceLabel&&!o.hidden&&this.edgesWithForcedLabels.add(r),this.settings.zIndex&&(o.zIndex<this.edgeZExtent[0]&&(this.edgeZExtent[0]=o.zIndex),o.zIndex>this.edgeZExtent[1]&&(this.edgeZExtent[1]=o.zIndex))}},{key:"updateEdge",value:function(r){this.addEdge(r)}},{key:"removeEdge",value:function(r){delete this.edgeDataCache[r],delete this.edgeProgramIndex[r],this.hoveredEdge===r&&(this.hoveredEdge=null),this.edgesWithForcedLabels.delete(r)}},{key:"clearNodeIndices",value:function(){this.labelGrid=new Jc,this.nodeExtent={x:[0,1],y:[0,1]},this.nodeDataCache={},this.edgeProgramIndex={},this.nodesWithForcedLabels=new Set,this.nodeZExtent=[1/0,-1/0],this.highlightedNodes=new Set}},{key:"clearEdgeIndices",value:function(){this.edgeDataCache={},this.edgeProgramIndex={},this.edgesWithForcedLabels=new Set,this.edgeZExtent=[1/0,-1/0]}},{key:"clearIndices",value:function(){this.clearEdgeIndices(),this.clearNodeIndices()}},{key:"clearNodeState",value:function(){this.displayedNodeLabels=new Set,this.highlightedNodes=new Set,this.hoveredNode=null}},{key:"clearEdgeState",value:function(){this.displayedEdgeLabels=new Set,this.highlightedNodes=new Set,this.hoveredEdge=null}},{key:"clearState",value:function(){this.clearEdgeState(),this.clearNodeState()}},{key:"addNodeToProgram",value:function(r,i,o){var a=this.nodeDataCache[r],s=this.nodePrograms[a.type];if(!s)throw new Error('Sigma: could not find a suitable program for node type "'.concat(a.type,'"!'));s.process(i,o,a),this.nodeProgramIndex[r]=o}},{key:"addEdgeToProgram",value:function(r,i,o){var a=this.edgeDataCache[r],s=this.edgePrograms[a.type];if(!s)throw new Error('Sigma: could not find a suitable program for edge type "'.concat(a.type,'"!'));var l=this.graph.extremities(r),u=this.nodeDataCache[l[0]],c=this.nodeDataCache[l[1]];s.process(i,o,u,c,a),this.edgeProgramIndex[r]=o}},{key:"getRenderParams",value:function(){return{matrix:this.matrix,invMatrix:this.invMatrix,width:this.width,height:this.height,pixelRatio:this.pixelRatio,zoomRatio:this.camera.ratio,cameraAngle:this.camera.angle,sizeRatio:1/this.scaleSize(),correctionRatio:this.correctionRatio,downSizingRatio:this.pickingDownSizingRatio,minEdgeThickness:this.settings.minEdgeThickness,antiAliasingFeather:this.settings.antiAliasingFeather}}},{key:"getStagePadding",value:function(){var r=this.settings,i=r.stagePadding,o=r.autoRescale;return o&&i||0}},{key:"createLayer",value:function(r,i){var o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this.elements[r])throw new Error('Sigma: a layer named "'.concat(r,'" already exists'));var a=qc(i,{position:"absolute"},{class:"sigma-".concat(r)});return o.style&&Object.assign(a.style,o.style),this.elements[r]=a,"beforeLayer"in o&&o.beforeLayer?this.elements[o.beforeLayer].before(a):"afterLayer"in o&&o.afterLayer?this.elements[o.afterLayer].after(a):this.container.appendChild(a),a}},{key:"createCanvas",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.createLayer(r,"canvas",i)}},{key:"createCanvasContext",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=this.createCanvas(r,i),a={preserveDrawingBuffer:!1,antialias:!1};return this.canvasContexts[r]=o.getContext("2d",a),this}},{key:"createWebGLContext",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=i?.canvas||this.createCanvas(r,i);i.hidden&&o.remove();var a=G({preserveDrawingBuffer:!1,antialias:!1},i),s;s=o.getContext("webgl2",a),s||(s=o.getContext("webgl",a)),s||(s=o.getContext("experimental-webgl",a));var l=s;if(this.webGLContexts[r]=l,l.blendFunc(l.ONE,l.ONE_MINUS_SRC_ALPHA),i.picking){this.pickingLayers.add(r);var u=l.createFramebuffer();if(!u)throw new Error("Sigma: cannot create a new frame buffer for layer ".concat(r));this.frameBuffers[r]=u}return l}},{key:"killLayer",value:function(r){var i=this.elements[r];if(!i)throw new Error("Sigma: cannot kill layer ".concat(r,", which does not exist"));if(this.webGLContexts[r]){var o,a=this.webGLContexts[r];(o=a.getExtension("WEBGL_lose_context"))===null||o===void 0||o.loseContext(),delete this.webGLContexts[r]}else this.canvasContexts[r]&&delete this.canvasContexts[r];return i.remove(),delete this.elements[r],this}},{key:"getCamera",value:function(){return this.camera}},{key:"setCamera",value:function(r){this.unbindCameraHandlers(),this.camera=r,this.bindCameraHandlers()}},{key:"getContainer",value:function(){return this.container}},{key:"getGraph",value:function(){return this.graph}},{key:"setGraph",value:function(r){r!==this.graph&&(this.hoveredNode&&!r.hasNode(this.hoveredNode)&&(this.hoveredNode=null),this.hoveredEdge&&!r.hasEdge(this.hoveredEdge)&&(this.hoveredEdge=null),this.unbindGraphHandlers(),this.checkEdgesEventsFrame!==null&&(cancelAnimationFrame(this.checkEdgesEventsFrame),this.checkEdgesEventsFrame=null),this.graph=r,this.bindGraphHandlers(),this.refresh())}},{key:"getMouseCaptor",value:function(){return this.mouseCaptor}},{key:"getTouchCaptor",value:function(){return this.touchCaptor}},{key:"getDimensions",value:function(){return{width:this.width,height:this.height}}},{key:"getGraphDimensions",value:function(){var r=this.customBBox||this.nodeExtent;return{width:r.x[1]-r.x[0]||1,height:r.y[1]-r.y[0]||1}}},{key:"getNodeDisplayData",value:function(r){var i=this.nodeDataCache[r];return i?Object.assign({},i):void 0}},{key:"getEdgeDisplayData",value:function(r){var i=this.edgeDataCache[r];return i?Object.assign({},i):void 0}},{key:"getNodeDisplayedLabels",value:function(){return new Set(this.displayedNodeLabels)}},{key:"getEdgeDisplayedLabels",value:function(){return new Set(this.displayedEdgeLabels)}},{key:"getSettings",value:function(){return G({},this.settings)}},{key:"getSetting",value:function(r){return this.settings[r]}},{key:"setSetting",value:function(r,i){var o=G({},this.settings);return this.settings[r]=i,jr(this.settings),this.handleSettingsUpdate(o),this.scheduleRefresh(),this}},{key:"updateSetting",value:function(r,i){return this.setSetting(r,i(this.settings[r])),this}},{key:"setSettings",value:function(r){var i=G({},this.settings);return this.settings=G(G({},this.settings),r),jr(this.settings),this.handleSettingsUpdate(i),this.scheduleRefresh(),this}},{key:"resize",value:function(r){var i=this.width,o=this.height;if(this.width=this.container.offsetWidth,this.height=this.container.offsetHeight,this.pixelRatio=Yo(),this.width===0)if(this.settings.allowInvalidContainer)this.width=1;else throw new Error("Sigma: Container has no width. You can set the allowInvalidContainer setting to true to stop seeing this error.");if(this.height===0)if(this.settings.allowInvalidContainer)this.height=1;else throw new Error("Sigma: Container has no height. You can set the allowInvalidContainer setting to true to stop seeing this error.");if(!r&&i===this.width&&o===this.height)return this;for(var a in this.elements){var s=this.elements[a];s.style.width=this.width+"px",s.style.height=this.height+"px"}for(var l in this.canvasContexts)this.elements[l].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[l].setAttribute("height",this.height*this.pixelRatio+"px"),this.pixelRatio!==1&&this.canvasContexts[l].scale(this.pixelRatio,this.pixelRatio);for(var u in this.webGLContexts){this.elements[u].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[u].setAttribute("height",this.height*this.pixelRatio+"px");var c=this.webGLContexts[u];if(c.viewport(0,0,this.width*this.pixelRatio,this.height*this.pixelRatio),this.pickingLayers.has(u)){var h=this.textures[u];h&&c.deleteTexture(h)}}return this.emit("resize"),this}},{key:"clear",value:function(){return this.emit("beforeClear"),this.webGLContexts.nodes.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER,null),this.webGLContexts.nodes.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.webGLContexts.edges.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER,null),this.webGLContexts.edges.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.webGLContexts.hoverNodes.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.canvasContexts.labels.clearRect(0,0,this.width,this.height),this.canvasContexts.hovers.clearRect(0,0,this.width,this.height),this.canvasContexts.edgeLabels.clearRect(0,0,this.width,this.height),this.emit("afterClear"),this}},{key:"refresh",value:function(r){var i=this,o=r?.skipIndexation!==void 0?r?.skipIndexation:!1,a=r?.schedule!==void 0?r.schedule:!1,s=!r||!r.partialGraph;if(s)this.clearEdgeIndices(),this.clearNodeIndices(),this.graph.forEachNode(function(k){return i.addNode(k)}),this.graph.forEachEdge(function(k){return i.addEdge(k)});else{for(var l,u,c=((l=r.partialGraph)===null||l===void 0?void 0:l.nodes)||[],h=0,d=c?.length||0;h<d;h++){var f=c[h];if(this.updateNode(f),o){var v=this.nodeProgramIndex[f];if(v===void 0)throw new Error('Sigma: node "'.concat(f,`" can't be repaint`));this.addNodeToProgram(f,this.nodeIndices[f],v)}}for(var m=(r==null||(u=r.partialGraph)===null||u===void 0?void 0:u.edges)||[],g=0,w=m.length;g<w;g++){var y=m[g];if(this.updateEdge(y),o){var _=this.edgeProgramIndex[y];if(_===void 0)throw new Error('Sigma: edge "'.concat(y,`" can't be repaint`));this.addEdgeToProgram(y,this.edgeIndices[y],_)}}}return(s||!o)&&(this.needToProcess=!0),a?this.scheduleRender():this.render(),this}},{key:"scheduleRender",value:function(){var r=this;return this.renderFrame||(this.renderFrame=requestAnimationFrame(function(){r.render()})),this}},{key:"scheduleRefresh",value:function(r){return this.refresh(G(G({},r),{},{schedule:!0}))}},{key:"getViewportZoomedState",value:function(r,i){var o=this.camera.getState(),a=o.ratio,s=o.angle,l=o.x,u=o.y,c=this.settings,h=c.minCameraRatio,d=c.maxCameraRatio;typeof d=="number"&&(i=Math.min(i,d)),typeof h=="number"&&(i=Math.max(i,h));var f=i/a,v={x:this.width/2,y:this.height/2},m=this.viewportToFramedGraph(r),g=this.viewportToFramedGraph(v);return{angle:s,x:(m.x-g.x)*(1-f)+l,y:(m.y-g.y)*(1-f)+u,ratio:i}}},{key:"viewRectangle",value:function(){var r=this.viewportToFramedGraph({x:0,y:0}),i=this.viewportToFramedGraph({x:this.width,y:0}),o=this.viewportToFramedGraph({x:0,y:this.height});return{x1:r.x,y1:r.y,x2:i.x,y2:i.y,height:i.y-o.y}}},{key:"framedGraphToViewport",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=!!i.cameraState||!!i.viewportDimensions||!!i.graphDimensions,a=i.matrix?i.matrix:o?Qt(i.cameraState||this.camera.getState(),i.viewportDimensions||this.getDimensions(),i.graphDimensions||this.getGraphDimensions(),i.padding||this.getStagePadding()):this.matrix,s=Br(a,r);return{x:(1+s.x)*this.width/2,y:(1-s.y)*this.height/2}}},{key:"viewportToFramedGraph",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=!!i.cameraState||!!i.viewportDimensions||!i.graphDimensions,a=i.matrix?i.matrix:o?Qt(i.cameraState||this.camera.getState(),i.viewportDimensions||this.getDimensions(),i.graphDimensions||this.getGraphDimensions(),i.padding||this.getStagePadding(),!0):this.invMatrix,s=Br(a,{x:r.x/this.width*2-1,y:1-r.y/this.height*2});return isNaN(s.x)&&(s.x=0),isNaN(s.y)&&(s.y=0),s}},{key:"viewportToGraph",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.normalizationFunction.inverse(this.viewportToFramedGraph(r,i))}},{key:"graphToViewport",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.framedGraphToViewport(this.normalizationFunction(r),i)}},{key:"getGraphToViewportRatio",value:function(){var r={x:0,y:0},i={x:1,y:1},o=Math.sqrt(Math.pow(r.x-i.x,2)+Math.pow(r.y-i.y,2)),a=this.graphToViewport(r),s=this.graphToViewport(i),l=Math.sqrt(Math.pow(a.x-s.x,2)+Math.pow(a.y-s.y,2));return l/o}},{key:"getBBox",value:function(){return this.nodeExtent}},{key:"getCustomBBox",value:function(){return this.customBBox}},{key:"setCustomBBox",value:function(r){return this.customBBox=r,this.scheduleRender(),this}},{key:"kill",value:function(){this.emit("kill"),this.removeAllListeners(),this.unbindCameraHandlers(),window.removeEventListener("resize",this.activeListeners.handleResize),this.mouseCaptor.kill(),this.touchCaptor.kill(),this.unbindGraphHandlers(),this.clearIndices(),this.clearState(),this.nodeDataCache={},this.edgeDataCache={},this.highlightedNodes.clear(),this.renderFrame&&(cancelAnimationFrame(this.renderFrame),this.renderFrame=null),this.renderHighlightedNodesFrame&&(cancelAnimationFrame(this.renderHighlightedNodesFrame),this.renderHighlightedNodesFrame=null);for(var r=this.container;r.firstChild;)r.removeChild(r.firstChild);for(var i in this.nodePrograms)this.nodePrograms[i].kill();for(var o in this.nodeHoverPrograms)this.nodeHoverPrograms[o].kill();for(var a in this.edgePrograms)this.edgePrograms[a].kill();this.nodePrograms={},this.nodeHoverPrograms={},this.edgePrograms={};for(var s in this.elements)this.killLayer(s);this.canvasContexts={},this.webGLContexts={},this.elements={}}},{key:"scaleSize",value:function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.camera.ratio;return r/this.settings.zoomToSizeRatioFunction(i)*(this.getSetting("itemSizesReference")==="positions"?i*this.graphToViewportRatio:1)}},{key:"getCanvases",value:function(){var r={};for(var i in this.elements)this.elements[i]instanceof HTMLCanvasElement&&(r[i]=this.elements[i]);return r}}])})(Ur),id=ny;var gt={dark:{accent:"#c6a0f6",success:"#a6da95",warning:"#eed49f",dim:"#a5adcb",text:"#cad3f5",muted:"#939ab7",line:"#494d64",ground:"#24273a"},light:{accent:"#7113ec",success:"#28641b",warning:"#7c4f10",dim:"#56586a",text:"#4c4f69",muted:"#606274",line:"#bcc0cc",ground:"#eff1f5"}},ry={vault:"accent",note:"text",repository:"accent",module:"dim",package:"dim",entryPoint:"dim",gitState:"dim",external:"dim",file:"dim"},iy={contains:"dim","anchored-at":"dim","links-to":"accent",mentions:"accent"};function oy(t,e){return gt[e][ry[t]]}function od(t,e){return gt[e][iy[t]]}function ay(t,e){return sy(t)?ta(od(t,e),e,ly):od(t,e)}function sy(t){return t==="contains"||t==="anchored-at"}var ea=.85,ly=.3;function Nn(t,e,n){let r=l=>/^#[0-9a-f]{6}$/.test(l)?[Number.parseInt(l.slice(1,3),16),Number.parseInt(l.slice(3,5),16),Number.parseInt(l.slice(5,7),16)]:null,i=r(t),o=r(e);if(i===null||o===null)return t;let a=Math.min(1,Math.max(0,Number.isFinite(n)?n:0)),s=(l,u)=>Math.round(l+(u-l)*a).toString(16).padStart(2,"0");return`#${s(i[0],o[0])}${s(i[1],o[1])}${s(i[2],o[2])}`}function ta(t,e,n=ea){return Nn(t,gt[e].ground,n)}var uy={contains:1,"anchored-at":1,"links-to":1.4,mentions:1},ad=1.6,ld=32,cy=ld/2;function dy(t,e=ld){if(e<=0)return t.length>0?"…":t;if(t.length<=e)return t;let n=e-1,i=t.slice(0,n).lastIndexOf(" "),o=i>=cy?i:n;return`${t.slice(0,o).trimEnd()}…`}function hy(t){let e=Ct(t.provenance),n=Re(t);return dy(e===""?n:`${e} ${n}`)}var fy=6,py=6;function gy(t){return(e,n,r)=>{if(n.label===null||n.label==="")return;let i=gt[t];e.save(),e.font=`${r.labelSize}px ${r.labelFont}`,e.textAlign="center",e.shadowColor=i.ground,e.shadowBlur=py,e.fillStyle=i.text,e.fillText(n.label,n.x,n.y+n.size+r.labelSize+fy),e.restore()}}function ud(t){let e=1/0,n=1/0,r=-1/0,i=-1/0,o=0;for(let a of t)!Number.isFinite(a.x)||!Number.isFinite(a.y)||(o++,a.x<e&&(e=a.x),a.x>r&&(r=a.x),a.y<n&&(n=a.y),a.y>i&&(i=a.y));return o===0?null:{x:[e,r],y:[n,i]}}var cd={nodes:[],edges:[]};function dd(t){return`${t.source}\0${t.target}\0${t.kind}`}function my(t,e){let n=new Map,r=new Set;for(let i of t){if(i.source===i.target||!e.has(i.source)||!e.has(i.target))continue;let o=dd(i);r.has(o)||(r.add(o),n.set(i.source,(n.get(i.source)??0)+1),n.set(i.target,(n.get(i.target)??0)+1))}return n}function hd(t,e,n,r,i){let o=new Map;for(let h of t){if(o.has(h.id))continue;let d=n.get(h.id);d===void 0||!Number.isFinite(d.x)||!Number.isFinite(d.y)||o.set(h.id,h)}let a=new Set(o.keys()),s=my(e,a),l=[];for(let[h,d]of o){let f=n.get(h),v=Xi(s.get(h)??0);l.push({id:h,x:f.x,y:f.y,size:v,label:hy(d),color:i?.get(h)??oy(d.kind,r),kind:d.kind,provenance:d.provenance,zIndex:Math.round(v),type:"circle"})}let u=[],c=new Set;for(let h of e){if(h.source===h.target||!a.has(h.source)||!a.has(h.target))continue;let d=dd(h);c.has(d)||(c.add(d),u.push({key:d,source:h.source,target:h.target,size:uy[h.kind],color:ay(h.kind,r),kind:h.kind,zIndex:0,type:"line"}))}return{nodes:l,edges:u}}function fd(t,e,n=1){return(r,i,o)=>t===null||n<=0?{}:r===e&&t.has(r)?{zIndex:i.zIndex+sd*2,size:i.size*Xr(by,n)}:t.has(r)?{zIndex:i.zIndex+sd,size:i.size*Xr(xy,n)}:{color:ta(i.color,o,ea*n),label:n>=wy?null:i.label,zIndex:0}}var vy=60,yy=.004;function pd(t,e,n){let r=Number.isFinite(n)&&n>0?n:0,i=e+(t-e)*Math.exp(-r/vy);return Math.abs(e-i)<yy?e:i}function Xr(t,e){return 1+(t-1)*e}var wy=.5,by=1.45,xy=1.15,sd=gr+1;function gd(t,e,n=1){return(r,i,o)=>t===null||n<=0?{}:!t.has(i.source)||!t.has(i.target)?{color:ta(i.color,o,ea*n)}:e!=null&&(i.source===e||i.target===e)?{zIndex:2,size:i.size*Xr(ad*1.35,n),color:Nn(i.color,gt[o].accent,n)}:{zIndex:1,size:i.size*Xr(ad,n)}}var _y=(pr+gr)/2,ky=mr*4,Ey=1;function md(t){let e=gt[t];return{hideEdgesOnMove:!0,enableCameraPanning:!0,renderEdgeLabels:!1,labelDensity:Ey,labelGridCellSize:ky,labelRenderedSizeThreshold:_y,labelFont:"inherit",labelSize:11,labelColor:{color:e.text},defaultNodeColor:e.dim,defaultEdgeColor:e.line,defaultNodeType:"circle",defaultEdgeType:"line",minEdgeThickness:.6,zIndex:!0,itemSizesReference:"positions",zoomToSizeRatioFunction:n=>n,stagePadding:mr,defaultDrawNodeHover:gy(t),allowInvalidContainer:!0}}var bd=dn($r(),1);function Sy(){let t=arguments[0];for(let e=1,n=arguments.length;e<n;e++)if(arguments[e])for(let r in arguments[e])t[r]=arguments[e][r];return t}var ce=Sy;typeof Object.assign=="function"&&(ce=Object.assign);function Ge(t,e,n,r){let i=t._nodes.get(e),o=null;return i&&(r==="mixed"?o=i.out&&i.out[n]||i.undirected&&i.undirected[n]:r==="directed"?o=i.out&&i.out[n]:o=i.undirected&&i.undirected[n]),o}function me(t){return typeof t=="object"&&t!==null}function xd(t){let e;for(e in t)return!1;return!0}function Me(t,e,n){Object.defineProperty(t,e,{enumerable:!1,configurable:!1,writable:!0,value:n})}function We(t,e,n){let r={enumerable:!0,configurable:!0};typeof n=="function"?r.get=n:(r.value=n,r.writable=!1),Object.defineProperty(t,e,r)}function vd(t){return!(!me(t)||t.attributes&&!Array.isArray(t.attributes))}function Ty(){let t=Math.floor(Math.random()*256)&255;return()=>t++}function at(){let t=arguments,e=null,n=-1;return{[Symbol.iterator](){return this},next(){let r=null;do{if(e===null){if(n++,n>=t.length)return{done:!0};e=t[n][Symbol.iterator]()}if(r=e.next(),r.done){e=null;continue}break}while(!0);return r}}}function en(){return{[Symbol.iterator](){return this},next(){return{done:!0}}}}var In=class extends Error{constructor(e){super(),this.name="GraphError",this.message=e}},I=class t extends In{constructor(e){super(e),this.name="InvalidArgumentsGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,t.prototype.constructor)}},N=class t extends In{constructor(e){super(e),this.name="NotFoundGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,t.prototype.constructor)}},O=class t extends In{constructor(e){super(e),this.name="UsageGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,t.prototype.constructor)}};function _d(t,e){this.key=t,this.attributes=e,this.clear()}_d.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}};function kd(t,e){this.key=t,this.attributes=e,this.clear()}kd.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={}};function Ed(t,e){this.key=t,this.attributes=e,this.clear()}Ed.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={}};function tn(t,e,n,r,i){this.key=e,this.attributes=i,this.undirected=t,this.source=n,this.target=r}tn.prototype.attach=function(){let t="out",e="in";this.undirected&&(t=e="undirected");let n=this.source.key,r=this.target.key;this.source[t][r]=this,!(this.undirected&&n===r)&&(this.target[e][n]=this)};tn.prototype.attachMulti=function(){let t="out",e="in",n=this.source.key,r=this.target.key;this.undirected&&(t=e="undirected");let i=this.source[t],o=i[r];if(typeof o>"u"){i[r]=this,this.undirected&&n===r||(this.target[e][n]=this);return}o.previous=this,this.next=o,i[r]=this,this.target[e][n]=this};tn.prototype.detach=function(){let t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),delete this.source[n][e],delete this.target[r][t]};tn.prototype.detachMulti=function(){let t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),this.previous===void 0?this.next===void 0?(delete this.source[n][e],delete this.target[r][t]):(this.next.previous=void 0,this.source[n][e]=this.next,this.target[r][t]=this.next):(this.previous.next=this.next,this.next!==void 0&&(this.next.previous=this.previous))};var Sd=0,Td=1,Ay=2,Ad=3;function st(t,e,n,r,i,o,a){let s,l,u,c;if(r=""+r,n===Sd){if(s=t._nodes.get(r),!s)throw new N(`Graph.${e}: could not find the "${r}" node in the graph.`);u=i,c=o}else if(n===Ad){if(i=""+i,l=t._edges.get(i),!l)throw new N(`Graph.${e}: could not find the "${i}" edge in the graph.`);let h=l.source.key,d=l.target.key;if(r===h)s=l.target;else if(r===d)s=l.source;else throw new N(`Graph.${e}: the "${r}" node is not attached to the "${i}" edge (${h}, ${d}).`);u=o,c=a}else{if(l=t._edges.get(r),!l)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`);n===Td?s=l.source:s=l.target,u=i,c=o}return[s,u,c]}function Ry(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);return a.attributes[s]}}function Cy(t,e,n){t.prototype[e]=function(r,i){let[o]=st(this,e,n,r,i);return o.attributes}}function Ly(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);return a.attributes.hasOwnProperty(s)}}function Ny(t,e,n){t.prototype[e]=function(r,i,o,a){let[s,l,u]=st(this,e,n,r,i,o,a);return s.attributes[l]=u,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:l}),this}}function Dy(t,e,n){t.prototype[e]=function(r,i,o,a){let[s,l,u]=st(this,e,n,r,i,o,a);if(typeof u!="function")throw new I(`Graph.${e}: updater should be a function.`);let c=s.attributes,h=u(c[l]);return c[l]=h,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:l}),this}}function Py(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);return delete a.attributes[s],this.emit("nodeAttributesUpdated",{key:a.key,type:"remove",attributes:a.attributes,name:s}),this}}function Iy(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);if(!me(s))throw new I(`Graph.${e}: provided attributes are not a plain object.`);return a.attributes=s,this.emit("nodeAttributesUpdated",{key:a.key,type:"replace",attributes:a.attributes}),this}}function My(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);if(!me(s))throw new I(`Graph.${e}: provided attributes are not a plain object.`);return ce(a.attributes,s),this.emit("nodeAttributesUpdated",{key:a.key,type:"merge",attributes:a.attributes,data:s}),this}}function Gy(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);if(typeof s!="function")throw new I(`Graph.${e}: provided updater is not a function.`);return a.attributes=s(a.attributes),this.emit("nodeAttributesUpdated",{key:a.key,type:"update",attributes:a.attributes}),this}}var Fy=[{name:t=>`get${t}Attribute`,attacher:Ry},{name:t=>`get${t}Attributes`,attacher:Cy},{name:t=>`has${t}Attribute`,attacher:Ly},{name:t=>`set${t}Attribute`,attacher:Ny},{name:t=>`update${t}Attribute`,attacher:Dy},{name:t=>`remove${t}Attribute`,attacher:Py},{name:t=>`replace${t}Attributes`,attacher:Iy},{name:t=>`merge${t}Attributes`,attacher:My},{name:t=>`update${t}Attributes`,attacher:Gy}];function Oy(t){Fy.forEach(function({name:e,attacher:n}){n(t,e("Node"),Sd),n(t,e("Source"),Td),n(t,e("Target"),Ay),n(t,e("Opposite"),Ad)})}function zy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return o.attributes[i]}}function $y(t,e,n){t.prototype[e]=function(r){let i;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>1){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+r,a=""+arguments[1];if(i=Ge(this,o,a,n),!i)throw new N(`Graph.${e}: could not find an edge for the given path ("${o}" - "${a}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,i=this._edges.get(r),!i)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return i.attributes}}function Uy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return o.attributes.hasOwnProperty(i)}}function Hy(t,e,n){t.prototype[e]=function(r,i,o){let a;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let s=""+r,l=""+i;if(i=arguments[2],o=arguments[3],a=Ge(this,s,l,n),!a)throw new N(`Graph.${e}: could not find an edge for the given path ("${s}" - "${l}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,a=this._edges.get(r),!a)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return a.attributes[i]=o,this.emit("edgeAttributesUpdated",{key:a.key,type:"set",attributes:a.attributes,name:i}),this}}function By(t,e,n){t.prototype[e]=function(r,i,o){let a;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let s=""+r,l=""+i;if(i=arguments[2],o=arguments[3],a=Ge(this,s,l,n),!a)throw new N(`Graph.${e}: could not find an edge for the given path ("${s}" - "${l}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,a=this._edges.get(r),!a)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}if(typeof o!="function")throw new I(`Graph.${e}: updater should be a function.`);return a.attributes[i]=o(a.attributes[i]),this.emit("edgeAttributesUpdated",{key:a.key,type:"set",attributes:a.attributes,name:i}),this}}function Wy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return delete o.attributes[i],this.emit("edgeAttributesUpdated",{key:o.key,type:"remove",attributes:o.attributes,name:i}),this}}function Ky(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}if(!me(i))throw new I(`Graph.${e}: provided attributes are not a plain object.`);return o.attributes=i,this.emit("edgeAttributesUpdated",{key:o.key,type:"replace",attributes:o.attributes}),this}}function Vy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}if(!me(i))throw new I(`Graph.${e}: provided attributes are not a plain object.`);return ce(o.attributes,i),this.emit("edgeAttributesUpdated",{key:o.key,type:"merge",attributes:o.attributes,data:i}),this}}function jy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}if(typeof i!="function")throw new I(`Graph.${e}: provided updater is not a function.`);return o.attributes=i(o.attributes),this.emit("edgeAttributesUpdated",{key:o.key,type:"update",attributes:o.attributes}),this}}var qy=[{name:t=>`get${t}Attribute`,attacher:zy},{name:t=>`get${t}Attributes`,attacher:$y},{name:t=>`has${t}Attribute`,attacher:Uy},{name:t=>`set${t}Attribute`,attacher:Hy},{name:t=>`update${t}Attribute`,attacher:By},{name:t=>`remove${t}Attribute`,attacher:Wy},{name:t=>`replace${t}Attributes`,attacher:Ky},{name:t=>`merge${t}Attributes`,attacher:Vy},{name:t=>`update${t}Attributes`,attacher:jy}];function Yy(t){qy.forEach(function({name:e,attacher:n}){n(t,e("Edge"),"mixed"),n(t,e("DirectedEdge"),"directed"),n(t,e("UndirectedEdge"),"undirected")})}var Xy=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"inboundEdges",type:"mixed",direction:"in"},{name:"outboundEdges",type:"mixed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}];function Zy(t,e,n,r){let i=!1;for(let o in e){if(o===r)continue;let a=e[o];if(i=n(a.key,a.attributes,a.source.key,a.target.key,a.source.attributes,a.target.attributes,a.undirected),t&&i)return a.key}}function Qy(t,e,n,r){let i,o,a,s=!1;for(let l in e)if(l!==r){i=e[l];do{if(o=i.source,a=i.target,s=n(i.key,i.attributes,o.key,a.key,o.attributes,a.attributes,i.undirected),t&&s)return i.key;i=i.next}while(i!==void 0)}}function na(t,e){let n=Object.keys(t),r=n.length,i,o=0;return{[Symbol.iterator](){return this},next(){do if(i)i=i.next;else{if(o>=r)return{done:!0};let a=n[o++];if(a===e){i=void 0;continue}i=t[a]}while(!i);return{done:!1,value:{edge:i.key,attributes:i.attributes,source:i.source.key,target:i.target.key,sourceAttributes:i.source.attributes,targetAttributes:i.target.attributes,undirected:i.undirected}}}}}function Jy(t,e,n,r){let i=e[n];if(!i)return;let o=i.source,a=i.target;if(r(i.key,i.attributes,o.key,a.key,o.attributes,a.attributes,i.undirected)&&t)return i.key}function ew(t,e,n,r){let i=e[n];if(!i)return;let o=!1;do{if(o=r(i.key,i.attributes,i.source.key,i.target.key,i.source.attributes,i.target.attributes,i.undirected),t&&o)return i.key;i=i.next}while(i!==void 0)}function ra(t,e){let n=t[e];if(n.next!==void 0)return{[Symbol.iterator](){return this},next(){if(!n)return{done:!0};let i={edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected};return n=n.next,{done:!1,value:i}}};let r=!1;return{[Symbol.iterator](){return this},next(){return r===!0?{done:!0}:(r=!0,{done:!1,value:{edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected}})}}}function tw(t,e){if(t.size===0)return[];if(e==="mixed"||e===t.type)return Array.from(t._edges.keys());let n=e==="undirected"?t.undirectedSize:t.directedSize,r=new Array(n),i=e==="undirected",o=t._edges.values(),a=0,s,l;for(;s=o.next(),s.done!==!0;)l=s.value,l.undirected===i&&(r[a++]=l.key);return r}function Rd(t,e,n,r){if(e.size===0)return;let i=n!=="mixed"&&n!==e.type,o=n==="undirected",a,s,l=!1,u=e._edges.values();for(;a=u.next(),a.done!==!0;){if(s=a.value,i&&s.undirected!==o)continue;let{key:c,attributes:h,source:d,target:f}=s;if(l=r(c,h,d.key,f.key,d.attributes,f.attributes,s.undirected),t&&l)return c}}function nw(t,e){if(t.size===0)return en();let n=e!=="mixed"&&e!==t.type,r=e==="undirected",i=t._edges.values();return{[Symbol.iterator](){return this},next(){let o,a;for(;;){if(o=i.next(),o.done)return o;if(a=o.value,!(n&&a.undirected!==r))break}return{value:{edge:a.key,attributes:a.attributes,source:a.source.key,target:a.target.key,sourceAttributes:a.source.attributes,targetAttributes:a.target.attributes,undirected:a.undirected},done:!1}}}}function ia(t,e,n,r,i,o){let a=e?Qy:Zy,s;if(n!=="undirected"&&(r!=="out"&&(s=a(t,i.in,o),t&&s)||r!=="in"&&(s=a(t,i.out,o,r?void 0:i.key),t&&s))||n!=="directed"&&(s=a(t,i.undirected,o),t&&s))return s}function rw(t,e,n,r){let i=[];return ia(!1,t,e,n,r,function(o){i.push(o)}),i}function iw(t,e,n){let r=en();return t!=="undirected"&&(e!=="out"&&typeof n.in<"u"&&(r=at(r,na(n.in))),e!=="in"&&typeof n.out<"u"&&(r=at(r,na(n.out,e?void 0:n.key)))),t!=="directed"&&typeof n.undirected<"u"&&(r=at(r,na(n.undirected))),r}function oa(t,e,n,r,i,o,a){let s=n?ew:Jy,l;if(e!=="undirected"&&(typeof i.in<"u"&&r!=="out"&&(l=s(t,i.in,o,a),t&&l)||typeof i.out<"u"&&r!=="in"&&(r||i.key!==o)&&(l=s(t,i.out,o,a),t&&l))||e!=="directed"&&typeof i.undirected<"u"&&(l=s(t,i.undirected,o,a),t&&l))return l}function ow(t,e,n,r,i){let o=[];return oa(!1,t,e,n,r,i,function(a){o.push(a)}),o}function aw(t,e,n,r){let i=en();return t!=="undirected"&&(typeof n.in<"u"&&e!=="out"&&r in n.in&&(i=at(i,ra(n.in,r))),typeof n.out<"u"&&e!=="in"&&r in n.out&&(e||n.key!==r)&&(i=at(i,ra(n.out,r)))),t!=="directed"&&typeof n.undirected<"u"&&r in n.undirected&&(i=at(i,ra(n.undirected,r))),i}function sw(t,e){let{name:n,type:r,direction:i}=e;t.prototype[n]=function(o,a){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return[];if(!arguments.length)return tw(this,r);if(arguments.length===1){o=""+o;let s=this._nodes.get(o);if(typeof s>"u")throw new N(`Graph.${n}: could not find the "${o}" node in the graph.`);return rw(this.multi,r==="mixed"?this.type:r,i,s)}if(arguments.length===2){o=""+o,a=""+a;let s=this._nodes.get(o);if(!s)throw new N(`Graph.${n}: could not find the "${o}" source node in the graph.`);if(!this._nodes.has(a))throw new N(`Graph.${n}: could not find the "${a}" target node in the graph.`);return ow(r,this.multi,i,s,a)}throw new I(`Graph.${n}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function lw(t,e){let{name:n,type:r,direction:i}=e,o="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(u,c,h){if(!(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)){if(arguments.length===1)return h=u,Rd(!1,this,r,h);if(arguments.length===2){u=""+u,h=c;let d=this._nodes.get(u);if(typeof d>"u")throw new N(`Graph.${o}: could not find the "${u}" node in the graph.`);return ia(!1,this.multi,r==="mixed"?this.type:r,i,d,h)}if(arguments.length===3){u=""+u,c=""+c;let d=this._nodes.get(u);if(!d)throw new N(`Graph.${o}: could not find the "${u}" source node in the graph.`);if(!this._nodes.has(c))throw new N(`Graph.${o}: could not find the "${c}" target node in the graph.`);return oa(!1,r,this.multi,i,d,c,h)}throw new I(`Graph.${o}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)}};let a="map"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(){let u=Array.prototype.slice.call(arguments),c=u.pop(),h;if(u.length===0){let d=0;r!=="directed"&&(d+=this.undirectedSize),r!=="undirected"&&(d+=this.directedSize),h=new Array(d);let f=0;u.push((v,m,g,w,y,_,k)=>{h[f++]=c(v,m,g,w,y,_,k)})}else h=[],u.push((d,f,v,m,g,w,y)=>{h.push(c(d,f,v,m,g,w,y))});return this[o].apply(this,u),h};let s="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(){let u=Array.prototype.slice.call(arguments),c=u.pop(),h=[];return u.push((d,f,v,m,g,w,y)=>{c(d,f,v,m,g,w,y)&&h.push(d)}),this[o].apply(this,u),h};let l="reduce"+n[0].toUpperCase()+n.slice(1);t.prototype[l]=function(){let u=Array.prototype.slice.call(arguments);if(u.length<2||u.length>4)throw new I(`Graph.${l}: invalid number of arguments (expecting 2, 3 or 4 and got ${u.length}).`);if(typeof u[u.length-1]=="function"&&typeof u[u.length-2]!="function")throw new I(`Graph.${l}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let c,h;u.length===2?(c=u[0],h=u[1],u=[]):u.length===3?(c=u[1],h=u[2],u=[u[0]]):u.length===4&&(c=u[2],h=u[3],u=[u[0],u[1]]);let d=h;return u.push((f,v,m,g,w,y,_)=>{d=c(d,f,v,m,g,w,y,_)}),this[o].apply(this,u),d}}function uw(t,e){let{name:n,type:r,direction:i}=e,o="find"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(l,u,c){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return!1;if(arguments.length===1)return c=l,Rd(!0,this,r,c);if(arguments.length===2){l=""+l,c=u;let h=this._nodes.get(l);if(typeof h>"u")throw new N(`Graph.${o}: could not find the "${l}" node in the graph.`);return ia(!0,this.multi,r==="mixed"?this.type:r,i,h,c)}if(arguments.length===3){l=""+l,u=""+u;let h=this._nodes.get(l);if(!h)throw new N(`Graph.${o}: could not find the "${l}" source node in the graph.`);if(!this._nodes.has(u))throw new N(`Graph.${o}: could not find the "${u}" target node in the graph.`);return oa(!0,r,this.multi,i,h,u,c)}throw new I(`Graph.${o}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)};let a="some"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[a]=function(){let l=Array.prototype.slice.call(arguments),u=l.pop();return l.push((h,d,f,v,m,g,w)=>u(h,d,f,v,m,g,w)),!!this[o].apply(this,l)};let s="every"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[s]=function(){let l=Array.prototype.slice.call(arguments),u=l.pop();return l.push((h,d,f,v,m,g,w)=>!u(h,d,f,v,m,g,w)),!this[o].apply(this,l)}}function cw(t,e){let{name:n,type:r,direction:i}=e,o=n.slice(0,-1)+"Entries";t.prototype[o]=function(a,s){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return en();if(!arguments.length)return nw(this,r);if(arguments.length===1){a=""+a;let l=this._nodes.get(a);if(!l)throw new N(`Graph.${o}: could not find the "${a}" node in the graph.`);return iw(r,i,l)}if(arguments.length===2){a=""+a,s=""+s;let l=this._nodes.get(a);if(!l)throw new N(`Graph.${o}: could not find the "${a}" source node in the graph.`);if(!this._nodes.has(s))throw new N(`Graph.${o}: could not find the "${s}" target node in the graph.`);return aw(r,i,l,s)}throw new I(`Graph.${o}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function dw(t){Xy.forEach(e=>{sw(t,e),lw(t,e),uw(t,e),cw(t,e)})}var hw=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"inboundNeighbors",type:"mixed",direction:"in"},{name:"outboundNeighbors",type:"mixed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}];function ri(){this.A=null,this.B=null}ri.prototype.wrap=function(t){this.A===null?this.A=t:this.B===null&&(this.B=t)};ri.prototype.has=function(t){return this.A!==null&&t in this.A||this.B!==null&&t in this.B};function Dn(t,e,n,r,i){for(let o in r){let a=r[o],s=a.source,l=a.target,u=s===n?l:s;if(e&&e.has(u.key))continue;let c=i(u.key,u.attributes);if(t&&c)return u.key}}function aa(t,e,n,r,i){if(e!=="mixed"){if(e==="undirected")return Dn(t,null,r,r.undirected,i);if(typeof n=="string")return Dn(t,null,r,r[n],i)}let o=new ri,a;if(e!=="undirected"){if(n!=="out"){if(a=Dn(t,null,r,r.in,i),t&&a)return a;o.wrap(r.in)}if(n!=="in"){if(a=Dn(t,o,r,r.out,i),t&&a)return a;o.wrap(r.out)}}if(e!=="directed"&&(a=Dn(t,o,r,r.undirected,i),t&&a))return a}function fw(t,e,n){if(t!=="mixed"){if(t==="undirected")return Object.keys(n.undirected);if(typeof e=="string")return Object.keys(n[e])}let r=[];return aa(!1,t,e,n,function(i){r.push(i)}),r}function Pn(t,e,n){let r=Object.keys(n),i=r.length,o=0;return{[Symbol.iterator](){return this},next(){let a=null;do{if(o>=i)return t&&t.wrap(n),{done:!0};let s=n[r[o++]],l=s.source,u=s.target;if(a=l===e?u:l,t&&t.has(a.key)){a=null;continue}}while(a===null);return{done:!1,value:{neighbor:a.key,attributes:a.attributes}}}}}function pw(t,e,n){if(t!=="mixed"){if(t==="undirected")return Pn(null,n,n.undirected);if(typeof e=="string")return Pn(null,n,n[e])}let r=en(),i=new ri;return t!=="undirected"&&(e!=="out"&&(r=at(r,Pn(i,n,n.in))),e!=="in"&&(r=at(r,Pn(i,n,n.out)))),t!=="directed"&&(r=at(r,Pn(i,n,n.undirected))),r}function gw(t,e){let{name:n,type:r,direction:i}=e;t.prototype[n]=function(o){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return[];o=""+o;let a=this._nodes.get(o);if(typeof a>"u")throw new N(`Graph.${n}: could not find the "${o}" node in the graph.`);return fw(r==="mixed"?this.type:r,i,a)}}function mw(t,e){let{name:n,type:r,direction:i}=e,o="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(u,c){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return;u=""+u;let h=this._nodes.get(u);if(typeof h>"u")throw new N(`Graph.${o}: could not find the "${u}" node in the graph.`);aa(!1,r==="mixed"?this.type:r,i,h,c)};let a="map"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(u,c){let h=[];return this[o](u,(d,f)=>{h.push(c(d,f))}),h};let s="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(u,c){let h=[];return this[o](u,(d,f)=>{c(d,f)&&h.push(d)}),h};let l="reduce"+n[0].toUpperCase()+n.slice(1);t.prototype[l]=function(u,c,h){if(arguments.length<3)throw new I(`Graph.${l}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let d=h;return this[o](u,(f,v)=>{d=c(d,f,v)}),d}}function vw(t,e){let{name:n,type:r,direction:i}=e,o=n[0].toUpperCase()+n.slice(1,-1),a="find"+o;t.prototype[a]=function(u,c){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return;u=""+u;let h=this._nodes.get(u);if(typeof h>"u")throw new N(`Graph.${a}: could not find the "${u}" node in the graph.`);return aa(!0,r==="mixed"?this.type:r,i,h,c)};let s="some"+o;t.prototype[s]=function(u,c){return!!this[a](u,c)};let l="every"+o;t.prototype[l]=function(u,c){return!this[a](u,(d,f)=>!c(d,f))}}function yw(t,e){let{name:n,type:r,direction:i}=e,o=n.slice(0,-1)+"Entries";t.prototype[o]=function(a){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return en();a=""+a;let s=this._nodes.get(a);if(typeof s>"u")throw new N(`Graph.${o}: could not find the "${a}" node in the graph.`);return pw(r==="mixed"?this.type:r,i,s)}}function ww(t){hw.forEach(e=>{gw(t,e),mw(t,e),vw(t,e),yw(t,e)})}function Zr(t,e,n,r,i){let o=r._nodes.values(),a=r.type,s,l,u,c,h,d,f;for(;s=o.next(),s.done!==!0;){let v=!1;if(l=s.value,a!=="undirected"){c=l.out;for(u in c){h=c[u];do{if(d=h.target,v=!0,f=i(l.key,d.key,l.attributes,d.attributes,h.key,h.attributes,h.undirected),t&&f)return h;h=h.next}while(h)}}if(a!=="directed"){c=l.undirected;for(u in c)if(!(e&&l.key>u)){h=c[u];do{if(d=h.target,d.key!==u&&(d=h.source),v=!0,f=i(l.key,d.key,l.attributes,d.attributes,h.key,h.attributes,h.undirected),t&&f)return h;h=h.next}while(h)}}if(n&&!v&&(f=i(l.key,null,l.attributes,null,null,null,null),t&&f))return null}}function bw(t,e){let n={key:t};return xd(e.attributes)||(n.attributes=ce({},e.attributes)),n}function xw(t,e,n){let r={key:e,source:n.source.key,target:n.target.key};return xd(n.attributes)||(r.attributes=ce({},n.attributes)),t==="mixed"&&n.undirected&&(r.undirected=!0),r}function _w(t){if(!me(t))throw new I('Graph.import: invalid serialized node. A serialized node should be a plain object with at least a "key" property.');if(!("key"in t))throw new I("Graph.import: serialized node is missing its key.");if("attributes"in t&&(!me(t.attributes)||t.attributes===null))throw new I("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.")}function kw(t){if(!me(t))throw new I('Graph.import: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.');if(!("source"in t))throw new I("Graph.import: serialized edge is missing its source.");if(!("target"in t))throw new I("Graph.import: serialized edge is missing its target.");if("attributes"in t&&(!me(t.attributes)||t.attributes===null))throw new I("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.");if("undirected"in t&&typeof t.undirected!="boolean")throw new I("Graph.import: invalid undirectedness information. Undirected should be boolean or omitted.")}var Ew=Ty(),Sw=new Set(["directed","undirected","mixed"]),yd=new Set(["domain","_events","_eventsCount","_maxListeners"]),Tw=[{name:t=>`${t}Edge`,generateKey:!0},{name:t=>`${t}DirectedEdge`,generateKey:!0,type:"directed"},{name:t=>`${t}UndirectedEdge`,generateKey:!0,type:"undirected"},{name:t=>`${t}EdgeWithKey`},{name:t=>`${t}DirectedEdgeWithKey`,type:"directed"},{name:t=>`${t}UndirectedEdgeWithKey`,type:"undirected"}],Aw={allowSelfLoops:!0,multi:!1,type:"mixed"};function Rw(t,e,n){if(n&&!me(n))throw new I(`Graph.addNode: invalid attributes. Expecting an object but got "${n}"`);if(e=""+e,n=n||{},t._nodes.has(e))throw new O(`Graph.addNode: the "${e}" node already exist in the graph.`);let r=new t.NodeDataClass(e,n);return t._nodes.set(e,r),t.emit("nodeAdded",{key:e,attributes:n}),r}function wd(t,e,n){let r=new t.NodeDataClass(e,n);return t._nodes.set(e,r),t.emit("nodeAdded",{key:e,attributes:n}),r}function Cd(t,e,n,r,i,o,a,s){if(!r&&t.type==="undirected")throw new O(`Graph.${e}: you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.`);if(r&&t.type==="directed")throw new O(`Graph.${e}: you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.`);if(s&&!me(s))throw new I(`Graph.${e}: invalid attributes. Expecting an object but got "${s}"`);if(o=""+o,a=""+a,s=s||{},!t.allowSelfLoops&&o===a)throw new O(`Graph.${e}: source & target are the same ("${o}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let l=t._nodes.get(o),u=t._nodes.get(a);if(!l)throw new N(`Graph.${e}: source node "${o}" not found.`);if(!u)throw new N(`Graph.${e}: target node "${a}" not found.`);let c={key:null,undirected:r,source:o,target:a,attributes:s};if(n)i=t._edgeKeyGenerator();else if(i=""+i,t._edges.has(i))throw new O(`Graph.${e}: the "${i}" edge already exists in the graph.`);if(!t.multi&&(r?typeof l.undirected[a]<"u":typeof l.out[a]<"u"))throw new O(`Graph.${e}: an edge linking "${o}" to "${a}" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option.`);let h=new tn(r,i,l,u,s);t._edges.set(i,h);let d=o===a;return r?(l.undirectedDegree++,u.undirectedDegree++,d&&(l.undirectedLoops++,t._undirectedSelfLoopCount++)):(l.outDegree++,u.inDegree++,d&&(l.directedLoops++,t._directedSelfLoopCount++)),t.multi?h.attachMulti():h.attach(),r?t._undirectedSize++:t._directedSize++,c.key=i,t.emit("edgeAdded",c),i}function Cw(t,e,n,r,i,o,a,s,l){if(!r&&t.type==="undirected")throw new O(`Graph.${e}: you cannot merge/update a directed edge to an undirected graph. Use the #.mergeEdge/#.updateEdge or #.addUndirectedEdge instead.`);if(r&&t.type==="directed")throw new O(`Graph.${e}: you cannot merge/update an undirected edge to a directed graph. Use the #.mergeEdge/#.updateEdge or #.addDirectedEdge instead.`);if(s){if(l){if(typeof s!="function")throw new I(`Graph.${e}: invalid updater function. Expecting a function but got "${s}"`)}else if(!me(s))throw new I(`Graph.${e}: invalid attributes. Expecting an object but got "${s}"`)}o=""+o,a=""+a;let u;if(l&&(u=s,s=void 0),!t.allowSelfLoops&&o===a)throw new O(`Graph.${e}: source & target are the same ("${o}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let c=t._nodes.get(o),h=t._nodes.get(a),d,f;if(!n&&(d=t._edges.get(i),d)){if((d.source.key!==o||d.target.key!==a)&&(!r||d.source.key!==a||d.target.key!==o))throw new O(`Graph.${e}: inconsistency detected when attempting to merge the "${i}" edge with "${o}" source & "${a}" target vs. ("${d.source.key}", "${d.target.key}").`);f=d}if(!f&&!t.multi&&c&&(f=r?c.undirected[a]:c.out[a]),f){let y=[f.key,!1,!1,!1];if(l?!u:!s)return y;if(l){let _=f.attributes;f.attributes=u(_),t.emit("edgeAttributesUpdated",{type:"replace",key:f.key,attributes:f.attributes})}else ce(f.attributes,s),t.emit("edgeAttributesUpdated",{type:"merge",key:f.key,attributes:f.attributes,data:s});return y}s=s||{},l&&u&&(s=u(s));let v={key:null,undirected:r,source:o,target:a,attributes:s};if(n)i=t._edgeKeyGenerator();else if(i=""+i,t._edges.has(i))throw new O(`Graph.${e}: the "${i}" edge already exists in the graph.`);let m=!1,g=!1;c||(c=wd(t,o,{}),m=!0,o===a&&(h=c,g=!0)),h||(h=wd(t,a,{}),g=!0),d=new tn(r,i,c,h,s),t._edges.set(i,d);let w=o===a;return r?(c.undirectedDegree++,h.undirectedDegree++,w&&(c.undirectedLoops++,t._undirectedSelfLoopCount++)):(c.outDegree++,h.inDegree++,w&&(c.directedLoops++,t._directedSelfLoopCount++)),t.multi?d.attachMulti():d.attach(),r?t._undirectedSize++:t._directedSize++,v.key=i,t.emit("edgeAdded",v),[i,!0,m,g]}function Jt(t,e){t._edges.delete(e.key);let{source:n,target:r,attributes:i}=e,o=e.undirected,a=n===r;o?(n.undirectedDegree--,r.undirectedDegree--,a&&(n.undirectedLoops--,t._undirectedSelfLoopCount--)):(n.outDegree--,r.inDegree--,a&&(n.directedLoops--,t._directedSelfLoopCount--)),t.multi?e.detachMulti():e.detach(),o?t._undirectedSize--:t._directedSize--,t.emit("edgeDropped",{key:e.key,attributes:i,source:n.key,target:r.key,undirected:o})}var q=class t extends bd.EventEmitter{constructor(e){if(super(),e=ce({},Aw,e),typeof e.multi!="boolean")throw new I(`Graph.constructor: invalid 'multi' option. Expecting a boolean but got "${e.multi}".`);if(!Sw.has(e.type))throw new I(`Graph.constructor: invalid 'type' option. Should be one of "mixed", "directed" or "undirected" but got "${e.type}".`);if(typeof e.allowSelfLoops!="boolean")throw new I(`Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got "${e.allowSelfLoops}".`);let n=e.type==="mixed"?_d:e.type==="directed"?kd:Ed;Me(this,"NodeDataClass",n);let r="geid_"+Ew()+"_",i=0,o=()=>{let a;do a=r+i++;while(this._edges.has(a));return a};Me(this,"_attributes",{}),Me(this,"_nodes",new Map),Me(this,"_edges",new Map),Me(this,"_directedSize",0),Me(this,"_undirectedSize",0),Me(this,"_directedSelfLoopCount",0),Me(this,"_undirectedSelfLoopCount",0),Me(this,"_edgeKeyGenerator",o),Me(this,"_options",e),yd.forEach(a=>Me(this,a,this[a])),We(this,"order",()=>this._nodes.size),We(this,"size",()=>this._edges.size),We(this,"directedSize",()=>this._directedSize),We(this,"undirectedSize",()=>this._undirectedSize),We(this,"selfLoopCount",()=>this._directedSelfLoopCount+this._undirectedSelfLoopCount),We(this,"directedSelfLoopCount",()=>this._directedSelfLoopCount),We(this,"undirectedSelfLoopCount",()=>this._undirectedSelfLoopCount),We(this,"multi",this._options.multi),We(this,"type",this._options.type),We(this,"allowSelfLoops",this._options.allowSelfLoops),We(this,"implementation",()=>"graphology")}_resetInstanceCounters(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0}hasNode(e){return this._nodes.has(""+e)}hasDirectedEdge(e,n){if(this.type==="undirected")return!1;if(arguments.length===1){let r=""+e,i=this._edges.get(r);return!!i&&!i.undirected}else if(arguments.length===2){e=""+e,n=""+n;let r=this._nodes.get(e);return r?r.out.hasOwnProperty(n):!1}throw new I(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasUndirectedEdge(e,n){if(this.type==="directed")return!1;if(arguments.length===1){let r=""+e,i=this._edges.get(r);return!!i&&i.undirected}else if(arguments.length===2){e=""+e,n=""+n;let r=this._nodes.get(e);return r?r.undirected.hasOwnProperty(n):!1}throw new I(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasEdge(e,n){if(arguments.length===1){let r=""+e;return this._edges.has(r)}else if(arguments.length===2){e=""+e,n=""+n;let r=this._nodes.get(e);return r?typeof r.out<"u"&&r.out.hasOwnProperty(n)||typeof r.undirected<"u"&&r.undirected.hasOwnProperty(n):!1}throw new I(`Graph.hasEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}directedEdge(e,n){if(this.type==="undirected")return;if(e=""+e,n=""+n,this.multi)throw new O("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");let r=this._nodes.get(e);if(!r)throw new N(`Graph.directedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(n))throw new N(`Graph.directedEdge: could not find the "${n}" target node in the graph.`);let i=r.out&&r.out[n]||void 0;if(i)return i.key}undirectedEdge(e,n){if(this.type==="directed")return;if(e=""+e,n=""+n,this.multi)throw new O("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");let r=this._nodes.get(e);if(!r)throw new N(`Graph.undirectedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(n))throw new N(`Graph.undirectedEdge: could not find the "${n}" target node in the graph.`);let i=r.undirected&&r.undirected[n]||void 0;if(i)return i.key}edge(e,n){if(this.multi)throw new O("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.edge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(n))throw new N(`Graph.edge: could not find the "${n}" target node in the graph.`);let i=r.out&&r.out[n]||r.undirected&&r.undirected[n]||void 0;if(i)return i.key}areDirectedNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areDirectedNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:n in r.in||n in r.out}areOutNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areOutNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:n in r.out}areInNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areInNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:n in r.in}areUndirectedNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areUndirectedNeighbors: could not find the "${e}" node in the graph.`);return this.type==="directed"?!1:n in r.undirected}areNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&(n in r.in||n in r.out)||this.type!=="directed"&&n in r.undirected}areInboundNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areInboundNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&n in r.in||this.type!=="directed"&&n in r.undirected}areOutboundNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areOutboundNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&n in r.out||this.type!=="directed"&&n in r.undirected}inDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.inDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.inDegree}outDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.outDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.outDegree}directedDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.directedDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.inDegree+n.outDegree}undirectedDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.undirectedDegree: could not find the "${e}" node in the graph.`);return this.type==="directed"?0:n.undirectedDegree}inboundDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.inboundDegree: could not find the "${e}" node in the graph.`);let r=0;return this.type!=="directed"&&(r+=n.undirectedDegree),this.type!=="undirected"&&(r+=n.inDegree),r}outboundDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.outboundDegree: could not find the "${e}" node in the graph.`);let r=0;return this.type!=="directed"&&(r+=n.undirectedDegree),this.type!=="undirected"&&(r+=n.outDegree),r}degree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.degree: could not find the "${e}" node in the graph.`);let r=0;return this.type!=="directed"&&(r+=n.undirectedDegree),this.type!=="undirected"&&(r+=n.inDegree+n.outDegree),r}inDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.inDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.inDegree-n.directedLoops}outDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.outDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.outDegree-n.directedLoops}directedDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.directedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.inDegree+n.outDegree-n.directedLoops*2}undirectedDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.undirectedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="directed"?0:n.undirectedDegree-n.undirectedLoops*2}inboundDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.inboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let r=0,i=0;return this.type!=="directed"&&(r+=n.undirectedDegree,i+=n.undirectedLoops*2),this.type!=="undirected"&&(r+=n.inDegree,i+=n.directedLoops),r-i}outboundDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.outboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let r=0,i=0;return this.type!=="directed"&&(r+=n.undirectedDegree,i+=n.undirectedLoops*2),this.type!=="undirected"&&(r+=n.outDegree,i+=n.directedLoops),r-i}degreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.degreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let r=0,i=0;return this.type!=="directed"&&(r+=n.undirectedDegree,i+=n.undirectedLoops*2),this.type!=="undirected"&&(r+=n.inDegree+n.outDegree,i+=n.directedLoops*2),r-i}source(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.source: could not find the "${e}" edge in the graph.`);return n.source.key}target(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.target: could not find the "${e}" edge in the graph.`);return n.target.key}extremities(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.extremities: could not find the "${e}" edge in the graph.`);return[n.source.key,n.target.key]}opposite(e,n){e=""+e,n=""+n;let r=this._edges.get(n);if(!r)throw new N(`Graph.opposite: could not find the "${n}" edge in the graph.`);let i=r.source.key,o=r.target.key;if(e===i)return o;if(e===o)return i;throw new N(`Graph.opposite: the "${e}" node is not attached to the "${n}" edge (${i}, ${o}).`)}hasExtremity(e,n){e=""+e,n=""+n;let r=this._edges.get(e);if(!r)throw new N(`Graph.hasExtremity: could not find the "${e}" edge in the graph.`);return r.source.key===n||r.target.key===n}isUndirected(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.isUndirected: could not find the "${e}" edge in the graph.`);return n.undirected}isDirected(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.isDirected: could not find the "${e}" edge in the graph.`);return!n.undirected}isSelfLoop(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.isSelfLoop: could not find the "${e}" edge in the graph.`);return n.source===n.target}addNode(e,n){return Rw(this,e,n).key}mergeNode(e,n){if(n&&!me(n))throw new I(`Graph.mergeNode: invalid attributes. Expecting an object but got "${n}"`);e=""+e,n=n||{};let r=this._nodes.get(e);return r?(n&&(ce(r.attributes,n),this.emit("nodeAttributesUpdated",{type:"merge",key:e,attributes:r.attributes,data:n})),[e,!1]):(r=new this.NodeDataClass(e,n),this._nodes.set(e,r),this.emit("nodeAdded",{key:e,attributes:n}),[e,!0])}updateNode(e,n){if(n&&typeof n!="function")throw new I(`Graph.updateNode: invalid updater function. Expecting a function but got "${n}"`);e=""+e;let r=this._nodes.get(e);if(r){if(n){let o=r.attributes;r.attributes=n(o),this.emit("nodeAttributesUpdated",{type:"replace",key:e,attributes:r.attributes})}return[e,!1]}let i=n?n({}):{};return r=new this.NodeDataClass(e,i),this._nodes.set(e,r),this.emit("nodeAdded",{key:e,attributes:i}),[e,!0]}dropNode(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.dropNode: could not find the "${e}" node in the graph.`);let r;if(this.type!=="undirected"){for(let i in n.out){r=n.out[i];do Jt(this,r),r=r.next;while(r)}for(let i in n.in){r=n.in[i];do Jt(this,r),r=r.next;while(r)}}if(this.type!=="directed")for(let i in n.undirected){r=n.undirected[i];do Jt(this,r),r=r.next;while(r)}this._nodes.delete(e),this.emit("nodeDropped",{key:e,attributes:n.attributes})}dropEdge(e){let n;if(arguments.length>1){let r=""+arguments[0],i=""+arguments[1];if(n=Ge(this,r,i,this.type),!n)throw new N(`Graph.dropEdge: could not find the "${r}" -> "${i}" edge in the graph.`)}else if(e=""+e,n=this._edges.get(e),!n)throw new N(`Graph.dropEdge: could not find the "${e}" edge in the graph.`);return Jt(this,n),this}dropDirectedEdge(e,n){if(arguments.length<2)throw new O("Graph.dropDirectedEdge: it does not make sense to try and drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new O("Graph.dropDirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");e=""+e,n=""+n;let r=Ge(this,e,n,"directed");if(!r)throw new N(`Graph.dropDirectedEdge: could not find a "${e}" -> "${n}" edge in the graph.`);return Jt(this,r),this}dropUndirectedEdge(e,n){if(arguments.length<2)throw new O("Graph.dropUndirectedEdge: it does not make sense to drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new O("Graph.dropUndirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");let r=Ge(this,e,n,"undirected");if(!r)throw new N(`Graph.dropUndirectedEdge: could not find a "${e}" -> "${n}" edge in the graph.`);return Jt(this,r),this}clear(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")}clearEdges(){let e=this._nodes.values(),n;for(;n=e.next(),n.done!==!0;)n.value.clear();this._edges.clear(),this._resetInstanceCounters(),this.emit("edgesCleared")}getAttribute(e){return this._attributes[e]}getAttributes(){return this._attributes}hasAttribute(e){return this._attributes.hasOwnProperty(e)}setAttribute(e,n){return this._attributes[e]=n,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:e}),this}updateAttribute(e,n){if(typeof n!="function")throw new I("Graph.updateAttribute: updater should be a function.");let r=this._attributes[e];return this._attributes[e]=n(r),this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:e}),this}removeAttribute(e){return delete this._attributes[e],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:e}),this}replaceAttributes(e){if(!me(e))throw new I("Graph.replaceAttributes: provided attributes are not a plain object.");return this._attributes=e,this.emit("attributesUpdated",{type:"replace",attributes:this._attributes}),this}mergeAttributes(e){if(!me(e))throw new I("Graph.mergeAttributes: provided attributes are not a plain object.");return ce(this._attributes,e),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:e}),this}updateAttributes(e){if(typeof e!="function")throw new I("Graph.updateAttributes: provided updater is not a function.");return this._attributes=e(this._attributes),this.emit("attributesUpdated",{type:"update",attributes:this._attributes}),this}updateEachNodeAttributes(e,n){if(typeof e!="function")throw new I("Graph.updateEachNodeAttributes: expecting an updater function.");if(n&&!vd(n))throw new I("Graph.updateEachNodeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");let r=this._nodes.values(),i,o;for(;i=r.next(),i.done!==!0;)o=i.value,o.attributes=e(o.key,o.attributes);this.emit("eachNodeAttributesUpdated",{hints:n||null})}updateEachEdgeAttributes(e,n){if(typeof e!="function")throw new I("Graph.updateEachEdgeAttributes: expecting an updater function.");if(n&&!vd(n))throw new I("Graph.updateEachEdgeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");let r=this._edges.values(),i,o,a,s;for(;i=r.next(),i.done!==!0;)o=i.value,a=o.source,s=o.target,o.attributes=e(o.key,o.attributes,a.key,s.key,a.attributes,s.attributes,o.undirected);this.emit("eachEdgeAttributesUpdated",{hints:n||null})}forEachAdjacencyEntry(e){if(typeof e!="function")throw new I("Graph.forEachAdjacencyEntry: expecting a callback.");Zr(!1,!1,!1,this,e)}forEachAdjacencyEntryWithOrphans(e){if(typeof e!="function")throw new I("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");Zr(!1,!1,!0,this,e)}forEachAssymetricAdjacencyEntry(e){if(typeof e!="function")throw new I("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");Zr(!1,!0,!1,this,e)}forEachAssymetricAdjacencyEntryWithOrphans(e){if(typeof e!="function")throw new I("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");Zr(!1,!0,!0,this,e)}nodes(){return Array.from(this._nodes.keys())}forEachNode(e){if(typeof e!="function")throw new I("Graph.forEachNode: expecting a callback.");let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)i=r.value,e(i.key,i.attributes)}findNode(e){if(typeof e!="function")throw new I("Graph.findNode: expecting a callback.");let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)if(i=r.value,e(i.key,i.attributes))return i.key}mapNodes(e){if(typeof e!="function")throw new I("Graph.mapNode: expecting a callback.");let n=this._nodes.values(),r,i,o=new Array(this.order),a=0;for(;r=n.next(),r.done!==!0;)i=r.value,o[a++]=e(i.key,i.attributes);return o}someNode(e){if(typeof e!="function")throw new I("Graph.someNode: expecting a callback.");let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)if(i=r.value,e(i.key,i.attributes))return!0;return!1}everyNode(e){if(typeof e!="function")throw new I("Graph.everyNode: expecting a callback.");let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)if(i=r.value,!e(i.key,i.attributes))return!1;return!0}filterNodes(e){if(typeof e!="function")throw new I("Graph.filterNodes: expecting a callback.");let n=this._nodes.values(),r,i,o=[];for(;r=n.next(),r.done!==!0;)i=r.value,e(i.key,i.attributes)&&o.push(i.key);return o}reduceNodes(e,n){if(typeof e!="function")throw new I("Graph.reduceNodes: expecting a callback.");if(arguments.length<2)throw new I("Graph.reduceNodes: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.");let r=n,i=this._nodes.values(),o,a;for(;o=i.next(),o.done!==!0;)a=o.value,r=e(r,a.key,a.attributes);return r}nodeEntries(){let e=this._nodes.values();return{[Symbol.iterator](){return this},next(){let n=e.next();if(n.done)return n;let r=n.value;return{value:{node:r.key,attributes:r.attributes},done:!1}}}}export(){let e=new Array(this._nodes.size),n=0;this._nodes.forEach((i,o)=>{e[n++]=bw(o,i)});let r=new Array(this._edges.size);return n=0,this._edges.forEach((i,o)=>{r[n++]=xw(this.type,o,i)}),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:r}}import(e,n=!1){if(e instanceof t)return e.forEachNode((l,u)=>{n?this.mergeNode(l,u):this.addNode(l,u)}),e.forEachEdge((l,u,c,h,d,f,v)=>{n?v?this.mergeUndirectedEdgeWithKey(l,c,h,u):this.mergeDirectedEdgeWithKey(l,c,h,u):v?this.addUndirectedEdgeWithKey(l,c,h,u):this.addDirectedEdgeWithKey(l,c,h,u)}),this;if(!me(e))throw new I("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(e.attributes){if(!me(e.attributes))throw new I("Graph.import: invalid attributes. Expecting a plain object.");n?this.mergeAttributes(e.attributes):this.replaceAttributes(e.attributes)}let r,i,o,a,s;if(e.nodes){if(o=e.nodes,!Array.isArray(o))throw new I("Graph.import: invalid nodes. Expecting an array.");for(r=0,i=o.length;r<i;r++){a=o[r],_w(a);let{key:l,attributes:u}=a;n?this.mergeNode(l,u):this.addNode(l,u)}}if(e.edges){let l=!1;if(this.type==="undirected"&&(l=!0),o=e.edges,!Array.isArray(o))throw new I("Graph.import: invalid edges. Expecting an array.");for(r=0,i=o.length;r<i;r++){s=o[r],kw(s);let{source:u,target:c,attributes:h,undirected:d=l}=s,f;"key"in s?(f=n?d?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:d?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey,f.call(this,s.key,u,c,h)):(f=n?d?this.mergeUndirectedEdge:this.mergeDirectedEdge:d?this.addUndirectedEdge:this.addDirectedEdge,f.call(this,u,c,h))}}return this}nullCopy(e){let n=new t(ce({},this._options,e));return n.replaceAttributes(ce({},this.getAttributes())),n}emptyCopy(e){let n=this.nullCopy(e);return this._nodes.forEach((r,i)=>{let o=ce({},r.attributes);r=new n.NodeDataClass(i,o),n._nodes.set(i,r)}),n}copy(e){if(e=e||{},typeof e.type=="string"&&e.type!==this.type&&e.type!=="mixed")throw new O(`Graph.copy: cannot create an incompatible copy from "${this.type}" type to "${e.type}" because this would mean losing information about the current graph.`);if(typeof e.multi=="boolean"&&e.multi!==this.multi&&e.multi!==!0)throw new O("Graph.copy: cannot create an incompatible copy by downgrading a multi graph to a simple one because this would mean losing information about the current graph.");if(typeof e.allowSelfLoops=="boolean"&&e.allowSelfLoops!==this.allowSelfLoops&&e.allowSelfLoops!==!0)throw new O("Graph.copy: cannot create an incompatible copy from a graph allowing self loops to one that does not because this would mean losing information about the current graph.");let n=this.emptyCopy(e),r=this._edges.values(),i,o;for(;i=r.next(),i.done!==!0;)o=i.value,Cd(n,"copy",!1,o.undirected,o.key,o.source.key,o.target.key,ce({},o.attributes));return n}toJSON(){return this.export()}toString(){return"[object Graph]"}inspect(){let e={};this._nodes.forEach((o,a)=>{e[a]=o.attributes});let n={},r={};this._edges.forEach((o,a)=>{let s=o.undirected?"--":"->",l="",u=o.source.key,c=o.target.key,h;o.undirected&&u>c&&(h=u,u=c,c=h);let d=`(${u})${s}(${c})`;a.startsWith("geid_")?this.multi&&(typeof r[d]>"u"?r[d]=0:r[d]++,l+=`${r[d]}. `):l+=`[${a}]: `,l+=d,n[l]=o.attributes});let i={};for(let o in this)this.hasOwnProperty(o)&&!yd.has(o)&&typeof this[o]!="function"&&typeof o!="symbol"&&(i[o]=this[o]);return i.attributes=this._attributes,i.nodes=e,i.edges=n,Me(i,"constructor",this.constructor),i}};typeof Symbol<"u"&&(q.prototype[Symbol.for("nodejs.util.inspect.custom")]=q.prototype.inspect);Tw.forEach(t=>{["add","merge","update"].forEach(e=>{let n=t.name(e),r=e==="add"?Cd:Cw;t.generateKey?q.prototype[n]=function(i,o,a){return r(this,n,!0,(t.type||this.type)==="undirected",null,i,o,a,e==="update")}:q.prototype[n]=function(i,o,a,s){return r(this,n,!1,(t.type||this.type)==="undirected",i,o,a,s,e==="update")}})});Oy(q);Yy(q);dw(q);ww(q);var Qr=class extends q{constructor(e){let n=ce({type:"directed"},e);if("multi"in n&&n.multi!==!1)throw new I("DirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(n.type!=="directed")throw new I('DirectedGraph.from: inconsistent "'+n.type+'" type in given options!');super(n)}},Jr=class extends q{constructor(e){let n=ce({type:"undirected"},e);if("multi"in n&&n.multi!==!1)throw new I("UndirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(n.type!=="undirected")throw new I('UndirectedGraph.from: inconsistent "'+n.type+'" type in given options!');super(n)}},ei=class extends q{constructor(e){let n=ce({multi:!0},e);if("multi"in n&&n.multi!==!0)throw new I("MultiGraph.from: inconsistent indication that the graph should be simple in given options!");super(n)}},ti=class extends q{constructor(e){let n=ce({type:"directed",multi:!0},e);if("multi"in n&&n.multi!==!0)throw new I("MultiDirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(n.type!=="directed")throw new I('MultiDirectedGraph.from: inconsistent "'+n.type+'" type in given options!');super(n)}},ni=class extends q{constructor(e){let n=ce({type:"undirected",multi:!0},e);if("multi"in n&&n.multi!==!0)throw new I("MultiUndirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(n.type!=="undirected")throw new I('MultiUndirectedGraph.from: inconsistent "'+n.type+'" type in given options!');super(n)}};function nn(t){t.from=function(e,n){let r=ce({},e.options,n),i=new t(r);return i.import(e),i}}nn(q);nn(Qr);nn(Jr);nn(ei);nn(ti);nn(ni);q.Graph=q;q.DirectedGraph=Qr;q.UndirectedGraph=Jr;q.MultiGraph=ei;q.MultiDirectedGraph=ti;q.MultiUndirectedGraph=ni;q.InvalidArgumentsGraphError=I;q.NotFoundGraphError=N;q.UsageGraphError=O;function Lw(){return new q({multi:!0,type:"directed"})}function sa(t){let e=Lw();for(let n of t.nodes){let{id:r,...i}=n;e.addNode(r,i)}for(let n of t.edges){let{key:r,source:i,target:o,...a}=n;e.addDirectedEdgeWithKey(r,i,o,{source:i,target:o,...a})}return e}function Ld(t,e){let n=0;for(let[r,i]of e)t.hasNode(r)&&(!Number.isFinite(i.x)||!Number.isFinite(i.y)||(t.mergeNodeAttributes(r,{x:i.x,y:i.y}),n++));return n}function la(t){let e=new Map;return t.forEachNode((n,r)=>{e.set(n,{x:r.x,y:r.y})}),e}var Nd=t=>({now:()=>t.performance.now(),request:e=>t.requestAnimationFrame(()=>e()),cancel:e=>t.cancelAnimationFrame(e)});function Dd(t,e,n){let r=null,i=sa({nodes:[],edges:[]}),o=null,a=null,s=0,l=0,u=null,c=0,h=()=>{},d=()=>{},f=()=>{},v=()=>{},m=()=>{},g=null,w=A=>{if(g===null)return;let R=g;g=null,r?.setSetting("enableCameraPanning",!0),(A===null||A===R)&&m(R)},y=()=>ud([...la(i).values()]),_=A=>{let R=fd(o,a,s),M=gd(o,a,s);A.setSetting("nodeReducer",(L,S)=>({...S,...R(L,S,e)})),A.setSetting("edgeReducer",(L,S)=>({...S,...M(L,S,e)}))},k=()=>{if(n===void 0||u!==null)return;c=n.now();let A=()=>{u=null;let R=n.now();if(s=pd(s,l,R-c),c=R,r!==null&&_(r),s===l){s===0&&(o=null);return}u=n.request(A)};u=n.request(A)};return{mount(A){if(r!==null)return;let R=t(i,A,md(e));R.on("clickNode",({node:M})=>h(M)),R.on("clickStage",()=>h(null)),R.on("downNode",({node:M})=>{g=M,r?.setSetting("enableCameraPanning",!1),f(M)}),R.on("moveBody",M=>{g!==null&&(M.preventSigmaDefault(),v(g,R.viewportToGraph({x:M.event.x,y:M.event.y})))}),R.on("enterNode",({node:M})=>d(M)),R.on("leaveNode",()=>d(null)),R.on("upNode",()=>w(g)),R.on("upStage",()=>w(null)),_(R),R.setCustomBBox(y()),r=R},setGraph(A){i=sa(A),r?.setGraph(i),r?.setCustomBBox(y())},setPositions(A){Ld(i,A),r?.refresh()},setHighlight(A,R=null){if(n===void 0){o=A,a=R,s=A===null?0:1,l=s,r!==null&&_(r);return}if(A===null){if(l=0,o===null)return}else o=A,a=R,l=1;r!==null&&_(r),s!==l&&k()},onSelect(A){h=A},onHover(A){d=A},onDragStart(A){f=A},onDragMove(A){v=A},onDragEnd(A){m=A},fit(){r?.setCustomBBox(y()),r?.getCamera().animatedReset()},positions(){return la(i)},destroy(){u!==null&&(n?.cancel(u),u=null),r?.kill(),r=null}}}var Pd=t=>Dd((e,n,r)=>new id(e,n,r),t,Nd(window));var Id=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");function Md(t,e,n){return t===0?null:t===1?0:e<0?n?t-1:0:n?e===0?t-1:e-1:e===t-1?0:e+1}function Gd(t,e,n,r){return t==="Tab"&&!e&&!n&&!r}function Fd(t){return t===null?!1:(t.focus(),!0)}function ii(){let t=V(null);return ee(()=>{let e=document.activeElement;return t.current?.focus(),()=>{Fd(e instanceof HTMLElement?e:null)}},[]),{ref:t,onKeyDown(e){if(!Gd(e.key,e.ctrlKey,e.metaKey,e.altKey))return!1;let n=[...t.current?.querySelectorAll(Id)??[]],r=Md(n.length,n.indexOf(document.activeElement),e.shiftKey);return r===null?!1:(e.preventDefault(),n[r]?.focus(),!0)}}}function $d(t,e){let n=e.trim().toLowerCase();if(!n)return 0;let r=t.toLowerCase(),i=r.indexOf(n);return i<0?0:r===n?100:i===0?70:/[a-z0-9]/.test(r.charAt(i-1))?30:50}function Nw(t){return Math.min(Math.max(t,0),10)*2}function Dw(t){return`note:${t}`}function Pw(t,e){return $d(t.summary.title,e)+Nw(t.score)}function Iw(t,e){return $d(t.label,e)}var Mw=["path","manifest","url","slug"];function Gw(t){for(let e of Mw){let n=t.detail[e];if(typeof n=="string"&&n)return n}return""}function Fw(t,e){return t.score!==e.score?e.score-t.score:t.kind!==e.kind?t.kind==="note"?-1:1:t.label.localeCompare(e.label)||t.id.localeCompare(e.id)}function Ow(t,e,n,r){let i=new Map;for(let o of t){let a=Dw(o.summary.slug);i.set(a,{id:a,kind:"note",label:o.summary.title,detail:o.snippet,badge:"note",score:Pw(o,e)})}for(let o of n){if(i.has(o.id))continue;let a=Iw(o,r);a&&i.set(o.id,{id:o.id,kind:"node",label:o.label,detail:Gw(o),badge:o.kind,score:a})}return[...i.values()].sort(Fw).slice(0,20)}function Ud(){return{query:"",answered:"",hits:[],cursor:0,loading:!1,failed:!1}}function ua(t,e){return e<=0?0:Math.min(Math.max(t,0),e-1)}function Od(t,e,n){return n<=0?0:((t+e)%n+n)%n}function Hd(t,e){return e===null?null:t[e]?.id??null}function Bd(t,e,n){let r={cursor:t,activate:null,dismiss:!1,handled:!1},i=ua(t,n);return e==="ArrowDown"?{...r,cursor:Od(i,1,n),handled:!0}:e==="ArrowUp"?{...r,cursor:Od(i,-1,n),handled:!0}:e==="Home"?{...r,cursor:0,handled:!0}:e==="End"?{...r,cursor:ua(n-1,n),handled:!0}:e==="Escape"?{...r,dismiss:!0,handled:!0}:e!=="Enter"||n===0?r:{...r,cursor:i,activate:i,dismiss:!0,handled:!0}}var oi="Search the workspace",Wd="Search notes and repository…",Kd="↑↓ move · ↵ open · esc close";function zw(t,e){return t.query.trim()?e>0?null:t.failed?"search failed — the workspace server may be gone":t.loading?"searching…":`no matches for “${t.query.trim()}”`:"Type to search notes, modules, files and entry points."}function $w(t){return t===1?"1 result":`${t} results`}function zd(t){return`weave-search-row-${t}`}function Vd(t,e){let n=Ow(t.hits,t.answered,e?.model.nodes??[],t.query),r=ua(t.cursor,n.length);return{rows:n.map((o,a)=>({...o,active:a===r,domId:zd(a)})),status:zw(t,n.length),count:n.length,countLabel:$w(n.length),cursor:r,activeDomId:n.length?zd(r):null}}var Uw=0;function b(t,e,n,r,i,o){e||(e={});var a,s,l=e;if("ref"in l)for(s in l={},e)s=="ref"?a=e[s]:l[s]=e[s];var u={type:t,props:l,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Uw,__i:-1,__u:0,__source:i,__self:o};if(typeof t=="function"&&(a=t.defaultProps))for(s in a)l[s]===void 0&&(l[s]=a[s]);return K.vnode&&K.vnode(u),u}function Bw({row:t,onPick:e,onHover:n}){return b("li",{id:t.domId,role:"option","aria-selected":t.active,class:`weave-hit weave-hit-${t.kind}${t.active?" weave-hit-on":""}`,onMouseMove:n,onClick:e,children:[b("span",{class:"weave-hit-badge",children:t.badge}),b("span",{class:"weave-hit-label",children:t.label}),b("span",{class:"weave-hit-detail",children:t.detail})]})}function jd(t){let[e,n]=B(Ud),r=V(0),i=V(null),o=ii(),a=V(null);ee(()=>{a.current?.focus()},[]),ee(()=>{let u=e.query.trim(),c=!0;if(!u)return i.current?.abort(),n(d=>({...d,hits:[],answered:"",loading:!1,failed:!1})),()=>{c=!1};let h=window.setTimeout(async()=>{let d=++r.current;i.current?.abort();let f=new AbortController;i.current=f,n(m=>({...m,loading:!0,failed:!1}));let v=await Rl(t.ports.fetch,u,f.signal);!c||f.signal.aborted||d!==r.current||n(m=>v.ok?{...m,hits:v.data.hits,answered:u,loading:!1,failed:!1,cursor:0}:{...m,loading:!1,failed:!0})},140);return()=>{c=!1,window.clearTimeout(h),i.current?.abort()}},[e.query,t.ports.fetch]);let s=Vd(e,t.graph),l=u=>{let c=Hd(s.rows,u);c!==null&&t.onSelect(c),t.onClose()};return b("div",{class:"weave-scrim",onClick:()=>l(null),children:b("div",{class:"weave-palette",role:"dialog","aria-modal":"true","aria-label":oi,tabIndex:-1,ref:o.ref,onClick:u=>u.stopPropagation(),onKeyDown:u=>{if(o.onKeyDown(u))return;let c=Bd(e.cursor,u.key,s.count);c.handled&&(u.preventDefault(),n(h=>({...h,cursor:c.cursor})),c.dismiss&&l(c.activate))},children:[b("input",{type:"search",class:"weave-palette-input",ref:a,value:e.query,placeholder:Wd,"aria-label":oi,"aria-controls":"weave-search-results","aria-activedescendant":s.activeDomId??void 0,onInput:u=>n(c=>({...c,query:u.currentTarget.value,cursor:0}))}),s.status===null?b("ul",{id:"weave-search-results",class:"weave-hits",role:"listbox","aria-label":oi,children:s.rows.map((u,c)=>b(Bw,{row:u,onPick:()=>l(c),onHover:()=>n(h=>({...h,cursor:c}))},u.id))}):b("p",{class:"weave-palette-status",role:"status",children:s.status}),b("p",{class:"weave-palette-foot",children:[b("span",{children:s.countLabel}),b("span",{class:"weave-palette-hint",children:Kd})]})]})})}var qd="pi-weave.selection.v1";function Yd(t,e){try{return t.setItem(qd,e??""),!0}catch{return!1}}function Xd(t,e){if(t===null)return null;let n;try{n=e.getItem(qd)}catch{return null}return n===null||n===""?null:t.model.nodes.some(r=>r.id===n)?n:null}function Zd(){return{graph:null,graphFailed:!1,note:null,recentIds:new Set,selectedId:null}}var Ww=2e3,Kw=3e3,Jd=new Set;function Vw(t,e){if(t===null)return Jd;let n=new Set(t.model.nodes.map(r=>r.id));return new Set(e.model.nodes.filter(r=>!n.has(r.id)).map(r=>r.id))}function Qd(t){if(t===null||!t.startsWith("note:"))return null;let e=t.slice(5);return e===""?null:e}function eh(t){let e=t.state,n=!1,r=!1,i=null,o=d=>{Object.entries(d).every(([f,v])=>e[f]===v)||(e={...e,...d},t.setState(e))},a=t.defer??((d,f)=>{let v=setTimeout(d,f);return()=>clearTimeout(v)}),s=async()=>{let d=Qd(e.selectedId);if(d===null){o({note:null});return}let f=await Al(t.fetch,d);f.ok&&o({note:f.data})},l=async()=>{let d=e.graph,f=await Tl(t.fetch,e.graph);if(!f.ok)return e.graph===null&&o({graphFailed:!0}),f;if(!f.cached){let v=Vw(d,f.data);o({graph:f.data,graphFailed:!1,recentIds:v}),i?.(),i=null,v.size>0&&(i=a(()=>{i=null,o({recentIds:Jd})},Kw))}return f},u=async()=>{if(!(n||r)){r=!0;try{let d=await l();d.ok&&!d.cached&&Qd(e.selectedId)!==null&&await s()}finally{r=!1}}},h=(t.repeat??((d,f)=>{let v=setInterval(d,f);return()=>clearInterval(v)}))(()=>{u()},Ww);return u(),{refresh:()=>{u()},select:async d=>{o({selectedId:d}),await s()},syncNote:s,stop:()=>{n||(n=!0,h(),i?.(),i=null)}}}function th(t){return t==="contains"||t==="anchored-at"}function jw(t,e){let n=new Set(t.map(i=>i.id)),r=new Map;for(let i of e)th(i.kind)&&i.source!==i.target&&(!n.has(i.source)||!n.has(i.target)||r.has(i.target)||r.set(i.target,i.source));return r}function qw(t,e){let n=jw(t,e),r=new Map;for(let i of t){let o=i.id,a=i.id,s=0,l=new Set([o]);for(;;){let u=n.get(o);if(u===void 0||l.has(u))break;l.add(u),a=o,o=u,s++}r.set(i.id,{key:a,depth:Math.max(0,s-1)})}return r}function Yw(t){let e=new Map;for(let n of t.values())e.set(n,(e.get(n)??0)+1);return e}var Xw={dark:["#f5bde6","#c6a0f6","#ed8796","#f5a97f","#eed49f","#a6da95","#8bd5ca","#7dc4e4","#8aadf4","#b7bdf8"],light:["#824171","#7832d4","#d20f39","#9f3e07","#7b4e10","#28641b","#106368","#14616e","#1853c8","#445198"]},Zw=3;function Qw(t,e){let n=Xw[e],i=[...Yw(t).entries()].sort((a,s)=>s[1]-a[1]||(a[0]<s[0]?-1:a[0]>s[0]?1:0)),o=new Map;return i.forEach(([a],s)=>o.set(a,n[s*Zw%n.length])),o}var Jw=.11,eb=.34;function tb(t,e,n){let r=Number.isFinite(e)&&e>0?e:0;return Nn(t,gt[n].ground,Math.min(eb,r*Jw))}var nb=.26,rb=.55;function ib(t,e,n){if(e.length===0)return t;let r=t,i=0;for(let o of e){let a=Math.min(nb,rb-i);if(a<=0)break;i+=a,r=Nn(r,o,a)}return r}function nh(t,e,n){let r=qw(t,e),i=new Map;for(let[c,h]of r)i.set(c,h.key);let o=Qw(i,n),a=new Set(t.map(c=>c.id)),s=new Map,l=(c,h)=>{let d=r.get(c)?.key,f=r.get(h)?.key;if(d===void 0||f===void 0||d===f)return;let v=s.get(c);v===void 0?s.set(c,new Set([f])):v.add(f)};for(let c of e)th(c.kind)||c.source!==c.target&&(!a.has(c.source)||!a.has(c.target)||(l(c.source,c.target),l(c.target,c.source)));let u=new Map;for(let c of t){let h=r.get(c.id);if(h===void 0)continue;let d=o.get(h.key);if(d===void 0)continue;let f=tb(d,h.depth,n),v=[...s.get(c.id)??[]].sort().map(m=>o.get(m)).filter(m=>m!==void 0);u.set(c.id,ib(f,v,n))}return u}function rh(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^=e>>>16,e>>>0}var ob=300,ab=1;function sb(t,e,n){let r=new Map(n??[]);if(r.size>0)for(let o of e){if(o.kind!=="contains"&&o.kind!=="anchored-at"||r.has(o.target))continue;let a=r.get(o.source);a!==void 0&&r.set(o.target,{x:a.x,y:a.y})}let i={ticks:ob,seed:ab,pinWarm:!0};return r.size>0&&(i.initial=r),rl({generatedAt:"",staleness:null,nodes:[...t],edges:[...e],contentDigest:""},i)}function lb(t,e){let n=0,r=0;for(let o of t){let a=rh(o.id);n^=a,r=r+a>>>0}for(let o of e){let a=rh(`${o.source}\0${o.target}\0${o.kind}`);n^=a,r=r+a>>>0}return[t.length,e.length,n>>>0,r].map(o=>o.toString(16)).join("-")}var ai="pi-weave.graph.positions.v4";function ih(t){return Math.round(t*10)/10}function ub(t,e){let n={};for(let[r,i]of e)n[r]=[ih(i.x),ih(i.y)];return JSON.stringify({v:4,key:t,at:n})}function cb(t,e){if(t===null)return null;let n;try{n=JSON.parse(t)}catch{return null}if(typeof n!="object"||n===null||Array.isArray(n))return null;let r=n;if(r.v!==4||r.key!==e)return null;let i=r.at;if(typeof i!="object"||i===null||Array.isArray(i))return null;let o=new Map;for(let[a,s]of Object.entries(i)){if(!Array.isArray(s)||s.length!==2)return null;let[l,u]=s;if(typeof l!="number"||typeof u!="number"||!Number.isFinite(l)||!Number.isFinite(u))return null;o.set(a,{x:l,y:u})}return o.size===0?null:o}function db(t,e){let n;try{n=t.getItem(ai)}catch{return null}return cb(n,e)}function hb(t,e,n){try{return t.setItem(ai,ub(e,n)),!0}catch{return!1}}function oh(t,e,n){let r=lb(e,n),i=db(t,r);if(i!==null&&e.every(a=>i.has(a.id)))return{key:r,positions:i,cached:!0};let o=sb(e,n);return hb(t,r,o),{key:r,positions:o,cached:!1}}function fb(t){return{expanded:new Set(Rr(t,new Set).clusters.keys())}}function sh(t,e){return e!==null?e:t===null?{expanded:new Set}:fb(Rt(t))}function pb(t,e){let n=new Set(t.expanded);return n.delete(e)||n.add(e),{...t,expanded:n}}function gb(t,e){return e===null?null:Ar(e,t)}function lh(t,e,n){return e===null?n:Ar(e,t)}var uh="fit",ch="frame the whole graph",dh="sliders",hh="tune the layout physics and colours",si={selected:"selected",neighborhood:"neighborhood",dimmed:"not related"};function fh(t,e){let n=e===1?"node":"nodes";return t===e?`${e} ${n}`:`${t} of ${e} ${n}`}function mb(t,e){return t===null?"Loading…":t.model.nodes.length===0?"Nothing indexed yet — add a note or run /weave-scan.":e===0?"Nothing to draw at this expansion.":null}var vb="The workspace did not load — ⟳ retries now, and the next change to the vault retries on its own.",ah={graph:cd,highlight:null,key:"",cached:!1,clusters:new Map,visible:0,total:0,empty:"Loading…"};function ph(t,e,n,r,i,o=!1,a=!0){if(t===null)return o?{...ah,empty:vb}:ah;let s=Rt(t),l=Rr(s,n.expanded),c=n.expanded.has("vault")?l.edges.filter(f=>f.source!=="vault"&&f.target!=="vault"):l.edges,h=oh(r,l.nodes,c),d=a?nh(l.nodes,c,i):void 0;return{graph:hd(l.nodes,c,h.positions,i,d),highlight:gb(c,e),key:h.key,cached:h.cached,clusters:l.clusters,visible:l.nodes.length,total:s.nodes.length,empty:mb(t,l.nodes.length)}}function gh(t,e,n){return n===null?{state:t,selectedId:null}:e.get(n)===void 0||t.expanded.has(n)?{state:t,selectedId:n}:{state:pb(t,n),selectedId:n}}var yb=.06,wb=.2,ca=.001,mh=.5;function vh(t,e){if(t.nodes.length===0)return null;let n=t.nodes.map(s=>{let l=e?.get(s.id);return{id:s.id,x:l!==void 0&&Number.isFinite(l.x)?l.x:s.x,y:l!==void 0&&Number.isFinite(l.y)?l.y:s.y,vx:0,vy:0,r:Zi(s.size)}}),r=new Map(n.map(s=>[s.id,s])),i=new Set,o=[];for(let s of t.edges){if(s.source===s.target||!r.has(s.source)||!r.has(s.target))continue;let l=`${s.source}\0${s.target}\0${s.kind}`;i.has(l)||(i.add(l),o.push({source:s.source,target:s.target,kind:s.kind}))}let a=Ji({nodes:n,links:o,seed:1}).alpha(yb).alphaMin(ca);return{tick(){a.tick()},awake(){return a.alphaTarget()>ca||a.alpha()>ca},positions(){return new Map(n.map(s=>[s.id,{x:s.x??0,y:s.y??0}]))},pin(s,l){let u=r.get(s);if(!u)return;let c=u.fx!=null&&u.fy!=null&&Math.abs(u.fx-l.x)<mh&&Math.abs(u.fy-l.y)<mh;u.fx=l.x,u.fy=l.y,a.alphaTarget(c?0:wb)},release(s){let l=r.get(s);l&&(l.fx=null,l.fy=null,a.alphaTarget(0))}}}function yh(t){let[,e]=B(0),[n,r]=B(!1),i=(a,s)=>{Qi({[a.key]:sl(a,s)}),r(!1),e(l=>l+1),t.onChange()},o=a=>{Qi(a),r(!1),e(s=>s+1),t.onChange()};return b("div",{class:"weave-tuner",children:[b("p",{class:"weave-tuner-title",children:"graph forces · ?sliders=1"}),b("label",{class:"weave-tuner-toggle",title:"hue per containment group, shade per kind",children:[b("input",{type:"checkbox",checked:t.groupColors,onChange:a=>t.onGroupColors(a.currentTarget.checked)}),b("span",{children:"colour by group"})]}),vr.map(a=>b("label",{class:"weave-tuner-row",title:a.hint,children:[b("span",{class:"weave-tuner-label",children:[a.label,b("b",{children:ll(ve[a.key])})]}),b("input",{type:"range",min:a.min,max:a.max,step:a.step,value:al(ve,a),onInput:s=>i(a,s.currentTarget.value)})]},a.key)),b("div",{class:"weave-tuner-actions",children:[b("button",{type:"button",class:"weave-chip",disabled:ul(ve),onClick:()=>o(vn),children:"reset"}),b("button",{type:"button",class:"weave-chip",title:"the pre-tuner constants, for comparison — see HAIRBALL",onClick:()=>o(ol),children:"before"}),b("button",{type:"button",class:"weave-chip",onClick:()=>{navigator.clipboard?.writeText(eo(ve)).then(()=>r(!0),()=>r(!1))},children:n?"copied ✓":"copy values"})]}),b("pre",{class:"weave-tuner-snippet",children:eo(ve)})]})}function wh(t){let e=V(null),n=V(null),r=V(null),i=V(null),o=_l(()=>{if(i.current!==null)return;let y=()=>{i.current=null;let _=r.current;_!==null&&(_.tick(),_.awake()&&(n.current?.setPositions(_.positions()),i.current=requestAnimationFrame(y)))};i.current=requestAnimationFrame(y)},[]),[a,s]=B(null),[l,u]=B(0),[c,h]=B(()=>dl(t.storage)),[d,f]=B(t.tuner===!0),v=t.scheme??Mr(t.host),m=sh(t.graph,a),g=Ze(()=>ph(t.graph,t.selectedId,m,t.storage,v,t.bootFailed,c),[t.graph,t.selectedId,m,t.storage,v,t.bootFailed,l,c]),w=V({view:m,model:g,onSelect:t.onSelect,selectedId:t.selectedId});return w.current={view:m,model:g,onSelect:t.onSelect,selectedId:t.selectedId},ee(()=>{let y=t.renderer(v);return y.onSelect(_=>{let k=gh(w.current.view,w.current.model.clusters,_);s(k.state),w.current.onSelect(k.selectedId)}),y.onHover(_=>{let{model:k,selectedId:A}=w.current;y.setHighlight(lh(k.graph.edges,_,k.highlight),_??A)}),y.onDragStart(_=>{let k=n.current?.positions().get(_);k&&(r.current?.pin(_,k),o())}),y.onDragMove((_,k)=>{r.current?.pin(_,k)}),y.onDragEnd(_=>{r.current?.release(_)}),y.mount(e.current??{clientWidth:0,clientHeight:0}),n.current=y,y.setGraph(w.current.model.graph),y.setHighlight(w.current.model.highlight,w.current.selectedId),t.fit.current=()=>y.fit(),()=>{y.destroy(),n.current=null,t.fit.current=null}},[t.renderer,v]),ee(()=>{n.current?.setGraph(g.graph)},[g.key,l,c]),ee(()=>{let y=vh(g.graph,n.current?.positions());return r.current=y,y!==null&&o(),()=>{r.current=null}},[g.key,o,l]),ee(()=>()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[]),ee(()=>{n.current?.setHighlight(g.highlight,t.selectedId)},[g.highlight,t.selectedId]),b("div",{class:"weave-graph",children:[g.empty===null?null:b("p",{class:"weave-graph-empty",children:g.empty}),b("div",{class:"weave-graph-canvas",ref:e,role:"img","aria-label":"Knowledge graph",tabIndex:-1}),d?b(yh,{groupColors:c,onGroupColors:y=>{hl(t.storage,y),h(y)},onChange:()=>{try{t.storage.setItem(ai,"")}catch{}u(y=>y+1)}}):null,b("div",{class:"weave-graph-controls",children:[b("button",{type:"button",class:"weave-chip",title:ch,onClick:()=>n.current?.fit(),children:uh}),b("button",{type:"button",class:d?"weave-chip weave-chip-on":"weave-chip",title:hh,"aria-pressed":d,onClick:()=>f(!d),children:dh}),b("span",{class:"weave-graph-legend",children:[b("span",{class:"weave-legend-on",children:["◉ ",si.selected]}),b("span",{class:"weave-legend-near",children:["● ",si.neighborhood]}),b("span",{class:"weave-legend-dim",children:["· ",si.dimmed]})]})]}),b("p",{class:"weave-graph-count",children:fh(g.visible,g.total)})]})}function bh(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function bb(t){if(Array.isArray(t))return t}function xb(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,i,o,a,s=[],l=!0,u=!1;try{if(o=(n=n.call(t)).next,e!==0)for(;!(l=(r=o.call(n)).done)&&(s.push(r.value),s.length!==e);l=!0);}catch(c){u=!0,i=c}finally{try{if(!l&&n.return!=null&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw i}}return s}}function _b(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
397
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Zc(t){return Yv(t)||Xv(t)||Oo(t)||Zv()}function Qv(t,e){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.indexOf(r)!==-1)continue;n[r]=t[r]}return n}function Jo(t,e){if(t==null)return{};var n,r,i=Qv(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}var Qc=(function(){function t(e,n){le(this,t),this.key=e,this.size=n}return ue(t,null,[{key:"compare",value:function(n,r){return n.size>r.size?-1:n.size<r.size||n.key>r.key?1:-1}}])})(),Jc=(function(){function t(){le(this,t),T(this,"width",0),T(this,"height",0),T(this,"cellSize",0),T(this,"columns",0),T(this,"rows",0),T(this,"cells",{})}return ue(t,[{key:"resizeAndClear",value:function(n,r){this.width=n.width,this.height=n.height,this.cellSize=r,this.columns=Math.ceil(n.width/r),this.rows=Math.ceil(n.height/r),this.cells={}}},{key:"getIndex",value:function(n){var r=Math.floor(n.x/this.cellSize),i=Math.floor(n.y/this.cellSize);return i*this.columns+r}},{key:"add",value:function(n,r,i){var o=new Qc(n,r),a=this.getIndex(i),s=this.cells[a];s||(s=[],this.cells[a]=s),s.push(o)}},{key:"organize",value:function(){for(var n in this.cells){var r=this.cells[n];r.sort(Qc.compare)}}},{key:"getLabelsToDisplay",value:function(n,r){var i=this.cellSize*this.cellSize,o=i/n/n,a=o*r/i,s=Math.ceil(a),l=[];for(var u in this.cells)for(var c=this.cells[u],h=0;h<Math.min(s,c.length);h++)l.push(c[h].key);return l}}])})();function Jv(t){var e=t.graph,n=t.hoveredNode,r=t.highlightedNodes,i=t.displayedNodeLabels,o=[];return e.forEachEdge(function(a,s,l,u){(l===n||u===n||r.has(l)||r.has(u)||i.has(l)&&i.has(u))&&o.push(a)}),o}var ed=150,td=50,ot=Object.prototype.hasOwnProperty;function ey(t,e,n){if(!ot.call(n,"x")||!ot.call(n,"y"))throw new Error('Sigma: could not find a valid position (x, y) for node "'.concat(e,'". All your nodes must have a number "x" and "y". Maybe your forgot to apply a layout or your "nodeReducer" is not returning the correct data?'));return n.color||(n.color=t.defaultNodeColor),!n.label&&n.label!==""&&(n.label=null),n.label!==void 0&&n.label!==null?n.label=""+n.label:n.label=null,n.size||(n.size=2),ot.call(n,"hidden")||(n.hidden=!1),ot.call(n,"highlighted")||(n.highlighted=!1),ot.call(n,"forceLabel")||(n.forceLabel=!1),(!n.type||n.type==="")&&(n.type=t.defaultNodeType),n.zIndex||(n.zIndex=0),n}function ty(t,e,n){return n.color||(n.color=t.defaultEdgeColor),n.label||(n.label=""),n.size||(n.size=.5),ot.call(n,"hidden")||(n.hidden=!1),ot.call(n,"forceLabel")||(n.forceLabel=!1),(!n.type||n.type==="")&&(n.type=t.defaultEdgeType),n.zIndex||(n.zIndex=0),n}var ny=(function(t){function e(n,r){var i,o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(le(this,e),i=_e(this,e),T(i,"elements",{}),T(i,"canvasContexts",{}),T(i,"webGLContexts",{}),T(i,"pickingLayers",new Set),T(i,"textures",{}),T(i,"frameBuffers",{}),T(i,"activeListeners",{}),T(i,"labelGrid",new Jc),T(i,"nodeDataCache",{}),T(i,"edgeDataCache",{}),T(i,"nodeProgramIndex",{}),T(i,"edgeProgramIndex",{}),T(i,"nodesWithForcedLabels",new Set),T(i,"edgesWithForcedLabels",new Set),T(i,"nodeExtent",{x:[0,1],y:[0,1]}),T(i,"nodeZExtent",[1/0,-1/0]),T(i,"edgeZExtent",[1/0,-1/0]),T(i,"matrix",Ie()),T(i,"invMatrix",Ie()),T(i,"correctionRatio",1),T(i,"customBBox",null),T(i,"normalizationFunction",Zo({x:[0,1],y:[0,1]})),T(i,"graphToViewportRatio",1),T(i,"itemIDsIndex",{}),T(i,"nodeIndices",{}),T(i,"edgeIndices",{}),T(i,"width",0),T(i,"height",0),T(i,"pixelRatio",Yo()),T(i,"pickingDownSizingRatio",2*i.pixelRatio),T(i,"displayedNodeLabels",new Set),T(i,"displayedEdgeLabels",new Set),T(i,"highlightedNodes",new Set),T(i,"hoveredNode",null),T(i,"hoveredEdge",null),T(i,"renderFrame",null),T(i,"renderHighlightedNodesFrame",null),T(i,"needToProcess",!1),T(i,"checkEdgesEventsFrame",null),T(i,"nodePrograms",{}),T(i,"nodeHoverPrograms",{}),T(i,"edgePrograms",{}),i.settings=Yc(o),jr(i.settings),jc(n),!(r instanceof HTMLElement))throw new Error("Sigma: container should be an html element.");i.graph=n,i.container=r,i.createWebGLContext("edges",{picking:o.enableEdgeEvents}),i.createCanvasContext("edgeLabels"),i.createWebGLContext("nodes",{picking:!0}),i.createCanvasContext("labels"),i.createCanvasContext("hovers"),i.createWebGLContext("hoverNodes"),i.createCanvasContext("mouse",{style:{touchAction:"none",userSelect:"none"}}),i.resize();for(var a in i.settings.nodeProgramClasses)i.registerNodeProgram(a,i.settings.nodeProgramClasses[a],i.settings.nodeHoverProgramClasses[a]);for(var s in i.settings.edgeProgramClasses)i.registerEdgeProgram(s,i.settings.edgeProgramClasses[s]);return i.camera=new Xc,i.bindCameraHandlers(),i.mouseCaptor=new Kv(i.elements.mouse,i),i.mouseCaptor.setSettings(i.settings),i.touchCaptor=new qv(i.elements.mouse,i),i.touchCaptor.setSettings(i.settings),i.bindEventHandlers(),i.bindGraphHandlers(),i.handleSettingsUpdate(),i.refresh(),i}return ke(e,t),ue(e,[{key:"registerNodeProgram",value:function(r,i,o){return this.nodePrograms[r]&&this.nodePrograms[r].kill(),this.nodeHoverPrograms[r]&&this.nodeHoverPrograms[r].kill(),this.nodePrograms[r]=new i(this.webGLContexts.nodes,this.frameBuffers.nodes,this),this.nodeHoverPrograms[r]=new(o||i)(this.webGLContexts.hoverNodes,null,this),this}},{key:"registerEdgeProgram",value:function(r,i){return this.edgePrograms[r]&&this.edgePrograms[r].kill(),this.edgePrograms[r]=new i(this.webGLContexts.edges,this.frameBuffers.edges,this),this}},{key:"unregisterNodeProgram",value:function(r){if(this.nodePrograms[r]){var i=this.nodePrograms,o=i[r],a=Jo(i,[r].map(Nt));o.kill(),this.nodePrograms=a}if(this.nodeHoverPrograms[r]){var s=this.nodeHoverPrograms,l=s[r],u=Jo(s,[r].map(Nt));l.kill(),this.nodePrograms=u}return this}},{key:"unregisterEdgeProgram",value:function(r){if(this.edgePrograms[r]){var i=this.edgePrograms,o=i[r],a=Jo(i,[r].map(Nt));o.kill(),this.edgePrograms=a}return this}},{key:"resetWebGLTexture",value:function(r){var i=this.webGLContexts[r],o=this.frameBuffers[r],a=this.textures[r];a&&i.deleteTexture(a);var s=i.createTexture();return i.bindFramebuffer(i.FRAMEBUFFER,o),i.bindTexture(i.TEXTURE_2D,s),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,this.width,this.height,0,i.RGBA,i.UNSIGNED_BYTE,null),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,s,0),this.textures[r]=s,this}},{key:"bindCameraHandlers",value:function(){var r=this;return this.activeListeners.camera=function(){r.scheduleRender()},this.camera.on("updated",this.activeListeners.camera),this}},{key:"unbindCameraHandlers",value:function(){return this.camera.removeListener("updated",this.activeListeners.camera),this}},{key:"getNodeAtPosition",value:function(r){var i=r.x,o=r.y,a=Uo(this.webGLContexts.nodes,this.frameBuffers.nodes,i,o,this.pixelRatio,this.pickingDownSizingRatio),s=$o.apply(void 0,Zc(a)),l=this.itemIDsIndex[s];return l&&l.type==="node"?l.id:null}},{key:"bindEventHandlers",value:function(){var r=this;this.activeListeners.handleResize=function(){r.scheduleRefresh()},window.addEventListener("resize",this.activeListeners.handleResize),this.activeListeners.handleMove=function(o){var a=Cn(o),s={event:a,preventSigmaDefault:function(){a.preventSigmaDefault()}},l=r.getNodeAtPosition(a);if(l&&r.hoveredNode!==l&&!r.nodeDataCache[l].hidden){r.hoveredNode&&r.emit("leaveNode",G(G({},s),{},{node:r.hoveredNode})),r.hoveredNode=l,r.emit("enterNode",G(G({},s),{},{node:l})),r.scheduleHighlightedNodesRender();return}if(r.hoveredNode&&r.getNodeAtPosition(a)!==r.hoveredNode){var u=r.hoveredNode;r.hoveredNode=null,r.emit("leaveNode",G(G({},s),{},{node:u})),r.scheduleHighlightedNodesRender();return}if(r.settings.enableEdgeEvents){var c=r.hoveredNode?null:r.getEdgeAtPoint(s.event.x,s.event.y);c!==r.hoveredEdge&&(r.hoveredEdge&&r.emit("leaveEdge",G(G({},s),{},{edge:r.hoveredEdge})),c&&r.emit("enterEdge",G(G({},s),{},{edge:c})),r.hoveredEdge=c)}},this.activeListeners.handleMoveBody=function(o){var a=Cn(o);r.emit("moveBody",{event:a,preventSigmaDefault:function(){a.preventSigmaDefault()}})},this.activeListeners.handleLeave=function(o){var a=Cn(o),s={event:a,preventSigmaDefault:function(){a.preventSigmaDefault()}};r.hoveredNode&&(r.emit("leaveNode",G(G({},s),{},{node:r.hoveredNode})),r.scheduleHighlightedNodesRender()),r.settings.enableEdgeEvents&&r.hoveredEdge&&(r.emit("leaveEdge",G(G({},s),{},{edge:r.hoveredEdge})),r.scheduleHighlightedNodesRender()),r.emit("leaveStage",G({},s))},this.activeListeners.handleEnter=function(o){var a=Cn(o),s={event:a,preventSigmaDefault:function(){a.preventSigmaDefault()}};r.emit("enterStage",G({},s))};var i=function(a){return function(s){var l=Cn(s),u={event:l,preventSigmaDefault:function(){l.preventSigmaDefault()}},c=r.getNodeAtPosition(l);if(c)return r.emit("".concat(a,"Node"),G(G({},u),{},{node:c}));if(r.settings.enableEdgeEvents){var h=r.getEdgeAtPoint(l.x,l.y);if(h)return r.emit("".concat(a,"Edge"),G(G({},u),{},{edge:h}))}return r.emit("".concat(a,"Stage"),u)}};return this.activeListeners.handleClick=i("click"),this.activeListeners.handleRightClick=i("rightClick"),this.activeListeners.handleDoubleClick=i("doubleClick"),this.activeListeners.handleWheel=i("wheel"),this.activeListeners.handleDown=i("down"),this.activeListeners.handleUp=i("up"),this.mouseCaptor.on("mousemove",this.activeListeners.handleMove),this.mouseCaptor.on("mousemovebody",this.activeListeners.handleMoveBody),this.mouseCaptor.on("click",this.activeListeners.handleClick),this.mouseCaptor.on("rightClick",this.activeListeners.handleRightClick),this.mouseCaptor.on("doubleClick",this.activeListeners.handleDoubleClick),this.mouseCaptor.on("wheel",this.activeListeners.handleWheel),this.mouseCaptor.on("mousedown",this.activeListeners.handleDown),this.mouseCaptor.on("mouseup",this.activeListeners.handleUp),this.mouseCaptor.on("mouseleave",this.activeListeners.handleLeave),this.mouseCaptor.on("mouseenter",this.activeListeners.handleEnter),this.touchCaptor.on("touchdown",this.activeListeners.handleDown),this.touchCaptor.on("touchdown",this.activeListeners.handleMove),this.touchCaptor.on("touchup",this.activeListeners.handleUp),this.touchCaptor.on("touchmove",this.activeListeners.handleMove),this.touchCaptor.on("tap",this.activeListeners.handleClick),this.touchCaptor.on("doubletap",this.activeListeners.handleDoubleClick),this.touchCaptor.on("touchmove",this.activeListeners.handleMoveBody),this}},{key:"bindGraphHandlers",value:function(){var r=this,i=this.graph,o=new Set(["x","y","zIndex","type"]);return this.activeListeners.eachNodeAttributesUpdatedGraphUpdate=function(a){var s,l=(s=a.hints)===null||s===void 0?void 0:s.attributes;r.graph.forEachNode(function(c){return r.updateNode(c)});var u=!l||l.some(function(c){return o.has(c)});r.refresh({partialGraph:{nodes:i.nodes()},skipIndexation:!u,schedule:!0})},this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate=function(a){var s,l=(s=a.hints)===null||s===void 0?void 0:s.attributes;r.graph.forEachEdge(function(c){return r.updateEdge(c)});var u=l&&["zIndex","type"].some(function(c){return l?.includes(c)});r.refresh({partialGraph:{edges:i.edges()},skipIndexation:!u,schedule:!0})},this.activeListeners.addNodeGraphUpdate=function(a){var s=a.key;r.addNode(s),r.refresh({partialGraph:{nodes:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.updateNodeGraphUpdate=function(a){var s=a.key;r.refresh({partialGraph:{nodes:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropNodeGraphUpdate=function(a){var s=a.key;r.removeNode(s),r.refresh({schedule:!0})},this.activeListeners.addEdgeGraphUpdate=function(a){var s=a.key;r.addEdge(s),r.refresh({partialGraph:{edges:[s]},schedule:!0})},this.activeListeners.updateEdgeGraphUpdate=function(a){var s=a.key;r.refresh({partialGraph:{edges:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropEdgeGraphUpdate=function(a){var s=a.key;r.removeEdge(s),r.refresh({schedule:!0})},this.activeListeners.clearEdgesGraphUpdate=function(){r.clearEdgeState(),r.clearEdgeIndices(),r.refresh({schedule:!0})},this.activeListeners.clearGraphUpdate=function(){r.clearEdgeState(),r.clearNodeState(),r.clearEdgeIndices(),r.clearNodeIndices(),r.refresh({schedule:!0})},i.on("nodeAdded",this.activeListeners.addNodeGraphUpdate),i.on("nodeDropped",this.activeListeners.dropNodeGraphUpdate),i.on("nodeAttributesUpdated",this.activeListeners.updateNodeGraphUpdate),i.on("eachNodeAttributesUpdated",this.activeListeners.eachNodeAttributesUpdatedGraphUpdate),i.on("edgeAdded",this.activeListeners.addEdgeGraphUpdate),i.on("edgeDropped",this.activeListeners.dropEdgeGraphUpdate),i.on("edgeAttributesUpdated",this.activeListeners.updateEdgeGraphUpdate),i.on("eachEdgeAttributesUpdated",this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate),i.on("edgesCleared",this.activeListeners.clearEdgesGraphUpdate),i.on("cleared",this.activeListeners.clearGraphUpdate),this}},{key:"unbindGraphHandlers",value:function(){var r=this.graph;r.removeListener("nodeAdded",this.activeListeners.addNodeGraphUpdate),r.removeListener("nodeDropped",this.activeListeners.dropNodeGraphUpdate),r.removeListener("nodeAttributesUpdated",this.activeListeners.updateNodeGraphUpdate),r.removeListener("eachNodeAttributesUpdated",this.activeListeners.eachNodeAttributesUpdatedGraphUpdate),r.removeListener("edgeAdded",this.activeListeners.addEdgeGraphUpdate),r.removeListener("edgeDropped",this.activeListeners.dropEdgeGraphUpdate),r.removeListener("edgeAttributesUpdated",this.activeListeners.updateEdgeGraphUpdate),r.removeListener("eachEdgeAttributesUpdated",this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate),r.removeListener("edgesCleared",this.activeListeners.clearEdgesGraphUpdate),r.removeListener("cleared",this.activeListeners.clearGraphUpdate)}},{key:"getEdgeAtPoint",value:function(r,i){var o=Uo(this.webGLContexts.edges,this.frameBuffers.edges,r,i,this.pixelRatio,this.pickingDownSizingRatio),a=$o.apply(void 0,Zc(o)),s=this.itemIDsIndex[a];return s&&s.type==="edge"?s.id:null}},{key:"process",value:function(){var r=this;this.emit("beforeProcess");var i=this.graph,o=this.settings,a=this.getDimensions();if(this.nodeExtent=Vc(this.graph),!this.settings.autoRescale){var s=a.width,l=a.height,u=this.nodeExtent,c=u.x,h=u.y;this.nodeExtent={x:[(c[0]+c[1])/2-s/2,(c[0]+c[1])/2+s/2],y:[(h[0]+h[1])/2-l/2,(h[0]+h[1])/2+l/2]}}this.normalizationFunction=Zo(this.customBBox||this.nodeExtent);var d=new Xc,f=Qt(d.getState(),a,this.getGraphDimensions(),this.getStagePadding());this.labelGrid.resizeAndClear(a,o.labelGridCellSize);for(var v={},m={},g={},w={},y=1,_=i.nodes(),k=0,A=_.length;k<A;k++){var R=_[k],M=this.nodeDataCache[R],L=i.getNodeAttributes(R);M.x=L.x,M.y=L.y,this.normalizationFunction.applyTo(M),typeof M.label=="string"&&!M.hidden&&this.labelGrid.add(R,M.size,this.framedGraphToViewport(M,{matrix:f})),v[M.type]=(v[M.type]||0)+1}this.labelGrid.organize();for(var S in this.nodePrograms){if(!ot.call(this.nodePrograms,S))throw new Error('Sigma: could not find a suitable program for node type "'.concat(S,'"!'));this.nodePrograms[S].reallocate(v[S]||0),v[S]=0}this.settings.zIndex&&this.nodeZExtent[0]!==this.nodeZExtent[1]&&(_=Xo(this.nodeZExtent,function(sn){return r.nodeDataCache[sn].zIndex},_));for(var D=0,$=_.length;D<$;D++){var W=_[D];m[W]=y,w[m[W]]={type:"node",id:W},y++;var te=this.nodeDataCache[W];this.addNodeToProgram(W,m[W],v[te.type]++)}for(var ge={},he=i.edges(),Ve=0,Mt=he.length;Ve<Mt;Ve++){var Fe=he[Ve],Oe=this.edgeDataCache[Fe];ge[Oe.type]=(ge[Oe.type]||0)+1}this.settings.zIndex&&this.edgeZExtent[0]!==this.edgeZExtent[1]&&(he=Xo(this.edgeZExtent,function(sn){return r.edgeDataCache[sn].zIndex},he));for(var ze in this.edgePrograms){if(!ot.call(this.edgePrograms,ze))throw new Error('Sigma: could not find a suitable program for edge type "'.concat(ze,'"!'));this.edgePrograms[ze].reallocate(ge[ze]||0),ge[ze]=0}for(var je=0,an=he.length;je<an;je++){var De=he[je];g[De]=y,w[g[De]]={type:"edge",id:De},y++;var X=this.edgeDataCache[De];this.addEdgeToProgram(De,g[De],ge[X.type]++)}return this.itemIDsIndex=w,this.nodeIndices=m,this.edgeIndices=g,this.emit("afterProcess"),this}},{key:"handleSettingsUpdate",value:function(r){var i=this,o=this.settings;if(this.camera.minRatio=o.minCameraRatio,this.camera.maxRatio=o.maxCameraRatio,this.camera.enabledZooming=o.enableCameraZooming,this.camera.enabledPanning=o.enableCameraPanning,this.camera.enabledRotation=o.enableCameraRotation,o.cameraPanBoundaries?this.camera.clean=function(c){return i.cleanCameraState(c,o.cameraPanBoundaries&&Wr(o.cameraPanBoundaries)==="object"?o.cameraPanBoundaries:{})}:this.camera.clean=null,this.camera.setState(this.camera.validateState(this.camera.getState())),r){if(r.edgeProgramClasses!==o.edgeProgramClasses){for(var a in o.edgeProgramClasses)o.edgeProgramClasses[a]!==r.edgeProgramClasses[a]&&this.registerEdgeProgram(a,o.edgeProgramClasses[a]);for(var s in r.edgeProgramClasses)o.edgeProgramClasses[s]||this.unregisterEdgeProgram(s)}if(r.nodeProgramClasses!==o.nodeProgramClasses||r.nodeHoverProgramClasses!==o.nodeHoverProgramClasses){for(var l in o.nodeProgramClasses)(o.nodeProgramClasses[l]!==r.nodeProgramClasses[l]||o.nodeHoverProgramClasses[l]!==r.nodeHoverProgramClasses[l])&&this.registerNodeProgram(l,o.nodeProgramClasses[l],o.nodeHoverProgramClasses[l]);for(var u in r.nodeProgramClasses)o.nodeProgramClasses[u]||this.unregisterNodeProgram(u)}}return this.mouseCaptor.setSettings(this.settings),this.touchCaptor.setSettings(this.settings),this}},{key:"cleanCameraState",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=i.tolerance,a=o===void 0?0:o,s=i.boundaries,l=G({},r),u=s||this.nodeExtent,c=ft(u.x,2),h=c[0],d=c[1],f=ft(u.y,2),v=f[0],m=f[1],g=[this.graphToViewport({x:h,y:v},{cameraState:r}),this.graphToViewport({x:d,y:v},{cameraState:r}),this.graphToViewport({x:h,y:m},{cameraState:r}),this.graphToViewport({x:d,y:m},{cameraState:r})],w=1/0,y=-1/0,_=1/0,k=-1/0;g.forEach(function(ge){var he=ge.x,Ve=ge.y;w=Math.min(w,he),y=Math.max(y,he),_=Math.min(_,Ve),k=Math.max(k,Ve)});var A=y-w,R=k-_,M=this.getDimensions(),L=M.width,S=M.height,D=0,$=0;if(A>=L?y<L-a?D=y-(L-a):w>a&&(D=w-a):y>L+a?D=y-(L+a):w<-a&&(D=w+a),R>=S?k<S-a?$=k-(S-a):_>a&&($=_-a):k>S+a?$=k-(S+a):_<-a&&($=_+a),D||$){var W=this.viewportToFramedGraph({x:0,y:0},{cameraState:r}),te=this.viewportToFramedGraph({x:D,y:$},{cameraState:r});D=te.x-W.x,$=te.y-W.y,l.x+=D,l.y+=$}return l}},{key:"renderLabels",value:function(){if(!this.settings.renderLabels)return this;var r=this.camera.getState(),i=this.labelGrid.getLabelsToDisplay(r.ratio,this.settings.labelDensity);Qo(i,this.nodesWithForcedLabels),this.displayedNodeLabels=new Set;for(var o=this.canvasContexts.labels,a=0,s=i.length;a<s;a++){var l=i[a],u=this.nodeDataCache[l];if(!this.displayedNodeLabels.has(l)&&!u.hidden){var c=this.framedGraphToViewport(u),h=c.x,d=c.y,f=this.scaleSize(u.size);if(!(!u.forceLabel&&f<this.settings.labelRenderedSizeThreshold)&&!(h<-ed||h>this.width+ed||d<-td||d>this.height+td)){this.displayedNodeLabels.add(l);var v=this.settings.defaultDrawNodeLabel,m=this.nodePrograms[u.type],g=m?.drawLabel||v;g(o,G(G({key:l},u),{},{size:f,x:h,y:d}),this.settings)}}}return this}},{key:"renderEdgeLabels",value:function(){if(!this.settings.renderEdgeLabels)return this;var r=this.canvasContexts.edgeLabels;r.clearRect(0,0,this.width,this.height);var i=Jv({graph:this.graph,hoveredNode:this.hoveredNode,displayedNodeLabels:this.displayedNodeLabels,highlightedNodes:this.highlightedNodes});Qo(i,this.edgesWithForcedLabels);for(var o=new Set,a=0,s=i.length;a<s;a++){var l=i[a],u=this.graph.extremities(l),c=this.nodeDataCache[u[0]],h=this.nodeDataCache[u[1]],d=this.edgeDataCache[l];if(!o.has(l)&&!(d.hidden||c.hidden||h.hidden)){var f=this.settings.defaultDrawEdgeLabel,v=this.edgePrograms[d.type],m=v?.drawLabel||f;m(r,G(G({key:l},d),{},{size:this.scaleSize(d.size)}),G(G(G({key:u[0]},c),this.framedGraphToViewport(c)),{},{size:this.scaleSize(c.size)}),G(G(G({key:u[1]},h),this.framedGraphToViewport(h)),{},{size:this.scaleSize(h.size)}),this.settings),o.add(l)}}return this.displayedEdgeLabels=o,this}},{key:"renderHighlightedNodes",value:function(){var r=this,i=this.canvasContexts.hovers;i.clearRect(0,0,this.width,this.height);var o=function(f){var v=r.nodeDataCache[f],m=r.framedGraphToViewport(v),g=m.x,w=m.y,y=r.scaleSize(v.size),_=r.settings.defaultDrawNodeHover,k=r.nodePrograms[v.type],A=k?.drawHover||_;A(i,G(G({key:f},v),{},{size:y,x:g,y:w}),r.settings)},a=[];this.hoveredNode&&!this.nodeDataCache[this.hoveredNode].hidden&&a.push(this.hoveredNode),this.highlightedNodes.forEach(function(d){d!==r.hoveredNode&&a.push(d)}),a.forEach(function(d){return o(d)});var s={};a.forEach(function(d){var f=r.nodeDataCache[d].type;s[f]=(s[f]||0)+1});for(var l in this.nodeHoverPrograms)this.nodeHoverPrograms[l].reallocate(s[l]||0),s[l]=0;a.forEach(function(d){var f=r.nodeDataCache[d];r.nodeHoverPrograms[f.type].process(0,s[f.type]++,f)}),this.webGLContexts.hoverNodes.clear(this.webGLContexts.hoverNodes.COLOR_BUFFER_BIT);var u=this.getRenderParams();for(var c in this.nodeHoverPrograms){var h=this.nodeHoverPrograms[c];h.render(u)}}},{key:"scheduleHighlightedNodesRender",value:function(){var r=this;this.renderHighlightedNodesFrame||this.renderFrame||(this.renderHighlightedNodesFrame=requestAnimationFrame(function(){r.renderHighlightedNodesFrame=null,r.renderHighlightedNodes(),r.renderEdgeLabels()}))}},{key:"render",value:function(){var r=this;this.emit("beforeRender");var i=function(){return r.emit("afterRender"),r};if(this.renderFrame&&(cancelAnimationFrame(this.renderFrame),this.renderFrame=null),this.resize(),this.needToProcess&&this.process(),this.needToProcess=!1,this.clear(),this.pickingLayers.forEach(function(g){return r.resetWebGLTexture(g)}),!this.graph.order)return i();var o=this.mouseCaptor,a=this.camera.isAnimated()||o.isMoving||o.draggedEvents||o.currentWheelDirection,s=this.camera.getState(),l=this.getDimensions(),u=this.getGraphDimensions(),c=this.getStagePadding();this.matrix=Qt(s,l,u,c),this.invMatrix=Qt(s,l,u,c,!0),this.correctionRatio=Kc(this.matrix,s,l),this.graphToViewportRatio=this.getGraphToViewportRatio();var h=this.getRenderParams();for(var d in this.nodePrograms){var f=this.nodePrograms[d];f.render(h)}if(!this.settings.hideEdgesOnMove||!a)for(var v in this.edgePrograms){var m=this.edgePrograms[v];m.render(h)}return this.settings.hideLabelsOnMove&&a||(this.renderLabels(),this.renderEdgeLabels(),this.renderHighlightedNodes()),i()}},{key:"addNode",value:function(r){var i=Object.assign({},this.graph.getNodeAttributes(r));this.settings.nodeReducer&&(i=this.settings.nodeReducer(r,i));var o=ey(this.settings,r,i);this.nodeDataCache[r]=o,this.nodesWithForcedLabels.delete(r),o.forceLabel&&!o.hidden&&this.nodesWithForcedLabels.add(r),this.highlightedNodes.delete(r),o.highlighted&&!o.hidden&&this.highlightedNodes.add(r),this.settings.zIndex&&(o.zIndex<this.nodeZExtent[0]&&(this.nodeZExtent[0]=o.zIndex),o.zIndex>this.nodeZExtent[1]&&(this.nodeZExtent[1]=o.zIndex))}},{key:"updateNode",value:function(r){this.addNode(r);var i=this.nodeDataCache[r];this.normalizationFunction.applyTo(i)}},{key:"removeNode",value:function(r){delete this.nodeDataCache[r],delete this.nodeProgramIndex[r],this.highlightedNodes.delete(r),this.hoveredNode===r&&(this.hoveredNode=null),this.nodesWithForcedLabels.delete(r)}},{key:"addEdge",value:function(r){var i=Object.assign({},this.graph.getEdgeAttributes(r));this.settings.edgeReducer&&(i=this.settings.edgeReducer(r,i));var o=ty(this.settings,r,i);this.edgeDataCache[r]=o,this.edgesWithForcedLabels.delete(r),o.forceLabel&&!o.hidden&&this.edgesWithForcedLabels.add(r),this.settings.zIndex&&(o.zIndex<this.edgeZExtent[0]&&(this.edgeZExtent[0]=o.zIndex),o.zIndex>this.edgeZExtent[1]&&(this.edgeZExtent[1]=o.zIndex))}},{key:"updateEdge",value:function(r){this.addEdge(r)}},{key:"removeEdge",value:function(r){delete this.edgeDataCache[r],delete this.edgeProgramIndex[r],this.hoveredEdge===r&&(this.hoveredEdge=null),this.edgesWithForcedLabels.delete(r)}},{key:"clearNodeIndices",value:function(){this.labelGrid=new Jc,this.nodeExtent={x:[0,1],y:[0,1]},this.nodeDataCache={},this.edgeProgramIndex={},this.nodesWithForcedLabels=new Set,this.nodeZExtent=[1/0,-1/0],this.highlightedNodes=new Set}},{key:"clearEdgeIndices",value:function(){this.edgeDataCache={},this.edgeProgramIndex={},this.edgesWithForcedLabels=new Set,this.edgeZExtent=[1/0,-1/0]}},{key:"clearIndices",value:function(){this.clearEdgeIndices(),this.clearNodeIndices()}},{key:"clearNodeState",value:function(){this.displayedNodeLabels=new Set,this.highlightedNodes=new Set,this.hoveredNode=null}},{key:"clearEdgeState",value:function(){this.displayedEdgeLabels=new Set,this.highlightedNodes=new Set,this.hoveredEdge=null}},{key:"clearState",value:function(){this.clearEdgeState(),this.clearNodeState()}},{key:"addNodeToProgram",value:function(r,i,o){var a=this.nodeDataCache[r],s=this.nodePrograms[a.type];if(!s)throw new Error('Sigma: could not find a suitable program for node type "'.concat(a.type,'"!'));s.process(i,o,a),this.nodeProgramIndex[r]=o}},{key:"addEdgeToProgram",value:function(r,i,o){var a=this.edgeDataCache[r],s=this.edgePrograms[a.type];if(!s)throw new Error('Sigma: could not find a suitable program for edge type "'.concat(a.type,'"!'));var l=this.graph.extremities(r),u=this.nodeDataCache[l[0]],c=this.nodeDataCache[l[1]];s.process(i,o,u,c,a),this.edgeProgramIndex[r]=o}},{key:"getRenderParams",value:function(){return{matrix:this.matrix,invMatrix:this.invMatrix,width:this.width,height:this.height,pixelRatio:this.pixelRatio,zoomRatio:this.camera.ratio,cameraAngle:this.camera.angle,sizeRatio:1/this.scaleSize(),correctionRatio:this.correctionRatio,downSizingRatio:this.pickingDownSizingRatio,minEdgeThickness:this.settings.minEdgeThickness,antiAliasingFeather:this.settings.antiAliasingFeather}}},{key:"getStagePadding",value:function(){var r=this.settings,i=r.stagePadding,o=r.autoRescale;return o&&i||0}},{key:"createLayer",value:function(r,i){var o=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this.elements[r])throw new Error('Sigma: a layer named "'.concat(r,'" already exists'));var a=qc(i,{position:"absolute"},{class:"sigma-".concat(r)});return o.style&&Object.assign(a.style,o.style),this.elements[r]=a,"beforeLayer"in o&&o.beforeLayer?this.elements[o.beforeLayer].before(a):"afterLayer"in o&&o.afterLayer?this.elements[o.afterLayer].after(a):this.container.appendChild(a),a}},{key:"createCanvas",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.createLayer(r,"canvas",i)}},{key:"createCanvasContext",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=this.createCanvas(r,i),a={preserveDrawingBuffer:!1,antialias:!1};return this.canvasContexts[r]=o.getContext("2d",a),this}},{key:"createWebGLContext",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=i?.canvas||this.createCanvas(r,i);i.hidden&&o.remove();var a=G({preserveDrawingBuffer:!1,antialias:!1},i),s;s=o.getContext("webgl2",a),s||(s=o.getContext("webgl",a)),s||(s=o.getContext("experimental-webgl",a));var l=s;if(this.webGLContexts[r]=l,l.blendFunc(l.ONE,l.ONE_MINUS_SRC_ALPHA),i.picking){this.pickingLayers.add(r);var u=l.createFramebuffer();if(!u)throw new Error("Sigma: cannot create a new frame buffer for layer ".concat(r));this.frameBuffers[r]=u}return l}},{key:"killLayer",value:function(r){var i=this.elements[r];if(!i)throw new Error("Sigma: cannot kill layer ".concat(r,", which does not exist"));if(this.webGLContexts[r]){var o,a=this.webGLContexts[r];(o=a.getExtension("WEBGL_lose_context"))===null||o===void 0||o.loseContext(),delete this.webGLContexts[r]}else this.canvasContexts[r]&&delete this.canvasContexts[r];return i.remove(),delete this.elements[r],this}},{key:"getCamera",value:function(){return this.camera}},{key:"setCamera",value:function(r){this.unbindCameraHandlers(),this.camera=r,this.bindCameraHandlers()}},{key:"getContainer",value:function(){return this.container}},{key:"getGraph",value:function(){return this.graph}},{key:"setGraph",value:function(r){r!==this.graph&&(this.hoveredNode&&!r.hasNode(this.hoveredNode)&&(this.hoveredNode=null),this.hoveredEdge&&!r.hasEdge(this.hoveredEdge)&&(this.hoveredEdge=null),this.unbindGraphHandlers(),this.checkEdgesEventsFrame!==null&&(cancelAnimationFrame(this.checkEdgesEventsFrame),this.checkEdgesEventsFrame=null),this.graph=r,this.bindGraphHandlers(),this.refresh())}},{key:"getMouseCaptor",value:function(){return this.mouseCaptor}},{key:"getTouchCaptor",value:function(){return this.touchCaptor}},{key:"getDimensions",value:function(){return{width:this.width,height:this.height}}},{key:"getGraphDimensions",value:function(){var r=this.customBBox||this.nodeExtent;return{width:r.x[1]-r.x[0]||1,height:r.y[1]-r.y[0]||1}}},{key:"getNodeDisplayData",value:function(r){var i=this.nodeDataCache[r];return i?Object.assign({},i):void 0}},{key:"getEdgeDisplayData",value:function(r){var i=this.edgeDataCache[r];return i?Object.assign({},i):void 0}},{key:"getNodeDisplayedLabels",value:function(){return new Set(this.displayedNodeLabels)}},{key:"getEdgeDisplayedLabels",value:function(){return new Set(this.displayedEdgeLabels)}},{key:"getSettings",value:function(){return G({},this.settings)}},{key:"getSetting",value:function(r){return this.settings[r]}},{key:"setSetting",value:function(r,i){var o=G({},this.settings);return this.settings[r]=i,jr(this.settings),this.handleSettingsUpdate(o),this.scheduleRefresh(),this}},{key:"updateSetting",value:function(r,i){return this.setSetting(r,i(this.settings[r])),this}},{key:"setSettings",value:function(r){var i=G({},this.settings);return this.settings=G(G({},this.settings),r),jr(this.settings),this.handleSettingsUpdate(i),this.scheduleRefresh(),this}},{key:"resize",value:function(r){var i=this.width,o=this.height;if(this.width=this.container.offsetWidth,this.height=this.container.offsetHeight,this.pixelRatio=Yo(),this.width===0)if(this.settings.allowInvalidContainer)this.width=1;else throw new Error("Sigma: Container has no width. You can set the allowInvalidContainer setting to true to stop seeing this error.");if(this.height===0)if(this.settings.allowInvalidContainer)this.height=1;else throw new Error("Sigma: Container has no height. You can set the allowInvalidContainer setting to true to stop seeing this error.");if(!r&&i===this.width&&o===this.height)return this;for(var a in this.elements){var s=this.elements[a];s.style.width=this.width+"px",s.style.height=this.height+"px"}for(var l in this.canvasContexts)this.elements[l].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[l].setAttribute("height",this.height*this.pixelRatio+"px"),this.pixelRatio!==1&&this.canvasContexts[l].scale(this.pixelRatio,this.pixelRatio);for(var u in this.webGLContexts){this.elements[u].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[u].setAttribute("height",this.height*this.pixelRatio+"px");var c=this.webGLContexts[u];if(c.viewport(0,0,this.width*this.pixelRatio,this.height*this.pixelRatio),this.pickingLayers.has(u)){var h=this.textures[u];h&&c.deleteTexture(h)}}return this.emit("resize"),this}},{key:"clear",value:function(){return this.emit("beforeClear"),this.webGLContexts.nodes.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER,null),this.webGLContexts.nodes.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.webGLContexts.edges.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER,null),this.webGLContexts.edges.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.webGLContexts.hoverNodes.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.canvasContexts.labels.clearRect(0,0,this.width,this.height),this.canvasContexts.hovers.clearRect(0,0,this.width,this.height),this.canvasContexts.edgeLabels.clearRect(0,0,this.width,this.height),this.emit("afterClear"),this}},{key:"refresh",value:function(r){var i=this,o=r?.skipIndexation!==void 0?r?.skipIndexation:!1,a=r?.schedule!==void 0?r.schedule:!1,s=!r||!r.partialGraph;if(s)this.clearEdgeIndices(),this.clearNodeIndices(),this.graph.forEachNode(function(k){return i.addNode(k)}),this.graph.forEachEdge(function(k){return i.addEdge(k)});else{for(var l,u,c=((l=r.partialGraph)===null||l===void 0?void 0:l.nodes)||[],h=0,d=c?.length||0;h<d;h++){var f=c[h];if(this.updateNode(f),o){var v=this.nodeProgramIndex[f];if(v===void 0)throw new Error('Sigma: node "'.concat(f,`" can't be repaint`));this.addNodeToProgram(f,this.nodeIndices[f],v)}}for(var m=(r==null||(u=r.partialGraph)===null||u===void 0?void 0:u.edges)||[],g=0,w=m.length;g<w;g++){var y=m[g];if(this.updateEdge(y),o){var _=this.edgeProgramIndex[y];if(_===void 0)throw new Error('Sigma: edge "'.concat(y,`" can't be repaint`));this.addEdgeToProgram(y,this.edgeIndices[y],_)}}}return(s||!o)&&(this.needToProcess=!0),a?this.scheduleRender():this.render(),this}},{key:"scheduleRender",value:function(){var r=this;return this.renderFrame||(this.renderFrame=requestAnimationFrame(function(){r.render()})),this}},{key:"scheduleRefresh",value:function(r){return this.refresh(G(G({},r),{},{schedule:!0}))}},{key:"getViewportZoomedState",value:function(r,i){var o=this.camera.getState(),a=o.ratio,s=o.angle,l=o.x,u=o.y,c=this.settings,h=c.minCameraRatio,d=c.maxCameraRatio;typeof d=="number"&&(i=Math.min(i,d)),typeof h=="number"&&(i=Math.max(i,h));var f=i/a,v={x:this.width/2,y:this.height/2},m=this.viewportToFramedGraph(r),g=this.viewportToFramedGraph(v);return{angle:s,x:(m.x-g.x)*(1-f)+l,y:(m.y-g.y)*(1-f)+u,ratio:i}}},{key:"viewRectangle",value:function(){var r=this.viewportToFramedGraph({x:0,y:0}),i=this.viewportToFramedGraph({x:this.width,y:0}),o=this.viewportToFramedGraph({x:0,y:this.height});return{x1:r.x,y1:r.y,x2:i.x,y2:i.y,height:i.y-o.y}}},{key:"framedGraphToViewport",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=!!i.cameraState||!!i.viewportDimensions||!!i.graphDimensions,a=i.matrix?i.matrix:o?Qt(i.cameraState||this.camera.getState(),i.viewportDimensions||this.getDimensions(),i.graphDimensions||this.getGraphDimensions(),i.padding||this.getStagePadding()):this.matrix,s=Br(a,r);return{x:(1+s.x)*this.width/2,y:(1-s.y)*this.height/2}}},{key:"viewportToFramedGraph",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=!!i.cameraState||!!i.viewportDimensions||!i.graphDimensions,a=i.matrix?i.matrix:o?Qt(i.cameraState||this.camera.getState(),i.viewportDimensions||this.getDimensions(),i.graphDimensions||this.getGraphDimensions(),i.padding||this.getStagePadding(),!0):this.invMatrix,s=Br(a,{x:r.x/this.width*2-1,y:1-r.y/this.height*2});return isNaN(s.x)&&(s.x=0),isNaN(s.y)&&(s.y=0),s}},{key:"viewportToGraph",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.normalizationFunction.inverse(this.viewportToFramedGraph(r,i))}},{key:"graphToViewport",value:function(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.framedGraphToViewport(this.normalizationFunction(r),i)}},{key:"getGraphToViewportRatio",value:function(){var r={x:0,y:0},i={x:1,y:1},o=Math.sqrt(Math.pow(r.x-i.x,2)+Math.pow(r.y-i.y,2)),a=this.graphToViewport(r),s=this.graphToViewport(i),l=Math.sqrt(Math.pow(a.x-s.x,2)+Math.pow(a.y-s.y,2));return l/o}},{key:"getBBox",value:function(){return this.nodeExtent}},{key:"getCustomBBox",value:function(){return this.customBBox}},{key:"setCustomBBox",value:function(r){return this.customBBox=r,this.scheduleRender(),this}},{key:"kill",value:function(){this.emit("kill"),this.removeAllListeners(),this.unbindCameraHandlers(),window.removeEventListener("resize",this.activeListeners.handleResize),this.mouseCaptor.kill(),this.touchCaptor.kill(),this.unbindGraphHandlers(),this.clearIndices(),this.clearState(),this.nodeDataCache={},this.edgeDataCache={},this.highlightedNodes.clear(),this.renderFrame&&(cancelAnimationFrame(this.renderFrame),this.renderFrame=null),this.renderHighlightedNodesFrame&&(cancelAnimationFrame(this.renderHighlightedNodesFrame),this.renderHighlightedNodesFrame=null);for(var r=this.container;r.firstChild;)r.removeChild(r.firstChild);for(var i in this.nodePrograms)this.nodePrograms[i].kill();for(var o in this.nodeHoverPrograms)this.nodeHoverPrograms[o].kill();for(var a in this.edgePrograms)this.edgePrograms[a].kill();this.nodePrograms={},this.nodeHoverPrograms={},this.edgePrograms={};for(var s in this.elements)this.killLayer(s);this.canvasContexts={},this.webGLContexts={},this.elements={}}},{key:"scaleSize",value:function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.camera.ratio;return r/this.settings.zoomToSizeRatioFunction(i)*(this.getSetting("itemSizesReference")==="positions"?i*this.graphToViewportRatio:1)}},{key:"getCanvases",value:function(){var r={};for(var i in this.elements)this.elements[i]instanceof HTMLCanvasElement&&(r[i]=this.elements[i]);return r}}])})(Ur),id=ny;var gt={dark:{accent:"#c6a0f6",success:"#a6da95",warning:"#eed49f",dim:"#a5adcb",text:"#cad3f5",muted:"#939ab7",line:"#494d64",ground:"#24273a"},light:{accent:"#7113ec",success:"#28641b",warning:"#7c4f10",dim:"#56586a",text:"#4c4f69",muted:"#606274",line:"#bcc0cc",ground:"#eff1f5"}},ry={vault:"accent",note:"text",repository:"accent",module:"dim",package:"dim",entryPoint:"dim",gitState:"dim",external:"dim",file:"dim"},iy={contains:"dim","anchored-at":"dim","links-to":"accent",mentions:"accent"};function oy(t,e){return gt[e][ry[t]]}function od(t,e){return gt[e][iy[t]]}function ay(t,e){return sy(t)?ta(od(t,e),e,ly):od(t,e)}function sy(t){return t==="contains"||t==="anchored-at"}var ea=.85,ly=.3;function Nn(t,e,n){let r=l=>/^#[0-9a-f]{6}$/.test(l)?[Number.parseInt(l.slice(1,3),16),Number.parseInt(l.slice(3,5),16),Number.parseInt(l.slice(5,7),16)]:null,i=r(t),o=r(e);if(i===null||o===null)return t;let a=Math.min(1,Math.max(0,Number.isFinite(n)?n:0)),s=(l,u)=>Math.round(l+(u-l)*a).toString(16).padStart(2,"0");return`#${s(i[0],o[0])}${s(i[1],o[1])}${s(i[2],o[2])}`}function ta(t,e,n=ea){return Nn(t,gt[e].ground,n)}var uy={contains:1,"anchored-at":1,"links-to":1.4,mentions:1},ad=1.6,ld=32,cy=ld/2;function dy(t,e=ld){if(e<=0)return t.length>0?"…":t;if(t.length<=e)return t;let n=e-1,i=t.slice(0,n).lastIndexOf(" "),o=i>=cy?i:n;return`${t.slice(0,o).trimEnd()}…`}function hy(t){let e=Ct(t.provenance),n=Re(t);return dy(e===""?n:`${e} ${n}`)}var fy=6,py=6;function gy(t){return(e,n,r)=>{if(n.label===null||n.label==="")return;let i=gt[t];e.save(),e.font=`${r.labelSize}px ${r.labelFont}`,e.textAlign="center",e.shadowColor=i.ground,e.shadowBlur=py,e.fillStyle=i.text,e.fillText(n.label,n.x,n.y+n.size+r.labelSize+fy),e.restore()}}function ud(t){let e=1/0,n=1/0,r=-1/0,i=-1/0,o=0;for(let a of t)!Number.isFinite(a.x)||!Number.isFinite(a.y)||(o++,a.x<e&&(e=a.x),a.x>r&&(r=a.x),a.y<n&&(n=a.y),a.y>i&&(i=a.y));return o===0?null:{x:[e,r],y:[n,i]}}var cd={nodes:[],edges:[]};function dd(t){return`${t.source}\0${t.target}\0${t.kind}`}function my(t,e){let n=new Map,r=new Set;for(let i of t){if(i.source===i.target||!e.has(i.source)||!e.has(i.target))continue;let o=dd(i);r.has(o)||(r.add(o),n.set(i.source,(n.get(i.source)??0)+1),n.set(i.target,(n.get(i.target)??0)+1))}return n}function hd(t,e,n,r,i){let o=new Map;for(let h of t){if(o.has(h.id))continue;let d=n.get(h.id);d===void 0||!Number.isFinite(d.x)||!Number.isFinite(d.y)||o.set(h.id,h)}let a=new Set(o.keys()),s=my(e,a),l=[];for(let[h,d]of o){let f=n.get(h),v=Xi(s.get(h)??0);l.push({id:h,x:f.x,y:f.y,size:v,label:hy(d),color:i?.get(h)??oy(d.kind,r),kind:d.kind,provenance:d.provenance,zIndex:Math.round(v),type:"circle"})}let u=[],c=new Set;for(let h of e){if(h.source===h.target||!a.has(h.source)||!a.has(h.target))continue;let d=dd(h);c.has(d)||(c.add(d),u.push({key:d,source:h.source,target:h.target,size:uy[h.kind],color:ay(h.kind,r),kind:h.kind,zIndex:0,type:"line"}))}return{nodes:l,edges:u}}function fd(t,e,n=1){return(r,i,o)=>t===null||n<=0?{}:r===e&&t.has(r)?{zIndex:i.zIndex+sd*2,size:i.size*Xr(by,n)}:t.has(r)?{zIndex:i.zIndex+sd,size:i.size*Xr(xy,n)}:{color:ta(i.color,o,ea*n),label:n>=wy?null:i.label,zIndex:0}}var vy=60,yy=.004;function pd(t,e,n){let r=Number.isFinite(n)&&n>0?n:0,i=e+(t-e)*Math.exp(-r/vy);return Math.abs(e-i)<yy?e:i}function Xr(t,e){return 1+(t-1)*e}var wy=.5,by=1.45,xy=1.15,sd=gr+1;function gd(t,e,n=1){return(r,i,o)=>t===null||n<=0?{}:!t.has(i.source)||!t.has(i.target)?{color:ta(i.color,o,ea*n)}:e!=null&&(i.source===e||i.target===e)?{zIndex:2,size:i.size*Xr(ad*1.35,n),color:Nn(i.color,gt[o].accent,n)}:{zIndex:1,size:i.size*Xr(ad,n)}}var _y=(pr+gr)/2,ky=mr*4,Ey=1;function md(t){let e=gt[t];return{hideEdgesOnMove:!0,enableCameraPanning:!0,renderEdgeLabels:!1,labelDensity:Ey,labelGridCellSize:ky,labelRenderedSizeThreshold:_y,labelFont:"inherit",labelSize:11,labelColor:{color:e.text},defaultNodeColor:e.dim,defaultEdgeColor:e.line,defaultNodeType:"circle",defaultEdgeType:"line",minEdgeThickness:.6,zIndex:!0,itemSizesReference:"positions",zoomToSizeRatioFunction:n=>n,stagePadding:mr,defaultDrawNodeHover:gy(t),allowInvalidContainer:!0}}var bd=dn($r(),1);function Sy(){let t=arguments[0];for(let e=1,n=arguments.length;e<n;e++)if(arguments[e])for(let r in arguments[e])t[r]=arguments[e][r];return t}var ce=Sy;typeof Object.assign=="function"&&(ce=Object.assign);function Ge(t,e,n,r){let i=t._nodes.get(e),o=null;return i&&(r==="mixed"?o=i.out&&i.out[n]||i.undirected&&i.undirected[n]:r==="directed"?o=i.out&&i.out[n]:o=i.undirected&&i.undirected[n]),o}function me(t){return typeof t=="object"&&t!==null}function xd(t){let e;for(e in t)return!1;return!0}function Me(t,e,n){Object.defineProperty(t,e,{enumerable:!1,configurable:!1,writable:!0,value:n})}function We(t,e,n){let r={enumerable:!0,configurable:!0};typeof n=="function"?r.get=n:(r.value=n,r.writable=!1),Object.defineProperty(t,e,r)}function vd(t){return!(!me(t)||t.attributes&&!Array.isArray(t.attributes))}function Ty(){let t=Math.floor(Math.random()*256)&255;return()=>t++}function at(){let t=arguments,e=null,n=-1;return{[Symbol.iterator](){return this},next(){let r=null;do{if(e===null){if(n++,n>=t.length)return{done:!0};e=t[n][Symbol.iterator]()}if(r=e.next(),r.done){e=null;continue}break}while(!0);return r}}}function en(){return{[Symbol.iterator](){return this},next(){return{done:!0}}}}var In=class extends Error{constructor(e){super(),this.name="GraphError",this.message=e}},I=class t extends In{constructor(e){super(e),this.name="InvalidArgumentsGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,t.prototype.constructor)}},N=class t extends In{constructor(e){super(e),this.name="NotFoundGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,t.prototype.constructor)}},O=class t extends In{constructor(e){super(e),this.name="UsageGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,t.prototype.constructor)}};function _d(t,e){this.key=t,this.attributes=e,this.clear()}_d.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}};function kd(t,e){this.key=t,this.attributes=e,this.clear()}kd.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={}};function Ed(t,e){this.key=t,this.attributes=e,this.clear()}Ed.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={}};function tn(t,e,n,r,i){this.key=e,this.attributes=i,this.undirected=t,this.source=n,this.target=r}tn.prototype.attach=function(){let t="out",e="in";this.undirected&&(t=e="undirected");let n=this.source.key,r=this.target.key;this.source[t][r]=this,!(this.undirected&&n===r)&&(this.target[e][n]=this)};tn.prototype.attachMulti=function(){let t="out",e="in",n=this.source.key,r=this.target.key;this.undirected&&(t=e="undirected");let i=this.source[t],o=i[r];if(typeof o>"u"){i[r]=this,this.undirected&&n===r||(this.target[e][n]=this);return}o.previous=this,this.next=o,i[r]=this,this.target[e][n]=this};tn.prototype.detach=function(){let t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),delete this.source[n][e],delete this.target[r][t]};tn.prototype.detachMulti=function(){let t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),this.previous===void 0?this.next===void 0?(delete this.source[n][e],delete this.target[r][t]):(this.next.previous=void 0,this.source[n][e]=this.next,this.target[r][t]=this.next):(this.previous.next=this.next,this.next!==void 0&&(this.next.previous=this.previous))};var Sd=0,Td=1,Ay=2,Ad=3;function st(t,e,n,r,i,o,a){let s,l,u,c;if(r=""+r,n===Sd){if(s=t._nodes.get(r),!s)throw new N(`Graph.${e}: could not find the "${r}" node in the graph.`);u=i,c=o}else if(n===Ad){if(i=""+i,l=t._edges.get(i),!l)throw new N(`Graph.${e}: could not find the "${i}" edge in the graph.`);let h=l.source.key,d=l.target.key;if(r===h)s=l.target;else if(r===d)s=l.source;else throw new N(`Graph.${e}: the "${r}" node is not attached to the "${i}" edge (${h}, ${d}).`);u=o,c=a}else{if(l=t._edges.get(r),!l)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`);n===Td?s=l.source:s=l.target,u=i,c=o}return[s,u,c]}function Ry(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);return a.attributes[s]}}function Cy(t,e,n){t.prototype[e]=function(r,i){let[o]=st(this,e,n,r,i);return o.attributes}}function Ly(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);return a.attributes.hasOwnProperty(s)}}function Ny(t,e,n){t.prototype[e]=function(r,i,o,a){let[s,l,u]=st(this,e,n,r,i,o,a);return s.attributes[l]=u,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:l}),this}}function Dy(t,e,n){t.prototype[e]=function(r,i,o,a){let[s,l,u]=st(this,e,n,r,i,o,a);if(typeof u!="function")throw new I(`Graph.${e}: updater should be a function.`);let c=s.attributes,h=u(c[l]);return c[l]=h,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:l}),this}}function Py(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);return delete a.attributes[s],this.emit("nodeAttributesUpdated",{key:a.key,type:"remove",attributes:a.attributes,name:s}),this}}function Iy(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);if(!me(s))throw new I(`Graph.${e}: provided attributes are not a plain object.`);return a.attributes=s,this.emit("nodeAttributesUpdated",{key:a.key,type:"replace",attributes:a.attributes}),this}}function My(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);if(!me(s))throw new I(`Graph.${e}: provided attributes are not a plain object.`);return ce(a.attributes,s),this.emit("nodeAttributesUpdated",{key:a.key,type:"merge",attributes:a.attributes,data:s}),this}}function Gy(t,e,n){t.prototype[e]=function(r,i,o){let[a,s]=st(this,e,n,r,i,o);if(typeof s!="function")throw new I(`Graph.${e}: provided updater is not a function.`);return a.attributes=s(a.attributes),this.emit("nodeAttributesUpdated",{key:a.key,type:"update",attributes:a.attributes}),this}}var Fy=[{name:t=>`get${t}Attribute`,attacher:Ry},{name:t=>`get${t}Attributes`,attacher:Cy},{name:t=>`has${t}Attribute`,attacher:Ly},{name:t=>`set${t}Attribute`,attacher:Ny},{name:t=>`update${t}Attribute`,attacher:Dy},{name:t=>`remove${t}Attribute`,attacher:Py},{name:t=>`replace${t}Attributes`,attacher:Iy},{name:t=>`merge${t}Attributes`,attacher:My},{name:t=>`update${t}Attributes`,attacher:Gy}];function Oy(t){Fy.forEach(function({name:e,attacher:n}){n(t,e("Node"),Sd),n(t,e("Source"),Td),n(t,e("Target"),Ay),n(t,e("Opposite"),Ad)})}function zy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return o.attributes[i]}}function $y(t,e,n){t.prototype[e]=function(r){let i;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>1){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+r,a=""+arguments[1];if(i=Ge(this,o,a,n),!i)throw new N(`Graph.${e}: could not find an edge for the given path ("${o}" - "${a}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,i=this._edges.get(r),!i)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return i.attributes}}function Uy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return o.attributes.hasOwnProperty(i)}}function Hy(t,e,n){t.prototype[e]=function(r,i,o){let a;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let s=""+r,l=""+i;if(i=arguments[2],o=arguments[3],a=Ge(this,s,l,n),!a)throw new N(`Graph.${e}: could not find an edge for the given path ("${s}" - "${l}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,a=this._edges.get(r),!a)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return a.attributes[i]=o,this.emit("edgeAttributesUpdated",{key:a.key,type:"set",attributes:a.attributes,name:i}),this}}function By(t,e,n){t.prototype[e]=function(r,i,o){let a;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let s=""+r,l=""+i;if(i=arguments[2],o=arguments[3],a=Ge(this,s,l,n),!a)throw new N(`Graph.${e}: could not find an edge for the given path ("${s}" - "${l}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,a=this._edges.get(r),!a)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}if(typeof o!="function")throw new I(`Graph.${e}: updater should be a function.`);return a.attributes[i]=o(a.attributes[i]),this.emit("edgeAttributesUpdated",{key:a.key,type:"set",attributes:a.attributes,name:i}),this}}function Wy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}return delete o.attributes[i],this.emit("edgeAttributesUpdated",{key:o.key,type:"remove",attributes:o.attributes,name:i}),this}}function Ky(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}if(!me(i))throw new I(`Graph.${e}: provided attributes are not a plain object.`);return o.attributes=i,this.emit("edgeAttributesUpdated",{key:o.key,type:"replace",attributes:o.attributes}),this}}function Vy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}if(!me(i))throw new I(`Graph.${e}: provided attributes are not a plain object.`);return ce(o.attributes,i),this.emit("edgeAttributesUpdated",{key:o.key,type:"merge",attributes:o.attributes,data:i}),this}}function jy(t,e,n){t.prototype[e]=function(r,i){let o;if(this.type!=="mixed"&&n!=="mixed"&&n!==this.type)throw new O(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new O(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+r,s=""+i;if(i=arguments[2],o=Ge(this,a,s,n),!o)throw new N(`Graph.${e}: could not find an edge for the given path ("${a}" - "${s}").`)}else{if(n!=="mixed")throw new O(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(r=""+r,o=this._edges.get(r),!o)throw new N(`Graph.${e}: could not find the "${r}" edge in the graph.`)}if(typeof i!="function")throw new I(`Graph.${e}: provided updater is not a function.`);return o.attributes=i(o.attributes),this.emit("edgeAttributesUpdated",{key:o.key,type:"update",attributes:o.attributes}),this}}var qy=[{name:t=>`get${t}Attribute`,attacher:zy},{name:t=>`get${t}Attributes`,attacher:$y},{name:t=>`has${t}Attribute`,attacher:Uy},{name:t=>`set${t}Attribute`,attacher:Hy},{name:t=>`update${t}Attribute`,attacher:By},{name:t=>`remove${t}Attribute`,attacher:Wy},{name:t=>`replace${t}Attributes`,attacher:Ky},{name:t=>`merge${t}Attributes`,attacher:Vy},{name:t=>`update${t}Attributes`,attacher:jy}];function Yy(t){qy.forEach(function({name:e,attacher:n}){n(t,e("Edge"),"mixed"),n(t,e("DirectedEdge"),"directed"),n(t,e("UndirectedEdge"),"undirected")})}var Xy=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"inboundEdges",type:"mixed",direction:"in"},{name:"outboundEdges",type:"mixed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}];function Zy(t,e,n,r){let i=!1;for(let o in e){if(o===r)continue;let a=e[o];if(i=n(a.key,a.attributes,a.source.key,a.target.key,a.source.attributes,a.target.attributes,a.undirected),t&&i)return a.key}}function Qy(t,e,n,r){let i,o,a,s=!1;for(let l in e)if(l!==r){i=e[l];do{if(o=i.source,a=i.target,s=n(i.key,i.attributes,o.key,a.key,o.attributes,a.attributes,i.undirected),t&&s)return i.key;i=i.next}while(i!==void 0)}}function na(t,e){let n=Object.keys(t),r=n.length,i,o=0;return{[Symbol.iterator](){return this},next(){do if(i)i=i.next;else{if(o>=r)return{done:!0};let a=n[o++];if(a===e){i=void 0;continue}i=t[a]}while(!i);return{done:!1,value:{edge:i.key,attributes:i.attributes,source:i.source.key,target:i.target.key,sourceAttributes:i.source.attributes,targetAttributes:i.target.attributes,undirected:i.undirected}}}}}function Jy(t,e,n,r){let i=e[n];if(!i)return;let o=i.source,a=i.target;if(r(i.key,i.attributes,o.key,a.key,o.attributes,a.attributes,i.undirected)&&t)return i.key}function ew(t,e,n,r){let i=e[n];if(!i)return;let o=!1;do{if(o=r(i.key,i.attributes,i.source.key,i.target.key,i.source.attributes,i.target.attributes,i.undirected),t&&o)return i.key;i=i.next}while(i!==void 0)}function ra(t,e){let n=t[e];if(n.next!==void 0)return{[Symbol.iterator](){return this},next(){if(!n)return{done:!0};let i={edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected};return n=n.next,{done:!1,value:i}}};let r=!1;return{[Symbol.iterator](){return this},next(){return r===!0?{done:!0}:(r=!0,{done:!1,value:{edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected}})}}}function tw(t,e){if(t.size===0)return[];if(e==="mixed"||e===t.type)return Array.from(t._edges.keys());let n=e==="undirected"?t.undirectedSize:t.directedSize,r=new Array(n),i=e==="undirected",o=t._edges.values(),a=0,s,l;for(;s=o.next(),s.done!==!0;)l=s.value,l.undirected===i&&(r[a++]=l.key);return r}function Rd(t,e,n,r){if(e.size===0)return;let i=n!=="mixed"&&n!==e.type,o=n==="undirected",a,s,l=!1,u=e._edges.values();for(;a=u.next(),a.done!==!0;){if(s=a.value,i&&s.undirected!==o)continue;let{key:c,attributes:h,source:d,target:f}=s;if(l=r(c,h,d.key,f.key,d.attributes,f.attributes,s.undirected),t&&l)return c}}function nw(t,e){if(t.size===0)return en();let n=e!=="mixed"&&e!==t.type,r=e==="undirected",i=t._edges.values();return{[Symbol.iterator](){return this},next(){let o,a;for(;;){if(o=i.next(),o.done)return o;if(a=o.value,!(n&&a.undirected!==r))break}return{value:{edge:a.key,attributes:a.attributes,source:a.source.key,target:a.target.key,sourceAttributes:a.source.attributes,targetAttributes:a.target.attributes,undirected:a.undirected},done:!1}}}}function ia(t,e,n,r,i,o){let a=e?Qy:Zy,s;if(n!=="undirected"&&(r!=="out"&&(s=a(t,i.in,o),t&&s)||r!=="in"&&(s=a(t,i.out,o,r?void 0:i.key),t&&s))||n!=="directed"&&(s=a(t,i.undirected,o),t&&s))return s}function rw(t,e,n,r){let i=[];return ia(!1,t,e,n,r,function(o){i.push(o)}),i}function iw(t,e,n){let r=en();return t!=="undirected"&&(e!=="out"&&typeof n.in<"u"&&(r=at(r,na(n.in))),e!=="in"&&typeof n.out<"u"&&(r=at(r,na(n.out,e?void 0:n.key)))),t!=="directed"&&typeof n.undirected<"u"&&(r=at(r,na(n.undirected))),r}function oa(t,e,n,r,i,o,a){let s=n?ew:Jy,l;if(e!=="undirected"&&(typeof i.in<"u"&&r!=="out"&&(l=s(t,i.in,o,a),t&&l)||typeof i.out<"u"&&r!=="in"&&(r||i.key!==o)&&(l=s(t,i.out,o,a),t&&l))||e!=="directed"&&typeof i.undirected<"u"&&(l=s(t,i.undirected,o,a),t&&l))return l}function ow(t,e,n,r,i){let o=[];return oa(!1,t,e,n,r,i,function(a){o.push(a)}),o}function aw(t,e,n,r){let i=en();return t!=="undirected"&&(typeof n.in<"u"&&e!=="out"&&r in n.in&&(i=at(i,ra(n.in,r))),typeof n.out<"u"&&e!=="in"&&r in n.out&&(e||n.key!==r)&&(i=at(i,ra(n.out,r)))),t!=="directed"&&typeof n.undirected<"u"&&r in n.undirected&&(i=at(i,ra(n.undirected,r))),i}function sw(t,e){let{name:n,type:r,direction:i}=e;t.prototype[n]=function(o,a){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return[];if(!arguments.length)return tw(this,r);if(arguments.length===1){o=""+o;let s=this._nodes.get(o);if(typeof s>"u")throw new N(`Graph.${n}: could not find the "${o}" node in the graph.`);return rw(this.multi,r==="mixed"?this.type:r,i,s)}if(arguments.length===2){o=""+o,a=""+a;let s=this._nodes.get(o);if(!s)throw new N(`Graph.${n}: could not find the "${o}" source node in the graph.`);if(!this._nodes.has(a))throw new N(`Graph.${n}: could not find the "${a}" target node in the graph.`);return ow(r,this.multi,i,s,a)}throw new I(`Graph.${n}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function lw(t,e){let{name:n,type:r,direction:i}=e,o="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(u,c,h){if(!(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)){if(arguments.length===1)return h=u,Rd(!1,this,r,h);if(arguments.length===2){u=""+u,h=c;let d=this._nodes.get(u);if(typeof d>"u")throw new N(`Graph.${o}: could not find the "${u}" node in the graph.`);return ia(!1,this.multi,r==="mixed"?this.type:r,i,d,h)}if(arguments.length===3){u=""+u,c=""+c;let d=this._nodes.get(u);if(!d)throw new N(`Graph.${o}: could not find the "${u}" source node in the graph.`);if(!this._nodes.has(c))throw new N(`Graph.${o}: could not find the "${c}" target node in the graph.`);return oa(!1,r,this.multi,i,d,c,h)}throw new I(`Graph.${o}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)}};let a="map"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(){let u=Array.prototype.slice.call(arguments),c=u.pop(),h;if(u.length===0){let d=0;r!=="directed"&&(d+=this.undirectedSize),r!=="undirected"&&(d+=this.directedSize),h=new Array(d);let f=0;u.push((v,m,g,w,y,_,k)=>{h[f++]=c(v,m,g,w,y,_,k)})}else h=[],u.push((d,f,v,m,g,w,y)=>{h.push(c(d,f,v,m,g,w,y))});return this[o].apply(this,u),h};let s="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(){let u=Array.prototype.slice.call(arguments),c=u.pop(),h=[];return u.push((d,f,v,m,g,w,y)=>{c(d,f,v,m,g,w,y)&&h.push(d)}),this[o].apply(this,u),h};let l="reduce"+n[0].toUpperCase()+n.slice(1);t.prototype[l]=function(){let u=Array.prototype.slice.call(arguments);if(u.length<2||u.length>4)throw new I(`Graph.${l}: invalid number of arguments (expecting 2, 3 or 4 and got ${u.length}).`);if(typeof u[u.length-1]=="function"&&typeof u[u.length-2]!="function")throw new I(`Graph.${l}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let c,h;u.length===2?(c=u[0],h=u[1],u=[]):u.length===3?(c=u[1],h=u[2],u=[u[0]]):u.length===4&&(c=u[2],h=u[3],u=[u[0],u[1]]);let d=h;return u.push((f,v,m,g,w,y,_)=>{d=c(d,f,v,m,g,w,y,_)}),this[o].apply(this,u),d}}function uw(t,e){let{name:n,type:r,direction:i}=e,o="find"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(l,u,c){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return!1;if(arguments.length===1)return c=l,Rd(!0,this,r,c);if(arguments.length===2){l=""+l,c=u;let h=this._nodes.get(l);if(typeof h>"u")throw new N(`Graph.${o}: could not find the "${l}" node in the graph.`);return ia(!0,this.multi,r==="mixed"?this.type:r,i,h,c)}if(arguments.length===3){l=""+l,u=""+u;let h=this._nodes.get(l);if(!h)throw new N(`Graph.${o}: could not find the "${l}" source node in the graph.`);if(!this._nodes.has(u))throw new N(`Graph.${o}: could not find the "${u}" target node in the graph.`);return oa(!0,r,this.multi,i,h,u,c)}throw new I(`Graph.${o}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)};let a="some"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[a]=function(){let l=Array.prototype.slice.call(arguments),u=l.pop();return l.push((h,d,f,v,m,g,w)=>u(h,d,f,v,m,g,w)),!!this[o].apply(this,l)};let s="every"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[s]=function(){let l=Array.prototype.slice.call(arguments),u=l.pop();return l.push((h,d,f,v,m,g,w)=>!u(h,d,f,v,m,g,w)),!this[o].apply(this,l)}}function cw(t,e){let{name:n,type:r,direction:i}=e,o=n.slice(0,-1)+"Entries";t.prototype[o]=function(a,s){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return en();if(!arguments.length)return nw(this,r);if(arguments.length===1){a=""+a;let l=this._nodes.get(a);if(!l)throw new N(`Graph.${o}: could not find the "${a}" node in the graph.`);return iw(r,i,l)}if(arguments.length===2){a=""+a,s=""+s;let l=this._nodes.get(a);if(!l)throw new N(`Graph.${o}: could not find the "${a}" source node in the graph.`);if(!this._nodes.has(s))throw new N(`Graph.${o}: could not find the "${s}" target node in the graph.`);return aw(r,i,l,s)}throw new I(`Graph.${o}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function dw(t){Xy.forEach(e=>{sw(t,e),lw(t,e),uw(t,e),cw(t,e)})}var hw=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"inboundNeighbors",type:"mixed",direction:"in"},{name:"outboundNeighbors",type:"mixed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}];function ri(){this.A=null,this.B=null}ri.prototype.wrap=function(t){this.A===null?this.A=t:this.B===null&&(this.B=t)};ri.prototype.has=function(t){return this.A!==null&&t in this.A||this.B!==null&&t in this.B};function Dn(t,e,n,r,i){for(let o in r){let a=r[o],s=a.source,l=a.target,u=s===n?l:s;if(e&&e.has(u.key))continue;let c=i(u.key,u.attributes);if(t&&c)return u.key}}function aa(t,e,n,r,i){if(e!=="mixed"){if(e==="undirected")return Dn(t,null,r,r.undirected,i);if(typeof n=="string")return Dn(t,null,r,r[n],i)}let o=new ri,a;if(e!=="undirected"){if(n!=="out"){if(a=Dn(t,null,r,r.in,i),t&&a)return a;o.wrap(r.in)}if(n!=="in"){if(a=Dn(t,o,r,r.out,i),t&&a)return a;o.wrap(r.out)}}if(e!=="directed"&&(a=Dn(t,o,r,r.undirected,i),t&&a))return a}function fw(t,e,n){if(t!=="mixed"){if(t==="undirected")return Object.keys(n.undirected);if(typeof e=="string")return Object.keys(n[e])}let r=[];return aa(!1,t,e,n,function(i){r.push(i)}),r}function Pn(t,e,n){let r=Object.keys(n),i=r.length,o=0;return{[Symbol.iterator](){return this},next(){let a=null;do{if(o>=i)return t&&t.wrap(n),{done:!0};let s=n[r[o++]],l=s.source,u=s.target;if(a=l===e?u:l,t&&t.has(a.key)){a=null;continue}}while(a===null);return{done:!1,value:{neighbor:a.key,attributes:a.attributes}}}}}function pw(t,e,n){if(t!=="mixed"){if(t==="undirected")return Pn(null,n,n.undirected);if(typeof e=="string")return Pn(null,n,n[e])}let r=en(),i=new ri;return t!=="undirected"&&(e!=="out"&&(r=at(r,Pn(i,n,n.in))),e!=="in"&&(r=at(r,Pn(i,n,n.out)))),t!=="directed"&&(r=at(r,Pn(i,n,n.undirected))),r}function gw(t,e){let{name:n,type:r,direction:i}=e;t.prototype[n]=function(o){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return[];o=""+o;let a=this._nodes.get(o);if(typeof a>"u")throw new N(`Graph.${n}: could not find the "${o}" node in the graph.`);return fw(r==="mixed"?this.type:r,i,a)}}function mw(t,e){let{name:n,type:r,direction:i}=e,o="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(u,c){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return;u=""+u;let h=this._nodes.get(u);if(typeof h>"u")throw new N(`Graph.${o}: could not find the "${u}" node in the graph.`);aa(!1,r==="mixed"?this.type:r,i,h,c)};let a="map"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(u,c){let h=[];return this[o](u,(d,f)=>{h.push(c(d,f))}),h};let s="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(u,c){let h=[];return this[o](u,(d,f)=>{c(d,f)&&h.push(d)}),h};let l="reduce"+n[0].toUpperCase()+n.slice(1);t.prototype[l]=function(u,c,h){if(arguments.length<3)throw new I(`Graph.${l}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let d=h;return this[o](u,(f,v)=>{d=c(d,f,v)}),d}}function vw(t,e){let{name:n,type:r,direction:i}=e,o=n[0].toUpperCase()+n.slice(1,-1),a="find"+o;t.prototype[a]=function(u,c){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return;u=""+u;let h=this._nodes.get(u);if(typeof h>"u")throw new N(`Graph.${a}: could not find the "${u}" node in the graph.`);return aa(!0,r==="mixed"?this.type:r,i,h,c)};let s="some"+o;t.prototype[s]=function(u,c){return!!this[a](u,c)};let l="every"+o;t.prototype[l]=function(u,c){return!this[a](u,(d,f)=>!c(d,f))}}function yw(t,e){let{name:n,type:r,direction:i}=e,o=n.slice(0,-1)+"Entries";t.prototype[o]=function(a){if(r!=="mixed"&&this.type!=="mixed"&&r!==this.type)return en();a=""+a;let s=this._nodes.get(a);if(typeof s>"u")throw new N(`Graph.${o}: could not find the "${a}" node in the graph.`);return pw(r==="mixed"?this.type:r,i,s)}}function ww(t){hw.forEach(e=>{gw(t,e),mw(t,e),vw(t,e),yw(t,e)})}function Zr(t,e,n,r,i){let o=r._nodes.values(),a=r.type,s,l,u,c,h,d,f;for(;s=o.next(),s.done!==!0;){let v=!1;if(l=s.value,a!=="undirected"){c=l.out;for(u in c){h=c[u];do{if(d=h.target,v=!0,f=i(l.key,d.key,l.attributes,d.attributes,h.key,h.attributes,h.undirected),t&&f)return h;h=h.next}while(h)}}if(a!=="directed"){c=l.undirected;for(u in c)if(!(e&&l.key>u)){h=c[u];do{if(d=h.target,d.key!==u&&(d=h.source),v=!0,f=i(l.key,d.key,l.attributes,d.attributes,h.key,h.attributes,h.undirected),t&&f)return h;h=h.next}while(h)}}if(n&&!v&&(f=i(l.key,null,l.attributes,null,null,null,null),t&&f))return null}}function bw(t,e){let n={key:t};return xd(e.attributes)||(n.attributes=ce({},e.attributes)),n}function xw(t,e,n){let r={key:e,source:n.source.key,target:n.target.key};return xd(n.attributes)||(r.attributes=ce({},n.attributes)),t==="mixed"&&n.undirected&&(r.undirected=!0),r}function _w(t){if(!me(t))throw new I('Graph.import: invalid serialized node. A serialized node should be a plain object with at least a "key" property.');if(!("key"in t))throw new I("Graph.import: serialized node is missing its key.");if("attributes"in t&&(!me(t.attributes)||t.attributes===null))throw new I("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.")}function kw(t){if(!me(t))throw new I('Graph.import: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.');if(!("source"in t))throw new I("Graph.import: serialized edge is missing its source.");if(!("target"in t))throw new I("Graph.import: serialized edge is missing its target.");if("attributes"in t&&(!me(t.attributes)||t.attributes===null))throw new I("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.");if("undirected"in t&&typeof t.undirected!="boolean")throw new I("Graph.import: invalid undirectedness information. Undirected should be boolean or omitted.")}var Ew=Ty(),Sw=new Set(["directed","undirected","mixed"]),yd=new Set(["domain","_events","_eventsCount","_maxListeners"]),Tw=[{name:t=>`${t}Edge`,generateKey:!0},{name:t=>`${t}DirectedEdge`,generateKey:!0,type:"directed"},{name:t=>`${t}UndirectedEdge`,generateKey:!0,type:"undirected"},{name:t=>`${t}EdgeWithKey`},{name:t=>`${t}DirectedEdgeWithKey`,type:"directed"},{name:t=>`${t}UndirectedEdgeWithKey`,type:"undirected"}],Aw={allowSelfLoops:!0,multi:!1,type:"mixed"};function Rw(t,e,n){if(n&&!me(n))throw new I(`Graph.addNode: invalid attributes. Expecting an object but got "${n}"`);if(e=""+e,n=n||{},t._nodes.has(e))throw new O(`Graph.addNode: the "${e}" node already exist in the graph.`);let r=new t.NodeDataClass(e,n);return t._nodes.set(e,r),t.emit("nodeAdded",{key:e,attributes:n}),r}function wd(t,e,n){let r=new t.NodeDataClass(e,n);return t._nodes.set(e,r),t.emit("nodeAdded",{key:e,attributes:n}),r}function Cd(t,e,n,r,i,o,a,s){if(!r&&t.type==="undirected")throw new O(`Graph.${e}: you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.`);if(r&&t.type==="directed")throw new O(`Graph.${e}: you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.`);if(s&&!me(s))throw new I(`Graph.${e}: invalid attributes. Expecting an object but got "${s}"`);if(o=""+o,a=""+a,s=s||{},!t.allowSelfLoops&&o===a)throw new O(`Graph.${e}: source & target are the same ("${o}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let l=t._nodes.get(o),u=t._nodes.get(a);if(!l)throw new N(`Graph.${e}: source node "${o}" not found.`);if(!u)throw new N(`Graph.${e}: target node "${a}" not found.`);let c={key:null,undirected:r,source:o,target:a,attributes:s};if(n)i=t._edgeKeyGenerator();else if(i=""+i,t._edges.has(i))throw new O(`Graph.${e}: the "${i}" edge already exists in the graph.`);if(!t.multi&&(r?typeof l.undirected[a]<"u":typeof l.out[a]<"u"))throw new O(`Graph.${e}: an edge linking "${o}" to "${a}" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option.`);let h=new tn(r,i,l,u,s);t._edges.set(i,h);let d=o===a;return r?(l.undirectedDegree++,u.undirectedDegree++,d&&(l.undirectedLoops++,t._undirectedSelfLoopCount++)):(l.outDegree++,u.inDegree++,d&&(l.directedLoops++,t._directedSelfLoopCount++)),t.multi?h.attachMulti():h.attach(),r?t._undirectedSize++:t._directedSize++,c.key=i,t.emit("edgeAdded",c),i}function Cw(t,e,n,r,i,o,a,s,l){if(!r&&t.type==="undirected")throw new O(`Graph.${e}: you cannot merge/update a directed edge to an undirected graph. Use the #.mergeEdge/#.updateEdge or #.addUndirectedEdge instead.`);if(r&&t.type==="directed")throw new O(`Graph.${e}: you cannot merge/update an undirected edge to a directed graph. Use the #.mergeEdge/#.updateEdge or #.addDirectedEdge instead.`);if(s){if(l){if(typeof s!="function")throw new I(`Graph.${e}: invalid updater function. Expecting a function but got "${s}"`)}else if(!me(s))throw new I(`Graph.${e}: invalid attributes. Expecting an object but got "${s}"`)}o=""+o,a=""+a;let u;if(l&&(u=s,s=void 0),!t.allowSelfLoops&&o===a)throw new O(`Graph.${e}: source & target are the same ("${o}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let c=t._nodes.get(o),h=t._nodes.get(a),d,f;if(!n&&(d=t._edges.get(i),d)){if((d.source.key!==o||d.target.key!==a)&&(!r||d.source.key!==a||d.target.key!==o))throw new O(`Graph.${e}: inconsistency detected when attempting to merge the "${i}" edge with "${o}" source & "${a}" target vs. ("${d.source.key}", "${d.target.key}").`);f=d}if(!f&&!t.multi&&c&&(f=r?c.undirected[a]:c.out[a]),f){let y=[f.key,!1,!1,!1];if(l?!u:!s)return y;if(l){let _=f.attributes;f.attributes=u(_),t.emit("edgeAttributesUpdated",{type:"replace",key:f.key,attributes:f.attributes})}else ce(f.attributes,s),t.emit("edgeAttributesUpdated",{type:"merge",key:f.key,attributes:f.attributes,data:s});return y}s=s||{},l&&u&&(s=u(s));let v={key:null,undirected:r,source:o,target:a,attributes:s};if(n)i=t._edgeKeyGenerator();else if(i=""+i,t._edges.has(i))throw new O(`Graph.${e}: the "${i}" edge already exists in the graph.`);let m=!1,g=!1;c||(c=wd(t,o,{}),m=!0,o===a&&(h=c,g=!0)),h||(h=wd(t,a,{}),g=!0),d=new tn(r,i,c,h,s),t._edges.set(i,d);let w=o===a;return r?(c.undirectedDegree++,h.undirectedDegree++,w&&(c.undirectedLoops++,t._undirectedSelfLoopCount++)):(c.outDegree++,h.inDegree++,w&&(c.directedLoops++,t._directedSelfLoopCount++)),t.multi?d.attachMulti():d.attach(),r?t._undirectedSize++:t._directedSize++,v.key=i,t.emit("edgeAdded",v),[i,!0,m,g]}function Jt(t,e){t._edges.delete(e.key);let{source:n,target:r,attributes:i}=e,o=e.undirected,a=n===r;o?(n.undirectedDegree--,r.undirectedDegree--,a&&(n.undirectedLoops--,t._undirectedSelfLoopCount--)):(n.outDegree--,r.inDegree--,a&&(n.directedLoops--,t._directedSelfLoopCount--)),t.multi?e.detachMulti():e.detach(),o?t._undirectedSize--:t._directedSize--,t.emit("edgeDropped",{key:e.key,attributes:i,source:n.key,target:r.key,undirected:o})}var q=class t extends bd.EventEmitter{constructor(e){if(super(),e=ce({},Aw,e),typeof e.multi!="boolean")throw new I(`Graph.constructor: invalid 'multi' option. Expecting a boolean but got "${e.multi}".`);if(!Sw.has(e.type))throw new I(`Graph.constructor: invalid 'type' option. Should be one of "mixed", "directed" or "undirected" but got "${e.type}".`);if(typeof e.allowSelfLoops!="boolean")throw new I(`Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got "${e.allowSelfLoops}".`);let n=e.type==="mixed"?_d:e.type==="directed"?kd:Ed;Me(this,"NodeDataClass",n);let r="geid_"+Ew()+"_",i=0,o=()=>{let a;do a=r+i++;while(this._edges.has(a));return a};Me(this,"_attributes",{}),Me(this,"_nodes",new Map),Me(this,"_edges",new Map),Me(this,"_directedSize",0),Me(this,"_undirectedSize",0),Me(this,"_directedSelfLoopCount",0),Me(this,"_undirectedSelfLoopCount",0),Me(this,"_edgeKeyGenerator",o),Me(this,"_options",e),yd.forEach(a=>Me(this,a,this[a])),We(this,"order",()=>this._nodes.size),We(this,"size",()=>this._edges.size),We(this,"directedSize",()=>this._directedSize),We(this,"undirectedSize",()=>this._undirectedSize),We(this,"selfLoopCount",()=>this._directedSelfLoopCount+this._undirectedSelfLoopCount),We(this,"directedSelfLoopCount",()=>this._directedSelfLoopCount),We(this,"undirectedSelfLoopCount",()=>this._undirectedSelfLoopCount),We(this,"multi",this._options.multi),We(this,"type",this._options.type),We(this,"allowSelfLoops",this._options.allowSelfLoops),We(this,"implementation",()=>"graphology")}_resetInstanceCounters(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0}hasNode(e){return this._nodes.has(""+e)}hasDirectedEdge(e,n){if(this.type==="undirected")return!1;if(arguments.length===1){let r=""+e,i=this._edges.get(r);return!!i&&!i.undirected}else if(arguments.length===2){e=""+e,n=""+n;let r=this._nodes.get(e);return r?r.out.hasOwnProperty(n):!1}throw new I(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasUndirectedEdge(e,n){if(this.type==="directed")return!1;if(arguments.length===1){let r=""+e,i=this._edges.get(r);return!!i&&i.undirected}else if(arguments.length===2){e=""+e,n=""+n;let r=this._nodes.get(e);return r?r.undirected.hasOwnProperty(n):!1}throw new I(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasEdge(e,n){if(arguments.length===1){let r=""+e;return this._edges.has(r)}else if(arguments.length===2){e=""+e,n=""+n;let r=this._nodes.get(e);return r?typeof r.out<"u"&&r.out.hasOwnProperty(n)||typeof r.undirected<"u"&&r.undirected.hasOwnProperty(n):!1}throw new I(`Graph.hasEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}directedEdge(e,n){if(this.type==="undirected")return;if(e=""+e,n=""+n,this.multi)throw new O("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");let r=this._nodes.get(e);if(!r)throw new N(`Graph.directedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(n))throw new N(`Graph.directedEdge: could not find the "${n}" target node in the graph.`);let i=r.out&&r.out[n]||void 0;if(i)return i.key}undirectedEdge(e,n){if(this.type==="directed")return;if(e=""+e,n=""+n,this.multi)throw new O("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");let r=this._nodes.get(e);if(!r)throw new N(`Graph.undirectedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(n))throw new N(`Graph.undirectedEdge: could not find the "${n}" target node in the graph.`);let i=r.undirected&&r.undirected[n]||void 0;if(i)return i.key}edge(e,n){if(this.multi)throw new O("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.edge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(n))throw new N(`Graph.edge: could not find the "${n}" target node in the graph.`);let i=r.out&&r.out[n]||r.undirected&&r.undirected[n]||void 0;if(i)return i.key}areDirectedNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areDirectedNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:n in r.in||n in r.out}areOutNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areOutNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:n in r.out}areInNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areInNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:n in r.in}areUndirectedNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areUndirectedNeighbors: could not find the "${e}" node in the graph.`);return this.type==="directed"?!1:n in r.undirected}areNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&(n in r.in||n in r.out)||this.type!=="directed"&&n in r.undirected}areInboundNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areInboundNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&n in r.in||this.type!=="directed"&&n in r.undirected}areOutboundNeighbors(e,n){e=""+e,n=""+n;let r=this._nodes.get(e);if(!r)throw new N(`Graph.areOutboundNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&n in r.out||this.type!=="directed"&&n in r.undirected}inDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.inDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.inDegree}outDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.outDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.outDegree}directedDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.directedDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.inDegree+n.outDegree}undirectedDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.undirectedDegree: could not find the "${e}" node in the graph.`);return this.type==="directed"?0:n.undirectedDegree}inboundDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.inboundDegree: could not find the "${e}" node in the graph.`);let r=0;return this.type!=="directed"&&(r+=n.undirectedDegree),this.type!=="undirected"&&(r+=n.inDegree),r}outboundDegree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.outboundDegree: could not find the "${e}" node in the graph.`);let r=0;return this.type!=="directed"&&(r+=n.undirectedDegree),this.type!=="undirected"&&(r+=n.outDegree),r}degree(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.degree: could not find the "${e}" node in the graph.`);let r=0;return this.type!=="directed"&&(r+=n.undirectedDegree),this.type!=="undirected"&&(r+=n.inDegree+n.outDegree),r}inDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.inDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.inDegree-n.directedLoops}outDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.outDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.outDegree-n.directedLoops}directedDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.directedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:n.inDegree+n.outDegree-n.directedLoops*2}undirectedDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.undirectedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="directed"?0:n.undirectedDegree-n.undirectedLoops*2}inboundDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.inboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let r=0,i=0;return this.type!=="directed"&&(r+=n.undirectedDegree,i+=n.undirectedLoops*2),this.type!=="undirected"&&(r+=n.inDegree,i+=n.directedLoops),r-i}outboundDegreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.outboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let r=0,i=0;return this.type!=="directed"&&(r+=n.undirectedDegree,i+=n.undirectedLoops*2),this.type!=="undirected"&&(r+=n.outDegree,i+=n.directedLoops),r-i}degreeWithoutSelfLoops(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.degreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let r=0,i=0;return this.type!=="directed"&&(r+=n.undirectedDegree,i+=n.undirectedLoops*2),this.type!=="undirected"&&(r+=n.inDegree+n.outDegree,i+=n.directedLoops*2),r-i}source(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.source: could not find the "${e}" edge in the graph.`);return n.source.key}target(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.target: could not find the "${e}" edge in the graph.`);return n.target.key}extremities(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.extremities: could not find the "${e}" edge in the graph.`);return[n.source.key,n.target.key]}opposite(e,n){e=""+e,n=""+n;let r=this._edges.get(n);if(!r)throw new N(`Graph.opposite: could not find the "${n}" edge in the graph.`);let i=r.source.key,o=r.target.key;if(e===i)return o;if(e===o)return i;throw new N(`Graph.opposite: the "${e}" node is not attached to the "${n}" edge (${i}, ${o}).`)}hasExtremity(e,n){e=""+e,n=""+n;let r=this._edges.get(e);if(!r)throw new N(`Graph.hasExtremity: could not find the "${e}" edge in the graph.`);return r.source.key===n||r.target.key===n}isUndirected(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.isUndirected: could not find the "${e}" edge in the graph.`);return n.undirected}isDirected(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.isDirected: could not find the "${e}" edge in the graph.`);return!n.undirected}isSelfLoop(e){e=""+e;let n=this._edges.get(e);if(!n)throw new N(`Graph.isSelfLoop: could not find the "${e}" edge in the graph.`);return n.source===n.target}addNode(e,n){return Rw(this,e,n).key}mergeNode(e,n){if(n&&!me(n))throw new I(`Graph.mergeNode: invalid attributes. Expecting an object but got "${n}"`);e=""+e,n=n||{};let r=this._nodes.get(e);return r?(n&&(ce(r.attributes,n),this.emit("nodeAttributesUpdated",{type:"merge",key:e,attributes:r.attributes,data:n})),[e,!1]):(r=new this.NodeDataClass(e,n),this._nodes.set(e,r),this.emit("nodeAdded",{key:e,attributes:n}),[e,!0])}updateNode(e,n){if(n&&typeof n!="function")throw new I(`Graph.updateNode: invalid updater function. Expecting a function but got "${n}"`);e=""+e;let r=this._nodes.get(e);if(r){if(n){let o=r.attributes;r.attributes=n(o),this.emit("nodeAttributesUpdated",{type:"replace",key:e,attributes:r.attributes})}return[e,!1]}let i=n?n({}):{};return r=new this.NodeDataClass(e,i),this._nodes.set(e,r),this.emit("nodeAdded",{key:e,attributes:i}),[e,!0]}dropNode(e){e=""+e;let n=this._nodes.get(e);if(!n)throw new N(`Graph.dropNode: could not find the "${e}" node in the graph.`);let r;if(this.type!=="undirected"){for(let i in n.out){r=n.out[i];do Jt(this,r),r=r.next;while(r)}for(let i in n.in){r=n.in[i];do Jt(this,r),r=r.next;while(r)}}if(this.type!=="directed")for(let i in n.undirected){r=n.undirected[i];do Jt(this,r),r=r.next;while(r)}this._nodes.delete(e),this.emit("nodeDropped",{key:e,attributes:n.attributes})}dropEdge(e){let n;if(arguments.length>1){let r=""+arguments[0],i=""+arguments[1];if(n=Ge(this,r,i,this.type),!n)throw new N(`Graph.dropEdge: could not find the "${r}" -> "${i}" edge in the graph.`)}else if(e=""+e,n=this._edges.get(e),!n)throw new N(`Graph.dropEdge: could not find the "${e}" edge in the graph.`);return Jt(this,n),this}dropDirectedEdge(e,n){if(arguments.length<2)throw new O("Graph.dropDirectedEdge: it does not make sense to try and drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new O("Graph.dropDirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");e=""+e,n=""+n;let r=Ge(this,e,n,"directed");if(!r)throw new N(`Graph.dropDirectedEdge: could not find a "${e}" -> "${n}" edge in the graph.`);return Jt(this,r),this}dropUndirectedEdge(e,n){if(arguments.length<2)throw new O("Graph.dropUndirectedEdge: it does not make sense to drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new O("Graph.dropUndirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");let r=Ge(this,e,n,"undirected");if(!r)throw new N(`Graph.dropUndirectedEdge: could not find a "${e}" -> "${n}" edge in the graph.`);return Jt(this,r),this}clear(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")}clearEdges(){let e=this._nodes.values(),n;for(;n=e.next(),n.done!==!0;)n.value.clear();this._edges.clear(),this._resetInstanceCounters(),this.emit("edgesCleared")}getAttribute(e){return this._attributes[e]}getAttributes(){return this._attributes}hasAttribute(e){return this._attributes.hasOwnProperty(e)}setAttribute(e,n){return this._attributes[e]=n,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:e}),this}updateAttribute(e,n){if(typeof n!="function")throw new I("Graph.updateAttribute: updater should be a function.");let r=this._attributes[e];return this._attributes[e]=n(r),this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:e}),this}removeAttribute(e){return delete this._attributes[e],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:e}),this}replaceAttributes(e){if(!me(e))throw new I("Graph.replaceAttributes: provided attributes are not a plain object.");return this._attributes=e,this.emit("attributesUpdated",{type:"replace",attributes:this._attributes}),this}mergeAttributes(e){if(!me(e))throw new I("Graph.mergeAttributes: provided attributes are not a plain object.");return ce(this._attributes,e),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:e}),this}updateAttributes(e){if(typeof e!="function")throw new I("Graph.updateAttributes: provided updater is not a function.");return this._attributes=e(this._attributes),this.emit("attributesUpdated",{type:"update",attributes:this._attributes}),this}updateEachNodeAttributes(e,n){if(typeof e!="function")throw new I("Graph.updateEachNodeAttributes: expecting an updater function.");if(n&&!vd(n))throw new I("Graph.updateEachNodeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");let r=this._nodes.values(),i,o;for(;i=r.next(),i.done!==!0;)o=i.value,o.attributes=e(o.key,o.attributes);this.emit("eachNodeAttributesUpdated",{hints:n||null})}updateEachEdgeAttributes(e,n){if(typeof e!="function")throw new I("Graph.updateEachEdgeAttributes: expecting an updater function.");if(n&&!vd(n))throw new I("Graph.updateEachEdgeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");let r=this._edges.values(),i,o,a,s;for(;i=r.next(),i.done!==!0;)o=i.value,a=o.source,s=o.target,o.attributes=e(o.key,o.attributes,a.key,s.key,a.attributes,s.attributes,o.undirected);this.emit("eachEdgeAttributesUpdated",{hints:n||null})}forEachAdjacencyEntry(e){if(typeof e!="function")throw new I("Graph.forEachAdjacencyEntry: expecting a callback.");Zr(!1,!1,!1,this,e)}forEachAdjacencyEntryWithOrphans(e){if(typeof e!="function")throw new I("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");Zr(!1,!1,!0,this,e)}forEachAssymetricAdjacencyEntry(e){if(typeof e!="function")throw new I("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");Zr(!1,!0,!1,this,e)}forEachAssymetricAdjacencyEntryWithOrphans(e){if(typeof e!="function")throw new I("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");Zr(!1,!0,!0,this,e)}nodes(){return Array.from(this._nodes.keys())}forEachNode(e){if(typeof e!="function")throw new I("Graph.forEachNode: expecting a callback.");let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)i=r.value,e(i.key,i.attributes)}findNode(e){if(typeof e!="function")throw new I("Graph.findNode: expecting a callback.");let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)if(i=r.value,e(i.key,i.attributes))return i.key}mapNodes(e){if(typeof e!="function")throw new I("Graph.mapNode: expecting a callback.");let n=this._nodes.values(),r,i,o=new Array(this.order),a=0;for(;r=n.next(),r.done!==!0;)i=r.value,o[a++]=e(i.key,i.attributes);return o}someNode(e){if(typeof e!="function")throw new I("Graph.someNode: expecting a callback.");let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)if(i=r.value,e(i.key,i.attributes))return!0;return!1}everyNode(e){if(typeof e!="function")throw new I("Graph.everyNode: expecting a callback.");let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)if(i=r.value,!e(i.key,i.attributes))return!1;return!0}filterNodes(e){if(typeof e!="function")throw new I("Graph.filterNodes: expecting a callback.");let n=this._nodes.values(),r,i,o=[];for(;r=n.next(),r.done!==!0;)i=r.value,e(i.key,i.attributes)&&o.push(i.key);return o}reduceNodes(e,n){if(typeof e!="function")throw new I("Graph.reduceNodes: expecting a callback.");if(arguments.length<2)throw new I("Graph.reduceNodes: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.");let r=n,i=this._nodes.values(),o,a;for(;o=i.next(),o.done!==!0;)a=o.value,r=e(r,a.key,a.attributes);return r}nodeEntries(){let e=this._nodes.values();return{[Symbol.iterator](){return this},next(){let n=e.next();if(n.done)return n;let r=n.value;return{value:{node:r.key,attributes:r.attributes},done:!1}}}}export(){let e=new Array(this._nodes.size),n=0;this._nodes.forEach((i,o)=>{e[n++]=bw(o,i)});let r=new Array(this._edges.size);return n=0,this._edges.forEach((i,o)=>{r[n++]=xw(this.type,o,i)}),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:r}}import(e,n=!1){if(e instanceof t)return e.forEachNode((l,u)=>{n?this.mergeNode(l,u):this.addNode(l,u)}),e.forEachEdge((l,u,c,h,d,f,v)=>{n?v?this.mergeUndirectedEdgeWithKey(l,c,h,u):this.mergeDirectedEdgeWithKey(l,c,h,u):v?this.addUndirectedEdgeWithKey(l,c,h,u):this.addDirectedEdgeWithKey(l,c,h,u)}),this;if(!me(e))throw new I("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(e.attributes){if(!me(e.attributes))throw new I("Graph.import: invalid attributes. Expecting a plain object.");n?this.mergeAttributes(e.attributes):this.replaceAttributes(e.attributes)}let r,i,o,a,s;if(e.nodes){if(o=e.nodes,!Array.isArray(o))throw new I("Graph.import: invalid nodes. Expecting an array.");for(r=0,i=o.length;r<i;r++){a=o[r],_w(a);let{key:l,attributes:u}=a;n?this.mergeNode(l,u):this.addNode(l,u)}}if(e.edges){let l=!1;if(this.type==="undirected"&&(l=!0),o=e.edges,!Array.isArray(o))throw new I("Graph.import: invalid edges. Expecting an array.");for(r=0,i=o.length;r<i;r++){s=o[r],kw(s);let{source:u,target:c,attributes:h,undirected:d=l}=s,f;"key"in s?(f=n?d?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:d?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey,f.call(this,s.key,u,c,h)):(f=n?d?this.mergeUndirectedEdge:this.mergeDirectedEdge:d?this.addUndirectedEdge:this.addDirectedEdge,f.call(this,u,c,h))}}return this}nullCopy(e){let n=new t(ce({},this._options,e));return n.replaceAttributes(ce({},this.getAttributes())),n}emptyCopy(e){let n=this.nullCopy(e);return this._nodes.forEach((r,i)=>{let o=ce({},r.attributes);r=new n.NodeDataClass(i,o),n._nodes.set(i,r)}),n}copy(e){if(e=e||{},typeof e.type=="string"&&e.type!==this.type&&e.type!=="mixed")throw new O(`Graph.copy: cannot create an incompatible copy from "${this.type}" type to "${e.type}" because this would mean losing information about the current graph.`);if(typeof e.multi=="boolean"&&e.multi!==this.multi&&e.multi!==!0)throw new O("Graph.copy: cannot create an incompatible copy by downgrading a multi graph to a simple one because this would mean losing information about the current graph.");if(typeof e.allowSelfLoops=="boolean"&&e.allowSelfLoops!==this.allowSelfLoops&&e.allowSelfLoops!==!0)throw new O("Graph.copy: cannot create an incompatible copy from a graph allowing self loops to one that does not because this would mean losing information about the current graph.");let n=this.emptyCopy(e),r=this._edges.values(),i,o;for(;i=r.next(),i.done!==!0;)o=i.value,Cd(n,"copy",!1,o.undirected,o.key,o.source.key,o.target.key,ce({},o.attributes));return n}toJSON(){return this.export()}toString(){return"[object Graph]"}inspect(){let e={};this._nodes.forEach((o,a)=>{e[a]=o.attributes});let n={},r={};this._edges.forEach((o,a)=>{let s=o.undirected?"--":"->",l="",u=o.source.key,c=o.target.key,h;o.undirected&&u>c&&(h=u,u=c,c=h);let d=`(${u})${s}(${c})`;a.startsWith("geid_")?this.multi&&(typeof r[d]>"u"?r[d]=0:r[d]++,l+=`${r[d]}. `):l+=`[${a}]: `,l+=d,n[l]=o.attributes});let i={};for(let o in this)this.hasOwnProperty(o)&&!yd.has(o)&&typeof this[o]!="function"&&typeof o!="symbol"&&(i[o]=this[o]);return i.attributes=this._attributes,i.nodes=e,i.edges=n,Me(i,"constructor",this.constructor),i}};typeof Symbol<"u"&&(q.prototype[Symbol.for("nodejs.util.inspect.custom")]=q.prototype.inspect);Tw.forEach(t=>{["add","merge","update"].forEach(e=>{let n=t.name(e),r=e==="add"?Cd:Cw;t.generateKey?q.prototype[n]=function(i,o,a){return r(this,n,!0,(t.type||this.type)==="undirected",null,i,o,a,e==="update")}:q.prototype[n]=function(i,o,a,s){return r(this,n,!1,(t.type||this.type)==="undirected",i,o,a,s,e==="update")}})});Oy(q);Yy(q);dw(q);ww(q);var Qr=class extends q{constructor(e){let n=ce({type:"directed"},e);if("multi"in n&&n.multi!==!1)throw new I("DirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(n.type!=="directed")throw new I('DirectedGraph.from: inconsistent "'+n.type+'" type in given options!');super(n)}},Jr=class extends q{constructor(e){let n=ce({type:"undirected"},e);if("multi"in n&&n.multi!==!1)throw new I("UndirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(n.type!=="undirected")throw new I('UndirectedGraph.from: inconsistent "'+n.type+'" type in given options!');super(n)}},ei=class extends q{constructor(e){let n=ce({multi:!0},e);if("multi"in n&&n.multi!==!0)throw new I("MultiGraph.from: inconsistent indication that the graph should be simple in given options!");super(n)}},ti=class extends q{constructor(e){let n=ce({type:"directed",multi:!0},e);if("multi"in n&&n.multi!==!0)throw new I("MultiDirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(n.type!=="directed")throw new I('MultiDirectedGraph.from: inconsistent "'+n.type+'" type in given options!');super(n)}},ni=class extends q{constructor(e){let n=ce({type:"undirected",multi:!0},e);if("multi"in n&&n.multi!==!0)throw new I("MultiUndirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(n.type!=="undirected")throw new I('MultiUndirectedGraph.from: inconsistent "'+n.type+'" type in given options!');super(n)}};function nn(t){t.from=function(e,n){let r=ce({},e.options,n),i=new t(r);return i.import(e),i}}nn(q);nn(Qr);nn(Jr);nn(ei);nn(ti);nn(ni);q.Graph=q;q.DirectedGraph=Qr;q.UndirectedGraph=Jr;q.MultiGraph=ei;q.MultiDirectedGraph=ti;q.MultiUndirectedGraph=ni;q.InvalidArgumentsGraphError=I;q.NotFoundGraphError=N;q.UsageGraphError=O;function Lw(){return new q({multi:!0,type:"directed"})}function sa(t){let e=Lw();for(let n of t.nodes){let{id:r,...i}=n;e.addNode(r,i)}for(let n of t.edges){let{key:r,source:i,target:o,...a}=n;e.addDirectedEdgeWithKey(r,i,o,{source:i,target:o,...a})}return e}function Ld(t,e){let n=0;for(let[r,i]of e)t.hasNode(r)&&(!Number.isFinite(i.x)||!Number.isFinite(i.y)||(t.mergeNodeAttributes(r,{x:i.x,y:i.y}),n++));return n}function la(t){let e=new Map;return t.forEachNode((n,r)=>{e.set(n,{x:r.x,y:r.y})}),e}var Nd=t=>({now:()=>t.performance.now(),request:e=>t.requestAnimationFrame(()=>e()),cancel:e=>t.cancelAnimationFrame(e)});function Dd(t,e,n){let r=null,i=sa({nodes:[],edges:[]}),o=null,a=null,s=0,l=0,u=null,c=0,h=()=>{},d=()=>{},f=()=>{},v=()=>{},m=()=>{},g=null,w=A=>{if(g===null)return;let R=g;g=null,r?.setSetting("enableCameraPanning",!0),(A===null||A===R)&&m(R)},y=()=>ud([...la(i).values()]),_=A=>{let R=fd(o,a,s),M=gd(o,a,s);A.setSetting("nodeReducer",(L,S)=>({...S,...R(L,S,e)})),A.setSetting("edgeReducer",(L,S)=>({...S,...M(L,S,e)}))},k=()=>{if(n===void 0||u!==null)return;c=n.now();let A=()=>{u=null;let R=n.now();if(s=pd(s,l,R-c),c=R,r!==null&&_(r),s===l){s===0&&(o=null);return}u=n.request(A)};u=n.request(A)};return{mount(A){if(r!==null)return;let R=t(i,A,md(e));R.on("clickNode",({node:M})=>h(M)),R.on("clickStage",()=>h(null)),R.on("downNode",({node:M})=>{g=M,r?.setSetting("enableCameraPanning",!1),f(M)}),R.on("moveBody",M=>{g!==null&&(M.preventSigmaDefault(),v(g,R.viewportToGraph({x:M.event.x,y:M.event.y})))}),R.on("enterNode",({node:M})=>d(M)),R.on("leaveNode",()=>d(null)),R.on("upNode",()=>w(g)),R.on("upStage",()=>w(null)),_(R),R.setCustomBBox(y()),r=R},setGraph(A){i=sa(A),r?.setGraph(i),r?.setCustomBBox(y())},setPositions(A){Ld(i,A),r?.refresh()},setHighlight(A,R=null){if(n===void 0){o=A,a=R,s=A===null?0:1,l=s,r!==null&&_(r);return}if(A===null){if(l=0,o===null)return}else o=A,a=R,l=1;r!==null&&_(r),s!==l&&k()},onSelect(A){h=A},onHover(A){d=A},onDragStart(A){f=A},onDragMove(A){v=A},onDragEnd(A){m=A},fit(){r?.setCustomBBox(y()),r?.getCamera().animatedReset()},positions(){return la(i)},destroy(){u!==null&&(n?.cancel(u),u=null),r?.kill(),r=null}}}var Pd=t=>Dd((e,n,r)=>new id(e,n,r),t,Nd(window));var Id=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");function Md(t,e,n){return t===0?null:t===1?0:e<0?n?t-1:0:n?e===0?t-1:e-1:e===t-1?0:e+1}function Gd(t,e,n,r){return t==="Tab"&&!e&&!n&&!r}function Fd(t){return t===null?!1:(t.focus(),!0)}function ii(){let t=V(null);return ee(()=>{let e=document.activeElement;return t.current?.focus(),()=>{Fd(e instanceof HTMLElement?e:null)}},[]),{ref:t,onKeyDown(e){if(!Gd(e.key,e.ctrlKey,e.metaKey,e.altKey))return!1;let n=[...t.current?.querySelectorAll(Id)??[]],r=Md(n.length,n.indexOf(document.activeElement),e.shiftKey);return r===null?!1:(e.preventDefault(),n[r]?.focus(),!0)}}}function $d(t,e){let n=e.trim().toLowerCase();if(!n)return 0;let r=t.toLowerCase(),i=r.indexOf(n);return i<0?0:r===n?100:i===0?70:/[a-z0-9]/.test(r.charAt(i-1))?30:50}function Nw(t){return Math.min(Math.max(t,0),10)*2}function Dw(t){return`note:${t}`}function Pw(t,e){return $d(t.summary.title,e)+Nw(t.score)}function Iw(t,e){return $d(t.label,e)}var Mw=["path","manifest","url","slug"];function Gw(t){for(let e of Mw){let n=t.detail[e];if(typeof n=="string"&&n)return n}return""}function Fw(t,e){return t.score!==e.score?e.score-t.score:t.kind!==e.kind?t.kind==="note"?-1:1:t.label.localeCompare(e.label)||t.id.localeCompare(e.id)}function Ow(t,e,n,r){let i=new Map;for(let o of t){let a=Dw(o.summary.slug);i.set(a,{id:a,kind:"note",label:o.summary.title,detail:o.snippet,badge:"note",score:Pw(o,e)})}for(let o of n){if(i.has(o.id))continue;let a=Iw(o,r);a&&i.set(o.id,{id:o.id,kind:"node",label:o.label,detail:Gw(o),badge:o.kind,score:a})}return[...i.values()].sort(Fw).slice(0,20)}function Ud(){return{query:"",answered:"",hits:[],cursor:0,loading:!1,failed:!1}}function ua(t,e){return e<=0?0:Math.min(Math.max(t,0),e-1)}function Od(t,e,n){return n<=0?0:((t+e)%n+n)%n}function Hd(t,e){return e===null?null:t[e]?.id??null}function Bd(t,e,n){let r={cursor:t,activate:null,dismiss:!1,handled:!1},i=ua(t,n);return e==="ArrowDown"?{...r,cursor:Od(i,1,n),handled:!0}:e==="ArrowUp"?{...r,cursor:Od(i,-1,n),handled:!0}:e==="Home"?{...r,cursor:0,handled:!0}:e==="End"?{...r,cursor:ua(n-1,n),handled:!0}:e==="Escape"?{...r,dismiss:!0,handled:!0}:e!=="Enter"||n===0?r:{...r,cursor:i,activate:i,dismiss:!0,handled:!0}}var oi="Search the workspace",Wd="Search notes and repository…",Kd="↑↓ move · ↵ open · esc close";function zw(t,e){return t.query.trim()?e>0?null:t.failed?"search failed — the workspace server may be gone":t.loading?"searching…":`no matches for “${t.query.trim()}”`:"Type to search notes, modules, files and entry points."}function $w(t){return t===1?"1 result":`${t} results`}function zd(t){return`weave-search-row-${t}`}function Vd(t,e){let n=Ow(t.hits,t.answered,e?.model.nodes??[],t.query),r=ua(t.cursor,n.length);return{rows:n.map((o,a)=>({...o,active:a===r,domId:zd(a)})),status:zw(t,n.length),count:n.length,countLabel:$w(n.length),cursor:r,activeDomId:n.length?zd(r):null}}var Uw=0;function b(t,e,n,r,i,o){e||(e={});var a,s,l=e;if("ref"in l)for(s in l={},e)s=="ref"?a=e[s]:l[s]=e[s];var u={type:t,props:l,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Uw,__i:-1,__u:0,__source:i,__self:o};if(typeof t=="function"&&(a=t.defaultProps))for(s in a)l[s]===void 0&&(l[s]=a[s]);return K.vnode&&K.vnode(u),u}function Bw({row:t,onPick:e,onHover:n}){return b("li",{id:t.domId,role:"option","aria-selected":t.active,class:`weave-hit weave-hit-${t.kind}${t.active?" weave-hit-on":""}`,onMouseMove:n,onClick:e,children:[b("span",{class:"weave-hit-badge",children:t.badge}),b("span",{class:"weave-hit-label",children:t.label}),b("span",{class:"weave-hit-detail",children:t.detail})]})}function jd(t){let[e,n]=B(Ud),r=V(0),i=V(null),o=ii(),a=V(null);ee(()=>{a.current?.focus()},[]),ee(()=>{let u=e.query.trim(),c=!0;if(!u)return i.current?.abort(),n(d=>({...d,hits:[],answered:"",loading:!1,failed:!1})),()=>{c=!1};let h=window.setTimeout(async()=>{let d=++r.current;i.current?.abort();let f=new AbortController;i.current=f,n(m=>({...m,loading:!0,failed:!1}));let v=await Rl(t.ports.fetch,u,f.signal);!c||f.signal.aborted||d!==r.current||n(m=>v.ok?{...m,hits:v.data.hits,answered:u,loading:!1,failed:!1,cursor:0}:{...m,loading:!1,failed:!0})},140);return()=>{c=!1,window.clearTimeout(h),i.current?.abort()}},[e.query,t.ports.fetch]);let s=Vd(e,t.graph),l=u=>{let c=Hd(s.rows,u);c!==null&&t.onSelect(c),t.onClose()};return b("div",{class:"weave-scrim",onClick:()=>l(null),children:b("div",{class:"weave-palette",role:"dialog","aria-modal":"true","aria-label":oi,tabIndex:-1,ref:o.ref,onClick:u=>u.stopPropagation(),onKeyDown:u=>{if(o.onKeyDown(u))return;let c=Bd(e.cursor,u.key,s.count);c.handled&&(u.preventDefault(),n(h=>({...h,cursor:c.cursor})),c.dismiss&&l(c.activate))},children:[b("input",{type:"search",class:"weave-palette-input",ref:a,value:e.query,placeholder:Wd,"aria-label":oi,"aria-controls":"weave-search-results","aria-activedescendant":s.activeDomId??void 0,onInput:u=>n(c=>({...c,query:u.currentTarget.value,cursor:0}))}),s.status===null?b("ul",{id:"weave-search-results",class:"weave-hits",role:"listbox","aria-label":oi,children:s.rows.map((u,c)=>b(Bw,{row:u,onPick:()=>l(c),onHover:()=>n(h=>({...h,cursor:c}))},u.id))}):b("p",{class:"weave-palette-status",role:"status",children:s.status}),b("p",{class:"weave-palette-foot",children:[b("span",{children:s.countLabel}),b("span",{class:"weave-palette-hint",children:Kd})]})]})})}var qd="pi-weave.selection.v1";function Yd(t,e){try{return t.setItem(qd,e??""),!0}catch{return!1}}function Xd(t,e){if(t===null)return null;let n;try{n=e.getItem(qd)}catch{return null}return n===null||n===""?null:t.model.nodes.some(r=>r.id===n)?n:null}function Zd(){return{graph:null,graphFailed:!1,note:null,noteFailed:!1,recentIds:new Set,selectedId:null}}var Ww=2e3,Kw=3e3,Jd=new Set;function Vw(t,e){if(t===null)return Jd;let n=new Set(t.model.nodes.map(r=>r.id));return new Set(e.model.nodes.filter(r=>!n.has(r.id)).map(r=>r.id))}function Qd(t){if(t===null||!t.startsWith("note:"))return null;let e=t.slice(5);return e===""?null:e}function eh(t){let e=t.state,n=!1,r=!1,i=null,o=d=>{Object.entries(d).every(([f,v])=>e[f]===v)||(e={...e,...d},t.setState(e))},a=t.defer??((d,f)=>{let v=setTimeout(d,f);return()=>clearTimeout(v)}),s=async()=>{let d=Qd(e.selectedId);if(d===null){o({note:null,noteFailed:!1});return}let f=await Al(t.fetch,d);f.ok?o({note:f.data,noteFailed:!1}):o({note:null,noteFailed:!0})},l=async()=>{let d=e.graph,f=await Tl(t.fetch,e.graph);if(!f.ok)return e.graph===null&&o({graphFailed:!0}),f;if(!f.cached){let v=Vw(d,f.data);o({graph:f.data,graphFailed:!1,recentIds:v}),i?.(),i=null,v.size>0&&(i=a(()=>{i=null,o({recentIds:Jd})},Kw))}return f},u=async()=>{if(!(n||r)){r=!0;try{let d=await l();Qd(e.selectedId)!==null&&(e.note===null||d.ok&&!d.cached)&&await s()}finally{r=!1}}},h=(t.repeat??((d,f)=>{let v=setInterval(d,f);return()=>clearInterval(v)}))(()=>{u()},Ww);return u(),{refresh:()=>{u()},select:async d=>{o({selectedId:d}),await s()},syncNote:s,stop:()=>{n||(n=!0,h(),i?.(),i=null)}}}function th(t){return t==="contains"||t==="anchored-at"}function jw(t,e){let n=new Set(t.map(i=>i.id)),r=new Map;for(let i of e)th(i.kind)&&i.source!==i.target&&(!n.has(i.source)||!n.has(i.target)||r.has(i.target)||r.set(i.target,i.source));return r}function qw(t,e){let n=jw(t,e),r=new Map;for(let i of t){let o=i.id,a=i.id,s=0,l=new Set([o]);for(;;){let u=n.get(o);if(u===void 0||l.has(u))break;l.add(u),a=o,o=u,s++}r.set(i.id,{key:a,depth:Math.max(0,s-1)})}return r}function Yw(t){let e=new Map;for(let n of t.values())e.set(n,(e.get(n)??0)+1);return e}var Xw={dark:["#f5bde6","#c6a0f6","#ed8796","#f5a97f","#eed49f","#a6da95","#8bd5ca","#7dc4e4","#8aadf4","#b7bdf8"],light:["#824171","#7832d4","#d20f39","#9f3e07","#7b4e10","#28641b","#106368","#14616e","#1853c8","#445198"]},Zw=3;function Qw(t,e){let n=Xw[e],i=[...Yw(t).entries()].sort((a,s)=>s[1]-a[1]||(a[0]<s[0]?-1:a[0]>s[0]?1:0)),o=new Map;return i.forEach(([a],s)=>o.set(a,n[s*Zw%n.length])),o}var Jw=.11,eb=.34;function tb(t,e,n){let r=Number.isFinite(e)&&e>0?e:0;return Nn(t,gt[n].ground,Math.min(eb,r*Jw))}var nb=.26,rb=.55;function ib(t,e,n){if(e.length===0)return t;let r=t,i=0;for(let o of e){let a=Math.min(nb,rb-i);if(a<=0)break;i+=a,r=Nn(r,o,a)}return r}function nh(t,e,n){let r=qw(t,e),i=new Map;for(let[c,h]of r)i.set(c,h.key);let o=Qw(i,n),a=new Set(t.map(c=>c.id)),s=new Map,l=(c,h)=>{let d=r.get(c)?.key,f=r.get(h)?.key;if(d===void 0||f===void 0||d===f)return;let v=s.get(c);v===void 0?s.set(c,new Set([f])):v.add(f)};for(let c of e)th(c.kind)||c.source!==c.target&&(!a.has(c.source)||!a.has(c.target)||(l(c.source,c.target),l(c.target,c.source)));let u=new Map;for(let c of t){let h=r.get(c.id);if(h===void 0)continue;let d=o.get(h.key);if(d===void 0)continue;let f=tb(d,h.depth,n),v=[...s.get(c.id)??[]].sort().map(m=>o.get(m)).filter(m=>m!==void 0);u.set(c.id,ib(f,v,n))}return u}function rh(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e^=e>>>16,e=Math.imul(e,2246822507),e^=e>>>13,e=Math.imul(e,3266489909),e^=e>>>16,e>>>0}var ob=300,ab=1;function sb(t,e,n){let r=new Map(n??[]);if(r.size>0)for(let o of e){if(o.kind!=="contains"&&o.kind!=="anchored-at"||r.has(o.target))continue;let a=r.get(o.source);a!==void 0&&r.set(o.target,{x:a.x,y:a.y})}let i={ticks:ob,seed:ab,pinWarm:!0};return r.size>0&&(i.initial=r),rl({generatedAt:"",staleness:null,nodes:[...t],edges:[...e],contentDigest:""},i)}function lb(t,e){let n=0,r=0;for(let o of t){let a=rh(o.id);n^=a,r=r+a>>>0}for(let o of e){let a=rh(`${o.source}\0${o.target}\0${o.kind}`);n^=a,r=r+a>>>0}return[t.length,e.length,n>>>0,r].map(o=>o.toString(16)).join("-")}var ai="pi-weave.graph.positions.v4";function ih(t){return Math.round(t*10)/10}function ub(t,e){let n={};for(let[r,i]of e)n[r]=[ih(i.x),ih(i.y)];return JSON.stringify({v:4,key:t,at:n})}function cb(t,e){if(t===null)return null;let n;try{n=JSON.parse(t)}catch{return null}if(typeof n!="object"||n===null||Array.isArray(n))return null;let r=n;if(r.v!==4||r.key!==e)return null;let i=r.at;if(typeof i!="object"||i===null||Array.isArray(i))return null;let o=new Map;for(let[a,s]of Object.entries(i)){if(!Array.isArray(s)||s.length!==2)return null;let[l,u]=s;if(typeof l!="number"||typeof u!="number"||!Number.isFinite(l)||!Number.isFinite(u))return null;o.set(a,{x:l,y:u})}return o.size===0?null:o}function db(t,e){let n;try{n=t.getItem(ai)}catch{return null}return cb(n,e)}function hb(t,e,n){try{return t.setItem(ai,ub(e,n)),!0}catch{return!1}}function oh(t,e,n){let r=lb(e,n),i=db(t,r);if(i!==null&&e.every(a=>i.has(a.id)))return{key:r,positions:i,cached:!0};let o=sb(e,n);return hb(t,r,o),{key:r,positions:o,cached:!1}}function fb(t){return{expanded:new Set(Rr(t,new Set).clusters.keys())}}function sh(t,e){return e!==null?e:t===null?{expanded:new Set}:fb(Rt(t))}function pb(t,e){let n=new Set(t.expanded);return n.delete(e)||n.add(e),{...t,expanded:n}}function gb(t,e){return e===null?null:Ar(e,t)}function lh(t,e,n){return e===null?n:Ar(e,t)}var uh="fit",ch="frame the whole graph",dh="sliders",hh="tune the layout physics and colours",si={selected:"selected",neighborhood:"neighborhood",dimmed:"not related"};function fh(t,e){let n=e===1?"node":"nodes";return t===e?`${e} ${n}`:`${t} of ${e} ${n}`}function mb(t,e){return t===null?"Loading…":t.model.nodes.length===0?"Nothing indexed yet — add a note or run /weave-scan.":e===0?"Nothing to draw at this expansion.":null}var vb="The workspace did not load — ⟳ retries now, and the next change to the vault retries on its own.",ah={graph:cd,highlight:null,key:"",cached:!1,clusters:new Map,visible:0,total:0,empty:"Loading…"};function ph(t,e,n,r,i,o=!1,a=!0){if(t===null)return o?{...ah,empty:vb}:ah;let s=Rt(t),l=Rr(s,n.expanded),c=n.expanded.has("vault")?l.edges.filter(f=>f.source!=="vault"&&f.target!=="vault"):l.edges,h=oh(r,l.nodes,c),d=a?nh(l.nodes,c,i):void 0;return{graph:hd(l.nodes,c,h.positions,i,d),highlight:gb(c,e),key:h.key,cached:h.cached,clusters:l.clusters,visible:l.nodes.length,total:s.nodes.length,empty:mb(t,l.nodes.length)}}function gh(t,e,n){return n===null?{state:t,selectedId:null}:e.get(n)===void 0||t.expanded.has(n)?{state:t,selectedId:n}:{state:pb(t,n),selectedId:n}}var yb=.06,wb=.2,ca=.001,mh=.5;function vh(t,e){if(t.nodes.length===0)return null;let n=t.nodes.map(s=>{let l=e?.get(s.id);return{id:s.id,x:l!==void 0&&Number.isFinite(l.x)?l.x:s.x,y:l!==void 0&&Number.isFinite(l.y)?l.y:s.y,vx:0,vy:0,r:Zi(s.size)}}),r=new Map(n.map(s=>[s.id,s])),i=new Set,o=[];for(let s of t.edges){if(s.source===s.target||!r.has(s.source)||!r.has(s.target))continue;let l=`${s.source}\0${s.target}\0${s.kind}`;i.has(l)||(i.add(l),o.push({source:s.source,target:s.target,kind:s.kind}))}let a=Ji({nodes:n,links:o,seed:1}).alpha(yb).alphaMin(ca);return{tick(){a.tick()},awake(){return a.alphaTarget()>ca||a.alpha()>ca},positions(){return new Map(n.map(s=>[s.id,{x:s.x??0,y:s.y??0}]))},pin(s,l){let u=r.get(s);if(!u)return;let c=u.fx!=null&&u.fy!=null&&Math.abs(u.fx-l.x)<mh&&Math.abs(u.fy-l.y)<mh;u.fx=l.x,u.fy=l.y,a.alphaTarget(c?0:wb)},release(s){let l=r.get(s);l&&(l.fx=null,l.fy=null,a.alphaTarget(0))}}}function yh(t){let[,e]=B(0),[n,r]=B(!1),i=(a,s)=>{Qi({[a.key]:sl(a,s)}),r(!1),e(l=>l+1),t.onChange()},o=a=>{Qi(a),r(!1),e(s=>s+1),t.onChange()};return b("div",{class:"weave-tuner",children:[b("p",{class:"weave-tuner-title",children:"graph forces · ?sliders=1"}),b("label",{class:"weave-tuner-toggle",title:"hue per containment group, shade per kind",children:[b("input",{type:"checkbox",checked:t.groupColors,onChange:a=>t.onGroupColors(a.currentTarget.checked)}),b("span",{children:"colour by group"})]}),vr.map(a=>b("label",{class:"weave-tuner-row",title:a.hint,children:[b("span",{class:"weave-tuner-label",children:[a.label,b("b",{children:ll(ve[a.key])})]}),b("input",{type:"range",min:a.min,max:a.max,step:a.step,value:al(ve,a),onInput:s=>i(a,s.currentTarget.value)})]},a.key)),b("div",{class:"weave-tuner-actions",children:[b("button",{type:"button",class:"weave-chip",disabled:ul(ve),onClick:()=>o(vn),children:"reset"}),b("button",{type:"button",class:"weave-chip",title:"the pre-tuner constants, for comparison — see HAIRBALL",onClick:()=>o(ol),children:"before"}),b("button",{type:"button",class:"weave-chip",onClick:()=>{navigator.clipboard?.writeText(eo(ve)).then(()=>r(!0),()=>r(!1))},children:n?"copied ✓":"copy values"})]}),b("pre",{class:"weave-tuner-snippet",children:eo(ve)})]})}function wh(t){let e=V(null),n=V(null),r=V(null),i=V(null),o=_l(()=>{if(i.current!==null)return;let y=()=>{i.current=null;let _=r.current;_!==null&&(_.tick(),_.awake()&&(n.current?.setPositions(_.positions()),i.current=requestAnimationFrame(y)))};i.current=requestAnimationFrame(y)},[]),[a,s]=B(null),[l,u]=B(0),[c,h]=B(()=>dl(t.storage)),[d,f]=B(t.tuner===!0),v=t.scheme??Mr(t.host),m=sh(t.graph,a),g=Ze(()=>ph(t.graph,t.selectedId,m,t.storage,v,t.bootFailed,c),[t.graph,t.selectedId,m,t.storage,v,t.bootFailed,l,c]),w=V({view:m,model:g,onSelect:t.onSelect,selectedId:t.selectedId});return w.current={view:m,model:g,onSelect:t.onSelect,selectedId:t.selectedId},ee(()=>{let y=t.renderer(v);return y.onSelect(_=>{let k=gh(w.current.view,w.current.model.clusters,_);s(k.state),w.current.onSelect(k.selectedId)}),y.onHover(_=>{let{model:k,selectedId:A}=w.current;y.setHighlight(lh(k.graph.edges,_,k.highlight),_??A)}),y.onDragStart(_=>{let k=n.current?.positions().get(_);k&&(r.current?.pin(_,k),o())}),y.onDragMove((_,k)=>{r.current?.pin(_,k)}),y.onDragEnd(_=>{r.current?.release(_)}),y.mount(e.current??{clientWidth:0,clientHeight:0}),n.current=y,y.setGraph(w.current.model.graph),y.setHighlight(w.current.model.highlight,w.current.selectedId),t.fit.current=()=>y.fit(),()=>{y.destroy(),n.current=null,t.fit.current=null}},[t.renderer,v]),ee(()=>{n.current?.setGraph(g.graph)},[g.key,l,c]),ee(()=>{let y=vh(g.graph,n.current?.positions());return r.current=y,y!==null&&o(),()=>{r.current=null}},[g.key,o,l]),ee(()=>()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)},[]),ee(()=>{n.current?.setHighlight(g.highlight,t.selectedId)},[g.highlight,t.selectedId]),b("div",{class:"weave-graph",children:[g.empty===null?null:b("p",{class:"weave-graph-empty",children:g.empty}),b("div",{class:"weave-graph-canvas",ref:e,role:"img","aria-label":"Knowledge graph",tabIndex:-1}),d?b(yh,{groupColors:c,onGroupColors:y=>{hl(t.storage,y),h(y)},onChange:()=>{try{t.storage.setItem(ai,"")}catch{}u(y=>y+1)}}):null,b("div",{class:"weave-graph-controls",children:[b("button",{type:"button",class:"weave-chip",title:ch,onClick:()=>n.current?.fit(),children:uh}),b("button",{type:"button",class:d?"weave-chip weave-chip-on":"weave-chip",title:hh,"aria-pressed":d,onClick:()=>f(!d),children:dh}),b("span",{class:"weave-graph-legend",children:[b("span",{class:"weave-legend-on",children:["◉ ",si.selected]}),b("span",{class:"weave-legend-near",children:["● ",si.neighborhood]}),b("span",{class:"weave-legend-dim",children:["· ",si.dimmed]})]})]}),b("p",{class:"weave-graph-count",children:fh(g.visible,g.total)})]})}function bh(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function bb(t){if(Array.isArray(t))return t}function xb(t,e){var n=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(n!=null){var r,i,o,a,s=[],l=!0,u=!1;try{if(o=(n=n.call(t)).next,e!==0)for(;!(l=(r=o.call(n)).done)&&(s.push(r.value),s.length!==e);l=!0);}catch(c){u=!0,i=c}finally{try{if(!l&&n.return!=null&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw i}}return s}}function _b(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
398
398
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function kb(t,e){return bb(t)||xb(t,e)||Eb(t,e)||_b()}function Eb(t,e){if(t){if(typeof t=="string")return bh(t,e);var n={}.toString.call(t).slice(8,-1);return n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set"?Array.from(t):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?bh(t,e):void 0}}var Mh=Object.entries,xh=Object.setPrototypeOf,Sb=Object.isFrozen,Tb=Object.getPrototypeOf,Ab=Object.getOwnPropertyDescriptor,de=Object.freeze,pe=Object.seal,rn=Object.create,Gh=typeof Reflect<"u"&&Reflect,va=Gh.apply,ya=Gh.construct;de||(de=function(e){return e});pe||(pe=function(e){return e});va||(va=function(e,n){for(var r=arguments.length,i=new Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];return e.apply(n,i)});ya||(ya=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return new e(...r)});var It=se(Array.prototype.forEach),Rb=se(Array.prototype.lastIndexOf),_h=se(Array.prototype.pop),Mn=se(Array.prototype.push),Cb=se(Array.prototype.splice),on=Array.isArray,On=se(String.prototype.toLowerCase),da=se(String.prototype.toString),kh=se(String.prototype.match),Gn=se(String.prototype.replace),Eh=se(String.prototype.indexOf),Lb=se(String.prototype.trim),Nb=se(Number.prototype.toString),Db=se(Boolean.prototype.toString),Sh=typeof BigInt>"u"?null:se(BigInt.prototype.toString),Th=typeof Symbol>"u"?null:se(Symbol.prototype.toString),Te=se(Object.prototype.hasOwnProperty),Fn=se(Object.prototype.toString),we=se(RegExp.prototype.test),Pt=Pb(TypeError);function se(t){return function(e){e instanceof RegExp&&(e.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return va(t,e,r)}}function Pb(t){return function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return ya(t,n)}}function H(t,e){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:On;if(xh&&xh(t,null),!on(e))return t;let r=e.length;for(;r--;){let i=e[r];if(typeof i=="string"){let o=n(i);o!==i&&(Sb(e)||(e[r]=o),i=o)}t[i]=!0}return t}function Ib(t){for(let e=0;e<t.length;e++)Te(t,e)||(t[e]=null);return t}function Ne(t){let e=rn(null);for(let r of Mh(t)){var n=kb(r,2);let i=n[0],o=n[1];Te(t,i)&&(on(o)?e[i]=Ib(o):o&&typeof o=="object"&&o.constructor===Object?e[i]=Ne(o):e[i]=o)}return e}function Mb(t){switch(typeof t){case"string":return t;case"number":return Nb(t);case"boolean":return Db(t);case"bigint":return Sh?Sh(t):"0";case"symbol":return Th?Th(t):"Symbol()";case"undefined":return Fn(t);case"function":case"object":{if(t===null)return Fn(t);let e=t,n=Ke(e,"toString");if(typeof n=="function"){let r=n(e);return typeof r=="string"?r:Fn(r)}return Fn(t)}default:return Fn(t)}}function Ke(t,e){for(;t!==null;){let r=Ab(t,e);if(r){if(r.get)return se(r.get);if(typeof r.value=="function")return se(r.value)}t=Tb(t)}function n(){return null}return n}function Gb(t){try{return we(t,""),!0}catch{return!1}}var Ah=de(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),ha=de(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),fa=de(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Fb=de(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),pa=de(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),Ob=de(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Rh=de(["#text"]),Ch=de(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","command","commandfor","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns"]),ga=de(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dominant-baseline","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","pointer-events","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-orientation","text-rendering","textlength","type","u1","u2","unicode","values","vector-effect","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),Lh=de(["accent","accentunder","align","bevelled","close","columnalign","columnlines","columnspacing","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lquote","lspace","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),li=de(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),zb=pe(/{{[\w\W]*|^[\w\W]*}}/g),$b=pe(/<%[\w\W]*|^[\w\W]*%>/g),Ub=pe(/\${[\w\W]*/g),Hb=pe(/^data-[\-\w.\u00B7-\uFFFF]+$/),Bb=pe(/^aria-[\-\w]+$/),Nh=pe(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Wb=pe(/^(?:\w+script|data):/i),Kb=pe(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Vb=pe(/^html$/i),jb=pe(/^[a-z][.\w]*(-[.\w]+)+$/i),Dh=pe(/<[/\w!]/g),Ph=pe(/<[/\w]/g),qb=pe(/<\/no(script|embed|frames)/i),Yb=pe(/\/>/i),Le={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Fh=["style","script","xmp","iframe","noembed","noframes","plaintext","noscript"],Xb=de(H({},Fh)),Zb=(function(){let t={};return It(Fh,e=>{t[e]=pe(new RegExp("</"+e+"(?=[\\t\\n\\f\\r />])","i"))}),de(t)})(),Qb=function(){return typeof window>"u"?null:window},Jb=function(e,n){if(typeof e!="object"||typeof e.createPolicy!="function")return null;let r=null,i="data-tt-policy-suffix";n&&n.hasAttribute(i)&&(r=n.getAttribute(i));let o="dompurify"+(r?"#"+r:"");try{return e.createPolicy(o,{createHTML(a){return a},createScriptURL(a){return a}})}catch{return console.warn("TrustedTypes policy "+o+" could not be created."),null}},Ih=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},mt=function(e,n,r,i){return Te(e,n)&&on(e[n])?H(i.base?Ne(i.base):{},e[n],i.transform):r},ma=function(e,n,r){let i=Te(e,n)?e[n]:void 0;return i&&typeof i=="object"?Ne(i):r()};function Oh(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Qb(),e=C=>Oh(C);if(e.version="3.4.14",e.removed=[],!t||!t.document||t.document.nodeType!==Le.document||!t.Element)return e.isSupported=!1,e;let n=t.document,r=n,i=r.currentScript;t.DocumentFragment;let o=t.HTMLTemplateElement,a=t.Node,s=t.Element,l=t.NodeFilter,u=t.NamedNodeMap;u===void 0&&(t.NamedNodeMap||t.MozNamedAttrMap),t.HTMLFormElement;let c=t.DOMParser,h=t.trustedTypes,d=s.prototype,f=Ke(d,"cloneNode"),v=Ke(d,"remove"),m=Ke(d,"nextSibling"),g=Ke(d,"childNodes"),w=Ke(d,"parentNode"),y=Ke(d,"shadowRoot"),_=Ke(d,"attributes"),k=a&&a.prototype?Ke(a.prototype,"nodeType"):null,A=a&&a.prototype?Ke(a.prototype,"nodeName"):null,R=a&&a.prototype?Ke(a.prototype,"ownerDocument"):null,M=function(p){return k?k(p):p.nodeType},L=function(p){return A?A(p):p.nodeName};if(typeof o=="function"){let C=n.createElement("template");C.content&&C.content.ownerDocument&&(n=C.content.ownerDocument)}let S,D="",$,W=!1,te=0,ge=function(){if(te>0)throw Pt('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.')},he=function(p){ge(),te++;try{return S.createHTML(p)}finally{te--}},Ve=function(p){ge(),te++;try{return S.createScriptURL(p)}finally{te--}},Mt=function(){return W||($=Jb(h,i),W=!0),$},Fe=n,Oe=Fe.implementation,ze=Fe.createNodeIterator,je=Fe.createDocumentFragment,an=Fe.getElementsByTagName,De=r.importNode,X=Ih();e.isSupported=typeof Mh=="function"&&typeof w=="function"&&Oe&&Oe.createHTMLDocument!==void 0;let sn=zb,jf=$b,qf=Ub,Yf=Hb,Xf=Bb,Zf=Wb,La=Kb,Qf=jb,Na=Nh,Q=null,mi=H({},[...Ah,...ha,...fa,...pa,...Rh]),J=null,vi=H({},[...Ch,...ga,...Lh,...li]),qe=Object.seal(rn(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ln=null,Da=null,lt=Object.seal(rn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Pa=!0,yi=!0,Ia=!1,Ma=!0,ut=!1,vt=!0,yt=!1,wi=!1,Hn=null,Bn=null,bi=!1,Gt=!1,Wn=!1,Kn=!1,Ga=!0,Fa=!1,Oa="user-content-",xi=!0,_i=!1,Ft={},Ot=null,za=H({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","selectedcontent","style","svg","template","thead","title","video","xmp"]),$a=null,Ua=H({},["audio","video","img","source","image","track"]),Ha=null,Ba=H({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Vn="http://www.w3.org/1998/Math/MathML",jn="http://www.w3.org/2000/svg",Ye="http://www.w3.org/1999/xhtml",zt=Ye,ki=!1,Ei=null,Jf=H({},[Vn,jn,Ye],da),Wa=de(["mi","mo","mn","ms","mtext"]),Si=H({},Wa),Ka=de(["annotation-xml"]),Ti=H({},Ka),ep=H({},["title","style","font","a","script"]),un=null,tp=["application/xhtml+xml","text/html"],np="text/html",ie=null,$t=null,rp=n.createElement("form"),Va=function(p){return p instanceof RegExp||p instanceof Function},Ai=function(){let p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if($t&&$t===p)return;(!p||typeof p!="object")&&(p={}),p=Ne(p),un=tp.indexOf(p.PARSER_MEDIA_TYPE)===-1?np:p.PARSER_MEDIA_TYPE,ie=un==="application/xhtml+xml"?da:On,Q=mt(p,"ALLOWED_TAGS",mi,{transform:ie}),J=mt(p,"ALLOWED_ATTR",vi,{transform:ie}),Ei=mt(p,"ALLOWED_NAMESPACES",Jf,{transform:da}),Ha=mt(p,"ADD_URI_SAFE_ATTR",Ba,{transform:ie,base:Ba}),$a=mt(p,"ADD_DATA_URI_TAGS",Ua,{transform:ie,base:Ua}),Ot=mt(p,"FORBID_CONTENTS",za,{transform:ie}),ln=mt(p,"FORBID_TAGS",Ne({}),{transform:ie}),Da=mt(p,"FORBID_ATTR",Ne({}),{transform:ie}),Ft=Te(p,"USE_PROFILES")?p.USE_PROFILES&&typeof p.USE_PROFILES=="object"?Ne(p.USE_PROFILES):p.USE_PROFILES:!1,Pa=p.ALLOW_ARIA_ATTR!==!1,yi=p.ALLOW_DATA_ATTR!==!1,Ia=p.ALLOW_UNKNOWN_PROTOCOLS||!1,Ma=p.ALLOW_SELF_CLOSE_IN_ATTR!==!1,ut=p.SAFE_FOR_TEMPLATES||!1,vt=p.SAFE_FOR_XML!==!1,yt=p.WHOLE_DOCUMENT||!1,Gt=p.RETURN_DOM||!1,Wn=p.RETURN_DOM_FRAGMENT||!1,Kn=p.RETURN_TRUSTED_TYPE||!1,bi=p.FORCE_BODY||!1,Ga=p.SANITIZE_DOM!==!1,Fa=p.SANITIZE_NAMED_PROPS||!1,xi=p.KEEP_CONTENT!==!1,_i=p.IN_PLACE||!1,Na=Gb(p.ALLOWED_URI_REGEXP)?p.ALLOWED_URI_REGEXP:Nh,zt=typeof p.NAMESPACE=="string"?p.NAMESPACE:Ye,Si=ma(p,"MATHML_TEXT_INTEGRATION_POINTS",()=>H({},Wa)),Ti=ma(p,"HTML_INTEGRATION_POINTS",()=>H({},Ka));let x=ma(p,"CUSTOM_ELEMENT_HANDLING",()=>rn(null));if(qe=rn(null),Te(x,"tagNameCheck")&&Va(x.tagNameCheck)&&(qe.tagNameCheck=x.tagNameCheck),Te(x,"attributeNameCheck")&&Va(x.attributeNameCheck)&&(qe.attributeNameCheck=x.attributeNameCheck),Te(x,"allowCustomizedBuiltInElements")&&typeof x.allowCustomizedBuiltInElements=="boolean"&&(qe.allowCustomizedBuiltInElements=x.allowCustomizedBuiltInElements),pe(qe),ut&&(yi=!1),Wn&&(Gt=!0),Ft&&(Q=H({},Rh),J=rn(null),Ft.html===!0&&(H(Q,Ah),H(J,Ch)),Ft.svg===!0&&(H(Q,ha),H(J,ga),H(J,li)),Ft.svgFilters===!0&&(H(Q,fa),H(J,ga),H(J,li)),Ft.mathMl===!0&&(H(Q,pa),H(J,Lh),H(J,li))),lt.tagCheck=null,lt.attributeCheck=null,Te(p,"ADD_TAGS")&&(typeof p.ADD_TAGS=="function"?lt.tagCheck=p.ADD_TAGS:on(p.ADD_TAGS)&&(Q===mi&&(Q=Ne(Q)),H(Q,p.ADD_TAGS,ie))),Te(p,"ADD_ATTR")&&(typeof p.ADD_ATTR=="function"?lt.attributeCheck=p.ADD_ATTR:on(p.ADD_ATTR)&&(J===vi&&(J=Ne(J)),H(J,p.ADD_ATTR,ie))),Te(p,"ADD_FORBID_CONTENTS")&&on(p.ADD_FORBID_CONTENTS)&&(Ot===za&&(Ot=Ne(Ot)),H(Ot,p.ADD_FORBID_CONTENTS,ie)),xi&&(Q["#text"]=!0),yt&&H(Q,["html","head","body"]),Q.table&&(H(Q,["tbody"]),delete ln.tbody),p.TRUSTED_TYPES_POLICY){if(typeof p.TRUSTED_TYPES_POLICY.createHTML!="function")throw Pt('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof p.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Pt('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');let E=S;S=p.TRUSTED_TYPES_POLICY;try{D=he("")}catch(P){throw S=E,P}}else p.TRUSTED_TYPES_POLICY===null?(S=void 0,D=""):(S===void 0&&(S=Mt()),S&&typeof D=="string"&&(D=he("")));de&&de(p),$t=p},ja=H({},[...ha,...fa,...Fb]),qa=H({},[...pa,...Ob]),ip=function(p,x,E){return x.namespaceURI===Ye?p==="svg":x.namespaceURI===Vn?p==="svg"&&(E==="annotation-xml"||Si[E]):!!ja[p]},op=function(p,x,E){return x.namespaceURI===Ye?p==="math":x.namespaceURI===jn?p==="math"&&Ti[E]:!!qa[p]},ap=function(p,x,E){return x.namespaceURI===jn&&!Ti[E]||x.namespaceURI===Vn&&!Si[E]?!1:!qa[p]&&(ep[p]||!ja[p])},sp=function(p){let x=w(p);(!x||!x.tagName)&&(x={namespaceURI:zt,tagName:"template"});let E=On(p.tagName),P=On(x.tagName);return Ei[p.namespaceURI]?p.namespaceURI===jn?ip(E,x,P):p.namespaceURI===Vn?op(E,x,P):p.namespaceURI===Ye?ap(E,x,P):!!(un==="application/xhtml+xml"&&Ei[p.namespaceURI]):!1},ct=function(p){Mn(e.removed,{element:p});try{w(p).removeChild(p)}catch{if(v(p),!w(p))throw Pt("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place")}},Ya=function(p,x,E){try{p.removeAttributeNode(x)}catch{try{p.removeAttribute(E)}catch{}}},qn=function(p){Yn(p);let x=g(p);if(x){let P=[];It(x,F=>{Mn(P,F)}),It(P,F=>{try{v(F)}catch{}})}let E=_(p);if(E)for(let P=E.length-1;P>=0;--P){let F=E[P],z=F&&F.name;typeof z=="string"&&Ya(p,F,z)}},wt=function(p,x,E){if(!E)try{E=x.getAttributeNode(p)}catch{E=null}Mn(e.removed,{attribute:E||null,from:x});try{E?x.removeAttributeNode(E):x.removeAttribute(p)}catch{try{x.removeAttribute(p)}catch{}}if(p==="is")if(Gt||Wn)try{ct(x)}catch{}else try{x.setAttribute(p,"")}catch{}},lp=function(p){let x=_(p);if(x)for(let E=x.length-1;E>=0;--E){let P=x[E],F=P&&P.name;typeof F!="string"||J[ie(F)]||Ya(p,P,F)}},Yn=function(p){let x=[p];for(;x.length>0;){let E=x.pop();M(E)===Le.element&&lp(E);let F=g(E);if(F)for(let z=F.length-1;z>=0;--z)x.push(F[z])}},Xa=function(p,x){return vt?p==="patchsrc"?!0:p==="for"&&x!=="label"&&x!=="output":!1},up=function(p){if(!vt)return;let x=[p];for(;x.length>0;){let E=x.pop(),P=M(E);if(P===Le.processingInstruction||P===Le.comment&&we(Ph,E.data)){try{v(E)}catch{}continue}if(P===Le.element){let z=E,Z=ie(L(E));try{z.hasAttribute&&z.hasAttribute("patchsrc")&&z.removeAttribute("patchsrc"),z.hasAttribute&&z.hasAttribute("for")&&Xa("for",Z)&&z.removeAttribute("for")}catch{}}let F=g(E);if(F)for(let z=F.length-1;z>=0;--z)x.push(F[z])}},Za=function(p){let x=null,E=null;if(bi)p="<remove></remove>"+p;else{let z=kh(p,/^[\r\n\t ]+/);E=z&&z[0]}un==="application/xhtml+xml"&&zt===Ye&&(p='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+p+"</body></html>");let P=S?he(p):p;if(zt===Ye)try{x=new c().parseFromString(P,un)}catch{}if(!x||!x.documentElement){x=Oe.createDocument(zt,"template",null);try{x.documentElement.innerHTML=ki?D:P}catch{}}let F=x.body||x.documentElement;return p&&E&&F.insertBefore(n.createTextNode(E),F.childNodes[0]||null),zt===Ye?an.call(x,yt?"html":"body")[0]:yt?x.documentElement:F},Qa=function(p){let x=R?R(p):p.ownerDocument;return ze.call(x||p,p,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},Xn=function(p){return p=Gn(p,sn," "),p=Gn(p,jf," "),p=Gn(p,qf," "),p},Ri=function(p){var x;p.normalize();let E=R?R(p):p.ownerDocument,P=ze.call(E||p,p,l.SHOW_TEXT|l.SHOW_COMMENT|l.SHOW_CDATA_SECTION|l.SHOW_PROCESSING_INSTRUCTION,null),F=P.nextNode();for(;F;)F.data=Xn(F.data),F=P.nextNode();let z=(x=p.querySelectorAll)===null||x===void 0?void 0:x.call(p,"template");z&&It(z,Z=>{Ut(Z.content)&&Ri(Z.content)})},Zn=function(p){let x=A?A(p):null;return typeof x!="string"||ie(x)!=="form"?!1:typeof p.nodeName!="string"||typeof p.textContent!="string"||typeof p.removeChild!="function"||p.attributes!==_(p)||typeof p.removeAttribute!="function"||typeof p.setAttribute!="function"||typeof p.namespaceURI!="string"||typeof p.insertBefore!="function"||typeof p.hasChildNodes!="function"||p.nodeType!==k(p)||p.childNodes!==g(p)},Ut=function(p){if(!k||typeof p!="object"||p===null)return!1;try{return k(p)===Le.documentFragment}catch{return!1}},cn=function(p){if(!k||typeof p!="object"||p===null)return!1;try{return typeof k(p)=="number"}catch{return!1}};function Xe(C,p,x){C.length!==0&&It(C,E=>{E.call(e,p,x,$t)})}let cp=function(p,x){return!!(vt&&p.hasChildNodes()&&!cn(p.firstElementChild)&&we(Dh,p.textContent)&&we(Dh,p.innerHTML)||vt&&p.namespaceURI===Ye&&Xb[x]&&(cn(p.firstElementChild)||typeof p.textContent=="string"&&we(Zb[x],p.textContent))||p.nodeType===Le.processingInstruction||vt&&p.nodeType===Le.comment&&we(Ph,p.data))},Qn=function(p,x){if(p instanceof RegExp)return we(p,x);if(p instanceof Function){for(var E=arguments.length,P=new Array(E>2?E-2:0),F=2;F<E;F++)P[F-2]=arguments[F];return!!p(x,...P)}return!1},dp=function(p,x,E){if(!ln[x]&&rs(x)&&Qn(qe.tagNameCheck,x))return!1;if(xi&&!Ot[x]){let P=w(p),F=g(p);if(F&&P){let z=F.length;for(let Z=z-1;Z>=0;--Z){let ne=p===E?f(F[Z],!0):F[Z];P.insertBefore(ne,m(p))}}}return ct(p),!0},Ja=function(p,x,E,P){return p.length===0?x:x===E||x===P?Ne(x):x},es=function(p,x){return p===x||w(p)!==null?!1:(_i&&Yn(p),!0)},ts=function(p,x){if(Xe(X.beforeSanitizeElements,p,null),es(p,x))return!0;if(Zn(p))return ct(p),!0;let E=ie(L(p));if(Q=Ja(X.uponSanitizeElement,Q,mi,Hn),Xe(X.uponSanitizeElement,p,{tagName:E,allowedTags:Q}),es(p,x))return!0;if(cp(p,E))return ct(p),!0;if(ln[E]||!(lt.tagCheck instanceof Function&&lt.tagCheck(E))&&!Q[E]){let F=dp(p,E,x);return F===!1&&Xe(X.afterSanitizeElements,p,null),F}if(M(p)===Le.element&&!sp(p)||(E==="noscript"||E==="noembed"||E==="noframes")&&we(qb,p.innerHTML))return ct(p),!0;if(ut&&p.nodeType===Le.text){let F=Xn(p.textContent);p.textContent!==F&&(Mn(e.removed,{element:p.cloneNode()}),p.textContent=F)}return Xe(X.afterSanitizeElements,p,null),!1},ns=function(p,x,E){if(Da[x]||Xa(x,p)||Ga&&(x==="id"||x==="name")&&(E in n||E in rp))return!1;let P=J[x]||lt.attributeCheck instanceof Function&&lt.attributeCheck(x,p);return yi&&we(Yf,x)||Pa&&we(Xf,x)?!0:P?Ha[x]||we(Na,Gn(E,La,""))||(x==="src"||x==="xlink:href"||x==="href")&&p!=="script"&&Eh(E,"data:")===0&&$a[p]||Ia&&!we(Zf,Gn(E,La,""))?!0:!E:rs(p)&&Qn(qe.tagNameCheck,p)&&Qn(qe.attributeNameCheck,x,p)||x==="is"&&qe.allowCustomizedBuiltInElements&&Qn(qe.tagNameCheck,E)},hp=H({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),rs=function(p){return!hp[On(p)]&&we(Qf,p)},fp=function(p,x,E,P){if(S&&typeof h=="object"&&typeof h.getAttributeType=="function"&&!E)switch(h.getAttributeType(p,x)){case"TrustedHTML":return he(P);case"TrustedScriptURL":return Ve(P)}return P},pp=function(p,x,E,P){try{E?p.setAttributeNS(E,x,P):p.setAttribute(x,P),Zn(p)?ct(p):_h(e.removed)}catch{wt(x,p)}},is=function(p){Xe(X.beforeSanitizeAttributes,p,null);let x=p.attributes;if(!x||Zn(p))return;J=Ja(X.uponSanitizeAttribute,J,vi,Bn);let E={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:J,forceKeepAttr:void 0},P=x.length,F=ie(p.nodeName);for(;P--;){let z=x[P],Z=z.name,ne=z.namespaceURI,Ee=z.value,Se=ie(Z),Li=Ee,be=Z==="value"?Li:Lb(Li);if(E.attrName=Se,E.attrValue=be,E.keepAttr=!0,E.forceKeepAttr=void 0,Xe(X.uponSanitizeAttribute,p,E),be=E.attrValue,Fa&&(Se==="id"||Se==="name")&&Eh(be,Oa)!==0&&(wt(Z,p,z),be=Oa+be),vt&&we(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,be)){wt(Z,p,z);continue}if(Se==="attributename"&&kh(be,"href")){wt(Z,p,z);continue}if(!E.forceKeepAttr){if(!E.keepAttr){wt(Z,p,z);continue}if(!Ma&&we(Yb,be)){wt(Z,p,z);continue}if(ut&&(be=Xn(be)),!ns(F,Se,be)){wt(Z,p,z);continue}be=fp(F,Se,ne,be),be!==Li&&pp(p,Z,ne,be)}}Xe(X.afterSanitizeAttributes,p,null)},Jn=function(p){let x=null,E=Qa(p);for(Xe(X.beforeSanitizeShadowDOM,p,null);x=E.nextNode();)if(Xe(X.uponSanitizeShadowNode,x,null),ts(x,p),is(x),Ut(x.content)&&Jn(x.content),M(x)===Le.element){let P=y(x);Ut(P)&&(Ci(P),Jn(P))}Xe(X.afterSanitizeShadowDOM,p,null)},Ci=function(p){let x=[{node:p,shadow:null}];for(;x.length>0;){let E=x.pop();if(E.shadow){Jn(E.shadow);continue}let P=E.node,z=M(P)===Le.element,Z=g(P);if(Z)for(let ne=Z.length-1;ne>=0;--ne)x.push({node:Z[ne],shadow:null});if(z){let ne=A?A(P):null;if(typeof ne=="string"&&ie(ne)==="template"){let Ee=P.content;Ut(Ee)&&x.push({node:Ee,shadow:null})}}if(z){let ne=y(P);Ut(ne)&&x.push({node:null,shadow:ne},{node:ne,shadow:null})}}};return e.sanitize=function(C){let p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},x=null,E=null,P=null,F=null;if(ki=!C,ki&&(C="<!-->"),typeof C!="string"&&!cn(C)&&(C=Mb(C),typeof C!="string"))throw Pt("dirty is not a string, aborting");if(!e.isSupported)return C;wi?(Q=Hn,J=Bn):Ai(p),(X.uponSanitizeElement.length>0||X.uponSanitizeAttribute.length>0)&&(Q=Ne(Q)),X.uponSanitizeAttribute.length>0&&(J=Ne(J)),e.removed=[];let z=_i&&typeof C!="string"&&cn(C);if(z){up(C);let Ee=L(C);if(typeof Ee=="string"){let Se=ie(Ee);if(!Q[Se]||ln[Se])throw qn(C),Pt("root node is forbidden and cannot be sanitized in-place")}if(Zn(C))throw qn(C),Pt("root node is clobbered and cannot be sanitized in-place");try{Ci(C)}catch(Se){throw qn(C),Se}}else if(cn(C))x=Za("<!---->"),E=x.ownerDocument.importNode(C,!0),E.nodeType===Le.element&&E.nodeName==="BODY"||E.nodeName==="HTML"?x=E:x.appendChild(E),Ci(E);else{if(!Gt&&!ut&&!yt&&C.indexOf("<")===-1)return S&&Kn?he(C):C;if(x=Za(C),!x)return Gt?null:Kn?D:""}x&&bi&&ct(x.firstChild);let Z=z?C:x;try{let Ee=Qa(Z);for(;P=Ee.nextNode();)ts(P,Z),is(P),Ut(P.content)&&Jn(P.content)}catch(Ee){throw z&&(qn(C),It(e.removed,Se=>{Se.element&&Yn(Se.element)})),Ee}if(z)return It(e.removed,Ee=>{Ee.element&&Yn(Ee.element)}),ut&&Ri(C),C;if(Gt){if(ut&&Ri(x),Wn)for(F=je.call(x.ownerDocument);x.firstChild;)F.appendChild(x.firstChild);else F=x;return(J.shadowroot||J.shadowrootmode)&&(F=De.call(r,F,!0)),F}let ne=yt?x.outerHTML:x.innerHTML;return yt&&Q["!doctype"]&&x.ownerDocument&&x.ownerDocument.doctype&&x.ownerDocument.doctype.name&&we(Vb,x.ownerDocument.doctype.name)&&(ne="<!DOCTYPE "+x.ownerDocument.doctype.name+`>
399
- `+ne),ut&&(ne=Xn(ne)),S&&Kn?he(ne):ne},e.setConfig=function(){let C=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ai(C),wi=!0,Hn=Q,Bn=J},e.clearConfig=function(){$t=null,wi=!1,Hn=null,Bn=null,S=$,D=""},e.isValidAttribute=function(C,p,x){$t||Ai({});let E=ie(C),P=ie(p);return ns(E,P,x)},e.addHook=function(C,p){typeof p=="function"&&Te(X,C)&&Mn(X[C],p)},e.removeHook=function(C,p){if(Te(X,C)){if(p!==void 0){let x=Rb(X[C],p);return x===-1?void 0:Cb(X[C],x,1)[0]}return _h(X[C])}},e.removeHooks=function(C){Te(X,C)&&(X[C]=[])},e.removeAllHooks=function(){X=Ih()},e}var zh=Oh();var ex="weave-preview-x",tx="weave-preview-y";function nx({view:t,open:e,editing:n,saving:r,onDone:i,onSave:o}){return b("header",{class:"weave-note-head",children:[b("h3",{class:"weave-note-title",children:t.title}),b("p",{class:"weave-note-meta",children:[n?b(Ae,{children:[b("button",{type:"button",class:"weave-note-save",disabled:r,onClick:o,children:r?Hu:Uu}),b("button",{type:"button",class:"weave-note-edit",onClick:i,children:$u})]}):null,b("button",{type:"button",class:"weave-note-open",title:"Open in $EDITOR","aria-label":"Open in $EDITOR",onClick:e,children:b("span",{class:"weave-note-open-mark","aria-hidden":"true",children:"↗"})}),b("span",{class:`weave-prov weave-prov-${t.provenance}`,title:t.provenanceTitle,children:[t.provenanceGlyph," ",t.provenance]}),b("span",{class:"weave-note-time",title:t.updatedIso,children:[Ou," ",t.updated]}),b("span",{class:"weave-note-time",title:t.createdIso,children:[zu," ",t.created]})]}),b("p",{class:"weave-note-tags",children:t.tags.map(a=>b("span",{class:"weave-tag",children:Yu(a)},a))})]})}function $h(t){let e=t.note?.note??null,n=Du(t.graph,t.selectedId),r=Ju(t.selectedId,e),i=Ze(()=>e===null?null:Pu(t.graph,e.slug),[e,t.graph]),o=Ze(()=>e===null||i===null?"":Mu(zh,e.body,i),[e,i]),[a,s]=B(Pr),l=L=>{s(S=>Qu(S,L))},u=V(null),c=V(null),[h,d]=B(null),[f,v]=B(!1),m=e!==null&&h!==null&&Wu(h,e.body),g=V(0),w=V(h);w.current=h,t.editor.current={dirty:()=>m,discard:()=>y()},ee(()=>()=>{t.editor.current=null},[t.editor]);let y=()=>{g.current+=1,d(null),v(!1)},_=L=>{g.current+=1,d(L)},k=async()=>{if(e===null||h===null||f)return;let L=g.current,S=h;v(!0);let D=await t.onSave(e.slug,S);Vu(L,g.current)&&(!D||ju(S,w.current)?v(!1):y())},A=()=>{e!==null&&(h===null?_(e.body):(!m||window.confirm(Ir))&&y())},R=a.anchor===null?null:Xu(t.graph,a.anchor);if(kt(()=>{l({type:"hide"}),y()},[e===null?null:e.slug]),kt(()=>{let L=u.current;if(L!==null){let $=a.anchor?.slug??null;for(let W of L.querySelectorAll(`a[${rt}]`))$!==null&&W.getAttribute(rt)===$?W.setAttribute("aria-describedby",Do):W.removeAttribute("aria-describedby")}let S=c.current;if(S===null||R===null)return;let D=Zu(a.pointerX,a.pointerY,S.offsetWidth,S.offsetHeight,window.innerWidth,window.innerHeight);S.style.setProperty(`--${ex}`,`${D.x}px`),S.style.setProperty(`--${tx}`,`${D.y}px`)},[a,R]),n!==null){let L=t.graph?.model.nodes.find($=>$.id===t.selectedId),S=L?.label??n,D=L===void 0?n:Nu(L)??n;return b("article",{class:"weave-note weave-note-artifact",children:[b("header",{class:"weave-note-head",children:[b("h3",{class:"weave-note-title",children:S}),b("p",{class:"weave-note-meta",children:b("span",{class:"weave-note-time",children:n})})]}),b("iframe",{class:"weave-artifact-frame",title:S,sandbox:"allow-scripts",src:`/api/artifact/${encodeURIComponent(n)}`},D)]},D)}if(e===null||i===null)return b("p",{class:"weave-note-empty",children:r});let M=qu(e,t.now);return b("article",{class:`weave-note weave-note-${M.provenance}`,children:[b(nx,{view:M,open:()=>t.onOpen(e.slug),editing:h!==null,saving:f,onDone:A,onSave:()=>{k()}}),h!==null?b("textarea",{class:"weave-note-editor","aria-label":Bu,spellcheck:!0,value:h,onInput:L=>d(L.target.value),onKeyDown:L=>{if(L.key==="Escape"){L.stopPropagation(),A();return}L.key.toLowerCase()!=="s"||!(L.metaKey||L.ctrlKey)||(L.preventDefault(),k())}}):b("div",{ref:u,class:"weave-note-body",tabIndex:-1,onMouseOver:L=>{let S=Po(L.target);l(S!==null?{type:"show",anchor:S,x:L.clientX,y:L.clientY}:{type:"hide"})},onMouseLeave:()=>l({type:"hide"}),onFocus:L=>{let S=Po(L.target);if(S===null)return;let D=L.target.getBoundingClientRect?.();l({type:"show",anchor:S,x:D?.left??0,y:D?.bottom??0})},onBlur:()=>l({type:"hide"}),onClick:L=>{let S=typeof window<"u"&&typeof window.getSelection=="function"?window.getSelection():null,D=No(L.target),$=Ku(Fu(S),D);$==="navigate"&&D!==null?t.onSelect(D):$==="edit"&&_(e.body)},onKeyDown:L=>{if(L.key==="Escape"&&a.anchor!==null){L.stopPropagation(),l({type:"dismiss"});return}if(L.key!=="Enter"&&L.key!==" ")return;let S=No(L.target);L.preventDefault(),S!==null?t.onSelect(S):_(e.body)},dangerouslySetInnerHTML:{__html:o}}),R===null?null:b("div",{ref:c,id:Do,role:"tooltip",class:`weave-preview${R.ghost?" weave-preview-ghost":""}`,children:[b("span",{class:"weave-preview-kind",children:R.kind}),b("span",{class:"weave-preview-title",children:R.title}),R.text===""?null:b("p",{class:"weave-preview-text",children:R.text})]})]},e.slug)}var zn=["tree","note","graph"],wa={tree:180,note:320,graph:260},Bh={tree:.22,note:.46,graph:.32},rx=1100,ix=800;function Wh(t){return!Number.isFinite(t)||t<ix?"narrow":t<rx?"medium":"wide"}function Uh(t){return t==="wide"?zn:t==="medium"?["tree","note"]:["note"]}function Kh(t,e,n){let r={tree:0,note:0,graph:0},i=0;for(let l of t){let u=e[l];r[l]=Number.isFinite(u)&&u>0?u:Bh[l],i+=r[l]}for(let l of t)r[l]/=i;let o=0,a=0,s={tree:!1,note:!1,graph:!1};for(let l of t){let u=n[l];r[l]<u?(o+=u-r[l],r[l]=u,s[l]=!0):a+=r[l]-u}if(o>0&&a>0){let l=Math.min(o,a)/a;for(let u of t)s[u]||(r[u]-=(r[u]-n[u])*l)}return{tree:r.tree,note:r.note,graph:r.graph}}function Vh(t,e){return Kh(zn,t,e)}function xa(t){let e=Number.isFinite(t)&&t>0?t:1,n={tree:wa.tree/e,note:wa.note/e,graph:wa.graph/e},r=n.tree+n.note+n.graph;if(r<=.9)return n;let i=.9/r;return{tree:n.tree*i,note:n.note*i,graph:n.graph*i}}function jh(t,e){return{fractions:Vh(t,xa(e))}}function Hh(t){return jh(Bh,t)}function qh(t,e,n){let r=Number.isFinite(e)&&e>0?e:0,i=Kh(Uh(n),t.fractions,xa(r));return Uh(n).map(o=>({id:o,width:i[o]*r}))}function ox(t){return t==="tree"?["tree","note"]:["note","graph"]}function _a(t,e,n,r){let i=Number.isFinite(r)&&r>0?r:0;if(i===0||!Number.isFinite(n)||n===0)return t;let[o,a]=ox(e),s=xa(i),l=Math.max(-Math.max(0,t.fractions[o]-s[o]),Math.min(Math.max(0,t.fractions[a]-s[a]),n/i));return l===0?t:{fractions:Vh({...t.fractions,[o]:t.fractions[o]+l,[a]:t.fractions[a]-l},s)}}var Yh="pi-weave.layout.v1",ba=t=>Math.round(t*1e4)/1e4;function ax(t){return JSON.stringify({v:1,tree:ba(t.fractions.tree),note:ba(t.fractions.note),graph:ba(t.fractions.graph)})}function sx(t,e){if(t===null)return null;let n;try{n=JSON.parse(t)}catch{return null}if(typeof n!="object"||n===null||Array.isArray(n))return null;let r=n;if(r.v!==1)return null;let i={};for(let o of zn){let a=r[o];if(typeof a!="number"||!Number.isFinite(a)||a<=0)return null;i[o]=a}return jh(i,e)}function Xh(t,e){try{return sx(t.getItem(Yh),e)??Hh(e)}catch{return Hh(e)}}function Zh(t,e){try{return t.setItem(Yh,ax(e)),!0}catch{return!1}}var lx={notes:0,repo:null,nodes:0},ux=["note"];function Qh(t){if(t===null)return lx;let e=t.model.nodes;return{notes:e.filter(n=>ux.includes(n.kind)).length,repo:t.model.staleness?.state??null,nodes:e.length}}function cx(t){return t===null||t==="missing"?"unindexed":t}function Jh(t){return[`vault:${t.notes}`,`repo:${cx(t.repo)}`,`${t.nodes} nodes`]}var dx={tree:{title:"Tree"},note:{title:"Note"},graph:{title:"Graph"}};function ef(t){return dx[t]}var ka={title:"Context"},tf="—";function nf(t,e,n){return{cwd:t===""?tf:t,selection:e??"nothing selected",stamp:n}}function rf(t){return t===null?tf:/T(\d{2}:\d{2}:\d{2})/.exec(t)?.[1]??t}var of=["M21 12a9 9 0 1 1-2.64-6.36","M21 3v6h-6"],af=6e4,sf="Search…";function Ea(t){return t?"⌘K":"Ctrl K"}function lf(t){return`Search notes and repository (${t})`}function Sa(t){return/mac|iphone|ipad/i.test(t)}var hx={k:{type:"openSearch"}},uf={1:"tree",2:"note",3:"graph"},fx=new Set(["tree","graph"]);function px(t){return t.ctrl!==t.meta&&!t.alt&&!t.shift}function gx(t){return!t.ctrl&&!t.meta&&!t.alt}var mx={"/":{type:"filterTree"},g:{type:"fitGraph"},"?":{type:"openHelp"},t:{type:"cycleTheme"}};function cf(t,e){if(e.overlay!==null)return t.key==="Escape"?{type:"closeOverlay"}:null;if(px(t)){let n=hx[t.key.toLowerCase()];if(n!==void 0)return n;let r=uf[t.key];return r===void 0?null:{type:"focusColumn",column:r}}return t.key==="Escape"?e.hasSelection?{type:"clearSelection"}:null:!gx(t)||t.typing?null:mx[t.key]??null}var vx=["INPUT","TEXTAREA","SELECT"];function Ta(t,e){return e?!0:t!==null&&vx.includes(t.toUpperCase())}function df(t){return{key:t.key,ctrl:t.ctrlKey,meta:t.metaKey,shift:t.shiftKey,alt:t.altKey,typing:Ta(t.target?.tagName??null,t.target?.isContentEditable===!0)}}var yx={tree:".weave-col-tree .weave-rows",note:".weave-col-note .weave-note-body",graph:".weave-col-graph .weave-graph-canvas"},wx=".weave-col-tree .weave-filter";function bx(t){let e=t;return typeof e?.focus=="function"?e:null}function hf(t,e){let n=bx(t.querySelector(e));return n===null?!1:(n.focus(),!0)}function ff(t,e){switch(t.type){case"openSearch":return e.setOverlay("search");case"openHelp":return e.setOverlay("help");case"closeOverlay":return e.setOverlay(null);case"focusColumn":return void e.focusSelector(yx[t.column]);case"filterTree":return void e.focusSelector(wx);case"fitGraph":return e.fitGraph();case"clearSelection":return e.clearSelection();case"cycleTheme":return e.cycleTheme()}}function pf(t){return[{title:"Global",entries:[{combo:`${t}K`,what:"Search notes and the repository"},...Object.entries(uf).map(([e,n])=>({combo:`${t}${e}`,what:`Focus the ${n} column${fx.has(n)?" (when on screen)":""}`})),{combo:"?",what:"This help"},{combo:"t",what:"Cycle the colour theme (system / light / dark)"},{combo:"Esc",what:"Clear the selection, or close an overlay"}]},{title:"Tree",entries:[{combo:"/",what:"Filter the tree"},{combo:"j / ↓",what:"Next row"},{combo:"k / ↑",what:"Previous row"},{combo:"→",what:"Expand, or step into"},{combo:"←",what:"Collapse, or step out"},{combo:"Home / End",what:"First / last row"}]},{title:"Graph",entries:[{combo:"g",what:"Fit the whole graph"}]},{title:"Search",entries:[{combo:"↑ / ↓",what:"Move through results"},{combo:"↵",what:"Open the highlighted result"},{combo:"Esc",what:"Close the palette"}]}]}var Aa="Keyboard shortcuts",gf="esc close";var mf={chevron:{d:["M5.75 4.25 9.5 8l-3.75 3.75"],filled:!1},vault:{d:["M8 2.6 13.4 8 8 13.4 2.6 8Z"],filled:!0},note:{d:["M4.5 2.75h4.75l2.25 2.25v8.25h-7Z","M9.25 2.75V5h2.25"],filled:!1},repository:{d:["M2.75 4.25h10.5v7.5H2.75Z","M2.75 6.75h10.5"],filled:!1},module:{d:["M2.75 4.25h4l1.5 1.75h5v5.75h-10.5Z"],filled:!1},package:{d:["M8 2.5 13.25 5v6L8 13.5 2.75 11V5Z","M2.75 5 8 7.5 13.25 5","M8 7.5v6"],filled:!1},entryPoint:{d:["M5.75 3.75v8.5L12.75 8Z"],filled:!0},gitState:{d:["M8 2.85 13.15 8 8 13.15 2.85 8Z"],filled:!1},external:{d:["M4.5 11.5l7-7","M6.75 4.5h4.75v4.75"],filled:!1},file:{d:["M4.5 2.75h7v10.5h-7Z"],filled:!1}};function $n({name:t,class:e}){let n=mf[t];return b("svg",{class:e,width:16,height:16,viewBox:`0 0 ${16} ${16}`,fill:n.filled?"currentColor":"none",stroke:n.filled?void 0:"currentColor","stroke-width":n.filled?void 0:n.width??1.5,"stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:n.d.map(r=>b("path",{d:r}))})}function _x({view:t,recentIds:e,edit:n,onEdit:r,onRename:i,onSelect:o,onToggle:a,onMenu:s,onDrop:l}){let u=Ro(t.id);return b("li",{id:t.domId,"data-row-id":t.id,class:`weave-row weave-row-${t.kind}${t.selected?" weave-row-on":""}${e.has(t.id)?" weave-row-new":""}`,role:"treeitem","aria-level":t.level,"aria-posinset":t.posinset,"aria-setsize":t.setsize,"aria-selected":t.selected,"aria-expanded":t.hasKids?t.expanded:void 0,style:mu(t.depth),onClick:o,draggable:t.id.startsWith("note:"),"aria-label":t.id===jt?"New folder":void 0,onDragStart:c=>c.dataTransfer?.setData("text/plain",t.id),onDragOver:u===void 0?void 0:c=>c.preventDefault(),onDrop:u===void 0?void 0:c=>{c.preventDefault(),l(c.dataTransfer?.getData("text/plain")??"")},onContextMenu:c=>{c.preventDefault(),c.stopPropagation(),s(c.clientX,c.clientY)},children:[b("span",{class:"weave-twisty","aria-hidden":"true",onClick:c=>{c.stopPropagation(),a()},children:t.hasKids?b($n,{name:"chevron",class:t.expanded?"weave-icon weave-icon-open":"weave-icon"}):null}),b("span",{class:"weave-kind","aria-hidden":"true",children:b($n,{name:t.kindIcon,class:"weave-icon"})}),b("span",{class:`weave-prov weave-prov-${t.provenance??"none"}`,title:t.provenanceTitle,children:t.provenanceGlyph}),n===null?b("span",{class:"weave-label",children:t.label}):b(kx,{value:n,draft:t.id===jt,onEdit:r,onCommit:i}),b("span",{class:"weave-meta",children:t.meta})]})}function kx({value:t,draft:e,onEdit:n,onCommit:r}){let i=V(null);return kt(()=>{let o=i.current;o!==null&&(o.focus(),o.select())},[]),b("input",{ref:i,class:"weave-tree-rename",value:t,placeholder:e?"New folder name…":void 0,onClick:o=>o.stopPropagation(),onInput:o=>n(o.currentTarget.value),onBlur:o=>r(o.currentTarget.value),onKeyDown:o=>{o.stopPropagation(),o.key==="Enter"?o.currentTarget.blur():o.key==="Escape"&&r(null)}})}function vf(t){let[e,n]=B(ru),[r,i]=B(null),[o,a]=B(null),[s,l]=B(null),u=su(iu(t.graph,e),s),c=Eu(t.graph,u,e),h=async(m,g)=>{let w=await m;if(!w.ok)window.alert(w.message);else{let y=w.data.id??g;y!==void 0&&t.onSelect(y),t.onRefresh()}},d=async m=>{if(r===null)return;let g=En(r.id);if(i(null),g!==null){if(m==="newFolder"){let w=ou(g);w!==""&&n(y=>Ao(y,`vfolder:${w}`)),l(w),a({id:jt,label:"",value:""})}else if(m==="rename")a({id:r.id,label:r.label,value:r.label});else if(g.type!=="vault"){if(Lr(t.selectedId,g)&&!t.onMutate())return;await h(g.type==="note"?Pl(Pe,g.path):Gl(Pe,g.path),Lr(t.selectedId,g)?"vault":void 0)}}},f=m=>{if(r!==null){if(Co(m)&&r.armed!==!0){i({...r,armed:!0});return}d("delete")}},v=m=>{let g=o,w=s;if(a(null),l(null),g===null)return;let y=m?.trim();if(g.id===jt){let k=w===null||!y?null:au(w,y);k!==null&&h(Il(Pe,k));return}let _=En(g.id);if(_!==null&&y&&y!==g.label){if(Lr(t.selectedId,_)&&!t.onMutate())return;h(_.type==="note"?Nl(Pe,_.path,y):Ml(Pe,_.path,y))}};return b("div",{class:"weave-tree",onKeyDown:m=>{let g=m.target,w=hu(u,e,t.selectedId,m.key,Ta(g?.tagName??null,g?.isContentEditable===!0));w.handled&&(m.preventDefault(),n(w.state),w.selectedId!==null&&t.onSelect(w.selectedId))},children:[b("div",{class:"weave-tree-controls",children:[b("input",{type:"search",class:"weave-filter",value:e.query,placeholder:bu,"aria-label":_u,title:ku,onInput:m=>n(uu(e,m.currentTarget.value))}),b("button",{type:"button",class:"weave-chip",title:vu(e.provFilter),onClick:()=>n(cu(e)),children:["◧ ",Cr(e.provFilter)]}),b("button",{type:"button",class:"weave-chip",title:wu(e.showInternals),onClick:()=>n(du(e)),children:["◧ ",yu(e.showInternals)]})]}),c===null?b("ul",{class:"weave-rows",role:"tree",tabIndex:0,"aria-label":xu,"aria-activedescendant":gu(u,t.selectedId)??void 0,onContextMenu:m=>{m.preventDefault(),i({id:"vault",label:"Vault",x:m.clientX,y:m.clientY})},children:pu(u,t.selectedId,t.now).map(m=>b(_x,{view:m,recentIds:t.recentIds,edit:o?.id===m.id?o.value:null,onEdit:g=>a(w=>w===null?null:{...w,value:g}),onRename:v,onSelect:()=>{t.onSelect(m.id),m.hasKids&&n(g=>To(g,m.id))},onToggle:()=>n(To(e,m.id)),onMenu:(g,w)=>i({id:m.id,label:m.label,x:g,y:w}),onDrop:g=>{let w=Ro(m.id);if(g.startsWith("note:")&&w!==void 0){if(g===t.selectedId&&!t.onMutate())return;h(Dl(Pe,g.slice(5),w))}}},m.id))}):b("p",{class:"weave-tree-empty",children:c}),b("p",{class:"weave-tree-count",children:Su(u)}),r!==null&&En(r.id)!==null?(()=>{let m=En(r.id);return b(Ae,{children:[b("button",{type:"button",class:"weave-menu-backdrop","aria-label":"Close context menu",onClick:()=>i(null)}),b("div",{class:"weave-menu",role:"menu",style:{left:`${r.x}px`,top:`${r.y}px`},children:[b("button",{type:"button",role:"menuitem",onClick:()=>{d("newFolder")},children:"New folder…"}),m.type!=="vault"?b(Ae,{children:[b("button",{type:"button",role:"menuitem",onClick:()=>{d("rename")},children:"Rename…"}),b("button",{type:"button",role:"menuitem",class:"weave-menu-danger",onClick:()=>f(m),children:lu(m,r.label,r.armed===!0)})]}):null]})]})})():null]})}var Un={links:"LINKS",backlinks:"BACKLINKS",tags:"TAGS",mentions:"MENTIONS"};function di(t,e,n){return{id:t,target:e.id,label:Re(e),kind:e.kind,kindIcon:Lo(e.kind),provenance:e.provenance,provenanceGlyph:Ct(e.provenance),provenanceTitle:qt(e.provenance),selected:e.id===n}}function Ex(t,e,n){let r=t.target;if(r===void 0)return null;let i=e.get(r);return i===void 0?null:di(t.id,i,n)}function Sx(t){let e=new Map;for(let n of t.nodes)e.set(n.id,n);return e}var Tx=["link:links-to:"];function Ax(t){return Tx.some(e=>t.id.startsWith(e))}function Rx(t){return t.id.startsWith("link:mentions:")}function Cx(t,e,n,r){let i=[];for(let[o,a]of Object.entries(t.tags)){if(!a.includes(e))continue;let s=[];for(let l of a){if(l===e)continue;let u=n.get(`note:${l}`);u!==void 0&&s.push(di(`tag:${o}:${l}`,u,r))}i.push({tag:o,count:a.length,siblings:s})}return i}function Lx(t,e,n,r){let i=[];for(let o of t.edges){if(o.kind!=="mentions"||o.target!==e)continue;let a=n.get(o.source);a!==void 0&&i.push(di(`mentioned-by:${o.source}`,a,r))}return i}function Nx(t){if(!t.startsWith("note:"))return null;let e=t.slice(5);return e===""?null:e}var ci={loading:"Loading…",noSelection:"Select anything to see what it connects to.",unknown:"This node is not in the current graph.",isolated:"Nothing links to or from this yet."};function Ra(t){return{subject:null,groups:[],tags:[],tagsCount:0,empty:t}}function yf(t,e){if(t===null)return Ra(ci.loading);if(e===null)return Ra(ci.noSelection);let n=Rt(t),r=_o(n,e);if(r===null)return Ra(ci.unknown);let i=Sx(n),o=[],a=(h,d)=>{d.length>0&&o.push({heading:h,count:d.length,rows:d})},s=h=>h.map(d=>Ex(d,i,e)).filter(d=>d!==null);a(Un.links,s(r.links.filter(Ax)));let l=ko(n.edges).get(e)??[];a(Un.backlinks,l.map(h=>i.get(h)).filter(h=>h!==void 0).map(h=>di(`backlink:${h.id}`,h,e))),a(Un.mentions,[...s(r.links.filter(Rx)),...Lx(n,e,i,e)]);let u=Nx(e),c=u===null?[]:Cx(t,u,i,e);return o.length===0&&c.length===0?{subject:r.label,groups:[],tags:[],tagsCount:0,empty:ci.isolated}:{subject:r.label,groups:o,tags:c,tagsCount:c.length,empty:null}}function wf(){return{open:new Set,closed:new Set}}var Dx=8;function bf(t,e,n,r){return r?!1:t.closed.has(e)?!0:t.open.has(e)?!1:n>Dx}function Px(t){return t.some(e=>e.selected)}function xf(t,e){let n=bf(e,t.heading,t.count,Px(t.rows));return{heading:t.heading,count:t.count,collapsed:n,rows:n?[]:t.rows}}function _f(t,e){let n=bf(e,Un.tags,t.length,t.some(r=>r.siblings.some(i=>i.selected)));return{heading:Un.tags,count:t.length,collapsed:n,rows:[]}}function kf(t,e,n){let r=new Set(t.open),i=new Set(t.closed);return n?(r.add(e),i.delete(e)):(i.add(e),r.delete(e)),{open:r,closed:i}}function hi(t){return`weave-ctx-panel-${t.toLowerCase()}`}function Ef({row:t,onSelect:e}){return b("li",{class:`weave-ctx-row${t.selected?" weave-row-on":""}`,children:b("button",{type:"button",class:"weave-ctx-link",onClick:e,children:[b("span",{class:"weave-kind","aria-hidden":"true",children:b($n,{name:t.kindIcon,class:"weave-icon"})}),b("span",{class:`weave-prov weave-prov-${t.provenance??"none"}`,title:t.provenanceTitle,children:t.provenanceGlyph}),b("span",{class:"weave-label",children:t.label})]})})}function Sf({view:t,onToggle:e}){return b("h4",{class:"weave-ctx-head",children:b("button",{type:"button",class:"weave-ctx-heading","aria-expanded":!t.collapsed,"aria-controls":hi(t.heading),onClick:e,children:[b("span",{class:"weave-ctx-chevron","aria-hidden":"true",children:b($n,{name:"chevron",class:t.collapsed?"weave-icon":"weave-icon weave-icon-open"})}),t.heading,b("span",{class:"weave-ctx-count",children:t.count})]})})}function Ix({view:t,onSelect:e,onToggle:n}){return b("section",{class:"weave-ctx-group",children:[b(Sf,{view:t,onToggle:n}),b("ul",{class:"weave-ctx-rows",id:hi(t.heading),hidden:t.collapsed,children:t.rows.map(r=>b(Ef,{row:r,onSelect:()=>e(r.target)},r.id))})]})}function Mx({tag:t,onSelect:e}){return b("li",{class:"weave-ctx-tag",children:[b("span",{class:"weave-tag",children:["#",t.tag]}),b("ul",{class:"weave-ctx-rows",children:t.siblings.map(n=>b(Ef,{row:n,onSelect:()=>e(n.target)},n.id))})]})}function Tf(t){let e=yf(t.graph,t.selectedId),[n,r]=B(wf),i=a=>()=>r(kf(n,a.heading,a.collapsed)),o=_f(e.tags,n);return b("div",{class:"weave-rail","aria-label":ka.title,children:[b("h2",{class:"weave-col-title",children:ka.title}),e.empty===null?null:b("p",{class:"weave-ctx-empty",children:e.empty}),e.groups.map(a=>{let s=xf(a,n);return b(Ix,{view:s,onSelect:t.onSelect,onToggle:i(s)},a.heading)}),e.tags.length===0?null:b("section",{class:"weave-ctx-group",children:[b(Sf,{view:o,onToggle:i(o)}),b("ul",{class:"weave-ctx-tags",id:hi(o.heading),hidden:o.collapsed,children:e.tags.map(a=>b(Mx,{tag:a,onSelect:t.onSelect},a.tag))})]})]})}function Af(t){return b("div",{class:"weave-divider",role:"separator","aria-orientation":"vertical","aria-label":t.label,tabIndex:0,onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),t.onDown(e.clientX)},onPointerMove:e=>t.onMove(e.clientX),onPointerUp:e=>{e.currentTarget.releasePointerCapture(e.pointerId),t.onUp()},onKeyDown:e=>t.onKey(e.key)})}function Gx({id:t,props:e}){let n=ef(t);return b("section",{class:`weave-col weave-col-${t}`,"aria-label":n.title,children:[b("h2",{class:"weave-col-title",children:n.title}),t==="tree"?b(vf,{graph:e.graph,selectedId:e.selectedId,recentIds:e.recentIds,onSelect:e.onSelect,onMutate:e.onMutate,onRefresh:e.onRefresh,now:e.now}):null,t==="note"?b($h,{note:e.note,graph:e.graph,selectedId:e.selectedId,onSelect:e.onSelect,now:e.now,onOpen:e.onOpen,onSave:e.onSave,editor:e.editor}):null,t==="graph"?b(wh,{graph:e.graph,selectedId:e.selectedId,onSelect:e.onSelect,renderer:e.renderer,storage:e.storage,host:e.host,scheme:e.scheme,bootFailed:e.bootFailed,fit:e.fit,tuner:e.tuner}):null,t==="graph"?b(Tf,{graph:e.graph,selectedId:e.selectedId,onSelect:e.onSelect}):null]})}function Rf(t){let e=V(null);return kt(()=>{let n=e.current;if(n!==null)for(let{id:r,width:i}of t.resolved)n.style.setProperty(`--weave-col-${r}`,`${Math.round(i)}px`)},[t.resolved]),b("div",{class:"weave-grid",ref:e,"data-columns":t.resolved.length,children:t.resolved.map((n,r)=>{let i=r<t.resolved.length-1&&n.id!=="graph"?n.id:null;return[b(Gx,{id:n.id,props:t},`${n.id}-column`),i===null?null:b(Af,{label:`Resize ${n.id} column`,onDown:o=>t.onDown(i,o),onMove:t.onMove,onUp:t.onUp,onKey:o=>t.onKey(i,o)},`${n.id}-divider`)]})})}function Fx(t){if(t===""||t==="#")return null;let e=t.slice(1),n=/^note[/:](.+)$/.exec(e);return n===null?null:`note:${n[1]}`}function Cf(t,e){let n=Fx(t);return n===null||e===null?null:e.model.nodes.some(r=>r.id===n)?n:null}function Lf(t){let e=t===null?null:t.startsWith("note:")?t.slice(5):null;return e===null||e===""?"":`#note/${e}`}function Ox(t,e,n){return{divider:t,origin:e,base:n}}function zx(t,e,n){return _a(t.base,t.divider,e-t.origin,n)}function $x(t,e){return zn.some(n=>t.base.fractions[n]!==e.fractions[n])}var Nf=24;function Ux(t){return t==="ArrowLeft"?-Nf:t==="ArrowRight"?Nf:0}function Df(t){let e=null;return{onDown(n,r){e=Ox(n,r,t.layout())},onMove(n){e!==null&&t.setLayout(zx(e,n,t.width()))},onUp(){let n=e;e=null,n!==null&&$x(n,t.layout())&&t.persist(t.layout())},onKey(n,r){let i=_a(t.layout(),n,Ux(r),t.width());i!==t.layout()&&(t.setLayout(i),t.persist(i))}}}var Pf="image/png",If="iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAMKADAAQAAAABAAAAMAAAAADbN2wMAAALxElEQVRoBe1ZCXCU1R3/f+d+u5s9sleyOUlICBAMkQQQgpqBKqAoFQZFEYwWUAShjsco7dg4njRtPQcoXhSxWMGCimIYj1QqeICAcoQrd0iy2c1+u/vdZ9+m0xnFVCKw0+kMb+fb7/vevnnv//v/f//jvQVIYWtsbCn47uTJ3BQuAXgqJzdRM9CVyjVSCkACCUBIpfgAZCqnl5D8GJ5aBCm1ACALiGIqVZRqC7AIAGApRZBSCiUUBVN14/8YAJfAdN1MKU1TagEuwWEgp1T+1EYhRVUMhdNSmgdSagFeEHVJU/RUOkFKAThIWknLZNRUAkhFjKPSg2Muszocl/i8/mLT1M1IpO/rCBvaK/cePXGhwVxAANacYEHlkmEjymeguFNKUhShaToYhgG6rgJuAifL4oHjpxo3xdu/fAkBuSCWuSAAPNljLsvPH/lCusdfSVlIkFUFVCS0CQYkazkMuTGJEUAQJMrMEkTD3TvaWg/dJUab2s7XIsT5TkA6Cifl5434sCCvqEAS4sBzMdAVFdxYOjgxF6ShD6VTkBCjoEkiEKYBAX9WsaGT0yKh8DsAYvx8ZDhPADnW4SXlr+XnDh0WY3tBlgQwDQ10UQe/NQgOygkexoe4E4WE0AdgIkohWskiD440t9/EKX+cbd36PwNgd+ffMyR/2GJZjoOmySAryfITAxNHQkoyiLLYT6U2thHRB0djNPSuAY4lnyVQVLlMEMm9utp3zs59XmnSmeaelmZzgq7KkIjHgY3FQFOUfs4HHYUgawLQuAVspgdZRgcFAWRZFlRFRmMMtJvCMIKiZpyPBX5WHnA4hvkom/N6VVc+T4S/bXU4XCUCokZSaJokUd3JIDBqP4CuWDMIegRaIhIQyIFV1A+GCXbG2n/XVR2NN4AkiYokAE+g4mqapsrZRHSzFDvWPFhQPweAy+HxfZQdLBgtSVxPs8I/gdji1ZA2RVEAl98D106fAjzPw57P9gAb7QQLZQHVjIOAAKYHAjCheiLgyOY7360HmZdQiNWSlilM95c9npeT9yBJMxS0Q013DMYiAPxgQAzaiTOyxt/rcqXPa2tvApLA0zCcmsrQFIVhBmaxW+DJVQ/BroZdEOrugoUL58LB/Y0gCRLKAQZk5GTA0uXz4Z2t28Fuo+GeZTWwc+enIAhC8nerlbFeoagScbqrA3wejx8j3L0C3/XFYAAMygfs9pIyl9O1MhYNQzzGrgj1hrZKsoYbhorzXByurL4Mwt2nYcNL68DvcUKWzwlFQ7OQU8ugagoMLciEHL8Lcd6Etc+sAcxQYEzFJSAl95zID+KcBD294Q2JRGI5G2fB5fI8YnGUlAwGwGAohNMMU4cWc/Sx7KuG2vI8x8Jawjpso81mmZNmRTRBcV9B/PbmFcNL6zfD9voGmFRZDiamIfEwiERZmHbDIojHBQgOLQBJ1UBE1jGQdRTN0AVBXGfIJ+9FAstRlqqgKOttDEU/JQPMRn0/Wc2elUIMkzGEsTlXJXi+XUzEb3K48m7Jy7/0EcOQFUXRhtusNN7dE4aJl08EX4YXWFGFkqJC6Go/jaKO0p+JNeSweYUFkOb3wby5M5AlLPD2W+8ix1ZAkuWEw2FrzM4tu0/RGUaMs8+aOH4NTuIVkkmvBzWe+ClLDFhK+EpmVyL1lbsN/vWOrhM3khbrBo7nZjot+JFA5tBGTdcJUeIhnuDAjixgtzKQGcyCEWWjkBNz0Hz8GIR6QuByu4GiCYhGYuAPeKFg2HCw0BQc2PsN9PR0I+2bIKJ84XQ60BwOFJFIs635cLEO5FCLzb5D4rnZdXJz/ZHPDyxDfNz38pTxn5wJ5kcWmANziGYf9iFGuhbqBN7Js20WXZY/MOSWjZnZZS/abday1o6WQ5KsHHc60rOCmQGcZaMgoeza2dIKXW0toMgyijYYTKwaC5mZGdDe2g4CL0BHczN0oOcYyhcySmrZwWyQUaWXiLEf83w84fP6gjhppWN9B59XJThlc1C23KorJkEw94+KwE+4IT+4tqGh4Qeb7IEsgPmLZ69EaX4egSmfUTR2imacR+OhZi7T5XqPZXvtPT1dNarUvKmoZFqb00ZmtnR2ogJOA4eVAgrlA5Ig+rmvo7LBRB+CJPqppOs6SMixeVRqoAgGOUE/RFi+tbNt9xAgcmbl5Q3ZYrenR4pmVNxUfvVUXzwSzVVwwq243NNNTd/46rSJz53pEwNFIbP3xNtP2OhEFYqRR2UdX6OqYjdtd47ri/bSmirL/iFF3ZfPucfNxkInBIEDK00jpcu7E6KcYHmUlUUZBFlFOcAE3cRAkDTgBBlinAhokxZFkekf6e505AIqJBJsY119faD6uqmGpkiapPE2f0awCJXeB8W+wPOuuNzl23tgChL+2TOFT9JpIADJfmj77v0oup2wEDCpff+bewvGD98IFBWxEDiDwsf9hM8/05WT2xxLJEyaJmm7le7ho9FxkswvS/Dc/dFY/LlonNvSF49vY+Pc6hifWIpC8Dw+dqrS7XIj7zaocJQ1Kqdc0YZJ9PRwT2QJCrOU2+8Jjysd/envp08+FtBbr8RVaF710J2xfqEG+PqRD3x/THG+rUU0PLPtROE39uyMcWxXVycKLZM5Nmoc++dbS1csvnnrRx/vxVE9M8GTkV3qyw6Ee1u/qtOVyB50fajJvZs1Ofw3XQl/sF2OfDtz6W29TYfaF1hp+0IBhdFYLPrI8f31D+x88y+H4qz2G4vV6qXtrqdLKyrJ2b+YcJITbTNDVGjTvu3bf8D778s4kA98/3fIKps1BjOpsa5AuuXIod2vOBStHsXpqr6+SHX1pJrPWaqlINTW8QeU1aZnlZdR+eUlvyU0vY1kLCRptZiMg0F1EkHjBBgUQVQ27W+8dt+2nXYbSW5cNOf2Y8hDTr++7a9MU1vTG2Coh2PRo1WPPrZ1kSpKhkbInz39WM2+Hwh0xstZE5nOmx2YlamPhGWtIOeSxlioqV6K81W+YPbdLN1ZihEWLm/kqId0XT7sLyzo0riEDyfpRlRRNxk4jRJcQiEMtLtXyOt0IHYXlA45Xgiz4tmZubvwU60tkjdQ6khzLZIVExsz8tK9117+6Aw9xDxoIWweTQmNOEPeH72eFYCVIXHJNATAqBzd0Ce7fJmbuGhjKaIRf2Bn9lqAWqNi8WIqXUhvf3/VijXXPFCbyTC2+QppYSinN6wIHI2Z2DTM1Hc4KAPFePygE7PLoUhk7JMvLD+GJPoGyLxWmmb+XpI36kFRkGehAtxiqFo3SgtnPZL5r078H6gthzd345g6iTbk0ThmNuMYE1S4ozWSzNYlhU+Oo7stowRePJ18/qCutnvT75bVaR5fjeTyf6va019WJellKsxyAqcH/jR/7sHTEaVN541MtF/+N4UJc7MiHJ8f8GVUaqZqSlhstAnRisdfXHDWsvqsFkgKdfrQm+3olrwOF1feOLdk4q23B4cVvdawvhZ1AaBN1nBTV79MPpfOqaXdQmQ838OC1euTUbncjHP4nSoeWGF09d2VHLNu3Z3C8kWruTvueMqHXntfe3hD56HOYzWKIsefeWUJOrFIHgMMrp3ViQeapqRqbiVOWyfjJLlTZZwdjMrfAgb/itXmrqJJy0gMx47rUmSXf/pV3m1Lbm655f4X51oY5zgqLh7Red5u8PoXhElngsnkY5i4h6TwaswkGla/sfTrgdb7qb5zApCcsKTqDlTAkLertPNhAsMkq5pYzxDYJ1+9v2bX9xe8fuHKDJr2/nLL6vv+nOxfsOBJryli1zFGcKWN8hbzemiLyLX/6o0dted0OnHOAJLClFy1LEvBiMMYQSgMSHUUgUcoEpOApFmaolkGw3UrYbuR0I3dhKoLlEGmo2LDhTb4HGV4J1Fgv17RYr9+ddvit5LznUs7LwDJBUurby1C1aPW2LC+pbT67jTKTfssFOFFB1lOdJSF6lSKoHCStSgGj0qkMNrDhN97r7b/j7M5U2s9m+tr0XnLxXZRAxc1cFEDFzVwUQPnpoF/AbqLsVZFbswxAAAAAElFTkSuQmCC";function Hx({onRefresh:t}){let[e,n]=B(!1);return b("button",{type:"button",class:"weave-refresh",onClick:()=>{t(),n(!0)},onAnimationEnd:()=>n(!1),title:"Refetch everything","aria-busy":e?"true":void 0,children:b("svg",{class:e?"weave-refresh-glyph weave-refresh-spinning":"weave-refresh-glyph",viewBox:"0 0 24 24",width:14,height:14,fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:of.map(r=>b("path",{d:r},r))})})}function Mf(t){return b("header",{class:"weave-header",children:[b("span",{class:"weave-brand",children:[b("img",{class:"weave-brand-mark",src:`data:${Pf};base64,${If}`,alt:"",width:18,height:18}),"pi-weave"]}),b("button",{type:"button",class:"weave-search",title:lf(t.shortcut),onClick:t.onSearch,children:[b("span",{class:"weave-search-text",children:sf}),b("kbd",{children:t.shortcut})]}),b("span",{class:"weave-summary",children:Jh(t.summary).map(e=>b("span",{class:"weave-summary-part",children:e},e))}),b("button",{type:"button",class:"weave-theme",onClick:t.onTheme,title:t.theme.hint,"aria-label":t.theme.hint,children:t.theme.glyph}),b(Hx,{onRefresh:t.onRefresh})]})}function Bx({group:t}){return b("div",{children:[b("p",{class:"weave-key-group",children:t.title}),t.entries.map(e=>b("div",{class:"weave-key-row",children:[b("kbd",{class:"weave-key-combo",children:e.combo}),b("span",{class:"weave-key-what",children:e.what})]},e.combo))]})}function Gf(t){let e=ii(),n=t.shortcut.slice(0,-1);return b("div",{class:"weave-scrim",onClick:t.onClose,children:b("div",{class:"weave-help",role:"dialog","aria-modal":"true","aria-label":Aa,tabIndex:-1,ref:e.ref,onClick:r=>r.stopPropagation(),onKeyDown:r=>{e.onKeyDown(r)},children:[b("h2",{class:"weave-help-title",children:Aa}),b("div",{class:"weave-keys",children:pf(n).map(r=>b(Bx,{group:r},r.title))}),b("p",{class:"weave-help-foot",children:[b("button",{type:"button",class:"weave-chip",onClick:t.onClose,children:"close"}),b("span",{class:"weave-help-hint",children:gf})]})]})})}function Ff(t,e){let n=r=>{let i=cf(df(r),e.context());i!==null&&(r.preventDefault(),e.run(i))};return t.addEventListener("keydown",n),()=>t.removeEventListener("keydown",n)}function Of({model:t}){return b("footer",{class:"weave-status",children:[b("span",{class:"weave-status-cwd",title:t.cwd,children:t.cwd}),b("span",{class:"weave-status-sel",title:"the §1.3 context bus — one signal, every column",children:t.selection}),b("span",{class:"weave-status-stamp",title:"data as of",children:rf(t.stamp)})]})}var Ca=["system","light","dark"],zf="pi-weave.theme.v1";function Wx(t){return t==="system"||t==="light"||t==="dark"}function fi(t){try{let e=t.getItem(zf);return Wx(e)?e:null}catch{return null}}function $f(t,e){try{return t.setItem(zf,e),!0}catch{return!1}}function pi(t){let e=Ca.indexOf(t);return Ca[(e+1)%Ca.length]??"system"}function Uf(t,e){return t==="system"?e:t}function gi(t){return t==="system"?null:t}var Kx={dark:"●",system:"◐",light:"○"};function Hf(t){return{glyph:Kx[t],hint:`Colour theme: ${t} — click for ${pi(t)}`}}function Vx(t){t===null?delete document.documentElement.dataset.weaveTheme:document.documentElement.dataset.weaveTheme=t}function Bf(t){let[e,n]=B(Zd),[r,i]=B(null),[o,a]=B(t.initialWidth),[s,l]=B(()=>Xh(localStorage,t.initialWidth)),[u,c]=B(()=>fi(localStorage)??"system"),[h,d]=B(()=>Mr(window)),f=V(null),v=V(null),m=V(null),g=()=>{let S=m.current;return S===null||!S.dirty()?!0:window.confirm(Ir)?(S.discard(),!0):!1},w=S=>{g()&&f.current?.select(S)},y=V({overlay:r,selectedId:e.selectedId,layout:s,width:o});y.current={overlay:r,selectedId:e.selectedId,layout:s,width:o},ee(()=>{let S=eh({fetch:Pe,state:e,setState:n});return f.current=S,()=>S.stop()},[]),ee(()=>{let S=()=>a(window.innerWidth);return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);let _=V(!1),k=V(location.hash);ee(()=>{_.current&&(Yd(localStorage,e.selectedId),history.replaceState(null,"",Lf(e.selectedId)))},[e.selectedId]),ee(()=>{if(_.current||e.graph===null||(_.current=!0,e.selectedId!==null))return;let S=Cf(k.current,e.graph);if(S!==null)f.current?.select(S);else{let D=Xd(e.graph,localStorage);D!==null&&f.current?.select(D)}},[e.graph]);let[A,R]=B(()=>Date.now());ee(()=>{let S=setInterval(()=>R(Date.now()),af);return()=>clearInterval(S)},[]),ee(()=>Vx(gi(u)),[u]),ee(()=>{$f(localStorage,u)},[u]),ee(()=>tc(window,d),[]),ee(()=>{let S=D=>{m.current?.dirty()===!0&&(D.preventDefault(),D.returnValue="")};return window.addEventListener("beforeunload",S),()=>window.removeEventListener("beforeunload",S)},[]),ee(()=>Ff(document,{context:()=>({overlay:y.current.overlay,hasSelection:y.current.selectedId!==null}),run:S=>ff(S,{setOverlay:i,focusSelector:D=>hf(document,D),fitGraph:()=>v.current?.(),clearSelection:()=>w(null),cycleTheme:()=>c(D=>pi(D))})}),[]);let M=Ze(()=>qh(s,o,Wh(o)),[s,o]),L=Ze(()=>Df({layout:()=>y.current.layout,width:()=>y.current.width,setLayout:l,persist:S=>{Zh(localStorage,S)}}),[]);return b(Ae,{children:[b(Mf,{summary:Qh(e.graph),shortcut:Ea(Sa(t.platform)),onRefresh:()=>f.current?.refresh(),onSearch:()=>i("search"),theme:Hf(u),onTheme:()=>c(S=>pi(S))}),b(Rf,{resolved:M,onDown:L.onDown,onMove:L.onMove,onUp:L.onUp,onKey:L.onKey,scheme:Uf(u,h),bootFailed:e.graphFailed,graph:e.graph,note:e.note,selectedId:e.selectedId,recentIds:e.recentIds,onSelect:w,onMutate:g,onRefresh:()=>f.current?.refresh(),onOpen:S=>{(async()=>{let D=await Cl(Pe,S);D.ok?D.data.opened||window.alert("could not open the note in an editor"):window.alert(D.message)})()},onSave:async(S,D)=>{let $=await Ll(Pe,S,D);return $.ok?(f.current?.refresh(),!0):(window.alert($.message),!1)},editor:m,now:A,renderer:Pd,storage:localStorage,host:window,fit:v,tuner:t.tuner===!0}),b(Of,{model:nf(t.cwd,e.selectedId,e.graph?.model.generatedAt??null)}),r==="search"?b(jd,{graph:e.graph,onSelect:w,onClose:()=>i(null),ports:{fetch:Pe}}):null,r==="help"?b(Gf,{shortcut:Ea(Sa(t.platform)),onClose:()=>i(null)}):null]})}var Wf=`
399
+ `+ne),ut&&(ne=Xn(ne)),S&&Kn?he(ne):ne},e.setConfig=function(){let C=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ai(C),wi=!0,Hn=Q,Bn=J},e.clearConfig=function(){$t=null,wi=!1,Hn=null,Bn=null,S=$,D=""},e.isValidAttribute=function(C,p,x){$t||Ai({});let E=ie(C),P=ie(p);return ns(E,P,x)},e.addHook=function(C,p){typeof p=="function"&&Te(X,C)&&Mn(X[C],p)},e.removeHook=function(C,p){if(Te(X,C)){if(p!==void 0){let x=Rb(X[C],p);return x===-1?void 0:Cb(X[C],x,1)[0]}return _h(X[C])}},e.removeHooks=function(C){Te(X,C)&&(X[C]=[])},e.removeAllHooks=function(){X=Ih()},e}var zh=Oh();var ex="weave-preview-x",tx="weave-preview-y";function nx({view:t,open:e,editing:n,saving:r,onDone:i,onSave:o}){return b("header",{class:"weave-note-head",children:[b("h3",{class:"weave-note-title",children:t.title}),b("p",{class:"weave-note-meta",children:[n?b(Ae,{children:[b("button",{type:"button",class:"weave-note-save",disabled:r,onClick:o,children:r?Hu:Uu}),b("button",{type:"button",class:"weave-note-edit",onClick:i,children:$u})]}):null,b("button",{type:"button",class:"weave-note-open",title:"Open in $EDITOR","aria-label":"Open in $EDITOR",onClick:e,children:b("span",{class:"weave-note-open-mark","aria-hidden":"true",children:"↗"})}),b("span",{class:`weave-prov weave-prov-${t.provenance}`,title:t.provenanceTitle,children:[t.provenanceGlyph," ",t.provenance]}),b("span",{class:"weave-note-time",title:t.updatedIso,children:[Ou," ",t.updated]}),b("span",{class:"weave-note-time",title:t.createdIso,children:[zu," ",t.created]})]}),b("p",{class:"weave-note-tags",children:t.tags.map(a=>b("span",{class:"weave-tag",children:Yu(a)},a))})]})}function $h(t){let e=t.note?.note??null,n=Du(t.graph,t.selectedId),r=Ju(t.selectedId,e,t.loadFailed),i=Ze(()=>e===null?null:Pu(t.graph,e.slug),[e,t.graph]),o=Ze(()=>e===null||i===null?"":Mu(zh,e.body,i),[e,i]),[a,s]=B(Pr),l=L=>{s(S=>Qu(S,L))},u=V(null),c=V(null),[h,d]=B(null),[f,v]=B(!1),m=e!==null&&h!==null&&Wu(h,e.body),g=V(0),w=V(h);w.current=h,t.editor.current={dirty:()=>m,discard:()=>y()},ee(()=>()=>{t.editor.current=null},[t.editor]);let y=()=>{g.current+=1,d(null),v(!1)},_=L=>{g.current+=1,d(L)},k=async()=>{if(e===null||h===null||f)return;let L=g.current,S=h;v(!0);let D=await t.onSave(e.slug,S);Vu(L,g.current)&&(!D||ju(S,w.current)?v(!1):y())},A=()=>{e!==null&&(h===null?_(e.body):(!m||window.confirm(Ir))&&y())},R=a.anchor===null?null:Xu(t.graph,a.anchor);if(kt(()=>{l({type:"hide"}),y()},[e===null?null:e.slug]),kt(()=>{let L=u.current;if(L!==null){let $=a.anchor?.slug??null;for(let W of L.querySelectorAll(`a[${rt}]`))$!==null&&W.getAttribute(rt)===$?W.setAttribute("aria-describedby",Do):W.removeAttribute("aria-describedby")}let S=c.current;if(S===null||R===null)return;let D=Zu(a.pointerX,a.pointerY,S.offsetWidth,S.offsetHeight,window.innerWidth,window.innerHeight);S.style.setProperty(`--${ex}`,`${D.x}px`),S.style.setProperty(`--${tx}`,`${D.y}px`)},[a,R]),n!==null){let L=t.graph?.model.nodes.find($=>$.id===t.selectedId),S=L?.label??n,D=L===void 0?n:Nu(L)??n;return b("article",{class:"weave-note weave-note-artifact",children:[b("header",{class:"weave-note-head",children:[b("h3",{class:"weave-note-title",children:S}),b("p",{class:"weave-note-meta",children:b("span",{class:"weave-note-time",children:n})})]}),b("iframe",{class:"weave-artifact-frame",title:S,sandbox:"allow-scripts",src:`/api/artifact/${encodeURIComponent(n)}`},D)]},D)}if(e===null||i===null)return b("p",{class:"weave-note-empty",children:r});let M=qu(e,t.now);return b("article",{class:`weave-note weave-note-${M.provenance}`,children:[b(nx,{view:M,open:()=>t.onOpen(e.slug),editing:h!==null,saving:f,onDone:A,onSave:()=>{k()}}),h!==null?b("textarea",{class:"weave-note-editor","aria-label":Bu,spellcheck:!0,value:h,onInput:L=>d(L.target.value),onKeyDown:L=>{if(L.key==="Escape"){L.stopPropagation(),A();return}L.key.toLowerCase()!=="s"||!(L.metaKey||L.ctrlKey)||(L.preventDefault(),k())}}):b("div",{ref:u,class:"weave-note-body",tabIndex:-1,onMouseOver:L=>{let S=Po(L.target);l(S!==null?{type:"show",anchor:S,x:L.clientX,y:L.clientY}:{type:"hide"})},onMouseLeave:()=>l({type:"hide"}),onFocus:L=>{let S=Po(L.target);if(S===null)return;let D=L.target.getBoundingClientRect?.();l({type:"show",anchor:S,x:D?.left??0,y:D?.bottom??0})},onBlur:()=>l({type:"hide"}),onClick:L=>{let S=typeof window<"u"&&typeof window.getSelection=="function"?window.getSelection():null,D=No(L.target),$=Ku(Fu(S),D);$==="navigate"&&D!==null?t.onSelect(D):$==="edit"&&_(e.body)},onKeyDown:L=>{if(L.key==="Escape"&&a.anchor!==null){L.stopPropagation(),l({type:"dismiss"});return}if(L.key!=="Enter"&&L.key!==" ")return;let S=No(L.target);L.preventDefault(),S!==null?t.onSelect(S):_(e.body)},dangerouslySetInnerHTML:{__html:o}}),R===null?null:b("div",{ref:c,id:Do,role:"tooltip",class:`weave-preview${R.ghost?" weave-preview-ghost":""}`,children:[b("span",{class:"weave-preview-kind",children:R.kind}),b("span",{class:"weave-preview-title",children:R.title}),R.text===""?null:b("p",{class:"weave-preview-text",children:R.text})]})]},e.slug)}var zn=["tree","note","graph"],wa={tree:180,note:320,graph:260},Bh={tree:.22,note:.46,graph:.32},rx=1100,ix=800;function Wh(t){return!Number.isFinite(t)||t<ix?"narrow":t<rx?"medium":"wide"}function Uh(t){return t==="wide"?zn:t==="medium"?["tree","note"]:["note"]}function Kh(t,e,n){let r={tree:0,note:0,graph:0},i=0;for(let l of t){let u=e[l];r[l]=Number.isFinite(u)&&u>0?u:Bh[l],i+=r[l]}for(let l of t)r[l]/=i;let o=0,a=0,s={tree:!1,note:!1,graph:!1};for(let l of t){let u=n[l];r[l]<u?(o+=u-r[l],r[l]=u,s[l]=!0):a+=r[l]-u}if(o>0&&a>0){let l=Math.min(o,a)/a;for(let u of t)s[u]||(r[u]-=(r[u]-n[u])*l)}return{tree:r.tree,note:r.note,graph:r.graph}}function Vh(t,e){return Kh(zn,t,e)}function xa(t){let e=Number.isFinite(t)&&t>0?t:1,n={tree:wa.tree/e,note:wa.note/e,graph:wa.graph/e},r=n.tree+n.note+n.graph;if(r<=.9)return n;let i=.9/r;return{tree:n.tree*i,note:n.note*i,graph:n.graph*i}}function jh(t,e){return{fractions:Vh(t,xa(e))}}function Hh(t){return jh(Bh,t)}function qh(t,e,n){let r=Number.isFinite(e)&&e>0?e:0,i=Kh(Uh(n),t.fractions,xa(r));return Uh(n).map(o=>({id:o,width:i[o]*r}))}function ox(t){return t==="tree"?["tree","note"]:["note","graph"]}function _a(t,e,n,r){let i=Number.isFinite(r)&&r>0?r:0;if(i===0||!Number.isFinite(n)||n===0)return t;let[o,a]=ox(e),s=xa(i),l=Math.max(-Math.max(0,t.fractions[o]-s[o]),Math.min(Math.max(0,t.fractions[a]-s[a]),n/i));return l===0?t:{fractions:Vh({...t.fractions,[o]:t.fractions[o]+l,[a]:t.fractions[a]-l},s)}}var Yh="pi-weave.layout.v1",ba=t=>Math.round(t*1e4)/1e4;function ax(t){return JSON.stringify({v:1,tree:ba(t.fractions.tree),note:ba(t.fractions.note),graph:ba(t.fractions.graph)})}function sx(t,e){if(t===null)return null;let n;try{n=JSON.parse(t)}catch{return null}if(typeof n!="object"||n===null||Array.isArray(n))return null;let r=n;if(r.v!==1)return null;let i={};for(let o of zn){let a=r[o];if(typeof a!="number"||!Number.isFinite(a)||a<=0)return null;i[o]=a}return jh(i,e)}function Xh(t,e){try{return sx(t.getItem(Yh),e)??Hh(e)}catch{return Hh(e)}}function Zh(t,e){try{return t.setItem(Yh,ax(e)),!0}catch{return!1}}var lx={notes:0,repo:null,nodes:0},ux=["note"];function Qh(t){if(t===null)return lx;let e=t.model.nodes;return{notes:e.filter(n=>ux.includes(n.kind)).length,repo:t.model.staleness?.state??null,nodes:e.length}}function cx(t){return t===null||t==="missing"?"unindexed":t}function Jh(t){return[`vault:${t.notes}`,`repo:${cx(t.repo)}`,`${t.nodes} nodes`]}var dx={tree:{title:"Tree"},note:{title:"Note"},graph:{title:"Graph"}};function ef(t){return dx[t]}var ka={title:"Context"},tf="—";function nf(t,e,n){return{cwd:t===""?tf:t,selection:e??"nothing selected",stamp:n}}function rf(t){return t===null?tf:/T(\d{2}:\d{2}:\d{2})/.exec(t)?.[1]??t}var of=["M21 12a9 9 0 1 1-2.64-6.36","M21 3v6h-6"],af=6e4,sf="Search…";function Ea(t){return t?"⌘K":"Ctrl K"}function lf(t){return`Search notes and repository (${t})`}function Sa(t){return/mac|iphone|ipad/i.test(t)}var hx={k:{type:"openSearch"}},uf={1:"tree",2:"note",3:"graph"},fx=new Set(["tree","graph"]);function px(t){return t.ctrl!==t.meta&&!t.alt&&!t.shift}function gx(t){return!t.ctrl&&!t.meta&&!t.alt}var mx={"/":{type:"filterTree"},g:{type:"fitGraph"},"?":{type:"openHelp"},t:{type:"cycleTheme"}};function cf(t,e){if(e.overlay!==null)return t.key==="Escape"?{type:"closeOverlay"}:null;if(px(t)){let n=hx[t.key.toLowerCase()];if(n!==void 0)return n;let r=uf[t.key];return r===void 0?null:{type:"focusColumn",column:r}}return t.key==="Escape"?e.hasSelection?{type:"clearSelection"}:null:!gx(t)||t.typing?null:mx[t.key]??null}var vx=["INPUT","TEXTAREA","SELECT"];function Ta(t,e){return e?!0:t!==null&&vx.includes(t.toUpperCase())}function df(t){return{key:t.key,ctrl:t.ctrlKey,meta:t.metaKey,shift:t.shiftKey,alt:t.altKey,typing:Ta(t.target?.tagName??null,t.target?.isContentEditable===!0)}}var yx={tree:".weave-col-tree .weave-rows",note:".weave-col-note .weave-note-body",graph:".weave-col-graph .weave-graph-canvas"},wx=".weave-col-tree .weave-filter";function bx(t){let e=t;return typeof e?.focus=="function"?e:null}function hf(t,e){let n=bx(t.querySelector(e));return n===null?!1:(n.focus(),!0)}function ff(t,e){switch(t.type){case"openSearch":return e.setOverlay("search");case"openHelp":return e.setOverlay("help");case"closeOverlay":return e.setOverlay(null);case"focusColumn":return void e.focusSelector(yx[t.column]);case"filterTree":return void e.focusSelector(wx);case"fitGraph":return e.fitGraph();case"clearSelection":return e.clearSelection();case"cycleTheme":return e.cycleTheme()}}function pf(t){return[{title:"Global",entries:[{combo:`${t}K`,what:"Search notes and the repository"},...Object.entries(uf).map(([e,n])=>({combo:`${t}${e}`,what:`Focus the ${n} column${fx.has(n)?" (when on screen)":""}`})),{combo:"?",what:"This help"},{combo:"t",what:"Cycle the colour theme (system / light / dark)"},{combo:"Esc",what:"Clear the selection, or close an overlay"}]},{title:"Tree",entries:[{combo:"/",what:"Filter the tree"},{combo:"j / ↓",what:"Next row"},{combo:"k / ↑",what:"Previous row"},{combo:"→",what:"Expand, or step into"},{combo:"←",what:"Collapse, or step out"},{combo:"Home / End",what:"First / last row"}]},{title:"Graph",entries:[{combo:"g",what:"Fit the whole graph"}]},{title:"Search",entries:[{combo:"↑ / ↓",what:"Move through results"},{combo:"↵",what:"Open the highlighted result"},{combo:"Esc",what:"Close the palette"}]}]}var Aa="Keyboard shortcuts",gf="esc close";var mf={chevron:{d:["M5.75 4.25 9.5 8l-3.75 3.75"],filled:!1},vault:{d:["M8 2.6 13.4 8 8 13.4 2.6 8Z"],filled:!0},note:{d:["M4.5 2.75h4.75l2.25 2.25v8.25h-7Z","M9.25 2.75V5h2.25"],filled:!1},repository:{d:["M2.75 4.25h10.5v7.5H2.75Z","M2.75 6.75h10.5"],filled:!1},module:{d:["M2.75 4.25h4l1.5 1.75h5v5.75h-10.5Z"],filled:!1},package:{d:["M8 2.5 13.25 5v6L8 13.5 2.75 11V5Z","M2.75 5 8 7.5 13.25 5","M8 7.5v6"],filled:!1},entryPoint:{d:["M5.75 3.75v8.5L12.75 8Z"],filled:!0},gitState:{d:["M8 2.85 13.15 8 8 13.15 2.85 8Z"],filled:!1},external:{d:["M4.5 11.5l7-7","M6.75 4.5h4.75v4.75"],filled:!1},file:{d:["M4.5 2.75h7v10.5h-7Z"],filled:!1}};function $n({name:t,class:e}){let n=mf[t];return b("svg",{class:e,width:16,height:16,viewBox:`0 0 ${16} ${16}`,fill:n.filled?"currentColor":"none",stroke:n.filled?void 0:"currentColor","stroke-width":n.filled?void 0:n.width??1.5,"stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:n.d.map(r=>b("path",{d:r}))})}function _x({view:t,recentIds:e,edit:n,onEdit:r,onRename:i,onSelect:o,onToggle:a,onMenu:s,onDrop:l}){let u=Ro(t.id);return b("li",{id:t.domId,"data-row-id":t.id,class:`weave-row weave-row-${t.kind}${t.selected?" weave-row-on":""}${e.has(t.id)?" weave-row-new":""}`,role:"treeitem","aria-level":t.level,"aria-posinset":t.posinset,"aria-setsize":t.setsize,"aria-selected":t.selected,"aria-expanded":t.hasKids?t.expanded:void 0,style:mu(t.depth),onClick:o,draggable:t.id.startsWith("note:"),"aria-label":t.id===jt?"New folder":void 0,onDragStart:c=>c.dataTransfer?.setData("text/plain",t.id),onDragOver:u===void 0?void 0:c=>c.preventDefault(),onDrop:u===void 0?void 0:c=>{c.preventDefault(),l(c.dataTransfer?.getData("text/plain")??"")},onContextMenu:c=>{c.preventDefault(),c.stopPropagation(),s(c.clientX,c.clientY)},children:[b("span",{class:"weave-twisty","aria-hidden":"true",onClick:c=>{c.stopPropagation(),a()},children:t.hasKids?b($n,{name:"chevron",class:t.expanded?"weave-icon weave-icon-open":"weave-icon"}):null}),b("span",{class:"weave-kind","aria-hidden":"true",children:b($n,{name:t.kindIcon,class:"weave-icon"})}),b("span",{class:`weave-prov weave-prov-${t.provenance??"none"}`,title:t.provenanceTitle,children:t.provenanceGlyph}),n===null?b("span",{class:"weave-label",children:t.label}):b(kx,{value:n,draft:t.id===jt,onEdit:r,onCommit:i}),b("span",{class:"weave-meta",children:t.meta})]})}function kx({value:t,draft:e,onEdit:n,onCommit:r}){let i=V(null);return kt(()=>{let o=i.current;o!==null&&(o.focus(),o.select())},[]),b("input",{ref:i,class:"weave-tree-rename",value:t,placeholder:e?"New folder name…":void 0,onClick:o=>o.stopPropagation(),onInput:o=>n(o.currentTarget.value),onBlur:o=>r(o.currentTarget.value),onKeyDown:o=>{o.stopPropagation(),o.key==="Enter"?o.currentTarget.blur():o.key==="Escape"&&r(null)}})}function vf(t){let[e,n]=B(ru),[r,i]=B(null),[o,a]=B(null),[s,l]=B(null),u=su(iu(t.graph,e),s),c=Eu(t.graph,u,e),h=async(m,g)=>{let w=await m;if(!w.ok)window.alert(w.message);else{let y=w.data.id??g;y!==void 0&&t.onSelect(y),t.onRefresh()}},d=async m=>{if(r===null)return;let g=En(r.id);if(i(null),g!==null){if(m==="newFolder"){let w=ou(g);w!==""&&n(y=>Ao(y,`vfolder:${w}`)),l(w),a({id:jt,label:"",value:""})}else if(m==="rename")a({id:r.id,label:r.label,value:r.label});else if(g.type!=="vault"){if(Lr(t.selectedId,g)&&!t.onMutate())return;await h(g.type==="note"?Pl(Pe,g.path):Gl(Pe,g.path),Lr(t.selectedId,g)?"vault":void 0)}}},f=m=>{if(r!==null){if(Co(m)&&r.armed!==!0){i({...r,armed:!0});return}d("delete")}},v=m=>{let g=o,w=s;if(a(null),l(null),g===null)return;let y=m?.trim();if(g.id===jt){let k=w===null||!y?null:au(w,y);k!==null&&h(Il(Pe,k));return}let _=En(g.id);if(_!==null&&y&&y!==g.label){if(Lr(t.selectedId,_)&&!t.onMutate())return;h(_.type==="note"?Nl(Pe,_.path,y):Ml(Pe,_.path,y))}};return b("div",{class:"weave-tree",onKeyDown:m=>{let g=m.target,w=hu(u,e,t.selectedId,m.key,Ta(g?.tagName??null,g?.isContentEditable===!0));w.handled&&(m.preventDefault(),n(w.state),w.selectedId!==null&&t.onSelect(w.selectedId))},children:[b("div",{class:"weave-tree-controls",children:[b("input",{type:"search",class:"weave-filter",value:e.query,placeholder:bu,"aria-label":_u,title:ku,onInput:m=>n(uu(e,m.currentTarget.value))}),b("button",{type:"button",class:"weave-chip",title:vu(e.provFilter),onClick:()=>n(cu(e)),children:["◧ ",Cr(e.provFilter)]}),b("button",{type:"button",class:"weave-chip",title:wu(e.showInternals),onClick:()=>n(du(e)),children:["◧ ",yu(e.showInternals)]})]}),c===null?b("ul",{class:"weave-rows",role:"tree",tabIndex:0,"aria-label":xu,"aria-activedescendant":gu(u,t.selectedId)??void 0,onContextMenu:m=>{m.preventDefault(),i({id:"vault",label:"Vault",x:m.clientX,y:m.clientY})},children:pu(u,t.selectedId,t.now).map(m=>b(_x,{view:m,recentIds:t.recentIds,edit:o?.id===m.id?o.value:null,onEdit:g=>a(w=>w===null?null:{...w,value:g}),onRename:v,onSelect:()=>{t.onSelect(m.id),m.hasKids&&n(g=>To(g,m.id))},onToggle:()=>n(To(e,m.id)),onMenu:(g,w)=>i({id:m.id,label:m.label,x:g,y:w}),onDrop:g=>{let w=Ro(m.id);if(g.startsWith("note:")&&w!==void 0){if(g===t.selectedId&&!t.onMutate())return;h(Dl(Pe,g.slice(5),w))}}},m.id))}):b("p",{class:"weave-tree-empty",children:c}),b("p",{class:"weave-tree-count",children:Su(u)}),r!==null&&En(r.id)!==null?(()=>{let m=En(r.id);return b(Ae,{children:[b("button",{type:"button",class:"weave-menu-backdrop","aria-label":"Close context menu",onClick:()=>i(null)}),b("div",{class:"weave-menu",role:"menu",style:{left:`${r.x}px`,top:`${r.y}px`},children:[b("button",{type:"button",role:"menuitem",onClick:()=>{d("newFolder")},children:"New folder…"}),m.type!=="vault"?b(Ae,{children:[b("button",{type:"button",role:"menuitem",onClick:()=>{d("rename")},children:"Rename…"}),b("button",{type:"button",role:"menuitem",class:"weave-menu-danger",onClick:()=>f(m),children:lu(m,r.label,r.armed===!0)})]}):null]})]})})():null]})}var Un={links:"LINKS",backlinks:"BACKLINKS",tags:"TAGS",mentions:"MENTIONS"};function di(t,e,n){return{id:t,target:e.id,label:Re(e),kind:e.kind,kindIcon:Lo(e.kind),provenance:e.provenance,provenanceGlyph:Ct(e.provenance),provenanceTitle:qt(e.provenance),selected:e.id===n}}function Ex(t,e,n){let r=t.target;if(r===void 0)return null;let i=e.get(r);return i===void 0?null:di(t.id,i,n)}function Sx(t){let e=new Map;for(let n of t.nodes)e.set(n.id,n);return e}var Tx=["link:links-to:"];function Ax(t){return Tx.some(e=>t.id.startsWith(e))}function Rx(t){return t.id.startsWith("link:mentions:")}function Cx(t,e,n,r){let i=[];for(let[o,a]of Object.entries(t.tags)){if(!a.includes(e))continue;let s=[];for(let l of a){if(l===e)continue;let u=n.get(`note:${l}`);u!==void 0&&s.push(di(`tag:${o}:${l}`,u,r))}i.push({tag:o,count:a.length,siblings:s})}return i}function Lx(t,e,n,r){let i=[];for(let o of t.edges){if(o.kind!=="mentions"||o.target!==e)continue;let a=n.get(o.source);a!==void 0&&i.push(di(`mentioned-by:${o.source}`,a,r))}return i}function Nx(t){if(!t.startsWith("note:"))return null;let e=t.slice(5);return e===""?null:e}var ci={loading:"Loading…",noSelection:"Select anything to see what it connects to.",unknown:"This node is not in the current graph.",isolated:"Nothing links to or from this yet."};function Ra(t){return{subject:null,groups:[],tags:[],tagsCount:0,empty:t}}function yf(t,e){if(t===null)return Ra(ci.loading);if(e===null)return Ra(ci.noSelection);let n=Rt(t),r=_o(n,e);if(r===null)return Ra(ci.unknown);let i=Sx(n),o=[],a=(h,d)=>{d.length>0&&o.push({heading:h,count:d.length,rows:d})},s=h=>h.map(d=>Ex(d,i,e)).filter(d=>d!==null);a(Un.links,s(r.links.filter(Ax)));let l=ko(n.edges).get(e)??[];a(Un.backlinks,l.map(h=>i.get(h)).filter(h=>h!==void 0).map(h=>di(`backlink:${h.id}`,h,e))),a(Un.mentions,[...s(r.links.filter(Rx)),...Lx(n,e,i,e)]);let u=Nx(e),c=u===null?[]:Cx(t,u,i,e);return o.length===0&&c.length===0?{subject:r.label,groups:[],tags:[],tagsCount:0,empty:ci.isolated}:{subject:r.label,groups:o,tags:c,tagsCount:c.length,empty:null}}function wf(){return{open:new Set,closed:new Set}}var Dx=8;function bf(t,e,n,r){return r?!1:t.closed.has(e)?!0:t.open.has(e)?!1:n>Dx}function Px(t){return t.some(e=>e.selected)}function xf(t,e){let n=bf(e,t.heading,t.count,Px(t.rows));return{heading:t.heading,count:t.count,collapsed:n,rows:n?[]:t.rows}}function _f(t,e){let n=bf(e,Un.tags,t.length,t.some(r=>r.siblings.some(i=>i.selected)));return{heading:Un.tags,count:t.length,collapsed:n,rows:[]}}function kf(t,e,n){let r=new Set(t.open),i=new Set(t.closed);return n?(r.add(e),i.delete(e)):(i.add(e),r.delete(e)),{open:r,closed:i}}function hi(t){return`weave-ctx-panel-${t.toLowerCase()}`}function Ef({row:t,onSelect:e}){return b("li",{class:`weave-ctx-row${t.selected?" weave-row-on":""}`,children:b("button",{type:"button",class:"weave-ctx-link",onClick:e,children:[b("span",{class:"weave-kind","aria-hidden":"true",children:b($n,{name:t.kindIcon,class:"weave-icon"})}),b("span",{class:`weave-prov weave-prov-${t.provenance??"none"}`,title:t.provenanceTitle,children:t.provenanceGlyph}),b("span",{class:"weave-label",children:t.label})]})})}function Sf({view:t,onToggle:e}){return b("h4",{class:"weave-ctx-head",children:b("button",{type:"button",class:"weave-ctx-heading","aria-expanded":!t.collapsed,"aria-controls":hi(t.heading),onClick:e,children:[b("span",{class:"weave-ctx-chevron","aria-hidden":"true",children:b($n,{name:"chevron",class:t.collapsed?"weave-icon":"weave-icon weave-icon-open"})}),t.heading,b("span",{class:"weave-ctx-count",children:t.count})]})})}function Ix({view:t,onSelect:e,onToggle:n}){return b("section",{class:"weave-ctx-group",children:[b(Sf,{view:t,onToggle:n}),b("ul",{class:"weave-ctx-rows",id:hi(t.heading),hidden:t.collapsed,children:t.rows.map(r=>b(Ef,{row:r,onSelect:()=>e(r.target)},r.id))})]})}function Mx({tag:t,onSelect:e}){return b("li",{class:"weave-ctx-tag",children:[b("span",{class:"weave-tag",children:["#",t.tag]}),b("ul",{class:"weave-ctx-rows",children:t.siblings.map(n=>b(Ef,{row:n,onSelect:()=>e(n.target)},n.id))})]})}function Tf(t){let e=yf(t.graph,t.selectedId),[n,r]=B(wf),i=a=>()=>r(kf(n,a.heading,a.collapsed)),o=_f(e.tags,n);return b("div",{class:"weave-rail","aria-label":ka.title,children:[b("h2",{class:"weave-col-title",children:ka.title}),e.empty===null?null:b("p",{class:"weave-ctx-empty",children:e.empty}),e.groups.map(a=>{let s=xf(a,n);return b(Ix,{view:s,onSelect:t.onSelect,onToggle:i(s)},a.heading)}),e.tags.length===0?null:b("section",{class:"weave-ctx-group",children:[b(Sf,{view:o,onToggle:i(o)}),b("ul",{class:"weave-ctx-tags",id:hi(o.heading),hidden:o.collapsed,children:e.tags.map(a=>b(Mx,{tag:a,onSelect:t.onSelect},a.tag))})]})]})}function Af(t){return b("div",{class:"weave-divider",role:"separator","aria-orientation":"vertical","aria-label":t.label,tabIndex:0,onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),t.onDown(e.clientX)},onPointerMove:e=>t.onMove(e.clientX),onPointerUp:e=>{e.currentTarget.releasePointerCapture(e.pointerId),t.onUp()},onKeyDown:e=>t.onKey(e.key)})}function Gx({id:t,props:e}){let n=ef(t);return b("section",{class:`weave-col weave-col-${t}`,"aria-label":n.title,children:[b("h2",{class:"weave-col-title",children:n.title}),t==="tree"?b(vf,{graph:e.graph,selectedId:e.selectedId,recentIds:e.recentIds,onSelect:e.onSelect,onMutate:e.onMutate,onRefresh:e.onRefresh,now:e.now}):null,t==="note"?b($h,{note:e.note,loadFailed:e.noteFailed,graph:e.graph,selectedId:e.selectedId,onSelect:e.onSelect,now:e.now,onOpen:e.onOpen,onSave:e.onSave,editor:e.editor}):null,t==="graph"?b(wh,{graph:e.graph,selectedId:e.selectedId,onSelect:e.onSelect,renderer:e.renderer,storage:e.storage,host:e.host,scheme:e.scheme,bootFailed:e.bootFailed,fit:e.fit,tuner:e.tuner}):null,t==="graph"?b(Tf,{graph:e.graph,selectedId:e.selectedId,onSelect:e.onSelect}):null]})}function Rf(t){let e=V(null);return kt(()=>{let n=e.current;if(n!==null)for(let{id:r,width:i}of t.resolved)n.style.setProperty(`--weave-col-${r}`,`${Math.round(i)}px`)},[t.resolved]),b("div",{class:"weave-grid",ref:e,"data-columns":t.resolved.length,children:t.resolved.map((n,r)=>{let i=r<t.resolved.length-1&&n.id!=="graph"?n.id:null;return[b(Gx,{id:n.id,props:t},`${n.id}-column`),i===null?null:b(Af,{label:`Resize ${n.id} column`,onDown:o=>t.onDown(i,o),onMove:t.onMove,onUp:t.onUp,onKey:o=>t.onKey(i,o)},`${n.id}-divider`)]})})}function Fx(t){if(t===""||t==="#")return null;let e=t.slice(1),n=/^note[/:](.+)$/.exec(e);return n===null?null:`note:${n[1]}`}function Cf(t,e){let n=Fx(t);return n===null||e===null?null:e.model.nodes.some(r=>r.id===n)?n:null}function Lf(t){let e=t===null?null:t.startsWith("note:")?t.slice(5):null;return e===null||e===""?"":`#note/${e}`}function Ox(t,e,n){return{divider:t,origin:e,base:n}}function zx(t,e,n){return _a(t.base,t.divider,e-t.origin,n)}function $x(t,e){return zn.some(n=>t.base.fractions[n]!==e.fractions[n])}var Nf=24;function Ux(t){return t==="ArrowLeft"?-Nf:t==="ArrowRight"?Nf:0}function Df(t){let e=null;return{onDown(n,r){e=Ox(n,r,t.layout())},onMove(n){e!==null&&t.setLayout(zx(e,n,t.width()))},onUp(){let n=e;e=null,n!==null&&$x(n,t.layout())&&t.persist(t.layout())},onKey(n,r){let i=_a(t.layout(),n,Ux(r),t.width());i!==t.layout()&&(t.setLayout(i),t.persist(i))}}}var Pf="image/png",If="iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAMKADAAQAAAABAAAAMAAAAADbN2wMAAALxElEQVRoBe1ZCXCU1R3/f+d+u5s9sleyOUlICBAMkQQQgpqBKqAoFQZFEYwWUAShjsco7dg4njRtPQcoXhSxWMGCimIYj1QqeICAcoQrd0iy2c1+u/vdZ9+m0xnFVCKw0+kMb+fb7/vevnnv//v/f//jvQVIYWtsbCn47uTJ3BQuAXgqJzdRM9CVyjVSCkACCUBIpfgAZCqnl5D8GJ5aBCm1ACALiGIqVZRqC7AIAGApRZBSCiUUBVN14/8YAJfAdN1MKU1TagEuwWEgp1T+1EYhRVUMhdNSmgdSagFeEHVJU/RUOkFKAThIWknLZNRUAkhFjKPSg2Muszocl/i8/mLT1M1IpO/rCBvaK/cePXGhwVxAANacYEHlkmEjymeguFNKUhShaToYhgG6rgJuAifL4oHjpxo3xdu/fAkBuSCWuSAAPNljLsvPH/lCusdfSVlIkFUFVCS0CQYkazkMuTGJEUAQJMrMEkTD3TvaWg/dJUab2s7XIsT5TkA6Cifl5434sCCvqEAS4sBzMdAVFdxYOjgxF6ShD6VTkBCjoEkiEKYBAX9WsaGT0yKh8DsAYvx8ZDhPADnW4SXlr+XnDh0WY3tBlgQwDQ10UQe/NQgOygkexoe4E4WE0AdgIkohWskiD440t9/EKX+cbd36PwNgd+ffMyR/2GJZjoOmySAryfITAxNHQkoyiLLYT6U2thHRB0djNPSuAY4lnyVQVLlMEMm9utp3zs59XmnSmeaelmZzgq7KkIjHgY3FQFOUfs4HHYUgawLQuAVspgdZRgcFAWRZFlRFRmMMtJvCMIKiZpyPBX5WHnA4hvkom/N6VVc+T4S/bXU4XCUCokZSaJokUd3JIDBqP4CuWDMIegRaIhIQyIFV1A+GCXbG2n/XVR2NN4AkiYokAE+g4mqapsrZRHSzFDvWPFhQPweAy+HxfZQdLBgtSVxPs8I/gdji1ZA2RVEAl98D106fAjzPw57P9gAb7QQLZQHVjIOAAKYHAjCheiLgyOY7360HmZdQiNWSlilM95c9npeT9yBJMxS0Q013DMYiAPxgQAzaiTOyxt/rcqXPa2tvApLA0zCcmsrQFIVhBmaxW+DJVQ/BroZdEOrugoUL58LB/Y0gCRLKAQZk5GTA0uXz4Z2t28Fuo+GeZTWwc+enIAhC8nerlbFeoagScbqrA3wejx8j3L0C3/XFYAAMygfs9pIyl9O1MhYNQzzGrgj1hrZKsoYbhorzXByurL4Mwt2nYcNL68DvcUKWzwlFQ7OQU8ugagoMLciEHL8Lcd6Etc+sAcxQYEzFJSAl95zID+KcBD294Q2JRGI5G2fB5fI8YnGUlAwGwGAohNMMU4cWc/Sx7KuG2vI8x8Jawjpso81mmZNmRTRBcV9B/PbmFcNL6zfD9voGmFRZDiamIfEwiERZmHbDIojHBQgOLQBJ1UBE1jGQdRTN0AVBXGfIJ+9FAstRlqqgKOttDEU/JQPMRn0/Wc2elUIMkzGEsTlXJXi+XUzEb3K48m7Jy7/0EcOQFUXRhtusNN7dE4aJl08EX4YXWFGFkqJC6Go/jaKO0p+JNeSweYUFkOb3wby5M5AlLPD2W+8ix1ZAkuWEw2FrzM4tu0/RGUaMs8+aOH4NTuIVkkmvBzWe+ClLDFhK+EpmVyL1lbsN/vWOrhM3khbrBo7nZjot+JFA5tBGTdcJUeIhnuDAjixgtzKQGcyCEWWjkBNz0Hz8GIR6QuByu4GiCYhGYuAPeKFg2HCw0BQc2PsN9PR0I+2bIKJ84XQ60BwOFJFIs635cLEO5FCLzb5D4rnZdXJz/ZHPDyxDfNz38pTxn5wJ5kcWmANziGYf9iFGuhbqBN7Js20WXZY/MOSWjZnZZS/abday1o6WQ5KsHHc60rOCmQGcZaMgoeza2dIKXW0toMgyijYYTKwaC5mZGdDe2g4CL0BHczN0oOcYyhcySmrZwWyQUaWXiLEf83w84fP6gjhppWN9B59XJThlc1C23KorJkEw94+KwE+4IT+4tqGh4Qeb7IEsgPmLZ69EaX4egSmfUTR2imacR+OhZi7T5XqPZXvtPT1dNarUvKmoZFqb00ZmtnR2ogJOA4eVAgrlA5Ig+rmvo7LBRB+CJPqppOs6SMixeVRqoAgGOUE/RFi+tbNt9xAgcmbl5Q3ZYrenR4pmVNxUfvVUXzwSzVVwwq243NNNTd/46rSJz53pEwNFIbP3xNtP2OhEFYqRR2UdX6OqYjdtd47ri/bSmirL/iFF3ZfPucfNxkInBIEDK00jpcu7E6KcYHmUlUUZBFlFOcAE3cRAkDTgBBlinAhokxZFkekf6e505AIqJBJsY119faD6uqmGpkiapPE2f0awCJXeB8W+wPOuuNzl23tgChL+2TOFT9JpIADJfmj77v0oup2wEDCpff+bewvGD98IFBWxEDiDwsf9hM8/05WT2xxLJEyaJmm7le7ho9FxkswvS/Dc/dFY/LlonNvSF49vY+Pc6hifWIpC8Dw+dqrS7XIj7zaocJQ1Kqdc0YZJ9PRwT2QJCrOU2+8Jjysd/envp08+FtBbr8RVaF710J2xfqEG+PqRD3x/THG+rUU0PLPtROE39uyMcWxXVycKLZM5Nmoc++dbS1csvnnrRx/vxVE9M8GTkV3qyw6Ee1u/qtOVyB50fajJvZs1Ofw3XQl/sF2OfDtz6W29TYfaF1hp+0IBhdFYLPrI8f31D+x88y+H4qz2G4vV6qXtrqdLKyrJ2b+YcJITbTNDVGjTvu3bf8D778s4kA98/3fIKps1BjOpsa5AuuXIod2vOBStHsXpqr6+SHX1pJrPWaqlINTW8QeU1aZnlZdR+eUlvyU0vY1kLCRptZiMg0F1EkHjBBgUQVQ27W+8dt+2nXYbSW5cNOf2Y8hDTr++7a9MU1vTG2Coh2PRo1WPPrZ1kSpKhkbInz39WM2+Hwh0xstZE5nOmx2YlamPhGWtIOeSxlioqV6K81W+YPbdLN1ZihEWLm/kqId0XT7sLyzo0riEDyfpRlRRNxk4jRJcQiEMtLtXyOt0IHYXlA45Xgiz4tmZubvwU60tkjdQ6khzLZIVExsz8tK9117+6Aw9xDxoIWweTQmNOEPeH72eFYCVIXHJNATAqBzd0Ce7fJmbuGhjKaIRf2Bn9lqAWqNi8WIqXUhvf3/VijXXPFCbyTC2+QppYSinN6wIHI2Z2DTM1Hc4KAPFePygE7PLoUhk7JMvLD+GJPoGyLxWmmb+XpI36kFRkGehAtxiqFo3SgtnPZL5r078H6gthzd345g6iTbk0ThmNuMYE1S4ozWSzNYlhU+Oo7stowRePJ18/qCutnvT75bVaR5fjeTyf6va019WJellKsxyAqcH/jR/7sHTEaVN541MtF/+N4UJc7MiHJ8f8GVUaqZqSlhstAnRisdfXHDWsvqsFkgKdfrQm+3olrwOF1feOLdk4q23B4cVvdawvhZ1AaBN1nBTV79MPpfOqaXdQmQ838OC1euTUbncjHP4nSoeWGF09d2VHLNu3Z3C8kWruTvueMqHXntfe3hD56HOYzWKIsefeWUJOrFIHgMMrp3ViQeapqRqbiVOWyfjJLlTZZwdjMrfAgb/itXmrqJJy0gMx47rUmSXf/pV3m1Lbm655f4X51oY5zgqLh7Red5u8PoXhElngsnkY5i4h6TwaswkGla/sfTrgdb7qb5zApCcsKTqDlTAkLertPNhAsMkq5pYzxDYJ1+9v2bX9xe8fuHKDJr2/nLL6vv+nOxfsOBJryli1zFGcKWN8hbzemiLyLX/6o0dted0OnHOAJLClFy1LEvBiMMYQSgMSHUUgUcoEpOApFmaolkGw3UrYbuR0I3dhKoLlEGmo2LDhTb4HGV4J1Fgv17RYr9+ddvit5LznUs7LwDJBUurby1C1aPW2LC+pbT67jTKTfssFOFFB1lOdJSF6lSKoHCStSgGj0qkMNrDhN97r7b/j7M5U2s9m+tr0XnLxXZRAxc1cFEDFzVwUQPnpoF/AbqLsVZFbswxAAAAAElFTkSuQmCC";function Hx({onRefresh:t}){let[e,n]=B(!1);return b("button",{type:"button",class:"weave-refresh",onClick:()=>{t(),n(!0)},onAnimationEnd:()=>n(!1),title:"Refetch everything","aria-busy":e?"true":void 0,children:b("svg",{class:e?"weave-refresh-glyph weave-refresh-spinning":"weave-refresh-glyph",viewBox:"0 0 24 24",width:14,height:14,fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",children:of.map(r=>b("path",{d:r},r))})})}function Mf(t){return b("header",{class:"weave-header",children:[b("span",{class:"weave-brand",children:[b("img",{class:"weave-brand-mark",src:`data:${Pf};base64,${If}`,alt:"",width:18,height:18}),"pi-weave"]}),b("button",{type:"button",class:"weave-search",title:lf(t.shortcut),onClick:t.onSearch,children:[b("span",{class:"weave-search-text",children:sf}),b("kbd",{children:t.shortcut})]}),b("span",{class:"weave-summary",children:Jh(t.summary).map(e=>b("span",{class:"weave-summary-part",children:e},e))}),b("button",{type:"button",class:"weave-theme",onClick:t.onTheme,title:t.theme.hint,"aria-label":t.theme.hint,children:t.theme.glyph}),b(Hx,{onRefresh:t.onRefresh})]})}function Bx({group:t}){return b("div",{children:[b("p",{class:"weave-key-group",children:t.title}),t.entries.map(e=>b("div",{class:"weave-key-row",children:[b("kbd",{class:"weave-key-combo",children:e.combo}),b("span",{class:"weave-key-what",children:e.what})]},e.combo))]})}function Gf(t){let e=ii(),n=t.shortcut.slice(0,-1);return b("div",{class:"weave-scrim",onClick:t.onClose,children:b("div",{class:"weave-help",role:"dialog","aria-modal":"true","aria-label":Aa,tabIndex:-1,ref:e.ref,onClick:r=>r.stopPropagation(),onKeyDown:r=>{e.onKeyDown(r)},children:[b("h2",{class:"weave-help-title",children:Aa}),b("div",{class:"weave-keys",children:pf(n).map(r=>b(Bx,{group:r},r.title))}),b("p",{class:"weave-help-foot",children:[b("button",{type:"button",class:"weave-chip",onClick:t.onClose,children:"close"}),b("span",{class:"weave-help-hint",children:gf})]})]})})}function Ff(t,e){let n=r=>{let i=cf(df(r),e.context());i!==null&&(r.preventDefault(),e.run(i))};return t.addEventListener("keydown",n),()=>t.removeEventListener("keydown",n)}function Of({model:t}){return b("footer",{class:"weave-status",children:[b("span",{class:"weave-status-cwd",title:t.cwd,children:t.cwd}),b("span",{class:"weave-status-sel",title:"the §1.3 context bus — one signal, every column",children:t.selection}),b("span",{class:"weave-status-stamp",title:"data as of",children:rf(t.stamp)})]})}var Ca=["system","light","dark"],zf="pi-weave.theme.v1";function Wx(t){return t==="system"||t==="light"||t==="dark"}function fi(t){try{let e=t.getItem(zf);return Wx(e)?e:null}catch{return null}}function $f(t,e){try{return t.setItem(zf,e),!0}catch{return!1}}function pi(t){let e=Ca.indexOf(t);return Ca[(e+1)%Ca.length]??"system"}function Uf(t,e){return t==="system"?e:t}function gi(t){return t==="system"?null:t}var Kx={dark:"●",system:"◐",light:"○"};function Hf(t){return{glyph:Kx[t],hint:`Colour theme: ${t} — click for ${pi(t)}`}}function Vx(t){t===null?delete document.documentElement.dataset.weaveTheme:document.documentElement.dataset.weaveTheme=t}function Bf(t){let[e,n]=B(Zd),[r,i]=B(null),[o,a]=B(t.initialWidth),[s,l]=B(()=>Xh(localStorage,t.initialWidth)),[u,c]=B(()=>fi(localStorage)??"system"),[h,d]=B(()=>Mr(window)),f=V(null),v=V(null),m=V(null),g=()=>{let S=m.current;return S===null||!S.dirty()?!0:window.confirm(Ir)?(S.discard(),!0):!1},w=S=>{g()&&f.current?.select(S)},y=V({overlay:r,selectedId:e.selectedId,layout:s,width:o});y.current={overlay:r,selectedId:e.selectedId,layout:s,width:o},ee(()=>{let S=eh({fetch:Pe,state:e,setState:n});return f.current=S,()=>S.stop()},[]),ee(()=>{let S=()=>a(window.innerWidth);return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]);let _=V(!1),k=V(location.hash);ee(()=>{_.current&&(Yd(localStorage,e.selectedId),history.replaceState(null,"",Lf(e.selectedId)))},[e.selectedId]),ee(()=>{if(_.current||e.graph===null||(_.current=!0,e.selectedId!==null))return;let S=Cf(k.current,e.graph);if(S!==null)f.current?.select(S);else{let D=Xd(e.graph,localStorage);D!==null&&f.current?.select(D)}},[e.graph]);let[A,R]=B(()=>Date.now());ee(()=>{let S=setInterval(()=>R(Date.now()),af);return()=>clearInterval(S)},[]),ee(()=>Vx(gi(u)),[u]),ee(()=>{$f(localStorage,u)},[u]),ee(()=>tc(window,d),[]),ee(()=>{let S=D=>{m.current?.dirty()===!0&&(D.preventDefault(),D.returnValue="")};return window.addEventListener("beforeunload",S),()=>window.removeEventListener("beforeunload",S)},[]),ee(()=>Ff(document,{context:()=>({overlay:y.current.overlay,hasSelection:y.current.selectedId!==null}),run:S=>ff(S,{setOverlay:i,focusSelector:D=>hf(document,D),fitGraph:()=>v.current?.(),clearSelection:()=>w(null),cycleTheme:()=>c(D=>pi(D))})}),[]);let M=Ze(()=>qh(s,o,Wh(o)),[s,o]),L=Ze(()=>Df({layout:()=>y.current.layout,width:()=>y.current.width,setLayout:l,persist:S=>{Zh(localStorage,S)}}),[]);return b(Ae,{children:[b(Mf,{summary:Qh(e.graph),shortcut:Ea(Sa(t.platform)),onRefresh:()=>f.current?.refresh(),onSearch:()=>i("search"),theme:Hf(u),onTheme:()=>c(S=>pi(S))}),b(Rf,{resolved:M,onDown:L.onDown,onMove:L.onMove,onUp:L.onUp,onKey:L.onKey,scheme:Uf(u,h),bootFailed:e.graphFailed,graph:e.graph,note:e.note,noteFailed:e.noteFailed,selectedId:e.selectedId,recentIds:e.recentIds,onSelect:w,onMutate:g,onRefresh:()=>f.current?.refresh(),onOpen:S=>{(async()=>{let D=await Cl(Pe,S);D.ok?D.data.opened||window.alert("could not open the note in an editor"):window.alert(D.message)})()},onSave:async(S,D)=>{let $=await Ll(Pe,S,D);return $.ok?(f.current?.refresh(),!0):(window.alert($.message),!1)},editor:m,now:A,renderer:Pd,storage:localStorage,host:window,fit:v,tuner:t.tuner===!0}),b(Of,{model:nf(t.cwd,e.selectedId,e.graph?.model.generatedAt??null)}),r==="search"?b(jd,{graph:e.graph,onSelect:w,onClose:()=>i(null),ports:{fetch:Pe}}):null,r==="help"?b(Gf,{shortcut:Ea(Sa(t.platform)),onClose:()=>i(null)}):null]})}var Wf=`
400
400
  --weave-bg:#eff1f5;--weave-panel:#e6e9ef;--weave-raise:#ccd0da;--weave-fg:#4c4f69;--weave-dim:#56586a;
401
401
  --weave-faint:#606274;--weave-line:#ccd0da;--weave-line-strong:#bcc0cc;
402
402
  --weave-accent:#7113ec;--weave-ok:#28641b;--weave-warn:#7c4f10;--weave-bad:#b20d30;