@fgbg/mdocs 1.3.30 → 1.3.32
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/README.md +1 -1
- package/agent-skills/changelog/SKILL.md +11 -0
- package/dist/server/agent/Agent/run.js +2 -2
- package/dist/server/agent/Agent/run.js.map +1 -1
- package/dist/server/agent/Agent/system-prompt.js +8 -6
- package/dist/server/agent/Agent/system-prompt.js.map +1 -1
- package/dist/server/agent/Agent/tool-call-ui.js +4 -2
- package/dist/server/agent/Agent/tool-call-ui.js.map +1 -1
- package/dist/server/agent/Agent/tool-ui-effects.js +31 -9
- package/dist/server/agent/Agent/tool-ui-effects.js.map +1 -1
- package/dist/server/agent/Agent/tools-registry.js +2 -2
- package/dist/server/agent/Agent/tools-registry.js.map +1 -1
- package/dist/server/agent/Agent/tools-registry.test.js +4 -3
- package/dist/server/agent/Agent/tools-registry.test.js.map +1 -1
- package/dist/server/agent/Agent/tools-sheet.js +102 -54
- package/dist/server/agent/Agent/tools-sheet.js.map +1 -1
- package/dist/server/agent/Agent/tools-sheet.test.js +39 -12
- package/dist/server/agent/Agent/tools-sheet.test.js.map +1 -1
- package/dist/server/agent/Agent/tools-template.js +3 -2
- package/dist/server/agent/Agent/tools-template.js.map +1 -1
- package/dist/server/agent/Agent/tools-thinking.js +33 -0
- package/dist/server/agent/Agent/tools-thinking.js.map +1 -0
- package/dist/server/agent/Config/config.js +31 -0
- package/dist/server/agent/Config/config.js.map +1 -1
- package/dist/server/db/repositories/agent-model-config.repo.js +6 -4
- package/dist/server/db/repositories/agent-model-config.repo.js.map +1 -1
- package/dist/server/db/schema.js +10 -0
- package/dist/server/db/schema.js.map +1 -1
- package/dist/server/routes/agent.routes.js +1 -0
- package/dist/server/routes/agent.routes.js.map +1 -1
- package/dist/shared/sheetDocument.js +70 -7
- package/dist/shared/sheetDocument.js.map +1 -1
- package/dist/shared/sheetDocument.test.js +19 -2
- package/dist/shared/sheetDocument.test.js.map +1 -1
- package/dist/web/assets/{AgentChatPanel-e1h0rqbg.js → AgentChatPanel-BJ49TwV5.js} +2 -2
- package/dist/web/assets/{AiWriteWorkbench-Dq0aCk5c.js → AiWriteWorkbench-B7MnIKzJ.js} +1 -1
- package/dist/web/assets/{DiagramEditor-NtNY3sZL-DHC7qgkW.js → DiagramEditor-NtNY3sZL-D12WH5JY.js} +1 -1
- package/dist/web/assets/{DocChrome-7KIXAHsE.js → DocChrome-CjNrjXnZ.js} +1 -1
- package/dist/web/assets/{DocumentEditor-CmIk_VBn.js → DocumentEditor-BcktjJUV.js} +1 -1
- package/dist/web/assets/{HtmlEditor-REIKOoam.js → HtmlEditor-D-H5FPUP.js} +1 -1
- package/dist/web/assets/{MergeView-DCgxAslc.js → MergeView-a2_gRrrh.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-Cz9TMo7h.js → PlaygroundPage-BXmSDi40.js} +1 -1
- package/dist/web/assets/SettingsPage-xJkP4WaU.js +21 -0
- package/dist/web/assets/{SheetEditor-Bkxxf3ly.js → SheetEditor-BV3loL4j.js} +1 -1
- package/dist/web/assets/{Toolbar-ClbpubYi.js → Toolbar-Caimz2EG.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-D4xmZbNY.js → VisitorPickerModal-BiMxEHCX.js} +1 -1
- package/dist/web/assets/{check-CuLfkkz7.js → check-IPzs2Va9.js} +1 -1
- package/dist/web/assets/{copy-CjAdouag.js → copy-Bp0JPDN6.js} +1 -1
- package/dist/web/assets/{index-DAhW-QRN.js → index-DHKGh7I3.js} +2 -2
- package/dist/web/assets/{italic-cqqPz-_Q.js → italic-BOhgURiY.js} +1 -1
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-CNHknbe2.js → meta2dEngine-BD2XbzaV-Bjx9jCbC.js} +1 -1
- package/dist/web/assets/{plus-DkLh2brQ.js → plus-BMAfiGed.js} +1 -1
- package/dist/web/assets/{react-Dj2vqPq5.js → react-BiN5Ertc.js} +3 -3
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/SettingsPage-DsLbUPt-.js +0 -21
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DocumentEditor-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DocumentEditor-BcktjJUV.js","assets/react-vendor-BVS1XoFi.js","assets/ui-CEFkTVnG.js","assets/motion-BAXVQJfN.js","assets/react-BiN5Ertc.js","assets/editor-DBWWidi3.js","assets/diagram-BF8g9yg4.js","assets/plus-BMAfiGed.js","assets/copy-Bp0JPDN6.js","assets/check-IPzs2Va9.js","assets/Toolbar-Caimz2EG.js","assets/italic-BOhgURiY.js","assets/DocChrome-CjNrjXnZ.js","assets/file-type-policy-C6Nun42Q.js","assets/VisitorPickerModal-BiMxEHCX.js","assets/docPlainCharCount-DO5lb3Wt.js","assets/HtmlEditor-D-H5FPUP.js","assets/HtmlEditor-iolk903a.css","assets/SheetEditor-BV3loL4j.js","assets/SheetEditor-DbT_K_Ia.css","assets/SettingsPage-xJkP4WaU.js","assets/AgentChatPanel-BJ49TwV5.js","assets/AiWriteWorkbench-B7MnIKzJ.js","assets/MergeView-a2_gRrrh.js","assets/PlaygroundPage-BXmSDi40.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var rs=Object.defineProperty;var is=(e,n,o)=>n in e?rs(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o;var Jt=(e,n,o)=>is(e,typeof n!="symbol"?n+"":n,o);import{r as x,j as c,R as zi,B as as,_ as Pt,a9 as ss,aa as ls,ab as cs,ac as mo,c as ds,ad as us}from"./react-vendor-BVS1XoFi.js";import{a5 as fs,a6 as ms}from"./ui-CEFkTVnG.js";import{d as hs,s as Oo,p as ps,t as gs,a as ys,q as vs,o as bs,b as xs,c as ws,e as ht,f as _s,g as Is,y as ks,m as Ar,h as Mr}from"./diagram-BF8g9yg4.js";import{f as Ss}from"./motion-BAXVQJfN.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const s of i.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function o(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=o(a);fetch(a.href,i)}})();/**
|
|
3
3
|
* @license lucide-react v0.562.0 - ISC
|
|
4
4
|
*
|
|
@@ -296,4 +296,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
296
296
|
`;zu($u);function Xo(e,n){(n==null||n>e.length)&&(n=e.length);for(var o=0,r=Array(n);o<n;o++)r[o]=e[o];return r}function Uu(e){if(Array.isArray(e))return e}function Bu(e){if(Array.isArray(e))return Xo(e)}function Ii(e,n,o){if(wa())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,n);var a=new(e.bind.apply(e,r));return a}function Sn(e,n,o){return(n=Ku(n))in e?Object.defineProperty(e,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[n]=o,e}function wa(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(wa=function(){return!!e})()}function Hu(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Vu(e,n){var o=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(o!=null){var r,a,i,s,l=[],u=!0,d=!1;try{if(i=(o=o.call(e)).next,n!==0)for(;!(u=(r=i.call(o)).done)&&(l.push(r.value),l.length!==n);u=!0);}catch(h){d=!0,a=h}finally{try{if(!u&&o.return!=null&&(s=o.return(),Object(s)!==s))return}finally{if(d)throw a}}return l}}function Gu(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
297
297
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Wu(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
298
298
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ki(e,n){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),o.push.apply(o,r)}return o}function Qt(e){for(var n=1;n<arguments.length;n++){var o=arguments[n]!=null?arguments[n]:{};n%2?ki(Object(o),!0).forEach(function(r){Sn(e,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):ki(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function In(e,n){return Uu(e)||Vu(e,n)||_a(e,n)||Gu()}function He(e){return Bu(e)||Hu(e)||_a(e)||Wu()}function qu(e,n){if(typeof e!="object"||!e)return e;var o=e[Symbol.toPrimitive];if(o!==void 0){var r=o.call(e,n);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(e)}function Ku(e){var n=qu(e,"string");return typeof n=="symbol"?n:n+""}function Zo(e){"@babel/helpers - typeof";return Zo=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Zo(e)}function _a(e,n){if(e){if(typeof e=="string")return Xo(e,n);var o={}.toString.call(e).slice(8,-1);return o==="Object"&&e.constructor&&(o=e.constructor.name),o==="Map"||o==="Set"?Array.from(e):o==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?Xo(e,n):void 0}}var Yu=bs(xs);function Si(e,n,o){!n||typeof o!="string"||e.filter(function(r){return!r[o]}).forEach(function(r){r[o]=Yu(n(r))})}function Ju(e,n){var o=e.nodes,r=e.links,a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i=a.nodeFilter,s=i===void 0?function(){return!0}:i,l=a.onLoopError,u=l===void 0?function(p){throw"Invalid DAG structure! Found cycle in node path: ".concat(p.join(" -> "),".")}:l,d={};o.forEach(function(p){return d[n(p)]={data:p,out:[],depth:-1,skip:!s(p)}}),r.forEach(function(p){var g=p.source,w=p.target,b=P(g),v=P(w);if(!d.hasOwnProperty(b))throw"Missing source node with id: ".concat(b);if(!d.hasOwnProperty(v))throw"Missing target node with id: ".concat(v);var S=d[b],D=d[v];S.out.push(D);function P(_){return Zo(_)==="object"?n(_):_}});var h=[];f(Object.values(d));var m=Object.assign.apply(Object,[{}].concat(He(Object.entries(d).filter(function(p){var g=In(p,2),w=g[1];return!w.skip}).map(function(p){var g=In(p,2),w=g[0],b=g[1];return Sn({},w,b.depth)}))));return m;function f(p){for(var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],w=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,b=function(){var P=p[v];if(g.indexOf(P)!==-1){var _=[].concat(He(g.slice(g.indexOf(P))),[P]).map(function(T){return n(T.data)});return h.some(function(T){return T.length===_.length&&T.every(function(I,N){return I===_[N]})})||(h.push(_),u(_)),1}w>P.depth&&(P.depth=w,f(P.out,[].concat(He(g),[P]),w+(P.skip?0:1)))},v=0,S=p.length;v<S;v++)b()}}var Xu=2,Te=function(n,o){return o.onNeedsRedraw&&o.onNeedsRedraw()},Ci=function(n,o){if(!o.isShadow){var r=ae(o.linkDirectionalParticles);o.graphData.links.forEach(function(a){var i=Math.round(Math.abs(r(a)));i?a.__photons=He(Array(i)).map(function(){return{}}):delete a.__photons})}},Xn=rr({props:{graphData:{default:{nodes:[],links:[]},onChange:function(n,o){o.engineRunning=!1,Ci(n,o)}},dagMode:{onChange:function(n,o){!n&&(o.graphData.nodes||[]).forEach(function(r){return r.fx=r.fy=void 0})}},dagLevelDistance:{},dagNodeFilter:{default:function(n){return!0}},onDagError:{triggerUpdate:!1},nodeRelSize:{default:4,triggerUpdate:!1,onChange:Te},nodeId:{default:"id"},nodeVal:{default:"val",triggerUpdate:!1,onChange:Te},nodeColor:{default:"color",triggerUpdate:!1,onChange:Te},nodeAutoColorBy:{},nodeCanvasObject:{triggerUpdate:!1,onChange:Te},nodeCanvasObjectMode:{default:function(){return"replace"},triggerUpdate:!1,onChange:Te},nodeVisibility:{default:!0,triggerUpdate:!1,onChange:Te},linkSource:{default:"source"},linkTarget:{default:"target"},linkVisibility:{default:!0,triggerUpdate:!1,onChange:Te},linkColor:{default:"color",triggerUpdate:!1,onChange:Te},linkAutoColorBy:{},linkLineDash:{triggerUpdate:!1,onChange:Te},linkWidth:{default:1,triggerUpdate:!1,onChange:Te},linkCurvature:{default:0,triggerUpdate:!1,onChange:Te},linkCanvasObject:{triggerUpdate:!1,onChange:Te},linkCanvasObjectMode:{default:function(){return"replace"},triggerUpdate:!1,onChange:Te},linkDirectionalArrowLength:{default:0,triggerUpdate:!1,onChange:Te},linkDirectionalArrowColor:{triggerUpdate:!1,onChange:Te},linkDirectionalArrowRelPos:{default:.5,triggerUpdate:!1,onChange:Te},linkDirectionalParticles:{default:0,triggerUpdate:!1,onChange:Ci},linkDirectionalParticleSpeed:{default:.01,triggerUpdate:!1},linkDirectionalParticleOffset:{default:0,triggerUpdate:!1},linkDirectionalParticleWidth:{default:4,triggerUpdate:!1},linkDirectionalParticleColor:{triggerUpdate:!1},linkDirectionalParticleCanvasObject:{triggerUpdate:!1},globalScale:{default:1,triggerUpdate:!1},d3AlphaMin:{default:0,triggerUpdate:!1},d3AlphaDecay:{default:.0228,triggerUpdate:!1,onChange:function(n,o){o.forceLayout.alphaDecay(n)}},d3AlphaTarget:{default:0,triggerUpdate:!1,onChange:function(n,o){o.forceLayout.alphaTarget(n)}},d3VelocityDecay:{default:.4,triggerUpdate:!1,onChange:function(n,o){o.forceLayout.velocityDecay(n)}},warmupTicks:{default:0,triggerUpdate:!1},cooldownTicks:{default:1/0,triggerUpdate:!1},cooldownTime:{default:15e3,triggerUpdate:!1},onUpdate:{default:function(){},triggerUpdate:!1},onFinishUpdate:{default:function(){},triggerUpdate:!1},onEngineTick:{default:function(){},triggerUpdate:!1},onEngineStop:{default:function(){},triggerUpdate:!1},onNeedsRedraw:{triggerUpdate:!1},isShadow:{default:!1,triggerUpdate:!1}},methods:{d3Force:function(n,o,r){return r===void 0?n.forceLayout.force(o):(n.forceLayout.force(o,r),this)},d3ReheatSimulation:function(n){return n.forceLayout.alpha(1),this.resetCountdown(),this},resetCountdown:function(n){return n.cntTicks=0,n.startTickTime=new Date,n.engineRunning=!0,this},isEngineRunning:function(n){return!!n.engineRunning},tickFrame:function(n){return!n.isShadow&&o(),a(),!n.isShadow&&i(),!n.isShadow&&s(),r(),this;function o(){n.engineRunning&&(++n.cntTicks>n.cooldownTicks||new Date-n.startTickTime>n.cooldownTime||n.d3AlphaMin>0&&n.forceLayout.alpha()<n.d3AlphaMin?(n.engineRunning=!1,n.onEngineStop()):(n.forceLayout.tick(),n.onEngineTick()))}function r(){var l=ae(n.nodeVisibility),u=ae(n.nodeVal),d=ae(n.nodeColor),h=ae(n.nodeCanvasObjectMode),m=n.ctx,f=n.isShadow/n.globalScale,p=n.graphData.nodes.filter(l);m.save(),p.forEach(function(g){var w=h(g);if(n.nodeCanvasObject&&(w==="before"||w==="replace")&&(n.nodeCanvasObject(g,m,n.globalScale),w==="replace")){m.restore();return}var b=Math.sqrt(Math.max(0,u(g)||1))*n.nodeRelSize+f;m.beginPath(),m.arc(g.x,g.y,b,0,2*Math.PI,!1),m.fillStyle=d(g)||"rgba(31, 120, 180, 0.92)",m.fill(),n.nodeCanvasObject&&w==="after"&&n.nodeCanvasObject(g,n.ctx,n.globalScale)}),m.restore()}function a(){var l=ae(n.linkVisibility),u=ae(n.linkColor),d=ae(n.linkWidth),h=ae(n.linkLineDash),m=ae(n.linkCurvature),f=ae(n.linkCanvasObjectMode),p=n.ctx,g=n.isShadow*2,w=n.graphData.links.filter(l);w.forEach(T);var b=[],v=[],S=w;if(n.linkCanvasObject){var D=[],P=[];w.forEach(function(I){return({before:b,after:v,replace:D}[f(I)]||P).push(I)}),S=[].concat(He(b),v,P),b=b.concat(D)}p.save(),b.forEach(function(I){return n.linkCanvasObject(I,p,n.globalScale)}),p.restore();var _=Lu(S,[u,d,h]);p.save(),Object.entries(_).forEach(function(I){var N=In(I,2),L=N[0],E=N[1],O=!L||L==="undefined"?"rgba(0,0,0,0.15)":L;Object.entries(E).forEach(function($){var V=In($,2),J=V[0],ne=V[1],B=(J||1)/n.globalScale+g;Object.entries(ne).forEach(function(G){var ce=In(G,2);ce[0];var ue=ce[1],A=h(ue[0]);p.beginPath(),ue.forEach(function(ie){var oe=ie.source,re=ie.target;if(!(!oe||!re||!oe.hasOwnProperty("x")||!re.hasOwnProperty("x"))){p.moveTo(oe.x,oe.y);var K=ie.__controlPoints;K?p[K.length===2?"quadraticCurveTo":"bezierCurveTo"].apply(p,He(K).concat([re.x,re.y])):p.lineTo(re.x,re.y)}}),p.strokeStyle=O,p.lineWidth=B,p.setLineDash(A||[]),p.stroke()})})}),p.restore(),p.save(),v.forEach(function(I){return n.linkCanvasObject(I,p,n.globalScale)}),p.restore();function T(I){var N=m(I);if(!N){I.__controlPoints=null;return}var L=I.source,E=I.target;if(!(!L||!E||!L.hasOwnProperty("x")||!E.hasOwnProperty("x"))){var O=Math.sqrt(Math.pow(E.x-L.x,2)+Math.pow(E.y-L.y,2));if(O>0){var $=Math.atan2(E.y-L.y,E.x-L.x),V=O*N,J={x:(L.x+E.x)/2+V*Math.cos($-Math.PI/2),y:(L.y+E.y)/2+V*Math.sin($-Math.PI/2)};I.__controlPoints=[J.x,J.y]}else{var ne=N*70;I.__controlPoints=[E.x,E.y-ne,E.x+ne,E.y]}}}}function i(){var l=1.6,u=.2,d=ae(n.linkDirectionalArrowLength),h=ae(n.linkDirectionalArrowRelPos),m=ae(n.linkVisibility),f=ae(n.linkDirectionalArrowColor||n.linkColor),p=ae(n.nodeVal),g=n.ctx;g.save(),n.graphData.links.filter(m).forEach(function(w){var b=d(w);if(!(!b||b<0)){var v=w.source,S=w.target;if(!(!v||!S||!v.hasOwnProperty("x")||!S.hasOwnProperty("x"))){var D=Math.sqrt(Math.max(0,p(v)||1))*n.nodeRelSize,P=Math.sqrt(Math.max(0,p(S)||1))*n.nodeRelSize,_=Math.min(1,Math.max(0,h(w))),T=f(w)||"rgba(0,0,0,0.28)",I=b/l/2,N=w.__controlPoints&&Ii(he,[v.x,v.y].concat(He(w.__controlPoints),[S.x,S.y])),L=N?function(B){return N.get(B)}:function(B){return{x:v.x+(S.x-v.x)*B||0,y:v.y+(S.y-v.y)*B||0}},E=N?N.length():Math.sqrt(Math.pow(S.x-v.x,2)+Math.pow(S.y-v.y,2)),O=D+b+(E-D-P-b)*_,$=L(O/E),V=L((O-b)/E),J=L((O-b*(1-u))/E),ne=Math.atan2($.y-V.y,$.x-V.x)-Math.PI/2;g.beginPath(),g.moveTo($.x,$.y),g.lineTo(V.x+I*Math.cos(ne),V.y+I*Math.sin(ne)),g.lineTo(J.x,J.y),g.lineTo(V.x-I*Math.cos(ne),V.y-I*Math.sin(ne)),g.fillStyle=T,g.fill()}}}),g.restore()}function s(){var l=ae(n.linkDirectionalParticles),u=ae(n.linkDirectionalParticleSpeed),d=ae(n.linkDirectionalParticleOffset),h=ae(n.linkDirectionalParticleWidth),m=ae(n.linkVisibility),f=ae(n.linkDirectionalParticleColor||n.linkColor),p=n.ctx;p.save(),n.graphData.links.filter(m).forEach(function(g){var w=l(g);if(!(!g.hasOwnProperty("__photons")||!g.__photons.length)){var b=g.source,v=g.target;if(!(!b||!v||!b.hasOwnProperty("x")||!v.hasOwnProperty("x"))){var S=u(g),D=Math.abs(d(g)),P=g.__photons||[],_=Math.max(0,h(g)/2)/Math.sqrt(n.globalScale),T=f(g)||"rgba(0,0,0,0.28)";p.fillStyle=T;var I=g.__controlPoints?Ii(he,[b.x,b.y].concat(He(g.__controlPoints),[v.x,v.y])):null,N=0,L=!1;P.forEach(function(E){var O=!!E.__singleHop;if(E.hasOwnProperty("__progressRatio")||(E.__progressRatio=O?S<0?1:0:(N+D)/w),!O&&N++,E.__progressRatio+=S,E.__progressRatio>=1||E.__progressRatio<0)if(!O)E.__progressRatio=E.__progressRatio%1,E.__progressRatio<0&&E.__progressRatio++;else{L=!0;return}var $=E.__progressRatio,V=I?I.get($):{x:b.x+(v.x-b.x)*$||0,y:b.y+(v.y-b.y)*$||0};n.linkDirectionalParticleCanvasObject?n.linkDirectionalParticleCanvasObject(V.x,V.y,g,p,n.globalScale):(p.beginPath(),p.arc(V.x,V.y,_,0,2*Math.PI,!1),p.fill())}),L&&(g.__photons=g.__photons.filter(function(E){return!E.__singleHop||E.__progressRatio<=1&&E.__progressRatio>=0}))}}}),p.restore()}},emitParticle:function(n,o){return o&&(!o.__photons&&(o.__photons=[]),o.__photons.push({__singleHop:!0})),this}},stateInit:function(){return{forceLayout:gu().force("link",lu()).force("charge",yu()).force("center",Cd()).force("dagRadial",null).stop(),engineRunning:!1}},init:function(n,o){o.ctx=n},update:function(n,o){n.engineRunning=!1,n.onUpdate(),n.nodeAutoColorBy!==null&&Si(n.graphData.nodes,ae(n.nodeAutoColorBy),n.nodeColor),n.linkAutoColorBy!==null&&Si(n.graphData.links,ae(n.linkAutoColorBy),n.linkColor),n.graphData.links.forEach(function(f){f.source=f[n.linkSource],f.target=f[n.linkTarget]}),n.forceLayout.stop().alpha(1).nodes(n.graphData.nodes);var r=n.forceLayout.force("link");r&&r.id(function(f){return f[n.nodeId]}).links(n.graphData.links);var a=n.dagMode&&Ju(n.graphData,function(f){return f[n.nodeId]},{nodeFilter:n.dagNodeFilter,onLoopError:n.onDagError||void 0}),i=Math.max.apply(Math,He(Object.values(a||[]))),s=n.dagLevelDistance||n.graphData.nodes.length/(i||1)*Xu*(["radialin","radialout"].indexOf(n.dagMode)!==-1?.7:1);if(["lr","rl","td","bu"].includes(o.dagMode)){var l=["lr","rl"].includes(o.dagMode)?"fx":"fy";n.graphData.nodes.filter(n.dagNodeFilter).forEach(function(f){return delete f[l]})}if(["lr","rl","td","bu"].includes(n.dagMode)){var u=["rl","bu"].includes(n.dagMode),d=function(p){return(a[p[n.nodeId]]-i/2)*s*(u?-1:1)},h=["lr","rl"].includes(n.dagMode)?"fx":"fy";n.graphData.nodes.filter(n.dagNodeFilter).forEach(function(f){return f[h]=d(f)})}n.forceLayout.force("dagRadial",["radialin","radialout"].indexOf(n.dagMode)!==-1?vu(function(f){var p=a[f[n.nodeId]]||-1;return(n.dagMode==="radialin"?i-p:p)*s}).strength(function(f){return n.dagNodeFilter(f)?1:0}):null);for(var m=0;m<n.warmupTicks&&!(n.d3AlphaMin>0&&n.forceLayout.alpha()<n.d3AlphaMin);m++)n.forceLayout.tick();this.resetCountdown(),n.onFinishUpdate()}});function Ia(e,n){var o=e instanceof Array?e:[e],r=new n;return r._destructor&&r._destructor(),{linkProp:function(i){return{default:r[i](),onChange:function(l,u){o.forEach(function(d){return u[d][i](l)})},triggerUpdate:!1}},linkMethod:function(i){return function(s){for(var l=arguments.length,u=new Array(l>1?l-1:0),d=1;d<l;d++)u[d-1]=arguments[d];var h=[];return o.forEach(function(m){var f=s[m],p=f[i].apply(f,u);p!==f&&h.push(p)}),h.length?h[0]:this}}}}var Zu=800,Qu=4,ef=5,ka=Ia("forceGraph",Xn),tf=Ia(["forceGraph","shadowGraph"],Xn),nf=Object.assign.apply(Object,He(["nodeColor","nodeAutoColorBy","nodeCanvasObject","nodeCanvasObjectMode","linkColor","linkAutoColorBy","linkLineDash","linkWidth","linkCanvasObject","linkCanvasObjectMode","linkDirectionalArrowLength","linkDirectionalArrowColor","linkDirectionalArrowRelPos","linkDirectionalParticles","linkDirectionalParticleSpeed","linkDirectionalParticleOffset","linkDirectionalParticleWidth","linkDirectionalParticleColor","linkDirectionalParticleCanvasObject","dagMode","dagLevelDistance","dagNodeFilter","onDagError","d3AlphaMin","d3AlphaDecay","d3VelocityDecay","warmupTicks","cooldownTicks","cooldownTime","onEngineTick","onEngineStop"].map(function(e){return Sn({},e,ka.linkProp(e))})).concat(He(["nodeRelSize","nodeId","nodeVal","nodeVisibility","linkSource","linkTarget","linkVisibility","linkCurvature"].map(function(e){return Sn({},e,tf.linkProp(e))})))),of=Object.assign.apply(Object,He(["d3Force","d3ReheatSimulation","emitParticle"].map(function(e){return Sn({},e,ka.linkMethod(e))})));function Io(e){if(e.canvas){var n=e.canvas.width,o=e.canvas.height;n===300&&o===150&&(n=o=0);var r=window.devicePixelRatio;n/=r,o/=r,[e.canvas,e.shadowCanvas].forEach(function(i){i.style.width="".concat(e.width,"px"),i.style.height="".concat(e.height,"px"),i.width=e.width*r,i.height=e.height*r,!n&&!o&&i.getContext("2d").scale(r,r)});var a=ht(e.canvas).k;e.zoom.translateBy(e.zoom.__baseElem,(e.width-n)/2/a,(e.height-o)/2/a),e.needsRedraw=!0}}function Sa(e){var n=window.devicePixelRatio;e.setTransform(n,0,0,n,0,0)}function Di(e,n,o){e.save(),Sa(e),e.clearRect(0,0,n,o),e.restore()}var rf=rr({props:Qt({width:{default:window.innerWidth,onChange:function(n,o){return Io(o)},triggerUpdate:!1},height:{default:window.innerHeight,onChange:function(n,o){return Io(o)},triggerUpdate:!1},graphData:{default:{nodes:[],links:[]},onChange:function(n,o){[n.nodes,n.links].every(function(a){return(a||[]).every(function(i){return!i.hasOwnProperty("__indexColor")})})&&o.colorTracker.reset(),[{type:"Node",objs:n.nodes},{type:"Link",objs:n.links}].forEach(r),o.forceGraph.graphData(n),o.shadowGraph.graphData(n);function r(a){var i=a.type,s=a.objs;s.filter(function(l){if(!l.hasOwnProperty("__indexColor"))return!0;var u=o.colorTracker.lookup(l.__indexColor);return!u||!u.hasOwnProperty("d")||u.d!==l}).forEach(function(l){l.__indexColor=o.colorTracker.register({type:i,d:l})})}},triggerUpdate:!1},backgroundColor:{onChange:function(n,o){o.canvas&&n&&(o.canvas.style.background=n)},triggerUpdate:!1},nodeLabel:{default:"name",triggerUpdate:!1},nodePointerAreaPaint:{onChange:function(n,o){o.shadowGraph.nodeCanvasObject(n?function(r,a,i){return n(r,r.__indexColor,a,i)}:null),o.flushShadowCanvas&&o.flushShadowCanvas()},triggerUpdate:!1},linkPointerAreaPaint:{onChange:function(n,o){o.shadowGraph.linkCanvasObject(n?function(r,a,i){return n(r,r.__indexColor,a,i)}:null),o.flushShadowCanvas&&o.flushShadowCanvas()},triggerUpdate:!1},linkLabel:{default:"name",triggerUpdate:!1},linkHoverPrecision:{default:4,triggerUpdate:!1},minZoom:{default:.01,onChange:function(n,o){o.zoom.scaleExtent([n,o.zoom.scaleExtent()[1]])},triggerUpdate:!1},maxZoom:{default:1e3,onChange:function(n,o){o.zoom.scaleExtent([o.zoom.scaleExtent()[0],n])},triggerUpdate:!1},enableNodeDrag:{default:!0,triggerUpdate:!1},enableZoomInteraction:{default:!0,triggerUpdate:!1},enablePanInteraction:{default:!0,triggerUpdate:!1},enableZoomPanInteraction:{default:!0,triggerUpdate:!1},enablePointerInteraction:{default:!0,onChange:function(n,o){o.hoverObj=null},triggerUpdate:!1},autoPauseRedraw:{default:!0,triggerUpdate:!1},onNodeDrag:{default:function(){},triggerUpdate:!1},onNodeDragEnd:{default:function(){},triggerUpdate:!1},onNodeClick:{triggerUpdate:!1},onNodeRightClick:{triggerUpdate:!1},onNodeHover:{triggerUpdate:!1},onLinkClick:{triggerUpdate:!1},onLinkRightClick:{triggerUpdate:!1},onLinkHover:{triggerUpdate:!1},onBackgroundClick:{triggerUpdate:!1},onBackgroundRightClick:{triggerUpdate:!1},showPointerCursor:{default:!0,triggerUpdate:!1},onZoom:{triggerUpdate:!1},onZoomEnd:{triggerUpdate:!1},onRenderFramePre:{triggerUpdate:!1},onRenderFramePost:{triggerUpdate:!1}},nf),aliases:{stopAnimation:"pauseAnimation"},methods:Qt({graph2ScreenCoords:function(n,o,r){var a=ht(n.canvas);return{x:o*a.k+a.x,y:r*a.k+a.y}},screen2GraphCoords:function(n,o,r){var a=ht(n.canvas);return{x:(o-a.x)/a.k,y:(r-a.y)/a.k}},centerAt:function(n,o,r,a){if(!n.canvas)return null;if(o!==void 0||r!==void 0){var i=Object.assign({},o!==void 0?{x:o}:{},r!==void 0?{y:r}:{});return a?n.tweenGroup.add(new Zr(s()).to(i,a).easing(Ut.Quadratic.Out).onUpdate(l).onComplete(function(){n.tweenGroup.remove(this)}).start()):l(i),this}return s();function s(){var u=ht(n.canvas);return{x:(n.width/2-u.x)/u.k,y:(n.height/2-u.y)/u.k}}function l(u){var d=u.x,h=u.y;n.zoom.translateTo(n.zoom.__baseElem,d===void 0?s().x:d,h===void 0?s().y:h),n.needsRedraw=!0}},zoom:function(n,o,r){if(!n.canvas)return null;if(o!==void 0)return r?n.tweenGroup.add(new Zr({k:a()}).to({k:o},r).easing(Ut.Quadratic.Out).onUpdate(function(s){var l=s.k;return i(l)}).onComplete(function(){n.tweenGroup.remove(this)}).start()):i(o),this;return a();function a(){return ht(n.canvas).k}function i(s){n.zoom.scaleTo(n.zoom.__baseElem,s),n.needsRedraw=!0}},zoomToFit:function(n){for(var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:10,a=arguments.length,i=new Array(a>3?a-3:0),s=3;s<a;s++)i[s-3]=arguments[s];var l=this.getGraphBbox.apply(this,i);if(l){var u={x:(l.x[0]+l.x[1])/2,y:(l.y[0]+l.y[1])/2},d=Math.max(1e-12,Math.min(1e12,(n.width-r*2)/(l.x[1]-l.x[0]),(n.height-r*2)/(l.y[1]-l.y[0])));this.centerAt(u.x,u.y,o),this.zoom(d,o)}return this},getGraphBbox:function(n){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:function(){return!0},r=ae(n.nodeVal),a=function(l){return Math.sqrt(Math.max(0,r(l)||1))*n.nodeRelSize},i=n.graphData.nodes.filter(o).map(function(s){return{x:s.x,y:s.y,r:a(s)}});return i.length?{x:[Ar(i,function(s){return s.x-s.r}),Mr(i,function(s){return s.x+s.r})],y:[Ar(i,function(s){return s.y-s.r}),Mr(i,function(s){return s.y+s.r})]}:null},pauseAnimation:function(n){return n.animationFrameRequestId&&(cancelAnimationFrame(n.animationFrameRequestId),n.animationFrameRequestId=null),this},resumeAnimation:function(n){return n.animationFrameRequestId||this._animationCycle(),this},_destructor:function(){this.pauseAnimation(),this.graphData({nodes:[],links:[]})}},of),stateInit:function(){return{lastSetZoom:1,zoom:ks(),forceGraph:new Xn,shadowGraph:new Xn().cooldownTicks(0).nodeColor("__indexColor").linkColor("__indexColor").isShadow(!0),colorTracker:new od,tweenGroup:new Ji}},init:function(n,o){var r=this;n.innerHTML="";var a=document.createElement("div");a.classList.add("force-graph-container"),a.style.position="relative",n.appendChild(a),o.canvas=document.createElement("canvas"),o.backgroundColor&&(o.canvas.style.background=o.backgroundColor),a.appendChild(o.canvas),o.shadowCanvas=document.createElement("canvas");var i=o.canvas.getContext("2d"),s=o.shadowCanvas.getContext("2d",{willReadFrequently:!0}),l={x:-1e12,y:-1e12},u=function(){var m=null,f=window.devicePixelRatio,p=l.x>0&&l.y>0?s.getImageData(l.x*f,l.y*f,1,1):null;return p&&(m=o.colorTracker.lookup(p.data)),m};Oo(o.canvas).call(ws().subject(function(){if(!o.enableNodeDrag)return null;var h=u();return h&&h.type==="Node"?h.d:null}).on("start",function(h){var m=h.subject;m.__initialDragPos={x:m.x,y:m.y,fx:m.fx,fy:m.fy},h.active||(m.fx=m.x,m.fy=m.y),o.canvas.classList.add("grabbable")}).on("drag",function(h){var m=h.subject,f=m.__initialDragPos,p=h,g=ht(o.canvas).k,w={x:f.x+(p.x-f.x)/g-m.x,y:f.y+(p.y-f.y)/g-m.y};["x","y"].forEach(function(b){return m["f".concat(b)]=m[b]=f[b]+(p[b]-f[b])/g}),!(!m.__dragged&&ef>=Math.sqrt(_s(["x","y"].map(function(b){return Math.pow(h[b]-f[b],2)}))))&&(o.forceGraph.d3AlphaTarget(.3).resetCountdown(),o.isPointerDragging=!0,m.__dragged=!0,o.onNodeDrag(m,w))}).on("end",function(h){var m=h.subject,f=m.__initialDragPos,p={x:m.x-f.x,y:m.y-f.y};f.fx===void 0&&(m.fx=void 0),f.fy===void 0&&(m.fy=void 0),delete m.__initialDragPos,o.forceGraph.d3AlphaTarget()&&o.forceGraph.d3AlphaTarget(0).resetCountdown(),o.canvas.classList.remove("grabbable"),o.isPointerDragging=!1,m.__dragged&&(delete m.__dragged,o.onNodeDragEnd(m,p))})),o.zoom(o.zoom.__baseElem=Oo(o.canvas)),o.zoom.__baseElem.on("dblclick.zoom",null),o.zoom.filter(function(h){return!h.button&&o.enableZoomPanInteraction&&(h.type!=="wheel"||ae(o.enableZoomInteraction)(h))&&(h.type==="wheel"||ae(o.enablePanInteraction)(h))}).on("zoom",function(h){var m=h.transform;[i,s].forEach(function(f){Sa(f),f.translate(m.x,m.y),f.scale(m.k,m.k)}),o.isPointerDragging=!0,o.onZoom&&o.onZoom(Qt(Qt({},m),r.centerAt())),o.needsRedraw=!0}).on("end",function(h){o.isPointerDragging=!1,o.onZoomEnd&&o.onZoomEnd(Qt(Qt({},h.transform),r.centerAt()))}),Io(o),o.forceGraph.onNeedsRedraw(function(){return o.needsRedraw=!0}).onFinishUpdate(function(){ht(o.canvas).k===o.lastSetZoom&&o.graphData.nodes.length&&(o.zoom.scaleTo(o.zoom.__baseElem,o.lastSetZoom=Qu/Math.cbrt(o.graphData.nodes.length)),o.needsRedraw=!0)}),o.tooltip=new Sd(a),["pointermove","pointerdown"].forEach(function(h){return a.addEventListener(h,function(m){h==="pointerdown"&&(o.isPointerPressed=!0,o.pointerDownEvent=m),!o.isPointerDragging&&m.type==="pointermove"&&o.onBackgroundClick&&(m.pressure>0||o.isPointerPressed)&&(m.pointerType==="mouse"||m.movementX===void 0||[m.movementX,m.movementY].some(function(g){return Math.abs(g)>1}))&&(o.isPointerDragging=!0);var f=p(a);l.x=m.pageX-f.left,l.y=m.pageY-f.top;function p(g){var w=g.getBoundingClientRect(),b=window.pageXOffset||document.documentElement.scrollLeft,v=window.pageYOffset||document.documentElement.scrollTop;return{top:w.top+v,left:w.left+b}}},{passive:!0})}),a.addEventListener("pointerup",function(h){if(o.isPointerPressed){if(o.isPointerPressed=!1,o.isPointerDragging){o.isPointerDragging=!1;return}var m=[h,o.pointerDownEvent];requestAnimationFrame(function(){if(h.button===0)if(o.hoverObj){var f=o["on".concat(o.hoverObj.type,"Click")];f&&f.apply(void 0,[o.hoverObj.d].concat(m))}else o.onBackgroundClick&&o.onBackgroundClick.apply(o,m);if(h.button===2)if(o.hoverObj){var p=o["on".concat(o.hoverObj.type,"RightClick")];p&&p.apply(void 0,[o.hoverObj.d].concat(m))}else o.onBackgroundRightClick&&o.onBackgroundRightClick.apply(o,m)})}},{passive:!0}),a.addEventListener("contextmenu",function(h){return!o.onBackgroundRightClick&&!o.onNodeRightClick&&!o.onLinkRightClick?!0:(h.preventDefault(),!1)}),o.forceGraph(i),o.shadowGraph(s);var d=Is(function(){Di(s,o.width,o.height),o.shadowGraph.linkWidth(function(m){return ae(o.linkWidth)(m)+o.linkHoverPrecision});var h=ht(o.canvas);o.shadowGraph.globalScale(h.k).tickFrame()},Zu);o.flushShadowCanvas=d.flush,(this._animationCycle=function h(){var m=!o.autoPauseRedraw||!!o.needsRedraw||o.forceGraph.isEngineRunning()||o.graphData.links.some(function(D){return D.__photons&&D.__photons.length});if(o.needsRedraw=!1,o.enablePointerInteraction){var f=o.isPointerDragging?null:u();if(f!==o.hoverObj){var p=o.hoverObj,g=p?p.type:null,w=f?f.type:null;if(g&&g!==w){var b=o["on".concat(g,"Hover")];b&&b(null,p.d)}if(w){var v=o["on".concat(w,"Hover")];v&&v(f.d,g===w?p.d:null)}o.tooltip.content(f&&ae(o["".concat(f.type.toLowerCase(),"Label")])(f.d)||null),o.canvas.classList[(f&&o["on".concat(w,"Click")]||!f&&o.onBackgroundClick)&&ae(o.showPointerCursor)(f==null?void 0:f.d)?"add":"remove"]("clickable"),o.hoverObj=f}m&&d()}if(m){Di(i,o.width,o.height);var S=ht(o.canvas).k;o.onRenderFramePre&&o.onRenderFramePre(i,S),o.forceGraph.globalScale(S).tickFrame(),o.onRenderFramePost&&o.onRenderFramePost(i,S)}o.tweenGroup.update(),o.animationFrameRequestId=requestAnimationFrame(h)})()},update:function(n){}}),Ca={exports:{}},af="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",sf=af,lf=sf;function Da(){}function Na(){}Na.resetWarningCache=Da;var cf=function(){function e(r,a,i,s,l,u){if(u!==lf){var d=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw d.name="Invariant Violation",d}}e.isRequired=e;function n(){return e}var o={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:n,element:e,elementType:e,instanceOf:n,node:e,objectOf:n,oneOf:n,oneOfType:n,shape:n,exact:n,checkPropTypes:Na,resetWarningCache:Da};return o.PropTypes=o,o};Ca.exports=cf();var df=Ca.exports;const C=as(df),ro={width:C.number,height:C.number,graphData:C.shape({nodes:C.arrayOf(C.object).isRequired,links:C.arrayOf(C.object).isRequired}),backgroundColor:C.string,nodeRelSize:C.number,nodeId:C.string,nodeLabel:C.oneOfType([C.string,C.func]),nodeVal:C.oneOfType([C.number,C.string,C.func]),nodeVisibility:C.oneOfType([C.bool,C.string,C.func]),nodeColor:C.oneOfType([C.string,C.func]),nodeAutoColorBy:C.oneOfType([C.string,C.func]),onNodeHover:C.func,onNodeClick:C.func,linkSource:C.string,linkTarget:C.string,linkLabel:C.oneOfType([C.string,C.func]),linkVisibility:C.oneOfType([C.bool,C.string,C.func]),linkColor:C.oneOfType([C.string,C.func]),linkAutoColorBy:C.oneOfType([C.string,C.func]),linkWidth:C.oneOfType([C.number,C.string,C.func]),linkCurvature:C.oneOfType([C.number,C.string,C.func]),linkDirectionalArrowLength:C.oneOfType([C.number,C.string,C.func]),linkDirectionalArrowColor:C.oneOfType([C.string,C.func]),linkDirectionalArrowRelPos:C.oneOfType([C.number,C.string,C.func]),linkDirectionalParticles:C.oneOfType([C.number,C.string,C.func]),linkDirectionalParticleSpeed:C.oneOfType([C.number,C.string,C.func]),linkDirectionalParticleOffset:C.oneOfType([C.number,C.string,C.func]),linkDirectionalParticleWidth:C.oneOfType([C.number,C.string,C.func]),linkDirectionalParticleColor:C.oneOfType([C.string,C.func]),onLinkHover:C.func,onLinkClick:C.func,dagMode:C.oneOf(["td","bu","lr","rl","zin","zout","radialin","radialout"]),dagLevelDistance:C.number,dagNodeFilter:C.func,onDagError:C.func,d3AlphaMin:C.number,d3AlphaDecay:C.number,d3VelocityDecay:C.number,warmupTicks:C.number,cooldownTicks:C.number,cooldownTime:C.number,onEngineTick:C.func,onEngineStop:C.func,getGraphBbox:C.func},Pa={zoomToFit:C.func,onNodeRightClick:C.func,onNodeDrag:C.func,onNodeDragEnd:C.func,onLinkRightClick:C.func,linkHoverPrecision:C.number,onBackgroundClick:C.func,onBackgroundRightClick:C.func,showPointerCursor:C.oneOfType([C.bool,C.func]),enablePointerInteraction:C.bool,enableNodeDrag:C.bool},ur={showNavInfo:C.bool,nodeOpacity:C.number,nodeResolution:C.number,nodeThreeObject:C.oneOfType([C.object,C.string,C.func]),nodeThreeObjectExtend:C.oneOfType([C.bool,C.string,C.func]),nodePositionUpdate:C.func,linkOpacity:C.number,linkResolution:C.number,linkCurveRotation:C.oneOfType([C.number,C.string,C.func]),linkMaterial:C.oneOfType([C.object,C.string,C.func]),linkThreeObject:C.oneOfType([C.object,C.string,C.func]),linkThreeObjectExtend:C.oneOfType([C.bool,C.string,C.func]),linkPositionUpdate:C.func,linkDirectionalArrowResolution:C.number,linkDirectionalParticleResolution:C.number,linkDirectionalParticleThreeObject:C.oneOfType([C.object,C.string,C.func]),forceEngine:C.oneOf(["d3","ngraph"]),ngraphPhysics:C.object,numDimensions:C.oneOf([1,2,3])},uf=Object.assign({},ro,Pa,{linkLineDash:C.oneOfType([C.arrayOf(C.number),C.string,C.func]),nodeCanvasObjectMode:C.oneOfType([C.string,C.func]),nodeCanvasObject:C.func,nodePointerAreaPaint:C.func,linkCanvasObjectMode:C.oneOfType([C.string,C.func]),linkCanvasObject:C.func,linkPointerAreaPaint:C.func,linkDirectionalParticleCanvasObject:C.func,autoPauseRedraw:C.bool,minZoom:C.number,maxZoom:C.number,enableZoomInteraction:C.oneOfType([C.bool,C.func]),enablePanInteraction:C.oneOfType([C.bool,C.func]),onZoom:C.func,onZoomEnd:C.func,onRenderFramePre:C.func,onRenderFramePost:C.func});Object.assign({},ro,Pa,ur,{enableNavigationControls:C.bool,controlType:C.oneOf(["trackball","orbit","fly"]),rendererConfig:C.object,extraRenderers:C.arrayOf(C.shape({render:C.func.isRequired}))});Object.assign({},ro,ur,{nodeDesc:C.oneOfType([C.string,C.func]),linkDesc:C.oneOfType([C.string,C.func])});Object.assign({},ro,ur,{markerAttrs:C.object,yOffset:C.number,glScale:C.number});const fr=dc(rf,{methodNames:["emitParticle","d3Force","d3ReheatSimulation","stopAnimation","pauseAnimation","resumeAnimation","centerAt","zoom","zoomToFit","getGraphBbox","screen2GraphCoords","graph2ScreenCoords"]});fr.displayName="ForceGraph2D";fr.propTypes=uf;const ff=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function mf(e){const{t:n}=Ve(),[o,r]=x.useState("deepseek"),[a,i]=x.useState(""),[s,l]=x.useState(""),[u,d]=x.useState("openai-completions"),[h,m]=x.useState(""),[f,p]=x.useState(!1),[g,w]=x.useState(!1),[b,v]=x.useState(null),S=x.useRef(!1);function D(I){if(i(I),S.current)return;I.toLowerCase().includes("anthropic")?d("anthropic-messages"):d("openai-completions")}function P(I){S.current=!0,d(I)}async function _(){var N;const I=h.trim();if(!I){v("请输入 API Key");return}w(!0),v(null);try{if(o==="deepseek")await qr({kind:"deepseek",modelId:"deepseek-flash",apiKey:I});else{const L=a.trim();if(!L){v("请输入 API 地址");return}const E=s.trim();if(!E){v("请输入 Model ID");return}await qr({kind:"custom",baseUrl:L,modelId:E,apiType:u,apiKey:I})}m(""),i(""),l(""),await((N=e.onConfigured)==null?void 0:N.call(e))}catch(L){v(L instanceof Error?L.message:String(L))}finally{w(!1)}}const T=h.trim()&&(o==="deepseek"||a.trim()&&s.trim());return c.jsxs("div",{className:"mdocs-agent-apikey-inline",children:[c.jsx("p",{className:"mdocs-agent-apikey-inline-lead",children:"配置 AI 供应商后即可使用(仅本人可见,不会分享给其他访客)"}),c.jsxs("div",{className:"mdocs-agent-kind-tabs mdocs-agent-apikey-inline-tabs",role:"tablist","aria-label":"配置方式",children:[c.jsx("button",{type:"button",role:"tab","aria-selected":o==="deepseek",className:o==="deepseek"?"active":"",onClick:()=>r("deepseek"),disabled:g,children:"Deepseek"}),c.jsx("button",{type:"button",role:"tab","aria-selected":o==="custom",className:o==="custom"?"active":"",onClick:()=>r("custom"),disabled:g,children:"自定义"})]}),o==="custom"?c.jsxs(c.Fragment,{children:[c.jsxs("label",{className:"mdocs-agent-field mdocs-agent-apikey-inline-field",children:[c.jsx("span",{children:"API 地址"}),c.jsx("input",{type:"url",value:a,onChange:I=>D(I.target.value),placeholder:"https://api.example.com/v1",className:"mdocs-agent-mono",disabled:g,onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),_())}})]}),c.jsxs("label",{className:"mdocs-agent-field mdocs-agent-apikey-inline-field",children:[c.jsx("span",{children:"API 协议"}),c.jsx("div",{className:"mdocs-agent-apikey-inline-protocol",children:ff.map(I=>c.jsx("button",{type:"button",className:u===I.value?"active":"",onClick:()=>P(I.value),disabled:g,children:I.label},I.value))})]}),c.jsxs("label",{className:"mdocs-agent-field mdocs-agent-apikey-inline-field",children:[c.jsx("span",{children:"Model ID"}),c.jsx("input",{type:"text",value:s,onChange:I=>l(I.target.value),placeholder:"模型名称,如 gpt-4o / claude-3-5-sonnet",className:"mdocs-agent-mono",disabled:g,onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),_())}})]})]}):null,c.jsxs("div",{className:"mdocs-agent-config-apikey mdocs-agent-apikey-inline-field",children:[c.jsx("input",{type:f?"text":"password",value:h,onChange:I=>m(I.target.value),placeholder:n("agentConfigApiKeyPlaceholder"),autoComplete:"off",disabled:g,onKeyDown:I=>{I.key==="Enter"&&(I.preventDefault(),_())}}),c.jsx("button",{type:"button",className:"mdocs-agent-config-eye","aria-label":n(f?"agentConfigHideKey":"agentConfigShowKey"),onClick:()=>p(I=>!I),disabled:g,children:f?c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[c.jsx("path",{d:"M3 3l18 18"}),c.jsx("path",{d:"M10.6 10.6a2 2 0 002.8 2.8"}),c.jsx("path",{d:"M9.9 5.1A10.5 0 0121 12c-.6 1.1-1.4 2.1-2.4 2.9"}),c.jsx("path",{d:"M6.1 6.1C4.5 7.4 3.2 9.1 2.5 12c1.5 3.5 5 7 9.5 7 1.4 0 2.7-.3 3.9-.8"})]}):c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":!0,children:[c.jsx("path",{d:"M2.5 12C4 8.5 7.5 5 12 5s8 3.5 9.5 7c-1.5 3.5-5 7-9.5 7s-8-3.5-9.5-7z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]}),b?c.jsx("p",{className:"mdocs-agent-apikey-inline-error",children:b}):null,c.jsx("button",{type:"button",className:"mdocs-agent-apikey-inline-save",onClick:()=>void _(),disabled:g||!T,children:g?n("saving"):"保存并启用"})]})}function Ni(e){return e==="contains"}function hf(e){return e==="related_to"||e==="part_of"||e==="depends_on"}function pf(e,n){var h,m;const o=new Set(e),r=new Map,a=new Map,i=new Map;for(const f of e)r.set(f,[]),a.set(f,[]),i.set(f,0);for(const f of n)!o.has(f.from)||!o.has(f.to)||f.from===f.to||(r.get(f.from).push(f.to),a.get(f.to).push(f.from),i.set(f.to,(i.get(f.to)??0)+1));let s=e.filter(f=>(i.get(f)??0)===0);if(s.length===0&&e.length>0){const f=new Map;for(const w of e)f.set(w,(((h=r.get(w))==null?void 0:h.length)??0)+(((m=a.get(w))==null?void 0:m.length)??0));const p=[...e].sort((w,b)=>(f.get(b)??0)-(f.get(w)??0)),g=f.get(p[0])??0;s=p.filter(w=>(f.get(w)??0)===g).slice(0,12)}const l=new Map,u=[];for(const f of s)l.set(f,0),u.push(f);let d=0;for(;d<u.length;){const f=u[d++],p=l.get(f)??0;for(const g of r.get(f)??[]){const w=p+1;(!l.has(g)||w<(l.get(g)??1/0))&&(l.set(g,w),u.push(g))}}for(const f of e)l.has(f)||l.set(f,0);return{childrenOf:r,parentsOf:a,roots:s,depthMap:l}}function ko(e,n,o,r,a){return a.has(e)?!1:(o.get(e)??0)<n?!0:r.has(e)}function gf(e,n,o){const r=new Set(e),a=[...e];let i=0;for(;i<a.length;){const s=a[i++];if(o(s))for(const l of n.get(s)??[])r.has(l)||(r.add(l),a.push(l))}return r}function yf(e,n){const o=[],r=new Set,a=[...n.get(e)??[]];for(;a.length>0;){const i=a.pop();if(!r.has(i)){r.add(i),o.push(i);for(const s of n.get(i)??[])a.push(s)}}return o}function vf(e){const{event:n,data:o}=e;switch(n){case"task.started":return`🚀 开始生成,共 ${(o==null?void 0:o.totalDocs)??0} 篇文档`;case"doc.started":return`📄 处理中:${(o==null?void 0:o.docPath)??""}(${(o==null?void 0:o.index)??0}/${(o==null?void 0:o.total)??0})`;case"doc.completed":return`✅ ${(o==null?void 0:o.docPath)??""}(提取 ${(o==null?void 0:o.conceptsExtracted)??0} 个知识块)`;case"doc.failed":return`⚠️ ${(o==null?void 0:o.docPath)??""} 失败:${(o==null?void 0:o.error)??""}`;case"folder.started":return`📁 归纳目录:${(o==null?void 0:o.folderPath)??""}`;case"folder.completed":return`✅ 目录归纳完成:${(o==null?void 0:o.folderPath)??""}`;case"domain.started":return"🌐 开始 domain 级合成";case"domain.completed":return`✅ domain 合成完成(${(o==null?void 0:o.totalNodes)??0} 节点,${(o==null?void 0:o.totalEdges)??0} 边)`;case"task.yielded":return"⏸️ 让出资源,排队等待中...";case"task.progress":return`⏳ ${(o==null?void 0:o.phase)??"progress"} ${(o==null?void 0:o.current)??0}/${(o==null?void 0:o.total)??0}`;case"task.completed":return`🎉 生成完成!${(o==null?void 0:o.nodes)??0} 个节点,${(o==null?void 0:o.edges)??0} 条边`;case"task.failed":return`❌ 生成失败:${(o==null?void 0:o.error)??""}`;default:return`${n}${o?`: ${JSON.stringify(o)}`:""}`}}function So(e){return e<=1?"排队中,即将开始…":`排队中,前面还有 ${e-1} 个任务`}function Co(e,n,o){const r=Math.max(e,.2);return Math.max(o??n*.75,n)/r}function bf({scope:e,resourceId:n,name:o,onOpenDocument:r,onClose:a}){const[i,s]=x.useState(null),[l,u]=x.useState(!0),[d,h]=x.useState(null),[m,f]=x.useState(!1),[p,g]=x.useState(!1),[w,b]=x.useState(0),[v,S]=x.useState(()=>new Set),[D,P]=x.useState(()=>new Set),[_,T]=x.useState(null),[I,N]=x.useState(null),[L,E]=x.useState(null),O=x.useRef(null),$=x.useRef(new Map),[V,J]=x.useState("not_found"),[ne,B]=x.useState([]),[G,ce]=x.useState(null),[ue,A]=x.useState(0),ie=`graph:${e==="domain"?"domain":"dir"}:${n}`,oe=x.useRef(ie),re=x.useRef(null),[K,Z]=x.useState(!1),[we,se]=x.useState(!1),[tt,Tt]=x.useState(!1),[vt,rn]=x.useState(!1),[Vt,At]=x.useState(!1),nt=x.useRef(null),_e=V==="running"||V==="pending";x.useEffect(()=>{let k=!1;return u(!0),h(null),T(null),b(0),S(new Set),P(new Set),g(!1),E(null),$.current=new Map,(e==="domain"?Yr:Kr)(n).then(z=>{k||(s(z),u(!1))}).catch(z=>{k||(h(z.message||"加载失败"),u(!1))}),()=>{k=!0}},[n,e]),x.useEffect(()=>(oe.current=ie,We(),Ge(),()=>We()),[ie]);async function Ge(){try{const k=await Vl(oe.current);J(k.status),B(k.logs),ce(k.progress??null),A(k.position),k.status==="completed"?(We(),Mt()):k.status==="failed"||k.status==="stale"?(We(),k.error&&h(k.error)):(k.status==="running"||k.status==="pending")&&Pn()}catch{}}function Pn(){re.current||(re.current=window.setInterval(()=>{Ge()},2e3))}function We(){re.current&&(clearInterval(re.current),re.current=null)}async function Mt(){try{const j=await(e==="domain"?Yr:Kr)(n);s(j)}catch(k){h(k.message||"加载失败")}}const $e=async()=>{if(!_e){h(null),Z(!1);try{const j=await(e==="domain"?Hl:Bl)(n);oe.current=j.taskId,J(j.status),A(j.position),B([]),ce(null),Pn()}catch(k){if(k instanceof et&&k.code==="AI_NOT_CONFIGURED"){Z(!0),h(k.message);return}h((k==null?void 0:k.message)||"生成失败")}}},Gt=async()=>{se(!1),Z(!1),h(null),await $e()},Ee=x.useMemo(()=>i?m?i.nodes:i.nodes.filter(k=>k.type==="concept"):[],[i,m]),me=x.useMemo(()=>{if(!i)return[];const k=new Set(Ee.map(j=>j.id));return i.edges.filter(j=>k.has(j.from)&&k.has(j.to))},[i,Ee]),Ce=x.useMemo(()=>{const k=me.filter(j=>Ni(String(j.type))).map(j=>({from:j.from,to:j.to}));return pf(Ee.map(j=>j.id),k)},[Ee,me]),be=x.useMemo(()=>gf(Ce.roots,Ce.childrenOf,k=>ko(k,w,Ce.depthMap,v,D)),[Ce,w,v,D]),{displayNodes:xe,displayEdges:jt}=x.useMemo(()=>{const k=Ee.filter(z=>be.has(z.id)),j=me.filter(z=>{if(!be.has(z.from)||!be.has(z.to))return!1;const F=String(z.type);return!!(Ni(F)||p&&hf(F))});return{displayNodes:k,displayEdges:j}},[Ee,me,be,p]),bt=x.useMemo(()=>{const k=new Map;for(const j of Ee)k.set(j.id,j);return k},[Ee]);function ct(k){b(k),S(new Set),P(new Set)}function an(k){if((Ce.childrenOf.get(k)??[]).length===0)return;ko(k,w,Ce.depthMap,v,D)?(P(F=>new Set(F).add(k)),S(F=>{const q=new Set(F);return q.delete(k),q})):(P(F=>{const q=new Set(F);return q.delete(k),q}),S(F=>new Set(F).add(k)))}function Me(k){const j=yf(k.id,Ce.parentsOf);P(z=>{const F=new Set(z);for(const q of j)F.delete(q);return F}),S(z=>{const F=new Set(z);for(const q of j)F.add(q);return F}),T(k)}const sn=x.useMemo(()=>{const k=xe.map(F=>{var De;const q=((De=Ce.childrenOf.get(F.id))==null?void 0:De.length)??0,X=ko(F.id,w,Ce.depthMap,v,D),te=$.current.get(F.id);let Q=te==null?void 0:te.x,ye=te==null?void 0:te.y;if(Q==null||ye==null){const je=(Ce.parentsOf.get(F.id)??[]).map(Ne=>$.current.get(Ne)).find(Ne=>Ne!=null);je?(Q=je.x+(Math.random()-.5)*60,ye=je.y+50+Math.random()*40):(Q=(Math.random()-.5)*240,ye=(Math.random()-.5)*180),$.current.set(F.id,{x:Q,y:ye})}return{id:F.id,name:F.label,type:F.type,val:F.type==="concept"?4:2,x:Q,y:ye,__raw:F,__childCount:q,__expanded:X}}),j=new Map,z=jt.map(F=>{const q=`${F.from}->${F.to}`,X=j.get(q)??0;j.set(q,X+1);const te=X===0?.08:.08+X*.14;return{source:F.from,target:F.to,type:F.type,curvature:te,__raw:F}});return{nodes:k,links:z}},[xe,jt,Ce,w,v,D]),ot=x.useMemo(()=>{const k=Math.max(1,xe.length);return{linkDistance:Math.min(140,70+Math.sqrt(k)*8),chargeStrength:Math.max(-420,-120-k*6)}},[xe.length]),Fe=x.useRef(null),[qe,Tn]=x.useState({width:800,height:600});x.useEffect(()=>{if(!Fe.current)return;const k=()=>{Fe.current&&Tn({width:Fe.current.clientWidth,height:Fe.current.clientHeight})};k();const j=new ResizeObserver(k);return j.observe(Fe.current),()=>j.disconnect()},[]),x.useEffect(()=>{if(!i||l)return;const k=window.setTimeout(()=>{var j,z;(z=(j=O.current)==null?void 0:j.zoomToFit)==null||z.call(j,400,80)},450);return()=>window.clearTimeout(k)},[i,m,p,l,qe.width,qe.height,w,be]),x.useEffect(()=>{var F,q,X,te;if(!i||l)return;const k=O.current;if(!k)return;const j=k.d3Force("charge");(F=j==null?void 0:j.strength)==null||F.call(j,ot.chargeStrength);const z=k.d3Force("link");(q=z==null?void 0:z.distance)==null||q.call(z,ot.linkDistance),(X=z==null?void 0:z.strength)==null||X.call(z,.35),(te=k.d3ReheatSimulation)==null||te.call(k)},[ot,i,l,m,sn]);const xt=k=>(Ce.childrenOf.get(k)??[]).map(z=>bt.get(z)??(i==null?void 0:i.nodes.find(F=>F.id===z))).filter(z=>!!z),Wt=k=>(Ce.parentsOf.get(k)??[]).map(z=>bt.get(z)??(i==null?void 0:i.nodes.find(F=>F.id===z))).filter(z=>!!z),An=k=>{if(!i)return[];const j=new Set,z=[],F=[k];for(;F.length>0;){const q=F.shift();if(j.has(q))continue;j.add(q);const X=i.nodes.find(Q=>Q.id===q);(X==null?void 0:X.type)==="doc"&&z.push(X);const te=i.edges.filter(Q=>Q.from===q).map(Q=>Q.to);F.push(...te)}return z};return x.useEffect(()=>{if(!Vt)return;const k=j=>{nt.current&&!nt.current.contains(j.target)&&At(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[Vt]),c.jsxs("div",{className:"graph-page",children:[c.jsxs("div",{className:"graph-toolbar",children:[c.jsxs("div",{className:"graph-toolbar-left",children:[c.jsx("span",{className:"graph-icon",children:"🕸️"}),c.jsxs("span",{className:"graph-title-text",title:`知识图谱 — ${o}`,children:["知识图谱 — ",o]}),a&&c.jsx("button",{className:"graph-btn graph-btn-danger",onClick:a,children:"退出图谱"})]}),c.jsxs("div",{className:"graph-toolbar-right",children:[c.jsxs("div",{className:"graph-mobile-toggle-wrap",ref:nt,children:[c.jsx("button",{type:"button",className:"graph-mobile-toggle-btn",onClick:()=>At(k=>!k),"aria-label":"更多操作",children:c.jsx(zs,{size:18,strokeWidth:1.75})}),Vt&&c.jsxs("div",{className:"graph-mobile-actions card",onClick:()=>At(!1),children:[c.jsxs("div",{className:"graph-mobile-action-group",children:[c.jsx("div",{className:"graph-mobile-action-label",children:"层级控制"}),c.jsx("button",{type:"button",className:`graph-mobile-action-item ${w===1?"active":""}`,onMouseDown:()=>ct(1),children:"展开一级"}),c.jsx("button",{type:"button",className:`graph-mobile-action-item ${w===2?"active":""}`,onMouseDown:()=>ct(2),children:"展开到二级"}),c.jsx("button",{type:"button",className:`graph-mobile-action-item ${w===0&&v.size===0?"active":""}`,onMouseDown:()=>ct(0),children:"全部收起"})]}),c.jsxs("div",{className:"graph-mobile-action-group",children:[c.jsx("div",{className:"graph-mobile-action-label",children:"视图"}),c.jsxs("label",{className:"graph-mobile-action-switch",children:[c.jsx("input",{type:"checkbox",checked:p,onChange:k=>g(k.target.checked)}),c.jsx("span",{children:"显示其它关系"})]}),c.jsxs("label",{className:"graph-mobile-action-switch",children:[c.jsx("input",{type:"checkbox",checked:m,onChange:k=>f(k.target.checked)}),c.jsx("span",{children:"显示 doc 节点"})]})]}),c.jsxs("button",{className:"graph-mobile-action-item",onMouseDown:()=>se(!0),children:[c.jsx(ho,{size:14}),"配置 AI"]}),c.jsx("button",{className:"graph-mobile-action-item graph-mobile-action-primary",onMouseDown:$e,disabled:_e,children:_e?c.jsxs(c.Fragment,{children:[c.jsx(On,{size:14,className:"spin"}),V==="pending"?So(ue):"生成中..."]}):c.jsxs(c.Fragment,{children:[c.jsx(Fr,{size:14}),i?"重新生成":"生成图谱"]})})]})]}),c.jsxs("div",{className:"graph-desktop-actions",children:[c.jsxs("div",{className:"graph-dropdown",children:[c.jsxs("button",{type:"button",className:"graph-btn",onClick:()=>Tt(k=>!k),onBlur:()=>setTimeout(()=>Tt(!1),150),children:["层级控制 ",c.jsx(Fo,{size:12})]}),tt&&c.jsxs("div",{className:"graph-dropdown-menu graph-dropdown-menu--right",children:[c.jsx("button",{type:"button",className:`graph-dropdown-item ${w===1?"active":""}`,onMouseDown:()=>{ct(1),Tt(!1)},children:"展开一级"}),c.jsx("button",{type:"button",className:`graph-dropdown-item ${w===2?"active":""}`,onMouseDown:()=>{ct(2),Tt(!1)},children:"展开到二级"}),c.jsx("button",{type:"button",className:`graph-dropdown-item ${w===0&&v.size===0?"active":""}`,onMouseDown:()=>{ct(0),Tt(!1)},children:"全部收起"})]})]}),c.jsxs("div",{className:"graph-dropdown",children:[c.jsxs("button",{type:"button",className:"graph-btn",onClick:()=>rn(k=>!k),onBlur:()=>setTimeout(()=>rn(!1),150),children:[c.jsx(Us,{size:14})," 视图 ",c.jsx(Fo,{size:12})]}),vt&&c.jsxs("div",{className:"graph-dropdown-menu graph-dropdown-menu--right",children:[c.jsxs("label",{className:"graph-dropdown-switch",children:[c.jsx("input",{type:"checkbox",checked:p,onChange:k=>g(k.target.checked)}),c.jsx("span",{children:"显示其它关系"})]}),c.jsxs("label",{className:"graph-dropdown-switch",children:[c.jsx("input",{type:"checkbox",checked:m,onChange:k=>f(k.target.checked)}),c.jsx("span",{children:"显示 doc 节点"})]})]})]}),c.jsxs("button",{className:"graph-btn graph-btn-ghost",onClick:()=>se(!0),title:"配置用于图谱分析的 AI 模型",children:[c.jsx(ho,{size:14}),"配置 AI"]}),c.jsx("button",{className:"graph-btn graph-btn-primary",onClick:$e,disabled:_e,children:_e?c.jsxs(c.Fragment,{children:[c.jsx(On,{size:14,className:"spin"}),V==="pending"?So(ue):"生成中..."]}):c.jsxs(c.Fragment,{children:[c.jsx(Fr,{size:14}),i?"重新生成":"生成图谱"]})})]})]})]}),c.jsxs("div",{className:"graph-canvas-container",ref:Fe,children:[l&&c.jsxs("div",{className:"graph-loading",children:[c.jsx(On,{size:32,className:"spin"}),c.jsx("p",{children:"加载图谱中..."})]}),d&&!l&&c.jsx("div",{className:"graph-error",children:K?c.jsxs(c.Fragment,{children:[c.jsx("p",{style:{fontSize:40,margin:0},children:"🔑"}),c.jsx("h3",{children:"还没有配置 AI 模型"}),c.jsx("p",{className:"muted",children:"图谱由 AI 分析生成,需要先配置一个可用的模型"}),c.jsxs("button",{className:"graph-btn graph-btn-primary",onClick:()=>se(!0),style:{marginTop:12},children:[c.jsx(ho,{size:14}),"配置 AI"]})]}):c.jsxs(c.Fragment,{children:[c.jsxs("p",{children:["❌ ",d]}),c.jsx("button",{className:"graph-btn",onClick:$e,children:"重试生成"})]})}),!l&&!d&&!i&&!_e&&c.jsxs("div",{className:"graph-empty",children:[c.jsx("p",{style:{fontSize:48,margin:0},children:"🕸️"}),c.jsx("h3",{children:"还没有知识图谱"}),c.jsx("p",{className:"muted",children:"点击右上角「生成图谱」开始构建"}),c.jsx("button",{className:"graph-btn graph-btn-primary",onClick:$e,disabled:_e,children:_e?"生成中...":"生成图谱"})]}),_e&&c.jsxs("div",{className:"graph-progress-panel",children:[c.jsxs("div",{className:"graph-progress-header",children:[c.jsx(On,{size:16,className:"spin"}),c.jsx("span",{children:V==="pending"?So(ue):G?`正在生成(${G.current}/${G.total})`:"正在生成..."})]}),G&&G.total>0&&c.jsx("div",{className:"graph-progress-bar",children:c.jsx("div",{className:"graph-progress-bar-fill",style:{width:`${G.current/G.total*100}%`}})}),c.jsx("div",{className:"graph-progress-logs",children:ne.slice(-10).map((k,j)=>c.jsx("div",{className:`graph-log-item graph-log-${k.level}`,children:c.jsx("span",{className:"graph-log-event",children:vf(k)})},j))})]}),!l&&!d&&i&&i.nodes.length===0&&!_e&&c.jsxs("div",{className:"graph-empty",children:[c.jsx("p",{style:{fontSize:48,margin:0},children:"📄"}),c.jsx("h3",{children:"图谱已生成"}),c.jsx("p",{className:"muted",children:"当前内容暂未提取到可关联的知识概念"}),c.jsx("p",{className:"muted",style:{fontSize:13,marginTop:4},children:"内容较少或结构较简单时可能出现这种情况,补充更多内容后可以重新生成"}),c.jsx("button",{className:"graph-btn graph-btn-primary",onClick:$e,disabled:_e,style:{marginTop:12},children:"重新生成"})]}),!l&&!d&&i&&i.nodes.length>0&&c.jsx(fr,{ref:O,width:qe.width,height:qe.height,graphData:sn,nodeId:"id",nodeVal:k=>k.type==="concept"?6:3,nodeColor:k=>k.type==="concept"?"#8b5cf6":"#06b6d4",nodeCanvasObjectMode:()=>"replace",nodeCanvasObject:(k,j,z)=>{const F=String(k.name??""),q=k.type==="concept",X=k.id===(_==null?void 0:_.id)||k.id===I,te=(q?9:5)/Math.max(z,.35);if(j.beginPath(),j.arc(k.x,k.y,te,0,2*Math.PI),j.fillStyle=q?"#8b5cf6":"#06b6d4",j.globalAlpha=X||!_?1:.35,j.fill(),j.strokeStyle="#ffffff",j.lineWidth=1.5/Math.max(z,.35),j.stroke(),j.globalAlpha=1,k.__childCount>0){const _t=7/Math.max(z,.4),dt=k.x+te+_t*.9,fe=k.y-te*.2;j.beginPath(),j.arc(dt,fe,_t,0,2*Math.PI),j.fillStyle=k.__expanded?"#475569":"#6366f1",j.fill(),j.fillStyle="#ffffff";const Ke=k.__expanded?"−":"+",Et=Math.max(10/z,9/z);j.font=`700 ${Et}px -apple-system, BlinkMacSystemFont, sans-serif`,j.textAlign="center",j.textBaseline="middle",j.fillText(Ke,dt,fe+.5/z)}if(!(X||q&&z>=.55||!q&&z>=1.4))return;const ye=Math.max(10/z,q?11/z:9/z),De=q?z<.9?8:16:10,je=F.length>De?F.slice(0,De)+"…":F;j.font=`${q?"600":"400"} ${ye}px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,j.textAlign="center",j.textBaseline="top";const Ne=k.y+te+3/z,ke=j.measureText(je).width,Pe=4/z,wt=2/z;j.fillStyle="rgba(255,255,255,0.88)",j.fillRect(k.x-ke/2-Pe,Ne-wt,ke+Pe*2,ye+wt*2),j.fillStyle=q?"#1e1b4b":"#0c4a6e",j.fillText(je,k.x,Ne)},linkDirectionalArrowLength:k=>{var F,q,X,te,Q,ye;const j=((q=(F=O.current)==null?void 0:F.zoom)==null?void 0:q.call(F))??1,z=((X=k.source)==null?void 0:X.id)===I||((te=k.target)==null?void 0:te.id)===I||((Q=k.source)==null?void 0:Q.id)===(_==null?void 0:_.id)||((ye=k.target)==null?void 0:ye.id)===(_==null?void 0:_.id);return Co(j,z?13:11,9)},linkDirectionalArrowRelPos:.86,linkDirectionalArrowColor:()=>"#475569",linkWidth:k=>{var F,q,X,te,Q,ye;const j=((q=(F=O.current)==null?void 0:F.zoom)==null?void 0:q.call(F))??1,z=((X=k.source)==null?void 0:X.id)===I||((te=k.target)==null?void 0:te.id)===I||((Q=k.source)==null?void 0:Q.id)===(_==null?void 0:_.id)||((ye=k.target)==null?void 0:ye.id)===(_==null?void 0:_.id);return Co(j,z?3.5:3,2.25)},linkColor:k=>{var z,F,q,X;return((z=k.source)==null?void 0:z.id)===I||((F=k.target)==null?void 0:F.id)===I||((q=k.source)==null?void 0:q.id)===(_==null?void 0:_.id)||((X=k.target)==null?void 0:X.id)===(_==null?void 0:_.id)?"#334155":"#64748b"},linkCurvature:k=>k.curvature??.12,linkCanvasObjectMode:()=>"after",linkCanvasObject:(k,j,z)=>{if(z<.45)return;const F=k.source,q=k.target;if(F.x==null||F.y==null||q.x==null||q.y==null)return;const te={contains:"包含",related_to:"相关",part_of:"属于",depends_on:"依赖"}[k.type]||String(k.type??""),Q=typeof k.curvature=="number"?k.curvature:.12,ye=(F.x+q.x)/2,De=(F.y+q.y)/2,je=ye-(q.y-F.y)*Q,Ne=De+(q.x-F.x)*Q,ke=.5,Pe=1-ke,wt=Pe*Pe*F.x+2*Pe*ke*je+ke*ke*q.x,_t=Pe*Pe*F.y+2*Pe*ke*Ne+ke*ke*q.y,dt=2*Pe*(je-F.x)+2*ke*(q.x-je),fe=2*Pe*(Ne-F.y)+2*ke*(q.y-Ne);let Ke=Math.atan2(fe,dt);(Ke>Math.PI/2||Ke<-Math.PI/2)&&(Ke+=Math.PI);const Et=Co(z,11,9);j.save(),j.translate(wt,_t),j.rotate(Ke),j.font=`500 ${Et}px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,j.textAlign="center",j.textBaseline="middle";const ln=j.measureText(te).width,Rt=3/z,qt=1.5/z;j.fillStyle="rgba(255,255,255,0.92)",j.fillRect(-ln/2-Rt,-Et/2-qt,ln+Rt*2,Et+qt*2),j.fillStyle="#475569",j.fillText(te,0,0),j.restore()},onZoom:()=>{var k,j;(j=(k=O.current)==null?void 0:k.refresh)==null||j.call(k)},cooldownTicks:120,cooldownTime:4e3,d3AlphaDecay:.022,d3VelocityDecay:.3,onNodeClick:(k,j)=>{var q,X,te,Q,ye;const z=k.__childCount??0;if(z>0&&O.current&&Fe.current){const De=Fe.current.getBoundingClientRect(),je=O.current.screen2GraphCoords(j.clientX-De.left,j.clientY-De.top),Ne=((X=(q=O.current).zoom)==null?void 0:X.call(q))??1,ke=(k.type==="concept"?9:5)/Math.max(Ne,.35),Pe=7/Math.max(Ne,.4),wt=k.x+ke+Pe*.9,_t=k.y-ke*.2,dt=je.x-wt,fe=je.y-_t;if(dt*dt+fe*fe<=(Pe+4/Ne)**2){an(String(k.id)),T(k.__raw);return}}const F=k.__raw;if(T(F),z>0&&!k.__expanded&&an(String(k.id)),(F==null?void 0:F.type)==="doc"){const De=(ye=(Q=(te=F.sources)==null?void 0:te[0])==null?void 0:Q.documentId)==null?void 0:ye.trim();De&&r(De)}},onNodeHover:k=>{var z;if(!k){N(null),E(null);return}N(String(k.id));const j=String(k.name??((z=k.__raw)==null?void 0:z.label)??"");if(O.current&&j){const F=O.current.graph2ScreenCoords(k.x,k.y);E({text:j,x:F.x,y:F.y})}else E({text:j,x:0,y:0})},onBackgroundClick:()=>{T(null),N(null),E(null)},onEngineTick:()=>{var j,z;const k=(z=(j=O.current)==null?void 0:j.graphData)==null?void 0:z.call(j);if(k!=null&&k.nodes)for(const F of k.nodes)F.id!=null&&F.x!=null&&F.y!=null&&$.current.set(String(F.id),{x:F.x,y:F.y})},onEngineStop:()=>{var k,j;(j=(k=O.current)==null?void 0:k.zoomToFit)==null||j.call(k,300,72)},linkHoverPrecision:8,enableNodeDrag:!0,enableZoomInteraction:!0,enablePanInteraction:!0,nodePointerAreaPaint:(k,j,z,F)=>{const q=(k.type==="concept"?14:9)/Math.max(F,.35);if(z.fillStyle=j,z.beginPath(),z.arc(k.x,k.y,q,0,2*Math.PI),z.fill(),k.__childCount>0){const X=10/Math.max(F,.4),te=(k.type==="concept"?9:5)/Math.max(F,.35),Q=k.x+te+X*.7,ye=k.y-te*.2;z.beginPath(),z.arc(Q,ye,X,0,2*Math.PI),z.fill()}}}),L&&c.jsx("div",{className:"graph-node-tooltip",style:{left:L.x,top:L.y},children:L.text})]}),_&&c.jsxs("div",{className:"graph-detail-panel",children:[c.jsxs("div",{className:"graph-detail-header",children:[c.jsx("span",{className:`graph-node-type-badge ${_.type}`,children:_.type==="concept"?"概念":"知识要点"}),c.jsx("button",{type:"button",className:"graph-close-btn","aria-label":"关闭",onClick:()=>T(null),children:c.jsx(zt,{size:18,strokeWidth:2.25})})]}),c.jsx("h3",{className:"graph-detail-title",children:_.label}),_.definition&&c.jsxs("div",{className:"graph-detail-section",children:[c.jsx("h4",{children:"定义"}),c.jsx("p",{children:_.definition})]}),c.jsxs("div",{className:"graph-detail-section",children:[c.jsx("h4",{children:"描述"}),c.jsx("p",{children:_.description})]}),c.jsx("div",{className:"graph-detail-meta",children:c.jsxs("span",{children:["置信度: ",(_.confidence*100).toFixed(0),"%"]})}),_.type==="concept"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"graph-detail-section",children:[c.jsxs("h4",{children:["包含的子节点 (",xt(_.id).length,")"]}),c.jsxs("ul",{className:"graph-node-list",children:[xt(_.id).slice(0,20).map(k=>c.jsxs("li",{className:`graph-node-item ${k.type}`,onClick:()=>Me(k),children:[c.jsx("span",{className:"dot"}),k.label]},k.id)),xt(_.id).length>20&&c.jsxs("li",{className:"muted",children:["还有 ",xt(_.id).length-20," 个..."]})]})]}),c.jsxs("div",{className:"graph-detail-section",children:[c.jsxs("h4",{children:["相关文章 (",An(_.id).length,")"]}),c.jsx("ul",{className:"graph-doc-list",children:Array.from(new Set(An(_.id).flatMap(k=>{var j;return((j=k.sources)==null?void 0:j.map(z=>({documentId:z.documentId,title:z.title||z.documentId,heading:z.heading})))||[]}))).slice(0,10).map((k,j)=>c.jsx("li",{className:"graph-doc-item",children:c.jsxs("button",{onClick:()=>r(k.documentId),children:["📄 ",k.title,k.heading&&c.jsxs("span",{className:"muted",children:[" · ",k.heading]})]})},j))})]})]}),_.type==="doc"&&_.sources&&c.jsxs("div",{className:"graph-detail-section",children:[c.jsx("h4",{children:"来源"}),c.jsx("ul",{className:"graph-doc-list",children:_.sources.map((k,j)=>c.jsx("li",{className:"graph-doc-item",children:c.jsxs("button",{onClick:()=>r(k.documentId),children:["📄 ",k.title||k.documentId,k.heading&&c.jsxs("span",{className:"muted",children:[" · ",k.heading]})]})},j))})]}),Wt(_.id).length>0&&c.jsxs("div",{className:"graph-detail-section",children:[c.jsxs("h4",{children:["所属概念 (",Wt(_.id).length,")"]}),c.jsx("ul",{className:"graph-node-list",children:Wt(_.id).map(k=>c.jsxs("li",{className:`graph-node-item ${k.type}`,onClick:()=>Me(k),children:[c.jsx("span",{className:"dot"}),k.label]},k.id))})]})]}),we&&c.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:k=>{k.target===k.currentTarget&&se(!1)},children:c.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true","aria-label":"配置 AI 模型",children:[c.jsx("h2",{children:"配置 AI 模型"}),c.jsx(mf,{onConfigured:Gt}),c.jsx("div",{className:"mdocs-dialog-actions",children:c.jsx("button",{type:"button",onClick:()=>se(!1),children:"取消"})})]})})]})}async function Pi(e){var o;const n=e.replace(/\u00a0/g," ");if(!n)return!1;try{if(typeof navigator<"u"&&((o=navigator.clipboard)!=null&&o.writeText))return await navigator.clipboard.writeText(n),!0}catch{}try{const r=document.createElement("textarea");r.value=n,r.setAttribute("readonly",""),r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.width="1px",r.style.height="1px",r.style.padding="0",r.style.border="none",r.style.outline="none",r.style.boxShadow="none",r.style.background="transparent",r.style.opacity="0",document.body.appendChild(r),r.focus(),r.select(),r.setSelectionRange(0,n.length);const a=document.execCommand("copy");return document.body.removeChild(r),a}catch{return!1}}function xf(e){var d;const{t:n}=Ve(),o=x.useRef(null);x.useEffect(()=>{function h(f){o.current&&!o.current.contains(f.target)&&e.onClose()}function m(f){f.key==="Escape"&&e.onClose()}return window.addEventListener("mousedown",h),window.addEventListener("keydown",m),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",m)}},[e.onClose]);const r=e.node.type==="folder";let a="";if(e.node.type==="folder"){const h=e.node;a=((d=h.folderDisplayName)==null?void 0:d.trim())||h.path||""}const i=r?a?n("newDocIn",{name:a}):n("newDocAtRoot"):n("newDocBeside"),s=r?a?n("newFolderIn",{name:a}):n("newFolderAtRoot"):n("newFolderBeside"),l=e.node.documentId,u=e.node.type==="folder"&&e.node.descDocumentId||e.node.documentId;return c.jsxs("div",{ref:o,className:"mdocs-context-menu card",style:{left:e.x,top:e.y},children:[c.jsx("button",{type:"button",className:"mdocs-context-item",onClick:()=>{const h=r?e.node.path:e.parentPath;e.onCreateChild(h),e.onClose()},children:i}),c.jsx("button",{type:"button",className:"mdocs-context-item",onClick:()=>{const h=r?e.node.path:e.parentPath;e.onCreateFolder(h),e.onClose()},children:s}),c.jsx("div",{className:"mdocs-context-divider"}),c.jsx("button",{type:"button",className:"mdocs-context-item",onClick:()=>{Pi(l).finally(e.onClose)},children:n("copyDocumentId")}),c.jsx("button",{type:"button",className:"mdocs-context-item",onClick:()=>{const h="/",m=h.endsWith("/")?h:`${h}/`;Pi(`${window.location.origin}${m}#/doc/${u}`).finally(e.onClose)},children:n("copyDocumentUrl")}),c.jsx("div",{className:"mdocs-context-divider"}),c.jsx("button",{type:"button",className:"mdocs-context-item danger",onClick:()=>{e.node.type==="document"?e.onDeleteDocument(e.node):e.onDeleteFolder(e.node),e.onClose()},children:e.node.type==="folder"?n("deleteFolder",{name:a||e.node.name}):n("deleteItem",{name:e.node.name})})]})}function wf({domains:e,value:n,onChange:o,ariaLabel:r,localizeName:a,onDomainsChange:i}){const{t:s}=Ve(),[l,u]=x.useState(!1),[d,h]=x.useState(e),[m,f]=x.useState(""),p=x.useRef(null),g=x.useRef(null),w=x.useRef(null);x.useEffect(()=>{h(e)},[e]);const b=d.find(I=>I.domainId===n),v=(b==null?void 0:b.permission)==="private",S=x.useMemo(()=>{const I=m.trim().toLowerCase();return I?d.filter(N=>a(N.domainName).toLowerCase().includes(I)||N.domainName.toLowerCase().includes(I)):d},[d,m,a]);function D(){u(!1),f("")}x.useEffect(()=>{if(!l)return;const I=N=>{var L,E;!((L=p.current)!=null&&L.contains(N.target))&&!((E=g.current)!=null&&E.contains(N.target))&&D()};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[l]),x.useEffect(()=>{if(!l)return;const I=N=>{var L;N.key==="Escape"&&(D(),(L=p.current)==null||L.focus())};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[l]),x.useEffect(()=>{var I;l&&((I=w.current)==null||I.focus())},[l]);function P(I){o(I),D()}function _(){if(l){D();return}u(!0),f(""),nr().then(I=>{h(I),i==null||i(I)})}function T(I){I.key==="Enter"&&S.length===1&&(I.preventDefault(),P(S[0].domainId))}return c.jsxs("div",{className:"mdocs-domain-select-wrapper",children:[c.jsxs("button",{ref:p,type:"button",className:"mdocs-domain-select-trigger","aria-label":r,"aria-expanded":l,"aria-haspopup":"listbox",onClick:_,children:[c.jsx("span",{className:"mdocs-domain-select-text",children:b?a(b.domainName):""}),v&&c.jsxs("svg",{className:"mdocs-domain-lock",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"2",children:[c.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),c.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),c.jsx("svg",{className:"mdocs-domain-select-chevron"+(l?" open":""),width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"1.5",children:c.jsx("path",{d:"M1 1l4 4 4-4"})})]}),l&&c.jsxs("div",{ref:g,className:"mdocs-domain-select-menu card",role:"listbox","aria-label":r,children:[c.jsx("div",{className:"mdocs-domain-select-search",children:c.jsx("input",{ref:w,type:"search",className:"mdocs-domain-select-search-input",value:m,placeholder:s("domainSearchPlaceholder"),"aria-label":s("domainSearchPlaceholder"),autoComplete:"off",onChange:I=>f(I.target.value),onKeyDown:T,onClick:I=>I.stopPropagation()})}),c.jsx("div",{className:"mdocs-domain-select-options",children:S.length===0?c.jsx("div",{className:"mdocs-domain-select-empty muted",children:s("domainNoMatch")}):S.map(I=>c.jsxs("button",{type:"button",className:"mdocs-domain-select-option"+(I.domainId===n?" active":""),role:"option","aria-selected":I.domainId===n,onClick:()=>P(I.domainId),children:[c.jsx("span",{children:a(I.domainName)}),I.permission==="private"&&c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--mdocs-text-muted)",strokeWidth:"2",children:[c.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),c.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})]},I.domainId))})]})]})}const Ta="data:image/svg+xml,%3csvg%20fill='%234D6BFE'%20fill-rule='evenodd'%20height='1em'%20style='flex:none;line-height:1'%20viewBox='0%200%2024%2024'%20width='1em'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eDeepSeek%3c/title%3e%3cpath%20d='M23.748%204.482c-.254-.124-.364.113-.512.234-.051.039-.094.09-.137.136-.372.397-.806.657-1.373.626-.829-.046-1.537.214-2.163.848-.133-.782-.575-1.248-1.247-1.548-.352-.156-.708-.311-.955-.65-.172-.241-.219-.51-.305-.774-.055-.16-.11-.323-.293-.35-.2-.031-.278.136-.356.276-.313.572-.434%201.202-.422%201.84.027%201.436.633%202.58%201.838%203.393.137.093.172.187.129.323-.082.28-.18.552-.266.833-.055.179-.137.217-.329.14a5.526%205.526%200%2001-1.736-1.18c-.857-.828-1.631-1.742-2.597-2.458a11.365%2011.365%200%2000-.689-.471c-.985-.957.13-1.743.388-1.836.27-.098.093-.432-.779-.428-.872.004-1.67.295-2.687.684a3.055%203.055%200%2001-.465.137%209.597%209.597%200%2000-2.883-.102c-1.885.21-3.39%201.102-4.497%202.623C.082%208.606-.231%2010.684.152%2012.85c.403%202.284%201.569%204.175%203.36%205.653%201.858%201.533%203.997%202.284%206.438%202.14%201.482-.085%203.133-.284%204.994-1.86.47.234.962.327%201.78.397.63.059%201.236-.03%201.705-.128.735-.156.684-.837.419-.961-2.155-1.004-1.682-.595-2.113-.926%201.096-1.296%202.746-2.642%203.392-7.003.05-.347.007-.565%200-.845-.004-.17.035-.237.23-.256a4.173%204.173%200%20001.545-.475c1.396-.763%201.96-2.015%202.093-3.517.02-.23-.004-.467-.247-.588zM11.581%2018c-2.089-1.642-3.102-2.183-3.52-2.16-.392.024-.321.471-.235.763.09.288.207.486.371.739.114.167.192.416-.113.603-.673.416-1.842-.14-1.897-.167-1.361-.802-2.5-1.86-3.301-3.307-.774-1.393-1.224-2.887-1.298-4.482-.02-.386.093-.522.477-.592a4.696%204.696%200%20011.529-.039c2.132.312%203.946%201.265%205.468%202.774.868.86%201.525%201.887%202.202%202.891.72%201.066%201.494%202.082%202.48%202.914.348.292.625.514.891.677-.802.09-2.14.11-3.054-.614zm1-6.44a.306.306%200%2001.415-.287.302.302%200%2001.2.288.306.306%200%2001-.31.307.303.303%200%2001-.304-.308zm3.11%201.596c-.2.081-.399.151-.59.16a1.245%201.245%200%2001-.798-.254c-.274-.23-.47-.358-.552-.758a1.73%201.73%200%2001.016-.588c.07-.327-.008-.537-.239-.727-.187-.156-.426-.199-.688-.199a.559.559%200%2001-.254-.078c-.11-.054-.2-.19-.114-.358.028-.054.16-.186.192-.21.356-.202.767-.136%201.146.016.352.144.618.408%201.001.782.391.451.462.576.685.914.176.265.336.537.445.848.067.195-.019.354-.25.452z'%3e%3c/path%3e%3c/svg%3e",st={left:12,bottom:64},mr="mdocs.agentFabPosition",Zn=36,Ti=3;function hr(e){const o=Math.max(8,window.innerWidth-Zn-8),r=Math.max(8,window.innerHeight-Zn-8);return{left:Math.min(o,Math.max(8,e.left)),bottom:Math.min(r,Math.max(8,e.bottom))}}function _f(e,n,o,r){const a=e-o,i=n-r,s=window.innerHeight-i-Zn;return hr({left:a,bottom:s})}function If(){try{const e=localStorage.getItem(mr);if(!e)return st;const n=JSON.parse(e);return typeof n.left!="number"||typeof n.bottom!="number"?st:hr({left:n.left,bottom:n.bottom})}catch{return st}}function Ai(e){localStorage.setItem(mr,JSON.stringify(e))}function kf(e){return e.left===st.left&&e.bottom===st.bottom}function Sf(e){const o=Math.min(480,window.innerWidth-72);let r=e.left+Zn+8;r+o>window.innerWidth-8&&(r=e.left-8-o),r=Math.max(8,r);const a=Math.max(8,e.bottom-8);return{left:r,bottom:a}}function Cf(e){const{t:n}=Ve(),o=!!e.disableDrag,[r,a]=x.useState(!1),[i,s]=x.useState(e.position),l=x.useRef(null),u=x.useRef(null),d=x.useRef(i),h=x.useRef(e.onPositionChange),m=x.useRef(e.onToggle);d.current=i,h.current=e.onPositionChange,m.current=e.onToggle;const f=x.useRef(null),p=x.useRef(0),g=x.useRef(null);x.useEffect(()=>{f.current||(s(e.position),d.current=e.position)},[e.position]),x.useEffect(()=>{function D(){const P=hr(d.current);P.left===d.current.left&&P.bottom===d.current.bottom||(d.current=P,s(P),h.current(P),Ai(P))}return window.addEventListener("resize",D),()=>window.removeEventListener("resize",D)},[]),x.useEffect(()=>{function D(){p.current=0;const T=g.current;if(!T)return;g.current=null,d.current=T,s(T);const I=u.current;I&&(I.style.left=`${T.left}px`,I.style.bottom=`${T.bottom}px`),h.current(T)}function P(T){const I=f.current;if(!I||T.pointerId!==I.pointerId)return;T.preventDefault();const N=T.clientX-I.startX,L=T.clientY-I.startY;!I.didMove&&N*N+L*L>=Ti*Ti&&(I.didMove=!0,a(!0)),I.didMove&&(g.current=_f(T.clientX,T.clientY,I.offsetX,I.offsetY),p.current||(p.current=requestAnimationFrame(D)))}function _(T){var N;const I=f.current;if(!(!I||T.pointerId!==I.pointerId)){f.current=null,a(!1),p.current&&(cancelAnimationFrame(p.current),p.current=0),g.current&&(d.current=g.current,s(g.current),g.current=null);try{(N=l.current)==null||N.releasePointerCapture(T.pointerId)}catch{}if(I.didMove){const L=d.current;h.current(L),Ai(L);return}m.current()}}return window.addEventListener("pointermove",P,{passive:!1}),window.addEventListener("pointerup",_),window.addEventListener("pointercancel",_),()=>{window.removeEventListener("pointermove",P),window.removeEventListener("pointerup",_),window.removeEventListener("pointercancel",_),p.current&&cancelAnimationFrame(p.current)}},[]);function w(D){if(D.button!==0)return;if(o){D.preventDefault(),e.onToggle();return}D.preventDefault();const P=D.currentTarget.getBoundingClientRect();f.current={pointerId:D.pointerId,offsetX:D.clientX-P.left,offsetY:D.clientY-P.top,startX:D.clientX,startY:D.clientY,didMove:!1},D.currentTarget.setPointerCapture(D.pointerId)}function b(){d.current=st,s(st),e.onPositionChange(st),localStorage.removeItem(mr)}const v=o?st:i,S=!o&&!kf(i);return c.jsxs("div",{ref:u,className:"mdocs-agent-fab-wrap"+(r?" dragging":""),style:{left:v.left,bottom:v.bottom},children:[c.jsx("button",{ref:l,type:"button",className:"mdocs-agent-fab"+(e.open?" open":"")+(r?" dragging":"")+(o?" mdocs-agent-fab--nodrag":""),"aria-label":n("agentFabOpen"),"aria-expanded":e.open,onPointerDown:w,children:c.jsx("img",{src:Ta,alt:"",draggable:!1})}),S&&c.jsx("button",{type:"button",className:"mdocs-agent-fab-reset",onClick:b,"aria-label":n("agentFabReset"),children:n("agentFabReset")})]})}function Df(){const[e,n]=x.useState(()=>typeof window>"u"?st:If());return[e,n]}function Nf({title:e,message:n,onClose:o}){const{t:r}=Ve();return c.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:a=>{a.target===a.currentTarget&&o()},children:c.jsxs("div",{className:"mdocs-dialog card mdocs-message-dialog",role:"alertdialog","aria-modal":"true",children:[e&&c.jsx("h2",{className:"mdocs-message-dialog-title",children:e}),c.jsx("p",{className:"mdocs-message-dialog-body",children:n}),c.jsx("div",{className:"mdocs-message-dialog-actions",children:c.jsx("button",{type:"button",className:"primary",onClick:o,children:r("gotIt")})})]})})}function Aa({title:e,message:n,confirmLabel:o="确定",cancelLabel:r="取消",onConfirm:a,onCancel:i,busy:s=!1,danger:l=!1}){return c.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:u=>{u.target===u.currentTarget&&!s&&i()},children:c.jsxs("div",{className:"mdocs-dialog card mdocs-message-dialog",role:"alertdialog","aria-modal":"true",children:[e&&c.jsx("h2",{className:"mdocs-message-dialog-title",children:e}),c.jsx("p",{className:"mdocs-message-dialog-body",children:n}),c.jsxs("div",{className:"mdocs-message-dialog-actions",style:{gap:8},children:[c.jsx("button",{type:"button",onClick:i,disabled:s,children:r}),c.jsx("button",{type:"button",className:l?"danger":"primary",onClick:a,disabled:s,children:s?"…":o})]})]})})}const Mi={"relative path is required":"pathRequired","path must be relative":"pathMustBeRelative","use forward slashes":"useForwardSlashes","path must not contain ..":"pathNoDotDot","document path must end with .md":"pathMustEndWithMd","path contains unsupported characters":"pathUnsupportedChars","path escapes docs root":"pathEscapesRoot"},Ma={"enter a folder name":"enterFolderName","use a single name, not a path":"singleNameNotPath","invalid folder name":"invalidFolderName","folder name is too long":"folderNameTooLong","enter a file name":"enterFileName","use a file name, not a path":"singleFileNameNotPath","invalid file name":"invalidFileName","file name is too long":"fileNameTooLong"};function Je(e,n){if(n instanceof et)return n.message;if(n instanceof St){const o=Mi[n.message];return o?e(o):n.message}if(n instanceof Error){const o=Mi[n.message]??Ma[n.message];return o?e(o):n.message}return String(n)}function kn(e,n,o){if(e==="Default")return o("defaultDomain");const r="个人域";return e.endsWith(r)?e.slice(0,-r.length)+o("personalDomainSuffix"):e}function Ah(e,n){return e==="public"?n("domainPublic"):e==="restricted"?n("domainRestricted"):e==="private"?n("domainPrivate"):e}function $n(e){const n=e.lastIndexOf("/");return n===-1?"":e.slice(0,n)}const Pf=280,en="";function Tf(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Do(e,n){const o=Array.from(new Set(n.filter(u=>u.length>0))).sort((u,d)=>d.length-u.length);if(o.length===0)return e;const r=new RegExp(o.map(Tf).join("|"),"gi"),a=[];let i=0,s,l=0;for(;(s=r.exec(e))!==null;)s.index>i&&a.push(e.slice(i,s.index)),a.push(c.jsx("mark",{children:s[0]},l++)),i=s.index+s[0].length,s[0].length===0&&r.lastIndex++;return i<e.length&&a.push(e.slice(i)),a}function Af(e,n){const o=new Date(e);return Number.isNaN(o.getTime())?"":o.toLocaleString(n==="zh"?"zh-CN":"en-US",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Mf(e){const{t:n,lang:o}=Ve(),r=x.useRef(null),a=x.useRef(null),[i,s]=x.useState(""),[l,u]=x.useState(en),[d,h]=x.useState("auto"),[m,f]=x.useState(!0),[p,g]=x.useState(!1),[w,b]=x.useState(""),[v,S]=x.useState(e.domains),[D,P]=x.useState([]),[_,T]=x.useState([]),[I,N]=x.useState(!1),[L,E]=x.useState(null),O=x.useRef(0);x.useEffect(()=>{S(e.domains)},[e.domains]);const $=x.useMemo(()=>{const B=new Map;for(const G of v)B.set(G.domainId,kn(G.domainName,o,n));return B},[v,o,n]),V=x.useMemo(()=>{const B=w.trim().toLowerCase();return B?v.filter(G=>kn(G.domainName,o,n).toLowerCase().includes(B)||G.domainName.toLowerCase().includes(B)||G.domainId.toLowerCase().includes(B)):v},[v,w,o,n]),J=l===en?n("docSearchAllDomains"):$.get(l)??n("docSearchAllDomains");function ne(){nr().then(B=>{var G;S(B),(G=e.onDomainsChange)==null||G.call(e,B)})}return x.useEffect(()=>{if(!e.open)return;s(""),u(en),g(!1),b(""),P([]),E(null),N(!1),ne();const B=window.setTimeout(()=>{var G;return(G=r.current)==null?void 0:G.focus()},0);return()=>window.clearTimeout(B)},[e.open]),x.useEffect(()=>{if(!e.open)return;const B=G=>{if(G.key==="Escape"){if(G.preventDefault(),p){g(!1);return}e.onClose()}};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[e.open,e.onClose,p]),x.useEffect(()=>{if(!p)return;const B=G=>{var ce;(ce=a.current)!=null&&ce.contains(G.target)||g(!1)};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[p]),x.useEffect(()=>{if(!e.open)return;const B=i.trim();if(!B){P([]),N(!1),E(null);return}N(!0),E(null);const G=++O.current,ce=window.setTimeout(()=>{Ol({query:B,mode:d,domainId:l||void 0,topN:20}).then(ue=>{G===O.current&&(P(ue.results),f(ue.modelReady),T(ue.tokens??[]),N(!1))}).catch(ue=>{G===O.current&&(P([]),f(!0),T([]),N(!1),E(Je(n,ue)||n("docSearchFailed")))})},Pf);return()=>window.clearTimeout(ce)},[i,e.open,l,d,n]),e.open?c.jsx("div",{className:"mdocs-doc-search-backdrop",role:"presentation",onMouseDown:B=>{B.target===B.currentTarget&&e.onClose()},children:c.jsxs("div",{className:"mdocs-doc-search-panel",role:"dialog","aria-modal":"true","aria-label":n("docSearchTitle"),children:[c.jsxs("div",{className:"mdocs-doc-search-bar",children:[c.jsx(Ui,{size:18,strokeWidth:1.75,"aria-hidden":!0}),c.jsx("input",{ref:r,className:"mdocs-doc-search-input",type:"search",value:i,placeholder:n("docSearchPlaceholder"),"aria-label":n("docSearchPlaceholder"),onChange:B=>s(B.target.value)}),c.jsxs("select",{className:"mdocs-doc-search-mode",value:d,"aria-label":n("myDocumentsSearchMode"),onChange:B=>h(B.target.value),children:[c.jsx("option",{value:"auto",children:n("myDocumentsModeAuto")}),c.jsx("option",{value:"keyword",children:n("myDocumentsModeKeyword")}),c.jsx("option",{value:"semantic",children:n("myDocumentsModeSemantic")})]}),c.jsxs("div",{className:"mdocs-doc-search-domain",ref:a,children:[c.jsxs("button",{type:"button",className:"mdocs-doc-search-domain-trigger","aria-label":n("docSearchDomainAria"),"aria-expanded":p,"aria-haspopup":"listbox",onClick:()=>{if(p){g(!1);return}g(!0),b(""),ne()},children:[c.jsx("span",{className:"mdocs-doc-search-domain-label",children:J}),c.jsx(Fo,{size:14,strokeWidth:1.75})]}),p&&c.jsxs("div",{className:"mdocs-doc-search-domain-menu",role:"listbox","aria-label":n("docSearchDomainAria"),children:[c.jsx("input",{className:"mdocs-doc-search-domain-filter",type:"search",value:w,placeholder:n("docSearchDomainFilter"),"aria-label":n("docSearchDomainFilter"),autoFocus:!0,onChange:B=>b(B.target.value),onClick:B=>B.stopPropagation()}),c.jsx("button",{type:"button",className:"mdocs-doc-search-domain-option"+(l===en?" active":""),role:"option","aria-selected":l===en,onClick:()=>{u(en),g(!1)},children:c.jsx("span",{className:"mdocs-doc-search-domain-option-name",children:n("docSearchAllDomains")})}),V.map(B=>{const G=kn(B.domainName,o,n),ce=B.permission==="private";return c.jsxs("button",{type:"button",className:"mdocs-doc-search-domain-option"+(B.domainId===l?" active":""),role:"option","aria-selected":B.domainId===l,onClick:()=>{u(B.domainId),g(!1)},children:[c.jsx("span",{className:"mdocs-doc-search-domain-option-name",children:G}),ce?c.jsx("span",{className:"mdocs-doc-search-domain-option-tag","aria-hidden":!0,children:c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[c.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),c.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}):null]},B.domainId)}),V.length===0&&c.jsx("p",{className:"mdocs-doc-search-domain-empty",children:n("docSearchDomainNoMatch")})]})]}),c.jsx("button",{type:"button",className:"mdocs-doc-search-close","aria-label":n("close"),onClick:e.onClose,children:c.jsx(zt,{size:16,strokeWidth:1.75})})]}),c.jsxs("div",{className:"mdocs-doc-search-results",children:[!i.trim()&&c.jsx("p",{className:"mdocs-doc-search-hint",children:n("docSearchEmptyHint")}),I&&c.jsx("p",{className:"mdocs-doc-search-hint",children:n("loading")}),L&&c.jsx("p",{className:"mdocs-doc-search-error",children:L}),!I&&!L&&i.trim()&&D.length===0&&c.jsx("p",{className:"mdocs-doc-search-hint",children:n(d==="semantic"&&!m?"myDocumentsSemanticNotReady":"docSearchNoResults")}),D.map(B=>{var ie;const G=Af(B.updatedAt,o),ue=[$.get(B.domainId),(ie=B.ownerVisitorName)==null?void 0:ie.trim(),G].filter(Boolean),A=[];return B.titleHit&&A.push(n("docSearchHitTitle")),B.bodyHit&&A.push(n("docSearchHitBody")),B.semanticHit&&A.push(n("docSearchHitSemantic")),c.jsxs("button",{type:"button",className:"mdocs-doc-search-row",onClick:()=>{e.onOpenDocument(B.documentId),e.onClose()},children:[c.jsxs("span",{className:"mdocs-doc-search-row-head",children:[c.jsx("span",{className:"mdocs-doc-search-row-title",children:Do(B.displayName,_)}),A.length>0&&c.jsx("span",{className:"mdocs-doc-search-row-sources",children:A.map(oe=>c.jsx("span",{className:"mdocs-doc-search-row-source",children:oe},oe))})]}),ue.length>0&&c.jsx("span",{className:"mdocs-doc-search-row-meta",children:ue.join(" · ")}),B.relativePath&&c.jsx("span",{className:"mdocs-doc-search-row-path",children:Do(B.relativePath,_)}),B.snippet&&c.jsx("span",{className:"mdocs-doc-search-row-snippet",children:Do(B.snippet,_)})]},B.documentId)})]})]})}):null}const Qn=2,ja=12,Ea=24,jf=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;function Nt(e){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`${e}_${crypto.randomUUID().slice(0,8)}`:`${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function Nn(e=""){return{v:e}}function Mh(e){return e==null?"":typeof e=="string"?e:e.v??""}function jh(e){if(!(e==null||typeof e=="string"))return e.style}function Ef(e){if(typeof e=="string")return{v:e};if(e==null)return{v:""};if(typeof e=="object"&&!Array.isArray(e)){const n=e,o=typeof n.v=="string"?n.v:n.v==null?"":String(n.v),r=Ra(n.style);return r?{v:o,style:r}:{v:o}}return{v:String(e)}}function eo(e){return jf.test(e.trim())}function Ra(e){if(e==null||typeof e!="object"||Array.isArray(e))return;const n=e,o={};if(typeof n.bg=="string"&&n.bg.trim()){const r=n.bg.trim();eo(r)&&(o.bg=r)}if(typeof n.color=="string"&&n.color.trim()){const r=n.color.trim();eo(r)&&(o.color=r)}if(n.bold===!0&&(o.bold=!0),n.italic===!0&&(o.italic=!0),typeof n.fontSize=="number"&&Number.isFinite(n.fontSize)){const r=Math.round(n.fontSize);r>=ja&&r<=Ea&&(o.fontSize=r)}return Object.keys(o).length>0?o:void 0}function Rf(e,n){if(n===null)return;if(n==null)return e;const o={...e??{}};if("bg"in n&&(n.bg==null||n.bg===""?delete o.bg:eo(n.bg)&&(o.bg=n.bg.trim())),"color"in n&&(n.color==null||n.color===""?delete o.color:eo(n.color)&&(o.color=n.color.trim())),"bold"in n&&(n.bold?o.bold=!0:delete o.bold),"italic"in n&&(n.italic?o.italic=!0:delete o.italic),"fontSize"in n)if(n.fontSize==null)delete o.fontSize;else{const r=Math.round(Number(n.fontSize));r>=ja&&r<=Ea&&(o.fontSize=r)}return Object.keys(o).length>0?o:void 0}function Of(e){const n=Ra(e.style);return n?{v:e.v,style:n}:e.v}function Ff(e){const n=(e.merges??[]).filter(Boolean);return{id:e.id,name:e.name,columns:e.columns,rows:e.rows.map(o=>({id:o.id,cells:Object.fromEntries(Object.entries(o.cells).map(([r,a])=>[r,Of(a)]))})),...n.length>0?{merges:n}:{}}}function Oa(e){var i;const n=Math.max(1,(e==null?void 0:e.columnCount)??3),o=Math.max(0,(e==null?void 0:e.rowCount)??5),r=[];for(let s=0;s<n;s+=1)r.push({id:Nt("c"),name:`列${s+1}`});const a=[];for(let s=0;s<o;s+=1){const l={};for(const u of r)l[u.id]=Nn();a.push({id:Nt("r"),cells:l})}return{id:Nt("s"),name:((i=e==null?void 0:e.name)==null?void 0:i.trim())||"Sheet1",columns:r,rows:a,merges:[]}}function tn(e){const n=Oa(e);return{version:Qn,sheets:[n],activeSheetId:n.id}}function Lf(e){const n={version:Qn,activeSheetId:e.activeSheetId,sheets:e.sheets.map(Ff)};return`${JSON.stringify(n,null,2)}
|
|
299
|
-
`}function zf(e,n){if(!Array.isArray(e))return[];const o=new Set(n.rows.map(i=>i.id)),r=new Set(n.columns.map(i=>i.id)),a=[];for(const i of e){if(!i||typeof i!="object")continue;const s=i,l=typeof s.startRowId=="string"?s.startRowId:"",u=typeof s.startColId=="string"?s.startColId:"",d=typeof s.endRowId=="string"?s.endRowId:"",h=typeof s.endColId=="string"?s.endColId:"";!o.has(l)||!o.has(d)||!r.has(u)||!r.has(h)||a.push({startRowId:l,startColId:u,endRowId:d,endColId:h})}return a}function ji(e,n){if(!e||typeof e!="object")return null;const o=e,r=Array.isArray(o.columns)?o.columns:[],a=Array.isArray(o.rows)?o.rows:[],i=[];for(const h of r){if(!h||typeof h!="object")continue;const m=h,f=typeof m.id=="string"&&m.id?m.id:Nt("c"),p=typeof m.name=="string"?m.name:f;i.push({id:f,name:p})}if(i.length===0)return null;const s=[];for(const h of a){if(!h||typeof h!="object")continue;const m=h,f=typeof m.id=="string"&&m.id?m.id:Nt("r"),p=m.cells&&typeof m.cells=="object"&&!Array.isArray(m.cells)?m.cells:{},g={};for(const w of i)g[w.id]=Ef(p[w.id]);s.push({id:f,cells:g})}const l=typeof o.id=="string"&&o.id?o.id:Nt("s"),u=typeof o.name=="string"&&o.name.trim()?o.name.trim():n,d=zf(o.merges,{columns:i,rows:s});return{id:l,name:u,columns:i,rows:s,merges:d}}function Eh(e){const n=e.trim();if(!n)return tn();let o;try{o=JSON.parse(n)}catch{return tn()}if(!o||typeof o!="object")return tn();const r=o;if(Array.isArray(r.sheets)&&r.sheets.length>0){const i=[];for(let u=0;u<r.sheets.length;u+=1){const d=ji(r.sheets[u],`Sheet${u+1}`);d&&i.push(d)}if(i.length===0)return tn();const s=typeof r.activeSheetId=="string"?r.activeSheetId:"",l=i.some(u=>u.id===s)?s:i[0].id;return{version:Qn,sheets:i,activeSheetId:l}}const a=ji(r,"Sheet1");return a?{version:Qn,sheets:[a],activeSheetId:a.id}:tn()}function pr(e,n){const o=n==null?void 0:n.trim();if(!o)return e.sheets.find(s=>s.id===e.activeSheetId)??e.sheets[0]??null;const r=e.sheets.find(s=>s.id===o);if(r)return r;const a=e.sheets.find(s=>s.name===o);if(a)return a;const i=o.toLowerCase();return e.sheets.find(s=>s.name.toLowerCase()===i)??null}function $f(e,n){if(!e.sheets.some(o=>o.id===n.id))throw new Error(`unknown sheet: ${n.id}`);return{...e,sheets:e.sheets.map(o=>o.id===n.id?n:o)}}function Rh(e,n){const o=pr(e,n);if(!o)throw new Error(`unknown sheet: ${n}`);return{...e,activeSheetId:o.id}}function Oh(e,n){let o=`Sheet${e.sheets.length+1}`;const r=new Set(e.sheets.map(i=>i.name));if(r.has(o)){let i=2;for(;r.has(`${o}${i}`);)i+=1;o=`${o}${i}`}const a=Oa({name:o});return{doc:{...e,sheets:[...e.sheets,a],activeSheetId:a.id},tab:a}}function Fh(e,n,o){const r=pr(e,n);if(!r)throw new Error(`unknown sheet: ${n}`);const a=o.trim();if(!a)throw new Error("sheet name is required");if(e.sheets.find(s=>s.id!==r.id&&s.name===a))throw new Error(`sheet name already exists: ${a}`);return $f(e,{...r,name:a})}function Lh(e,n){const o=pr(e,n);if(!o)throw new Error(`unknown sheet: ${n}`);if(e.sheets.length<=1)throw new Error("cannot delete the last sheet");const r=e.sheets.filter(i=>i.id!==o.id),a=e.activeSheetId===o.id?r[0].id:e.activeSheetId;return{...e,sheets:r,activeSheetId:a}}function Ze(e,n){return e.rows.findIndex(o=>o.id===n)}function Qe(e,n){return e.columns.findIndex(o=>o.id===n)}function Fa(e,n){const o=Ze(e,n.startRowId),r=Ze(e,n.endRowId),a=Qe(e,n.startColId),i=Qe(e,n.endColId);if(o<0||r<0||a<0||i<0)return null;const s=Math.min(o,r),l=Math.max(o,r),u=Math.min(a,i),d=Math.max(a,i);return s===l&&u===d?null:{startRowId:e.rows[s].id,startColId:e.columns[u].id,endRowId:e.rows[l].id,endColId:e.columns[d].id}}function Uf(e,n,o){const r=Ze(e,n.startRowId),a=Ze(e,n.endRowId),i=Qe(e,n.startColId),s=Qe(e,n.endColId),l=Ze(e,o.startRowId),u=Ze(e,o.endRowId),d=Qe(e,o.startColId),h=Qe(e,o.endColId);if(r<0||a<0||l<0||u<0||i<0||s<0||d<0||h<0)return!1;const m=Math.min(r,a),f=Math.max(r,a),p=Math.min(i,s),g=Math.max(i,s),w=Math.min(l,u),b=Math.max(l,u),v=Math.min(d,h),S=Math.max(d,h);return!(f<w||b<m||g<v||S<p)}function io(e,n,o){const r=Ze(e,n),a=Qe(e,o);if(r<0||a<0)return null;for(const i of e.merges??[]){const s=Ze(e,i.startRowId),l=Ze(e,i.endRowId),u=Qe(e,i.startColId),d=Qe(e,i.endColId);if(s<0||l<0||u<0||d<0)continue;const h=Math.min(s,l),m=Math.max(s,l),f=Math.min(u,d),p=Math.max(u,d);if(r>=h&&r<=m&&a>=f&&a<=p)return i}return null}function zh(e,n,o){const r=io(e,n,o);return r?r.startRowId===n&&r.startColId===o:!0}function $h(e,n,o){const r=io(e,n,o);return r?!(r.startRowId===n&&r.startColId===o):!1}function Uh(e,n){const o=Ze(e,n.startRowId),r=Ze(e,n.endRowId),a=Qe(e,n.startColId),i=Qe(e,n.endColId);return{rowSpan:Math.abs(r-o)+1,colSpan:Math.abs(i-a)+1}}function La(e){const n=new Set(e.rows.map(a=>a.id)),o=new Set(e.columns.map(a=>a.id)),r=(e.merges??[]).filter(a=>n.has(a.startRowId)&&n.has(a.endRowId)&&o.has(a.startColId)&&o.has(a.endColId)&&Fa(e,a)!=null);return{...e,merges:r}}function Bh(e,n){const o=Fa(e,n);if(!o)throw new Error("invalid merge range (need at least 2 cells)");for(const r of e.merges??[])if(Uf(e,r,o))throw new Error("merge overlaps existing merge");return{...e,merges:[...e.merges??[],o]}}function Hh(e,n,o){const r=io(e,n,o);return r?{tab:{...e,merges:(e.merges??[]).filter(a=>a!==r)},removed:r}:{tab:e,removed:null}}function za(e,n,o){const r=io(e,n,o);return!r||r.startRowId===n&&r.startColId===o?{rowId:n,columnId:o,redirected:!1}:{rowId:r.startRowId,columnId:r.startColId,redirected:!0}}function Vh(e,n){const o={id:Nt("c"),name:`列${e.columns.length+1}`};return{...e,columns:[...e.columns,o],rows:e.rows.map(r=>({...r,cells:{...r.cells,[o.id]:Nn()}}))}}function Gh(e){const n={};for(const o of e.columns)n[o.id]=Nn();return{...e,rows:[...e.rows,{id:Nt("r"),cells:n}]}}function Wh(e,n,o,r){const a=za(e,n,o);return{...e,rows:e.rows.map(i=>{if(i.id!==a.rowId)return i;const s=i.cells[a.columnId]??Nn();return{...i,cells:{...i.cells,[a.columnId]:{v:r,...s.style?{style:s.style}:{}}}}})}}function qh(e,n,o,r){const a=za(e,n,o);return{...e,rows:e.rows.map(i=>{if(i.id!==a.rowId)return i;const s=i.cells[a.columnId]??Nn(),l=Rf(s.style,r),u=l?{v:s.v,style:l}:{v:s.v};return{...i,cells:{...i.cells,[a.columnId]:u}}})}}function Kh(e,n,o){return{...e,columns:e.columns.map(r=>r.id===n?{...r,name:o}:r)}}function Yh(e,n){return La({...e,rows:e.rows.filter(o=>o.id!==n)})}function Jh(e,n){const o=[],r=new Set,a=[];for(const l of n){const u=Bf(e,l);if(!u){o.push(`unknown column: ${l}`);continue}r.has(u.id)||(r.add(u.id),a.push({id:u.id,name:u.name}))}if(r.size===0)return{tab:e,removed:[],errors:o};if(e.columns.length-r.size<1)throw new Error("cannot delete all columns; at least one column required");const i=e.columns.filter(l=>!r.has(l.id)),s=e.rows.map(l=>{const u={...l.cells};for(const d of r)delete u[d];return{...l,cells:u}});return{tab:La({...e,columns:i,rows:s}),removed:a,errors:o}}function Bf(e,n){const o=n.trim();if(!o)return null;const r=e.columns.find(s=>s.id===o);if(r)return r;const a=e.columns.find(s=>s.name===o);if(a)return a;const i=o.toLowerCase();return e.columns.find(s=>s.name.toLowerCase()===i)??null}function Hf(e){return JSON.stringify({root:{children:[{children:[{detail:0,format:0,mode:"normal",text:e,type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",tag:"h1",version:1}],direction:"ltr",type:"root",version:1}})}function No(e,n){const o=e.trim(),r=n.trim();return r?o?`${o}/${r}`:r:o}function $a(e,n=new Set){for(const o of e)o.type==="document"?n.add(o.path):(o.descDocumentId&&n.add(vl(o.path)),$a(o.children,n));return n}function Hn(e,n){for(const o of e){if(o.type==="folder"&&o.path===n)return o.documentId;if(o.type==="folder"){const r=Hn(o.children,n);if(r)return r}}return null}function Po(e,n){const o=Ma[n];return o?e(o):n}function Vf(e){const{tree:n,currentDomainId:o,selectedCreateParentPath:r,t:a,onDocCreated:i,refreshTree:s}=e,[l,u]=x.useState(null),[d,h]=x.useState(null),[m,f]=x.useState(!1),p=x.useRef(null);x.useEffect(()=>{if(!l)return;const v=window.setTimeout(()=>{var S;return(S=p.current)==null?void 0:S.focus()},0);return()=>window.clearTimeout(v)},[l]);function g(v,S="md"){const D=v!==void 0;h(null),u({kind:"document",parentMode:D?"fixed":"selection",parentPath:D?v:"",draft:S==="html"?"untitled.html":S==="sheet"?"untitled.sheet":"untitled.md",fileType:S})}function w(v){const S=v!==void 0;h(null),u({kind:"folder",parentMode:S?"fixed":"selection",parentPath:S?v:"",draft:""})}async function b(v){if(v.preventDefault(),!l)return;f(!0),h(null);const S=$a(n),D=l.parentMode==="selection"?r:l.parentPath;try{if(l.kind==="document"){const N=l.fileType;if(N==="html"||N==="sheet"){const ne=N==="html"?".html":".sheet",B=$r(l.draft,ne);if(!B.ok){h(Po(a,B.message));return}const G=B.displayFile,ce=G.replace(/\.html$/i,"").replace(/\.sheet$/i,"").replace(/\.md$/i,"");let ue;try{ue=Ur(No(D,G))}catch(re){h(Je(a,re));return}if(S.has(ue)){h(a("pathExists"));return}const A=D?Hn(n,D)??void 0:void 0,ie=N==="sheet"?Lf(tn()):"",oe=await $o({fileName:G,displayName:ce,content:ie,domainId:o,parentId:A,fileType:N});await s(),i(oe),u(null);return}const L=$r(l.draft);if(!L.ok){h(Po(a,L.message));return}const E=L.displayFile,O=E.replace(/\.md$/i,"");let $;try{$=Ur(No(D,E))}catch(ne){h(Je(a,ne));return}if(S.has($)){h(a("pathExists"));return}const V=D?Hn(n,D)??void 0:void 0,J=await $o({fileName:E,displayName:O,content:Hf(O),domainId:o,parentId:V});await s(),i(J),u(null);return}const P=wl(l.draft);if(!P.ok){h(Po(a,P.message));return}const _=Lo(P.display);if(!_){h(a("invalidFolderName"));return}const T=No(D,_);if(S.has(T)){h(a("folderExists"));return}const I=D?Hn(n,D)??void 0:void 0;await El({name:_,parentId:I,domainId:o}),await s(),u(null)}catch(P){h(Je(a,P))}finally{f(!1)}}return{createModal:l,setCreateModal:u,createModalError:d,createModalBusy:m,createModalInputRef:p,openNewDocumentModal:g,openNewFolderModal:w,submitCreateModal:b}}const Ei="(max-width: 768px)";function Gf(){const[e,n]=x.useState(()=>typeof window<"u"?window.matchMedia(Ei).matches:!1);return x.useEffect(()=>{const o=window.matchMedia(Ei),r=()=>n(o.matches);return r(),o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const Wf=28,Ri=56,qf=.75;function Kf(e,n,o){const r=!!(o!=null&&o.open),a=x.useRef(n),i=x.useRef(o==null?void 0:o.onClose);a.current=n,i.current=o==null?void 0:o.onClose,x.useEffect(()=>{if(!e)return;let s=null,l=0,u=0;const d=f=>{const p=f.touches[0];if(!p)return;const g=f.target;if(!(g instanceof Element&&g.closest(".mdocs-agent-fab-wrap"))){if(r){if(!i.current)return;s="close"}else{if(p.clientX>Wf)return;s="open"}l=p.clientX,u=p.clientY}},h=f=>{var b;if(!s)return;const p=f.touches[0];if(!p)return;const g=p.clientX-l,w=Math.abs(p.clientY-u);if(w>Math.abs(g)*qf&&w>24){s=null;return}if(s==="open"&&g>=Ri){s=null,a.current();return}s==="close"&&g<=-Ri&&(s=null,(b=i.current)==null||b.call(i))},m=()=>{s=null};return window.addEventListener("touchstart",d,{passive:!0}),window.addEventListener("touchmove",h,{passive:!0}),window.addEventListener("touchend",m,{passive:!0}),window.addEventListener("touchcancel",m,{passive:!0}),()=>{window.removeEventListener("touchstart",d),window.removeEventListener("touchmove",h),window.removeEventListener("touchend",m),window.removeEventListener("touchcancel",m)}},[e,r])}function Yf({open:e,onClose:n,onResolve:o,onForceOverwrite:r,forceBusy:a}){const{t:i}=Ve();return e?c.jsx("div",{className:"mdocs-conflict-modal-root",role:"alertdialog","aria-modal":"true",children:c.jsxs("div",{className:"mdocs-conflict-modal-panel",children:[c.jsx("h2",{className:"mdocs-conflict-modal-title",children:i("conflictTitle")}),c.jsx("p",{className:"mdocs-conflict-modal-body",children:i("conflictBody")}),r?c.jsx("p",{className:"mdocs-conflict-modal-force-hint",children:i("conflictForceHint")}):null,c.jsxs("div",{className:"mdocs-conflict-modal-actions",children:[c.jsx("button",{type:"button",className:"primary",onClick:o,disabled:a,children:i("conflictResolve")}),r?c.jsx("button",{type:"button",className:"mdocs-conflict-force-btn",disabled:a,onClick:r,children:i(a?"conflictForceBusy":"conflictForce")}):null,c.jsx("button",{type:"button",className:"secondary",onClick:n,disabled:a,children:i("conflictClose")})]})]})}):null}function Oi({documentId:e,visitorId:n,visitorName:o,documentOwnerId:r,onClose:a}){const[i,s]=x.useState([]),[l,u]=x.useState(""),[d,h]=x.useState(null),[m,f]=x.useState(!0),[p,g]=x.useState(!1),[w,b]=x.useState(null),[v,S]=x.useState(null),[D,P]=x.useState(360),[_,T]=x.useState(80),I=x.useRef(!1),N=x.useRef(!1),L=300,E=80,O=x.useRef(null);function $(){const K=O.current;if(!K)return;K.style.height="auto";const Z=K.scrollHeight,we=Math.min(Math.max(Z,E),L);K.style.height=`${we}px`,T(we)}x.useEffect(()=>{setTimeout(()=>$(),0)},[d]);function V(K){return n?K.visitorId===n||r===n:!1}const{rootComments:J,repliesByParentId:ne,totalCount:B}=x.useMemo(()=>{const K=[],Z=new Map;let we=0;for(const se of i)se.isDeleted||(we++,se.parentId?(Z.has(se.parentId)||Z.set(se.parentId,[]),Z.get(se.parentId).push(se)):K.push(se));return{rootComments:K,repliesByParentId:Z,totalCount:we}},[i]),G=x.useRef(e);x.useEffect(()=>{G.current=e,u(""),h(null),S(null),ce()},[e]);async function ce(){const K=G.current;f(!0);try{const Z=await zl(e);if(G.current!==K)return;s(Z.comments)}catch(Z){if(G.current!==K)return;S("加载评论失败"),console.error("Failed to load comments:",Z)}finally{G.current===K&&f(!1)}}async function ue(){var K;if(!(!l.trim()||!n)){g(!0),S(null);try{await $l(e,{content:l,parentId:(d==null?void 0:d.commentId)||null,replyToVisitorId:d?((K=i.find(Z=>Z.commentId===d.commentId))==null?void 0:K.visitorId)??null:null,replyToVisitorName:(d==null?void 0:d.visitorName)||null}),u(""),h(null),setTimeout(()=>$(),0),await ce()}catch(Z){S(Z.message||"发表失败,请重试")}finally{g(!1)}}}async function A(K){S(null);try{await Ul(e,K),await ce()}catch(Z){S(Z.message||"删除失败,请重试")}finally{b(null)}}function ie(K){const Z=Date.now()-new Date(K).getTime(),we=Math.floor(Z/6e4),se=Math.floor(Z/36e5),tt=Math.floor(Z/864e5);return we<1?"刚刚":we<60?`${we}分钟前`:se<24?`${se}小时前`:`${tt}天前`}function oe(K){I.current=!0,K.preventDefault()}function re(K){N.current=!0,K.preventDefault(),document.body.style.userSelect="none",document.body.style.cursor="row-resize"}return x.useEffect(()=>{function K(we){if(I.current){const se=Math.max(280,Math.min(600,window.innerWidth-we.clientX));P(se)}if(N.current){const se=-we.movementY;T(tt=>Math.max(60,Math.min(600,tt+se)))}}function Z(){I.current=!1,N.current=!1,document.body.style.userSelect="",document.body.style.cursor=""}return window.addEventListener("mousemove",K),window.addEventListener("mouseup",Z),()=>{window.removeEventListener("mousemove",K),window.removeEventListener("mouseup",Z)}},[]),c.jsxs("div",{className:"mdocs-comments-panel",style:{width:D},children:[c.jsx("div",{className:"mdocs-comments-resize-handle",onMouseDown:oe}),c.jsxs("div",{className:"mdocs-comments-header",children:[c.jsxs("h3",{style:{margin:0,fontSize:"1rem",display:"flex",alignItems:"center",gap:6},children:[c.jsx(Qs,{size:18}),"评论 (",B,")"]}),c.jsx("button",{type:"button",onClick:a,className:"mdocs-comments-close-btn",children:c.jsx(zt,{size:18})})]}),v&&c.jsxs("div",{className:"mdocs-comments-error",children:[v,c.jsx("button",{type:"button",onClick:()=>S(null),children:c.jsx(zt,{size:14})})]}),c.jsx("div",{className:"mdocs-comments-list",children:m?c.jsx("div",{className:"mdocs-comments-empty",children:"加载中..."}):J.length===0?c.jsx("div",{className:"mdocs-comments-empty",children:"暂无评论,来发表第一条吧~"}):J.map(K=>c.jsxs("div",{className:"mdocs-comment-root",children:[c.jsxs("div",{className:"mdocs-comment-header",children:[c.jsx("span",{className:"mdocs-comment-avatar",children:K.visitorName.charAt(0).toUpperCase()}),c.jsx("span",{className:"mdocs-comment-author",children:K.visitorName}),c.jsx("span",{className:"mdocs-comment-time",children:ie(K.createdAt)}),V(K)&&c.jsx("button",{type:"button",className:"mdocs-comment-delete",onClick:()=>b(K.commentId),title:"删除",children:c.jsx(zt,{size:14})})]}),c.jsx("div",{className:"mdocs-comment-content",children:K.content}),n&&c.jsx("button",{type:"button",className:"mdocs-comment-reply-btn",onClick:()=>h({commentId:K.commentId,visitorName:K.visitorName}),children:"回复"}),(ne.get(K.commentId)??[]).length>0&&c.jsx("div",{className:"mdocs-comment-replies",children:(ne.get(K.commentId)??[]).map(Z=>c.jsxs("div",{className:"mdocs-comment-reply",children:[c.jsxs("div",{className:"mdocs-comment-header",children:[c.jsx("span",{className:"mdocs-comment-avatar mdocs-comment-avatar-small",children:Z.visitorName.charAt(0).toUpperCase()}),c.jsx("span",{className:"mdocs-comment-author",children:Z.visitorName}),Z.replyToVisitorName&&c.jsxs("span",{className:"mdocs-comment-reply-to",children:["回复 ",Z.replyToVisitorName]}),c.jsx("span",{className:"mdocs-comment-time",children:ie(Z.createdAt)}),V(Z)&&c.jsx("button",{type:"button",className:"mdocs-comment-delete",onClick:()=>b(Z.commentId),title:"删除",children:c.jsx(zt,{size:12})})]}),c.jsx("div",{className:"mdocs-comment-content",children:Z.content}),n&&c.jsx("button",{type:"button",className:"mdocs-comment-reply-btn",onClick:()=>h({commentId:K.commentId,visitorName:Z.visitorName}),children:"回复"})]},Z.commentId))})]},K.commentId))}),n?c.jsxs("div",{className:"mdocs-comments-input-wrapper",children:[c.jsx("div",{className:"mdocs-comments-input-drag-handle",onMouseDown:re}),d&&c.jsxs("div",{className:"mdocs-comment-reply-notice",children:[c.jsxs("span",{children:["回复 ",c.jsx("span",{className:"mdocs-comment-reply-to-name",children:d.visitorName})]}),c.jsxs("button",{type:"button",onClick:()=>h(null),children:[c.jsx(zt,{size:14})," 取消"]})]}),c.jsx("textarea",{ref:O,value:l,onChange:K=>{u(K.target.value.slice(0,512)),setTimeout(()=>$(),0)},placeholder:d?`回复 ${d.visitorName}...`:"发表评论...",className:"mdocs-comments-input",style:{height:_},maxLength:512,onKeyDown:K=>{K.key==="Enter"&&(K.metaKey||K.ctrlKey)&&ue()}}),c.jsxs("div",{className:`mdocs-comments-char-count${l.length>=460?" mdocs-char-count--warn":""}`,children:[l.length,"/512"]}),c.jsx("div",{className:"mdocs-comments-input-actions",children:c.jsx("button",{type:"button",className:"mdocs-btn-primary",onClick:ue,disabled:p||!l.trim(),children:p?"发表中...":"发表"})})]}):c.jsx("div",{className:"mdocs-comments-input-wrapper",style:{textAlign:"center"},children:c.jsx("div",{style:{color:"#666",fontSize:"0.9rem"},children:"请先创建访客身份以发表评论"})}),w&&c.jsx(Aa,{title:"删除评论",message:"确定要删除这条评论吗?",confirmLabel:"删除",danger:!0,onConfirm:()=>A(w),onCancel:()=>b(null)})]})}const Jf="mdocs-drafts",Xf=5,Ae="drafts";let Ua=0;const Qo=new Set;function Xh(e){return Qo.add(e),()=>{Qo.delete(e)}}function Zh(){return Ua}function Ba(e,n){Ua+=1;for(const o of Qo)o(e,n)}const nn={DOC_NOT_FOUND:"DOC_NOT_FOUND",SYNC_HEAD_MISSING:"SYNC_HEAD_MISSING"};let To=null;function on(){return To||(To=new Promise((e,n)=>{const o=indexedDB.open(Jf,Xf);o.onupgradeneeded=r=>{const a=o.result;a.objectStoreNames.contains(Ae)||a.createObjectStore(Ae,{keyPath:"documentId"});const i=r.oldVersion;if(i>0&&i<4){const u=o.transaction.objectStore(Ae).openCursor();u.onsuccess=()=>{const d=u.result;if(!d)return;const h=d.value;typeof h.baseCommitId=="string"&&!h.localBaseCommitId&&(h.localBaseCommitId=h.baseCommitId,delete h.baseCommitId);const m=h.conflict;m&&(typeof m.baseCommitId=="string"&&!m.localBaseCommitId&&(m.localBaseCommitId=m.baseCommitId,delete m.baseCommitId),typeof m.expectedHeadCommitId=="string"&&!m.remoteCommitId&&(m.remoteCommitId=m.expectedHeadCommitId,delete m.expectedHeadCommitId)),d.update(h),d.continue()}}if(i>0&&i<5){const u=o.transaction.objectStore(Ae).openCursor();u.onsuccess=()=>{const d=u.result;if(!d)return;const h=d.value;h.contentKind==null&&(h.contentKind="lexical",d.update(h)),d.continue()}}},o.onsuccess=()=>e(o.result),o.onerror=()=>n(o.error)})),To}async function Zf(e){var r;const n=await Re(e.documentId),o={documentId:e.documentId,content:e.content,contentKind:e.contentKind??(n==null?void 0:n.contentKind)??"lexical",displayName:e.displayName,updatedAt:Date.now(),published:!1};if(n!=null&&n.localBaseCommitId)o.localBaseCommitId=n.localBaseCommitId;else{const a=(r=e.localBaseCommitIdAtEditStart)==null?void 0:r.trim();a&&(o.localBaseCommitId=a)}(n==null?void 0:n.permission)!=null?o.permission=n.permission:e.snapshotMeta&&(o.permission=e.snapshotMeta.permission),n!=null&&n.ownerVisitorId?o.ownerVisitorId=n.ownerVisitorId:e.snapshotMeta&&(o.ownerVisitorId=e.snapshotMeta.ownerVisitorId),n!=null&&n.domainId?o.domainId=n.domainId:e.snapshotMeta&&(o.domainId=e.snapshotMeta.domainId),n!=null&&n.publishError&&(o.publishError=n.publishError,o.publishErrorAt=n.publishErrorAt),n!=null&&n.conflictStatus&&(o.conflictStatus=n.conflictStatus),n!=null&&n.conflict&&(o.conflict=n.conflict),await $t(o)}function gr(e){const n={documentId:e.documentId,content:e.content,displayName:e.displayName,updatedAt:e.updatedAt,published:e.published};return e.permission!=null&&(n.permission=e.permission),e.ownerVisitorId&&(n.ownerVisitorId=e.ownerVisitorId),e.domainId&&(n.domainId=e.domainId),e.publishError!=null&&(n.publishError=e.publishError),e.publishErrorAt!=null&&(n.publishErrorAt=e.publishErrorAt),e.localBaseCommitId&&(n.localBaseCommitId=e.localBaseCommitId),e.conflictStatus!=null&&(n.conflictStatus=e.conflictStatus),e.conflict!=null&&(n.conflict=e.conflict),n}async function $t(e){const n=await on(),o=gr(e);return new Promise((r,a)=>{const i=n.transaction(Ae,"readwrite");i.objectStore(Ae).put(o),i.oncomplete=()=>{Ba(o.documentId,!o.published),r()},i.onerror=()=>a(i.error)})}async function Re(e){const n=await on();return new Promise((o,r)=>{const i=n.transaction(Ae,"readonly").objectStore(Ae).get(e);i.onsuccess=()=>o(i.result),i.onerror=()=>r(i.error)})}async function Ao(e){const n=await on();return new Promise((o,r)=>{const a=n.transaction(Ae,"readwrite");a.objectStore(Ae).delete(e),a.oncomplete=()=>{Ba(e,!1),o()},a.onerror=()=>r(a.error)})}async function Qf(e){const n=await on();return new Promise((o,r)=>{const i=n.transaction(Ae,"readonly").objectStore(Ae).getAll();i.onsuccess=()=>{let s=i.result;e!=null&&e.skipFailed&&(s=s.filter(l=>!l.publishError)),o(s)},i.onerror=()=>r(i.error)})}async function em(e,n){const o=await on();return new Promise((r,a)=>{const s=o.transaction(Ae,"readwrite").objectStore(Ae),l=s.get(e);l.onsuccess=()=>{const u=l.result;u&&s.put(gr({...u,publishError:n,publishErrorAt:Date.now()})),r()},l.onerror=()=>a(l.error)})}async function Mo(e){const n=await on();return new Promise((o,r)=>{const i=n.transaction(Ae,"readwrite").objectStore(Ae),s=i.get(e);s.onsuccess=()=>{const l=s.result;l&&i.put(gr({...l,publishError:void 0,publishErrorAt:void 0})),o()},s.onerror=()=>r(s.error)})}async function jo(e,n){const o=await Re(e);o&&await $t({...o,localBaseCommitId:n.localBaseCommitId,conflictStatus:n.conflictStatus,conflict:n.conflict})}async function Eo(e){const n=await Re(e);n&&await $t({...n,conflict:void 0,conflictStatus:"none"})}class Cn extends Error{constructor(o,r){super(o);Jt(this,"code");Jt(this,"cause");this.name="DraftPublishAborted",this.code=o,this.cause=r==null?void 0:r.cause}}function tm(e){return e instanceof Cn?e.code:e instanceof et?e.status===404?nn.DOC_NOT_FOUND:e.code||`HTTP_${e.status}`:e instanceof Error&&e.message.trim()?e.message.trim().slice(0,120):"UNKNOWN"}function nm(e,n,o,r){const a=(n==null?void 0:n.displayName)||e("unknownTitle");if(o===nn.SYNC_HEAD_MISSING)return e("draftPublishFailedSyncHead",{name:a});if(o===nn.DOC_NOT_FOUND)return e("draftPublishFailedNotice",{name:a});const i=r instanceof et||r instanceof Error&&r.message?r.message:o;return e("draftPublishFailedGeneric",{name:a,reason:i})}async function om(e,n,o){const r=tm(n);throw await em(e,r),n instanceof Cn?n:new Cn(r,{cause:n})}function rm(e,n){const o=x.useRef(n);o.current=n,x.useEffect(()=>{if(!e)return;const r=3e4,a=1e4,i=async()=>{const l=await Qf({skipFailed:!0}),u=Date.now();for(const d of l)if(!d.published&&!(u-d.updatedAt<r))try{await o.current(d.documentId)}catch(h){console.log("[autoPublish] scan publish failed:",h)}};i();const s=setInterval(i,a);return()=>clearInterval(s)},[e])}const im=1e4;function am(e,n){const[o,r]=x.useState(null),[a,i]=x.useState("up_to_date");return x.useEffect(()=>{if(!e){r(null),i("up_to_date");return}let l=!1;const u=e;async function d(){try{const m=await Al(u,n??void 0);if(l)return;r(m.headCommitId),i(m.status)}catch{}}d();const h=window.setInterval(()=>void d(),im);return()=>{l=!0,window.clearInterval(h)}},[e,n]),{remoteCommitId:o,syncStatus:a,syncBehind:!!(n&&o&&n!==o)||a==="behind"}}function Fi(e){return e.trim()}function sm(e){return e.trim()}const lm=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".ico",".bmp",".jfif",".pjpeg"]);function cm(e){const n=e.split("/").pop()??"",o=n.lastIndexOf(".");return o<=0?"":n.slice(o).toLowerCase()}function dm(e,n,o){let r,a;try{r=new URL(o),a=new URL(e,o)}catch{return null}if(a.origin!==r.origin||!a.pathname.startsWith("/api/assets/")||lm.has(cm(a.pathname)))return null;const i=n==null?void 0:n.trim();return i&&!a.searchParams.has("name")&&a.searchParams.set("name",i),a.toString()}function um(){const e=n=>{if(n.button!==0)return;const r=n.composedPath().find(i=>i instanceof HTMLAnchorElement);if(!r)return;const a=dm(r.href,r.getAttribute("download"),window.location.href);a&&(n.preventDefault(),n.stopPropagation(),window.location.assign(a))};return document.addEventListener("click",e,!0),()=>document.removeEventListener("click",e,!0)}const Le={DOCUMENT:"md",HTML:"html",SHEET:"sheet",FOLDER:"dir",FOLDER_DESC:"folder_desc",GRAPH_FILE:"graph_file",GRAPH_DIR:"graph_dir"},fm="/assets/mdocs-logo-Dsv_2t6v.svg",mm=x.lazy(()=>Pt(()=>import("./DocumentEditor-CmIk_VBn.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])).then(e=>({default:e.DocumentEditor}))),hm=x.lazy(()=>Pt(()=>import("./HtmlEditor-REIKOoam.js"),__vite__mapDeps([16,1,12,13,14,15,2,3,6,17])).then(e=>({default:e.HtmlEditor}))),pm=x.lazy(()=>Pt(()=>import("./SheetEditor-Bkxxf3ly.js"),__vite__mapDeps([18,1,12,13,14,7,11,2,3,6,19])).then(e=>({default:e.SheetEditor}))),gm=x.lazy(()=>Pt(()=>import("./SettingsPage-DsLbUPt-.js"),__vite__mapDeps([20,1,14,9,2,3,6])).then(e=>({default:e.SettingsPage}))),ym=x.lazy(()=>Pt(()=>import("./AgentChatPanel-e1h0rqbg.js"),__vite__mapDeps([21,1,9,8,7,2,3,6])).then(e=>({default:e.AgentChatPanel}))),vm=x.lazy(()=>Pt(()=>import("./AiWriteWorkbench-Dq0aCk5c.js"),__vite__mapDeps([22,1,21,9,8,7,2,3,6])).then(e=>({default:e.AiWriteWorkbench}))),bm=x.lazy(()=>Pt(()=>import("./MergeView-DCgxAslc.js"),__vite__mapDeps([23,1,4,5,2,3,6,7,8,9,13])).then(e=>({default:e.MergeView})));function xm(e,n){try{const o=new Intl.RelativeTimeFormat(n,{numeric:"auto"}),r=Date.now()-new Date(e).getTime(),a=Math.floor(r/6e4),i=Math.floor(a/60),s=Math.floor(i/24);return s>30?o.format(-Math.floor(s/30),"month"):s>0?o.format(-s,"day"):i>0?o.format(-i,"hour"):a>0?o.format(-a,"minute"):o.format(-Math.floor(r/1e3),"second")}catch{return e.slice(0,10)}}async function Ro(e,n,o,r){const a=await nr();n(a);const i=localStorage.getItem("mdocs.currentDomainId"),l=i&&a.some(u=>u.domainId===i)?i:Wl(a,e);o(l),await r(l)}function Li(){const{t:e,lang:n,setLang:o}=Ve(),[r,a]=x.useState("loading"),[i,s]=x.useState(()=>localStorage.getItem("mdocs.sidebarCollapsed")==="true"),l=Gf(),[u,d]=x.useState(!1),h=()=>{if(l){d(R=>!R);return}const y=!i;s(y),localStorage.setItem("mdocs.sidebarCollapsed",String(y))};x.useEffect(()=>{l||d(!1)},[l]),x.useEffect(()=>um(),[]);const[m,f]=x.useState(!1),[p,g]=x.useState(0),w=x.useRef(null),[b,v]=x.useState(null),[S,D]=x.useState(null),[P,_]=x.useState(null),[T,I]=x.useState([]),[N,L]=x.useState([]),[E,O]=x.useState("default"),[$,V]=x.useState(!1),J=x.useRef(null),{documentId:ne}=ss(),B=ls(),[G,ce]=x.useState(null),ue=(G==null?void 0:G.kind)==="document"?G.documentId:null,[A,ie]=x.useState(null),[oe,re]=x.useState(null),K=x.useRef(oe);K.current=oe;const[Z,we]=x.useState(0),[se,tt]=x.useState(null),[Tt,vt]=x.useState(!1),[rn,Vt]=x.useState(!1),[At,nt]=x.useState(!1),[_e,Ge]=x.useState(!1),Pn=(A==null?void 0:A.documentId)??null,{syncBehind:We,remoteCommitId:Mt}=am(Pn,se),[$e,Gt]=x.useState(null);x.useEffect(()=>{if(!At||!A){Gt(null);return}(async()=>{const y=await Re(A.documentId);if(y!=null&&y.conflict){Gt(y.conflict);return}if(y&&se&&Mt){const R=y.localBaseCommitId??se;if(!R)return;const M={localBaseCommitId:R,remoteCommitId:Mt,localSnapshotContent:y.content};await jo(A.documentId,{localBaseCommitId:M.localBaseCommitId,conflictStatus:"diverged",conflict:M}),Gt(M)}})()},[At,A,se,Mt]),x.useEffect(()=>{!A||!We||!_e||Re(A.documentId).then(async y=>{!y||y.conflict||y.conflictStatus==="publish_conflict"||y.conflictStatus!=="diverged"&&await $t({...y,conflictStatus:"diverged"})})},[A==null?void 0:A.documentId,We,_e]),x.useEffect(()=>{if(!A){tt(null);return}let y=!1;return Re(A.documentId).then(R=>{y||(R&&!R.published&&R.localBaseCommitId?tt(R.localBaseCommitId):tt(A.headCommitId??null))}),()=>{y=!0}},[A==null?void 0:A.documentId,A==null?void 0:A.headCommitId,_e]);const[Ee,me]=x.useState(null),[Ce,be]=x.useState(null),[xe,jt]=x.useState(null),[bt,ct]=x.useState(null),[an,Me]=x.useState(""),[sn,ot]=x.useState("docs");Kf(l&&sn==="docs",()=>d(!0),{open:u,onClose:()=>d(!1)});const[Fe,qe]=x.useState(!1),[Tn,xt]=x.useState(!1),[Wt,An]=Df(),k=x.useRef(null),[j,z]=x.useState(!1),[F,q]=x.useState(null),X=x.useRef(void 0),te=x.useRef(void 0);rm(localStorage.getItem("mdocs.autoPublish")==="true",Sr);async function Q(y){var R;await((R=X.current)==null?void 0:R.call(X)),y()}function ye(y){const M=(y.trim()||"untitled").replace(/[\\/:*?"<>|]/g,"-").slice(0,80);return M.endsWith(".md")?M:`${M}.md`}async function De(){var M,W;if(!A||!oe||A.fileType===Le.SHEET)return;await((M=X.current)==null?void 0:M.call(X));const y=A.fileType===Le.HTML;let R="";if(y)R=Fi(oe.content);else if(R=((W=te.current)==null?void 0:W.call(te))??"",!R.trim())try{R=(await vo({content:oe.content,from:"lexical",to:"markdown"})).content}catch{R=""}q({markdown:R,documentId:A.documentId,displayName:oe.displayName||A.displayName||"未命名",fileType:y?Le.HTML:Le.DOCUMENT}),z(!0),qe(!1)}function je(){q({markdown:"",documentId:null,displayName:"未命名",fileType:Le.DOCUMENT}),z(!0),qe(!1)}async function Ne(y){var le,Ie;const R=y.documentId.trim();if(!R)return;await((le=X.current)==null?void 0:le.call(X));let M="",W=y.displayName.trim()||"未命名",ee=Le.DOCUMENT;try{const Ft=await Xt(R);if(W=((Ie=Ft.displayName)==null?void 0:Ie.trim())||W,Ft.fileType===Le.SHEET)return;if(ee=Ft.fileType===Le.HTML?Le.HTML:Le.DOCUMENT,ee===Le.HTML)M=Fi(Ft.content);else try{M=(await vo({content:Ft.content,from:"lexical",to:"markdown"})).content}catch{M=""}}catch{}q({markdown:M,documentId:R,displayName:W,fileType:ee}),z(!0),qe(!1),ot("docs"),Q(()=>B(`/doc/${R}`))}async function ke(y){(A==null?void 0:A.documentId)===y.documentId&&await En()}async function Pe(y){const M=(y.documentId&&(F==null?void 0:F.documentId)===y.documentId?F.fileType:(A==null?void 0:A.documentId)===y.documentId?A.fileType:Le.DOCUMENT)===Le.HTML;if(y.documentId){const ee=(A==null?void 0:A.documentId)===y.documentId?A:null;let le;return M?le=sm(y.markdown):le=(await vo({content:y.markdown,from:"markdown",to:"lexical"})).content,await Zf({documentId:y.documentId,content:le,displayName:y.displayName,localBaseCommitIdAtEditStart:(ee==null?void 0:ee.headCommitId)??null,contentKind:M?"html":"lexical",snapshotMeta:ee?{permission:ee.permission,ownerVisitorId:ee.ownerVisitorId,domainId:ee.domainId}:void 0}),(A==null?void 0:A.documentId)===y.documentId?(re({documentId:y.documentId,content:le,displayName:y.displayName}),we(Ie=>Ie+1),Ge(!0)):await cn(y.documentId),me("帮写已写入草稿,可在编辑器中继续修改后发布"),{documentId:y.documentId}}const W=await $o({fileName:ye(y.displayName),displayName:y.displayName,content:y.markdown,contentFormat:"markdown",domainId:E||void 0,parentId:void 0});return await fe(),await cn(W.documentId),me("已创建文档"),{documentId:W.documentId}}x.useEffect(()=>{wt()},[]),x.useEffect(()=>{if(!Ee)return;const y=()=>{me(null)};return window.addEventListener("pointerdown",y,!0),()=>window.removeEventListener("pointerdown",y,!0)},[Ee]),x.useEffect(()=>{const y=R=>{var ee,le,Ie;const M=R;if(((ee=M.detail)==null?void 0:ee.status)===409||((le=M.detail)==null?void 0:le.code)==="AI_NOT_CONFIGURED")return;const W=(Ie=M.detail)==null?void 0:Ie.message;W&&be(W)};return window.addEventListener(zo,y),()=>window.removeEventListener(zo,y)},[]);async function wt(){try{const y=await Wr();v(y),Vn(y.visitorId),await Ro(y.visitorId,L,O,fe),a("ready")}catch(y){if(y instanceof et&&y.status===401){a("needsRegister");return}be(Je(e,y)),a("needsRegister")}}async function _t(y,R){const M=await Cl(y,R);v(M.visitor),D(M.visitor.visitorId),_(M.recoveryCode),Vn(M.visitor.visitorId),await Ro(M.visitor.visitorId,L,O,fe),a("ready")}async function dt(y){const R=await Wr();v(R),await Ro(R.visitorId,L,O,fe),a("ready")}async function fe(y){const M=await Tl(y??E);I(M)}function Ke(y){re({documentId:y.documentId,content:y.content,displayName:y.displayName}),we(R=>R+1),Ge(!1)}function Et(y,R){re({documentId:y,content:R.content,displayName:R.displayName}),we(M=>M+1),Ge(!0)}async function ln(y,R){await Ao(y);const M=await Xt(y);if((A==null?void 0:A.documentId)===y&&w.current===y){ie(fn(M)),Ge(!1);const W=K.current,ee=R!==void 0&&M.content===R,le=(W==null?void 0:W.documentId)===y&&W.content===M.content;ee||le?(W==null?void 0:W.documentId)===y&&W.displayName!==M.displayName&&re({...W,displayName:M.displayName}):Ke(M)}return M}function Rt(y,R,M="folder"){console.log("[openGraph]",M,y,R),ie(null),re(null),ce({kind:"graph",scope:M,resourceId:y,name:R})}function qt(){ce(null)}x.useEffect(()=>{function y(R){J.current&&!J.current.contains(R.target)&&V(!1)}if($)return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[$]);async function cn(y){w.current=y,ot("docs"),ce({kind:"document",documentId:y});try{const R=await Re(y);if(w.current!==y)return;const M=await Xt(y);if(w.current!==y||(M.domainId!==E&&(localStorage.setItem("mdocs.currentDomainId",M.domainId),O(M.domainId),fe(M.domainId)),Me($n(M.relativePath)),M.headCommitId&&R&&!R.published&&(R.publishError===nn.SYNC_HEAD_MISSING&&await Mo(y),R.localBaseCommitId||await $t({...R,localBaseCommitId:M.headCommitId})),ie(fn(M)),w.current!==y))return;R&&!R.published?Et(y,R):Ke(M)}catch(R){if(w.current!==y)return;be(Je(e,R))}}x.useEffect(()=>{r==="ready"&&(ne?cn(ne):(ce(null),ie(null),re(null),tt(null)))},[r,ne]);const{createModal:Kt,setCreateModal:ao,createModalError:yr,createModalBusy:Yt,createModalInputRef:Va,openNewDocumentModal:dn,openNewFolderModal:vr,submitCreateModal:Ga}=Vf({tree:T,currentDomainId:E,selectedCreateParentPath:an,t:e,onDocCreated:y=>{ie(fn(y)),Ke(y),Me($n(y.relativePath)),B(`/doc/${y.documentId}`)},refreshTree:fe}),[Wa,Mn]=x.useState(!1),[qa,so]=x.useState(!1);x.useEffect(()=>{const y=R=>{!(R.metaKey||R.ctrlKey)||R.key.toLowerCase()!=="k"||(R.preventDefault(),so(!0))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[]);const[Ka,un]=x.useState(!1),[Ot,br]=x.useState([]),[lo,xr]=x.useState(""),[jn,wr]=x.useState(""),[Ya,_r]=x.useState(new Set);async function Ja(){try{const y=await Fl();br(y)}catch(y){be(Je(e,y))}}const co=x.useMemo(()=>{const y={};for(const R of N)y[R.domainId]=R.domainName;return y},[N]),Ir=x.useMemo(()=>{let y=Ot;const R=lo.trim().toLowerCase();return R&&(y=y.filter(M=>{var W;return(W=M.displayName)==null?void 0:W.toLowerCase().includes(R)})),jn&&(y=y.filter(M=>M.domainId===jn)),y},[Ot,lo,jn]),Xa=x.useMemo(()=>{const y=new Set,R=[];for(const M of Ot){const W=M.domainId;W&&!y.has(W)&&(y.add(W),R.push({id:W,name:co[W]??W}))}return R},[Ot,co]);async function Za(y,R,M,W,ee){let le=await Re(y);!le&&(A==null?void 0:A.documentId)===y&&(le={documentId:y,content:R,displayName:M,updatedAt:Date.now(),published:!1,localBaseCommitId:W,permission:A.permission,ownerVisitorId:A.ownerVisitorId,domainId:A.domainId},await $t(le)),le&&await jo(y,{localBaseCommitId:W,conflictStatus:"publish_conflict",conflict:{localBaseCommitId:W,remoteCommitId:ee.headCommitId,localSnapshotContent:R}}),vt(!0)}async function Qa(){if(!A||rn||(b==null?void 0:b.visitorId)!==A.ownerVisitorId||!window.confirm(e("conflictForceConfirm")))return;const R=A.documentId;Vt(!0);try{await po(R).execute(async()=>{var fo,Dr,Nr,Pr,Tr;const M=await Re(R),W=((fo=M==null?void 0:M.conflict)==null?void 0:fo.localBaseCommitId)??(M==null?void 0:M.localBaseCommitId)??se??A.headCommitId,ee=((Dr=M==null?void 0:M.conflict)==null?void 0:Dr.remoteCommitId)??($e==null?void 0:$e.remoteCommitId),le=((Nr=M==null?void 0:M.conflict)==null?void 0:Nr.localSnapshotContent)??(M==null?void 0:M.content)??((Pr=K.current)==null?void 0:Pr.content),Ie=(M==null?void 0:M.displayName)??((Tr=K.current)==null?void 0:Tr.displayName)??A.displayName;if(!W||!ee||le==null)throw be(e("syncHeadMissing")),new Error("missing force overwrite payload");await yo(R,{content:le,displayName:Ie,version:{localBaseCommitId:W,merge:{remoteCommitId:ee,localSnapshotContent:le,forceLocal:!0}}});const Ft=await Xt(R);await kr(Ft)})}catch(M){M instanceof Error&&M.message==="missing force overwrite payload"||be(Je(e,M))}finally{Vt(!1)}}async function uo(y,R,M,W){return po(M).execute(async()=>{const ee=await Re(M),le=(ee==null?void 0:ee.localBaseCommitId)??(A==null?void 0:A.headCommitId);if(!le)throw be(e("syncHeadMissing")),new Error("missing localBaseCommitId");try{await yo(M,{content:y,displayName:R,permission:W,version:{localBaseCommitId:le}}),await Eo(M),await ln(M,y),await fe(),vt(!1),me(e("published")),window.setTimeout(()=>me(null),1200)}catch(Ie){throw Ie instanceof et&&Ie.status===409&&Ie.code==="VERSION_CONFLICT"&&Ie.details&&typeof Ie.details=="object"&&await Za(M,y,R,le,Ie.details),Ie}})}async function es(){if(!A)return;const y=await Xt(A.documentId);y.domainId!==E&&(localStorage.setItem("mdocs.currentDomainId",y.domainId),O(y.domainId),fe(y.domainId)),Me($n(y.relativePath)),ie(fn(y)),Ke(y),me(e("syncPullDone")),window.setTimeout(()=>me(null),1200)}async function En(){if(!A)return;const y=await Re(A.documentId),R=!!(y&&!y.published);if((y==null?void 0:y.conflictStatus)==="publish_conflict"||(y==null?void 0:y.conflictStatus)==="diverged"||!!(y!=null&&y.conflict)){nt(!0);return}if(R&&y){if(We&&Mt){const W=y.localBaseCommitId??se;if(W){const ee={localBaseCommitId:W,remoteCommitId:Mt,localSnapshotContent:y.content};await jo(A.documentId,{localBaseCommitId:W,conflictStatus:"diverged",conflict:ee}),Gt(ee)}nt(!0);return}me(e("pullBlockedDraft")),window.setTimeout(()=>me(null),3e3);return}await es()}async function kr(y){await Eo(y.documentId),await Ao(y.documentId),Ge(!1),nt(!1),vt(!1),await cn(y.documentId),fe(y.domainId),me(e("published")),window.setTimeout(()=>me(null),1200)}async function ts(y,R,M){try{await om(y,R,M)}catch(W){if(!(W instanceof Cn))throw W;const ee=M??await Re(y);throw me(nm(e,ee,W.code,W.cause??R)),window.setTimeout(()=>me(null),4e3),W}}async function Sr(y){let R;try{await po(y).execute(async()=>{const M=await Re(y);if(!M)return;R=M;let W=M.localBaseCommitId;if(W||(W=(await Xt(y)).headCommitId??void 0,W&&(await $t({...M,localBaseCommitId:W}),M.publishError===nn.SYNC_HEAD_MISSING&&await Mo(y))),!W)throw new Cn(nn.SYNC_HEAD_MISSING);const ee=await Re(y);ee&&(await yo(y,{content:ee.content,displayName:ee.displayName,version:{localBaseCommitId:W}}),await Eo(y),await Mo(y),(A==null?void 0:A.documentId)===y?await ln(y,ee.content):await Ao(y),await fe(),me(e("published")),window.setTimeout(()=>me(null),1200))})}catch(M){await ts(y,M,R)}}function Rn(y,R){jt({type:"document",id:y,name:R})}function Cr(y,R){jt({type:"folder",id:y,name:R})}async function ns(y,R){try{const M=await jl(y,R);await fe(M.domainId),(A==null?void 0:A.documentId)===y&&(ie(fn(M)),Me($n(M.relativePath)))}catch(M){M instanceof et?M.status===409&&be(M.message):be(Je(e,M))}}async function os(){if(xe)try{xe.type==="document"?(await Ml(xe.id),(A==null?void 0:A.documentId)===xe.id&&(ie(null),re(null),Me(""),B("/"))):xe.type==="folder"&&(await Rl(xe.id),A&&(ie(null),re(null),Me(""),B("/"))),await fe(),me(xe.type==="folder"?`已删除「${xe.name}」及其下所有内容`:`已删除「${xe.name}」`),window.setTimeout(()=>me(null),2e3)}catch(y){be(Je(e,y))}finally{jt(null)}}return r==="loading"?c.jsx("div",{className:"mdocs-loading muted",children:e("loading")}):r==="needsRegister"?c.jsx(ql,{onSubmit:_t,onRecover:dt,error:Ee}):c.jsxs("div",{className:"mdocs-app-root",children:[Gi(),c.jsx("div",{className:"mdocs-shell",children:sn==="settings"?c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"mdocs-main muted",style:{padding:24},children:"加载设置…"}),children:c.jsx(gm,{onBack:()=>ot("docs"),onPublishDraft:Sr,onOpenDocument:cn,onRecoverDraft:()=>void fe()})}):c.jsxs("div",{className:"mdocs-layout"+(l?" mdocs-layout--reader":""),children:[l&&u?c.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":e("collapseSidebar"),onClick:()=>d(!1)}):null,c.jsxs("aside",{className:"mdocs-sidebar"+(l?u?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":i?" mdocs-sidebar-collapsed":""),children:[c.jsxs("header",{className:"mdocs-sidebar-header",children:[c.jsxs("div",{className:"mdocs-brand",children:[c.jsx("img",{src:fm,alt:e("brand"),className:"mdocs-brand-logo"}),c.jsx("span",{children:e("brand")})]}),c.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:h,"aria-label":e(l?u?"collapseSidebar":"expandSidebar":i?"expandSidebar":"collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:y=>{y.currentTarget.style.background="var(--mdocs-hover-bg, #f0f0f0)"},onMouseLeave:y=>{y.currentTarget.style.background="none"},children:l?c.jsx(Rr,{size:18}):i?c.jsx(Or,{size:18}):c.jsx(Rr,{size:18})})]}),c.jsxs("div",{className:"mdocs-sidebar-actions",ref:J,children:[c.jsxs("button",{type:"button",className:"mdocs-sidebar-create-btn",onClick:()=>V(y=>!y),children:[c.jsx(Er,{size:15,strokeWidth:1.75}),e("newArticle")]}),$&&c.jsxs("div",{className:"mdocs-create-dropdown",children:[c.jsxs("button",{type:"button",className:"mdocs-create-dropdown-item",onClick:()=>{V(!1),dn()},children:[c.jsx(Er,{size:14,strokeWidth:1.5}),"Markdown"]}),c.jsxs("button",{type:"button",className:"mdocs-create-dropdown-item",onClick:()=>{V(!1),dn(void 0,"html")},children:[c.jsx(Fs,{size:14,strokeWidth:1.5}),"HTML"]}),c.jsxs("button",{type:"button",className:"mdocs-create-dropdown-item",onClick:()=>{V(!1),dn(void 0,"sheet")},children:[c.jsx(cl,{size:14,strokeWidth:1.5}),e("sheetDocument")]})]}),c.jsxs("button",{type:"button",className:"mdocs-sidebar-create-btn",onClick:()=>{V(!1),vr()},children:[c.jsx(Ws,{size:15,strokeWidth:1.75}),e("newDirectory")]}),c.jsx("span",{className:"mdocs-sidebar-icon mdocs-tooltip","data-tooltip":e("docSearch"),onClick:()=>so(!0),children:c.jsx(Ui,{size:18,strokeWidth:1.75})}),c.jsx("span",{className:"mdocs-sidebar-icon mdocs-tooltip","data-tooltip":"知识图谱",onClick:()=>Rt(E,"知识图谱","domain"),children:c.jsx(er,{size:18,strokeWidth:1.75})})]}),c.jsx(Yl,{nodes:T,activeDocumentId:ue,graphFocusAnchorId:(G==null?void 0:G.kind)==="graph"?G.resourceId:null,selectedParentPath:an,onOpen:y=>{l&&d(!1),Q(()=>B(`/doc/${y.documentId}`))},onOpenFolder:(y,R)=>{Q(()=>{Me(y),R&&(qt(),l&&d(!1),B(`/doc/${R}`))})},onContextMenu:ct,onMoveDocument:ns,onDeselect:()=>{qt(),Q(()=>{Me(""),B("/")})},onOpenGraph:(y,R)=>{if(y.type==="folder")Rt(y.documentId,y.name);else if(R){const M=T.find(W=>W.documentId===R);Rt(R,(M==null?void 0:M.name)??"图谱")}},onGenerateGraph:async(y,R)=>{var ee;const M=y.type==="folder"?y.documentId:R;if(!M)return;const W=y.type==="folder"?y.name:((ee=T.find(le=>le.documentId===R))==null?void 0:ee.name)??"图谱";Rt(M,W)}}),c.jsxs("footer",{className:"mdocs-sidebar-footer",children:[c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,cursor:"pointer"},onClick:()=>Q(()=>ot("settings")),children:[c.jsx("span",{className:"mdocs-visitor-avatar",children:b?b.visitorName.charAt(0).toUpperCase():"?"}),c.jsx("span",{className:"mdocs-visitor-footer-name",children:b?b.visitorName:""})]}),c.jsx("button",{type:"button",className:"mdocs-sidebar-bookmark mdocs-tooltip","data-tooltip":e("bookmark"),onClick:()=>{un(!0),xr(""),wr(""),Ja()},style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4},children:c.jsx(sl,{size:16,strokeWidth:1.5})}),c.jsx("button",{type:"button",className:"mdocs-sidebar-logout mdocs-tooltip","data-tooltip":e("logout"),onClick:()=>Mn(!0),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",lineHeight:1,borderRadius:4},children:c.jsx(Xs,{size:16,strokeWidth:1.5})})]})]}),c.jsxs("main",{className:"mdocs-main",children:[(G==null?void 0:G.kind)==="graph"?c.jsx(bf,{scope:G.scope,resourceId:G.resourceId,name:G.name,onClose:qt,onOpenDocument:y=>{Q(()=>B(`/doc/${y}`))}},`${G.scope}-${G.resourceId}`):A&&oe&&oe.documentId===A.documentId?A.fileType==="html"||A.fileType==="sheet"?c.jsxs("div",{className:"mdocs-editor-with-comments",children:[c.jsx("div",{className:"mdocs-editor-container",children:c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"muted",style:{padding:24},children:"加载编辑器…"}),children:A.fileType==="sheet"?c.jsx(pm,{meta:A,initialContent:oe.content,initialDisplayName:oe.displayName,contentRevision:Z,canEdit:!!(b&&(A.ownerVisitorId===b.visitorId||go(A.permission)||A.invitedEdit===!0)),domains:N,currentDomainId:E,onDomainChange:y=>{Q(()=>{localStorage.setItem("mdocs.currentDomainId",y),O(y),ie(null),re(null),Me(""),B("/"),fe(y)})},onDomainsChange:L,onContentChange:y=>{re(R=>R&&{...R,content:y})},onDraftExistsChange:Ge,hasLocalDraft:_e,onPublish:uo,syncBehind:We,onSyncClick:()=>void En(),onDelete:async()=>{Rn(A.documentId,A.relativePath)},canManageInvites:!!(b&&b.visitorId===A.ownerVisitorId),onToggleComments:()=>f(!m),commentPanelOpen:m,commentCount:p,onShowToast:me,readerChrome:l,onOpenMobileNav:()=>d(!0)},A.documentId):c.jsx(hm,{meta:A,initialContent:oe.content,initialDisplayName:oe.displayName,contentRevision:Z,canEdit:!!(b&&(A.ownerVisitorId===b.visitorId||go(A.permission)||A.invitedEdit===!0)),domains:N,currentDomainId:E,onDomainChange:y=>{Q(()=>{localStorage.setItem("mdocs.currentDomainId",y),O(y),ie(null),re(null),Me(""),B("/"),fe(y)})},onDomainsChange:L,onContentChange:y=>{re(R=>R&&{...R,content:y})},onDraftExistsChange:Ge,hasLocalDraft:_e,onPublish:uo,syncBehind:We,onSyncClick:()=>void En(),canManageInvites:!!(b&&b.visitorId===A.ownerVisitorId),onDelete:async()=>{Rn(A.documentId,A.relativePath)},onToggleComments:()=>f(!m),commentPanelOpen:m,commentCount:p,onAiWrite:l?void 0:()=>void De(),onShowToast:me,readerChrome:l,onOpenMobileNav:()=>d(!0)},A.documentId)})}),m&&c.jsx(Oi,{documentId:A.documentId,visitorId:b==null?void 0:b.visitorId,visitorName:b==null?void 0:b.visitorName,documentOwnerId:A.ownerVisitorId,onClose:()=>f(!1)})]}):c.jsxs("div",{className:"mdocs-editor-with-comments",children:[c.jsx("div",{className:"mdocs-editor-container",children:c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"muted",style:{padding:24},children:"加载编辑器…"}),children:c.jsx(mm,{meta:A,initialContent:oe.content,initialDisplayName:oe.displayName,contentRevision:Z,canEdit:!!(b&&(A.ownerVisitorId===b.visitorId||go(A.permission)||A.invitedEdit===!0)),domains:N,currentDomainId:E,onDomainChange:y=>{Q(()=>{localStorage.setItem("mdocs.currentDomainId",y),O(y),ie(null),re(null),Me(""),B("/"),fe(y)})},onDomainsChange:L,onPublish:uo,syncBehind:We,onSyncClick:()=>void En(),onDraftExistsChange:Ge,hasLocalDraft:_e,onConflictModalRequest:()=>vt(!0),onMergeRequest:()=>nt(!0),canManageInvites:!!(b&&b.visitorId===A.ownerVisitorId),onDelete:async()=>{if(A.relativePath.endsWith("/___desc___.md")){const y=A.relativePath.replace(/\/___desc___\.md$/,"");Cr(A.documentId,y)}else Rn(A.documentId,A.relativePath)},saveBeforeNavRef:X,exportMarkdownRef:te,onShowToast:me,onShowError:be,onToggleComments:()=>f(!m),commentPanelOpen:m,commentCount:p,onAiWrite:l?void 0:()=>void De(),readerChrome:l,onOpenMobileNav:()=>d(!0)},A.documentId)})}),m&&c.jsx(Oi,{documentId:A.documentId,visitorId:b==null?void 0:b.visitorId,visitorName:b==null?void 0:b.visitorName,documentOwnerId:A.ownerVisitorId,onClose:()=>f(!1)})]}):c.jsxs("div",{className:"mdocs-welcome",children:[l?c.jsxs("button",{type:"button",className:"mdocs-reader-float-pill",onClick:()=>d(!0),"aria-label":e("expandSidebar"),children:[c.jsx(Or,{size:18,strokeWidth:1.75}),c.jsx("span",{children:e("brand")})]}):null,c.jsx("div",{className:"mdocs-welcome-icon",children:c.jsx(Rs,{size:64,strokeWidth:1,opacity:.15})}),c.jsx("h1",{children:e("brand")}),c.jsx("p",{className:"mdocs-welcome-lead",children:e("createDocToStart")}),c.jsxs("div",{className:"mdocs-welcome-actions",children:[c.jsxs("button",{type:"button",className:"primary",onClick:()=>dn(),style:{display:"flex",alignItems:"center",gap:6},children:[c.jsx(Vs,{size:16,strokeWidth:1.5}),e("startWriting")]}),l?null:c.jsxs("button",{type:"button",className:"secondary",onClick:()=>je(),style:{display:"flex",alignItems:"center",gap:6},children:[c.jsx("img",{src:Ta,alt:"",width:16,height:16,style:{display:"block"}}),"AI 帮写"]})]}),c.jsxs("div",{className:"mdocs-welcome-domain",children:[c.jsx("label",{className:"muted mdocs-welcome-domain-label",children:e("domainLabel")}),c.jsx(wf,{domains:N.length?N:[{domainId:"default",domainName:e("defaultDomain"),permission:"",creatorVisitorId:"",docCount:0}],value:E,onChange:y=>{Q(()=>{localStorage.setItem("mdocs.currentDomainId",y),O(y),ie(null),re(null),Me(""),B("/"),fe(y)})},onDomainsChange:L,ariaLabel:e("domainLabel"),localizeName:y=>kn(y,n,e)})]})]}),c.jsx(Yf,{open:Tt,onClose:()=>vt(!1),onResolve:()=>{vt(!1),nt(!0)},onForceOverwrite:b&&A&&b.visitorId===A.ownerVisitorId?()=>void Qa():void 0,forceBusy:rn}),At&&A&&$e&&c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"merge-view-loading",children:e("mergeLoadingRemote")}),children:c.jsx(bm,{documentId:A.documentId,displayName:A.displayName,conflict:$e,fileType:A.fileType,onClose:()=>nt(!1),onSuccess:kr,onError:y=>be(y)})}),Ee&&c.jsx("div",{className:"mdocs-toast",role:"status",children:Ee}),Ce&&c.jsx(Nf,{title:e("error"),message:Ce,onClose:()=>be(null)})]}),Wa&&c.jsx("div",{className:"mdocs-dialog-backdrop",onClick:y=>{y.target===y.currentTarget&&Mn(!1)},children:c.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:440},children:[c.jsx("h1",{style:{fontSize:"1.125rem",marginBottom:8},children:"退出当前登录身份?"}),c.jsx("p",{style:{lineHeight:1.6,color:"var(--mdocs-text-secondary, #666)",marginBottom:20},children:"这将会导致您无法修改以前的文章。如果想找回账号,需要恢复码或联系管理员执行合并用户脚本。"}),c.jsxs("div",{className:"mdocs-dialog-actions",style:{justifyContent:"flex-end"},children:[c.jsx("button",{type:"button",onClick:()=>Mn(!1),children:"取消"}),c.jsx("button",{type:"button",className:"primary",style:{background:"#d32f2f"},onClick:()=>{Sl(),ie(null),re(null),v(null),I([]),Mn(!1),a("needsRegister")},children:"确认退出"})]})]})}),Ka&&c.jsx("div",{className:"mdocs-dialog-backdrop",onClick:y=>{y.target===y.currentTarget&&un(!1)},children:c.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:640,width:"min(640px, 100%)",maxHeight:"70vh",display:"flex",flexDirection:"column"},children:[c.jsxs("h1",{style:{fontSize:"1.125rem",marginBottom:16},children:[e("bookmarkTitle"),"(",Ot.length,")"]}),Ot.length>0&&c.jsxs("div",{className:"mdocs-bookmark-filterbar",children:[c.jsx("input",{type:"text",placeholder:e("bookmarkSearch"),value:lo,onChange:y=>xr(y.target.value)}),c.jsxs("select",{value:jn,onChange:y=>wr(y.target.value),children:[c.jsx("option",{value:"",children:e("bookmarkFilterAll")}),Xa.map(y=>c.jsx("option",{value:y.id,children:y.name},y.id))]})]}),Ot.length===0?c.jsx("p",{style:{color:"var(--mdocs-text-muted, #999)",textAlign:"center",padding:"2rem 0"},children:e("bookmarkEmpty")}):Ir.length===0?c.jsx("p",{style:{color:"var(--mdocs-text-muted, #999)",textAlign:"center",padding:"2rem 0"},children:e("bookmarkNoMatch")}):c.jsx("div",{style:{overflowY:"auto",flex:1,margin:"0 -1rem",padding:"0 1rem"},children:c.jsxs("table",{className:"mdocs-bookmark-table",children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:e("bookmarkColTitle")}),c.jsx("th",{children:e("bookmarkColDomain")}),c.jsx("th",{children:e("bookmarkColAuthor")}),c.jsx("th",{children:e("bookmarkColTime")}),c.jsx("th",{className:"mdocs-bookmark-col-action"})]})}),c.jsx("tbody",{children:Ir.map(y=>{const R=Ya.has(y.documentId);return c.jsxs("tr",{className:`${R?"mdocs-bookmark-removing":""}`,style:{opacity:y.isDeleted?.6:1},children:[c.jsx("td",{className:"mdocs-bookmark-col-title",children:c.jsxs("div",{style:{cursor:y.isDeleted?"default":"pointer",display:"flex",alignItems:"center",gap:6,overflow:"hidden"},onClick:()=>{y.isDeleted||Q(()=>{un(!1),B(`/doc/${y.documentId}`)})},children:[c.jsx("span",{ref:M=>{if(M){const W=M.scrollWidth>M.clientWidth;M.title=W?y.displayName??"":""}},style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:y.displayName??"(无标题)"}),y.isDeleted&&c.jsx("span",{style:{fontSize:"0.7rem",color:"#d32f2f",background:"#ffebee",padding:"1px 6px",borderRadius:4,flexShrink:0},children:"已删除"})]})}),c.jsx("td",{children:y.isDeleted?"":co[y.domainId??""]??y.domainId??""}),c.jsx("td",{children:y.isDeleted?"":y.ownerVisitorName??"-"}),c.jsx("td",{children:y.isDeleted?"":xm(y.bookmarkedAt,n)}),c.jsx("td",{className:"mdocs-bookmark-col-action",children:c.jsxs("div",{style:{display:"flex",gap:2,alignItems:"center",justifyContent:"flex-end"},children:[c.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkOpen"),onClick:()=>{y.isDeleted||Q(()=>{un(!1),B(`/doc/${y.documentId}`)})},style:{background:"none",border:"none",cursor:y.isDeleted?"default":"pointer",padding:"4px",color:"var(--mdocs-text-muted, #999)",lineHeight:1,borderRadius:4,display:"inline-flex",alignItems:"center"},children:c.jsx(Ms,{size:14,strokeWidth:1.5})}),c.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkRemove"),onClick:async()=>{try{await Ll(y.documentId),_r(M=>new Set(M).add(y.documentId)),setTimeout(()=>{br(M=>M.filter(W=>W.documentId!==y.documentId)),_r(M=>{const W=new Set(M);return W.delete(y.documentId),W})},300)}catch(M){be(Je(e,M))}},style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4,display:"inline-flex",alignItems:"center"},onMouseEnter:M=>{M.currentTarget.style.color="#d32f2f"},onMouseLeave:M=>{M.currentTarget.style.color="var(--mdocs-text-muted, #999)"},children:"✕"})]})})]},y.documentId)})})]})}),c.jsx("div",{className:"mdocs-dialog-actions",style:{justifyContent:"flex-end",marginTop:16,paddingTop:16,borderTop:"1px solid var(--mdocs-border, #eee)"},children:c.jsx("button",{type:"button",onClick:()=>un(!1),children:e("close")})})]})}),bt&&c.jsx(xf,{x:bt.x,y:bt.y,node:bt.node,parentPath:bt.parentPath,onClose:()=>ct(null),onCreateChild:y=>dn(y),onCreateFolder:y=>vr(y),onDeleteDocument:y=>Rn(y.documentId,y.path),onDeleteFolder:y=>Cr(y.documentId,y.folderDisplayName||y.name)}),xe&&c.jsx(Aa,{title:xe.type==="folder"?"删除文件夹":"删除文档",message:xe.type==="folder"?`确定要删除「${xe.name}」及其下的所有文档和子文件夹吗?此操作不可撤销。`:`确定要删除「${xe.name}」吗?`,confirmLabel:"删除",cancelLabel:"取消",onConfirm:os,onCancel:()=>jt(null),danger:!0}),Kt&&c.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&!Yt&&ao(null)},children:c.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[c.jsx("h1",{children:Kt.kind==="document"?e("newDocumentTitle"):e("newFolderTitle")}),c.jsx("p",{className:"muted",children:Kt.kind==="document"?e("fileNameHint"):e("folderNameHint")}),c.jsxs("form",{onSubmit:Ga,className:"mdocs-dialog-form",children:[c.jsxs("label",{className:"mdocs-dialog-label",children:[Kt.kind==="document"?e("fileNameLabel"):e("folderNameLabel"),c.jsx("input",{ref:Va,value:Kt.draft,onChange:y=>ao(R=>R&&{...R,draft:y.target.value}),placeholder:Kt.kind==="document"?e("untitledPlaceholder"):e("folderExamplePlaceholder"),maxLength:200,disabled:Yt})]}),yr&&c.jsx("div",{className:"mdocs-dialog-error",children:yr}),c.jsxs("div",{className:"mdocs-dialog-actions",children:[c.jsx("button",{type:"button",onClick:()=>!Yt&&ao(null),disabled:Yt,children:e("cancel")}),c.jsx("button",{type:"submit",className:"primary",disabled:Yt,children:e(Yt?"creating":"create")})]})]})]})})]})}),S&&b&&c.jsx(Kl,{visitorId:S,onDismiss:()=>D(null)}),P&&c.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:y=>{y.target===y.currentTarget&&_(null)},children:c.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480,textAlign:"center"},children:[c.jsx("h1",{style:{fontSize:"1.25rem",marginBottom:8},children:"🔑 保存你的恢复码"}),c.jsxs("p",{className:"muted",style:{marginBottom:16,lineHeight:1.5},children:["恢复码是你的唯一凭证,当 Token 丢失时可用它找回身份。",c.jsx("br",{}),c.jsx("strong",{children:"请立即复制保存,此弹窗关闭后不可再查看。"})]}),c.jsx("div",{style:{background:"#f5f5f5",borderRadius:8,padding:"12px 16px",fontFamily:"monospace",fontSize:"1.25rem",letterSpacing:"0.1em",marginBottom:20,userSelect:"all"},children:P}),c.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"center"},children:[c.jsx("button",{type:"button",className:"primary",onClick:()=>{navigator.clipboard.writeText(P)},children:"复制恢复码"}),c.jsx("button",{type:"button",onClick:()=>_(null),children:"已保存,关闭"})]})]})}),c.jsxs(c.Fragment,{children:[c.jsx(Cf,{open:Fe,onToggle:()=>{var y;Fe?(y=k.current)==null||y.requestClose():qe(!0)},position:Wt,onPositionChange:An}),Fe?c.jsx(x.Suspense,{fallback:null,children:c.jsx(ym,{ref:k,open:Fe,onClose:()=>{qe(!1),xt(!1)},visitorName:b==null?void 0:b.visitorName,fullscreen:l||Tn,onToggleFullscreen:l?void 0:()=>xt(y=>!y),domainId:E||null,domains:N,localizeDomainName:y=>kn(y,n,e),documentId:(A==null?void 0:A.documentId)??null,documentTitle:(A==null?void 0:A.displayName)??null,documentPath:(A==null?void 0:A.relativePath)??null,graphFileId:(G==null?void 0:G.kind)==="graph"?`${G.resourceId}.graph-file`:null,graphLabel:(G==null?void 0:G.kind)==="graph"?G.name:null,anchorStyle:l||Tn?void 0:Sf(Wt),onOpenDocument:y=>{ot("docs"),Q(()=>B(`/doc/${y}`)),qe(!1),xt(!1)},onTreeChanged:()=>void fe(),onDocumentOverwritten:y=>void ke(y),onOpenCoding:l?void 0:y=>void Ne(y)})}):null]}),F?c.jsx(x.Suspense,{fallback:null,children:c.jsx(vm,{open:j,initialMarkdown:F.markdown,documentId:F.documentId,displayName:F.displayName,onClose:()=>{z(!1),q(null)},onComplete:Pe})}):null,c.jsx(Mf,{open:qa,domains:N,onDomainsChange:L,onClose:()=>so(!1),onOpenDocument:y=>{l&&d(!1),ot("docs"),Q(()=>B(`/doc/${y}`))}})]})}const wm=x.lazy(()=>Pt(()=>import("./PlaygroundPage-Cz9TMo7h.js"),__vite__mapDeps([24,1,4,5,2,3,6,7,8,9,10,11])).then(e=>({default:e.PlaygroundPage})));function _m(){return c.jsxs(cs,{children:[c.jsx(mo,{path:"/",element:c.jsx(Li,{})}),c.jsx(mo,{path:"/doc/:documentId",element:c.jsx(Li,{})}),c.jsx(mo,{path:"/playground",element:c.jsx(x.Suspense,{fallback:c.jsx("div",{style:{padding:24},children:"Loading playground…"}),children:c.jsx(wm,{})})})]})}function Im(){const{pathname:e,hash:n,search:o,origin:r}=window.location,a="/",i=a.endsWith("/")?a.slice(0,-1):a;let s=e;i&&s.startsWith(i)&&(s=s.slice(i.length)||"/");const l=s.match(/^\/doc\/([^/]+)\/?$/);if(!l)return;const u=n.match(/^#\/doc\/([^/?#]+)/),d=(u==null?void 0:u[1])??l[1];if(!d)return;const h=a.endsWith("/")?a:`${a}/`;window.location.replace(`${r}${h}${o}#/doc/${d}`)}Im();const Ha=document.getElementById("root");if(!Ha)throw new Error("root element missing");ds.createRoot(Ha).render(c.jsx(zi.StrictMode,{children:c.jsx(fs,{motion:Ss,children:c.jsx(ms,{children:c.jsx(gl,{children:c.jsx(us,{children:c.jsx(_m,{})})})})})}));export{nr as $,Kh as A,Jh as B,Rs as C,rt as D,$h as E,zh as F,Uh as G,Wh as H,Yh as I,Fh as J,Rh as K,Lh as L,Oh as M,er as N,$f as O,qh as P,Bh as Q,Hh as R,sl as S,Gl as T,Or as U,wf as V,Fr as W,zt as X,zs as Y,Ta as Z,Qs as _,Re as a,vh as a$,Tl as a0,Yl as a1,$o as a2,Je as a3,Qf as a4,nm as a5,Mo as a6,Cn as a7,Mm as a8,Pl as a9,oh as aA,rh as aB,Gf as aC,Kf as aD,ho as aE,Er as aF,nh as aG,Fl as aH,sh as aI,fm as aJ,Rr as aK,Ui as aL,Gi as aM,Lm as aN,Fm as aO,th as aP,Ih as aQ,Nh as aR,Ph as aS,Dh as aT,Pi as aU,ph as aV,yh as aW,Gn as aX,Fo as aY,mf as aZ,gh as a_,Ah as aa,Hm as ab,Bm as ac,Um as ad,$m as ae,Wm as af,jm as ag,Rm as ah,Em as ai,Om as aj,Gm as ak,Vm as al,qm as am,Km as an,Ym as ao,lh as ap,Wr as aq,Aa as ar,ch as as,qr as at,dh as au,uh as av,fh as aw,mh as ax,hh as ay,Ol as az,Zh as b,bh as b0,Th as b1,Ch as b2,_h as b3,wh as b4,xh as b5,Sh as b6,kh as b7,Xt as b8,Jm as b9,vo as ba,yo as bb,On as bc,Ve as c,Ao as d,ih as e,zm as f,po as g,Pm as h,ah as i,Xm as j,Qm as k,kn as l,Zm as m,eh as n,ve as o,Eh as p,pr as q,Ll as r,Xh as s,Mh as t,Zf as u,Lf as v,jh as w,Gh as x,Vh as y,io as z};
|
|
299
|
+
`}function zf(e,n){if(!Array.isArray(e))return[];const o=new Set(n.rows.map(i=>i.id)),r=new Set(n.columns.map(i=>i.id)),a=[];for(const i of e){if(!i||typeof i!="object")continue;const s=i,l=typeof s.startRowId=="string"?s.startRowId:"",u=typeof s.startColId=="string"?s.startColId:"",d=typeof s.endRowId=="string"?s.endRowId:"",h=typeof s.endColId=="string"?s.endColId:"";!o.has(l)||!o.has(d)||!r.has(u)||!r.has(h)||a.push({startRowId:l,startColId:u,endRowId:d,endColId:h})}return a}function ji(e,n){if(!e||typeof e!="object")return null;const o=e,r=Array.isArray(o.columns)?o.columns:[],a=Array.isArray(o.rows)?o.rows:[],i=[];for(const h of r){if(!h||typeof h!="object")continue;const m=h,f=typeof m.id=="string"&&m.id?m.id:Nt("c"),p=typeof m.name=="string"?m.name:f;i.push({id:f,name:p})}if(i.length===0)return null;const s=[];for(const h of a){if(!h||typeof h!="object")continue;const m=h,f=typeof m.id=="string"&&m.id?m.id:Nt("r"),p=m.cells&&typeof m.cells=="object"&&!Array.isArray(m.cells)?m.cells:{},g={};for(const w of i)g[w.id]=Ef(p[w.id]);s.push({id:f,cells:g})}const l=typeof o.id=="string"&&o.id?o.id:Nt("s"),u=typeof o.name=="string"&&o.name.trim()?o.name.trim():n,d=zf(o.merges,{columns:i,rows:s});return{id:l,name:u,columns:i,rows:s,merges:d}}function Eh(e){const n=e.trim();if(!n)return tn();let o;try{o=JSON.parse(n)}catch{return tn()}if(!o||typeof o!="object")return tn();const r=o;if(Array.isArray(r.sheets)&&r.sheets.length>0){const i=[];for(let u=0;u<r.sheets.length;u+=1){const d=ji(r.sheets[u],`Sheet${u+1}`);d&&i.push(d)}if(i.length===0)return tn();const s=typeof r.activeSheetId=="string"?r.activeSheetId:"",l=i.some(u=>u.id===s)?s:i[0].id;return{version:Qn,sheets:i,activeSheetId:l}}const a=ji(r,"Sheet1");return a?{version:Qn,sheets:[a],activeSheetId:a.id}:tn()}function pr(e,n){const o=n==null?void 0:n.trim();if(!o)return e.sheets.find(s=>s.id===e.activeSheetId)??e.sheets[0]??null;const r=e.sheets.find(s=>s.id===o);if(r)return r;const a=e.sheets.find(s=>s.name===o);if(a)return a;const i=o.toLowerCase();return e.sheets.find(s=>s.name.toLowerCase()===i)??null}function $f(e,n){if(!e.sheets.some(o=>o.id===n.id))throw new Error(`unknown sheet: ${n.id}`);return{...e,sheets:e.sheets.map(o=>o.id===n.id?n:o)}}function Rh(e,n){const o=pr(e,n);if(!o)throw new Error(`unknown sheet: ${n}`);return{...e,activeSheetId:o.id}}function Oh(e,n){let o=`Sheet${e.sheets.length+1}`;const r=new Set(e.sheets.map(i=>i.name));if(r.has(o)){let i=2;for(;r.has(`${o}${i}`);)i+=1;o=`${o}${i}`}const a=Oa({name:o});return{doc:{...e,sheets:[...e.sheets,a],activeSheetId:a.id},tab:a}}function Fh(e,n,o){const r=pr(e,n);if(!r)throw new Error(`unknown sheet: ${n}`);const a=o.trim();if(!a)throw new Error("sheet name is required");if(e.sheets.find(s=>s.id!==r.id&&s.name===a))throw new Error(`sheet name already exists: ${a}`);return $f(e,{...r,name:a})}function Lh(e,n){const o=pr(e,n);if(!o)throw new Error(`unknown sheet: ${n}`);if(e.sheets.length<=1)throw new Error("cannot delete the last sheet");const r=e.sheets.filter(i=>i.id!==o.id),a=e.activeSheetId===o.id?r[0].id:e.activeSheetId;return{...e,sheets:r,activeSheetId:a}}function Ze(e,n){return e.rows.findIndex(o=>o.id===n)}function Qe(e,n){return e.columns.findIndex(o=>o.id===n)}function Fa(e,n){const o=Ze(e,n.startRowId),r=Ze(e,n.endRowId),a=Qe(e,n.startColId),i=Qe(e,n.endColId);if(o<0||r<0||a<0||i<0)return null;const s=Math.min(o,r),l=Math.max(o,r),u=Math.min(a,i),d=Math.max(a,i);return s===l&&u===d?null:{startRowId:e.rows[s].id,startColId:e.columns[u].id,endRowId:e.rows[l].id,endColId:e.columns[d].id}}function Uf(e,n,o){const r=Ze(e,n.startRowId),a=Ze(e,n.endRowId),i=Qe(e,n.startColId),s=Qe(e,n.endColId),l=Ze(e,o.startRowId),u=Ze(e,o.endRowId),d=Qe(e,o.startColId),h=Qe(e,o.endColId);if(r<0||a<0||l<0||u<0||i<0||s<0||d<0||h<0)return!1;const m=Math.min(r,a),f=Math.max(r,a),p=Math.min(i,s),g=Math.max(i,s),w=Math.min(l,u),b=Math.max(l,u),v=Math.min(d,h),S=Math.max(d,h);return!(f<w||b<m||g<v||S<p)}function io(e,n,o){const r=Ze(e,n),a=Qe(e,o);if(r<0||a<0)return null;for(const i of e.merges??[]){const s=Ze(e,i.startRowId),l=Ze(e,i.endRowId),u=Qe(e,i.startColId),d=Qe(e,i.endColId);if(s<0||l<0||u<0||d<0)continue;const h=Math.min(s,l),m=Math.max(s,l),f=Math.min(u,d),p=Math.max(u,d);if(r>=h&&r<=m&&a>=f&&a<=p)return i}return null}function zh(e,n,o){const r=io(e,n,o);return r?r.startRowId===n&&r.startColId===o:!0}function $h(e,n,o){const r=io(e,n,o);return r?!(r.startRowId===n&&r.startColId===o):!1}function Uh(e,n){const o=Ze(e,n.startRowId),r=Ze(e,n.endRowId),a=Qe(e,n.startColId),i=Qe(e,n.endColId);return{rowSpan:Math.abs(r-o)+1,colSpan:Math.abs(i-a)+1}}function La(e){const n=new Set(e.rows.map(a=>a.id)),o=new Set(e.columns.map(a=>a.id)),r=(e.merges??[]).filter(a=>n.has(a.startRowId)&&n.has(a.endRowId)&&o.has(a.startColId)&&o.has(a.endColId)&&Fa(e,a)!=null);return{...e,merges:r}}function Bh(e,n){const o=Fa(e,n);if(!o)throw new Error("invalid merge range (need at least 2 cells)");for(const r of e.merges??[])if(Uf(e,r,o))throw new Error("merge overlaps existing merge");return{...e,merges:[...e.merges??[],o]}}function Hh(e,n,o){const r=io(e,n,o);return r?{tab:{...e,merges:(e.merges??[]).filter(a=>a!==r)},removed:r}:{tab:e,removed:null}}function za(e,n,o){const r=io(e,n,o);return!r||r.startRowId===n&&r.startColId===o?{rowId:n,columnId:o,redirected:!1}:{rowId:r.startRowId,columnId:r.startColId,redirected:!0}}function Vh(e,n){const o={id:Nt("c"),name:`列${e.columns.length+1}`};return{...e,columns:[...e.columns,o],rows:e.rows.map(r=>({...r,cells:{...r.cells,[o.id]:Nn()}}))}}function Gh(e){const n={};for(const o of e.columns)n[o.id]=Nn();return{...e,rows:[...e.rows,{id:Nt("r"),cells:n}]}}function Wh(e,n,o,r){const a=za(e,n,o);return{...e,rows:e.rows.map(i=>{if(i.id!==a.rowId)return i;const s=i.cells[a.columnId]??Nn();return{...i,cells:{...i.cells,[a.columnId]:{v:r,...s.style?{style:s.style}:{}}}}})}}function qh(e,n,o,r){const a=za(e,n,o);return{...e,rows:e.rows.map(i=>{if(i.id!==a.rowId)return i;const s=i.cells[a.columnId]??Nn(),l=Rf(s.style,r),u=l?{v:s.v,style:l}:{v:s.v};return{...i,cells:{...i.cells,[a.columnId]:u}}})}}function Kh(e,n,o){return{...e,columns:e.columns.map(r=>r.id===n?{...r,name:o}:r)}}function Yh(e,n){return La({...e,rows:e.rows.filter(o=>o.id!==n)})}function Jh(e,n){const o=[],r=new Set,a=[];for(const l of n){const u=Bf(e,l);if(!u){o.push(`unknown column: ${l}`);continue}r.has(u.id)||(r.add(u.id),a.push({id:u.id,name:u.name}))}if(r.size===0)return{tab:e,removed:[],errors:o};if(e.columns.length-r.size<1)throw new Error("cannot delete all columns; at least one column required");const i=e.columns.filter(l=>!r.has(l.id)),s=e.rows.map(l=>{const u={...l.cells};for(const d of r)delete u[d];return{...l,cells:u}});return{tab:La({...e,columns:i,rows:s}),removed:a,errors:o}}function Bf(e,n){const o=n.trim();if(!o)return null;const r=e.columns.find(s=>s.id===o);if(r)return r;const a=e.columns.find(s=>s.name===o);if(a)return a;const i=o.toLowerCase();return e.columns.find(s=>s.name.toLowerCase()===i)??null}function Hf(e){return JSON.stringify({root:{children:[{children:[{detail:0,format:0,mode:"normal",text:e,type:"text",version:1}],direction:"ltr",format:"",indent:0,type:"heading",tag:"h1",version:1}],direction:"ltr",type:"root",version:1}})}function No(e,n){const o=e.trim(),r=n.trim();return r?o?`${o}/${r}`:r:o}function $a(e,n=new Set){for(const o of e)o.type==="document"?n.add(o.path):(o.descDocumentId&&n.add(vl(o.path)),$a(o.children,n));return n}function Hn(e,n){for(const o of e){if(o.type==="folder"&&o.path===n)return o.documentId;if(o.type==="folder"){const r=Hn(o.children,n);if(r)return r}}return null}function Po(e,n){const o=Ma[n];return o?e(o):n}function Vf(e){const{tree:n,currentDomainId:o,selectedCreateParentPath:r,t:a,onDocCreated:i,refreshTree:s}=e,[l,u]=x.useState(null),[d,h]=x.useState(null),[m,f]=x.useState(!1),p=x.useRef(null);x.useEffect(()=>{if(!l)return;const v=window.setTimeout(()=>{var S;return(S=p.current)==null?void 0:S.focus()},0);return()=>window.clearTimeout(v)},[l]);function g(v,S="md"){const D=v!==void 0;h(null),u({kind:"document",parentMode:D?"fixed":"selection",parentPath:D?v:"",draft:S==="html"?"untitled.html":S==="sheet"?"untitled.sheet":"untitled.md",fileType:S})}function w(v){const S=v!==void 0;h(null),u({kind:"folder",parentMode:S?"fixed":"selection",parentPath:S?v:"",draft:""})}async function b(v){if(v.preventDefault(),!l)return;f(!0),h(null);const S=$a(n),D=l.parentMode==="selection"?r:l.parentPath;try{if(l.kind==="document"){const N=l.fileType;if(N==="html"||N==="sheet"){const ne=N==="html"?".html":".sheet",B=$r(l.draft,ne);if(!B.ok){h(Po(a,B.message));return}const G=B.displayFile,ce=G.replace(/\.html$/i,"").replace(/\.sheet$/i,"").replace(/\.md$/i,"");let ue;try{ue=Ur(No(D,G))}catch(re){h(Je(a,re));return}if(S.has(ue)){h(a("pathExists"));return}const A=D?Hn(n,D)??void 0:void 0,ie=N==="sheet"?Lf(tn()):"",oe=await $o({fileName:G,displayName:ce,content:ie,domainId:o,parentId:A,fileType:N});await s(),i(oe),u(null);return}const L=$r(l.draft);if(!L.ok){h(Po(a,L.message));return}const E=L.displayFile,O=E.replace(/\.md$/i,"");let $;try{$=Ur(No(D,E))}catch(ne){h(Je(a,ne));return}if(S.has($)){h(a("pathExists"));return}const V=D?Hn(n,D)??void 0:void 0,J=await $o({fileName:E,displayName:O,content:Hf(O),domainId:o,parentId:V});await s(),i(J),u(null);return}const P=wl(l.draft);if(!P.ok){h(Po(a,P.message));return}const _=Lo(P.display);if(!_){h(a("invalidFolderName"));return}const T=No(D,_);if(S.has(T)){h(a("folderExists"));return}const I=D?Hn(n,D)??void 0:void 0;await El({name:_,parentId:I,domainId:o}),await s(),u(null)}catch(P){h(Je(a,P))}finally{f(!1)}}return{createModal:l,setCreateModal:u,createModalError:d,createModalBusy:m,createModalInputRef:p,openNewDocumentModal:g,openNewFolderModal:w,submitCreateModal:b}}const Ei="(max-width: 768px)";function Gf(){const[e,n]=x.useState(()=>typeof window<"u"?window.matchMedia(Ei).matches:!1);return x.useEffect(()=>{const o=window.matchMedia(Ei),r=()=>n(o.matches);return r(),o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const Wf=28,Ri=56,qf=.75;function Kf(e,n,o){const r=!!(o!=null&&o.open),a=x.useRef(n),i=x.useRef(o==null?void 0:o.onClose);a.current=n,i.current=o==null?void 0:o.onClose,x.useEffect(()=>{if(!e)return;let s=null,l=0,u=0;const d=f=>{const p=f.touches[0];if(!p)return;const g=f.target;if(!(g instanceof Element&&g.closest(".mdocs-agent-fab-wrap"))){if(r){if(!i.current)return;s="close"}else{if(p.clientX>Wf)return;s="open"}l=p.clientX,u=p.clientY}},h=f=>{var b;if(!s)return;const p=f.touches[0];if(!p)return;const g=p.clientX-l,w=Math.abs(p.clientY-u);if(w>Math.abs(g)*qf&&w>24){s=null;return}if(s==="open"&&g>=Ri){s=null,a.current();return}s==="close"&&g<=-Ri&&(s=null,(b=i.current)==null||b.call(i))},m=()=>{s=null};return window.addEventListener("touchstart",d,{passive:!0}),window.addEventListener("touchmove",h,{passive:!0}),window.addEventListener("touchend",m,{passive:!0}),window.addEventListener("touchcancel",m,{passive:!0}),()=>{window.removeEventListener("touchstart",d),window.removeEventListener("touchmove",h),window.removeEventListener("touchend",m),window.removeEventListener("touchcancel",m)}},[e,r])}function Yf({open:e,onClose:n,onResolve:o,onForceOverwrite:r,forceBusy:a}){const{t:i}=Ve();return e?c.jsx("div",{className:"mdocs-conflict-modal-root",role:"alertdialog","aria-modal":"true",children:c.jsxs("div",{className:"mdocs-conflict-modal-panel",children:[c.jsx("h2",{className:"mdocs-conflict-modal-title",children:i("conflictTitle")}),c.jsx("p",{className:"mdocs-conflict-modal-body",children:i("conflictBody")}),r?c.jsx("p",{className:"mdocs-conflict-modal-force-hint",children:i("conflictForceHint")}):null,c.jsxs("div",{className:"mdocs-conflict-modal-actions",children:[c.jsx("button",{type:"button",className:"primary",onClick:o,disabled:a,children:i("conflictResolve")}),r?c.jsx("button",{type:"button",className:"mdocs-conflict-force-btn",disabled:a,onClick:r,children:i(a?"conflictForceBusy":"conflictForce")}):null,c.jsx("button",{type:"button",className:"secondary",onClick:n,disabled:a,children:i("conflictClose")})]})]})}):null}function Oi({documentId:e,visitorId:n,visitorName:o,documentOwnerId:r,onClose:a}){const[i,s]=x.useState([]),[l,u]=x.useState(""),[d,h]=x.useState(null),[m,f]=x.useState(!0),[p,g]=x.useState(!1),[w,b]=x.useState(null),[v,S]=x.useState(null),[D,P]=x.useState(360),[_,T]=x.useState(80),I=x.useRef(!1),N=x.useRef(!1),L=300,E=80,O=x.useRef(null);function $(){const K=O.current;if(!K)return;K.style.height="auto";const Z=K.scrollHeight,we=Math.min(Math.max(Z,E),L);K.style.height=`${we}px`,T(we)}x.useEffect(()=>{setTimeout(()=>$(),0)},[d]);function V(K){return n?K.visitorId===n||r===n:!1}const{rootComments:J,repliesByParentId:ne,totalCount:B}=x.useMemo(()=>{const K=[],Z=new Map;let we=0;for(const se of i)se.isDeleted||(we++,se.parentId?(Z.has(se.parentId)||Z.set(se.parentId,[]),Z.get(se.parentId).push(se)):K.push(se));return{rootComments:K,repliesByParentId:Z,totalCount:we}},[i]),G=x.useRef(e);x.useEffect(()=>{G.current=e,u(""),h(null),S(null),ce()},[e]);async function ce(){const K=G.current;f(!0);try{const Z=await zl(e);if(G.current!==K)return;s(Z.comments)}catch(Z){if(G.current!==K)return;S("加载评论失败"),console.error("Failed to load comments:",Z)}finally{G.current===K&&f(!1)}}async function ue(){var K;if(!(!l.trim()||!n)){g(!0),S(null);try{await $l(e,{content:l,parentId:(d==null?void 0:d.commentId)||null,replyToVisitorId:d?((K=i.find(Z=>Z.commentId===d.commentId))==null?void 0:K.visitorId)??null:null,replyToVisitorName:(d==null?void 0:d.visitorName)||null}),u(""),h(null),setTimeout(()=>$(),0),await ce()}catch(Z){S(Z.message||"发表失败,请重试")}finally{g(!1)}}}async function A(K){S(null);try{await Ul(e,K),await ce()}catch(Z){S(Z.message||"删除失败,请重试")}finally{b(null)}}function ie(K){const Z=Date.now()-new Date(K).getTime(),we=Math.floor(Z/6e4),se=Math.floor(Z/36e5),tt=Math.floor(Z/864e5);return we<1?"刚刚":we<60?`${we}分钟前`:se<24?`${se}小时前`:`${tt}天前`}function oe(K){I.current=!0,K.preventDefault()}function re(K){N.current=!0,K.preventDefault(),document.body.style.userSelect="none",document.body.style.cursor="row-resize"}return x.useEffect(()=>{function K(we){if(I.current){const se=Math.max(280,Math.min(600,window.innerWidth-we.clientX));P(se)}if(N.current){const se=-we.movementY;T(tt=>Math.max(60,Math.min(600,tt+se)))}}function Z(){I.current=!1,N.current=!1,document.body.style.userSelect="",document.body.style.cursor=""}return window.addEventListener("mousemove",K),window.addEventListener("mouseup",Z),()=>{window.removeEventListener("mousemove",K),window.removeEventListener("mouseup",Z)}},[]),c.jsxs("div",{className:"mdocs-comments-panel",style:{width:D},children:[c.jsx("div",{className:"mdocs-comments-resize-handle",onMouseDown:oe}),c.jsxs("div",{className:"mdocs-comments-header",children:[c.jsxs("h3",{style:{margin:0,fontSize:"1rem",display:"flex",alignItems:"center",gap:6},children:[c.jsx(Qs,{size:18}),"评论 (",B,")"]}),c.jsx("button",{type:"button",onClick:a,className:"mdocs-comments-close-btn",children:c.jsx(zt,{size:18})})]}),v&&c.jsxs("div",{className:"mdocs-comments-error",children:[v,c.jsx("button",{type:"button",onClick:()=>S(null),children:c.jsx(zt,{size:14})})]}),c.jsx("div",{className:"mdocs-comments-list",children:m?c.jsx("div",{className:"mdocs-comments-empty",children:"加载中..."}):J.length===0?c.jsx("div",{className:"mdocs-comments-empty",children:"暂无评论,来发表第一条吧~"}):J.map(K=>c.jsxs("div",{className:"mdocs-comment-root",children:[c.jsxs("div",{className:"mdocs-comment-header",children:[c.jsx("span",{className:"mdocs-comment-avatar",children:K.visitorName.charAt(0).toUpperCase()}),c.jsx("span",{className:"mdocs-comment-author",children:K.visitorName}),c.jsx("span",{className:"mdocs-comment-time",children:ie(K.createdAt)}),V(K)&&c.jsx("button",{type:"button",className:"mdocs-comment-delete",onClick:()=>b(K.commentId),title:"删除",children:c.jsx(zt,{size:14})})]}),c.jsx("div",{className:"mdocs-comment-content",children:K.content}),n&&c.jsx("button",{type:"button",className:"mdocs-comment-reply-btn",onClick:()=>h({commentId:K.commentId,visitorName:K.visitorName}),children:"回复"}),(ne.get(K.commentId)??[]).length>0&&c.jsx("div",{className:"mdocs-comment-replies",children:(ne.get(K.commentId)??[]).map(Z=>c.jsxs("div",{className:"mdocs-comment-reply",children:[c.jsxs("div",{className:"mdocs-comment-header",children:[c.jsx("span",{className:"mdocs-comment-avatar mdocs-comment-avatar-small",children:Z.visitorName.charAt(0).toUpperCase()}),c.jsx("span",{className:"mdocs-comment-author",children:Z.visitorName}),Z.replyToVisitorName&&c.jsxs("span",{className:"mdocs-comment-reply-to",children:["回复 ",Z.replyToVisitorName]}),c.jsx("span",{className:"mdocs-comment-time",children:ie(Z.createdAt)}),V(Z)&&c.jsx("button",{type:"button",className:"mdocs-comment-delete",onClick:()=>b(Z.commentId),title:"删除",children:c.jsx(zt,{size:12})})]}),c.jsx("div",{className:"mdocs-comment-content",children:Z.content}),n&&c.jsx("button",{type:"button",className:"mdocs-comment-reply-btn",onClick:()=>h({commentId:K.commentId,visitorName:Z.visitorName}),children:"回复"})]},Z.commentId))})]},K.commentId))}),n?c.jsxs("div",{className:"mdocs-comments-input-wrapper",children:[c.jsx("div",{className:"mdocs-comments-input-drag-handle",onMouseDown:re}),d&&c.jsxs("div",{className:"mdocs-comment-reply-notice",children:[c.jsxs("span",{children:["回复 ",c.jsx("span",{className:"mdocs-comment-reply-to-name",children:d.visitorName})]}),c.jsxs("button",{type:"button",onClick:()=>h(null),children:[c.jsx(zt,{size:14})," 取消"]})]}),c.jsx("textarea",{ref:O,value:l,onChange:K=>{u(K.target.value.slice(0,512)),setTimeout(()=>$(),0)},placeholder:d?`回复 ${d.visitorName}...`:"发表评论...",className:"mdocs-comments-input",style:{height:_},maxLength:512,onKeyDown:K=>{K.key==="Enter"&&(K.metaKey||K.ctrlKey)&&ue()}}),c.jsxs("div",{className:`mdocs-comments-char-count${l.length>=460?" mdocs-char-count--warn":""}`,children:[l.length,"/512"]}),c.jsx("div",{className:"mdocs-comments-input-actions",children:c.jsx("button",{type:"button",className:"mdocs-btn-primary",onClick:ue,disabled:p||!l.trim(),children:p?"发表中...":"发表"})})]}):c.jsx("div",{className:"mdocs-comments-input-wrapper",style:{textAlign:"center"},children:c.jsx("div",{style:{color:"#666",fontSize:"0.9rem"},children:"请先创建访客身份以发表评论"})}),w&&c.jsx(Aa,{title:"删除评论",message:"确定要删除这条评论吗?",confirmLabel:"删除",danger:!0,onConfirm:()=>A(w),onCancel:()=>b(null)})]})}const Jf="mdocs-drafts",Xf=5,Ae="drafts";let Ua=0;const Qo=new Set;function Xh(e){return Qo.add(e),()=>{Qo.delete(e)}}function Zh(){return Ua}function Ba(e,n){Ua+=1;for(const o of Qo)o(e,n)}const nn={DOC_NOT_FOUND:"DOC_NOT_FOUND",SYNC_HEAD_MISSING:"SYNC_HEAD_MISSING"};let To=null;function on(){return To||(To=new Promise((e,n)=>{const o=indexedDB.open(Jf,Xf);o.onupgradeneeded=r=>{const a=o.result;a.objectStoreNames.contains(Ae)||a.createObjectStore(Ae,{keyPath:"documentId"});const i=r.oldVersion;if(i>0&&i<4){const u=o.transaction.objectStore(Ae).openCursor();u.onsuccess=()=>{const d=u.result;if(!d)return;const h=d.value;typeof h.baseCommitId=="string"&&!h.localBaseCommitId&&(h.localBaseCommitId=h.baseCommitId,delete h.baseCommitId);const m=h.conflict;m&&(typeof m.baseCommitId=="string"&&!m.localBaseCommitId&&(m.localBaseCommitId=m.baseCommitId,delete m.baseCommitId),typeof m.expectedHeadCommitId=="string"&&!m.remoteCommitId&&(m.remoteCommitId=m.expectedHeadCommitId,delete m.expectedHeadCommitId)),d.update(h),d.continue()}}if(i>0&&i<5){const u=o.transaction.objectStore(Ae).openCursor();u.onsuccess=()=>{const d=u.result;if(!d)return;const h=d.value;h.contentKind==null&&(h.contentKind="lexical",d.update(h)),d.continue()}}},o.onsuccess=()=>e(o.result),o.onerror=()=>n(o.error)})),To}async function Zf(e){var r;const n=await Re(e.documentId),o={documentId:e.documentId,content:e.content,contentKind:e.contentKind??(n==null?void 0:n.contentKind)??"lexical",displayName:e.displayName,updatedAt:Date.now(),published:!1};if(n!=null&&n.localBaseCommitId)o.localBaseCommitId=n.localBaseCommitId;else{const a=(r=e.localBaseCommitIdAtEditStart)==null?void 0:r.trim();a&&(o.localBaseCommitId=a)}(n==null?void 0:n.permission)!=null?o.permission=n.permission:e.snapshotMeta&&(o.permission=e.snapshotMeta.permission),n!=null&&n.ownerVisitorId?o.ownerVisitorId=n.ownerVisitorId:e.snapshotMeta&&(o.ownerVisitorId=e.snapshotMeta.ownerVisitorId),n!=null&&n.domainId?o.domainId=n.domainId:e.snapshotMeta&&(o.domainId=e.snapshotMeta.domainId),n!=null&&n.publishError&&(o.publishError=n.publishError,o.publishErrorAt=n.publishErrorAt),n!=null&&n.conflictStatus&&(o.conflictStatus=n.conflictStatus),n!=null&&n.conflict&&(o.conflict=n.conflict),await $t(o)}function gr(e){const n={documentId:e.documentId,content:e.content,displayName:e.displayName,updatedAt:e.updatedAt,published:e.published};return e.permission!=null&&(n.permission=e.permission),e.ownerVisitorId&&(n.ownerVisitorId=e.ownerVisitorId),e.domainId&&(n.domainId=e.domainId),e.publishError!=null&&(n.publishError=e.publishError),e.publishErrorAt!=null&&(n.publishErrorAt=e.publishErrorAt),e.localBaseCommitId&&(n.localBaseCommitId=e.localBaseCommitId),e.conflictStatus!=null&&(n.conflictStatus=e.conflictStatus),e.conflict!=null&&(n.conflict=e.conflict),n}async function $t(e){const n=await on(),o=gr(e);return new Promise((r,a)=>{const i=n.transaction(Ae,"readwrite");i.objectStore(Ae).put(o),i.oncomplete=()=>{Ba(o.documentId,!o.published),r()},i.onerror=()=>a(i.error)})}async function Re(e){const n=await on();return new Promise((o,r)=>{const i=n.transaction(Ae,"readonly").objectStore(Ae).get(e);i.onsuccess=()=>o(i.result),i.onerror=()=>r(i.error)})}async function Ao(e){const n=await on();return new Promise((o,r)=>{const a=n.transaction(Ae,"readwrite");a.objectStore(Ae).delete(e),a.oncomplete=()=>{Ba(e,!1),o()},a.onerror=()=>r(a.error)})}async function Qf(e){const n=await on();return new Promise((o,r)=>{const i=n.transaction(Ae,"readonly").objectStore(Ae).getAll();i.onsuccess=()=>{let s=i.result;e!=null&&e.skipFailed&&(s=s.filter(l=>!l.publishError)),o(s)},i.onerror=()=>r(i.error)})}async function em(e,n){const o=await on();return new Promise((r,a)=>{const s=o.transaction(Ae,"readwrite").objectStore(Ae),l=s.get(e);l.onsuccess=()=>{const u=l.result;u&&s.put(gr({...u,publishError:n,publishErrorAt:Date.now()})),r()},l.onerror=()=>a(l.error)})}async function Mo(e){const n=await on();return new Promise((o,r)=>{const i=n.transaction(Ae,"readwrite").objectStore(Ae),s=i.get(e);s.onsuccess=()=>{const l=s.result;l&&i.put(gr({...l,publishError:void 0,publishErrorAt:void 0})),o()},s.onerror=()=>r(s.error)})}async function jo(e,n){const o=await Re(e);o&&await $t({...o,localBaseCommitId:n.localBaseCommitId,conflictStatus:n.conflictStatus,conflict:n.conflict})}async function Eo(e){const n=await Re(e);n&&await $t({...n,conflict:void 0,conflictStatus:"none"})}class Cn extends Error{constructor(o,r){super(o);Jt(this,"code");Jt(this,"cause");this.name="DraftPublishAborted",this.code=o,this.cause=r==null?void 0:r.cause}}function tm(e){return e instanceof Cn?e.code:e instanceof et?e.status===404?nn.DOC_NOT_FOUND:e.code||`HTTP_${e.status}`:e instanceof Error&&e.message.trim()?e.message.trim().slice(0,120):"UNKNOWN"}function nm(e,n,o,r){const a=(n==null?void 0:n.displayName)||e("unknownTitle");if(o===nn.SYNC_HEAD_MISSING)return e("draftPublishFailedSyncHead",{name:a});if(o===nn.DOC_NOT_FOUND)return e("draftPublishFailedNotice",{name:a});const i=r instanceof et||r instanceof Error&&r.message?r.message:o;return e("draftPublishFailedGeneric",{name:a,reason:i})}async function om(e,n,o){const r=tm(n);throw await em(e,r),n instanceof Cn?n:new Cn(r,{cause:n})}function rm(e,n){const o=x.useRef(n);o.current=n,x.useEffect(()=>{if(!e)return;const r=3e4,a=1e4,i=async()=>{const l=await Qf({skipFailed:!0}),u=Date.now();for(const d of l)if(!d.published&&!(u-d.updatedAt<r))try{await o.current(d.documentId)}catch(h){console.log("[autoPublish] scan publish failed:",h)}};i();const s=setInterval(i,a);return()=>clearInterval(s)},[e])}const im=1e4;function am(e,n){const[o,r]=x.useState(null),[a,i]=x.useState("up_to_date");return x.useEffect(()=>{if(!e){r(null),i("up_to_date");return}let l=!1;const u=e;async function d(){try{const m=await Al(u,n??void 0);if(l)return;r(m.headCommitId),i(m.status)}catch{}}d();const h=window.setInterval(()=>void d(),im);return()=>{l=!0,window.clearInterval(h)}},[e,n]),{remoteCommitId:o,syncStatus:a,syncBehind:!!(n&&o&&n!==o)||a==="behind"}}function Fi(e){return e.trim()}function sm(e){return e.trim()}const lm=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".ico",".bmp",".jfif",".pjpeg"]);function cm(e){const n=e.split("/").pop()??"",o=n.lastIndexOf(".");return o<=0?"":n.slice(o).toLowerCase()}function dm(e,n,o){let r,a;try{r=new URL(o),a=new URL(e,o)}catch{return null}if(a.origin!==r.origin||!a.pathname.startsWith("/api/assets/")||lm.has(cm(a.pathname)))return null;const i=n==null?void 0:n.trim();return i&&!a.searchParams.has("name")&&a.searchParams.set("name",i),a.toString()}function um(){const e=n=>{if(n.button!==0)return;const r=n.composedPath().find(i=>i instanceof HTMLAnchorElement);if(!r)return;const a=dm(r.href,r.getAttribute("download"),window.location.href);a&&(n.preventDefault(),n.stopPropagation(),window.location.assign(a))};return document.addEventListener("click",e,!0),()=>document.removeEventListener("click",e,!0)}const Le={DOCUMENT:"md",HTML:"html",SHEET:"sheet",FOLDER:"dir",FOLDER_DESC:"folder_desc",GRAPH_FILE:"graph_file",GRAPH_DIR:"graph_dir"},fm="/assets/mdocs-logo-Dsv_2t6v.svg",mm=x.lazy(()=>Pt(()=>import("./DocumentEditor-BcktjJUV.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])).then(e=>({default:e.DocumentEditor}))),hm=x.lazy(()=>Pt(()=>import("./HtmlEditor-D-H5FPUP.js"),__vite__mapDeps([16,1,12,13,14,15,2,3,6,17])).then(e=>({default:e.HtmlEditor}))),pm=x.lazy(()=>Pt(()=>import("./SheetEditor-BV3loL4j.js"),__vite__mapDeps([18,1,12,13,14,7,11,2,3,6,19])).then(e=>({default:e.SheetEditor}))),gm=x.lazy(()=>Pt(()=>import("./SettingsPage-xJkP4WaU.js"),__vite__mapDeps([20,1,14,9,2,3,6])).then(e=>({default:e.SettingsPage}))),ym=x.lazy(()=>Pt(()=>import("./AgentChatPanel-BJ49TwV5.js"),__vite__mapDeps([21,1,9,8,7,2,3,6])).then(e=>({default:e.AgentChatPanel}))),vm=x.lazy(()=>Pt(()=>import("./AiWriteWorkbench-B7MnIKzJ.js"),__vite__mapDeps([22,1,21,9,8,7,2,3,6])).then(e=>({default:e.AiWriteWorkbench}))),bm=x.lazy(()=>Pt(()=>import("./MergeView-a2_gRrrh.js"),__vite__mapDeps([23,1,4,5,2,3,6,7,8,9,13])).then(e=>({default:e.MergeView})));function xm(e,n){try{const o=new Intl.RelativeTimeFormat(n,{numeric:"auto"}),r=Date.now()-new Date(e).getTime(),a=Math.floor(r/6e4),i=Math.floor(a/60),s=Math.floor(i/24);return s>30?o.format(-Math.floor(s/30),"month"):s>0?o.format(-s,"day"):i>0?o.format(-i,"hour"):a>0?o.format(-a,"minute"):o.format(-Math.floor(r/1e3),"second")}catch{return e.slice(0,10)}}async function Ro(e,n,o,r){const a=await nr();n(a);const i=localStorage.getItem("mdocs.currentDomainId"),l=i&&a.some(u=>u.domainId===i)?i:Wl(a,e);o(l),await r(l)}function Li(){const{t:e,lang:n,setLang:o}=Ve(),[r,a]=x.useState("loading"),[i,s]=x.useState(()=>localStorage.getItem("mdocs.sidebarCollapsed")==="true"),l=Gf(),[u,d]=x.useState(!1),h=()=>{if(l){d(R=>!R);return}const y=!i;s(y),localStorage.setItem("mdocs.sidebarCollapsed",String(y))};x.useEffect(()=>{l||d(!1)},[l]),x.useEffect(()=>um(),[]);const[m,f]=x.useState(!1),[p,g]=x.useState(0),w=x.useRef(null),[b,v]=x.useState(null),[S,D]=x.useState(null),[P,_]=x.useState(null),[T,I]=x.useState([]),[N,L]=x.useState([]),[E,O]=x.useState("default"),[$,V]=x.useState(!1),J=x.useRef(null),{documentId:ne}=ss(),B=ls(),[G,ce]=x.useState(null),ue=(G==null?void 0:G.kind)==="document"?G.documentId:null,[A,ie]=x.useState(null),[oe,re]=x.useState(null),K=x.useRef(oe);K.current=oe;const[Z,we]=x.useState(0),[se,tt]=x.useState(null),[Tt,vt]=x.useState(!1),[rn,Vt]=x.useState(!1),[At,nt]=x.useState(!1),[_e,Ge]=x.useState(!1),Pn=(A==null?void 0:A.documentId)??null,{syncBehind:We,remoteCommitId:Mt}=am(Pn,se),[$e,Gt]=x.useState(null);x.useEffect(()=>{if(!At||!A){Gt(null);return}(async()=>{const y=await Re(A.documentId);if(y!=null&&y.conflict){Gt(y.conflict);return}if(y&&se&&Mt){const R=y.localBaseCommitId??se;if(!R)return;const M={localBaseCommitId:R,remoteCommitId:Mt,localSnapshotContent:y.content};await jo(A.documentId,{localBaseCommitId:M.localBaseCommitId,conflictStatus:"diverged",conflict:M}),Gt(M)}})()},[At,A,se,Mt]),x.useEffect(()=>{!A||!We||!_e||Re(A.documentId).then(async y=>{!y||y.conflict||y.conflictStatus==="publish_conflict"||y.conflictStatus!=="diverged"&&await $t({...y,conflictStatus:"diverged"})})},[A==null?void 0:A.documentId,We,_e]),x.useEffect(()=>{if(!A){tt(null);return}let y=!1;return Re(A.documentId).then(R=>{y||(R&&!R.published&&R.localBaseCommitId?tt(R.localBaseCommitId):tt(A.headCommitId??null))}),()=>{y=!0}},[A==null?void 0:A.documentId,A==null?void 0:A.headCommitId,_e]);const[Ee,me]=x.useState(null),[Ce,be]=x.useState(null),[xe,jt]=x.useState(null),[bt,ct]=x.useState(null),[an,Me]=x.useState(""),[sn,ot]=x.useState("docs");Kf(l&&sn==="docs",()=>d(!0),{open:u,onClose:()=>d(!1)});const[Fe,qe]=x.useState(!1),[Tn,xt]=x.useState(!1),[Wt,An]=Df(),k=x.useRef(null),[j,z]=x.useState(!1),[F,q]=x.useState(null),X=x.useRef(void 0),te=x.useRef(void 0);rm(localStorage.getItem("mdocs.autoPublish")==="true",Sr);async function Q(y){var R;await((R=X.current)==null?void 0:R.call(X)),y()}function ye(y){const M=(y.trim()||"untitled").replace(/[\\/:*?"<>|]/g,"-").slice(0,80);return M.endsWith(".md")?M:`${M}.md`}async function De(){var M,W;if(!A||!oe||A.fileType===Le.SHEET)return;await((M=X.current)==null?void 0:M.call(X));const y=A.fileType===Le.HTML;let R="";if(y)R=Fi(oe.content);else if(R=((W=te.current)==null?void 0:W.call(te))??"",!R.trim())try{R=(await vo({content:oe.content,from:"lexical",to:"markdown"})).content}catch{R=""}q({markdown:R,documentId:A.documentId,displayName:oe.displayName||A.displayName||"未命名",fileType:y?Le.HTML:Le.DOCUMENT}),z(!0),qe(!1)}function je(){q({markdown:"",documentId:null,displayName:"未命名",fileType:Le.DOCUMENT}),z(!0),qe(!1)}async function Ne(y){var le,Ie;const R=y.documentId.trim();if(!R)return;await((le=X.current)==null?void 0:le.call(X));let M="",W=y.displayName.trim()||"未命名",ee=Le.DOCUMENT;try{const Ft=await Xt(R);if(W=((Ie=Ft.displayName)==null?void 0:Ie.trim())||W,Ft.fileType===Le.SHEET)return;if(ee=Ft.fileType===Le.HTML?Le.HTML:Le.DOCUMENT,ee===Le.HTML)M=Fi(Ft.content);else try{M=(await vo({content:Ft.content,from:"lexical",to:"markdown"})).content}catch{M=""}}catch{}q({markdown:M,documentId:R,displayName:W,fileType:ee}),z(!0),qe(!1),ot("docs"),Q(()=>B(`/doc/${R}`))}async function ke(y){(A==null?void 0:A.documentId)===y.documentId&&await En()}async function Pe(y){const M=(y.documentId&&(F==null?void 0:F.documentId)===y.documentId?F.fileType:(A==null?void 0:A.documentId)===y.documentId?A.fileType:Le.DOCUMENT)===Le.HTML;if(y.documentId){const ee=(A==null?void 0:A.documentId)===y.documentId?A:null;let le;return M?le=sm(y.markdown):le=(await vo({content:y.markdown,from:"markdown",to:"lexical"})).content,await Zf({documentId:y.documentId,content:le,displayName:y.displayName,localBaseCommitIdAtEditStart:(ee==null?void 0:ee.headCommitId)??null,contentKind:M?"html":"lexical",snapshotMeta:ee?{permission:ee.permission,ownerVisitorId:ee.ownerVisitorId,domainId:ee.domainId}:void 0}),(A==null?void 0:A.documentId)===y.documentId?(re({documentId:y.documentId,content:le,displayName:y.displayName}),we(Ie=>Ie+1),Ge(!0)):await cn(y.documentId),me("帮写已写入草稿,可在编辑器中继续修改后发布"),{documentId:y.documentId}}const W=await $o({fileName:ye(y.displayName),displayName:y.displayName,content:y.markdown,contentFormat:"markdown",domainId:E||void 0,parentId:void 0});return await fe(),await cn(W.documentId),me("已创建文档"),{documentId:W.documentId}}x.useEffect(()=>{wt()},[]),x.useEffect(()=>{if(!Ee)return;const y=()=>{me(null)};return window.addEventListener("pointerdown",y,!0),()=>window.removeEventListener("pointerdown",y,!0)},[Ee]),x.useEffect(()=>{const y=R=>{var ee,le,Ie;const M=R;if(((ee=M.detail)==null?void 0:ee.status)===409||((le=M.detail)==null?void 0:le.code)==="AI_NOT_CONFIGURED")return;const W=(Ie=M.detail)==null?void 0:Ie.message;W&&be(W)};return window.addEventListener(zo,y),()=>window.removeEventListener(zo,y)},[]);async function wt(){try{const y=await Wr();v(y),Vn(y.visitorId),await Ro(y.visitorId,L,O,fe),a("ready")}catch(y){if(y instanceof et&&y.status===401){a("needsRegister");return}be(Je(e,y)),a("needsRegister")}}async function _t(y,R){const M=await Cl(y,R);v(M.visitor),D(M.visitor.visitorId),_(M.recoveryCode),Vn(M.visitor.visitorId),await Ro(M.visitor.visitorId,L,O,fe),a("ready")}async function dt(y){const R=await Wr();v(R),await Ro(R.visitorId,L,O,fe),a("ready")}async function fe(y){const M=await Tl(y??E);I(M)}function Ke(y){re({documentId:y.documentId,content:y.content,displayName:y.displayName}),we(R=>R+1),Ge(!1)}function Et(y,R){re({documentId:y,content:R.content,displayName:R.displayName}),we(M=>M+1),Ge(!0)}async function ln(y,R){await Ao(y);const M=await Xt(y);if((A==null?void 0:A.documentId)===y&&w.current===y){ie(fn(M)),Ge(!1);const W=K.current,ee=R!==void 0&&M.content===R,le=(W==null?void 0:W.documentId)===y&&W.content===M.content;ee||le?(W==null?void 0:W.documentId)===y&&W.displayName!==M.displayName&&re({...W,displayName:M.displayName}):Ke(M)}return M}function Rt(y,R,M="folder"){console.log("[openGraph]",M,y,R),ie(null),re(null),ce({kind:"graph",scope:M,resourceId:y,name:R})}function qt(){ce(null)}x.useEffect(()=>{function y(R){J.current&&!J.current.contains(R.target)&&V(!1)}if($)return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[$]);async function cn(y){w.current=y,ot("docs"),ce({kind:"document",documentId:y});try{const R=await Re(y);if(w.current!==y)return;const M=await Xt(y);if(w.current!==y||(M.domainId!==E&&(localStorage.setItem("mdocs.currentDomainId",M.domainId),O(M.domainId),fe(M.domainId)),Me($n(M.relativePath)),M.headCommitId&&R&&!R.published&&(R.publishError===nn.SYNC_HEAD_MISSING&&await Mo(y),R.localBaseCommitId||await $t({...R,localBaseCommitId:M.headCommitId})),ie(fn(M)),w.current!==y))return;R&&!R.published?Et(y,R):Ke(M)}catch(R){if(w.current!==y)return;be(Je(e,R))}}x.useEffect(()=>{r==="ready"&&(ne?cn(ne):(ce(null),ie(null),re(null),tt(null)))},[r,ne]);const{createModal:Kt,setCreateModal:ao,createModalError:yr,createModalBusy:Yt,createModalInputRef:Va,openNewDocumentModal:dn,openNewFolderModal:vr,submitCreateModal:Ga}=Vf({tree:T,currentDomainId:E,selectedCreateParentPath:an,t:e,onDocCreated:y=>{ie(fn(y)),Ke(y),Me($n(y.relativePath)),B(`/doc/${y.documentId}`)},refreshTree:fe}),[Wa,Mn]=x.useState(!1),[qa,so]=x.useState(!1);x.useEffect(()=>{const y=R=>{!(R.metaKey||R.ctrlKey)||R.key.toLowerCase()!=="k"||(R.preventDefault(),so(!0))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[]);const[Ka,un]=x.useState(!1),[Ot,br]=x.useState([]),[lo,xr]=x.useState(""),[jn,wr]=x.useState(""),[Ya,_r]=x.useState(new Set);async function Ja(){try{const y=await Fl();br(y)}catch(y){be(Je(e,y))}}const co=x.useMemo(()=>{const y={};for(const R of N)y[R.domainId]=R.domainName;return y},[N]),Ir=x.useMemo(()=>{let y=Ot;const R=lo.trim().toLowerCase();return R&&(y=y.filter(M=>{var W;return(W=M.displayName)==null?void 0:W.toLowerCase().includes(R)})),jn&&(y=y.filter(M=>M.domainId===jn)),y},[Ot,lo,jn]),Xa=x.useMemo(()=>{const y=new Set,R=[];for(const M of Ot){const W=M.domainId;W&&!y.has(W)&&(y.add(W),R.push({id:W,name:co[W]??W}))}return R},[Ot,co]);async function Za(y,R,M,W,ee){let le=await Re(y);!le&&(A==null?void 0:A.documentId)===y&&(le={documentId:y,content:R,displayName:M,updatedAt:Date.now(),published:!1,localBaseCommitId:W,permission:A.permission,ownerVisitorId:A.ownerVisitorId,domainId:A.domainId},await $t(le)),le&&await jo(y,{localBaseCommitId:W,conflictStatus:"publish_conflict",conflict:{localBaseCommitId:W,remoteCommitId:ee.headCommitId,localSnapshotContent:R}}),vt(!0)}async function Qa(){if(!A||rn||(b==null?void 0:b.visitorId)!==A.ownerVisitorId||!window.confirm(e("conflictForceConfirm")))return;const R=A.documentId;Vt(!0);try{await po(R).execute(async()=>{var fo,Dr,Nr,Pr,Tr;const M=await Re(R),W=((fo=M==null?void 0:M.conflict)==null?void 0:fo.localBaseCommitId)??(M==null?void 0:M.localBaseCommitId)??se??A.headCommitId,ee=((Dr=M==null?void 0:M.conflict)==null?void 0:Dr.remoteCommitId)??($e==null?void 0:$e.remoteCommitId),le=((Nr=M==null?void 0:M.conflict)==null?void 0:Nr.localSnapshotContent)??(M==null?void 0:M.content)??((Pr=K.current)==null?void 0:Pr.content),Ie=(M==null?void 0:M.displayName)??((Tr=K.current)==null?void 0:Tr.displayName)??A.displayName;if(!W||!ee||le==null)throw be(e("syncHeadMissing")),new Error("missing force overwrite payload");await yo(R,{content:le,displayName:Ie,version:{localBaseCommitId:W,merge:{remoteCommitId:ee,localSnapshotContent:le,forceLocal:!0}}});const Ft=await Xt(R);await kr(Ft)})}catch(M){M instanceof Error&&M.message==="missing force overwrite payload"||be(Je(e,M))}finally{Vt(!1)}}async function uo(y,R,M,W){return po(M).execute(async()=>{const ee=await Re(M),le=(ee==null?void 0:ee.localBaseCommitId)??(A==null?void 0:A.headCommitId);if(!le)throw be(e("syncHeadMissing")),new Error("missing localBaseCommitId");try{await yo(M,{content:y,displayName:R,permission:W,version:{localBaseCommitId:le}}),await Eo(M),await ln(M,y),await fe(),vt(!1),me(e("published")),window.setTimeout(()=>me(null),1200)}catch(Ie){throw Ie instanceof et&&Ie.status===409&&Ie.code==="VERSION_CONFLICT"&&Ie.details&&typeof Ie.details=="object"&&await Za(M,y,R,le,Ie.details),Ie}})}async function es(){if(!A)return;const y=await Xt(A.documentId);y.domainId!==E&&(localStorage.setItem("mdocs.currentDomainId",y.domainId),O(y.domainId),fe(y.domainId)),Me($n(y.relativePath)),ie(fn(y)),Ke(y),me(e("syncPullDone")),window.setTimeout(()=>me(null),1200)}async function En(){if(!A)return;const y=await Re(A.documentId),R=!!(y&&!y.published);if((y==null?void 0:y.conflictStatus)==="publish_conflict"||(y==null?void 0:y.conflictStatus)==="diverged"||!!(y!=null&&y.conflict)){nt(!0);return}if(R&&y){if(We&&Mt){const W=y.localBaseCommitId??se;if(W){const ee={localBaseCommitId:W,remoteCommitId:Mt,localSnapshotContent:y.content};await jo(A.documentId,{localBaseCommitId:W,conflictStatus:"diverged",conflict:ee}),Gt(ee)}nt(!0);return}me(e("pullBlockedDraft")),window.setTimeout(()=>me(null),3e3);return}await es()}async function kr(y){await Eo(y.documentId),await Ao(y.documentId),Ge(!1),nt(!1),vt(!1),await cn(y.documentId),fe(y.domainId),me(e("published")),window.setTimeout(()=>me(null),1200)}async function ts(y,R,M){try{await om(y,R,M)}catch(W){if(!(W instanceof Cn))throw W;const ee=M??await Re(y);throw me(nm(e,ee,W.code,W.cause??R)),window.setTimeout(()=>me(null),4e3),W}}async function Sr(y){let R;try{await po(y).execute(async()=>{const M=await Re(y);if(!M)return;R=M;let W=M.localBaseCommitId;if(W||(W=(await Xt(y)).headCommitId??void 0,W&&(await $t({...M,localBaseCommitId:W}),M.publishError===nn.SYNC_HEAD_MISSING&&await Mo(y))),!W)throw new Cn(nn.SYNC_HEAD_MISSING);const ee=await Re(y);ee&&(await yo(y,{content:ee.content,displayName:ee.displayName,version:{localBaseCommitId:W}}),await Eo(y),await Mo(y),(A==null?void 0:A.documentId)===y?await ln(y,ee.content):await Ao(y),await fe(),me(e("published")),window.setTimeout(()=>me(null),1200))})}catch(M){await ts(y,M,R)}}function Rn(y,R){jt({type:"document",id:y,name:R})}function Cr(y,R){jt({type:"folder",id:y,name:R})}async function ns(y,R){try{const M=await jl(y,R);await fe(M.domainId),(A==null?void 0:A.documentId)===y&&(ie(fn(M)),Me($n(M.relativePath)))}catch(M){M instanceof et?M.status===409&&be(M.message):be(Je(e,M))}}async function os(){if(xe)try{xe.type==="document"?(await Ml(xe.id),(A==null?void 0:A.documentId)===xe.id&&(ie(null),re(null),Me(""),B("/"))):xe.type==="folder"&&(await Rl(xe.id),A&&(ie(null),re(null),Me(""),B("/"))),await fe(),me(xe.type==="folder"?`已删除「${xe.name}」及其下所有内容`:`已删除「${xe.name}」`),window.setTimeout(()=>me(null),2e3)}catch(y){be(Je(e,y))}finally{jt(null)}}return r==="loading"?c.jsx("div",{className:"mdocs-loading muted",children:e("loading")}):r==="needsRegister"?c.jsx(ql,{onSubmit:_t,onRecover:dt,error:Ee}):c.jsxs("div",{className:"mdocs-app-root",children:[Gi(),c.jsx("div",{className:"mdocs-shell",children:sn==="settings"?c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"mdocs-main muted",style:{padding:24},children:"加载设置…"}),children:c.jsx(gm,{onBack:()=>ot("docs"),onPublishDraft:Sr,onOpenDocument:cn,onRecoverDraft:()=>void fe()})}):c.jsxs("div",{className:"mdocs-layout"+(l?" mdocs-layout--reader":""),children:[l&&u?c.jsx("button",{type:"button",className:"mdocs-mobile-nav-scrim","aria-label":e("collapseSidebar"),onClick:()=>d(!1)}):null,c.jsxs("aside",{className:"mdocs-sidebar"+(l?u?" mdocs-sidebar--drawer-open":" mdocs-sidebar--drawer":i?" mdocs-sidebar-collapsed":""),children:[c.jsxs("header",{className:"mdocs-sidebar-header",children:[c.jsxs("div",{className:"mdocs-brand",children:[c.jsx("img",{src:fm,alt:e("brand"),className:"mdocs-brand-logo"}),c.jsx("span",{children:e("brand")})]}),c.jsx("button",{type:"button",className:"mdocs-sidebar-toggle",onClick:h,"aria-label":e(l?u?"collapseSidebar":"expandSidebar":i?"expandSidebar":"collapseSidebar"),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:y=>{y.currentTarget.style.background="var(--mdocs-hover-bg, #f0f0f0)"},onMouseLeave:y=>{y.currentTarget.style.background="none"},children:l?c.jsx(Rr,{size:18}):i?c.jsx(Or,{size:18}):c.jsx(Rr,{size:18})})]}),c.jsxs("div",{className:"mdocs-sidebar-actions",ref:J,children:[c.jsxs("button",{type:"button",className:"mdocs-sidebar-create-btn",onClick:()=>V(y=>!y),children:[c.jsx(Er,{size:15,strokeWidth:1.75}),e("newArticle")]}),$&&c.jsxs("div",{className:"mdocs-create-dropdown",children:[c.jsxs("button",{type:"button",className:"mdocs-create-dropdown-item",onClick:()=>{V(!1),dn()},children:[c.jsx(Er,{size:14,strokeWidth:1.5}),"Markdown"]}),c.jsxs("button",{type:"button",className:"mdocs-create-dropdown-item",onClick:()=>{V(!1),dn(void 0,"html")},children:[c.jsx(Fs,{size:14,strokeWidth:1.5}),"HTML"]}),c.jsxs("button",{type:"button",className:"mdocs-create-dropdown-item",onClick:()=>{V(!1),dn(void 0,"sheet")},children:[c.jsx(cl,{size:14,strokeWidth:1.5}),e("sheetDocument")]})]}),c.jsxs("button",{type:"button",className:"mdocs-sidebar-create-btn",onClick:()=>{V(!1),vr()},children:[c.jsx(Ws,{size:15,strokeWidth:1.75}),e("newDirectory")]}),c.jsx("span",{className:"mdocs-sidebar-icon mdocs-tooltip","data-tooltip":e("docSearch"),onClick:()=>so(!0),children:c.jsx(Ui,{size:18,strokeWidth:1.75})}),c.jsx("span",{className:"mdocs-sidebar-icon mdocs-tooltip","data-tooltip":"知识图谱",onClick:()=>Rt(E,"知识图谱","domain"),children:c.jsx(er,{size:18,strokeWidth:1.75})})]}),c.jsx(Yl,{nodes:T,activeDocumentId:ue,graphFocusAnchorId:(G==null?void 0:G.kind)==="graph"?G.resourceId:null,selectedParentPath:an,onOpen:y=>{l&&d(!1),Q(()=>B(`/doc/${y.documentId}`))},onOpenFolder:(y,R)=>{Q(()=>{Me(y),R&&(qt(),l&&d(!1),B(`/doc/${R}`))})},onContextMenu:ct,onMoveDocument:ns,onDeselect:()=>{qt(),Q(()=>{Me(""),B("/")})},onOpenGraph:(y,R)=>{if(y.type==="folder")Rt(y.documentId,y.name);else if(R){const M=T.find(W=>W.documentId===R);Rt(R,(M==null?void 0:M.name)??"图谱")}},onGenerateGraph:async(y,R)=>{var ee;const M=y.type==="folder"?y.documentId:R;if(!M)return;const W=y.type==="folder"?y.name:((ee=T.find(le=>le.documentId===R))==null?void 0:ee.name)??"图谱";Rt(M,W)}}),c.jsxs("footer",{className:"mdocs-sidebar-footer",children:[c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,cursor:"pointer"},onClick:()=>Q(()=>ot("settings")),children:[c.jsx("span",{className:"mdocs-visitor-avatar",children:b?b.visitorName.charAt(0).toUpperCase():"?"}),c.jsx("span",{className:"mdocs-visitor-footer-name",children:b?b.visitorName:""})]}),c.jsx("button",{type:"button",className:"mdocs-sidebar-bookmark mdocs-tooltip","data-tooltip":e("bookmark"),onClick:()=>{un(!0),xr(""),wr(""),Ja()},style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4},children:c.jsx(sl,{size:16,strokeWidth:1.5})}),c.jsx("button",{type:"button",className:"mdocs-sidebar-logout mdocs-tooltip","data-tooltip":e("logout"),onClick:()=>Mn(!0),style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",lineHeight:1,borderRadius:4},children:c.jsx(Xs,{size:16,strokeWidth:1.5})})]})]}),c.jsxs("main",{className:"mdocs-main",children:[(G==null?void 0:G.kind)==="graph"?c.jsx(bf,{scope:G.scope,resourceId:G.resourceId,name:G.name,onClose:qt,onOpenDocument:y=>{Q(()=>B(`/doc/${y}`))}},`${G.scope}-${G.resourceId}`):A&&oe&&oe.documentId===A.documentId?A.fileType==="html"||A.fileType==="sheet"?c.jsxs("div",{className:"mdocs-editor-with-comments",children:[c.jsx("div",{className:"mdocs-editor-container",children:c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"muted",style:{padding:24},children:"加载编辑器…"}),children:A.fileType==="sheet"?c.jsx(pm,{meta:A,initialContent:oe.content,initialDisplayName:oe.displayName,contentRevision:Z,canEdit:!!(b&&(A.ownerVisitorId===b.visitorId||go(A.permission)||A.invitedEdit===!0)),domains:N,currentDomainId:E,onDomainChange:y=>{Q(()=>{localStorage.setItem("mdocs.currentDomainId",y),O(y),ie(null),re(null),Me(""),B("/"),fe(y)})},onDomainsChange:L,onContentChange:y=>{re(R=>R&&{...R,content:y})},onDraftExistsChange:Ge,hasLocalDraft:_e,onPublish:uo,syncBehind:We,onSyncClick:()=>void En(),onDelete:async()=>{Rn(A.documentId,A.relativePath)},canManageInvites:!!(b&&b.visitorId===A.ownerVisitorId),onToggleComments:()=>f(!m),commentPanelOpen:m,commentCount:p,onShowToast:me,readerChrome:l,onOpenMobileNav:()=>d(!0)},A.documentId):c.jsx(hm,{meta:A,initialContent:oe.content,initialDisplayName:oe.displayName,contentRevision:Z,canEdit:!!(b&&(A.ownerVisitorId===b.visitorId||go(A.permission)||A.invitedEdit===!0)),domains:N,currentDomainId:E,onDomainChange:y=>{Q(()=>{localStorage.setItem("mdocs.currentDomainId",y),O(y),ie(null),re(null),Me(""),B("/"),fe(y)})},onDomainsChange:L,onContentChange:y=>{re(R=>R&&{...R,content:y})},onDraftExistsChange:Ge,hasLocalDraft:_e,onPublish:uo,syncBehind:We,onSyncClick:()=>void En(),canManageInvites:!!(b&&b.visitorId===A.ownerVisitorId),onDelete:async()=>{Rn(A.documentId,A.relativePath)},onToggleComments:()=>f(!m),commentPanelOpen:m,commentCount:p,onAiWrite:l?void 0:()=>void De(),onShowToast:me,readerChrome:l,onOpenMobileNav:()=>d(!0)},A.documentId)})}),m&&c.jsx(Oi,{documentId:A.documentId,visitorId:b==null?void 0:b.visitorId,visitorName:b==null?void 0:b.visitorName,documentOwnerId:A.ownerVisitorId,onClose:()=>f(!1)})]}):c.jsxs("div",{className:"mdocs-editor-with-comments",children:[c.jsx("div",{className:"mdocs-editor-container",children:c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"muted",style:{padding:24},children:"加载编辑器…"}),children:c.jsx(mm,{meta:A,initialContent:oe.content,initialDisplayName:oe.displayName,contentRevision:Z,canEdit:!!(b&&(A.ownerVisitorId===b.visitorId||go(A.permission)||A.invitedEdit===!0)),domains:N,currentDomainId:E,onDomainChange:y=>{Q(()=>{localStorage.setItem("mdocs.currentDomainId",y),O(y),ie(null),re(null),Me(""),B("/"),fe(y)})},onDomainsChange:L,onPublish:uo,syncBehind:We,onSyncClick:()=>void En(),onDraftExistsChange:Ge,hasLocalDraft:_e,onConflictModalRequest:()=>vt(!0),onMergeRequest:()=>nt(!0),canManageInvites:!!(b&&b.visitorId===A.ownerVisitorId),onDelete:async()=>{if(A.relativePath.endsWith("/___desc___.md")){const y=A.relativePath.replace(/\/___desc___\.md$/,"");Cr(A.documentId,y)}else Rn(A.documentId,A.relativePath)},saveBeforeNavRef:X,exportMarkdownRef:te,onShowToast:me,onShowError:be,onToggleComments:()=>f(!m),commentPanelOpen:m,commentCount:p,onAiWrite:l?void 0:()=>void De(),readerChrome:l,onOpenMobileNav:()=>d(!0)},A.documentId)})}),m&&c.jsx(Oi,{documentId:A.documentId,visitorId:b==null?void 0:b.visitorId,visitorName:b==null?void 0:b.visitorName,documentOwnerId:A.ownerVisitorId,onClose:()=>f(!1)})]}):c.jsxs("div",{className:"mdocs-welcome",children:[l?c.jsxs("button",{type:"button",className:"mdocs-reader-float-pill",onClick:()=>d(!0),"aria-label":e("expandSidebar"),children:[c.jsx(Or,{size:18,strokeWidth:1.75}),c.jsx("span",{children:e("brand")})]}):null,c.jsx("div",{className:"mdocs-welcome-icon",children:c.jsx(Rs,{size:64,strokeWidth:1,opacity:.15})}),c.jsx("h1",{children:e("brand")}),c.jsx("p",{className:"mdocs-welcome-lead",children:e("createDocToStart")}),c.jsxs("div",{className:"mdocs-welcome-actions",children:[c.jsxs("button",{type:"button",className:"primary",onClick:()=>dn(),style:{display:"flex",alignItems:"center",gap:6},children:[c.jsx(Vs,{size:16,strokeWidth:1.5}),e("startWriting")]}),l?null:c.jsxs("button",{type:"button",className:"secondary",onClick:()=>je(),style:{display:"flex",alignItems:"center",gap:6},children:[c.jsx("img",{src:Ta,alt:"",width:16,height:16,style:{display:"block"}}),"AI 帮写"]})]}),c.jsxs("div",{className:"mdocs-welcome-domain",children:[c.jsx("label",{className:"muted mdocs-welcome-domain-label",children:e("domainLabel")}),c.jsx(wf,{domains:N.length?N:[{domainId:"default",domainName:e("defaultDomain"),permission:"",creatorVisitorId:"",docCount:0}],value:E,onChange:y=>{Q(()=>{localStorage.setItem("mdocs.currentDomainId",y),O(y),ie(null),re(null),Me(""),B("/"),fe(y)})},onDomainsChange:L,ariaLabel:e("domainLabel"),localizeName:y=>kn(y,n,e)})]})]}),c.jsx(Yf,{open:Tt,onClose:()=>vt(!1),onResolve:()=>{vt(!1),nt(!0)},onForceOverwrite:b&&A&&b.visitorId===A.ownerVisitorId?()=>void Qa():void 0,forceBusy:rn}),At&&A&&$e&&c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"merge-view-loading",children:e("mergeLoadingRemote")}),children:c.jsx(bm,{documentId:A.documentId,displayName:A.displayName,conflict:$e,fileType:A.fileType,onClose:()=>nt(!1),onSuccess:kr,onError:y=>be(y)})}),Ee&&c.jsx("div",{className:"mdocs-toast",role:"status",children:Ee}),Ce&&c.jsx(Nf,{title:e("error"),message:Ce,onClose:()=>be(null)})]}),Wa&&c.jsx("div",{className:"mdocs-dialog-backdrop",onClick:y=>{y.target===y.currentTarget&&Mn(!1)},children:c.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:440},children:[c.jsx("h1",{style:{fontSize:"1.125rem",marginBottom:8},children:"退出当前登录身份?"}),c.jsx("p",{style:{lineHeight:1.6,color:"var(--mdocs-text-secondary, #666)",marginBottom:20},children:"这将会导致您无法修改以前的文章。如果想找回账号,需要恢复码或联系管理员执行合并用户脚本。"}),c.jsxs("div",{className:"mdocs-dialog-actions",style:{justifyContent:"flex-end"},children:[c.jsx("button",{type:"button",onClick:()=>Mn(!1),children:"取消"}),c.jsx("button",{type:"button",className:"primary",style:{background:"#d32f2f"},onClick:()=>{Sl(),ie(null),re(null),v(null),I([]),Mn(!1),a("needsRegister")},children:"确认退出"})]})]})}),Ka&&c.jsx("div",{className:"mdocs-dialog-backdrop",onClick:y=>{y.target===y.currentTarget&&un(!1)},children:c.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:640,width:"min(640px, 100%)",maxHeight:"70vh",display:"flex",flexDirection:"column"},children:[c.jsxs("h1",{style:{fontSize:"1.125rem",marginBottom:16},children:[e("bookmarkTitle"),"(",Ot.length,")"]}),Ot.length>0&&c.jsxs("div",{className:"mdocs-bookmark-filterbar",children:[c.jsx("input",{type:"text",placeholder:e("bookmarkSearch"),value:lo,onChange:y=>xr(y.target.value)}),c.jsxs("select",{value:jn,onChange:y=>wr(y.target.value),children:[c.jsx("option",{value:"",children:e("bookmarkFilterAll")}),Xa.map(y=>c.jsx("option",{value:y.id,children:y.name},y.id))]})]}),Ot.length===0?c.jsx("p",{style:{color:"var(--mdocs-text-muted, #999)",textAlign:"center",padding:"2rem 0"},children:e("bookmarkEmpty")}):Ir.length===0?c.jsx("p",{style:{color:"var(--mdocs-text-muted, #999)",textAlign:"center",padding:"2rem 0"},children:e("bookmarkNoMatch")}):c.jsx("div",{style:{overflowY:"auto",flex:1,margin:"0 -1rem",padding:"0 1rem"},children:c.jsxs("table",{className:"mdocs-bookmark-table",children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:e("bookmarkColTitle")}),c.jsx("th",{children:e("bookmarkColDomain")}),c.jsx("th",{children:e("bookmarkColAuthor")}),c.jsx("th",{children:e("bookmarkColTime")}),c.jsx("th",{className:"mdocs-bookmark-col-action"})]})}),c.jsx("tbody",{children:Ir.map(y=>{const R=Ya.has(y.documentId);return c.jsxs("tr",{className:`${R?"mdocs-bookmark-removing":""}`,style:{opacity:y.isDeleted?.6:1},children:[c.jsx("td",{className:"mdocs-bookmark-col-title",children:c.jsxs("div",{style:{cursor:y.isDeleted?"default":"pointer",display:"flex",alignItems:"center",gap:6,overflow:"hidden"},onClick:()=>{y.isDeleted||Q(()=>{un(!1),B(`/doc/${y.documentId}`)})},children:[c.jsx("span",{ref:M=>{if(M){const W=M.scrollWidth>M.clientWidth;M.title=W?y.displayName??"":""}},style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:y.displayName??"(无标题)"}),y.isDeleted&&c.jsx("span",{style:{fontSize:"0.7rem",color:"#d32f2f",background:"#ffebee",padding:"1px 6px",borderRadius:4,flexShrink:0},children:"已删除"})]})}),c.jsx("td",{children:y.isDeleted?"":co[y.domainId??""]??y.domainId??""}),c.jsx("td",{children:y.isDeleted?"":y.ownerVisitorName??"-"}),c.jsx("td",{children:y.isDeleted?"":xm(y.bookmarkedAt,n)}),c.jsx("td",{className:"mdocs-bookmark-col-action",children:c.jsxs("div",{style:{display:"flex",gap:2,alignItems:"center",justifyContent:"flex-end"},children:[c.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkOpen"),onClick:()=>{y.isDeleted||Q(()=>{un(!1),B(`/doc/${y.documentId}`)})},style:{background:"none",border:"none",cursor:y.isDeleted?"default":"pointer",padding:"4px",color:"var(--mdocs-text-muted, #999)",lineHeight:1,borderRadius:4,display:"inline-flex",alignItems:"center"},children:c.jsx(Ms,{size:14,strokeWidth:1.5})}),c.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkRemove"),onClick:async()=>{try{await Ll(y.documentId),_r(M=>new Set(M).add(y.documentId)),setTimeout(()=>{br(M=>M.filter(W=>W.documentId!==y.documentId)),_r(M=>{const W=new Set(M);return W.delete(y.documentId),W})},300)}catch(M){be(Je(e,M))}},style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4,display:"inline-flex",alignItems:"center"},onMouseEnter:M=>{M.currentTarget.style.color="#d32f2f"},onMouseLeave:M=>{M.currentTarget.style.color="var(--mdocs-text-muted, #999)"},children:"✕"})]})})]},y.documentId)})})]})}),c.jsx("div",{className:"mdocs-dialog-actions",style:{justifyContent:"flex-end",marginTop:16,paddingTop:16,borderTop:"1px solid var(--mdocs-border, #eee)"},children:c.jsx("button",{type:"button",onClick:()=>un(!1),children:e("close")})})]})}),bt&&c.jsx(xf,{x:bt.x,y:bt.y,node:bt.node,parentPath:bt.parentPath,onClose:()=>ct(null),onCreateChild:y=>dn(y),onCreateFolder:y=>vr(y),onDeleteDocument:y=>Rn(y.documentId,y.path),onDeleteFolder:y=>Cr(y.documentId,y.folderDisplayName||y.name)}),xe&&c.jsx(Aa,{title:xe.type==="folder"?"删除文件夹":"删除文档",message:xe.type==="folder"?`确定要删除「${xe.name}」及其下的所有文档和子文件夹吗?此操作不可撤销。`:`确定要删除「${xe.name}」吗?`,confirmLabel:"删除",cancelLabel:"取消",onConfirm:os,onCancel:()=>jt(null),danger:!0}),Kt&&c.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&!Yt&&ao(null)},children:c.jsxs("div",{className:"mdocs-dialog card",role:"dialog","aria-modal":"true",children:[c.jsx("h1",{children:Kt.kind==="document"?e("newDocumentTitle"):e("newFolderTitle")}),c.jsx("p",{className:"muted",children:Kt.kind==="document"?e("fileNameHint"):e("folderNameHint")}),c.jsxs("form",{onSubmit:Ga,className:"mdocs-dialog-form",children:[c.jsxs("label",{className:"mdocs-dialog-label",children:[Kt.kind==="document"?e("fileNameLabel"):e("folderNameLabel"),c.jsx("input",{ref:Va,value:Kt.draft,onChange:y=>ao(R=>R&&{...R,draft:y.target.value}),placeholder:Kt.kind==="document"?e("untitledPlaceholder"):e("folderExamplePlaceholder"),maxLength:200,disabled:Yt})]}),yr&&c.jsx("div",{className:"mdocs-dialog-error",children:yr}),c.jsxs("div",{className:"mdocs-dialog-actions",children:[c.jsx("button",{type:"button",onClick:()=>!Yt&&ao(null),disabled:Yt,children:e("cancel")}),c.jsx("button",{type:"submit",className:"primary",disabled:Yt,children:e(Yt?"creating":"create")})]})]})]})})]})}),S&&b&&c.jsx(Kl,{visitorId:S,onDismiss:()=>D(null)}),P&&c.jsx("div",{className:"mdocs-dialog-backdrop",style:{position:"fixed",zIndex:9999},onClick:y=>{y.target===y.currentTarget&&_(null)},children:c.jsxs("div",{className:"mdocs-dialog card",style:{maxWidth:480,textAlign:"center"},children:[c.jsx("h1",{style:{fontSize:"1.25rem",marginBottom:8},children:"🔑 保存你的恢复码"}),c.jsxs("p",{className:"muted",style:{marginBottom:16,lineHeight:1.5},children:["恢复码是你的唯一凭证,当 Token 丢失时可用它找回身份。",c.jsx("br",{}),c.jsx("strong",{children:"请立即复制保存,此弹窗关闭后不可再查看。"})]}),c.jsx("div",{style:{background:"#f5f5f5",borderRadius:8,padding:"12px 16px",fontFamily:"monospace",fontSize:"1.25rem",letterSpacing:"0.1em",marginBottom:20,userSelect:"all"},children:P}),c.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"center"},children:[c.jsx("button",{type:"button",className:"primary",onClick:()=>{navigator.clipboard.writeText(P)},children:"复制恢复码"}),c.jsx("button",{type:"button",onClick:()=>_(null),children:"已保存,关闭"})]})]})}),c.jsxs(c.Fragment,{children:[c.jsx(Cf,{open:Fe,onToggle:()=>{var y;Fe?(y=k.current)==null||y.requestClose():qe(!0)},position:Wt,onPositionChange:An}),Fe?c.jsx(x.Suspense,{fallback:null,children:c.jsx(ym,{ref:k,open:Fe,onClose:()=>{qe(!1),xt(!1)},visitorName:b==null?void 0:b.visitorName,fullscreen:l||Tn,onToggleFullscreen:l?void 0:()=>xt(y=>!y),domainId:E||null,domains:N,localizeDomainName:y=>kn(y,n,e),documentId:(A==null?void 0:A.documentId)??null,documentTitle:(A==null?void 0:A.displayName)??null,documentPath:(A==null?void 0:A.relativePath)??null,graphFileId:(G==null?void 0:G.kind)==="graph"?`${G.resourceId}.graph-file`:null,graphLabel:(G==null?void 0:G.kind)==="graph"?G.name:null,anchorStyle:l||Tn?void 0:Sf(Wt),onOpenDocument:y=>{ot("docs"),Q(()=>B(`/doc/${y}`)),qe(!1),xt(!1)},onTreeChanged:()=>void fe(),onDocumentOverwritten:y=>void ke(y),onOpenCoding:l?void 0:y=>void Ne(y)})}):null]}),F?c.jsx(x.Suspense,{fallback:null,children:c.jsx(vm,{open:j,initialMarkdown:F.markdown,documentId:F.documentId,displayName:F.displayName,onClose:()=>{z(!1),q(null)},onComplete:Pe})}):null,c.jsx(Mf,{open:qa,domains:N,onDomainsChange:L,onClose:()=>so(!1),onOpenDocument:y=>{l&&d(!1),ot("docs"),Q(()=>B(`/doc/${y}`))}})]})}const wm=x.lazy(()=>Pt(()=>import("./PlaygroundPage-BXmSDi40.js"),__vite__mapDeps([24,1,4,5,2,3,6,7,8,9,10,11])).then(e=>({default:e.PlaygroundPage})));function _m(){return c.jsxs(cs,{children:[c.jsx(mo,{path:"/",element:c.jsx(Li,{})}),c.jsx(mo,{path:"/doc/:documentId",element:c.jsx(Li,{})}),c.jsx(mo,{path:"/playground",element:c.jsx(x.Suspense,{fallback:c.jsx("div",{style:{padding:24},children:"Loading playground…"}),children:c.jsx(wm,{})})})]})}function Im(){const{pathname:e,hash:n,search:o,origin:r}=window.location,a="/",i=a.endsWith("/")?a.slice(0,-1):a;let s=e;i&&s.startsWith(i)&&(s=s.slice(i.length)||"/");const l=s.match(/^\/doc\/([^/]+)\/?$/);if(!l)return;const u=n.match(/^#\/doc\/([^/?#]+)/),d=(u==null?void 0:u[1])??l[1];if(!d)return;const h=a.endsWith("/")?a:`${a}/`;window.location.replace(`${r}${h}${o}#/doc/${d}`)}Im();const Ha=document.getElementById("root");if(!Ha)throw new Error("root element missing");ds.createRoot(Ha).render(c.jsx(zi.StrictMode,{children:c.jsx(fs,{motion:Ss,children:c.jsx(ms,{children:c.jsx(gl,{children:c.jsx(us,{children:c.jsx(_m,{})})})})})}));export{nr as $,Kh as A,Jh as B,Rs as C,rt as D,$h as E,zh as F,Uh as G,Wh as H,Yh as I,Fh as J,Rh as K,Lh as L,Oh as M,er as N,$f as O,qh as P,Bh as Q,Hh as R,sl as S,Gl as T,Or as U,wf as V,Fr as W,zt as X,zs as Y,Ta as Z,Qs as _,Re as a,vh as a$,Tl as a0,Yl as a1,$o as a2,Je as a3,Qf as a4,nm as a5,Mo as a6,Cn as a7,Mm as a8,Pl as a9,oh as aA,rh as aB,Gf as aC,Kf as aD,ho as aE,Er as aF,nh as aG,Fl as aH,sh as aI,fm as aJ,Rr as aK,Ui as aL,Gi as aM,Lm as aN,Fm as aO,th as aP,Ih as aQ,Nh as aR,Ph as aS,Dh as aT,Pi as aU,ph as aV,yh as aW,Gn as aX,Fo as aY,mf as aZ,gh as a_,Ah as aa,Hm as ab,Bm as ac,Um as ad,$m as ae,Wm as af,jm as ag,Rm as ah,Em as ai,Om as aj,Gm as ak,Vm as al,qm as am,Km as an,Ym as ao,lh as ap,Wr as aq,Aa as ar,ch as as,qr as at,dh as au,uh as av,fh as aw,mh as ax,hh as ay,Ol as az,Zh as b,bh as b0,Th as b1,Ch as b2,_h as b3,wh as b4,xh as b5,Sh as b6,kh as b7,Xt as b8,Jm as b9,vo as ba,yo as bb,On as bc,Ve as c,Ao as d,ih as e,zm as f,po as g,Pm as h,ah as i,Xm as j,Qm as k,kn as l,Zm as m,eh as n,ve as o,Eh as p,pr as q,Ll as r,Xh as s,Mh as t,Zf as u,Lf as v,jh as w,Gh as x,Vh as y,io as z};
|