@inkeep/open-knowledge 0.0.0-dev-20260501033542 → 0.0.0-dev-20260501040851

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 (32) hide show
  1. package/dist/cli.mjs +7 -7
  2. package/dist/constants-DbWjfO8Y.mjs +2 -0
  3. package/dist/index.mjs +1 -1
  4. package/dist/init-886jAWg3.mjs +1 -0
  5. package/dist/{init-B110s1wM.mjs → init-B519j2Fp.mjs} +2 -2
  6. package/dist/init-CUQclyI_.mjs +1 -0
  7. package/dist/{init-BgvX0Sq8.mjs → init-CUwt-8z3.mjs} +3 -3
  8. package/dist/loader-BGd9I_nb.mjs +1 -0
  9. package/dist/{loader-DmdfaHaq.mjs → loader-Ddm8Y9Hn.mjs} +2 -2
  10. package/dist/paths-FTUdNmIc.mjs +1 -0
  11. package/dist/paths-Tuv5LiM3.mjs +2 -0
  12. package/dist/preview-CQcXTpAn.mjs +1 -0
  13. package/dist/{preview-jvjjfAtM.mjs → preview-cJDBHw8J.mjs} +2 -2
  14. package/dist/public/assets/{SourceEditor-Bo2dIeu9.js → SourceEditor-C0WLCZqD.js} +1 -1
  15. package/dist/public/assets/clipboard-CIRkQ4_J.js +5 -0
  16. package/dist/public/assets/{index-sRsZ2bXw.css → index-BbGfAZdV.css} +1 -1
  17. package/dist/public/assets/{index-D3IFbquY.js → index-CrNx3AgB.js} +3 -3
  18. package/dist/public/index.html +3 -3
  19. package/dist/src-DnL9KLD6.mjs +1 -0
  20. package/dist/start-DJqiDIf4.mjs +1 -0
  21. package/dist/{start-M53xqMIa.mjs → start-DNJ1mf76.mjs} +2 -2
  22. package/package.json +1 -1
  23. package/dist/constants-C4c9G6bx.mjs +0 -2
  24. package/dist/init-CCv_Zp9V.mjs +0 -1
  25. package/dist/init-DLXU6VrK.mjs +0 -1
  26. package/dist/loader-CXRhSZPN.mjs +0 -1
  27. package/dist/paths-RkbKkMl_.mjs +0 -2
  28. package/dist/paths-r4eAorwU.mjs +0 -1
  29. package/dist/preview-CnsTM1D_.mjs +0 -1
  30. package/dist/public/assets/clipboard-B19FK6nN.js +0 -5
  31. package/dist/src-DKAFRzZc.mjs +0 -1
  32. package/dist/start-B8KGCnGd.mjs +0 -1
@@ -1,3 +1,3 @@
1
- import{$ as e}from"./dist-Bk22-nn7.mjs";import"./constants-C4c9G6bx.mjs";import{K as t}from"./dist-BKxD-v-w.mjs";import{join as n,relative as r}from"node:path";import{existsSync as i,lstatSync as a,readdirSync as o,realpathSync as s,statSync as c}from"node:fs";function l(e){let{projectDir:i,contentDir:l,include:u,exclude:d,sampleCap:f=5}=e,p=[],m=[];try{a(l)}catch(e){return{totalCount:0,sample:[],contentDir:l,include:u,exclude:d,warnings:[`cannot access content directory ${l}: ${e instanceof Error?e.message:String(e)}`]}}let h;try{h=t({projectDir:i,contentDir:l,includePatterns:u,excludePatterns:d})}catch(e){return{totalCount:0,sample:[],contentDir:l,include:u,exclude:d,warnings:[e instanceof Error?e.message:String(e)]}}function g(e){let t;try{t=o(e,{withFileTypes:!0})}catch(t){let n=t instanceof Error?t.message:String(t);p.push(`could not read directory ${r(l,e)||`.`}: ${n}`);return}for(let i of t){let t=n(e,i.name);if(i.isSymbolicLink()){let e;try{e=s(t)}catch(e){let n=e.code;n===`ENOENT`||n===`ELOOP`?p.push(`broken or cyclic symlink: ${r(l,t)}`):p.push(`cannot resolve symlink ${r(l,t)}: ${n??`unknown error`}`);continue}let n;try{n=c(e)}catch{continue}if(n.isDirectory()){let e=r(l,t);if(h.isDirExcluded(e))continue;g(t)}else if(n.isFile()){let e=r(l,t);if(h.isExcluded(e))continue;m.push(e)}}else if(i.isDirectory()){let e=r(l,t);if(h.isDirExcluded(e))continue;g(t)}else if(i.isFile()){let e=r(l,t);if(h.isExcluded(e))continue;m.push(e)}}}return g(l),{totalCount:m.length,sample:m.slice(0,f),contentDir:l,include:u,exclude:d,warnings:p}}function u(t,a){let o=[],s=r(a,t.contentDir),c=s===``?`./`:`./${s}`;o.push(`Content:`),o.push(` Found ${t.totalCount} markdown files in ${c}`);let l=t.include.join(`, `),u=t.exclude.length>0?t.exclude.join(`, `):`(none)`;if(o.push(` Scope: include=${l} exclude=${u}`),t.sample.length>0){let e=t.sample.join(`, `),n=t.totalCount>t.sample.length?`, …`:``;o.push(` Sample: ${e}${n}`)}if(t.warnings.length>0)for(let e of t.warnings)o.push(` Warning: ${e}`);return o.push(``),i(n(a,`.open-knowledge`,`config.yml`))?(o.push(` To adjust, edit ${e}/config.yml:`),o.push(` content:`),o.push(` include: ${JSON.stringify(t.include)}`),o.push(` exclude: ${JSON.stringify(t.exclude)}`)):(o.push(" Run `open-knowledge init` to scaffold config, then adjust:"),o.push(` ${e}/config.yml → content.include / content.exclude`)),o.push(``),o.push(` Re-check anytime: open-knowledge preview`),o.join(`
1
+ import{$ as e}from"./dist-Bk22-nn7.mjs";import"./constants-DbWjfO8Y.mjs";import{K as t}from"./dist-BKxD-v-w.mjs";import{join as n,relative as r}from"node:path";import{existsSync as i,lstatSync as a,readdirSync as o,realpathSync as s,statSync as c}from"node:fs";function l(e){let{projectDir:i,contentDir:l,include:u,exclude:d,sampleCap:f=5}=e,p=[],m=[];try{a(l)}catch(e){return{totalCount:0,sample:[],contentDir:l,include:u,exclude:d,warnings:[`cannot access content directory ${l}: ${e instanceof Error?e.message:String(e)}`]}}let h;try{h=t({projectDir:i,contentDir:l,includePatterns:u,excludePatterns:d})}catch(e){return{totalCount:0,sample:[],contentDir:l,include:u,exclude:d,warnings:[e instanceof Error?e.message:String(e)]}}function g(e){let t;try{t=o(e,{withFileTypes:!0})}catch(t){let n=t instanceof Error?t.message:String(t);p.push(`could not read directory ${r(l,e)||`.`}: ${n}`);return}for(let i of t){let t=n(e,i.name);if(i.isSymbolicLink()){let e;try{e=s(t)}catch(e){let n=e.code;n===`ENOENT`||n===`ELOOP`?p.push(`broken or cyclic symlink: ${r(l,t)}`):p.push(`cannot resolve symlink ${r(l,t)}: ${n??`unknown error`}`);continue}let n;try{n=c(e)}catch{continue}if(n.isDirectory()){let e=r(l,t);if(h.isDirExcluded(e))continue;g(t)}else if(n.isFile()){let e=r(l,t);if(h.isExcluded(e))continue;m.push(e)}}else if(i.isDirectory()){let e=r(l,t);if(h.isDirExcluded(e))continue;g(t)}else if(i.isFile()){let e=r(l,t);if(h.isExcluded(e))continue;m.push(e)}}}return g(l),{totalCount:m.length,sample:m.slice(0,f),contentDir:l,include:u,exclude:d,warnings:p}}function u(t,a){let o=[],s=r(a,t.contentDir),c=s===``?`./`:`./${s}`;o.push(`Content:`),o.push(` Found ${t.totalCount} markdown files in ${c}`);let l=t.include.join(`, `),u=t.exclude.length>0?t.exclude.join(`, `):`(none)`;if(o.push(` Scope: include=${l} exclude=${u}`),t.sample.length>0){let e=t.sample.join(`, `),n=t.totalCount>t.sample.length?`, …`:``;o.push(` Sample: ${e}${n}`)}if(t.warnings.length>0)for(let e of t.warnings)o.push(` Warning: ${e}`);return o.push(``),i(n(a,`.open-knowledge`,`config.yml`))?(o.push(` To adjust, edit ${e}/config.yml:`),o.push(` content:`),o.push(` include: ${JSON.stringify(t.include)}`),o.push(` exclude: ${JSON.stringify(t.exclude)}`)):(o.push(" Run `open-knowledge init` to scaffold config, then adjust:"),o.push(` ${e}/config.yml → content.include / content.exclude`)),o.push(``),o.push(` Re-check anytime: open-knowledge preview`),o.join(`
2
2
  `)}export{l as n,u as t};
3
- //# sourceMappingURL=preview-jvjjfAtM.mjs.map
3
+ //# sourceMappingURL=preview-cJDBHw8J.mjs.map
@@ -1,2 +1,2 @@
1
- import{r as e}from"./chunk-DECur_0Z.js";import{n as t,r as n,t as r}from"./compiler-runtime-Y11fyRVL.js";import{it as i,qn as a}from"./toggle-group-n36XMgMC.js";import{$ as o,G as s,at as c,b as l,ct as u,dt as d,h as f,it as p,lt as m,m as h,nt as g,ot as _,p as ee,q as v,rt as y,st as b,tt as x,ut as S}from"./DocumentContext-BtLDstmc.js";import{At as C,Dt as w,Et as te,N as T,Pt as E,Q as D,Tt as O,Y as k,Z as A,bt as j,ft as M,lt as ne,q as N,wt as P}from"./dist-dkPJvrfr.js";import{a as F,c as re,l as ie,s as ae,t as oe,u as se}from"./clipboard-B19FK6nN.js";var I=e(t(),1),ce=r(),L=class e{constructor(e,t){this.yanchor=e,this.yhead=t}toJSON(){return{yanchor:_(this.yanchor),yhead:_(this.yhead)}}static fromJSON(t){return new e(p(t.yanchor),p(t.yhead))}},le=class{constructor(e,t){this.ytext=e,this.awareness=t,this.undoManager=new x(e)}toYPos(e,t=0){return c(this.ytext,e,t)}fromYPos(e){let t=y(p(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 L(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?O.cursor(n.pos,n.assoc):O.range(t.pos,n.pos)}},R=w.define({combine(e){return e[e.length-1]}}),z=j.define(),B=class{constructor(e){this.view=e,this.conf=e.state.facet(R),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:[z.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(z)===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,`
1
+ import{r as e}from"./chunk-DECur_0Z.js";import{n as t,r as n,t as r}from"./compiler-runtime-Y11fyRVL.js";import{it as i,qn as a}from"./toggle-group-n36XMgMC.js";import{$ as o,G as s,at as c,b as l,ct as u,dt as d,h as f,it as p,lt as m,m as h,nt as g,ot as _,p as ee,q as v,rt as y,st as b,tt as x,ut as S}from"./DocumentContext-BtLDstmc.js";import{At as C,Dt as w,Et as te,N as T,Pt as E,Q as D,Tt as O,Y as k,Z as A,bt as j,ft as M,lt as ne,q as N,wt as P}from"./dist-dkPJvrfr.js";import{a as F,c as re,l as ie,s as ae,t as oe,u as se}from"./clipboard-CIRkQ4_J.js";var I=e(t(),1),ce=r(),L=class e{constructor(e,t){this.yanchor=e,this.yhead=t}toJSON(){return{yanchor:_(this.yanchor),yhead:_(this.yhead)}}static fromJSON(t){return new e(p(t.yanchor),p(t.yhead))}},le=class{constructor(e,t){this.ytext=e,this.awareness=t,this.undoManager=new x(e)}toYPos(e,t=0){return c(this.ytext,e,t)}fromYPos(e){let t=y(p(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 L(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?O.cursor(n.pos,n.assoc):O.range(t.pos,n.pos)}},R=w.define({combine(e){return e[e.length-1]}}),z=j.define(),B=class{constructor(e){this.view=e,this.conf=e.state.facet(R),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:[z.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(z)===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,`
2
2
  `);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)}},V=A.fromClass(B),H=k.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`}}),U=j.define(),W=class extends D{constructor(e,t){super(),this.color=e,this.name=t}toDOM(){return b(`span`,[m(`class`,`cm-ySelectionCaret`),m(`style`,`background-color: ${this.color}; border-color: ${this.color}`)],[u(`⁠`),b(`div`,[m(`class`,`cm-ySelectionCaretDot`)]),u(`⁠`),b(`div`,[m(`class`,`cm-ySelectionInfo`)],[u(this.name)]),u(`⁠`)])}eq(e){return e.color===this.color}compare(e){return e.color===this.color}updateDOM(){return!1}get estimatedHeight(){return-1}ignoreEvent(){return!0}},ue=class{constructor(e){this.conf=e.state.facet(R),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:[U.of([])]})},this._awareness=this.conf.awareness,this._awareness.on(`change`,this._listener),this.decorations=C.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:p(a.cursor.anchor),s=a.cursor==null?null:p(a.cursor.head);if(i!=null){let e=c(t,i.anchor),n=c(t,i.head);(a.cursor==null||!g(o,e)||!g(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=y(s.anchor,n),l=y(s.head,n);if(c==null||l==null||c.type!==t||l.type!==t)return;let{color:u=`#30bced`,name:f=`Anonymous`}=a.user||{},p=a.user&&a.user.colorLight||u+`33`,m=d(c.index,l.index),h=S(c.index,l.index),g=e.view.state.doc.lineAt(m),_=e.view.state.doc.lineAt(h);if(g.number===_.number)i.push({from:m,to:h,value:N.mark({attributes:{style:`background-color: ${p}`},class:`cm-ySelection`})});else{i.push({from:m,to:g.from+g.length,value:N.mark({attributes:{style:`background-color: ${p}`},class:`cm-ySelection`})}),i.push({from:_.from,to:h,value:N.mark({attributes:{style:`background-color: ${p}`},class:`cm-ySelection`})});for(let t=g.number+1;t<_.number;t++){let n=e.view.state.doc.line(t).from;i.push({from:n,to:n,value:N.line({attributes:{style:`background-color: ${p}`,class:`cm-yLineSelection`}})})}}i.push({from:l.index,to:l.index,value:N.widget({side:l.index-c.index>0?-1:1,block:!1,widget:new W(u,f)})})}),this.decorations=N.set(i,!0)}},de=A.fromClass(ue,{decorations:e=>e.decorations}),fe=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}},G=w.define({combine(e){return e[e.length-1]}});j.define();var pe=class{constructor(e){this.view=e,this.conf=e.state.facet(G),this._undoManager=this.conf.undoManager,this.syncConf=e.state.facet(R),this._beforeChangeSelection=null,this._mux=o(),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:[k.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(z)!==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)}},me=A.fromClass(pe),he=({state:e,dispatch:t})=>e.facet(G).undo()||!0,ge=({state:e,dispatch:t})=>e.facet(G).redo()||!0,_e=(e,t,{undoManager:n=new x(e)}={})=>{let r=new le(e,t),i=[R.of(r),V];return t&&i.push(H,de),n!==!1&&i.push(G.of(new fe(n)),me,k.domEventHandlers({beforeinput(e,t){return e.inputType===`historyUndo`?he(t):e.inputType===`historyRedo`?ge(t):!1}})),i},ve=N.mark({class:`cm-link-ref-broken`}),K=/^\s{0,3}\[([^\]]+)\]:\s/,q=/\[([^\]]*)\]\[([^\]]*)\]/g,ye=new Set([`FencedCode`,`CodeBlock`,`InlineCode`]);function J(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 be(e){let t=[];return T(e).iterate({enter(e){if(ye.has(e.name))return t.push({from:e.from,to:e.to}),!1}}),t.sort((e,t)=>e.from-t.from),t}function Y(e){let t=new Set,n=[],r=e.doc,i=be(e);for(let e=1;e<=r.lines;e++){let n=r.line(e);if(J(n.from,i))continue;let a=K.exec(n.text);a&&t.add(a[1].toLowerCase())}for(let e=1;e<=r.lines;e++){let t=r.line(e);if(!J(t.from,i)&&!K.test(t.text))for(q.lastIndex=0;;){let e=q.exec(t.text);if(!e)break;let r=t.from+e.index;if(J(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(ve.range(e.from,e.to));return a.sort((e,t)=>e.from-t.from),N.set(a)}var xe=E.define({create(e){return Y(e)},update(e,t){return t.docChanged?Y(t.state):e},provide:e=>k.decorations.from(e)}),Se=/^(\s*(?:[-*+]|\d+[.)]) (?:\[[ x]\] )?)/,Ce=N.mark({class:`cm-del`}),we=N.line({class:`cm-table-header`}),X=N.line({class:`cm-table-row`});function Te(e){let t=0;for(let n of e)if(n===` `)t++;else if(n===` `)t+=4;else break;return t}function Z(e){if(e.doc.lines<2)return null;let t=e.doc.line(1);if(t.text!==`---`)return null;for(let n=2;n<=e.doc.lines;n++){let r=e.doc.line(n);if(r.text===`---`)return{from:t.from,to:r.to}}return null}function Q(e,t){let n=[],r=T(e),i=Z(e),a=e=>i!==null&&e>=i.from&&e<=i.to;for(let{from:i,to:o}of t)r.iterate({from:i,to:o,enter(t){if(!a(t.from)){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(Ce.range(e,r)),!1}if(t.name===`ListItem`){let r=e.doc.lineAt(t.from),i=Se.exec(r.text),a=i?i[1].length:2,o=N.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=Te(r.text),a=N.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(we.range(r.from)),!1}if(t.name===`TableRow`){let r=e.doc.lineAt(t.from);return n.push(X.range(r.from)),!1}if(t.name===`TableDelimiter`&&t.node.parent?.name===`Table`){let r=e.doc.lineAt(t.from);return n.push(X.range(r.from)),!1}}}});return n.sort((e,t)=>e.from-t.from||e.value.startSide-t.value.startSide),N.set(n)}var Ee=class{decorations;constructor(e){this.decorations=Q(e.state,e.visibleRanges)}update(e){(e.docChanged||e.viewportChanged||T(e.startState)!==T(e.state))&&(this.decorations=Q(e.view.state,e.view.visibleRanges))}},De=A.fromClass(Ee,{decorations:e=>e.decorations});function Oe(){return[De,xe]}var ke=n();function $(e,t){let n=e.state.doc,r=1;if(n.lines>=1&&n.line(1).text===`---`){for(let e=2;e<=n.lines;e++)if(n.line(e).text===`---`){r=e+1;break}}let a=i(),o=0;for(let i=r;i<=n.lines;i++){let r=n.line(i);if(!a(r.text)&&/^#{1,6}\s/.test(r.text)){if(o===t.index){e.dispatch({selection:O.cursor(r.from),effects:k.scrollIntoView(r.from,{y:`start`})}),e.focus();return}o++}}}function Ae(e,t){requestAnimationFrame(()=>{let n=e.state.doc,r=Math.min(t.offset,n.length);e.dispatch({selection:O.cursor(r),effects:k.scrollIntoView(r,{y:`center`})}),e.focus()})}function je(e){let t=(0,ce.c)(25),{docName:n,ytext:r,provider:i,placeholder:o,isSourceModeActive:c}=e,l=(0,I.useRef)(null),u=(0,I.useRef)(null),d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=new P,t[0]=d):d=t[0];let p=(0,I.useRef)(d),m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=new P,t[1]=m):m=t[1];let g=(0,I.useRef)(m),[_,y]=(0,I.useState)(null);if(_)throw _;let{resolvedTheme:b}=a(),x=(0,I.useRef)(null),S;t[2]!==o||t[3]!==i||t[4]!==b||t[5]!==r?(S=()=>{let e=l.current;if(!e)return;let t=i.configuration.name??``,n,a=Me;try{n=s({docName:t,container:e,sizeStats:{viewCount:0,bytes:r.length},factory:e=>{let t=oe({ydoc:i.document,ytext:r}),n=new k({state:te.create({doc:r.toString(),extensions:[ae,ne.of([re]),_e(r,i.awareness),...ee({themeCompartment:p.current,resolvedTheme:b,ydoc:i.document}),Oe(),t,g.current.of(M(o??``)),k.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}}}),x.current=n,u.current=n.view}catch(e){let t=e;console.error(`[SourceEditor] mountCmEditor failed`,t),x.current=null,u.current=null,y(t instanceof Error?t:Error(String(t)))}return()=>{let e=x.current;e&&v(e),x.current=null,u.current=null}},t[2]=o,t[3]=i,t[4]=b,t[5]=r,t[6]=S):S=t[6];let C;t[7]!==i||t[8]!==r?(C=[r,i],t[7]=i,t[8]=r,t[9]=C):C=t[9],(0,I.useEffect)(S,C);let w,T;t[10]===b?(w=t[11],T=t[12]):(w=()=>{u.current&&u.current.dispatch({effects:p.current.reconfigure(b===`dark`?h:f)})},T=[b],t[10]=b,t[11]=w,t[12]=T),(0,I.useEffect)(w,T);let E,D;t[13]===o?(E=t[14],D=t[15]):(E=()=>{u.current&&u.current.dispatch({effects:g.current.reconfigure(M(o??``))})},D=[o],t[13]=o,t[14]=E,t[15]=D),(0,I.useEffect)(E,D);let O,A;t[16]!==n||t[17]!==c?(A=()=>{let e=function(e){let t=e.detail;if(!t||t.mode!==`source`||!c)return;let r=u.current;r&&($(r,t),ie(n))};return window.addEventListener(F,e),()=>window.removeEventListener(F,e)},O=[n,c],t[16]=n,t[17]=c,t[18]=O,t[19]=A):(O=t[18],A=t[19]),(0,I.useEffect)(A,O);let j,N;t[20]!==n||t[21]!==c?(j=()=>{if(!c)return;let e=u.current;if(!e)return;let t=se(n);if(t){if(t.kind===`outline`){$(e,t.detail);return}Ae(e,t.detail)}},N=[n,c],t[20]=n,t[21]=c,t[22]=j,t[23]=N):(j=t[22],N=t[23]),(0,I.useEffect)(j,N);let L;return t[24]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,ke.jsx)(`div`,{ref:l,className:`source-editor h-full py-3`}),t[24]=L):L=t[24],L}function Me(){return l()}export{je as SourceEditor};
@@ -0,0 +1,5 @@
1
+ import{r as e}from"./chunk-DECur_0Z.js";import{n as t,r as n,t as r}from"./compiler-runtime-Y11fyRVL.js";import{a as i,c as a,i as o,n as s,o as c,r as l,s as u,t as d,u as f}from"./panel-DT62BXGr.js";import{Cn as p,E as m,Mt as ee,Q as te,_t as ne,bn as h,i as re,j as ie,jt as g}from"./toggle-group-n36XMgMC.js";import{r as ae}from"./button-Dyz7QGIk.js";import{at as _,ht as v,n as oe,rt as se}from"./DocumentContext-BtLDstmc.js";import{x as y}from"./dialog-FUclf-NK.js";import{$ as b,A as x,B as S,Bt as C,Ct as w,D as ce,Dt as T,E,Et as le,Ft as D,Ht as ue,It as de,J as fe,Lt as pe,M as O,N as k,Nt as A,Pt as j,Q as M,Rt as me,S as he,St as ge,T as _e,Tt as N,Vt as P,Y as F,Z as ve,at as ye,bt as be,c as xe,ct as Se,d as Ce,et as we,g as Te,gt as Ee,ht as De,jt as Oe,kt as ke,lt as Ae,mt as je,n as Me,nt as Ne,ot as Pe,pt as Fe,q as I,st as Ie,tt as Le,ut as Re,v as ze,vt as L,x as Be,xt as Ve,zt as He}from"./dist-dkPJvrfr.js";import{i as Ue,n as We,o as Ge,r as Ke}from"./dist-oNAFjGrp.js";var qe=e(t(),1),Je=r(),Ye=new Map;function Xe(e,t){Ye.set(e,t)}function Ze(e){let t=Ye.get(e)??null;return Ye.delete(e),t}function Qe(e){Ye.delete(e)}var $e=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=it(e.state,n.from);return r.line?tt(e):r.block?rt(e):!1};function et(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var tt=et(lt,0),nt=et(ct,0),rt=et((e,t)=>ct(e,t,st(t)),0);function it(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var at=50;function ot(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-at,r),o=e.sliceDoc(i,i+at),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=2*at?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+at),d=e.sliceDoc(i-at,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function st(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function ct(e,t,n=t.selection.ranges){let r=n.map(e=>it(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>ot(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function lt(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=it(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var ut=be.define(),dt=be.define(),ft=T.define(),pt=T.define({combine(e){return He(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),mt=j.define({create(){return jt.empty},update(e,t){let n=t.state.facet(pt),r=t.annotation(ut);if(r){let i=R.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?xt(o,o.length,n.minDepth,i):Et(o,t.startState.selection),new jt(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(dt);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(de.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=R.fromTransaction(t),o=t.annotation(de.time),s=t.annotation(de.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new jt(e.done.map(R.fromJSON),e.undone.map(R.fromJSON))}});function ht(e={}){return[mt,pt.of(e),F.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?_t:e.inputType==`historyRedo`?vt:null;return n?(e.preventDefault(),n(t)):!1}})]}function gt(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(mt,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var _t=gt(0,!1),vt=gt(1,!1),yt=gt(0,!0),bt=gt(1,!0),R=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&ge.fromJSON(t.changes),[],t.mapped&&Ve.fromJSON(t.mapped),t.startSelection&&N.fromJSON(t.startSelection),t.selectionsAfter.map(N.fromJSON))}static fromTransaction(t,n){let r=z;for(let e of t.startState.facet(ft)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,z)}static selection(t){return new e(void 0,z,void 0,void 0,t)}};function xt(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function St(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function Ct(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function wt(e,t){return e.length?t.length?e.concat(t):e:t}var z=[],Tt=200;function Et(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Tt));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),xt(e,e.length-1,1e9,n.setSelAfter(r)))}else return[R.selection([t])]}function Dt(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function Ot(e,t){if(!e.length)return e;let n=e.length,r=z;for(;n;){let i=kt(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[R.selection(r)]:z}function kt(e,t,n){let r=wt(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):z,n);if(!e.changes)return R.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new R(i,A.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var At=/^(input\.type|delete)($|\.)/,jt=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||At.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,St(s.changes,t.changes))||r==`input.type.compose`)?xt(o,o.length-1,i.minDepth,new R(t.changes.compose(s.changes),wt(A.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,z)):xt(o,o.length,i.minDepth,t),new e(o,z,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:z;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Ct(a[a.length-1],t)?this:new e(Et(this.done,t),this.undone,n,r)}addMapping(t){return new e(Ot(this.done,t),Ot(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:ut.of({side:e,rest:Dt(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?z:r.slice(0,r.length-1);return i.mapped&&(n=Ot(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:ut.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};jt.empty=new jt(z,z);var Mt=[{key:`Mod-z`,run:_t,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:vt,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:vt,preventDefault:!0},{key:`Mod-u`,run:yt,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:bt,preventDefault:!0}];function Nt(e,t){return N.create(e.ranges.map(t),e.mainIndex)}function B(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function V({state:e,dispatch:t},n){let r=Nt(e.selection,n);return r.eq(e.selection,!0)?!1:(t(B(e,r)),!0)}function Pt(e,t){return N.cursor(t?e.to:e.from)}function Ft(e,t){return V(e,n=>n.empty?e.moveByChar(n,t):Pt(n,t))}function H(e){return e.textDirectionAt(e.state.selection.main.head)==fe.LTR}var It=e=>Ft(e,!H(e)),Lt=e=>Ft(e,H(e));function Rt(e,t){return V(e,n=>n.empty?e.moveByGroup(n,t):Pt(n,t))}var zt=e=>Rt(e,!H(e)),Bt=e=>Rt(e,H(e));typeof Intl<`u`&&Intl.Segmenter;function Vt(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Ht(e,t,n){let r=k(e).resolveInner(t.head),i=n?S.closedBy:S.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;Vt(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?x(e,r.from,1):x(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,N.cursor(s,n?-1:1)}var Ut=e=>V(e,t=>Ht(e.state,t,!H(e))),Wt=e=>V(e,t=>Ht(e.state,t,H(e)));function Gt(e,t){return V(e,n=>{if(!n.empty)return Pt(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var Kt=e=>Gt(e,!1),qt=e=>Gt(e,!0);function Jt(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(F.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function Yt(e,t){let n=Jt(e),{state:r}=e,i=Nt(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):Pt(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=F.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(B(r,i),{effects:a}),!0}var Xt=e=>Yt(e,!1),Zt=e=>Yt(e,!0);function U(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=N.cursor(r.from+n))}return i}var Qt=e=>V(e,t=>U(e,t,!0)),$t=e=>V(e,t=>U(e,t,!1)),en=e=>V(e,t=>U(e,t,!H(e))),tn=e=>V(e,t=>U(e,t,H(e))),nn=e=>V(e,t=>N.cursor(e.lineBlockAt(t.head).from,1)),rn=e=>V(e,t=>N.cursor(e.lineBlockAt(t.head).to,-1));function an(e,t,n){let r=!1,i=Nt(e.selection,t=>{let i=x(e,t.head,-1)||x(e,t.head,1)||t.head>0&&x(e,t.head-1,1)||t.head<e.doc.length&&x(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?N.range(t.anchor,a):N.cursor(a)});return r?(t(B(e,i)),!0):!1}var on=({state:e,dispatch:t})=>an(e,t,!1);function W(e,t){let n=Nt(e.state.selection,e=>{let n=t(e);return N.range(e.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(B(e.state,n)),!0)}function sn(e,t){return W(e,n=>e.moveByChar(n,t))}var cn=e=>sn(e,!H(e)),ln=e=>sn(e,H(e));function un(e,t){return W(e,n=>e.moveByGroup(n,t))}var dn=e=>un(e,!H(e)),fn=e=>un(e,H(e)),pn=e=>W(e,t=>Ht(e.state,t,!H(e))),mn=e=>W(e,t=>Ht(e.state,t,H(e)));function hn(e,t){return W(e,n=>e.moveVertically(n,t))}var gn=e=>hn(e,!1),_n=e=>hn(e,!0);function vn(e,t){return W(e,n=>e.moveVertically(n,t,Jt(e).height))}var yn=e=>vn(e,!1),bn=e=>vn(e,!0),xn=e=>W(e,t=>U(e,t,!0)),Sn=e=>W(e,t=>U(e,t,!1)),Cn=e=>W(e,t=>U(e,t,!H(e))),wn=e=>W(e,t=>U(e,t,H(e))),Tn=e=>W(e,t=>N.cursor(e.lineBlockAt(t.head).from)),En=e=>W(e,t=>N.cursor(e.lineBlockAt(t.head).to)),Dn=({state:e,dispatch:t})=>(t(B(e,{anchor:0})),!0),On=({state:e,dispatch:t})=>(t(B(e,{anchor:e.doc.length})),!0),kn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:0})),!0),An=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),jn=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),Mn=({state:e,dispatch:t})=>{let n=Zn(e).map(({from:t,to:n})=>N.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:N.create(n),userEvent:`select`})),!0},Nn=({state:e,dispatch:t})=>{let n=Nt(e.selection,t=>{let n=k(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return N.range(n.to,n.from)}return t});return n.eq(e.selection)?!1:(t(B(e,n)),!0)};function Pn(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(B(n,N.create(i,i.length-1))),!0)}var Fn=e=>Pn(e,!1),In=e=>Pn(e,!0),Ln=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=N.create([n.main]):n.main.empty||(r=N.create([N.cursor(n.main.head)])),r?(t(B(e,r)),!0):!1};function Rn(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=zn(e,o,!1)):o>i&&(n=`delete.forward`,o=zn(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=zn(e,i,!1),a=zn(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:N.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?F.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function zn(e,t,n){if(e instanceof F)for(let r of e.state.facet(F.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var Bn=(e,t,n)=>Rn(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=C(s,a.tabSize)%Be(a)||Be(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=P(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=P(o.text,c-o.from,!1,!1)+o.from);return c}),Vn=e=>Bn(e,!1,!0),Hn=e=>Bn(e,!0,!1),Un=(e,t)=>Rn(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=P(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),Wn=e=>Un(e,!1),Gn=e=>Un(e,!0),Kn=e=>Rn(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),qn=e=>Rn(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Jn=e=>Rn(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Yn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:D.of([``,``])},range:N.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},Xn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:P(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:P(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:N.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function Zn(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Qn(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of Zn(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(N.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(N.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:N.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var $n=({state:e,dispatch:t})=>Qn(e,t,!1),er=({state:e,dispatch:t})=>Qn(e,t,!0);function tr(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of Zn(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var nr=({state:e,dispatch:t})=>tr(e,t,!1),rr=({state:e,dispatch:t})=>tr(e,t,!0),ir=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Zn(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=Nt(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function ar(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=k(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(S.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var or=cr(!1),sr=cr(!0);function cr(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&ar(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new Me(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=he(s,r);for(c??=C(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,E(t,c)];return o&&l.push(E(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:D.of(l)},range:N.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function lr(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:N.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var ur=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Me(e,{overrideIndentation:e=>n[e]??-1}),i=lr(e,(t,i,a)=>{let o=he(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=E(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},dr=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(lr(e,(t,n)=>{n.push({from:t.from,insert:e.facet(ce)})}),{userEvent:`input.indent`})),!0),fr=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(lr(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=C(r,e.tabSize),a=0,o=E(e,Math.max(0,i-Be(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),pr=e=>(e.setTabFocusMode(),!0),mr=[{key:`Ctrl-b`,run:It,shift:cn,preventDefault:!0},{key:`Ctrl-f`,run:Lt,shift:ln},{key:`Ctrl-p`,run:Kt,shift:gn},{key:`Ctrl-n`,run:qt,shift:_n},{key:`Ctrl-a`,run:nn,shift:Tn},{key:`Ctrl-e`,run:rn,shift:En},{key:`Ctrl-d`,run:Hn},{key:`Ctrl-h`,run:Vn},{key:`Ctrl-k`,run:Kn},{key:`Ctrl-Alt-h`,run:Wn},{key:`Ctrl-o`,run:Yn},{key:`Ctrl-t`,run:Xn},{key:`Ctrl-v`,run:Zt}],hr=[{key:`ArrowLeft`,run:It,shift:cn,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:zt,shift:dn,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:en,shift:Cn,preventDefault:!0},{key:`ArrowRight`,run:Lt,shift:ln,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:Bt,shift:fn,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:tn,shift:wn,preventDefault:!0},{key:`ArrowUp`,run:Kt,shift:gn,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:Dn,shift:kn},{mac:`Ctrl-ArrowUp`,run:Xt,shift:yn},{key:`ArrowDown`,run:qt,shift:_n,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:On,shift:An},{mac:`Ctrl-ArrowDown`,run:Zt,shift:bn},{key:`PageUp`,run:Xt,shift:yn},{key:`PageDown`,run:Zt,shift:bn},{key:`Home`,run:$t,shift:Sn,preventDefault:!0},{key:`Mod-Home`,run:Dn,shift:kn},{key:`End`,run:Qt,shift:xn,preventDefault:!0},{key:`Mod-End`,run:On,shift:An},{key:`Enter`,run:or,shift:or},{key:`Mod-a`,run:jn},{key:`Backspace`,run:Vn,shift:Vn,preventDefault:!0},{key:`Delete`,run:Hn,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Wn,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:Gn,preventDefault:!0},{mac:`Mod-Backspace`,run:qn,preventDefault:!0},{mac:`Mod-Delete`,run:Jn,preventDefault:!0}].concat(mr.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),gr=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:Ut,shift:pn},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Wt,shift:mn},{key:`Alt-ArrowUp`,run:$n},{key:`Shift-Alt-ArrowUp`,run:nr},{key:`Alt-ArrowDown`,run:er},{key:`Shift-Alt-ArrowDown`,run:rr},{key:`Mod-Alt-ArrowUp`,run:Fn},{key:`Mod-Alt-ArrowDown`,run:In},{key:`Escape`,run:Ln},{key:`Mod-Enter`,run:sr},{key:`Alt-l`,mac:`Ctrl-l`,run:Mn},{key:`Mod-i`,run:Nn,preventDefault:!0},{key:`Mod-[`,run:fr},{key:`Mod-]`,run:dr},{key:`Mod-Alt-\\`,run:ur},{key:`Shift-Mod-k`,run:ir},{key:`Shift-Mod-\\`,run:on},{key:`Mod-/`,run:$e},{key:`Alt-A`,run:nt},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:pr}].concat(hr),_r={key:`Tab`,run:dr,shift:fr},vr=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,yr=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(vr(e)):vr,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return pe(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=ue(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=me(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n;;e++){let a=r.charCodeAt(e),o=this.match(a,i,this.bufferPos+this.bufferStart);if(e==r.length-1){if(o)return this.value=o,this;break}i==n&&e<t.length&&t.charCodeAt(e)==a&&i++}}}match(e,t,n){let r=null;for(let t=0;t<this.matches.length;t+=2){let i=this.matches[t],a=!1;this.query.charCodeAt(i)==e&&(i==this.query.length-1?r={from:this.matches[t+1],to:n}:(this.matches[t]++,a=!0)),a||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:n}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<`u`&&(yr.prototype[Symbol.iterator]=function(){return this});var br={from:-1,to:-1,match:/.*/.exec(``)},xr=`gm`+(/x/.unicode==null?``:`u`),Sr=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=br,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Tr(e,t,n,r,i);this.re=new RegExp(t,xr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter(),this.curLineStart=e.lineAt(r).from,this.matchPos=Dr(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=Dr(this.text,r+ +(n==r)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},Cr=new WeakMap,wr=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=Cr.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return Cr.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),Cr.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},Tr=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=br,this.matchPos=Dr(e,r),this.re=new RegExp(t,xr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=wr.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,match:t},this.matchPos=Dr(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=wr.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(Sr.prototype[Symbol.iterator]=Tr.prototype[Symbol.iterator]=function(){return this});function Er(e){try{return new RegExp(e,xr),!0}catch{return!1}}function Dr(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var Or=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=De(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),p=N.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,F.scrollIntoView(p.from,{y:`center`})],selection:p})}),!0},kr={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Ar=T.define({combine(e){return He(e,kr,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function jr(e){let t=[Lr,Ir];return e&&t.push(Ar.of(e)),t}var Mr=I.mark({class:`cm-selectionMatch`}),Nr=I.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function Pr(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=w.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=w.Word)}function Fr(e,t,n,r){return e(t.sliceDoc(n,n+1))==w.Word&&e(t.sliceDoc(r-1,r))==w.Word}var Ir=ve.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(Ar),{state:n}=e,r=n.selection;if(r.ranges.length>1)return I.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return I.none;let e=n.wordAt(i.head);if(!e)return I.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return I.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(Pr(o,n,i.from,i.to)&&Fr(o,n,i.from,i.to)))return I.none}else if(a=n.sliceDoc(i.from,i.to),!a)return I.none}let s=[];for(let r of e.visibleRanges){let e=new yr(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||Pr(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(Nr.range(r,a)):(r>=i.to||a<=i.from)&&s.push(Mr.range(r,a)),s.length>t.maxMatches))return I.none}}return I.set(s)}},{decorations:e=>e.decorations}),Lr=F.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Rr=({state:e,dispatch:t})=>{let{selection:n}=e,r=N.create(n.ranges.map(t=>e.wordAt(t.head)||N.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function zr(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new yr(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new yr(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var Br=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Rr({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=zr(e,r);return i?(t(e.update({selection:e.selection.addRange(N.range(i.from,i.to),!1),effects:F.scrollIntoView(i.to)})),!0):!1},Vr=T.define({combine(e){return He(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new bi(e),scrollToMatch:e=>F.scrollIntoView(e)})}}),Hr=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||Er(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
2
+ `:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new $r(this):new qr(this)}getCursor(e,t=0,n){let r=e.doc?e:le.create({doc:e});return n??=r.doc.length,this.regexp?Yr(this,r,t,n):Gr(this,r,t,n)}},Ur=class{constructor(e){this.spec=e}};function Wr(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function Gr(e,t,n,r){let i;return e.wholeWord&&(i=Kr(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=Wr(e.test,t,i)),new yr(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function Kr(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(Xr(i,n-a))!=w.Word||t(Zr(i,n-a))!=w.Word)&&(t(Zr(i,r-a))!=w.Word||t(Xr(i,r-a))!=w.Word))}var qr=class extends Ur{constructor(e){super(e)}nextMatch(e,t,n){let r=Gr(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=Gr(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=Gr(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=Gr(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=Gr(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function Jr(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function Yr(e,t,n,r){let i;return e.wholeWord&&(i=Qr(t.charCategorizer(t.selection.main.head))),e.test&&(i=Jr(e.test,t,i)),new Sr(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function Xr(e,t){return e.slice(P(e,t,!1),t)}function Zr(e,t){return e.slice(t,P(e,t))}function Qr(e){return(t,n,r)=>!r[0].length||(e(Xr(r.input,r.index))!=w.Word||e(Zr(r.input,r.index))!=w.Word)&&(e(Zr(r.input,r.index+r[0].length))!=w.Word||e(Xr(r.input,r.index+r[0].length))!=w.Word)}var $r=class extends Ur{nextMatch(e,t,n){let r=Yr(this.spec,e,n,e.doc.length).next();return r.done&&(r=Yr(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=Yr(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=Yr(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=Yr(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},ei=A.define(),ti=A.define(),G=j.define({create(e){return new ni(mi(e).create(),null)},update(e,t){for(let n of t.effects)n.is(ei)?e=new ni(n.value.create(),e.panel):n.is(ti)&&(e=new ni(e.query,n.value?pi:null));return e},provide:e=>Ee.from(e,e=>e.panel)}),ni=class{constructor(e,t){this.query=e,this.panel=t}},ri=I.mark({class:`cm-searchMatch`}),ii=I.mark({class:`cm-searchMatch cm-searchMatch-selected`}),ai=ve.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(G))}update(e){let t=e.state.field(G);(t!=e.startState.field(G)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return I.none;let{view:n}=this,r=new Oe;for(let t=0,i=n.visibleRanges,a=i.length;t<a;t++){let{from:o,to:s}=i[t];for(;t<a-1&&s>i[t+1].from-500;)s=i[++t].to;e.highlight(n.state,o,s,(e,t)=>{let i=n.state.selection.ranges.some(n=>n.from==e&&n.to==t);r.add(e,t,i?ii:ri)})}return r.finish()}},{decorations:e=>e.decorations});function oi(e){return t=>{let n=t.state.field(G,!1);return n&&n.query.spec.valid?e(t,n):_i(t)}}var si=oi((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=N.single(r.from,r.to),a=e.state.facet(Vr);return e.dispatch({selection:i,effects:[Ci(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),gi(e),!0}),ci=oi((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=N.single(i.from,i.to),o=e.state.facet(Vr);return e.dispatch({selection:a,effects:[Ci(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),gi(e),!0}),li=oi((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:N.create(n.map(e=>N.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),ui=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let t=new yr(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(N.range(t.value.from,t.value.to))}return t(e.update({selection:N.create(a,o),userEvent:`select.search.matches`})),!0},di=oi((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,s=[],c,l,u=[];o.from==r&&o.to==i&&(l=n.toText(t.getReplacement(o)),s.push({from:o.from,to:o.to,insert:l}),o=t.nextMatch(n,o.from,o.to),u.push(F.announce.of(n.phrase(`replaced match on line $`,n.doc.lineAt(r).number)+`.`)));let d=e.state.changes(s);return o&&(c=N.single(o.from,o.to).map(d),u.push(Ci(e,o)),u.push(n.facet(Vr).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),fi=oi((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(e=>{let{from:n,to:r}=e;return{from:n,to:r,insert:t.getReplacement(e)}});if(!n.length)return!1;let r=e.state.phrase(`replaced $ matches`,n.length)+`.`;return e.dispatch({changes:n,effects:F.announce.of(r),userEvent:`input.replace.all`}),!0});function pi(e){return e.state.facet(Vr).createPanel(e)}function mi(e,t){let n=e.selection.main,r=n.empty||n.to>n.from+100?``:e.sliceDoc(n.from,n.to);if(t&&!r)return t;let i=e.facet(Vr);return new Hr({search:t?.literal??i.literal?r:r.replace(/\n/g,`\\n`),caseSensitive:t?.caseSensitive??i.caseSensitive,literal:t?.literal??i.literal,regexp:t?.regexp??i.regexp,wholeWord:t?.wholeWord??i.wholeWord})}function hi(e){let t=Ne(e,pi);return t&&t.dom.querySelector(`[main-field]`)}function gi(e){let t=hi(e);t&&t==e.root.activeElement&&t.select()}var _i=e=>{let t=e.state.field(G,!1);if(t&&t.panel){let n=hi(e);if(n&&n!=e.root.activeElement){let r=mi(e.state,t.query.spec);r.valid&&e.dispatch({effects:ei.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[ti.of(!0),t?ei.of(mi(e.state,t.query.spec)):A.appendConfig.of(Ti)]});return!0},vi=e=>{let t=e.state.field(G,!1);if(!t||!t.panel)return!1;let n=Ne(e,pi);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:ti.of(!1)}),!0},yi=[{key:`Mod-f`,run:_i,scope:`editor search-panel`},{key:`F3`,run:si,shift:ci,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:si,shift:ci,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:vi,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:ui},{key:`Mod-Alt-g`,run:Or},{key:`Mod-d`,run:Br,preventDefault:!0}],bi=class{constructor(e){this.view=e;let t=this.query=e.state.field(G).query.spec;this.commit=this.commit.bind(this),this.searchField=L(`input`,{value:t.search,placeholder:K(e,`Find`),"aria-label":K(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=L(`input`,{value:t.replace,placeholder:K(e,`Replace`),"aria-label":K(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=L(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=L(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=L(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return L(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=L(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>si(e),[K(e,`next`)]),n(`prev`,()=>ci(e),[K(e,`previous`)]),n(`select`,()=>li(e),[K(e,`all`)]),L(`label`,null,[this.caseField,K(e,`match case`)]),L(`label`,null,[this.reField,K(e,`regexp`)]),L(`label`,null,[this.wordField,K(e,`by word`)]),...e.state.readOnly?[]:[L(`br`),this.replaceField,n(`replace`,()=>di(e),[K(e,`replace`)]),n(`replaceAll`,()=>fi(e),[K(e,`replace all`)])],L(`button`,{name:`close`,onclick:()=>vi(e),"aria-label":K(e,`close`),type:`button`},[`×`])])}commit(){let e=new Hr({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:ei.of(e)}))}keydown(e){je(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?ci:si)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),di(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(ei)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Vr).top}};function K(e,t){return e.state.phrase(t)}var xi=30,Si=/[\s\.,:;?!]/;function Ci(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-xi),o=Math.min(i,n+xi),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<xi;e++)if(!Si.test(s[e+1])&&Si.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-xi;e--)if(!Si.test(s[e-1])&&Si.test(s[e])){s=s.slice(0,e);break}}return F.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var wi=F.baseTheme({".cm-panel.cm-search":{padding:`2px 6px 4px`,position:`relative`,"& [name=close]":{position:`absolute`,top:`0`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0},"& input, & button, & label":{margin:`.2em .6em .2em 0`},"& input[type=checkbox]":{marginRight:`.2em`},"& label":{fontSize:`80%`,whiteSpace:`pre`}},"&light .cm-searchMatch":{backgroundColor:`#ffff0054`},"&dark .cm-searchMatch":{backgroundColor:`#00ffff8a`},"&light .cm-searchMatch-selected":{backgroundColor:`#ff6a0054`},"&dark .cm-searchMatch-selected":{backgroundColor:`#ff00ff8a`}}),Ti=[G,ke.low(ai),wi],Ei=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},Di=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet(zi).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),o=new Oe,s=[],c=0,l=r.doc.iter(),u=0,d=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!s.length)break;let n,r;if(s.length)n=c,r=s.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>d)break;r=t.to,s.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))s.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,d);let i=!1;if(s.some(e=>e.from==n&&(e.to==r||r==d))&&(i=n==r,!i&&r-n<10)){let e=n-(u+l.value.length);e>0&&(l.next(e),u=n);for(let e=n;;){if(e>=r){i=!0;break}if(!l.lineBreak&&u+l.value.length>e)break;e=u+l.value.length,u+=l.value.length,l.next()}}let f=Xi(s);if(i)o.add(n,n,I.widget({widget:new Ui(f),diagnostics:s.slice()}));else{let e=s.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);o.add(n,r,I.mark({class:`cm-lintRange cm-lintRange-`+f+e,diagnostics:s.slice(),inclusiveEnd:s.some(e=>e.to>r)}))}if(c=r,c==d)break;for(let e=0;e<s.length;e++)s[e].to<=c&&s.splice(e--,1)}let f=o.finish();return new e(f,n,q(f))}};function q(e,t=null,n=0){let r=null;return e.between(n,1e9,(e,n,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new Ei(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new Ei(r.from,n,r.diagnostic)}),r}function Oi(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(zi).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(Ai))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function ki(e,t){return e.field(J,!1)?t:t.concat(A.appendConfig.of(Zi))}var Ai=A.define(),ji=A.define(),Mi=A.define(),J=j.define({create(){return new Di(I.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let i=t.changes.mapPos(e.selected.from,1);r=q(n,e.selected.diagnostic,i)||q(n,null,i)}!n.size&&i&&t.state.facet(zi).autoPanel&&(i=null),e=new Di(n,i,r)}for(let n of t.effects)if(n.is(Ai)){let r=t.state.facet(zi).autoPanel?n.value.length?Gi.open:null:e.panel;e=Di.init(n.value,r,t.state)}else n.is(ji)?e=new Di(e.diagnostics,n.value?Gi.open:null,e.selected):n.is(Mi)&&(e=new Di(e.diagnostics,e.panel,n.value));return e},provide:e=>[Ee.from(e,e=>e.panel),F.decorations.from(e,e=>e.diagnostics)]}),Ni=I.mark({class:`cm-lintRange cm-lintRange-active`});function Pi(e,t,n){let{diagnostics:r}=e.state.field(J),i,a=-1,o=-1;r.between(t-+(n<0),t+ +(n>0),(e,r,{spec:s})=>{if(t>=e&&t<=r&&(e==r||(t>e||n>0)&&(t<r||n<0)))return i=s.diagnostics,a=e,o=r,!1});let s=e.state.facet(zi).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:Fi(e,i)}}}:null}function Fi(e,t){return L(`ul`,{class:`cm-tooltip-lint`},t.map(t=>Hi(e,t,!1)))}var Ii=e=>{let t=e.state.field(J,!1);(!t||!t.panel)&&e.dispatch({effects:ki(e.state,[ji.of(!0)])});let n=Ne(e,Gi.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},Li=e=>{let t=e.state.field(J,!1);return!t||!t.panel?!1:(e.dispatch({effects:ji.of(!1)}),!0)},Ri=[{key:`Mod-Shift-m`,run:Ii,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(J,!1);if(!t)return!1;let n=e.state.selection.main,r=q(t.diagnostics,null,n.to+1);return!r&&(r=q(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)}}],zi=T.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...He(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Bi,tooltipFilter:Bi,needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t,hideOn:(e,t)=>e?t?(n,r,i)=>e(n,r,i)||t(n,r,i):e:t,autoPanel:(e,t)=>e||t})}}});function Bi(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function Vi(e){let t=[];if(e)actions:for(let{name:n}of e){for(let e=0;e<n.length;e++){let r=n[e];if(/[a-zA-Z]/.test(r)&&!t.some(e=>e.toLowerCase()==r.toLowerCase())){t.push(r);continue actions}}t.push(``)}return t}function Hi(e,t,n){let r=n?Vi(t.actions):[];return L(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},L(`span`,{class:`cm-diagnosticText`},t.renderMessage?t.renderMessage(e):t.message),t.actions?.map((n,i)=>{let a=!1,o=r=>{if(r.preventDefault(),a)return;a=!0;let i=q(e.state.field(J).diagnostics,t);i&&n.apply(e,i.from,i.to)},{name:s}=n,c=r[i]?s.indexOf(r[i]):-1,l=c<0?s:[s.slice(0,c),L(`u`,s.slice(c,c+1)),s.slice(c+1)];return L(`button`,{type:`button`,class:`cm-diagnosticAction`+(n.markClass?` `+n.markClass:``),onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&L(`div`,{class:`cm-diagnosticSource`},t.source))}var Ui=class extends M{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return L(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},Wi=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=Hi(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},Gi=class e{constructor(e){this.view=e,this.items=[],this.list=L(`ul`,{tabIndex:0,role:`listbox`,"aria-label":this.view.state.phrase(`Diagnostics`),onkeydown:t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)Li(this.view),this.view.focus();else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else if(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:n}=this.items[this.selectedIndex],r=Vi(n.actions);for(let i=0;i<r.length;i++)if(r[i].toUpperCase().charCodeAt(0)==t.keyCode){let t=q(this.view.state.field(J).diagnostics,n);t&&n.actions[i].apply(e,t.from,t.to)}}else return;t.preventDefault()}},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=L(`div`,{class:`cm-panel-lint`},this.list,L(`button`,{type:`button`,name:`close`,"aria-label":this.view.state.phrase(`close`),onclick:()=>Li(this.view)},`×`)),this.update()}get selectedIndex(){let e=this.view.state.field(J).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(J),n=0,r=!1,i=null,a=new Set;for(e.between(0,this.view.state.doc.length,(e,o,{spec:s})=>{for(let e of s.diagnostics){if(a.has(e))continue;a.add(e);let o=-1,s;for(let t=n;t<this.items.length;t++)if(this.items[t].diagnostic==e){o=t;break}o<0?(s=new Wi(this.view,e),this.items.splice(n,0,s),r=!0):(s=this.items[o],o>n&&(this.items.splice(n,o-n),r=!0)),t&&s.diagnostic==t.diagnostic?s.dom.hasAttribute(`aria-selected`)||(s.dom.setAttribute(`aria-selected`,`true`),i=s):s.dom.hasAttribute(`aria-selected`)&&s.dom.removeAttribute(`aria-selected`),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)r=!0,this.items.pop();this.items.length==0&&(this.items.push(new Wi(this.view,{from:-1,to:-1,severity:`info`,message:this.view.state.phrase(`No diagnostics`)})),r=!0),i?(this.list.setAttribute(`aria-activedescendant`,i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let n=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/n:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/n)}})):this.selectedIndex<0&&this.list.removeAttribute(`aria-activedescendant`),r&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)t();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=q(this.view.state.field(J).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:Mi.of(t)})}static open(t){return new e(t)}};function Ki(e,t=`viewBox="0 0 40 40"`){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function qi(e){return Ki(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,`width="6" height="3"`)}var Ji=F.baseTheme({".cm-diagnostic":{padding:`3px 6px 3px 8px`,marginLeft:`-1px`,display:`block`,whiteSpace:`pre-wrap`},".cm-diagnostic-error":{borderLeft:`5px solid #d11`},".cm-diagnostic-warning":{borderLeft:`5px solid orange`},".cm-diagnostic-info":{borderLeft:`5px solid #999`},".cm-diagnostic-hint":{borderLeft:`5px solid #66d`},".cm-diagnosticAction":{font:`inherit`,border:`none`,padding:`2px 4px`,backgroundColor:`#444`,color:`white`,borderRadius:`3px`,marginLeft:`8px`,cursor:`pointer`},".cm-diagnosticSource":{fontSize:`70%`,opacity:.7},".cm-lintRange":{backgroundPosition:`left bottom`,backgroundRepeat:`repeat-x`,paddingBottom:`0.7px`},".cm-lintRange-error":{backgroundImage:qi(`#d11`)},".cm-lintRange-warning":{backgroundImage:qi(`orange`)},".cm-lintRange-info":{backgroundImage:qi(`#999`)},".cm-lintRange-hint":{backgroundImage:qi(`#66d`)},".cm-lintRange-active":{backgroundColor:`#ffdd9980`},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:`relative`,"&:after":{content:`""`,position:`absolute`,bottom:0,left:`-2px`,borderLeft:`3px solid transparent`,borderRight:`3px solid transparent`,borderBottom:`4px solid #d11`}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:`orange`}},".cm-lintPoint-info":{"&:after":{borderBottomColor:`#999`}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:`#66d`}},".cm-panel.cm-panel-lint":{position:`relative`,"& ul":{maxHeight:`100px`,overflowY:`auto`,"& [aria-selected]":{backgroundColor:`#ddd`,"& u":{textDecoration:`underline`}},"&:focus [aria-selected]":{background_fallback:`#bdf`,backgroundColor:`Highlight`,color_fallback:`white`,color:`HighlightText`},"& u":{textDecoration:`none`},padding:0,margin:0},"& [name=close]":{position:`absolute`,top:`0`,right:`2px`,background:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:`#86714a80`},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:`#2e343e`}}});function Yi(e){return e==`error`?4:e==`warning`?3:e==`info`?2:1}function Xi(e){let t=`hint`,n=1;for(let r of e){let e=Yi(r.severity);e>n&&(n=e,t=r.severity)}return t}var Zi=[J,F.decorations.compute([J],e=>{let{selected:t,panel:n}=e.field(J);return!t||!n||t.from==t.to?I.none:I.set([Ni.range(t.from,t.to)])}),Se(Pi,{hideOn:Oi}),Ji],Qi=[Re(),Pe(),Ie(),ht(),Te(),we(),Le(),le.allowMultipleSelections.of(!0),_e(),O(Ce,{fallback:!0}),xe(),Ke(),We(),Fe(),b(),ye(),jr(),Ae.of([...Ue,...gr,...yi,...Mt,...ze,...Ge,...Ri])];Ie(),ht(),we(),O(Ce,{fallback:!0}),Ae.of([...gr,...Mt]);function $i(e,t){let n=(0,Je.c)(4),r=t===void 0?!1:t,[i,a]=(0,qe.useState)(void 0),o=(0,qe.useRef)(null),s,c;return n[0]!==r||n[1]!==e?(s=()=>{if(r||e.length===0){a(void 0);return}let t=function(){let t=window.innerHeight/2,n,r;for(let i of e){let e=document.getElementById(i);if(!e)continue;let a=e.getBoundingClientRect().top;a<0?n=i:r===void 0&&a<t&&(r=i)}a(r??n??e[0])},n=function(){o.current===null&&(o.current=requestAnimationFrame(()=>{o.current=null,t()}))};return document.addEventListener(`scroll`,n,{capture:!0,passive:!0}),t(),()=>{document.removeEventListener(`scroll`,n,{capture:!0}),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null)}},c=[e,r],n[0]=r,n[1]=e,n[2]=s,n[3]=c):(s=n[2],c=n[3]),(0,qe.useEffect)(s,c),i}var Y=n(),ea=300;async function ta(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Server error: ${t.status} ${t.statusText}`);let n=await t.json();if(!n.ok)throw Error(n.error??`Failed to load headings`);return n.headings??[]}var na=32,ra=12,ia=6,aa=`open-knowledge:outline-nav`;function oa(e){let t=(0,Je.c)(2),n;return t[0]===e?n=t[1]:(n=(0,Y.jsx)(v,{name:`outline-panel`,children:(0,Y.jsx)(sa,{...e})}),t[0]=e,t[1]=n),n}function sa(e){let t=(0,Je.c)(49),{docName:n,isSourceMode:r,className:p}=e,m=p===void 0?``:p,{pages:ee,loading:te}=re(),ne=f(),{activeProvider:h,activeDocName:ie}=oe(),g,_;t[0]===n?(g=t[1],_=t[2]):(g=[`page-headings`,n],_=()=>ta(n),t[0]=n,t[1]=g,t[2]=_);let v;t[3]!==n||t[4]!==te||t[5]!==ee?(v=!te&&ee.has(n),t[3]=n,t[4]=te,t[5]=ee,t[6]=v):v=t[6];let se;t[7]!==g||t[8]!==_||t[9]!==v?(se={queryKey:g,queryFn:_,enabled:v,staleTime:1/0},t[7]=g,t[8]=_,t[9]=v,t[10]=se):se=t[10];let{data:y,isLoading:b,error:x}=a(se),S;t[11]===y?S=t[12]:(S=y===void 0?[]:y,t[11]=y,t[12]=S);let C=S,w,ce;t[13]!==ie||t[14]!==h||t[15]!==n||t[16]!==ne?(w=()=>{if(!h||ie!==n)return;let e=h.document,t=null,r=()=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{t=null,ne.invalidateQueries({queryKey:[`page-headings`,n]})},ea)};return e.on(`update`,r),()=>{e.off(`update`,r),t!==null&&clearTimeout(t)}},ce=[h,ie,n,ne],t[13]=ie,t[14]=h,t[15]=n,t[16]=ne,t[17]=w,t[18]=ce):(w=t[17],ce=t[18]),(0,qe.useEffect)(w,ce);let T;t[19]===C?T=t[20]:(T=C.map(ca),t[19]=C,t[20]=T);let E=$i(T,r),le;t[21]!==E||t[22]!==C?(le=E?C.findIndex(e=>e.slug===E):-1,t[21]=E,t[22]=C,t[23]=le):le=t[23];let D=le,ue;t[24]!==n||t[25]!==r?(ue=function(e,t){let i={index:e,slug:t,mode:r?`source`:`wysiwyg`};i.mode===`source`&&Xe(n,{kind:`outline`,detail:i}),window.dispatchEvent(new CustomEvent(aa,{detail:i}))},t[24]=n,t[25]=r,t[26]=ue):ue=t[26];let de=ue,fe=((D>=0?C[D].level:1)-1)*ra+(ra-ia)/2,pe=D*na+(na-ia)/2,O;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,Y.jsx)(u,{children:`Outline`}),t[27]=O):O=t[27];let k;t[28]!==C.length||t[29]!==b?(k=!b&&(0,Y.jsx)(l,{children:C.length}),t[28]=C.length,t[29]=b,t[30]=k):k=t[30];let A;t[31]===k?A=t[32]:(A=(0,Y.jsxs)(c,{children:[O,k]}),t[31]=k,t[32]=A);let j;t[33]!==D||t[34]!==E||t[35]!==x||t[36]!==de||t[37]!==C||t[38]!==b||t[39]!==fe||t[40]!==pe?(j=x?(0,Y.jsx)(i,{className:`px-2`,children:x instanceof Error?x.message:`Failed to load headings`}):C.length===0&&!b?(0,Y.jsx)(o,{className:`px-2`,children:`No headings yet.`}):(0,Y.jsxs)(`nav`,{"aria-label":`Document outline`,className:`relative`,children:[D>=0&&(0,Y.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 rounded-full bg-primary motion-safe:[transition:transform_0.25s_var(--ease-out-strong)]`,style:{width:ia,height:ia,transform:`translate(${fe}px, ${pe}px)`}}),C.map((e,t)=>{let n=e.slug===E;return(0,Y.jsx)(`button`,{type:`button`,"aria-current":n?`location`:void 0,onClick:()=>de(t,e.slug),className:ae(`w-full cursor-pointer truncate py-1.5 pe-2 text-left text-sm transition-colors`,n?`font-medium text-primary`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${(e.level-1)*ra+20}px`},title:e.text,children:e.text},t)})]}),t[33]=D,t[34]=E,t[35]=x,t[36]=de,t[37]=C,t[38]=b,t[39]=fe,t[40]=pe,t[41]=j):j=t[41];let M;t[42]!==b||t[43]!==j?(M=(0,Y.jsx)(s,{className:`px-3 py-2`,"aria-busy":b,children:j}),t[42]=b,t[43]=j,t[44]=M):M=t[44];let me;return t[45]!==m||t[46]!==A||t[47]!==M?(me=(0,Y.jsxs)(d,{className:m,children:[A,M]}),t[45]=m,t[46]=A,t[47]=M,t[48]=me):me=t[48],me}function ca(e){return e.slug}function la(e){if(!e)return`plaintext`;if(e.types.includes(`vscode-editor-data`))return`vscode`;if(e.types.includes(`text/x-gfm`))return`gfm`;let t=e.getData(`text/html`);return t?/data-pm-slice/i.test(t)?`pm-origin`:/docs-internal-guid-/i.test(t)?`gdocs`:/xmlns:o="urn:schemas-microsoft-com:office/i.test(t)||/<meta[^>]*Generator[^>]*Microsoft Word/i.test(t)?`word`:/class="gmail_|class='gmail_/i.test(t)?`gmail`:/notionvc:/i.test(t)?`notion`:/Cocoa HTML Writer/i.test(t)?`apple`:/c-message_kit__|c-message__|c-compose/i.test(t)?`slack`:/google-sheets-html-origin/i.test(t)?`gsheets`:/data-hovercard-type=/i.test(t)?`github`:`generic`:`plaintext`}var ua=250,da=100;function X(e,t){let n=performance.now()-e;n<(t.op===`paste`?ua:da)||console.warn(JSON.stringify({event:`clipboard-slow-op`,op:t.op,view:t.view,elapsedMs:Math.round(n),branch:t.branch,source:t.source,...t.htmlBytes==null?{}:{htmlBytes:t.htmlBytes}}))}function Z(e){console.warn(JSON.stringify({event:`clipboard-source-detected`,view:e.view,source:e.source,branch:e.branch}))}function Q(e){console.warn(JSON.stringify({event:`clipboard-html-conversion-failed`,view:e.view,stage:e.stage,source:e.source,...e.branch==null?{}:{branch:e.branch},reason:e.reason,...e.errorClass==null?{}:{errorClass:e.errorClass},...e.htmlBytes==null?{}:{htmlBytes:e.htmlBytes}}))}function fa(e){console.warn(JSON.stringify({event:`clipboard-serialize-failed`,view:e.view,kind:e.kind,reason:e.reason}))}function pa(e){console.warn(JSON.stringify({event:`clipboard-chunked-insert-failed`,view:e.view,chunksCompleted:e.chunksCompleted,totalChunks:e.totalChunks,bytesWritten:e.bytesWritten,bytesRemaining:e.bytesRemaining,reason:e.reason}))}function $(e){if(e instanceof ie)return`HtmlPayloadTooLargeError`;if(e instanceof m)return`ChunkedInsertError`;if(e instanceof Error&&e.name&&e.name!==`Error`)return e.name}var ma=/^```/m,ha=/^#{1,6} /m,ga=/^[-*+] /m,_a=/^\d+[.)] /m,va=/\[[^\]\n]+\]\([^)\n]+\)/,ya=/^\|.*\|$/m,ba=/^\|?\s*(:?-+:?)(\s*\|\s*:?-+:?)+\s*\|?$/m,xa=/\$\$[\s\S]+?\$\$/;function Sa(e){if(!e)return!1;let t=0;ma.test(e)&&t++,ha.test(e)&&t++,ga.test(e)&&t++,_a.test(e)&&t++,va.test(e)&&t++,ya.test(e)&&ba.test(e)&&t++,xa.test(e)&&t++;let n=e.split(`
3
+ `).length,r=Math.min(3,Math.floor(n/5));return t>=Math.max(1,r)}var Ca=3e3,wa=new Map;function Ta(e,t=`Pasted as plain text — some formatting could not be converted.`){let n=Date.now();return n-(wa.get(e)??0)<Ca?!1:(wa.set(e,n),y.error(t),!0)}var Ea=!1,Da=!1;function Oa(e){Ea=e.shiftKey}function ka(e){(e.key===`Shift`||!e.shiftKey)&&(Ea=!1)}function Aa(){Ea=!1}function ja(){Da||typeof window>`u`||(window.addEventListener(`keydown`,Oa,!0),window.addEventListener(`keyup`,ka,!0),window.addEventListener(`blur`,Aa,!0),Da=!0)}function Ma(){ja()}function Na(){return ja(),Ea}function Pa(e){return Na()?!0:e.shiftKey===!0}function Fa(e){return(t,n)=>{let r=n.clipboardData;if(!r||r.types.length===0)return!1;let i=performance.now(),a=la(r),o=r.getData(`text/plain`),s=r.getData(`text/html`);if(Pa(n))return o&&La(t,o),Z({view:`wysiwyg`,branch:`shift`,source:a}),X(i,{op:`paste`,view:`wysiwyg`,branch:`shift`,source:a}),!0;if(Ia(t))return o&&La(t,o),Z({view:`wysiwyg`,branch:`codeblock`,source:a}),X(i,{op:`paste`,view:`wysiwyg`,branch:`codeblock`,source:a}),!0;let c=r.getData(`vscode-editor-data`);if(c&&o&&za(t,c,o,a))return Z({view:`wysiwyg`,branch:`A`,source:a}),X(i,{op:`paste`,view:`wysiwyg`,branch:`A`,source:a}),!0;let l=r.getData(`text/x-gfm`);return l&&Ba(t,l,e,`B`,a)?(Z({view:`wysiwyg`,branch:`B`,source:a}),X(i,{op:`paste`,view:`wysiwyg`,branch:`B`,source:a}),!0):s&&/data-pm-slice/i.test(s)?(Z({view:`wysiwyg`,branch:`C`,source:a}),X(i,{op:`paste`,view:`wysiwyg`,branch:`C`,source:a}),!1):o&&s&&Sa(o)&&Ba(t,o,e,`B`,a)?(Z({view:`wysiwyg`,branch:`B`,source:a}),X(i,{op:`paste`,view:`wysiwyg`,branch:`B`,source:a}),!0):s&&Va(t,s,e,a)?(Z({view:`wysiwyg`,branch:`D`,source:a}),X(i,{op:`paste`,view:`wysiwyg`,branch:`D`,source:a,htmlBytes:s.length}),!0):o?Sa(o)&&Ba(t,o,e,`E`,`markdown-text`)?(Z({view:`wysiwyg`,branch:`E`,source:`markdown-text`}),X(i,{op:`paste`,view:`wysiwyg`,branch:`E`,source:`markdown-text`}),!0):(La(t,o),Z({view:`wysiwyg`,branch:`E`,source:`plaintext`}),X(i,{op:`paste`,view:`wysiwyg`,branch:`E`,source:`plaintext`}),!0):!1}}function Ia(e){let{$from:t}=e.state.selection;for(let e=t.depth;e>=0;e--)if(t.node(e).type.name===`codeBlock`)return!0;return!1}function La(e,t){let{schema:n,tr:r}=e.state;t&&e.dispatch(r.replaceSelectionWith(n.text(t)).scrollIntoView())}var Ra=/^[A-Za-z0-9_+-]+$/;function za(e,t,n,r){try{let r=JSON.parse(t),i=typeof r.mode==`string`?r.mode:``,a=Ra.test(i)?i:``,o=e.state.schema.nodes.codeBlock;if(!o)return!1;let s=o.create({language:a},n?e.state.schema.text(n):null);return e.dispatch(e.state.tr.replaceSelectionWith(s).scrollIntoView()),!0}catch(e){return Q({view:`wysiwyg`,stage:`branchA`,source:r,branch:`A`,reason:e?.message??`unknown`,errorClass:$(e)}),!1}}function Ba(e,t,n,r,i){let a;try{a=n.mdManager.parse(t)}catch(e){return Q({view:`wysiwyg`,stage:`mdManagerParse`,source:i,branch:r,reason:e?.message??`unknown`,errorClass:$(e)}),!1}return Ha(e,a,i,r)}function Va(e,t,n,r){let i;try{i=ne(t)}catch(e){return Q({view:`wysiwyg`,stage:`htmlToMdast`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:$(e),htmlBytes:t.length}),Ta(`wysiwyg`),!1}let a;try{a=ee(i)}catch(e){return Q({view:`wysiwyg`,stage:`mdastToMarkdown`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:$(e),htmlBytes:t.length}),Ta(`wysiwyg`),!1}let o;try{o=n.mdManager.parse(a)}catch(e){return Q({view:`wysiwyg`,stage:`mdManagerParse`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:$(e),htmlBytes:t.length}),Ta(`wysiwyg`),!1}return Ha(e,o,r,`D`,t.length)}function Ha(e,t,n,r,i){try{let n=e.state.schema.nodeFromJSON(t);return e.dispatch(e.state.tr.replaceSelection(n.slice(0,n.content.size)).scrollIntoView()),!0}catch(e){return Q({view:`wysiwyg`,stage:`applyJsonSlice`,source:n,branch:r,reason:e?.message??`unknown`,errorClass:$(e),...i==null?{}:{htmlBytes:i}}),!1}}function Ua(e){return(t,n)=>{try{return Ka(t,n.state.schema,e.mdManager)}catch(e){return console.warn(`[clipboard] text serialize fell through — PM default textBetween`,e),t.content.textBetween(0,t.content.size,`
4
+
5
+ `)}}}var Wa=class extends h{mdManager;constructor(e){super({},{}),this.mdManager=e}serializeFragment(e,t,n){try{let t=e.firstChild?.type.schema;if(!t)return n??document.createDocumentFragment();let r=Ya(qa(e,t,this.mdManager));if(n){for(let e of Array.from(r.childNodes))n.appendChild(e);return n}return r}catch(e){return console.warn(`[clipboard] HTML serialize fell through — PM default DOMSerializer`,e),n??document.createDocumentFragment()}}};function Ga(e){return new Wa(e.mdManager)}function Ka(e,t,n){return n.serialize(Ja(e,t))}function qa(e,t,n){return g(Ka(new p(e,0,0),t,n))}function Ja(e,t){let n=t.topNodeType.createAndFill(null,e.content);if(!n){let e=t.topNodeType.createAndFill();if(!e)throw Error(`[clipboard] schema cannot fill topNodeType`);return e.toJSON()}return n.toJSON()}function Ya(e){let t=new DOMParser().parseFromString(e,`text/html`),n=document.createDocumentFragment();for(let e of Array.from(t.body.childNodes))n.appendChild(e);return n}function Xa(e){return Ma(),F.domEventHandlers({copy:(e,t)=>Za(e,t,`copy`),cut:(e,t)=>Za(e,t,`cut`),paste:(t,n)=>Qa(t,n,e)})}function Za(e,t,n){let{from:r,to:i}=t.state.selection.main;if(r===i)return e.preventDefault(),!0;let a=e.clipboardData;if(!a)return!1;let o=performance.now();try{let s=t.state.sliceDoc(r,i);a.setData(`text/plain`,s);try{a.setData(`text/html`,g(s))}catch(e){fa({view:`source`,kind:`html`,reason:e?.message??`unknown`})}return e.preventDefault(),n===`cut`&&t.dispatch({changes:{from:r,to:i,insert:``}}),X(o,{op:n,view:`source`,branch:`serialize`,source:`local`}),!0}catch(e){return fa({view:`source`,kind:`text`,reason:e?.message??`unknown`}),!1}}function Qa(e,t,n){let r=e.clipboardData;if(!r||r.types.length===0)return!1;let i=performance.now(),a=la(r),o=r.getData(`text/plain`),s=r.getData(`text/html`);if(Pa(e))return Z({view:`source`,branch:`shift`,source:a}),X(i,{op:`paste`,view:`source`,branch:`shift`,source:a}),!1;let c=r.getData(`vscode-editor-data`);return c&&o&&eo(t,c,o,a)?(e.preventDefault(),Z({view:`source`,branch:`A`,source:a}),X(i,{op:`paste`,view:`source`,branch:`A`,source:a}),!0):s&&/data-pm-slice/i.test(s)?(Z({view:`source`,branch:`C`,source:a}),X(i,{op:`paste`,view:`source`,branch:`C`,source:a}),!1):s&&to(t,s,n,a)?(e.preventDefault(),Z({view:`source`,branch:`D`,source:a}),X(i,{op:`paste`,view:`source`,branch:`D`,source:a,htmlBytes:s.length}),!0):(Z({view:`source`,branch:`E`,source:a}),X(i,{op:`paste`,view:`source`,branch:`E`,source:a}),!1)}var $a=/^[A-Za-z0-9_+-]+$/;function eo(e,t,n,r){try{let r=JSON.parse(t),i=typeof r.mode==`string`?r.mode:``,a=`\`\`\`${$a.test(i)?i:``}\n${n}\n\`\`\`\n`,{from:o,to:s}=e.state.selection.main;return e.dispatch({changes:{from:o,to:s,insert:a},selection:{anchor:o+a.length}}),!0}catch(e){return Q({view:`source`,stage:`branchA`,source:r,branch:`A`,reason:e?.message??`unknown`,errorClass:$(e)}),!1}}function to(e,t,n,r){let i;try{i=ne(t)}catch(e){return Q({view:`source`,stage:`htmlToMdast`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:$(e),htmlBytes:t.length}),!1}let a;try{a=ee(i)}catch(e){return Q({view:`source`,stage:`mdastToMarkdown`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:$(e),htmlBytes:t.length}),!1}let{from:o,to:s}=e.state.selection.main;if(!(a.length>500*1024))return e.dispatch({changes:{from:o,to:s,insert:a},selection:{anchor:o+a.length}}),!0;let c=o===s?``:e.state.sliceDoc(o,s);o!==s&&e.dispatch({changes:{from:o,to:s,insert:``}});let l=o,u=_(n.ytext,l);return te(n.ydoc,n.ytext,l,a,{resolveOffset:e=>{let t=se(u,n.ydoc);return t==null?e:t.index+(e-l)}}).catch(i=>{no({view:e,source:r,html:t,restoreText:c,anchorIndex:l,anchorRelPos:u,ydoc:n.ydoc,err:i})}),!0}function no(e){let{view:t,source:n,html:r,restoreText:i,anchorIndex:a,anchorRelPos:o,ydoc:s,err:c}=e;if(c instanceof m&&c.bytesWritten>0){let e=o&&s?se(o,s)?.index??a:a,n=Math.min(e+c.bytesWritten,t.state.doc.length);try{t.dispatch({changes:{from:e,to:n,insert:i}})}catch(e){console.warn(`[clipboard] partial-chunk rollback dispatch failed`,e)}}else if(i.length>0)try{t.dispatch({changes:{from:a,to:a,insert:i}})}catch(e){console.warn(`[clipboard] selection-restore dispatch failed`,e)}if(c instanceof m){pa({view:`source`,chunksCompleted:c.chunksCompleted,totalChunks:c.totalChunks,bytesWritten:c.bytesWritten,bytesRemaining:c.bytesRemaining,reason:c.message}),y.error(`Paste was incomplete — ${c.chunksCompleted} of ${c.totalChunks} chunks landed. Your selection has been restored.`);return}Q({view:`source`,stage:`chunkedYTextInsert`,source:n,branch:`D`,reason:c?.message??`unknown`,errorClass:$(c),htmlBytes:r.length}),y.error(`Paste failed. Your selection has been restored.`)}export{aa as a,_r as c,Xe as d,Fa as i,Qe as l,Ga as n,oa as o,Ua as r,Qi as s,Xa as t,Ze as u};