UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 40.6 kB
import{N as e,l as t,s as n,t as r,m as s,P as i,T as o,n as a,p as l,o as h,q as f,r as c,a as d,u as p,v as u,w as m,x as g,y as k,z as x,A as b,e as L,i as S,B as C}from"./codemirror.js";class y{static create(e,t,r,n,s){return new y(e,t,r,n+(n<<8)+e+(t<<4)|0,s,[],[])}constructor(e,r,n,s,i,o,a){this.type=e,this.value=r,this.from=n,this.hash=s,this.end=i,this.children=o,this.positions=a,this.hashProp=[[t.contextHash,s]]}addChild(e,r){e.prop(t.contextHash)!=this.hash&&(e=new a(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(r)}toTree(t,r=this.end){let n=this.children.length-1;return n>=0&&(r=Math.max(r,this.positions[n]+this.children[n].length+this.from)),new a(t.types[this.type],this.children,this.positions,r-this.from).balance({makeTree:(t,r,n)=>new a(e.none,t,r,n,this.hashProp)})}}var w;!function(e){e[e.Document=1]="Document",e[e.CodeBlock=2]="CodeBlock",e[e.FencedCode=3]="FencedCode",e[e.Blockquote=4]="Blockquote",e[e.HorizontalRule=5]="HorizontalRule",e[e.BulletList=6]="BulletList",e[e.OrderedList=7]="OrderedList",e[e.ListItem=8]="ListItem",e[e.ATXHeading1=9]="ATXHeading1",e[e.ATXHeading2=10]="ATXHeading2",e[e.ATXHeading3=11]="ATXHeading3",e[e.ATXHeading4=12]="ATXHeading4",e[e.ATXHeading5=13]="ATXHeading5",e[e.ATXHeading6=14]="ATXHeading6",e[e.SetextHeading1=15]="SetextHeading1",e[e.SetextHeading2=16]="SetextHeading2",e[e.HTMLBlock=17]="HTMLBlock",e[e.LinkReference=18]="LinkReference",e[e.Paragraph=19]="Paragraph",e[e.CommentBlock=20]="CommentBlock",e[e.ProcessingInstructionBlock=21]="ProcessingInstructionBlock",e[e.Escape=22]="Escape",e[e.Entity=23]="Entity",e[e.HardBreak=24]="HardBreak",e[e.Emphasis=25]="Emphasis",e[e.StrongEmphasis=26]="StrongEmphasis",e[e.Link=27]="Link",e[e.Image=28]="Image",e[e.InlineCode=29]="InlineCode",e[e.HTMLTag=30]="HTMLTag",e[e.Comment=31]="Comment",e[e.ProcessingInstruction=32]="ProcessingInstruction",e[e.URL=33]="URL",e[e.HeaderMark=34]="HeaderMark",e[e.QuoteMark=35]="QuoteMark",e[e.ListMark=36]="ListMark",e[e.LinkMark=37]="LinkMark",e[e.EmphasisMark=38]="EmphasisMark",e[e.CodeMark=39]="CodeMark",e[e.CodeText=40]="CodeText",e[e.CodeInfo=41]="CodeInfo",e[e.LinkTitle=42]="LinkTitle",e[e.LinkLabel=43]="LinkLabel"}(w||(w={}));class A{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}}class I{constructor(){this.text="",this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return H(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,t=0,r=0){for(let n=t;n<e;n++)r+=9==this.text.charCodeAt(n)?4-r%4:1;return r}findColumn(e){let t=0;for(let r=0;t<this.text.length&&r<e;t++)r+=9==this.text.charCodeAt(t)?4-r%4:1;return t}scrub(){if(!this.baseIndent)return this.text;let e="";for(let t=0;t<this.basePos;t++)e+=" ";return e+this.text.slice(this.basePos)}}function T(e,t,r){if(r.pos==r.text.length||e!=t.block&&r.indent>=t.stack[r.depth+1].value+r.baseIndent)return!0;if(r.indent>=r.baseIndent+4)return!1;let n=(e.type==w.OrderedList?X:R)(r,t,!1);return n>0&&(e.type!=w.BulletList||N(r,t,!1)<0)&&r.text.charCodeAt(r.pos+n-1)==e.value}const B={[w.Blockquote]:(e,t,r)=>62==r.next&&(r.markers.push(ce(w.QuoteMark,t.lineStart+r.pos,t.lineStart+r.pos+1)),r.moveBase(r.pos+(E(r.text.charCodeAt(r.pos+1))?2:1)),e.end=t.lineStart+r.text.length,!0),[w.ListItem]:(e,t,r)=>!(r.indent<r.baseIndent+e.value&&r.next>-1||(r.moveBaseColumn(r.baseIndent+e.value),0)),[w.OrderedList]:T,[w.BulletList]:T,[w.Document]:()=>!0};function E(e){return 32==e||9==e||10==e||13==e}function H(e,t=0){for(;t<e.length&&E(e.charCodeAt(t));)t++;return t}function M(e,t,r){for(;t>r&&E(e.charCodeAt(t-1));)t--;return t}function v(e){if(96!=e.next&&126!=e.next)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;if(t<e.pos+3)return-1;if(96==e.next)for(let r=t;r<e.text.length;r++)if(96==e.text.charCodeAt(r))return-1;return t}function P(e){return 62!=e.next?-1:32==e.text.charCodeAt(e.pos+1)?2:1}function N(e,t,r){if(42!=e.next&&45!=e.next&&95!=e.next)return-1;let n=1;for(let t=e.pos+1;t<e.text.length;t++){let r=e.text.charCodeAt(t);if(r==e.next)n++;else if(!E(r))return-1}return r&&45==e.next&&D(e)>-1&&e.depth==t.stack.length||n<3?-1:1}function O(e,t){for(let r=e.stack.length-1;r>=0;r--)if(e.stack[r].type==t)return!0;return!1}function R(e,t,r){return 45!=e.next&&43!=e.next&&42!=e.next||e.pos!=e.text.length-1&&!E(e.text.charCodeAt(e.pos+1))||!(!r||O(t,w.BulletList)||e.skipSpace(e.pos+2)<e.text.length)?-1:1}function X(e,t,r){let n=e.pos,s=e.next;for(;s>=48&&s<=57;){if(n++,n==e.text.length)return-1;s=e.text.charCodeAt(n)}return n==e.pos||n>e.pos+9||46!=s&&41!=s||n<e.text.length-1&&!E(e.text.charCodeAt(n+1))||r&&!O(t,w.OrderedList)&&(e.skipSpace(n+1)==e.text.length||n>e.pos+1||49!=e.next)?-1:n+1-e.pos}function z(e){if(35!=e.next)return-1;let t=e.pos+1;for(;t<e.text.length&&35==e.text.charCodeAt(t);)t++;if(t<e.text.length&&32!=e.text.charCodeAt(t))return-1;let r=t-e.pos;return r>6?-1:r}function D(e){if(45!=e.next&&61!=e.next||e.indent>=e.baseIndent+4)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;let r=t;for(;t<e.text.length&&E(e.text.charCodeAt(t));)t++;return t==e.text.length?r:-1}const $=/^[ \t]*$/,q=/-->/,j=/\?>/,F=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,q],[/^\s*<\?/,j],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,$],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,$]];function U(e,t,r){if(60!=e.next)return-1;let n=e.text.slice(e.pos);for(let e=0,t=F.length-(r?1:0);e<t;e++)if(F[e][0].test(n))return e;return-1}function _(e,t){let r=e.countIndent(t,e.pos,e.indent),n=e.countIndent(e.skipSpace(t),t,r);return n>=r+5?r+1:n}function Q(e,t,r){let n=e.length-1;n>=0&&e[n].to==t&&e[n].type==w.CodeText?e[n].to=r:e.push(ce(w.CodeText,t,r))}const Z={LinkReference:void 0,IndentedCode(e,t){let r=t.baseIndent+4;if(t.indent<r)return!1;let n=t.findColumn(r),s=e.lineStart+n,i=e.lineStart+t.text.length,o=[],a=[];for(Q(o,s,i);e.nextLine()&&t.depth>=e.stack.length;)if(t.pos==t.text.length){Q(a,e.lineStart-1,e.lineStart);for(let e of t.markers)a.push(e)}else{if(t.indent<r)break;{if(a.length){for(let e of a)e.type==w.CodeText?Q(o,e.from,e.to):o.push(e);a=[]}Q(o,e.lineStart-1,e.lineStart);for(let e of t.markers)o.push(e);i=e.lineStart+t.text.length;let r=e.lineStart+t.findColumn(t.baseIndent+4);r<i&&Q(o,r,i)}}return a.length&&(a=a.filter((e=>e.type!=w.CodeText)),a.length&&(t.markers=a.concat(t.markers))),e.addNode(e.buffer.writeElements(o,-s).finish(w.CodeBlock,i-s),s),!0},FencedCode(e,t){let r=v(t);if(r<0)return!1;let n=e.lineStart+t.pos,s=t.next,i=r-t.pos,o=t.skipSpace(r),a=M(t.text,t.text.length,o),l=[ce(w.CodeMark,n,n+i)];o<a&&l.push(ce(w.CodeInfo,e.lineStart+o,e.lineStart+a));for(let r=!0;e.nextLine()&&t.depth>=e.stack.length;r=!1){let n=t.pos;if(t.indent-t.baseIndent<4)for(;n<t.text.length&&t.text.charCodeAt(n)==s;)n++;if(n-t.pos>=i&&t.skipSpace(n)==t.text.length){for(let e of t.markers)l.push(e);l.push(ce(w.CodeMark,e.lineStart+t.pos,e.lineStart+n)),e.nextLine();break}{r||Q(l,e.lineStart-1,e.lineStart);for(let e of t.markers)l.push(e);let n=e.lineStart+t.basePos,s=e.lineStart+t.text.length;n<s&&Q(l,n,s)}}return e.addNode(e.buffer.writeElements(l,-n).finish(w.FencedCode,e.prevLineEnd()-n),n),!0},Blockquote(e,t){let r=P(t);return!(r<0)&&(e.startContext(w.Blockquote,t.pos),e.addNode(w.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1),t.moveBase(t.pos+r),null)},HorizontalRule(e,t){if(N(t,e,!1)<0)return!1;let r=e.lineStart+t.pos;return e.nextLine(),e.addNode(w.HorizontalRule,r),!0},BulletList(e,t){let r=R(t,e,!1);if(r<0)return!1;e.block.type!=w.BulletList&&e.startContext(w.BulletList,t.basePos,t.next);let n=_(t,t.pos+1);return e.startContext(w.ListItem,t.basePos,n-t.baseIndent),e.addNode(w.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+r),t.moveBaseColumn(n),null},OrderedList(e,t){let r=X(t,e,!1);if(r<0)return!1;e.block.type!=w.OrderedList&&e.startContext(w.OrderedList,t.basePos,t.text.charCodeAt(t.pos+r-1));let n=_(t,t.pos+r);return e.startContext(w.ListItem,t.basePos,n-t.baseIndent),e.addNode(w.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+r),t.moveBaseColumn(n),null},ATXHeading(e,t){let r=z(t);if(r<0)return!1;let n=t.pos,s=e.lineStart+n,i=M(t.text,t.text.length,n),o=i;for(;o>n&&t.text.charCodeAt(o-1)==t.next;)o--;o!=i&&o!=n&&E(t.text.charCodeAt(o-1))||(o=t.text.length);let a=e.buffer.write(w.HeaderMark,0,r).writeElements(e.parser.parseInline(t.text.slice(n+r+1,o),s+r+1),-s);o<t.text.length&&a.write(w.HeaderMark,o-n,i-n);let l=a.finish(w.ATXHeading1-1+r,t.text.length-n);return e.nextLine(),e.addNode(l,s),!0},HTMLBlock(e,t){let r=U(t,0,!1);if(r<0)return!1;let n=e.lineStart+t.pos,s=F[r][1],i=[],o=s!=$;for(;!s.test(t.text)&&e.nextLine();){if(t.depth<e.stack.length){o=!1;break}for(let e of t.markers)i.push(e)}o&&e.nextLine();let a=s==q?w.CommentBlock:s==j?w.ProcessingInstructionBlock:w.HTMLBlock,l=e.prevLineEnd();return e.addNode(e.buffer.writeElements(i,-n).finish(a,l-n),n),!0},SetextHeading:void 0};class V{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,r){if(-1==this.stage)return!1;let n=r.content+"\n"+t.scrub(),s=this.advance(n);return s>-1&&s<n.length&&this.complete(e,r,s)}finish(e,t){return(2==this.stage||3==this.stage)&&H(t.content,this.pos)==t.content.length&&this.complete(e,t,t.content.length)}complete(e,t,r){return e.addLeafElement(t,ce(w.LinkReference,this.start,this.start+r,this.elts)),!0}nextStage(e){return e?(this.pos=e.to-this.start,this.elts.push(e),this.stage++,!0):(!1===e&&(this.stage=-1),!1)}advance(e){for(;;){if(-1==this.stage)return-1;if(0==this.stage){if(!this.nextStage(ye(e,this.pos,this.start,!0)))return-1;if(58!=e.charCodeAt(this.pos))return this.stage=-1;this.elts.push(ce(w.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else{if(1!=this.stage){if(2==this.stage){let t=H(e,this.pos),r=0;if(t>this.pos){let n=Ce(e,t,this.start);if(n){let t=G(e,n.to-this.start);t>0&&(this.nextStage(n),r=t)}}return r||(r=G(e,this.pos)),r>0&&r<e.length?r:-1}return G(e,this.pos)}if(!this.nextStage(Se(e,H(e,this.pos),this.start)))return-1}}}}function G(e,t){for(;t<e.length;t++){let r=e.charCodeAt(t);if(10==r)break;if(!E(r))return-1}return t}class K{nextLine(e,t,r){let n=t.depth<e.stack.length?-1:D(t),s=t.next;if(n<0)return!1;let i=ce(w.HeaderMark,e.lineStart+t.pos,e.lineStart+n);return e.nextLine(),e.addLeafElement(r,ce(61==s?w.SetextHeading1:w.SetextHeading2,r.start,e.prevLineEnd(),[...e.parser.parseInline(r.content,r.start),i])),!0}finish(){return!1}}const J={LinkReference:(e,t)=>91==t.content.charCodeAt(0)?new V(t):null,SetextHeading:()=>new K},W=[(e,t)=>z(t)>=0,(e,t)=>v(t)>=0,(e,t)=>P(t)>=0,(e,t)=>R(t,e,!0)>=0,(e,t)=>X(t,e,!0)>=0,(e,t)=>N(t,e,!0)>=0,(e,t)=>U(t,0,!0)>=0],Y={text:"",end:0};class ee{constructor(e,t,r,n){this.parser=e,this.input=t,this.ranges=n,this.line=new I,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=n[n.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=n[0].from,this.block=y.create(w.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=r.length?new Te(r,t):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(null!=this.stoppedAt&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line:e}=this;for(;;){for(;e.depth<this.stack.length;)this.finishContext();for(let t of e.markers)this.addNode(t.type,t.from,t.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 t of this.parser.blockParsers)if(t){let r=t(this,e);if(0!=r){if(1==r)return null;e.forward();continue e}}break}let t=new A(this.lineStart+e.pos,e.text.slice(e.pos));for(let e of this.parser.leafBlockParsers)if(e){let r=e(this,t);r&&t.parsers.push(r)}e:for(;this.nextLine()&&e.pos!=e.text.length;){if(e.indent<e.baseIndent+4)for(let r of this.parser.endLeafBlock)if(r(this,e,t))break e;for(let r of t.parsers)if(r.nextLine(this,e,t))return null;t.content+="\n"+e.scrub();for(let r of e.markers)t.marks.push(r)}return this.finishLeaf(t),null}stopAt(e){if(null!=this.stoppedAt&&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=Be(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0)}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=Y;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 e=this.absoluteLineStart,r=this.rangeI;for(;this.ranges[r].to<t.end;){r++;let n=this.ranges[r].from,s=this.lineChunkAt(n);t.end=n+s.length,t.text=t.text.slice(0,this.ranges[r-1].to-e)+s,e=t.end-t.text.length}}return t}readLine(){let{line:e}=this,{text:t,end:r}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=r,e.reset(t);e.depth<this.stack.length;e.depth++){let t=this.stack[e.depth],r=this.parser.skipContextMarkup[t.type];if(!r)throw new Error("Unhandled block context "+w[t.type]);if(!r(t,this,e))break;e.forward()}}lineChunkAt(e){let t,r=this.input.chunk(e);if(this.input.lineChunks)t="\n"==r?"":r;else{let e=r.indexOf("\n");t=e<0?r:r.slice(0,e)}return e+t.length>this.to?t.slice(0,this.to-e):t}prevLineEnd(){return this.atEnd?this.lineStart:this.lineStart-1}startContext(e,t,r=0){this.block=y.create(e,r,this.lineStart+t,this.block.hash,this.lineStart+this.line.text.length),this.stack.push(this.block)}startComposite(e,t,r=0){this.startContext(this.parser.getNodeType(e),t,r)}addNode(e,t,r){"number"==typeof e&&(e=new a(this.parser.nodeSet.types[e],ae,ae,(null!=r?r: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(Ae(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?te(this.ranges,0,e.topNode,this.ranges[0].from,this.reusePlaceholders):e}finishLeaf(e){for(let t of e.parsers)if(t.finish(this,e))return;let t=Ae(this.parser.parseInline(e.content,e.start),e.marks);this.addNode(this.buffer.writeElements(t,-e.start).finish(w.Paragraph,e.content.length),e.start)}elt(e,t,r,n){return"string"==typeof e?ce(this.parser.getNodeType(e),t,r,n):new fe(e,t)}get buffer(){return new le(this.parser.nodeSet)}}function te(e,t,r,n,s){let i=e[t].to,o=[],l=[],h=r.from+n;function f(r,s){for(;s?r>=i:r>i;){let s=e[t+1].from-i;n+=s,r+=s,t++,i=e[t].to}}for(let a=r.firstChild;a;a=a.nextSibling){f(a.from+n,!0);let r,c=a.from+n,d=s.get(a.tree);d?r=d:a.to+n>i?(r=te(e,t,a,n,s),f(a.to+n,!1)):r=a.toTree(),o.push(r),l.push(c-h)}return f(r.to+n,!1),new a(r.type,o,l,r.to+n-h,r.tree?r.tree.propValues:void 0)}class ne extends i{constructor(e,t,r,n,s,i,o,a,l){super(),this.nodeSet=e,this.blockParsers=t,this.leafBlockParsers=r,this.blockNames=n,this.endLeafBlock=s,this.skipContextMarkup=i,this.inlineParsers=o,this.inlineNames=a,this.wrappers=l,this.nodeTypes=Object.create(null);for(let t of e.types)this.nodeTypes[t.name]=t.id}createParse(e,t,r){let n=new ee(this,e,t,r);for(let s of this.wrappers)n=s(n,e,t,r);return n}configure(r){let i=se(r);if(!i)return this;let{nodeSet:a,skipContextMarkup:l}=this,h=this.blockParsers.slice(),f=this.leafBlockParsers.slice(),c=this.blockNames.slice(),d=this.inlineParsers.slice(),u=this.inlineNames.slice(),p=this.endLeafBlock.slice(),m=this.wrappers;if(re(i.defineNodes)){l=Object.assign({},l);let r,h=a.types.slice();for(let n of i.defineNodes){let{name:s,block:i,composite:a,style:f}="string"==typeof n?{name:n}:n;if(h.some((e=>e.name==s)))continue;a&&(l[h.length]=(e,t,r)=>a(t,r,e.value));let c=h.length,d=a?["Block","BlockContext"]:i?c>=w.ATXHeading1&&c<=w.SetextHeading2?["Block","LeafBlock","Heading"]:["Block","LeafBlock"]:void 0;h.push(e.define({id:c,name:s,props:d&&[[t.group,d]]})),f&&(r||(r={}),Array.isArray(f)||f instanceof o?r[s]=f:Object.assign(r,f))}a=new s(h),r&&(a=a.extend(n(r)))}if(re(i.props)&&(a=a.extend(...i.props)),re(i.remove))for(let e of i.remove){let t=this.blockNames.indexOf(e),r=this.inlineNames.indexOf(e);t>-1&&(h[t]=f[t]=void 0),r>-1&&(d[r]=void 0)}if(re(i.parseBlock))for(let e of i.parseBlock){let t=c.indexOf(e.name);if(t>-1)h[t]=e.parse,f[t]=e.leaf;else{let t=e.before?ie(c,e.before):e.after?ie(c,e.after)+1:c.length-1;h.splice(t,0,e.parse),f.splice(t,0,e.leaf),c.splice(t,0,e.name)}e.endLeaf&&p.push(e.endLeaf)}if(re(i.parseInline))for(let e of i.parseInline){let t=u.indexOf(e.name);if(t>-1)d[t]=e.parse;else{let t=e.before?ie(u,e.before):e.after?ie(u,e.after)+1:u.length-1;d.splice(t,0,e.parse),u.splice(t,0,e.name)}}return i.wrap&&(m=m.concat(i.wrap)),new ne(a,h,f,c,p,l,d,u,m)}getNodeType(e){let t=this.nodeTypes[e];if(null==t)throw new RangeError(`Unknown node type '${e}'`);return t}parseInline(e,t){let r=new we(this,e,t);e:for(let e=t;e<r.end;){let t=r.char(e);for(let n of this.inlineParsers)if(n){let s=n(r,t,e);if(s>=0){e=s;continue e}}e++}return r.resolveMarkers(0)}}function re(e){return null!=e&&e.length>0}function se(e){if(!Array.isArray(e))return e;if(0==e.length)return null;let t=se(e[0]);if(1==e.length)return t;let r=se(e.slice(1));if(!r||!t)return t||r;let n=(e,t)=>(e||ae).concat(t||ae),s=t.wrap,i=r.wrap;return{props:n(t.props,r.props),defineNodes:n(t.defineNodes,r.defineNodes),parseBlock:n(t.parseBlock,r.parseBlock),parseInline:n(t.parseInline,r.parseInline),remove:n(t.remove,r.remove),wrap:s?i?(e,t,r,n)=>s(i(e,t,r,n),t,r,n):s:i}}function ie(e,t){let r=e.indexOf(t);if(r<0)throw new RangeError(`Position specified relative to unknown parser ${t}`);return r}let oe=[e.none];for(let r,n=1;r=w[n];n++)oe[n]=e.define({id:n,name:r,props:n>=w.Escape?[]:[[t.group,n in B?["Block","BlockContext"]:["Block","LeafBlock"]]],top:"Document"==r});const ae=[];class le{constructor(e){this.nodeSet=e,this.content=[],this.nodes=[]}write(e,t,r,n=0){return this.content.push(e,t,r,4+4*n),this}writeElements(e,t=0){for(let r of e)r.writeTo(this,t);return this}finish(e,t){return a.build({buffer:this.content,nodeSet:this.nodeSet,reused:this.nodes,topID:e,length:t})}}class he{constructor(e,t,r,n=ae){this.type=e,this.from=t,this.to=r,this.children=n}writeTo(e,t){let r=e.content.length;e.writeElements(this.children,t),e.content.push(this.type,this.from+t,this.to+t,e.content.length+4-r)}toTree(e){return new le(e).writeElements(this.children,-this.from).finish(this.type,this.to-this.from)}}class fe{constructor(e,t){this.tree=e,this.from=t}get to(){return this.from+this.tree.length}get type(){return this.tree.type.id}get children(){return ae}writeTo(e,t){e.nodes.push(this.tree),e.content.push(e.nodes.length-1,this.from+t,this.to+t,-1)}toTree(){return this.tree}}function ce(e,t,r,n){return new he(e,t,r,n)}const de={resolve:"Emphasis",mark:"EmphasisMark"},pe={resolve:"Emphasis",mark:"EmphasisMark"},ue={},me={};class ge{constructor(e,t,r,n){this.type=e,this.from=t,this.to=r,this.side=n}}const ke="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";let xe=/[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;try{xe=new RegExp("[\\p{Pc}|\\p{Pd}|\\p{Pe}|\\p{Pf}|\\p{Pi}|\\p{Po}|\\p{Ps}]","u")}catch(e){}const be={Escape(e,t,r){if(92!=t||r==e.end-1)return-1;let n=e.char(r+1);for(let t=0;t<32;t++)if(ke.charCodeAt(t)==n)return e.append(ce(w.Escape,r,r+2));return-1},Entity(e,t,r){if(38!=t)return-1;let n=/^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(e.slice(r+1,r+31));return n?e.append(ce(w.Entity,r,r+1+n[0].length)):-1},InlineCode(e,t,r){if(96!=t||r&&96==e.char(r-1))return-1;let n=r+1;for(;n<e.end&&96==e.char(n);)n++;let s=n-r,i=0;for(;n<e.end;n++)if(96==e.char(n)){if(i++,i==s&&96!=e.char(n+1))return e.append(ce(w.InlineCode,r,n+1,[ce(w.CodeMark,r,r+s),ce(w.CodeMark,n+1-s,n+1)]))}else i=0;return-1},HTMLTag(e,t,r){if(60!=t||r==e.end-1)return-1;let n=e.slice(r+1,e.end),s=/^(?:[a-z][-\w+.]+:[^\s>]+|[a-z\d.!#$%&'*+/=?^_`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*)>/i.exec(n);if(s)return e.append(ce(w.URL,r,r+1+s[0].length));let i=/^!--[^>](?:-[^-]|[^-])*?-->/i.exec(n);if(i)return e.append(ce(w.Comment,r,r+1+i[0].length));let o=/^\?[^]*?\?>/.exec(n);if(o)return e.append(ce(w.ProcessingInstruction,r,r+1+o[0].length));let a=/^(?:![A-Z][^]*?>|!\[CDATA\[[^]*?\]\]>|\/\s*[a-zA-Z][\w-]*\s*>|\s*[a-zA-Z][\w-]*(\s+[a-zA-Z:_][\w-.:]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*(\/\s*)?>)/.exec(n);return a?e.append(ce(w.HTMLTag,r,r+1+a[0].length)):-1},Emphasis(e,t,r){if(95!=t&&42!=t)return-1;let n=r+1;for(;e.char(n)==t;)n++;let s=e.slice(r-1,r),i=e.slice(n,n+1),o=xe.test(s),a=xe.test(i),l=/\s|^$/.test(s),h=/\s|^$/.test(i),f=!h&&(!a||l||o),c=!l&&(!o||h||a),d=f&&(42==t||!c||o),u=c&&(42==t||!f||a);return e.append(new ge(95==t?de:pe,r,n,(d?1:0)|(u?2:0)))},HardBreak(e,t,r){if(92==t&&10==e.char(r+1))return e.append(ce(w.HardBreak,r,r+2));if(32==t){let t=r+1;for(;32==e.char(t);)t++;if(10==e.char(t)&&t>=r+2)return e.append(ce(w.HardBreak,r,t+1))}return-1},Link:(e,t,r)=>91==t?e.append(new ge(ue,r,r+1,1)):-1,Image:(e,t,r)=>33==t&&91==e.char(r+1)?e.append(new ge(me,r,r+2,1)):-1,LinkEnd(e,t,r){if(93!=t)return-1;for(let t=e.parts.length-1;t>=0;t--){let n=e.parts[t];if(n instanceof ge&&(n.type==ue||n.type==me)){if(!n.side||e.skipSpace(n.to)==r&&!/[(\[]/.test(e.slice(r+1,r+2)))return e.parts[t]=null,-1;let s=e.takeContent(t),i=e.parts[t]=Le(e,s,n.type==ue?w.Link:w.Image,n.from,r+1);if(n.type==ue)for(let r=0;r<t;r++){let t=e.parts[r];t instanceof ge&&t.type==ue&&(t.side=0)}return i.to}}return-1}};function Le(e,t,r,n,s){let{text:i}=e,o=e.char(s),a=s;if(t.unshift(ce(w.LinkMark,n,n+(r==w.Image?2:1))),t.push(ce(w.LinkMark,s-1,s)),40==o){let r,n=e.skipSpace(s+1),o=Se(i,n-e.offset,e.offset);o&&(n=e.skipSpace(o.to),r=Ce(i,n-e.offset,e.offset),r&&(n=e.skipSpace(r.to))),41==e.char(n)&&(t.push(ce(w.LinkMark,s,s+1)),a=n+1,o&&t.push(o),r&&t.push(r),t.push(ce(w.LinkMark,n,a)))}else if(91==o){let r=ye(i,s-e.offset,e.offset,!1);r&&(t.push(r),a=r.to)}return ce(r,n,a,t)}function Se(e,t,r){if(60==e.charCodeAt(t)){for(let n=t+1;n<e.length;n++){let s=e.charCodeAt(n);if(62==s)return ce(w.URL,t+r,n+1+r);if(60==s||10==s)return!1}return null}{let n=0,s=t;for(let t=!1;s<e.length;s++){let r=e.charCodeAt(s);if(E(r))break;if(t)t=!1;else if(40==r)n++;else if(41==r){if(!n)break;n--}else 92==r&&(t=!0)}return s>t?ce(w.URL,t+r,s+r):s==e.length&&null}}function Ce(e,t,r){let n=e.charCodeAt(t);if(39!=n&&34!=n&&40!=n)return!1;let s=40==n?41:n;for(let n=t+1,i=!1;n<e.length;n++){let o=e.charCodeAt(n);if(i)i=!1;else{if(o==s)return ce(w.LinkTitle,t+r,n+1+r);92==o&&(i=!0)}}return null}function ye(e,t,r,n){for(let s=!1,i=t+1,o=Math.min(e.length,i+999);i<o;i++){let o=e.charCodeAt(i);if(s)s=!1;else{if(93==o)return!n&&ce(w.LinkLabel,t+r,i+1+r);if(n&&!E(o)&&(n=!1),91==o)return!1;92==o&&(s=!0)}}return null}class we{constructor(e,t,r){this.parser=e,this.text=t,this.offset=r,this.parts=[]}char(e){return e>=this.end?-1:this.text.charCodeAt(e-this.offset)}get end(){return this.offset+this.text.length}slice(e,t){return this.text.slice(e-this.offset,t-this.offset)}append(e){return this.parts.push(e),e.to}addDelimiter(e,t,r,n,s){return this.append(new ge(e,t,r,(n?1:0)|(s?2:0)))}addElement(e){return this.append(e)}resolveMarkers(e){for(let t=e;t<this.parts.length;t++){let r=this.parts[t];if(!(r instanceof ge&&r.type.resolve&&2&r.side))continue;let n,s=r.type==de||r.type==pe,i=r.to-r.from,o=t-1;for(;o>=e;o--){let e=this.parts[o];if(e instanceof ge&&1&e.side&&e.type==r.type&&!(s&&(1&r.side||2&e.side)&&(e.to-e.from+i)%3==0&&((e.to-e.from)%3||i%3))){n=e;break}}if(!n)continue;let a=r.type.resolve,l=[],h=n.from,f=r.to;if(s){let e=Math.min(2,n.to-n.from,i);h=n.to-e,f=r.from+e,a=1==e?"Emphasis":"StrongEmphasis"}n.type.mark&&l.push(this.elt(n.type.mark,h,n.to));for(let e=o+1;e<t;e++)this.parts[e]instanceof he&&l.push(this.parts[e]),this.parts[e]=null;r.type.mark&&l.push(this.elt(r.type.mark,r.from,f));let c=this.elt(a,h,f,l);this.parts[o]=s&&n.from!=h?new ge(n.type,n.from,h,n.side):null,(this.parts[t]=s&&r.to!=f?new ge(r.type,f,r.to,r.side):null)?this.parts.splice(t,0,c):this.parts[t]=c}let t=[];for(let r=e;r<this.parts.length;r++){let e=this.parts[r];e instanceof he&&t.push(e)}return t}findOpeningDelimiter(e){for(let t=this.parts.length-1;t>=0;t--){let r=this.parts[t];if(r instanceof ge&&r.type==e)return t}return null}takeContent(e){let t=this.resolveMarkers(e);return this.parts.length=e,t}skipSpace(e){return H(this.text,e-this.offset)+this.offset}elt(e,t,r,n){return"string"==typeof e?ce(this.parser.getNodeType(e),t,r,n):new fe(e,t)}}function Ae(e,t){if(!t.length)return e;if(!e.length)return t;let r=e.slice(),n=0;for(let e of t){for(;n<r.length&&r[n].to<e.to;)n++;if(n<r.length&&r[n].from<e.from){let t=r[n];t instanceof he&&(r[n]=new he(t.type,t.from,t.to,Ae(t.children,[e])))}else r.splice(n++,0,e)}return r}const Ie=[w.CodeBlock,w.ListItem,w.OrderedList,w.BulletList];class Te{constructor(e,t){this.fragments=e,this.input=t,this.i=0,this.fragment=null,this.fragmentEnd=-1,this.cursor=null,e.length&&(this.fragment=e[this.i++])}nextFragment(){this.fragment=this.i<this.fragments.length?this.fragments[this.i++]:null,this.cursor=null,this.fragmentEnd=-1}moveTo(e,t){for(;this.fragment&&this.fragment.to<=e;)this.nextFragment();if(!this.fragment||this.fragment.from>(e?e-1:0))return!1;if(this.fragmentEnd<0){let e=this.fragment.to;for(;e>0&&"\n"!=this.input.read(e-1,e);)e--;this.fragmentEnd=e?e-1:0}let r=this.cursor;r||(r=this.cursor=this.fragment.tree.cursor(),r.firstChild());let n=e+this.fragment.offset;for(;r.to<=n;)if(!r.parent())return!1;for(;;){if(r.from>=n)return this.fragment.from<=t;if(!r.childAfter(n))return!1}}matches(e){let r=this.cursor.tree;return r&&r.prop(t.contextHash)==e}takeNodes(e){let t=this.cursor,r=this.fragment.offset,n=this.fragmentEnd-(this.fragment.openEnd?1:0),s=e.absoluteLineStart,i=s,o=e.block.children.length,l=i,h=o;for(;;){if(t.to-r>n){if(t.type.isAnonymous&&t.firstChild())continue;break}let s=Be(t.from-r,e.ranges);if(t.to-r<=e.ranges[e.rangeI].to)e.addNode(t.tree,s);else{let r=new a(e.parser.nodeSet.types[w.Paragraph],[],[],0,e.block.hashProp);e.reusePlaceholders.set(r,t.tree),e.addNode(r,s)}if(t.type.is("Block")&&(Ie.indexOf(t.type.id)<0?(i=t.to-r,o=e.block.children.length):(i=l,o=h,l=t.to-r,h=e.block.children.length)),!t.nextSibling())break}for(;e.block.children.length>o;)e.block.children.pop(),e.block.positions.pop();return i-s}}function Be(e,t){let r=e;for(let n=1;n<t.length;n++){let s=t[n-1].to,i=t[n].from;s<e&&(r-=i-s)}return r}const Ee=n({"Blockquote/...":r.quote,HorizontalRule:r.contentSeparator,"ATXHeading1/... SetextHeading1/...":r.heading1,"ATXHeading2/... SetextHeading2/...":r.heading2,"ATXHeading3/...":r.heading3,"ATXHeading4/...":r.heading4,"ATXHeading5/...":r.heading5,"ATXHeading6/...":r.heading6,"Comment CommentBlock":r.comment,Escape:r.escape,Entity:r.character,"Emphasis/...":r.emphasis,"StrongEmphasis/...":r.strong,"Link/... Image/...":r.link,"OrderedList/... BulletList/...":r.list,"BlockQuote/...":r.quote,"InlineCode CodeText":r.monospace,URL:r.url,"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":r.processingInstruction,"CodeInfo LinkLabel":r.labelName,LinkTitle:r.string,Paragraph:r.content}),He=new ne(new s(oe).extend(Ee),Object.keys(Z).map((e=>Z[e])),Object.keys(Z).map((e=>J[e])),Object.keys(Z),W,B,Object.keys(be).map((e=>be[e])),Object.keys(be),[]);function Me(e,t,r){let n=[];for(let s=e.firstChild,i=t;;s=s.nextSibling){let e=s?s.from:r;if(e>i&&n.push({from:i,to:e}),!s)break;i=s.to}return n}const ve={resolve:"Strikethrough",mark:"StrikethroughMark"},Pe={defineNodes:[{name:"Strikethrough",style:{"Strikethrough/...":r.strikethrough}},{name:"StrikethroughMark",style:r.processingInstruction}],parseInline:[{name:"Strikethrough",parse(e,t,r){if(126!=t||126!=e.char(r+1)||126==e.char(r+2))return-1;let n=e.slice(r-1,r),s=e.slice(r+2,r+3),i=/\s|^$/.test(n),o=/\s|^$/.test(s),a=xe.test(n),l=xe.test(s);return e.addDelimiter(ve,r,r+2,!o&&(!l||i||a),!i&&(!a||o||l))},after:"Emphasis"}]};function Ne(e,t,r=0,n,s=0){let i=0,o=!0,a=-1,l=-1,h=!1,f=()=>{n.push(e.elt("TableCell",s+a,s+l,e.parser.parseInline(t.slice(a,l),s+a)))};for(let c=r;c<t.length;c++){let r=t.charCodeAt(c);124!=r||h?(h||32!=r&&9!=r)&&(a<0&&(a=c),l=c+1):((!o||a>-1)&&i++,o=!1,n&&(a>-1&&f(),n.push(e.elt("TableDelimiter",c+s,c+s+1))),a=l=-1),h=!h&&92==r}return a>-1&&(i++,n&&f()),i}function Oe(e,t){for(let r=t;r<e.length;r++){let t=e.charCodeAt(r);if(124==t)return!0;92==t&&r++}return!1}const Re=/^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/;class Xe{constructor(){this.rows=null}nextLine(e,t,r){if(null==this.rows){let n;if(this.rows=!1,(45==t.next||58==t.next||124==t.next)&&Re.test(n=t.text.slice(t.pos))){let s=[];Ne(e,r.content,0,s,r.start)==Ne(e,n,t.pos)&&(this.rows=[e.elt("TableHeader",r.start,r.start+r.content.length,s),e.elt("TableDelimiter",e.lineStart+t.pos,e.lineStart+t.text.length)])}}else if(this.rows){let r=[];Ne(e,t.text,t.pos,r,e.lineStart),this.rows.push(e.elt("TableRow",e.lineStart+t.pos,e.lineStart+t.text.length,r))}return!1}finish(e,t){return!!this.rows&&(e.addLeafElement(t,e.elt("Table",t.start,t.start+t.content.length,this.rows)),!0)}}const ze={defineNodes:[{name:"Table",block:!0},{name:"TableHeader",style:{"TableHeader/...":r.heading}},"TableRow",{name:"TableCell",style:r.content},{name:"TableDelimiter",style:r.processingInstruction}],parseBlock:[{name:"Table",leaf:(e,t)=>Oe(t.content,0)?new Xe:null,endLeaf(e,t,r){if(r.parsers.some((e=>e instanceof Xe))||!Oe(t.text,t.basePos))return!1;let n=e.scanLine(e.absoluteLineEnd+1).text;return Re.test(n)&&Ne(e,t.text,t.basePos)==Ne(e,n,t.basePos)},before:"SetextHeading"}]};class De{nextLine(){return!1}finish(e,t){return e.addLeafElement(t,e.elt("Task",t.start,t.start+t.content.length,[e.elt("TaskMarker",t.start,t.start+3),...e.parser.parseInline(t.content.slice(3),t.start+3)])),!0}}const $e={defineNodes:[{name:"Task",block:!0,style:r.list},{name:"TaskMarker",style:r.atom}],parseBlock:[{name:"TaskList",leaf:(e,t)=>/^\[[ xX]\][ \t]/.test(t.content)&&"ListItem"==e.parentType().name?new De:null,after:"SetextHeading"}]},qe=/(www\.)|(https?:\/\/)|([\w.+-]+@)|(mailto:|xmpp:)/gy,je=/[\w-]+(\.\w+(\.\w+)?)(\/[^\s<]*)?/gy,Fe=/[\w.+-]+@[\w-]+\.[\w.-]+/gy,Ue=/\/[a-zA-Z\d@.]+/gy;function _e(e,t,r,n){let s=0;for(let i=t;i<r;i++)e[i]==n&&s++;return s}function Qe(e,t){Fe.lastIndex=t;let r=Fe.exec(e);if(!r)return-1;let n=r[0][r[0].length-1];return"_"==n||"-"==n?-1:t+r[0].length-("."==n?1:0)}const Ze=[ze,$e,Pe,{parseInline:[{name:"Autolink",parse(e,t,r){let n=r-e.offset;qe.lastIndex=n;let s=qe.exec(e.text),i=-1;return s?(s[1]||s[2]?i=function(e,t){je.lastIndex=t;let r=je.exec(e);if(!r)return-1;let n=t+r[0].length;for(;;){let r,s=e[n-1];if(/[?!.,:*_~]/.test(s)||")"==s&&_e(e,t,n,")")>_e(e,t,n,"("))n--;else{if(";"!=s||!(r=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(t,n))))break;n=t+r.index}}return n}(e.text,n+s[0].length):s[3]?i=Qe(e.text,n):(i=Qe(e.text,n+s[0].length),i>-1&&"xmpp:"==s[0]&&(Ue.lastIndex=i,s=Ue.exec(e.text),s&&(i=s.index+s[0].length))),i<0?-1:(e.addElement(e.elt("URL",r,i+e.offset)),i+e.offset)):-1}}]}];function Ve(e,t,r){return(n,s,i)=>{if(s!=e||n.char(i+1)==e)return-1;let o=[n.elt(r,i,i+1)];for(let s=i+1;s<n.end;s++){let a=n.char(s);if(a==e)return n.addElement(n.elt(t,i,s+1,o.concat(n.elt(r,s,s+1))));if(92==a&&o.push(n.elt("Escape",s,2+s++)),E(a))break}return-1}}const Ge={defineNodes:[{name:"Superscript",style:r.special(r.content)},{name:"SuperscriptMark",style:r.processingInstruction}],parseInline:[{name:"Superscript",parse:Ve(94,"Superscript","SuperscriptMark")}]},Ke={defineNodes:[{name:"Subscript",style:r.special(r.content)},{name:"SubscriptMark",style:r.processingInstruction}],parseInline:[{name:"Subscript",parse:Ve(126,"Subscript","SubscriptMark")}]},Je={defineNodes:[{name:"Emoji",style:r.character}],parseInline:[{name:"Emoji",parse(e,t,r){let n;return 58==t&&(n=/^[a-zA-Z_0-9]+:/.exec(e.slice(r+1,e.end)))?e.addElement(e.elt("Emoji",r,r+1+n[0].length)):-1}}]},We=m({commentTokens:{block:{open:"\x3c!--",close:"--\x3e"}}}),Ye=new t,et=He.configure({props:[L.add((e=>!e.is("Block")||e.is("Document")||null!=tt(e)?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to}))),Ye.add(tt),S.add({Document:()=>null}),C.add({Document:We})]});function tt(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function nt(e,t){let r=e;for(;;){let e,n=r.nextSibling;if(!n||null!=(e=tt(n.type))&&e<=t)break;r=n}return r.to}const rt=g.of(((e,t,r)=>{for(let n=f(e).resolveInner(r,-1);n&&!(n.from<t);n=n.parent){let e=n.type.prop(Ye);if(null==e)continue;let t=nt(n,e);if(t>r)return{from:r,to:t}}return null}));function st(e){return new h(We,e,[rt],"markdown")}const it=st(et),ot=st(et.configure([Ze,Ke,Ge,Je]));class at{constructor(e,t,r,n,s,i,o){this.node=e,this.from=t,this.to=r,this.spaceBefore=n,this.spaceAfter=s,this.type=i,this.item=o}blank(e,t=!0){let r=this.spaceBefore+("Blockquote"==this.node.name?">":"");if(null!=e){for(;r.length<e;)r+=" ";return r}for(let e=this.to-this.from-r.length-this.spaceAfter.length;e>0;e--)r+=" ";return r+(t?this.spaceAfter:"")}marker(e,t){let r="OrderedList"==this.node.name?String(+ht(this.item,e)[2]+t):"";return this.spaceBefore+r+this.type+this.spaceAfter}}function lt(e,t){let r=[];for(let t=e;t&&"Document"!=t.name;t=t.parent)"ListItem"!=t.name&&"Blockquote"!=t.name&&"FencedCode"!=t.name||r.push(t);let n=[];for(let e=r.length-1;e>=0;e--){let s,i=r[e],o=t.lineAt(i.from),a=i.from-o.from;if("FencedCode"==i.name)n.push(new at(i,a,a,"","","",null));else if("Blockquote"==i.name&&(s=/^[ \t]*>( ?)/.exec(o.text.slice(a))))n.push(new at(i,a,a+s[0].length,"",s[1],">",null));else if("ListItem"==i.name&&"OrderedList"==i.parent.name&&(s=/^([ \t]*)\d+([.)])([ \t]*)/.exec(o.text.slice(a)))){let e=s[3],t=s[0].length;e.length>=4&&(e=e.slice(0,e.length-4),t-=4),n.push(new at(i.parent,a,a+t,s[1],e,s[2],i))}else if("ListItem"==i.name&&"BulletList"==i.parent.name&&(s=/^([ \t]*)([-+*])([ \t]{1,4}\[[ xX]\])?([ \t]+)/.exec(o.text.slice(a)))){let e=s[4],t=s[0].length;e.length>4&&(e=e.slice(0,e.length-4),t-=4);let r=s[2];s[3]&&(r+=s[3].replace(/[xX]/," ")),n.push(new at(i.parent,a,a+t,s[1],e,r,i))}}return n}function ht(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function ft(e,t,r,n=0){for(let s=-1,i=e;;){if("ListItem"==i.name){let e=ht(i,t),o=+e[2];if(s>=0){if(o!=s+1)return;r.push({from:i.from+e[1].length,to:i.from+e[0].length,insert:String(s+2+n)})}s=o}let e=i.nextSibling;if(!e)break;i=e}}const ct=({state:e,dispatch:t})=>{let r=f(e),{doc:n}=e,s=null,i=e.changeByRange((t=>{if(!t.empty||!ot.isActiveAt(e,t.from))return s={range:t};let i=t.from,o=n.lineAt(i),a=lt(r.resolveInner(i,-1),n);for(;a.length&&a[a.length-1].from>i-o.from;)a.pop();if(!a.length)return s={range:t};let l=a[a.length-1];if(l.to-l.spaceAfter.length>i-o.from)return s={range:t};let h=i>=l.to-l.spaceAfter.length&&!/\S/.test(o.text.slice(l.to));if(l.item&&h){if(l.node.firstChild.to>=i||o.from>0&&!/[^\s>]/.test(n.lineAt(o.from-1).text)){let e,t=a.length>1?a[a.length-2]:null,r="";t&&t.item?(e=o.from+t.from,r=t.marker(n,1)):e=o.from+(t?t.to:0);let s=[{from:e,to:i,insert:r}];return"OrderedList"==l.node.name&&ft(l.item,n,s,-2),t&&"OrderedList"==t.node.name&&ft(t.item,n,s),{range:c.cursor(e+r.length),changes:s}}{let t="";for(let e=0,r=a.length-2;e<=r;e++)t+=a[e].blank(e<r?a[e+1].from-t.length:null,e<r);return t+=e.lineBreak,{range:c.cursor(i+t.length),changes:{from:o.from,insert:t}}}}if("Blockquote"==l.node.name&&h&&o.from){let r=n.lineAt(o.from-1),s=/>\s*$/.exec(r.text);if(s&&s.index==l.from){let n=e.changes([{from:r.from+s.index,to:r.to},{from:o.from+l.from,to:o.to}]);return{range:t.map(n),changes:n}}}let f=[];"OrderedList"==l.node.name&&ft(l.item,n,f);let d=l.item&&l.item.from<o.from,u="";if(!d||/^[\s\d.)\-+*>]*/.exec(o.text)[0].length>=l.to)for(let e=0,t=a.length-1;e<=t;e++)u+=e!=t||d?a[e].blank(e<t?a[e+1].from-u.length:null):a[e].marker(n,1);let p=i;for(;p>o.from&&/\s/.test(o.text.charAt(p-o.from-1));)p--;return u=e.lineBreak+u,f.push({from:p,to:i,insert:u}),{range:c.cursor(p+u.length),changes:f}}));return!s&&(t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0)};function dt(e){return"QuoteMark"==e.name||"ListMark"==e.name}const pt=({state:e,dispatch:t})=>{let r=f(e),n=null,s=e.changeByRange((t=>{let s=t.from,{doc:i}=e;if(t.empty&&ot.isActiveAt(e,t.from)){let e=i.lineAt(s),n=lt(function(e,t){let r=e.resolveInner(t,-1),n=t;dt(r)&&(n=r.from,r=r.parent);for(let e;e=r.childBefore(n);)if(dt(e))n=e.from;else{if("OrderedList"!=e.name&&"BulletList"!=e.name)break;r=e.lastChild,n=r.to}return r}(r,s),i);if(n.length){let r=n[n.length-1],i=r.to-r.spaceAfter.length+(r.spaceAfter?1:0);if(s-e.from>i&&!/\S/.test(e.text.slice(i,s-e.from)))return{range:c.cursor(e.from+i),changes:{from:e.from+i,to:s}};if(s-e.from==i&&(!r.item||e.from<=r.item.from||!/\S/.test(e.text.slice(0,r.to)))){let n=e.from+r.from;if(r.item&&r.node.from<r.item.from&&/\S/.test(e.text.slice(r.from,r.to)))return{range:t,changes:{from:n,to:e.from+r.to,insert:r.blank(r.to-r.from)}};if(n<s)return{range:c.cursor(n),changes:{from:n,to:s}}}}}return n={range:t}}));return!n&&(t(e.update(s,{scrollIntoView:!0,userEvent:"delete"})),!0)},ut=[{key:"Enter",run:ct},{key:"Backspace",run:pt}],mt=k({matchClosingTags:!1});function gt(e={}){let{codeLanguages:t,defaultCodeLanguage:r,addKeymap:n=!0,base:{parser:s}=it}=e;if(!(s instanceof ne))throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");let i,o=e.extensions?[e.extensions]:[],a=[mt.support];r instanceof d?(a.push(r.support),i=r.language):r&&(i=r);let h=t||i?(f=t,c=i,e=>{if(e&&f){let t=null;if(e=/\S*/.exec(e)[0],t="function"==typeof f?f(e):x.matchLanguageName(f,e,!0),t instanceof x)return t.support?t.support.language.parser:b.getSkippingParser(t.load());if(t)return t.parser}return c?c.parser:null}):void 0;var f,c;return o.push(function(e){let{codeParser:t,htmlParser:r}=e,n=l(((e,n)=>{let s=e.type.id;if(!t||s!=w.CodeBlock&&s!=w.FencedCode){if(r&&(s==w.HTMLBlock||s==w.HTMLTag))return{parser:r,overlay:Me(e.node,e.from,e.to)}}else{let r="";if(s==w.FencedCode){let t=e.node.getChild(w.CodeInfo);t&&(r=n.read(t.from,t.to))}let i=t(r);if(i)return{parser:i,overlay:e=>e.type.id==w.CodeText}}return null}));return{wrap:n}}({codeParser:h,htmlParser:mt.language.parser})),n&&a.push(p.high(u.of(ut))),new d(st(s.configure(o)),a)}export{it as commonmarkLanguage,pt as deleteMarkupBackward,ct as insertNewlineContinueMarkup,gt as markdown,ut as markdownKeymap,ot as markdownLanguage};