@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
6 lines • 43.7 kB
JavaScript
import{C as e,D as t,E as n,H as r,K as i,L as a,M as o,N as s,Ot as c,P as l,R as u,Tt as d,U as f,V as p,a as m,b as h,f as ee,i as te,j as g,o as ne,s as re,st as ie,wt as _,y as ae,z as v,zt as y}from"./dist-CrVLAEWP.js";import{t as oe}from"./dist-H6yvDjb0.js";import{html as se,htmlCompletionSource as ce}from"./dist-Dmx4nq4D.js";var le=class e{static create(t,n,r,i,a){let o=i+(i<<8)+t+(n<<4)|0;return new e(t,n,r,o,a,[],[])}constructor(e,t,n,r,i,o,s){this.type=e,this.value=t,this.from=n,this.hash=r,this.end=i,this.children=o,this.positions=s,this.hashProp=[[a.contextHash,r]]}addChild(e,t){e.prop(a.contextHash)!=this.hash&&(e=new r(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(t)}toTree(e,t=this.end){let n=this.children.length-1;return n>=0&&(t=Math.max(t,this.positions[n]+this.children[n].length+this.from)),new r(e.types[this.type],this.children,this.positions,t-this.from).balance({makeTree:(e,t,n)=>new r(v.none,e,t,n,this.hashProp)})}},b;(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.Autolink=33]=`Autolink`,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`,e[e.URL=44]=`URL`})(b||={});var ue=class{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}},de=class{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 S(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,n=0){for(let r=t;r<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return n}findColumn(e){let t=0;for(let n=0;t<this.text.length&&n<e;t++)n+=this.text.charCodeAt(t)==9?4-n%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 fe(e,t,n){if(n.pos==n.text.length||e!=t.block&&n.indent>=t.stack[n.depth+1].value+n.baseIndent)return!0;if(n.indent>=n.baseIndent+4)return!1;let r=(e.type==b.OrderedList?E:T)(n,t,!1);return r>0&&(e.type!=b.BulletList||C(n,t,!1)<0)&&n.text.charCodeAt(n.pos+r-1)==e.value}var pe={[b.Blockquote](e,t,n){return n.next==62?(n.markers.push(L(b.QuoteMark,t.lineStart+n.pos,t.lineStart+n.pos+1)),n.moveBase(n.pos+(x(n.text.charCodeAt(n.pos+1))?2:1)),e.end=t.lineStart+n.text.length,!0):!1},[b.ListItem](e,t,n){return n.indent<n.baseIndent+e.value&&n.next>-1?!1:(n.moveBaseColumn(n.baseIndent+e.value),!0)},[b.OrderedList]:fe,[b.BulletList]:fe,[b.Document](){return!0}};function x(e){return e==32||e==9||e==10||e==13}function S(e,t=0){for(;t<e.length&&x(e.charCodeAt(t));)t++;return t}function me(e,t,n){for(;t>n&&x(e.charCodeAt(t-1));)t--;return t}function he(e){if(e.next!=96&&e.next!=126)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(e.next==96){for(let n=t;n<e.text.length;n++)if(e.text.charCodeAt(n)==96)return-1}return t}function ge(e){return e.next==62?e.text.charCodeAt(e.pos+1)==32?2:1:-1}function C(e,t,n){if(e.next!=42&&e.next!=45&&e.next!=95)return-1;let r=1;for(let t=e.pos+1;t<e.text.length;t++){let n=e.text.charCodeAt(t);if(n==e.next)r++;else if(!x(n))return-1}return n&&e.next==45&&ve(e)>-1&&e.depth==t.stack.length&&t.parser.leafBlockParsers.indexOf(Te.SetextHeading)>-1||r<3?-1:1}function w(e,t){for(let n=e.stack.length-1;n>=0;n--)if(e.stack[n].type==t)return!0;return!1}function T(e,t,n){return(e.next==45||e.next==43||e.next==42)&&(e.pos==e.text.length-1||x(e.text.charCodeAt(e.pos+1)))&&(!n||w(t,b.BulletList)||e.skipSpace(e.pos+2)<e.text.length)?1:-1}function E(e,t,n){let r=e.pos,i=e.next;for(;i>=48&&i<=57;){if(r++,r==e.text.length)return-1;i=e.text.charCodeAt(r)}return r==e.pos||r>e.pos+9||i!=46&&i!=41||r<e.text.length-1&&!x(e.text.charCodeAt(r+1))||n&&!w(t,b.OrderedList)&&(e.skipSpace(r+1)==e.text.length||r>e.pos+1||e.next!=49)?-1:r+1-e.pos}function _e(e){if(e.next!=35)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==35;)t++;if(t<e.text.length&&e.text.charCodeAt(t)!=32)return-1;let n=t-e.pos;return n>6?-1:n}function ve(e){if(e.next!=45&&e.next!=61||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 n=t;for(;t<e.text.length&&x(e.text.charCodeAt(t));)t++;return t==e.text.length?n:-1}var D=/^[ \t]*$/,ye=/-->/,be=/\?>/,O=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,ye],[/^\s*<\?/,be],[/^\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,D],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,D]];function xe(e,t,n){if(e.next!=60)return-1;let r=e.text.slice(e.pos);for(let e=0,t=O.length-+!!n;e<t;e++)if(O[e][0].test(r))return e;return-1}function Se(e,t){let n=e.countIndent(t,e.pos,e.indent),r=e.countIndent(e.skipSpace(t),t,n);return r>=n+5?n+1:r}function k(e,t,n){let r=e.length-1;r>=0&&e[r].to==t&&e[r].type==b.CodeText?e[r].to=n:e.push(L(b.CodeText,t,n))}var A={LinkReference:void 0,IndentedCode(e,t){let n=t.baseIndent+4;if(t.indent<n)return!1;let r=t.findColumn(n),i=e.lineStart+r,a=e.lineStart+t.text.length,o=[],s=[];for(k(o,i,a);e.nextLine()&&t.depth>=e.stack.length;)if(t.pos==t.text.length){k(s,e.lineStart-1,e.lineStart);for(let e of t.markers)s.push(e)}else if(t.indent<n)break;else{if(s.length){for(let e of s)e.type==b.CodeText?k(o,e.from,e.to):o.push(e);s=[]}k(o,e.lineStart-1,e.lineStart);for(let e of t.markers)o.push(e);a=e.lineStart+t.text.length;let n=e.lineStart+t.findColumn(t.baseIndent+4);n<a&&k(o,n,a)}return s.length&&(s=s.filter(e=>e.type!=b.CodeText),s.length&&(t.markers=s.concat(t.markers))),e.addNode(e.buffer.writeElements(o,-i).finish(b.CodeBlock,a-i),i),!0},FencedCode(e,t){let n=he(t);if(n<0)return!1;let r=e.lineStart+t.pos,i=t.next,a=n-t.pos,o=t.skipSpace(n),s=me(t.text,t.text.length,o),c=[L(b.CodeMark,r,r+a)];o<s&&c.push(L(b.CodeInfo,e.lineStart+o,e.lineStart+s));for(let n=!0,r=!0,o=!1;e.nextLine()&&t.depth>=e.stack.length;n=!1){let s=t.pos;if(t.indent-t.baseIndent<4)for(;s<t.text.length&&t.text.charCodeAt(s)==i;)s++;if(s-t.pos>=a&&t.skipSpace(s)==t.text.length){for(let e of t.markers)c.push(e);r&&o&&k(c,e.lineStart-1,e.lineStart),c.push(L(b.CodeMark,e.lineStart+t.pos,e.lineStart+s)),e.nextLine();break}else{o=!0,n||(k(c,e.lineStart-1,e.lineStart),r=!1);for(let e of t.markers)c.push(e);let i=e.lineStart+t.basePos,a=e.lineStart+t.text.length;i<a&&(k(c,i,a),r=!1)}}return e.addNode(e.buffer.writeElements(c,-r).finish(b.FencedCode,e.prevLineEnd()-r),r),!0},Blockquote(e,t){let n=ge(t);return n<0?!1:(e.startContext(b.Blockquote,t.pos),e.addNode(b.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1),t.moveBase(t.pos+n),null)},HorizontalRule(e,t){if(C(t,e,!1)<0)return!1;let n=e.lineStart+t.pos;return e.nextLine(),e.addNode(b.HorizontalRule,n),!0},BulletList(e,t){let n=T(t,e,!1);if(n<0)return!1;e.block.type!=b.BulletList&&e.startContext(b.BulletList,t.basePos,t.next);let r=Se(t,t.pos+1);return e.startContext(b.ListItem,t.basePos,r-t.baseIndent),e.addNode(b.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},OrderedList(e,t){let n=E(t,e,!1);if(n<0)return!1;e.block.type!=b.OrderedList&&e.startContext(b.OrderedList,t.basePos,t.text.charCodeAt(t.pos+n-1));let r=Se(t,t.pos+n);return e.startContext(b.ListItem,t.basePos,r-t.baseIndent),e.addNode(b.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},ATXHeading(e,t){let n=_e(t);if(n<0)return!1;let r=t.pos,i=e.lineStart+r,a=me(t.text,t.text.length,r),o=a;for(;o>r&&t.text.charCodeAt(o-1)==t.next;)o--;(o==a||o==r||!x(t.text.charCodeAt(o-1)))&&(o=t.text.length);let s=e.buffer.write(b.HeaderMark,0,n).writeElements(e.parser.parseInline(t.text.slice(r+n+1,o),i+n+1),-i);o<t.text.length&&s.write(b.HeaderMark,o-r,a-r);let c=s.finish(b.ATXHeading1-1+n,t.text.length-r);return e.nextLine(),e.addNode(c,i),!0},HTMLBlock(e,t){let n=xe(t,e,!1);if(n<0)return!1;let r=e.lineStart+t.pos,i=O[n][1],a=[],o=i!=D;for(;!i.test(t.text)&&e.nextLine();){if(t.depth<e.stack.length){o=!1;break}for(let e of t.markers)a.push(e)}o&&e.nextLine();let s=i==ye?b.CommentBlock:i==be?b.ProcessingInstructionBlock:b.HTMLBlock,c=e.prevLineEnd();return e.addNode(e.buffer.writeElements(a,-r).finish(s,c-r),r),!0},SetextHeading:void 0},Ce=class{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,n){if(this.stage==-1)return!1;let r=n.content+`
`+t.scrub(),i=this.advance(r);return i>-1&&i<r.length&&this.complete(e,n,i)}finish(e,t){return(this.stage==2||this.stage==3)&&S(t.content,this.pos)==t.content.length&&this.complete(e,t,t.content.length)}complete(e,t,n){return e.addLeafElement(t,L(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;else if(this.stage==0){if(!this.nextStage(Be(e,this.pos,this.start,!0)))return-1;if(e.charCodeAt(this.pos)!=58)return this.stage=-1;this.elts.push(L(b.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else if(this.stage==1){if(!this.nextStage(Re(e,S(e,this.pos),this.start)))return-1}else if(this.stage==2){let t=S(e,this.pos),n=0;if(t>this.pos){let r=ze(e,t,this.start);if(r){let t=j(e,r.to-this.start);t>0&&(this.nextStage(r),n=t)}}return n||=j(e,this.pos),n>0&&n<e.length?n:-1}else return j(e,this.pos)}};function j(e,t){for(;t<e.length;t++){let n=e.charCodeAt(t);if(n==10)break;if(!x(n))return-1}return t}var we=class{nextLine(e,t,n){let r=t.depth<e.stack.length?-1:ve(t),i=t.next;if(r<0)return!1;let a=L(b.HeaderMark,e.lineStart+t.pos,e.lineStart+r);return e.nextLine(),e.addLeafElement(n,L(i==61?b.SetextHeading1:b.SetextHeading2,n.start,e.prevLineEnd(),[...e.parser.parseInline(n.content,n.start),a])),!0}finish(){return!1}},Te={LinkReference(e,t){return t.content.charCodeAt(0)==91?new Ce(t):null},SetextHeading(){return new we}},Ee=[(e,t)=>_e(t)>=0,(e,t)=>he(t)>=0,(e,t)=>ge(t)>=0,(e,t)=>T(t,e,!0)>=0,(e,t)=>E(t,e,!0)>=0,(e,t)=>C(t,e,!0)>=0,(e,t)=>xe(t,e,!0)>=0],De={text:``,end:0},Oe=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.line=new de,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=le.create(b.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=n.length?new He(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(let t=0;;){let n=e.depth<this.stack.length?this.stack[this.stack.length-1]:null;for(;t<e.markers.length&&(!n||e.markers[t].from<n.end);){let n=e.markers[t++];this.addNode(n.type,n.from,n.to)}if(!n)break;this.finishContext()}if(e.pos<e.text.length)break;if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(e.basePos))return null;start:for(;;){for(let t of this.parser.blockParsers)if(t){let n=t(this,e);if(n!=0){if(n==1)return null;e.forward();continue start}}break}let t=new ue(this.lineStart+e.pos,e.text.slice(e.pos));for(let e of this.parser.leafBlockParsers)if(e){let n=e(this,t);n&&t.parsers.push(n)}lines: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 lines}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 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=Ue(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)}peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}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=De;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,n=this.rangeI;for(;this.ranges[n].to<t.end;){n++;let r=this.ranges[n].from,i=this.lineChunkAt(r);t.end=r+i.length,t.text=t.text.slice(0,this.ranges[n-1].to-e)+i,e=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 t=this.stack[e.depth],n=this.parser.skipContextMarkup[t.type];if(!n)throw Error(`Unhandled block context `+b[t.type]);let r=this.line.markers.length;if(!n(t,this,e)){this.line.markers.length>r&&(t.end=this.line.markers[this.line.markers.length-1].to),e.forward();break}e.forward()}}lineChunkAt(e){let t=this.input.chunk(e),n;if(this.input.lineChunks)n=t==`
`?``:t;else{let e=t.indexOf(`
`);n=e<0?t:t.slice(0,e)}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=le.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 r(this.parser.nodeSet.types[e],F,F,(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(W(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?ke(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=W(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`?L(this.parser.getNodeType(e),t,n,r):new Ne(e,t)}get buffer(){return new Me(this.parser.nodeSet)}};function ke(e,t,n,i,a){let o=e[t].to,s=[],c=[],l=n.from+i;function u(n,r){for(;r?n>=o:n>o;){let r=e[t+1].from-o;i+=r,n+=r,t++,o=e[t].to}}for(let r=n.firstChild;r;r=r.nextSibling){u(r.from+i,!0);let n=r.from+i,d,f=a.get(r.tree);f?d=f:r.to+i>o?(d=ke(e,t,r,i,a),u(r.to+i,!1)):d=r.toTree(),s.push(d),c.push(n-l)}return u(n.to+i,!1),new r(n.type,s,c,n.to+i-l,n.tree?n.tree.propValues:void 0)}var Ae=class e extends p{constructor(e,t,n,r,i,a,o,s,c){super(),this.nodeSet=e,this.blockParsers=t,this.leafBlockParsers=n,this.blockNames=r,this.endLeafBlock=i,this.skipContextMarkup=a,this.inlineParsers=o,this.inlineNames=s,this.wrappers=c,this.nodeTypes=Object.create(null);for(let t of e.types)this.nodeTypes[t.name]=t.id}createParse(e,t,n){let r=new Oe(this,e,t,n);for(let i of this.wrappers)r=i(r,e,t,n);return r}configure(t){let n=N(t);if(!n)return this;let{nodeSet:r,skipContextMarkup:i}=this,c=this.blockParsers.slice(),l=this.leafBlockParsers.slice(),d=this.blockNames.slice(),f=this.inlineParsers.slice(),p=this.inlineNames.slice(),m=this.endLeafBlock.slice(),h=this.wrappers;if(M(n.defineNodes)){i=Object.assign({},i);let e=r.types.slice(),t;for(let r of n.defineNodes){let{name:n,block:s,composite:c,style:l}=typeof r==`string`?{name:r}:r;if(e.some(e=>e.name==n))continue;c&&(i[e.length]=(e,t,n)=>c(t,n,e.value));let u=e.length,d=c?[`Block`,`BlockContext`]:s?u>=b.ATXHeading1&&u<=b.SetextHeading2?[`Block`,`LeafBlock`,`Heading`]:[`Block`,`LeafBlock`]:void 0;e.push(v.define({id:u,name:n,props:d&&[[a.group,d]]})),l&&(t||={},Array.isArray(l)||l instanceof o?t[n]=l:Object.assign(t,l))}r=new u(e),t&&(r=r.extend(s(t)))}if(M(n.props)&&(r=r.extend(...n.props)),M(n.remove))for(let e of n.remove){let t=this.blockNames.indexOf(e),n=this.inlineNames.indexOf(e);t>-1&&(c[t]=l[t]=void 0),n>-1&&(f[n]=void 0)}if(M(n.parseBlock))for(let e of n.parseBlock){let t=d.indexOf(e.name);if(t>-1)c[t]=e.parse,l[t]=e.leaf;else{let t=e.before?P(d,e.before):e.after?P(d,e.after)+1:d.length-1;c.splice(t,0,e.parse),l.splice(t,0,e.leaf),d.splice(t,0,e.name)}e.endLeaf&&m.push(e.endLeaf)}if(M(n.parseInline))for(let e of n.parseInline){let t=p.indexOf(e.name);if(t>-1)f[t]=e.parse;else{let t=e.before?P(p,e.before):e.after?P(p,e.after)+1:p.length-1;f.splice(t,0,e.parse),p.splice(t,0,e.name)}}return n.wrap&&(h=h.concat(n.wrap)),new e(r,c,l,d,m,i,f,p,h)}getNodeType(e){let t=this.nodeTypes[e];if(t==null)throw RangeError(`Unknown node type '${e}'`);return t}parseInline(e,t){let n=new U(this,e,t);outer:for(let e=t;e<n.end;){let t=n.char(e);for(let r of this.inlineParsers)if(r){let i=r(n,t,e);if(i>=0){e=i;continue outer}}e++}return n.resolveMarkers(0)}};function M(e){return e!=null&&e.length>0}function N(e){if(!Array.isArray(e))return e;if(e.length==0)return null;let t=N(e[0]);if(e.length==1)return t;let n=N(e.slice(1));if(!n||!t)return t||n;let r=(e,t)=>(e||F).concat(t||F),i=t.wrap,a=n.wrap;return{props:r(t.props,n.props),defineNodes:r(t.defineNodes,n.defineNodes),parseBlock:r(t.parseBlock,n.parseBlock),parseInline:r(t.parseInline,n.parseInline),remove:r(t.remove,n.remove),wrap:i?a?(e,t,n,r)=>i(a(e,t,n,r),t,n,r):i:a}}function P(e,t){let n=e.indexOf(t);if(n<0)throw RangeError(`Position specified relative to unknown parser ${t}`);return n}var je=[v.none];for(let e=1,t;t=b[e];e++)je[e]=v.define({id:e,name:t,props:e>=b.Escape?[]:[[a.group,e in pe?[`Block`,`BlockContext`]:[`Block`,`LeafBlock`]]],top:t==`Document`});var F=[],Me=class{constructor(e){this.nodeSet=e,this.content=[],this.nodes=[]}write(e,t,n,r=0){return this.content.push(e,t,n,4+r*4),this}writeElements(e,t=0){for(let n of e)n.writeTo(this,t);return this}finish(e,t){return r.build({buffer:this.content,nodeSet:this.nodeSet,reused:this.nodes,topID:e,length:t})}},I=class{constructor(e,t,n,r=F){this.type=e,this.from=t,this.to=n,this.children=r}writeTo(e,t){let n=e.content.length;e.writeElements(this.children,t),e.content.push(this.type,this.from+t,this.to+t,e.content.length+4-n)}toTree(e){return new Me(e).writeElements(this.children,-this.from).finish(this.type,this.to-this.from)}},Ne=class{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 F}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 L(e,t,n,r){return new I(e,t,n,r)}var Pe={resolve:`Emphasis`,mark:`EmphasisMark`},Fe={resolve:`Emphasis`,mark:`EmphasisMark`},R={},z={},B=class{constructor(e,t,n,r){this.type=e,this.from=t,this.to=n,this.side=r}},Ie=`!"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`,V=/[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;try{V=RegExp(`[\\p{S}|\\p{P}]`,`u`)}catch{}var H={Escape(e,t,n){if(t!=92||n==e.end-1)return-1;let r=e.char(n+1);for(let t=0;t<32;t++)if(Ie.charCodeAt(t)==r)return e.append(L(b.Escape,n,n+2));return-1},Entity(e,t,n){if(t!=38)return-1;let r=/^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(e.slice(n+1,n+31));return r?e.append(L(b.Entity,n,n+1+r[0].length)):-1},InlineCode(e,t,n){if(t!=96||n&&e.char(n-1)==96)return-1;let r=n+1;for(;r<e.end&&e.char(r)==96;)r++;let i=r-n,a=0;for(;r<e.end;r++)if(e.char(r)==96){if(a++,a==i&&e.char(r+1)!=96)return e.append(L(b.InlineCode,n,r+1,[L(b.CodeMark,n,n+i),L(b.CodeMark,r+1-i,r+1)]))}else a=0;return-1},HTMLTag(e,t,n){if(t!=60||n==e.end-1)return-1;let r=e.slice(n+1,e.end),i=/^(?:[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(r);if(i)return e.append(L(b.Autolink,n,n+1+i[0].length,[L(b.LinkMark,n,n+1),L(b.URL,n+1,n+i[0].length),L(b.LinkMark,n+i[0].length,n+1+i[0].length)]));let a=/^!--[^>](?:-[^-]|[^-])*?-->/i.exec(r);if(a)return e.append(L(b.Comment,n,n+1+a[0].length));let o=/^\?[^]*?\?>/.exec(r);if(o)return e.append(L(b.ProcessingInstruction,n,n+1+o[0].length));let s=/^(?:![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(r);return s?e.append(L(b.HTMLTag,n,n+1+s[0].length)):-1},Emphasis(e,t,n){if(t!=95&&t!=42)return-1;let r=n+1;for(;e.char(r)==t;)r++;let i=e.slice(n-1,n),a=e.slice(r,r+1),o=V.test(i),s=V.test(a),c=/\s|^$/.test(i),l=/\s|^$/.test(a),u=!l&&(!s||c||o),d=!c&&(!o||l||s),f=u&&(t==42||!d||o),p=d&&(t==42||!u||s);return e.append(new B(t==95?Pe:Fe,n,r,!!f|(p?2:0)))},HardBreak(e,t,n){if(t==92&&e.char(n+1)==10)return e.append(L(b.HardBreak,n,n+2));if(t==32){let t=n+1;for(;e.char(t)==32;)t++;if(e.char(t)==10&&t>=n+2)return e.append(L(b.HardBreak,n,t+1))}return-1},Link(e,t,n){return t==91?e.append(new B(R,n,n+1,1)):-1},Image(e,t,n){return t==33&&e.char(n+1)==91?e.append(new B(z,n,n+2,1)):-1},LinkEnd(e,t,n){if(t!=93)return-1;for(let t=e.parts.length-1;t>=0;t--){let r=e.parts[t];if(r instanceof B&&(r.type==R||r.type==z)){if(!r.side||e.skipSpace(r.to)==n&&!/[(\[]/.test(e.slice(n+1,n+2)))return e.parts[t]=null,-1;let i=e.takeContent(t),a=e.parts[t]=Le(e,i,r.type==R?b.Link:b.Image,r.from,n+1);if(r.type==R)for(let n=0;n<t;n++){let t=e.parts[n];t instanceof B&&t.type==R&&(t.side=0)}return a.to}}return-1}};function Le(e,t,n,r,i){let{text:a}=e,o=e.char(i),s=i;if(t.unshift(L(b.LinkMark,r,r+(n==b.Image?2:1))),t.push(L(b.LinkMark,i-1,i)),o==40){let n=e.skipSpace(i+1),r=Re(a,n-e.offset,e.offset),o;r&&(n=e.skipSpace(r.to),n!=r.to&&(o=ze(a,n-e.offset,e.offset),o&&(n=e.skipSpace(o.to)))),e.char(n)==41&&(t.push(L(b.LinkMark,i,i+1)),s=n+1,r&&t.push(r),o&&t.push(o),t.push(L(b.LinkMark,n,s)))}else if(o==91){let n=Be(a,i-e.offset,e.offset,!1);n&&(t.push(n),s=n.to)}return L(n,r,s,t)}function Re(e,t,n){if(e.charCodeAt(t)==60){for(let r=t+1;r<e.length;r++){let i=e.charCodeAt(r);if(i==62)return L(b.URL,t+n,r+1+n);if(i==60||i==10)return!1}return null}else{let r=0,i=t;for(let t=!1;i<e.length;i++){let n=e.charCodeAt(i);if(x(n))break;if(t)t=!1;else if(n==40)r++;else if(n==41){if(!r)break;r--}else n==92&&(t=!0)}return i>t?L(b.URL,t+n,i+n):i==e.length&&null}}function ze(e,t,n){let r=e.charCodeAt(t);if(r!=39&&r!=34&&r!=40)return!1;let i=r==40?41:r;for(let r=t+1,a=!1;r<e.length;r++){let o=e.charCodeAt(r);if(a)a=!1;else if(o==i)return L(b.LinkTitle,t+n,r+1+n);else o==92&&(a=!0)}return null}function Be(e,t,n,r){for(let i=!1,a=t+1,o=Math.min(e.length,a+999);a<o;a++){let o=e.charCodeAt(a);if(i)i=!1;else if(o==93)return!r&&L(b.LinkLabel,t+n,a+1+n);else{if(r&&!x(o)&&(r=!1),o==91)return!1;o==92&&(i=!0)}}return null}var U=class{constructor(e,t,n){this.parser=e,this.text=t,this.offset=n,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,n,r,i){return this.append(new B(e,t,n,!!r|(i?2:0)))}get hasOpenLink(){for(let e=this.parts.length-1;e>=0;e--){let t=this.parts[e];if(t instanceof B&&(t.type==R||t.type==z))return!0}return!1}addElement(e){return this.append(e)}resolveMarkers(e){for(let t=e;t<this.parts.length;t++){let n=this.parts[t];if(!(n instanceof B&&n.type.resolve&&n.side&2))continue;let r=n.type==Pe||n.type==Fe,i=n.to-n.from,a,o=t-1;for(;o>=e;o--){let e=this.parts[o];if(e instanceof B&&e.side&1&&e.type==n.type&&!(r&&(n.side&1||e.side&2)&&(e.to-e.from+i)%3==0&&((e.to-e.from)%3||i%3))){a=e;break}}if(!a)continue;let s=n.type.resolve,c=[],l=a.from,u=n.to;if(r){let e=Math.min(2,a.to-a.from,i);l=a.to-e,u=n.from+e,s=e==1?`Emphasis`:`StrongEmphasis`}a.type.mark&&c.push(this.elt(a.type.mark,l,a.to));for(let e=o+1;e<t;e++)this.parts[e]instanceof I&&c.push(this.parts[e]),this.parts[e]=null;n.type.mark&&c.push(this.elt(n.type.mark,n.from,u));let d=this.elt(s,l,u,c);this.parts[o]=r&&a.from!=l?new B(a.type,a.from,l,a.side):null,(this.parts[t]=r&&n.to!=u?new B(n.type,u,n.to,n.side):null)?this.parts.splice(t,0,d):this.parts[t]=d}let t=[];for(let n=e;n<this.parts.length;n++){let e=this.parts[n];e instanceof I&&t.push(e)}return t}findOpeningDelimiter(e){for(let t=this.parts.length-1;t>=0;t--){let n=this.parts[t];if(n instanceof B&&n.type==e&&n.side&1)return t}return null}takeContent(e){let t=this.resolveMarkers(e);return this.parts.length=e,t}getDelimiterAt(e){let t=this.parts[e];return t instanceof B?t:null}skipSpace(e){return S(this.text,e-this.offset)+this.offset}elt(e,t,n,r){return typeof e==`string`?L(this.parser.getNodeType(e),t,n,r):new Ne(e,t)}};U.linkStart=R,U.imageStart=z;function W(e,t){if(!t.length)return e;if(!e.length)return t;let n=e.slice(),r=0;for(let e of t){for(;r<n.length&&n[r].to<e.to;)r++;if(r<n.length&&n[r].from<e.from){let t=n[r];t instanceof I&&(n[r]=new I(t.type,t.from,t.to,W(t.children,[e])))}else n.splice(r++,0,e)}return n}var Ve=[b.CodeBlock,b.ListItem,b.OrderedList,b.BulletList],He=class{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&&this.input.read(e-1,e)!=`
`;)e--;this.fragmentEnd=e?e-1:0}let n=this.cursor;n||(n=this.cursor=this.fragment.tree.cursor(),n.firstChild());let r=e+this.fragment.offset;for(;n.to<=r;)if(!n.parent())return!1;for(;;){if(n.from>=r)return this.fragment.from<=t;if(!n.childAfter(r))return!1}}matches(e){let t=this.cursor.tree;return t&&t.prop(a.contextHash)==e}takeNodes(e){let t=this.cursor,n=this.fragment.offset,i=this.fragmentEnd-+!!this.fragment.openEnd,a=e.absoluteLineStart,o=a,s=e.block.children.length,c=o,l=s;for(;;){if(t.to-n>i){if(t.type.isAnonymous&&t.firstChild())continue;break}let a=Ue(t.from-n,e.ranges);if(t.to-n<=e.ranges[e.rangeI].to)e.addNode(t.tree,a);else{let n=new r(e.parser.nodeSet.types[b.Paragraph],[],[],0,e.block.hashProp);e.reusePlaceholders.set(n,t.tree),e.addNode(n,a)}if(t.type.is(`Block`)&&(Ve.indexOf(t.type.id)<0?(o=t.to-n,s=e.block.children.length):(o=c,s=l),c=t.to-n,l=e.block.children.length),!t.nextSibling())break}for(;e.block.children.length>s;)e.block.children.pop(),e.block.positions.pop();return o-a}};function Ue(e,t){let n=e;for(let r=1;r<t.length;r++){let i=t[r-1].to,a=t[r].from;i<e&&(n-=a-i)}return n}var We=s({"Blockquote/...":l.quote,HorizontalRule:l.contentSeparator,"ATXHeading1/... SetextHeading1/...":l.heading1,"ATXHeading2/... SetextHeading2/...":l.heading2,"ATXHeading3/...":l.heading3,"ATXHeading4/...":l.heading4,"ATXHeading5/...":l.heading5,"ATXHeading6/...":l.heading6,"Comment CommentBlock":l.comment,Escape:l.escape,Entity:l.character,"Emphasis/...":l.emphasis,"StrongEmphasis/...":l.strong,"Link/... Image/...":l.link,"OrderedList/... BulletList/...":l.list,"BlockQuote/...":l.quote,"InlineCode CodeText":l.monospace,"URL Autolink":l.url,"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":l.processingInstruction,"CodeInfo LinkLabel":l.labelName,LinkTitle:l.string,Paragraph:l.content}),Ge=new Ae(new u(je).extend(We),Object.keys(A).map(e=>A[e]),Object.keys(A).map(e=>Te[e]),Object.keys(A),Ee,pe,Object.keys(H).map(e=>H[e]),Object.keys(H),[]);function Ke(e,t,n){let r=[];for(let i=e.firstChild,a=t;;i=i.nextSibling){let e=i?i.from:n;if(e>a&&r.push({from:a,to:e}),!i)break;a=i.to}return r}function qe(e){let{codeParser:t,htmlParser:n}=e;return{wrap:f((e,r)=>{let i=e.type.id;if(t&&(i==b.CodeBlock||i==b.FencedCode)){let n=``;if(i==b.FencedCode){let t=e.node.getChild(b.CodeInfo);t&&(n=r.read(t.from,t.to))}let a=t(n);if(a)return{parser:a,overlay:e=>e.type.id==b.CodeText,bracketed:i==b.FencedCode}}else if(n&&(i==b.HTMLBlock||i==b.HTMLTag||i==b.CommentBlock))return{parser:n,overlay:Ke(e.node,e.from,e.to)};return null})}}var Je={resolve:`Strikethrough`,mark:`StrikethroughMark`},Ye={defineNodes:[{name:`Strikethrough`,style:{"Strikethrough/...":l.strikethrough}},{name:`StrikethroughMark`,style:l.processingInstruction}],parseInline:[{name:`Strikethrough`,parse(e,t,n){if(t!=126||e.char(n+1)!=126||e.char(n+2)==126)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=V.test(r),c=V.test(i);return e.addDelimiter(Je,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))},after:`Emphasis`}]};function G(e,t,n=0,r,i=0){let a=0,o=!0,s=-1,c=-1,l=!1,u=()=>{r.push(e.elt(`TableCell`,i+s,i+c,e.parser.parseInline(t.slice(s,c),i+s)))};for(let d=n;d<t.length;d++){let n=t.charCodeAt(d);n==124&&!l?((!o||s>-1)&&a++,o=!1,r&&(s>-1&&u(),r.push(e.elt(`TableDelimiter`,d+i,d+i+1))),s=c=-1):(l||n!=32&&n!=9)&&(s<0&&(s=d),c=d+1),l=!l&&n==92}return s>-1&&(a++,r&&u()),a}function Xe(e,t){for(let n=t;n<e.length;n++){let t=e.charCodeAt(n);if(t==124)return!0;t==92&&n++}return!1}var Ze=/^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/,Qe=class{constructor(){this.rows=null}nextLine(e,t,n){if(this.rows==null){this.rows=!1;let r;if((t.next==45||t.next==58||t.next==124)&&Ze.test(r=t.text.slice(t.pos))){let i=[];G(e,n.content,0,i,n.start)==G(e,r,0)&&(this.rows=[e.elt(`TableHeader`,n.start,n.start+n.content.length,i),e.elt(`TableDelimiter`,e.lineStart+t.pos,e.lineStart+t.text.length)])}}else if(this.rows){let n=[];G(e,t.text,t.pos,n,e.lineStart),this.rows.push(e.elt(`TableRow`,e.lineStart+t.pos,e.lineStart+t.text.length,n))}return!1}finish(e,t){return this.rows?(e.addLeafElement(t,e.elt(`Table`,t.start,t.start+t.content.length,this.rows)),!0):!1}},$e={defineNodes:[{name:`Table`,block:!0},{name:`TableHeader`,style:{"TableHeader/...":l.heading}},`TableRow`,{name:`TableCell`,style:l.content},{name:`TableDelimiter`,style:l.processingInstruction}],parseBlock:[{name:`Table`,leaf(e,t){return Xe(t.content,0)?new Qe:null},endLeaf(e,t,n){if(n.parsers.some(e=>e instanceof Qe)||!Xe(t.text,t.basePos))return!1;let r=e.peekLine();return Ze.test(r)&&G(e,t.text,t.basePos)==G(e,r,t.basePos)},before:`SetextHeading`}]},et=class{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}},tt={defineNodes:[{name:`Task`,block:!0,style:l.list},{name:`TaskMarker`,style:l.atom}],parseBlock:[{name:`TaskList`,leaf(e,t){return/^\[[ xX]\][ \t]/.test(t.content)&&e.parentType().name==`ListItem`?new et:null},after:`SetextHeading`}]},nt=/(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy,rt=/[\w-]+(\.[\w-]+)+(:\d+)?(\/[^\s<]*)?/gy,it=/[\w-]+\.[\w-]+($|[/:])/,at=/[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy,ot=/\/[a-zA-Z\d@.]+/gy;function st(e,t,n,r){let i=0;for(let a=t;a<n;a++)e[a]==r&&i++;return i}function ct(e,t){rt.lastIndex=t;let n=rt.exec(e);if(!n||it.exec(n[0])[0].indexOf(`_`)>-1)return-1;let r=t+n[0].length;for(;;){let n=e[r-1],i;if(/[?!.,:*_~]/.test(n)||n==`)`&&st(e,t,r,`)`)>st(e,t,r,`(`))r--;else if(n==`;`&&(i=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(t,r))))r=t+i.index;else break}return r}function lt(e,t){at.lastIndex=t;let n=at.exec(e);if(!n)return-1;let r=n[0][n[0].length-1];return r==`_`||r==`-`?-1:t+n[0].length-+(r==`.`)}var ut=[$e,tt,Ye,{parseInline:[{name:`Autolink`,parse(e,t,n){let r=n-e.offset;if(r&&/\w/.test(e.text[r-1]))return-1;nt.lastIndex=r;let i=nt.exec(e.text),a=-1;return!i||(i[1]||i[2]?(a=ct(e.text,r+i[0].length),a>-1&&e.hasOpenLink&&(a=r+/([^\[\]]|\[[^\]]*\])*/.exec(e.text.slice(r,a))[0].length)):i[3]?a=lt(e.text,r):(a=lt(e.text,r+i[0].length),a>-1&&i[0]==`xmpp:`&&(ot.lastIndex=a,i=ot.exec(e.text),i&&(a=i.index+i[0].length))),a<0)?-1:(e.addElement(e.elt(`URL`,n,a+e.offset)),a+e.offset)}}]}];function dt(e,t,n){return(r,i,a)=>{if(i!=e||r.char(a+1)==e)return-1;let o=[r.elt(n,a,a+1)];for(let i=a+1;i<r.end;i++){let s=r.char(i);if(s==e)return r.addElement(r.elt(t,a,i+1,o.concat(r.elt(n,i,i+1))));if(s==92&&o.push(r.elt(`Escape`,i,i+++2)),x(s))break}return-1}}var ft={defineNodes:[{name:`Superscript`,style:l.special(l.content)},{name:`SuperscriptMark`,style:l.processingInstruction}],parseInline:[{name:`Superscript`,parse:dt(94,`Superscript`,`SuperscriptMark`)}]},pt={defineNodes:[{name:`Subscript`,style:l.special(l.content)},{name:`SubscriptMark`,style:l.processingInstruction}],parseInline:[{name:`Subscript`,parse:dt(126,`Subscript`,`SubscriptMark`)}]},mt={defineNodes:[{name:`Emoji`,style:l.character}],parseInline:[{name:`Emoji`,parse(e,t,n){let r;return t!=58||!(r=/^[a-zA-Z_0-9]+:/.exec(e.slice(n+1,e.end)))?-1:e.addElement(e.elt(`Emoji`,n,n+1+r[0].length))}}]},ht=ee({commentTokens:{block:{open:`<!--`,close:`-->`}}}),gt=new a,_t=Ge.configure({props:[ae.add(e=>!e.is(`Block`)||e.is(`Document`)||K(e)!=null||vt(e)?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})),gt.add(K),e.add({Document:()=>null}),t.add({Document:ht})]});function K(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function vt(e){return e.name==`OrderedList`||e.name==`BulletList`}function yt(e,t){let n=e;for(;;){let e=n.nextSibling,r;if(!e||(r=K(e.type))!=null&&r<=t)break;n=e}return n.to}var bt=h.of((e,t,n)=>{for(let r=g(e).resolveInner(n,-1);r&&!(r.from<t);r=r.parent){let e=r.type.prop(gt);if(e==null)continue;let t=yt(r,e);if(t>n)return{from:n,to:t}}return null});function q(e){return new te(ht,e,[],`markdown`)}var xt=q(_t),J=q(_t.configure([ut,pt,ft,mt,{props:[ae.add({Table:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})})]}]));function St(e,t){return n=>{if(n&&e){let t=null;if(n=/\S*/.exec(n)[0],t=typeof e==`function`?e(n):m.matchLanguageName(e,n,!0),t instanceof m)return t.support?t.support.language.parser:re.getSkippingParser(t.load());if(t)return t.parser}return t?t.parser:null}}var Y=class{constructor(e,t,n,r,i,a,o){this.node=e,this.from=t,this.to=n,this.spaceBefore=r,this.spaceAfter=i,this.type=a,this.item=o}blank(e,t=!0){let n=this.spaceBefore+(this.node.name==`Blockquote`?`>`:``);if(e!=null){for(;n.length<e;)n+=` `;return n}else{for(let e=this.to-this.from-n.length-this.spaceAfter.length;e>0;e--)n+=` `;return n+(t?this.spaceAfter:``)}}marker(e,t){let n=this.node.name==`OrderedList`?String(+wt(this.item,e)[2]+t):``;return this.spaceBefore+n+this.type+this.spaceAfter}};function Ct(e,t){let n=[],r=[];for(let t=e;t;t=t.parent){if(t.name==`FencedCode`)return r;(t.name==`ListItem`||t.name==`Blockquote`)&&n.push(t)}for(let e=n.length-1;e>=0;e--){let i=n[e],a,o=t.lineAt(i.from),s=i.from-o.from;if(i.name==`Blockquote`&&(a=/^ *>( ?)/.exec(o.text.slice(s))))r.push(new Y(i,s,s+a[0].length,``,a[1],`>`,null));else if(i.name==`ListItem`&&i.parent.name==`OrderedList`&&(a=/^( *)\d+([.)])( *)/.exec(o.text.slice(s)))){let e=a[3],t=a[0].length;e.length>=4&&(e=e.slice(0,e.length-4),t-=4),r.push(new Y(i.parent,s,s+t,a[1],e,a[2],i))}else if(i.name==`ListItem`&&i.parent.name==`BulletList`&&(a=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(o.text.slice(s)))){let e=a[4],t=a[0].length;e.length>4&&(e=e.slice(0,e.length-4),t-=4);let n=a[2];a[3]&&(n+=a[3].replace(/[xX]/,` `)),r.push(new Y(i.parent,s,s+t,a[1],e,n,i))}}return r}function wt(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function X(e,t,n,r=0){for(let i=-1,a=e;;){if(a.name==`ListItem`){let e=wt(a,t),o=+e[2];if(i>=0){if(o!=i+1)return;n.push({from:a.from+e[1].length,to:a.from+e[0].length,insert:String(i+2+r)})}i=o}let e=a.nextSibling;if(!e)break;a=e}}function Z(e,t){let r=/^[ \t]*/.exec(e)[0].length;if(!r||t.facet(n)!=` `)return e;let i=y(e,4,r),a=``;for(let e=i;e>0;)e>=4?(a+=` `,e-=4):(a+=` `,e--);return a+e.slice(r)}var Tt=((e={})=>({state:t,dispatch:n})=>{let r=g(t),{doc:i}=t,a=null,o=t.changeByRange(n=>{if(!n.empty||!J.isActiveAt(t,n.from,-1)&&!J.isActiveAt(t,n.from,1))return a={range:n};let o=n.from,s=i.lineAt(o),c=Ct(r.resolveInner(o,-1),i);for(;c.length&&c[c.length-1].from>o-s.from;)c.pop();if(!c.length)return a={range:n};let l=c[c.length-1];if(l.to-l.spaceAfter.length>o-s.from)return a={range:n};let u=o>=l.to-l.spaceAfter.length&&!/\S/.test(s.text.slice(l.to));if(l.item&&u){let n=l.node.firstChild,r=l.node.getChild(`ListItem`,`ListItem`);if(n.to>=o||r&&r.to<o||s.from>0&&!/[^\s>]/.test(i.lineAt(s.from-1).text)||e.nonTightLists===!1){let e=c.length>1?c[c.length-2]:null,t,n=``;e&&e.item?(t=s.from+e.from,n=e.marker(i,1)):t=s.from+(e?e.to:0);let r=[{from:t,to:o,insert:n}];return l.node.name==`OrderedList`&&X(l.item,i,r,-2),e&&e.node.name==`OrderedList`&&X(e.item,i,r),{range:_.cursor(t+n.length),changes:r}}else{let e=Ot(c,t,s);return{range:_.cursor(o+e.length+1),changes:{from:s.from,insert:e+t.lineBreak}}}}if(l.node.name==`Blockquote`&&u&&s.from){let e=i.lineAt(s.from-1),r=/>\s*$/.exec(e.text);if(r&&r.index==l.from){let i=t.changes([{from:e.from+r.index,to:e.to},{from:s.from+l.from,to:s.to}]);return{range:n.map(i),changes:i}}}let d=[];l.node.name==`OrderedList`&&X(l.item,i,d);let f=l.item&&l.item.from<s.from,p=``;if(!f||/^[\s\d.)\-+*>]*/.exec(s.text)[0].length>=l.to)for(let e=0,t=c.length-1;e<=t;e++)p+=e==t&&!f?c[e].marker(i,1):c[e].blank(e<t?y(s.text,4,c[e+1].from)-p.length:null);let m=o;for(;m>s.from&&/\s/.test(s.text.charAt(m-s.from-1));)m--;return p=Z(p,t),Dt(l.node,t.doc)&&(p=Ot(c,t,s)+t.lineBreak+p),d.push({from:m,to:o,insert:t.lineBreak+p}),{range:_.cursor(m+p.length+1),changes:d}});return a?!1:(n(t.update(o,{scrollIntoView:!0,userEvent:`input`})),!0)})();function Et(e){return e.name==`QuoteMark`||e.name==`ListMark`}function Dt(e,t){if(e.name!=`OrderedList`&&e.name!=`BulletList`)return!1;let n=e.firstChild,r=e.getChild(`ListItem`,`ListItem`);if(!r)return!1;let i=t.lineAt(n.to),a=t.lineAt(r.from),o=/^[\s>]*$/.test(i.text);return i.number+ +!o<a.number}function Ot(e,t,n){let r=``;for(let t=0,i=e.length-2;t<=i;t++)r+=e[t].blank(t<i?y(n.text,4,e[t+1].from)-r.length:null,t<i);return Z(r,t)}function kt(e,t){let n=e.resolveInner(t,-1),r=t;Et(n)&&(r=n.from,n=n.parent);for(let e;e=n.childBefore(r);)if(Et(e))r=e.from;else if(e.name==`OrderedList`||e.name==`BulletList`)n=e.lastChild,r=n.to;else break;return n}var At=[{key:`Enter`,run:Tt},{key:`Backspace`,run:({state:e,dispatch:t})=>{let n=g(e),r=null,i=e.changeByRange(t=>{let i=t.from,{doc:a}=e;if(t.empty&&J.isActiveAt(e,t.from)){let t=a.lineAt(i),r=Ct(kt(n,i),a);if(r.length){let n=r[r.length-1],a=n.to-n.spaceAfter.length+ +!!n.spaceAfter;if(i-t.from>a&&!/\S/.test(t.text.slice(a,i-t.from)))return{range:_.cursor(t.from+a),changes:{from:t.from+a,to:i}};if(i-t.from==a&&(!n.item||t.from<=n.item.from||!/\S/.test(t.text.slice(0,n.to)))){let r=t.from+n.from;if(n.item&&n.node.from<n.item.from&&/\S/.test(t.text.slice(n.from,n.to))){let i=n.blank(y(t.text,4,n.to)-y(t.text,4,n.from));return r==t.from&&(i=Z(i,e)),{range:_.cursor(r+i.length),changes:{from:r,to:t.from+n.to,insert:i}}}if(r<i)return{range:_.cursor(r),changes:{from:r,to:i}}}}}return r={range:t}});return r?!1:(t(e.update(i,{scrollIntoView:!0,userEvent:`delete`})),!0)}}],Q=se({matchClosingTags:!1});function jt(e={}){let{codeLanguages:t,defaultCodeLanguage:n,addKeymap:r=!0,base:{parser:i}=xt,completeHTMLTags:a=!0,pasteURLAsLink:o=!0,htmlTagLanguage:s=Q}=e;if(!(i instanceof Ae))throw RangeError("Base parser provided to `markdown` should be a Markdown parser");let l=e.extensions?[e.extensions]:[],u=[s.support,bt],d;o&&u.push(Ft),n instanceof ne?(u.push(n.support),d=n.language):n&&(d=n);let f=t||d?St(t,d):void 0;l.push(qe({codeParser:f,htmlParser:s.language.parser})),r&&u.push(c.high(ie.of(At)));let p=q(i.configure(l));return a&&u.push(p.data.of({autocomplete:Mt})),new ne(p,u)}function Mt(e){let{state:t,pos:n}=e,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(n-25,n));if(!r)return null;let i=g(t).resolveInner(n,-1);for(;i&&!i.type.isTop;){if(i.name==`CodeBlock`||i.name==`FencedCode`||i.name==`ProcessingInstructionBlock`||i.name==`CommentBlock`||i.name==`Link`||i.name==`Image`)return null;i=i.parent}return{from:n-r[0].length,to:n,options:Nt(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}var $=null;function Nt(){if($)return $;let e=ce(new oe(d.create({extensions:Q}),0,!0));return $=e?e.options:[]}var Pt=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,Ft=i.domEventHandlers({paste:(e,t)=>{let{main:n}=t.state.selection;if(n.empty)return!1;let r=e.clipboardData?.getData(`text/plain`);if(!r||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(r)||(/^www\./.test(r)&&(r=`https://`+r),!J.isActiveAt(t.state,n.from,1)))return!1;let i=g(t.state),a=!1;return i.iterate({from:n.from,to:n.to,enter:e=>{(e.from>n.from||Pt.test(e.name))&&(a=!0)},leave:e=>{e.to<n.to&&(a=!0)}}),a?!1:(t.dispatch({changes:[{from:n.from,insert:`[`},{from:n.to,insert:`](${r})`}],userEvent:`input.paste`,scrollIntoView:!0}),!0)}});export{jt as markdown};