varq=classi{lineAt(e){if(e<0||e>this.length)thrownewRangeError(`Invalid position ${e} in document of length ${this.length}`);returnthis.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)thrownewRangeError(`Invalid line number ${e} in ${this.lines}-line document`);returnthis.lineInner(e,!0,1,0)}replace(e,t,n){letr=[];returnthis.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),oi.from(r,this.length-(t-e)+n.length)}append(e){returnthis.replace(this.length,this.length,e)}slice(e,t=this.length){letn=[];returnthis.decompose(e,t,n,0),oi.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;lett=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=newGt(this),s=newGt(e);for(leto=t,O=t;;){if(r.next(o),s.next(o),o=0,r.lineBreak!=s.lineBreak||r.done!=s.done||r.value!=s.value)return!1;if(O+=r.value.length,r.done||O>=n)return!0}}iter(e=1){returnnewGt(this,e)}iterRange(e,t=this.length){returnnewXn(this,e,t)}iterLines(e,t){letn;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);letr=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}returnnewWn(n)}toString(){returnthis.sliceString(0)}toJSON(){lete=[];returnthis.flatten(e),e}constructor(){}staticof(e){if(e.length==0)thrownewRangeError("A document must have at least one line");returne.length==1&&!e[0]?i.empty:e.length<=32?newze(e):oi.from(ze.split(e,[]))}},ze=classiextendsq{constructor(e,t=$d(e)){super(),this.text=e,this.length=t}getlines(){returnthis.text.length}getchildren(){returnnull}lineInner(e,t,n,r){for(lets=0;;s++){leto=this.text[s],O=r+o.length;if((t?n:O)>=e)returnnewJr(r,O,n,o);r=O+1,n++}}decompose(e,t,n,r){lets=e<=0&&t>=this.length?this:newi(Ol(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(r&1){leto=n.pop(),O=zn(s.text,o.text.slice(),0,s.length);if(O.length<=32)n.push(newi(O,o.length+s.length));else{letl=O.length>>1;n.push(newi(O.slice(0,l)),newi(O.slice(l)))}}elsen.push(s)}replace(e,t,n){if(!(ninstanceofi))returnsuper.replace(e,t,n);letr=zn(this.text,zn(n.text,Ol(this.text,0,e)),t),s=this.length+n.length-(t-e);returnr.length<=32?newi(r,s):oi.from(i.split(r,[]),s)}sliceString(e,t=this.length,n=`
`,r=i.state.doc.line(r.number+(t?1:-1)),s=i.bidiSpans(r),a=S.cursor(t?r.from:r.to)}if(l){if(!l(h))return O}else{if(!n)return a;l=n(h)}O=a}}function fp(i,e,t){let n=i.state.charCategorizer(e),r=n(t);return s=>{let o=n(s);return r==qe.Space&&(r=o),r==o}}function up(i,e,t,n){let r=e.head,s=t?1:-1;if(r==(t?i.state.doc.length:0))return S.cursor(r,e.assoc);let o=e.goalColumn,O,l=i.contentDOM.getBoundingClientRect(),a=i.coordsAtPos(r,e.assoc||-1),h=i.documentTop;if(a)o==null&&(o=a.left-l.left),O=s<0?a.top:a.bottom;else{let d=i.viewState.lineBlockAt(r);o==null&&(o=Math.min(l.right-l.left,i.defaultCharacterWidth*(r-d.from))),O=(s<0?d.top:d.bottom)+h}let c=l.left+o,f=n??i.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=O+(f+d)*s,m=Ma(i,{x:c,y:p},!1,s);if(p<l.top||p>l.bottom||(s<0?m<r:m>r)){let $=i.docView.coordsForChar(m),g=!$||p<$.top?-1:1;return S.cursor(m,g,void 0,o)}}}function Ln(i,e,t){for(;;){let n=0;for(let r of i)r.between(e-1,e+1,(s,o,O)=>{if(e>s&&e<o){let l=n||t||(e-s<o-e?-1:1);e=l<0?s:o,n=l}});if(!n)return e}}function gs(i,e,t){let n=Ln(i.state.facet(oo).map(r=>r(i)),t.from,e.head>t.from?-1:1);return n==t.from?t:S.cursor(n,n<t.from?1:-1)}var Vs=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,z.safari&&e.contentDOM.addEventListener("input",()=>null),z.gecko&&Tp(e.contentDOM.ownerDocument)}handleEvent(e){!Qp(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||this.runHandlers(e.type,e)}runHandlers(e,t){let n=this.handlers[e];if(n){for(let r of n.observers)r(this.view,t);for(let r of n.handlers){if(t.defaultPrevented)break;if(r(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=dp(e),n=this.handlers,r=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,O=n[s];O&&o!=!O.handlers.length&&(r.removeEventListener(s,this.handleEvent),O=null),O||r.addEventListener(s,this.handleEvent,{passive:o})}for(let s in n)s!="scroll"&&!t[s]&&r.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&Date.now()<this.lastEscPress+2e3)return!0;if(e.keyCode!=27&&Da.indexOf(e.keyCode)<0&&(this.view.inputState.lastEscPress=0),z.android&&z.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return z.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=La.find(n=>n.keyCode==e.keyCode))&&!e.ctrlKey||pp.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(){let e=this.pendingIOSKey;return e?(this.pendingIOSKey=void 0,pi(this.view.contentDOM,e.key,e.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:z.safari&&!z.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function Dl(i,e){return(t,n)=>{try{return e.call(i,n,t)}catch(r){ut(t.state,r)}}}function dp(i){let e=Object.create(null);function t(n){return e[n]||(e[n]={observers:[],handlers:[]})}for(let n of i){let r=n.spec;if(r&&r.domEventHandlers)for(let s in r.domEventHandlers
`+t.scrub(),s=this.advance(r);return s>-1&&s<r.length?this.complete(e,n,s):!1}finish(e,t){return(this.stage==2||this.stage==3)&&yn(t.content,this.pos)==t.content.length?this.complete(e,t,t.content.length):!1}complete(e,t,n){return e.addLeafElement(t,U(b.LinkReference,this.start,this.start+n,this.elts)),!0}nextStage(e){return e?(this.pos=e.to-this.start,this.elts.push(e),this.stage++,!0):(e===!1&&(this.stage=-1),!1)}advance(e){for(;;){if(this.stage==-1)return-1;if(this.stage==0){if(!this.nextStage(Zu(e,this.pos,this.start,!0)))return-1;if(e.charCodeAt(this.pos)!=58)return this.stage=-1;this.elts.push(U(b.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else if(this.stage==1){if(!this.nextStage(Wu(e,yn(e,this.pos),this.start)))return-1}else if(this.stage==2){let t=yn(e,this.pos),n=0;if(t>this.pos){let r=Ru(e,t,this.start);if(r){let s=TO(e,r.to-this.start);s>0&&(this.nextStage(r),n=s)}}return n||(n=TO(e,this.pos)),n>0&&n<e.length?n:-1}else return TO(e,this.pos)}}};function TO(i,e){for(;e<i.length;e++){let t=i.charCodeAt(e);if(t==10)break;if(!Ie(t))return-1}return e}var VO=class{nextLine(e,t,n){let r=t.depth<e.stack.length?-1:Pu(t),s=t.next;if(r<0)return!1;let o=U(b.HeaderMark,e.lineStart+t.pos,e.lineStart+r);return e.nextLine(),e.addLeafElement(n,U(s==61?b.SetextHeading1:b.SetextHeading2,n.start,e.prevLineEnd(),[...e.parser.parseInline(n.content,n.start),o])),!0}finish(){return!1}},yQ={LinkReference(i,e){return e.content.charCodeAt(0)==91?new YO(e):null},SetextHeading(){return new VO}},bQ=[(i,e)=>bu(e)>=0,(i,e)=>Su(e)>=0,(i,e)=>Qu(e)>=0,(i,e)=>GO(e,i,!0)>=0,(i,e)=>IO(e,i,!0)>=0,(i,e)=>EO(e,i,!0)>=0,(i,e)=>ku(e,i,!0)>=0],PQ={text:"",end:0},CO=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.line=new WO,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=r[r.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=r[0].from,this.block=Lr.create(b.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=n.length?new AO(n,t):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(this.stoppedAt!=null&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line:e}=this;for(;;){for(;e.depth<this.stack.length;)this.finishContext();for(let n of e.markers)this.addNode(n.type,n.from,n.to);if(e.pos<e.text.length)break;if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(e.basePos))return null;e:for(;;){for(let n of this.parser.blockParsers)if(n){let r=n(this,e);if(r!=!1){if(r==!0)return null;e.forward();continue e}}break}let t=new XO(this.lineStart+e.pos,e.text.slice(e.pos));for(let n of this.parser.leafBlockParsers)if(n){let r=n(this,t);r&&t.parsers.push(r)}e:for(;this.nextLine()&&e.pos!=e.text.length;){if(e.indent<e.baseIndent+4){for(let n of this.parser.endLeafBlock)if(n(this,e,t))break e}for(let n of t.parsers)if(n.nextLine(this,e,t))return null;t.content+=`
`+e.scrub();for(let n of e.markers)t.marks.push(n)}return this.finishLeaf(t),null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}reuseFragment(e){if(!this.fragments.moveTo(this.absoluteLineStart+e,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let t=this.fragments.takeNodes(this);return t?(this.absoluteLineStart+=t,this.lineStart=Yu(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0):!1}get depth(){return this.stack.length}parentType(e=this.depth-1){return this.parser.nodeSet.types[this.stack[e].type]}nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}scanLine(e){let t=PQ;if(t.end=e,e>=this.to)t.text="";else if(t.text=this.lineChunkAt(e),t.end+=t.text.length,this.ranges.length>1){let n=this.absoluteLineStart,r=this.rangeI;for(;this.ranges[r].to<t.end;){r++;let s=this.ranges[r].from,o=this.lineChunkAt(s);t.end=s+o.length,t.text=t.text.slice(0,this.ranges[r-1].to-n)+o,n=t.end-t.text.length}}return t}readLine(){let{line:e}=this,{text:t,end:n}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=n,e.reset(t);e.depth<this.stack.length;e.depth++){let r=this.stack[e.depth],s=this.parser.skipContextMarkup[r.type];if(!s)throw new Error("Unhandled block context "+b[r.type]);if(!s(r,this,e))break;e.forward()}}lineChunkAt(e){let t=this.input.chunk(e),n;if(this.input.lineChunks)n=t==`
`);n=r<0?t:t.slice(0,r)}return e+n.length>this.to?n.slice(0,this.to-e):n}prevLineEnd(){return this.atEnd?this.lineStart:this.lineStart-1}startContext(e,t,n=0){this.block=Lr.create(e,n,this.lineStart+t,this.block.hash,this.lineStart+this.line.text.length),this.stack.push(this.block)}startComposite(e,t,n=0){this.startContext(this.parser.getNodeType(e),t,n)}addNode(e,t,n){typeof e=="number"&&(e=new Y(this.parser.nodeSet.types[e],zi,zi,(n??this.prevLineEnd())-t)),this.block.addChild(e,t-this.block.from)}addElement(e){this.block.addChild(e.toTree(this.parser.nodeSet),e.from-this.block.from)}addLeafElement(e,t){this.addNode(this.buffer.writeElements(_O(t.children,e.marks),-t.from).finish(t.type,t.to-t.from),t.from)}finishContext(){let e=this.stack.pop(),t=this.stack[this.stack.length-1];t.addChild(e.toTree(this.parser.nodeSet),e.from-t.from),this.block=t}finish(){for(;this.stack.length>1;)this.finishContext();return this.addGaps(this.block.toTree(this.parser.nodeSet,this.lineStart))}addGaps(e){return this.ranges.length>1?vu(this.ranges,0,e.topNode,this.ranges[0].from,this.reusePlaceholders):e}finishLeaf(e){for(let n of e.parsers)if(n.finish(this,e))return;let t=_O(this.parser.parseInline(e.content,e.start),e.marks);this.addNode(this.buffer.writeElements(t,-e.start).finish(b.Paragraph,e.content.length),e.start)}elt(e,t,n,r){return typeof e=="string"?U(this.parser.getNodeType(e),t,n,r):new Br(e,t)}get buffer(){return new Dr(this.parser.nodeSet)}};function vu(i,e,t,n,r){let s=i[e].to,o=[],O=[],l=t.from+n;function a(h,c){for(;c?h>=s:h>s;){let f=i[e+1].from-s;n+=f,h+=f,e++,s=i[e].to}}for(let h=t.firstChild;h;h=h.nextSibling){a(h.from+n,!0);let c=h.from+n,f,d=r.get(h.tree);d?f=d:h.to+n>s?(f=vu(i,e,h,n,r),a(h.to+n,!1)):f=h.toTree(),o.push(f),O.push(c-l)}return a(t.to+n,!1),new Y(t.type,o,O,t.to+n-l,t.tree?t.tree.propValues:void 0)}var Pn=class i extends $t{constructor(e,t,n,r,s,o,O,l,a){super(),this.nodeSet=e,this.blockParsers=t,this.leafBlockParsers=n,this.blockNames=r,this.endLeafBlock=s,this.skipContextMarkup=o,this.inlineParsers=O,this.inlineNames=l,this.wrappers=a,this.nodeTypes=Object.create(null);for(let h of e.types)this.nodeTypes[h.name]=h.id}createParse(e,t,n){let r=new CO(this,e,t,n);for(let s of this.wrappers)r=s(r,e,t,n);return r}configure(e){let t=qO(e);if(!t)return this;let{nodeSet:n,skipContextMarkup:r}=this,s=this.blockParsers.slice(),o=this.leafBlockParsers.slice(),O=this.blockNames.slice(),l=this.inlineParsers.slice(),a=this.inlineNames.slice(),h=this.endLeafBlock.slice(),c=this.wrappers;if(Sn(t.defineNodes)){r=Object.assign({},r);let f=n.types.slice(),d;for(let p of t.defineNodes){let{name:m,block:$,composite:g,style:Q}=typeof p=="string"?{name:p}:p;if(f.some(P=>P.name==m))continue;g&&(r[f.length]=(P,w,Z)=>g(w,Z,P.value));let k=f.length,y=g?["Block","BlockContext"]:$?k>=b.ATXHeading1&&k<=b.SetextHeading2?["Block","LeafBlock","Heading"]:["Block","LeafBlock"]:void 0;f.push(F.define({id:k,name:m,props:y&&[[R.group,y]]})),Q&&(d||(d={}),Array.isArray(Q)||Q instanceof je?d[m]=Q:Object.assign(d,Q))}n=new pt(f),d&&(n=n.extend(ne(d)))}if(Sn(t.props)&&(n=n.extend(...t.props)),Sn(t.remove))for(let f of t.remove){let d=this.blockNames.indexOf(f),p=this.inlineNames.indexOf(f);d>-1&&(s[d]=o[d]=void 0),p>-1&&(l[p]=void 0)}if(Sn(t.parseBlock))for(let f of t.parseBlock){let d=O.indexOf(f.name);if(d>-1)s[d]=f.parse,o[d]=f.leaf;else{let p=f.before?Mr(O,f.before):f.after?Mr(O,f.after)+1:O.length-1;s.splice(p,0,f.parse),o.splice(p,0,f.leaf),O.splice(p,0,f.name)}f.endLeaf&&h.push(f.endLeaf)}if(Sn(t.parseInline))for(let f of t.parseInline){let d=a.indexOf(f.name);if(d>-1)l[d]=f.parse;else{let p=f.before?Mr(a,f.before):f.after?Mr(a,f.after)+1:a.length-1;l.splice(p,0,f.parse),a.splice(p,0,f.name)}}return t.wrap&&(c=c.concat(t.wrap)),new i(n,s,o,O,h,r,l,a,c)}getNodeType(e){let t=this.nodeTypes[e];if(t==null)throw new RangeError(`Unknownnodetype'${e}'`);return t}parseInline(e,t){let n=new UO(this,e,t);e:for(let r=t;r<n.end;){let s=n.char(r);for(let o of this.inlineParsers)if(o){let O=o(n,s,r);if(O>=0){r=O;continue e}}r++}return n.resolv
`);let t=i.textContent.trimEnd(),n="";e!==null&&(n=e.className.replace("language-",""));let r=document.createElement("div");i.parentNode.insertBefore(r,i);let s=Wi("content-code-block",{parent:r,doc:t,extensions:Ho(r)});new _t(s).setMode(n,t),i.remove(),Cb(s)}function bP(i){let e=i.querySelectorAll("pre");for(let t of e)md(t)}function PP(){let i=document.querySelectorAll(".page-content pre, .comment-box .content pre");for(let e of i)md(e)}function xP(i,e,t,n){let r=Wi("content-code-block",{parent:i,doc:t,extensions:Ho(i),root:e}),s=new _t(r);return s.setMode(n,t),s}function wP(i,e){let t=i.textContent,n={parent:i.parentElement,doc:t,extensions:[...Vr(i.parentElement)]},r=new _t(Wi("code-editor",n));return r.setMode(e,t),i.style.display="none",r}function kP(i,e){let t=i.value,n={parent:i.parentElement,doc:t,extensions:[...Vr(i.parentElement),v.updateListener.of(o=>{o.docChanged&&(i.value=o.state.doc.toString())})]},r=Wi("code-input",n),s=new _t(r);return s.setMode(e,t),i.style.display="none",s}function vP(i,e,t,n){let r=i.textContent,s={parent:i.parentElement,doc:r,extensions:[st.of(n),...Vr(i.parentElement),v.updateListener.of(O=>{e(O)}),v.domEventHandlers(t)]};window.$events.emitPublic(i,"editor-markdown-cm6::pre-init",{editorViewConfig:s});let o=Wi("markdown-editor",s);return new _t(o).setMode("markdown",""),i.style.display="none",o}export{PP as highlight,bP as highlightWithin,kP as inlineEditor,vP as markdownEditor,wP as popupEditor,xP as wysiwygView};