@inkeep/open-knowledge 0.0.0-dev-20260422103101 → 0.0.0-dev-20260422171440

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 (51) hide show
  1. package/dist/cli.mjs +4 -4
  2. package/dist/constants-BsBTeRCL.mjs +2 -0
  3. package/dist/index.mjs +1 -1
  4. package/dist/init-B6Ufq752.mjs +1 -0
  5. package/dist/{init-d9wf2ATC.mjs → init-CM66xil2.mjs} +3 -3
  6. package/dist/{init-BwRnDaUa.mjs → init-DrSlBesI.mjs} +2 -2
  7. package/dist/init-DrW3fwT1.mjs +1 -0
  8. package/dist/{loader-X2UYTNqe.mjs → loader-CYvz6nef.mjs} +2 -2
  9. package/dist/loader-CiFIlkkp.mjs +1 -0
  10. package/dist/{paths-DYcYIqx2.mjs → paths-D6Xgg5WG.mjs} +2 -2
  11. package/dist/paths-Szv_tZj8.mjs +1 -0
  12. package/dist/{preview-CG6UE3J0.mjs → preview-CRZPJMbg.mjs} +2 -2
  13. package/dist/preview-CT7B_1hJ.mjs +1 -0
  14. package/dist/public/assets/GraphPanel-DqKpB1Tz.js +46 -0
  15. package/dist/public/assets/SourceEditor-CV7AqTwb.js +3 -0
  16. package/dist/public/assets/clipboard-D_fdmuyh.js +80 -0
  17. package/dist/public/assets/dist-BXy0xauE.js +1 -0
  18. package/dist/public/assets/dist-BZpbe8U5.js +1 -0
  19. package/dist/public/assets/dist-C0ssNH5f.js +9 -0
  20. package/dist/public/assets/dist-C5cYj6hk.js +1 -0
  21. package/dist/public/assets/dist-CYCPSCCQ.js +1 -0
  22. package/dist/public/assets/dist-CtX4SukE.js +13 -0
  23. package/dist/public/assets/dist-ztaVC3x4.js +1 -0
  24. package/dist/public/assets/index-Cc7W6NSO.js +17 -0
  25. package/dist/public/assets/panel-DFRQJTBG.js +240 -0
  26. package/dist/public/assets/toggle-group-D4a_dmpa.js +1 -0
  27. package/dist/public/assets/w3c-keyname-DLDSJn4E.js +1 -0
  28. package/dist/public/index.html +8 -4
  29. package/dist/src-vp93REiw.mjs +1 -0
  30. package/dist/start-CrLEzGrk.mjs +1 -0
  31. package/dist/{start-DHi9coRg.mjs → start-Dtc5s628.mjs} +2 -2
  32. package/package.json +1 -1
  33. package/dist/constants-BVlXdKF2.mjs +0 -2
  34. package/dist/init-BEXFKO6K.mjs +0 -1
  35. package/dist/init-CXKU8pCL.mjs +0 -1
  36. package/dist/loader-Ck0aVV42.mjs +0 -1
  37. package/dist/paths-BIn1dA04.mjs +0 -1
  38. package/dist/preview-CWlYVyE-.mjs +0 -1
  39. package/dist/public/assets/dist-4KUZ8qw_.js +0 -1
  40. package/dist/public/assets/dist-Bvlmbwcy.js +0 -1
  41. package/dist/public/assets/dist-CWsgPYc6.js +0 -13
  42. package/dist/public/assets/dist-D5yBWykF.js +0 -1
  43. package/dist/public/assets/dist-DcQNS1eS.js +0 -1
  44. package/dist/public/assets/dist-DvCIPVI0.js +0 -9
  45. package/dist/public/assets/dist-csWIvcml.js +0 -1
  46. package/dist/public/assets/dist-saWP7AQm.js +0 -1
  47. package/dist/public/assets/index-Baf8TpjF.js +0 -381
  48. package/dist/src-2kqr_sLQ.mjs +0 -1
  49. package/dist/start-BqWssZGZ.mjs +0 -1
  50. /package/dist/public/assets/{go-B8kgVkyB.js → go-IODVg4Ok.js} +0 -0
  51. /package/dist/public/assets/{shell-BsPlf5L6.js → shell-COsTRxlr.js} +0 -0
@@ -0,0 +1,3 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-BZpbe8U5.js","assets/dist-CtX4SukE.js","assets/panel-DFRQJTBG.js","assets/w3c-keyname-DLDSJn4E.js","assets/dist-ztaVC3x4.js","assets/dist-BXy0xauE.js","assets/dist-C0ssNH5f.js","assets/dist-C5cYj6hk.js","assets/dist-CYCPSCCQ.js"])))=>i.map(i=>d[i]);
2
+ import{C as e,J as t,Wn as n,Y as r,bn as i,gn as a,pn as o,q as s,v as c,xn as l}from"./panel-DFRQJTBG.js";import{A as u,Ct as d,F as f,G as p,I as m,J as h,K as g,L as _,P as v,Q as ee,St as y,Tt as b,_ as te,_t as x,a as S,bt as C,c as ne,d as re,et as ie,f as ae,g as oe,gt as w,h as T,ht as E,kt as D,l as se,m as ce,p as le,pt as ue,q as de,s as fe,t as pe,u as me,v as he,vt as O,wt as ge,xt as k,yt as A}from"./clipboard-D_fdmuyh.js";import{At as _e,Dt as j,Et as ve,N as M,Nt as N,Pt as P,Q as ye,Tt as F,Y as I,Z as L,a as R,bt as z,ft as B,jt as V,lt as be,q as H,wt as xe}from"./dist-CtX4SukE.js";var U=n(l(),1),Se=o(),Ce=class e{constructor(e,t){this.yanchor=e,this.yhead=t}toJSON(){return{yanchor:C(this.yanchor),yhead:C(this.yhead)}}static fromJSON(t){return new e(O(t.yanchor),O(t.yhead))}},we=class{constructor(e,t){this.ytext=e,this.awareness=t,this.undoManager=new E(e)}toYPos(e,t=0){return A(this.ytext,e,t)}fromYPos(e){let t=x(O(e),this.ytext.doc);if(t==null||t.type!==this.ytext)throw Error(`[y-codemirror] The position you want to retrieve was created by a different document`);return{pos:t.index,assoc:t.assoc}}toYRange(e){let t=e.assoc;return new Ce(this.toYPos(e.anchor,t),this.toYPos(e.head,t))}fromYRange(e){let t=this.fromYPos(e.yanchor),n=this.fromYPos(e.yhead);return t.pos===n.pos?F.cursor(n.pos,n.assoc):F.range(t.pos,n.pos)}},W=j.define({combine(e){return e[e.length-1]}}),G=z.define(),Te=class{constructor(e){this.view=e,this.conf=e.state.facet(W),this._observer=(t,n)=>{if(n.origin!==this.conf){let n=t.delta,r=[],i=0;for(let e=0;e<n.length;e++){let t=n[e];t.insert==null?t.delete==null?i+=t.retain:(r.push({from:i,to:i+t.delete,insert:``}),i+=t.delete):r.push({from:i,to:i,insert:t.insert})}e.dispatch({changes:r,annotations:[G.of(this.conf)]})}},this._ytext=this.conf.ytext,this._ytext.observe(this._observer)}update(e){if(!e.docChanged||e.transactions.length>0&&e.transactions[0].annotation(G)===this.conf)return;let t=this.conf.ytext;t.doc.transact(()=>{let n=0;e.changes.iterChanges((e,r,i,a,o)=>{let s=o.sliceString(0,o.length,`
3
+ `);e!==r&&t.delete(e+n,r-e),s.length>0&&t.insert(e+n,s),n+=s.length-(r-e)})},this.conf)}destroy(){this._ytext.unobserve(this._observer)}},Ee=L.fromClass(Te),De=I.baseTheme({".cm-ySelection":{},".cm-yLineSelection":{padding:0,margin:`0px 2px 0px 4px`},".cm-ySelectionCaret":{position:`relative`,borderLeft:`1px solid black`,borderRight:`1px solid black`,marginLeft:`-1px`,marginRight:`-1px`,boxSizing:`border-box`,display:`inline`},".cm-ySelectionCaretDot":{borderRadius:`50%`,position:`absolute`,width:`.4em`,height:`.4em`,top:`-.2em`,left:`-.2em`,backgroundColor:`inherit`,transition:`transform .3s ease-in-out`,boxSizing:`border-box`},".cm-ySelectionCaret:hover > .cm-ySelectionCaretDot":{transformOrigin:`bottom center`,transform:`scale(0)`},".cm-ySelectionInfo":{position:`absolute`,top:`-1.05em`,left:`-1px`,fontSize:`.75em`,fontFamily:`serif`,fontStyle:`normal`,fontWeight:`normal`,lineHeight:`normal`,userSelect:`none`,color:`white`,paddingLeft:`2px`,paddingRight:`2px`,zIndex:101,transition:`opacity .3s ease-in-out`,backgroundColor:`inherit`,opacity:0,transitionDelay:`0s`,whiteSpace:`nowrap`},".cm-ySelectionCaret:hover > .cm-ySelectionInfo":{opacity:1,transitionDelay:`0s`}}),Oe=z.define(),ke=class extends ye{constructor(e,t){super(),this.color=e,this.name=t}toDOM(){return k(`span`,[d(`class`,`cm-ySelectionCaret`),d(`style`,`background-color: ${this.color}; border-color: ${this.color}`)],[y(`⁠`),k(`div`,[d(`class`,`cm-ySelectionCaretDot`)]),y(`⁠`),k(`div`,[d(`class`,`cm-ySelectionInfo`)],[y(this.name)]),y(`⁠`)])}eq(e){return e.color===this.color}compare(e){return e.color===this.color}updateDOM(){return!1}get estimatedHeight(){return-1}ignoreEvent(){return!0}},Ae=class{constructor(e){this.conf=e.state.facet(W),this._listener=({added:t,updated:n,removed:r},i,a)=>{t.concat(n).concat(r).findIndex(e=>e!==this.conf.awareness.doc.clientID)>=0&&e.dispatch({annotations:[Oe.of([])]})},this._awareness=this.conf.awareness,this._awareness.on(`change`,this._listener),this.decorations=_e.of([])}destroy(){this._awareness.off(`change`,this._listener)}update(e){let t=this.conf.ytext,n=t.doc,r=this.conf.awareness,i=[],a=this.conf.awareness.getLocalState();if(a!=null){let n=e.view.hasFocus&&e.view.dom.ownerDocument.hasFocus(),i=n?e.state.selection.main:null,o=a.cursor==null?null:O(a.cursor.anchor),s=a.cursor==null?null:O(a.cursor.head);if(i!=null){let e=A(t,i.anchor),n=A(t,i.head);(a.cursor==null||!w(o,e)||!w(s,n))&&r.setLocalStateField(`cursor`,{anchor:e,head:n})}else a.cursor!=null&&n&&r.setLocalStateField(`cursor`,null)}r.getStates().forEach((a,o)=>{if(o===r.doc.clientID)return;let s=a.cursor;if(s==null||s.anchor==null||s.head==null)return;let c=x(s.anchor,n),l=x(s.head,n);if(c==null||l==null||c.type!==t||l.type!==t)return;let{color:u=`#30bced`,name:d=`Anonymous`}=a.user||{},f=a.user&&a.user.colorLight||u+`33`,p=b(c.index,l.index),m=ge(c.index,l.index),h=e.view.state.doc.lineAt(p),g=e.view.state.doc.lineAt(m);if(h.number===g.number)i.push({from:p,to:m,value:H.mark({attributes:{style:`background-color: ${f}`},class:`cm-ySelection`})});else{i.push({from:p,to:h.from+h.length,value:H.mark({attributes:{style:`background-color: ${f}`},class:`cm-ySelection`})}),i.push({from:g.from,to:m,value:H.mark({attributes:{style:`background-color: ${f}`},class:`cm-ySelection`})});for(let t=h.number+1;t<g.number;t++){let n=e.view.state.doc.line(t).from;i.push({from:n,to:n,value:H.line({attributes:{style:`background-color: ${f}`,class:`cm-yLineSelection`}})})}}i.push({from:l.index,to:l.index,value:H.widget({side:l.index-c.index>0?-1:1,block:!1,widget:new ke(u,d)})})}),this.decorations=H.set(i,!0)}},je=L.fromClass(Ae,{decorations:e=>e.decorations}),Me=class{constructor(e){this.undoManager=e}addTrackedOrigin(e){this.undoManager.addTrackedOrigin(e)}removeTrackedOrigin(e){this.undoManager.removeTrackedOrigin(e)}undo(){return this.undoManager.undo()!=null}redo(){return this.undoManager.redo()!=null}},K=j.define({combine(e){return e[e.length-1]}});z.define();var Ne=class{constructor(e){this.view=e,this.conf=e.state.facet(K),this._undoManager=this.conf.undoManager,this.syncConf=e.state.facet(W),this._beforeChangeSelection=null,this._mux=ue(),this._onStackItemAdded=({stackItem:e,changedParentTypes:t})=>{t.has(this.syncConf.ytext)&&this._beforeChangeSelection&&!e.meta.has(this)&&e.meta.set(this,this._beforeChangeSelection)},this._onStackItemPopped=({stackItem:t})=>{let n=t.meta.get(this);if(n){let t=this.syncConf.fromYRange(n);e.dispatch(e.state.update({selection:t,effects:[I.scrollIntoView(t)]})),this._storeSelection()}},this._storeSelection=()=>{this._beforeChangeSelection=this.syncConf.toYRange(this.view.state.selection.main)},this._undoManager.on(`stack-item-added`,this._onStackItemAdded),this._undoManager.on(`stack-item-popped`,this._onStackItemPopped),this._undoManager.addTrackedOrigin(this.syncConf)}update(e){e.selectionSet&&(e.transactions.length===0||e.transactions[0].annotation(G)!==this.syncConf)&&this._storeSelection()}destroy(){this._undoManager.off(`stack-item-added`,this._onStackItemAdded),this._undoManager.off(`stack-item-popped`,this._onStackItemPopped),this._undoManager.removeTrackedOrigin(this.syncConf)}},Pe=L.fromClass(Ne),Fe=({state:e,dispatch:t})=>e.facet(K).undo()||!0,Ie=({state:e,dispatch:t})=>e.facet(K).redo()||!0,Le=(e,t,{undoManager:n=new E(e)}={})=>{let r=new we(e,t),i=[W.of(r),Ee];return t&&i.push(De,je),n!==!1&&i.push(K.of(new Me(n)),Pe,I.domEventHandlers({beforeinput(e,t){return e.inputType===`historyUndo`?Fe(t):e.inputType===`historyRedo`?Ie(t):!1}})),i},Re=[R.of({name:`javascript`,alias:[`js`,`jsx`],extensions:[`js`,`mjs`,`cjs`,`jsx`],load:async()=>ce({jsx:!0})}),R.of({name:`typescript`,alias:[`ts`,`tsx`],extensions:[`ts`,`mts`,`cts`,`tsx`],load:async()=>ce({typescript:!0,jsx:!0})}),R.of({name:`json`,alias:[`jsonc`],extensions:[`json`,`jsonc`],load:()=>D(()=>import(`./dist-BZpbe8U5.js`).then(e=>e.json()),__vite__mapDeps([0,1,2,3,4]))}),R.of({name:`yaml`,alias:[`yml`],extensions:[`yaml`,`yml`],load:()=>D(()=>import(`./dist-BXy0xauE.js`).then(e=>e.yaml()),__vite__mapDeps([5,1,2,3,4]))}),R.of({name:`css`,alias:[`scss`,`less`],extensions:[`css`,`scss`,`less`],load:async()=>T()}),R.of({name:`html`,alias:[`htm`],extensions:[`html`,`htm`],load:async()=>le()}),R.of({name:`python`,alias:[`py`],extensions:[`py`,`pyw`],load:()=>D(()=>import(`./dist-C0ssNH5f.js`).then(e=>e.python()),__vite__mapDeps([6,7,1,2,3,4]))}),R.of({name:`rust`,alias:[`rs`],extensions:[`rs`],load:()=>D(()=>import(`./dist-CYCPSCCQ.js`).then(e=>e.rust()),__vite__mapDeps([8,1,2,3,4]))}),R.of({name:`markdown`,alias:[`md`,`mdx`],extensions:[`md`,`mdx`,`markdown`],load:async()=>re()}),R.of({name:`bash`,alias:[`sh`,`shell`,`zsh`],extensions:[`sh`,`bash`,`zsh`],load:async()=>{let[{StreamLanguage:e,LanguageSupport:t},{shell:n}]=await Promise.all([D(()=>import(`./dist-CtX4SukE.js`).then(e=>e.m),__vite__mapDeps([1,2,3])),D(()=>import(`./shell-COsTRxlr.js`),[])]);return new t(e.define(n))}}),R.of({name:`go`,alias:[`golang`],extensions:[`go`],load:async()=>{let[{StreamLanguage:e,LanguageSupport:t},{go:n}]=await Promise.all([D(()=>import(`./dist-CtX4SukE.js`).then(e=>e.m),__vite__mapDeps([1,2,3])),D(()=>import(`./go-IODVg4Ok.js`),[])]);return new t(e.define(n))}})],ze=N.define(),Be=N.define(),Ve=H.line({class:`agent-flash`}),He=P.define({create(){return H.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)if(n.is(ze)){let{from:r,to:i}=n.value,a=[];for(let e=r;e<=i;){let n=t.state.doc.lineAt(e);a.push(Ve.range(n.from)),e=n.to+1}e=e.update({add:a,sort:!0})}else n.is(Be)&&(e=H.none);return e},provide:e=>I.decorations.from(e)});function Ue(e){let n=e.getMap(`activity`);return[He,L.define(e=>{let i=0,a=Date.now(),o=null,c=null,l=!1;function u(){let t=e.state.doc.length;t!==0&&(l||(e.dispatch({effects:ze.of({from:0,to:t})}),c&&clearTimeout(c),c=setTimeout(()=>{c=null,!l&&e.dispatch({effects:Be.of(null)})},s)))}let d=e=>{if(t(n),!r(n,a))return;a=Date.now();let s=Date.now();if(s-i<500){if(!o){let e=500-(s-i);o=setTimeout(()=>{o=null,i=Date.now(),u()},e)}return}i=s,u()};n.observe(d);let f=()=>{document.visibilityState===`visible`?r(n,a)&&(a=Date.now(),i=Date.now(),u()):a=Date.now()};return document.addEventListener(`visibilitychange`,f),{update(e){},destroy(){l=!0,n.unobserve(d),document.removeEventListener(`visibilitychange`,f),o&&=(clearTimeout(o),null),c&&=(clearTimeout(c),null)}}})]}var q=/\[([^\]\n]*)\]\((<[^>\n]+>|[^)\s\n]+)(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?\)/g,We=H.mark({class:`cm-md-internal-link`});function Ge(e,t){return t>0&&e[t-1]===`!`}function Ke(e){let t=e[2]??``;return t.startsWith(`<`)&&t.endsWith(`>`)?t.slice(1,-1):t}function qe(e){let t=new V;for(let{from:n,to:r}of e.visibleRanges){let i=e.state.doc.sliceString(n,r);q.lastIndex=0;let a=q.exec(i);for(;a!==null;){let e=Ge(i,a.index)?null:p(Ke(a));e&&e.kind!==`external`&&t.add(n+a.index,n+a.index+a[0].length,We),a=q.exec(i)}}return t.finish()}var Je=L.fromClass(class{decorations;constructor(e){this.decorations=qe(e)}update(e){(e.docChanged||e.viewportChanged)&&(this.decorations=qe(e.view))}},{decorations:e=>e.decorations}),Ye=I.domEventHandlers({mousedown(e,t){if(!e.ctrlKey&&!e.metaKey)return!1;let n=t.posAtCoords({x:e.clientX,y:e.clientY});if(n===null)return!1;let r=t.state.doc.lineAt(n);q.lastIndex=0;let i=q.exec(r.text);for(;i!==null;){let t=r.from+i.index,a=t+i[0].length;if(n>=t&&n<=a){let t=Ge(r.text,i.index)?null:p(Ke(i));if(t&&t.kind!==`external`)return e.preventDefault(),t.kind===`doc`&&h(e)?(de(t),!0):(g(t),!0)}i=q.exec(r.text)}return!1}}),Xe=I.theme({".cm-md-internal-link":{color:`oklch(52.7% 0.154 228.4)`,fontWeight:`500`},".cm-md-internal-link:hover":{textDecoration:`underline`,cursor:`pointer`}});function Ze(){return[Je,Ye,Xe]}var Qe=5e3,J=null,$e=0,et=null,Y=new Map;async function tt(){let e=Date.now();return J&&e-$e<Qe?J:(J=await f(),$e=e,et=ot(J),J)}async function nt(e){let t=Date.now(),n=Y.get(e);if(n!==void 0&&t-n.time<Qe)return n.headings;try{let n=await v(e);return Y.set(e,{headings:n,time:t}),n}catch(n){return console.warn(`[wiki-link-source] /api/page-headings fetch failed:`,n),Y.set(e,{headings:[],time:t}),[]}}var X=/\[\[[^\]]*?\]\]/g,rt=H.mark({class:`cm-wiki-link`}),it=H.mark({class:`cm-wiki-link cm-wiki-link-broken`});function at(e){let t=new Set;for(let n of e)t.add(n.docName.toLowerCase()),n.title&&t.add(n.title.toLowerCase());return t}function ot(e){let t=at(e);for(let n of e){let e=n.docName.split(`/`);e.pop();let r=``;for(let n of e)r=r?`${r}/${n}`:n,t.add(r.toLowerCase())}return t}function st(e){return e.split(/[#|]/)[0].trim().toLowerCase()}function ct(e){let t=new V,n=J?et:null;for(let{from:r,to:i}of e.visibleRanges){let a=e.state.doc.sliceString(r,i);X.lastIndex=0;let o=X.exec(a);for(;o!==null;){let e=rt;if(n){let t=st(o[0].slice(2,-2));t&&!n.has(t)&&(e=it)}t.add(r+o.index,r+o.index+o[0].length,e),o=X.exec(a)}}return t.finish()}var lt=L.fromClass(class{decorations;cacheWarmAtBuild;constructor(e){this.cacheWarmAtBuild=J!==null,this.decorations=ct(e),this.cacheWarmAtBuild||this.warmCache(e)}update(e){let t=J!==null;(e.docChanged||e.viewportChanged||!this.cacheWarmAtBuild&&t)&&(this.cacheWarmAtBuild=t,this.decorations=ct(e.view))}warmCache(e){tt().then(()=>{try{e.dispatch({})}catch{}}).catch(e=>{console.warn(`[wiki-link-source] warmCache fetch failed:`,e)})}},{decorations:e=>e.decorations}),Z=/\[\[([^[\]|#]+?)(?:#([^\]|]+?))?(?:\|([^\]]+?))?\]\]/g,ut=I.domEventHandlers({mousedown(e,t){if(!e.ctrlKey&&!e.metaKey)return!1;let n=t.posAtCoords({x:e.clientX,y:e.clientY});if(n===null)return!1;let r=t.state.doc.lineAt(n);Z.lastIndex=0;let i=Z.exec(r.text);for(;i!==null;){let t=r.from+i.index,a=t+i[0].length;if(n>=t&&n<=a){let t=i[1]?.trim(),n=i[2]?.trim()||null;if(t){let r=c(t,n);if(!r)return!1;e.preventDefault(),r.kind===`external`?window.open(r.url,`_blank`,`noopener,noreferrer`):h(e)?de(r):window.location.hash=r.anchor?`#/${r.docName}?anchor=${encodeURIComponent(r.anchor)}`:`#/${r.docName}`}return!0}i=Z.exec(r.text)}return!1}});async function dt(e){let t=e.state.doc.sliceString(0,e.pos).match(/\[\[([^\]]*)$/);if(!t)return null;let n=t[1],r=e.pos-n.length,i=n.indexOf(`#`);if(i>0){let e=n.slice(0,i),t=n.slice(i+1),a=r+i+1,o=await nt(e);if(!o.length)return null;let s=m(o,t);return s.length?{from:a,filter:!1,options:s.map(e=>({label:e.text,detail:`H${e.level}`,apply(t,n,r,i){let a=t.state.doc.sliceString(i,i+2)===`]]`?``:`]]`;t.dispatch({changes:{from:r,to:i,insert:e.slug+a},selection:{anchor:r+e.slug.length+a.length}})}}))}:null}return{from:r,filter:!1,options:_(await tt().catch(e=>(console.warn(`[wiki-link-source] Failed to fetch pages:`,e),[])),n).map(e=>({label:e.title,detail:e.title===e.docName?void 0:e.docName,apply(t,n,r,i){let a=t.state.doc.sliceString(i,i+2)===`]]`?``:`]]`;t.dispatch({changes:{from:r,to:i,insert:e.docName+a},selection:{anchor:r+e.docName.length+a.length}})}}))}}var ft=I.theme({".cm-wiki-link":{color:`oklch(52.7% 0.154 228.4)`,fontWeight:`500`},".cm-wiki-link:hover":{textDecoration:`underline`,cursor:`pointer`}});function pt(){return[lt,ut,ft,ae.data.of({autocomplete:dt})]}var mt=H.mark({class:`cm-link-ref-broken`}),ht=/^\s{0,3}\[([^\]]+)\]:\s/,gt=/\[([^\]]*)\]\[([^\]]*)\]/g,_t=new Set([`FencedCode`,`CodeBlock`,`InlineCode`]);function Q(e,t){let n=0,r=t.length-1;for(;n<=r;){let i=n+r>>1,a=t[i];if(e<a.from)r=i-1;else if(e>=a.to)n=i+1;else return!0}return!1}function vt(e){let t=[];return M(e).iterate({enter(e){if(_t.has(e.name))return t.push({from:e.from,to:e.to}),!1}}),t.sort((e,t)=>e.from-t.from),t}function $(e){let t=new Set,n=[],r=e.doc,i=vt(e);for(let e=1;e<=r.lines;e++){let n=r.line(e);if(Q(n.from,i))continue;let a=ht.exec(n.text);a&&t.add(a[1].toLowerCase())}for(let e=1;e<=r.lines;e++){let t=r.line(e);if(!Q(t.from,i)&&!ht.test(t.text))for(gt.lastIndex=0;;){let e=gt.exec(t.text);if(!e)break;let r=t.from+e.index;if(Q(r,i))continue;let a=e[2]||e[1];n.push({from:r,to:r+e[0].length,label:a.toLowerCase()})}}let a=[];for(let e of n)t.has(e.label)||a.push(mt.range(e.from,e.to));return a.sort((e,t)=>e.from-t.from),H.set(a)}var yt=P.define({create(e){return $(e)},update(e,t){return t.docChanged?$(t.state):e},provide:e=>I.decorations.from(e)}),bt=/^(\s*(?:[-*+]|\d+[.)]) (?:\[[ x]\] )?)/,xt=H.mark({class:`cm-del`}),St=H.line({class:`cm-table-header`}),Ct=H.line({class:`cm-table-row`});function wt(e){let t=0;for(let n of e)if(n===` `)t++;else if(n===` `)t+=4;else break;return t}function Tt(e,t){let n=[],r=M(e);for(let{from:i,to:a}of t)r.iterate({from:i,to:a,enter(t){if(t.name===`Strikethrough`){let e=t.from,r=t.to,i=t.node.cursor();if(i.firstChild())do i.name===`StrikethroughMark`&&(i.from===t.from?e=i.to:r=i.from);while(i.nextSibling());return e<r&&n.push(xt.range(e,r)),!1}if(t.name===`ListItem`){let r=e.doc.lineAt(t.from),i=bt.exec(r.text),a=i?i[1].length:2,o=H.line({class:`cm-list-item`,attributes:{style:`--list-hang: ${a}ch`}});n.push(o.range(r.from));return}if(t.name===`FencedCode`){let r=e.doc.lineAt(t.from),i=e.doc.lineAt(t.to);for(let t=r.number+1;t<i.number;t++){let r=e.doc.line(t),i=wt(r.text),a=H.line({class:`cm-fenced-code-line`,attributes:{style:`--line-indent: ${i}`}});n.push(a.range(r.from))}return!1}if(t.name===`TableHeader`){let r=e.doc.lineAt(t.from);return n.push(St.range(r.from)),!1}if(t.name===`TableRow`){let r=e.doc.lineAt(t.from);return n.push(Ct.range(r.from)),!1}if(t.name===`TableDelimiter`&&t.node.parent?.name===`Table`){let r=e.doc.lineAt(t.from);return n.push(Ct.range(r.from)),!1}}});return n.sort((e,t)=>e.from-t.from||e.value.startSide-t.value.startSide),H.set(n)}var Et=class{decorations;constructor(e){this.decorations=Tt(e.state,e.visibleRanges)}update(e){(e.docChanged||e.viewportChanged||M(e.startState)!==M(e.state))&&(this.decorations=Tt(e.view.state,e.view.visibleRanges))}},Dt=L.fromClass(Et,{decorations:e=>e.decorations});function Ot(){return[Dt,yt]}var kt=i(),At=me({settings:{background:`var(--background)`,gutterBackground:`var(--background)`}}),jt=se({settings:{background:`var(--background)`,gutterBackground:`var(--background)`}}),Mt=new xe,Nt=new xe;function Pt(t,n){let r=t.state.doc,i=1;if(r.lines>=1&&r.line(1).text===`---`){for(let e=2;e<=r.lines;e++)if(r.line(e).text===`---`){i=e+1;break}}let a=e(),o=0;for(let e=i;e<=r.lines;e++){let i=r.line(e);if(!a(i.text)&&/^#{1,6}\s/.test(i.text)){if(o===n.index){t.dispatch({selection:F.cursor(i.from),effects:I.scrollIntoView(i.from,{y:`start`})}),t.focus();return}o++}}}function Ft(e,t){requestAnimationFrame(()=>{let n=e.state.doc,r=Math.min(t.offset,n.length);e.dispatch({selection:F.cursor(r),effects:I.scrollIntoView(r,{y:`center`})}),e.focus()})}function It(e){let t=(0,Se.c)(29),{docName:n,ytext:r,provider:i,placeholder:o,isSourceModeActive:s}=e,c=(0,U.useRef)(null),l=(0,U.useRef)(null),[u,d]=(0,U.useState)(null);if(u)throw u;let{resolvedTheme:f}=a(),p;t[0]!==s||t[1]!==i.awareness?(p=()=>{let e=i.awareness;if(e)return e.setLocalStateField(`mode`,s?`source`:`wysiwyg`),()=>{e.setLocalStateField(`mode`,`wysiwyg`)}},t[0]=s,t[1]=i.awareness,t[2]=p):p=t[2];let m;t[3]!==s||t[4]!==i?(m=[i,s],t[3]=s,t[4]=i,t[5]=m):m=t[5],(0,U.useEffect)(p,m);let h=(0,U.useRef)(null),g;t[6]!==o||t[7]!==i||t[8]!==f||t[9]!==r?(g=()=>{let e=c.current;if(!e)return;let t=i.configuration.name??``,n,a=Lt;try{n=ee({docName:t,container:e,sizeStats:{viewCount:0,bytes:r.length},factory:e=>{let t=pe({ydoc:i.document,ytext:r}),n=new I({state:ve.create({doc:r.toString(),extensions:[fe,be.of([ne]),re({base:ae,extensions:[oe],codeLanguages:Re}),Le(r,i.awareness),Ue(i.document),pt(),Ze(),Ot(),t,Mt.of(f===`dark`?At:jt),Nt.of(B(o??``)),I.lineWrapping,I.theme({"&":{height:`100%`}})]}),parent:e}),s=n.contentDOM;return s.addEventListener(`keydown`,a),s.addEventListener(`paste`,a),s.addEventListener(`drop`,a),s.addEventListener(`cut`,a),{view:n,ydoc:i.document,ytext:r,provider:i}}}),h.current=n,l.current=n.view}catch(e){let t=e;console.error(`[SourceEditor] mountCmEditor failed`,t),h.current=null,l.current=null,d(t instanceof Error?t:Error(String(t)))}return()=>{let e=h.current;e&&ie(e),h.current=null,l.current=null}},t[6]=o,t[7]=i,t[8]=f,t[9]=r,t[10]=g):g=t[10];let _;t[11]!==i||t[12]!==r?(_=[r,i],t[11]=i,t[12]=r,t[13]=_):_=t[13],(0,U.useEffect)(g,_);let v,y;t[14]===f?(v=t[15],y=t[16]):(v=()=>{l.current&&l.current.dispatch({effects:Mt.reconfigure(f===`dark`?At:jt)})},y=[f],t[14]=f,t[15]=v,t[16]=y),(0,U.useEffect)(v,y);let b,x;t[17]===o?(b=t[18],x=t[19]):(b=()=>{l.current&&l.current.dispatch({effects:Nt.reconfigure(B(o??``))})},x=[o],t[17]=o,t[18]=b,t[19]=x),(0,U.useEffect)(b,x);let C,w;t[20]!==n||t[21]!==s?(w=()=>{let e=function(e){let t=e.detail;if(!t||t.mode!==`source`||!s)return;let r=l.current;r&&(Pt(r,t),te(n))};return window.addEventListener(S,e),()=>window.removeEventListener(S,e)},C=[n,s],t[20]=n,t[21]=s,t[22]=C,t[23]=w):(C=t[22],w=t[23]),(0,U.useEffect)(w,C);let T,E;t[24]!==n||t[25]!==s?(T=()=>{if(!s)return;let e=l.current;if(!e)return;let t=he(n);if(t){if(t.kind===`outline`){Pt(e,t.detail);return}Ft(e,t.detail)}},E=[n,s],t[24]=n,t[25]=s,t[26]=T,t[27]=E):(T=t[26],E=t[27]),(0,U.useEffect)(T,E);let D;return t[28]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,kt.jsx)(`div`,{ref:c,className:`source-editor h-full py-3`}),t[28]=D):D=t[28],D}function Lt(){return u()}export{It as SourceEditor};