@mindflight/mindbrain-personal-studio 0.6.4 → 0.6.5

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.
Files changed (61) hide show
  1. package/README.md +2 -2
  2. package/build/client/_app/immutable/chunks/BsHs7Gcd.js +1 -0
  3. package/build/client/_app/immutable/chunks/BsHs7Gcd.js.br +0 -0
  4. package/build/client/_app/immutable/chunks/BsHs7Gcd.js.gz +0 -0
  5. package/build/client/_app/immutable/entry/{app.XgS1PoV0.js → app.CpAvcJQF.js} +2 -2
  6. package/build/client/_app/immutable/entry/app.CpAvcJQF.js.br +0 -0
  7. package/build/client/_app/immutable/entry/app.CpAvcJQF.js.gz +0 -0
  8. package/build/client/_app/immutable/entry/start.CI2IWrEW.js +1 -0
  9. package/build/client/_app/immutable/entry/start.CI2IWrEW.js.br +2 -0
  10. package/build/client/_app/immutable/entry/start.CI2IWrEW.js.gz +0 -0
  11. package/build/client/_app/immutable/nodes/{1.Cs3BmvHO.js → 1.D6NCzfyp.js} +1 -1
  12. package/build/client/_app/immutable/nodes/1.D6NCzfyp.js.br +1 -0
  13. package/build/client/_app/immutable/nodes/1.D6NCzfyp.js.gz +0 -0
  14. package/build/client/_app/immutable/nodes/2.EDmnjbqo.js +9 -0
  15. package/build/client/_app/immutable/nodes/2.EDmnjbqo.js.br +0 -0
  16. package/build/client/_app/immutable/nodes/2.EDmnjbqo.js.gz +0 -0
  17. package/build/client/_app/version.json +1 -1
  18. package/build/client/_app/version.json.br +0 -0
  19. package/build/client/_app/version.json.gz +0 -0
  20. package/build/handler.js +4 -4
  21. package/build/index.js +4 -4
  22. package/build/server/chunks/chunks/{graphRepository.js-D2DARfVY.js → graphRepository.js-CmIA6rqA.js} +4 -1
  23. package/build/server/chunks/chunks/graphRepository.js-CmIA6rqA.js.map +1 -0
  24. package/build/server/chunks/chunks/{internal.js-BnebQ91H.js → internal.js-Bx4qge33.js} +2 -2
  25. package/build/server/chunks/chunks/{internal.js-BnebQ91H.js.map → internal.js-Bx4qge33.js.map} +1 -1
  26. package/build/server/chunks/entries/endpoints/api/graph/{_server.ts.js-Bxo7qHVz.js → _server.ts.js-BDrhYCoq.js} +2 -2
  27. package/build/server/chunks/entries/endpoints/api/graph/{_server.ts.js-Bxo7qHVz.js.map → _server.ts.js-BDrhYCoq.js.map} +1 -1
  28. package/build/server/chunks/entries/endpoints/api/graph/count/{_server.ts.js-BajaLnqp.js → _server.ts.js-BeCjTntz.js} +2 -2
  29. package/build/server/chunks/entries/endpoints/api/graph/count/{_server.ts.js-BajaLnqp.js.map → _server.ts.js-BeCjTntz.js.map} +1 -1
  30. package/build/server/chunks/entries/endpoints/api/graph/gap-rules/_server.ts.js-DduzA_uh.js +68 -0
  31. package/build/server/chunks/entries/endpoints/api/graph/gap-rules/_server.ts.js-DduzA_uh.js.map +1 -0
  32. package/build/server/chunks/entries/endpoints/api/graph/ontologies/{_server.ts.js-BFq2mbbX.js → _server.ts.js-K5EkSYpR.js} +2 -2
  33. package/build/server/chunks/entries/endpoints/api/graph/ontologies/{_server.ts.js-BFq2mbbX.js.map → _server.ts.js-K5EkSYpR.js.map} +1 -1
  34. package/build/server/chunks/entries/endpoints/api/graph/schema-registry/{_server.ts.js-CAsXxBRq.js → _server.ts.js-B5OTti3s.js} +2 -2
  35. package/build/server/chunks/entries/endpoints/api/graph/schema-registry/{_server.ts.js-CAsXxBRq.js.map → _server.ts.js-B5OTti3s.js.map} +1 -1
  36. package/build/server/chunks/{handler-B8M0DnFi.js → handler-Cc3Mp_Ob.js} +3 -3
  37. package/build/server/chunks/{handler-B8M0DnFi.js.map → handler-Cc3Mp_Ob.js.map} +1 -1
  38. package/build/server/chunks/{index.js-qz9YZN7m.js → index.js-BRvQVgSe.js} +2 -2
  39. package/build/server/chunks/{index.js-qz9YZN7m.js.map → index.js-BRvQVgSe.js.map} +1 -1
  40. package/build/server/chunks/{manifest.js-BxEwHoCX.js → manifest.js-Bv1A6wIB.js} +15 -8
  41. package/build/server/chunks/manifest.js-Bv1A6wIB.js.map +1 -0
  42. package/build/server/chunks/nodes/{1.js-D3KAPgsF.js → 1.js-C8oWVl8C.js} +2 -2
  43. package/build/server/chunks/nodes/{1.js-D3KAPgsF.js.map → 1.js-C8oWVl8C.js.map} +1 -1
  44. package/build/server/chunks/nodes/{2.js-D9-B_qyX.js → 2.js-D2JlHjgb.js} +2 -2
  45. package/build/server/chunks/nodes/{2.js-D9-B_qyX.js.map → 2.js-D2JlHjgb.js.map} +1 -1
  46. package/package.json +1 -1
  47. package/build/client/_app/immutable/chunks/BjfgiHck.js +0 -1
  48. package/build/client/_app/immutable/chunks/BjfgiHck.js.br +0 -0
  49. package/build/client/_app/immutable/chunks/BjfgiHck.js.gz +0 -0
  50. package/build/client/_app/immutable/entry/app.XgS1PoV0.js.br +0 -0
  51. package/build/client/_app/immutable/entry/app.XgS1PoV0.js.gz +0 -0
  52. package/build/client/_app/immutable/entry/start.Dtz8dQFZ.js +0 -1
  53. package/build/client/_app/immutable/entry/start.Dtz8dQFZ.js.br +0 -2
  54. package/build/client/_app/immutable/entry/start.Dtz8dQFZ.js.gz +0 -0
  55. package/build/client/_app/immutable/nodes/1.Cs3BmvHO.js.br +0 -3
  56. package/build/client/_app/immutable/nodes/1.Cs3BmvHO.js.gz +0 -0
  57. package/build/client/_app/immutable/nodes/2.D0pSa9ko.js +0 -9
  58. package/build/client/_app/immutable/nodes/2.D0pSa9ko.js.br +0 -0
  59. package/build/client/_app/immutable/nodes/2.D0pSa9ko.js.gz +0 -0
  60. package/build/server/chunks/chunks/graphRepository.js-D2DARfVY.js.map +0 -1
  61. package/build/server/chunks/manifest.js-BxEwHoCX.js.map +0 -1
@@ -1,9 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["../chunks/-OSExkSk.js","../chunks/C5KYKPa8.js","../chunks/BJB7pSge.js","../chunks/i0D5dc1Y.js","../chunks/Gs0cNFYG.js","../chunks/DyXQogav.js","../chunks/Cp9dXlPT.js","../chunks/BP2JbIUZ.js","../chunks/BVrgUHq-.js","../chunks/CBDzfqXr.js"])))=>i.map(i=>d[i]);
2
- import{b as Va,a as x,f as D,c as zt,t as Bn}from"../chunks/NXeHtWpC.js";import{a as ra,o as Ka}from"../chunks/BNUkRZqg.js";import{h as cn,P as Ni,i as ds,a1 as s,U as $a,ag as Za,V as Ss,w as Rr,v as Gr,e as kr,C as Ua,aE as Wa,ap as Ns,a as cr,c as mi,aM as ir,b as Qi,aN as Ga,s as Ya,a9 as Xa,aO as Ja,aP as Qa,aH as qa,ad as Ds,aQ as eo,a5 as to,r as ia,p as sa,aR as Li,aS as no,aB as ro,m as io,d as so,aD as hs,aT as aa,t as ao,x as oa,aU as la,q as oo,aV as lo,aW as co,E as ho,J as uo,aX as fo,K as go,av as ca,W as da,g as us,X as fs,aY as vo,aZ as po,a_ as yo,a$ as mo,b0 as gs,aJ as mn,A as Nn,a2 as $t,u as De,a3 as u,aK as A,D as g,G as b,F as f,B as Dn,aL as be,z as ee,aq as Yt,y as et,b1 as Zr,b2 as li,b3 as ci,b4 as fr,b5 as _o}from"../chunks/BnkCgNCx.js";import{i as bo,s as F,d as jn,a as ze,e as Ct}from"../chunks/D0daF8Eh.js";import{p as K,b as Qr,i as q,_ as Yn}from"../chunks/nnWk1BBo.js";import{r as Mn,a as Rn,b as ko,s as Hn}from"../chunks/DpVrWha3.js";import{B as ha}from"../chunks/D4SoBmS0.js";const wo=Symbol("NaN");function xo(t,e,n){cn&&Ni();var r=new ha(t);ds(()=>{var i=e();i!==i&&(i=wo),r.ensure(i,n)})}function Mt(t,e){return e}function Co(t,e,n){for(var r=[],i=e.length,a,o=e.length,l=0;l<i;l++){let p=e[l];sa(p,()=>{if(a){if(a.pending.delete(p),a.done.add(p),a.pending.size===0){var m=t.outrogroups;qi(t,hs(a.done)),m.delete(a),m.size===0&&(t.outrogroups=null)}}else o-=1},!1)}if(o===0){var c=r.length===0&&n!==null;if(c){var d=n,h=d.parentNode;ro(h),h.append(d),t.items.clear()}qi(t,e,!c)}else a={pending:new Set(e),done:new Set},(t.outrogroups??=new Set).add(a)}function qi(t,e,n=!0){var r;if(t.pending.size>0){r=new Set;for(const o of t.pending.values())for(const l of o)r.add(t.items.get(l).e)}for(var i=0;i<e.length;i++){var a=e[i];if(r?.has(a)){a.f|=ir;const o=document.createDocumentFragment();io(a,o)}else so(e[i],n)}}var Ps;function _t(t,e,n,r,i,a=null){var o=t,l=new Map,c=(e&la)!==0;if(c){var d=t;o=cn?Rr(oa(d)):d.appendChild(mi())}cn&&Ni();var h=null,p=Xa(()=>{var B=n();return aa(B)?B:B==null?[]:hs(B)}),m,k=new Map,C=!0;function _(B){(E.effect.f&to)===0&&(E.pending.delete(B),E.fallback=h,So(E,m,o,e,r),h!==null&&(m.length===0?(h.f&ir)===0?ia(h):(h.f^=ir,Ur(h,null,o)):sa(h,()=>{h=null})))}function v(B){E.pending.delete(B)}var P=ds(()=>{m=s(p);var B=m.length;let V=!1;if(cn){var Z=$a(o)===Za;Z!==(B===0)&&(o=Ss(),Rr(o),Gr(!1),V=!0)}for(var j=new Set,ae=cr,ce=Ya(),de=0;de<B;de+=1){cn&&kr.nodeType===Ua&&kr.data===Wa&&(o=kr,V=!0,Gr(!1));var W=m[de],N=r(W,de),G=C?null:l.get(N);G?(G.v&&Ns(G.v,W),G.i&&Ns(G.i,de),ce&&ae.unskip_effect(G.e)):(G=No(l,C?o:Ps??=mi(),W,N,de,i,e,n),C||(G.e.f|=ir),l.set(N,G)),j.add(N)}if(B===0&&a&&!h&&(C?h=Qi(()=>a(o)):(h=Qi(()=>a(Ps??=mi())),h.f|=ir)),B>j.size&&Ga(),cn&&B>0&&Rr(Ss()),!C)if(k.set(ae,j),ce){for(const[O,X]of l)j.has(O)||ae.skip_effect(X.e);ae.oncommit(_),ae.ondiscard(v)}else _(ae);V&&Gr(!0),s(p)}),E={effect:P,items:l,pending:k,outrogroups:null,fallback:h};C=!1,cn&&(o=kr)}function Vr(t){for(;t!==null&&(t.f&no)===0;)t=t.next;return t}function So(t,e,n,r,i){var a=(r&lo)!==0,o=e.length,l=t.items,c=Vr(t.effect.first),d,h=null,p,m=[],k=[],C,_,v,P;if(a)for(P=0;P<o;P+=1)C=e[P],_=i(C,P),v=l.get(_).e,(v.f&ir)===0&&(v.nodes?.a?.measure(),(p??=new Set).add(v));for(P=0;P<o;P+=1){if(C=e[P],_=i(C,P),v=l.get(_).e,t.outrogroups!==null)for(const W of t.outrogroups)W.pending.delete(v),W.done.delete(v);if((v.f&Li)!==0&&(ia(v),a&&(v.nodes?.a?.unfix(),(p??=new Set).delete(v))),(v.f&ir)!==0)if(v.f^=ir,v===c)Ur(v,null,n);else{var E=h?h.next:c;v===t.effect.last&&(t.effect.last=v.prev),v.prev&&(v.prev.next=v.next),v.next&&(v.next.prev=v.prev),ur(t,h,v),ur(t,v,E),Ur(v,E,n),h=v,m=[],k=[],c=Vr(h.next);continue}if(v!==c){if(d!==void 0&&d.has(v)){if(m.length<k.length){var B=k[0],V;h=B.prev;var Z=m[0],j=m[m.length-1];for(V=0;V<m.length;V+=1)Ur(m[V],B,n);for(V=0;V<k.length;V+=1)d.delete(k[V]);ur(t,Z.prev,j.next),ur(t,h,Z),ur(t,j,B),c=B,h=j,P-=1,m=[],k=[]}else d.delete(v),Ur(v,c,n),ur(t,v.prev,v.next),ur(t,v,h===null?t.effect.first:h.next),ur(t,h,v),h=v;continue}for(m=[],k=[];c!==null&&c!==v;)(d??=new Set).add(c),k.push(c),c=Vr(c.next);if(c===null)continue}(v.f&ir)===0&&m.push(v),h=v,c=Vr(v.next)}if(t.outrogroups!==null){for(const W of t.outrogroups)W.pending.size===0&&(qi(t,hs(W.done)),t.outrogroups?.delete(W));t.outrogroups.size===0&&(t.outrogroups=null)}if(c!==null||d!==void 0){var ae=[];if(d!==void 0)for(v of d)(v.f&Li)===0&&ae.push(v);for(;c!==null;)(c.f&Li)===0&&c!==t.fallback&&ae.push(c),c=Vr(c.next);var ce=ae.length;if(ce>0){var de=(r&la)!==0&&o===0?n:null;if(a){for(P=0;P<ce;P+=1)ae[P].nodes?.a?.measure();for(P=0;P<ce;P+=1)ae[P].nodes?.a?.fix()}Co(t,ae,de)}}a&&oo(()=>{if(p!==void 0)for(v of p)v.nodes?.a?.apply()})}function No(t,e,n,r,i,a,o,l){var c=(o&Ja)!==0?(o&Qa)===0?qa(n,!1,!1):Ds(n):null,d=(o&eo)!==0?Ds(i):null;return{v:c,i:d,e:Qi(()=>(a(e,c??n,d??i,l),()=>{t.delete(r)}))}}function Ur(t,e,n){if(t.nodes)for(var r=t.nodes.start,i=t.nodes.end,a=e&&(e.f&ir)===0?e.nodes.start:n;r!==null;){var o=ao(r);if(a.before(r),r===i)return;r=o}}function ur(t,e,n){e===null?t.effect.first=n:e.next=n,n===null?t.effect.last=e:n.prev=e}function Do(t,e,n,r,i,a){let o=cn;cn&&Ni();var l=null;cn&&kr.nodeType===co&&(l=kr,Ni());var c=cn?kr:t,d=new ha(c,!1);ds(()=>{const h=e()||null;var p=h==="svg"?fo:void 0;if(h===null){d.ensure(null,null);return}return d.ensure(h,m=>{if(h){if(l=cn?l:uo(h,p),Va(l,l),r){cn&&bo(h)&&l.append(document.createComment(""));var k=cn?oa(l):l.appendChild(mi());cn&&(k===null?Gr(!1):Rr(k)),r(l,k)}go.nodes.end=l,m.before(l)}cn&&Rr(m)}),()=>{}},ho),ca(()=>{}),o&&(Gr(!0),Rr(c))}function Po(t,e,n){da(()=>{var r=us(()=>e(t,n?.())||{});if(n&&r?.update){var i=!1,a={};fs(()=>{var o=n();vo(o),i&&po(a,o)&&(a=o,r.update(o))}),i=!0}if(r?.destroy)return()=>r.destroy()})}function ua(t){var e,n,r="";if(typeof t=="string"||typeof t=="number")r+=t;else if(typeof t=="object")if(Array.isArray(t)){var i=t.length;for(e=0;e<i;e++)t[e]&&(n=ua(t[e]))&&(r&&(r+=" "),r+=n)}else for(n in t)t[n]&&(r&&(r+=" "),r+=n);return r}function Io(){for(var t,e,n=0,r="",i=arguments.length;n<i;n++)(t=arguments[n])&&(e=ua(t))&&(r&&(r+=" "),r+=e);return r}function To(t){return typeof t=="object"?Io(t):t??""}const Is=[...`
3
- \r\f \v\uFEFF`];function Mo(t,e,n){var r=t==null?"":""+t;if(e&&(r=r?r+" "+e:e),n){for(var i of Object.keys(n))if(n[i])r=r?r+" "+i:i;else if(r.length)for(var a=i.length,o=0;(o=r.indexOf(i,o))>=0;){var l=o+a;(o===0||Is.includes(r[o-1]))&&(l===r.length||Is.includes(r[l]))?r=(o===0?"":r.substring(0,o))+r.substring(l+1):o=l}}return r===""?null:r}function Ts(t,e=!1){var n=e?" !important;":";",r="";for(var i of Object.keys(t)){var a=t[i];a!=null&&a!==""&&(r+=" "+i+": "+a+n)}return r}function Hi(t){return t[0]!=="-"||t[1]!=="-"?t.toLowerCase():t}function Eo(t,e){if(e){var n="",r,i;if(Array.isArray(e)?(r=e[0],i=e[1]):r=e,t){t=String(t).replaceAll(/\s*\/\*.*?\*\/\s*/g,"").trim();var a=!1,o=0,l=!1,c=[];r&&c.push(...Object.keys(r).map(Hi)),i&&c.push(...Object.keys(i).map(Hi));var d=0,h=-1;const _=t.length;for(var p=0;p<_;p++){var m=t[p];if(l?m==="/"&&t[p-1]==="*"&&(l=!1):a?a===m&&(a=!1):m==="/"&&t[p+1]==="*"?l=!0:m==='"'||m==="'"?a=m:m==="("?o++:m===")"&&o--,!l&&a===!1&&o===0){if(m===":"&&h===-1)h=p;else if(m===";"||p===_-1){if(h!==-1){var k=Hi(t.substring(d,h).trim());if(!c.includes(k)){m!==";"&&p++;var C=t.substring(d,p).trim();n+=" "+C+";"}}d=p+1,h=-1}}}}return r&&(n+=Ts(r)),i&&(n+=Ts(i,!0)),n=n.trim(),n===""?null:n}return t==null?null:String(t)}function st(t,e,n,r,i,a){var o=t.__className;if(cn||o!==n||o===void 0){var l=Mo(n,r,a);(!cn||l!==t.getAttribute("class"))&&(l==null?t.removeAttribute("class"):e?t.className=l:t.setAttribute("class",l)),t.__className=n}else if(a&&i!==a)for(var c in a){var d=!!a[c];(i==null||d!==!!i[c])&&t.classList.toggle(c,d)}return a}function zi(t,e={},n,r){for(var i in n){var a=n[i];e[i]!==a&&(n[i]==null?t.style.removeProperty(i):t.style.setProperty(i,a,r))}}function rr(t,e,n,r){var i=t.__style;if(cn||i!==e){var a=Eo(e,r);(!cn||a!==t.getAttribute("style"))&&(a==null?t.removeAttribute("style"):t.style.cssText=a),t.__style=e}else r&&(Array.isArray(r)?(zi(t,n?.[0],r[0]),zi(t,n?.[1],r[1],"important")):zi(t,n,r));return r}function qr(t,e,n=!1){if(t.multiple){if(e==null)return;if(!aa(e))return yo();for(var r of t.options)r.selected=e.includes(Yr(r));return}for(r of t.options){var i=Yr(r);if(mo(i,e)){r.selected=!0;return}}(!n||e!==void 0)&&(t.selectedIndex=-1)}function Di(t){var e=new MutationObserver(()=>{qr(t,t.__value)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),ca(()=>{e.disconnect()})}function Or(t,e,n=e){var r=new WeakSet,i=!0;gs(t,"change",a=>{var o=a?"[selected]":":checked",l;if(t.multiple)l=[].map.call(t.querySelectorAll(o),Yr);else{var c=t.querySelector(o)??t.querySelector("option:not([disabled])");l=c&&Yr(c)}n(l),t.__value=l,cr!==null&&r.add(cr)}),da(()=>{var a=e();if(t===document.activeElement){var o=cr;if(r.has(o))return}if(qr(t,a,i),i&&a===void 0){var l=t.querySelector(":checked");l!==null&&(a=Yr(l),n(a))}t.__value=a,i=!1}),Di(t)}function Yr(t){return"__value"in t?t.__value:t.value}function zr(t,e,n=e){var r=new WeakSet;gs(t,"input",async i=>{var a=i?t.defaultValue:t.value;if(a=Fi(t)?Bi(a):a,n(a),cr!==null&&r.add(cr),await mn(),a!==(a=e())){var o=t.selectionStart,l=t.selectionEnd,c=t.value.length;if(t.value=a??"",l!==null){var d=t.value.length;o===l&&l===c&&d>c?(t.selectionStart=d,t.selectionEnd=d):(t.selectionStart=o,t.selectionEnd=Math.min(l,d))}}}),(cn&&t.defaultValue!==t.value||us(e)==null&&t.value)&&(n(Fi(t)?Bi(t.value):t.value),cr!==null&&r.add(cr)),fs(()=>{var i=e();if(t===document.activeElement){var a=cr;if(r.has(a))return}Fi(t)&&i===Bi(t.value)||t.type==="date"&&!i&&!t.value||i!==t.value&&(t.value=i??"")})}function or(t,e,n=e){gs(t,"change",r=>{var i=r?t.defaultChecked:t.checked;n(i)}),(cn&&t.defaultChecked!==t.checked||us(e)==null)&&n(t.checked),fs(()=>{var r=e();t.checked=!!r})}function Fi(t){var e=t.type;return e==="number"||e==="range"}function Bi(t){return t===""?null:+t}function Ao(t,e,n){const r=new Set([e]);let i=[e];for(let a=0;a<n;a++){const o=[];for(const l of i)t.forEachOutNeighbor(l,c=>{r.has(c)||(r.add(c),o.push(c))}),t.forEachInNeighbor(l,c=>{r.has(c)||(r.add(c),o.push(c))});i=o}return r}const Ro=[{id:"circular_force",label:"Circular + ForceAtlas2 (default)"},{id:"circular_only",label:"Circular ring only"},{id:"random_force",label:"Random seed + ForceAtlas2"},{id:"linlog_clusters",label:"ForceAtlas2 LinLog (clusters)"}];function fa(t,e){const n=new Map;if(t.forEachNode(h=>{const p=e(h);p!=null&&(n.has(p)||n.set(p,[]),n.get(p).push(h))}),n.size===0)return;const r=[...n.keys()].sort(),i=r.length,a=Math.max(5,Math.sqrt(t.order)*1.5),o=Math.max(.5,a/(i*1.8)),l=new Map;r.forEach((h,p)=>{const m=2*Math.PI*p/i;l.set(h,{cx:Math.cos(m)*a,cy:Math.sin(m)*a})});let c=42;function d(){return c=c*1664525+1013904223&4294967295,(c>>>0)/4294967296}t.forEachNode(h=>{const p=e(h),m=p!=null?l.get(p):null;m?(t.setNodeAttribute(h,"x",m.cx+(d()-.5)*o*2),t.setNodeAttribute(h,"y",m.cy+(d()-.5)*o*2)):(t.setNodeAttribute(h,"x",(d()-.5)*o),t.setNodeAttribute(h,"y",(d()-.5)*o))})}function Oo(t,e,n,r){const{circular:i,random:a}=e;if(r)return fa(t,r),!0;switch(n){case"circular_only":return i.assign(t,{scale:1}),!1;case"random_force":return a.assign(t,{scale:1}),!0;default:return i.assign(t,{scale:1}),!0}}function ji(t,e,n,r,i,a,o){if(!Oo(t,e,i,a))return()=>{};const c=r.inferSettings(t),d=t.order;let h;a?h={...c,linLogMode:!0,gravity:.08}:i==="linlog_clusters"?h={...c,linLogMode:!0,gravity:.02}:h={...c,linLogMode:d>30},d>3e3&&(h={...h,slowDown:Math.max(h.slowDown??1,3)});const p=new n(t,{settings:h});p.start();const m=d<50?1500:d<500?3e3:d<3e3?5e3:8e3,k=setTimeout(()=>{p.isRunning()&&p.stop()},m);return()=>{clearTimeout(k),p.isRunning()&&p.stop(),p.kill()}}function Lo(t,e,n,r,i){const{circular:a,random:o}=e,l=n.inferSettings(t),c=t.order,d={iterations:Math.min(300,50+c*2),settings:{...l,linLogMode:c>30}};if(i){fa(t,i),n.assign(t,{iterations:Math.min(400,80+c*2),settings:{...l,linLogMode:!0,gravity:.08}});return}switch(r){case"circular_only":a.assign(t,{scale:1});return;case"random_force":o.assign(t,{scale:1}),n.assign(t,d);return;case"linlog_clusters":a.assign(t,{scale:1}),n.assign(t,{iterations:Math.min(400,80+c*2),settings:{...l,linLogMode:!0,gravity:.02}});return;default:a.assign(t,{scale:1}),n.assign(t,d)}}const ei=3,Lr=2,Ho=2,ti=[{name:"Chapters",fills:["#fbbf24","#f59e0b","#eab308","#ca8a04"],label:"#fffbeb"},{name:"Articles & annexes",fills:["#38bdf8","#22d3ee","#0ea5e9","#06b6d4"],label:"#ecfeff"},{name:"Concepts & obligations",fills:["#a78bfa","#818cf8","#c084fc","#34d399","#f472b6"],label:"#f5f3ff"},{name:"Other (AI Act tier)",fills:["#94a3b8","#78716c","#64748b","#737373"],label:"#f8fafc"}],Ms="#64748b",di=56,hi=36,ui=40,zo=14,Es=18,Fo=8e3;function _i(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function Bo(t,e,n){const r=(t%360+360)%360,i=e/100,a=n/100,o=(1-Math.abs(2*a-1))*i,l=r/60,c=o*(1-Math.abs(l%2-1));let d=0,h=0,p=0;l>=0&&l<1?[d,h,p]=[o,c,0]:l<2?[d,h,p]=[c,o,0]:l<3?[d,h,p]=[0,o,c]:l<4?[d,h,p]=[0,c,o]:l<5?[d,h,p]=[c,0,o]:[d,h,p]=[o,0,c];const m=a-o/2,k=Math.round((d+m)*255),C=Math.round((h+m)*255),_=Math.round((p+m)*255);return`#${k.toString(16).padStart(2,"0")}${C.toString(16).padStart(2,"0")}${_.toString(16).padStart(2,"0")}`}function tr(t,e=0){const n=_i(`${e}\0${t}`)%360,r=58+_i(t)%12,i=52+_i(t+"L")%10;return Bo(n,r,i)}function jo(t,e){const r=ti[Math.min(t,ti.length-1)].fills;let i=0;for(let a=0;a<e.length;a++)i=i*31+e.charCodeAt(a)>>>0;return r[i%r.length]}function ga(t){const e=hr(t),n=e?On(e,"entity_type"):null,r=(t.node_type||n||"").toLowerCase(),i=(t.schema_id||"").toLowerCase();return r==="document"||r==="chapter"||r==="section"||i.includes("chapter")?0:r==="article"||r==="paragraph"||r==="recital"||r==="annex"||r==="annex-entry"||r==="definition"||i.includes(":article")||i.includes(":annex")?1:["concept","role","obligation","risk-level","deadline","domain","penalty","penalty-tier","risk-level","ai-system-category","stakeholder-role","obligation-type","sector","fundamental-right","exemption","usecase","classification","intent-pattern","user-profile","project-stage","facet-vector","answer-template","query-example","decision","task","constraint","source","note","integration","environment"].some(a=>r===a||r.includes(a))||/ai-act:(concept|obligation|role|risk|deadline|domain|penalty|recital|usecase)/.test(i)?2:3}function bi(t){if((t.schema_id||"").trim().toLowerCase().startsWith("ai-act:"))return!0;const n=hr(t);if(!n)return!1;const r=On(n,"workspace_id")??On(n,"workspace"),i=On(n,"record_id")??On(n,"source_ref"),a=On(n,"ontology_layer");if(r?.toLowerCase()==="ai-act"&&(a||i&&!i.toLowerCase().startsWith("workspace:ai-act:loadout"))||i?.toLowerCase().startsWith("ai-act:")||On(n,"celex")==="32024R1689"||On(n,"legal_version")?.toLowerCase().includes("ai act"))return!0;const c=On(n,"source_ref");return!!(a&&(c?.includes("L_202401689")||c?.toLowerCase().includes("ai_act")))}function Vi(t){const e=(t.schema_id||"").trim();if(e!=="")return e;const n=(t.node_type||"").trim();return n!==""?`type:${n}`:"(no schema / type)"}function Ki(t){const e=(t.schema_id||"").trim();if(e===""){const r=(t.node_type||"").trim();return r!==""?`(type: ${r})`:"(no namespace)"}const n=e.indexOf(":");return n===-1?e:e.slice(0,n)}function Vo(t){const e=ga(t),n=[11,9,7,5.5],r=[12,9,6,3],i=ti[Math.min(e,ti.length-1)];return{color:jo(e,t.id),labelColor:i.label,size:n[e]??6,zIndex:r[e]??0}}function Wn(t,e){return`${t} (${e})`}function Ko(t){const e=[0,0,0,0];for(const n of t){if(!bi(n))continue;const r=Math.min(Math.max(ga(n),0),3);e[r]++}return e}function $o(t,e){const n=new Map;for(const r of t){const i=e(r);n.set(i,(n.get(i)??0)+1)}return n}function Zo(t){const e=new Map;for(const n of t){const r=(n.label??"").trim();r!==""&&e.set(r,(e.get(r)??0)+1)}return e}function hr(t){const e=t.facets;return e==null||typeof e!="object"||Array.isArray(e)?null:e}function On(t,e){const n=t[e];if(n==null)return null;const r=String(n).trim();return r===""?null:r}const As="abstraction_level:";function va(t){const e=t.facet_tags;if(!Array.isArray(e))return[];const n=[];for(const r of e){if(typeof r!="string"||!r.startsWith(As))continue;const i=r.slice(As.length).trim();i!==""&&n.push(i)}return n}function Uo(t,e){const n=new Map;let r=0;for(const i of t){const a=hr(i);if(!a)continue;const o=On(a,e);o!=null&&(r++,n.set(o,(n.get(o)??0)+1))}return{counts:n,covered:r}}function Wo(t){const e=new Map;let n=0;for(const r of t){const i=hr(r);if(!i)continue;const a=va(i);if(a.length!==0){n++;for(const o of a)e.set(o,(e.get(o)??0)+1)}}return{counts:e,covered:n}}function Go(t){const e=new Map;for(const n of t)e.has(n.source)||e.set(n.source,new Set),e.has(n.target)||e.set(n.target,new Set),e.get(n.source).add(n.target),e.get(n.target).add(n.source);return e}function $i(t,e,n,r){if(t.size===0)return new Set;const i=Go(e),a=new Set(t);let o=[...t];for(let l=0;l<n;l++){const c=[];for(const d of o)for(const h of i.get(d)??[])r&&!r(h)||a.has(h)||(a.add(h),c.push(h));o=c}return a}function Rs(t){const e=hr(t);return e?On(e,"audit_phase")??On(e,"run_stage"):null}function Os(t,e,n){if(n.kind==="scalar"){const r=new Set;for(const i of t){const a=hr(i);a&&On(a,n.key)===n.value&&r.add(i.id)}return r}if(n.kind==="abstraction"){const r=new Set;for(const i of t){const a=hr(i);a&&va(a).includes(n.value)&&r.add(i.id)}return r}if(n.kind==="chantier_week_neighborhood"){const r=new Set;for(const i of t){const a=hr(i);if(!a)continue;On(a,"week_number")===n.week&&r.add(i.id)}return $i(r,e,Lr)}if(n.kind==="audit_phase_neighborhood"){const r=new Set,i=new Map(t.map(a=>[a.id,a]));for(const a of t)Rs(a)===n.phase&&r.add(a.id);return $i(r,e,Ho,a=>{const o=i.get(a);if(!o)return!1;const l=Rs(o);return l==null||l===n.phase})}return $i(new Set([n.platformId]),e,ei)}function Ls(t,e,n,r,i,a){if(e.size===0||n===0)return null;const o=[...e.entries()].sort((d,h)=>h[1]-d[1]||d[0].localeCompare(h[0],void 0,{sensitivity:"base"})),c=o.slice(0,r).map(([d,h])=>{let p;return a.mode==="scalar"?p={kind:"scalar",key:a.key,value:d}:a.mode==="abstraction"?p={kind:"abstraction",value:d}:a.mode==="chantier_week"?p={kind:"chantier_week_neighborhood",week:d}:p={kind:"audit_phase_neighborhood",phase:d},{swatch:tr(`facet:${t}:${d}`,i),label:Wn(d,h),facetFilter:p}});if(o.length>r){const h=o.slice(r).reduce((p,[,m])=>p+m,0);c.push({swatch:"#64748b",label:`… +${o.length-r} more values (${h} counts)`})}return{title:`${t} (${n})`,rows:c}}function Yo(t){if(t.length===0||t.length>Fo)return[];if(t.filter(a=>{const o=hr(a);return o!=null&&Object.keys(o).length>0}).length===0)return[];const n=[{kind:"scalar",label:"AI layer",key:"ontology_layer"},{kind:"scalar",label:"AI entity type",key:"entity_type"},{kind:"scalar",label:"risk level",key:"risk_level"},{kind:"scalar",label:"stakeholder role",key:"stakeholder_role"},{kind:"scalar",label:"obligation type",key:"obligation_type"},{kind:"scalar",label:"sector",key:"sector"},{kind:"scalar",label:"penalty tier",key:"penalty_tier"},{kind:"scalar",label:"deadline",key:"deadline"},{kind:"scalar",label:"fundamental right",key:"fundamental_right"},{kind:"scalar",label:"intent",key:"intent_primary"},{kind:"scalar",label:"answer granularity",key:"answer_granularity"},{kind:"scalar",label:"geo scope",key:"geo_scope"},{kind:"scalar",label:"validation",key:"validation_status"},{kind:"scalar",label:"audit phase",key:"audit_phase"},{kind:"scalar",label:"graph layer",key:"graph_layer"},{kind:"scalar",label:"semantic group",key:"semantic_group"},{kind:"scalar",label:"severity",key:"severity"},{kind:"scalar",label:"status",key:"status"},{kind:"scalar",label:"issue category",key:"issue_category"},{kind:"scalar",label:"page tier",key:"page_tier"},{kind:"scalar",label:"device",key:"device"},{kind:"scalar",label:"channel",key:"channel"},{kind:"scalar",label:"position bucket",key:"position_bucket"},{kind:"scalar",label:"domain",key:"domain"},{kind:"scalar",label:"week (chantier)",key:"week_number"},{kind:"scalar",label:"provider",key:"provider"},{kind:"scalar",label:"tier",key:"tier"},{kind:"scalar",label:"complexity",key:"complexity"},{kind:"abstraction"},{kind:"scalar",label:"action verb",key:"action_verb"},{kind:"scalar",label:"composability",key:"composability"},{kind:"scalar",label:"specificity",key:"specificity"},{kind:"scalar",label:"input type",key:"input_type"},{kind:"scalar",label:"output format",key:"output_format"},{kind:"scalar",label:"dependency type",key:"dependency_type"},{kind:"scalar",label:"interaction mode",key:"interaction_mode"}],r=[];let i=11;for(const a of n)if(a.kind==="scalar"){const{counts:o,covered:l}=Uo(t,a.key),c=a.key==="week_number"?{mode:"chantier_week"}:a.key==="audit_phase"?{mode:"audit_phase"}:{mode:"scalar",key:a.key},d=Ls(a.label,o,l,Es,i++,c);d&&r.push(d)}else{const o=Wo(t),l=Ls("abstraction (from tags)",o.counts,o.covered,Es,i++,{mode:"abstraction"});l&&r.push(l)}return r}function Xo(t){const e=t.filter(r=>(r.node_type||"").trim()==="Platform");if(e.length===0)return null;const n=e.map(r=>{const i=(r.label||r.id).trim();return{swatch:tr(`platform-hull:${r.id}`,42),label:`Ship · ${i}`,facetFilter:{kind:"platform_hull",platformId:r.id}}});return{title:`Ship hull (≤${ei} hops)`,rows:n}}function fi(t,e,n){const r=n==="all",i=t.filter(bi),a=t.filter(Z=>!bi(Z)),o=Ko(i),l=Zo(e),c=r?[...new Set(a.map(Ki))].sort((Z,j)=>Z.localeCompare(j,void 0,{sensitivity:"base"})):[...new Set(a.map(Vi))].sort((Z,j)=>Z.localeCompare(j,void 0,{sensitivity:"base"})),d=new Map,h=new Map;c.forEach((Z,j)=>{d.set(Z,tr(Z)),h.set(Z,j)});const p=[...new Set(e.map(Z=>(Z.label??"").trim()).filter(Z=>Z.length>0))].sort((Z,j)=>Z.localeCompare(j,void 0,{sensitivity:"base"})),m=new Map;for(const Z of p)m.set(Z,tr(Z,7));const k=$o(a,r?Ki:Vi);function C(Z){return r?Ki(Z):Vi(Z)}function _(Z){if(bi(Z))return Vo(Z);const j=C(Z),ae=d.get(j)??tr(j),ce=h.get(j)??0;let de=6.6+_i(j)%5*.55,W=4+ce%8;const N=(Z.node_type||"").trim();return N==="Platform"?(de=Math.max(de,17),W=Math.max(W,24)):(N==="OTSystem"||N==="ITSystem"||N==="Emitter"||N==="Network")&&(de=Math.max(de,11),W=Math.max(W,14)),{color:ae,labelColor:"#f8fafc",size:de,zIndex:W}}function v(Z){if(Z==null)return Ms;const j=Z.trim();return j===""?Ms:m.get(j)??tr(j,7)}const P=[],E=Yo(t),B=E.length>0&&i.length>0;if(i.length>0&&(n==="ai-act"||n==="all")&&P.push({title:Wn("AI Act (node tiers)",i.length),rows:ti.map((Z,j)=>({swatch:Z.fills[0],label:Wn(Z.name,o[j]??0)}))}),B&&P.push(...E),r){if(c.length>0){const Z=a.length,ae=c.slice(0,ui).map(ce=>({swatch:d.get(ce)??tr(ce),label:Wn(ce,k.get(ce)??0)}));if(c.length>ui){const de=c.slice(ui).reduce((W,N)=>W+(k.get(N)??0),0);ae.push({swatch:"#64748b",label:`… +${c.length-ui} more namespaces (${de} nodes)`})}P.push({title:Wn("Ontologies (node colour = prefix)",Z),rows:ae})}if(p.length>0){const Z=e.length,j=p.slice(0,zo),ae=j.map(de=>({swatch:m.get(de)??tr(de,7),label:Wn(de,l.get(de)??0)})),ce=p.length-j.length;ce>0&&ae.push({swatch:"#64748b",label:`… +${ce} more relation types — pick one ontology to list only those`}),P.push({title:Wn(`Relations (sample of ${p.length} types)`,Z),rows:ae})}P.push({title:"Tip",rows:[{swatch:"#334155",label:"Choose an ontology in the header for full types & relations"}]})}else{if(c.length>0){const Z=a.length,ae=c.slice(0,di).map(de=>({swatch:d.get(de)??tr(de),label:Wn(de,k.get(de)??0)}));if(c.length>di){const W=c.slice(di).reduce((N,G)=>N+(k.get(G)??0),0);ae.push({swatch:"#64748b",label:`… +${c.length-di} more schema / type keys (${W} nodes)`})}const ce=n==="_none"?"Nodes (schema / type)":`Nodes — ${n} (schema_id / type)`;P.push({title:Wn(ce,Z),rows:ae})}if(p.length>0){const Z=e.length,ae=p.slice(0,hi).map(ce=>({swatch:m.get(ce)??tr(ce,7),label:Wn(ce,l.get(ce)??0)}));if(p.length>hi){const de=p.slice(hi).reduce((W,N)=>W+(l.get(N)??0),0);ae.push({swatch:"#64748b",label:`… +${p.length-hi} more edge labels (${de} edges)`})}P.push({title:Wn("Relations (edge labels)",Z),rows:ae})}}const V=Xo(t);if(V)if(r){const Z=P.findIndex(j=>j.title==="Tip");Z>=0?P.splice(Z,0,V):P.push(V)}else P.push(V);if(E.length>0&&!B)if(r){const Z=P.findIndex(j=>j.title==="Tip");Z>=0?P.splice(Z,0,...E):P.push(...E)}else P.push(...E);return{styleNode:_,edgeColor:v,legendSections:P}}const Jo=["BELONGS_TO_DOMAIN","PART_OF","BELONGS_TO","REQUIRES_TOOL","HAS_SKILL","IMPLEMENTS_PATTERN"],Qo=new Set(Jo);function qo(t){const e=(t??"").trim();return Qo.has(e)}async function*el(t){if(!t.body)throw new Error("Response body is null");const e=t.body.pipeThrough(new TextDecoderStream).getReader();let n="";try{for(;;){const{value:i,done:a}=await e.read();if(a)break;n+=i;let o;for(;(o=n.indexOf(`
4
- `))!==-1;){const l=n.slice(0,o).trim();n=n.slice(o+1),l&&(yield JSON.parse(l))}}const r=n.trim();r&&(yield JSON.parse(r))}finally{e.releaseLock()}}function es(t){if(!t)return{};if(typeof t=="object"&&!Array.isArray(t))return t;if(typeof t!="string")return{};try{const e=JSON.parse(t);return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function tl(t){return t.entity&&typeof t.entity=="object"?t.entity:t}function Hs(t){const e=tl(t),n=String(e.entity_id??e.id??e.node_id??""),r=es(e.metadata??e.metadata_json),i=es(e.facets??e.facets_json),a=String(e.entity_type??e.node_type??e.type??"");return{id:n,label:String(e.name??e.label??r.label??n),node_type:a||null,schema_id:a||null,facets:{...r,...i,workspace_id:e.workspace_id??r.workspace_id,entity_type:a}}}function nl(t){const e=Number(t);return!Number.isFinite(e)||e<=0?null:new Date(e*1e3).toISOString().slice(0,10)}function rl(t,e=[]){const r=[String(t.relation_type??t.label??"relation")];for(const o of e){const l=String(o.property_key??o.key??""),c=o.property_value??o.value;l&&c!=null&&c!==""&&r.push(`${l}=${c}`)}const i=es(t.metadata_json);i.quotePart!=null&&r.push(`quote=${i.quotePart}`),i.status!=null&&r.push(String(i.status));const a=nl(t.valid_from_unix);return a&&r.push(`from ${a}`),r.join(" · ")}function il(t,e){const n=t.relation&&typeof t.relation=="object"?t.relation:t,r=String(n.relation_id??n.id??n.edge_id??""),i=String(n.source_id??n.source??n.source_entity_id??""),a=String(n.target_id??n.target??n.target_entity_id??""),o=Array.isArray(e?.properties)?e.properties:Array.isArray(n.properties)?n.properties:[],l={};for(const c of o){const d=String(c.property_key??c.key??"");d&&(l[d]=c.property_value??c.value)}return{id:r,source:i,target:a,label:rl(n,o),weight:n.confidence==null?null:Number(n.confidence),properties:Object.keys(l).length>0?l:void 0,relationMeta:n}}function sl(t){const e=t.kind;if(typeof e=="string"&&e.length>0&&!e.startsWith("."))return e;const n=t.payload??{};return n.relation?"edge":n.entity?n.depth==null?"seed_node":"node":n.kind==="subgraph"?"done":""}function al(t){const e=new Map,n=new Map;for(const o of t){const l=o.payload??{},c=sl(o);if(c!=="done"){if(c==="seed_node"||c==="node"){const d=Hs(l);d.id&&e.set(d.id,d);continue}if(c==="edge"){const d=il(l,l);d.id&&d.source&&d.target&&n.set(d.id,d);for(const h of["source","target"]){const p=l[h];if(p&&typeof p=="object"){const m=Hs(p);m.id&&e.set(m.id,m)}}}}}const r=[...e.values()],i=new Set(r.map(o=>o.id)),a=[...n.values()].filter(o=>i.has(o.source)&&i.has(o.target));return{nodes:r,edges:a,sourceUsed:"graph"}}var ol=D('<span class="stream-sep svelte-11bec40">·</span> <span class="stream-nums svelte-11bec40"> </span> <span class="stream-sep svelte-11bec40">·</span> <span class="stream-status svelte-11bec40">streaming…</span>',1),ll=D('<span class="stream-sep svelte-11bec40">·</span> <span class="stream-status svelte-11bec40">loading edges…</span>',1),cl=D('<span class="stream-sep svelte-11bec40">·</span> <span class="stream-status svelte-11bec40">streaming…</span>',1),dl=D('<span class="stream-nums svelte-11bec40"> </span> <!>',1),hl=D('<span class="stream-nums svelte-11bec40"> </span> <span class="stream-sep svelte-11bec40">·</span> <span class="stream-status stream-status--done svelte-11bec40">ready</span>',1),ul=D('<div role="status" aria-live="polite" aria-label="Graph loading progress"><div class="stream-track svelte-11bec40"><div class="stream-fill svelte-11bec40"></div></div> <span class="stream-label svelte-11bec40"><!></span></div>'),fl=D('<div class="focus-bar svelte-11bec40" role="status"><span class="svelte-11bec40">Focus</span> <span class="focus-text svelte-11bec40"> </span> <span class="focus-reset svelte-11bec40">Click background to reset</span></div>'),gl=D('<div class="source-hint svelte-11bec40" role="status"> </div>'),vl=D('<div class="overlay svelte-11bec40">Loading graph…</div>'),pl=D('<div class="overlay svelte-11bec40">No nodes to display (try another ontology, workspace, or source mode).</div>'),yl=D('<div class="overlay error svelte-11bec40"><strong>Graph load failed</strong> <p class="svelte-11bec40"> </p></div>'),ml=D('<div class="wrap svelte-11bec40"><div class="canvas svelte-11bec40" aria-label="Knowledge graph visualization"></div> <!> <!> <!> <!> <!> <!></div>');function _l(t,e){Nn(e,!0);const n=Number.POSITIVE_INFINITY,r=.5,i=3e3;let a=null;function o(){return a||(a=Promise.all([Yn(()=>import("../chunks/-OSExkSk.js"),__vite__mapDeps([0,1,2,3]),import.meta.url),Yn(()=>import("../chunks/Gs0cNFYG.js"),__vite__mapDeps([4,2]),import.meta.url),Yn(()=>import("../chunks/DyXQogav.js").then($=>$.i),__vite__mapDeps([5,3]),import.meta.url),Yn(()=>import("../chunks/Cp9dXlPT.js").then($=>$.i),__vite__mapDeps([6,3,7]),import.meta.url),Yn(()=>import("../chunks/BVrgUHq-.js").then($=>$.w),__vite__mapDeps([8,3,7]),import.meta.url),Yn(()=>import("../chunks/CBDzfqXr.js"),__vite__mapDeps([9,1]),import.meta.url)]).then(([$,Y,ge,Me,Ye,_e])=>({Sigma:$.default,DirectedGraph:Y.DirectedGraph,layoutMod:ge,forceAtlas2:Me.default,FA2LayoutCtor:Ye.default,drawDarkDiscNodeHover:_e.drawDarkDiscNodeHover}))),a}function l($,Y,ge){if(Y<=i)return()=>{};const Me=$.getCamera();let Ye=!1;const _e=()=>{const Oe=Me.ratio>r;Oe!==Ye&&(Ye=Oe,!s(he)&&!j()&&$.setSettings({edgeReducer:Oe?(Xe,it)=>({...it,hidden:!0}):null,labelRenderedSizeThreshold:Oe?8:ge?3:4}))};return Me.on("updated",_e),()=>Me.removeListener("updated",_e)}let c=K(e,"ontologyKey",3,"all"),d=K(e,"providerKey",3,null),h=K(e,"layoutTemplate",3,"circular_force"),p=K(e,"dbKey",3,"default"),m=K(e,"edgeLinkMode",3,"all"),k=K(e,"expandHops",3,0),C=K(e,"focusCompositionOnly",3,!1),_=K(e,"graphSource",3,"auto"),v=K(e,"workspaceId",3,null),P=K(e,"scenarioId",3,null),E=K(e,"topK",3,30),B=K(e,"groupByDimension",3,null),V=K(e,"dataSource",3,"sqlite-demo"),Z=K(e,"brainSeedIds",19,()=>[]),j=K(e,"facetFilter",15,null),ae=K(e,"legendBlocks",31,()=>$t([]));const ce=2,de={renderEdgeLabels:!0,edgeLabelSize:10,edgeLabelWeight:"400",edgeLabelColor:{color:"#cbd5e1"}},W=120;function N($){return{labelDensity:$?.14:.09,labelRenderedSizeThreshold:$?3:4}}function G(){return{labelDensity:1,labelRenderedSizeThreshold:0}}function O($,Y,ge){return{label:$??"",size:Math.max(1.2,Math.min(2.8,(Y??1)*.35)),color:ge,forceLabel:!0,labelColor:"#cbd5e1"}}let X=A(null);De(()=>{ae(s(X)?.plan?.legendSections??[])});let ue=be(()=>s(X)?.nodes??[]),fe=be(()=>s(X)?.edges??[]),Se=be(()=>new Map(s(ue).map($=>[$.id,$]))),se=be(()=>new Map(s(fe).map($=>[$.id,$]))),he=A(null),xe=A(null);De(()=>{const $=j();if($){if($.kind==="platform_hull"){u(he,null);return}s(he)&&s(ue).length>0&&(Os(s(ue),s(fe),$).has(s(he))||u(he,null))}});let Ce=A(null),nt=A(null),ke=A(void 0),U=A("loading"),me=A(null),ve=null,Ze=A(null),Le=A(!1),Be=A(null),Ge=A($t({nodes:0,edges:0})),Je=A(!1),Ke=!1,yt=be(()=>s(Be)&&s(Be).nodeCount>0?Math.min(100,Math.round(s(Ge).nodes/s(Be).nodeCount*100)):0),ut=be(()=>s(Be)?s(Be).edgeCount>0?Math.round((s(Ge).nodes*.3+s(Ge).edges*.7)/(s(Be).nodeCount*.3+s(Be).edgeCount*.7)*100):s(yt):0);function tt($,Y){return $===Y?!0:!$||!Y||$.kind!==Y.kind?!1:$.kind==="scalar"&&Y.kind==="scalar"?$.key===Y.key&&$.value===Y.value:$.kind==="platform_hull"&&Y.kind==="platform_hull"?$.platformId===Y.platformId:$.kind==="abstraction"&&Y.kind==="abstraction"?$.value===Y.value:$.kind==="chantier_week_neighborhood"&&Y.kind==="chantier_week_neighborhood"?$.week===Y.week:$.kind==="audit_phase_neighborhood"&&Y.kind==="audit_phase_neighborhood"?$.phase===Y.phase:!1}function Fe($){const Y=s(Se).get($);if(!Y||Y.node_type!=="AuditRun")return null;const ge=Y.facets;if(ge==null||typeof ge!="object"||Array.isArray(ge))return null;const Me=String(ge.audit_phase??"").trim();return!Me||Me.includes("_to_")?null:{kind:"audit_phase_neighborhood",phase:Me}}function qe($){if(s(he)===$){u(he,null);const Ye=Fe($);Ye&&tt(j(),Ye)&&j(null);return}u(he,$,!0);const Y=s(Se).get($),ge=Number.parseInt($,10);Number.isFinite(ge)&&e.onSelect?.({kind:"entity",entityId:ge,entityType:Y?.node_type??"",label:Y?.label??$});const Me=Fe($);Me&&j(Me)}function lt($){const Y=s(se).get($),ge=Number.parseInt($,10);Number.isFinite(ge)&&e.onSelect?.({kind:"relation",relationId:ge,relationType:Y?.label??""})}function L($){return $==="all"?null:$.toLowerCase().startsWith("type:")?$.slice(5):$}async function ne($,Y,ge,Me){let Ye=Y.filter(it=>Number.isFinite(it)&&it>0);if(Ye.length===0){const it=new URLSearchParams({workspace_id:$,limit:String(ge??30)});Me&&it.set("entity_type",Me);const Ve=await fetch(`/api/brain/ghostcrab/graph-search?${it}`);if(!Ve.ok)throw new Error(await Ve.text());Ye=((await Ve.json()).rows??[]).map(w=>Number(w.entity_id)).filter(w=>Number.isFinite(w))}if(Ye.length===0)return{nodes:[],edges:[],sourceUsed:"graph"};const _e=new URLSearchParams({workspace_id:$,seed_ids:Ye.slice(0,30).join(","),hops:"2",format:"json"});Me&&_e.set("entity_type",Me);const Oe=await fetch(`/api/brain/graph/subgraph?${_e}`);if(!Oe.ok)throw new Error(await Oe.text());const Xe=await Oe.json();return al(Xe)}function H(){u(he,null),j(null)}De(()=>{const $=c(),Y=d(),ge=p(),Me=m(),Ye=k(),_e=P()?.trim()||null,Oe=E(),Xe=V(),it=Z().filter(Ee=>Number.isFinite(Ee)).sort((Ee,Ae)=>Ee-Ae),Ve=it.join(","),I=_e?"graph":_(),w=v()?.trim()||null,z=w??"default";let ie=!1;return u(X,null),u(he,null),j(null),u(Ze,null),u(U,"loading"),u(me,null),u(nt,null),u(Le,!1),u(Be,null),u(Ge,{nodes:0,edges:0},!0),u(Je,!1),o().catch(()=>{}),(async()=>{try{const Ee=new URLSearchParams;if($!=="all"&&Ee.set("ontology",$),ge!=="default"&&Ee.set("db",ge),Y&&Ee.set("provider",Y),Me!=="all"&&Ee.set("linkMode",Me),Ye>0&&Ee.set("expandHops",String(Ye)),I!=="auto"&&Ee.set("source",I),w&&Ee.set("workspace",w),_e&&Ee.set("scenarioId",_e),Oe==null||Oe<=0?Ee.set("topK","none"):Ee.set("topK",String(Oe)),s(Ce)?.ontology===$&&s(Ce)?.db===ge&&s(Ce)?.provider===Y&&s(Ce)?.linkMode===Me&&s(Ce)?.expandHops===Ye&&s(Ce)?.graphSource===I&&s(Ce)?.workspaceId===w&&s(Ce)?.scenarioId===_e&&s(Ce)?.topK===Oe&&s(Ce)?.dataSource===Xe&&s(Ce)?.brainSeedKey===Ve){const ct=s(Ce).payload;if(ie)return;T(ct,$,()=>ie);return}if(Xe==="brain"){const ct=await ne(z,it,Oe,L($));if(ie)return;u(Ce,{db:ge,ontology:$,provider:Y,linkMode:Me,expandHops:Ye,graphSource:I,workspaceId:w,scenarioId:_e,topK:Oe,dataSource:Xe,brainSeedKey:Ve,payload:ct},!0),T(ct,$,()=>ie);return}const Ae=new URLSearchParams(Ee);let Ne=!1;try{const ct=await fetch(`/api/graph/count?${Ae}`);ct.ok&&!ie&&(Ne=(await ct.json()).nodeCount>n)}catch{}if(ie)return;if(!Ne){const ct=new URLSearchParams(Ee),dt=await fetch(`/api/graph?${ct}`);if(ie)return;if(!dt.ok){const Et=await dt.text();throw new Error(Et||`HTTP ${dt.status}`)}const Nt=await dt.json();if(u(Ce,{db:ge,ontology:$,provider:Y,linkMode:Me,expandHops:Ye,graphSource:I,workspaceId:w,scenarioId:_e,topK:Oe,dataSource:Xe,brainSeedKey:Ve,payload:Nt},!0),ie)return;T(Nt,$,()=>ie);return}u(Le,!0),u(Je,!1),u(Ge,{nodes:0,edges:0},!0);const $e=new URLSearchParams(Ee);$e.set("topK","30");const Ue=await fetch(`/api/graph/stream?${$e}`);if(ie)return;if(!Ue.ok){const ct=await Ue.text();throw new Error(ct||`HTTP ${Ue.status}`)}const y=[],je=[];let St=null,te=Date.now(),le=null,rt=null,ft=!1;for await(const ct of el(Ue)){if(ie)break;if(ct.type==="meta")St=ct,u(Be,{nodeCount:St.nodeCount,edgeCount:St.edgeCount,sourceUsed:St.sourceUsed},!0);else if(ct.type==="node"){const dt=ct;y.push({id:dt.id,label:dt.label,node_type:dt.node_type,schema_id:dt.schema_id,facets:dt.facets});const Nt=Date.now();if(Nt-te>120&&(u(Ge,{nodes:y.length,edges:0},!0),te=Nt),!ft&&St&&y.length>=St.nodeCount&&!ie){if(ft=!0,u(Ge,{nodes:y.length,edges:0},!0),y.length===0)continue;rt=fi(y,[],$);const Et=await o();if(ie)break;const Pn=s(ke);if(!Pn)break;ve?.kill(),ve=null,u(xe,null),le=new Et.DirectedGraph;const at=new Map(y.map(xt=>[xt.id,xt]));for(const xt of y){const nn=(xt.label?.trim()||xt.id).slice(0,80),Rt=rt.styleNode(xt);le.addNode(xt.id,{label:nn,size:Rt.size,x:0,y:0,color:Rt.color,labelColor:Rt.labelColor,zIndex:Rt.zIndex})}const At=B()?.trim()||null,dn=At?xt=>{const Rt=at.get(xt)?.facets;if(Rt==null||typeof Rt!="object"||Array.isArray(Rt))return null;const bt=Rt[At];return bt==null?null:String(bt).trim()||null}:void 0;let Qt=ji(le,Et.layoutMod,Et.FA2LayoutCtor,Et.forceAtlas2,h(),dn);if(ie){Qt();break}const Ft=(St.sourceUsed??"mfo")==="graph";ve=new Et.Sigma(le,Pn,{renderLabels:!0,defaultNodeColor:"#94a3b8",defaultEdgeColor:"#64748b",labelDensity:Ft?.14:.09,zIndex:!0,labelSize:Ft?14:13,labelWeight:"500",labelColor:{attribute:"labelColor",color:"#f1f5f9"},labelRenderedSizeThreshold:Ft?3:4,defaultDrawNodeHover:Et.drawDarkDiscNodeHover,...de}),ve.on("clickNode",({node:xt})=>{qe(xt)}),ve.on("clickEdge",({edge:xt})=>{lt(xt)}),ve.on("clickStage",()=>{H()}),l(ve,y.length,Ft),u(nt,Ft?"GhostCrab PERSO SQLite":"Legacy graph source",!0),u(xe,{graph:le,sigma:ve},!0),u(U,"ready"),Ke=!0}}else if(ct.type==="edge"){const dt=ct;if(je.push({id:dt.id,source:dt.source,target:dt.target,label:dt.label,weight:dt.weight}),le&&rt)try{le.hasNode(dt.source)&&le.hasNode(dt.target)&&!le.hasEdge(dt.id)&&le.addEdgeWithKey(dt.id,dt.source,dt.target,{...O(dt.label,dt.weight,rt.edgeColor(dt.label))})}catch{}const Nt=Date.now();Nt-te>200&&(u(Ge,{nodes:y.length,edges:je.length},!0),te=Nt)}}if(ie){u(Le,!1);return}if(u(Ge,{nodes:y.length,edges:je.length},!0),y.length===0){u(U,"empty"),u(Le,!1);return}if(!ft){const ct=St?.sourceUsed??"mfo";u(nt,ct==="mfo"?"Legacy graph source":"GhostCrab PERSO SQLite",!0);const dt=fi(y,je,$);if(ie){u(Le,!1);return}const{Sigma:Nt,DirectedGraph:Et,layoutMod:Pn,forceAtlas2:at,FA2LayoutCtor:At,drawDarkDiscNodeHover:dn}=await o();if(ie){u(Le,!1);return}const Qt=s(ke);if(!Qt){u(Le,!1);return}ve?.kill(),ve=null,u(xe,null),le=new Et;const hn=new Map(y.map(bt=>[bt.id,bt]));for(const bt of y){const pn=(bt.label?.trim()||bt.id).slice(0,80),Xt=dt.styleNode(bt);le.addNode(bt.id,{label:pn,size:Xt.size,x:0,y:0,color:Xt.color,labelColor:Xt.labelColor,zIndex:Xt.zIndex})}for(const bt of je)if(!(!le.hasNode(bt.source)||!le.hasNode(bt.target)))try{le.addEdgeWithKey(bt.id,bt.source,bt.target,O(bt.label,bt.weight,dt.edgeColor(bt.label)))}catch{}const Ft=B()?.trim()||null,xt=Ft?bt=>{const Xt=hn.get(bt)?.facets;if(Xt==null||typeof Xt!="object"||Array.isArray(Xt))return null;const bn=Xt[Ft];return bn==null?null:String(bn).trim()||null}:void 0;let nn=ji(le,Pn,At,at,h(),xt);if(ie){nn(),u(Le,!1);return}const Rt=ct==="graph";ve=new Nt(le,Qt,{renderLabels:!0,defaultNodeColor:"#94a3b8",defaultEdgeColor:"#64748b",labelDensity:Rt?.14:.09,zIndex:!0,labelSize:Rt?14:13,labelWeight:"500",labelColor:{attribute:"labelColor",color:"#f1f5f9"},labelRenderedSizeThreshold:Rt?3:4,defaultDrawNodeHover:dn,...de}),ve.on("clickNode",({node:bt})=>{qe(bt)}),ve.on("clickEdge",({edge:bt})=>{lt(bt)}),ve.on("clickStage",()=>{H()}),l(ve,y.length,Rt),u(xe,{graph:le,sigma:ve},!0),u(U,"ready"),Ke=!0,rt=dt}if(ie)return;if(le&&rt){const ct=fi(y,je,$);for(const Nt of y)if(le.hasNode(Nt.id)){const Et=ct.styleNode(Nt);le.setNodeAttribute(Nt.id,"size",Et.size),le.setNodeAttribute(Nt.id,"color",Et.color)}u(xe,le&&ve?{graph:le,sigma:ve}:s(xe),!0);const dt=St?.sourceUsed??"mfo";u(Ge,{nodes:y.length,edges:je.length},!0),u(Je,!0),u(Ce,{db:ge,ontology:$,provider:Y,linkMode:Me,expandHops:Ye,graphSource:I,workspaceId:w,scenarioId:_e,topK:Oe,dataSource:Xe,brainSeedKey:Ve,payload:{nodes:y,edges:je,sourceUsed:dt}},!0),Ke=!0,u(X,{nodes:y,edges:je,plan:ct,sourceUsed:dt,ontology:$},!0)}setTimeout(()=>{ie||u(Le,!1)},1800)}catch(Ee){if(ie)return;u(U,"error"),u(Le,!1),u(me,Ee instanceof Error?Ee.message:String(Ee),!0)}})(),()=>{ie=!0,s(Le)&&ve&&!s(X)&&(ve.kill(),ve=null,u(xe,null)),u(Le,!1)}});function T($,Y,ge){$.sourceUsed==="mfo"?u(nt,"Legacy graph source"):$.sourceUsed==="graph"?u(nt,V()==="brain"?"MindBrain live graph":"GhostCrab PERSO SQLite",!0):u(nt,null);const Me=$.nodes??[],Ye=$.edges??[];if(Me.length===0){u(nt,null),u(U,"empty");return}const _e=fi(Me,Ye,Y);ge()||u(X,{nodes:Me,edges:Ye,plan:_e,sourceUsed:$.sourceUsed,ontology:Y},!0)}De(()=>{const $=s(ke),Y=s(X),ge=h(),Me=B()?.trim()||null;if(Ke){Ke=!1;return}if(ve?.kill(),ve=null,u(xe,null),!$||!Y)return;const{nodes:Ye,edges:_e,plan:Oe}=Y;let Xe=!1,it=null,Ve=()=>{};return(async()=>{try{const{Sigma:I,DirectedGraph:w,layoutMod:z,forceAtlas2:ie,FA2LayoutCtor:Ee,drawDarkDiscNodeHover:Ae}=await o();if(Xe)return;const Ne=new w,$e=new Map(Ye.map(je=>[je.id,je]));for(const je of Ye){const St=(je.label?.trim()||je.id).slice(0,80),te=Oe.styleNode(je);Ne.addNode(je.id,{label:St,size:te.size,x:0,y:0,color:te.color,labelColor:te.labelColor,zIndex:te.zIndex})}for(const je of _e)if(!(!Ne.hasNode(je.source)||!Ne.hasNode(je.target)))try{Ne.addEdgeWithKey(je.id,je.source,je.target,O(je.label,je.weight,Oe.edgeColor(je.label)))}catch{}if(it=ji(Ne,z,Ee,ie,ge,Me?je=>{const te=$e.get(je)?.facets;if(te==null||typeof te!="object"||Array.isArray(te))return null;const le=te[Me];return le==null?null:String(le).trim()||null}:void 0),Xe){it?.();return}const y=Y.sourceUsed==="graph";ve=new I(Ne,$,{renderLabels:!0,defaultNodeColor:"#94a3b8",defaultEdgeColor:"#64748b",labelDensity:y?.14:.09,zIndex:!0,labelSize:y?14:13,labelWeight:"500",labelColor:{attribute:"labelColor",color:"#f1f5f9"},labelRenderedSizeThreshold:y?3:4,defaultDrawNodeHover:Ae,...de}),ve.on("clickNode",({node:je})=>{qe(je)}),ve.on("clickEdge",({edge:je})=>{lt(je)}),ve.on("clickStage",()=>{H()}),Ve=l(ve,Ne.order,y),u(xe,{graph:Ne,sigma:ve},!0),u(U,"ready")}catch(I){if(Xe)return;u(U,"error"),u(me,I instanceof Error?I.message:String(I),!0)}})(),()=>{Xe=!0,Ve(),it?.(),it=null,u(xe,null),ve?.kill(),ve=null}}),De(()=>{const $=s(xe);if(!$?.sigma)return;const{graph:Y,sigma:ge}=$,Me=s(he),Ye=C(),_e=j(),Oe=s(ue),Xe=s(fe),it=_e?.kind==="platform_hull",Ve=_e&&Oe.length>0?Os(Oe,Xe,_e):null,I=Me!=null&&Y.hasNode(Me),w=!it&&I&&Me!=null?Ao(Y,Me,ce):null;if(!Ve&&!I){u(Ze,null);const Ne=s(X)?.sourceUsed==="graph";ge.setSettings({nodeReducer:null,edgeReducer:null,...N(Ne)});return}const z=Ve&&w?[...w].filter(Ne=>Ve.has(Ne)).length:Ve?Ve.size:w?w.size:Y.order,ie=z>0&&z<=W,Ee=s(X)?.sourceUsed==="graph",Ae=ie?G():N(Ee);if(I&&Me!=null&&w){const Ne=Y.getNodeAttribute(Me,"label"),$e=typeof Ne=="string"&&Ne.trim()?Ne.trim():Me,Ue=Ye?" · composition edges":"";let y=`${$e} · ${w.size} nodes (≤${ce} hops)${Ue}`;if(Ve&&_e){const je=[...w].filter(te=>Ve.has(te)).length,St=_e.kind==="scalar"?`${_e.key}=${_e.value}`:_e.kind==="abstraction"?`abstraction=${_e.value}`:_e.kind==="chantier_week_neighborhood"?`demo_week=${_e.week} (≤${Lr} hops)`:_e.kind==="audit_phase_neighborhood"?`audit_phase=${_e.phase}`:`hull=${_e.platformId}`;y+=` · facet ${St} · ${je} nodes in both`}u(Ze,y,!0)}else if(Ve&&_e)if(_e.kind==="platform_hull"){const $e=(s(Se).get(_e.platformId)?.label||_e.platformId).trim();u(Ze,`Ship hull · ${$e} · ≤${ei} hops · ${Ve.size} nodes — click row again to clear`)}else{const Ne=_e.kind==="scalar"?`${_e.key}=${_e.value}`:_e.kind==="chantier_week_neighborhood"?`demo_week=${_e.week} (≤${Lr} hops)`:_e.kind==="audit_phase_neighborhood"?`audit_phase=${_e.phase}`:`abstraction=${_e.value}`;u(Ze,`Facet · ${Ne} · ${Ve.size} nodes — click row again to clear`)}else u(Ze,null);ge.setSettings({...Ae,nodeReducer:(Ne,$e)=>{let Ue=!1;return Ve&&!Ve.has(Ne)&&(Ue=!0),!Ue&&w&&!w.has(Ne)&&(Ue=!0),Ue?{...$e,hidden:!0}:ie?{...$e,hidden:!1,forceLabel:!0}:{...$e,hidden:!1}},edgeReducer:(Ne,$e)=>{const[Ue,y]=Y.extremities(Ne);let je=!1;return Ve&&(!Ve.has(Ue)||!Ve.has(y))&&(je=!0),!je&&w&&(!w.has(Ue)||!w.has(y))&&(je=!0),!je&&Ye&&I&&!qo(String($e.label??""))&&(je=!0),je?{...$e,hidden:!0}:{...$e,hidden:!1}}})});var R=ml(),J=g(R);Qr(J,$=>u(ke,$),()=>s(ke));var Q=b(J,2);{var Pe=$=>{var Y=ul();let ge;var Me=g(Y),Ye=g(Me);let _e;f(Me);var Oe=b(Me,2),Xe=g(Oe);{var it=I=>{var w=dl(),z=et(w),ie=g(z);f(z);var Ee=b(z,2);{var Ae=Ue=>{var y=ol(),je=b(et(y),2),St=g(je);f(je),Yt(4),ee(te=>F(St,`${te??""} edges`),[()=>s(Ge).edges.toLocaleString()]),x(Ue,y)},Ne=Ue=>{var y=ll();Yt(2),x(Ue,y)},$e=Ue=>{var y=cl();Yt(2),x(Ue,y)};q(Ee,Ue=>{s(Ge).edges>0?Ue(Ae):s(Ge).nodes>=s(Be).nodeCount?Ue(Ne,1):Ue($e,-1)})}ee((Ue,y)=>F(ie,`${Ue??""}/${y??""} nodes`),[()=>s(Ge).nodes.toLocaleString(),()=>s(Be).nodeCount.toLocaleString()]),x(I,w)},Ve=I=>{var w=hl(),z=et(w),ie=g(z);f(z),Yt(4),ee((Ee,Ae)=>F(ie,`${Ee??""} nodes · ${Ae??""} edges`),[()=>s(Be).nodeCount.toLocaleString(),()=>s(Ge).edges.toLocaleString()]),x(I,w)};q(Xe,I=>{s(Je)?I(Ve,-1):I(it)})}f(Oe),f(Y),ee(()=>{ge=st(Y,1,"stream-bar svelte-11bec40",null,ge,{"stream-bar--complete":s(Je)}),_e=rr(Ye,"",_e,{width:`${s(ut)??""}%`})}),x($,Y)};q(Q,$=>{s(Le)&&s(Be)&&$(Pe)})}var Ie=b(Q,2);{var pe=$=>{var Y=fl(),ge=b(g(Y),2),Me=g(ge,!0);f(ge),Yt(2),f(Y),ee(()=>F(Me,s(Ze))),x($,Y)};q(Ie,$=>{s(Ze)&&$(pe)})}var ye=b(Ie,2);{var M=$=>{var Y=gl(),ge=g(Y);f(Y),ee(()=>F(ge,`Source: ${s(nt)??""}`)),x($,Y)};q(ye,$=>{s(U)==="ready"&&s(nt)&&$(M)})}var re=b(ye,2);{var oe=$=>{var Y=vl();x($,Y)};q(re,$=>{s(U)==="loading"&&!s(Le)&&$(oe)})}var Te=b(re,2);{var we=$=>{var Y=pl();x($,Y)};q(Te,$=>{s(U)==="empty"&&$(we)})}var He=b(Te,2);{var Qe=$=>{var Y=yl(),ge=b(g(Y),2),Me=g(ge,!0);f(ge),f(Y),ee(()=>F(Me,s(me))),x($,Y)};q(He,$=>{s(U)==="error"&&$(Qe)})}f(R),x(t,R),Dn()}const Un={concreteClass:"#38bdf8",abstractClass:"#64748b",concreteLabel:"#f0f9ff",abstractLabel:"#cbd5e1",relationEdge:"#a78bfa",relationLabel:"#ede9fe",isAEdge:"#475569",isALabel:"#94a3b8"},bl=[{swatch:Un.concreteClass,label:"Concrete class"},{swatch:Un.abstractClass,label:"Abstract mixin"},{swatch:Un.relationEdge,label:"Relation type"},{swatch:Un.isAEdge,label:"Inheritance (is_a)",dashed:!0}];function kl(t){const e=t.abstract||t.synthetic;return{color:e?Un.abstractClass:Un.concreteClass,labelColor:e?Un.abstractLabel:Un.concreteLabel,size:e?10:14,label:t.label||t.typeName,forceLabel:!1,zIndex:e?2:4}}function wl(t){return t.kind==="is_a"?{color:Un.isAEdge,labelColor:Un.isALabel,size:1,label:"is_a",forceLabel:!1,type:"line",zIndex:1,dashed:!0}:{color:Un.relationEdge,labelColor:Un.relationLabel,size:2,label:t.edgeType??t.label,forceLabel:!1,type:"arrow",zIndex:3}}var xl=D('<p class="muted svelte-es94y4">No schema types to display.</p>'),Cl=D('<p class="error svelte-es94y4"> </p>'),Sl=D('<div class="legend-row svelte-es94y4"><span></span> <span class="legend-label svelte-es94y4"> </span></div>'),Nl=D('<div class="schema-graph svelte-es94y4"><div class="sigma-root svelte-es94y4"><!></div> <aside class="legend svelte-es94y4" aria-label="Schema graph legend"></aside></div>');function zs(t,e){Nn(e,!0);let n=K(e,"showEdgeLabels",3,!1),r=A(void 0),i=A("loading"),a=A(null),o=null,l=0;De(()=>{const _=s(r),v=e.nodes,P=e.edges,E=n();if(!_)return;const B=++l;return c(_,v,P,E,B),()=>{l++,o?.kill(),o=null}});async function c(_,v,P,E,B){if(o?.kill(),o=null,u(a,null),v.length===0){u(i,"empty");return}u(i,"loading");try{const[{default:V},{MultiDirectedGraph:Z},j,ae]=await Promise.all([Yn(()=>import("../chunks/-OSExkSk.js"),__vite__mapDeps([0,1,2,3]),import.meta.url),Yn(()=>import("../chunks/Gs0cNFYG.js"),__vite__mapDeps([4,2]),import.meta.url),Yn(()=>import("../chunks/DyXQogav.js").then(N=>N.i),__vite__mapDeps([5,3]),import.meta.url),Yn(()=>import("../chunks/Cp9dXlPT.js").then(N=>N.i),__vite__mapDeps([6,3,7]),import.meta.url)]);if(B!==l||s(r)!==_)return;const ce=new Z,de=new Map(v.map(N=>[N.id,N])),W=new Map;for(const N of v){const G=kl(N);ce.addNode(N.id,{label:G.label,size:G.size,x:0,y:0,color:G.color,labelColor:G.labelColor,forceLabel:G.forceLabel,zIndex:G.zIndex,schemaAbstract:N.abstract||N.synthetic,schemaDomain:typeof N.metadata?.ontology_key=="string"?N.metadata.ontology_key:null})}for(const N of P){if(!ce.hasNode(N.source)||!ce.hasNode(N.target)||ce.hasEdge(N.id))continue;const G=wl(N);W.set(N.id,N);try{ce.addEdgeWithKey(N.id,N.source,N.target,{label:E&&N.importantLabel?G.label:"",size:G.size,color:G.color,labelColor:G.labelColor,forceLabel:E&&N.kind==="relation"&&N.importantLabel,type:"arrow",zIndex:G.zIndex,schemaKind:N.kind})}catch{W.delete(N.id)}}if(Lo(ce,j,ae.default,"circular_force",N=>{const G=ce.getNodeAttribute(N,"schemaDomain");return typeof G=="string"&&G?G:null}),B!==l||s(r)!==_)return;o=new V(ce,_,{renderLabels:!0,renderEdgeLabels:E,labelDensity:.08,labelSize:12,labelWeight:"600",labelColor:{attribute:"labelColor",color:"#f0f9ff"},edgeLabelSize:10,edgeLabelWeight:"500",edgeLabelColor:{attribute:"labelColor",color:"#ede9fe"},labelRenderedSizeThreshold:9,zIndex:!0,defaultEdgeType:"arrow",enableEdgeEvents:!0,allowInvalidContainer:!0,edgeReducer(N,G){return ce.getEdgeAttribute(N,"schemaKind")==="is_a"?{...G,size:1,color:"#475569"}:G}}),o.on("clickNode",({node:N})=>{const G=de.get(N);G&&e.onNodeClick?.(G)}),o.on("clickEdge",({edge:N})=>{const G=W.get(N);G&&e.onEdgeClick?.(G)}),o.refresh(),o.getCamera().animatedReset({duration:0}),u(i,"ready")}catch(V){if(B!==l)return;u(a,V instanceof Error?V.message:String(V),!0),u(i,"error")}}var d=Nl(),h=g(d),p=g(h);{var m=_=>{var v=xl();x(_,v)},k=_=>{var v=Cl(),P=g(v,!0);f(v),ee(()=>F(P,s(a))),x(_,v)};q(p,_=>{s(i)==="empty"?_(m):s(i)==="error"&&s(a)&&_(k,1)})}f(h),Qr(h,_=>u(r,_),()=>s(r));var C=b(h,2);_t(C,21,()=>bl,Mt,(_,v)=>{var P=Sl(),E=g(P);let B,V;var Z=b(E,2),j=g(Z,!0);f(Z),f(P),ee(()=>{B=st(E,1,"swatch svelte-es94y4",null,B,{dashed:s(v).dashed}),V=rr(E,"",V,{background:s(v).dashed?"transparent":s(v).swatch,"border-color":s(v).swatch}),F(j,s(v).label)}),x(_,P)}),f(C),f(d),x(t,d),Dn()}function Dr(t){return`entity_type:${t}`}function Ei(t){return t.metadata.synthetic===!0||t.metadata.abstract===!0}function Dl(t,e){return[...t.classes.values()].filter(n=>!(n.metadata.synthetic&&e||e&&Ei(n)))}function Pl(t){const e=t.metadata??{},n=typeof e.ghostcrab=="object"&&e.ghostcrab?e.ghostcrab:null,i=(typeof n?.["ghostcrab.native_edge_type"]=="string"?n["ghostcrab.native_edge_type"]:null)??(typeof e.linkml_slot=="string"?e.linkml_slot:null)??t.edgeType;return i.includes("contains")?"contains":i}const Il=new Set(["ADDRESSED_TO","APPOINTS","ASSOCIATED_WITH","BELONGS_TO","CLOSES","CONTAINS","DOCUMENTS","HAS_ACCOUNT","HAS_BUDGET","HAS_MEMBER","HAS_OCCUPANT","HAS_OWNER","LINKED_TO","LOCATED_IN","OPENS","OWNED_BY","PART_OF","RECORDED_IN","REFERENCES","REPRESENTS","RESULTS_FROM","TRIGGERS","USES_KEY","VERIFIES","VOTED_ON","contains","belongs_to","bills_to","created_by","has_member","leases","occupies","owns","primary_residence_of","triggers_spend","uses_common","uses_exclusive"]),Tl=["adm_","com_","dec_","exp_","tec_"];function Ml(t){return!t||t==="is_a"||Tl.some(e=>t.startsWith(e))?!1:Il.has(t)?!0:/^[A-Z][A-Z0-9_]+$/.test(t)}function El(t,e){const n=e.classes.get(t);return n?Ei(n):!1}function Al(t,e){return[...t.classes.values()].filter(n=>{if(n.metadata.synthetic||e&&Ei(n)||n.typeName==="Asset")return!1;let r=n.parentTypeName;for(;r;){if(r==="Asset")return!0;r=t.classes.get(r)?.parentTypeName??null}return!1}).map(n=>n.typeName).sort((n,r)=>n.localeCompare(r))}function Rl(t){return t.includes("contains")||t==="uses_common"||t==="uses_exclusive"||t==="part_of"}function Ol(t,e,n){return t.targetType!=="Asset"||!El("Asset",e)||!Rl(t.edgeType)?[t.targetType]:Al(e,n)}function Ll(t,e){const n=Dl(t,e.hideAbstract),r=new Set(n.map(l=>Dr(l.typeName))),i=n.map(l=>({id:Dr(l.typeName),typeName:l.typeName,label:l.label||l.typeName,abstract:Ei(l),synthetic:l.metadata.synthetic===!0,metadata:l.metadata})).sort((l,c)=>l.typeName.localeCompare(c.typeName)),a=[],o=new Set;if(e.showRelations)for(const l of t.allRelations){if(l.edgeType==="contains"&&l.targetType==="Asset")continue;const c=Dr(l.sourceType);if(!r.has(c))continue;const d=Pl(l);for(const h of Ol(l,t,e.hideAbstract)){const p=Dr(h);if(!r.has(p))continue;const m=`${l.sourceType}|${d}|${h}`;o.has(m)||(o.add(m),a.push({id:`rel:${m}`,kind:"relation",source:c,target:p,label:d,edgeType:l.edgeType,importantLabel:Ml(d),metadata:l.metadata}))}}if(e.showIsA)for(const l of n){if(!l.parentTypeName)continue;const c=Dr(l.typeName),d=Dr(l.parentTypeName);!r.has(c)||!r.has(d)||a.push({id:`isa:${l.typeName}->${l.parentTypeName}`,kind:"is_a",source:c,target:d,label:"is_a",importantLabel:!1})}return{nodes:i,edges:a,stats:{classCount:i.length,relationCount:a.filter(l=>l.kind==="relation").length,isACount:a.filter(l=>l.kind==="is_a").length}}}const _n="__all__";function Xr(t,e){const n=`${e}::`;if(t.startsWith(n))return t.slice(n.length);const r=t.indexOf("::");return r>=0?t.slice(r+2):t}async function Hl(t,e){return zl(t,e)}async function zl(t,e){const n=new URLSearchParams({ontology_id:t});e.trim()&&n.set("workspace_id",e.trim());const r=await fetch(`/api/brain/ontology/graph?${n}`);if(!r.ok)throw new Error(await r.text());const i=await r.json(),a=i.nodes??[],o=[];for(const l of a){const c=Ar(l.metadata??l.metadata_json),d=ts(c);if(d["ghostcrab.native_edge_type"]!=="true")continue;const h=Zi(d["ghostcrab.native_edge_label"]),p=Zi(d["ghostcrab.source_entity_type"]),m=Zi(d["ghostcrab.target_entity_type"]);!h||!p||!m||o.push({edge_type:h,source_entity_type:p,target_entity_type:m,directed:!0,metadata:{...c,native_relation_class:String(l.type??l.id??h)}})}return{ontology_id:t,workspace_id:e,name:t,namespaces:[],dimensions:[],values:[],entity_types:a.filter(l=>{const c=String(l.kind??l.node_kind??"");return c==="entity_type"||c==="class"}).map(l=>{const c=String(l.id??"");return{entity_type:String(l.type??c.replace(/^entity_type:/,"").replace(/^class:/,"")),label:l.label==null?null:String(l.label),metadata:Ar(l.metadata??l.metadata_json)}}).filter(l=>{const c=ts(Ar(l.metadata));return Bl(l.entity_type)&&c["ghostcrab.native_edge_type"]!=="true"}),edge_types:[...(i.edges??[]).map(l=>{const c=l.source_entity_type??l.source_type,d=l.target_entity_type??l.target_type;return{edge_type:String(l.edge_type??l.type??l.label??l.id??"relation"),source_entity_type:c==null?null:String(c),target_entity_type:d==null?null:String(d),directed:l.directed!==!1,metadata:Ar(l.metadata??l.metadata_json)}}),...o],integrity:{ok:!0}}}async function Fl(t){const e=new URLSearchParams({workspace:t}),n=await fetch(`/api/graph/schema-registry?${e}`);if(!n.ok)throw new Error(await n.text());return await n.json()}function Ar(t){if(!t)return{};if(typeof t=="object"&&!Array.isArray(t))return t;if(typeof t!="string")return{};try{const e=JSON.parse(t);return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function Zi(t){return typeof t=="string"&&t.trim()?t.trim():null}function Kr(t,e){return`${t}:${e}`}function Bl(t){return!new Set(["owl_blank_node","owl_class","owl_object_property","owl_resource"]).has(t)}function ts(t){return t.ghostcrab&&typeof t.ghostcrab=="object"&&!Array.isArray(t.ghostcrab)?t.ghostcrab:{}}function jl(t,e,n){const r=ts(n)["ghostcrab.schema_family"];if(typeof r!="string")return e;const i=`${t}:`;if(!r.startsWith(i))return e;const a=r.slice(i.length).split(":")[0]?.trim();return a?`${t}::${a}`:e}function Vl(t,e){return t.entity_type}function Kl(t,e,n=_n,r=[]){const i=new Map,a=[],o=new Map,l=new Map,c=new Map,d=e.filter(_=>n===_n?!0:Xr(_.ontology_id,t)===n);for(const _ of d)for(const v of _.entity_types??[]){const P=Ar(v.metadata),E=jl(t,_.ontology_id,P),B=Xr(E,t),V=typeof P.is_a=="string"&&P.is_a.trim()?P.is_a.trim():null,Z=Kr(E,v.entity_type);o.has(v.entity_type)||o.set(v.entity_type,new Set),o.get(v.entity_type)?.add(E);const j=typeof P.linkml_class=="string"?P.linkml_class:"";j&&(l.has(j)||l.set(j,new Set),l.get(j)?.add(E)),V&&c.set(Z,V),i.set(Z,{typeName:Z,label:Vl(v),parentTypeName:null,metadata:{...P,source_ontology_id:_.ontology_id,ontology_id:E,ontology_key:B,native_type:v.entity_type},properties:[],outgoingRelations:[],incomingRelations:[]})}function h(_,v){const P=Kr(v,_);if(i.has(P))return P;const E=Kr(`${t}::core`,_);if(i.has(E))return E;const B=o.get(_);return!B||B.size===0?null:B.size===1?Kr([...B][0],_):null}function p(_,v){const P=l.get(_);if(!P||P.size===0)return null;const E=P.has(v)?v:null,B=P.has(`${t}::core`)?`${t}::core`:null,V=E??B??(P.size===1?[...P][0]:null);if(!V)return null;for(const Z of i.values())if(Z.metadata.linkml_class===_&&Z.metadata.ontology_id===V)return Z.typeName;return null}function m(_){const v=Kr(`${t}::core`,_);return i.has(v)||i.set(v,{typeName:v,label:_,parentTypeName:null,metadata:{abstract:!0,synthetic:!0,ontology_id:`${t}::core`,ontology_key:"core",native_type:_},properties:[],outgoingRelations:[],incomingRelations:[]}),v}for(const[_,v]of c){const P=i.get(_);if(!P)continue;const E=typeof P.metadata.ontology_id=="string"?P.metadata.ontology_id:"";P.parentTypeName=h(v,E)??m(v)}for(const _ of d)for(const v of _.edge_types??[]){if(!v.source_entity_type||!v.target_entity_type)continue;const P=Ar(v.metadata),E=h(v.source_entity_type,_.ontology_id),B=h(v.target_entity_type,_.ontology_id);if(!E||!B)continue;const V=i.get(E)?.metadata??{},Z=typeof V.ontology_id=="string"?V.ontology_id:_.ontology_id,j={edgeType:v.edge_type,sourceType:E,targetType:B,label:v.edge_type,directed:v.directed!==!1,metadata:{...P,source_ontology_id:_.ontology_id,ontology_id:Z,ontology_key:Xr(Z,t),native_edge_type:v.edge_type,native_source_type:v.source_entity_type,native_target_type:v.target_entity_type}};a.push(j),i.get(j.sourceType)?.outgoingRelations.push(j),i.get(j.targetType)?.incomingRelations.push(j)}const k=new Set(["boolean","date","datetime","decimal","double","euro","float","integer","list<string>","string","time","uri"]),C=new Set(a.map(_=>`${_.sourceType}|${_.edgeType}|${_.targetType}`));for(const _ of r){if(n!==_n&&_.ontology_key!==n)continue;const v=`${t}::${_.ontology_key}`,P=h(_.entity_type,v);if(P)for(const E of _.fields??[]){const B=E.range?.trim();if(!B||k.has(B)||B.endsWith("Enum"))continue;const V=p(B,v)??h(B,v);if(!V)continue;const Z=`${P}|${E.name}|${V}`;if(C.has(Z))continue;C.add(Z);const j={edgeType:E.name,sourceType:P,targetType:V,label:E.name,directed:!0,metadata:{ontology_id:v,ontology_key:_.ontology_key,schema_id:_.schema_id,native_edge_type:E.name,native_source_type:_.entity_type,native_target_range:B,field:E}};a.push(j),i.get(P)?.outgoingRelations.push(j),i.get(V)?.incomingRelations.push(j)}}for(const _ of i.values())_.outgoingRelations.sort((v,P)=>v.edgeType.localeCompare(P.edgeType)),_.incomingRelations.sort((v,P)=>v.edgeType.localeCompare(P.edgeType));return{ontologyId:n,classes:i,roots:[...i.values()].filter(_=>!_.parentTypeName||!i.has(_.parentTypeName)).map(_=>_.typeName).sort((_,v)=>_.localeCompare(v)),allRelations:a}}var $l=D("<option> </option>"),Zl=D('<p class="muted svelte-1hnvxh9">Loading workspace model...</p>'),Ul=D('<p class="error svelte-1hnvxh9"> </p>'),Wl=D('<div class="summary-bar svelte-1hnvxh9"><span> </span> <span> </span> <span> </span> <span> </span></div> <div class="model-graph-panel svelte-1hnvxh9"><div class="graph-toolbar svelte-1hnvxh9"><label class="svelte-1hnvxh9"><input type="checkbox" class="svelte-1hnvxh9"/> Relations métier</label> <label class="svelte-1hnvxh9"><input type="checkbox" class="svelte-1hnvxh9"/> Labels importants</label> <label class="svelte-1hnvxh9"><input type="checkbox" class="svelte-1hnvxh9"/> Abstractions</label> <label><input type="checkbox" class="svelte-1hnvxh9"/> Héritage</label> <span> </span></div> <!></div>',1),Gl=D("<span>registry unavailable</span>"),Yl=D('<p class="warn svelte-1hnvxh9"> </p>'),Xl=D('<button type="button" class="svelte-1hnvxh9"><strong class="svelte-1hnvxh9"> </strong> <span class="svelte-1hnvxh9"> </span> <small class="svelte-1hnvxh9"> </small></button>'),Jl=D('<p class="muted svelte-1hnvxh9">No schema registry rows for this view.</p>'),Ql=D('<div class="summary-bar svelte-1hnvxh9"><span> </span> <span> </span> <span> </span> <span> </span> <!></div> <div class="schema-layout svelte-1hnvxh9"><aside class="schema-list svelte-1hnvxh9" aria-label="Schema registry"><!> <!> <!></aside> <div class="schema-graph-panel svelte-1hnvxh9"><div class="graph-toolbar svelte-1hnvxh9"><label class="svelte-1hnvxh9"><input type="checkbox" class="svelte-1hnvxh9"/> Relations métier</label> <label class="svelte-1hnvxh9"><input type="checkbox" class="svelte-1hnvxh9"/> Labels importants</label> <label class="svelte-1hnvxh9"><input type="checkbox" class="svelte-1hnvxh9"/> Abstractions</label> <label><input type="checkbox" class="svelte-1hnvxh9"/> Héritage</label> <span> </span></div> <!></div></div>',1),ql=D('<div class="workspace-model svelte-1hnvxh9"><div class="model-toolbar svelte-1hnvxh9"><div class="segmented svelte-1hnvxh9" role="tablist" aria-label="Model surface"><button type="button">Ontologies</button> <button type="button">Schema</button></div> <label class="select-wrap svelte-1hnvxh9"><span>View</span> <select class="svelte-1hnvxh9"><option>Tous</option><!></select></label></div> <!></div>');function ec(t,e){Nn(e,!0);let n=K(e,"selectedOntologyId",3,_n),r=A("ontologies"),i=A($t(_n)),a=A(!0),o=A(null),l=A($t([])),c=A(null),d=A(!0),h=A(!0),p=A(!1),m=A(!1),k=A($t([])),C=A($t([])),_=A($t({classCount:0,relationCount:0,isACount:0}));De(()=>{e.workspaceId&&e.ontologies.length>0&&v()}),De(()=>{u(i,n()===_n?_n:Xr(n(),e.workspaceId),!0)}),De(()=>{const ke=Kl(e.workspaceId,s(l),s(i),s(c)?.rows??[]),U=Ll(ke,{hideAbstract:!s(m),showRelations:s(d),showIsA:s(m)&&s(p)});u(k,U.nodes,!0),u(C,U.edges,!0),u(_,U.stats,!0)});async function v(){u(a,!0),u(o,null);try{const ke=await Promise.all(e.ontologies.map(U=>Hl(U.ontology_id,e.workspaceId)));u(l,ke,!0);try{u(c,await Fl(e.workspaceId),!0)}catch(U){u(c,{workspace_id:e.workspaceId,total:0,facet_definition_total:0,rows:[],source:"unavailable",error:U instanceof Error?U.message:String(U)},!0)}}catch(ke){u(o,ke instanceof Error?ke.message:String(ke),!0),u(l,[],!0),u(c,null)}finally{u(a,!1)}}function P(ke){return Xr(ke.ontology_id,e.workspaceId)}function E(){return s(i)===_n?s(l):s(l).filter(ke=>P(ke)===s(i))}function B(){const ke=s(c)?.rows??[];return s(i)===_n?ke:ke.filter(U=>U.ontology_key===s(i))}function V(ke){const U=ke.metadata??{};e.onSelect?.({nodeKind:"entity",typeName:String(U.native_type??ke.typeName),payload:{...U,typeName:String(U.native_type??ke.typeName),qualifiedTypeName:ke.typeName,ontology_id:U.ontology_id}})}function Z(ke){const U=ke.metadata??{};e.onSelect?.({nodeKind:"edge",typeName:String(U.native_edge_type??ke.edgeType??ke.label),payload:{id:ke.id,source:ke.source,target:ke.target,label:ke.label,edgeType:String(U.native_edge_type??ke.edgeType??ke.label),ontology_id:U.ontology_id,native_source_type:U.native_source_type,native_target_type:U.native_target_type}})}var j=ql(),ae=g(j),ce=g(ae),de=g(ce);let W;var N=b(de,2);let G;f(ce);var O=b(ce,2),X=b(g(O),2),ue=g(X),fe={},Se=b(ue);_t(Se,17,()=>e.ontologies,Mt,(ke,U)=>{var me=$l(),ve=g(me,!0);f(me);var Ze={};ee((Le,Be)=>{F(ve,Le),Ze!==(Ze=Be)&&(me.value=(me.__value=Be)??"")},[()=>P(s(U)),()=>P(s(U))]),x(ke,me)}),f(X),f(O),f(ae);var se=b(ae,2);{var he=ke=>{var U=Zl();x(ke,U)},xe=ke=>{var U=Ul(),me=g(U,!0);f(U),ee(()=>F(me,s(o))),x(ke,U)},Ce=ke=>{var U=Wl(),me=et(U),ve=g(me),Ze=g(ve);f(ve);var Le=b(ve,2),Be=g(Le);f(Le);var Ge=b(Le,2),Je=g(Ge);f(Ge);var Ke=b(Ge,2),yt=g(Ke);f(Ke),f(me);var ut=b(me,2),tt=g(ut),Fe=g(tt),qe=g(Fe);Mn(qe),Yt(),f(Fe);var lt=b(Fe,2),L=g(lt);Mn(L),Yt(),f(lt);var ne=b(lt,2),H=g(ne);Mn(H),Yt(),f(ne);var T=b(ne,2);let R;var J=g(T);Mn(J),Yt(),f(T);var Q=b(T,2),Pe=g(Q);f(Q),f(tt);var Ie=b(tt,2);zs(Ie,{get nodes(){return s(k)},get edges(){return s(C)},get showEdgeLabels(){return s(h)},onNodeClick:V,onEdgeClick:Z}),f(ut),ee((pe,ye)=>{F(Ze,`${pe??""} ontologies`),F(Be,`${s(_).classCount??""} classes`),F(Je,`${s(_).relationCount??""} relations`),F(yt,`${ye??""} dimensions`),R=st(T,1,"svelte-1hnvxh9",null,R,{disabled:!s(m)}),J.disabled=!s(m),F(Pe,`${s(_).classCount??""} classes · ${s(_).relationCount??""} relations · ${s(_).isACount??""} is_a`)},[()=>E().length,()=>E().reduce((pe,ye)=>pe+(ye.dimensions?.length??0),0)]),or(qe,()=>s(d),pe=>u(d,pe)),or(L,()=>s(h),pe=>u(h,pe)),or(H,()=>s(m),pe=>u(m,pe)),or(J,()=>s(p),pe=>u(p,pe)),x(ke,U)},nt=ke=>{var U=Ql(),me=et(U),ve=g(me),Ze=g(ve);f(ve);var Le=b(ve,2),Be=g(Le);f(Le);var Ge=b(Le,2),Je=g(Ge);f(Ge);var Ke=b(Ge,2),yt=g(Ke);f(Ke);var ut=b(Ke,2);{var tt=Y=>{var ge=Gl();x(Y,ge)};q(ut,Y=>{s(c)?.source==="unavailable"&&Y(tt)})}f(me);var Fe=b(me,2),qe=g(Fe),lt=g(qe);{var L=Y=>{var ge=Yl(),Me=g(ge,!0);f(ge),ee(()=>F(Me,s(c).error)),x(Y,ge)};q(lt,Y=>{s(c)?.error&&Y(L)})}var ne=b(lt,2);_t(ne,17,B,Mt,(Y,ge)=>{var Me=Xl(),Ye=g(Me),_e=g(Ye,!0);f(Ye);var Oe=b(Ye,2),Xe=g(Oe,!0);f(Oe);var it=b(Oe,2),Ve=g(it);f(it),f(Me),ee(()=>{F(_e,s(ge).entity_type),F(Xe,s(ge).schema_id),F(Ve,`${s(ge).facet_definition_count??""} facets`)}),ze("click",Me,()=>e.onSelect?.({nodeKind:"schema",typeName:s(ge).entity_type,payload:s(ge)})),x(Y,Me)});var H=b(ne,2);{var T=Y=>{var ge=Jl();x(Y,ge)},R=be(()=>B().length===0);q(H,Y=>{s(R)&&Y(T)})}f(qe);var J=b(qe,2),Q=g(J),Pe=g(Q),Ie=g(Pe);Mn(Ie),Yt(),f(Pe);var pe=b(Pe,2),ye=g(pe);Mn(ye),Yt(),f(pe);var M=b(pe,2),re=g(M);Mn(re),Yt(),f(M);var oe=b(M,2);let Te;var we=g(oe);Mn(we),Yt(),f(oe);var He=b(oe,2),Qe=g(He);f(He),f(Q);var $=b(Q,2);zs($,{get nodes(){return s(k)},get edges(){return s(C)},get showEdgeLabels(){return s(h)},onNodeClick:V,onEdgeClick:Z}),f(J),f(Fe),ee((Y,ge)=>{F(Ze,`${Y??""} schemas`),F(Be,`${ge??""} facet definitions`),F(Je,`${s(_).classCount??""} graph classes`),F(yt,`${s(_).relationCount??""} graph relations`),Te=st(oe,1,"svelte-1hnvxh9",null,Te,{disabled:!s(m)}),we.disabled=!s(m),F(Qe,`${s(_).classCount??""} classes · ${s(_).relationCount??""} relations · ${s(_).isACount??""} is_a`)},[()=>B().length,()=>B().reduce((Y,ge)=>Y+ge.facet_definition_count,0)]),or(Ie,()=>s(d),Y=>u(d,Y)),or(ye,()=>s(h),Y=>u(h,Y)),or(re,()=>s(m),Y=>u(m,Y)),or(we,()=>s(p),Y=>u(p,Y)),x(ke,U)};q(se,ke=>{s(a)?ke(he):s(o)?ke(xe,1):s(r)==="ontologies"?ke(Ce,2):ke(nt,-1)})}f(j),ee(()=>{W=st(de,1,"svelte-1hnvxh9",null,W,{active:s(r)==="ontologies"}),G=st(N,1,"svelte-1hnvxh9",null,G,{active:s(r)==="schema"}),fe!==(fe=_n)&&(ue.value=(ue.__value=_n)??"")}),ze("click",de,()=>u(r,"ontologies")),ze("click",N,()=>u(r,"schema")),Or(X,()=>s(i),ke=>u(i,ke)),x(t,j),Dn()}jn(["click"]);var tc=D('<p class="muted svelte-1d1a86y">Select an ontology to explore the model.</p>'),nc=D('<div class="modele-panel svelte-1d1a86y"><div class="body svelte-1d1a86y"><!></div></div>');function rc(t,e){Nn(e,!0);let n=K(e,"workspaceId",3,""),r=K(e,"ontologies",19,()=>[]);var i=nc(),a=g(i),o=g(a);{var l=d=>{var h=tc();x(d,h)},c=d=>{{let h=be(()=>e.ontologyId||_n);ec(d,{get workspaceId(){return n()},get ontologies(){return r()},get selectedOntologyId(){return s(h)},get onSelect(){return e.onSelect}})}};q(o,d=>{!e.ontologyId||r().length===0?d(l):d(c,-1)})}f(a),f(i),x(t,i),Dn()}var ic=D('<p class="search-error svelte-yyldap"> </p>'),sc=D('<span class="result-sub svelte-yyldap"> </span>'),ac=D('<button type="button" class="clear-result svelte-yyldap" title="Clear search focus">×</button>'),oc=D('<div><button type="button" class="result svelte-yyldap"><span class="result-label svelte-yyldap"> </span> <!></button> <!></div>'),lc=D('<div class="results svelte-yyldap"></div>'),cc=D('<section class="search svelte-yyldap" aria-label="Graph search"><form class="search-form svelte-yyldap"><select aria-label="Search mode" class="svelte-yyldap"><option>Graph</option><option>BM25</option></select> <input placeholder="Search graph" aria-label="Search query" class="svelte-yyldap"/> <button type="submit" class="svelte-yyldap"> </button></form></section> <!> <!>',1);function dc(t,e){Nn(e,!0);let n=K(e,"workspaceId",3,"default"),r=K(e,"entityType",3,null),i=A("graph"),a=A(""),o=A(!1),l=A(null),c=A($t([])),d=A("");function h(O){const X=Number(O.entity_id??O.id);return Number.isFinite(X)&&X>0?X:null}function p(O){return O.map(X=>{const ue=h(X);return{key:String(ue??X.name??crypto.randomUUID()),label:String(X.name??X.entity_type??ue??"result"),subtitle:X.score==null?String(X.entity_type??""):`score ${Number(X.score).toFixed(2)}`,entityId:ue??void 0,raw:X}})}function m(O){return O.map(X=>{const ue=h(X),fe=X.score??X.rank,Se=String(X.excerpt??X.content??X.snippet??"").slice(0,120);return{key:String(X.doc_id??ue??crypto.randomUUID()),label:String(X.title??X.doc_id??X.name??"document"),subtitle:[fe==null?null:`score ${Number(fe).toFixed(2)}`,Se||null].filter(Boolean).join(" · "),entityId:ue??void 0,raw:X}})}async function k(){u(o,!0),u(l,null),u(c,[],!0),u(d,"");try{const O=n().trim()||"default";if(s(i)==="graph"){const X=new URLSearchParams({workspace_id:O,query:s(a),limit:"20"});r()&&X.set("entity_type",r());const ue=await fetch(`/api/brain/ghostcrab/graph-search?${X}`);if(!ue.ok)throw new Error(await ue.text());const fe=await ue.json();u(c,p(fe.rows??[]),!0),e.onSeeds?.(s(c).map(Se=>Se.entityId).filter(Se=>Se!=null))}else{const X=await fetch("/api/brain/ghostcrab/search",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({workspace_id:O,query:s(a),embedding:[],vector_weight:0,limit:20})});if(!X.ok)throw new Error(await X.text());const ue=await X.json();u(c,m(ue.matches??[]),!0),e.onSeeds?.(s(c).map(fe=>fe.entityId).filter(fe=>fe!=null))}}catch(O){u(l,O instanceof Error?O.message:String(O),!0)}finally{u(o,!1)}}function C(O){O.entityId!=null&&(u(d,O.key,!0),e.onSeeds?.([O.entityId]))}function _(){u(d,""),e.onSeeds?.([])}var v=cc(),P=et(v),E=g(P),B=g(E),V=g(B);V.value=V.__value="graph";var Z=b(V);Z.value=Z.__value="bm25",f(B);var j=b(B,2);Mn(j);var ae=b(j,2),ce=g(ae,!0);f(ae),f(E),f(P);var de=b(P,2);{var W=O=>{var X=ic(),ue=g(X,!0);f(X),ee(()=>F(ue,s(l))),x(O,X)};q(de,O=>{s(l)&&O(W)})}var N=b(de,2);{var G=O=>{var X=lc();_t(X,21,()=>s(c).slice(0,8),Mt,(ue,fe)=>{var Se=oc();let se;var he=g(Se),xe=g(he),Ce=g(xe,!0);f(xe);var nt=b(xe,2);{var ke=ve=>{var Ze=sc(),Le=g(Ze,!0);f(Ze),ee(()=>F(Le,s(fe).subtitle)),x(ve,Ze)};q(nt,ve=>{s(fe).subtitle&&ve(ke)})}f(he);var U=b(he,2);{var me=ve=>{var Ze=ac();ee(()=>Rn(Ze,"aria-label",`Clear search focus for ${s(fe).label}`)),ze("click",Ze,_),x(ve,Ze)};q(U,ve=>{s(d)===s(fe).key&&ve(me)})}f(Se),ee(()=>{se=st(Se,1,"result-wrap svelte-yyldap",null,se,{focused:s(d)===s(fe).key}),he.disabled=s(fe).entityId==null,F(Ce,s(fe).label)}),ze("click",he,()=>C(s(fe))),x(ue,Se)}),f(X),x(O,X)};q(N,O=>{s(c).length>0&&O(G)})}ee(()=>{ae.disabled=s(o),F(ce,s(o)?"Searching":"Search")}),Ct("submit",E,O=>{O.preventDefault(),k()}),Or(B,()=>s(i),O=>u(i,O)),zr(j,()=>s(a),O=>u(a,O)),x(t,v),Dn()}jn(["click"]);var hc=D('<p class="legend-hint-line svelte-lmk6mp"><strong>Facet row</strong>: filter graph — chantier weeks use <code class="svelte-lmk6mp">week_number</code> </p>'),uc=D("<strong>Ship</strong> ",1),fc=D('<div class="legend-hint svelte-lmk6mp"><p class="legend-hint-line svelte-lmk6mp"><strong>Node</strong> <strong>Background</strong>: reset selection</p> <!> <p class="legend-hint-line svelte-lmk6mp"><!> <strong>Links</strong>: edge mode + composition when a node is focused</p></div>'),gc=D('<div class="legend-hint svelte-lmk6mp"><p class="legend-hint-line svelte-lmk6mp"><strong>Facet row</strong>: filter graph — chantier weeks use <code class="svelte-lmk6mp">week_number</code> </p> <p class="legend-hint-line svelte-lmk6mp"><strong>Ship</strong> </p></div>'),vc=D('<div class="legend-active svelte-lmk6mp" role="status" aria-label="Active facet filter"><span class="svelte-lmk6mp">Active filter</span> <strong class="svelte-lmk6mp"> </strong> <button type="button" class="svelte-lmk6mp">clear</button></div>'),pc=D("<!> <!>",1),yc=D('<p class="legend-empty svelte-lmk6mp"><!></p>'),mc=D('<button type="button"><span class="swatch svelte-lmk6mp"></span> <span class="legend-label svelte-lmk6mp"> </span></button>'),_c=D('<div class="legend-row svelte-lmk6mp"><span class="swatch svelte-lmk6mp"></span> <span class="legend-label svelte-lmk6mp"> </span></div>'),bc=D('<div class="legend-block-rows svelte-lmk6mp"></div>'),kc=D('<div class="legend-block svelte-lmk6mp"><button type="button"><span aria-hidden="true">›</span> <span class="legend-block-title svelte-lmk6mp"> </span></button> <!></div>'),wc=D('<div class="legend svelte-lmk6mp"><!> <!> <!></div>');function Fs(t,e){Nn(e,!0);let n=K(e,"legendBlocks",19,()=>[]),r=K(e,"facetFilter",15,null),i=K(e,"focusDepth",3,2),a=K(e,"variant",3,"all");function o(W){return W.rows.some(N=>N.facetFilter)}const l=be(()=>a()==="all"?n():a()==="facets"?n().filter(o):n().filter(W=>!o(W)));function c(W,N){return W===N?!0:!W||!N||W.kind!==N.kind?!1:W.kind==="scalar"&&N.kind==="scalar"?W.key===N.key&&W.value===N.value:W.kind==="platform_hull"&&N.kind==="platform_hull"?W.platformId===N.platformId:W.kind==="abstraction"&&N.kind==="abstraction"?W.value===N.value:W.kind==="chantier_week_neighborhood"&&N.kind==="chantier_week_neighborhood"?W.week===N.week:W.kind==="audit_phase_neighborhood"&&N.kind==="audit_phase_neighborhood"?W.phase===N.phase:!1}function d(W){return W.kind==="scalar"?`${W.key} = ${W.value}`:W.kind==="abstraction"?`abstraction = ${W.value}`:W.kind==="chantier_week_neighborhood"?`week_number = ${W.week} (≤${Lr} hops)`:W.kind==="audit_phase_neighborhood"?`audit_phase = ${W.phase}`:`hull = ${W.platformId}`}function h(W){return!!(W.facetFilter&&c(r(),W.facetFilter))}function p(W){if(!W.facetFilter)return;const N=W.facetFilter;if(c(r(),N)){r(null);return}r(N)}let m=A($t(new Set)),k=A(null);function C(W){return W.title}function _(W){return s(m).has(W)}function v(W){const N=C(W),G=new Set(s(m));G.has(N)?G.delete(N):G.add(N),u(m,G,!0)}function P(W){return W.rows.some(N=>h(N))}De(()=>{if(a()!=="facets")return;const W=r();if(!W){u(k,null);return}if(c(W,s(k)))return;u(k,W,!0);const N=s(l).filter(P).map(C);N.length!==0&&u(m,new Set([...s(m),...N]),!0)});var E=wc(),B=g(E);{var V=W=>{var N=fc(),G=g(N),O=b(g(G));Yt(2),f(G);var X=b(G,2);{var ue=he=>{var xe=hc(),Ce=b(g(xe),3);f(xe),ee(()=>F(Ce,` + neighbors
5
- ≤${Lr} hops; click the same row again to clear`)),x(he,xe)};q(X,he=>{a()==="all"&&he(ue)})}var fe=b(X,2),Se=g(fe);{var se=he=>{var xe=uc(),Ce=b(et(xe));ee(()=>F(Ce,`: hull ≤${ei} hops ·`)),x(he,xe)};q(Se,he=>{a()==="all"&&he(se)})}Yt(3),f(fe),f(N),ee(()=>F(O,`: neighborhood ≤${i()??""} hops · `)),x(W,N)};q(B,W=>{(a()==="all"||a()==="legend")&&W(V)})}var Z=b(B,2);{var j=W=>{var N=pc(),G=et(N);{var O=fe=>{var Se=gc(),se=g(Se),he=b(g(se),3);f(se);var xe=b(se,2),Ce=b(g(xe));f(xe),f(Se),ee(()=>{F(he,` + neighbors
6
- ≤${Lr} hops; click the same row again to clear`),F(Ce,`: hull ≤${ei} hops`)}),x(fe,Se)};q(G,fe=>{a()==="facets"&&fe(O)})}var X=b(G,2);{var ue=fe=>{var Se=vc(),se=b(g(Se),2),he=g(se,!0);f(se);var xe=b(se,2);f(Se),ee(Ce=>F(he,Ce),[()=>d(r())]),ze("click",xe,()=>{r(null)}),x(fe,Se)};q(X,fe=>{r()&&fe(ue)})}x(W,N)};q(Z,W=>{(a()==="all"||a()==="facets")&&W(j)})}var ae=b(Z,2);{var ce=W=>{var N=yc(),G=g(N);{var O=fe=>{var Se=Bn("No facet dimensions in this graph.");x(fe,Se)},X=fe=>{var Se=Bn("Load a graph to see ontology and relation colours.");x(fe,Se)},ue=fe=>{var Se=Bn("Load a graph to see ontology and relation facets.");x(fe,Se)};q(G,fe=>{a()==="facets"?fe(O):a()==="legend"?fe(X,1):fe(ue,-1)})}f(N),x(W,N)},de=W=>{var N=zt(),G=et(N);_t(G,17,()=>s(l),O=>C(O),(O,X)=>{var ue=kc(),fe=g(ue);let Se;var se=g(fe);let he;var xe=b(se,2),Ce=g(xe,!0);f(xe),f(fe);var nt=b(fe,2);{var ke=me=>{var ve=bc();_t(ve,21,()=>s(X).rows,Mt,(Ze,Le)=>{var Be=zt(),Ge=et(Be);{var Je=yt=>{var ut=mc();let tt;var Fe=g(ut);let qe;var lt=b(Fe,2),L=g(lt,!0);f(lt),f(ut),ee(ne=>{tt=st(ut,1,"legend-row legend-row--clickable svelte-lmk6mp",null,tt,ne),qe=rr(Fe,"",qe,{background:s(Le).swatch}),F(L,s(Le).label)},[()=>({"legend-row--active":h(s(Le))})]),ze("click",ut,()=>p(s(Le))),x(yt,ut)},Ke=yt=>{var ut=_c(),tt=g(ut);let Fe;var qe=b(tt,2),lt=g(qe,!0);f(qe),f(ut),ee(()=>{Fe=rr(tt,"",Fe,{background:s(Le).swatch}),F(lt,s(Le).label)}),x(yt,ut)};q(Ge,yt=>{s(Le).facetFilter?yt(Je):yt(Ke,-1)})}x(Ze,Be)}),f(ve),x(me,ve)},U=be(()=>_(C(s(X))));q(nt,me=>{s(U)&&me(ke)})}f(ue),ee((me,ve,Ze)=>{Se=st(fe,1,"legend-block-toggle svelte-lmk6mp",null,Se,me),Rn(fe,"aria-expanded",ve),he=st(se,1,"block-chevron svelte-lmk6mp",null,he,Ze),F(Ce,s(X).title)},[()=>({"legend-block-toggle--active":P(s(X))}),()=>_(C(s(X))),()=>({expanded:_(C(s(X)))})]),ze("click",fe,()=>v(s(X))),x(O,ue)}),x(W,N)};q(ae,W=>{s(l).length===0?W(ce):W(de,-1)})}f(E),ee(()=>Rn(E,"aria-label",a()==="facets"?"Graph facets":"Graph legend")),x(t,E),Dn()}jn(["click"]);function Ui(t){if(!t)return{};if(typeof t=="object"&&!Array.isArray(t))return t;if(typeof t!="string")return{};try{const e=JSON.parse(t);return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function gi(t){const e=Number(t);return!Number.isFinite(e)||e<=0?null:new Date(e*1e3).toISOString().slice(0,10)}function mr(t,e=new Set){const n=[];for(const[r,i]of Object.entries(t))e.has(r)||i==null||i===""||typeof i!="object"&&n.push([r,String(i)]);return n}function xc(t){const e=t.triples;if(!Array.isArray(e))return[];const n=[];for(const r of e){if(!r||typeof r!="object")continue;const i=r,a=String(i.predicate??"");a&&n.push({subject:String(i.subject??""),predicate:a,object_value:String(i.object_value??i.object??""),object_kind:i.object_kind==null?void 0:String(i.object_kind)})}return n}function Cc(t){for(const e of t){const n=e.predicate.toLowerCase();if(n.includes("definition")||n.endsWith("comment")||n.endsWith("label"))return e.object_value}return null}const Sc="http://www.w3.org/2000/01/rdf-schema#domain",Nc="http://www.w3.org/2000/01/rdf-schema#range",Dc="http://www.w3.org/2002/07/owl#DatatypeProperty",Pc="http://www.w3.org/1999/02/22-rdf-syntax-ns#type";function ns(t){const e=t.lastIndexOf("#");if(e>=0)return t.slice(e+1);const n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t.startsWith("studio:")?t.slice(7):t}function Ic(t){return t.includes("XMLSchema#string")?"string":t.includes("XMLSchema#date")?"date":t.includes("XMLSchema#integer")?"integer":t.includes("XMLSchema#decimal")||t.includes("XMLSchema#double")?"number":t.includes("XMLSchema#boolean")?"boolean":ns(t)}function Tc(t,e,n){const r=new Set([e]);n&&r.add(n),r.add(`studio:class:${e}`);const i=new Map;for(const o of t){const l=i.get(o.subject)??[];l.push(o),i.set(o.subject,l)}const a=[];for(const[o,l]of i){if(!l.some(m=>m.predicate===Pc&&(m.object_value===Dc||m.object_value.endsWith("DatatypeProperty"))))continue;const d=l.find(m=>m.predicate===Sc)?.object_value;if(!d||!r.has(d)&&!r.has(ns(d)))continue;const h=l.find(m=>m.predicate===Nc),p=o.startsWith("studio:property:")?o.slice(16):ns(o);a.push({name:p,range:h?Ic(h.object_value):"string",propertyUri:o})}return a.sort((o,l)=>o.name.localeCompare(l.name))}var Mc=D('<label class="svelte-pwv6at"><span class="svelte-pwv6at">Range</span> <select class="svelte-pwv6at"><option>string</option><option>date</option><option>integer</option><option>number</option><option>boolean</option></select></label>'),Ec=D('<label class="svelte-pwv6at"><span class="svelte-pwv6at">Target class</span> <input placeholder="unit" class="svelte-pwv6at"/></label>'),Ac=D('<p class="error svelte-pwv6at"> </p>'),Rc=D('<form class="property-editor svelte-pwv6at"><h4 class="svelte-pwv6at"> </h4> <label class="svelte-pwv6at"><span class="svelte-pwv6at">Name</span> <input class="svelte-pwv6at"/></label> <!> <label class="checkbox svelte-pwv6at"><input type="checkbox" class="svelte-pwv6at"/> <span class="svelte-pwv6at">Required</span></label> <!> <div class="actions svelte-pwv6at"><button type="button" class="secondary svelte-pwv6at">Cancel</button> <button type="submit" class="svelte-pwv6at"> </button></div></form>');function Oc(t,e){Nn(e,!0);let n=K(e,"kind",3,"datatype"),r=K(e,"initialName",3,""),i=K(e,"initialRange",3,"string"),a=K(e,"initialTarget",3,""),o=A(""),l=A("string"),c=A(""),d=A(!1),h=A(!1),p=A(null);De(()=>{u(o,r()),u(l,i()),u(c,a())});async function m(){if(!s(o).trim()){u(p,"Name is required.");return}u(h,!0),u(p,null);try{const O=n()==="object"?{ontology_id:e.ontologyId,edge_type:s(o).trim(),source_entity_type:e.domainClass,target_entity_type:s(c).trim()||"unit",directed:!0,metadata_json:JSON.stringify({required:s(d)})}:{ontology_id:e.ontologyId,name:s(o).trim(),kind:"datatype",domain:e.domainClass,range:s(l).trim()||"string",required:s(d),metadata_json:JSON.stringify({})},X=n()==="object"?"/api/brain/ontology/edge-type":"/api/brain/ontology/property",ue=await fetch(X,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(O)});if(!ue.ok)throw new Error(await ue.text());e.onSaved?.()}catch(O){u(p,O instanceof Error?O.message:String(O),!0)}finally{u(h,!1)}}var k=Rc(),C=g(k),_=g(C);f(C);var v=b(C,2),P=b(g(v),2);Mn(P),f(v);var E=b(v,2);{var B=O=>{var X=Mc(),ue=b(g(X),2),fe=g(ue);fe.value=fe.__value="string";var Se=b(fe);Se.value=Se.__value="date";var se=b(Se);se.value=se.__value="integer";var he=b(se);he.value=he.__value="number";var xe=b(he);xe.value=xe.__value="boolean",f(ue),f(X),Or(ue,()=>s(l),Ce=>u(l,Ce)),x(O,X)},V=O=>{var X=Ec(),ue=b(g(X),2);Mn(ue),f(X),zr(ue,()=>s(c),fe=>u(c,fe)),x(O,X)};q(E,O=>{n()==="datatype"?O(B):O(V,-1)})}var Z=b(E,2),j=g(Z);Mn(j),Yt(2),f(Z);var ae=b(Z,2);{var ce=O=>{var X=Ac(),ue=g(X,!0);f(X),ee(()=>F(ue,s(p))),x(O,X)};q(ae,O=>{s(p)&&O(ce)})}var de=b(ae,2),W=g(de),N=b(W,2),G=g(N,!0);f(N),f(de),f(k),ee(()=>{F(_,`${n()==="object"?"Add relation":"Add property"} · ${e.domainClass??""}`),Rn(P,"placeholder",n()==="object"?"owns":"quotePart"),N.disabled=s(h),F(G,s(h)?"Saving…":"Save")}),Ct("submit",k,O=>(O.preventDefault(),m())),zr(P,()=>s(o),O=>u(o,O)),or(j,()=>s(d),O=>u(d,O)),ze("click",W,()=>e.onCancel?.()),x(t,k),Dn()}jn(["click"]);var Lc=D('<div class="help-popover svelte-r3rl1u" role="dialog"> </div>'),Hc=D('<span class="help-wrap svelte-r3rl1u"><button type="button" class="help-hint svelte-r3rl1u">?</button> <!></span>');function zc(t,e){Nn(e,!0);let n=K(e,"label",3,"Help"),r=A(!1),i=A(void 0);function a(){u(r,!s(r))}function o(){u(r,!1)}De(()=>{if(!s(r))return;function p(k){k.key==="Escape"&&o()}function m(k){const C=k.target;s(i)&&C&&!s(i).contains(C)&&o()}return document.addEventListener("keydown",p),document.addEventListener("pointerdown",m,!0),()=>{document.removeEventListener("keydown",p),document.removeEventListener("pointerdown",m,!0)}});var l=Hc(),c=g(l),d=b(c,2);{var h=p=>{var m=Lc(),k=g(m,!0);f(m),ee(()=>{Rn(m,"aria-label",n()),F(k,e.text)}),x(p,m)};q(d,p=>{s(r)&&p(h)})}f(l),Qr(l,p=>u(i,p),()=>s(i)),ee(()=>{Rn(c,"aria-label",n()),Rn(c,"aria-expanded",s(r))}),ze("click",c,a),x(t,l),Dn()}jn(["click"]);const Fc={inspectorDefinition:"Edit label, description, properties, and relations for the selected type. Use the Taxonomies tab only for enum value lists."};var Bc=D('<h2 class="svelte-k2kih7">Inspector</h2>'),jc=D('<p class="muted svelte-k2kih7">Select a node or edge to inspect instance facts and ontology definition.</p>'),Vc=D('<p class="muted svelte-k2kih7">Loading…</p>'),Kc=D('<p class="warn svelte-k2kih7"> </p>'),$c=D('<button type="button" class="link svelte-k2kih7">View type in Modèle</button>'),Zc=D('<p class="subtitle svelte-k2kih7"> <!></p>'),Uc=D('<div class="svelte-k2kih7"><dt class="svelte-k2kih7"> </dt><dd class="svelte-k2kih7"> </dd></div>'),Wc=D('<dl class="kv svelte-k2kih7"></dl>'),Gc=D('<div class="svelte-k2kih7"><dt class="svelte-k2kih7"> </dt><dd class="svelte-k2kih7"> </dd></div>'),Yc=D('<h4 class="svelte-k2kih7">Relation properties</h4> <dl class="kv svelte-k2kih7"></dl>',1),Xc=D('<div class="svelte-k2kih7"><dt class="svelte-k2kih7"> </dt><dd class="svelte-k2kih7"> </dd></div>'),Jc=D('<h4 class="svelte-k2kih7">Facets</h4> <dl class="kv svelte-k2kih7"></dl>',1),Qc=D('<li class="svelte-k2kih7"> <span class="muted-inline svelte-k2kih7"> </span></li>'),qc=D('<h4 class="svelte-k2kih7"> </h4> <ul class="list svelte-k2kih7"></ul>',1),ed=D('<div class="svelte-k2kih7"><dt class="svelte-k2kih7"> </dt><dd class="svelte-k2kih7"> </dd></div>'),td=D('<h4 class="svelte-k2kih7">Provenance</h4> <dl class="kv svelte-k2kih7"></dl>',1),nd=D('<section class="svelte-k2kih7"><h3 class="svelte-k2kih7">Instance</h3> <p class="title svelte-k2kih7"> </p> <!> <!> <!> <!> <!> <!></section>'),rd=D('<p class="muted svelte-k2kih7"> </p>'),id=D('<p class="muted svelte-k2kih7"> </p>'),sd=D('<p class="definition svelte-k2kih7"> </p>'),ad=D('<p class="muted svelte-k2kih7"><!> <!></p>'),od=D('<div class="def-actions svelte-k2kih7"><button type="button" class="svelte-k2kih7">Add property</button> <button type="button" class="svelte-k2kih7">Add relation</button></div> <!>',1),ld=D('<li class="svelte-k2kih7"><code class="svelte-k2kih7"> </code> <span class="muted-inline svelte-k2kih7"> </span></li>'),cd=D('<h4 class="svelte-k2kih7"> </h4> <ul class="list relations svelte-k2kih7"></ul>',1),dd=D('<div class="svelte-k2kih7"><dt class="svelte-k2kih7"> </dt><dd class="svelte-k2kih7"> </dd></div>'),hd=D('<h4 class="svelte-k2kih7"> </h4> <dl class="kv svelte-k2kih7"></dl>',1),ud=D('<li class="svelte-k2kih7"><code class="svelte-k2kih7"> </code> </li>'),fd=D('<h4 class="svelte-k2kih7"> </h4> <ul class="list triples svelte-k2kih7"></ul>',1),gd=D('<p class="title svelte-k2kih7"> </p> <p class="type-id svelte-k2kih7"> </p> <!> <!> <!> <!> <!> <!> <!>',1),vd=D('<section class="svelte-k2kih7"><div class="section-head svelte-k2kih7"><h3 class="svelte-k2kih7">Definition</h3> <!></div> <!></section>'),pd=D('<p class="muted svelte-k2kih7"> </p>'),yd=D('<p class="muted svelte-k2kih7"> </p>'),md=D('<span class="chip svelte-k2kih7"> </span>'),_d=D('<div class="chips svelte-k2kih7"></div>'),bd=D('<li class="svelte-k2kih7"><strong> </strong> <span class="muted-inline svelte-k2kih7"> </span> <!></li>'),kd=D('<ul class="list taxonomy svelte-k2kih7"></ul>'),wd=D('<section class="svelte-k2kih7"><h3 class="svelte-k2kih7">Taxonomy</h3> <!></section>'),xd=D('<pre class="svelte-k2kih7"> </pre>'),Cd=D('<!> <!> <!> <!> <button type="button" class="toggle-raw svelte-k2kih7"> </button> <!>',1),Sd=D("<!> <!>",1);function Nd(t,e){Nn(e,!0);let n=K(e,"selection",11,null),r=K(e,"ontologyId",3,""),i=K(e,"workspaceId",3,""),a=K(e,"embedded",3,!1),o=A(!1),l=A(null),c=A(null),d=A(null),h=A(null),p=A(!1),m=A(!1),k=A("datatype");De(()=>{C(n(),r(),i())});async function C(N,G,O){if(!N){u(c,null),u(d,null),u(h,null),u(l,null);return}u(o,!0),u(l,null);try{if(N.kind==="entity"){const X=await v(N,O);u(c,V(X,N),!0);const ue=String(X.entity?.entity_type??N.entityType);u(d,await B(G,"entity",ue,O),!0),u(h,null)}else if(N.kind==="relation"){const X=await P(N,O);u(c,Z(X,N),!0);const ue=String(X.relation?.relation_type??N.relationType);u(d,await B(G,"edge",ue),!0),u(h,null)}else u(c,j(N),!0),u(d,ae(N),!0),u(h,null)}catch(X){u(l,X instanceof Error?X.message:String(X),!0),u(c,ce(N),!0),u(d,null),u(h,null)}finally{u(o,!1)}}async function _(N){const G=await fetch(N);if(!G.ok)throw new Error(await G.text());return await G.json()}async function v(N,G){const O=new URLSearchParams({entity_id:String(N.entityId)});G.trim()&&O.set("workspace_id",G.trim());try{return await _(`/api/brain/graph/entity?${O}`)}catch{return{entity:{entity_id:N.entityId,entity_type:N.entityType,name:N.label,metadata_json:JSON.stringify(N.payload??{})},incident_relations:[],facets:[]}}}async function P(N,G){const O=new URLSearchParams({relation_id:String(N.relationId)});G.trim()&&O.set("workspace_id",G.trim());try{return await _(`/api/brain/graph/relation?${O}`)}catch{return{relation:{relation_id:N.relationId,relation_type:N.relationType,...N.payload??{}},properties:[]}}}async function E(N,G,O){try{const X=new URLSearchParams({ontology_id:N});O.trim()&&X.set("workspace_id",O.trim());const ue=await _(`/api/brain/ontology/graph?${X}`),fe=Array.isArray(ue.edges)?ue.edges:[],Se=new Set,se=[];for(const he of fe){if(String(he.source_type??"")!==G)continue;const Ce=String(he.type??he.label??""),nt=String(he.target_type??"?"),ke=`${Ce}:${nt}`;!Ce||Se.has(ke)||(Se.add(ke),se.push({edgeType:Ce,targetType:nt}))}return se.sort((he,xe)=>he.edgeType.localeCompare(xe.edgeType))}catch{return[]}}async function B(N,G,O,X=""){if(!N||!O)return{typeName:O,triples:[],scalars:[],properties:[],outgoingRelations:[],unavailable:"No ontology linked."};try{const ue=await _(`/api/brain/ontology/type?ontology_id=${encodeURIComponent(N)}&kind=${G}&type=${encodeURIComponent(O)}`),fe=xc(ue),Se=Ui(ue.metadata_json),se=typeof Se.class_uri=="string"?Se.class_uri:null,he=typeof Se.is_a=="string"&&Se.is_a.trim()?Se.is_a.trim():null;return{typeName:String(ue.type_name??O),label:ue.label==null?null:String(ue.label),definition:Cc(fe)??(Se.definition==null?null:String(Se.definition)),parentType:he,sourceType:ue.source_entity_type==null?null:String(ue.source_entity_type),targetType:ue.target_entity_type==null?null:String(ue.target_entity_type),triples:fe,scalars:mr(Se),properties:Tc(fe,O,se),outgoingRelations:G==="entity"?await E(N,O,X):[],kind:G}}catch(ue){return{typeName:O,triples:[],scalars:[],properties:[],outgoingRelations:[],unavailable:ue instanceof Error?ue.message:"Ontology type unavailable."}}}function V(N,G){const O=N.entity??{},X=Ui(O.metadata_json??O.metadata),ue=N.facets,fe=[];if(Array.isArray(ue))for(const se of ue){if(!se||typeof se!="object")continue;const he=se,xe=String(he.id??he.facet_id??"facet"),Ce=String(he.content??he.value??JSON.stringify(he.facets_json??he.facets??""));fe.push([xe,Ce.slice(0,240)])}const Se=Array.isArray(N.incident_relations)?N.incident_relations:[];return{title:String(O.name??G.label),subtitle:String(O.entity_type??G.entityType),scalars:[["entity_id",String(O.entity_id??G.entityId)],["confidence",O.confidence==null?"":String(O.confidence)],...mr(X,new Set(["label","workspace_id"]))].filter(se=>se[1]!==""),facets:fe,incidentRelations:Se,properties:[],provenance:mr({deprecated_at:gi(O.deprecated_at)??"",created_at:gi(O.created_at_unix??O.created_at)??"",run_id:O.run_id,patch_id:O.patch_id}),raw:N}}function Z(N,G){const O=N.relation??{},X=Ui(O.metadata_json??O.metadata),ue=N.properties??O.properties,fe=[];if(Array.isArray(ue))for(const Se of ue){if(!Se||typeof Se!="object")continue;const se=Se,he=String(se.property_key??se.key??"property");fe.push([he,String(se.property_value??se.value??"")])}return{title:String(O.relation_type??G.relationType),subtitle:`${O.source_id??"?"} → ${O.target_id??"?"}`,scalars:[["relation_id",String(O.relation_id??G.relationId)],["confidence",O.confidence==null?"":String(O.confidence)],["valid_from",gi(O.valid_from_unix)??""],["valid_to",gi(O.valid_to_unix)??""],...mr(X)].filter(Se=>Se[1]!==""),facets:[],incidentRelations:[],properties:fe,provenance:mr({run_id:O.run_id,patch_id:O.patch_id,source:X.source,domain:X.domain}),raw:N}}function j(N){const G=N.payload??{};return{title:N.typeName,subtitle:N.nodeKind,scalars:mr(G),facets:[],incidentRelations:[],properties:[],provenance:[],raw:G}}function ae(N){const G=N.payload??{},O=G.field&&typeof G.field=="object"&&!Array.isArray(G.field)?G.field:null,X=G.native_source_type==null?null:String(G.native_source_type),ue=G.native_target_type==null?G.native_target_range==null?null:String(G.native_target_range):String(G.native_target_type),fe=typeof G.is_a=="string"&&G.is_a.trim()?G.is_a.trim():null,Se=O?.description==null?G.definition==null?null:String(G.definition):String(O.description);return{typeName:N.typeName,label:G.label==null?O?.name==null?null:String(O.name):String(G.label),definition:Se,parentType:fe,sourceType:X,targetType:ue,triples:[],scalars:mr(G,new Set(["field"])),properties:O&&O.range!=null?[{name:String(O.name??N.typeName),range:String(O.range)}]:[],outgoingRelations:[],kind:N.nodeKind==="edge"?"edge":"entity"}}function ce(N){return N?N.kind==="entity"?{title:N.label,subtitle:N.entityType,scalars:[["entity_id",String(N.entityId)]],facets:[],incidentRelations:[],properties:[],provenance:[]}:N.kind==="relation"?{title:N.relationType,subtitle:`relation ${N.relationId}`,scalars:[["relation_id",String(N.relationId)]],facets:[],incidentRelations:[],properties:[],provenance:[]}:j(N):null}var de=zt(),W=et(de);Do(W,()=>a()?"div":"aside",!1,(N,G)=>{let O;ee(()=>O=st(N,0,"inspector svelte-k2kih7",null,O,{embedded:a()}));var X=Sd(),ue=et(X);{var fe=Ce=>{var nt=Bc();x(Ce,nt)};q(ue,Ce=>{a()||Ce(fe)})}var Se=b(ue,2);{var se=Ce=>{var nt=jc();x(Ce,nt)},he=Ce=>{var nt=Vc();x(Ce,nt)},xe=Ce=>{var nt=Cd(),ke=et(nt);{var U=tt=>{var Fe=Kc(),qe=g(Fe,!0);f(Fe),ee(()=>F(qe,s(l))),x(tt,Fe)};q(ke,tt=>{s(l)&&tt(U)})}var me=b(ke,2);{var ve=tt=>{var Fe=nd(),qe=b(g(Fe),2),lt=g(qe,!0);f(qe);var L=b(qe,2);{var ne=re=>{var oe=Zc(),Te=g(oe),we=b(Te);{var He=Qe=>{var $=$c();ze("click",$,()=>e.onOpenType?.(n().kind==="entity"?n().entityType:n().relationType,n().kind==="relation"?"edge":"entity")),x(Qe,$)};q(we,Qe=>{(n().kind==="entity"||n().kind==="relation")&&Qe(He)})}f(oe),ee(()=>F(Te,`${s(c).subtitle??""} `)),x(re,oe)};q(L,re=>{s(c).subtitle&&re(ne)})}var H=b(L,2);{var T=re=>{var oe=Wc();_t(oe,21,()=>s(c).scalars,Mt,(Te,we)=>{var He=be(()=>Zr(s(we),2));let Qe=()=>s(He)[0],$=()=>s(He)[1];var Y=Uc(),ge=g(Y),Me=g(ge,!0);f(ge);var Ye=b(ge),_e=g(Ye,!0);f(Ye),f(Y),ee(()=>{F(Me,Qe()),F(_e,$())}),x(Te,Y)}),f(oe),x(re,oe)};q(H,re=>{s(c).scalars.length>0&&re(T)})}var R=b(H,2);{var J=re=>{var oe=Yc(),Te=b(et(oe),2);_t(Te,21,()=>s(c).properties,Mt,(we,He)=>{var Qe=be(()=>Zr(s(He),2));let $=()=>s(Qe)[0],Y=()=>s(Qe)[1];var ge=Gc(),Me=g(ge),Ye=g(Me,!0);f(Me);var _e=b(Me),Oe=g(_e,!0);f(_e),f(ge),ee(()=>{F(Ye,$()),F(Oe,Y())}),x(we,ge)}),f(Te),x(re,oe)};q(R,re=>{s(c).properties.length>0&&re(J)})}var Q=b(R,2);{var Pe=re=>{var oe=Jc(),Te=b(et(oe),2);_t(Te,21,()=>s(c).facets,Mt,(we,He)=>{var Qe=be(()=>Zr(s(He),2));let $=()=>s(Qe)[0],Y=()=>s(Qe)[1];var ge=Xc(),Me=g(ge),Ye=g(Me,!0);f(Me);var _e=b(Me),Oe=g(_e,!0);f(_e),f(ge),ee(()=>{F(Ye,$()),F(Oe,Y())}),x(we,ge)}),f(Te),x(re,oe)};q(Q,re=>{s(c).facets.length>0&&re(Pe)})}var Ie=b(Q,2);{var pe=re=>{var oe=qc(),Te=et(oe),we=g(Te);f(Te);var He=b(Te,2);_t(He,21,()=>s(c).incidentRelations.slice(0,8),Mt,(Qe,$)=>{var Y=Qc(),ge=g(Y),Me=b(ge),Ye=g(Me);f(Me),f(Y),ee(_e=>{F(ge,`${_e??""} `),F(Ye,`${s($).source_id??""??""} → ${s($).target_id??""??""}`)},[()=>String(s($).relation_type??s($).label??"relation")]),x(Qe,Y)}),f(He),ee(()=>F(we,`Incident relations (${s(c).incidentRelations.length??""})`)),x(re,oe)};q(Ie,re=>{s(c).incidentRelations.length>0&&re(pe)})}var ye=b(Ie,2);{var M=re=>{var oe=td(),Te=b(et(oe),2);_t(Te,21,()=>s(c).provenance,Mt,(we,He)=>{var Qe=be(()=>Zr(s(He),2));let $=()=>s(Qe)[0],Y=()=>s(Qe)[1];var ge=ed(),Me=g(ge),Ye=g(Me,!0);f(Me);var _e=b(Me),Oe=g(_e,!0);f(_e),f(ge),ee(()=>{F(Ye,$()),F(Oe,Y())}),x(we,ge)}),f(Te),x(re,oe)};q(ye,re=>{s(c).provenance.length>0&&re(M)})}f(Fe),ee(()=>F(lt,s(c).title)),x(tt,Fe)};q(me,tt=>{s(c)&&tt(ve)})}var Ze=b(me,2);{var Le=tt=>{var Fe=vd(),qe=g(Fe),lt=b(g(qe),2);zc(lt,{get text(){return Fc.inspectorDefinition},label:"Definition help"}),f(qe);var L=b(qe,2);{var ne=T=>{var R=rd(),J=g(R,!0);f(R),ee(()=>F(J,s(d).unavailable)),x(T,R)},H=T=>{var R=gd(),J=et(R),Q=g(J,!0);f(J);var Pe=b(J,2),Ie=g(Pe,!0);f(Pe);var pe=b(Pe,2);{var ye=_e=>{var Oe=id(),Xe=g(Oe);f(Oe),ee(()=>F(Xe,`subclass of ${s(d).parentType??""}`)),x(_e,Oe)};q(pe,_e=>{s(d).parentType&&_e(ye)})}var M=b(pe,2);{var re=_e=>{var Oe=sd(),Xe=g(Oe,!0);f(Oe),ee(()=>F(Xe,s(d).definition)),x(_e,Oe)};q(M,_e=>{s(d).definition&&_e(re)})}var oe=b(M,2);{var Te=_e=>{var Oe=ad(),Xe=g(Oe);{var it=w=>{var z=Bn();ee(()=>F(z,`domain: ${s(d).sourceType??""}`)),x(w,z)};q(Xe,w=>{s(d).sourceType&&w(it)})}var Ve=b(Xe,2);{var I=w=>{var z=Bn();ee(()=>F(z,`· range: ${s(d).targetType??""}`)),x(w,z)};q(Ve,w=>{s(d).targetType&&w(I)})}f(Oe),x(_e,Oe)};q(oe,_e=>{(s(d).sourceType||s(d).targetType)&&_e(Te)})}var we=b(oe,2);{var He=_e=>{var Oe=od(),Xe=et(Oe),it=g(Xe),Ve=b(it,2);f(Xe);var I=b(Xe,2);{var w=z=>{Oc(z,{get ontologyId(){return r()},get domainClass(){return s(d).typeName},get kind(){return s(k)},onSaved:()=>{u(m,!1),C(n(),r(),i())},onCancel:()=>u(m,!1)})};q(I,z=>{s(m)&&z(w)})}ze("click",it,()=>(u(m,!0),u(k,"datatype"))),ze("click",Ve,()=>(u(m,!0),u(k,"object"))),x(_e,Oe)};q(we,_e=>{s(d).kind==="entity"&&r()&&_e(He)})}var Qe=b(we,2);{var $=_e=>{var Oe=cd(),Xe=et(Oe),it=g(Xe);f(Xe);var Ve=b(Xe,2);_t(Ve,21,()=>s(d).outgoingRelations,Mt,(I,w)=>{var z=ld(),ie=g(z),Ee=g(ie,!0);f(ie);var Ae=b(ie,2),Ne=g(Ae);f(Ae),f(z),ee(()=>{F(Ee,s(w).edgeType),F(Ne,`→ ${s(w).targetType??""}`)}),x(I,z)}),f(Ve),ee(()=>F(it,`Relations (${s(d).outgoingRelations.length??""})`)),x(_e,Oe)};q(Qe,_e=>{s(d).outgoingRelations.length>0&&_e($)})}var Y=b(Qe,2);{var ge=_e=>{var Oe=hd(),Xe=et(Oe),it=g(Xe);f(Xe);var Ve=b(Xe,2);_t(Ve,21,()=>s(d).properties,Mt,(I,w)=>{var z=dd(),ie=g(z),Ee=g(ie,!0);f(ie);var Ae=b(ie),Ne=g(Ae,!0);f(Ae),f(z),ee(()=>{F(Ee,s(w).name),F(Ne,s(w).range)}),x(I,z)}),f(Ve),ee(()=>F(it,`Properties (${s(d).properties.length??""})`)),x(_e,Oe)};q(Y,_e=>{s(d).properties.length>0&&_e(ge)})}var Me=b(Y,2);{var Ye=_e=>{var Oe=fd(),Xe=et(Oe),it=g(Xe);f(Xe);var Ve=b(Xe,2);_t(Ve,21,()=>s(d).triples.slice(0,12),Mt,(I,w)=>{var z=ud(),ie=g(z),Ee=g(ie,!0);f(ie);var Ae=b(ie);f(z),ee(()=>{F(Ee,s(w).subject),F(Ae,` · ${s(w).predicate??""} · ${s(w).object_value??""}`)}),x(I,z)}),f(Ve),ee(()=>F(it,`Raw triples (${s(d).triples.length??""})`)),x(_e,Oe)};q(Me,_e=>{s(d).triples.length>0&&_e(Ye)})}ee(()=>{F(Q,s(d).label??s(d).typeName),F(Ie,s(d).typeName)}),x(T,R)};q(L,T=>{s(d).unavailable?T(ne):T(H,-1)})}f(Fe),x(tt,Fe)};q(Ze,tt=>{s(d)&&tt(Le)})}var Be=b(Ze,2);{var Ge=tt=>{var Fe=wd(),qe=b(g(Fe),2);{var lt=H=>{var T=pd(),R=g(T,!0);f(T),ee(()=>F(R,s(h).unavailable)),x(H,T)},L=H=>{var T=yd(),R=g(T);f(T),ee(()=>F(R,`No taxonomy dimensions for ${s(h).ontologyId??""}.`)),x(H,T)},ne=H=>{var T=kd();_t(T,21,()=>s(h).dimensions.slice(0,10),Mt,(R,J)=>{var Q=bd(),Pe=g(Q),Ie=g(Pe,!0);f(Pe);var pe=b(Pe,2),ye=g(pe);f(pe);var M=b(pe,2);{var re=oe=>{var Te=_d();_t(Te,21,()=>s(J).values.slice(0,12),Mt,(we,He)=>{var Qe=md(),$=g(Qe,!0);f(Qe),ee(()=>F($,s(He).label??s(He).value)),x(we,Qe)}),f(Te),x(oe,Te)};q(M,oe=>{s(J).values.length>0&&oe(re)})}f(Q),ee(()=>{F(Ie,s(J).label),F(ye,`${s(J).valueType??""} · ${s(J).hierarchyKind??""}`)}),x(R,Q)}),f(T),x(H,T)};q(qe,H=>{s(h).unavailable?H(lt):s(h).dimensions.length===0?H(L,1):H(ne,-1)})}f(Fe),x(tt,Fe)};q(Be,tt=>{s(h)&&tt(Ge)})}var Je=b(Be,2),Ke=g(Je,!0);f(Je);var yt=b(Je,2);{var ut=tt=>{var Fe=xd(),qe=g(Fe,!0);f(Fe),ee(lt=>F(qe,lt),[()=>JSON.stringify(s(c).raw,null,2)]),x(tt,Fe)};q(yt,tt=>{s(p)&&s(c)?.raw&&tt(ut)})}ee(()=>F(Ke,s(p)?"Hide raw JSON":"Show raw JSON")),ze("click",Je,()=>u(p,!s(p))),x(Ce,nt)};q(Se,Ce=>{n()?s(o)?Ce(he,1):Ce(xe,-1):Ce(se)})}x(G,X)}),x(t,de),Dn()}jn(["click"]);var Dd=D('<div class="section-body svelte-9xspyz"><!></div>'),Pd=D("<option> </option>"),Id=D("<option> </option>"),Td=D('<div class="section-body display-fields svelte-9xspyz"><label class="field svelte-9xspyz"><span class="field-label svelte-9xspyz">Filter type</span> <select class="select svelte-9xspyz" aria-label="Filter type"><option> </option><!></select></label> <label class="field svelte-9xspyz"><span class="field-label svelte-9xspyz">Layout</span> <select class="select svelte-9xspyz" aria-label="Graph layout template"></select></label> <label class="field svelte-9xspyz"><span class="field-label svelte-9xspyz">Links</span> <select class="select svelte-9xspyz" aria-label="Edge link semantics"><option>All edge types</option><option>Composition</option><option>Discovery</option></select></label> <label class="field svelte-9xspyz"><span class="field-label svelte-9xspyz">TopK</span> <select class="select svelte-9xspyz" aria-label="Maximum links per source node"><option>10 per source</option><option>30 per source</option><option>100 per source</option><option>All links</option></select></label></div>'),Md=D('<div class="section-body svelte-9xspyz"><!></div>'),Ed=D('<section class="collapsible svelte-9xspyz"><button type="button" class="section-toggle svelte-9xspyz"><span aria-hidden="true">›</span> Search</button> <!></section> <section class="collapsible svelte-9xspyz"><button type="button" class="section-toggle svelte-9xspyz"><span aria-hidden="true">›</span> Display</button> <!></section> <section class="collapsible svelte-9xspyz"><button type="button" class="section-toggle svelte-9xspyz"><span aria-hidden="true">›</span> Legend</button> <!></section>',1),Ad=D('<div class="section-body selection-body svelte-9xspyz"><!></div>'),Rd=D('<div class="section-body grow-body svelte-9xspyz"><!></div>'),Od=D('<section><button type="button" class="section-toggle svelte-9xspyz"><span aria-hidden="true">›</span> Facets</button> <!></section>'),Ld=D('<div id="inspector-panel" class="panel svelte-9xspyz"><div class="sections svelte-9xspyz"><div class="sections-upper svelte-9xspyz"><!> <section class="collapsible svelte-9xspyz"><button type="button" class="section-toggle svelte-9xspyz"><span aria-hidden="true">›</span> Selection</button> <!></section></div> <!></div></div>'),Hd=D('<aside aria-label="Inspector sidebar"><button type="button" aria-controls="inspector-panel"><span class="rail-label svelte-9xspyz">Inspector</span> <span class="rail-chevron svelte-9xspyz" aria-hidden="true"> </span></button> <!></aside>');function zd(t,e){Nn(e,!0);let n=K(e,"open",15,!1),r=K(e,"sections",31,()=>$t({search:!0,display:!1,facets:!1,legend:!1,selection:!0})),i=K(e,"showGraphTools",3,!1),a=K(e,"brainOnline",3,!1),o=K(e,"selection",15,null),l=K(e,"ontologyId",3,""),c=K(e,"workspaceId",3,""),d=K(e,"ontologyKey",11,"all"),h=K(e,"layoutTemplate",15,"circular_force"),p=K(e,"edgeLinkMode",15,"all"),m=K(e,"topK",15,"30"),k=K(e,"ontologies",19,()=>[]),C=K(e,"legendBlocks",19,()=>[]),_=K(e,"facetFilter",15,null);function v(de){r({...r(),[de]:!r()[de]})}var P=Hd();let E;var B=g(P);let V;var Z=b(g(B),2),j=g(Z,!0);f(Z),f(B);var ae=b(B,2);{var ce=de=>{var W=Ld(),N=g(W),G=g(N),O=g(G);{var X=ke=>{var U=Ed(),me=et(U),ve=g(me),Ze=g(ve);let Le;Yt(),f(ve);var Be=b(ve,2);{var Ge=R=>{var J=Dd(),Q=g(J);{let Pe=be(()=>c().trim()||"default"),Ie=be(()=>e.filterEntityType?.()??null);dc(Q,{get workspaceId(){return s(Pe)},get entityType(){return s(Ie)},get onSeeds(){return e.onSeeds}})}f(J),x(R,J)};q(Be,R=>{r().search&&R(Ge)})}f(me);var Je=b(me,2),Ke=g(Je),yt=g(Ke);let ut;Yt(),f(Ke);var tt=b(Ke,2);{var Fe=R=>{var J=Td(),Q=g(J),Pe=b(g(Q),2),Ie=g(Pe),pe=g(Ie,!0);f(Ie),Ie.value=Ie.__value="all";var ye=b(Ie);_t(ye,17,k,Mt,(Xe,it)=>{var Ve=Pd(),I=g(Ve);f(Ve);var w={};ee(z=>{F(I,`${z??""} (${s(it).nodeCount??""})`),w!==(w=s(it).id)&&(Ve.value=(Ve.__value=s(it).id)??"")},[()=>e.ontologyLabel?.(s(it).id)??s(it).id]),x(Xe,Ve)}),f(Pe);var M;Di(Pe),f(Q);var re=b(Q,2),oe=b(g(re),2);_t(oe,21,()=>Ro,Mt,(Xe,it)=>{var Ve=Id(),I=g(Ve,!0);f(Ve);var w={};ee(()=>{F(I,s(it).label),w!==(w=s(it).id)&&(Ve.value=(Ve.__value=s(it).id)??"")}),x(Xe,Ve)}),f(oe),f(re);var Te=b(re,2),we=b(g(Te),2),He=g(we);He.value=He.__value="all";var Qe=b(He);Qe.value=Qe.__value="composition";var $=b(Qe);$.value=$.__value="discovery",f(we),f(Te);var Y=b(Te,2),ge=b(g(Y),2),Me=g(ge);Me.value=Me.__value="10";var Ye=b(Me);Ye.value=Ye.__value="30";var _e=b(Ye);_e.value=_e.__value="100";var Oe=b(_e);Oe.value=Oe.__value="none",f(ge),f(Y),f(J),ee(Xe=>{F(pe,Xe),M!==(M=d())&&(Pe.value=(Pe.__value=d())??"",qr(Pe,d()))},[()=>e.ontologyLabel?.("all")??"All entity types"]),ze("change",Pe,function(...Xe){e.onOntologyChange?.apply(this,Xe)}),Or(oe,h),Or(we,p),Or(ge,m),x(R,J)};q(tt,R=>{r().display&&R(Fe)})}f(Je);var qe=b(Je,2),lt=g(qe),L=g(lt);let ne;Yt(),f(lt);var H=b(lt,2);{var T=R=>{var J=Md(),Q=g(J);Fs(Q,{get legendBlocks(){return C()},variant:"legend",get facetFilter(){return _()},set facetFilter(Pe){_(Pe)}}),f(J),x(R,J)};q(H,R=>{r().legend&&R(T)})}f(qe),ee(()=>{Le=st(Ze,1,"chevron svelte-9xspyz",null,Le,{expanded:r().search}),ut=st(yt,1,"chevron svelte-9xspyz",null,ut,{expanded:r().display}),ne=st(L,1,"chevron svelte-9xspyz",null,ne,{expanded:r().legend})}),ze("click",ve,()=>v("search")),ze("click",Ke,()=>v("display")),ze("click",lt,()=>v("legend")),x(ke,U)};q(O,ke=>{i()&&a()&&ke(X)})}var ue=b(O,2),fe=g(ue),Se=g(fe);let se;Yt(),f(fe);var he=b(fe,2);{var xe=ke=>{var U=Ad(),me=g(U);Nd(me,{embedded:!0,get ontologyId(){return l()},get workspaceId(){return c()},get onOpenType(){return e.onOpenType},get selection(){return o()},set selection(ve){o(ve)}}),f(U),x(ke,U)};q(he,ke=>{r().selection&&ke(xe)})}f(ue),f(G);var Ce=b(G,2);{var nt=ke=>{var U=Od();let me;var ve=g(U),Ze=g(ve);let Le;Yt(),f(ve);var Be=b(ve,2);{var Ge=Je=>{var Ke=Rd(),yt=g(Ke);Fs(yt,{get legendBlocks(){return C()},variant:"facets",get facetFilter(){return _()},set facetFilter(ut){_(ut)}}),f(Ke),x(Je,Ke)};q(Be,Je=>{r().facets&&Je(Ge)})}f(U),ee(()=>{me=st(U,1,"collapsible collapsible-grow svelte-9xspyz",null,me,{expanded:r().facets}),Le=st(Ze,1,"chevron svelte-9xspyz",null,Le,{expanded:r().facets})}),ze("click",ve,()=>v("facets")),x(ke,U)};q(Ce,ke=>{i()&&a()&&ke(nt)})}f(N),f(W),ee(()=>se=st(Se,1,"chevron svelte-9xspyz",null,se,{expanded:r().selection})),ze("click",fe,()=>v("selection")),x(de,W)};q(ae,de=>{n()&&de(ce)})}f(P),ee(()=>{E=st(P,1,"shell svelte-9xspyz",null,E,{open:n()}),V=st(B,1,"rail svelte-9xspyz",null,V,{active:n()}),Rn(B,"aria-expanded",n()),F(j,n()?"▸":"◂")}),ze("click",B,()=>n(!n())),x(t,P),Dn()}jn(["click","change"]);function Bs(t){const e=t?.trim();if(!e?.startsWith("projection:"))return;const n=e.slice(11).trim();return n.length>0?n:void 0}function dr(t){if(!t||typeof t!="object")return[];const e=t,n=[];for(const r of["entity_id","evidence_entity_id","source_id","target_id","entity_ids","seed_ids"]){const i=e[r];if(Array.isArray(i))for(const a of i){const o=Number(a);Number.isFinite(o)&&o>0&&n.push(o)}else{const a=Number(i);Number.isFinite(a)&&a>0&&n.push(a)}}for(const r of Object.values(e))if(Array.isArray(r))for(const i of r)n.push(...dr(i));else r&&typeof r=="object"&&n.push(...dr(r));return[...new Set(n)]}function pa(t){const e=t.rows??t.projection_results??t.results;return Array.isArray(e)?e.map(n=>{const r=n,i=r.source_ref==null?null:String(r.source_ref),a=r.artifact_kind==null?r.type==null?r.proj_type==null?void 0:Fd(String(r.proj_type)):String(r.type):String(r.artifact_kind),o=r.projection_id==null?Bs(i):String(r.projection_id);return{id:r.id==null?void 0:String(r.id),artifact_id:r.artifact_id==null?void 0:String(r.artifact_id),artifact_kind:a,legacy_kind:r.legacy_kind==null?void 0:String(r.legacy_kind),public_label:r.public_label==null?void 0:String(r.public_label),scope:r.scope==null?null:String(r.scope),lifecycle:r.lifecycle==null?void 0:String(r.lifecycle),state:r.state==null?void 0:String(r.state),current_version:r.current_version==null||!Number.isFinite(Number(r.current_version))?void 0:Number(r.current_version),projection_id:o,linked_projection_id:Bs(i),type:a,status:r.status==null?void 0:String(r.status),weight:r.weight==null?void 0:Number(r.weight),proj_type:r.proj_type==null?void 0:String(r.proj_type),content:r.content==null?void 0:String(r.content).slice(0,200),preview:r.preview==null?void 0:String(r.preview).slice(0,260),source_ref:i,entity_id:dr(r)[0],graph_focusable:r.graph_focusable==null?void 0:!!r.graph_focusable,suggested_tools:Array.isArray(r.suggested_tools)?r.suggested_tools.map(l=>String(l)):void 0,linked_snapshot_id:r.linked_snapshot_id==null?void 0:String(r.linked_snapshot_id),source:r.source==null?void 0:String(r.source),raw:r}}):[]}function Fd(t){const e=t.trim().toUpperCase();return e==="FACT"||e==="STEP"||e==="GOAL"||e==="CONSTRAINT"?"analysis_plan":t}function zn(t){return t.public_label??t.artifact_id??t.projection_id??t.id??t.content??t.artifact_kind??"Artifact"}function ki(t){switch(t){case"analysis_plan":return"Analysis plan";case"answer_snapshot":return"Snapshot";case"live_answer_view":return"Live answer";case"evidence_pack":return"Evidence pack";default:return t??"Artifact"}}function ya(t,e){if(!e.label&&!e.entityType)return!1;const n=`${t.public_label??""} ${t.preview??""} ${t.content??""}`.toLowerCase(),r=(e.label??"").toLowerCase(),i=(e.entityType??"").toLowerCase();return!!(r&&n.includes(r)||i&&n.includes(i))}var ma=function(){},Xn="undefined",Bd=typeof window!==Xn&&typeof window.navigator!==Xn&&/Trident\/|MSIE /.test(window.navigator.userAgent),rs=["trace","debug","info","warn","error"],ni={},Jt=null;function js(t,e){var n=t[e];if(typeof n.bind=="function")return n.bind(t);try{return Function.prototype.bind.call(n,t)}catch{return function(){return Function.prototype.apply.apply(n,[t,arguments])}}}function jd(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function Vd(t){return t==="debug"&&(t="log"),typeof console===Xn?!1:t==="trace"&&Bd?jd:console[t]!==void 0?js(console,t):console.log!==void 0?js(console,"log"):ma}function Wr(){for(var t=this.getLevel(),e=0;e<rs.length;e++){var n=rs[e];this[n]=e<t?ma:this.methodFactory(n,t,this.name)}if(this.log=this.debug,typeof console===Xn&&t<this.levels.SILENT)return"No console available for logging"}function Kd(t){return function(){typeof console!==Xn&&(Wr.call(this),this[t].apply(this,arguments))}}function $d(t,e,n){return Vd(t)||Kd.apply(this,arguments)}function _a(t,e){var n=this,r,i,a,o="loglevel";typeof t=="string"?o+=":"+t:typeof t=="symbol"&&(o=void 0);function l(m){var k=(rs[m]||"silent").toUpperCase();if(!(typeof window===Xn||!o)){try{window.localStorage[o]=k;return}catch{}try{window.document.cookie=encodeURIComponent(o)+"="+k+";"}catch{}}}function c(){var m;if(!(typeof window===Xn||!o)){try{m=window.localStorage[o]}catch{}if(typeof m===Xn)try{var k=window.document.cookie,C=encodeURIComponent(o),_=k.indexOf(C+"=");_!==-1&&(m=/^([^;]+)/.exec(k.slice(_+C.length+1))[1])}catch{}return n.levels[m]===void 0&&(m=void 0),m}}function d(){if(!(typeof window===Xn||!o)){try{window.localStorage.removeItem(o)}catch{}try{window.document.cookie=encodeURIComponent(o)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function h(m){var k=m;if(typeof k=="string"&&n.levels[k.toUpperCase()]!==void 0&&(k=n.levels[k.toUpperCase()]),typeof k=="number"&&k>=0&&k<=n.levels.SILENT)return k;throw new TypeError("log.setLevel() called with invalid level: "+m)}n.name=t,n.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},n.methodFactory=e||$d,n.getLevel=function(){return a??i??r},n.setLevel=function(m,k){return a=h(m),k!==!1&&l(a),Wr.call(n)},n.setDefaultLevel=function(m){i=h(m),c()||n.setLevel(m,!1)},n.resetLevel=function(){a=null,d(),Wr.call(n)},n.enableAll=function(m){n.setLevel(n.levels.TRACE,m)},n.disableAll=function(m){n.setLevel(n.levels.SILENT,m)},n.rebuild=function(){if(Jt!==n&&(r=h(Jt.getLevel())),Wr.call(n),Jt===n)for(var m in ni)ni[m].rebuild()},r=h(Jt?Jt.getLevel():"WARN");var p=c();p!=null&&(a=h(p)),Wr.call(n)}Jt=new _a;Jt.getLogger=function(e){if(typeof e!="symbol"&&typeof e!="string"||e==="")throw new TypeError("You must supply a name when creating a logger.");var n=ni[e];return n||(n=ni[e]=new _a(e,Jt.methodFactory)),n};var Zd=typeof window!==Xn?window.log:void 0;Jt.noConflict=function(){return typeof window!==Xn&&window.log===Jt&&(window.log=Zd),Jt};Jt.getLoggers=function(){return ni};Jt.default=Jt;var Ud=function(t){for(var e=1,n=arguments.length,r;e<n;e++)for(r in arguments[e])Object.prototype.hasOwnProperty.call(arguments[e],r)&&(t[r]=arguments[e][r]);return t},Wd={template:"[%t] %l:",levelFormatter:function(t){return t.toUpperCase()},nameFormatter:function(t){return t||"root"},timestampFormatter:function(t){return t.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")},format:void 0},ba,_r={},Gd=function(t){if(!t||!t.getLogger)throw new TypeError("Argument is not a root logger");ba=t},Yd=function(t,e){if(!t||!t.setLevel)throw new TypeError("Argument is not a logger");var n=t.methodFactory,r=t.name||"",i=_r[r]||_r[""]||Wd;function a(o,l,c){var d=n(o,l,c),h=_r[c]||_r[""],p=h.template.indexOf("%t")!==-1,m=h.template.indexOf("%l")!==-1,k=h.template.indexOf("%n")!==-1;return function(){for(var C="",_=arguments.length,v=Array(_),P=0;P<_;P++)v[P]=arguments[P];if(r||!_r[c]){var E=h.timestampFormatter(new Date),B=h.levelFormatter(o),V=h.nameFormatter(c);h.format?C+=h.format(B,V,E):(C+=h.template,p&&(C=C.replace(/%t/,E)),m&&(C=C.replace(/%l/,B)),k&&(C=C.replace(/%n/,V))),v.length&&typeof v[0]=="string"?v[0]=C+" "+v[0]:v.unshift(C)}d.apply(void 0,v)}}return _r[r]||(t.methodFactory=a),e=e||{},e.template&&(e.format=void 0),_r[r]=Ud({},i,e),t.setLevel(t.getLevel()),ba||t.warn("It is necessary to call the function reg() of loglevel-plugin-prefix before calling apply. From the next release, it will throw an error. See more: https://github.com/kutuluk/loglevel-plugin-prefix/blob/master/README.md"),t},Ai={reg:Gd,apply:Yd};const Xd={trace:"#9ca3af",debug:"#0ea5e9",info:"#10b981",warn:"#f59e0b",error:"#ef4444"};Ai.reg(Jt);Jt.setLevel("silent");const Jd={format(t,e,n){return`%c[${n}]%c %c[${t.toUpperCase()}]%c %c[${e}]%c`},timestampFormatter(t){return t.toTimeString().split(" ")[0]+"."+t.getMilliseconds().toString().padStart(3,"0")}};function Qd(t){return function(e,n,r){const i=t(e,n,r);return function(...a){if(a.length>0&&typeof a[0]=="string"&&a[0].includes("%c")){const o=Xd[e]||"#666",l=(a[0].match(/%c/g)||[]).length,c=[];for(let d=0;d<l;d++)c.push(d%2===0?`color: ${o}; font-weight: bold;`:"color: inherit;");i(a[0],...c,...a.slice(1))}else i(...a)}}}const qd=Jt.getLogger("LTREE:INIT"),eh=Jt.getLogger("LTREE:DATA"),wi=Jt.getLogger("LTREE:RENDER"),Gn=Jt.getLogger("LTREE:INDEX"),Wt=Jt.getLogger("LTREE:DRAG"),Sn=Jt.getLogger("LTREE:UI"),th=[qd,eh,wi,Gn,Wt,Sn];th.forEach(t=>{const e=t.methodFactory;t.methodFactory=Qd(e),Ai.apply(t,Jd),t.setLevel("silent")});var nh=D("<span></span>"),rh=D("<span></span>"),ih=D('<label class="ltree-checkbox"><input type="checkbox"/> <span class="ltree-checkbox__box"></span></label>'),sh=D('<div class="ltree-loading-more"> </div>'),ah=D('<div class="ltree-children"><!> <!></div>'),oh=D('<div class="ltree-node"><div class="ltree-node-row"><!> <!> <div><!></div></div> <!></div>');function xi(t,e){Nn(e,!0);let n=K(e,"node",7),r=K(e,"children",3,void 0),i=K(e,"progressiveRender",3,!1),a=K(e,"renderBatchSize",3,50),o=K(e,"isDraggedNode",3,!1),l=K(e,"isDragInProgress",3,!1),c=K(e,"hoveredNodeForDropPath",3,null),d=K(e,"activeDropPosition",3,null),h=K(e,"dropOperation",3,"move"),p=K(e,"flatMode",3,!1),m=K(e,"flatGap",3,!1);const k=li("NodeCallbacks"),C=li("NodeConfig"),{expandIconClass:_,collapseIconClass:v,leafIconClass:P,highlightedNodeClass:E,focusedNodeClass:B,dragOverNodeClass:V,allowCopy:Z}=C,j=be(()=>C.clickBehavior),ae=be(()=>C.showCheckboxes),ce=be(()=>C.checkboxMode),de=be(()=>s(ce)==="cascade"&&n().visualState==="indeterminate"),W=be(()=>C.dropZoneMode),N=be(()=>C.dropZoneStart),G=be(()=>C.accordionExpand),O=be(()=>C.toggleIconMode),X=be(()=>c()===n().path),ue=li("Ltree"),fe=li("RenderCoordinator");let Se=A(!1),se=A(null);const he=be(()=>ue.getNodeAllowedDropPositions(n()));function xe(M){return!s(he)||s(he).length===0?!0:s(he).includes(M)}function Ce(M,re){const oe=re.getBoundingClientRect(),Te=M.clientX-oe.left,we=M.clientY-oe.top,He=oe.width,Qe=oe.height,$=typeof s(N)=="number"?s(N)/100*He:typeof s(N)=="string"&&s(N).endsWith("px")?parseFloat(s(N)):typeof s(N)=="string"?parseFloat(s(N))/100*He:He/2,Y=isNaN($)?He/2:$;let ge;return Te>Y?ge="child":we<Qe/2?ge="before":ge="after",!s(he)||s(he).length===0||s(he).includes(ge)?ge:s(he).length===1?s(he)[0]:s(he).includes("before")&&s(he).includes("after")?we<Qe/2?"before":"after":s(he)[0]}const nt=be(()=>ue.getNodeIsCollapsible(n())),ke=be(()=>p()?[]:Object.values(n()?.children||[])),U=be(()=>n()?.hasChildren||!1),me=be(()=>p()?`margin-left: calc(${n()?.level||1} * var(--tree-node-indent-per-level, 0.5rem))${m()?"; margin-top: 2px":""}`:"margin-left: var(--tree-node-indent-per-level, 0.5rem)");let ve=A(0),Ze=null,Le=!1,Be=0;const Ge=be(()=>!p()&&i()&&fe?s(ke).slice(0,s(ve)):s(ke)),Je=be(()=>!p()&&i()&&fe&&s(ve)<s(ke).length);De(()=>{if(p())return;const M=n()?.isExpanded??!1,re=s(ke).length,oe=i()&&fe&&re>0;if(M!==Le||re!==Be)if(Le=M,Be=re,M&&oe){if(Ze&&(Ze(),Ze=null),fe.isCompleted(n().path)){u(ve,re,!0);return}u(ve,Math.min(a(),re),!0),s(ve)<re&&(Ze=fe.register(n().path,()=>s(ve)<re?(u(ve,Math.min(s(ve)+a(),re),!0),s(ve)<re):!1))}else M||(Ze&&(Ze(),Ze=null),u(ve,0))}),ra(()=>{Ze&&(Ze(),Ze=null)});function Ke(){if(n().hasChildren&&s(nt)){const M=!n().isExpanded;if(M&&s(G)){const re=ue.getSiblings(n().path);console.log(`[accordion] expanding ${n().path}, checking ${re.length} siblings, accordionExpand=${s(G)}`);for(const oe of re)oe.path!==n().path&&oe.isExpanded&&ue.getNodeIsCollapsible(oe)&&(console.log(`[accordion] collapsing sibling: ${oe.path}`),oe.isExpanded=!1,oe._rev=(oe._rev||0)+1)}Sn.debug(`${M?"Expanding":"Collapsing"} node: ${n().path}`),n().isExpanded=M,n()._rev=(n()._rev||0)+1,ue.refresh()}}function yt(M,re){return M.indeterminate=re,{update(oe){M.indeterminate=oe}}}function ut(M){Sn.debug(`Node clicked: ${n().path}`,{id:n().id,hasChildren:n().hasChildren});const re=M?{ctrl:M.ctrlKey||M.metaKey,shift:M.shiftKey}:void 0;s(j)==="expand"?Ke():s(j)==="expand-and-focus"?(k.onNodeClicked(n(),re),Ke()):k.onNodeClicked(n(),re)}function tt(M){s(j)==="select"&&Ke()}var Fe=oh(),qe=g(Fe),lt=g(qe);{var L=M=>{var re=nh();let oe;ee(()=>oe=st(re,1,`ltree-toggle-icon ltree-clickable ${(s(O)==="swap"&&n().isExpanded?v:_)??""}`,null,oe,{expanded:s(O)==="rotate"&&n().isExpanded})),ze("click",re,Ke),x(M,re)},ne=M=>{var re=rh();ee(()=>st(re,1,`ltree-toggle-icon ${P??""}`)),x(M,re)};q(lt,M=>{s(U)&&s(nt)?M(L):M(ne,-1)})}var H=b(lt,2);{var T=M=>{var re=ih(),oe=g(re);Mn(oe),Rn(oe,"tabindex",-1),Po(oe,(Te,we)=>yt?.(Te,we),()=>s(de)),Yt(2),f(re),ee(()=>ko(oe,n().isSelected&&!s(de))),ze("click",re,Te=>{Te.preventDefault(),Te.stopPropagation(),k.onCheckboxToggle(n())}),x(M,re)};q(H,M=>{s(ae)&&n().isSelectable&&M(T)})}var R=b(H,2);let J;var Q=g(R);{var Pe=M=>{var re=zt(),oe=et(re);Hn(oe,r,n),x(M,re)},Ie=M=>{var re=Bn();ee(oe=>F(re,oe),[()=>ue.getNodeDisplayValue(n())]),x(M,re)};q(Q,M=>{r()?M(Pe):M(Ie,-1)})}f(R),f(qe);var pe=b(qe,2);{var ye=M=>{var re=ah(),oe=g(re);_t(oe,17,()=>s(Ge),He=>He.id,(He,Qe)=>{xi(He,{get node(){return s(Qe)},get children(){return r()},get progressiveRender(){return i()},get renderBatchSize(){return a()},get isDraggedNode(){return o()},get isDragInProgress(){return l()},get hoveredNodeForDropPath(){return c()},get activeDropPosition(){return d()},get dropOperation(){return h()}})});var Te=b(oe,2);{var we=He=>{var Qe=sh(),$=g(Qe);f(Qe),ee(()=>F($,`Loading... (${s(ve)??""}/${s(ke).length??""})`)),x(He,Qe)};q(Te,He=>{s(Je)&&He(we)})}f(re),x(M,re)};q(pe,M=>{!p()&&n()?.isExpanded&&n()?.hasChildren&&M(ye)})}f(Fe),ee(M=>{Rn(Fe,"id",`${n().treeId??""}-${n().id??""}`),Rn(Fe,"data-tree-path",n().path),rr(Fe,s(me)),J=st(R,1,`ltree-node-content ${(n().isHighlighted?E:"")??""} ${(n().isFocused&&B?B:"")??""} ${(s(Se)&&V?V:"")??""}`,null,J,M),Rn(R,"draggable",n()?.isDraggable)},[()=>({"ltree-clickable":n().isSelectable,"ltree-dragged":o(),"ltree-draggable":n()?.isDraggable,"ltree-glow-before":s(W)==="glow"&&l()&&s(X)&&s(se)==="before"&&xe("before"),"ltree-glow-after":s(W)==="glow"&&l()&&s(X)&&s(se)==="after"&&xe("after"),"ltree-glow-child":s(W)==="glow"&&l()&&s(X)&&s(se)==="child"&&xe("child"),"ltree-drop-copy":l()&&s(X)&&h()==="copy"})]),ze("click",R,M=>{M.stopPropagation(),ut(M)}),ze("dblclick",R,M=>{M.stopPropagation(),tt()}),ze("contextmenu",R,M=>{M.stopPropagation(),k.onNodeRightClicked(n(),M)}),Ct("dragstart",R,M=>{n()?.isDraggable&&M.dataTransfer&&(M.dataTransfer.effectAllowed=Z?"copyMove":"move",M.dataTransfer.setData("application/svelte-treeview",JSON.stringify(n())),k.onNodeDragStart(n(),M))}),Ct("dragover",R,M=>{M.dataTransfer?.types.includes("application/svelte-treeview")&&(M.preventDefault(),M.dataTransfer&&(M.dataTransfer.dropEffect=Z&&M.ctrlKey?"copy":"move"),u(Se,!0),s(W)==="glow"&&u(se,Ce(M,M.currentTarget),!0)),k.onNodeDragOver(n(),M)}),Ct("dragleave",R,M=>{const re=M.currentTarget.getBoundingClientRect(),oe=M.clientX,Te=M.clientY;(oe<re.left||oe>=re.right||Te<re.top||Te>=re.bottom)&&(u(Se,!1),u(se,null),k.onNodeDragLeave(n(),M))}),Ct("drop",R,M=>{M.stopPropagation(),M.dataTransfer&&(M.dataTransfer.dropEffect=Z&&M.ctrlKey?"copy":"move"),u(Se,!1),s(W)==="glow"&&s(se)?k.onZoneDrop(n(),s(se),M):k.onNodeDrop(n(),M),u(se,null)}),ze("touchstart",R,M=>k.onTouchDragStart(n(),M)),ze("touchmove",R,M=>k.onTouchDragMove(n(),M)),ze("touchend",R,M=>k.onTouchDragEnd(n(),M)),x(t,Fe),Dn()}jn(["click","dblclick","contextmenu","touchstart","touchmove","touchend"]);var nr;(function(t){t.indeterminate="indeterminate",t.selected="true",t.notSelected="false"})(nr||(nr={}));function Pr(t){return{treeId:"",path:"",pathSegment:"",parentPath:void 0,level:void 0,id:-1,children:{},hasChildren:!1,data:void 0,isDraggable:!0,isCollapsible:!0,isDropAllowed:!0,allowedDropPositions:void 0,visualState:nr.notSelected,isExpanded:!1,isFocused:!1,isHighlighted:!1,isSelected:!1,isSelectable:!0,_rev:0,...t}}var We;function Cn(t,e,n){const r=typeof n,i=typeof t;if(r!=="undefined"){if(i!=="undefined"){if(n){if(i==="function"&&r===i)return function(l){return t(n(l))};if(e=t.constructor,e===n.constructor){if(e===Array)return n.concat(t);if(e===Map){var a=new Map(n);for(var o of t)a.set(o[0],o[1]);return a}if(e===Set){o=new Set(n);for(a of t.values())o.add(a);return o}}}return t}return n}return i==="undefined"?e:t}function Ir(t,e){return typeof t>"u"?e:t}function gn(){return Object.create(null)}function Jn(t){return typeof t=="string"}function ri(t){return typeof t=="object"}function ii(t,e){if(Jn(e))t=t[e];else for(let n=0;t&&n<e.length;n++)t=t[e[n]];return t}const lh=/[^\p{L}\p{N}]+/u,ch=/(\d{3})/g,dh=/(\D)(\d{3})/g,hh=/(\d{3})(\D)/g,Vs=/[\u0300-\u036f]/g;function si(t={}){if(!this||this.constructor!==si)return new si(...arguments);if(arguments.length)for(t=0;t<arguments.length;t++)this.assign(arguments[t]);else this.assign(t)}We=si.prototype;We.assign=function(t){this.normalize=Cn(t.normalize,!0,this.normalize);let e=t.include,n=e||t.exclude||t.split,r;if(n||n===""){if(typeof n=="object"&&n.constructor!==RegExp){let i="";r=!e,e||(i+="\\p{Z}"),n.letter&&(i+="\\p{L}"),n.number&&(i+="\\p{N}",r=!!e),n.symbol&&(i+="\\p{S}"),n.punctuation&&(i+="\\p{P}"),n.control&&(i+="\\p{C}"),(n=n.char)&&(i+=typeof n=="object"?n.join(""):n);try{this.split=new RegExp("["+(e?"^":"")+i+"]+","u")}catch{this.split=/\s+/}}else this.split=n,r=n===!1||"a1a".split(n).length<2;this.numeric=Cn(t.numeric,r)}else{try{this.split=Cn(this.split,lh)}catch{this.split=/\s+/}this.numeric=Cn(t.numeric,Cn(this.numeric,!0))}if(this.prepare=Cn(t.prepare,null,this.prepare),this.finalize=Cn(t.finalize,null,this.finalize),n=t.filter,this.filter=typeof n=="function"?n:Cn(n&&new Set(n),null,this.filter),this.dedupe=Cn(t.dedupe,!0,this.dedupe),this.matcher=Cn((n=t.matcher)&&new Map(n),null,this.matcher),this.mapper=Cn((n=t.mapper)&&new Map(n),null,this.mapper),this.stemmer=Cn((n=t.stemmer)&&new Map(n),null,this.stemmer),this.replacer=Cn(t.replacer,null,this.replacer),this.minlength=Cn(t.minlength,1,this.minlength),this.maxlength=Cn(t.maxlength,1024,this.maxlength),this.rtl=Cn(t.rtl,!1,this.rtl),(this.cache=n=Cn(t.cache,!0,this.cache))&&(this.F=null,this.L=typeof n=="number"?n:2e5,this.B=new Map,this.D=new Map,this.I=this.H=128),this.h="",this.J=null,this.A="",this.K=null,this.matcher)for(const i of this.matcher.keys())this.h+=(this.h?"|":"")+i;if(this.stemmer)for(const i of this.stemmer.keys())this.A+=(this.A?"|":"")+i;return this};We.addStemmer=function(t,e){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(t,e),this.A+=(this.A?"|":"")+t,this.K=null,this.cache&&wr(this),this};We.addFilter=function(t){return typeof t=="function"?this.filter=t:(this.filter||(this.filter=new Set),this.filter.add(t)),this.cache&&wr(this),this};We.addMapper=function(t,e){return typeof t=="object"?this.addReplacer(t,e):t.length>1?this.addMatcher(t,e):(this.mapper||(this.mapper=new Map),this.mapper.set(t,e),this.cache&&wr(this),this)};We.addMatcher=function(t,e){return typeof t=="object"?this.addReplacer(t,e):t.length<2&&(this.dedupe||this.mapper)?this.addMapper(t,e):(this.matcher||(this.matcher=new Map),this.matcher.set(t,e),this.h+=(this.h?"|":"")+t,this.J=null,this.cache&&wr(this),this)};We.addReplacer=function(t,e){return typeof t=="string"?this.addMatcher(t,e):(this.replacer||(this.replacer=[]),this.replacer.push(t,e),this.cache&&wr(this),this)};We.encode=function(t,e){if(this.cache&&t.length<=this.H)if(this.F){if(this.B.has(t))return this.B.get(t)}else this.F=setTimeout(wr,50,this);this.normalize&&(typeof this.normalize=="function"?t=this.normalize(t):t=Vs?t.normalize("NFKD").replace(Vs,"").toLowerCase():t.toLowerCase()),this.prepare&&(t=this.prepare(t)),this.numeric&&t.length>3&&(t=t.replace(dh,"$1 $2").replace(hh,"$1 $2").replace(ch,"$1 "));const n=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let r=[],i=gn(),a,o,l=this.split||this.split===""?t.split(this.split):[t];for(let d=0,h,p;d<l.length;d++)if((h=p=l[d])&&!(h.length<this.minlength||h.length>this.maxlength)){if(e){if(i[h])continue;i[h]=1}else{if(a===h)continue;a=h}if(n)r.push(h);else if(!this.filter||(typeof this.filter=="function"?this.filter(h):!this.filter.has(h))){if(this.cache&&h.length<=this.I)if(this.F){var c=this.D.get(h);if(c||c===""){c&&r.push(c);continue}}else this.F=setTimeout(wr,50,this);if(this.stemmer){this.K||(this.K=new RegExp("(?!^)("+this.A+")$"));let m;for(;m!==h&&h.length>2;)m=h,h=h.replace(this.K,k=>this.stemmer.get(k))}if(h&&(this.mapper||this.dedupe&&h.length>1)){c="";for(let m=0,k="",C,_;m<h.length;m++)C=h.charAt(m),C===k&&this.dedupe||((_=this.mapper&&this.mapper.get(C))||_===""?_===k&&this.dedupe||!(k=_)||(c+=_):c+=k=C);h=c}if(this.matcher&&h.length>1&&(this.J||(this.J=new RegExp("("+this.h+")","g")),h=h.replace(this.J,m=>this.matcher.get(m))),h&&this.replacer)for(c=0;h&&c<this.replacer.length;c+=2)h=h.replace(this.replacer[c],this.replacer[c+1]);if(this.cache&&p.length<=this.I&&(this.D.set(p,h),this.D.size>this.L&&(this.D.clear(),this.I=this.I/1.1|0)),h){if(h!==p)if(e){if(i[h])continue;i[h]=1}else{if(o===h)continue;o=h}r.push(h)}}}return this.finalize&&(r=this.finalize(r)||r),this.cache&&t.length<=this.H&&(this.B.set(t,r),this.B.size>this.L&&(this.B.clear(),this.H=this.H/1.1|0)),r};function wr(t){t.F=null,t.B.clear(),t.D.clear()}function vs(t,e,n){n||(e||typeof t!="object"?typeof e=="object"&&(n=e,e=0):n=t),n&&(t=n.query||t,e=n.limit||e);let r=""+(e||0);n&&(r+=(n.offset||0)+!!n.context+!!n.suggest+(n.resolve!==!1)+(n.resolution||this.resolution)+(n.boost||0)),t=(""+t).toLowerCase(),this.cache||(this.cache=new Cr);let i=this.cache.get(t+r);if(!i){const a=n&&n.cache;a&&(n.cache=!1),i=this.search(t,e,n),a&&(n.cache=a),this.cache.set(t+r,i)}return i}function Cr(t){this.limit=t&&t!==!0?t:1e3,this.cache=new Map,this.h=""}Cr.prototype.set=function(t,e){this.cache.set(this.h=t,e),this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};Cr.prototype.get=function(t){const e=this.cache.get(t);return e&&this.h!==t&&(this.cache.delete(t),this.cache.set(this.h=t,e)),e};Cr.prototype.remove=function(t){for(const e of this.cache){const n=e[0];e[1].includes(t)&&this.cache.delete(n)}};Cr.prototype.clear=function(){this.cache.clear(),this.h=""};const Ks={normalize:!1,numeric:!1,dedupe:!1},vi={},Wi=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]),$s=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Zs=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"],Us={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,ß:2,d:3,t:3,l:4,m:5,n:5,r:6};var ps={Exact:Ks,Default:vi,Normalize:vi,LatinBalance:{mapper:Wi},LatinAdvanced:{mapper:Wi,matcher:$s,replacer:Zs},LatinExtra:{mapper:Wi,replacer:Zs.concat([/(?!^)[aeo]/g,""]),matcher:$s},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(t){for(let n=0;n<t.length;n++){var e=t[n];let r=e.charAt(0),i=Us[r];for(let a=1,o;a<e.length&&(o=e.charAt(a),o==="h"||o==="w"||!(o=Us[o])||o===i||(r+=o,i=o,r.length!==4));a++);t[n]=r}}},CJK:{split:""},LatinExact:Ks,LatinDefault:vi,LatinSimple:vi};function Ws(t,e,n,r){let i=[];for(let a=0,o;a<t.index.length;a++)if(o=t.index[a],e>=o.length)e-=o.length;else{e=o[r?"splice":"slice"](e,n);const l=e.length;if(l&&(i=i.length?i.concat(e):e,n-=l,r&&(t.length-=l),!n))break;e=0}return i}function Fr(t){if(!this||this.constructor!==Fr)return new Fr(t);this.index=t?[t]:[],this.length=t?t.length:0;const e=this;return new Proxy([],{get(n,r){if(r==="length")return e.length;if(r==="push")return function(i){e.index[e.index.length-1].push(i),e.length++};if(r==="pop")return function(){if(e.length)return e.length--,e.index[e.index.length-1].pop()};if(r==="indexOf")return function(i){let a=0;for(let o=0,l,c;o<e.index.length;o++){if(l=e.index[o],c=l.indexOf(i),c>=0)return a+c;a+=l.length}return-1};if(r==="includes")return function(i){for(let a=0;a<e.index.length;a++)if(e.index[a].includes(i))return!0;return!1};if(r==="slice")return function(i,a){return Ws(e,i||0,a||e.length,!1)};if(r==="splice")return function(i,a){return Ws(e,i||0,a||e.length,!0)};if(r==="constructor")return Array;if(typeof r!="symbol")return(n=e.index[r/2**31|0])&&n[r]},set(n,r,i){return n=r/2**31|0,(e.index[n]||(e.index[n]=[]))[r]=i,e.length++,!0}})}Fr.prototype.clear=function(){this.index.length=0};Fr.prototype.push=function(){};function Qn(t=8){if(!this||this.constructor!==Qn)return new Qn(t);this.index=gn(),this.h=[],this.size=0,t>32?(this.B=wa,this.A=BigInt(t)):(this.B=ka,this.A=t)}Qn.prototype.get=function(t){const e=this.index[this.B(t)];return e&&e.get(t)};Qn.prototype.set=function(t,e){var n=this.B(t);let r=this.index[n];r?(n=r.size,r.set(t,e),(n-=r.size)&&this.size++):(this.index[n]=r=new Map([[t,e]]),this.h.push(r),this.size++)};function qn(t=8){if(!this||this.constructor!==qn)return new qn(t);this.index=gn(),this.h=[],this.size=0,t>32?(this.B=wa,this.A=BigInt(t)):(this.B=ka,this.A=t)}qn.prototype.add=function(t){var e=this.B(t);let n=this.index[e];n?(e=n.size,n.add(t),(e-=n.size)&&this.size++):(this.index[e]=n=new Set([t]),this.h.push(n),this.size++)};We=Qn.prototype;We.has=qn.prototype.has=function(t){const e=this.index[this.B(t)];return e&&e.has(t)};We.delete=qn.prototype.delete=function(t){const e=this.index[this.B(t)];e&&e.delete(t)&&this.size--};We.clear=qn.prototype.clear=function(){this.index=gn(),this.h=[],this.size=0};We.values=qn.prototype.values=function*(){for(let t=0;t<this.h.length;t++)for(let e of this.h[t].values())yield e};We.keys=qn.prototype.keys=function*(){for(let t=0;t<this.h.length;t++)for(let e of this.h[t].keys())yield e};We.entries=qn.prototype.entries=function*(){for(let t=0;t<this.h.length;t++)for(let e of this.h[t].entries())yield e};function ka(t){let e=2**this.A-1;if(typeof t=="number")return t&e;let n=0,r=this.A+1;for(let i=0;i<t.length;i++)n=(n*r^t.charCodeAt(i))&e;return this.A===32?n+2**31:n}function wa(t){let e=BigInt(2)**this.A-BigInt(1);var n=typeof t;if(n==="bigint")return t&e;if(n==="number")return BigInt(t)&e;n=BigInt(0);let r=this.A+BigInt(1);for(let i=0;i<t.length;i++)n=(n*r^BigInt(t.charCodeAt(i)))&e;return n}let Tr,$r;async function uh(t){t=t.data;var e=t.task;const n=t.id;let r=t.args;if(e==="init")$r=t.options||{},(e=t.factory)?(Function("return "+e)()(self),Tr=new self.FlexSearch.Index($r),delete self.FlexSearch):Tr=new er($r),postMessage({id:n});else{let i;e==="export"&&(r[1]?(r[0]=$r.export,r[2]=0,r[3]=1):r=null),e==="import"?r[0]&&(t=await $r.import.call(Tr,r[0]),Tr.import(r[0],t)):((i=r&&Tr[e].apply(Tr,r))&&i.then&&(i=await i),i&&i.await&&(i=await i.await),e==="search"&&i.result&&(i=i.result)),postMessage(e==="search"?{id:n,msg:i}:{id:n})}}function ys(t){Mr.call(t,"add"),Mr.call(t,"append"),Mr.call(t,"search"),Mr.call(t,"update"),Mr.call(t,"remove"),Mr.call(t,"searchCache")}let is,Gs,Ci;function fh(){is=Ci=0}function Mr(t){this[t+"Async"]=function(){const e=arguments;var n=e[e.length-1];let r;if(typeof n=="function"&&(r=n,delete e[e.length-1]),is?Ci||(Ci=Date.now()-Gs>=this.priority*this.priority*3):(is=setTimeout(fh,0),Gs=Date.now()),Ci){const a=this;return new Promise(o=>{setTimeout(function(){o(a[t+"Async"].apply(a,e))},0)})}const i=this[t].apply(this,e);return n=i.then?i:new Promise(a=>a(i)),r&&n.then(r),n}}let gr=0;function Br(t={},e){function n(l){function c(d){d=d.data||d;const h=d.id,p=h&&a.h[h];p&&(p(d.msg),delete a.h[h])}if(this.worker=l,this.h=gn(),this.worker)return i?this.worker.on("message",c):this.worker.onmessage=c,t.config?new Promise(function(d){gr>1e9&&(gr=0),a.h[++gr]=function(){d(a)},a.worker.postMessage({id:gr,task:"init",factory:r,options:t})}):(this.priority=t.priority||4,this.encoder=e||null,this.worker.postMessage({task:"init",factory:r,options:t}),this)}if(!this||this.constructor!==Br)return new Br(t);let r=typeof self<"u"?self._factory:typeof window<"u"?window._factory:null;r&&(r=r.toString());const i=typeof window>"u",a=this,o=gh(r,i,t.worker);return o.then?o.then(function(l){return n.call(a,l)}):n.call(this,o)}vr("add");vr("append");vr("search");vr("update");vr("remove");vr("clear");vr("export");vr("import");Br.prototype.searchCache=vs;ys(Br.prototype);function vr(t){Br.prototype[t]=function(){const e=this,n=[].slice.call(arguments);var r=n[n.length-1];let i;return typeof r=="function"&&(i=r,n.pop()),r=new Promise(function(a){t==="export"&&typeof n[0]=="function"&&(n[0]=null),gr>1e9&&(gr=0),e.h[++gr]=a,e.worker.postMessage({task:t,id:gr,args:n})}),i?(r.then(i),this):r}}function gh(t,e,n){return e?typeof module<"u"?new(require("worker_threads")).Worker(__dirname+"/worker/node.js"):Yn(()=>import("../chunks/BIHI7g3E.js"),[],import.meta.url).then(function(r){return new r.Worker(import.meta.dirname+"/node/node.mjs")}):t?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+uh.toString()],{type:"text/javascript"}))):new window.Worker(typeof n=="string"?n:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js","module/worker/worker.js").replace("flexsearch.bundle.module.min.mjs","module/worker/worker.js"),{type:"module"})}jr.prototype.add=function(t,e,n){if(ri(t)&&(e=t,t=ii(e,this.key)),e&&(t||t===0)){if(!n&&this.reg.has(t))return this.update(t,e);for(let l=0,c;l<this.field.length;l++){c=this.B[l];var r=this.index.get(this.field[l]);if(typeof c=="function"){var i=c(e);i&&r.add(t,i,n,!0)}else i=c.G,(!i||i(e))&&(c.constructor===String?c=[""+c]:Jn(c)&&(c=[c]),as(e,c,this.D,0,r,t,c[0],n))}if(this.tag)for(r=0;r<this.A.length;r++){var a=this.A[r];i=this.tag.get(this.F[r]);let l=gn();if(typeof a=="function"){if(a=a(e),!a)continue}else{var o=a.G;if(o&&!o(e))continue;a.constructor===String&&(a=""+a),a=ii(e,a)}if(i&&a){Jn(a)&&(a=[a]);for(let c=0,d,h;c<a.length;c++)if(d=a[c],!l[d]&&(l[d]=1,(o=i.get(d))?h=o:i.set(d,h=[]),!n||!h.includes(t))){if(h.length===2**31-1){if(o=new Fr(h),this.fastupdate)for(let p of this.reg.values())p.includes(h)&&(p[p.indexOf(h)]=o);i.set(d,h=o)}h.push(t),this.fastupdate&&((o=this.reg.get(t))?o.push(h):this.reg.set(t,[h]))}}}if(this.store&&(!n||!this.store.has(t))){let l;if(this.h){l=gn();for(let c=0,d;c<this.h.length;c++){if(d=this.h[c],(n=d.G)&&!n(e))continue;let h;if(typeof d=="function"){if(h=d(e),!h)continue;d=[d.O]}else if(Jn(d)||d.constructor===String){l[d]=e[d];continue}ss(e,l,d,0,d[0],h)}}this.store.set(t,l||e)}this.worker&&(this.fastupdate||this.reg.add(t))}return this};function ss(t,e,n,r,i,a){if(t=t[i],r===n.length-1)e[i]=a||t;else if(t)if(t.constructor===Array)for(e=e[i]=Array(t.length),i=0;i<t.length;i++)ss(t,e,n,r,i);else e=e[i]||(e[i]=gn()),i=n[++r],ss(t,e,n,r,i)}function as(t,e,n,r,i,a,o,l){if(t=t[o])if(r===e.length-1){if(t.constructor===Array){if(n[r]){for(e=0;e<t.length;e++)i.add(a,t[e],!0,!0);return}t=t.join(" ")}i.add(a,t,l,!0)}else if(t.constructor===Array)for(o=0;o<t.length;o++)as(t,e,n,r,i,a,o,l);else o=e[++r],as(t,e,n,r,i,a,o,l)}function ms(t,e,n,r){if(!t.length)return t;if(t.length===1)return t=t[0],t=n||t.length>e?t.slice(n,n+e):t,r?Hr.call(this,t):t;let i=[];for(let a=0,o,l;a<t.length;a++)if((o=t[a])&&(l=o.length)){if(n){if(n>=l){n-=l;continue}o=o.slice(n,n+e),l=o.length,n=0}if(l>e&&(o=o.slice(0,e),l=e),!i.length&&l>=e)return r?Hr.call(this,o):o;if(i.push(o),e-=l,!e)break}return i=i.length>1?[].concat.apply([],i):i[0],r?Hr.call(this,i):i}function Ri(t,e,n,r){var i=r[0];if(i[0]&&i[0].query)return t[e].apply(t,i);if(!(e!=="and"&&e!=="not"||t.result.length||t.await||i.suggest))return r.length>1&&(i=r[r.length-1]),(r=i.resolve)?t.await||t.result:t;let a=[],o=0,l=0,c,d,h,p,m;for(e=0;e<r.length;e++)if(i=r[e]){var k=void 0;if(i.constructor===Gt)k=i.await||i.result;else if(i.then||i.constructor===Array)k=i;else{o=i.limit||0,l=i.offset||0,h=i.suggest,d=i.resolve,c=((p=i.highlight||t.highlight)||i.enrich)&&d,k=i.queue;let C=i.async||k,_=i.index,v=i.query;if(_?t.index||(t.index=_):_=t.index,v||i.tag){const P=i.field||i.pluck;if(P&&(!v||t.query&&!p||(t.query=v,t.field=P,t.highlight=p),_=_.index.get(P)),k&&(m||t.await)){m=1;let E;const B=t.C.length,V=new Promise(function(Z){E=Z});(function(Z,j){V.h=function(){j.index=null,j.resolve=!1;let ae=C?Z.searchAsync(j):Z.search(j);return ae.then?ae.then(function(ce){return t.C[B]=ce=ce.result||ce,E(ce),ce}):(ae=ae.result||ae,E(ae),ae)}})(_,Object.assign({},i)),t.C.push(V),a[e]=V;continue}else i.resolve=!1,i.index=null,k=C?_.searchAsync(i):_.search(i),i.resolve=d,i.index=_}else if(i.and)k=pi(i,"and",_);else if(i.or)k=pi(i,"or",_);else if(i.not)k=pi(i,"not",_);else if(i.xor)k=pi(i,"xor",_);else continue}k.await?(m=1,k=k.await):k.then?(m=1,k=k.then(function(C){return C.result||C})):k=k.result||k,a[e]=k}if(m&&!t.await&&(t.await=new Promise(function(C){t.return=C})),m){const C=Promise.all(a).then(function(_){for(let v=0;v<t.C.length;v++)if(t.C[v]===C){t.C[v]=function(){return n.call(t,_,o,l,c,d,h,p)};break}_s(t)});t.C.push(C)}else if(t.await)t.C.push(function(){return n.call(t,a,o,l,c,d,h,p)});else return n.call(t,a,o,l,c,d,h,p);return d?t.await||t.result:t}function pi(t,e,n){t=t[e];const r=t[0]||t;return r.index||(r.index=n),n=new Gt(r),t.length>1&&(n=n[e].apply(n,t.slice(1))),n}Gt.prototype.or=function(){return Ri(this,"or",vh,arguments)};function vh(t,e,n,r,i,a,o){return t.length&&(this.result.length&&t.push(this.result),t.length<2?this.result=t[0]:(this.result=xa(t,e,n,!1,this.h),n=0)),i&&(this.await=null),i?this.resolve(e,n,r,o):this}Gt.prototype.and=function(){return Ri(this,"and",ph,arguments)};function ph(t,e,n,r,i,a,o){if(!a&&!this.result.length)return i?this.result:this;let l;if(t.length)if(this.result.length&&t.unshift(this.result),t.length<2)this.result=t[0];else{let c=0;for(let d=0,h,p;d<t.length;d++)if((h=t[d])&&(p=h.length))c<p&&(c=p);else if(!a){c=0;break}c?(this.result=Pi(t,c,e,n,a,this.h,i),l=!0):this.result=[]}else a||(this.result=t);return i&&(this.await=null),i?this.resolve(e,n,r,o,l):this}Gt.prototype.xor=function(){return Ri(this,"xor",yh,arguments)};function yh(t,e,n,r,i,a,o){if(t.length)if(this.result.length&&t.unshift(this.result),t.length<2)this.result=t[0];else{e:{a=n;var l=this.h;const c=[],d=gn();let h=0;for(let p=0,m;p<t.length;p++)if(m=t[p]){h<m.length&&(h=m.length);for(let k=0,C;k<m.length;k++)if(C=m[k])for(let _=0,v;_<C.length;_++)v=C[_],d[v]=d[v]?2:1}for(let p=0,m,k=0;p<h;p++)for(let C=0,_;C<t.length;C++)if((_=t[C])&&(m=_[p])){for(let v=0,P;v<m.length;v++)if(P=m[v],d[P]===1)if(a)a--;else if(i){if(c.push(P),c.length===e){t=c;break e}}else{const E=p+(C?l:0);if(c[E]||(c[E]=[]),c[E].push(P),++k===e){t=c;break e}}}t=c}this.result=t,l=!0}else a||(this.result=t);return i&&(this.await=null),i?this.resolve(e,n,r,o,l):this}Gt.prototype.not=function(){return Ri(this,"not",mh,arguments)};function mh(t,e,n,r,i,a,o){if(!a&&!this.result.length)return i?this.result:this;if(t.length&&this.result.length){e:{a=n;var l=[];t=new Set(t.flat().flat());for(let c=0,d,h=0;c<this.result.length;c++)if(d=this.result[c]){for(let p=0,m;p<d.length;p++)if(m=d[p],!t.has(m)){if(a)a--;else if(i){if(l.push(m),l.length===e){t=l;break e}}else if(l[c]||(l[c]=[]),l[c].push(m),++h===e){t=l;break e}}}t=l}this.result=t,l=!0}return i&&(this.await=null),i?this.resolve(e,n,r,o,l):this}function Si(t,e,n,r,i){let a,o,l;typeof i=="string"?(a=i,i=""):a=i.template,o=a.indexOf("$1"),l=a.substring(o+2),o=a.substring(0,o);let c=i&&i.boundary,d=!i||i.clip!==!1,h=i&&i.merge&&l&&o&&new RegExp(l+" "+o,"g");i=i&&i.ellipsis;var p=0;if(typeof i=="object"){var m=i.template;p=m.length-2,i=i.pattern}typeof i!="string"&&(i=i===!1?"":"..."),p&&(i=m.replace("$1",i)),m=i.length-p;let k,C;typeof c=="object"&&(k=c.before,k===0&&(k=-1),C=c.after,C===0&&(C=-1),c=c.total||9e5),p=new Map;for(let Se=0,se,he,xe;Se<e.length;Se++){let Ce;if(r)Ce=e,xe=r;else{var _=e[Se];if(xe=_.field,!xe)continue;Ce=_.result}he=n.get(xe),se=he.encoder,_=p.get(se),typeof _!="string"&&(_=se.encode(t),p.set(se,_));for(let nt=0;nt<Ce.length;nt++){var v=Ce[nt].doc;if(!v||(v=ii(v,xe),!v))continue;var P=v.trim().split(/\s+/);if(!P.length)continue;v="";var E=[];let ke=[];for(var B=-1,V=-1,Z=0,j=0;j<P.length;j++){var ae=P[j],ce=se.encode(ae);ce=ce.length>1?ce.join(" "):ce[0];let U;if(ce&&ae){for(var de=ae.length,W=(se.split?ae.replace(se.split,""):ae).length-ce.length,N="",G=0,O=0;O<_.length;O++){var X=_[O];if(X){var ue=X.length;ue+=W<0?0:W,G&&ue<=G||(X=ce.indexOf(X),X>-1&&(N=(X?ae.substring(0,X):"")+o+ae.substring(X,X+ue)+l+(X+ue<de?ae.substring(X+ue):""),G=ue,U=!0))}}N&&(c&&(B<0&&(B=v.length+(v?1:0)),V=v.length+(v?1:0)+N.length,Z+=de,ke.push(E.length),E.push({match:N})),v+=(v?" ":"")+N)}if(!U)ae=P[j],v+=(v?" ":"")+ae,c&&E.push({text:ae});else if(c&&Z>=c)break}if(Z=ke.length*(a.length-2),k||C||c&&v.length-Z>c)if(Z=c+Z-m*2,j=V-B,k>0&&(j+=k),C>0&&(j+=C),j<=Z)P=k?B-(k>0?k:0):B-((Z-j)/2|0),E=C?V+(C>0?C:0):P+Z,d||(P>0&&v.charAt(P)!==" "&&v.charAt(P-1)!==" "&&(P=v.indexOf(" ",P),P<0&&(P=0)),E<v.length&&v.charAt(E-1)!==" "&&v.charAt(E)!==" "&&(E=v.lastIndexOf(" ",E),E<V?E=V:++E)),v=(P?i:"")+v.substring(P,E)+(E<v.length?i:"");else{for(V=[],B={},Z={},j={},ae={},ce={},N=W=de=0,O=G=1;;){var fe=void 0;for(let U=0,me;U<ke.length;U++){if(me=ke[U],N)if(W!==N){if(j[U+1])continue;if(me+=N,B[me]){de-=m,Z[U+1]=1,j[U+1]=1;continue}if(me>=E.length-1){if(me>=E.length){j[U+1]=1,me>=P.length&&(Z[U+1]=1);continue}de-=m}if(v=E[me].text,ue=C&&ce[U])if(ue>0){if(v.length>ue)if(j[U+1]=1,d)v=v.substring(0,ue);else continue;(ue-=v.length)||(ue=-1),ce[U]=ue}else{j[U+1]=1;continue}if(de+v.length+1<=c)v=" "+v,V[U]+=v;else if(d)fe=c-de-1,fe>0&&(v=" "+v.substring(0,fe),V[U]+=v),j[U+1]=1;else{j[U+1]=1;continue}}else{if(j[U])continue;if(me-=W,B[me]){de-=m,j[U]=1,Z[U]=1;continue}if(me<=0){if(me<0){j[U]=1,Z[U]=1;continue}de-=m}if(v=E[me].text,ue=k&&ae[U])if(ue>0){if(v.length>ue)if(j[U]=1,d)v=v.substring(v.length-ue);else continue;(ue-=v.length)||(ue=-1),ae[U]=ue}else{j[U]=1;continue}if(de+v.length+1<=c)v+=" ",V[U]=v+V[U];else if(d)fe=v.length+1-(c-de),fe>=0&&fe<v.length&&(v=v.substring(fe)+" ",V[U]=v+V[U]),j[U]=1;else{j[U]=1;continue}}else{v=E[me].match,k&&(ae[U]=k),C&&(ce[U]=C),U&&de++;let ve;if(me?!U&&m&&(de+=m):(Z[U]=1,j[U]=1),me>=P.length-1||me<E.length-1&&E[me+1].match?ve=1:m&&(de+=m),de-=a.length-2,!U||de+v.length<=c)V[U]=v;else{fe=G=O=Z[U]=0;break}ve&&(Z[U+1]=1,j[U+1]=1)}de+=v.length,fe=B[me]=1}if(fe)W===N?N++:W++;else{if(W===N?G=0:O=0,!G&&!O)break;G?(W++,N=W):N++}}v="";for(let U=0,me;U<V.length;U++)me=(Z[U]?U?" ":"":(U&&!i?" ":"")+i)+V[U],v+=me;i&&!Z[V.length]&&(v+=i)}h&&(v=v.replace(h," ")),Ce[nt].highlight=v}if(r)break}return e}function Gt(t,e){if(!this||this.constructor!==Gt)return new Gt(t,e);let n=0,r,i,a,o,l,c;if(t&&t.index){const d=t;if(e=d.index,n=d.boost||0,i=d.query){a=d.field||d.pluck,o=d.highlight;const h=d.resolve;t=d.async||d.queue,d.resolve=!1,d.index=null,t=t?e.searchAsync(d):e.search(d),d.resolve=h,d.index=e,t=t.result||t}else t=[]}if(t&&t.then){const d=this;t=t.then(function(h){d.C[0]=d.result=h.result||h,_s(d)}),r=[t],t=[],l=new Promise(function(h){c=h})}this.index=e||null,this.result=t||[],this.h=n,this.C=r||[],this.await=l||null,this.return=c||null,this.highlight=o||null,this.query=i||"",this.field=a||""}We=Gt.prototype;We.limit=function(t){if(this.await){const e=this;this.C.push(function(){return e.limit(t).result})}else if(this.result.length){const e=[];for(let n=0,r;n<this.result.length;n++)if(r=this.result[n])if(r.length<=t){if(e[n]=r,t-=r.length,!t)break}else{e[n]=r.slice(0,t);break}this.result=e}return this};We.offset=function(t){if(this.await){const e=this;this.C.push(function(){return e.offset(t).result})}else if(this.result.length){const e=[];for(let n=0,r;n<this.result.length;n++)(r=this.result[n])&&(r.length<=t?t-=r.length:(e[n]=r.slice(t),t=0));this.result=e}return this};We.boost=function(t){if(this.await){const e=this;this.C.push(function(){return e.boost(t).result})}else this.h+=t;return this};function _s(t,e){let n=t.result;var r=t.await;t.await=null;for(let i=0,a;i<t.C.length;i++)if(a=t.C[i]){if(typeof a=="function")n=a(),t.C[i]=n=n.result||n,i--;else if(a.h)n=a.h(),t.C[i]=n=n.result||n,i--;else if(a.then)return t.await=r}return r=t.return,t.C=[],t.return=null,e||r(n),n}We.resolve=function(t,e,n,r,i){let a=this.await?_s(this,!0):this.result;if(a.then){const o=this;return a.then(function(){return o.resolve(t,e,n,r,i)})}return a.length&&(typeof t=="object"?(r=t.highlight||this.highlight,n=!!r||t.enrich,e=t.offset,t=t.limit):(r=r||this.highlight,n=!!r||n),a=i?n?Hr.call(this.index,a):a:ms.call(this.index,a,t||100,e,n)),this.finalize(a,r)};We.finalize=function(t,e){if(t.then){const r=this;return t.then(function(i){return r.finalize(i,e)})}e&&t.length&&this.query&&(t=Si(this.query,t,this.index.index,this.field,e));const n=this.return;return this.highlight=this.index=this.result=this.C=this.await=this.return=null,this.query=this.field="",n&&n(t),t};function Pi(t,e,n,r,i,a,o){const l=t.length;let c=[],d,h;d=gn();for(let p=0,m,k,C,_;p<e;p++)for(let v=0;v<l;v++)if(C=t[v],p<C.length&&(m=C[p]))for(let P=0;P<m.length;P++){if(k=m[P],(h=d[k])?d[k]++:(h=0,d[k]=1),_=c[h]||(c[h]=[]),!o){let E=p+(v||!i?0:a||0);_=_[E]||(_[E]=[])}if(_.push(k),o&&n&&h===l-1&&_.length-r===n)return r?_.slice(r):_}if(t=c.length)if(i)c=c.length>1?xa(c,n,r,o,a):(c=c[0])&&n&&c.length>n||r?c.slice(r,n+r):c;else{if(t<l)return[];if(c=c[t-1],n||r)if(o)(c.length>n||r)&&(c=c.slice(r,n+r));else{i=[];for(let p=0,m;p<c.length;p++)if(m=c[p]){if(r&&m.length>r)r-=m.length;else if((n&&m.length>n||r)&&(m=m.slice(r,n+r),n-=m.length,r&&(r-=m.length)),i.push(m),!n)break}c=i}}return c}function xa(t,e,n,r,i){const a=[],o=gn();let l;var c=t.length;let d;if(r){for(i=c-1;i>=0;i--)if(d=(r=t[i])&&r.length){for(c=0;c<d;c++)if(l=r[c],!o[l]){if(o[l]=1,n)n--;else if(a.push(l),a.length===e)return a}}}else for(let h=c-1,p,m=0;h>=0;h--){p=t[h];for(let k=0;k<p.length;k++)if(d=(r=p[k])&&r.length){for(let C=0;C<d;C++)if(l=r[C],!o[l])if(o[l]=1,n)n--;else{let _=(k+(h<c-1&&i||0))/(h+1)|0;if((a[_]||(a[_]=[])).push(l),++m===e)return a}}}return a}function _h(t,e,n,r,i){const a=gn(),o=[];for(let l=0,c;l<e.length;l++){c=e[l];for(let d=0;d<c.length;d++)a[c[d]]=1}if(i){for(let l=0,c;l<t.length;l++)if(c=t[l],a[c]){if(r)r--;else if(o.push(c),a[c]=0,n&&--n===0)break}}else for(let l=0,c,d;l<t.result.length;l++)for(c=t.result[l],e=0;e<c.length;e++)d=c[e],a[d]&&((o[l]||(o[l]=[])).push(d),a[d]=0);return o}jr.prototype.search=function(t,e,n,r){n||(!e&&ri(t)?(n=t,t=""):ri(e)&&(n=e,e=0));let i=[];var a=[];let o,l,c,d,h,p,m=0,k=!0,C;if(n){n.constructor===Array&&(n={index:n}),t=n.query||t,o=n.pluck,l=n.merge,d=n.boost,p=o||n.field||(p=n.index)&&(p.index?null:p);var _=this.tag&&n.tag;c=n.suggest,k=n.resolve!==!1,h=n.cache,C=k&&this.store&&n.highlight;var v=!!C||k&&this.store&&n.enrich;e=n.limit||e;var P=n.offset||0;if(e||(e=k?100:0),_&&(!this.db||!r)){_.constructor!==Array&&(_=[_]);var E=[];for(let ae=0,ce;ae<_.length;ae++)if(ce=_[ae],ce.field&&ce.tag){var B=ce.tag;if(B.constructor===Array)for(var V=0;V<B.length;V++)E.push(ce.field,B[V]);else E.push(ce.field,B)}else{B=Object.keys(ce);for(let de=0,W,N;de<B.length;de++)if(W=B[de],N=ce[W],N.constructor===Array)for(V=0;V<N.length;V++)E.push(W,N[V]);else E.push(W,N)}if(_=E,!t){if(a=[],E.length)for(_=0;_<E.length;_+=2){if(this.db){if(r=this.index.get(E[_]),!r)continue;a.push(r=r.db.tag(E[_+1],e,P,v))}else r=bh.call(this,E[_],E[_+1],e,P,v);i.push(k?{field:E[_],tag:E[_+1],result:r}:[r])}if(a.length){const ae=this;return Promise.all(a).then(function(ce){for(let de=0;de<ce.length;de++)k?i[de].result=ce[de]:i[de]=ce[de];return k?i:new Gt(i.length>1?Pi(i,1,0,0,c,d):i[0],ae)})}return k?i:new Gt(i.length>1?Pi(i,1,0,0,c,d):i[0],this)}}k||o||!(p=p||this.field)||(Jn(p)?o=p:(p.constructor===Array&&p.length===1&&(p=p[0]),o=p.field||p.index)),p&&p.constructor!==Array&&(p=[p])}p||(p=this.field);let Z;E=(this.worker||this.db)&&!r&&[];for(let ae=0,ce,de,W;ae<p.length;ae++){if(de=p[ae],this.db&&this.tag&&!this.B[ae])continue;let N;if(Jn(de)||(N=de,de=N.field,t=N.query||t,e=Ir(N.limit,e),P=Ir(N.offset,P),c=Ir(N.suggest,c),C=k&&this.store&&Ir(N.highlight,C),v=!!C||k&&this.store&&Ir(N.enrich,v),h=Ir(N.cache,h)),r)ce=r[ae];else{B=N||n||{},V=B.enrich;var j=this.index.get(de);if(_&&(this.db&&(B.tag=_,B.field=p,Z=j.db.support_tag_search),!Z&&V&&(B.enrich=!1),Z||(B.limit=0,B.offset=0)),ce=h?j.searchCache(t,_&&!Z?0:e,B):j.search(t,_&&!Z?0:e,B),_&&!Z&&(B.limit=e,B.offset=P),V&&(B.enrich=V),E){E[ae]=ce;continue}}if(W=(ce=ce.result||ce)&&ce.length,_&&W){if(B=[],V=0,this.db&&r){if(!Z)for(j=p.length;j<r.length;j++){let G=r[j];if(G&&G.length)V++,B.push(G);else if(!c)return k?i:new Gt(i,this)}}else for(let G=0,O,X;G<_.length;G+=2){if(O=this.tag.get(_[G]),!O){if(c)continue;return k?i:new Gt(i,this)}if(X=(O=O&&O.get(_[G+1]))&&O.length)V++,B.push(O);else if(!c)return k?i:new Gt(i,this)}if(V){if(ce=_h(ce,B,e,P,k),W=ce.length,!W&&!c)return k?ce:new Gt(ce,this);V--}}if(W)a[m]=de,i.push(ce),m++;else if(p.length===1)return k?i:new Gt(i,this)}if(E){if(this.db&&_&&_.length&&!Z)for(v=0;v<_.length;v+=2){if(a=this.index.get(_[v]),!a){if(c)continue;return k?i:new Gt(i,this)}E.push(a.db.tag(_[v+1],e,P,!1))}const ae=this;return Promise.all(E).then(function(ce){return n&&(n.resolve=k),ce.length&&(ce=ae.search(t,e,n,ce)),ce})}if(!m)return k?i:new Gt(i,this);if(o&&(!v||!this.store))return i=i[0],k?i:new Gt(i,this);for(E=[],P=0;P<a.length;P++){if(_=i[P],v&&_.length&&typeof _[0].doc>"u"&&(this.db?E.push(_=this.index.get(this.field[0]).db.enrich(_)):_=Hr.call(this,_)),o)return k?C?Si(t,_,this.index,o,C):_:new Gt(_,this);i[P]={field:a[P],result:_}}if(v&&this.db&&E.length){const ae=this;return Promise.all(E).then(function(ce){for(let de=0;de<ce.length;de++)i[de].result=ce[de];return C&&(i=Si(t,i,ae.index,o,C)),l?Ys(i):i})}return C&&(i=Si(t,i,this.index,o,C)),l?Ys(i):i};function Ys(t){const e=[],n=gn(),r=gn();for(let i=0,a,o,l,c,d,h,p;i<t.length;i++){a=t[i],o=a.field,l=a.result;for(let m=0;m<l.length;m++)d=l[m],typeof d!="object"?d={id:c=d}:c=d.id,(h=n[c])?h.push(o):(d.field=n[c]=[o],e.push(d)),(p=d.highlight)&&(h=r[c],h||(r[c]=h={},d.highlight=h),h[o]=p)}return e}function bh(t,e,n,r,i){return t=this.tag.get(t),t?(t=t.get(e),t?(e=t.length-r,e>0&&((n&&e>n||r)&&(t=t.slice(r,r+n)),i&&(t=Hr.call(this,t))),t):[]):[]}function Hr(t){if(!this||!this.store)return t;if(this.db)return this.index.get(this.field[0]).db.enrich(t);const e=Array(t.length);for(let n=0,r;n<t.length;n++)r=t[n],e[n]={id:r,doc:this.store.get(r)};return e}function jr(t){if(!this||this.constructor!==jr)return new jr(t);const e=t.document||t.doc||t;let n,r;if(this.B=[],this.field=[],this.D=[],this.key=(n=e.key||e.id)&&Ii(n,this.D)||"id",(r=t.keystore||0)&&(this.keystore=r),this.fastupdate=!!t.fastupdate,this.reg=!this.fastupdate||t.worker||t.db?r?new qn(r):new Set:r?new Qn(r):new Map,this.h=(n=e.store||null)&&n&&n!==!0&&[],this.store=n?r?new Qn(r):new Map:null,this.cache=(n=t.cache||null)&&new Cr(n),t.cache=!1,this.worker=t.worker||!1,this.priority=t.priority||4,this.index=kh.call(this,t,e),this.tag=null,(n=e.tag)&&(typeof n=="string"&&(n=[n]),n.length)){this.tag=new Map,this.A=[],this.F=[];for(let i=0,a,o;i<n.length;i++){if(a=n[i],o=a.field||a,!o)throw Error("The tag field from the document descriptor is undefined.");a.custom?this.A[i]=a.custom:(this.A[i]=Ii(o,this.D),a.filter&&(typeof this.A[i]=="string"&&(this.A[i]=new String(this.A[i])),this.A[i].G=a.filter)),this.F[i]=o,this.tag.set(o,new Map)}}if(this.worker){this.fastupdate=!1,t=[];for(const i of this.index.values())i.then&&t.push(i);if(t.length){const i=this;return Promise.all(t).then(function(a){let o=0;for(const l of i.index.entries()){const c=l[0];let d=l[1];d.then&&(d=a[o],i.index.set(c,d),o++)}return i})}}else t.db&&(this.fastupdate=!1,this.mount(t.db))}We=jr.prototype;We.mount=function(t){let e=this.field;if(this.tag)for(let a=0,o;a<this.F.length;a++){o=this.F[a];var n=void 0;this.index.set(o,n=new er({},this.reg)),e===this.field&&(e=e.slice(0)),e.push(o),n.tag=this.tag.get(o)}n=[];const r={db:t.db,type:t.type,fastupdate:t.fastupdate};for(let a=0,o,l;a<e.length;a++){r.field=l=e[a],o=this.index.get(l);const c=new t.constructor(t.id,r);c.id=t.id,n[a]=c.mount(o),o.document=!0,a?o.bypass=!0:o.store=this.store}const i=this;return this.db=Promise.all(n).then(function(){i.db=!0})};We.commit=async function(){const t=[];for(const e of this.index.values())t.push(e.commit());await Promise.all(t),this.reg.clear()};We.destroy=function(){const t=[];for(const e of this.index.values())t.push(e.destroy());return Promise.all(t)};function kh(t,e){const n=new Map;let r=e.index||e.field||e;Jn(r)&&(r=[r]);for(let a=0,o,l;a<r.length;a++){if(o=r[a],Jn(o)||(l=o,o=o.field),l=ri(l)?Object.assign({},t,l):t,this.worker){var i=void 0;i=(i=l.encoder)&&i.encode?i:new si(typeof i=="string"?ps[i]:i||{}),i=new Br(l,i),n.set(o,i)}this.worker||n.set(o,new er(l,this.reg)),l.custom?this.B[a]=l.custom:(this.B[a]=Ii(o,this.D),l.filter&&(typeof this.B[a]=="string"&&(this.B[a]=new String(this.B[a])),this.B[a].G=l.filter)),this.field[a]=o}if(this.h){t=e.store,Jn(t)&&(t=[t]);for(let a=0,o,l;a<t.length;a++)o=t[a],l=o.field||o,o.custom?(this.h[a]=o.custom,o.custom.O=l):(this.h[a]=Ii(l,this.D),o.filter&&(typeof this.h[a]=="string"&&(this.h[a]=new String(this.h[a])),this.h[a].G=o.filter))}return n}function Ii(t,e){const n=t.split(":");let r=0;for(let i=0;i<n.length;i++)t=n[i],t[t.length-1]==="]"&&(t=t.substring(0,t.length-2))&&(e[r]=!0),t&&(n[r++]=t);return r<n.length&&(n.length=r),r>1?n:n[0]}We.append=function(t,e){return this.add(t,e,!0)};We.update=function(t,e){return this.remove(t).add(t,e)};We.remove=function(t){ri(t)&&(t=ii(t,this.key));for(var e of this.index.values())e.remove(t,!0);if(this.reg.has(t)){if(this.tag&&!this.fastupdate)for(let n of this.tag.values())for(let r of n){e=r[0];const i=r[1],a=i.indexOf(t);a>-1&&(i.length>1?i.splice(a,1):n.delete(e))}this.store&&this.store.delete(t),this.reg.delete(t)}return this.cache&&this.cache.remove(t),this};We.clear=function(){const t=[];for(const e of this.index.values()){const n=e.clear();n.then&&t.push(n)}if(this.tag)for(const e of this.tag.values())e.clear();return this.store&&this.store.clear(),this.cache&&this.cache.clear(),t.length?Promise.all(t):this};We.contain=function(t){return this.db?this.index.get(this.field[0]).db.has(t):this.reg.has(t)};We.cleanup=function(){for(const t of this.index.values())t.cleanup();return this};We.get=function(t){return this.db?this.index.get(this.field[0]).db.enrich(t).then(function(e){return e[0]&&e[0].doc||null}):this.store.get(t)||null};We.set=function(t,e){return typeof t=="object"&&(e=t,t=ii(e,this.key)),this.store.set(t,e),this};We.searchCache=vs;We.export=wh;We.import=xh;ys(jr.prototype);function bs(t,e=0){let n=[],r=[];e&&(e=25e4/e*5e3|0);for(const i of t.entries())r.push(i),r.length===e&&(n.push(r),r=[]);return r.length&&n.push(r),n}function ks(t,e){e||(e=new Map);for(let n=0,r;n<t.length;n++)r=t[n],e.set(r[0],r[1]);return e}function Ca(t,e=0){let n=[],r=[];e&&(e=25e4/e*1e3|0);for(const i of t.entries())r.push([i[0],bs(i[1])[0]||[]]),r.length===e&&(n.push(r),r=[]);return r.length&&n.push(r),n}function Sa(t,e){e||(e=new Map);for(let n=0,r,i;n<t.length;n++)r=t[n],i=e.get(r[0]),e.set(r[0],ks(r[1],i));return e}function Na(t){let e=[],n=[];for(const r of t.keys())n.push(r),n.length===25e4&&(e.push(n),n=[]);return n.length&&e.push(n),e}function Da(t,e){e||(e=new Set);for(let n=0;n<t.length;n++)e.add(t[n]);return e}function Ti(t,e,n,r,i,a,o=0){const l=r&&r.constructor===Array;var c=l?r.shift():r;if(!c)return this.export(t,e,i,a+1);if((c=t((e?e+".":"")+(o+1)+"."+n,JSON.stringify(c)))&&c.then){const d=this;return c.then(function(){return Ti.call(d,t,e,n,l?r:null,i,a,o+1)})}return Ti.call(this,t,e,n,l?r:null,i,a,o+1)}function wh(t,e,n=0,r=0){if(n<this.field.length){const o=this.field[n];if((e=this.index.get(o).export(t,o,n,r=1))&&e.then){const l=this;return e.then(function(){return l.export(t,o,n+1)})}return this.export(t,o,n+1)}let i,a;switch(r){case 0:i="reg",a=Na(this.reg),e=null;break;case 1:i="tag",a=this.tag&&Ca(this.tag,this.reg.size),e=null;break;case 2:i="doc",a=this.store&&bs(this.store),e=null;break;default:return}return Ti.call(this,t,e,i,a||null,n,r)}function xh(t,e){var n=t.split(".");n[n.length-1]==="json"&&n.pop();const r=n.length>2?n[0]:"";if(n=n.length>2?n[2]:n[1],this.worker&&r)return this.index.get(r).import(t);if(e){if(typeof e=="string"&&(e=JSON.parse(e)),r)return this.index.get(r).import(n,e);switch(n){case"reg":this.fastupdate=!1,this.reg=Da(e,this.reg);for(let i=0,a;i<this.field.length;i++)a=this.index.get(this.field[i]),a.fastupdate=!1,a.reg=this.reg;if(this.worker){e=[];for(const i of this.index.values())e.push(i.import(t));return Promise.all(e)}break;case"tag":this.tag=Sa(e,this.tag);break;case"doc":this.store=ks(e,this.store)}}}function Xs(t,e){let n="";for(const r of t.entries()){t=r[0];const i=r[1];let a="";for(let o=0,l;o<i.length;o++){l=i[o]||[""];let c="";for(let d=0;d<l.length;d++)c+=(c?",":"")+(e==="string"?'"'+l[d]+'"':l[d]);c="["+c+"]",a+=(a?",":"")+c}a='["'+t+'",['+a+"]]",n+=(n?",":"")+a}return n}er.prototype.remove=function(t,e){const n=this.reg.size&&(this.fastupdate?this.reg.get(t):this.reg.has(t));if(n){if(this.fastupdate){for(let r=0,i,a;r<n.length;r++)if((i=n[r])&&(a=i.length))if(i[a-1]===t)i.pop();else{const o=i.indexOf(t);o>=0&&i.splice(o,1)}}else ai(this.map,t),this.depth&&ai(this.ctx,t);e||this.reg.delete(t)}return this.db&&(this.commit_task.push({del:t}),this.M&&Pa(this)),this.cache&&this.cache.remove(t),this};function ai(t,e){let n=0;var r=typeof e>"u";if(t.constructor===Array){for(let i=0,a,o,l;i<t.length;i++)if((a=t[i])&&a.length){if(r)return 1;if(o=a.indexOf(e),o>=0){if(a.length>1)return a.splice(o,1),1;if(delete t[i],n)return 1;l=1}else{if(l)return 1;n++}}}else for(let i of t.entries())r=i[0],ai(i[1],e)?n++:t.delete(r);return n}const Ch={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};er.prototype.add=function(t,e,n,r){if(e&&(t||t===0)){if(!r&&!n&&this.reg.has(t))return this.update(t,e);r=this.depth,e=this.encoder.encode(e,!r);const d=e.length;if(d){const h=gn(),p=gn(),m=this.resolution;for(let k=0;k<d;k++){let C=e[this.rtl?d-1-k:k];var i=C.length;if(i&&(r||!p[C])){var a=this.score?this.score(e,C,k,null,0):yi(m,d,k),o="";switch(this.tokenize){case"tolerant":if(ar(this,p,C,a,t,n),i>2){for(let _=1,v,P,E,B;_<i-1;_++)v=C.charAt(_),P=C.charAt(_+1),E=C.substring(0,_)+P,B=C.substring(_+2),o=E+v+B,ar(this,p,o,a,t,n),o=E+B,ar(this,p,o,a,t,n);ar(this,p,C.substring(0,C.length-1),a,t,n)}break;case"full":if(i>2){for(let _=0,v;_<i;_++)for(a=i;a>_;a--){o=C.substring(_,a),v=this.rtl?i-1-_:_;var l=this.score?this.score(e,C,k,o,v):yi(m,d,k,i,v);ar(this,p,o,l,t,n)}break}case"bidirectional":case"reverse":if(i>1){for(l=i-1;l>0;l--){o=C[this.rtl?i-1-l:l]+o;var c=this.score?this.score(e,C,k,o,l):yi(m,d,k,i,l);ar(this,p,o,c,t,n)}o=""}case"forward":if(i>1){for(l=0;l<i;l++)o+=C[this.rtl?i-1-l:l],ar(this,p,o,a,t,n);break}default:if(ar(this,p,C,a,t,n),r&&d>1&&k<d-1)for(i=this.N,o=C,a=Math.min(r+1,this.rtl?k+1:d-k),l=1;l<a;l++){C=e[this.rtl?d-1-k-l:k+l],c=this.bidirectional&&C>o;const _=this.score?this.score(e,o,k,C,l-1):yi(i+(d/2>i?0:1),d,k,a-1,l-1);ar(this,h,c?o:C,_,t,n,c?C:o)}}}}this.fastupdate||this.reg.add(t)}}return this.db&&(this.commit_task.push(n?{ins:t}:{del:t}),this.M&&Pa(this)),this};function ar(t,e,n,r,i,a,o){let l,c;if(!(l=e[n])||o&&!l[o]){if(o?(e=l||(e[n]=gn()),e[o]=1,c=t.ctx,(l=c.get(o))?c=l:c.set(o,c=t.keystore?new Qn(t.keystore):new Map)):(c=t.map,e[n]=1),(l=c.get(n))?c=l:c.set(n,c=l=[]),a){for(let d=0,h;d<l.length;d++)if((h=l[d])&&h.includes(i)){if(d<=r)return;h.splice(h.indexOf(i),1),t.fastupdate&&(e=t.reg.get(i))&&e.splice(e.indexOf(h),1);break}}if(c=c[r]||(c[r]=[]),c.push(i),c.length===2**31-1){if(e=new Fr(c),t.fastupdate)for(let d of t.reg.values())d.includes(c)&&(d[d.indexOf(c)]=e);l[r]=c=e}t.fastupdate&&((r=t.reg.get(i))?r.push(c):t.reg.set(i,[c]))}}function yi(t,e,n,r,i){return n&&t>1?e+(r||0)<=t?n+(i||0):(t-1)/(e+(r||0))*(n+(i||0))+1|0:0}er.prototype.search=function(t,e,n){if(n||(e||typeof t!="object"?typeof e=="object"&&(n=e,e=0):(n=t,t="")),n&&n.cache)return n.cache=!1,t=this.searchCache(t,e,n),n.cache=!0,t;let r=[],i,a,o,l=0,c,d,h,p,m;n&&(t=n.query||t,e=n.limit||e,l=n.offset||0,a=n.context,o=n.suggest,m=(c=n.resolve)&&n.enrich,h=n.boost,p=n.resolution,d=this.db&&n.tag),typeof c>"u"&&(c=this.resolve),a=this.depth&&a!==!1;let k=this.encoder.encode(t,!a);if(i=k.length,e=e||(c?100:0),i===1)return Qs.call(this,k[0],"",e,l,c,m,d);if(i===2&&a&&!o)return Qs.call(this,k[1],k[0],e,l,c,m,d);let C=gn(),_=0,v;if(a&&(v=k[0],_=1),p||p===0||(p=v?this.N:this.resolution),this.db){if(this.db.search&&(n=this.db.search(this,k,e,l,o,c,m,d),n!==!1))return n;const P=this;return(async function(){for(let E,B;_<i;_++){if((B=k[_])&&!C[B]){if(C[B]=1,E=await os(P,B,v,0,0,!1,!1),E=qs(E,r,o,p)){r=E;break}v&&(o&&E&&r.length||(v=B))}o&&v&&_===i-1&&!r.length&&(p=P.resolution,v="",_=-1,C=gn())}return Js(r,p,e,l,o,h,c)})()}for(let P,E;_<i;_++){if((E=k[_])&&!C[E]){if(C[E]=1,P=os(this,E,v,0,0,!1,!1),P=qs(P,r,o,p)){r=P;break}v&&(o&&P&&r.length||(v=E))}o&&v&&_===i-1&&!r.length&&(p=this.resolution,v="",_=-1,C=gn())}return Js(r,p,e,l,o,h,c)};function Js(t,e,n,r,i,a,o){let l=t.length,c=t;if(l>1)c=Pi(t,e,n,r,i,a,o);else if(l===1)return o?ms.call(null,t[0],n,r):new Gt(t[0],this);return o?c:new Gt(c,this)}function Qs(t,e,n,r,i,a,o){return t=os(this,t,e,n,r,i,a,o),this.db?t.then(function(l){return i?l||[]:new Gt(l,this)}):t&&t.length?i?ms.call(this,t,n,r):new Gt(t,this):i?[]:new Gt([],this)}function qs(t,e,n,r){let i=[];if(t&&t.length){if(t.length<=r){e.push(t);return}for(let a=0,o;a<r;a++)(o=t[a])&&(i[a]=o);if(i.length){e.push(i);return}}if(!n)return i}function os(t,e,n,r,i,a,o,l){let c;return n&&(c=t.bidirectional&&e>n)&&(c=n,n=e,e=c),t.db?t.db.get(e,n,r,i,a,o,l):(t=n?(t=t.ctx.get(n))&&t.get(e):t.map.get(e),t)}function er(t,e){if(!this||this.constructor!==er)return new er(t);if(t){var n=Jn(t)?t:t.preset;n&&(t=Object.assign({},Ch[n],t))}else t={};n=t.context;const r=n===!0?{depth:1}:n||{},i=Jn(t.encoder)?ps[t.encoder]:t.encode||t.encoder||{};this.encoder=i.encode?i:typeof i=="object"?new si(i):{encode:i},this.resolution=t.resolution||9,this.tokenize=n=(n=t.tokenize)&&n!=="default"&&n!=="exact"&&n||"strict",this.depth=n==="strict"&&r.depth||0,this.bidirectional=r.bidirectional!==!1,this.fastupdate=!!t.fastupdate,this.score=t.score||null,(n=t.keystore||0)&&(this.keystore=n),this.map=n?new Qn(n):new Map,this.ctx=n?new Qn(n):new Map,this.reg=e||(this.fastupdate?n?new Qn(n):new Map:n?new qn(n):new Set),this.N=r.resolution||3,this.rtl=i.rtl||t.rtl||!1,this.cache=(n=t.cache||null)&&new Cr(n),this.resolve=t.resolve!==!1,(n=t.db)&&(this.db=this.mount(n)),this.M=t.commit!==!1,this.commit_task=[],this.commit_timer=null,this.priority=t.priority||4}We=er.prototype;We.mount=function(t){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),t.mount(this)};We.commit=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.commit(this)};We.destroy=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.destroy()};function Pa(t){t.commit_timer||(t.commit_timer=setTimeout(function(){t.commit_timer=null,t.db.commit(t)},1))}We.clear=function(){return this.map.clear(),this.ctx.clear(),this.reg.clear(),this.cache&&this.cache.clear(),this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this};We.append=function(t,e){return this.add(t,e,!0)};We.contain=function(t){return this.db?this.db.has(t):this.reg.has(t)};We.update=function(t,e){const n=this,r=this.remove(t);return r&&r.then?r.then(()=>n.add(t,e)):this.add(t,e)};We.cleanup=function(){return this.fastupdate?(ai(this.map),this.depth&&ai(this.ctx),this):this};We.searchCache=vs;We.export=function(t,e,n=0,r=0){let i,a;switch(r){case 0:i="reg",a=Na(this.reg);break;case 1:i="cfg",a=null;break;case 2:i="map",a=bs(this.map,this.reg.size);break;case 3:i="ctx",a=Ca(this.ctx,this.reg.size);break;default:return}return Ti.call(this,t,e,i,a,n,r)};We.import=function(t,e){if(e)switch(typeof e=="string"&&(e=JSON.parse(e)),t=t.split("."),t[t.length-1]==="json"&&t.pop(),t.length===3&&t.shift(),t=t.length>1?t[1]:t[0],t){case"reg":this.fastupdate=!1,this.reg=Da(e,this.reg);break;case"map":this.map=ks(e,this.map);break;case"ctx":this.ctx=Sa(e,this.ctx)}};We.serialize=function(t=!0){let e="",n="",r="";if(this.reg.size){let a;for(var i of this.reg.keys())a||(a=typeof i),e+=(e?",":"")+(a==="string"?'"'+i+'"':i);e="index.reg=new Set(["+e+"]);",n=Xs(this.map,a),n="index.map=new Map(["+n+"]);";for(const o of this.ctx.entries()){i=o[0];let l=Xs(o[1],a);l="new Map(["+l+"])",l='["'+i+'",'+l+"]",r+=(r?",":"")+l}r="index.ctx=new Map(["+r+"]);"}return t?"function inject(index){"+e+n+r+"}":e+n+r};ys(er.prototype);const Ia=typeof window<"u"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Mi=["map","ctx","tag","reg","cfg"],br=gn();function ls(t,e={}){if(!this||this.constructor!==ls)return new ls(t,e);typeof t=="object"&&(e=t,t=t.name),t||console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(t?":"+t.toLowerCase().replace(/[^a-z0-9_\-]/g,""):""),this.field=e.field?e.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"",this.type=e.type,this.fastupdate=this.support_tag_search=!1,this.db=null,this.h={}}We=ls.prototype;We.mount=function(t){return t.index?t.mount(this):(t.db=this,this.open())};We.open=function(){if(this.db)return this.db;let t=this;navigator.storage&&navigator.storage.persist&&navigator.storage.persist(),br[t.id]||(br[t.id]=[]),br[t.id].push(t.field);const e=Ia.open(t.id,1);return e.onupgradeneeded=function(){const n=t.db=this.result;for(let r=0,i;r<Mi.length;r++){i=Mi[r];for(let a=0,o;a<br[t.id].length;a++)o=br[t.id][a],n.objectStoreNames.contains(i+(i!=="reg"&&o?":"+o:""))||n.createObjectStore(i+(i!=="reg"&&o?":"+o:""))}},t.db=pr(e,function(n){t.db=n,t.db.onversionchange=function(){t.close()}})};We.close=function(){this.db&&this.db.close(),this.db=null};We.destroy=function(){const t=Ia.deleteDatabase(this.id);return pr(t)};We.clear=function(){const t=[];for(let n=0,r;n<Mi.length;n++){r=Mi[n];for(let i=0,a;i<br[this.id].length;i++)a=br[this.id][i],t.push(r+(r!=="reg"&&a?":"+a:""))}const e=this.db.transaction(t,"readwrite");for(let n=0;n<t.length;n++)e.objectStore(t[n]).clear();return pr(e)};We.get=function(t,e,n=0,r=0,i=!0,a=!1){t=this.db.transaction((e?"ctx":"map")+(this.field?":"+this.field:""),"readonly").objectStore((e?"ctx":"map")+(this.field?":"+this.field:"")).get(e?e+":"+t:t);const o=this;return pr(t).then(function(l){let c=[];if(!l||!l.length)return c;if(i){if(!n&&!r&&l.length===1)return l[0];for(let d=0,h;d<l.length;d++)if((h=l[d])&&h.length){if(r>=h.length){r-=h.length;continue}const p=n?r+Math.min(h.length-r,n):h.length;for(let m=r;m<p;m++)c.push(h[m]);if(r=0,c.length===n)break}return a?o.enrich(c):c}return l})};We.tag=function(t,e=0,n=0,r=!1){t=this.db.transaction("tag"+(this.field?":"+this.field:""),"readonly").objectStore("tag"+(this.field?":"+this.field:"")).get(t);const i=this;return pr(t).then(function(a){return!a||!a.length||n>=a.length?[]:!e&&!n?a:(a=a.slice(n,n+e),r?i.enrich(a):a)})};We.enrich=function(t){typeof t!="object"&&(t=[t]);const e=this.db.transaction("reg","readonly").objectStore("reg"),n=[];for(let r=0;r<t.length;r++)n[r]=pr(e.get(t[r]));return Promise.all(n).then(function(r){for(let i=0;i<r.length;i++)r[i]={id:t[i],doc:r[i]?JSON.parse(r[i]):null};return r})};We.has=function(t){return t=this.db.transaction("reg","readonly").objectStore("reg").getKey(t),pr(t).then(function(e){return!!e})};We.search=null;We.info=function(){};We.transaction=function(t,e,n){t+=t!=="reg"&&this.field?":"+this.field:"";let r=this.h[t+":"+e];if(r)return n.call(this,r);let i=this.db.transaction(t,e);this.h[t+":"+e]=r=i.objectStore(t);const a=n.call(this,r);return this.h[t+":"+e]=null,pr(i).finally(function(){return a})};We.commit=async function(t){let e=t.commit_task,n=[];t.commit_task=[];for(let r=0,i;r<e.length;r++)i=e[r],i.del&&n.push(i.del);n.length&&await this.remove(n),t.reg.size&&(await this.transaction("map","readwrite",function(r){for(const i of t.map){const a=i[0],o=i[1];o.length&&(r.get(a).onsuccess=function(){let l=this.result;var c;if(l&&l.length){const d=Math.max(l.length,o.length);for(let h=0,p,m;h<d;h++)if((m=o[h])&&m.length){if((p=l[h])&&p.length)for(c=0;c<m.length;c++)p.push(m[c]);else l[h]=m;c=1}}else l=o,c=1;c&&r.put(l,a)})}}),await this.transaction("ctx","readwrite",function(r){for(const i of t.ctx){const a=i[0],o=i[1];for(const l of o){const c=l[0],d=l[1];d.length&&(r.get(a+":"+c).onsuccess=function(){let h=this.result;var p;if(h&&h.length){const m=Math.max(h.length,d.length);for(let k=0,C,_;k<m;k++)if((_=d[k])&&_.length){if((C=h[k])&&C.length)for(p=0;p<_.length;p++)C.push(_[p]);else h[k]=_;p=1}}else h=d,p=1;p&&r.put(h,a+":"+c)})}}}),t.store?await this.transaction("reg","readwrite",function(r){for(const i of t.store){const a=i[0],o=i[1];r.put(typeof o=="object"?JSON.stringify(o):1,a)}}):t.bypass||await this.transaction("reg","readwrite",function(r){for(const i of t.reg.keys())r.put(1,i)}),t.tag&&await this.transaction("tag","readwrite",function(r){for(const i of t.tag){const a=i[0],o=i[1];o.length&&(r.get(a).onsuccess=function(){let l=this.result;l=l&&l.length?l.concat(o):o,r.put(l,a)})}}),t.map.clear(),t.ctx.clear(),t.tag&&t.tag.clear(),t.store&&t.store.clear(),t.document||t.reg.clear())};function Gi(t,e,n){const r=t.value;let i,a=0;for(let o=0,l;o<r.length;o++){if(l=n?r:r[o]){for(let c=0,d,h;c<e.length;c++)if(h=e[c],d=l.indexOf(h),d>=0)if(i=1,l.length>1)l.splice(d,1);else{r[o]=[];break}a+=l.length}if(n)break}a?i&&t.update(r):t.delete(),t.continue()}We.remove=function(t){return typeof t!="object"&&(t=[t]),Promise.all([this.transaction("map","readwrite",function(e){e.openCursor().onsuccess=function(){const n=this.result;n&&Gi(n,t)}}),this.transaction("ctx","readwrite",function(e){e.openCursor().onsuccess=function(){const n=this.result;n&&Gi(n,t)}}),this.transaction("tag","readwrite",function(e){e.openCursor().onsuccess=function(){const n=this.result;n&&Gi(n,t,!0)}}),this.transaction("reg","readwrite",function(e){for(let n=0;n<t.length;n++)e.delete(t[n])})])};function pr(t,e){return new Promise((n,r)=>{t.onsuccess=t.oncomplete=function(){e&&e(this.result),e=null,n(this.result)},t.onerror=t.onblocked=r,t=null})}const Sh={Index:er},Nh=ps,kn=t=>!t||typeof t=="string"&&t.trim()==="",Dh=t=>t&&t.trim()!=="";function ea(t,e="."){if(!t||typeof t!="string")return null;const n=t.lastIndexOf(e);return n===-1?"":t.substring(0,n)}function Yi(t,e,n="."){return kn(e)?t:t.startsWith(e+n)?t.substring(e.length+n.length):t}function Xi(t,e=0,n=1,r="."){return t.split(r).slice(e,e+n).join(r)}function Er(t,e){return t.split(e).length}function Ph(){return new Sh.Index({tokenize:"full",resolution:9,encoder:Nh.Normalize})}class Ih{timeout;treeId;processingQueue=[];batchSize;searchIndex;isProcessing=!1;shouldCalculateSearchValue;searchValueMember;getSearchValueCallback;onProgressCallback;onCompleteCallback;totalItemsAdded=0;totalItemsProcessed=0;constructor(e,n,r,i,a,o=25,l=50,c=!1){this.timeout=l,this.treeId=e,this.searchIndex=n,this.batchSize=o,this.shouldCalculateSearchValue=r,this.searchValueMember=i,this.getSearchValueCallback=a,Gn.debug(`[${this.treeId}] Initialized with batch size: ${o}`)}addToQueue(e){this.processingQueue=this.processingQueue.concat(e),this.totalItemsAdded+=e.length,Gn.debug(`[${this.treeId}] Added ${e.length} items to queue. Queue size: ${this.processingQueue.length}`),this.isProcessing||this.startProcessing()}addItem(e){this.processingQueue.push(e),this.totalItemsAdded++,this.isProcessing||this.startProcessing()}setCallbacks(e,n){this.onProgressCallback=e,this.onCompleteCallback=n}setBatchSize(e){this.batchSize=e,Gn.debug(`[${this.treeId}] Batch size updated to: ${this.batchSize}`)}startProcessing(){this.isProcessing||this.processingQueue.length===0||(this.isProcessing=!0,Gn.debug(`[${this.treeId}] Starting indexing. Queue size: ${this.processingQueue.length}`),this.processNextBatch())}processNextBatch(){requestIdleCallback(e=>this.processBatch(e),{timeout:this.timeout})}processBatch(e){const n=performance.now();let r=0;const i=e.didTimeout,a=16;Gn.trace(`[${this.treeId}] Batch start: timeout=${i}, timeRemaining=${e.timeRemaining().toFixed(1)}ms, queueSize=${this.processingQueue.length}`);let o;for(i?o=Math.min(5,Math.ceil(this.batchSize/5)):o=this.batchSize;this.processingQueue.length>0&&r<o&&(!i&&e.timeRemaining()>1||i);){const c=performance.now()-n;if(c>a){Gn.trace(`[${this.treeId}] Time limit hit after ${c.toFixed(2)}ms, processed ${r} items`);break}const d=this.processingQueue.shift();if(this.indexItem(d),r++,this.totalItemsProcessed++,i&&r>=o)break}const l=performance.now()-n;Gn.trace(`[${this.treeId}] Batch end: ${r} items in ${l.toFixed(2)}ms`),this.onProgressCallback&&this.onProgressCallback(this.totalItemsProcessed,this.totalItemsAdded),this.processingQueue.length>0?this.processNextBatch():this.finishProcessing()}indexItem(e){const n=this.shouldCalculateSearchValue?this.getSearchValueCallback&&this.getSearchValueCallback(e.node):this.searchValueMember&&e.node.data?.[this.searchValueMember]?.toString();if(Dh(n)){const r=performance.now();this.searchIndex.add(e.index,n);const i=performance.now()-r;i>5&&Gn.warn(`[${this.treeId}] Slow FlexSearch.add(): ${i.toFixed(2)}ms for index ${e.index}`)}}finishProcessing(){this.isProcessing=!1,Gn.info(`[${this.treeId}] Indexing complete. Processed ${this.totalItemsProcessed} items.`),this.onCompleteCallback&&this.onCompleteCallback()}getStatus(){return{queueSize:this.processingQueue.length,isProcessing:this.isProcessing,processed:this.totalItemsProcessed,total:this.totalItemsAdded,batchSize:this.batchSize}}clearQueue(){this.processingQueue=[],this.isProcessing=!1,this.totalItemsAdded=0,this.totalItemsProcessed=0,Gn.debug(`[${this.treeId}] Queue cleared`)}isBusy(){return this.isProcessing||this.processingQueue.length>0}async waitForCompletion(){return new Promise(e=>{if(!this.isBusy()){e();return}const n=this.onCompleteCallback;this.onCompleteCallback=()=>{n&&n(),e()}})}}const xr=Jt.getLogger("LTREE:PERF");let Ta=0;const Th="#a855f7",Mh={format(t,e,n){return`%c[${n}]%c %c[PERF]%c`},timestampFormatter(t){return t.toTimeString().split(" ")[0]+"."+t.getMilliseconds().toString().padStart(3,"0")}};function Eh(t){return function(e,n,r){const i=t(e,n,r);return function(...a){if(a.length>0&&typeof a[0]=="string"&&a[0].includes("%c")){const o=(a[0].match(/%c/g)||[]).length,l=[];for(let c=0;c<o;c++)l.push(c%2===0?`color: ${Th}; font-weight: bold;`:"color: inherit;");i(a[0],...l,...a.slice(1))}else i(...a)}}}const Ah=xr.methodFactory;xr.methodFactory=Eh(Ah);Ai.reg(Jt);Ai.apply(xr,Mh);xr.setLevel("silent");const cs=new Map;function lr(t,e){cs.set(t,{start:performance.now(),metadata:e})}function Fn(t,e){const n=cs.get(t);if(!n)return xr.warn(`Timer "${t}" not found`),0;const r=performance.now()-n.start;if(cs.delete(t),r<Ta)return r;let i=`${t}: ${Jr(r)}`;if(e!==void 0&&e>0){const a=r/e,o=1e3/a;i+=` | ${e.toLocaleString()} items | ${Jr(a)}/item | ${Oh(o)} items/sec`}return n.metadata&&(i+=` | ${JSON.stringify(n.metadata)}`),xr.info(i),r}function Rh(t,e,n){const r=Object.values(e).reduce((a,o)=>a+o,0);if(r<Ta)return;let i=`[${t}] Performance Summary:
7
- `;for(const[a,o]of Object.entries(e)){const l=(o/r*100).toFixed(1);i+=` ${a}: ${Jr(o)} (${l}%)
8
- `}i+=` TOTAL: ${Jr(r)}`,n!==void 0&&(i+=` | ${n.toLocaleString()} items | ${Jr(r/n)}/item`),xr.info(i)}function Jr(t){return t<1?`${(t*1e3).toFixed(2)}µs`:t<1e3?`${t.toFixed(2)}ms`:`${(t/1e3).toFixed(2)}s`}function Oh(t){return t.toLocaleString(void 0,{maximumFractionDigits:0})}function kt(t,e){return t[e]}function Lh(t,e,n,r,i,a,o,l,c,d,h,p,m,k,C,_,v,P,E,B,V,Z,j,ae,ce,de,W,N){let G=kn(n),O=kn(r),X=kn(i),ue=kn(a),fe=kn(o),Se=kn(l),se=kn(c),he=kn(h),xe=kn(p),Ce=kn(P),nt=kn(m),ke=kn(C);const U="x";let me=Pr(),ve=Pr(),Ze=null;ae&&(Ze=ce?ce():Ph());let Le=A($t(Symbol())),Be=0,Ge=0,Je=[],Ke=null,yt=!1,ut=[],tt=null,Fe=null,qe=null,lt;return ae&&Ze&&(Fe=new Ih(V||"unknown",Ze,ke,C,_,de||25,W||50,N?.shouldDisplayDebugInformation??!1)),{treePathSeparator:Z||".",root:me,filteredRoot:ve,get changeTracker(){return s(Le)},idMember:t,pathMember:e,parentPathMember:n,levelMember:r,isExpandedMember:a,isSelectableMember:o,isSelectedMember:l,isDraggableMember:c,getIsDraggableCallback:d,isDropAllowedMember:h,allowedDropPositionsMember:p,hasChildrenMember:i,displayValueMember:m,getDisplayValueCallback:k,searchValueMember:C,getSearchValueCallback:_,getAllowedDropPositionsCallback:v,isCollapsibleMember:P,getIsCollapsibleCallback:E,orderMember:B,isSorted:!1,shouldDisplayDebugInformation:N?.shouldDisplayDebugInformation??!1,filteredTree:Ke,isFiltered:yt,get tree(){return this.isFiltered?Object.values(ve?.children)||[]:!me?.children||!s(Le)?[]:Object.values(me.children)},get visibleFlatNodes(){const L=s(Le);if(L===tt&&ut.length>0)return ut;performance.now();const ne=this.isFiltered?ve:me;if(!ne?.children||!L)return ut=[],tt=L,ut;const H=[];function T(R){const J=Object.values(R.children);for(const Q of J)H.push(Q),Q.isExpanded&&Q.hasChildren&&T(Q)}return T(ne),ut=H,tt=L,H},get statistics(){const ne=Fe?.getStatus()||{isProcessing:!1,queueSize:0};return s(Le)&&{nodeCount:Be,maxLevel:Ge,filteredNodeCount:0,isIndexing:ne.isProcessing,pendingIndexCount:ne.queueSize}},insertArray(L,ne=!1){L=L||[],Fe?.clearQueue(),Je=[],me.children={},Be=0,Ge=0,lr(`[${V}] insertArray:conversion`);const H=[];let T=L.map((oe,Te)=>{const we=Pr();we.treeId=V||"",we.id=t?kt(oe,t):void 0;const He=e?kt(oe,e):void 0;if(He==null||He===""||typeof He!="string"){we.path="",we.data=oe;const Qe=He===""?"empty string":He==null?"undefined/null":`non-string (${typeof He})`;return H.push({node:we,originalData:oe,error:`Item at index ${Te} has invalid path (${Qe}). Check that pathMember="${e}" matches your data. First item keys: ${Te===0?JSON.stringify(Object.keys(oe)):"(see index 0)"}`}),null}return we.path=He,G?we.parentPath=ea(we.path,this.treePathSeparator):we.parentPath=kt(oe,n),we.pathSegment=Xi(Yi(we.path,we.parentPath??"",this.treePathSeparator),0,1,this.treePathSeparator),O?we.level=Er(we.path,this.treePathSeparator):we.level=kt(oe,r),ue?j&&(we.isExpanded=(we.level??0)<=j):we.isExpanded=kt(oe,a),fe||(we.isSelectable=kt(oe,o)),Se||(we.isSelected=kt(oe,l)),se||(we.isDraggable=kt(oe,c)),Ce||(we.isCollapsible=kt(oe,P)),he||(we.isDropAllowed=kt(oe,h)),xe||(we.allowedDropPositions=kt(oe,p)),X||(we.hasChildren=kt(oe,i)),we.data=oe,we}).filter(oe=>oe!==null);const R=Fn(`[${V}] insertArray:conversion`,L.length);lr(`[${V}] insertArray:sort`),this.isSorted||(this.sortCallback?T=this.sortCallback(T):T=this._defaultSort(this,T));const J=Fn(`[${V}] insertArray:sort`,L.length);lr(`[${V}] insertArray:insert`);const Q=[...H];H.length>0&&console.warn(`[Tree ${V}] ${H.length} of ${L.length} items have invalid paths (pathMember="${e}"). These items will be skipped.
9
- First failure: ${H[0].error}`);const Pe=[];let Ie=0,pe=0,ye=!1,M=-1;if(j&&!ne){for(let oe=T.length-1;oe>=0;oe--)if((T[oe].level||Er(T[oe].path,this.treePathSeparator))<=j){M=oe;break}}if(T.forEach((oe,Te)=>{const we=this.insertTreeNode(oe.parentPath??"",oe,!0);we?Q.push({node:oe,originalData:L[Te],error:we}):(pe++,ae&&Fe&&(Je.push(oe),Pe.push({node:oe,index:Ie}),Ie++),!ne&&!ye&&j&&Te===M&&(ye=!0,this._emitTreeChanged()))}),Q.length>0){const oe=Q.map(Te=>Te.error);console.warn(`[Tree ${V}] ${Q.length} nodes failed to insert:`,oe)}Pe.length>0&&Fe&&(Fe.setCallbacks(void 0,()=>{kn(qe)||this.filterNodes(qe,lt),ne||this._emitTreeChanged()}),Fe.addToQueue(Pe)),ne||this._emitTreeChanged();const re=Fn(`[${V}] insertArray:insert`,L.length);return Rh(V||"unknown",{Conversion:R,Sort:J,Insert:re},L.length),{successful:pe,failed:Q,total:L.length}},insertTreeNode(L,ne,H){const T=this.getNodeByPath(L);if(!T)return`Node: ${ne.path} - Could not find parent node: ${L}`;O&&(ne.level=(T.level||0)+1);const R=U+Xi(Yi(ne?.path,L,this.treePathSeparator),0,1,this.treePathSeparator);return T.children.hasOwnProperty(R)||(T.children[R]=ne,X&&!T.hasChildren&&(T.hasChildren=!0),Be++,Ge=Math.max(Ge,ne.level||0)),H||this._emitTreeChanged(),null},filterNodes(L,ne){if(qe=L,lt=ne,kn(L)){ve.children={},this.isFiltered=!1,this._emitTreeChanged();return}if(!ae)return;lr(`[${V}] filterNodes:search`);const H=Ze.search(L,ne),T=H.map(R=>Je[R].path);Fn(`[${V}] filterNodes:search`,H.length),this.createFilteredTree(T)},searchNodes(L,ne){return kn(L)?[]:ae?Ze.search(L,ne).map(R=>Je[R]):[]},createFilteredTree(L){lr(`[${V}] createFilteredTree`),ve.children={},Ke=null;const ne=new Set;L.forEach(R=>{const J=R.split(this.treePathSeparator);for(let Q=1;Q<=J.length;Q++)ne.add(J.slice(0,Q).join(this.treePathSeparator))});const H=new Map;ne.forEach(R=>{const J=this.getNodeByPath(R,me);if(J){const Q={...J,children:{},hasChildren:!1,isExpanded:!0};H.set(R,Q)}}),ne.forEach(R=>{const J=H.get(R);if(!J)return;const Q=R.split(this.treePathSeparator);if(Q.length>1){const Pe=Q.slice(0,-1).join(this.treePathSeparator),Ie=H.get(Pe),pe=U+Q[Q.length-1];Ie&&(Ie.children[pe]=J,Ie.hasChildren=!0)}});const T=[];ne.forEach(R=>{if(!R.includes(this.treePathSeparator)){const J=H.get(R);J&&T.push(J)}}),T.forEach(R=>{ve.children[U+R.path]=R}),Ke=T,this.isFiltered=!0,this._emitTreeChanged(),Fn(`[${V}] createFilteredTree`,T.length)},clearFilter(){ve.children={},Ke=null,this.isFiltered=!1,this._emitTreeChanged()},expandAll(L){lr(`[${V}] expandAll`);function ne(H,T){H.isExpanded=T;for(const R in H.children)ne(H.children[R],T)}if(kn(L))ne(me,!0);else{const H=this.getNodeByPath(L);H&&ne(H,!0)}this._emitTreeChanged(),Fn(`[${V}] expandAll`)},collapseAll(L){lr(`[${V}] collapseAll`);const ne=this;function H(T){T.isExpanded&&ne.getNodeIsCollapsible(T)&&(T.isExpanded=!1);for(const R in T.children)H(T.children[R])}if(kn(L))H(me);else{const T=this.getNodeByPath(L);T&&H(T)}this._emitTreeChanged(),Fn(`[${V}] collapseAll`)},insert(L,ne,H=!1){let T=this.root;const R=L.split(this.treePathSeparator);for(let J=0;J<R.length;J++){const Q=U+R[J];T.children.hasOwnProperty(Q)||(T.children[Q]=Pr()),T=T.children[Q]}T.hasChildren=!0,T.data=ne,H||this._emitTreeChanged()},expandNodes(L,ne=!1){lr(`[${V}] expandNodes`);let H=this.isFiltered?ve:me,T=!1;const R=L.split(this.treePathSeparator);for(let J=0;J<R.length;J++){const Q=U+R[J];H.children.hasOwnProperty(Q)&&(H=H.children[Q],H.isExpanded||(H.isExpanded=!0,T=!0))}return!ne&&T&&this._emitTreeChanged(),Fn(`[${V}] expandNodes`),this},collapseNodes(L,ne=!1){let H=this.isFiltered?ve:this.root,T=!1;const R=L.split(this.treePathSeparator);for(let J=0;J<R.length;J++){const Q=U+R[J];H.children.hasOwnProperty(Q)&&(H=H.children[Q])}return H.isExpanded&&(H.isExpanded=!1,T=!0),!ne&&T&&this._emitTreeChanged(),this},getNodeByPath(L,ne){let H=ne||(this.isFiltered?ve:me);if(L){const T=L.split(this.treePathSeparator);for(let R=0;R<T.length;R++){const J=U+T[R];if(!H.children.hasOwnProperty(J))return null;H=H.children[J]}}return H},getNodeDisplayValue(L){return!nt&&L.data?kt(L.data,m):this.getDisplayValueCallback?this.getDisplayValueCallback(L):"[N/A]"},getNodeSearchValue(L){return!ke&&L.data?kt(L.data,C):this.getSearchValueCallback?this.getSearchValueCallback(L):"[N/A]"},getNodeAllowedDropPositions(L){return this.getAllowedDropPositionsCallback?this.getAllowedDropPositionsCallback(L):!xe&&L.data?kt(L.data,p):L.allowedDropPositions},getNodeIsDraggable(L){return this.getIsDraggableCallback?this.getIsDraggableCallback(L):!se&&L.data?kt(L.data,c):L.isDraggable},getNodeIsCollapsible(L){return this.getIsCollapsibleCallback?this.getIsCollapsibleCallback(L):!Ce&&L.data?kt(L.data,P):L.isCollapsible},refresh(){this._emitTreeChanged()},getChildren(L){const ne=s(Le),H=this.getNodeByPath(L);return!H||!ne?[]:Object.values(H.children)},getSiblings(L){const ne=s(Le),H=this.getNodeByPath(L);if(!H||!ne)return[];const T=H.parentPath||"";return this.getChildren(T)},refreshSiblings(L){const ne=L?this.getNodeByPath(L):me;if(!ne)return;const H=Object.values(ne.children);if(H.length===0)return;let T;this.sortCallback?T=this.sortCallback(H):T=[...H].sort((J,Q)=>{if(this.orderMember&&J.data&&Q.data){const Pe=kt(J.data,this.orderMember)??0,Ie=kt(Q.data,this.orderMember)??0;if(Pe!==Ie)return Pe-Ie}return this.getNodeDisplayValue(J).localeCompare(this.getNodeDisplayValue(Q))});const R={};T.forEach(J=>{const Q=U+J.pathSegment;R[Q]=J}),ne.children=R,this._emitTreeChanged()},refreshNode(L){this._emitTreeChanged()},moveNode(L,ne,H){const T=this.getNodeByPath(L);if(!T)return{success:!1,error:`Source node not found: ${L}`};const R=this.getNodeByPath(ne);if(!R)return{success:!1,error:`Target node not found: ${ne}`};if(ne.startsWith(L+this.treePathSeparator)||ne===L)return{success:!1,error:"Cannot move a node into itself or its descendants"};const J=T.parentPath||"",Q=J?this.getNodeByPath(J):me;if(!Q)return{success:!1,error:`Source parent not found: ${J}`};const Pe=U+T.pathSegment;delete Q.children[Pe],Object.keys(Q.children).length===0&&(Q.hasChildren=!1,i&&Q.data&&(Q.data[i]=!1));let Ie,pe;H==="child"?(Ie=ne,pe=R):(Ie=R.parentPath||"",pe=Ie?this.getNodeByPath(Ie):me);let ye=T.pathSegment;const M=pe.children[U+ye];if(M&&M!==T){const Te=T.id?.toString();Te&&!pe.children[U+Te]?ye=Te:ye=`${ye}_${Date.now()}`}const re=Ie?`${Ie}${this.treePathSeparator}${ye}`:ye,oe=T.path;if(T.path=re,T.pathSegment=ye,T.parentPath=Ie,T.level=Er(re,this.treePathSeparator),T.data&&(e&&(T.data[e]=re),n&&(T.data[n]=Ie),r&&(T.data[r]=T.level)),this._updateDescendantPaths(T,oe,re),pe.children[U+ye]=T,pe.hasChildren=!0,i&&pe.data&&(pe.data[i]=!0),this.orderMember&&H!=="child"&&T.data){const Te=this.orderMember,we=Object.values(pe.children),He=(R.data?kt(R.data,Te):0)??0;if(H==="before"){const $=we.filter(Y=>Y!==T&&Y.data&&kt(Y.data,Te)!==void 0).map(Y=>kt(Y.data,Te)).filter(Y=>Y<He).sort((Y,ge)=>ge-Y)[0]??He-20;T.data[Te]=Math.floor(($+He)/2)}else{const $=we.filter(Y=>Y!==T&&Y.data&&kt(Y.data,Te)!==void 0).map(Y=>kt(Y.data,Te)).filter(Y=>Y>He).sort((Y,ge)=>Y-ge)[0]??He+20;T.data[Te]=Math.floor((He+$)/2)}}return this.refreshSiblings(Ie),{success:!0}},_updateDescendantPaths(L,ne,H){for(const T of Object.values(L.children)){const R=T.path,J=R.substring(ne.length),Q=H+J;T.path=Q,T.parentPath=L.path,T.level=Er(Q,this.treePathSeparator),T.data&&(e&&(T.data[e]=Q),n&&(T.data[n]=L.path),r&&(T.data[r]=T.level)),this._updateDescendantPaths(T,R,Q)}},removeNode(L,ne=!0){const H=this.getNodeByPath(L);if(!H)return{success:!1,error:`Node not found: ${L}`};const T=H.parentPath||"",R=T?this.getNodeByPath(T):me;if(!R)return{success:!1,error:`Parent not found: ${T}`};const J=U+H.pathSegment;if(delete R.children[J],Object.keys(R.children).length===0&&(R.hasChildren=!1,i&&R.data&&(R.data[i]=!1)),ne){const Q=Pe=>{let Ie=1;for(const pe of Object.values(Pe.children))Ie+=Q(pe);return Ie};Be-=Q(H)}else Be--;return this._emitTreeChanged(),{success:!0,node:H}},addNode(L,ne,H){const T=L?this.getNodeByPath(L):me;if(!T&&L)return{success:!1,error:`Parent not found: ${L}`};H||(H=(t&&ne?ne[t]:void 0)?.toString()||`new_${Date.now()}_${Math.random().toString(36).substr(2,9)}`);const R=H,J=L?`${L}${this.treePathSeparator}${R}`:R;if(this.getNodeByPath(J))return{success:!1,error:`Node already exists at path: ${J}`};const Q=Pr();Q.treeId=V||"",Q.id=t&&ne?ne[t]:void 0,Q.path=J,Q.pathSegment=R,Q.parentPath=L,Q.level=Er(J,this.treePathSeparator),Q.data=ne,Q.isExpanded=j?Q.level<=j:!1,Q.hasChildren=!1,ne&&(e&&(ne[e]=J),n&&(ne[n]=L),r&&(ne[r]=Q.level),i&&(ne[i]=!1));const Pe=T||me;return Pe.children[U+H]=Q,Pe.hasChildren=!0,i&&Pe.data&&(Pe.data[i]=!0),Be++,Ge=Math.max(Ge,Q.level||0),Je.push(Q),this.refreshSiblings(L),this._emitTreeChanged(),{success:!0,node:Q}},updateNode(L,ne){const H=this.getNodeByPath(L);if(!H)return{success:!1,error:`Node not found: ${L}`};if(!H.data)return{success:!1,error:`Node has no data: ${L}`};const T=this.orderMember&&this.orderMember in ne;if(H.data={...H.data,...ne},H._rev=(H._rev||0)+1,Fe&&ae){const R=Je.indexOf(H);R!==-1&&Fe.addItem({node:H,index:R})}return T&&this.refreshSiblings(H.parentPath||""),this._emitTreeChanged(),{success:!0,node:H}},applyChanges(L){const ne=[];let H=0;for(let T=0;T<L.length;T++){const R=L[T];let J;switch(R.operation){case"create":J=this.addNode(R.parentPath,R.data,R.pathSegment),J.success?H++:ne.push({index:T,operation:R.operation,path:R.parentPath,error:J.error||"Unknown error"});break;case"update":J=this.updateNode(R.path,R.data),J.success?H++:ne.push({index:T,operation:R.operation,path:R.path,error:J.error||"Unknown error"});break;case"delete":J=this.removeNode(R.path),J.success?H++:ne.push({index:T,operation:R.operation,path:R.path,error:J.error||"Unknown error"});break}}return H>0&&this._emitTreeChanged(),{successful:H,failed:ne}},copyNodeWithDescendants(L,ne,H,T,R){if(!L.data)return{success:!1,count:0,error:"Source node has no data"};let J=0;const Q=(Ie,pe)=>{if(!Ie.data)return null;const ye=H(Ie.data),M=this.addNode(pe,ye);if(!M.success||!M.node)return this.shouldDisplayDebugInformation&&console.warn(`[Tree ${V}] copyNodeWithDescendants: Failed to add node`,M.error),null;J++;const re=M.node;if(Ie.children&&Object.keys(Ie.children).length>0)for(const oe of Object.values(Ie.children))Q(oe,re.path);return re},Pe=Q(L,ne);if(!Pe)return{success:!1,count:0,error:"Failed to copy root node"};if(T&&R&&Pe.data){const Ie=this.getNodeByPath(T);if(Ie&&this.orderMember){const pe=ne?this.getNodeByPath(ne):me;if(pe){const ye=Object.values(pe.children),M=this.orderMember,re=Ie.data?.[M]??0;if(R==="before"){const Te=ye.filter(we=>we!==Pe&&we.data?.[M]!==void 0).map(we=>we.data[M]).filter(we=>we<re).sort((we,He)=>He-we)[0]??re-20;Pe.data[M]=Math.floor((Te+re)/2)}else{const Te=ye.filter(we=>we!==Pe&&we.data?.[M]!==void 0).map(we=>we.data[M]).filter(we=>we>re).sort((we,He)=>we-He)[0]??re+20;Pe.data[M]=Math.floor((re+Te)/2)}this.refreshSiblings(ne)}}}return{success:!0,rootNode:Pe,count:J}},getExpandedPaths(){const L=[],ne=H=>{H.isExpanded&&H.path&&L.push(H.path);for(const T of Object.values(H.children))ne(T)};return ne(me),L},setExpandedPaths(L){const ne=new Set(L),H=T=>{T.path&&(T.isExpanded=ne.has(T.path));for(const R of Object.values(T.children))H(R)};H(me),this._emitTreeChanged()},getAllData(){const L=[],ne=H=>{H.data&&L.push(H.data);for(const T of Object.values(H.children))ne(T)};return ne(me),L},insertBranch(L,ne){const H=L?this.getNodeByPath(L):me;if(!H&&L)return{success:!1,count:0,failed:[],parentNode:null};const T=H||me;if(ne.length===0)return{success:!0,count:0,failed:[],parentNode:T};const R=[];let J=ne.map((pe,ye)=>{const M=Pr();M.treeId=V||"",M.id=t?kt(pe,t):void 0;const re=e?kt(pe,e):void 0;if(re==null||re===""||typeof re!="string"){const oe=re===""?"empty string":re==null?"undefined/null":`non-string (${typeof re})`;return R.push({data:pe,error:`Item at index ${ye} has invalid path (${oe})`}),null}return M.path=re,G?M.parentPath=ea(M.path,this.treePathSeparator):M.parentPath=kt(pe,n),M.pathSegment=Xi(Yi(M.path,M.parentPath??"",this.treePathSeparator),0,1,this.treePathSeparator),O?M.level=Er(M.path,this.treePathSeparator):M.level=kt(pe,r),ue?j&&(M.isExpanded=(M.level??0)<=j):M.isExpanded=kt(pe,a),fe||(M.isSelectable=kt(pe,o)),Se||(M.isSelected=kt(pe,l)),se||(M.isDraggable=kt(pe,c)),Ce||(M.isCollapsible=kt(pe,P)),he||(M.isDropAllowed=kt(pe,h)),xe||(M.allowedDropPositions=kt(pe,p)),X||(M.hasChildren=kt(pe,i)),M.data=pe,M}).filter(pe=>pe!==null);this.isSorted||(this.sortCallback?J=this.sortCallback(J):J=this._defaultSort(this,J));const Q=new Set;let Pe=0;for(const pe of J){const ye=this.insertTreeNode(pe.parentPath??"",pe,!0);ye?R.push({data:pe.data,error:ye}):(Pe++,Q.add(pe.parentPath??""),ae&&Je.push(pe))}for(const pe of Q){const ye=pe?this.getNodeByPath(pe):me;if(!ye)continue;const M=Object.values(ye.children);if(M.length===0)continue;let re;this.sortCallback?re=this.sortCallback(M):re=[...M].sort((Te,we)=>{if(this.orderMember&&Te.data&&we.data){const He=kt(Te.data,this.orderMember)??0,Qe=kt(we.data,this.orderMember)??0;if(He!==Qe)return He-Qe}return this.getNodeDisplayValue(Te).localeCompare(this.getNodeDisplayValue(we))});const oe={};re.forEach(Te=>{oe[U+Te.pathSegment]=Te}),ye.children=oe}for(const pe of Q){const ye=pe?this.getNodeByPath(pe):me;ye&&(ye.hasChildren=Object.keys(ye.children).length>0,i&&ye.data&&(ye.data[i]=ye.hasChildren))}const Ie=new Set;for(const pe of Q){let ye=pe;for(;ye&&!Ie.has(ye);){Ie.add(ye);const M=this.getNodeByPath(ye);M&&(M._rev=(M._rev||0)+1);const re=ye.lastIndexOf(this.treePathSeparator);ye=re>0?ye.substring(0,re):""}}if(ae&&Fe){const pe=Je.length-Pe,ye=[];for(let M=pe;M<Je.length;M++)ye.push({node:Je[M],index:M});ye.length>0&&Fe.addToQueue(ye)}return this._emitTreeChanged(),{success:!0,count:Pe,failed:R,parentNode:T}},replaceBranch(L,ne){const H=L?this.getNodeByPath(L):me;if(!H&&L)return{success:!1,count:0,failed:[],parentNode:null};const T=H||me,R=Q=>{let Pe=0;for(const Ie of Object.values(Q.children))Pe+=1+R(Ie);return Pe},J=R(T);if(J>0){const Q=(Ie,pe)=>{for(const ye of Object.values(Ie.children))pe.add(ye.path),Q(ye,pe)},Pe=new Set;Q(T,Pe),Je=Je.filter(Ie=>!Pe.has(Ie.path))}return T.children={},T.hasChildren=!1,i&&T.data&&(T.data[i]=!1),Be-=J,this.insertBranch(L,ne)},deleteBranch(L,ne=!1){const H=R=>{let J=0;for(const Q of Object.values(R.children))J+=1+H(Q);return J},T=(R,J)=>{for(const Q of Object.values(R.children))J.add(Q.path),T(Q,J)};if(ne){const R=L?this.getNodeByPath(L):me;if(!R&&L)return{success:!1,removedCount:0,error:`Node not found: ${L}`};const J=R||me,Q=H(J);if(Q===0)return{success:!0,removedCount:0};const Pe=new Set;T(J,Pe),Je=Je.filter(pe=>!Pe.has(pe.path)),J.children={},J.hasChildren=!1,i&&J.data&&(J.data[i]=!1),Be-=Q,J._rev=(J._rev||0)+1;let Ie=L;for(;Ie;){const pe=Ie.lastIndexOf(this.treePathSeparator);if(Ie=pe>0?Ie.substring(0,pe):"",Ie){const ye=this.getNodeByPath(Ie);ye&&(ye._rev=(ye._rev||0)+1)}}return this._emitTreeChanged(),{success:!0,removedCount:Q}}else{if(L==="")return{success:!1,removedCount:0,error:"Cannot delete root node"};const R=this.getNodeByPath(L);if(!R)return{success:!1,removedCount:0,error:`Node not found: ${L}`};const J=R.parentPath||"",Q=J?this.getNodeByPath(J):me;if(!Q)return{success:!1,removedCount:0,error:`Parent not found: ${J}`};const Pe=1+H(R),Ie=new Set;Ie.add(R.path),T(R,Ie),Je=Je.filter(M=>!Ie.has(M.path));const pe=U+R.pathSegment;delete Q.children[pe],Object.keys(Q.children).length===0&&(Q.hasChildren=!1,i&&Q.data&&(Q.data[i]=!1)),Be-=Pe;let ye=J;for(;ye;){const M=this.getNodeByPath(ye);M&&(M._rev=(M._rev||0)+1);const re=ye.lastIndexOf(this.treePathSeparator);ye=re>0?ye.substring(0,re):""}return this._emitTreeChanged(),{success:!0,removedCount:Pe}}},_defaultSort(L,ne){return ne.sort((H,T)=>{const R=H.level||0,J=T.level||0;if(R!==J)return R-J;if(H.parentPath!==T.parentPath)return H.parentPath?T.parentPath?H.parentPath.localeCompare(T.parentPath):1:-1;if(L.orderMember&&H.data&&T.data){const Q=H.data[L.orderMember]??0,Pe=T.data[L.orderMember]??0;if(Q!==Pe)return Q-Pe}return L.getNodeDisplayValue(H).localeCompare(L.getNodeDisplayValue(T))})},_emitTreeChanged(){u(Le,Symbol(),!0)},...N}}function Hh(t=100,e){const n=new Map,r=new Set;let i=null,a=!1,o=0,l=!1;function c(){i!==null||n.size===0||(i=requestAnimationFrame(()=>{i=null,d()}))}function d(){const h=performance.now();if(n.size===0){l&&(a=!1,l=!1,e?.onComplete?.({pending:0,processed:o}));return}l||(l=!0,o=0,e?.onStart?.()),a=!0;let p=t;const m=[];wi.trace(`Frame start: pending=${n.size}, budget=${p}`);for(const[C,_]of n){if(p<=0)break;const v=performance.now(),P=_(),E=performance.now()-v;E>10&&wi.warn(`Slow callback: ${C} took ${E.toFixed(2)}ms`),p--,o++,P||m.push(C)}for(const C of m)n.delete(C),r.add(C);const k=performance.now()-h;wi.trace(`Frame end: processed ${t-p} nodes in ${k.toFixed(2)}ms`),e?.onProgress?.({pending:n.size,processed:o}),n.size>0?c():(a=!1,l=!1,e?.onComplete?.({pending:0,processed:o}))}return{register(h,p){return r.has(h)?()=>{}:(n.set(h,p),c(),()=>{n.delete(h)})},isActive(){return a||n.size>0},getStats(){return{pending:n.size,processed:o}},isCompleted(h){return r.has(h)},reset(){r.clear(),n.clear(),i!==null&&(cancelAnimationFrame(i),i=null),a=!1,l=!1,o=0}}}let oi=null;function ta(t){oi=t}function zh(){return oi}function Ji(){oi=null}function Fh(){return oi!==null}function na(){return oi?.operation??null}class Bh{tree;renderCoordinator;nodeCallbacks;#e=A($t({clickBehavior:"expand-and-focus",showCheckboxes:!1,checkboxMode:"independent",expandIconClass:"ltree-icon-expand",collapseIconClass:"ltree-icon-collapse",leafIconClass:"ltree-icon-leaf",highlightedNodeClass:void 0,focusedNodeClass:void 0,dragOverNodeClass:void 0,dropZoneMode:"glow",dropZoneLayout:"around",dropZoneStart:33,toggleIconMode:"rotate",dropZoneMaxWidth:120,allowCopy:!1,accordionExpand:!1}));get nodeConfig(){return s(this.#e)}set nodeConfig(e){u(this.#e,e,!0)}#t=A("");get treeId(){return s(this.#t)}set treeId(e){u(this.#t,e,!0)}#n=A(".");get treePathSeparator(){return s(this.#n)}set treePathSeparator(e){u(this.#n,e,!0)}#r=A([]);get data(){return s(this.#r)}set data(e){u(this.#r,e)}#i=A(null);get focusedNode(){return s(this.#i)}set focusedNode(e){u(this.#i,e)}#s=A(new Set);get highlightedPaths(){return s(this.#s)}set highlightedPaths(e){u(this.#s,e)}lastHighlightedPath=null;#a=A(new Set);get selectedPaths(){return s(this.#a)}set selectedPaths(e){u(this.#a,e)}#o=A(null);get insertResult(){return s(this.#o)}set insertResult(e){u(this.#o,e)}#l=A(void 0);get searchText(){return s(this.#l)}set searchText(e){u(this.#l,e,!0)}#c=A(!1);get isRendering(){return s(this.#c)}set isRendering(e){u(this.#c,e,!0)}#d=A(!1);get shouldDisplayDebugInformation(){return s(this.#d)}set shouldDisplayDebugInformation(e){u(this.#d,e,!0)}#h=A(!1);get shouldDisplayContextMenuInDebugMode(){return s(this.#h)}set shouldDisplayContextMenuInDebugMode(e){u(this.#h,e,!0)}#u=A("visual");get rangeSelectionMode(){return s(this.#u)}set rangeSelectionMode(e){u(this.#u,e,!0)}#f=A(!1);get isLoading(){return s(this.#f)}set isLoading(e){u(this.#f,e,!0)}#g=A(!0);get useFlatRendering(){return s(this.#g)}set useFlatRendering(e){u(this.#g,e,!0)}#v=A(!0);get progressiveRender(){return s(this.#v)}set progressiveRender(e){u(this.#v,e,!0)}#p=A(20);get initialBatchSize(){return s(this.#p)}set initialBatchSize(e){u(this.#p,e,!0)}#y=A(500);get maxBatchSize(){return s(this.#y)}set maxBatchSize(e){u(this.#y,e,!0)}#m=A(void 0);get bodyClass(){return s(this.#m)}set bodyClass(e){u(this.#m,e,!0)}#_=A("none");get dragDropMode(){return s(this.#_)}set dragDropMode(e){u(this.#_,e,!0)}#b=A(!1);get allowCopy(){return s(this.#b)}set allowCopy(e){u(this.#b,e,!0)}#k=A(!1);get accordionExpand(){return s(this.#k)}set accordionExpand(e){u(this.#k,e,!0)}#w=A(!0);get autoHandleCopy(){return s(this.#w)}set autoHandleCopy(e){u(this.#w,e,!0)}#x=A(!0);get autoHandleMove(){return s(this.#x)}set autoHandleMove(e){u(this.#x,e,!0)}#C=A(!0);get autoHandlePaste(){return s(this.#C)}set autoHandlePaste(e){u(this.#C,e,!0)}onNodeClickHandler;onHighlightChangeHandler;onSelectionChangeHandler;onNodeDragStartHandler;onNodeDragOverHandler;onNodeDropHandler;onPasteHandler;onRenderStartHandler;onRenderProgressHandler;onRenderCompleteHandler;beforeDropHandler;beforeCopyHandler;beforeCutHandler;beforePasteHandler;beforeCheckboxToggleHandler;getContextMenuItemsHandler;#S=A("expand-and-focus");get clickBehavior(){return s(this.#S)}set clickBehavior(e){u(this.#S,e,!0)}#N=A(!1);get showCheckboxes(){return s(this.#N)}set showCheckboxes(e){u(this.#N,e,!0)}#D=A("independent");get checkboxMode(){return s(this.#D)}set checkboxMode(e){u(this.#D,e,!0)}#P=A("ltree-icon-expand");get expandIconClass(){return s(this.#P)}set expandIconClass(e){u(this.#P,e,!0)}#I=A("ltree-icon-collapse");get collapseIconClass(){return s(this.#I)}set collapseIconClass(e){u(this.#I,e,!0)}#T=A("ltree-icon-leaf");get leafIconClass(){return s(this.#T)}set leafIconClass(e){u(this.#T,e,!0)}#M=A("rotate");get toggleIconMode(){return s(this.#M)}set toggleIconMode(e){u(this.#M,e,!0)}#E=A(void 0);get highlightedNodeClass(){return s(this.#E)}set highlightedNodeClass(e){u(this.#E,e,!0)}#A=A(void 0);get focusedNodeClass(){return s(this.#A)}set focusedNodeClass(e){u(this.#A,e,!0)}#R=A(void 0);get dragOverNodeClass(){return s(this.#R)}set dragOverNodeClass(e){u(this.#R,e,!0)}#O=A("glow");get dropZoneMode(){return s(this.#O)}set dropZoneMode(e){u(this.#O,e,!0)}#L=A("around");get dropZoneLayout(){return s(this.#L)}set dropZoneLayout(e){u(this.#L,e,!0)}#H=A(33);get dropZoneStart(){return s(this.#H)}set dropZoneStart(e){u(this.#H,e,!0)}#z=A(120);get dropZoneMaxWidth(){return s(this.#z)}set dropZoneMaxWidth(e){u(this.#z,e,!0)}#F=A(4e3);get scrollHighlightTimeout(){return s(this.#F)}set scrollHighlightTimeout(e){u(this.#F,e,!0)}#B=A("ltree-scroll-highlight");get scrollHighlightClass(){return s(this.#B)}set scrollHighlightClass(e){u(this.#B,e,!0)}#j=A(8);get contextMenuXOffset(){return s(this.#j)}set contextMenuXOffset(e){u(this.#j,e,!0)}#V=A(0);get contextMenuYOffset(){return s(this.#V)}set contextMenuYOffset(e){u(this.#V,e,!0)}#K=A(!1);get hasContextMenuSnippet(){return s(this.#K)}set hasContextMenuSnippet(e){u(this.#K,e,!0)}#$=A(!1);get virtualScroll(){return s(this.#$)}set virtualScroll(e){u(this.#$,e,!0)}#Z=A(void 0);get virtualRowHeight(){return s(this.#Z)}set virtualRowHeight(e){u(this.#Z,e,!0)}#U=A(5);get virtualOverscan(){return s(this.#U)}set virtualOverscan(e){u(this.#U,e,!0)}#W=A(void 0);get virtualContainerHeight(){return s(this.#W)}set virtualContainerHeight(e){u(this.#W,e,!0)}navigation;#G=A(!1);get contextMenuVisible(){return s(this.#G)}set contextMenuVisible(e){u(this.#G,e,!0)}#Y=A(0);get contextMenuX(){return s(this.#Y)}set contextMenuX(e){u(this.#Y,e,!0)}#X=A(0);get contextMenuY(){return s(this.#X)}set contextMenuY(e){u(this.#X,e,!0)}#J=A(null);get contextMenuNode(){return s(this.#J)}set contextMenuNode(e){u(this.#J,e)}#Q=A(!1);get isDebugMenuActive(){return s(this.#Q)}set isDebugMenuActive(e){u(this.#Q,e,!0)}currentHighlight=null;#q=A(null);get draggedNode(){return s(this.#q)}set draggedNode(e){u(this.#q,e)}#ee=A(!1);get isDragInProgress(){return s(this.#ee)}set isDragInProgress(e){u(this.#ee,e,!0)}#te=A(null);get hoveredNodeForDrop(){return s(this.#te)}set hoveredNodeForDrop(e){u(this.#te,e)}#ne=A(null);get activeDropPosition(){return s(this.#ne)}set activeDropPosition(e){u(this.#ne,e,!0)}#re=A("move");get currentDropOperation(){return s(this.#re)}set currentDropOperation(e){u(this.#re,e,!0)}#ie=A(null);get floatingZoneRect(){return s(this.#ie)}set floatingZoneRect(e){u(this.#ie,e,!0)}#se=A(null);get floatingHoveredZone(){return s(this.#se)}set floatingHoveredZone(e){u(this.#se,e,!0)}#ae=A({node:null,startX:0,startY:0,isDragging:!1,ghostElement:null,currentDropTarget:null});get touchDragState(){return s(this.#ae)}set touchDragState(e){u(this.#ae,e)}touchTimer=null;#oe=A(new Set);get flatRenderedIds(){return s(this.#oe)}set flatRenderedIds(e){u(this.#oe,e)}#le=A([]);get flatRenderQueue(){return s(this.#le)}set flatRenderQueue(e){u(this.#le,e)}flatRenderAnimationFrame=null;currentBatchSize=0;#ce=A(0);get vsScrollTop(){return s(this.#ce)}set vsScrollTop(e){u(this.#ce,e,!0)}#de=A(null);get vsMeasuredRowHeight(){return s(this.#de)}set vsMeasuredRowHeight(e){u(this.#de,e,!0)}#he=A();get vsContainerRef(){return s(this.#he)}set vsContainerRef(e){u(this.#he,e,!0)}#ue=A(null);get vsDetectedHeight(){return s(this.#ue)}set vsDetectedHeight(e){u(this.#ue,e,!0)}vsRafPending=!1;#fe=A(!1);get isDropPlaceholderActive(){return s(this.#fe)}set isDropPlaceholderActive(e){u(this.#fe,e,!0)}#ge=A(new Set);get cutPaths(){return s(this.#ge)}set cutPaths(e){u(this.#ge,e)}_skipInsertArray=!1;lastFlatNodesTracker=null;containerElement=null;#ve=be(()=>this.virtualRowHeight??this.vsMeasuredRowHeight??32);get vsRowHeight(){return s(this.#ve)}set vsRowHeight(e){u(this.#ve,e)}#pe=be(()=>this.virtualScroll&&this.useFlatRendering);get vsActive(){return s(this.#pe)}set vsActive(e){u(this.#pe,e)}#ye=be(()=>this.virtualContainerHeight??this.vsDetectedHeight??"400px");get vsContainerStyle(){return s(this.#ye)}set vsContainerStyle(e){u(this.#ye,e)}#me=be(()=>this.tree?.visibleFlatNodes??[]);get allFlatNodes(){return s(this.#me)}set allFlatNodes(e){u(this.#me,e)}#_e=be(()=>this.allFlatNodes.length);get vsTotalCount(){return s(this.#_e)}set vsTotalCount(e){u(this.#_e,e)}#be=be(()=>this.vsTotalCount*this.vsRowHeight);get vsTotalHeight(){return s(this.#be)}set vsTotalHeight(e){u(this.#be,e)}#ke=be(()=>this.vsActive?Math.max(0,Math.floor(this.vsScrollTop/this.vsRowHeight)-this.virtualOverscan):0);get vsStartIndex(){return s(this.#ke)}set vsStartIndex(e){u(this.#ke,e)}#we=be(()=>this.vsActive?Math.min(this.vsTotalCount,Math.ceil((this.vsScrollTop+(this.vsContainerRef?.clientHeight??0))/this.vsRowHeight)+this.virtualOverscan):this.vsTotalCount);get vsEndIndex(){return s(this.#we)}set vsEndIndex(e){u(this.#we,e)}#xe=be(()=>this.vsStartIndex*this.vsRowHeight);get vsOffsetY(){return s(this.#xe)}set vsOffsetY(e){u(this.#xe,e)}#Ce=be(()=>this.vsActive?this.allFlatNodes.slice(this.vsStartIndex,this.vsEndIndex):this.useFlatRendering&&this.progressiveRender?this.tree?.visibleFlatNodes?.filter(e=>this.flatRenderedIds.has(String(e.id)))??[]:this.tree?.visibleFlatNodes??[]);get flatNodesToRender(){return s(this.#Ce)}set flatNodesToRender(e){u(this.#Ce,e)}get statistics(){return this.tree?.statistics}constructor(e){this.treeId=e.treeId||this.generateTreeId(),this.treePathSeparator=e.treePathSeparator??".",this.data=e.data,this.focusedNode=e.focusedNode??null,this.highlightedPaths=e.highlightedPaths??new Set,this.selectedPaths=e.selectedPaths??new Set,this.searchText=e.searchText,this.shouldDisplayDebugInformation=e.shouldDisplayDebugInformation??!1,this.shouldDisplayContextMenuInDebugMode=e.shouldDisplayContextMenuInDebugMode??!1,this.rangeSelectionMode=e.rangeSelectionMode??"visual",this.isLoading=e.isLoading??!1,this.useFlatRendering=e.useFlatRendering??!0,this.progressiveRender=e.progressiveRender??!0,this.initialBatchSize=e.initialBatchSize??20,this.maxBatchSize=e.maxBatchSize??500,this.bodyClass=e.bodyClass,this.dragDropMode=e.dragDropMode??"none",this.allowCopy=e.allowCopy??!1,this.autoHandleCopy=e.autoHandleCopy??!0,this.autoHandleMove=e.autoHandleMove??!0,this.autoHandlePaste=e.autoHandlePaste??!0,this.accordionExpand=e.accordionExpand??!1,this.clickBehavior=e.clickBehavior??"expand-and-focus",this.showCheckboxes=e.showCheckboxes??!1,this.checkboxMode=e.checkboxMode??"independent",this.beforeCheckboxToggleHandler=e.beforeCheckboxToggleCallback,this.expandIconClass=e.expandIconClass??"ltree-icon-expand",this.collapseIconClass=e.collapseIconClass??"ltree-icon-collapse",this.leafIconClass=e.leafIconClass??"ltree-icon-leaf",this.toggleIconMode=e.toggleIconMode??"rotate",this.highlightedNodeClass=e.highlightedNodeClass,this.focusedNodeClass=e.focusedNodeClass,this.dragOverNodeClass=e.dragOverNodeClass,this.dropZoneMode=e.dropZoneMode??"glow",this.dropZoneLayout=e.dropZoneLayout??"around",this.dropZoneStart=e.dropZoneStart??33,this.dropZoneMaxWidth=e.dropZoneMaxWidth??120,this.scrollHighlightTimeout=e.scrollHighlightTimeout??4e3,this.scrollHighlightClass=e.scrollHighlightClass??"ltree-scroll-highlight",this.contextMenuXOffset=e.contextMenuXOffset??8,this.contextMenuYOffset=e.contextMenuYOffset??0,this.hasContextMenuSnippet=e.hasContextMenuSnippet??!1,this.virtualScroll=e.virtualScroll??!1,this.virtualRowHeight=e.virtualRowHeight,this.virtualOverscan=e.virtualOverscan??5,this.virtualContainerHeight=e.virtualContainerHeight,this.onNodeClickHandler=e.onNodeClick,this.onHighlightChangeHandler=e.onHighlightChange,this.onSelectionChangeHandler=e.onSelectionChange,this.onNodeDragStartHandler=e.onNodeDragStart,this.onNodeDragOverHandler=e.onNodeDragOver,this.onNodeDropHandler=e.onNodeDrop,this.onPasteHandler=e.onPaste,this.beforeDropHandler=e.beforeDropCallback,this.beforeCopyHandler=e.beforeCopyCallback,this.beforeCutHandler=e.beforeCutCallback,this.beforePasteHandler=e.beforePasteCallback,this.getContextMenuItemsHandler=e.getContextMenuItemsCallback,this.onRenderStartHandler=e.onRenderStart,this.onRenderProgressHandler=e.onRenderProgress,this.onRenderCompleteHandler=e.onRenderComplete,this.tree=Lh(e.idMember,e.pathMember,e.parentPathMember,e.levelMember,e.hasChildrenMember,e.isExpandedMember,e.isSelectableMember,e.isSelectedMember,e.isDraggableMember,e.getIsDraggableCallback,e.isDropAllowedMember,e.allowedDropPositionsMember,e.displayValueMember,e.getDisplayValueCallback,e.searchValueMember,e.getSearchValueCallback,e.getAllowedDropPositionsCallback,e.isCollapsibleMember,e.getIsCollapsibleCallback,e.orderMember,this.treeId,this.treePathSeparator,e.expandLevel,e.shouldUseInternalSearchIndex,e.initializeIndexCallback,e.indexerBatchSize,e.indexerTimeout,{shouldDisplayDebugInformation:e.shouldDisplayDebugInformation,isSorted:e.isSorted,sortCallback:e.sortCallback}),this.renderCoordinator=this.progressiveRender?Hh(2,{onStart:()=>{this.isRendering=!0,this.onRenderStartHandler?.()},onProgress:n=>{this.onRenderProgressHandler?.(n)},onComplete:n=>{this.isRendering=!1,this.onRenderCompleteHandler?.(n)}}):null,this.nodeCallbacks={onNodeClicked:(n,r)=>this._onNodeClicked(n,r),onCheckboxToggle:n=>this._onCheckboxToggle(n),onNodeRightClicked:this._onNodeRightClicked.bind(this),onNodeDragStart:this._onNodeDragStart.bind(this),onNodeDragOver:this._onNodeDragOver.bind(this),onNodeDragLeave:this._onNodeDragLeave.bind(this),onNodeDrop:this._onNodeDrop.bind(this),onZoneDrop:this._onZoneDrop.bind(this),onTouchDragStart:this._onTouchStart.bind(this),onTouchDragMove:this._onTouchMove.bind(this),onTouchDragEnd:this._onTouchEnd.bind(this)},this.nodeConfig={clickBehavior:this.clickBehavior,showCheckboxes:this.showCheckboxes,checkboxMode:this.checkboxMode,expandIconClass:this.expandIconClass,collapseIconClass:this.collapseIconClass,leafIconClass:this.leafIconClass,toggleIconMode:this.toggleIconMode,highlightedNodeClass:this.highlightedNodeClass,focusedNodeClass:this.focusedNodeClass,dragOverNodeClass:this.dragOverNodeClass,dropZoneMode:this.dropZoneMode,dropZoneLayout:this.dropZoneLayout,dropZoneStart:this.dropZoneStart,dropZoneMaxWidth:this.dropZoneMaxWidth,allowCopy:this.allowCopy,accordionExpand:this.accordionExpand},this.navigation=this.createDefaultNavigation(),De(()=>{this.tree.treePathSeparator=this.treePathSeparator}),De(()=>{Object.assign(this.nodeConfig,{clickBehavior:this.clickBehavior,showCheckboxes:this.showCheckboxes,expandIconClass:this.expandIconClass,collapseIconClass:this.collapseIconClass,leafIconClass:this.leafIconClass,toggleIconMode:this.toggleIconMode,highlightedNodeClass:this.highlightedNodeClass,focusedNodeClass:this.focusedNodeClass,dragOverNodeClass:this.dragOverNodeClass,dropZoneMode:this.dropZoneMode,dropZoneLayout:this.dropZoneLayout,dropZoneStart:this.dropZoneStart,dropZoneMaxWidth:this.dropZoneMaxWidth,allowCopy:this.allowCopy,accordionExpand:this.accordionExpand})}),De(()=>{this.tree.filterNodes(this.searchText)}),De(()=>{if(this.tree&&this.data){if(this._skipInsertArray){this._skipInsertArray=!1;return}if(this.renderCoordinator?.reset(),this.flatRenderedIds=new Set,this.flatRenderQueue=[],this.currentBatchSize=0,this.vsMeasuredRowHeight=null,this.vsDetectedHeight=null,this.insertResult=this.tree.insertArray(this.data),this.tree.isSelectedMember){const n=new Set,r=i=>{i.isSelected&&n.add(i.path);for(const a in i.children)r(i.children[a])};for(const i in this.tree.root.children)r(this.tree.root.children[i]);this.selectedPaths=n}}}),De(()=>{if(!this.useFlatRendering||!this.progressiveRender||!this.tree?.visibleFlatNodes)return;const n=this.tree.changeTracker;if(n===this.lastFlatNodesTracker)return;this.lastFlatNodesTracker=n;const r=this.tree.visibleFlatNodes,i=new Set(r.map(d=>String(d.id))),a=new Set(this.flatRenderedIds),o=new Set(this.flatRenderQueue),l=[];for(const d of r){const h=String(d.id);!a.has(h)&&!o.has(h)&&l.push(h)}const c=[];for(const d of a)i.has(d)||c.push(d);if(c.length>0){const d=new Set(a);for(const h of c)d.delete(h);this.flatRenderedIds=d}if(l.length>0){const d=a.size>1e3,h=l.length<200;if(d&&h)this.flatRenderedIds=new Set([...this.flatRenderedIds,...l]);else{this.currentBatchSize=this.initialBatchSize;const p=l.slice(0,this.currentBatchSize),m=l.slice(this.currentBatchSize);p.length>0&&(this.flatRenderedIds=new Set([...this.flatRenderedIds,...p])),this.currentBatchSize=Math.min(this.currentBatchSize*2,this.maxBatchSize),m.length>0&&(this.flatRenderQueue=[...m],this.scheduleFlatRenderBatch())}}}),De(()=>{!this.vsActive||this.virtualRowHeight||this.vsMeasuredRowHeight||this.allFlatNodes.length!==0&&mn().then(()=>{if(this.vsContainerRef){const n=this.vsContainerRef.querySelector(".ltree-node");if(n){const r=n.getBoundingClientRect().height;r>0&&(this.vsMeasuredRowHeight=r)}}})}),De(()=>{!this.vsActive||this.virtualContainerHeight||this.vsDetectedHeight||mn().then(()=>{if(this.vsContainerRef?.parentElement){const n=this.vsContainerRef.parentElement.clientHeight;n>100&&(this.vsDetectedHeight=n+"px")}})}),De(()=>{if(this.contextMenuVisible){const n=i=>{i.target.closest(".ltree-context-menu")||this.closeContextMenu()},r=()=>{this.closeContextMenu()};return document.addEventListener("click",n),document.addEventListener("contextmenu",n),window.addEventListener("scroll",r,!0),document.addEventListener("scroll",r,!0),window.addEventListener("wheel",r,{passive:!0}),()=>{document.removeEventListener("click",n),document.removeEventListener("contextmenu",n),window.removeEventListener("scroll",r,!0),document.removeEventListener("scroll",r,!0),window.removeEventListener("wheel",r)}}}),De(()=>{if(this.shouldDisplayContextMenuInDebugMode&&(this.hasContextMenuSnippet||this.getContextMenuItemsHandler)&&this.tree?.tree&&this.tree.tree.length>0){const n=this.tree.tree.length>1?this.tree.tree[1]:this.tree.tree[0];if(n&&this.containerElement){const r=this.containerElement.getBoundingClientRect();this.contextMenuNode=n,this.contextMenuX=r.left+200,this.contextMenuY=r.top+100,this.contextMenuVisible=!0,this.isDebugMenuActive=!0}}else!this.shouldDisplayContextMenuInDebugMode&&this.isDebugMenuActive&&(this.contextMenuVisible=!1,this.contextMenuNode=null,this.isDebugMenuActive=!1)})}handleVirtualScroll=e=>{this.vsRafPending||(this.vsRafPending=!0,requestAnimationFrame(()=>{this.vsScrollTop=e.target.scrollTop,this.vsRafPending=!1}))};async expandNodes(e){this.tree.expandNodes(e)}async collapseNodes(e){this.tree.collapseNodes(e)}expandAll(e){this.tree?.expandAll(e)}collapseAll(e){this.tree?.collapseAll(e)}filterNodes(e,n){this.tree?.filterNodes(e,n)}searchNodes(e,n){return this.tree?.searchNodes(e,n)||[]}getChildren(e){return this.tree?.getChildren(e)||[]}getSiblings(e){return this.tree?.getSiblings(e)||[]}refreshSiblings(e){this.tree?.refreshSiblings(e)}refreshNode(e){this.tree?.refreshNode(e)}getNodeByPath(e){return this.tree?.getNodeByPath(e)||null}moveNode(e,n,r){this._skipInsertArray=!0;const i=this.tree?.moveNode(e,n,r)||{success:!1,error:"Tree not initialized"};return mn().then(()=>{this._skipInsertArray=!1}),i}removeNode(e,n=!0){this._skipInsertArray=!0;const r=this.tree?.removeNode(e,n)||{success:!1,error:"Tree not initialized"};return mn().then(()=>{this._skipInsertArray=!1}),r}addNode(e,n,r){this._skipInsertArray=!0;const i=this.tree?.addNode(e,n,r)||{success:!1,error:"Tree not initialized"};return mn().then(()=>{this._skipInsertArray=!1}),i}updateNode(e,n){this._skipInsertArray=!0;const r=this.tree?.updateNode(e,n)||{success:!1,error:"Tree not initialized"};return mn().then(()=>{this._skipInsertArray=!1}),r}applyChanges(e){this._skipInsertArray=!0;const n=this.tree?.applyChanges(e)||{successful:0,failed:[]};return mn().then(()=>{this._skipInsertArray=!1}),n}copyNodeWithDescendants(e,n,r,i,a){this._skipInsertArray=!0;const o=this.tree?.copyNodeWithDescendants(e,n,r,i,a)||{success:!1,count:0,error:"Tree not initialized"};return mn().then(()=>{this._skipInsertArray=!1}),o}insertBranch(e,n){this._skipInsertArray=!0;const r=this.tree?.insertBranch(e,n)||{success:!1,count:0,failed:[],parentNode:null};return mn().then(()=>{this._skipInsertArray=!1}),r}replaceBranch(e,n){this._skipInsertArray=!0;const r=this.tree?.replaceBranch(e,n)||{success:!1,count:0,failed:[],parentNode:null};return mn().then(()=>{this._skipInsertArray=!1}),r}deleteBranch(e,n){this._skipInsertArray=!0;const r=this.tree?.deleteBranch(e,n)||{success:!1,removedCount:0,error:"Tree not initialized"};return mn().then(()=>{this._skipInsertArray=!1}),r}_collectClipboardEntry(e){const n=[];this.treePathSeparator;const r=i=>{for(const a of Object.values(i.children)){const o=a.path.substring(e.path.length);n.push({relativePath:o,data:structuredClone(a.data)}),r(a)}};return r(e),{sourceTreeId:this.treeId,sourcePath:e.path,data:structuredClone(e.data),descendants:n}}copyNodes(e){let n=e??[...this.highlightedPaths];if(n.length===0)return;if(this.beforeCopyHandler){const i=this.beforeCopyHandler(n);if(i===!1)return;Array.isArray(i)&&(n=i)}const r=[];for(const i of n){const a=this.tree.getNodeByPath(i);a&&r.push(this._collectClipboardEntry(a))}r.length!==0&&(this.cutPaths=new Set,ta({operation:"copy",entries:r,sourceTreeId:this.treeId}),Sn.debug(`[clipboard] Copied ${r.length} node(s)`))}cutNodes(e){let n=e??[...this.highlightedPaths];if(n.length===0)return;if(this.beforeCutHandler){const a=this.beforeCutHandler(n);if(a===!1)return;Array.isArray(a)&&(n=a)}const r=[],i=new Set;for(const a of n){const o=this.tree.getNodeByPath(a);if(o){r.push(this._collectClipboardEntry(o)),i.add(a);const l=c=>{for(const d of Object.values(c.children))i.add(d.path),l(d)};l(o)}}r.length!==0&&(ta({operation:"cut",entries:r,sourceTreeId:this.treeId}),this.cutPaths=i,Sn.debug(`[clipboard] Cut ${r.length} node(s), dimming ${i.size} paths`))}pasteNodes(e,n,r="child"){const i=zh();if(!i||i.entries.length===0)return{success:!1,count:0,error:"Clipboard is empty"};if(this.beforePasteHandler){const h=this.beforePasteHandler(e,i.operation,i.entries);if(h===!1)return{success:!1,count:0,error:"Paste blocked by beforePasteCallback"};h&&typeof h=="object"&&(h.targetPath!==void 0&&(e=h.targetPath),h.position!==void 0&&(r=h.position))}const a=e==="",o=a?null:this.tree.getNodeByPath(e);if(!a&&!o)return{success:!1,count:0,error:`Target node not found: ${e}`};if(!a&&i.sourceTreeId===this.treeId){const h=this.treePathSeparator;for(const p of i.entries)if(e===p.sourcePath||e.startsWith(p.sourcePath+h))return{success:!1,count:0,error:"Cannot paste a node into itself or its own descendant"}}if(!this.autoHandlePaste){const h={success:!0,count:i.entries.length,entries:i.entries,operation:i.operation,targetPath:e,position:r};return this.cutPaths=new Set,Ji(),Sn.debug(`[clipboard] autoHandlePaste=false — forwarding ${i.entries.length} entries to consumer`),this.onPasteHandler?.(h),h}this._skipInsertArray=!0;let l=0,c;for(const h of i.entries){const p=n(h.data,l,i.operation);let m;if(a||r==="child"?m=this.tree.addNode(e,p):m=this.tree.addNode(o.parentPath??"",p),m.success&&m.node){l++;for(const k of h.descendants){const C=n(k.data,l,i.operation),_=k.relativePath.substring(0,k.relativePath.lastIndexOf(this.treePathSeparator)),v=_?m.node.path+_:m.node.path;this.tree.addNode(v,C).success&&l++}}else c=m.error}if(i.operation==="cut"&&i.sourceTreeId===this.treeId)for(const h of i.entries)this.tree.removeNode(h.sourcePath,!0);mn().then(()=>{this._skipInsertArray=!1}),this.cutPaths=new Set,Ji();const d={success:l>0,count:l,error:l===0?c??"No nodes pasted":void 0};return Sn.debug(`[clipboard] Pasted ${l} node(s)`),this.onPasteHandler?.(d),d}cancelCut(){na()==="cut"&&Ji(),this.cutPaths=new Set,Sn.debug("[clipboard] Cut cancelled")}hasClipboardContent(){return Fh()}getClipboardOperation(){return na()}getExpandedPaths(){return this.tree?.getExpandedPaths()||[]}setExpandedPaths(e){this.tree?.setExpandedPaths(e)}getAllData(){return this.tree?.getAllData()||[]}openContextMenu(e,n,r){this.contextMenuNode=e,this.contextMenuX=n+this.contextMenuXOffset,this.contextMenuY=r+this.contextMenuYOffset,this.contextMenuVisible=!0,this.isDebugMenuActive=!1}closeContextMenu(){this.contextMenuVisible=!1,this.contextMenuNode=null,this.isDebugMenuActive=!1}startDrag(e,n){if(Wt.debug("startDrag",{path:e.path,isDraggable:this.getNodeIsDraggable(e),hasDataTransfer:!!n.dataTransfer}),!this.getNodeIsDraggable(e)||!n.dataTransfer)return;n.dataTransfer.effectAllowed=this.allowCopy?"copyMove":"move",n.dataTransfer.setData("application/svelte-treeview",JSON.stringify(e));const r=this.tree.getNodeDisplayValue(e);r&&n.dataTransfer.setData("text/plain",r),this._onNodeDragStart(e,n)}dragOver(e,n,r){if(!n.dataTransfer?.types.includes("application/svelte-treeview")){Wt.debug("dragOver SKIP - no svelte-treeview type",{path:e.path,types:Array.from(n.dataTransfer?.types??[])});return}let i=this.draggedNode,a=!1;if(!i){a=!0;try{const c=n.dataTransfer.getData("application/svelte-treeview");c&&(i=JSON.parse(c))}catch{}this.isDragInProgress=!0}if(!(a?this.dragDropMode==="both"||this.dragDropMode==="cross":this.isDropAllowedByMode(i?.treeId))){Wt.debug("dragOver REJECTED - mode not allowed",{path:e.path,dragDropMode:this.dragDropMode,isCrossTreeDrag:a,draggedTreeId:i?.treeId,thisTreeId:this.treeId}),this.hoveredNodeForDrop=null;return}if(!(i?a||i.path!==e.path:this.isDragInProgress)){Wt.debug("dragOver REJECTED - invalid drop (same node?)",{path:e.path,draggedPath:i?.path});return}if(n.preventDefault(),this.hoveredNodeForDrop=e,this.currentDropOperation=this.allowCopy&&n.ctrlKey?"copy":"move",n.dataTransfer&&(n.dataTransfer.dropEffect=this.currentDropOperation),r){const c=this.getNodeAllowedDropPositions(e);this.activeDropPosition=this.calculateDropPositionFromEvent(n,r,c)}else{const c=n.currentTarget||n.target;c&&(this.activeDropPosition=this.calculateDropPosition(n,c))}Wt.debug("dragOver OK",{target:e.path,position:this.activeDropPosition,operation:this.currentDropOperation,hasElement:!!r}),this.onNodeDragOverHandler?.(e,n)}dragLeave(e,n){const r=n.currentTarget;if(!r)return;const i=r.getBoundingClientRect(),a=n.clientX,o=n.clientY;(a<i.left||a>=i.right||o<i.top||o>=i.bottom)&&(Wt.debug("dragLeave",{path:e.path}),this.hoveredNodeForDrop=null,this.activeDropPosition=null)}drop(e,n){Wt.debug("drop called",{target:e.path,draggedNode:this.draggedNode?.path,activeDropPosition:this.activeDropPosition}),n.preventDefault(),n.stopPropagation(),n.dataTransfer&&(n.dataTransfer.dropEffect=this.allowCopy&&n.ctrlKey?"copy":"move");let r=!1;if(!this.draggedNode){const i=n.dataTransfer?.getData("application/svelte-treeview");Wt.debug("drop - no draggedNode, read from dataTransfer:",{hasData:!!i}),i&&(this.draggedNode=JSON.parse(i),r=this.draggedNode?.treeId!==this.treeId)}if(this.draggedNode){const i=r?this.dragDropMode==="both"||this.dragDropMode==="cross":this.isDropAllowedByMode(this.draggedNode.treeId),a=!r&&this.draggedNode.path===e.path;if(Wt.debug("drop check",{dropAllowed:i,isCrossTreeDrag:r,sameNode:a,draggedPath:this.draggedNode.path,targetPath:e.path,dragDropMode:this.dragDropMode}),i&&(r||this.draggedNode.path!==e.path)){const o=this.activeDropPosition||"child";Wt.debug("drop EXECUTING",{from:this.draggedNode.path,to:e.path,position:o}),this._handleDrop(e,this.draggedNode,o,n)}else Wt.debug("drop REJECTED",{dropAllowed:i,sameNode:a})}else Wt.debug("drop - no draggedNode available, skipping");this._resetDragState()}dropAt(e,n,r){if(Wt.debug("dropAt",{target:e.path,position:n,draggedNode:this.draggedNode?.path}),r instanceof DragEvent&&(r.preventDefault(),!this.draggedNode)){const i=r.dataTransfer?.getData("application/svelte-treeview");i&&(this.draggedNode=JSON.parse(i))}this.draggedNode?(Wt.debug("dropAt EXECUTING",{from:this.draggedNode.path,to:e.path,position:n}),this._handleDrop(e,this.draggedNode,n,r)):Wt.debug("dropAt - no draggedNode, skipping"),this._resetDragState()}cancelDrag(){Wt.debug("Drag cancelled via public API"),this._resetDragState()}touchStart(e,n){this._onTouchStart(e,n)}touchMove(e,n){this._onTouchMove(e,n)}touchEnd(e,n){this._onTouchEnd(e,n)}getNodeAllowedDropPositions(e){return this.tree?.getNodeAllowedDropPositions(e)??null}getNodeIsDraggable(e){return this.tree?.getNodeIsDraggable(e)??!0}getNodeIsCollapsible(e){return this.tree?.getNodeIsCollapsible(e)??!0}calculateDropPositionFromEvent(e,n,r){const i=n.getBoundingClientRect(),a=e.clientX-i.left,o=e.clientY-i.top,l=i.width,c=i.height;let d;return a>l/2?d="child":o<c/2?d="before":d="after",!r||r.length===0||r.includes(d)?d:r.length===1?r[0]:r.includes("before")&&r.includes("after")?o<c/2?"before":"after":r[0]}async scrollToPath(e,n){lr(`[${this.treeId}] scrollToPath`);const{expand:r=!0,expandTarget:i=!1,highlight:a=!0,scrollOptions:o={behavior:"smooth",block:"center"},containerScroll:l=!1,containerElement:c}=n||{},d=this.tree.getNodeByPath(e);if(!d||!d.id)return console.warn(`[Tree ${this.treeId}] Node not found for path: ${e}`),Fn(`[${this.treeId}] scrollToPath`),!1;if(r&&d.parentPath&&this.tree.expandNodes(d.parentPath),i&&this.tree.expandNodes(e),(r||i)&&await mn(),this.vsActive&&this.vsContainerRef){const C=this.allFlatNodes.findIndex(v=>v.path===e);if(C===-1)return console.warn(`[Tree ${this.treeId}] Node not found in flat nodes for path: ${e}`),Fn(`[${this.treeId}] scrollToPath`),!1;const _=C*this.vsRowHeight-this.vsContainerRef.clientHeight/2+this.vsRowHeight/2;if(this.vsContainerRef.scrollTo({top:Math.max(0,_),behavior:o?.behavior||"smooth"}),await mn(),await new Promise(v=>requestAnimationFrame(v)),await mn(),await new Promise(v=>requestAnimationFrame(v)),a&&this.scrollHighlightClass){const v=`${this.treeId}-${d.id}`;this.applyHighlight(v)||(await mn(),await new Promise(P=>requestAnimationFrame(P)),this.applyHighlight(v))}return Fn(`[${this.treeId}] scrollToPath`),!0}const h=`${this.treeId}-${d.id}`,p=c||this.containerElement,k=(p?p.querySelector(`#${CSS.escape(h)}`):document.getElementById(h))?.querySelector(".ltree-node-content");if(!k)return console.warn(`[Tree ${this.treeId}] DOM element not found for node ID: ${h}`),Fn(`[${this.treeId}] scrollToPath`),!1;if(l){const C=this.findScrollableAncestor(k);if(C){const _=C.getBoundingClientRect(),v=k.getBoundingClientRect(),P=C.scrollTop+(v.top-_.top)-_.height/2+v.height/2;C.scrollTo({top:P,behavior:o?.behavior||"smooth"})}}else k.scrollIntoView(o);return a&&this.scrollHighlightClass&&this.applyHighlight(h),Fn(`[${this.treeId}] scrollToPath`),!0}applyHighlight(e){const n=this.containerElement,i=(n?n.querySelector(`#${CSS.escape(e)}`):document.getElementById(e))?.querySelector(".ltree-node-content");if(!i||!this.scrollHighlightClass)return!1;this.currentHighlight&&(this.currentHighlight.element.classList.remove(this.scrollHighlightClass),clearTimeout(this.currentHighlight.timeoutId),this.currentHighlight=null),i.classList.add(this.scrollHighlightClass);const a=this.scrollHighlightClass,o=setTimeout(()=>{i.classList.remove(a),this.currentHighlight=null},this.scrollHighlightTimeout);return this.currentHighlight={element:i,timeoutId:o},!0}updateProps(e){e.treeId!==void 0&&(this.treeId=e.treeId||this.treeId),e.treePathSeparator!==void 0&&(this.treePathSeparator=e.treePathSeparator??"."),e.data!==void 0&&(this.data=e.data),e.focusedNode!==void 0&&this._setFocusedNode(e.focusedNode??null),e.highlightedPaths!==void 0&&(this.highlightedPaths=e.highlightedPaths??new Set),e.selectedPaths!==void 0&&(this.selectedPaths=e.selectedPaths??new Set),e.searchText!==void 0&&(this.searchText=e.searchText),e.shouldDisplayDebugInformation!==void 0&&(this.shouldDisplayDebugInformation=e.shouldDisplayDebugInformation),e.rangeSelectionMode!==void 0&&(this.rangeSelectionMode=e.rangeSelectionMode??"visual"),e.shouldDisplayContextMenuInDebugMode!==void 0&&(this.shouldDisplayContextMenuInDebugMode=e.shouldDisplayContextMenuInDebugMode??!1),e.isLoading!==void 0&&(this.isLoading=e.isLoading??!1),e.bodyClass!==void 0&&(this.bodyClass=e.bodyClass),e.virtualScroll!==void 0&&(this.virtualScroll=e.virtualScroll??!1),e.virtualRowHeight!==void 0&&(this.virtualRowHeight=e.virtualRowHeight),e.virtualOverscan!==void 0&&(this.virtualOverscan=e.virtualOverscan??5),e.virtualContainerHeight!==void 0&&(this.virtualContainerHeight=e.virtualContainerHeight),e.clickBehavior!==void 0&&(this.clickBehavior=e.clickBehavior??"expand-and-focus"),e.showCheckboxes!==void 0&&(this.showCheckboxes=e.showCheckboxes??!1),e.checkboxMode!==void 0&&(this.checkboxMode=e.checkboxMode??"independent"),e.beforeCheckboxToggleCallback!==void 0&&(this.beforeCheckboxToggleHandler=e.beforeCheckboxToggleCallback),e.expandIconClass!==void 0&&(this.expandIconClass=e.expandIconClass??"ltree-icon-expand"),e.collapseIconClass!==void 0&&(this.collapseIconClass=e.collapseIconClass??"ltree-icon-collapse"),e.leafIconClass!==void 0&&(this.leafIconClass=e.leafIconClass??"ltree-icon-leaf"),e.highlightedNodeClass!==void 0&&(this.highlightedNodeClass=e.highlightedNodeClass),e.focusedNodeClass!==void 0&&(this.focusedNodeClass=e.focusedNodeClass),e.dragOverNodeClass!==void 0&&(this.dragOverNodeClass=e.dragOverNodeClass),e.dropZoneMode!==void 0&&(this.dropZoneMode=e.dropZoneMode??"glow"),e.dropZoneLayout!==void 0&&(this.dropZoneLayout=e.dropZoneLayout??"around"),e.dropZoneStart!==void 0&&(this.dropZoneStart=e.dropZoneStart??33),e.dropZoneMaxWidth!==void 0&&(this.dropZoneMaxWidth=e.dropZoneMaxWidth??120),e.allowCopy!==void 0&&(this.allowCopy=e.allowCopy??!1),e.autoHandleCopy!==void 0&&(this.autoHandleCopy=e.autoHandleCopy??!0),e.autoHandleMove!==void 0&&(this.autoHandleMove=e.autoHandleMove??!0),e.autoHandlePaste!==void 0&&(this.autoHandlePaste=e.autoHandlePaste??!0),e.dragDropMode!==void 0&&(this.dragDropMode=e.dragDropMode??"none"),e.scrollHighlightTimeout!==void 0&&(this.scrollHighlightTimeout=e.scrollHighlightTimeout??4e3),e.scrollHighlightClass!==void 0&&(this.scrollHighlightClass=e.scrollHighlightClass??"ltree-scroll-highlight"),e.contextMenuXOffset!==void 0&&(this.contextMenuXOffset=e.contextMenuXOffset??8),e.contextMenuYOffset!==void 0&&(this.contextMenuYOffset=e.contextMenuYOffset??0),e.onNodeClick!==void 0&&(this.onNodeClickHandler=e.onNodeClick),e.onNodeDragStart!==void 0&&(this.onNodeDragStartHandler=e.onNodeDragStart),e.onNodeDragOver!==void 0&&(this.onNodeDragOverHandler=e.onNodeDragOver),e.beforeDropCallback!==void 0&&(this.beforeDropHandler=e.beforeDropCallback),e.beforeCopyCallback!==void 0&&(this.beforeCopyHandler=e.beforeCopyCallback),e.beforeCutCallback!==void 0&&(this.beforeCutHandler=e.beforeCutCallback),e.beforePasteCallback!==void 0&&(this.beforePasteHandler=e.beforePasteCallback),e.onNodeDrop!==void 0&&(this.onNodeDropHandler=e.onNodeDrop),e.onPaste!==void 0&&(this.onPasteHandler=e.onPaste),e.getContextMenuItemsCallback!==void 0&&(this.getContextMenuItemsHandler=e.getContextMenuItemsCallback),e.onHighlightChange!==void 0&&(this.onHighlightChangeHandler=e.onHighlightChange),e.onSelectionChange!==void 0&&(this.onSelectionChangeHandler=e.onSelectionChange)}async _onNodeClicked(e,n){this.contextMenuVisible&&this.closeContextMenu();const r=n?.ctrl??!1,i=n?.shift??!1;if(Sn.debug(`[highlight] Click on ${e.path}`,{ctrl:r,shift:i,lastAnchor:this.lastHighlightedPath,prevCount:this.highlightedPaths.size}),r){const a=new Set([...this.highlightedPaths]);a.has(e.path)?(a.delete(e.path),e.isHighlighted=!1):(a.add(e.path),e.isHighlighted=!0),e._rev=(e._rev||0)+1,this.highlightedPaths=a,this.lastHighlightedPath=e.path}else if(i&&this.lastHighlightedPath){const a=this._getNodesBetween(this.lastHighlightedPath,e.path);this._clearAllHighlightFlags();const o=new Set;for(const l of a){o.add(l);const c=this.tree.getNodeByPath(l);c&&(c.isHighlighted=!0,c._rev=(c._rev||0)+1)}this.highlightedPaths=o}else{this._clearAllHighlightFlags(),e.isHighlighted=!0,e._rev=(e._rev||0)+1;const a=new Set;a.add(e.path),this.highlightedPaths=a,this.lastHighlightedPath=e.path}this._setFocusedNode(e),this.onNodeClickHandler?.(e),this._notifyHighlightChanged(),this.tree.refresh(),this.containerElement?.focus()}_getDescendantPaths(e){const n=[],r=i=>{for(const a of Object.values(i.children))n.push(a.path),r(a)};return r(e),n}_onCheckboxToggle(e){const n=this.checkboxMode==="cascade"&&e.visualState===nr.indeterminate?!0:!e.isSelected,r=this.highlightedPaths.size>1&&this.highlightedPaths.has(e.path);let i=[];if(r?i=[...this.highlightedPaths]:i=[e.path],this.checkboxMode==="cascade"){const l=new Set(i);for(const c of i){const d=this.tree.getNodeByPath(c);if(d)for(const h of this._getDescendantPaths(d))l.add(h)}i=[...l]}if(this.beforeCheckboxToggleHandler){const l=this.beforeCheckboxToggleHandler(e,n,i);if(l===!1)return;Array.isArray(l)&&(i=l)}const a=new Set([...this.selectedPaths]);for(const l of i){const c=this.tree.getNodeByPath(l);c&&(n?(a.add(l),c.isSelected=!0):(a.delete(l),c.isSelected=!1),c._rev=(c._rev||0)+1)}this.selectedPaths=a,this._setFocusedNode(e);const o=r?[...this.highlightedPaths]:[e.path];for(const l of o){const c=this.tree.getNodeByPath(l);if(c){if(this.checkboxMode==="cascade"){const d=this._computeVisualState(c);c.visualState!==d&&(c.visualState=d,c._rev=(c._rev||0)+1)}this._updateAncestorVisualStates(l)}}this.onNodeClickHandler?.(e),this._notifySelectionChanged(),this.tree.refresh(),this.containerElement?.focus()}_updateAncestorVisualStates(e){const n=new Set([...this.selectedPaths]);let r=this.tree.getNodeByPath(e)?.parentPath;for(;r;){const i=this.tree.getNodeByPath(r);if(!i)break;const a=this._computeVisualState(i),o=a===nr.selected;i.isSelected!==o&&(i.isSelected=o,o?n.add(r):n.delete(r)),i.visualState!==a&&(i.visualState=a),i._rev=(i._rev||0)+1,r=i.parentPath}this.selectedPaths=n}_computeVisualState(e){const n=Object.values(e.children);if(n.length===0)return e.isSelected?nr.selected:nr.notSelected;let r=!0,i=!0;const a=o=>{if(!(!r&&!i)){o.isSelected?i=!1:r=!1;for(const l of Object.values(o.children)){if(!r&&!i)return;a(l)}}};for(const o of n)if(a(o),!r&&!i)break;return r?nr.selected:i?nr.notSelected:nr.indeterminate}_setFocusedNode(e){this.focusedNode&&this.focusedNode.path!==e?.path&&(this.focusedNode.isFocused=!1,this.focusedNode._rev=(this.focusedNode._rev||0)+1),e&&(e.isFocused=!0,e._rev=(e._rev||0)+1),this.focusedNode=e}_clearAllHighlightFlags(){for(const e of this.highlightedPaths){const n=this.tree.getNodeByPath(e);n&&(n.isHighlighted=!1,n._rev=(n._rev||0)+1)}}_clearAllSelectionFlags(){for(const e of this.selectedPaths){const n=this.tree.getNodeByPath(e);n&&(n.isSelected=!1,n._rev=(n._rev||0)+1)}}_notifyHighlightChanged(){if(this.onHighlightChangeHandler){const e=this.getHighlightedNodes();this.onHighlightChangeHandler(this.highlightedPaths,e)}}_notifySelectionChanged(){if(this.onSelectionChangeHandler){const e=this.getSelectedNodes();this.onSelectionChangeHandler(this.selectedPaths,e)}}_getNodesBetween(e,n){return Sn.debug(`[multi-select] _getNodesBetween: ${e} → ${n}, mode=${this.rangeSelectionMode}`),this.rangeSelectionMode==="logical"?this._getAllNodesBetween(e,n):this._getVisibleNodesBetween(e,n)}_getVisibleNodesBetween(e,n){const r=this.tree.visibleFlatNodes;let i=-1,a=-1;for(let d=0;d<r.length&&(r[d].path===e&&(i=d),r[d].path===n&&(a=d),!(i!==-1&&a!==-1));d++);if(Sn.debug(`[multi-select] _getVisibleNodesBetween: indexA=${i}, indexB=${a}, totalVisible=${r.length}`),i===-1||a===-1)return Sn.debug(`[multi-select] _getVisibleNodesBetween: path not found in visible nodes, falling back to [${n}]`),[n];const o=Math.min(i,a),l=Math.max(i,a),c=r.slice(o,l+1).map(d=>d.path);return Sn.debug(`[multi-select] _getVisibleNodesBetween: selected ${c.length} visible nodes [${o}..${l}]`),c}_getAllNodesBetween(e,n){const r=[],i=h=>{h.path&&r.push(h.path);for(const p of Object.values(h.children))i(p)};for(const h of this.tree.tree)i(h);let a=-1,o=-1;for(let h=0;h<r.length&&(r[h]===e&&(a=h),r[h]===n&&(o=h),!(a!==-1&&o!==-1));h++);if(Sn.debug(`[multi-select] _getAllNodesBetween: indexA=${a}, indexB=${o}, totalNodes=${r.length}`),a===-1||o===-1)return Sn.debug(`[multi-select] _getAllNodesBetween: path not found in tree, falling back to [${n}]`),[n];const l=Math.min(a,o),c=Math.max(a,o),d=r.slice(l,c+1);return Sn.debug(`[multi-select] _getAllNodesBetween: selected ${d.length} nodes [${l}..${c}]`),d}highlightNode(e,n="replace"){const r=this.tree.getNodeByPath(e);r&&(n==="toggle"?this._onNodeClicked(r,{ctrl:!0,shift:!1}):n==="range"?this._onNodeClicked(r,{ctrl:!1,shift:!0}):this._onNodeClicked(r))}highlightNodes(e){this._clearAllHighlightFlags();const n=new Set;let r=null;for(const i of e){const a=this.tree.getNodeByPath(i);a&&(a.isHighlighted=!0,a._rev=(a._rev||0)+1,n.add(i),r=a)}this.highlightedPaths=n,r&&(this._setFocusedNode(r),this.lastHighlightedPath=r.path),this._notifyHighlightChanged(),this.tree.refresh()}clearHighlight(){this._clearAllHighlightFlags(),this.highlightedPaths=new Set,this.lastHighlightedPath=null,this._notifyHighlightChanged(),this.tree.refresh()}getHighlightedNodes(){const e=[];for(const n of this.highlightedPaths){const r=this.tree.getNodeByPath(n);r&&e.push(r)}return e}isNodeHighlighted(e){return this.highlightedPaths.has(e)}getSelectedNodes(){const e=[];for(const n of this.selectedPaths){const r=this.tree.getNodeByPath(n);r&&e.push(r)}return e}isNodeSelected(e){return this.selectedPaths.has(e)}deselectAll(){this._clearAllSelectionFlags(),this.selectedPaths=new Set,this._notifySelectionChanged(),this.tree.refresh()}selectNode(e,n="replace"){this.highlightNode(e,n)}selectNodes(e){this.highlightNodes(e)}_onNodeRightClicked(e,n){!this.hasContextMenuSnippet&&!this.getContextMenuItemsHandler||(this.highlightedPaths.has(e.path)||(this._clearAllHighlightFlags(),e.isHighlighted=!0,e._rev=(e._rev||0)+1,this.highlightedPaths=new Set([e.path]),this._setFocusedNode(e),this.lastHighlightedPath=e.path,this._notifyHighlightChanged(),this.tree.refresh()),Sn.debug(`Context menu opened: ${e.path}`),n.preventDefault(),this.openContextMenu(e,n.clientX,n.clientY))}isDropAllowedByMode(e){if(this.dragDropMode==="none")return!1;const n=e===this.treeId;return!(this.dragDropMode==="self"&&!n||this.dragDropMode==="cross"&&n)}calculateDropPosition(e,n){const r=n.getBoundingClientRect(),i=e.clientY-r.top,a=r.height;return i<a*.25?"before":i>a*.75?"after":"child"}_onNodeDragStart(e,n){Wt.debug(`Drag started: ${e.path}`,{ctrlKey:n.ctrlKey,allowCopy:this.allowCopy,treeId:this.treeId}),this.draggedNode=e,this.isDragInProgress=!0,this.onNodeDragStartHandler?.(e,n)}_onNodeDragEnd=e=>{Wt.debug("Drag ended",{dropEffect:e.dataTransfer?.dropEffect,operation:this.currentDropOperation}),this._resetDragState()};_resetDragState(){Wt.debug("_resetDragState"),this.isDragInProgress=!1,this.draggedNode=null,this.hoveredNodeForDrop=null,this.activeDropPosition=null,this.isDropPlaceholderActive=!1,this.currentDropOperation="move",this.floatingZoneRect=null,this.floatingHoveredZone=null}async _handleDrop(e,n,r,i){let a="move";const o=i instanceof DragEvent,l=o?i.ctrlKey:!1;if(this.allowCopy&&o&&l&&(a="copy"),Wt.info(`Drop: ${n.path} -> ${e?.path??"empty tree"}`,{position:r,operation:a,isCrossTree:n.treeId!==this.treeId}),this.beforeDropHandler){const d=await this.beforeDropHandler(e,n,r,i,a);if(d===!1)return!1;d&&typeof d=="object"&&("position"in d&&d.position&&(r=d.position),"operation"in d&&d.operation&&(a=d.operation))}const c=n.treeId===this.treeId;if(c&&a==="move"&&e){if(this.autoHandleMove){const d=this.moveNode(n.path,e.path,r);return this.onNodeDropHandler?.(e,n,r,i,a),d.success}return this.onNodeDropHandler?.(e,n,r,i,a),!0}if(c&&a==="copy"&&e&&this.autoHandleCopy){const d=r==="child"?e.path:e.parentPath||"",h=r!=="child"?e.path:void 0,p=r!=="child"?r:void 0,m=this.tree.copyNodeWithDescendants(n,d,k=>({...k,[this.tree.idMember||"id"]:`${k[this.tree.idMember||"id"]}_copy_${Date.now()}`}),h,p);return this.onNodeDropHandler?.(e,n,r,i,a),m.success}return this.onNodeDropHandler?.(e,n,r,i,a),!0}_onNodeDragOver(e,n){let r=this.draggedNode,i=!1;if(!r&&n.dataTransfer?.types.includes("application/svelte-treeview")){i=!0;try{const l=n.dataTransfer.getData("application/svelte-treeview");l&&(r=JSON.parse(l))}catch{}this.isDragInProgress=!0}if(!(i?this.dragDropMode==="both"||this.dragDropMode==="cross":this.isDropAllowedByMode(r?.treeId))){this.hoveredNodeForDrop=null;return}if(r?i||r.path!==e.path:this.isDragInProgress){n.preventDefault(),this.hoveredNodeForDrop=e;const l=n.target.closest(".ltree-node-content");if(l&&(this.activeDropPosition=this.calculateDropPosition(n,l)),this.currentDropOperation=this.allowCopy&&n.ctrlKey?"copy":"move",this.onNodeDragOverHandler?.(e,n),n.dataTransfer&&(n.dataTransfer.dropEffect=this.currentDropOperation),this.dropZoneMode==="floating"){const c=n.target.closest(".ltree-node-row");if(c){const d=c.getBoundingClientRect();this.floatingZoneRect={top:d.top,left:d.left,width:d.width,height:d.height}}}}}_onNodeDragLeave(e,n){}_onNodeDrop(e,n){n.preventDefault();let r=!1;if(!this.draggedNode){const a=n.dataTransfer?.getData("application/svelte-treeview");a&&(this.draggedNode=JSON.parse(a),r=this.draggedNode?.treeId!==this.treeId)}if(!(r?this.dragDropMode==="both"||this.dragDropMode==="cross":this.isDropAllowedByMode(this.draggedNode?.treeId))){this._onNodeDragEnd(n);return}if(this.draggedNode&&(r||this.draggedNode!==e)){const a=this.activeDropPosition||"child";this._handleDrop(e,this.draggedNode,a,n)}this._onNodeDragEnd(n)}_onZoneDrop(e,n,r){r.preventDefault();let i=!1;if(!this.draggedNode){const o=r.dataTransfer?.getData("application/svelte-treeview");o&&(this.draggedNode=JSON.parse(o),i=this.draggedNode?.treeId!==this.treeId)}if(!this.draggedNode){this._onNodeDragEnd(r);return}if(!(i?this.dragDropMode==="both"||this.dragDropMode==="cross":this.isDropAllowedByMode(this.draggedNode?.treeId))){this._onNodeDragEnd(r);return}(i||this.draggedNode!==e)&&this._handleDrop(e,this.draggedNode,n,r),this._onNodeDragEnd(r)}isFloatingPositionAllowed(e){if(!this.hoveredNodeForDrop)return!1;const n=this.tree.getNodeAllowedDropPositions(this.hoveredNodeForDrop);return!n||n.length===0?!0:n.includes(e)}handleFloatingZoneDragOver(e,n){n.preventDefault(),n.dataTransfer&&(n.dataTransfer.dropEffect=this.allowCopy&&n.ctrlKey?"copy":"move"),this.floatingHoveredZone=e,this.hoveredNodeForDrop&&this._onNodeDragOver(this.hoveredNodeForDrop,n)}handleFloatingZoneDragLeave(){this.floatingHoveredZone=null}handleFloatingZoneDrop(e,n){this.floatingHoveredZone=null,this.hoveredNodeForDrop&&this._onZoneDrop(this.hoveredNodeForDrop,e,n)}_onTouchStart(e,n){if(!this.getNodeIsDraggable(e))return;const r=n.touches[0];this.touchDragState={node:e,startX:r.clientX,startY:r.clientY,isDragging:!1,ghostElement:null,currentDropTarget:null},this._addDocumentTouchListeners(),this.touchTimer=setTimeout(()=>{this.touchDragState.isDragging=!0,this.draggedNode=e,this.isDragInProgress=!0,Wt.debug(`Touch drag started: ${e.path}`),this.createGhostElement(e,r.clientX,r.clientY);try{navigator.vibrate?.(50)}catch{}},300)}_onTouchMove(e,n){}_onTouchEnd(e,n){}_boundDocTouchMove=null;_boundDocTouchEnd=null;_addDocumentTouchListeners(){this._removeDocumentTouchListeners(),this._boundDocTouchMove=e=>this._docTouchMove(e),this._boundDocTouchEnd=e=>this._docTouchEnd(e),document.addEventListener("touchmove",this._boundDocTouchMove,{passive:!1}),document.addEventListener("touchend",this._boundDocTouchEnd),document.addEventListener("touchcancel",this._boundDocTouchEnd)}_removeDocumentTouchListeners(){this._boundDocTouchMove&&(document.removeEventListener("touchmove",this._boundDocTouchMove),this._boundDocTouchMove=null),this._boundDocTouchEnd&&(document.removeEventListener("touchend",this._boundDocTouchEnd),document.removeEventListener("touchcancel",this._boundDocTouchEnd),this._boundDocTouchEnd=null)}_docTouchMove(e){if(!this.touchDragState.node)return;const n=e.touches[0];if(!this.touchDragState.isDragging){const i=Math.abs(n.clientX-this.touchDragState.startX),a=Math.abs(n.clientY-this.touchDragState.startY);(i>10||a>10)&&(this.touchTimer&&clearTimeout(this.touchTimer),this._resetTouchState());return}e.preventDefault(),this.touchDragState.ghostElement&&(this.touchDragState.ghostElement.style.left=`${n.clientX}px`,this.touchDragState.ghostElement.style.top=`${n.clientY}px`),this.touchDragState.ghostElement&&(this.touchDragState.ghostElement.style.pointerEvents="none");const r=document.elementFromPoint(n.clientX,n.clientY);this.touchDragState.ghostElement&&(this.touchDragState.ghostElement.style.pointerEvents=""),this.updateDropTarget(r)}_docTouchEnd(e){if(this.touchTimer&&clearTimeout(this.touchTimer),this.touchDragState.isDragging&&this.draggedNode){const n=e.changedTouches[0];this.touchDragState.ghostElement&&(this.touchDragState.ghostElement.style.display="none");const r=document.elementFromPoint(n.clientX,n.clientY),i=this.findNodeFromElement(r),a=r?.closest(".ltree-empty-state"),o=r?.closest(".ltree-root-drop-zone");(a||o)&&!i?(Wt.debug(`Touch drag ended: ${this.draggedNode.path} -> empty tree`),this._handleDrop(null,this.draggedNode,"child",e)):i&&i!==this.draggedNode&&i.isDropAllowed?(Wt.debug(`Touch drag ended: ${this.draggedNode.path} -> ${i.path}`),this._handleDrop(i,this.draggedNode,"child",e)):Wt.debug(`Touch drag cancelled: ${this.draggedNode.path}`),this.removeGhostElement(),this.clearDropTargetHighlight()}this._resetTouchState()}_resetTouchState(){this._removeDocumentTouchListeners(),this.touchDragState={node:null,startX:0,startY:0,isDragging:!1,ghostElement:null,currentDropTarget:null},this.draggedNode=null,this.isDragInProgress=!1,this.isDropPlaceholderActive=!1}createGhostElement(e,n,r){this.removeGhostElement(),document.querySelectorAll(".ltree-touch-ghost").forEach(a=>a.remove());const i=document.createElement("div");i.className="ltree-touch-ghost",i.textContent=this.tree.getNodeDisplayValue(e),i.style.left=`${n}px`,i.style.top=`${r}px`,document.body.appendChild(i),this.touchDragState.ghostElement=i}removeGhostElement(){this.touchDragState.ghostElement&&(this.touchDragState.ghostElement.remove(),this.touchDragState.ghostElement=null)}destroy(){typeof document>"u"||(this._removeDocumentTouchListeners(),this.removeGhostElement(),document.querySelectorAll(".ltree-touch-ghost").forEach(e=>e.remove()))}findNodeFromElement(e){if(!e)return null;const n=e.closest(".ltree-node");if(!n)return null;const r=n.getAttribute("data-tree-path");return r?this.tree.getNodeByPath(r):null}updateDropTarget(e){const n=this.findNodeFromElement(e);if(this.touchDragState.currentDropTarget&&this.touchDragState.currentDropTarget!==n&&document.querySelector(`[data-tree-path="${this.touchDragState.currentDropTarget.path}"] .ltree-node-content`)?.classList.remove(this.dragOverNodeClass||"ltree-dragover-highlight"),e?.closest(".ltree-empty-state")&&!n){this.isDropPlaceholderActive=!0,this.touchDragState.currentDropTarget=null;return}else this.isDropPlaceholderActive=!1;n&&n!==this.draggedNode&&n.isDropAllowed?(document.querySelector(`[data-tree-path="${n.path}"] .ltree-node-content`)?.classList.add(this.dragOverNodeClass||"ltree-dragover-highlight"),this.touchDragState.currentDropTarget=n):this.touchDragState.currentDropTarget=null}clearDropTargetHighlight(){this.touchDragState.currentDropTarget&&document.querySelector(`[data-tree-path="${this.touchDragState.currentDropTarget.path}"] .ltree-node-content`)?.classList.remove(this.dragOverNodeClass||"ltree-dragover-highlight")}handleEmptyTreeDragOver=e=>{this.dragDropMode!=="none"&&e.dataTransfer?.types.includes("application/svelte-treeview")&&(e.preventDefault(),this.isDropPlaceholderActive=!0,e.dataTransfer&&(e.dataTransfer.dropEffect="move"))};handleEmptyTreeDragLeave=e=>{const n=e.currentTarget.getBoundingClientRect(),r=e.clientX,i=e.clientY;(r<n.left||r>=n.right||i<n.top||i>=n.bottom)&&(this.isDropPlaceholderActive=!1)};handleEmptyTreeDrop=e=>{if(e.preventDefault(),this.isDropPlaceholderActive=!1,this.dragDropMode==="none")return;const n=e.dataTransfer?.getData("application/svelte-treeview");if(n){const r=JSON.parse(n);this._handleDrop(null,r,"child",e)}this._onNodeDragEnd(e)};handleEmptyTreeTouchEnd=e=>{this.dragDropMode!=="none"&&this.draggedNode&&this.isDropPlaceholderActive&&(this._handleDrop(null,this.draggedNode,"child",e),this.isDropPlaceholderActive=!1)};handleTreeDragEnter=e=>{e.dataTransfer?.types.includes("application/svelte-treeview")&&(this.isDragInProgress=!0)};handleTreeDragLeave=e=>{const n=e.currentTarget.getBoundingClientRect(),r=e.clientX,i=e.clientY;(r<n.left||r>=n.right||i<n.top||i>=n.bottom)&&this.draggedNode?.treeId!==this.treeId&&(this.isDragInProgress=!1,this.hoveredNodeForDrop=null,this.activeDropPosition=null)};scheduleFlatRenderBatch(){this.flatRenderAnimationFrame||(this.flatRenderAnimationFrame=requestAnimationFrame(()=>{if(this.flatRenderAnimationFrame=null,this.flatRenderQueue.length===0)return;const e=this.currentBatchSize||this.initialBatchSize,n=this.flatRenderQueue.slice(0,e),r=this.flatRenderQueue.slice(e);this.flatRenderedIds=new Set([...this.flatRenderedIds,...n]),this.flatRenderQueue=r,this.currentBatchSize=Math.min(e*2,this.maxBatchSize),r.length>0&&this.scheduleFlatRenderBatch()}))}generateTreeId(){return`${Date.now()}${Math.floor(Math.random()*1e4)}`}navTo(e){this.navigation.navTo(e)}navNextSibling(){this.navigation.navNextSibling()}navPrevSibling(){this.navigation.navPrevSibling()}navInto(){this.navigation.navInto()}navOut(){this.navigation.navOut()}navBackOut(){this.navigation.navBackOut()}navToggle(){this.navigation.navToggle()}navFirst(){this.navigation.navFirst()}navLast(){this.navigation.navLast()}navPageDown(){this.navigation.navPageDown()}navPageUp(){this.navigation.navPageUp()}navHighlightNext(){this.navigation.navHighlightNext()}navHighlightPrev(){this.navigation.navHighlightPrev()}navHighlightFirst(){this.navigation.navHighlightFirst()}navHighlightLast(){this.navigation.navHighlightLast()}navHighlightPageDown(){this.navigation.navHighlightPageDown()}navHighlightPageUp(){this.navigation.navHighlightPageUp()}createDefaultNavigation(){return{navTo:e=>{this.getNodeByPath(e)&&(this.selectNode(e,"replace"),this.scrollToPath(e,{expand:!1,highlight:!1,containerScroll:!0}))},navNextSibling:()=>{const e=this.allFlatNodes;if(e.length===0)return;const n=this.focusedNode?.path,r=n?e.findIndex(a=>a.path===n):-1;if(r===-1){this.navigation.navTo(e[0].path);return}const i=e[r].level;for(let a=r+1;a<e.length;a++)if(e[a].level===i){this.navigation.navTo(e[a].path);return}},navPrevSibling:()=>{const e=this.allFlatNodes;if(e.length===0)return;const n=this.focusedNode?.path,r=n?e.findIndex(a=>a.path===n):-1;if(r===-1){this.navigation.navTo(e[e.length-1].path);return}const i=e[r].level;for(let a=r-1;a>=0;a--)if(e[a].level===i){this.navigation.navTo(e[a].path);return}},navInto:()=>{const e=this.focusedNode?.path;if(!e)return;const n=this.getNodeByPath(e);if(!n)return;const r=this.allFlatNodes,i=r.findIndex(a=>a.path===e);if(n.hasChildren&&!n.isExpanded&&n.isCollapsible!==!1)this.expandNodes(e),mn().then(()=>{const a=this.allFlatNodes,o=a.findIndex(l=>l.path===e);o>=0&&o+1<a.length&&this.navigation.navTo(a[o+1].path)});else if(n.hasChildren&&n.isExpanded){const a=i+1;a<r.length&&this.navigation.navTo(r[a].path)}},navOut:()=>{const e=this.focusedNode?.path;if(!e)return;const n=this.getNodeByPath(e);n?.parentPath&&this.navigation.navTo(n.parentPath)},navBackOut:()=>{const e=this.focusedNode?.path;if(!e)return;const n=this.getNodeByPath(e);if(!n?.parentPath)return;const r=this.getNodeByPath(n.parentPath);r&&(r.hasChildren&&r.isExpanded&&r.isCollapsible!==!1&&(this.collapseNodes(r.path),r._rev=(r._rev||0)+1),mn().then(()=>{this.navigation.navTo(r.path)}))},navToggle:()=>{const e=this.focusedNode?.path;if(!e)return;const n=this.getNodeByPath(e);!n?.hasChildren||n.isCollapsible===!1||(n.isExpanded?this.collapseNodes(e):this.expandNodes(e))},navFirst:()=>{const e=this.allFlatNodes;e.length>0&&this.navigation.navTo(e[0].path)},navLast:()=>{const e=this.allFlatNodes;e.length>0&&this.navigation.navTo(e[e.length-1].path)},navPageDown:()=>{const e=this.allFlatNodes;if(e.length===0)return;const n=this.focusedNode?.path,r=n?e.findIndex(a=>a.path===n):-1,i=Math.min((r===-1?0:r)+10,e.length-1);this.navigation.navTo(e[i].path)},navPageUp:()=>{const e=this.allFlatNodes;if(e.length===0)return;const n=this.focusedNode?.path,r=n?e.findIndex(a=>a.path===n):e.length,i=Math.max((r===-1?e.length:r)-10,0);this.navigation.navTo(e[i].path)},navHighlightNext:()=>{const e=this.allFlatNodes;if(e.length===0)return;const n=this.focusedNode?.path,r=n?e.findIndex(a=>a.path===n):-1;if(r===-1)return;const i=e[r].level;for(let a=r+1;a<e.length;a++)if(e[a].level===i){this._navHighlightTo(e[a].path);return}},navHighlightPrev:()=>{const e=this.allFlatNodes;if(e.length===0)return;const n=this.focusedNode?.path,r=n?e.findIndex(a=>a.path===n):-1;if(r===-1)return;const i=e[r].level;for(let a=r-1;a>=0;a--)if(e[a].level===i){this._navHighlightTo(e[a].path);return}},navHighlightFirst:()=>{const e=this.allFlatNodes;e.length>0&&this._navHighlightTo(e[0].path)},navHighlightLast:()=>{const e=this.allFlatNodes;e.length>0&&this._navHighlightTo(e[e.length-1].path)},navHighlightPageDown:()=>{const e=this.allFlatNodes;if(e.length===0)return;const n=this.focusedNode?.path,r=n?e.findIndex(a=>a.path===n):-1;if(r===-1)return;const i=Math.min(r+10,e.length-1);this._navHighlightTo(e[i].path)},navHighlightPageUp:()=>{const e=this.allFlatNodes;if(e.length===0)return;const n=this.focusedNode?.path,r=n?e.findIndex(a=>a.path===n):-1;if(r===-1)return;const i=Math.max(r-10,0);this._navHighlightTo(e[i].path)}}}_navHighlightTo(e){if(!this.lastHighlightedPath&&this.focusedNode){this.lastHighlightedPath=this.focusedNode.path;const r=this.focusedNode;r.isHighlighted||(r.isHighlighted=!0,r._rev=(r._rev||0)+1,this.highlightedPaths=new Set([r.path]))}this.highlightNode(e,"range");const n=this.tree.getNodeByPath(e);n&&this._setFocusedNode(n),this.scrollToPath(e,{expand:!1,highlight:!1,containerScroll:!0}),this.tree.refresh()}findScrollableAncestor(e){let n=e.parentElement;for(;n;){const i=getComputedStyle(n).overflowY;if((i==="auto"||i==="scroll")&&n.scrollHeight>n.clientHeight)return n;n=n.parentElement}return null}}function jh(t){return new Bh(t)}var Vh=D("<span> </span>"),Kh=D("<span> </span>"),$h=D('<div class="ltree-debug-info"><details><summary>Debug Info</summary> <div class="ltree-debug-stats"><span> </span> <span> </span> <span> </span> <span> </span> <span> </span> <!> <!> <span> </span></div></details></div>'),Zh=D('<div class="ltree-loading-spinner"></div>'),Uh=D('<div class="ltree-loading-overlay"><!></div>'),Wh=D('<div class="ltree-drop-placeholder-content">Drop here to add</div>'),Gh=D("<div><!></div>"),Yh=D('<div class="ltree-tree ltree-flat-mode ltree-virtual-scroll"><div><div></div></div></div>'),Xh=D('<div class="ltree-drop-placeholder-content">Drop here to add</div>'),Jh=D("<div><!></div>"),Qh=D('<div class="ltree-tree ltree-flat-mode"></div>'),qh=D('<div class="ltree-drop-placeholder-content">Drop here to add</div>'),eu=D("<div><!></div>"),tu=D('<div class="ltree-tree"></div>'),nu=D('<div class="ltree-drop-placeholder-content">Drop here to add</div>'),ru=D("<div><!></div>"),iu=D("<div>↑ Before</div>"),su=D("<div>↓ After</div>"),au=D("<div>→ Child</div>"),ou=D("<div><!> <!> <!></div>"),lu=D('<span class="ltree-context-menu-divider-label"> </span>'),cu=D('<div class="ltree-context-menu-divider" role="separator"><!></div>'),du=D('<span class="ltree-context-menu-icon"> </span>'),hu=D('<span class="ltree-context-menu-shortcut"> </span>'),uu=D('<span class="ltree-context-menu-arrow">&#x25B8;</span> <div class="ltree-context-submenu" role="menu"><!></div>',1),fu=D('<div role="menuitem"><!> <span class="ltree-context-menu-label"> </span> <!> <!></div>'),gu=D('<div class="ltree-context-menu" role="menu"><!></div>'),vu=D('<div class="ltree-container" tabindex="0"><!> <!> <!> <div><!></div> <!> <!> <!></div>');function pu(t,e){Nn(e,!0);let n=K(e,"treeId",7),r=K(e,"treePathSeparator",7,"."),i=K(e,"idMember",7),a=K(e,"pathMember",7),o=K(e,"parentPathMember",7),l=K(e,"levelMember",7),c=K(e,"hasChildrenMember",7),d=K(e,"isExpandedMember",7),h=K(e,"isSelectableMember",7),p=K(e,"isSelectedMember",7),m=K(e,"isDraggableMember",7),k=K(e,"getIsDraggableCallback",7),C=K(e,"isDropAllowedMember",7),_=K(e,"isCollapsibleMember",7),v=K(e,"getIsCollapsibleCallback",7),P=K(e,"displayValueMember",7),E=K(e,"getDisplayValueCallback",7),B=K(e,"searchValueMember",7),V=K(e,"getSearchValueCallback",7),Z=K(e,"orderMember",7),j=K(e,"isSorted",7),ae=K(e,"sortCallback",7),ce=K(e,"data",15),de=K(e,"focusedNode",15),W=K(e,"highlightedPaths",31,()=>$t(new Set)),N=K(e,"selectedPaths",31,()=>$t(new Set)),G=K(e,"insertResult",15),O=K(e,"nodeTemplate",3,void 0),X=K(e,"treeHeader",3,void 0),ue=K(e,"treeFooter",3,void 0),fe=K(e,"noDataFound",3,void 0),Se=K(e,"contextMenu",3,void 0),se=K(e,"dropPlaceholder",3,void 0),he=K(e,"loadingPlaceholder",3,void 0),xe=K(e,"expandLevel",7,2),Ce=K(e,"clickBehavior",7,"expand-and-focus"),nt=K(e,"showCheckboxes",7,!1),ke=K(e,"checkboxMode",7,"independent"),U=K(e,"beforeCheckboxToggleCallback",7),me=K(e,"rangeSelectionMode",7,"visual"),ve=K(e,"shouldUseInternalSearchIndex",7,!0),Ze=K(e,"initializeIndexCallback",7),Le=K(e,"searchText",15),Be=K(e,"indexerBatchSize",7,25),Ge=K(e,"indexerTimeout",7,50),Je=K(e,"shouldDisplayDebugInformation",7,!1),Ke=K(e,"shouldDisplayContextMenuInDebugMode",7,!1),yt=K(e,"isLoading",3,!1),ut=K(e,"progressiveRender",3,!0),tt=K(e,"initialBatchSize",3,20),Fe=K(e,"maxBatchSize",3,500),qe=K(e,"isRendering",15,!1),lt=K(e,"useFlatRendering",3,!0),L=K(e,"virtualScroll",7,!1),ne=K(e,"virtualRowHeight",7,void 0),H=K(e,"virtualOverscan",7,5),T=K(e,"virtualContainerHeight",7,void 0),R=K(e,"dragDropMode",7,"none"),J=K(e,"dropZoneMode",7,"glow"),Q=K(e,"dropZoneLayout",3,"around"),Pe=K(e,"dropZoneStart",3,33),Ie=K(e,"dropZoneMaxWidth",3,120),pe=K(e,"allowCopy",3,!1),ye=K(e,"autoHandleCopy",3,!0),M=K(e,"autoHandleMove",3,!0),re=K(e,"autoHandlePaste",3,!0),oe=K(e,"accordionExpand",7,!1),Te=K(e,"onNodeClick",7),we=K(e,"onHighlightChange",7),He=K(e,"onSelectionChange",7),Qe=K(e,"onNodeDragStart",7),$=K(e,"onNodeDragOver",7),Y=K(e,"onNodeDrop",7),ge=K(e,"beforeDropCallback",7),Me=K(e,"beforeCopyCallback",7),Ye=K(e,"beforeCutCallback",7),_e=K(e,"beforePasteCallback",7),Oe=K(e,"getContextMenuItemsCallback",7),Xe=K(e,"bodyClass",7),it=K(e,"expandIconClass",7,"ltree-icon-expand"),Ve=K(e,"collapseIconClass",7,"ltree-icon-collapse"),I=K(e,"leafIconClass",7,"ltree-icon-leaf"),w=K(e,"toggleIconMode",7,"rotate"),z=K(e,"highlightedNodeClass",7),ie=K(e,"focusedNodeClass",7),Ee=K(e,"dragOverNodeClass",7),Ae=K(e,"scrollHighlightTimeout",7,4e3),Ne=K(e,"scrollHighlightClass",7,"ltree-scroll-highlight"),$e=K(e,"contextMenuXOffset",7,8),Ue=K(e,"contextMenuYOffset",7,0);const y=jh({idMember:i(),pathMember:a(),parentPathMember:o(),levelMember:l(),hasChildrenMember:c(),isExpandedMember:d(),isSelectableMember:h(),isSelectedMember:p(),isDraggableMember:m(),getIsDraggableCallback:k(),isDropAllowedMember:C(),allowedDropPositionsMember:e.allowedDropPositionsMember,getAllowedDropPositionsCallback:e.getAllowedDropPositionsCallback,isCollapsibleMember:_(),getIsCollapsibleCallback:v(),displayValueMember:P(),getDisplayValueCallback:E(),searchValueMember:B(),getSearchValueCallback:V(),orderMember:Z(),isSorted:j(),sortCallback:ae(),treeId:n(),treePathSeparator:r(),data:ce(),focusedNode:de(),highlightedPaths:W(),selectedPaths:N(),expandLevel:xe(),clickBehavior:Ce(),showCheckboxes:nt(),checkboxMode:ke(),beforeCheckboxToggleCallback:U(),rangeSelectionMode:me(),shouldUseInternalSearchIndex:ve(),initializeIndexCallback:Ze(),searchText:Le(),indexerBatchSize:Be(),indexerTimeout:Ge(),shouldDisplayDebugInformation:Je(),shouldDisplayContextMenuInDebugMode:Ke(),isLoading:yt(),progressiveRender:ut(),initialBatchSize:tt(),maxBatchSize:Fe(),onRenderStart:e.onRenderStart,onRenderProgress:e.onRenderProgress,onRenderComplete:e.onRenderComplete,useFlatRendering:lt(),virtualScroll:L(),virtualRowHeight:ne(),virtualOverscan:H(),virtualContainerHeight:T(),dragDropMode:R(),dropZoneMode:J(),dropZoneLayout:Q(),dropZoneStart:Pe(),dropZoneMaxWidth:Ie(),allowCopy:pe(),autoHandleCopy:ye(),autoHandleMove:M(),autoHandlePaste:re(),accordionExpand:oe(),onNodeClick:Te(),onHighlightChange:we(),onSelectionChange:He(),onNodeDragStart:Qe(),onNodeDragOver:$(),onNodeDrop:Y(),beforeDropCallback:ge(),beforeCopyCallback:Me(),beforeCutCallback:Ye(),beforePasteCallback:_e(),getContextMenuItemsCallback:Oe(),hasContextMenuSnippet:!!Se(),bodyClass:Xe(),highlightedNodeClass:z(),focusedNodeClass:ie(),dragOverNodeClass:Ee(),expandIconClass:it(),collapseIconClass:Ve(),leafIconClass:I(),toggleIconMode:w(),scrollHighlightTimeout:Ae(),scrollHighlightClass:Ne(),contextMenuXOffset:$e(),contextMenuYOffset:Ue()});e.navigationOverrides&&(y.navigation={...y.createDefaultNavigation(),...e.navigationOverrides}),ci("Ltree",y.tree),ci("NodeCallbacks",y.nodeCallbacks),ci("NodeConfig",y.nodeConfig),y.renderCoordinator&&ci("RenderCoordinator",y.renderCoordinator),ra(()=>y.destroy());let je;De(()=>{je&&(y.containerElement=je)}),De(()=>{y.data=ce()}),De(()=>{y.searchText=Le()}),De(()=>{n()&&(y.treeId=n())}),De(()=>{y.treePathSeparator=r()??"."}),De(()=>{y.shouldDisplayDebugInformation=Je()??!1}),De(()=>{y.shouldDisplayContextMenuInDebugMode=Ke()??!1}),De(()=>{y.isLoading=yt()??!1}),De(()=>{y.bodyClass=Xe()}),De(()=>{y.useFlatRendering=lt()??!0}),De(()=>{y.virtualScroll=L()??!1}),De(()=>{y.virtualRowHeight=ne()}),De(()=>{y.virtualOverscan=H()??5}),De(()=>{y.virtualContainerHeight=T()}),De(()=>{y.progressiveRender=ut()??!0}),De(()=>{y.initialBatchSize=tt()??20}),De(()=>{y.maxBatchSize=Fe()??500}),De(()=>{y.dragDropMode=R()??"none"}),De(()=>{y.allowCopy=pe()??!1}),De(()=>{y.autoHandleCopy=ye()??!0}),De(()=>{y.autoHandleMove=M()??!0}),De(()=>{y.autoHandlePaste=re()??!0}),De(()=>{y.accordionExpand=oe()??!1}),De(()=>{y.hasContextMenuSnippet=!!Se()}),De(()=>{y.clickBehavior=Ce()??"expand-and-focus"}),De(()=>{y.showCheckboxes=nt()??!1}),De(()=>{y.checkboxMode=ke()??"independent"}),De(()=>{y.beforeCheckboxToggleHandler=U()}),De(()=>{y.rangeSelectionMode=me()??"visual"}),De(()=>{y.expandIconClass=it()??"ltree-icon-expand"}),De(()=>{y.collapseIconClass=Ve()??"ltree-icon-collapse"}),De(()=>{y.leafIconClass=I()??"ltree-icon-leaf"}),De(()=>{y.toggleIconMode=w()??"rotate"}),De(()=>{y.highlightedNodeClass=z()}),De(()=>{y.focusedNodeClass=ie()}),De(()=>{y.dragOverNodeClass=Ee()}),De(()=>{y.dropZoneMode=J()??"glow"}),De(()=>{y.dropZoneLayout=Q()??"around"}),De(()=>{y.dropZoneStart=Pe()??33}),De(()=>{y.dropZoneMaxWidth=Ie()??120}),De(()=>{y.scrollHighlightTimeout=Ae()??4e3}),De(()=>{y.scrollHighlightClass=Ne()??"ltree-scroll-highlight"}),De(()=>{y.contextMenuXOffset=$e()??8}),De(()=>{y.contextMenuYOffset=Ue()??0}),De(()=>{y.onNodeClickHandler=Te()}),De(()=>{y.onHighlightChangeHandler=we()}),De(()=>{y.onSelectionChangeHandler=He()}),De(()=>{y.onNodeDragStartHandler=Qe()}),De(()=>{y.onNodeDragOverHandler=$()}),De(()=>{y.onNodeDropHandler=Y()}),De(()=>{y.beforeDropHandler=ge()}),De(()=>{y.beforeCopyHandler=Me()}),De(()=>{y.beforeCutHandler=Ye()}),De(()=>{y.beforePasteHandler=_e()}),De(()=>{y.getContextMenuItemsHandler=Oe()}),De(()=>{y.onRenderStartHandler=e.onRenderStart}),De(()=>{y.onRenderProgressHandler=e.onRenderProgress}),De(()=>{y.onRenderCompleteHandler=e.onRenderComplete}),De(()=>{de(y.focusedNode)}),De(()=>{W(y.highlightedPaths)}),De(()=>{N(y.selectedPaths)}),De(()=>{G(y.insertResult)}),De(()=>{qe(y.isRendering)}),De(()=>{y.focusedNode=de()}),De(()=>{const S=W(),Re=y.highlightedPaths;(S.size!==Re.size||[...S].some(wt=>!Re.has(wt)))&&(y.highlightedPaths=new Set(S))}),De(()=>{const S=N(),Re=y.selectedPaths;(S.size!==Re.size||[...S].some(wt=>!Re.has(wt)))&&(y.selectedPaths=new Set(S))});const St=be(()=>typeof y.dropZoneStart=="number"?`${y.dropZoneStart}%`:y.dropZoneStart);async function te(S){y.expandNodes(S)}async function le(S){y.collapseNodes(S)}function rt(S){y.expandAll(S)}function ft(S){y.collapseAll(S)}function ct(S,Re){y.filterNodes(S,Re)}function dt(S,Re){return y.searchNodes(S,Re)}function Nt(S){return y.getChildren(S)}function Et(S){return y.getSiblings(S)}function Pn(S){y.refreshSiblings(S)}function at(S){y.refreshNode(S)}function At(S){return y.getNodeByPath(S)}function dn(S,Re,wt){return y.moveNode(S,Re,wt)}function Qt(S,Re=!0){return y.removeNode(S,Re)}function hn(S,Re,wt){return y.addNode(S,Re,wt)}function Ft(S,Re){return y.updateNode(S,Re)}function xt(S){return y.applyChanges(S)}function nn(S,Re){return y.insertBranch(S,Re)}function Rt(S,Re){return y.replaceBranch(S,Re)}function bt(S,Re){return y.deleteBranch(S,Re)}function pn(S,Re,wt,Tt,Tn){return y.copyNodeWithDescendants(S,Re,wt,Tt,Tn)}function Xt(){return y.getExpandedPaths()}function bn(S){y.setExpandedPaths(S)}function En(){return y.getAllData()}function Vt(){y.closeContextMenu()}function rn(S,Re="replace"){y.selectNode(S,Re)}function qt(S){y.selectNodes(S)}function sn(){y.deselectAll()}function yn(){return y.getSelectedNodes()}function vn(S){return y.isNodeSelected(S)}async function an(S,Re){return y.scrollToPath(S,Re)}function wn(S){S.treeId!==void 0&&n(S.treeId),S.treePathSeparator!==void 0&&r(S.treePathSeparator),S.idMember!==void 0&&i(S.idMember),S.pathMember!==void 0&&a(S.pathMember),S.parentPathMember!==void 0&&o(S.parentPathMember),S.levelMember!==void 0&&l(S.levelMember),S.hasChildrenMember!==void 0&&c(S.hasChildrenMember),S.isExpandedMember!==void 0&&d(S.isExpandedMember),S.isSelectableMember!==void 0&&h(S.isSelectableMember),S.isSelectedMember!==void 0&&p(S.isSelectedMember),S.isDraggableMember!==void 0&&m(S.isDraggableMember),S.getIsDraggableCallback!==void 0&&k(S.getIsDraggableCallback),S.isDropAllowedMember!==void 0&&C(S.isDropAllowedMember),S.displayValueMember!==void 0&&P(S.displayValueMember),S.getDisplayValueCallback!==void 0&&E(S.getDisplayValueCallback),S.searchValueMember!==void 0&&B(S.searchValueMember),S.getSearchValueCallback!==void 0&&V(S.getSearchValueCallback),S.isCollapsibleMember!==void 0&&_(S.isCollapsibleMember),S.getIsCollapsibleCallback!==void 0&&v(S.getIsCollapsibleCallback),S.orderMember!==void 0&&Z(S.orderMember),S.isSorted!==void 0&&j(S.isSorted),S.sortCallback!==void 0&&ae(S.sortCallback),S.data!==void 0&&ce(S.data),S.focusedNode!==void 0&&de(S.focusedNode),S.highlightedPaths!==void 0&&W(S.highlightedPaths),S.selectedPaths!==void 0&&N(S.selectedPaths),S.expandLevel!==void 0&&xe(S.expandLevel),S.clickBehavior!==void 0&&Ce(S.clickBehavior),S.showCheckboxes!==void 0&&nt(S.showCheckboxes),S.checkboxMode!==void 0&&ke(S.checkboxMode),S.beforeCheckboxToggleCallback!==void 0&&U(S.beforeCheckboxToggleCallback),S.rangeSelectionMode!==void 0&&me(S.rangeSelectionMode),S.shouldUseInternalSearchIndex!==void 0&&ve(S.shouldUseInternalSearchIndex),S.initializeIndexCallback!==void 0&&Ze(S.initializeIndexCallback),S.searchText!==void 0&&Le(S.searchText),S.indexerBatchSize!==void 0&&Be(S.indexerBatchSize),S.indexerTimeout!==void 0&&Ge(S.indexerTimeout),S.shouldDisplayDebugInformation!==void 0&&Je(S.shouldDisplayDebugInformation),S.shouldDisplayContextMenuInDebugMode!==void 0&&Ke(S.shouldDisplayContextMenuInDebugMode),S.onNodeClick!==void 0&&Te(S.onNodeClick),S.onHighlightChange!==void 0&&we(S.onHighlightChange),S.onSelectionChange!==void 0&&He(S.onSelectionChange),S.onNodeDragStart!==void 0&&Qe(S.onNodeDragStart),S.onNodeDragOver!==void 0&&$(S.onNodeDragOver),S.onNodeDrop!==void 0&&Y(S.onNodeDrop),S.beforeDropCallback!==void 0&&ge(S.beforeDropCallback),S.beforeCopyCallback!==void 0&&Me(S.beforeCopyCallback),S.beforeCutCallback!==void 0&&Ye(S.beforeCutCallback),S.beforePasteCallback!==void 0&&_e(S.beforePasteCallback),S.getContextMenuItemsCallback!==void 0&&Oe(S.getContextMenuItemsCallback),S.virtualScroll!==void 0&&L(S.virtualScroll),S.virtualRowHeight!==void 0&&ne(S.virtualRowHeight),S.virtualOverscan!==void 0&&H(S.virtualOverscan),S.virtualContainerHeight!==void 0&&T(S.virtualContainerHeight),S.dragDropMode!==void 0&&R(S.dragDropMode),S.dropZoneMode!==void 0&&J(S.dropZoneMode),S.bodyClass!==void 0&&Xe(S.bodyClass),S.expandIconClass!==void 0&&it(S.expandIconClass),S.collapseIconClass!==void 0&&Ve(S.collapseIconClass),S.leafIconClass!==void 0&&I(S.leafIconClass),S.toggleIconMode!==void 0&&w(S.toggleIconMode),S.highlightedNodeClass!==void 0&&z(S.highlightedNodeClass),S.focusedNodeClass!==void 0&&ie(S.focusedNodeClass),S.dragOverNodeClass!==void 0&&Ee(S.dragOverNodeClass),S.scrollHighlightTimeout!==void 0&&Ae(S.scrollHighlightTimeout),S.scrollHighlightClass!==void 0&&Ne(S.scrollHighlightClass),S.contextMenuXOffset!==void 0&&$e(S.contextMenuXOffset),S.contextMenuYOffset!==void 0&&Ue(S.contextMenuYOffset),S.accordionExpand!==void 0&&oe(S.accordionExpand)}function In(S){if(["Control","Shift","Alt","Meta"].includes(S.key)||y.contextMenuVisible)return;if(e.onTreeKeydown?.(S,y)===!0){S.preventDefault();return}if(y.allFlatNodes.length===0)return;let Re=!0;switch(S.key){case"ArrowDown":S.shiftKey?y.navHighlightNext():y.navNextSibling();break;case"ArrowUp":S.shiftKey?y.navHighlightPrev():y.navPrevSibling();break;case"ArrowRight":y.navInto();break;case"ArrowLeft":y.navOut();break;case"Backspace":y.navBackOut();break;case"Home":S.shiftKey?y.navHighlightFirst():y.navFirst();break;case"End":S.shiftKey?y.navHighlightLast():y.navLast();break;case"PageDown":S.shiftKey?y.navHighlightPageDown():y.navPageDown();break;case"PageUp":S.shiftKey?y.navHighlightPageUp():y.navPageUp();break;case"Enter":case" ":y.navToggle();break;default:Re=!1}Re&&S.preventDefault()}function Vn(S){const Re=S.split("+").map(Tt=>Tt.trim());return{key:Re.pop().toLowerCase(),ctrl:Re.some(Tt=>Tt.toLowerCase()==="ctrl"),shift:Re.some(Tt=>Tt.toLowerCase()==="shift"),alt:Re.some(Tt=>Tt.toLowerCase()==="alt")}}function Kn(S,Re){for(const wt of S)if(!("divider"in wt)&&!(wt.isVisible===!1||wt.isDisabled)){if(wt.shortcut){const Tt=Vn(wt.shortcut);if((Re.key.length===1?Re.key.toLowerCase():Re.key)===Tt.key&&Re.ctrlKey===Tt.ctrl&&Re.shiftKey===Tt.shift&&Re.altKey===Tt.alt)return wt}if(wt.children){const Tt=Kn(wt.children,Re);if(Tt)return Tt}}return null}async function Dt(S){if(!y.contextMenuVisible||!y.contextMenuNode||!Oe())return;if(S.key==="Escape"){y.closeContextMenu();return}const Re=Oe()(y.contextMenuNode,y.closeContextMenu.bind(y),y.getSelectedNodes()),wt=Kn(Re,S);if(wt){S.preventDefault();try{await wt.onclick?.()}catch(Tt){console.error("Context menu shortcut error:",Tt)}}}var Zt={expandNodes:te,collapseNodes:le,expandAll:rt,collapseAll:ft,filterNodes:ct,searchNodes:dt,getChildren:Nt,getSiblings:Et,refreshSiblings:Pn,refreshNode:at,getNodeByPath:At,moveNode:dn,removeNode:Qt,addNode:hn,updateNode:Ft,applyChanges:xt,insertBranch:nn,replaceBranch:Rt,deleteBranch:bt,copyNodeWithDescendants:pn,getExpandedPaths:Xt,setExpandedPaths:bn,getAllData:En,closeContextMenu:Vt,selectNode:rn,selectNodes:qt,deselectAll:sn,getSelectedNodes:yn,isNodeSelected:vn,scrollToPath:an,update:wn},Ut=vu();Ct("keydown",_o,Dt);var mt=g(Ut);{var Pt=S=>{var Re=$h(),wt=g(Re),Tt=b(g(wt),2),Tn=g(Tt),on=g(Tn);f(Tn);var pt=b(Tn,2),Lt=g(pt);f(pt);var Bt=b(pt,2),jt=g(Bt);f(Bt);var It=b(Bt,2),ht=g(It);f(It);var ot=b(It,2),gt=g(ot);f(ot);var vt=b(ot,2);{var An=Kt=>{var tn=Vh(),ln=g(tn);f(tn),ee(()=>F(ln,`Filtered: ${y.tree.statistics.filteredNodeCount??""}`)),x(Kt,tn)};q(vt,Kt=>{y.tree?.statistics.filteredNodeCount>0&&Kt(An)})}var Ht=b(vt,2);{var Ot=Kt=>{var tn=Kh(),ln=g(tn);f(tn),ee(()=>F(ln,`Indexing: ${y.tree.statistics.pendingIndexCount??""} pending`)),x(Kt,tn)};q(Ht,Kt=>{y.tree?.statistics.isIndexing&&Kt(Ot)})}var fn=b(Ht,2),en=g(fn);f(fn),f(Tt),f(wt),f(Re),ee(()=>{F(on,`Tree: ${y.treeId??""}`),F(Lt,`Data: ${(y.data?.length||0)??""}`),F(jt,`Expand level: ${(xe()||0)??""}`),F(ht,`Nodes: ${(y.tree?.statistics.nodeCount||0)??""}`),F(gt,`Levels: ${(y.tree?.statistics.maxLevel||0)??""}`),F(en,`Dragging: ${(y.draggedNode?.path||"none")??""}`)}),x(S,Re)};q(mt,S=>{y.shouldDisplayDebugInformation&&S(Pt)})}var un=b(mt,2);Hn(un,()=>X()??fr);var Ln=b(un,2);{var Sr=S=>{var Re=Uh(),wt=g(Re);{var Tt=on=>{var pt=zt(),Lt=et(pt);Hn(Lt,he),x(on,pt)},Tn=on=>{var pt=Zh();x(on,pt)};q(wt,on=>{he()?on(Tt):on(Tn,-1)})}f(Re),x(S,Re)};q(Ln,S=>{y.isLoading&&S(Sr)})}var sr=b(Ln,2),Oi=g(sr);{var Ea=S=>{var Re=zt(),wt=et(Re);{var Tt=pt=>{var Lt=Yh(),Bt=g(Lt),jt=g(Bt);_t(jt,23,()=>y.flatNodesToRender,It=>It.id+"|"+It.path+"|"+It.hasChildren+"|"+It._rev,(It,ht,ot)=>{const gt=be(()=>y.vsStartIndex+s(ot)),vt=be(()=>s(gt)>0?y.allFlatNodes[s(gt)-1]:null);{let An=be(()=>y.draggedNode?.path===s(ht).path),Ht=be(()=>y.hoveredNodeForDrop?.path),Ot=be(()=>s(vt)!=null&&(s(ht).level??0)>(s(vt).level??0));xi(It,{get node(){return s(ht)},get children(){return O()},progressiveRender:!1,get isDraggedNode(){return s(An)},get isDragInProgress(){return y.isDragInProgress},get hoveredNodeForDropPath(){return s(Ht)},get activeDropPosition(){return y.activeDropPosition},get dropOperation(){return y.currentDropOperation},flatMode:!0,get flatGap(){return s(Ot)}})}},It=>{var ht=Gh();let ot;var gt=g(ht);{var vt=Ht=>{var Ot=zt(),fn=et(Ot);{var en=tn=>{var ln=zt(),$n=et(ln);Hn($n,se),x(tn,ln)},Kt=tn=>{var ln=Wh();x(tn,ln)};q(fn,tn=>{se()?tn(en):tn(Kt,-1)})}x(Ht,Ot)},An=Ht=>{var Ot=zt(),fn=et(Ot);Hn(fn,()=>fe()??fr),x(Ht,Ot)};q(gt,Ht=>{y.isDropPlaceholderActive?Ht(vt):Ht(An,-1)})}f(ht),ee(()=>ot=st(ht,1,"ltree-empty-state",null,ot,{"ltree-drop-placeholder":y.isDropPlaceholderActive})),Ct("dragenter",ht,function(...Ht){y.handleEmptyTreeDragOver?.apply(this,Ht)}),Ct("dragover",ht,function(...Ht){y.handleEmptyTreeDragOver?.apply(this,Ht)}),Ct("dragleave",ht,function(...Ht){y.handleEmptyTreeDragLeave?.apply(this,Ht)}),Ct("drop",ht,function(...Ht){y.handleEmptyTreeDrop?.apply(this,Ht)}),ze("touchend",ht,function(...Ht){y.handleEmptyTreeTouchEnd?.apply(this,Ht)}),x(It,ht)}),f(jt),f(Bt),f(Lt),Qr(Lt,It=>y.vsContainerRef=It,()=>y?.vsContainerRef),ee(()=>{rr(Lt,`height: ${y.vsContainerStyle??""}; overflow-y: auto;`),rr(Bt,`height: ${y.vsTotalHeight??""}px; position: relative;`),rr(jt,`transform: translateY(${y.vsOffsetY??""}px);`)}),Ct("scroll",Lt,function(...It){y.handleVirtualScroll?.apply(this,It)}),x(pt,Lt)},Tn=pt=>{var Lt=Qh();_t(Lt,23,()=>y.flatNodesToRender,Bt=>Bt.id+"|"+Bt.path+"|"+Bt.hasChildren+"|"+Bt._rev,(Bt,jt,It)=>{const ht=be(()=>s(It)>0?y.flatNodesToRender[s(It)-1]:null);{let ot=be(()=>y.draggedNode?.path===s(jt).path),gt=be(()=>y.hoveredNodeForDrop?.path),vt=be(()=>s(ht)!=null&&(s(jt).level??0)>(s(ht).level??0));xi(Bt,{get node(){return s(jt)},get children(){return O()},progressiveRender:!1,get isDraggedNode(){return s(ot)},get isDragInProgress(){return y.isDragInProgress},get hoveredNodeForDropPath(){return s(gt)},get activeDropPosition(){return y.activeDropPosition},get dropOperation(){return y.currentDropOperation},flatMode:!0,get flatGap(){return s(vt)}})}},Bt=>{var jt=Jh();let It;var ht=g(jt);{var ot=vt=>{var An=zt(),Ht=et(An);{var Ot=en=>{var Kt=zt(),tn=et(Kt);Hn(tn,se),x(en,Kt)},fn=en=>{var Kt=Xh();x(en,Kt)};q(Ht,en=>{se()?en(Ot):en(fn,-1)})}x(vt,An)},gt=vt=>{var An=zt(),Ht=et(An);Hn(Ht,()=>fe()??fr),x(vt,An)};q(ht,vt=>{y.isDropPlaceholderActive?vt(ot):vt(gt,-1)})}f(jt),ee(()=>It=st(jt,1,"ltree-empty-state",null,It,{"ltree-drop-placeholder":y.isDropPlaceholderActive})),Ct("dragenter",jt,function(...vt){y.handleEmptyTreeDragOver?.apply(this,vt)}),Ct("dragover",jt,function(...vt){y.handleEmptyTreeDragOver?.apply(this,vt)}),Ct("dragleave",jt,function(...vt){y.handleEmptyTreeDragLeave?.apply(this,vt)}),Ct("drop",jt,function(...vt){y.handleEmptyTreeDrop?.apply(this,vt)}),ze("touchend",jt,function(...vt){y.handleEmptyTreeTouchEnd?.apply(this,vt)}),x(Bt,jt)}),f(Lt),x(pt,Lt)},on=pt=>{var Lt=zt(),Bt=et(Lt);xo(Bt,()=>y.tree.changeTracker,jt=>{var It=tu();_t(It,21,()=>y.tree.tree,ht=>ht.id,(ht,ot)=>{{let gt=be(()=>y.draggedNode?.path===s(ot).path),vt=be(()=>y.hoveredNodeForDrop?.path);xi(ht,{get node(){return s(ot)},get children(){return O()},get progressiveRender(){return y.progressiveRender},get renderBatchSize(){return y.initialBatchSize},get isDraggedNode(){return s(gt)},get isDragInProgress(){return y.isDragInProgress},get hoveredNodeForDropPath(){return s(vt)},get activeDropPosition(){return y.activeDropPosition},get dropOperation(){return y.currentDropOperation}})}},ht=>{var ot=eu();let gt;var vt=g(ot);{var An=Ot=>{var fn=zt(),en=et(fn);{var Kt=ln=>{var $n=zt(),yr=et($n);Hn(yr,se),x(ln,$n)},tn=ln=>{var $n=qh();x(ln,$n)};q(en,ln=>{se()?ln(Kt):ln(tn,-1)})}x(Ot,fn)},Ht=Ot=>{var fn=zt(),en=et(fn);Hn(en,()=>fe()??fr),x(Ot,fn)};q(vt,Ot=>{y.isDropPlaceholderActive?Ot(An):Ot(Ht,-1)})}f(ot),ee(()=>gt=st(ot,1,"ltree-empty-state",null,gt,{"ltree-drop-placeholder":y.isDropPlaceholderActive})),Ct("dragenter",ot,function(...Ot){y.handleEmptyTreeDragOver?.apply(this,Ot)}),Ct("dragover",ot,function(...Ot){y.handleEmptyTreeDragOver?.apply(this,Ot)}),Ct("dragleave",ot,function(...Ot){y.handleEmptyTreeDragLeave?.apply(this,Ot)}),Ct("drop",ot,function(...Ot){y.handleEmptyTreeDrop?.apply(this,Ot)}),ze("touchend",ot,function(...Ot){y.handleEmptyTreeTouchEnd?.apply(this,Ot)}),x(ht,ot)}),f(It),x(jt,It)}),x(pt,Lt)};q(wt,pt=>{y.vsActive?pt(Tt):y.useFlatRendering?pt(Tn,1):pt(on,-1)})}x(S,Re)},Aa=S=>{var Re=ru();let wt;var Tt=g(Re);{var Tn=pt=>{var Lt=zt(),Bt=et(Lt);{var jt=ht=>{var ot=zt(),gt=et(ot);Hn(gt,se),x(ht,ot)},It=ht=>{var ot=nu();x(ht,ot)};q(Bt,ht=>{se()?ht(jt):ht(It,-1)})}x(pt,Lt)},on=pt=>{var Lt=zt(),Bt=et(Lt);Hn(Bt,()=>fe()??fr),x(pt,Lt)};q(Tt,pt=>{y.isDropPlaceholderActive?pt(Tn):pt(on,-1)})}f(Re),ee(()=>wt=st(Re,1,"ltree-empty-state",null,wt,{"ltree-drop-placeholder":y.isDropPlaceholderActive})),Ct("dragenter",Re,function(...pt){y.handleEmptyTreeDragOver?.apply(this,pt)}),Ct("dragover",Re,function(...pt){y.handleEmptyTreeDragOver?.apply(this,pt)}),Ct("dragleave",Re,function(...pt){y.handleEmptyTreeDragLeave?.apply(this,pt)}),Ct("drop",Re,function(...pt){y.handleEmptyTreeDrop?.apply(this,pt)}),ze("touchend",Re,function(...pt){y.handleEmptyTreeTouchEnd?.apply(this,pt)}),x(S,Re)};q(Oi,S=>{y.tree?.root?S(Ea):S(Aa,-1)})}f(sr);var ws=b(sr,2);Hn(ws,()=>ue()??fr);var xs=b(ws,2);{var Ra=S=>{var Re=ou(),wt=g(Re);{var Tt=ht=>{var ot=iu();let gt;ee(()=>gt=st(ot,1,"ltree-drop-zone ltree-drop-before",null,gt,{"ltree-drop-zone-active":y.floatingHoveredZone==="before"})),Ct("dragover",ot,vt=>y.handleFloatingZoneDragOver("before",vt)),Ct("dragleave",ot,()=>y.handleFloatingZoneDragLeave()),Ct("drop",ot,vt=>y.handleFloatingZoneDrop("before",vt)),x(ht,ot)},Tn=be(()=>y.isFloatingPositionAllowed("before"));q(wt,ht=>{s(Tn)&&ht(Tt)})}var on=b(wt,2);{var pt=ht=>{var ot=su();let gt;ee(()=>gt=st(ot,1,"ltree-drop-zone ltree-drop-after",null,gt,{"ltree-drop-zone-active":y.floatingHoveredZone==="after"})),Ct("dragover",ot,vt=>y.handleFloatingZoneDragOver("after",vt)),Ct("dragleave",ot,()=>y.handleFloatingZoneDragLeave()),Ct("drop",ot,vt=>y.handleFloatingZoneDrop("after",vt)),x(ht,ot)},Lt=be(()=>y.isFloatingPositionAllowed("after"));q(on,ht=>{s(Lt)&&ht(pt)})}var Bt=b(on,2);{var jt=ht=>{var ot=au();let gt;ee(()=>gt=st(ot,1,"ltree-drop-zone ltree-drop-child",null,gt,{"ltree-drop-zone-active":y.floatingHoveredZone==="child"})),Ct("dragover",ot,vt=>y.handleFloatingZoneDragOver("child",vt)),Ct("dragleave",ot,()=>y.handleFloatingZoneDragLeave()),Ct("drop",ot,vt=>y.handleFloatingZoneDrop("child",vt)),x(ht,ot)},It=be(()=>y.isFloatingPositionAllowed("child"));q(Bt,ht=>{s(It)&&ht(jt)})}f(Re),ee(()=>{st(Re,1,`ltree-drop-zones ltree-drop-zones-${y.dropZoneLayout??""}`),rr(Re,`position: fixed; top: ${y.floatingZoneRect.top??""}px; left: ${y.floatingZoneRect.left??""}px; width: ${y.floatingZoneRect.width??""}px; height: ${y.floatingZoneRect.height??""}px; z-index: 10000; --drop-zone-start: ${s(St)??""}; --drop-zone-max-width: ${y.dropZoneMaxWidth??""}px;`)}),x(S,Re)};q(xs,S=>{y.dropZoneMode==="floating"&&y.isDragInProgress&&y.hoveredNodeForDrop&&y.floatingZoneRect&&S(Ra)})}var Oa=b(xs,2);{var La=S=>{var Re=gu(),wt=g(Re);{var Tt=on=>{const pt=(Bt,jt=fr)=>{var It=zt(),ht=et(It);_t(ht,17,jt,Mt,(ot,gt)=>{var vt=zt(),An=et(vt);{var Ht=fn=>{var en=cu(),Kt=g(en);{var tn=ln=>{var $n=lu(),yr=g($n,!0);f($n),ee(()=>F(yr,s(gt).label)),x(ln,$n)};q(Kt,ln=>{s(gt).label&&ln(tn)})}f(en),x(fn,en)},Ot=fn=>{const en=be(()=>s(gt).children&&s(gt).children.length>0);var Kt=fu();let tn;var ln=g(Kt);{var $n=xn=>{var Zn=du(),Nr=g(Zn,!0);f(Zn),ee(()=>F(Nr,s(gt).icon)),x(xn,Zn)};q(ln,xn=>{s(gt).icon&&xn($n)})}var yr=b(ln,2),Ha=g(yr,!0);f(yr);var Cs=b(yr,2);{var za=xn=>{var Zn=hu(),Nr=g(Zn,!0);f(Zn),ee(()=>F(Nr,s(gt).shortcut)),x(xn,Zn)};q(Cs,xn=>{s(gt).shortcut&&xn(za)})}var Fa=b(Cs,2);{var Ba=xn=>{var Zn=uu(),Nr=b(et(Zn),2),ja=g(Nr);pt(ja,()=>s(gt).children),f(Nr),x(xn,Zn)};q(Fa,xn=>{s(en)&&xn(Ba)})}f(Kt),ee(()=>{tn=st(Kt,1,`ltree-context-menu-item ${(s(gt).className||"")??""}`,null,tn,{"ltree-context-menu-item-disabled":s(gt).isDisabled,"ltree-context-menu-has-children":s(en)}),Rn(Kt,"tabindex",s(gt).isDisabled?-1:0),F(Ha,s(gt).label)}),ze("click",Kt,async()=>{if(!s(gt).isDisabled&&!s(en))try{await s(gt).onclick?.()}catch(xn){console.error("Context menu callback error:",xn)}}),ze("keydown",Kt,async xn=>{if((xn.key==="Enter"||xn.key===" ")&&!s(gt).isDisabled&&!s(en)){xn.preventDefault();try{await s(gt).onclick?.()}catch(Zn){console.error("Context menu callback error:",Zn)}}}),x(fn,Kt)};q(An,fn=>{"divider"in s(gt)?fn(Ht):s(gt).isVisible!==!1&&fn(Ot,1)})}x(ot,vt)}),x(Bt,It)},Lt=be(()=>Oe()(y.contextMenuNode,y.closeContextMenu.bind(y),y.getSelectedNodes()));pt(on,()=>s(Lt))},Tn=on=>{var pt=zt(),Lt=et(pt);{let Bt=be(()=>y.closeContextMenu.bind(y));Hn(Lt,Se,()=>y.contextMenuNode,()=>s(Bt))}x(on,pt)};q(wt,on=>{Oe()?on(Tt):Se()&&on(Tn,1)})}f(Re),ee(()=>rr(Re,`left: ${y.contextMenuX??""}px; top: ${y.contextMenuY??""}px;`)),x(S,Re)};q(Oa,S=>{y.contextMenuVisible&&y.contextMenuNode&&S(La)})}return f(Ut),Qr(Ut,S=>je=S,()=>je),ee(()=>st(sr,1,To(y.bodyClass))),ze("keydown",Ut,In),Ct("dragenter",Ut,function(...S){y.handleTreeDragEnter?.apply(this,S)}),Ct("dragleave",Ut,function(...S){y.handleTreeDragLeave?.apply(this,S)}),Ct("dragend",Ut,function(...S){y._onNodeDragEnd?.apply(this,S)}),x(t,Ut),Dn(Zt)}jn(["keydown","touchend","click"]);var yu=D('<div><span class="json-key svelte-19sik8e"> </span> <span class="json-separator svelte-19sik8e">:</span> <span> </span></div>'),mu=D('<div class="json-tree svelte-19sik8e"><!></div>');function Ma(t,e){Nn(e,!0);let n=K(e,"expandLevel",3,2);function r(m){return m===null?"null":Array.isArray(m)?"array":typeof m=="object"?"object":typeof m=="string"?"string":typeof m=="number"?"number":typeof m=="boolean"?"boolean":"string"}function i(m){return m.replaceAll(".","\\.")}function a(m){return typeof m=="string"?JSON.stringify(m):m===void 0?"undefined":String(m)}function o(m){if(Array.isArray(m))return{value:m.length===0?"[]":`Array(${m.length})`,count:m.length};if(m&&typeof m=="object"){const k=Object.keys(m).length;return{value:k===0?"{}":`Object(${k})`,count:k}}return{value:a(m),count:0}}function l(m,k,C,_){const v=r(C),P=o(C);if(m.push({id:_,path:_,key:k,value:v==="object"||v==="array"?P.value:a(C),type:v,count:P.count}),Array.isArray(C)){C.forEach((E,B)=>l(m,`[${B}]`,E,`${_}.${B}`));return}if(C&&typeof C=="object")for(const[E,B]of Object.entries(C))l(m,E,B,`${_}.${i(E)}`)}function c(m){const k=[];return l(k,"root",m,"root"),k}let d=be(()=>c(e.value));var h=mu(),p=g(h);pu(p,{get data(){return s(d)},idMember:"id",pathMember:"path",displayValueMember:"key",get expandLevel(){return n()},clickBehavior:"expand-and-focus",dragDropMode:"none",nodeTemplate:(k,C=fr)=>{const _=be(()=>C().data);var v=zt(),P=et(v);{var E=B=>{var V=yu();let Z;var j=g(V),ae=g(j,!0);f(j);var ce=b(j,4);let de;var W=g(ce,!0);f(ce),f(V),ee(()=>{Z=st(V,1,"json-row svelte-19sik8e",null,Z,{branch:s(_).type==="object"||s(_).type==="array"}),F(ae,s(_).key),de=st(ce,1,"json-value svelte-19sik8e",null,de,{"type-string":s(_).type==="string","type-number":s(_).type==="number","type-boolean":s(_).type==="boolean","type-null":s(_).type==="null"}),F(W,s(_).value)}),x(B,V)};q(P,B=>{s(_)&&B(E)})}x(k,v)},$$slots:{nodeTemplate:!0}}),f(h),x(t,h),Dn()}var _u=D('<button type="button"> <span class="svelte-6ezzcw"> </span></button>'),bu=D('<button type="button"> <span class="svelte-6ezzcw"> </span></button>'),ku=D('<nav class="proj-type-tabs svelte-6ezzcw" aria-label="Analysis plan subtype"><button type="button">All plan types <span class="svelte-6ezzcw"> </span></button> <!></nav>'),wu=D('<p class="error svelte-6ezzcw"> </p>'),xu=D('<p class="muted svelte-6ezzcw">Loading workspace artifacts...</p>'),Cu=D('<p class="muted svelte-6ezzcw"> </p>'),Su=D('<p class="muted svelte-6ezzcw">No artifacts match this filter.</p>'),Nu=D('<span class="title-prefix svelte-6ezzcw">Analysis plan:</span>'),Du=D('<span class="content svelte-6ezzcw"> </span>'),Pu=D('<span class="tag svelte-6ezzcw"> </span>'),Iu=D('<span class="scope svelte-6ezzcw"> </span>'),Tu=D('<button type="button" class="svelte-6ezzcw">Pack context</button>'),Mu=D('<button type="button" class="svelte-6ezzcw">Focus graph</button>'),Eu=D('<button type="button" class="svelte-6ezzcw">Refresh live</button>'),Au=D('<li><button type="button" class="row-button svelte-6ezzcw"><span class="row-title svelte-6ezzcw"><!> </span> <!></button> <div class="row-meta svelte-6ezzcw"><!> <!></div> <div class="row-actions svelte-6ezzcw"><button type="button" class="svelte-6ezzcw"> </button> <!> <!> <!></div></li>'),Ru=D('<ul class="rows svelte-6ezzcw"></ul>'),Ou=D('<section class="type-group svelte-6ezzcw"><header class="svelte-6ezzcw"><button type="button" class="group-toggle svelte-6ezzcw"><span class="svelte-6ezzcw"> </span> <small class="svelte-6ezzcw"> </small></button></header> <!></section>'),Lu=D('<button type="button" class="svelte-6ezzcw">Refresh live</button>'),Hu=D('<button type="button" class="svelte-6ezzcw">Focus graph</button>'),zu=D('<p class="detail-line svelte-6ezzcw"> </p>'),Fu=D('<li class="svelte-6ezzcw"> </li>'),Bu=D('<h4 class="svelte-6ezzcw"> </h4> <ul class="detail-list svelte-6ezzcw"></ul>',1),ju=D('<p class="detail-line svelte-6ezzcw">No packed context rows returned for this scope.</p>'),Vu=D('<p class="detail-line svelte-6ezzcw"> </p>'),Ku=D('<li class="svelte-6ezzcw"><strong> </strong> <p class="svelte-6ezzcw"> </p></li>'),$u=D('<h4 class="svelte-6ezzcw"> </h4> <ul class="detail-list svelte-6ezzcw"></ul>',1),Zu=D('<li class="svelte-6ezzcw"> </li>'),Uu=D('<h4 class="svelte-6ezzcw"> </h4> <ul class="detail-list svelte-6ezzcw"></ul>',1),Wu=D('<li class="svelte-6ezzcw"><strong> </strong> <p class="svelte-6ezzcw"> </p></li>'),Gu=D('<h4 class="svelte-6ezzcw"> </h4> <ul class="detail-list svelte-6ezzcw"></ul>',1),Yu=D("<!> <!> <!> <!>",1),Xu=D('<header class="result-head svelte-6ezzcw"><div><h3 class="svelte-6ezzcw"> </h3> <p class="svelte-6ezzcw"> </p></div> <div class="result-actions svelte-6ezzcw"><!> <!></div></header> <!> <details class="svelte-6ezzcw"><summary class="svelte-6ezzcw">Technical details</summary> <!></details>',1),Ju=D('<p class="muted svelte-6ezzcw">Select an artifact.</p>'),Qu=D('<div class="projections svelte-6ezzcw"><header class="toolbar svelte-6ezzcw"><div><h2 class="svelte-6ezzcw">Projections</h2> <p class="svelte-6ezzcw"> </p></div> <div class="actions svelte-6ezzcw"><label class="search svelte-6ezzcw"><span class="svelte-6ezzcw">Filter</span> <input class="svelte-6ezzcw"/></label> <button type="button" class="svelte-6ezzcw">Refresh</button></div></header> <nav class="kind-tabs svelte-6ezzcw" aria-label="Projection artifact type"><button type="button">All <span class="svelte-6ezzcw"> </span></button> <!></nav> <!> <!> <div class="layout svelte-6ezzcw"><section class="catalog svelte-6ezzcw"><!></section> <section class="result svelte-6ezzcw"><!></section></div></div>');function qu(t,e){Nn(e,!0);const n=["analysis_plan","answer_snapshot","live_answer_view","evidence_pack"],r=["FACT","GOAL","STEP","CONSTRAINT"];let i=K(e,"workspaceId",3,""),a=K(e,"graphContext",19,()=>({})),o=K(e,"active",3,!1),l=K(e,"initialProjectionId",3,""),c=A(""),d=A("all"),h=A("all"),p=A(!1),m=A(!1),k=A(null),C=A($t([])),_=A(""),v=A(null),P=A(""),E=A(""),B=A(""),V=A($t({analysis_plan:!1,answer_snapshot:!0,live_answer_view:!0,evidence_pack:!0}));De(()=>{const I=Z();o()&&I&&(s(P)!==I||s(E)!==s(c).trim())&&fe()}),De(()=>{l()&&l()!==s(B)&&(u(B,l()),xe(l(),null))});function Z(){return i().trim()||"default"}function j(I){return I.artifact_id??I.projection_id??I.id??(I.entity_id==null?void 0:String(I.entity_id))??zn(I)}function ae(I){return I.artifact_kind??I.type??"artifact"}function ce(){return s(C).filter(I=>s(h)!=="all"?ae(I)==="analysis_plan"&&I.proj_type===s(h):!(s(d)!=="all"&&ae(I)!==s(d)))}function de(){const I=new Map;for(const w of n)I.set(w,[]);for(const w of ce()){const z=ae(w);I.set(z,[...I.get(z)??[],w])}return[...I.entries()].filter(([,w])=>w.length>0)}function W(I){return s(C).filter(w=>ae(w)===I).length}function N(I){return s(C).filter(w=>ae(w)==="analysis_plan"&&w.proj_type===I).length}function G(I){return s(V)[I]??!0}function O(I){u(V,{...s(V),[I]:!G(I)},!0)}function X(I){u(d,I,!0),u(h,"all"),I!=="all"&&u(V,{...s(V),[I]:!0},!0)}function ue(I){u(d,"analysis_plan"),u(h,I,!0),u(V,{...s(V),analysis_plan:!0},!0)}async function fe(){const I=Z();u(p,!0),u(k,null);try{const w=new URLSearchParams({workspace_id:I,limit:"1000"});s(c).trim()&&w.set("search",s(c).trim());const z=await fetch(`/api/projections/catalog?${w}`);if(!z.ok)throw new Error(await z.text());const ie=await z.json();u(C,pa(ie),!0),u(P,I,!0),u(E,s(c).trim(),!0);const Ee=s(_)?s(C).find(Ne=>j(Ne)===s(_)):null,Ae=s(B)?s(C).find(Ne=>Ne.projection_id===s(B)):null;if(Ae&&!Ee)u(_,j(Ae),!0);else if(!Ee){const Ne=s(C)[0];u(_,Ne?j(Ne):"",!0),u(v,null),Ne&&Se(Ne)}}catch(w){u(k,w instanceof Error?w.message:String(w),!0),u(C,[],!0),u(v,null)}finally{u(p,!1)}}async function Se(I){if(u(_,j(I),!0),ae(I)==="answer_snapshot"&&I.projection_id){await xe(I.projection_id,I);return}if(I.artifact_id){await he(I);return}u(v,{kind:"artifact",row:I,title:zn(I),raw:I.raw},!0)}async function se(I){const w=I.scope?.trim();if(w){u(_,j(I),!0),u(p,!0),u(k,null);try{const z=new URLSearchParams({agent_id:"agent:self",workspace_id:Z(),scope:w,query:zn(I),limit:"12"}),ie=await fetch(`/api/brain/ghostcrab/pack-projections?${z}`);if(!ie.ok)throw new Error(await ie.text());u(v,{kind:"pack",row:I,title:`${zn(I)} context`,raw:await ie.json()},!0)}catch(z){u(k,z instanceof Error?z.message:String(z),!0)}finally{u(p,!1)}}}async function he(I){if(I.artifact_id){u(p,!0),u(k,null);try{const w=new URLSearchParams({workspace_id:Z()}),z=await fetch(`/api/brain/ghostcrab/artifact/${encodeURIComponent(I.artifact_id)}?${w}`);if(!z.ok){u(v,{kind:"artifact",row:I,title:zn(I),raw:I.raw},!0);return}u(v,{kind:"artifact",row:I,title:zn(I),raw:await z.json()},!0)}catch{u(v,{kind:"artifact",row:I,title:zn(I),raw:I.raw},!0)}finally{u(p,!1)}}}async function xe(I,w){const z=I.trim();if(z){u(p,!0),u(k,null);try{const ie=new URLSearchParams({workspace_id:Z(),projection_id:z,include_evidence:"true",include_deltas:"true"}),Ee=await fetch(`/api/brain/ghostcrab/projection-get?${ie}`);if(!Ee.ok)throw new Error(await Ee.text());u(v,{kind:"snapshot",row:w,title:w?zn(w):z,raw:await Ee.json()},!0)}catch(ie){u(k,ie instanceof Error?ie.message:String(ie),!0),u(v,w?{kind:"artifact",row:w,title:zn(w),raw:w.raw}:null,!0)}finally{u(p,!1)}}}async function Ce(I){if(!(!I.artifact_id||ae(I)!=="live_answer_view")){u(m,!0),u(k,null);try{const w=new URLSearchParams({workspace_id:Z()}),z=await fetch(`/api/brain/ghostcrab/artifact/${encodeURIComponent(I.artifact_id)}/refresh?${w}`,{method:"POST"});if(!z.ok)throw new Error(await z.text());await fe();const ie=s(C).find(Ee=>Ee.artifact_id===I.artifact_id)??I;await Se(ie)}catch(w){u(k,w instanceof Error?w.message:String(w),!0)}finally{u(m,!1)}}}function nt(){const I=s(v)?.row;I&&Ce(I)}function ke(I){const w=I.raw,ie=(w.metadata&&typeof w.metadata=="object"?w.metadata:null)?.source_plan_id;return typeof ie=="string"&&ie.trim()?ie.trim():void 0}function U(I){const w=I.entity_id!=null?[I.entity_id]:dr(I.raw);if(w.length>0)return w;if(!I.artifact_id)return[];const z=s(C).find(ie=>ae(ie)==="answer_snapshot"&&ke(ie)===I.artifact_id);return z?z.entity_id!=null?[z.entity_id]:dr(z.raw):[]}function me(I){const w=U(I);w.length>0&&e.onViewInGraph?.(w)}function ve(){if(!s(v))return;const I=s(v).kind==="snapshot"?dr(s(v).raw):U(s(v).row);I.length>0&&e.onViewInGraph?.(I)}function Ze(){return s(v)?s(v).kind==="snapshot"?dr(s(v).raw):U(s(v).row):[]}function Le(){return s(v)?.kind==="snapshot"?s(v).raw:{}}function Be(){const I=s(v)?.kind==="pack"?s(v).raw.rows:null;return Array.isArray(I)?I:[]}function Ge(){const I=Le();return I.report?.has_projection??I.has_projection}function Je(I){return[I.proj_type,I.lifecycle,I.state??I.status,I.current_version==null?void 0:`v${I.current_version}`,I.source==="legacy_projection"?"legacy":void 0].filter(w=>!!w)}function Ke(I){return I.preview??I.content??I.public_label??""}function yt(I,w=320){const z=typeof I=="object"?JSON.stringify(I)??String(I):String(I);return z.length>w?`${z.slice(0,w)}...`:z}function ut(I){switch(ae(I)){case"answer_snapshot":return"Open snapshot";case"live_answer_view":return"Open live answer";case"analysis_plan":return"Open plan";case"evidence_pack":return"Open evidence";default:return"Open"}}var tt=Qu(),Fe=g(tt),qe=g(Fe),lt=b(g(qe),2),L=g(lt);f(lt),f(qe);var ne=b(qe,2),H=g(ne),T=b(g(H),2);Mn(T),f(H);var R=b(H,2);f(ne),f(Fe);var J=b(Fe,2),Q=g(J);let Pe;var Ie=b(g(Q)),pe=g(Ie,!0);f(Ie),f(Q);var ye=b(Q,2);_t(ye,17,()=>n,Mt,(I,w)=>{var z=_u();let ie;var Ee=g(z),Ae=b(Ee),Ne=g(Ae,!0);f(Ae),f(z),ee(($e,Ue,y)=>{z.disabled=$e,ie=st(z,1,"svelte-6ezzcw",null,ie,{active:s(d)===s(w)&&s(h)==="all"}),F(Ee,`${Ue??""} `),F(Ne,y)},[()=>W(s(w))===0,()=>ki(s(w)),()=>W(s(w))]),ze("click",z,()=>X(s(w))),x(I,z)}),f(J);var M=b(J,2);{var re=I=>{var w=ku(),z=g(w);let ie;var Ee=b(g(z)),Ae=g(Ee,!0);f(Ee),f(z);var Ne=b(z,2);_t(Ne,17,()=>r,Mt,($e,Ue)=>{var y=bu();let je;var St=g(y),te=b(St),le=g(te,!0);f(te),f(y),ee((rt,ft)=>{y.disabled=rt,je=st(y,1,"svelte-6ezzcw",null,je,{active:s(h)===s(Ue)}),F(St,`${s(Ue)??""} `),F(le,ft)},[()=>N(s(Ue))===0,()=>N(s(Ue))]),ze("click",y,()=>ue(s(Ue))),x($e,y)}),f(w),ee($e=>{ie=st(z,1,"svelte-6ezzcw",null,ie,{active:s(h)==="all"}),F(Ae,$e)},[()=>W("analysis_plan")]),ze("click",z,()=>X("analysis_plan")),x(I,w)},oe=be(()=>W("analysis_plan")>0);q(M,I=>{s(oe)&&I(re)})}var Te=b(M,2);{var we=I=>{var w=wu(),z=g(w,!0);f(w),ee(()=>F(z,s(k))),x(I,w)};q(Te,I=>{s(k)&&I(we)})}var He=b(Te,2),Qe=g(He),$=g(Qe);{var Y=I=>{var w=xu();x(I,w)},ge=I=>{var w=Cu(),z=g(w);f(w),ee(ie=>F(z,`No projection artifacts found for workspace ${ie??""} in this SQLite runtime.`),[()=>Z()]),x(I,w)},Me=I=>{var w=Su();x(I,w)},Ye=be(()=>ce().length===0),_e=I=>{var w=zt(),z=et(w);_t(z,17,de,Mt,(ie,Ee)=>{var Ae=be(()=>Zr(s(Ee),2));let Ne=()=>s(Ae)[0],$e=()=>s(Ae)[1];var Ue=Ou(),y=g(Ue),je=g(y),St=g(je),te=g(St);f(St);var le=b(St,2),rt=g(le,!0);f(le),f(je),f(y);var ft=b(y,2);{var ct=Nt=>{var Et=Ru();_t(Et,21,$e,Pn=>j(Pn),(Pn,at)=>{var At=Au();let dn;var Qt=g(At),hn=g(Qt),Ft=g(hn);{var xt=mt=>{var Pt=Nu();x(mt,Pt)},nn=be(()=>ae(s(at))==="analysis_plan");q(Ft,mt=>{s(nn)&&mt(xt)})}var Rt=b(Ft);f(hn);var bt=b(hn,2);{var pn=mt=>{var Pt=Du(),un=g(Pt,!0);f(Pt),ee(Ln=>F(un,Ln),[()=>Ke(s(at))]),x(mt,Pt)},Xt=be(()=>Ke(s(at)));q(bt,mt=>{s(Xt)&&mt(pn)})}f(Qt);var bn=b(Qt,2),En=g(bn);_t(En,17,()=>Je(s(at)),Mt,(mt,Pt)=>{var un=Pu(),Ln=g(un,!0);f(un),ee(()=>F(Ln,s(Pt))),x(mt,un)});var Vt=b(En,2);{var rn=mt=>{var Pt=Iu(),un=g(Pt,!0);f(Pt),ee(()=>F(un,s(at).scope)),x(mt,Pt)};q(Vt,mt=>{s(at).scope&&mt(rn)})}f(bn);var qt=b(bn,2),sn=g(qt),yn=g(sn,!0);f(sn);var vn=b(sn,2);{var an=mt=>{var Pt=Tu();ze("click",Pt,()=>se(s(at))),x(mt,Pt)},wn=be(()=>ae(s(at))==="analysis_plan"&&s(at).scope);q(vn,mt=>{s(wn)&&mt(an)})}var In=b(vn,2);{var Vn=mt=>{var Pt=Mu();ze("click",Pt,()=>me(s(at))),x(mt,Pt)},Kn=be(()=>U(s(at)).length>0);q(In,mt=>{s(Kn)&&mt(Vn)})}var Dt=b(In,2);{var Zt=mt=>{var Pt=Eu();ee(()=>Pt.disabled=s(m)),ze("click",Pt,()=>Ce(s(at))),x(mt,Pt)},Ut=be(()=>ae(s(at))==="live_answer_view");q(Dt,mt=>{s(Ut)&&mt(Zt)})}f(qt),f(At),ee((mt,Pt,un)=>{dn=st(At,1,"svelte-6ezzcw",null,dn,mt),F(Rt,` ${Pt??""}`),F(yn,un)},[()=>({highlight:ya(s(at),a()),selected:s(_)===j(s(at))}),()=>zn(s(at)),()=>ut(s(at))]),ze("click",Qt,()=>Se(s(at))),ze("click",sn,()=>Se(s(at))),x(Pn,At)}),f(Et),x(Nt,Et)},dt=be(()=>G(Ne()));q(ft,Nt=>{s(dt)&&Nt(ct)})}f(Ue),ee((Nt,Et)=>{F(te,`${Nt??""} ${Et??""}`),F(rt,$e().length)},[()=>G(Ne())?"▼":"▶",()=>ki(Ne())]),ze("click",je,()=>O(Ne())),x(ie,Ue)}),x(I,w)};q($,I=>{s(p)&&s(C).length===0?I(Y):s(C).length===0?I(ge,1):s(Ye)?I(Me,2):I(_e,-1)})}f(Qe);var Oe=b(Qe,2),Xe=g(Oe);{var it=I=>{var w=Xu(),z=et(w),ie=g(z),Ee=g(ie),Ae=g(Ee,!0);f(Ee);var Ne=b(Ee,2),$e=g(Ne);f(Ne),f(ie);var Ue=b(ie,2),y=g(Ue);{var je=at=>{var At=Lu();ee(()=>At.disabled=s(m)),ze("click",At,nt),x(at,At)},St=be(()=>s(v).row&&ae(s(v).row)==="live_answer_view");q(y,at=>{s(St)&&at(je)})}var te=b(y,2);{var le=at=>{var At=Hu();ze("click",At,ve),x(at,At)},rt=be(()=>Ze().length>0);q(te,at=>{s(rt)&&at(le)})}f(Ue),f(z);var ft=b(z,2);{var ct=at=>{var At=zt(),dn=et(At);{var Qt=hn=>{var Ft=zu(),xt=g(Ft,!0);f(Ft),ee(()=>F(xt,s(v).row.preview??s(v).row.content)),x(hn,Ft)};q(dn,hn=>{(s(v).row?.preview||s(v).row?.content)&&hn(Qt)})}x(at,At)},dt=at=>{var At=zt(),dn=et(At);{var Qt=xt=>{var nn=Bu(),Rt=et(nn),bt=g(Rt);f(Rt);var pn=b(Rt,2);_t(pn,21,()=>Be().slice(0,12),Mt,(Xt,bn)=>{var En=Fu(),Vt=g(En,!0);f(En),ee(rn=>F(Vt,rn),[()=>yt(s(bn))]),x(Xt,En)}),f(pn),ee(Xt=>F(bt,`Context rows (${Xt??""})`),[()=>Be().length]),x(xt,nn)},hn=be(()=>Be().length>0),Ft=xt=>{var nn=ju();x(xt,nn)};q(dn,xt=>{s(hn)?xt(Qt):xt(Ft,-1)})}x(at,At)},Nt=at=>{var At=Yu(),dn=et(At);{var Qt=Vt=>{var rn=Vu(),qt=g(rn);f(rn),ee(sn=>F(qt,`has_projection: ${sn??""}`),[()=>String(Ge())]),x(Vt,rn)},hn=be(()=>Ge()!=null);q(dn,Vt=>{s(hn)&&Vt(Qt)})}var Ft=b(dn,2);{var xt=Vt=>{var rn=$u(),qt=et(rn),sn=g(qt);f(qt);var yn=b(qt,2);_t(yn,21,()=>Le().projection_results?.slice(0,8)??[],Mt,(vn,an)=>{var wn=Ku(),In=g(wn),Vn=g(In,!0);f(In);var Kn=b(In,2),Dt=g(Kn,!0);f(Kn),f(wn),ee((Zt,Ut)=>{F(Vn,Zt),F(Dt,Ut)},[()=>String(s(an).name??s(an).entity_type??"ProjectionResult"),()=>yt(s(an).metadata??s(an).metadata_json??s(an))]),x(vn,wn)}),f(yn),ee(vn=>F(sn,`Snapshot results (${vn??""})`),[()=>Le().projection_results?.length]),x(Vt,rn)},nn=be(()=>Le().projection_results?.length);q(Ft,Vt=>{s(nn)&&Vt(xt)})}var Rt=b(Ft,2);{var bt=Vt=>{var rn=Uu(),qt=et(rn),sn=g(qt);f(qt);var yn=b(qt,2);_t(yn,21,()=>Le().linked_evidence?.slice(0,8)??[],Mt,(vn,an)=>{var wn=Zu(),In=g(wn,!0);f(wn),ee(Vn=>F(In,Vn),[()=>yt(s(an))]),x(vn,wn)}),f(yn),ee(vn=>F(sn,`Evidence (${vn??""})`),[()=>Le().linked_evidence?.length]),x(Vt,rn)},pn=be(()=>Le().linked_evidence?.length);q(Rt,Vt=>{s(pn)&&Vt(bt)})}var Xt=b(Rt,2);{var bn=Vt=>{var rn=Gu(),qt=et(rn),sn=g(qt);f(qt);var yn=b(qt,2);_t(yn,21,()=>Le().deltas?.slice(0,8)??[],Mt,(vn,an)=>{var wn=Wu(),In=g(wn),Vn=g(In,!0);f(In);var Kn=b(In,2),Dt=g(Kn,!0);f(Kn),f(wn),ee((Zt,Ut)=>{F(Vn,Zt),F(Dt,Ut)},[()=>String(s(an).name??s(an).entity_type??"DeltaFinding"),()=>yt(s(an).metadata??s(an).metadata_json??s(an))]),x(vn,wn)}),f(yn),ee(vn=>F(sn,`Deltas (${vn??""})`),[()=>Le().deltas?.length]),x(Vt,rn)},En=be(()=>Le().deltas?.length);q(Xt,Vt=>{s(En)&&Vt(bn)})}x(at,At)};q(ft,at=>{s(v).kind==="artifact"?at(ct):s(v).kind==="pack"?at(dt,1):at(Nt,-1)})}var Et=b(ft,2),Pn=b(g(Et),2);Ma(Pn,{get value(){return s(v).raw}}),f(Et),ee(at=>{F(Ae,s(v).title),F($e,`${at??""} · ${s(v).kind??""}`)},[()=>s(v).row?ki(ae(s(v).row)):"Snapshot"]),x(I,w)},Ve=I=>{var w=Ju();x(I,w)};q(Xe,I=>{s(v)?I(it):I(Ve,-1)})}f(Oe),f(He),f(tt),ee(I=>{F(L,`${s(C).length??""} artifacts · ${I??""}`),R.disabled=s(p),Pe=st(Q,1,"svelte-6ezzcw",null,Pe,{active:s(d)==="all"&&s(h)==="all"}),F(pe,s(C).length),Rn(Qe,"aria-busy",s(p))},[()=>Z()]),ze("keydown",T,I=>{I.key==="Enter"&&fe()}),zr(T,()=>s(c),I=>u(c,I)),ze("click",R,fe),ze("click",Q,()=>X("all")),x(t,tt),Dn()}jn(["keydown","click"]);var ef=D('<button type="button" class="reset svelte-1mzsyd7">Reset graph</button>'),tf=D('<p class="error svelte-1mzsyd7"> </p>'),nf=D('<p class="muted svelte-1mzsyd7">No graph-focusable projections for this workspace.</p>'),rf=D('<span class="tag svelte-1mzsyd7"> </span>'),sf=D('<span class="content svelte-1mzsyd7"> </span>'),af=D('<button type="button" class="svelte-1mzsyd7">Open snapshot</button>'),of=D('<li><button type="button" class="row-select svelte-1mzsyd7"><span class="row-head svelte-1mzsyd7"><strong class="svelte-1mzsyd7"> </strong> <span class="tag svelte-1mzsyd7"> </span> <!></span> <!></button> <div class="actions svelte-1mzsyd7"><!></div></li>'),lf=D('<ul class="svelte-1mzsyd7"></ul>'),cf=D('<div class="filter-row svelte-1mzsyd7"><input placeholder="Filter projections" aria-label="Filter projections" class="svelte-1mzsyd7"/> <span class="svelte-1mzsyd7"> </span></div> <!>',1),df=D('<aside><header class="svelte-1mzsyd7"><button type="button" class="toggle svelte-1mzsyd7"> </button> <span class="hint svelte-1mzsyd7"><!></span> <!></header> <!></aside>');function hf(t,e){Nn(e,!0);let n=K(e,"workspaceId",3,""),r=K(e,"graphContext",19,()=>({})),i=K(e,"graphFocused",3,!1),a=A(!1),o=A(null),l=A($t([])),c=A(!0),d=A(""),h=A(""),p=A("");De(()=>{const se=n().trim(),he=`${se}:${r().label??""}:${r().entityType??""}`;se&&he!==s(d)&&m(se,he)});async function m(se,he){u(a,!0),u(o,null);try{const xe=new URLSearchParams({workspace_id:se,limit:"8"}),Ce=await fetch(`/api/projections/catalog?${xe}`);if(!Ce.ok)throw new Error(await Ce.text());u(l,pa(await Ce.json()),!0),u(d,he,!0)}catch(xe){u(o,xe instanceof Error?xe.message:String(xe),!0),u(l,[],!0)}finally{u(a,!1)}}function k(se){const he=P(se);he.length>0&&(u(h,C(se),!0),e.onViewInGraph?.(he))}function C(se){return se.artifact_id??se.projection_id??se.id??(se.entity_id==null?void 0:String(se.entity_id))??zn(se)}function _(se){u(h,C(se),!0)}function v(se){const he=se.raw,Ce=(he.metadata&&typeof he.metadata=="object"?he.metadata:null)?.source_plan_id;return typeof Ce=="string"&&Ce.trim()?Ce.trim():void 0}function P(se){const he=se.entity_id!=null?[se.entity_id]:dr(se.raw);if(he.length>0)return he;if(!se.artifact_id)return[];const xe=s(l).find(Ce=>(Ce.artifact_kind??Ce.type)==="answer_snapshot"&&v(Ce)===se.artifact_id);return xe?xe.entity_id!=null?[xe.entity_id]:dr(xe.raw):[]}function E(){const se=s(l).filter(xe=>P(xe).length>0),he=s(p).trim().toLowerCase();return he?se.filter(xe=>[zn(xe),xe.preview,xe.content,xe.artifact_kind,xe.state,xe.status].filter(Boolean).join(" ").toLowerCase().includes(he)):se}function B(se){return se.state??se.status??se.lifecycle}var V=df();let Z;var j=g(V),ae=g(j),ce=g(ae);f(ae);var de=b(ae,2),W=g(de);{var N=se=>{var he=Bn("Loading…");x(se,he)},G=se=>{var he=Bn();ee(()=>F(he,`Context: ${r().label??""}`)),x(se,he)},O=se=>{var he=Bn();ee(()=>F(he,n()||"workspace")),x(se,he)};q(W,se=>{s(a)?se(N):r().label?se(G,1):se(O,-1)})}f(de);var X=b(de,2);{var ue=se=>{var he=ef();ze("click",he,()=>e.onResetGraph?.()),x(se,he)};q(X,se=>{i()&&se(ue)})}f(j);var fe=b(j,2);{var Se=se=>{var he=cf(),xe=et(he),Ce=g(xe);Mn(Ce);var nt=b(Ce,2),ke=g(nt,!0);f(nt),f(xe);var U=b(xe,2);{var me=Be=>{var Ge=tf(),Je=g(Ge,!0);f(Ge),ee(()=>F(Je,s(o))),x(Be,Ge)},ve=Be=>{var Ge=nf();x(Be,Ge)},Ze=be(()=>E().length===0),Le=Be=>{var Ge=lf();_t(Ge,21,E,Mt,(Je,Ke)=>{var yt=of();let ut;var tt=g(yt),Fe=g(tt),qe=g(Fe),lt=g(qe,!0);f(qe);var L=b(qe,2),ne=g(L,!0);f(L);var H=b(L,2);{var T=ye=>{var M=rf(),re=g(M,!0);f(M),ee(oe=>F(re,oe),[()=>B(s(Ke))]),x(ye,M)},R=be(()=>B(s(Ke)));q(H,ye=>{s(R)&&ye(T)})}f(Fe);var J=b(Fe,2);{var Q=ye=>{var M=sf(),re=g(M,!0);f(M),ee(()=>F(re,s(Ke).preview??s(Ke).content)),x(ye,M)};q(J,ye=>{(s(Ke).preview||s(Ke).content)&&ye(Q)})}f(tt);var Pe=b(tt,2),Ie=g(Pe);{var pe=ye=>{var M=af();ze("click",M,()=>{_(s(Ke)),e.onOpenDetail?.(s(Ke).projection_id)}),x(ye,M)};q(Ie,ye=>{s(Ke).artifact_kind==="answer_snapshot"&&s(Ke).projection_id&&ye(pe)})}f(Pe),f(yt),ee((ye,M,re)=>{ut=st(yt,1,"svelte-1mzsyd7",null,ut,ye),F(lt,M),F(ne,re)},[()=>({highlight:ya(s(Ke),r()),selected:s(h)===C(s(Ke))}),()=>zn(s(Ke)),()=>ki(s(Ke).artifact_kind??s(Ke).type)]),ze("click",tt,()=>k(s(Ke))),x(Je,yt)}),f(Ge),x(Be,Ge)};q(U,Be=>{s(o)?Be(me):s(Ze)?Be(ve,1):Be(Le,-1)})}ee(Be=>F(ke,Be),[()=>E().length]),zr(Ce,()=>s(p),Be=>u(p,Be)),x(se,he)};q(fe,se=>{s(c)||se(Se)})}f(V),ee(()=>{Z=st(V,1,"drawer svelte-1mzsyd7",null,Z,{collapsed:s(c)}),F(ce,`${s(c)?"▲":"▼"} Projections`)}),ze("click",ae,()=>u(c,!s(c))),x(t,V),Dn()}jn(["click"]);var uf=D('<button type="button"> </button>'),ff=D('<button type="button" class="svelte-1u70db1"> </button>'),gf=D('<p class="error svelte-1u70db1"> </p>'),vf=D('<p class="muted svelte-1u70db1">Loading rules...</p>'),pf=D('<p class="muted svelte-1u70db1">No graph gap rules found for this workspace.</p>'),yf=D('<p class="muted svelte-1u70db1">No rules match this filter.</p>'),mf=D('<button type="button" class="svelte-1u70db1">Focus graph</button>'),_f=D('<li><button type="button" class="row-button svelte-1u70db1"><span class="row-title svelte-1u70db1"> </span> <span class="content svelte-1u70db1"> </span></button> <div class="row-meta svelte-1u70db1"><span class="tag severity svelte-1u70db1"> </span> <span class="tag svelte-1u70db1"> </span> <span class="scope svelte-1u70db1"> </span></div> <div class="row-actions svelte-1u70db1"><span class="count invalid svelte-1u70db1"> </span> <span class="count svelte-1u70db1"> </span> <!></div></li>'),bf=D('<ul class="rows svelte-1u70db1"></ul>'),kf=D('<button type="button" class="svelte-1u70db1">Focus invalid</button>'),wf=D('<p class="detail-line svelte-1u70db1"> </p>'),xf=D('<p class="muted svelte-1u70db1">No invalid subjects for this rule.</p>'),Cf=D('<li class="svelte-1u70db1"><button type="button" class="link-button svelte-1u70db1"> </button> <span> </span></li>'),Sf=D('<ul class="detail-list svelte-1u70db1"></ul>'),Nf=D('<li class="svelte-1u70db1"><button type="button" class="link-button svelte-1u70db1"> </button> <span> </span></li>'),Df=D('<h4 class="svelte-1u70db1">Recent events</h4> <ul class="detail-list svelte-1u70db1"></ul>',1),Pf=D('<header class="result-head svelte-1u70db1"><div><h3 class="svelte-1u70db1"> </h3> <p class="svelte-1u70db1"> </p></div> <div class="result-actions svelte-1u70db1"><!></div></header> <!> <div class="cards svelte-1u70db1"><div class="svelte-1u70db1"><strong class="svelte-1u70db1"> </strong> <span class="svelte-1u70db1">invalid</span></div> <div class="svelte-1u70db1"><strong class="svelte-1u70db1"> </strong> <span class="svelte-1u70db1">valid</span></div> <div class="svelte-1u70db1"><strong class="svelte-1u70db1"> </strong> <span class="svelte-1u70db1">diagnostic issues</span></div></div> <h4 class="svelte-1u70db1">Invalid subjects</h4> <!> <!> <details class="svelte-1u70db1"><summary class="svelte-1u70db1">Technical details</summary> <!></details>',1),If=D('<p class="muted svelte-1u70db1">Select a rule.</p>'),Tf=D('<div class="rules svelte-1u70db1"><header class="toolbar svelte-1u70db1"><div><h2 class="svelte-1u70db1">Rules</h2> <p class="svelte-1u70db1"> <!></p></div> <div class="actions svelte-1u70db1"><label class="search svelte-1u70db1"><span class="svelte-1u70db1">Filter</span> <input class="svelte-1u70db1"/></label> <button type="button" class="svelte-1u70db1">Refresh</button> <button type="button" class="svelte-1u70db1"> </button></div></header> <nav class="filters svelte-1u70db1" aria-label="Rule filters"><button type="button">All <span class="svelte-1u70db1"> </span></button> <button type="button">Invalid <span class="svelte-1u70db1"> </span></button> <button type="button">Valid <span class="svelte-1u70db1"> </span></button> <button type="button">All severities</button> <!></nav> <section class="summary svelte-1u70db1" aria-label="Rule diagnostics summary"><span class="svelte-1u70db1"> </span> <span class="svelte-1u70db1"> </span> <span class="svelte-1u70db1"> </span> <span class="svelte-1u70db1"> </span> <!></section> <!> <div class="layout svelte-1u70db1"><section class="catalog svelte-1u70db1"><!></section> <section class="result svelte-1u70db1"><!></section></div></div>');function Mf(t,e){Nn(e,!0);let n=K(e,"workspaceId",3,"default"),r=K(e,"ontologyId",3,""),i=K(e,"active",3,!1),a=A(!1),o=A(!1),l=A(null),c=A(""),d=A("all"),h=A("all"),p=A(""),m=A(""),k=A(""),C=A($t([])),_=A($t([])),v=A($t([])),P=A(null),E=A(null);De(()=>{const te=B(),le=V();i()&&te&&(s(m)!==te||s(k)!==le)&&ae()});function B(){return n().trim()||"default"}function V(){const te=r().trim();if(te&&te!==_n)return te;const le=B();return le!=="default"?le:""}function Z(te=new URLSearchParams){te.set("workspace_id",B());const le=V();return le&&te.set("ontology_id",le),te}async function j(te,le){const rt=await fetch(te,le);if(!rt.ok)throw new Error(await rt.text());return await rt.json()}async function ae(){u(a,!0),u(l,null);try{const[te,le,rt,ft]=await Promise.all([j(`/api/brain/graph/gap-rules?${Z()}`),j(`/api/brain/graph/rule-evaluations?${Z(new URLSearchParams({limit:"500"}))}`),j(`/api/brain/graph/rule-events?${Z(new URLSearchParams({limit:"100"}))}`),j(`/api/brain/graph/diagnostics?${Z(new URLSearchParams({limit:"500"}))}`)]);u(C,Array.isArray(te.rules)?te.rules:[],!0),u(_,Array.isArray(le.evaluations)?le.evaluations:[],!0),u(v,Array.isArray(rt.events)?rt.events:[],!0),u(P,ft,!0),u(m,B(),!0),u(k,V(),!0),s(p)&&!s(C).some(ct=>ct.rule_id===s(p))&&u(p,""),!s(p)&&s(C).length>0&&u(p,s(C)[0].rule_id,!0)}catch(te){u(l,te instanceof Error?te.message:String(te),!0),u(C,[],!0),u(_,[],!0),u(v,[],!0),u(P,null)}finally{u(a,!1)}}async function ce(){u(o,!0),u(l,null);try{const te={workspace_id:B(),limit:100,create_remediation_actions:!1},le=V();le&&(te.ontology_id=le),u(E,await j("/api/brain/graph/rule-evaluations/run",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(te)}),!0),await ae()}catch(te){u(l,te instanceof Error?te.message:String(te),!0)}finally{u(o,!1)}}function de(te){return s(_).filter(le=>le.rule_id===te)}function W(te){const le=s(P)?.issues;return Array.isArray(le)?le.filter(rt=>rt.rule_id===te):[]}function N(te){return de(te).filter(le=>le.state==="invalid").length}function G(te){return de(te).filter(le=>le.state==="valid").length}function O(te,le=!0){const rt=new Set;for(const ft of de(te))(!le||ft.state==="invalid")&&rt.add(Number(ft.subject_entity_id));for(const ft of W(te)){const ct=Number(ft.entity_id);Number.isFinite(ct)&&ct>0&&rt.add(ct)}return[...rt].filter(ft=>Number.isFinite(ft)&&ft>0)}function X(){const te=s(c).trim().toLowerCase();return s(C).filter(le=>s(h)!=="all"&&le.severity!==s(h)||s(d)==="invalid"&&N(le.rule_id)===0||s(d)==="valid"&&G(le.rule_id)===0?!1:te?[le.rule_id,le.label,le.entity_type,le.relation_type,le.target_entity_type,le.severity].filter(Boolean).join(" ").toLowerCase().includes(te):!0)}function ue(){return s(C).find(te=>te.rule_id===s(p))??X()[0]??null}function fe(){return[...new Set(s(C).map(te=>te.severity).filter(te=>!!te))].sort()}function Se(){const te=s(P)?.summary;return te&&typeof te=="object"?te:{}}function se(){const te=new Set;for(const le of X())for(const rt of O(le.rule_id,s(d)!=="valid"))te.add(rt);return[...te]}function he(te){const le=[...new Set(te)].filter(rt=>Number.isFinite(rt)&&rt>0).slice(0,30);le.length>0&&e.onViewInGraph?.(le)}function xe(te){return te==null?"0":String(te)}function Ce(te){const le=te.target_entity_type?` -> ${te.target_entity_type}`:"";return`${te.entity_type??"?"} · ${te.direction??"?"} ${te.relation_type??"?"}${le}`}var nt=Tf(),ke=g(nt),U=g(ke),me=b(g(U),2),ve=g(me),Ze=b(ve);{var Le=te=>{var le=Bn();ee(rt=>F(le,`· ${rt??""}`),[()=>V()]),x(te,le)},Be=be(()=>V());q(Ze,te=>{s(Be)&&te(Le)})}f(me),f(U);var Ge=b(U,2),Je=g(Ge),Ke=b(g(Je),2);Mn(Ke),f(Je);var yt=b(Je,2),ut=b(yt,2),tt=g(ut,!0);f(ut),f(Ge),f(ke);var Fe=b(ke,2),qe=g(Fe);let lt;var L=b(g(qe)),ne=g(L,!0);f(L),f(qe);var H=b(qe,2);let T;var R=b(g(H)),J=g(R,!0);f(R),f(H);var Q=b(H,2);let Pe;var Ie=b(g(Q)),pe=g(Ie,!0);f(Ie),f(Q);var ye=b(Q,2);let M;var re=b(ye,2);_t(re,17,fe,Mt,(te,le)=>{var rt=uf();let ft;var ct=g(rt,!0);f(rt),ee(()=>{ft=st(rt,1,"svelte-1u70db1",null,ft,{active:s(h)===s(le)}),F(ct,s(le))}),ze("click",rt,()=>u(h,s(le),!0)),x(te,rt)}),f(Fe);var oe=b(Fe,2),Te=g(oe),we=g(Te);f(Te);var He=b(Te,2),Qe=g(He);f(He);var $=b(He,2),Y=g($);f($);var ge=b($,2),Me=g(ge);f(ge);var Ye=b(ge,2);{var _e=te=>{var le=ff(),rt=g(le);f(le),ee(ft=>F(rt,`Focus impacted (${ft??""})`),[()=>Math.min(se().length,30)]),ze("click",le,()=>he(se())),x(te,le)},Oe=be(()=>se().length>0);q(Ye,te=>{s(Oe)&&te(_e)})}f(oe);var Xe=b(oe,2);{var it=te=>{var le=gf(),rt=g(le,!0);f(le),ee(()=>F(rt,s(l))),x(te,le)};q(Xe,te=>{s(l)&&te(it)})}var Ve=b(Xe,2),I=g(Ve),w=g(I);{var z=te=>{var le=vf();x(te,le)},ie=te=>{var le=pf();x(te,le)},Ee=te=>{var le=yf();x(te,le)},Ae=be(()=>X().length===0),Ne=te=>{var le=bf();_t(le,21,X,rt=>rt.rule_id,(rt,ft)=>{var ct=_f();let dt;var Nt=g(ct),Et=g(Nt),Pn=g(Et,!0);f(Et);var at=b(Et,2),At=g(at,!0);f(at),f(Nt);var dn=b(Nt,2),Qt=g(dn),hn=g(Qt,!0);f(Qt);var Ft=b(Qt,2),xt=g(Ft,!0);f(Ft);var nn=b(Ft,2),Rt=g(nn,!0);f(nn),f(dn);var bt=b(dn,2),pn=g(bt),Xt=g(pn);f(pn);var bn=b(pn,2),En=g(bn);f(bn);var Vt=b(bn,2);{var rn=sn=>{var yn=mf();ze("click",yn,()=>he(O(s(ft).rule_id))),x(sn,yn)},qt=be(()=>O(s(ft).rule_id).length>0);q(Vt,sn=>{s(qt)&&sn(rn)})}f(bt),f(ct),ee((sn,yn,vn,an)=>{dt=st(ct,1,"svelte-1u70db1",null,dt,{selected:s(p)===s(ft).rule_id}),F(Pn,s(ft).rule_id),F(At,sn),F(hn,s(ft).severity??"info"),F(xt,s(ft).enabled===!1?"disabled":"enabled"),F(Rt,yn),F(Xt,`invalid ${vn??""}`),F(En,`valid ${an??""}`)},[()=>s(ft).label??Ce(s(ft)),()=>Ce(s(ft)),()=>N(s(ft).rule_id),()=>G(s(ft).rule_id)]),ze("click",Nt,()=>u(p,s(ft).rule_id,!0)),x(rt,ct)}),f(le),x(te,le)};q(w,te=>{s(a)&&s(C).length===0?te(z):s(C).length===0?te(ie,1):s(Ae)?te(Ee,2):te(Ne,-1)})}f(I);var $e=b(I,2),Ue=g($e);{var y=te=>{const le=be(ue);var rt=Pf(),ft=et(rt),ct=g(ft),dt=g(ct),Nt=g(dt,!0);f(dt);var Et=b(dt,2),Pn=g(Et,!0);f(Et),f(ct);var at=b(ct,2),At=g(at);{var dn=Dt=>{var Zt=kf();ze("click",Zt,()=>he(O(s(le).rule_id))),x(Dt,Zt)},Qt=be(()=>s(le)&&O(s(le).rule_id).length>0);q(At,Dt=>{s(Qt)&&Dt(dn)})}f(at),f(ft);var hn=b(ft,2);{var Ft=Dt=>{var Zt=wf(),Ut=g(Zt,!0);f(Zt),ee(()=>F(Ut,s(le).label)),x(Dt,Zt)};q(hn,Dt=>{s(le)?.label&&Dt(Ft)})}var xt=b(hn,2),nn=g(xt),Rt=g(nn),bt=g(Rt,!0);f(Rt),Yt(2),f(nn);var pn=b(nn,2),Xt=g(pn),bn=g(Xt,!0);f(Xt),Yt(2),f(pn);var En=b(pn,2),Vt=g(En),rn=g(Vt,!0);f(Vt),Yt(2),f(En),f(xt);var qt=b(xt,4);{var sn=Dt=>{var Zt=xf();x(Dt,Zt)},yn=be(()=>de(s(le)?.rule_id??"").filter(Dt=>Dt.state==="invalid").length===0),vn=Dt=>{var Zt=Sf();_t(Zt,21,()=>de(s(le)?.rule_id??"").filter(Ut=>Ut.state==="invalid").slice(0,40),Mt,(Ut,mt)=>{var Pt=Cf(),un=g(Pt),Ln=g(un);f(un);var Sr=b(un,2),sr=g(Sr);f(Sr),f(Pt),ee(()=>{F(Ln,`#${s(mt).subject_entity_id??""}`),F(sr,`observed ${s(mt).observed_count??0??""}, expected min ${s(mt).expected_min??0??""}`)}),ze("click",un,()=>he([s(mt).subject_entity_id])),x(Ut,Pt)}),f(Zt),x(Dt,Zt)};q(qt,Dt=>{s(yn)?Dt(sn):Dt(vn,-1)})}var an=b(qt,2);{var wn=Dt=>{var Zt=Df(),Ut=b(et(Zt),2);_t(Ut,21,()=>s(v).filter(mt=>mt.rule_id===s(le)?.rule_id).slice(0,8),Mt,(mt,Pt)=>{var un=Nf(),Ln=g(un),Sr=g(Ln);f(Ln);var sr=b(Ln,2),Oi=g(sr);f(sr),f(un),ee(()=>{F(Sr,`#${s(Pt).subject_entity_id??""}`),F(Oi,`${s(Pt).from_state??"?"??""} -> ${s(Pt).to_state??"?"??""}`)}),ze("click",Ln,()=>he([s(Pt).subject_entity_id])),x(mt,un)}),f(Ut),x(Dt,Zt)},In=be(()=>s(v).filter(Dt=>Dt.rule_id===s(le)?.rule_id).length>0);q(an,Dt=>{s(In)&&Dt(wn)})}var Vn=b(an,2),Kn=b(g(Vn),2);{let Dt=be(()=>({rule:s(le),evaluations:de(s(le)?.rule_id??""),issues:W(s(le)?.rule_id??"")}));Ma(Kn,{get value(){return s(Dt)}})}f(Vn),ee((Dt,Zt,Ut,mt)=>{F(Nt,s(le)?.rule_id),F(Pn,Dt),F(bt,Zt),F(bn,Ut),F(rn,mt)},[()=>s(le)?Ce(s(le)):"",()=>N(s(le)?.rule_id??""),()=>G(s(le)?.rule_id??""),()=>W(s(le)?.rule_id??"").length]),x(te,rt)},je=be(()=>ue()),St=te=>{var le=If();x(te,le)};q(Ue,te=>{s(je)?te(y):te(St,-1)})}f($e),f(Ve),f(nt),ee((te,le,rt,ft,ct,dt,Nt)=>{F(ve,`${s(C).length??""} rules · ${te??""} `),yt.disabled=s(a)||s(o),ut.disabled=s(a)||s(o),F(tt,s(o)?"Running...":"Run evaluations"),lt=st(qe,1,"svelte-1u70db1",null,lt,{active:s(d)==="all"}),F(ne,s(C).length),T=st(H,1,"svelte-1u70db1",null,T,{active:s(d)==="invalid"}),F(J,le),Pe=st(Q,1,"svelte-1u70db1",null,Pe,{active:s(d)==="valid"}),F(pe,rt),M=st(ye,1,"svelte-1u70db1",null,M,{active:s(h)==="all"}),F(we,`evaluated ${ft??""}`),F(Qe,`invalid ${ct??""}`),F(Y,`events ${dt??""}`),F(Me,`diagnostic issues ${Nt??""}`),Rn(I,"aria-busy",s(a))},[()=>B(),()=>s(_).filter(te=>te.state==="invalid").length,()=>s(_).filter(te=>te.state==="valid").length,()=>xe(s(E)?.evaluated??Se().rules_evaluated),()=>xe(s(E)?.invalid_count??Se().missing_required_relations),()=>xe(s(E)?.events_created??s(v).length),()=>xe(Se().issues_total)]),ze("keydown",Ke,te=>{te.key==="Enter"&&ae()}),zr(Ke,()=>s(c),te=>u(c,te)),ze("click",yt,ae),ze("click",ut,ce),ze("click",qe,()=>u(d,"all")),ze("click",H,()=>u(d,"invalid")),ze("click",Q,()=>u(d,"valid")),ze("click",ye,()=>u(h,"all")),x(t,nt),Dn()}jn(["keydown","click"]);function Ef(t,e,n){if(e.length===0)return n?.trim()??"";const r=t.trim(),i=new Map(e.map(d=>[d.ontology_id,d])),a=`${r}::core`;if(i.has(a))return a;const o=e.filter(d=>d.source_kind==="linkml");if(o.length===1)return o[0].ontology_id;if(o.length>1)return o.find(h=>h.ontology_id.startsWith(`${r}::`))?.ontology_id??o[0].ontology_id;const l=e.filter(d=>!d.ontology_id.endsWith("::default"));if(l.length>0)return l[0].ontology_id;const c=n?.trim();return c&&i.has(c)?c:e[0]?.ontology_id??""}var Af=D("<option>All workspaces</option>"),Rf=D("<option> </option>"),Of=D("<option> </option>"),Lf=D("<option> </option>"),Hf=D('<label class="field svelte-1uha8ag"><span class="field-label svelte-1uha8ag">Ontology</span> <select class="select svelte-1uha8ag" aria-label="Ontology model"><!><!></select></label>'),zf=D('<p class="ontologies-warn svelte-1uha8ag" role="status"> </p>'),Ff=D('<p class="panel-message svelte-1uha8ag">Modèle view requires MindBrain online.</p>'),Bf=D('<div class="donnees-stage svelte-1uha8ag"><!> <!></div>'),jf=D('<p class="panel-message svelte-1uha8ag">Projections require MindBrain online (brain mode).</p>'),Vf=D('<p class="panel-message svelte-1uha8ag">Rules require MindBrain online (brain mode).</p>'),Kf=D('<main class="page svelte-1uha8ag"><header class="bar svelte-1uha8ag"><div class="bar-top svelte-1uha8ag"><div class="title-block svelte-1uha8ag"><h1 class="svelte-1uha8ag">GhostCrab Graph Explorer</h1> <span class="hint svelte-1uha8ag"><span></span> <!></span></div> <div class="tabs svelte-1uha8ag"><button>Modèle</button> <button>Données</button> <button>Projections</button> <button>Rules</button></div> <div class="controls svelte-1uha8ag"><label class="field field-workspace svelte-1uha8ag"><span class="field-label svelte-1uha8ag">Workspace</span> <select class="select svelte-1uha8ag" aria-label="Workspace"><!><!></select></label> <!></div></div> <!></header> <div><div class="stage svelte-1uha8ag"><!></div> <!></div></main>');function Jf(t,e){Nn(e,!0);let n=A("donnees"),r=A("all"),i=A("circular_force"),a=A("all"),o=A(""),l=A(""),c=A("30"),d=A($t([])),h=A($t([])),p=A($t([])),m=A(null),k=A(null),C=A("brain"),_=A(null),v=A($t([])),P=A(""),E=A(!1),B=A($t({search:!0,display:!1,facets:!1,legend:!1,selection:!0})),V=A(null),Z=A($t([])),j=be(()=>s(c)==="none"?null:Number(s(c))),ae=be(()=>s(o).trim()==="immeuble-demo"?"sqlite-demo":s(C)),ce=be(()=>{const w=s(_);return w?.kind==="ontology"&&w.payload?.ontology_id?String(w.payload.ontology_id):s(l)===_n?"":s(l)}),de=be(()=>{const w=s(_);return w?w.kind==="entity"?{entityId:w.entityId,entityType:w.entityType,label:w.label}:w.kind==="relation"?{relationType:w.relationType}:{}:{}});async function W(){try{const w=await fetch("/api/brain/health");if(!w.ok)throw new Error(w.statusText);const z=await w.json();u(k,z.online,!0),u(C,z.mode,!0),s(C)==="brain"&&z.online?await ue():await N()}catch{u(k,!1),await N()}}async function N(){u(m,null);try{const w=new URLSearchParams;s(o)&&w.set("workspace",s(o));const z=await fetch(`/api/graph/ontologies?${w}`);if(!z.ok)throw new Error(z.statusText);const ie=await z.json();u(h,ie.ontologies??[],!0),u(d,ie.graphWorkspaces??[],!0),s(o)&&!s(d).some(Ee=>Ee.id===s(o))&&u(o,""),s(r)!=="all"&&!s(h).some(Ee=>Ee.id===s(r))&&u(r,"all")}catch(w){u(m,w instanceof Error?w.message:String(w),!0)}}function G(w,z){if(z&&w.some(Ae=>Ae.id===z))return z;const ie=w.filter(Ae=>Ae.defaultOntologyId),Ee=[...w].sort((Ae,Ne)=>Ne.entityCount-Ae.entityCount);return w.find(Ae=>Ae.id==="immeuble-demo")?.id??ie.find(Ae=>Ae.entityCount>0)?.id??Ee.find(Ae=>Ae.entityCount>0)?.id??ie[0]?.id??w.find(Ae=>Ae.id!=="default")?.id??w[0]?.id??""}async function O(w){const z=await fetch(`/api/graph/ontologies?workspace=${encodeURIComponent(w)}`);if(!z.ok)throw new Error(await z.text());const ie=await z.json();u(h,ie.ontologies??[],!0),ie.graphWorkspaces?.length&&u(d,ie.graphWorkspaces,!0)}async function X(){if(s(k)!==!0){u(p,[],!0),u(l,"");return}try{const w=s(o).trim();if(!w){u(p,[],!0),u(l,"");return}const z=await fetch(`/api/brain/ontology/list?workspace_id=${encodeURIComponent(w)}`);if(!z.ok)throw new Error(await z.text());const ie=await z.json(),Ee=`${w}::`;u(p,(ie.ontologies??[]).filter($e=>$e.ontology_id===w||$e.ontology_id.startsWith(Ee)),!0);const Ae=(ie.default_ontology_id===w||ie.default_ontology_id?.startsWith(Ee)?ie.default_ontology_id:null)??s(d).find($e=>$e.id===w)?.defaultOntologyId??null,Ne=Ef(w,s(p),Ae);u(l,s(l)===_n||s(p).some($e=>$e.ontology_id===s(l))?s(l)||_n:s(p).length>1?_n:Ne,!0)}catch{u(p,[],!0),u(l,"")}}async function ue(){u(m,null);try{const w=await fetch("/api/graph/ontologies");if(!w.ok)throw new Error(await w.text());const z=await w.json();u(d,z.graphWorkspaces??[],!0);const ie=G(s(d),s(o).trim());ie&&s(o)!==ie&&u(o,ie,!0),ie?await O(ie):u(h,z.ontologies??[],!0),await X()}catch(w){u(m,w instanceof Error?w.message:String(w),!0),u(d,[],!0),u(h,[],!0),u(p,[],!0),u(l,"")}}function fe(w){const z=w.currentTarget;u(o,z.value,!0),u(r,"all"),u(v,[],!0),u(_,null),s(C)==="brain"&&s(k)===!0?(async()=>(await O(s(o)),await X()))():N()}function Se(w){const z=w.currentTarget;u(r,z.value,!0)}function se(w){const z=w.currentTarget;u(l,z.value,!0)}function he(w){if(w==="all")return"All entity types";const z=s(h).find(ie=>ie.id===w);return z?.label?z.label:w.toLowerCase().startsWith("type:")?w.slice(5):w}function xe(){return s(r)==="all"?null:he(s(r))}function Ce(w){u(_,w,!0),u(E,!0),w&&u(B,{...s(B),selection:!0},!0)}function nt(w,z){u(n,"modele"),Ce({kind:"ontology",nodeKind:z,typeName:w})}function ke(w){u(n,"donnees"),u(v,w,!0)}function U(w){u(n,"donnees"),u(v,w,!0)}function me(){u(v,[],!0),u(_,null)}function ve(w){u(P,w,!0),u(n,"projections")}Ka(()=>{W()});var Ze=Kf(),Le=g(Ze),Be=g(Le),Ge=g(Be),Je=b(g(Ge),2),Ke=g(Je);let yt;var ut=b(Ke,2);{var tt=w=>{var z=Bn("Demo SQLite · read-only");x(w,z)},Fe=w=>{var z=Bn("MindBrain live · dual view");x(w,z)},qe=w=>{var z=Bn("Brain offline · demo fallback recommended");x(w,z)};q(ut,w=>{s(C)==="sqlite-demo"?w(tt):s(k)===!0?w(Fe,1):w(qe,-1)})}f(Je),f(Ge);var lt=b(Ge,2),L=g(lt);let ne;var H=b(L,2);let T;var R=b(H,2);let J;var Q=b(R,2);let Pe;f(lt);var Ie=b(lt,2),pe=g(Ie),ye=b(g(pe),2),M=g(ye);{var re=w=>{var z=Af();z.value=z.__value="",x(w,z)};q(M,w=>{(s(C)!=="brain"||s(k)!==!0)&&w(re)})}var oe=b(M);_t(oe,17,()=>s(d),Mt,(w,z)=>{var ie=Rf(),Ee=g(ie);f(ie);var Ae={};ee(()=>{F(Ee,`${(s(z).label?`${s(z).label} · ${s(z).id}`:s(z).id)??""} (${s(z).entityCount??""})`),Ae!==(Ae=s(z).id)&&(ie.value=(ie.__value=s(z).id)??"")}),x(w,ie)}),f(ye);var Te;Di(ye),f(pe);var we=b(pe,2);{var He=w=>{var z=Hf(),ie=b(g(z),2),Ee=g(ie);{var Ae=Ue=>{var y=Of(),je=g(y);f(y);var St={};ee(()=>{F(je,`Tous · ${s(p).length??""} ontologies`),St!==(St=_n)&&(y.value=(y.__value=_n)??"")}),x(Ue,y)};q(Ee,Ue=>{s(p).length>1&&Ue(Ae)})}var Ne=b(Ee);_t(Ne,17,()=>s(p),Mt,(Ue,y)=>{var je=Lf(),St=g(je);f(je);var te={};ee(()=>{F(St,`${s(y).name??""} · ${s(y).ontology_id??""}`),te!==(te=s(y).ontology_id)&&(je.value=(je.__value=s(y).ontology_id)??"")}),x(Ue,je)}),f(ie);var $e;Di(ie),f(z),ee(()=>{$e!==($e=s(l))&&(ie.value=(ie.__value=s(l))??"",qr(ie,s(l)))}),ze("change",ie,se),x(w,z)};q(we,w=>{s(n)==="modele"&&w(He)})}f(Ie),f(Be);var Qe=b(Be,2);{var $=w=>{var z=zf(),ie=g(z);f(z),ee(()=>F(ie,`Ontology list unavailable: ${s(m)??""}`)),x(w,z)};q(Qe,w=>{s(m)&&w($)})}f(Le);var Y=b(Le,2);let ge;var Me=g(Y),Ye=g(Me);{var _e=w=>{var z=zt(),ie=et(z);{var Ee=Ne=>{{let $e=be(()=>s(o).trim()||"default");rc(Ne,{get ontologyId(){return s(l)},get workspaceId(){return s($e)},get ontologies(){return s(p)},onSelect:Ue=>{Ce({kind:"ontology",nodeKind:Ue.nodeKind,typeName:Ue.typeName,payload:Ue.payload})}})}},Ae=Ne=>{var $e=Ff();x(Ne,$e)};q(ie,Ne=>{s(k)?Ne(Ee):Ne(Ae,-1)})}x(w,z)},Oe=w=>{var z=Bf(),ie=g(z);{let Ne=be(()=>s(o).trim()||(s(C)==="brain"?"default":null));_l(ie,{get ontologyKey(){return s(r)},get layoutTemplate(){return s(i)},get edgeLinkMode(){return s(a)},get workspaceId(){return s(Ne)},get topK(){return s(j)},get dataSource(){return s(ae)},get brainSeedIds(){return s(v)},onSelect:$e=>{Ce($e)},get facetFilter(){return s(V)},set facetFilter($e){u(V,$e,!0)},get legendBlocks(){return s(Z)},set legendBlocks($e){u(Z,$e,!0)}})}var Ee=b(ie,2);{var Ae=Ne=>{{let $e=be(()=>s(o).trim()||"default"),Ue=be(()=>s(v).length>0);hf(Ne,{get workspaceId(){return s($e)},get graphContext(){return s(de)},get graphFocused(){return s(Ue)},onViewInGraph:ke,onResetGraph:me,onOpenDetail:ve})}};q(Ee,Ne=>{s(C)==="brain"&&s(k)&&Ne(Ae)})}f(z),x(w,z)},Xe=w=>{var z=zt(),ie=et(z);{var Ee=Ne=>{var $e=jf();x(Ne,$e)},Ae=Ne=>{{let $e=be(()=>s(o).trim()||"default"),Ue=be(()=>s(n)==="projections");qu(Ne,{get workspaceId(){return s($e)},get graphContext(){return s(de)},get active(){return s(Ue)},get initialProjectionId(){return s(P)},onViewInGraph:ke})}};q(ie,Ne=>{s(C)==="sqlite-demo"||s(k)!==!0?Ne(Ee):Ne(Ae,-1)})}x(w,z)},it=w=>{var z=zt(),ie=et(z);{var Ee=Ne=>{var $e=Vf();x(Ne,$e)},Ae=Ne=>{{let $e=be(()=>s(o).trim()||"default"),Ue=be(()=>s(n)==="rules");Mf(Ne,{get workspaceId(){return s($e)},get ontologyId(){return s(l)},get active(){return s(Ue)},onViewInGraph:U})}};q(ie,Ne=>{s(C)==="sqlite-demo"||s(k)!==!0?Ne(Ee):Ne(Ae,-1)})}x(w,z)};q(Ye,w=>{s(n)==="modele"?w(_e):s(n)==="donnees"?w(Oe,1):s(n)==="projections"?w(Xe,2):w(it,-1)})}f(Me);var Ve=b(Me,2);{var I=w=>{{let z=be(()=>s(n)==="donnees"&&s(C)==="brain"&&s(k)===!0),ie=be(()=>s(k)===!0),Ee=be(()=>s(o).trim());zd(w,{get showGraphTools(){return s(z)},get brainOnline(){return s(ie)},get ontologyId(){return s(ce)},get workspaceId(){return s(Ee)},onOpenType:nt,get ontologies(){return s(h)},ontologyLabel:he,onOntologyChange:Se,filterEntityType:xe,onSeeds:Ae=>{u(v,Ae,!0)},get legendBlocks(){return s(Z)},get open(){return s(E)},set open(Ae){u(E,Ae,!0)},get sections(){return s(B)},set sections(Ae){u(B,Ae,!0)},get selection(){return s(_)},set selection(Ae){u(_,Ae,!0)},get ontologyKey(){return s(r)},set ontologyKey(Ae){u(r,Ae,!0)},get layoutTemplate(){return s(i)},set layoutTemplate(Ae){u(i,Ae,!0)},get edgeLinkMode(){return s(a)},set edgeLinkMode(Ae){u(a,Ae,!0)},get topK(){return s(c)},set topK(Ae){u(c,Ae,!0)},get facetFilter(){return s(V)},set facetFilter(Ae){u(V,Ae,!0)}})}};q(Ve,w=>{s(n)!=="projections"&&s(n)!=="rules"&&w(I)})}f(Y),f(Ze),ee(()=>{yt=st(Ke,1,"health-badge svelte-1uha8ag",null,yt,{online:s(k)===!0,offline:s(k)===!1,demo:s(C)==="sqlite-demo"}),ne=st(L,1,"svelte-1uha8ag",null,ne,{active:s(n)==="modele"}),T=st(H,1,"svelte-1uha8ag",null,T,{active:s(n)==="donnees"}),J=st(R,1,"svelte-1uha8ag",null,J,{active:s(n)==="projections"}),Pe=st(Q,1,"svelte-1uha8ag",null,Pe,{active:s(n)==="rules"}),Te!==(Te=s(o))&&(ye.value=(ye.__value=s(o))??"",qr(ye,s(o))),ge=st(Y,1,"workspace svelte-1uha8ag",null,ge,{"with-inspector":s(n)!=="projections"&&s(n)!=="rules"})}),ze("click",L,()=>u(n,"modele")),ze("click",H,()=>u(n,"donnees")),ze("click",R,()=>u(n,"projections")),ze("click",Q,()=>u(n,"rules")),ze("change",ye,fe),x(t,Ze),Dn()}jn(["click","change"]);export{Jf as component};