dsh-memory-eternal 0.4.8 → 0.4.9
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.
- package/lib/client.js +10 -8
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -20,9 +20,11 @@ var it=Object.create;var Pe=Object.defineProperty;var st=Object.getOwnPropertyDe
|
|
|
20
20
|
.mc-tabs { display: inline-flex; gap: 4px; padding: 3px; background: var(--dsw-alias-bg-base, #f3f4f6); border-radius: 999px; }
|
|
21
21
|
.mc-tab { border: 0; background: transparent; color: inherit; border-radius: 999px; padding: 5px 14px; font-size: 12px; cursor: pointer; opacity: 0.7; }
|
|
22
22
|
.mc-viewbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
|
|
23
|
-
.mc-
|
|
24
|
-
.mc-
|
|
25
|
-
.mc-
|
|
23
|
+
.mc-rail { width: 54px; flex: none; display: flex; flex-direction: column; gap: 8px; align-items: center; padding-right: 12px; }
|
|
24
|
+
.mc-railbtn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); background: var(--dsw-alias-bg-base, #f3f4f6); color: var(--dsw-alias-label-secondary, #6b7280); cursor: pointer; font-size: 19px; display: flex; align-items: center; justify-content: center; transition: all 0.16s ease; }
|
|
25
|
+
.mc-railbtn:hover { border-color: var(--dsw-alias-brand-primary, #3b82f6); color: var(--dsw-alias-label-primary, #111); }
|
|
26
|
+
.mc-railbtn.active { background: #3b82f6; border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(59,130,246,0.35); }
|
|
27
|
+
.mc-main { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; }
|
|
26
28
|
.mc-tab.active { background: var(--dsw-alias-bg-layer-1, #fff); opacity: 1; font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,0.12); }
|
|
27
29
|
.mc-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
|
|
28
30
|
.mc-chip { border: 1px solid var(--dsw-alias-border-l2, #d1d5db); background: transparent; color: inherit; border-radius: 999px; padding: 4px 12px; font-size: 12px; cursor: pointer; opacity: 0.7; }
|
|
@@ -72,7 +74,7 @@ var it=Object.create;var Pe=Object.defineProperty;var st=Object.getOwnPropertyDe
|
|
|
72
74
|
.me-modal-head .spacer { flex: 1; }
|
|
73
75
|
.me-modal-close { border: 1px solid var(--dsw-alias-border-l2, #d1d5db); background: transparent; color: inherit; border-radius: 8px; width: 30px; height: 30px; line-height: 1; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
|
|
74
76
|
.me-modal-close:hover { background: var(--dsw-alias-bg-layer-1, #f3f4f6); }
|
|
75
|
-
.me-modal-body { flex: 1; padding: 18px 20px; overflow:
|
|
77
|
+
.me-modal-body { flex: 1; padding: 18px 20px; overflow: hidden; display: flex; }
|
|
76
78
|
.me-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1002; display: flex; align-items: center; justify-content: center; padding: 24px; }
|
|
77
79
|
.me-dialog { background: var(--dsw-alias-bg-overlay, #fff); color: var(--dsw-alias-label-primary, #111); border-radius: 14px; max-width: 760px; width: 100%; max-height: 84vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0,0,0,0.3); }
|
|
78
80
|
.me-dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--dsw-alias-border-l1, #e5e7eb); }
|
|
@@ -89,7 +91,7 @@ var it=Object.create;var Pe=Object.defineProperty;var st=Object.getOwnPropertyDe
|
|
|
89
91
|
.me-dialog-body blockquote { border-left: 3px solid var(--dsw-alias-border-l2, #d1d5db); margin: 6px 0; padding: 2px 12px; opacity: 0.85; }
|
|
90
92
|
|
|
91
93
|
/* ---- enhanced graph ---- */
|
|
92
|
-
.me-graph { display: flex; flex-direction: column; gap: 8px;
|
|
94
|
+
.me-graph { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
|
|
93
95
|
.me-graph-toolbar { display: flex; align-items: center; gap: 8px; }
|
|
94
96
|
.me-graph-count { font-size: 12px; opacity: 0.7; }
|
|
95
97
|
.me-graph-canvas { position: relative; flex: 1; min-height: 300px; border-radius: 14px; overflow: hidden; background: radial-gradient(120% 120% at 50% 40%, var(--dsw-alias-bg-layer-2, #f8fafc) 0%, var(--dsw-alias-bg-base, #eef2f7) 100%); border: 1px solid var(--dsw-alias-border-l1, #e5e7eb); cursor: grab; touch-action: none; user-select: none; }
|
|
@@ -109,12 +111,12 @@ var it=Object.create;var Pe=Object.defineProperty;var st=Object.getOwnPropertyDe
|
|
|
109
111
|
.me-graph-ctxmenu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: none; border-radius: 7px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
|
|
110
112
|
.me-graph-ctxmenu button:hover { background: rgba(255,255,255,0.1); }
|
|
111
113
|
.me-graph-hint { font-size: 11px; opacity: 0.6; margin-left: auto; }
|
|
112
|
-
`;function yt(o){o.effect(()=>o.locale.register(Be,{zh:ft,en:bt}),"memory-eternal: locale");let i=o.locale.bind(Be);o.effect(()=>o.slots.inject("settings.section",()=>o.slots.register({name:"settings.section",id:Be,order:25,label:()=>i("nav"),locale:Be,inject:()=>({})},()=>d.default.createElement(nt,{t:i,inModal:!1}))),"memory-eternal: settings section"),o.effect(()=>o.slots.inject("sidebar.footer.action",()=>o.slots.register({name:"sidebar.footer.action",id:`${Be}:footer`,order:100,label:()=>i("nav"),locale:Be,inject:()=>({})},g=>d.default.createElement(xt,{t:i,wide:!(g&&g.wide===!1)}))),"memory-eternal: sidebar footer action")}function xt({t:o,wide:i}){let[g,h]=(0,d.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${i?"":" rail"}`,children:[(0,e.jsx)("style",{children:ve}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>h(!0),"aria-label":o("nav"),title:o("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(at,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:o("nav")})]}),g&&(0,e.jsx)(vt,{t:o,onClose:()=>h(!1)})]})}function at(){return(0,e.jsxs)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[(0,e.jsx)("defs",{children:(0,e.jsxs)("linearGradient",{id:"mg-brain",x1:"0",y1:"0",x2:"1",y2:"1",children:[(0,e.jsx)("stop",{offset:"0%",stopColor:"#FFC46B"}),(0,e.jsx)("stop",{offset:"50%",stopColor:"#F97316"}),(0,e.jsx)("stop",{offset:"100%",stopColor:"#EA580C"})]})}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 0-6.4.1 4.1 4.1 0 0 0-2.7 5.9 4.1 4.1 0 0 0 .6 6.7A4.2 4.2 0 0 0 12 18.2Z"}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 1 6.4.1 4.1 4.1 0 0 1 2.7 5.9 4.1 4.1 0 0 1-.6 6.7A4.2 4.2 0 0 1 12 18.2Z"}),(0,e.jsx)("path",{d:"M12 9.2c-.8-1.4-1.7-2-3.1-2.2M12 9.2c.8-1.4 1.7-2 3.1-2.2M12 12.4c-1.2 1-3.2 1.6-5 1.4M12 12.4c1.2 1 3.2 1.6 5 1.4M12 13.2v4",fill:"none",stroke:"rgba(255,255,255,0.62)",strokeWidth:"1",strokeLinecap:"round"}),(0,e.jsx)("circle",{cx:"12",cy:"8.6",r:"1.1",fill:"rgba(255,255,255,0.85)"})]})}function vt({t:o,onClose:i}){let[g,h]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{let n=
|
|
114
|
+
`;function yt(o){o.effect(()=>o.locale.register(Be,{zh:ft,en:bt}),"memory-eternal: locale");let i=o.locale.bind(Be);o.effect(()=>o.slots.inject("settings.section",()=>o.slots.register({name:"settings.section",id:Be,order:25,label:()=>i("nav"),locale:Be,inject:()=>({})},()=>d.default.createElement(nt,{t:i,inModal:!1}))),"memory-eternal: settings section"),o.effect(()=>o.slots.inject("sidebar.footer.action",()=>o.slots.register({name:"sidebar.footer.action",id:`${Be}:footer`,order:100,label:()=>i("nav"),locale:Be,inject:()=>({})},g=>d.default.createElement(xt,{t:i,wide:!(g&&g.wide===!1)}))),"memory-eternal: sidebar footer action")}function xt({t:o,wide:i}){let[g,h]=(0,d.useState)(!1);return(0,e.jsxs)("div",{className:`me-footer${i?"":" rail"}`,children:[(0,e.jsx)("style",{children:ve}),(0,e.jsxs)("button",{type:"button",className:"me-footer-btn",onClick:()=>h(!0),"aria-label":o("nav"),title:o("nav"),children:[(0,e.jsx)("span",{className:"me-footer-ico","aria-hidden":"true",children:(0,e.jsx)(at,{})}),(0,e.jsx)("span",{className:"me-footer-label",children:o("nav")})]}),g&&(0,e.jsx)(vt,{t:o,onClose:()=>h(!1)})]})}function at(){return(0,e.jsxs)("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:[(0,e.jsx)("defs",{children:(0,e.jsxs)("linearGradient",{id:"mg-brain",x1:"0",y1:"0",x2:"1",y2:"1",children:[(0,e.jsx)("stop",{offset:"0%",stopColor:"#FFC46B"}),(0,e.jsx)("stop",{offset:"50%",stopColor:"#F97316"}),(0,e.jsx)("stop",{offset:"100%",stopColor:"#EA580C"})]})}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 0-6.4.1 4.1 4.1 0 0 0-2.7 5.9 4.1 4.1 0 0 0 .6 6.7A4.2 4.2 0 0 0 12 18.2Z"}),(0,e.jsx)("path",{fill:"url(#mg-brain)",d:"M12 4.5a3.2 3.2 0 0 1 6.4.1 4.1 4.1 0 0 1 2.7 5.9 4.1 4.1 0 0 1-.6 6.7A4.2 4.2 0 0 1 12 18.2Z"}),(0,e.jsx)("path",{d:"M12 9.2c-.8-1.4-1.7-2-3.1-2.2M12 9.2c.8-1.4 1.7-2 3.1-2.2M12 12.4c-1.2 1-3.2 1.6-5 1.4M12 12.4c1.2 1 3.2 1.6 5 1.4M12 13.2v4",fill:"none",stroke:"rgba(255,255,255,0.62)",strokeWidth:"1",strokeLinecap:"round"}),(0,e.jsx)("circle",{cx:"12",cy:"8.6",r:"1.1",fill:"rgba(255,255,255,0.85)"})]})}function vt({t:o,onClose:i}){let[g,h]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{let n=m=>{m.key==="Escape"&&i()};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[i]),(0,e.jsxs)("div",{className:"me-overlay-top",onClick:i,children:[(0,e.jsx)("style",{children:ve}),(0,e.jsx)("div",{className:"me-modal",onClick:n=>n.stopPropagation(),style:g?{position:"fixed",inset:0,width:"100vw",height:"100vh",maxWidth:"100vw",maxHeight:"100vh",borderRadius:0}:{},children:(0,e.jsx)(nt,{t:o,inModal:!0,onClose:i,onFull:()=>h(n=>!n),full:g})})]})}function nt({t:o,inModal:i,onClose:g,onFull:h,full:n}){let[m,T]=(0,d.useState)(null),[M,D]=(0,d.useState)([]),[R,$]=(0,d.useState)(!0),[ne,ee]=(0,d.useState)(""),[V,we]=(0,d.useState)("all"),[O,me]=(0,d.useState)(""),[X,le]=(0,d.useState)("cards"),[de,G]=(0,d.useState)("recent"),[K,u]=(0,d.useState)(null),S=(0,d.useRef)(null),B=(0,d.useRef)(null),[L,ue]=(0,d.useState)(!1),[Q,z]=(0,d.useState)(null),[H,_]=(0,d.useState)(null),[ke,re]=(0,d.useState)(!1),ce=(0,d.useRef)(null),[fe,Ne]=(0,d.useState)(24),Ce=(0,d.useRef)(null);(0,d.useEffect)(()=>{if(X!=="cards")return;let c=Ce.current;if(!c)return;let v=new IntersectionObserver(f=>{f[0]&&f[0].isIntersecting&&Ne(t=>t+24)},{rootMargin:"400px"});return v.observe(c),()=>v.disconnect()},[X,M,V,O]);let Ee=(0,d.useCallback)(async(c=V,v=O)=>{try{$(!0),ee("");let f=new URLSearchParams;c&&c!=="all"&&f.set("kind",c),v.trim()&&f.set("q",v.trim());let Y=await(await fetch(`${A}/cards?${f.toString()}`)).json();Y.ok&&(D(Y.cards||[]),Ne(24))}catch(f){ee(String(f&&f.message?f.message:f))}finally{$(!1)}},[V,O]),te=(0,d.useCallback)(async()=>{try{let[c,v]=await Promise.all([fetch(`${A}/overview`).then(f=>f.json()),fetch(`${A}/cards`).then(f=>f.json())]);c.ok&&T(c),v.ok&&(D(v.cards||[]),Ne(24))}catch(c){ee(String(c&&c.message?c.message:c))}finally{$(!1)}},[]),be=async c=>{try{let f=await(await fetch(`${A}/delete?path=${encodeURIComponent(c)}`)).json();f.ok?(u({ok:!0,msg:o("deleted")}),await te()):u({ok:!1,msg:f.error||o("deleteFail")})}catch{u({ok:!1,msg:o("deleteFail")})}S.current&&clearTimeout(S.current),S.current=setTimeout(()=>u(null),2e3)};(0,d.useEffect)(()=>(te(),()=>{ce.current&&clearTimeout(ce.current)}),[te]);let W=c=>{me(c),ce.current&&clearTimeout(ce.current),ce.current=setTimeout(()=>Ee(V,c),280)},Fe=c=>{we(c),Ee(c,O)},J=async c=>{try{let f=await(await fetch(`${A}/card?path=${encodeURIComponent(c.path||c.id)}`)).json();f.ok&&z({path:f.path,title:c.title,text:f.text})}catch(v){ee(String(v&&v.message?v.message:v))}},l=async(c,v)=>{ue(!0);try{let f=await fetch(`${A}/export`);if(!f.ok)throw new Error("HTTP "+f.status);let t=await f.json();if(!t.ok)throw new Error(t.error||"export failed");let Y,Me,Se;c==="json"?(Me="memory-vault.json",Se="application/json",Y=JSON.stringify(t.cards.map(ie=>({path:ie.path,title:ie.title,kind:ie.kind,text:ie.text})),null,2)):(Me="memory-vault.md",Se="text/markdown;charset=utf-8",Y=t.cards.map(ie=>ie.text.trim()).filter(Boolean).join(`
|
|
113
115
|
|
|
114
116
|
---
|
|
115
117
|
|
|
116
|
-
`));let Ye=new Blob([Y],{type:Se}),he=await Tt(Ye,Me,!1);if(!he.ok){m({ok:!1,msg:o("exportFail")}),ue(!1);return}m({ok:!0,msg:o("exportedTo")+"\uFF1A"+o("defaultDownloads")+" \xB7 "+he.name})}catch(f){m({ok:!1,msg:o("exportFail")+" \xB7 "+(f.message||"")})}finally{ue(!1)}S.current&&clearTimeout(S.current),S.current=setTimeout(()=>m(null),2600)},a=async c=>{let v=c.target.files&&c.target.files[0];if(c.target.value="",!!v){try{let f=await v.text(),Y=await(await fetch(`${A}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:f})).json();Y.ok?(await te(),m({ok:!0,msg:o("importedVault")+"\uFF1A"+(Y.imported||0)+(Y.skipped?o("importedSkipped")+Y.skipped:"")})):m({ok:!1,msg:Y.error||o("importFail")})}catch{m({ok:!1,msg:o("importFail")})}S.current&&clearTimeout(S.current),S.current=setTimeout(()=>m(null),2400)}},N=(0,d.useMemo)(()=>{let c=M.slice();return de==="title"?c.sort((v,f)=>String(v.title||"").localeCompare(String(f.title||""))):de==="hot"?c.sort((v,f)=>(f.weight||f.links||0)-(v.weight||v.links||0)):c.sort((v,f)=>new Date(f.updated||0).getTime()-new Date(v.updated||0).getTime()),c},[M,de]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:ve}),K&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(K.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:K.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:K.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{children:K.msg})]}),i&&(0,e.jsxs)("div",{className:"me-modal-head",children:[(0,e.jsxs)("div",{className:"me-modal-title",children:[(0,e.jsx)("span",{className:"me-wicon",children:(0,e.jsx)(at,{})}),(0,e.jsx)("h2",{children:o("memoryTitle")}),(0,e.jsx)("span",{children:o("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),h&&(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:h,"aria-label":o(n?"exitFull":"fullscreen"),children:n?"\u2750":"\u26F6"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:g,"aria-label":o("close"),children:"\u2715"})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:"mc-viewbar",children:[(0,e.jsxs)("button",{type:"button",className:`mc-view${X==="cards"?" active":""}`,onClick:()=>le("cards"),children:["\u{1F4C7} ",o("cardsTab")]}),(0,e.jsxs)("button",{type:"button",className:`mc-view${X==="graph"?" active":""}`,onClick:()=>le("graph"),children:["\u{1F578} ",o("graphTab")]})]}),(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(Ae,{label:o("total"),value:u?u.total:"\u2014"}),(0,e.jsx)(Ae,{label:o("recent"),value:u?u.recent:"\u2014"}),(0,e.jsx)(Ae,{label:o("tags"),value:u?u.tags:"\u2014"}),(0,e.jsx)(Ae,{label:o("cardCount"),value:u?u.byKind?.knowledge??0:"\u2014"})]}),(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:o("searchPlaceholder"),value:O,onChange:c=>W(c.target.value)}),(0,e.jsx)("input",{ref:B,type:"file",accept:".json,application/json",style:{display:"none"},onChange:a}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>B.current&&B.current.click(),children:o("importVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:L,onClick:()=>l("md"),children:o(L?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:L,onClick:()=>l("json"),children:o(L?"exporting":"exportJson")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:ke,onChange:c=>re(c.target.checked)}),o("crossVault")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>_({tab:"stats"}),children:o("manage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>te(),children:o("refresh")})]}),X==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[ht.map(c=>(0,e.jsx)("button",{type:"button",className:`mc-chip${V===c?" active":""}`,onClick:()=>Fe(c),children:o(c==="all"?"all":xe[c])},c)),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:o("sortRecent")},{key:"title",label:o("sortTitle")},{key:"hot",label:o("sortHot")}].map(c=>(0,e.jsx)("button",{type:"button",className:`mc-chip${de===c.key?" active":""}`,onClick:()=>G(c.key),children:c.label},c.key))]}),ne&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",ne]}),X==="cards"?R&&!M.length?(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}):M.length===0?(0,e.jsx)("div",{className:"mc-empty",children:o("empty")}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mc-grid",children:N.slice(0,fe).map(c=>(0,e.jsx)(wt,{card:c,t:o,query:O.trim(),onOpen:J,onDelete:be},c.path))}),N.length>fe&&(0,e.jsx)("div",{ref:Ne,style:{height:1}})]}):(0,e.jsx)(Nt,{t:o,onOpen:J,all:ke}),Q&&(0,e.jsx)(Ct,{t:o,card:Q,onClose:()=>z(null),onDelete:c=>{z(null),be(c)}}),H&&(0,e.jsx)(kt,{t:o,tab:H.tab,onTab:c=>_({tab:c}),onClose:()=>_(null),onReload:()=>te()})]})]})}var Ae=({label:o,value:i})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:i}),(0,e.jsx)("span",{children:o})]}),wt=({card:o,t:i,onOpen:g,query:h,onDelete:n})=>(0,e.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>g(o),children:[(0,e.jsxs)("h4",{children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:We[o.kind]||We.other}}),h?ot(o.title,h):o.title,zt(o.updated)&&(0,e.jsx)("span",{className:"mc-new",children:i("newBadge")})]}),(0,e.jsx)("p",{children:h?ot(o.summary||"",h):o.summary||""}),o.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:o.tags.slice(0,4).map(u=>(0,e.jsx)("span",{className:"mc-tag",children:u},u))}),(0,e.jsxs)("footer",{children:[(0,e.jsx)("span",{children:i(xe[o.kind])}),(0,e.jsx)("span",{children:rt(o.updated)}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:i("delete"),onClick:u=>{u.stopPropagation(),window.confirm(i("deleteConfirm"))&&n&&n(o.path)},children:"\u2715"})]})]});function kt({t:o,tab:i,onTab:g,onClose:h,onReload:n}){let[u,T]=(0,d.useState)(null),[M,D]=(0,d.useState)(null),[R,$]=(0,d.useState)(null),[ne,ee]=(0,d.useState)(""),[V,we]=(0,d.useState)(""),O=(0,d.useCallback)(async()=>{try{let m=await fetch(`${A}/todayBrief`).then(S=>S.json());ee(m.ok&&m.brief||"")}catch{}},[]),me=(0,d.useCallback)(async()=>{if(!(!M||!M.merge||!M.merge.length)&&window.confirm(o("mergeAllConfirm"))){we("merge");try{let m={},S=z=>m[z]===void 0?z:m[z]=S(m[z]),B=(z,H)=>{m[S(z)]=S(H)},L=new Set;for(let z of M.merge)L.add(z.a.path),L.add(z.b.path),B(z.a.path,z.b.path);let ue={};for(let z of L){let H=S(z);(ue[H]=ue[H]||[]).push(z)}let Q=0;for(let z of Object.values(ue)){if(z.length<2)continue;(await fetch(`${A}/merge?paths=${encodeURIComponent(z.join(","))}`).then(_=>_.json())).ok&&Q++}await X(),n&&n()}catch{}we("")}},[M,X,n,o]);async function X(){try{let[m,S,B]=await Promise.all([fetch(`${A}/stats`).then(L=>L.json()),fetch(`${A}/optimize`).then(L=>L.json()),fetch(`${A}/budget`).then(L=>L.json())]);m.ok&&T(m),S.ok&&D(S),B.ok&&$(B)}catch{}}(0,d.useEffect)(()=>{X()},[]);let le=async(m,S)=>{if(window.confirm(o("mergeConfirm")))try{(await fetch(`${A}/merge?paths=${encodeURIComponent(m+","+S)}`).then(L=>L.json())).ok&&(await X(),n&&n())}catch{}},de=async m=>{if(window.confirm(o("deleteConfirm")))try{(await fetch(`${A}/delete?path=${encodeURIComponent(m)}`).then(B=>B.json())).ok&&(await X(),n&&n())}catch{}},G=["project","knowledge","content","prompt","business","tool","mistake"],K=({title:m,kind:S,updated:B,path:L})=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Le.colors[S]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:rt(B)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>de(L),children:[o("delete")," \u2715"]})]});return(0,e.jsxs)("div",{className:"me-overlay",onClick:h,children:[(0,e.jsx)("style",{children:ve}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720,width:"94vw",maxHeight:"86vh"},onClick:m=>m.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${i==="stats"?" active":""}`,onClick:()=>g("stats"),children:o("tabUsage")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${i==="optimize"?" active":""}`,onClick:()=>g("optimize"),children:o("tabOptimize")})]}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:h,children:o("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{overflow:"auto"},children:[i==="stats"&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:o("todayBriefLabel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:O,children:o("todayBrief")}),ne&&(0,e.jsx)("pre",{style:{margin:0,fontSize:12,width:"100%",whiteSpace:"pre-wrap",opacity:.85},children:ne})]}),u&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:u.total}),(0,e.jsx)("span",{children:o("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:u.today}),(0,e.jsx)("span",{children:o("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:u.week}),(0,e.jsx)("span",{children:o("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:u.tags}),(0,e.jsx)("span",{children:o("tags")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("byKind")}),(0,e.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:G.map(m=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Le.colors[m]||"#666"}}),o(xe[m]),": ",u.byKind?.[m]||0]},m))})]}),R&&(R.budgetChars||R.recallLimit||R.embedding)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,e.jsx)("b",{children:o("budgetLabel")}),"\uFF1A",o("budgetChars")," ",(0,e.jsx)("b",{children:R.budgetChars||8e4})," \xB7 ",o("recallLimitLabel")," ",(0,e.jsx)("b",{children:R.recallLimit||5})," \xB7 ",o("embeddingLabel")," ",R.embedding?"ON":"OFF"]}),(0,e.jsxs)("div",{className:"mc-card",children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("todayList"),"\uFF08",u.todayCards?.length||0,"\uFF09"]}),u.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:u.todayCards.map(m=>(0,e.jsx)(K,{title:m.title,kind:m.kind,updated:m.updated,path:m.path},m.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})]})]}),i==="optimize"&&(0,e.jsx)("div",{children:M&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:M.merge?.length?o("mergePairs"):o("noOptimize")}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),M.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!V,onClick:me,children:o(V==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("mergePairs")}),M.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:M.merge.map((m,S)=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsxs)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[m.a.title," \u21C4 ",m.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(m.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>le(m.a.path,m.b.path),children:o("mergeNow")})]},S))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:o("noOptimize")}),(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("staleCards"),"\uFF08",M.stale?.length||0,"\uFF09"]}),M.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:M.stale.map(m=>(0,e.jsx)(K,{title:m.title,kind:"other",updated:m.updated,path:m.path},m.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})})]})]})]})}function Ct({t:o,card:i,onClose:g,onDelete:h}){(0,d.useEffect)(()=>{let M=D=>{D.key==="Escape"&&g()};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[g]);let[n,u]=(0,d.useState)(!1),T=(i.text||"").length>460;return(0,e.jsxs)("div",{className:"me-overlay",onClick:g,children:[(0,e.jsx)("style",{children:ve}),(0,e.jsxs)("div",{className:"me-dialog",onClick:M=>M.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:i.title}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[T&&(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>u(M=>!M),children:o(n?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(o("deleteConfirm"))&&h&&h(i.path)},children:o("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:g,children:o("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:n?{}:{maxHeight:300,overflow:"hidden"},dangerouslySetInnerHTML:{__html:Bt(i.text)}})]})]})}function Nt({t:o,onOpen:i,all:g}){let[h,n]=(0,d.useState)(null),[u,T]=(0,d.useState)(""),M=(0,d.useCallback)(async()=>{try{let $=await(await fetch(`${A}/graph${g?"?all=1":""}`)).json();n($.ok?$:null),T("")}catch(R){T(String(R&&R.message?R.message:R))}},[g]);(0,d.useEffect)(()=>{let R=!0;return fetch(`${A}/graph${g?"?all=1":""}`).then($=>$.json()).then($=>{R&&n($.ok?$:null)}).catch($=>{R&&T(String($&&$.message?$.message:$))}),()=>{R=!1}},[g]);let D=(0,d.useCallback)(async R=>{try{let ne=await(await fetch(`${A}/delete?path=${encodeURIComponent(R)}`)).json();return ne&&ne.ok?(await M(),!0):!1}catch{return!1}},[M]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:ve}),u&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",u]}),!h&&!u&&(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}),h&&h.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:o("emptyGraph")}),h&&h.nodes.length>0&&(0,e.jsx)(St,{nodes:h.nodes,edges:h.edges,onOpen:i,onDelete:D,t:o,countLabel:`${h.nodes.length} ${o("nodes")} \xB7 ${Mt(h.edges)} ${o("edges")}`})]})}function Mt(o){let i=new Set;for(let g of o||[])i.add([g.source,g.target].sort().join("|"));return i.size}var Le={colors:{project:"#3B82F6",knowledge:"#10B981",content:"#F59E0B",prompt:"#A855F7",business:"#EC4899",tool:"#06B6D4",mistake:"#EF4444",other:"#6B7280"},shapes:{project:"circle",knowledge:"circle",content:"rect",prompt:"diamond",business:"hexagon",tool:"circle",mistake:"diamond",other:"circle"}};function St({nodes:o,edges:i,onOpen:g,onDelete:h,t:n,countLabel:u}){let T=(0,d.useRef)(null),M=(0,d.useRef)(null),D=(0,d.useRef)(null),R=(0,d.useRef)(null),$=(0,d.useRef)(null),ne=(0,d.useRef)(g);(0,d.useEffect)(()=>{ne.current=g},[g]);let ee=(0,d.useRef)(h);(0,d.useEffect)(()=>{ee.current=h},[h]);let[V,we]=(0,d.useState)(""),[O,me]=(0,d.useState)(null),X=(0,d.useRef)("");(0,d.useEffect)(()=>{X.current=V.trim().toLowerCase()},[V]);let[le,de]=(0,d.useState)("all"),G=(0,d.useRef)("all"),[K,m]=(0,d.useState)(!1),S=(0,d.useRef)(!1),[B,L]=(0,d.useState)(null);(0,d.useEffect)(()=>{G.current=le},[le]),(0,d.useEffect)(()=>{S.current=K},[K]);let ue=(()=>{let l=V.trim().toLowerCase();return!!l&&!o.some(a=>(a.title||a.name||"").toLowerCase().includes(l)||String(a.kind||"").toLowerCase().includes(l)||String(xe[a.kind]||"").toLowerCase().includes(l))})();(0,d.useEffect)(()=>{let l=D.current;l&&l.wake&&l.wake()},[V]),(0,d.useEffect)(()=>{let l=D.current;l&&l.render&&l.render()},[le,K]);let Q=(0,d.useRef)(null),[z,H]=(0,d.useState)([]),[_,ke]=(0,d.useState)(null),[re,ce]=(0,d.useState)(!1),[fe,Ce]=(0,d.useState)(null),[Ne,Ee]=(0,d.useState)(""),te=(0,d.useRef)(null),be=(0,d.useRef)(null),W=(l,a=!0)=>{te.current&&clearTimeout(te.current),Ce({msg:l,ok:a}),te.current=setTimeout(()=>Ce(null),1900)},Fe=l=>{Ee(l),be.current&&clearTimeout(be.current),be.current=setTimeout(()=>Ee(""),1600)};(0,d.useEffect)(()=>()=>{te.current&&clearTimeout(te.current),be.current&&clearTimeout(be.current)},[]);let J=(0,d.useMemo)(()=>o.reduce((l,a)=>(l[a.id]=a,l),{}),[o]);return(0,d.useEffect)(()=>{let l=T.current;if(!l||o.length===0)return;let a=l.getContext("2d");if(!a)return;let N=Math.max(1,window.devicePixelRatio||1),c=()=>document.documentElement.getAttribute("data-theme")==="dark",v={};i.forEach(r=>{v[r.source]=(v[r.source]||0)+1,v[r.target]=(v[r.target]||0)+1});let f=Math.max(1,...Object.values(v)),t={nodes:o.map(r=>({id:r.id,name:r.title||"",type:r.kind||"other",r:9+Math.min(10,(v[r.id]||0)/f*8),x:0,y:0,vx:0,vy:0})),edges:i.map(r=>({sourceNodeId:r.source,targetNodeId:r.target,weight:1})),panX:0,panY:0,zoom:1,running:!0,raf:0,tickCount:0,quietTicks:0,dragNode:null,selectedId:null,mouseX:0,mouseY:0,w:0,h:0,dpr:N,ctx:a,multi:[],marquee:null};t.domain=o,t.domainById=o.reduce((r,b)=>(r[b.id]=b,r),{}),t.nodes.forEach((r,b)=>{let p=b/t.nodes.length*Math.PI*2-Math.PI/2;r.x=Math.cos(p)*60,r.y=Math.sin(p)*60});let Y=[...new Set(t.nodes.map(r=>r.type))];t.clustered=Y.length>1,t.typeCenters={},Y.forEach((r,b)=>{let p=b/Y.length*Math.PI*2-Math.PI/2;t.typeCenters[r]={x:Math.cos(p)*160,y:Math.sin(p)*160}}),D.current=t;let Me=()=>{let r=l.clientWidth,b=l.clientHeight;t.w=r,t.h=b,l.width=r*N,l.height=b*N,a.setTransform(N,0,0,N,0,0)};Me();let Se=new ResizeObserver(Me);Se.observe(l.parentElement);let Ye=(r,b)=>r&&r.length>b?r.slice(0,b)+"\u2026":r,he=(r,b,p,y)=>{if(a.beginPath(),y==="rect")a.rect(r-p,b-p*.75,p*2,p*1.5);else if(y==="diamond")a.moveTo(r,b-p),a.lineTo(r+p,b),a.lineTo(r,b+p),a.lineTo(r-p,b),a.closePath();else if(y==="hexagon"){for(let x=0;x<6;x++){let C=Math.PI/3*x-Math.PI/2,E=r+p*Math.cos(C),s=b+p*Math.sin(C);x===0?a.moveTo(E,s):a.lineTo(E,s)}a.closePath()}else a.arc(r,b,p,0,Math.PI*2)},ie=()=>{if(!t.nodes.length)return;let r=1/0,b=-1/0,p=1/0,y=-1/0;t.nodes.forEach(I=>{r=Math.min(r,I.x),b=Math.max(b,I.x),p=Math.min(p,I.y),y=Math.max(y,I.y)});let x=36,C=b-r+x*2,E=y-p+x*2,s=Math.min(t.w/C,t.h/E);t.zoom=Math.max(.45,Math.min(2.4,s*1.22)),t.panX=t.w/2-(r+b)/2*t.zoom,t.panY=t.h/2-(p+y)/2*t.zoom};R.current=ie;let qe=()=>{a.clearRect(0,0,t.w,t.h),t.searchTerm=X.current,t.kindFilter=G.current,t.timeMode=S.current;let r=t.kindFilter,b=s=>String(s||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");a.save(),a.strokeStyle=c()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",a.lineWidth=.5;for(let s=0;s<t.w;s+=24)a.beginPath(),a.moveTo(s,0),a.lineTo(s,t.h),a.stroke();for(let s=0;s<t.h;s+=24)a.beginPath(),a.moveTo(0,s),a.lineTo(t.w,s),a.stroke();a.restore(),a.save(),a.translate(t.panX,t.panY),a.scale(t.zoom,t.zoom);let p={};t.nodes.forEach(s=>p[s.id]=s);let y=t.nodes.length>40,x=y?1.5:.55,C=t.selectedId||t.hoverId;t.edges.forEach(s=>{let I=p[s.sourceNodeId],F=p[s.targetNodeId];if(!I||!F)return;if(r!=="all"){let Z=t.domainById[s.sourceNodeId]&&t.domainById[s.sourceNodeId].kind,Qe=t.domainById[s.targetNodeId]&&t.domainById[s.targetNodeId].kind;if(Z!==r&&Qe!==r)return}let w=F.x-I.x,k=F.y-I.y,j=Math.sqrt(w*w+k*k)||1,P=y?12:18,q=-k/j*P,oe=w/j*P,U=(I.x+F.x)/2+q,pe=(I.y+F.y)/2+oe,ae=Le.colors[t.domainById[I.id]&&t.domainById[I.id].kind||"other"],ge=C&&(s.sourceNodeId===C||s.targetNodeId===C),Ie=C?ge?.6:.08:y?.14:.24,je=parseInt(ae.slice(1,3),16),De=parseInt(ae.slice(3,5),16),Ze=parseInt(ae.slice(5,7),16);a.strokeStyle="rgba("+je+","+De+","+Ze+","+Ie+")",a.lineWidth=ge?1.6+(s.weight||1):.8+(s.weight||1)*.5,a.beginPath(),a.moveTo(I.x,I.y),a.quadraticCurveTo(U,pe,F.x,F.y),a.stroke()});let E=[];if(t.nodes.forEach(s=>{let I=t.domainById[s.id]||{},F=I.kind||"other",w=t.timeMode?It(I.updated):Le.colors[F],k=Le.shapes[F],j=t.selectedId===s.id,P=t.hoverId===s.id,q=t.searchTerm||"",oe=!q||(s.name||"").toLowerCase().includes(q)||String(xe[F]||"").toLowerCase().includes(q)||String(F).toLowerCase().includes(q),U=r==="all"||F===r,pe=C&&s.id!==C&&!t.edges.some(Z=>Z.sourceNodeId===C&&Z.targetNodeId===s.id||Z.targetNodeId===C&&Z.sourceNodeId===s.id)||q&&!oe||!U;a.save(),a.globalAlpha=pe?.08:1,(j||P)&&(a.shadowColor=w,a.shadowBlur=j?20:14),he(s.x,s.y,s.r,k);let ae=parseInt(w.slice(1,3),16),ge=parseInt(w.slice(3,5),16),Ie=parseInt(w.slice(5,7),16),je=a.createRadialGradient(s.x-s.r*.3,s.y-s.r*.3,0,s.x,s.y,s.r*1.2);je.addColorStop(0,"rgba("+Math.min(255,ae+70)+","+Math.min(255,ge+70)+","+Math.min(255,Ie+70)+",0.95)"),je.addColorStop(1,w),a.fillStyle=je,a.fill(),a.restore(),j?(a.save(),he(s.x,s.y,s.r+3,k),a.strokeStyle=w,a.lineWidth=3,a.shadowColor=w,a.shadowBlur=12,a.stroke(),a.restore()):P?(a.save(),he(s.x,s.y,s.r+2,k),a.strokeStyle=w,a.lineWidth=2,a.stroke(),a.restore()):q&&oe?(a.save(),he(s.x,s.y,s.r+2,k),a.strokeStyle="#e11d48",a.lineWidth=2,a.stroke(),a.restore()):t.multi.indexOf(s.id)>=0&&(a.save(),he(s.x,s.y,s.r+2,k),a.strokeStyle="#60a5fa",a.lineWidth=2,a.shadowColor="#60a5fa",a.shadowBlur=8,a.stroke(),a.restore());let De=Ye(s.name,16);if((j||P||t.zoom>x||!y&&t.zoom>.6)&&U){let Z=1/t.zoom;a.font="500 "+(12*Z).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";let ye=a.measureText(De).width+16*Z,Oe=18*Z,ze=s.y+s.r+8*Z,et=!0;for(let Te of E)if(s.x-ye/2<Te.x+Te.w&&s.x+ye/2>Te.x&&ze<Te.y+Te.h&&ze+Oe>Te.y){et=!1;break}if(!et&&!j&&!P)return;E.push({x:s.x-ye/2,y:ze,w:ye,h:Oe}),a.fillStyle=c()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",a.beginPath(),a.roundRect?a.roundRect(s.x-ye/2,ze,ye,Oe,4*Z):a.rect(s.x-ye/2,ze,ye,Oe),a.fill(),a.strokeStyle=c()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",a.lineWidth=1*Z,a.stroke(),a.fillStyle=c()?j||P?"#eee":"#bbb":j||P?"#111":"#444",a.textAlign="center",a.fillText(De,s.x,ze+13*Z)}}),a.restore(),t.marquee){let s=t.marquee,I=Math.min(s.sx,s.ex),F=Math.min(s.sy,s.ey),w=Math.abs(s.ex-s.sx),k=Math.abs(s.ey-s.sy);a.save(),a.setLineDash([4,4]),a.strokeStyle="rgba(96,165,250,0.9)",a.lineWidth=1,a.fillStyle="rgba(96,165,250,0.12)",a.fillRect(I,F,w,k),a.strokeRect(I,F,w,k),a.restore()}if(t.hoverId&&Q.current){let s=t.domainById[t.hoverId],I=t.nodes.find(function(F){return F.id===t.hoverId});if(s&&I){let F=t.edges.filter(function(j){return j.sourceNodeId===s.id||j.targetNodeId===s.id}).length,w=I.x*t.zoom+t.panX,k=I.y*t.zoom+t.panY;Q.current.style.display="block",Q.current.style.left=w+14+"px",Q.current.style.top=k-6+"px",Q.current.innerHTML="<b>"+b(s.title||s.name||"")+'</b><br/><span style="opacity:.8">'+b(s.kind||"")+" \xB7 "+F+" \u8FDE\u63A5</span>"}}else Q.current&&(Q.current.style.display="none")},se=()=>{t.running=!0,t.raf||(t.raf=requestAnimationFrame(Xe))};t.wake=se,t.render=qe;let Ue=()=>{let r=t.nodes.length;t.tickCount++;let p=.9-Math.min(.4,t.tickCount/1500),y=r>1e3?3e3:r>100?2e3:r>50?1200:800,x=r>100?.002:.005,C=r>1e3?.012:r>100?.005:.01,E=r>1e3?6:r>200?12:24,s={};t.nodes.forEach(w=>s[w.id]=w);for(let w=0;w<r;w++){if(t.dragNode===t.nodes[w])continue;let k=t.nodes[w],j=0,P=0;for(let U=0;U<r;U++){if(w===U)continue;let pe=k.x-t.nodes[U].x,ae=k.y-t.nodes[U].y,ge=Math.sqrt(pe*pe+ae*ae)||1,Ie=y/(ge*ge);j+=pe/ge*Ie,P+=ae/ge*Ie}if(t.clustered&&t.typeCenters[k.type]){let U=t.typeCenters[k.type];j+=(U.x-k.x)*.006,P+=(U.y-k.y)*.006}else j-=k.x*C,P-=k.y*C;let q=(k.vx+j)*p,oe=(k.vy+P)*p;q=Math.max(-E,Math.min(E,q)),oe=Math.max(-E,Math.min(E,oe)),k.vx=q,k.vy=oe}t.edges.forEach(w=>{let k=s[w.sourceNodeId],j=s[w.targetNodeId];if(!k||!j)return;let P=j.x-k.x,q=j.y-k.y,oe=Math.sqrt(P*P+q*q)||1,U=(oe-100)*x,pe=P/oe*U,ae=q/oe*U;t.dragNode!==k&&(k.vx+=pe,k.vy+=ae),t.dragNode!==j&&(j.vx-=pe,j.vy-=ae)});let I=0;t.nodes.forEach(w=>{t.dragNode!==w&&(w.x+=w.vx,w.y+=w.vy,I+=w.vx*w.vx+w.vy*w.vy)}),t.autoFitPending&&t.tickCount>45&&(t.autoFitPending=!1,ie()),(r?Math.sqrt(I/r):0)<.05&&t.tickCount>60&&!t.dragNode?t.quietTicks=(t.quietTicks|0)+1:t.quietTicks=0},Xe=()=>{if(t.running){try{Ue(),qe()}catch{}if(t.quietTicks>30){t.raf=0;return}t.raf=requestAnimationFrame(Xe)}},Re=(r,b)=>{let p=l.getBoundingClientRect();return{x:(r-p.left-t.panX)/t.zoom,y:(b-p.top-t.panY)/t.zoom}},$e=(r,b,p)=>Math.max(b,Math.min(p,r)),Ke=r=>{t.mouseX=r.clientX,t.mouseY=r.clientY;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let x=t.nodes[y];if(G.current!=="all"&&(t.domainById[x.id]&&t.domainById[x.id].kind)!==G.current)continue;let C=x.x-b.x,E=x.y-b.y;if(C*C+E*E<x.r*x.r+36){p=x.id;break}}p!==t.hoverId&&(t.hoverId=p,se())},He=r=>{if(r.button!==0)return;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let x=t.nodes[y];if(G.current!=="all"&&(t.domainById[x.id]&&t.domainById[x.id].kind)!==G.current)continue;let C=x.x-b.x,E=x.y-b.y;if(C*C+E*E<x.r*x.r+25){p=x;break}}if(r.shiftKey){t.marquee={sx:r.clientX,sy:r.clientY,ex:r.clientX,ey:r.clientY};return}t.dragStart={x:r.clientX,y:r.clientY,px:t.panX,py:t.panY},t.dragging=!1,t.dragNode=p||null,p&&(t.dragOffset={dx:p.x-b.x,dy:p.y-b.y})},Ve=r=>{if(t.marquee){t.marquee.ex=r.clientX,t.marquee.ey=r.clientY,se();return}if(!t.dragStart)return;let b=r.clientX-t.dragStart.x,p=r.clientY-t.dragStart.y;if(Math.abs(b)+Math.abs(p)>3&&(t.dragging=!0),t.dragNode){let y=Re(r.clientX,r.clientY);t.dragNode.x=y.x+t.dragOffset.dx,t.dragNode.y=y.y+t.dragOffset.dy,se()}else t.dragging&&(t.panX=$e(t.dragStart.px+b,-1e5,1e5),t.panY=$e(t.dragStart.py+p,-1e5,1e5),se())},Ge=r=>{if(t.marquee){let p=t.marquee;t.marquee=null;let y=l.getBoundingClientRect(),x=Math.min(p.sx,p.ex)-y.left,C=Math.max(p.sx,p.ex)-y.left,E=Math.min(p.sy,p.ey)-y.top,s=Math.max(p.sy,p.ey)-y.top,I=t.nodes.filter(F=>{let w=F.x*t.zoom+t.panX,k=F.y*t.zoom+t.panY;return w>=x&&w<=C&&k>=E&&k<=s}).map(F=>F.id);t.multi=I,H(I),se();return}if(t.dragStart&&!t.dragging){let p=Re(r.clientX,r.clientY),y=null;for(let x=t.nodes.length-1;x>=0;x--){let C=t.nodes[x];if(G.current!=="all"&&(t.domainById[C.id]&&t.domainById[C.id].kind)!==G.current)continue;let E=C.x-p.x,s=C.y-p.y;if(E*E+s*s<C.r*C.r+20){y=C;break}}y?(t.selectedId=y.id,me(y.id),se()):(t.selectedId=null,t.hoverId=null,r.shiftKey||(t.multi=[],H([])),me(null),se())}t.dragStart=null,t.dragging=!1,t.dragNode=null},_e=r=>{r.preventDefault();let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let x=t.nodes[y];if(G.current!=="all"&&(t.domainById[x.id]&&t.domainById[x.id].kind)!==G.current)continue;let C=x.x-b.x,E=x.y-b.y;if(C*C+E*E<x.r*x.r+25){p=x;break}}if(p){let y=t.domainById[p.id];y&&L({x:r.clientX,y:r.clientY,id:p.id,path:y.id,title:y.title})}else L(null)},Je=r=>{r.preventDefault();let b=l.getBoundingClientRect(),p=(r.clientX-b.left-t.panX)/t.zoom,y=(r.clientY-b.top-t.panY)/t.zoom,x=Math.max(.3,Math.min(3,t.zoom*(r.deltaY<0?1.1:1/1.1)));t.panX=$e(t.panX+p*(t.zoom-x),-1e5,1e5),t.panY=$e(t.panY+y*(t.zoom-x),-1e5,1e5),t.zoom=x,se()};l.addEventListener("mousemove",Ke),l.addEventListener("mousedown",He),window.addEventListener("mousemove",Ve),window.addEventListener("mouseup",Ge),l.addEventListener("wheel",Je,{passive:!1}),l.addEventListener("contextmenu",_e),$.current=()=>{t.selectedId=null,t.hoverId=null,t.multi=[],H([]),ie(),se()};for(let r=0;r<200;r++)Ue();return ie(),se(),()=>{t.running=!1,t.raf&&cancelAnimationFrame(t.raf),Se.disconnect(),l.removeEventListener("mousemove",Ke),l.removeEventListener("mousedown",He),window.removeEventListener("mousemove",Ve),window.removeEventListener("mouseup",Ge),l.removeEventListener("wheel",Je),l.removeEventListener("contextmenu",_e)}},[o,i]),(0,e.jsxs)("div",{className:"me-graph",ref:M,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[o.length," ",n("nodes")," \xB7 ",i.length," ",n("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",className:"mc-btn",style:{padding:"6px 10px",minWidth:140},placeholder:n("search"),value:V,onChange:l=>we(l.target.value)}),(0,e.jsx)("button",{type:"button",className:`mc-btn${K?" me-on":""}`,onClick:()=>m(l=>!l),children:n("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let l=T.current;if(l)try{l.toBlob(a=>{a&&ke({url:URL.createObjectURL(a),blob:a})},"image/png")}catch{}},children:n("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>R.current&&R.current(),children:n("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{me(null),de("all"),$.current&&$.current()},children:n("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:T,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:Q,style:{display:"none",position:"absolute",zIndex:4,pointerEvents:"none",background:"rgba(28,28,32,0.88)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:8,padding:"7px 10px",fontSize:12,maxWidth:220,boxShadow:"0 8px 24px rgba(0,0,0,.2)"}}),(0,e.jsxs)("div",{className:"me-graph-legend",style:{position:"absolute",left:12,bottom:8,zIndex:2},children:[K?[{c:"#10b981",l:n("timeNew")},{c:"#f59e0b",l:n("timeRecent")},{c:"#f97316",l:n("timeMonth")},{c:"#94a3b8",l:n("timeOld")}].map(l=>(0,e.jsxs)("span",{className:"lg",children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:l.c}}),l.l]},l.c)):Object.keys(We).map(l=>(0,e.jsxs)("button",{type:"button",className:`lg${le===l?" active":""}`,onClick:()=>de(a=>a===l?"all":l),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Le.colors[l]||We[l]}}),n(xe[l])]},l)),!K&&le!=="all"&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",onClick:()=>de("all"),children:[n("clearFilter")," \u2715"]})]}),ue&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:n("noMatch")}),B&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>L(null)}),B&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:B.x,top:B.y,zIndex:31},onMouseDown:l=>l.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{ne.current({path:B.path,title:B.title}),L(null)},children:n("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{B.id&&(D.current.selectedId=B.id,me(B.id)),L(null);let l=D.current;l&&l.wake&&l.wake()},children:n("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(B.title||"")}catch{}L(null),W(n("copied"))},children:n("copyName")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let l=B.path;L(null),window.confirm(n("deleteConfirm"))&&(async()=>{try{(ee.current?await ee.current(l):!1)?W(n("deleted")):W(n("deleteFail"),!1)}catch{W(n("deleteFail"),!1)}})()},children:n("delete")})]}),z.length>0&&(0,e.jsxs)("div",{style:{position:"absolute",left:10,top:10,zIndex:3,display:"flex",gap:8,alignItems:"center",background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:"6px 10px",fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsxs)("span",{style:{fontWeight:700},children:[z.length," ",n("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let a=z.map(f=>J[f]).filter(Boolean).map(f=>f.title||f.name).join(`
|
|
117
|
-
`),
|
|
118
|
+
`));let Ye=new Blob([Y],{type:Se}),he=await Tt(Ye,Me,!1);if(!he.ok){u({ok:!1,msg:o("exportFail")}),ue(!1);return}u({ok:!0,msg:o("exportedTo")+"\uFF1A"+o("defaultDownloads")+" \xB7 "+he.name})}catch(f){u({ok:!1,msg:o("exportFail")+" \xB7 "+(f.message||"")})}finally{ue(!1)}S.current&&clearTimeout(S.current),S.current=setTimeout(()=>u(null),2600)},a=async c=>{let v=c.target.files&&c.target.files[0];if(c.target.value="",!!v){try{let f=await v.text(),Y=await(await fetch(`${A}/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:f})).json();Y.ok?(await te(),u({ok:!0,msg:o("importedVault")+"\uFF1A"+(Y.imported||0)+(Y.skipped?o("importedSkipped")+Y.skipped:"")})):u({ok:!1,msg:Y.error||o("importFail")})}catch{u({ok:!1,msg:o("importFail")})}S.current&&clearTimeout(S.current),S.current=setTimeout(()=>u(null),2400)}},C=(0,d.useMemo)(()=>{let c=M.slice();return de==="title"?c.sort((v,f)=>String(v.title||"").localeCompare(String(f.title||""))):de==="hot"?c.sort((v,f)=>(f.weight||f.links||0)-(v.weight||v.links||0)):c.sort((v,f)=>new Date(f.updated||0).getTime()-new Date(v.updated||0).getTime()),c},[M,de]);return(0,e.jsxs)("div",{className:"memory-eternal-root",style:{height:"100%",display:"flex",flexDirection:"column"},children:[(0,e.jsx)("style",{children:ve}),K&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(K.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:K.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:K.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{children:K.msg})]}),i&&(0,e.jsxs)("div",{className:"me-modal-head",children:[(0,e.jsxs)("div",{className:"me-modal-title",children:[(0,e.jsx)("span",{className:"me-wicon",children:(0,e.jsx)(at,{})}),(0,e.jsx)("h2",{children:o("memoryTitle")}),(0,e.jsx)("span",{children:o("memoryHint")})]}),(0,e.jsx)("div",{className:"spacer"}),h&&(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:h,"aria-label":o(n?"exitFull":"fullscreen"),children:n?"\u2750":"\u26F6"}),(0,e.jsx)("button",{type:"button",className:"me-modal-close",onClick:g,"aria-label":o("close"),children:"\u2715"})]}),(0,e.jsxs)("div",{className:"me-modal-body",children:[(0,e.jsxs)("div",{className:"mc-rail",children:[(0,e.jsx)("button",{type:"button",className:`mc-railbtn${X==="cards"?" active":""}`,onClick:()=>le("cards"),title:o("cardsTab"),children:"\u{1F4C7}"}),(0,e.jsx)("button",{type:"button",className:`mc-railbtn${X==="graph"?" active":""}`,onClick:()=>le("graph"),title:o("graphTab"),children:"\u{1F578}"})]}),(0,e.jsxs)("div",{className:"mc-main",children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsx)(Ae,{label:o("total"),value:m?m.total:"\u2014"}),(0,e.jsx)(Ae,{label:o("recent"),value:m?m.recent:"\u2014"}),(0,e.jsx)(Ae,{label:o("tags"),value:m?m.tags:"\u2014"}),(0,e.jsx)(Ae,{label:o("cardCount"),value:m?m.byKind?.knowledge??0:"\u2014"})]}),(0,e.jsxs)("div",{className:"mc-toolbar",children:[(0,e.jsx)("input",{type:"text",placeholder:o("searchPlaceholder"),value:O,onChange:c=>W(c.target.value)}),(0,e.jsx)("input",{ref:B,type:"file",accept:".json,application/json",style:{display:"none"},onChange:a}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>B.current&&B.current.click(),children:o("importVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:L,onClick:()=>l("md"),children:o(L?"exporting":"exportVault")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",disabled:L,onClick:()=>l("json"),children:o(L?"exporting":"exportJson")}),(0,e.jsxs)("label",{className:"mc-btn",style:{display:"inline-flex",alignItems:"center",gap:5,cursor:"pointer"},title:o("crossVault"),children:[(0,e.jsx)("input",{type:"checkbox",checked:ke,onChange:c=>re(c.target.checked)}),o("crossVault")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>_({tab:"stats"}),children:o("manage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>te(),children:o("refresh")})]}),X==="cards"&&(0,e.jsxs)("div",{className:"mc-chips",children:[ht.map(c=>(0,e.jsx)("button",{type:"button",className:`mc-chip${V===c?" active":""}`,onClick:()=>Fe(c),children:o(c==="all"?"all":xe[c])},c)),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),[{key:"recent",label:o("sortRecent")},{key:"title",label:o("sortTitle")},{key:"hot",label:o("sortHot")}].map(c=>(0,e.jsx)("button",{type:"button",className:`mc-chip${de===c.key?" active":""}`,onClick:()=>G(c.key),children:c.label},c.key))]}),ne&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",ne]}),X==="cards"?R&&!M.length?(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}):M.length===0?(0,e.jsx)("div",{className:"mc-empty",children:o("empty")}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mc-grid",children:C.slice(0,fe).map(c=>(0,e.jsx)(wt,{card:c,t:o,query:O.trim(),onOpen:J,onDelete:be},c.path))}),C.length>fe&&(0,e.jsx)("div",{ref:Ce,style:{height:1}})]}):(0,e.jsx)(Ct,{t:o,onOpen:J,all:ke}),Q&&(0,e.jsx)(Nt,{t:o,card:Q,onClose:()=>z(null),onDelete:c=>{z(null),be(c)}}),H&&(0,e.jsx)(kt,{t:o,tab:H.tab,onTab:c=>_({tab:c}),onClose:()=>_(null),onReload:()=>te()})]})]})]})}var Ae=({label:o,value:i})=>(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:i}),(0,e.jsx)("span",{children:o})]}),wt=({card:o,t:i,onOpen:g,query:h,onDelete:n})=>(0,e.jsxs)("article",{className:"mc-cardrow mc-card",onClick:()=>g(o),children:[(0,e.jsxs)("h4",{children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:We[o.kind]||We.other}}),h?ot(o.title,h):o.title,zt(o.updated)&&(0,e.jsx)("span",{className:"mc-new",children:i("newBadge")})]}),(0,e.jsx)("p",{children:h?ot(o.summary||"",h):o.summary||""}),o.tags.length>0&&(0,e.jsx)("div",{className:"mc-tags",children:o.tags.slice(0,4).map(m=>(0,e.jsx)("span",{className:"mc-tag",children:m},m))}),(0,e.jsxs)("footer",{children:[(0,e.jsx)("span",{children:i(xe[o.kind])}),(0,e.jsx)("span",{children:rt(o.updated)}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-card-del",title:i("delete"),onClick:m=>{m.stopPropagation(),window.confirm(i("deleteConfirm"))&&n&&n(o.path)},children:"\u2715"})]})]});function kt({t:o,tab:i,onTab:g,onClose:h,onReload:n}){let[m,T]=(0,d.useState)(null),[M,D]=(0,d.useState)(null),[R,$]=(0,d.useState)(null),[ne,ee]=(0,d.useState)(""),[V,we]=(0,d.useState)(""),O=(0,d.useCallback)(async()=>{try{let u=await fetch(`${A}/todayBrief`).then(S=>S.json());ee(u.ok&&u.brief||"")}catch{}},[]),me=(0,d.useCallback)(async()=>{if(!(!M||!M.merge||!M.merge.length)&&window.confirm(o("mergeAllConfirm"))){we("merge");try{let u={},S=z=>u[z]===void 0?z:u[z]=S(u[z]),B=(z,H)=>{u[S(z)]=S(H)},L=new Set;for(let z of M.merge)L.add(z.a.path),L.add(z.b.path),B(z.a.path,z.b.path);let ue={};for(let z of L){let H=S(z);(ue[H]=ue[H]||[]).push(z)}let Q=0;for(let z of Object.values(ue)){if(z.length<2)continue;(await fetch(`${A}/merge?paths=${encodeURIComponent(z.join(","))}`).then(_=>_.json())).ok&&Q++}await X(),n&&n()}catch{}we("")}},[M,X,n,o]);async function X(){try{let[u,S,B]=await Promise.all([fetch(`${A}/stats`).then(L=>L.json()),fetch(`${A}/optimize`).then(L=>L.json()),fetch(`${A}/budget`).then(L=>L.json())]);u.ok&&T(u),S.ok&&D(S),B.ok&&$(B)}catch{}}(0,d.useEffect)(()=>{X()},[]);let le=async(u,S)=>{if(window.confirm(o("mergeConfirm")))try{(await fetch(`${A}/merge?paths=${encodeURIComponent(u+","+S)}`).then(L=>L.json())).ok&&(await X(),n&&n())}catch{}},de=async u=>{if(window.confirm(o("deleteConfirm")))try{(await fetch(`${A}/delete?path=${encodeURIComponent(u)}`).then(B=>B.json())).ok&&(await X(),n&&n())}catch{}},G=["project","knowledge","content","prompt","business","tool","mistake"],K=({title:u,kind:S,updated:B,path:L})=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"3px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)"},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Le.colors[S]||"#666"}}),(0,e.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u}),(0,e.jsx)("span",{style:{opacity:.55,fontSize:11},children:rt(B)}),(0,e.jsxs)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>de(L),children:[o("delete")," \u2715"]})]});return(0,e.jsxs)("div",{className:"me-overlay",onClick:h,children:[(0,e.jsx)("style",{children:ve}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:720,width:"94vw",maxHeight:"86vh"},onClick:u=>u.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("button",{type:"button",className:`mc-tab${i==="stats"?" active":""}`,onClick:()=>g("stats"),children:o("tabUsage")}),(0,e.jsx)("button",{type:"button",className:`mc-tab${i==="optimize"?" active":""}`,onClick:()=>g("optimize"),children:o("tabOptimize")})]}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:h,children:o("close")})]}),(0,e.jsxs)("div",{className:"me-dialog-body",style:{overflow:"auto"},children:[!m&&!M&&(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}),i==="stats"&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:o("todayBriefLabel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:O,children:o("todayBrief")}),ne&&(0,e.jsx)("pre",{style:{margin:0,fontSize:12,width:"100%",whiteSpace:"pre-wrap",opacity:.85},children:ne})]}),m&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-stats",children:[(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:m.total}),(0,e.jsx)("span",{children:o("total")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:m.today}),(0,e.jsx)("span",{children:o("todayAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:m.week}),(0,e.jsx)("span",{children:o("weekAdd")})]}),(0,e.jsxs)("div",{className:"mc-stat mc-card",children:[(0,e.jsx)("b",{children:m.tags}),(0,e.jsx)("span",{children:o("tags")})]})]}),(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10},children:[(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("byKind")}),(0,e.jsx)("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:G.map(u=>(0,e.jsxs)("span",{style:{fontSize:12},children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Le.colors[u]||"#666"}}),o(xe[u]),": ",m.byKind?.[u]||0]},u))})]}),R&&(R.budgetChars||R.recallLimit||R.embedding)&&(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,fontSize:12},children:[(0,e.jsx)("b",{children:o("budgetLabel")}),"\uFF1A",o("budgetChars")," ",(0,e.jsx)("b",{children:R.budgetChars||8e4})," \xB7 ",o("recallLimitLabel")," ",(0,e.jsx)("b",{children:R.recallLimit||5})," \xB7 ",o("embeddingLabel")," ",R.embedding?"ON":"OFF"]}),(0,e.jsxs)("div",{className:"mc-card",children:[(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("todayList"),"\uFF08",m.todayCards?.length||0,"\uFF09"]}),m.todayCards?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:m.todayCards.map(u=>(0,e.jsx)(K,{title:u.title,kind:u.kind,updated:u.updated,path:u.path},u.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})]})]}),i==="optimize"&&(0,e.jsx)("div",{children:M&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:"mc-card",style:{marginBottom:10,display:"flex",gap:10,alignItems:"center"},children:[(0,e.jsx)("b",{style:{fontSize:12},children:M.merge?.length?o("mergePairs"):o("noOptimize")}),(0,e.jsx)("div",{className:"spacer",style:{flex:1}}),M.merge?.length>0&&(0,e.jsx)("button",{type:"button",className:"mc-btn me-on",disabled:!!V,onClick:me,children:o(V==="merge"?"exporting":"batchMerge")})]}),(0,e.jsx)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:o("mergePairs")}),M.merge?.length?(0,e.jsx)("ul",{style:{margin:"0 0 12px",padding:0,listStyle:"none"},children:M.merge.map((u,S)=>(0,e.jsxs)("li",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 4px",borderBottom:"1px solid rgba(127,127,127,0.12)",fontSize:12},children:[(0,e.jsxs)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[u.a.title," \u21C4 ",u.b.title]}),(0,e.jsxs)("span",{style:{opacity:.6},children:[Math.round(u.sim*100),"%"]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{padding:"2px 8px"},onClick:()=>le(u.a.path,u.b.path),children:o("mergeNow")})]},S))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12,marginBottom:12},children:o("noOptimize")}),(0,e.jsxs)("div",{style:{fontSize:12,fontWeight:700,marginBottom:6},children:[o("staleCards"),"\uFF08",M.stale?.length||0,"\uFF09"]}),M.stale?.length?(0,e.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none"},children:M.stale.map(u=>(0,e.jsx)(K,{title:u.title,kind:"other",updated:u.updated,path:u.path},u.path))}):(0,e.jsx)("div",{style:{opacity:.6,fontSize:12},children:o("noOptimize")})]})})]})]})]})}function Nt({t:o,card:i,onClose:g,onDelete:h}){(0,d.useEffect)(()=>{let M=D=>{D.key==="Escape"&&g()};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[g]);let[n,m]=(0,d.useState)(!1),T=(i.text||"").length>460;return(0,e.jsxs)("div",{className:"me-overlay",onClick:g,children:[(0,e.jsx)("style",{children:ve}),(0,e.jsxs)("div",{className:"me-dialog",onClick:M=>M.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:i.title}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[T&&(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>m(M=>!M),children:o(n?"collapse":"expand")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{window.confirm(o("deleteConfirm"))&&h&&h(i.path)},children:o("delete")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:g,children:o("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:n?{}:{maxHeight:300,overflow:"hidden"},dangerouslySetInnerHTML:{__html:Bt(i.text)}})]})]})}function Ct({t:o,onOpen:i,all:g}){let[h,n]=(0,d.useState)(null),[m,T]=(0,d.useState)(""),M=(0,d.useCallback)(async()=>{try{let $=await(await fetch(`${A}/graph${g?"?all=1":""}`)).json();n($.ok?$:null),T("")}catch(R){T(String(R&&R.message?R.message:R))}},[g]);(0,d.useEffect)(()=>{let R=!0;return fetch(`${A}/graph${g?"?all=1":""}`).then($=>$.json()).then($=>{R&&n($.ok?$:null)}).catch($=>{R&&T(String($&&$.message?$.message:$))}),()=>{R=!1}},[g]);let D=(0,d.useCallback)(async R=>{try{let ne=await(await fetch(`${A}/delete?path=${encodeURIComponent(R)}`)).json();return ne&&ne.ok?(await M(),!0):!1}catch{return!1}},[M]);return(0,e.jsxs)("div",{className:"me-graph",children:[(0,e.jsx)("style",{children:ve}),m&&(0,e.jsxs)("div",{className:"mc-empty",children:[o("error"),"\uFF1A",m]}),!h&&!m&&(0,e.jsx)("div",{className:"mc-empty",children:o("loading")}),h&&h.nodes.length===0&&(0,e.jsx)("div",{className:"mc-empty",children:o("emptyGraph")}),h&&h.nodes.length>0&&(0,e.jsx)(St,{nodes:h.nodes,edges:h.edges,onOpen:i,onDelete:D,t:o,countLabel:`${h.nodes.length} ${o("nodes")} \xB7 ${Mt(h.edges)} ${o("edges")}`})]})}function Mt(o){let i=new Set;for(let g of o||[])i.add([g.source,g.target].sort().join("|"));return i.size}var Le={colors:{project:"#3B82F6",knowledge:"#10B981",content:"#F59E0B",prompt:"#A855F7",business:"#EC4899",tool:"#06B6D4",mistake:"#EF4444",other:"#6B7280"},shapes:{project:"circle",knowledge:"circle",content:"rect",prompt:"diamond",business:"hexagon",tool:"circle",mistake:"diamond",other:"circle"}};function St({nodes:o,edges:i,onOpen:g,onDelete:h,t:n,countLabel:m}){let T=(0,d.useRef)(null),M=(0,d.useRef)(null),D=(0,d.useRef)(null),R=(0,d.useRef)(null),$=(0,d.useRef)(null),ne=(0,d.useRef)(g);(0,d.useEffect)(()=>{ne.current=g},[g]);let ee=(0,d.useRef)(h);(0,d.useEffect)(()=>{ee.current=h},[h]);let[V,we]=(0,d.useState)(""),[O,me]=(0,d.useState)(null),X=(0,d.useRef)("");(0,d.useEffect)(()=>{X.current=V.trim().toLowerCase()},[V]);let[le,de]=(0,d.useState)("all"),G=(0,d.useRef)("all"),[K,u]=(0,d.useState)(!1),S=(0,d.useRef)(!1),[B,L]=(0,d.useState)(null);(0,d.useEffect)(()=>{G.current=le},[le]),(0,d.useEffect)(()=>{S.current=K},[K]);let ue=(()=>{let l=V.trim().toLowerCase();return!!l&&!o.some(a=>(a.title||a.name||"").toLowerCase().includes(l)||String(a.kind||"").toLowerCase().includes(l)||String(xe[a.kind]||"").toLowerCase().includes(l))})();(0,d.useEffect)(()=>{let l=D.current;l&&l.wake&&l.wake()},[V]),(0,d.useEffect)(()=>{let l=D.current;l&&l.render&&l.render()},[le,K]);let Q=(0,d.useRef)(null),[z,H]=(0,d.useState)([]),[_,ke]=(0,d.useState)(null),[re,ce]=(0,d.useState)(!1),[fe,Ne]=(0,d.useState)(null),[Ce,Ee]=(0,d.useState)(""),te=(0,d.useRef)(null),be=(0,d.useRef)(null),W=(l,a=!0)=>{te.current&&clearTimeout(te.current),Ne({msg:l,ok:a}),te.current=setTimeout(()=>Ne(null),1900)},Fe=l=>{Ee(l),be.current&&clearTimeout(be.current),be.current=setTimeout(()=>Ee(""),1600)};(0,d.useEffect)(()=>()=>{te.current&&clearTimeout(te.current),be.current&&clearTimeout(be.current)},[]);let J=(0,d.useMemo)(()=>o.reduce((l,a)=>(l[a.id]=a,l),{}),[o]);return(0,d.useEffect)(()=>{let l=T.current;if(!l||o.length===0)return;let a=l.getContext("2d");if(!a)return;let C=Math.max(1,window.devicePixelRatio||1),c=()=>document.documentElement.getAttribute("data-theme")==="dark",v={};i.forEach(r=>{v[r.source]=(v[r.source]||0)+1,v[r.target]=(v[r.target]||0)+1});let f=Math.max(1,...Object.values(v)),t={nodes:o.map(r=>({id:r.id,name:r.title||"",type:r.kind||"other",r:9+Math.min(10,(v[r.id]||0)/f*8),x:0,y:0,vx:0,vy:0})),edges:i.map(r=>({sourceNodeId:r.source,targetNodeId:r.target,weight:1})),panX:0,panY:0,zoom:1,running:!0,raf:0,tickCount:0,quietTicks:0,dragNode:null,selectedId:null,mouseX:0,mouseY:0,w:0,h:0,dpr:C,ctx:a,multi:[],marquee:null};t.domain=o,t.domainById=o.reduce((r,b)=>(r[b.id]=b,r),{}),t.nodes.forEach((r,b)=>{let p=b/t.nodes.length*Math.PI*2-Math.PI/2;r.x=Math.cos(p)*60,r.y=Math.sin(p)*60});let Y=[...new Set(t.nodes.map(r=>r.type))];t.clustered=Y.length>1,t.typeCenters={},Y.forEach((r,b)=>{let p=b/Y.length*Math.PI*2-Math.PI/2;t.typeCenters[r]={x:Math.cos(p)*160,y:Math.sin(p)*160}}),D.current=t;let Me=()=>{let r=l.clientWidth,b=l.clientHeight;t.w=r,t.h=b,l.width=r*C,l.height=b*C,a.setTransform(C,0,0,C,0,0)};Me();let Se=new ResizeObserver(Me);Se.observe(l.parentElement);let Ye=(r,b)=>r&&r.length>b?r.slice(0,b)+"\u2026":r,he=(r,b,p,y)=>{if(a.beginPath(),y==="rect")a.rect(r-p,b-p*.75,p*2,p*1.5);else if(y==="diamond")a.moveTo(r,b-p),a.lineTo(r+p,b),a.lineTo(r,b+p),a.lineTo(r-p,b),a.closePath();else if(y==="hexagon"){for(let x=0;x<6;x++){let N=Math.PI/3*x-Math.PI/2,E=r+p*Math.cos(N),s=b+p*Math.sin(N);x===0?a.moveTo(E,s):a.lineTo(E,s)}a.closePath()}else a.arc(r,b,p,0,Math.PI*2)},ie=()=>{if(!t.nodes.length)return;let r=1/0,b=-1/0,p=1/0,y=-1/0;t.nodes.forEach(I=>{r=Math.min(r,I.x),b=Math.max(b,I.x),p=Math.min(p,I.y),y=Math.max(y,I.y)});let x=20,N=b-r+x*2,E=y-p+x*2,s=Math.min(t.w/N,t.h/E);t.zoom=Math.max(.35,Math.min(1.8,s)),t.panX=t.w/2-(r+b)/2*t.zoom,t.panY=t.h/2-(p+y)/2*t.zoom};R.current=ie;let qe=()=>{a.clearRect(0,0,t.w,t.h),t.searchTerm=X.current,t.kindFilter=G.current,t.timeMode=S.current;let r=t.kindFilter,b=s=>String(s||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");a.save(),a.strokeStyle=c()?"rgba(255,255,255,0.04)":"rgba(0,0,0,0.04)",a.lineWidth=.5;for(let s=0;s<t.w;s+=24)a.beginPath(),a.moveTo(s,0),a.lineTo(s,t.h),a.stroke();for(let s=0;s<t.h;s+=24)a.beginPath(),a.moveTo(0,s),a.lineTo(t.w,s),a.stroke();a.restore(),a.save(),a.translate(t.panX,t.panY),a.scale(t.zoom,t.zoom);let p={};t.nodes.forEach(s=>p[s.id]=s);let y=t.nodes.length>40,x=y?1.5:.55,N=t.selectedId||t.hoverId;t.edges.forEach(s=>{let I=p[s.sourceNodeId],F=p[s.targetNodeId];if(!I||!F)return;if(r!=="all"){let Z=t.domainById[s.sourceNodeId]&&t.domainById[s.sourceNodeId].kind,Qe=t.domainById[s.targetNodeId]&&t.domainById[s.targetNodeId].kind;if(Z!==r&&Qe!==r)return}let w=F.x-I.x,k=F.y-I.y,j=Math.sqrt(w*w+k*k)||1,P=y?12:18,q=-k/j*P,oe=w/j*P,U=(I.x+F.x)/2+q,pe=(I.y+F.y)/2+oe,ae=Le.colors[t.domainById[I.id]&&t.domainById[I.id].kind||"other"],ge=N&&(s.sourceNodeId===N||s.targetNodeId===N),Ie=N?ge?.6:.08:y?.14:.24,je=parseInt(ae.slice(1,3),16),De=parseInt(ae.slice(3,5),16),Ze=parseInt(ae.slice(5,7),16);a.strokeStyle="rgba("+je+","+De+","+Ze+","+Ie+")",a.lineWidth=ge?1.6+(s.weight||1):.8+(s.weight||1)*.5,a.beginPath(),a.moveTo(I.x,I.y),a.quadraticCurveTo(U,pe,F.x,F.y),a.stroke()});let E=[];if(t.nodes.forEach(s=>{let I=t.domainById[s.id]||{},F=I.kind||"other",w=t.timeMode?It(I.updated):Le.colors[F],k=Le.shapes[F],j=t.selectedId===s.id,P=t.hoverId===s.id,q=t.searchTerm||"",oe=!q||(s.name||"").toLowerCase().includes(q)||String(xe[F]||"").toLowerCase().includes(q)||String(F).toLowerCase().includes(q),U=r==="all"||F===r,pe=N&&s.id!==N&&!t.edges.some(Z=>Z.sourceNodeId===N&&Z.targetNodeId===s.id||Z.targetNodeId===N&&Z.sourceNodeId===s.id)||q&&!oe||!U;a.save(),a.globalAlpha=pe?.08:1,(j||P)&&(a.shadowColor=w,a.shadowBlur=j?20:14),he(s.x,s.y,s.r,k);let ae=parseInt(w.slice(1,3),16),ge=parseInt(w.slice(3,5),16),Ie=parseInt(w.slice(5,7),16),je=a.createRadialGradient(s.x-s.r*.3,s.y-s.r*.3,0,s.x,s.y,s.r*1.2);je.addColorStop(0,"rgba("+Math.min(255,ae+70)+","+Math.min(255,ge+70)+","+Math.min(255,Ie+70)+",0.95)"),je.addColorStop(1,w),a.fillStyle=je,a.fill(),a.restore(),j?(a.save(),he(s.x,s.y,s.r+3,k),a.strokeStyle=w,a.lineWidth=3,a.shadowColor=w,a.shadowBlur=12,a.stroke(),a.restore()):P?(a.save(),he(s.x,s.y,s.r+2,k),a.strokeStyle=w,a.lineWidth=2,a.stroke(),a.restore()):q&&oe?(a.save(),he(s.x,s.y,s.r+2,k),a.strokeStyle="#e11d48",a.lineWidth=2,a.stroke(),a.restore()):t.multi.indexOf(s.id)>=0&&(a.save(),he(s.x,s.y,s.r+2,k),a.strokeStyle="#60a5fa",a.lineWidth=2,a.shadowColor="#60a5fa",a.shadowBlur=8,a.stroke(),a.restore());let De=Ye(s.name,16);if((j||P||t.zoom>x||!y&&t.zoom>.6)&&U){let Z=1/t.zoom;a.font="500 "+(12*Z).toFixed(1)+"px -apple-system,Segoe UI,sans-serif";let ye=a.measureText(De).width+16*Z,Oe=18*Z,ze=s.y+s.r+8*Z,et=!0;for(let Te of E)if(s.x-ye/2<Te.x+Te.w&&s.x+ye/2>Te.x&&ze<Te.y+Te.h&&ze+Oe>Te.y){et=!1;break}if(!et&&!j&&!P)return;E.push({x:s.x-ye/2,y:ze,w:ye,h:Oe}),a.fillStyle=c()?"rgba(30,30,35,0.92)":"rgba(255,255,255,0.92)",a.beginPath(),a.roundRect?a.roundRect(s.x-ye/2,ze,ye,Oe,4*Z):a.rect(s.x-ye/2,ze,ye,Oe),a.fill(),a.strokeStyle=c()?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.08)",a.lineWidth=1*Z,a.stroke(),a.fillStyle=c()?j||P?"#eee":"#bbb":j||P?"#111":"#444",a.textAlign="center",a.fillText(De,s.x,ze+13*Z)}}),a.restore(),t.marquee){let s=t.marquee,I=Math.min(s.sx,s.ex),F=Math.min(s.sy,s.ey),w=Math.abs(s.ex-s.sx),k=Math.abs(s.ey-s.sy);a.save(),a.setLineDash([4,4]),a.strokeStyle="rgba(96,165,250,0.9)",a.lineWidth=1,a.fillStyle="rgba(96,165,250,0.12)",a.fillRect(I,F,w,k),a.strokeRect(I,F,w,k),a.restore()}if(t.hoverId&&Q.current){let s=t.domainById[t.hoverId],I=t.nodes.find(function(F){return F.id===t.hoverId});if(s&&I){let F=t.edges.filter(function(j){return j.sourceNodeId===s.id||j.targetNodeId===s.id}).length,w=I.x*t.zoom+t.panX,k=I.y*t.zoom+t.panY;Q.current.style.display="block",Q.current.style.left=w+14+"px",Q.current.style.top=k-6+"px",Q.current.innerHTML="<b>"+b(s.title||s.name||"")+'</b><br/><span style="opacity:.8">'+b(s.kind||"")+" \xB7 "+F+" \u8FDE\u63A5</span>"}}else Q.current&&(Q.current.style.display="none")},se=()=>{t.running=!0,t.raf||(t.raf=requestAnimationFrame(Xe))};t.wake=se,t.render=qe;let Ue=()=>{let r=t.nodes.length;t.tickCount++;let p=.9-Math.min(.4,t.tickCount/1500),y=r>1e3?3e3:r>100?2e3:r>50?1200:800,x=r>100?.002:.005,N=r>1e3?.012:r>100?.005:.01,E=r>1e3?6:r>200?12:24,s={};t.nodes.forEach(w=>s[w.id]=w);for(let w=0;w<r;w++){if(t.dragNode===t.nodes[w])continue;let k=t.nodes[w],j=0,P=0;for(let U=0;U<r;U++){if(w===U)continue;let pe=k.x-t.nodes[U].x,ae=k.y-t.nodes[U].y,ge=Math.sqrt(pe*pe+ae*ae)||1,Ie=y/(ge*ge);j+=pe/ge*Ie,P+=ae/ge*Ie}if(t.clustered&&t.typeCenters[k.type]){let U=t.typeCenters[k.type];j+=(U.x-k.x)*.006,P+=(U.y-k.y)*.006}else j-=k.x*N,P-=k.y*N;let q=(k.vx+j)*p,oe=(k.vy+P)*p;q=Math.max(-E,Math.min(E,q)),oe=Math.max(-E,Math.min(E,oe)),k.vx=q,k.vy=oe}t.edges.forEach(w=>{let k=s[w.sourceNodeId],j=s[w.targetNodeId];if(!k||!j)return;let P=j.x-k.x,q=j.y-k.y,oe=Math.sqrt(P*P+q*q)||1,U=(oe-100)*x,pe=P/oe*U,ae=q/oe*U;t.dragNode!==k&&(k.vx+=pe,k.vy+=ae),t.dragNode!==j&&(j.vx-=pe,j.vy-=ae)});let I=0;t.nodes.forEach(w=>{t.dragNode!==w&&(w.x+=w.vx,w.y+=w.vy,I+=w.vx*w.vx+w.vy*w.vy)}),t.autoFitPending&&t.tickCount>45&&(t.autoFitPending=!1,ie()),(r?Math.sqrt(I/r):0)<.05&&t.tickCount>60&&!t.dragNode?t.quietTicks=(t.quietTicks|0)+1:t.quietTicks=0},Xe=()=>{if(t.running){try{Ue(),qe()}catch{}if(t.quietTicks>30){t.raf=0;return}t.raf=requestAnimationFrame(Xe)}},Re=(r,b)=>{let p=l.getBoundingClientRect();return{x:(r-p.left-t.panX)/t.zoom,y:(b-p.top-t.panY)/t.zoom}},$e=(r,b,p)=>Math.max(b,Math.min(p,r)),Ke=r=>{t.mouseX=r.clientX,t.mouseY=r.clientY;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let x=t.nodes[y];if(G.current!=="all"&&(t.domainById[x.id]&&t.domainById[x.id].kind)!==G.current)continue;let N=x.x-b.x,E=x.y-b.y;if(N*N+E*E<x.r*x.r+36){p=x.id;break}}p!==t.hoverId&&(t.hoverId=p,se())},He=r=>{if(r.button!==0)return;let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let x=t.nodes[y];if(G.current!=="all"&&(t.domainById[x.id]&&t.domainById[x.id].kind)!==G.current)continue;let N=x.x-b.x,E=x.y-b.y;if(N*N+E*E<x.r*x.r+25){p=x;break}}if(r.shiftKey){t.marquee={sx:r.clientX,sy:r.clientY,ex:r.clientX,ey:r.clientY};return}t.dragStart={x:r.clientX,y:r.clientY,px:t.panX,py:t.panY},t.dragging=!1,t.dragNode=p||null,p&&(t.dragOffset={dx:p.x-b.x,dy:p.y-b.y})},Ve=r=>{if(t.marquee){t.marquee.ex=r.clientX,t.marquee.ey=r.clientY,se();return}if(!t.dragStart)return;let b=r.clientX-t.dragStart.x,p=r.clientY-t.dragStart.y;if(Math.abs(b)+Math.abs(p)>3&&(t.dragging=!0),t.dragNode){let y=Re(r.clientX,r.clientY);t.dragNode.x=y.x+t.dragOffset.dx,t.dragNode.y=y.y+t.dragOffset.dy,se()}else t.dragging&&(t.panX=$e(t.dragStart.px+b,-1e5,1e5),t.panY=$e(t.dragStart.py+p,-1e5,1e5),se())},Ge=r=>{if(t.marquee){let p=t.marquee;t.marquee=null;let y=l.getBoundingClientRect(),x=Math.min(p.sx,p.ex)-y.left,N=Math.max(p.sx,p.ex)-y.left,E=Math.min(p.sy,p.ey)-y.top,s=Math.max(p.sy,p.ey)-y.top,I=t.nodes.filter(F=>{let w=F.x*t.zoom+t.panX,k=F.y*t.zoom+t.panY;return w>=x&&w<=N&&k>=E&&k<=s}).map(F=>F.id);t.multi=I,H(I),se();return}if(t.dragStart&&!t.dragging){let p=Re(r.clientX,r.clientY),y=null;for(let x=t.nodes.length-1;x>=0;x--){let N=t.nodes[x];if(G.current!=="all"&&(t.domainById[N.id]&&t.domainById[N.id].kind)!==G.current)continue;let E=N.x-p.x,s=N.y-p.y;if(E*E+s*s<N.r*N.r+20){y=N;break}}y?(t.selectedId=y.id,me(y.id),se()):(t.selectedId=null,t.hoverId=null,r.shiftKey||(t.multi=[],H([])),me(null),se())}t.dragStart=null,t.dragging=!1,t.dragNode=null},_e=r=>{r.preventDefault();let b=Re(r.clientX,r.clientY),p=null;for(let y=t.nodes.length-1;y>=0;y--){let x=t.nodes[y];if(G.current!=="all"&&(t.domainById[x.id]&&t.domainById[x.id].kind)!==G.current)continue;let N=x.x-b.x,E=x.y-b.y;if(N*N+E*E<x.r*x.r+25){p=x;break}}if(p){let y=t.domainById[p.id];y&&L({x:r.clientX,y:r.clientY,id:p.id,path:y.id,title:y.title})}else L(null)},Je=r=>{r.preventDefault();let b=l.getBoundingClientRect(),p=(r.clientX-b.left-t.panX)/t.zoom,y=(r.clientY-b.top-t.panY)/t.zoom,x=Math.max(.3,Math.min(3,t.zoom*(r.deltaY<0?1.1:1/1.1)));t.panX=$e(t.panX+p*(t.zoom-x),-1e5,1e5),t.panY=$e(t.panY+y*(t.zoom-x),-1e5,1e5),t.zoom=x,se()};l.addEventListener("mousemove",Ke),l.addEventListener("mousedown",He),window.addEventListener("mousemove",Ve),window.addEventListener("mouseup",Ge),l.addEventListener("wheel",Je,{passive:!1}),l.addEventListener("contextmenu",_e),$.current=()=>{t.selectedId=null,t.hoverId=null,t.multi=[],H([]),ie(),se()};for(let r=0;r<200;r++)Ue();return ie(),se(),()=>{t.running=!1,t.raf&&cancelAnimationFrame(t.raf),Se.disconnect(),l.removeEventListener("mousemove",Ke),l.removeEventListener("mousedown",He),window.removeEventListener("mousemove",Ve),window.removeEventListener("mouseup",Ge),l.removeEventListener("wheel",Je),l.removeEventListener("contextmenu",_e)}},[o,i]),(0,e.jsxs)("div",{className:"me-graph",ref:M,children:[(0,e.jsxs)("div",{className:"me-graph-toolbar",children:[(0,e.jsxs)("span",{className:"me-graph-count",children:[o.length," ",n("nodes")," \xB7 ",i.length," ",n("edges")]}),(0,e.jsx)("span",{className:"spacer",style:{flex:1}}),(0,e.jsx)("input",{type:"text",className:"mc-btn",style:{padding:"6px 10px",minWidth:140},placeholder:n("search"),value:V,onChange:l=>we(l.target.value)}),(0,e.jsx)("button",{type:"button",className:`mc-btn${K?" me-on":""}`,onClick:()=>u(l=>!l),children:n("timeDim")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let l=T.current;if(l)try{l.toBlob(a=>{a&&ke({url:URL.createObjectURL(a),blob:a})},"image/png")}catch{}},children:n("exportGraph")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>R.current&&R.current(),children:n("fit")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{me(null),de("all"),$.current&&$.current()},children:n("reset")})]}),(0,e.jsxs)("div",{className:"me-graph-canvas",style:{position:"relative",overflow:"hidden"},children:[(0,e.jsx)("canvas",{ref:T,style:{width:"100%",height:"100%",display:"block",cursor:"grab"}}),(0,e.jsx)("div",{className:"me-graph-tooltip",ref:Q,style:{display:"none",position:"absolute",zIndex:4,pointerEvents:"none",background:"rgba(28,28,32,0.88)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:8,padding:"7px 10px",fontSize:12,maxWidth:220,boxShadow:"0 8px 24px rgba(0,0,0,.2)"}}),(0,e.jsxs)("div",{className:"me-graph-legend",style:{position:"absolute",left:12,bottom:8,zIndex:2},children:[K?[{c:"#10b981",l:n("timeNew")},{c:"#f59e0b",l:n("timeRecent")},{c:"#f97316",l:n("timeMonth")},{c:"#94a3b8",l:n("timeOld")}].map(l=>(0,e.jsxs)("span",{className:"lg",children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:l.c}}),l.l]},l.c)):Object.keys(We).map(l=>(0,e.jsxs)("button",{type:"button",className:`lg${le===l?" active":""}`,onClick:()=>de(a=>a===l?"all":l),children:[(0,e.jsx)("span",{className:"mc-kind",style:{background:Le.colors[l]||We[l]}}),n(xe[l])]},l)),!K&&le!=="all"&&(0,e.jsxs)("button",{type:"button",className:"lg lg-clear",onClick:()=>de("all"),children:[n("clearFilter")," \u2715"]})]}),ue&&(0,e.jsx)("div",{className:"mc-empty",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)"},children:n("noMatch")}),B&&(0,e.jsx)("div",{className:"me-graph-ctx-back",style:{position:"fixed",inset:0,zIndex:30},onMouseDown:()=>L(null)}),B&&(0,e.jsxs)("div",{className:"me-graph-ctxmenu",style:{position:"fixed",left:B.x,top:B.y,zIndex:31},onMouseDown:l=>l.stopPropagation(),children:[(0,e.jsx)("button",{type:"button",onClick:()=>{ne.current({path:B.path,title:B.title}),L(null)},children:n("openCard")}),(0,e.jsx)("button",{type:"button",onClick:()=>{B.id&&(D.current.selectedId=B.id,me(B.id)),L(null);let l=D.current;l&&l.wake&&l.wake()},children:n("focusNeighbors")}),(0,e.jsx)("button",{type:"button",onClick:()=>{try{navigator.clipboard&&navigator.clipboard.writeText(B.title||"")}catch{}L(null),W(n("copied"))},children:n("copyName")}),(0,e.jsx)("button",{type:"button",style:{color:"#f87171"},onClick:()=>{let l=B.path;L(null),window.confirm(n("deleteConfirm"))&&(async()=>{try{(ee.current?await ee.current(l):!1)?W(n("deleted")):W(n("deleteFail"),!1)}catch{W(n("deleteFail"),!1)}})()},children:n("delete")})]}),z.length>0&&(0,e.jsxs)("div",{style:{position:"absolute",left:10,top:10,zIndex:3,display:"flex",gap:8,alignItems:"center",background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:"6px 10px",fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsxs)("span",{style:{fontWeight:700},children:[z.length," ",n("nodes")]}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let a=z.map(f=>J[f]).filter(Boolean).map(f=>f.title||f.name).join(`
|
|
119
|
+
`),C=new Blob([a],{type:"text/plain;charset=utf-8"}),c=URL.createObjectURL(C),v=document.createElement("a");v.href=c,v.download="memory-selected.txt",document.body.appendChild(v),v.click(),document.body.removeChild(v),setTimeout(()=>URL.revokeObjectURL(c),1e3),W(z.length+n("exportedSel"))},children:n("exportSel")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{if(z.length<2){W(n("mergeNeed"),!1);return}let l=z.map(C=>J[C]?J[C].id:C);if(!window.confirm(n("mergeConfirm")))return;H([]);let a=D.current;a&&(a.multi=[]),fetch(`${A}/merge?paths=${encodeURIComponent(l.join(","))}`).then(C=>C.json()).then(C=>{C&&C.ok?W(n("merged")):W(n("mergeFail"),!1)}).catch(()=>W(n("mergeFail"),!1))},children:n("merge")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",style:{color:"#f87171"},onClick:()=>{if(!window.confirm(n("deleteConfirm")))return;let l=z.map(C=>J[C]?J[C].id:C);H([]);let a=D.current;a&&(a.multi=[]),(async()=>{let C=0;for(let c of l)try{(ee.current?await ee.current(c):!1)&&C++}catch{}W(C+n("deletedSelected"),C>0)})()},children:n("deleteSelected")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let l=D.current;l&&(l.multi=[]),H([]);let a=D.current;a&&a.render&&a.render()},children:n("clearSelection")})]}),O&&(0,e.jsxs)("div",{className:"me-graph-sidebar",style:{position:"absolute",right:10,top:10,zIndex:3,maxWidth:240,background:"rgba(28,28,32,0.92)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",color:"#eee",borderRadius:10,padding:12,fontSize:12,boxShadow:"0 10px 30px rgba(0,0,0,.25)"},children:[(0,e.jsx)("div",{style:{fontWeight:700,fontSize:13,marginBottom:4},children:J[O]?J[O].title||J[O].name:O}),(0,e.jsx)("div",{style:{opacity:.8,marginBottom:8},children:J[O]?n(xe[J[O].kind]||"kindKnowledge"):"\u2014"}),(0,e.jsx)("div",{style:{fontSize:11,opacity:.65,letterSpacing:".04em",marginBottom:6},children:n("graphHint")}),(i.filter(l=>l.source===O||l.target===O)||[]).slice(0,8).map((l,a)=>{let C=l.source===O?l.target:l.source,c=J[C];return(0,e.jsx)("div",{style:{padding:"4px 6px",cursor:"pointer",borderRadius:6},onMouseDown:v=>{v.preventDefault();let f=D.current;f&&(f.selectedId=C,f.hoverId=C,f.wake&&f.wake()),me(C)},children:c?(c.title||c.name).slice(0,28):C},a)})]})]}),(0,e.jsx)("div",{className:"me-graph-tip",children:n("graphTip")}),fe&&(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,position:"fixed",left:"50%",transform:"translateX(-50%)",top:22,zIndex:70,background:"rgba(20,22,26,0.97)",backdropFilter:"blur(12px)",WebkitBackdropFilter:"blur(12px)",color:"#f5f5f5",borderRadius:12,padding:"10px 20px",fontSize:13.5,fontWeight:600,boxShadow:"0 14px 44px rgba(0,0,0,.5)",pointerEvents:"none",animation:"me-pop .22s ease",borderLeft:"4px solid "+(fe.ok?"#22c55e":"#ef4444"),maxWidth:"90vw"},children:[(0,e.jsx)("span",{style:{color:fe.ok?"#34d399":"#f87171",fontWeight:800,fontSize:15},children:fe.ok?"\u2713":"\u2715"}),(0,e.jsx)("span",{style:{wordBreak:"break-all"},children:fe.msg})]}),_&&(0,e.jsxs)("div",{className:"me-overlay",onClick:()=>{_.url&&URL.revokeObjectURL(_.url),ke(null),ce(!1)},children:[(0,e.jsx)("style",{children:ve}),(0,e.jsxs)("div",{className:"me-dialog",style:{maxWidth:re?"100vw":900,width:re?"100vw":"92vw",maxHeight:re?"100vh":"90vh",height:re?"100vh":void 0,borderRadius:re?0:14},onClick:l=>l.stopPropagation(),children:[(0,e.jsxs)("div",{className:"me-dialog-head",children:[(0,e.jsx)("h3",{children:n("exportGraph")}),(0,e.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,e.jsx)("a",{className:"mc-btn",href:_.url,download:"memory-graph.png",onClick:()=>{Fe("download"),W(n("downloaded")+" \xB7 "+n("defaultDownloads"))},style:{textDecoration:"none",display:"inline-flex",alignItems:"center"},children:n(Ce==="download"?"done":"download")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{Fe("full"),ce(l=>!l),W(n("fullscreen"))},children:n(Ce==="full"?"done":re?"exitFull":"fullscreen")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{let l=_.blob;l&&window.ClipboardItem&&navigator.clipboard?navigator.clipboard.write([new window.ClipboardItem({"image/png":l})]).then(()=>{Fe("copy"),W(n("copied"))}).catch(()=>{W(n("copyFail"),!1)}):W(n("copyFail"),!1)},children:n(Ce==="copy"?"done":"copyImage")}),(0,e.jsx)("button",{type:"button",className:"mc-btn",onClick:()=>{_.url&&URL.revokeObjectURL(_.url),ke(null),ce(!1)},children:n("close")})]})]}),(0,e.jsx)("div",{className:"me-dialog-body",style:{display:"flex",justifyContent:"center",background:re?"var(--dsw-alias-bg-base, #0b0d10)":"var(--dsw-alias-bg-base, #f3f4f6)"},children:(0,e.jsx)("img",{src:_.url,alt:n("exportGraph"),style:{maxWidth:"100%",maxHeight:re?"calc(100vh - 64px)":"70vh",borderRadius:re?0:8,cursor:"zoom-in"},onClick:()=>ce(l=>!l)})})]})]})]})}function It(o){let i=new Date(o||0).getTime();if(!i)return"#94a3b8";let g=(Date.now()-i)/864e5;return g<3?"#10b981":g<14?"#f59e0b":g<30?"#f97316":"#94a3b8"}function zt(o){let i=new Date(o||0).getTime();return!!i&&(Date.now()-i)/864e5<3}async function Tt(o,i,g){if(g&&typeof window.showSaveFilePicker=="function")try{let m=await window.showSaveFilePicker({suggestedName:i}),T=await m.createWritable();return await T.write(o),await T.close(),{ok:!0,picked:!0,name:m.name}}catch(m){return m&&m.name==="AbortError"?{ok:!1,aborted:!0}:{ok:!1,err:String(m.message||m)}}let h=URL.createObjectURL(o),n=document.createElement("a");return n.href=h,n.download=i,document.body.appendChild(n),n.click(),document.body.removeChild(n),setTimeout(()=>URL.revokeObjectURL(h),1e3),{ok:!0,picked:!1,name:i}}function ot(o,i){if(!i||!o)return o;let g=o.toLowerCase(),h=i.toLowerCase(),n=[],m=0;for(;m<o.length;){let T=g.indexOf(h,m);if(T<0){n.push(o.slice(m));break}T>m&&n.push(o.slice(m,T)),n.push((0,e.jsx)("mark",{className:"mc-hl",children:o.slice(T,T+h.length)},T)),m=T+h.length}return n}function Bt(o){if(!o)return"";let i=String(o).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),g=[];return i=i.replace(/```([\w-]*)\n([\s\S]*?)```/g,function(h,n,m){return g.push("<pre><code>"+m+"</code></pre>"),"\0"+(g.length-1)+"\0"}),i=i.replace(/^(#{1,3})\s+(.+)$/gm,function(h,n,m){return"<h"+n.length+">"+m+"</h"+n.length+">"}),i=i.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),i=i.replace(/`([^`\n]+)`/g,"<code>$1</code>"),i=i.replace(/(^|[^*])\*([^*]+)\*/g,"$1<em>$2</em>"),i=i.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(h,n,m){return/^(https?:|\/)/.test(m)?'<a href="'+m+'" target="_blank" rel="noopener noreferrer">'+n+"</a>":n}),i=i.replace(/^(-)\s+(.+)$/gm,"\u2022 $2"),i=i.replace(/^\s*(>)\s*(.+)$/gm,"<blockquote>$2</blockquote>"),i=i.replace(/\n/g,"<br/>"),i=i.replace(/\u0000(\d+)\u0000/g,function(h,n){return g[n]}),i}function rt(o){if(!o)return"";let i=new Date(o);if(Number.isNaN(i.getTime()))return"";let g=new Date,h=i.toDateString()===g.toDateString(),n=T=>String(T).padStart(2,"0"),m=`${n(i.getHours())}:${n(i.getMinutes())}`;return h?m:`${i.getMonth()+1}-${i.getDate()} ${m}`}
|
|
118
120
|
|
|
119
121
|
return module.exports;
|
|
120
122
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-memory-eternal",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "记忆核心(Memory Eternal):自研的 DeepSeek Harness 记忆插件,不移植任何既有记忆框架——对话结束后自动沉淀知识卡到本地 Markdown Vault(自研去重、自研 CJK 检索、可 git 管理),设置页提供图形化知识库(统计 / 搜索 / 知识图谱 + 侧边栏一键弹窗),Agent 通过 memory_recall 工具按需召回历史上下文。零人工干预。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|