@fgbg/mdocs 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/README.md +1 -1
  2. package/agent-skills/changelog/SKILL.md +6 -0
  3. package/dist/web/assets/{AgentChatPanel-_IV-LAS4.js → AgentChatPanel-BMOzVvwA.js} +1 -1
  4. package/dist/web/assets/{AiWriteWorkbench-DzJAmRHY.js → AiWriteWorkbench-ob4AeDFt.js} +1 -1
  5. package/dist/web/assets/{DiagramEditor-NtNY3sZL-KWdKFFEL.js → DiagramEditor-NtNY3sZL-BuZCaqLT.js} +1 -1
  6. package/dist/web/assets/DocChrome-DwSYxHOP.js +16 -0
  7. package/dist/web/assets/{DocumentEditor-CrU6HKmU.js → DocumentEditor-C_TFaCan.js} +1 -1
  8. package/dist/web/assets/{HtmlEditor-BBcreXJD.js → HtmlEditor-CYPTi1_L.js} +1 -1
  9. package/dist/web/assets/{MergeView-LV_hny8a.js → MergeView-FPF3k11v.js} +1 -1
  10. package/dist/web/assets/{PlaygroundPage-Bo9rM8MY.js → PlaygroundPage-Bt53Sr06.js} +1 -1
  11. package/dist/web/assets/{SettingsPage-D09P0j48.js → SettingsPage-C2SYz-8K.js} +1 -1
  12. package/dist/web/assets/{SheetEditor-Dyk-jpRL.js → SheetEditor-BOF-OgqU.js} +1 -1
  13. package/dist/web/assets/{Toolbar-C1HmC2Qc.js → Toolbar-LRioFemr.js} +1 -1
  14. package/dist/web/assets/{VisitorPickerModal-Cx03Papl.js → VisitorPickerModal-iK2QsYfY.js} +1 -1
  15. package/dist/web/assets/{check-BAYRiedE.js → check-65pb-o1o.js} +1 -1
  16. package/dist/web/assets/{copy-J9XXv57X.js → copy-BT35-MU9.js} +1 -1
  17. package/dist/web/assets/{index-Btfv_3-Q.js → index-92xZ1zjh.js} +2 -2
  18. package/dist/web/assets/{index-C1Mc0Svw.css → index-DE_nAopH.css} +1 -1
  19. package/dist/web/assets/{italic-BfR6fH81.js → italic-BmGXEOKX.js} +1 -1
  20. package/dist/web/assets/{meta2dEngine-BD2XbzaV-MY1Hyyeh.js → meta2dEngine-BD2XbzaV-DeIPntMM.js} +1 -1
  21. package/dist/web/assets/{plus-DvWl4lHk.js → plus-Ss1czARp.js} +1 -1
  22. package/dist/web/assets/{react-C7aGt3wN.js → react-DHtvOuT-.js} +3 -3
  23. package/dist/web/index.html +2 -2
  24. package/package.json +1 -1
  25. package/dist/web/assets/DocChrome-CtT7xOl6.js +0 -16
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DocumentEditor-CrU6HKmU.js","assets/react-vendor-BVS1XoFi.js","assets/ui-CEFkTVnG.js","assets/motion-BAXVQJfN.js","assets/react-C7aGt3wN.js","assets/editor-DBWWidi3.js","assets/diagram-BF8g9yg4.js","assets/plus-DvWl4lHk.js","assets/copy-J9XXv57X.js","assets/check-BAYRiedE.js","assets/Toolbar-C1HmC2Qc.js","assets/italic-BfR6fH81.js","assets/DocChrome-CtT7xOl6.js","assets/file-type-policy-aRrzC4LZ.js","assets/VisitorPickerModal-Cx03Papl.js","assets/docPlainCharCount-DO5lb3Wt.js","assets/HtmlEditor-BBcreXJD.js","assets/HtmlEditor-iolk903a.css","assets/SheetEditor-Dyk-jpRL.js","assets/SheetEditor-BPTMQ2s5.css","assets/SettingsPage-D09P0j48.js","assets/AgentChatPanel-_IV-LAS4.js","assets/AiWriteWorkbench-DzJAmRHY.js","assets/MergeView-LV_hny8a.js","assets/PlaygroundPage-Bo9rM8MY.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DocumentEditor-C_TFaCan.js","assets/react-vendor-BVS1XoFi.js","assets/ui-CEFkTVnG.js","assets/motion-BAXVQJfN.js","assets/react-DHtvOuT-.js","assets/editor-DBWWidi3.js","assets/diagram-BF8g9yg4.js","assets/plus-Ss1czARp.js","assets/copy-BT35-MU9.js","assets/check-65pb-o1o.js","assets/Toolbar-LRioFemr.js","assets/italic-BmGXEOKX.js","assets/DocChrome-DwSYxHOP.js","assets/file-type-policy-aRrzC4LZ.js","assets/VisitorPickerModal-iK2QsYfY.js","assets/docPlainCharCount-DO5lb3Wt.js","assets/HtmlEditor-CYPTi1_L.js","assets/HtmlEditor-iolk903a.css","assets/SheetEditor-BOF-OgqU.js","assets/SheetEditor-BPTMQ2s5.css","assets/SettingsPage-C2SYz-8K.js","assets/AgentChatPanel-BMOzVvwA.js","assets/AiWriteWorkbench-ob4AeDFt.js","assets/MergeView-FPF3k11v.js","assets/PlaygroundPage-Bt53Sr06.js"])))=>i.map(i=>d[i]);
2
2
  var is=Object.defineProperty;var as=(e,n,o)=>n in e?is(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o;var Jt=(e,n,o)=>as(e,typeof n!="symbol"?n+"":n,o);import{r as x,j as c,R as zi,B as ss,_ as Pt,a9 as ls,aa as cs,ab as ds,ac as mo,c as us,ad as fs}from"./react-vendor-BVS1XoFi.js";import{a5 as ms,a6 as hs}from"./ui-CEFkTVnG.js";import{d as ps,s as Oo,p as gs,t as ys,a as vs,q as bs,o as xs,b as ws,c as _s,e as ht,f as Is,g as ks,y as Ss,m as Ar,h as Mr}from"./diagram-BF8g9yg4.js";import{f as Cs}from"./motion-BAXVQJfN.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const s of a.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function o(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(i){if(i.ep)return;i.ep=!0;const a=o(i);fetch(i.href,a)}})();/**
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
  `;$u(Uu);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 Bu(e){if(Array.isArray(e))return e}function Hu(e){if(Array.isArray(e))return Xo(e)}function Ii(e,n,o){if(_a())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,n);var i=new(e.bind.apply(e,r));return i}function Sn(e,n,o){return(n=Yu(n))in e?Object.defineProperty(e,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[n]=o,e}function _a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(_a=function(){return!!e})()}function Vu(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Gu(e,n){var o=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(o!=null){var r,i,a,s,l=[],u=!0,d=!1;try{if(a=(o=o.call(e)).next,n!==0)for(;!(u=(r=a.call(o)).done)&&(l.push(r.value),l.length!==n);u=!0);}catch(h){d=!0,i=h}finally{try{if(!u&&o.return!=null&&(s=o.return(),Object(s)!==s))return}finally{if(d)throw i}}return l}}function Wu(){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 qu(){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(i){return Object.getOwnPropertyDescriptor(e,i).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 Bu(e)||Gu(e,n)||Ia(e,n)||Wu()}function He(e){return Hu(e)||Vu(e)||Ia(e)||qu()}function Ku(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 Yu(e){var n=Ku(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 Ia(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 Ju=xs(ws);function Si(e,n,o){!n||typeof o!="string"||e.filter(function(r){return!r[o]}).forEach(function(r){r[o]=Ju(n(r))})}function Xu(e,n){var o=e.nodes,r=e.links,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},a=i.nodeFilter,s=a===void 0?function(){return!0}:a,l=i.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 Zu=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(i){var a=Math.round(Math.abs(r(i)));a?i.__photons=He(Array(a)).map(function(){return{}}):delete i.__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(),i(),!n.isShadow&&a(),!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 i(){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 _=zu(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 a(){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:yu().force("link",cu()).force("charge",vu()).force("center",Dd()).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 i=n.dagMode&&Xu(n.graphData,function(f){return f[n.nodeId]},{nodeFilter:n.dagNodeFilter,onLoopError:n.onDagError||void 0}),a=Math.max.apply(Math,He(Object.values(i||[]))),s=n.dagLevelDistance||n.graphData.nodes.length/(a||1)*Zu*(["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(i[p[n.nodeId]]-a/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?bu(function(f){var p=i[f[n.nodeId]]||-1;return(n.dagMode==="radialin"?a-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 ka(e,n){var o=e instanceof Array?e:[e],r=new n;return r._destructor&&r._destructor(),{linkProp:function(a){return{default:r[a](),onChange:function(l,u){o.forEach(function(d){return u[d][a](l)})},triggerUpdate:!1}},linkMethod:function(a){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[a].apply(f,u);p!==f&&h.push(p)}),h.length?h[0]:this}}}}var Qu=800,ef=4,tf=5,Sa=ka("forceGraph",Xn),nf=ka(["forceGraph","shadowGraph"],Xn),of=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,Sa.linkProp(e))})).concat(He(["nodeRelSize","nodeId","nodeVal","nodeVisibility","linkSource","linkTarget","linkVisibility","linkCurvature"].map(function(e){return Sn({},e,nf.linkProp(e))})))),rf=Object.assign.apply(Object,He(["d3Force","d3ReheatSimulation","emitParticle"].map(function(e){return Sn({},e,Sa.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(a){a.style.width="".concat(e.width,"px"),a.style.height="".concat(e.height,"px"),a.width=e.width*r,a.height=e.height*r,!n&&!o&&a.getContext("2d").scale(r,r)});var i=ht(e.canvas).k;e.zoom.translateBy(e.zoom.__baseElem,(e.width-n)/2/i,(e.height-o)/2/i),e.needsRedraw=!0}}function Ca(e){var n=window.devicePixelRatio;e.setTransform(n,0,0,n,0,0)}function Di(e,n,o){e.save(),Ca(e),e.clearRect(0,0,n,o),e.restore()}var af=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(i){return(i||[]).every(function(a){return!a.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(i){var a=i.type,s=i.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:a,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,i,a){return n(r,r.__indexColor,i,a)}:null),o.flushShadowCanvas&&o.flushShadowCanvas()},triggerUpdate:!1},linkPointerAreaPaint:{onChange:function(n,o){o.shadowGraph.linkCanvasObject(n?function(r,i,a){return n(r,r.__indexColor,i,a)}: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}},of),aliases:{stopAnimation:"pauseAnimation"},methods:Qt({graph2ScreenCoords:function(n,o,r){var i=ht(n.canvas);return{x:o*i.k+i.x,y:r*i.k+i.y}},screen2GraphCoords:function(n,o,r){var i=ht(n.canvas);return{x:(o-i.x)/i.k,y:(r-i.y)/i.k}},centerAt:function(n,o,r,i){if(!n.canvas)return null;if(o!==void 0||r!==void 0){var a=Object.assign({},o!==void 0?{x:o}:{},r!==void 0?{y:r}:{});return i?n.tweenGroup.add(new Zr(s()).to(a,i).easing(Ut.Quadratic.Out).onUpdate(l).onComplete(function(){n.tweenGroup.remove(this)}).start()):l(a),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:i()}).to({k:o},r).easing(Ut.Quadratic.Out).onUpdate(function(s){var l=s.k;return a(l)}).onComplete(function(){n.tweenGroup.remove(this)}).start()):a(o),this;return i();function i(){return ht(n.canvas).k}function a(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,i=arguments.length,a=new Array(i>3?i-3:0),s=3;s<i;s++)a[s-3]=arguments[s];var l=this.getGraphBbox.apply(this,a);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),i=function(l){return Math.sqrt(Math.max(0,r(l)||1))*n.nodeRelSize},a=n.graphData.nodes.filter(o).map(function(s){return{x:s.x,y:s.y,r:i(s)}});return a.length?{x:[Ar(a,function(s){return s.x-s.r}),Mr(a,function(s){return s.x+s.r})],y:[Ar(a,function(s){return s.y-s.r}),Mr(a,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:[]})}},rf),stateInit:function(){return{lastSetZoom:1,zoom:Ss(),forceGraph:new Xn,shadowGraph:new Xn().cooldownTicks(0).nodeColor("__indexColor").linkColor("__indexColor").isShadow(!0),colorTracker:new rd,tweenGroup:new Xi}},init:function(n,o){var r=this;n.innerHTML="";var i=document.createElement("div");i.classList.add("force-graph-container"),i.style.position="relative",n.appendChild(i),o.canvas=document.createElement("canvas"),o.backgroundColor&&(o.canvas.style.background=o.backgroundColor),i.appendChild(o.canvas),o.shadowCanvas=document.createElement("canvas");var a=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(_s().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&&tf>=Math.sqrt(Is(["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;[a,s].forEach(function(f){Ca(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=ef/Math.cbrt(o.graphData.nodes.length)),o.needsRedraw=!0)}),o.tooltip=new Cd(i),["pointermove","pointerdown"].forEach(function(h){return i.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(i);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})}),i.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}),i.addEventListener("contextmenu",function(h){return!o.onBackgroundRightClick&&!o.onNodeRightClick&&!o.onLinkRightClick?!0:(h.preventDefault(),!1)}),o.forceGraph(a),o.shadowGraph(s);var d=ks(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()},Qu);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(a,o.width,o.height);var S=ht(o.canvas).k;o.onRenderFramePre&&o.onRenderFramePre(a,S),o.forceGraph.globalScale(S).tickFrame(),o.onRenderFramePost&&o.onRenderFramePost(a,S)}o.tweenGroup.update(),o.animationFrameRequestId=requestAnimationFrame(h)})()},update:function(n){}}),Da={exports:{}},sf="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",lf=sf,cf=lf;function Na(){}function Pa(){}Pa.resetWarningCache=Na;var df=function(){function e(r,i,a,s,l,u){if(u!==cf){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:Pa,resetWarningCache:Na};return o.PropTypes=o,o};Da.exports=df();var uf=Da.exports;const C=ss(uf),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},Ta={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])},ff=Object.assign({},ro,Ta,{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,Ta,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=uc(af,{methodNames:["emitParticle","d3Force","d3ReheatSimulation","stopAnimation","pauseAnimation","resumeAnimation","centerAt","zoom","zoomToFit","getGraphBbox","screen2GraphCoords","graph2ScreenCoords"]});fr.displayName="ForceGraph2D";fr.propTypes=ff;const mf=[{value:"openai-completions",label:"OpenAI 兼容"},{value:"anthropic-messages",label:"Anthropic 兼容"}];function hf(e){const{t:n}=Ve(),[o,r]=x.useState("deepseek"),[i,a]=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(a(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=i.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(""),a(""),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"||i.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:i,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:mf.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 pf(e){return e==="related_to"||e==="part_of"||e==="depends_on"}function gf(e,n){var h,m;const o=new Set(e),r=new Map,i=new Map,a=new Map;for(const f of e)r.set(f,[]),i.set(f,[]),a.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),i.get(f.to).push(f.from),a.set(f.to,(a.get(f.to)??0)+1));let s=e.filter(f=>(a.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=i.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:i,roots:s,depthMap:l}}function ko(e,n,o,r,i){return i.has(e)?!1:(o.get(e)??0)<n?!0:r.has(e)}function yf(e,n,o){const r=new Set(e),i=[...e];let a=0;for(;a<i.length;){const s=i[a++];if(o(s))for(const l of n.get(s)??[])r.has(l)||(r.add(l),i.push(l))}return r}function vf(e,n){const o=[],r=new Set,i=[...n.get(e)??[]];for(;i.length>0;){const a=i.pop();if(!r.has(a)){r.add(a),o.push(a);for(const s of n.get(a)??[])i.push(s)}}return o}function bf(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 xf({scope:e,resourceId:n,name:o,onOpenDocument:r,onClose:i}){const[a,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 Gl(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"?Vl:Hl)(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(()=>a?m?a.nodes:a.nodes.filter(k=>k.type==="concept"):[],[a,m]),me=x.useMemo(()=>{if(!a)return[];const k=new Set(Ee.map(j=>j.id));return a.edges.filter(j=>k.has(j.from)&&k.has(j.to))},[a,Ee]),Ce=x.useMemo(()=>{const k=me.filter(j=>Ni(String(j.type))).map(j=>({from:j.from,to:j.to}));return gf(Ee.map(j=>j.id),k)},[Ee,me]),be=x.useMemo(()=>yf(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&&pf(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=vf(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(!a||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)},[a,m,p,l,qe.width,qe.height,w,be]),x.useEffect(()=>{var F,q,X,te;if(!a||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,a,l,m,sn]);const xt=k=>(Ce.childrenOf.get(k)??[]).map(z=>bt.get(z)??(a==null?void 0:a.nodes.find(F=>F.id===z))).filter(z=>!!z),Wt=k=>(Ce.parentsOf.get(k)??[]).map(z=>bt.get(z)??(a==null?void 0:a.nodes.find(F=>F.id===z))).filter(z=>!!z),An=k=>{if(!a)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=a.nodes.find(Q=>Q.id===q);(X==null?void 0:X.type)==="doc"&&z.push(X);const te=a.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]}),i&&c.jsx("button",{className:"graph-btn graph-btn-danger",onClick:i,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($s,{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}),a?"重新生成":"生成图谱"]})})]})]}),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(Bs,{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}),a?"重新生成":"生成图谱"]})})]})]})]}),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&&!a&&!_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:bf(k)})},j))})]}),!l&&!d&&a&&a.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&&a&&a.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(hf,{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 i=document.execCommand("copy");return document.body.removeChild(r),i}catch{return!1}}function wf(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 i="";if(e.node.type==="folder"){const h=e.node;i=((d=h.folderDisplayName)==null?void 0:d.trim())||h.path||""}const a=r?i?n("newDocIn",{name:i}):n("newDocAtRoot"):n("newDocBeside"),s=r?i?n("newFolderIn",{name:i}):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:a}),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:i||e.node.name}):n("deleteItem",{name:e.node.name})})]})}function _f({domains:e,value:n,onChange:o,ariaLabel:r,localizeName:i,onDomainsChange:a}){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=>i(N.domainName).toLowerCase().includes(I)||N.domainName.toLowerCase().includes(I)):d},[d,m,i]);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),a==null||a(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?i(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:i(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 Aa="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 If(e,n,o,r){const i=e-o,a=n-r,s=window.innerHeight-a-Zn;return hr({left:i,bottom:s})}function kf(){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 Sf(e){return e.left===st.left&&e.bottom===st.bottom}function Cf(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 i=Math.max(8,e.bottom-8);return{left:r,bottom:i}}function Df(e){const{t:n}=Ve(),o=!!e.disableDrag,[r,i]=x.useState(!1),[a,s]=x.useState(e.position),l=x.useRef(null),u=x.useRef(null),d=x.useRef(a),h=x.useRef(e.onPositionChange),m=x.useRef(e.onToggle);d.current=a,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,i(!0)),I.didMove&&(g.current=If(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,i(!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:a,S=!o&&!Sf(a);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:Aa,alt:"",draggable:!1})}),S&&c.jsx("button",{type:"button",className:"mdocs-agent-fab-reset",onClick:b,"aria-label":n("agentFabReset"),children:n("agentFabReset")})]})}function Nf(){const[e,n]=x.useState(()=>typeof window>"u"?st:kf());return[e,n]}function Pf({title:e,message:n,onClose:o}){const{t:r}=Ve();return c.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:i=>{i.target===i.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 Ma({title:e,message:n,confirmLabel:o="确定",cancelLabel:r="取消",onConfirm:i,onCancel:a,busy:s=!1,danger:l=!1}){return c.jsx("div",{className:"mdocs-dialog-backdrop",role:"presentation",onMouseDown:u=>{u.target===u.currentTarget&&!s&&a()},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:a,disabled:s,children:r}),c.jsx("button",{type:"button",className:l?"danger":"primary",onClick:i,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"},ja={"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]??ja[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 Eh(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 Tf=280,en="";function Af(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(Af).join("|"),"gi"),i=[];let a=0,s,l=0;for(;(s=r.exec(e))!==null;)s.index>a&&i.push(e.slice(a,s.index)),i.push(c.jsx("mark",{children:s[0]},l++)),a=s.index+s[0].length,s[0].length===0&&r.lastIndex++;return a<e.length&&i.push(e.slice(a)),i}function Mf(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 jf(e){const{t:n,lang:o}=Ve(),r=x.useRef(null),i=x.useRef(null),[a,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=i.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=a.trim();if(!B){P([]),N(!1),E(null);return}N(!0),E(null);const G=++O.current,ce=window.setTimeout(()=>{Fl({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")))})},Tf);return()=>window.clearTimeout(ce)},[a,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:a,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:i,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:[!a.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&&a.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=Mf(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,Ea=12,Ra=24,Ef=/^#([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 Rh(e){return e==null?"":typeof e=="string"?e:e.v??""}function Oh(e){if(!(e==null||typeof e=="string"))return e.style}function Rf(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=Oa(n.style);return r?{v:o,style:r}:{v:o}}return{v:String(e)}}function eo(e){return Ef.test(e.trim())}function Oa(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>=Ea&&r<=Ra&&(o.fontSize=r)}return Object.keys(o).length>0?o:void 0}function Of(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>=Ea&&r<=Ra&&(o.fontSize=r)}return Object.keys(o).length>0?o:void 0}function Ff(e){const n=Oa(e.style);return n?{v:e.v,style:n}:e.v}function Lf(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,i])=>[r,Ff(i)]))})),...n.length>0?{merges:n}:{}}}function Fa(e){var a;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 i=[];for(let s=0;s<o;s+=1){const l={};for(const u of r)l[u.id]=Nn();i.push({id:Nt("r"),cells:l})}return{id:Nt("s"),name:((a=e==null?void 0:e.name)==null?void 0:a.trim())||"Sheet1",columns:r,rows:i,merges:[]}}function tn(e){const n=Fa(e);return{version:Qn,sheets:[n],activeSheetId:n.id}}function zf(e){const n={version:Qn,activeSheetId:e.activeSheetId,sheets:e.sheets.map(Lf)};return`${JSON.stringify(n,null,2)}
299
- `}function $f(e,n){if(!Array.isArray(e))return[];const o=new Set(n.rows.map(a=>a.id)),r=new Set(n.columns.map(a=>a.id)),i=[];for(const a of e){if(!a||typeof a!="object")continue;const s=a,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)||i.push({startRowId:l,startColId:u,endRowId:d,endColId:h})}return i}function ji(e,n){if(!e||typeof e!="object")return null;const o=e,r=Array.isArray(o.columns)?o.columns:[],i=Array.isArray(o.rows)?o.rows:[],a=[];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;a.push({id:f,name:p})}if(a.length===0)return null;const s=[];for(const h of i){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 a)g[w.id]=Rf(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=$f(o.merges,{columns:a,rows:s});return{id:l,name:u,columns:a,rows:s,merges:d}}function Fh(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 a=[];for(let u=0;u<r.sheets.length;u+=1){const d=ji(r.sheets[u],`Sheet${u+1}`);d&&a.push(d)}if(a.length===0)return tn();const s=typeof r.activeSheetId=="string"?r.activeSheetId:"",l=a.some(u=>u.id===s)?s:a[0].id;return{version:Qn,sheets:a,activeSheetId:l}}const i=ji(r,"Sheet1");return i?{version:Qn,sheets:[i],activeSheetId:i.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 i=e.sheets.find(s=>s.name===o);if(i)return i;const a=o.toLowerCase();return e.sheets.find(s=>s.name.toLowerCase()===a)??null}function Uf(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 Lh(e,n){const o=pr(e,n);if(!o)throw new Error(`unknown sheet: ${n}`);return{...e,activeSheetId:o.id}}function zh(e,n){let o=`Sheet${e.sheets.length+1}`;const r=new Set(e.sheets.map(a=>a.name));if(r.has(o)){let a=2;for(;r.has(`${o}${a}`);)a+=1;o=`${o}${a}`}const i=Fa({name:o});return{doc:{...e,sheets:[...e.sheets,i],activeSheetId:i.id},tab:i}}function $h(e,n,o){const r=pr(e,n);if(!r)throw new Error(`unknown sheet: ${n}`);const i=o.trim();if(!i)throw new Error("sheet name is required");if(e.sheets.find(s=>s.id!==r.id&&s.name===i))throw new Error(`sheet name already exists: ${i}`);return Uf(e,{...r,name:i})}function Uh(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(a=>a.id!==o.id),i=e.activeSheetId===o.id?r[0].id:e.activeSheetId;return{...e,sheets:r,activeSheetId:i}}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 La(e,n){const o=Ze(e,n.startRowId),r=Ze(e,n.endRowId),i=Qe(e,n.startColId),a=Qe(e,n.endColId);if(o<0||r<0||i<0||a<0)return null;const s=Math.min(o,r),l=Math.max(o,r),u=Math.min(i,a),d=Math.max(i,a);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 Bf(e,n,o){const r=Ze(e,n.startRowId),i=Ze(e,n.endRowId),a=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||i<0||l<0||u<0||a<0||s<0||d<0||h<0)return!1;const m=Math.min(r,i),f=Math.max(r,i),p=Math.min(a,s),g=Math.max(a,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),i=Qe(e,o);if(r<0||i<0)return null;for(const a of e.merges??[]){const s=Ze(e,a.startRowId),l=Ze(e,a.endRowId),u=Qe(e,a.startColId),d=Qe(e,a.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&&i>=f&&i<=p)return a}return null}function Bh(e,n,o){const r=io(e,n,o);return r?r.startRowId===n&&r.startColId===o:!0}function Hh(e,n,o){const r=io(e,n,o);return r?!(r.startRowId===n&&r.startColId===o):!1}function Vh(e,n){const o=Ze(e,n.startRowId),r=Ze(e,n.endRowId),i=Qe(e,n.startColId),a=Qe(e,n.endColId);return{rowSpan:Math.abs(r-o)+1,colSpan:Math.abs(a-i)+1}}function za(e){const n=new Set(e.rows.map(i=>i.id)),o=new Set(e.columns.map(i=>i.id)),r=(e.merges??[]).filter(i=>n.has(i.startRowId)&&n.has(i.endRowId)&&o.has(i.startColId)&&o.has(i.endColId)&&La(e,i)!=null);return{...e,merges:r}}function Gh(e,n){const o=La(e,n);if(!o)throw new Error("invalid merge range (need at least 2 cells)");for(const r of e.merges??[])if(Bf(e,r,o))throw new Error("merge overlaps existing merge");return{...e,merges:[...e.merges??[],o]}}function Wh(e,n,o){const r=io(e,n,o);return r?{tab:{...e,merges:(e.merges??[]).filter(i=>i!==r)},removed:r}:{tab:e,removed:null}}function $a(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 qh(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 Kh(e){const n={};for(const o of e.columns)n[o.id]=Nn();return{...e,rows:[...e.rows,{id:Nt("r"),cells:n}]}}function Yh(e,n,o,r){const i=$a(e,n,o);return{...e,rows:e.rows.map(a=>{if(a.id!==i.rowId)return a;const s=a.cells[i.columnId]??Nn();return{...a,cells:{...a.cells,[i.columnId]:{v:r,...s.style?{style:s.style}:{}}}}})}}function Jh(e,n,o,r){const i=$a(e,n,o);return{...e,rows:e.rows.map(a=>{if(a.id!==i.rowId)return a;const s=a.cells[i.columnId]??Nn(),l=Of(s.style,r),u=l?{v:s.v,style:l}:{v:s.v};return{...a,cells:{...a.cells,[i.columnId]:u}}})}}function Xh(e,n,o){return{...e,columns:e.columns.map(r=>r.id===n?{...r,name:o}:r)}}function Zh(e,n){return za({...e,rows:e.rows.filter(o=>o.id!==n)})}function Qh(e,n){const o=[],r=new Set,i=[];for(const l of n){const u=Hf(e,l);if(!u){o.push(`unknown column: ${l}`);continue}r.has(u.id)||(r.add(u.id),i.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 a=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:za({...e,columns:a,rows:s}),removed:i,errors:o}}function Hf(e,n){const o=n.trim();if(!o)return null;const r=e.columns.find(s=>s.id===o);if(r)return r;const i=e.columns.find(s=>s.name===o);if(i)return i;const a=o.toLowerCase();return e.columns.find(s=>s.name.toLowerCase()===a)??null}function Vf(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 Ua(e,n=new Set){for(const o of e)o.type==="document"?n.add(o.path):(o.descDocumentId&&n.add(bl(o.path)),Ua(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=ja[n];return o?e(o):n}function Gf(e){const{tree:n,currentDomainId:o,selectedCreateParentPath:r,t:i,onDocCreated:a,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=Ua(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(i,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(i,re));return}if(S.has(ue)){h(i("pathExists"));return}const A=D?Hn(n,D)??void 0:void 0,ie=N==="sheet"?zf(tn()):"",oe=await $o({fileName:G,displayName:ce,content:ie,domainId:o,parentId:A,fileType:N});await s(),a(oe),u(null);return}const L=$r(l.draft);if(!L.ok){h(Po(i,L.message));return}const E=L.displayFile,O=E.replace(/\.md$/i,"");let $;try{$=Ur(No(D,E))}catch(ne){h(Je(i,ne));return}if(S.has($)){h(i("pathExists"));return}const V=D?Hn(n,D)??void 0:void 0,J=await $o({fileName:E,displayName:O,content:Vf(O),domainId:o,parentId:V});await s(),a(J),u(null);return}const P=_l(l.draft);if(!P.ok){h(Po(i,P.message));return}const _=Lo(P.display);if(!_){h(i("invalidFolderName"));return}const T=No(D,_);if(S.has(T)){h(i("folderExists"));return}const I=D?Hn(n,D)??void 0:void 0;await Rl({name:_,parentId:I,domainId:o}),await s(),u(null)}catch(P){h(Je(i,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 Wf(){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 qf=64,Ri=44,Kf=.75;function Yf(e,n,o){const r=!!(o!=null&&o.open),i=x.useRef(n),a=x.useRef(o==null?void 0:o.onClose);i.current=n,a.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(!a.current)return;s="close"}else{if(p.clientX>qf)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)*Kf&&w>24){s=null;return}if(s==="open"&&g>=Ri){s=null,i.current();return}s==="close"&&g<=-Ri&&(s=null,(b=a.current)==null||b.call(a))},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 Jf({open:e,onClose:n,onResolve:o,onForceOverwrite:r,forceBusy:i}){const{t:a}=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:a("conflictTitle")}),c.jsx("p",{className:"mdocs-conflict-modal-body",children:a("conflictBody")}),r?c.jsx("p",{className:"mdocs-conflict-modal-force-hint",children:a("conflictForceHint")}):null,c.jsxs("div",{className:"mdocs-conflict-modal-actions",children:[c.jsx("button",{type:"button",className:"primary",onClick:o,disabled:i,children:a("conflictResolve")}),r?c.jsx("button",{type:"button",className:"mdocs-conflict-force-btn",disabled:i,onClick:r,children:a(i?"conflictForceBusy":"conflictForce")}):null,c.jsx("button",{type:"button",className:"secondary",onClick:n,disabled:i,children:a("conflictClose")})]})]})}):null}function Oi({documentId:e,visitorId:n,visitorName:o,documentOwnerId:r,onClose:i}){const[a,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 a)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}},[a]),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 $l(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 Ul(e,{content:l,parentId:(d==null?void 0:d.commentId)||null,replyToVisitorId:d?((K=a.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 Bl(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(el,{size:18}),"评论 (",B,")"]}),c.jsx("button",{type:"button",onClick:i,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(Ma,{title:"删除评论",message:"确定要删除这条评论吗?",confirmLabel:"删除",danger:!0,onConfirm:()=>A(w),onCancel:()=>b(null)})]})}const Xf="mdocs-drafts",Zf=5,Ae="drafts";let Ba=0;const Qo=new Set;function ep(e){return Qo.add(e),()=>{Qo.delete(e)}}function tp(){return Ba}function Ha(e,n){Ba+=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(Xf,Zf);o.onupgradeneeded=r=>{const i=o.result;i.objectStoreNames.contains(Ae)||i.createObjectStore(Ae,{keyPath:"documentId"});const a=r.oldVersion;if(a>0&&a<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(a>0&&a<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 Qf(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 i=(r=e.localBaseCommitIdAtEditStart)==null?void 0:r.trim();i&&(o.localBaseCommitId=i)}(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,i)=>{const a=n.transaction(Ae,"readwrite");a.objectStore(Ae).put(o),a.oncomplete=()=>{Ha(o.documentId,!o.published),r()},a.onerror=()=>i(a.error)})}async function Re(e){const n=await on();return new Promise((o,r)=>{const a=n.transaction(Ae,"readonly").objectStore(Ae).get(e);a.onsuccess=()=>o(a.result),a.onerror=()=>r(a.error)})}async function Ao(e){const n=await on();return new Promise((o,r)=>{const i=n.transaction(Ae,"readwrite");i.objectStore(Ae).delete(e),i.oncomplete=()=>{Ha(e,!1),o()},i.onerror=()=>r(i.error)})}async function em(e){const n=await on();return new Promise((o,r)=>{const a=n.transaction(Ae,"readonly").objectStore(Ae).getAll();a.onsuccess=()=>{let s=a.result;e!=null&&e.skipFailed&&(s=s.filter(l=>!l.publishError)),o(s)},a.onerror=()=>r(a.error)})}async function tm(e,n){const o=await on();return new Promise((r,i)=>{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=()=>i(l.error)})}async function Mo(e){const n=await on();return new Promise((o,r)=>{const a=n.transaction(Ae,"readwrite").objectStore(Ae),s=a.get(e);s.onsuccess=()=>{const l=s.result;l&&a.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 nm(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 om(e,n,o,r){const i=(n==null?void 0:n.displayName)||e("unknownTitle");if(o===nn.SYNC_HEAD_MISSING)return e("draftPublishFailedSyncHead",{name:i});if(o===nn.DOC_NOT_FOUND)return e("draftPublishFailedNotice",{name:i});const a=r instanceof et||r instanceof Error&&r.message?r.message:o;return e("draftPublishFailedGeneric",{name:i,reason:a})}async function rm(e,n,o){const r=nm(n);throw await tm(e,r),n instanceof Cn?n:new Cn(r,{cause:n})}function im(e,n){const o=x.useRef(n);o.current=n,x.useEffect(()=>{if(!e)return;const r=3e4,i=1e4,a=async()=>{const l=await em({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)}};a();const s=setInterval(a,i);return()=>clearInterval(s)},[e])}const am=1e4;function sm(e,n){const[o,r]=x.useState(null),[i,a]=x.useState("up_to_date");return x.useEffect(()=>{if(!e){r(null),a("up_to_date");return}let l=!1;const u=e;async function d(){try{const m=await Ml(u,n??void 0);if(l)return;r(m.headCommitId),a(m.status)}catch{}}d();const h=window.setInterval(()=>void d(),am);return()=>{l=!0,window.clearInterval(h)}},[e,n]),{remoteCommitId:o,syncStatus:i,syncBehind:!!(n&&o&&n!==o)||i==="behind"}}function Fi(e){return e.trim()}function lm(e){return e.trim()}const cm=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".ico",".bmp",".jfif",".pjpeg"]);function dm(e){const n=e.split("/").pop()??"",o=n.lastIndexOf(".");return o<=0?"":n.slice(o).toLowerCase()}function um(e,n,o){let r,i;try{r=new URL(o),i=new URL(e,o)}catch{return null}if(i.origin!==r.origin||!i.pathname.startsWith("/api/assets/")||cm.has(dm(i.pathname)))return null;const a=n==null?void 0:n.trim();return a&&!i.searchParams.has("name")&&i.searchParams.set("name",a),i.toString()}function fm(){const e=n=>{if(n.button!==0)return;const r=n.composedPath().find(a=>a instanceof HTMLAnchorElement);if(!r)return;const i=um(r.href,r.getAttribute("download"),window.location.href);i&&(n.preventDefault(),n.stopPropagation(),window.location.assign(i))};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"},mm="/assets/mdocs-logo-Dsv_2t6v.svg",hm=x.lazy(()=>Pt(()=>import("./DocumentEditor-CrU6HKmU.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])).then(e=>({default:e.DocumentEditor}))),pm=x.lazy(()=>Pt(()=>import("./HtmlEditor-BBcreXJD.js"),__vite__mapDeps([16,1,12,13,14,15,2,3,6,17])).then(e=>({default:e.HtmlEditor}))),gm=x.lazy(()=>Pt(()=>import("./SheetEditor-Dyk-jpRL.js"),__vite__mapDeps([18,1,12,13,14,7,11,2,3,6,19])).then(e=>({default:e.SheetEditor}))),ym=x.lazy(()=>Pt(()=>import("./SettingsPage-D09P0j48.js"),__vite__mapDeps([20,1,14,9,2,3,6])).then(e=>({default:e.SettingsPage}))),vm=x.lazy(()=>Pt(()=>import("./AgentChatPanel-_IV-LAS4.js"),__vite__mapDeps([21,1,9,8,7,2,3,6])).then(e=>({default:e.AgentChatPanel}))),bm=x.lazy(()=>Pt(()=>import("./AiWriteWorkbench-DzJAmRHY.js"),__vite__mapDeps([22,1,21,9,8,7,2,3,6])).then(e=>({default:e.AiWriteWorkbench}))),xm=x.lazy(()=>Pt(()=>import("./MergeView-LV_hny8a.js"),__vite__mapDeps([23,1,4,5,2,3,6,7,8,9,13])).then(e=>({default:e.MergeView})));function wm(e,n){try{const o=new Intl.RelativeTimeFormat(n,{numeric:"auto"}),r=Date.now()-new Date(e).getTime(),i=Math.floor(r/6e4),a=Math.floor(i/60),s=Math.floor(a/24);return s>30?o.format(-Math.floor(s/30),"month"):s>0?o.format(-s,"day"):a>0?o.format(-a,"hour"):i>0?o.format(-i,"minute"):o.format(-Math.floor(r/1e3),"second")}catch{return e.slice(0,10)}}async function Ro(e,n,o,r){const i=await nr();n(i);const a=localStorage.getItem("mdocs.currentDomainId"),l=a&&i.some(u=>u.domainId===a)?a:ql(i,e);o(l),await r(l)}function Li(){const{t:e,lang:n,setLang:o}=Ve(),[r,i]=x.useState("loading"),[a,s]=x.useState(()=>localStorage.getItem("mdocs.sidebarCollapsed")==="true"),l=Wf(),[u,d]=x.useState(!1),h=()=>{if(l){d(R=>!R);return}const y=!a;s(y),localStorage.setItem("mdocs.sidebarCollapsed",String(y))};x.useEffect(()=>{l||d(!1)},[l]),x.useEffect(()=>fm(),[]);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}=ls(),B=cs(),[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}=sm(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");Yf(l&&sn==="docs",()=>d(!0),{open:u,onClose:()=>d(!1)});const[Fe,qe]=x.useState(!1),[Tn,xt]=x.useState(!1),[Wt,An]=Nf(),k=x.useRef(null),[j,z]=x.useState(!1),[F,q]=x.useState(null),X=x.useRef(void 0),te=x.useRef(void 0);im(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=lm(y.markdown):le=(await vo({content:y.markdown,from:"markdown",to:"lexical"})).content,await Qf({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),i("ready")}catch(y){if(y instanceof et&&y.status===401){i("needsRegister");return}be(Je(e,y)),i("needsRegister")}}async function _t(y,R){const M=await Dl(y,R);v(M.visitor),D(M.visitor.visitorId),_(M.recoveryCode),Vn(M.visitor.visitorId),await Ro(M.visitor.visitorId,L,O,fe),i("ready")}async function dt(y){const R=await Wr();v(R),await Ro(R.visitorId,L,O,fe),i("ready")}async function fe(y){const M=await Al(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:Ga,openNewDocumentModal:dn,openNewFolderModal:vr,submitCreateModal:Wa}=Gf({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}),[qa,Mn]=x.useState(!1),[Ka,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[Ya,un]=x.useState(!1),[Ot,br]=x.useState([]),[lo,xr]=x.useState(""),[jn,wr]=x.useState(""),[Ja,_r]=x.useState(new Set);async function Xa(){try{const y=await Ll();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]),Za=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 Qa(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 es(){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 Qa(M,y,R,le,Ie.details),Ie}})}async function ts(){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 ts()}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 ns(y,R,M){try{await rm(y,R,M)}catch(W){if(!(W instanceof Cn))throw W;const ee=M??await Re(y);throw me(om(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 ns(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 os(y,R){try{const M=await El(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 rs(){if(xe)try{xe.type==="document"?(await jl(xe.id),(A==null?void 0:A.documentId)===xe.id&&(ie(null),re(null),Me(""),B("/"))):xe.type==="folder"&&(await Ol(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(Kl,{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(ym,{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":a?" mdocs-sidebar-collapsed":""),children:[c.jsxs("header",{className:"mdocs-sidebar-header",children:[c.jsxs("div",{className:"mdocs-brand",children:[c.jsx("img",{src:mm,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":a?"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}):a?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(Ls,{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(dl,{size:14,strokeWidth:1.5}),e("sheetDocument")]})]}),c.jsxs("button",{type:"button",className:"mdocs-sidebar-create-btn",onClick:()=>{V(!1),vr()},children:[c.jsx(qs,{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(Jl,{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:os,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(""),Xa()},style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4},children:c.jsx(ll,{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(Zs,{size:16,strokeWidth:1.5})})]})]}),c.jsxs("main",{className:"mdocs-main",children:[(G==null?void 0:G.kind)==="graph"?c.jsx(xf,{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(gm,{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(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(),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(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,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(Os,{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(Gs,{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:Aa,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(_f,{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(Jf,{open:Tt,onClose:()=>vt(!1),onResolve:()=>{vt(!1),nt(!0)},onForceOverwrite:b&&A&&b.visitorId===A.ownerVisitorId?()=>void es():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(xm,{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(Pf,{title:e("error"),message:Ce,onClose:()=>be(null)})]}),qa&&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:()=>{Cl(),ie(null),re(null),v(null),I([]),Mn(!1),i("needsRegister")},children:"确认退出"})]})]})}),Ya&&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")}),Za.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=Ja.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?"":wm(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(js,{size:14,strokeWidth:1.5})}),c.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkRemove"),onClick:async()=>{try{await zl(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(wf,{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(Ma,{title:xe.type==="folder"?"删除文件夹":"删除文档",message:xe.type==="folder"?`确定要删除「${xe.name}」及其下的所有文档和子文件夹吗?此操作不可撤销。`:`确定要删除「${xe.name}」吗?`,confirmLabel:"删除",cancelLabel:"取消",onConfirm:rs,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:Wa,className:"mdocs-dialog-form",children:[c.jsxs("label",{className:"mdocs-dialog-label",children:[Kt.kind==="document"?e("fileNameLabel"):e("folderNameLabel"),c.jsx("input",{ref:Ga,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(Yl,{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(Df,{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(vm,{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:Cf(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(bm,{open:j,initialMarkdown:F.markdown,documentId:F.documentId,displayName:F.displayName,onClose:()=>{z(!1),q(null)},onComplete:Pe})}):null,c.jsx(jf,{open:Ka,domains:N,onDomainsChange:L,onClose:()=>so(!1),onOpenDocument:y=>{l&&d(!1),ot("docs"),Q(()=>B(`/doc/${y}`))}})]})}const _m=x.lazy(()=>Pt(()=>import("./PlaygroundPage-Bo9rM8MY.js"),__vite__mapDeps([24,1,4,5,2,3,6,7,8,9,10,11])).then(e=>({default:e.PlaygroundPage})));function Im(){return c.jsxs(ds,{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(_m,{})})})]})}function km(){const{pathname:e,hash:n,search:o,origin:r}=window.location,i="/",a=i.endsWith("/")?i.slice(0,-1):i;let s=e;a&&s.startsWith(a)&&(s=s.slice(a.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=i.endsWith("/")?i:`${i}/`;window.location.replace(`${r}${h}${o}#/doc/${d}`)}km();const Va=document.getElementById("root");if(!Va)throw new Error("root element missing");us.createRoot(Va).render(c.jsx(zi.StrictMode,{children:c.jsx(ms,{motion:Cs,children:c.jsx(hs,{children:c.jsx(yl,{children:c.jsx(fs,{children:c.jsx(Im,{})})})})})}));export{el as $,Xh as A,Qh as B,Os as C,rt as D,Hh as E,Bh as F,Vh as G,Yh as H,Zh as I,$h as J,Lh as K,zh as L,Ma as M,er as N,Uh as O,Uf as P,Jh as Q,Gh as R,ll as S,Wh as T,Wl as U,Or as V,_f as W,zt as X,Fr as Y,$s as Z,Aa as _,Re as a,jh as a$,nr as a0,Al as a1,Jl as a2,$o as a3,Je as a4,em as a5,om as a6,Mo as a7,Cn as a8,jm as a9,rh as aA,ih as aB,Wf as aC,Yf as aD,ho as aE,Er as aF,oh as aG,Ll as aH,lh as aI,mm as aJ,Rr as aK,Ui as aL,Gi as aM,zm as aN,Lm as aO,nh as aP,kh as aQ,Ph as aR,Th as aS,Nh as aT,Pi as aU,gh as aV,vh as aW,Mh as aX,Gn as aY,Fo as aZ,hf as a_,Tl as aa,Eh as ab,Vm as ac,Hm as ad,Bm as ae,Um as af,qm as ag,Em as ah,Om as ai,Rm as aj,Fm as ak,Wm as al,Gm as am,Km as an,Ym as ao,Jm as ap,ch as aq,Wr as ar,dh as as,qr as at,uh as au,fh as av,mh as aw,hh as ax,ph as ay,Fl as az,tp as b,yh as b0,bh as b1,xh as b2,Ah as b3,Dh as b4,Ih as b5,_h as b6,wh as b7,Ch as b8,Sh as b9,Xt as ba,Xm as bb,vo as bc,yo as bd,On as be,Ve as c,Ao as d,ah as e,$m as f,po as g,Tm as h,sh as i,Zm as j,eh as k,kn as l,Qm as m,th as n,ve as o,Fh as p,pr as q,zl as r,ep as s,Rh as t,Qf as u,zf as v,Oh as w,Kh as x,qh as y,io as z};
299
+ `}function $f(e,n){if(!Array.isArray(e))return[];const o=new Set(n.rows.map(a=>a.id)),r=new Set(n.columns.map(a=>a.id)),i=[];for(const a of e){if(!a||typeof a!="object")continue;const s=a,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)||i.push({startRowId:l,startColId:u,endRowId:d,endColId:h})}return i}function ji(e,n){if(!e||typeof e!="object")return null;const o=e,r=Array.isArray(o.columns)?o.columns:[],i=Array.isArray(o.rows)?o.rows:[],a=[];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;a.push({id:f,name:p})}if(a.length===0)return null;const s=[];for(const h of i){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 a)g[w.id]=Rf(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=$f(o.merges,{columns:a,rows:s});return{id:l,name:u,columns:a,rows:s,merges:d}}function Fh(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 a=[];for(let u=0;u<r.sheets.length;u+=1){const d=ji(r.sheets[u],`Sheet${u+1}`);d&&a.push(d)}if(a.length===0)return tn();const s=typeof r.activeSheetId=="string"?r.activeSheetId:"",l=a.some(u=>u.id===s)?s:a[0].id;return{version:Qn,sheets:a,activeSheetId:l}}const i=ji(r,"Sheet1");return i?{version:Qn,sheets:[i],activeSheetId:i.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 i=e.sheets.find(s=>s.name===o);if(i)return i;const a=o.toLowerCase();return e.sheets.find(s=>s.name.toLowerCase()===a)??null}function Uf(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 Lh(e,n){const o=pr(e,n);if(!o)throw new Error(`unknown sheet: ${n}`);return{...e,activeSheetId:o.id}}function zh(e,n){let o=`Sheet${e.sheets.length+1}`;const r=new Set(e.sheets.map(a=>a.name));if(r.has(o)){let a=2;for(;r.has(`${o}${a}`);)a+=1;o=`${o}${a}`}const i=Fa({name:o});return{doc:{...e,sheets:[...e.sheets,i],activeSheetId:i.id},tab:i}}function $h(e,n,o){const r=pr(e,n);if(!r)throw new Error(`unknown sheet: ${n}`);const i=o.trim();if(!i)throw new Error("sheet name is required");if(e.sheets.find(s=>s.id!==r.id&&s.name===i))throw new Error(`sheet name already exists: ${i}`);return Uf(e,{...r,name:i})}function Uh(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(a=>a.id!==o.id),i=e.activeSheetId===o.id?r[0].id:e.activeSheetId;return{...e,sheets:r,activeSheetId:i}}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 La(e,n){const o=Ze(e,n.startRowId),r=Ze(e,n.endRowId),i=Qe(e,n.startColId),a=Qe(e,n.endColId);if(o<0||r<0||i<0||a<0)return null;const s=Math.min(o,r),l=Math.max(o,r),u=Math.min(i,a),d=Math.max(i,a);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 Bf(e,n,o){const r=Ze(e,n.startRowId),i=Ze(e,n.endRowId),a=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||i<0||l<0||u<0||a<0||s<0||d<0||h<0)return!1;const m=Math.min(r,i),f=Math.max(r,i),p=Math.min(a,s),g=Math.max(a,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),i=Qe(e,o);if(r<0||i<0)return null;for(const a of e.merges??[]){const s=Ze(e,a.startRowId),l=Ze(e,a.endRowId),u=Qe(e,a.startColId),d=Qe(e,a.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&&i>=f&&i<=p)return a}return null}function Bh(e,n,o){const r=io(e,n,o);return r?r.startRowId===n&&r.startColId===o:!0}function Hh(e,n,o){const r=io(e,n,o);return r?!(r.startRowId===n&&r.startColId===o):!1}function Vh(e,n){const o=Ze(e,n.startRowId),r=Ze(e,n.endRowId),i=Qe(e,n.startColId),a=Qe(e,n.endColId);return{rowSpan:Math.abs(r-o)+1,colSpan:Math.abs(a-i)+1}}function za(e){const n=new Set(e.rows.map(i=>i.id)),o=new Set(e.columns.map(i=>i.id)),r=(e.merges??[]).filter(i=>n.has(i.startRowId)&&n.has(i.endRowId)&&o.has(i.startColId)&&o.has(i.endColId)&&La(e,i)!=null);return{...e,merges:r}}function Gh(e,n){const o=La(e,n);if(!o)throw new Error("invalid merge range (need at least 2 cells)");for(const r of e.merges??[])if(Bf(e,r,o))throw new Error("merge overlaps existing merge");return{...e,merges:[...e.merges??[],o]}}function Wh(e,n,o){const r=io(e,n,o);return r?{tab:{...e,merges:(e.merges??[]).filter(i=>i!==r)},removed:r}:{tab:e,removed:null}}function $a(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 qh(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 Kh(e){const n={};for(const o of e.columns)n[o.id]=Nn();return{...e,rows:[...e.rows,{id:Nt("r"),cells:n}]}}function Yh(e,n,o,r){const i=$a(e,n,o);return{...e,rows:e.rows.map(a=>{if(a.id!==i.rowId)return a;const s=a.cells[i.columnId]??Nn();return{...a,cells:{...a.cells,[i.columnId]:{v:r,...s.style?{style:s.style}:{}}}}})}}function Jh(e,n,o,r){const i=$a(e,n,o);return{...e,rows:e.rows.map(a=>{if(a.id!==i.rowId)return a;const s=a.cells[i.columnId]??Nn(),l=Of(s.style,r),u=l?{v:s.v,style:l}:{v:s.v};return{...a,cells:{...a.cells,[i.columnId]:u}}})}}function Xh(e,n,o){return{...e,columns:e.columns.map(r=>r.id===n?{...r,name:o}:r)}}function Zh(e,n){return za({...e,rows:e.rows.filter(o=>o.id!==n)})}function Qh(e,n){const o=[],r=new Set,i=[];for(const l of n){const u=Hf(e,l);if(!u){o.push(`unknown column: ${l}`);continue}r.has(u.id)||(r.add(u.id),i.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 a=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:za({...e,columns:a,rows:s}),removed:i,errors:o}}function Hf(e,n){const o=n.trim();if(!o)return null;const r=e.columns.find(s=>s.id===o);if(r)return r;const i=e.columns.find(s=>s.name===o);if(i)return i;const a=o.toLowerCase();return e.columns.find(s=>s.name.toLowerCase()===a)??null}function Vf(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 Ua(e,n=new Set){for(const o of e)o.type==="document"?n.add(o.path):(o.descDocumentId&&n.add(bl(o.path)),Ua(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=ja[n];return o?e(o):n}function Gf(e){const{tree:n,currentDomainId:o,selectedCreateParentPath:r,t:i,onDocCreated:a,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=Ua(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(i,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(i,re));return}if(S.has(ue)){h(i("pathExists"));return}const A=D?Hn(n,D)??void 0:void 0,ie=N==="sheet"?zf(tn()):"",oe=await $o({fileName:G,displayName:ce,content:ie,domainId:o,parentId:A,fileType:N});await s(),a(oe),u(null);return}const L=$r(l.draft);if(!L.ok){h(Po(i,L.message));return}const E=L.displayFile,O=E.replace(/\.md$/i,"");let $;try{$=Ur(No(D,E))}catch(ne){h(Je(i,ne));return}if(S.has($)){h(i("pathExists"));return}const V=D?Hn(n,D)??void 0:void 0,J=await $o({fileName:E,displayName:O,content:Vf(O),domainId:o,parentId:V});await s(),a(J),u(null);return}const P=_l(l.draft);if(!P.ok){h(Po(i,P.message));return}const _=Lo(P.display);if(!_){h(i("invalidFolderName"));return}const T=No(D,_);if(S.has(T)){h(i("folderExists"));return}const I=D?Hn(n,D)??void 0:void 0;await Rl({name:_,parentId:I,domainId:o}),await s(),u(null)}catch(P){h(Je(i,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 Wf(){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 Ri=40,qf=.75;function Kf(){return typeof window>"u"?96:Math.min(140,Math.max(96,Math.round(window.innerWidth*.28)))}function Yf(e,n,o){const r=!!(o!=null&&o.open),i=x.useRef(n),a=x.useRef(o==null?void 0:o.onClose);i.current=n,a.current=o==null?void 0:o.onClose,x.useEffect(()=>{if(!e)return;let s=null,l=0,u=0;const d=p=>{const g=p.touches[0];if(!g)return;const w=p.target;if(!(w instanceof Element&&w.closest(".mdocs-agent-fab-wrap"))){if(r){if(!a.current)return;s="close"}else{if(g.clientX>Kf())return;s="open"}l=g.clientX,u=g.clientY}},h=p=>{var v;if(!s)return;const g=p.touches[0];if(!g)return;const w=g.clientX-l,b=Math.abs(g.clientY-u);if(b>Math.abs(w)*qf&&b>24){s=null;return}if(s==="open"&&w>=Ri){s=null,i.current();return}s==="close"&&w<=-Ri&&(s=null,(v=a.current)==null||v.call(a))},m=()=>{s=null},f={passive:!0,capture:!0};return window.addEventListener("touchstart",d,f),window.addEventListener("touchmove",h,f),window.addEventListener("touchend",m,f),window.addEventListener("touchcancel",m,f),()=>{window.removeEventListener("touchstart",d,f),window.removeEventListener("touchmove",h,f),window.removeEventListener("touchend",m,f),window.removeEventListener("touchcancel",m,f)}},[e,r])}function Jf({open:e,onClose:n,onResolve:o,onForceOverwrite:r,forceBusy:i}){const{t:a}=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:a("conflictTitle")}),c.jsx("p",{className:"mdocs-conflict-modal-body",children:a("conflictBody")}),r?c.jsx("p",{className:"mdocs-conflict-modal-force-hint",children:a("conflictForceHint")}):null,c.jsxs("div",{className:"mdocs-conflict-modal-actions",children:[c.jsx("button",{type:"button",className:"primary",onClick:o,disabled:i,children:a("conflictResolve")}),r?c.jsx("button",{type:"button",className:"mdocs-conflict-force-btn",disabled:i,onClick:r,children:a(i?"conflictForceBusy":"conflictForce")}):null,c.jsx("button",{type:"button",className:"secondary",onClick:n,disabled:i,children:a("conflictClose")})]})]})}):null}function Oi({documentId:e,visitorId:n,visitorName:o,documentOwnerId:r,onClose:i}){const[a,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 a)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}},[a]),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 $l(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 Ul(e,{content:l,parentId:(d==null?void 0:d.commentId)||null,replyToVisitorId:d?((K=a.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 Bl(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(el,{size:18}),"评论 (",B,")"]}),c.jsx("button",{type:"button",onClick:i,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(Ma,{title:"删除评论",message:"确定要删除这条评论吗?",confirmLabel:"删除",danger:!0,onConfirm:()=>A(w),onCancel:()=>b(null)})]})}const Xf="mdocs-drafts",Zf=5,Ae="drafts";let Ba=0;const Qo=new Set;function ep(e){return Qo.add(e),()=>{Qo.delete(e)}}function tp(){return Ba}function Ha(e,n){Ba+=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(Xf,Zf);o.onupgradeneeded=r=>{const i=o.result;i.objectStoreNames.contains(Ae)||i.createObjectStore(Ae,{keyPath:"documentId"});const a=r.oldVersion;if(a>0&&a<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(a>0&&a<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 Qf(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 i=(r=e.localBaseCommitIdAtEditStart)==null?void 0:r.trim();i&&(o.localBaseCommitId=i)}(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,i)=>{const a=n.transaction(Ae,"readwrite");a.objectStore(Ae).put(o),a.oncomplete=()=>{Ha(o.documentId,!o.published),r()},a.onerror=()=>i(a.error)})}async function Re(e){const n=await on();return new Promise((o,r)=>{const a=n.transaction(Ae,"readonly").objectStore(Ae).get(e);a.onsuccess=()=>o(a.result),a.onerror=()=>r(a.error)})}async function Ao(e){const n=await on();return new Promise((o,r)=>{const i=n.transaction(Ae,"readwrite");i.objectStore(Ae).delete(e),i.oncomplete=()=>{Ha(e,!1),o()},i.onerror=()=>r(i.error)})}async function em(e){const n=await on();return new Promise((o,r)=>{const a=n.transaction(Ae,"readonly").objectStore(Ae).getAll();a.onsuccess=()=>{let s=a.result;e!=null&&e.skipFailed&&(s=s.filter(l=>!l.publishError)),o(s)},a.onerror=()=>r(a.error)})}async function tm(e,n){const o=await on();return new Promise((r,i)=>{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=()=>i(l.error)})}async function Mo(e){const n=await on();return new Promise((o,r)=>{const a=n.transaction(Ae,"readwrite").objectStore(Ae),s=a.get(e);s.onsuccess=()=>{const l=s.result;l&&a.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 nm(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 om(e,n,o,r){const i=(n==null?void 0:n.displayName)||e("unknownTitle");if(o===nn.SYNC_HEAD_MISSING)return e("draftPublishFailedSyncHead",{name:i});if(o===nn.DOC_NOT_FOUND)return e("draftPublishFailedNotice",{name:i});const a=r instanceof et||r instanceof Error&&r.message?r.message:o;return e("draftPublishFailedGeneric",{name:i,reason:a})}async function rm(e,n,o){const r=nm(n);throw await tm(e,r),n instanceof Cn?n:new Cn(r,{cause:n})}function im(e,n){const o=x.useRef(n);o.current=n,x.useEffect(()=>{if(!e)return;const r=3e4,i=1e4,a=async()=>{const l=await em({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)}};a();const s=setInterval(a,i);return()=>clearInterval(s)},[e])}const am=1e4;function sm(e,n){const[o,r]=x.useState(null),[i,a]=x.useState("up_to_date");return x.useEffect(()=>{if(!e){r(null),a("up_to_date");return}let l=!1;const u=e;async function d(){try{const m=await Ml(u,n??void 0);if(l)return;r(m.headCommitId),a(m.status)}catch{}}d();const h=window.setInterval(()=>void d(),am);return()=>{l=!0,window.clearInterval(h)}},[e,n]),{remoteCommitId:o,syncStatus:i,syncBehind:!!(n&&o&&n!==o)||i==="behind"}}function Fi(e){return e.trim()}function lm(e){return e.trim()}const cm=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".ico",".bmp",".jfif",".pjpeg"]);function dm(e){const n=e.split("/").pop()??"",o=n.lastIndexOf(".");return o<=0?"":n.slice(o).toLowerCase()}function um(e,n,o){let r,i;try{r=new URL(o),i=new URL(e,o)}catch{return null}if(i.origin!==r.origin||!i.pathname.startsWith("/api/assets/")||cm.has(dm(i.pathname)))return null;const a=n==null?void 0:n.trim();return a&&!i.searchParams.has("name")&&i.searchParams.set("name",a),i.toString()}function fm(){const e=n=>{if(n.button!==0)return;const r=n.composedPath().find(a=>a instanceof HTMLAnchorElement);if(!r)return;const i=um(r.href,r.getAttribute("download"),window.location.href);i&&(n.preventDefault(),n.stopPropagation(),window.location.assign(i))};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"},mm="/assets/mdocs-logo-Dsv_2t6v.svg",hm=x.lazy(()=>Pt(()=>import("./DocumentEditor-C_TFaCan.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])).then(e=>({default:e.DocumentEditor}))),pm=x.lazy(()=>Pt(()=>import("./HtmlEditor-CYPTi1_L.js"),__vite__mapDeps([16,1,12,13,14,15,2,3,6,17])).then(e=>({default:e.HtmlEditor}))),gm=x.lazy(()=>Pt(()=>import("./SheetEditor-BOF-OgqU.js"),__vite__mapDeps([18,1,12,13,14,7,11,2,3,6,19])).then(e=>({default:e.SheetEditor}))),ym=x.lazy(()=>Pt(()=>import("./SettingsPage-C2SYz-8K.js"),__vite__mapDeps([20,1,14,9,2,3,6])).then(e=>({default:e.SettingsPage}))),vm=x.lazy(()=>Pt(()=>import("./AgentChatPanel-BMOzVvwA.js"),__vite__mapDeps([21,1,9,8,7,2,3,6])).then(e=>({default:e.AgentChatPanel}))),bm=x.lazy(()=>Pt(()=>import("./AiWriteWorkbench-ob4AeDFt.js"),__vite__mapDeps([22,1,21,9,8,7,2,3,6])).then(e=>({default:e.AiWriteWorkbench}))),xm=x.lazy(()=>Pt(()=>import("./MergeView-FPF3k11v.js"),__vite__mapDeps([23,1,4,5,2,3,6,7,8,9,13])).then(e=>({default:e.MergeView})));function wm(e,n){try{const o=new Intl.RelativeTimeFormat(n,{numeric:"auto"}),r=Date.now()-new Date(e).getTime(),i=Math.floor(r/6e4),a=Math.floor(i/60),s=Math.floor(a/24);return s>30?o.format(-Math.floor(s/30),"month"):s>0?o.format(-s,"day"):a>0?o.format(-a,"hour"):i>0?o.format(-i,"minute"):o.format(-Math.floor(r/1e3),"second")}catch{return e.slice(0,10)}}async function Ro(e,n,o,r){const i=await nr();n(i);const a=localStorage.getItem("mdocs.currentDomainId"),l=a&&i.some(u=>u.domainId===a)?a:ql(i,e);o(l),await r(l)}function Li(){const{t:e,lang:n,setLang:o}=Ve(),[r,i]=x.useState("loading"),[a,s]=x.useState(()=>localStorage.getItem("mdocs.sidebarCollapsed")==="true"),l=Wf(),[u,d]=x.useState(!1),h=()=>{if(l){d(R=>!R);return}const y=!a;s(y),localStorage.setItem("mdocs.sidebarCollapsed",String(y))};x.useEffect(()=>{l||d(!1)},[l]),x.useEffect(()=>fm(),[]);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}=ls(),B=cs(),[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}=sm(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");Yf(l&&sn==="docs",()=>d(!0),{open:u,onClose:()=>d(!1)});const[Fe,qe]=x.useState(!1),[Tn,xt]=x.useState(!1),[Wt,An]=Nf(),k=x.useRef(null),[j,z]=x.useState(!1),[F,q]=x.useState(null),X=x.useRef(void 0),te=x.useRef(void 0);im(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=lm(y.markdown):le=(await vo({content:y.markdown,from:"markdown",to:"lexical"})).content,await Qf({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),i("ready")}catch(y){if(y instanceof et&&y.status===401){i("needsRegister");return}be(Je(e,y)),i("needsRegister")}}async function _t(y,R){const M=await Dl(y,R);v(M.visitor),D(M.visitor.visitorId),_(M.recoveryCode),Vn(M.visitor.visitorId),await Ro(M.visitor.visitorId,L,O,fe),i("ready")}async function dt(y){const R=await Wr();v(R),await Ro(R.visitorId,L,O,fe),i("ready")}async function fe(y){const M=await Al(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:Ga,openNewDocumentModal:dn,openNewFolderModal:vr,submitCreateModal:Wa}=Gf({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}),[qa,Mn]=x.useState(!1),[Ka,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[Ya,un]=x.useState(!1),[Ot,br]=x.useState([]),[lo,xr]=x.useState(""),[jn,wr]=x.useState(""),[Ja,_r]=x.useState(new Set);async function Xa(){try{const y=await Ll();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]),Za=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 Qa(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 es(){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 Qa(M,y,R,le,Ie.details),Ie}})}async function ts(){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 ts()}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 ns(y,R,M){try{await rm(y,R,M)}catch(W){if(!(W instanceof Cn))throw W;const ee=M??await Re(y);throw me(om(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 ns(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 os(y,R){try{const M=await El(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 rs(){if(xe)try{xe.type==="document"?(await jl(xe.id),(A==null?void 0:A.documentId)===xe.id&&(ie(null),re(null),Me(""),B("/"))):xe.type==="folder"&&(await Ol(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(Kl,{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(ym,{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":a?" mdocs-sidebar-collapsed":""),children:[c.jsxs("header",{className:"mdocs-sidebar-header",children:[c.jsxs("div",{className:"mdocs-brand",children:[c.jsx("img",{src:mm,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":a?"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}):a?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(Ls,{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(dl,{size:14,strokeWidth:1.5}),e("sheetDocument")]})]}),c.jsxs("button",{type:"button",className:"mdocs-sidebar-create-btn",onClick:()=>{V(!1),vr()},children:[c.jsx(qs,{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(Jl,{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:os,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(""),Xa()},style:{background:"none",border:"none",cursor:"pointer",padding:"6px",color:"var(--mdocs-text-muted, #999)",fontSize:"1rem",lineHeight:1,borderRadius:4},children:c.jsx(ll,{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(Zs,{size:16,strokeWidth:1.5})})]})]}),c.jsxs("main",{className:"mdocs-main",children:[(G==null?void 0:G.kind)==="graph"?c.jsx(xf,{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(gm,{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(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(),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(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,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(Os,{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(Gs,{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:Aa,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(_f,{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(Jf,{open:Tt,onClose:()=>vt(!1),onResolve:()=>{vt(!1),nt(!0)},onForceOverwrite:b&&A&&b.visitorId===A.ownerVisitorId?()=>void es():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(xm,{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(Pf,{title:e("error"),message:Ce,onClose:()=>be(null)})]}),qa&&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:()=>{Cl(),ie(null),re(null),v(null),I([]),Mn(!1),i("needsRegister")},children:"确认退出"})]})]})}),Ya&&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")}),Za.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=Ja.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?"":wm(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(js,{size:14,strokeWidth:1.5})}),c.jsx("button",{type:"button",className:"mdocs-tooltip","data-tooltip":e("bookmarkRemove"),onClick:async()=>{try{await zl(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(wf,{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(Ma,{title:xe.type==="folder"?"删除文件夹":"删除文档",message:xe.type==="folder"?`确定要删除「${xe.name}」及其下的所有文档和子文件夹吗?此操作不可撤销。`:`确定要删除「${xe.name}」吗?`,confirmLabel:"删除",cancelLabel:"取消",onConfirm:rs,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:Wa,className:"mdocs-dialog-form",children:[c.jsxs("label",{className:"mdocs-dialog-label",children:[Kt.kind==="document"?e("fileNameLabel"):e("folderNameLabel"),c.jsx("input",{ref:Ga,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(Yl,{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(Df,{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(vm,{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:Cf(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(bm,{open:j,initialMarkdown:F.markdown,documentId:F.documentId,displayName:F.displayName,onClose:()=>{z(!1),q(null)},onComplete:Pe})}):null,c.jsx(jf,{open:Ka,domains:N,onDomainsChange:L,onClose:()=>so(!1),onOpenDocument:y=>{l&&d(!1),ot("docs"),Q(()=>B(`/doc/${y}`))}})]})}const _m=x.lazy(()=>Pt(()=>import("./PlaygroundPage-Bt53Sr06.js"),__vite__mapDeps([24,1,4,5,2,3,6,7,8,9,10,11])).then(e=>({default:e.PlaygroundPage})));function Im(){return c.jsxs(ds,{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(_m,{})})})]})}function km(){const{pathname:e,hash:n,search:o,origin:r}=window.location,i="/",a=i.endsWith("/")?i.slice(0,-1):i;let s=e;a&&s.startsWith(a)&&(s=s.slice(a.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=i.endsWith("/")?i:`${i}/`;window.location.replace(`${r}${h}${o}#/doc/${d}`)}km();const Va=document.getElementById("root");if(!Va)throw new Error("root element missing");us.createRoot(Va).render(c.jsx(zi.StrictMode,{children:c.jsx(ms,{motion:Cs,children:c.jsx(hs,{children:c.jsx(yl,{children:c.jsx(fs,{children:c.jsx(Im,{})})})})})}));export{el as $,Xh as A,Qh as B,Os as C,rt as D,Hh as E,Bh as F,Vh as G,Yh as H,Zh as I,$h as J,Lh as K,zh as L,Ma as M,er as N,Uh as O,Uf as P,Jh as Q,Gh as R,ll as S,Wh as T,Wl as U,Or as V,_f as W,zt as X,Fr as Y,$s as Z,Aa as _,Re as a,jh as a$,nr as a0,Al as a1,Jl as a2,$o as a3,Je as a4,em as a5,om as a6,Mo as a7,Cn as a8,jm as a9,rh as aA,ih as aB,Wf as aC,Yf as aD,ho as aE,Er as aF,oh as aG,Ll as aH,lh as aI,mm as aJ,Rr as aK,Ui as aL,Gi as aM,zm as aN,Lm as aO,nh as aP,kh as aQ,Ph as aR,Th as aS,Nh as aT,Pi as aU,gh as aV,vh as aW,Mh as aX,Gn as aY,Fo as aZ,hf as a_,Tl as aa,Eh as ab,Vm as ac,Hm as ad,Bm as ae,Um as af,qm as ag,Em as ah,Om as ai,Rm as aj,Fm as ak,Wm as al,Gm as am,Km as an,Ym as ao,Jm as ap,ch as aq,Wr as ar,dh as as,qr as at,uh as au,fh as av,mh as aw,hh as ax,ph as ay,Fl as az,tp as b,yh as b0,bh as b1,xh as b2,Ah as b3,Dh as b4,Ih as b5,_h as b6,wh as b7,Ch as b8,Sh as b9,Xt as ba,Xm as bb,vo as bc,yo as bd,On as be,Ve as c,Ao as d,ah as e,$m as f,po as g,Tm as h,sh as i,Zm as j,eh as k,kn as l,Qm as m,th as n,ve as o,Fh as p,pr as q,zl as r,ep as s,Rh as t,Qf as u,zf as v,Oh as w,Kh as x,qh as y,io as z};