/* esm.sh - @codemirror/lang-markdown@6.5.2 */ import{EditorSelection as N,countColumn as U,Prec as zt,EditorState as Rt}from"./cm-state.mjs";import{EditorView as Tt,keymap as Dt}from"./cm-view.mjs";import{defineLanguageFacet as Ft,foldNodeProp as ut,indentNodeProp as Xt,languageDataProp as $t,foldService as Ut,syntaxTree as j,Language as jt,LanguageDescription as at,ParseContext as _t,indentUnit as qt,LanguageSupport as lt}from"./cm-language.mjs";import{CompletionContext as Qt}from"./cm-autocomplete.mjs";import{NodeType as J,NodeProp as D,NodeSet as Oe,Tree as x,Parser as bt,IterMode as Ce,parseMixed as wt}from"./lezer-common.mjs";import{styleTags as ze,tags as m,Tag as St}from"./lezer-highlight.mjs";var Q=class t{static create(e,r,n,s,i){let o=s+(s<<8)+e+(r<<4)|0;return new t(e,r,n,o,i,[],[])}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.blankFirstLine=!1,this.hashProp=[[D.contextHash,s]]}addChild(e,r){e.prop(D.contextHash)!=this.hash&&(e=new x(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(r)}toTree(e,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 x(e.types[this.type],this.children,this.positions,r-this.from).balance({makeTree:(s,i,o)=>new x(J.none,s,i,o,this.hashProp)})}},u;(function(t){t[t.Document=1]="Document",t[t.CodeBlock=2]="CodeBlock",t[t.FencedCode=3]="FencedCode",t[t.Blockquote=4]="Blockquote",t[t.HorizontalRule=5]="HorizontalRule",t[t.BulletList=6]="BulletList",t[t.OrderedList=7]="OrderedList",t[t.ListItem=8]="ListItem",t[t.ATXHeading1=9]="ATXHeading1",t[t.ATXHeading2=10]="ATXHeading2",t[t.ATXHeading3=11]="ATXHeading3",t[t.ATXHeading4=12]="ATXHeading4",t[t.ATXHeading5=13]="ATXHeading5",t[t.ATXHeading6=14]="ATXHeading6",t[t.SetextHeading1=15]="SetextHeading1",t[t.SetextHeading2=16]="SetextHeading2",t[t.HTMLBlock=17]="HTMLBlock",t[t.LinkReference=18]="LinkReference",t[t.Paragraph=19]="Paragraph",t[t.CommentBlock=20]="CommentBlock",t[t.ProcessingInstructionBlock=21]="ProcessingInstructionBlock",t[t.Escape=22]="Escape",t[t.Entity=23]="Entity",t[t.HardBreak=24]="HardBreak",t[t.Emphasis=25]="Emphasis",t[t.StrongEmphasis=26]="StrongEmphasis",t[t.Link=27]="Link",t[t.Image=28]="Image",t[t.InlineCode=29]="InlineCode",t[t.HTMLTag=30]="HTMLTag",t[t.Comment=31]="Comment",t[t.ProcessingInstruction=32]="ProcessingInstruction",t[t.Autolink=33]="Autolink",t[t.HeaderMark=34]="HeaderMark",t[t.QuoteMark=35]="QuoteMark",t[t.ListMark=36]="ListMark",t[t.LinkMark=37]="LinkMark",t[t.EmphasisMark=38]="EmphasisMark",t[t.CodeMark=39]="CodeMark",t[t.CodeText=40]="CodeText",t[t.CodeInfo=41]="CodeInfo",t[t.LinkTitle=42]="LinkTitle",t[t.LinkLabel=43]="LinkLabel",t[t.URL=44]="URL"})(u||(u={}));var te=class{constructor(e,r){this.start=e,this.content=r,this.marks=[],this.parsers=[]}},re=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 R(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,r=0,n=0){for(let s=r;s=e.stack[r.depth+1].value+r.baseIndent)return!0;if(r.indent>=r.baseIndent+4)return!1;let n=(t.type==u.OrderedList?ce:pe)(r,e,!1);return n>0&&(t.type!=u.BulletList||de(r,e,!1)<0)&&r.text.charCodeAt(r.pos+n-1)==t.value}var Re={[u.Blockquote](t,e,r){return r.next!=62?!1:(r.markers.push(g(u.QuoteMark,e.lineStart+r.pos,e.lineStart+r.pos+1)),r.moveBase(r.pos+(A(r.text.charCodeAt(r.pos+1))?2:1)),t.end=e.lineStart+r.text.length,!0)},[u.ListItem](t,e,r){return(r.next<0?t.blankFirstLine&&t.children.length==1:r.indentr&&A(t.charCodeAt(e-1));)e--;return e}function Te(t){if(t.next!=96&&t.next!=126)return-1;let e=t.pos+1;for(;e-1&&t.depth==e.stack.length&&e.parser.leafBlockParsers.indexOf(qe.SetextHeading)>-1||n<3?-1:1}function Fe(t,e){for(let r=t.stack.length-1;r>=0;r--)if(t.stack[r].type==e)return!0;return!1}function pe(t,e,r){return(t.next==45||t.next==43||t.next==42)&&(t.pos==t.text.length-1||A(t.text.charCodeAt(t.pos+1)))&&(!r||Fe(e,u.BulletList)||t.skipSpace(t.pos+2)=48&&s<=57;){n++;if(n==t.text.length)return-1;s=t.text.charCodeAt(n)}return n==t.pos||n>t.pos+9||s!=46&&s!=41||nt.pos+1||t.next!=49)?-1:n+1-t.pos}function Xe(t){if(t.next!=35)return-1;let e=t.pos+1;for(;e6?-1:r}function $e(t){if(t.next!=45&&t.next!=61||t.indent>=t.baseIndent+4)return-1;let e=t.pos+1;for(;e/,je=/\?>/,se=[[/^<(?:script|pre|style|textarea)(?:\s|>|$)/i,/<\/(?:script|pre|style|textarea)>/i],[/^\s*)/.exec(n);if(i)return t.append(g(u.Comment,r,r+1+i[0].length));let o=/^\?[^]*?\?>/.exec(n);if(o)return t.append(g(u.ProcessingInstruction,r,r+1+o[0].length));let a=/^(?:![A-Z][^]*?>|!\[CDATA\[[^]*?\]\]>|\/[a-zA-Z][\w-]*\s*>|[a-zA-Z][\w-]*(\s+[a-zA-Z:_][\w-.:]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*\/?>)/.exec(n);return a?t.append(g(u.HTMLTag,r,r+1+a[0].length)):-1},Emphasis(t,e,r){if(e!=95&&e!=42)return-1;let n=r+1;for(;t.char(n)==e;)n++;let s=t.slice(r-1,r),i=t.slice(n,n+1),o=X.test(s),a=X.test(i),l=/\s|^$/.test(s),h=/\s|^$/.test(i),f=!h&&(!a||l||o),p=!l&&(!o||h||a),d=f&&(e==42||!p||o),c=p&&(e==42||!f||a);return t.append(new C(e==95?me:ge,r,n,(d?1:0)|(c?2:0)))},HardBreak(t,e,r){if(e==92&&t.char(r+1)==10)return t.append(g(u.HardBreak,r,r+2));if(e==32){let n=r+1;for(;t.char(n)==32;)n++;if(t.char(n)==10&&n>=r+2)return t.append(g(u.HardBreak,r,n+1))}return-1},Link(t,e,r){return e==91?t.append(new C(H,r,r+1,1)):-1},Image(t,e,r){return e==33&&t.char(r+1)==91?t.append(new C(V,r,r+2,1)):-1},LinkEnd(t,e,r){if(e!=93)return-1;for(let n=t.parts.length-1;n>=0;n--){let s=t.parts[n];if(s instanceof C&&(s.type==H||s.type==V)){if(!s.side||t.skipSpace(s.to)==r&&!/[(\[]/.test(t.slice(r+1,r+2)))return t.parts[n]=null,-1;let i=t.takeContent(n),o=t.parts[n]=xt(t,i,s.type==H?u.Link:u.Image,s.from,r+1);if(s.type==H)for(let a=0;ae?g(u.URL,e+r,i+r):i==t.length?null:!1}}function Ve(t,e,r){let n=t.charCodeAt(e);if(n!=39&&n!=34&&n!=40)return!1;let s=n==40?41:n;for(let i=e+1,o=!1;i=this.end?-1:this.text.charCodeAt(e-this.offset)}get end(){return this.offset+this.text.length}slice(e,r){return this.text.slice(e-this.offset,r-this.offset)}append(e){return this.parts.push(e),e.to}addDelimiter(e,r,n,s,i){return this.append(new C(e,r,n,(s?1:0)|(i?2:0)))}get hasOpenLink(){for(let e=this.parts.length-1;e>=0;e--){let r=this.parts[e];if(r instanceof C&&(r.type==H||r.type==V))return!0}return!1}addElement(e){return this.append(e)}resolveMarkers(e){for(let n=e;n=e;l--){let k=this.parts[l];if(k instanceof C&&k.side&1&&k.type==s.type&&!(i&&(s.side&1||k.side&2)&&(k.size+s.size)%3==0&&(k.size%3||s.size%3))){a=k;break}}if(!a)continue;let h=s.type.resolve,f=[],p=a.from,d=s.to;if(i){let k=Math.min(2,a.to-a.from,o);p=a.to-k,d=s.from+k,h=k==1?"Emphasis":"StrongEmphasis"}a.type.mark&&f.push(this.elt(a.type.mark,p,a.to));for(let k=l+1;k=0;r--){let n=this.parts[r];if(n instanceof C&&n.type==e&&n.side&1)return r}return null}takeContent(e){let r=this.resolveMarkers(e);return this.parts.length=e,r}getDelimiterAt(e){let r=this.parts[e];return r instanceof C?r:null}skipSpace(e){return R(this.text,e-this.offset)+this.offset}elt(e,r,n,s){return typeof e=="string"?g(this.parser.getNodeType(e),r,n,s):new G(e,r)}};P.linkStart=H;P.imageStart=V;P.emphasisAsterisk=ge;P.emphasisUnderscore=me;function he(t,e){if(!e.length)return t;if(!t.length)return e;let r=t.slice(),n=0;for(let s of e){for(;n(e?e-1:0))return!1;if(this.fragmentEnd<0){let i=this.fragment.to;for(;i>0&&this.input.read(i-1,i)!=` `;)i--;this.fragmentEnd=i?i-1:0}let n=this.cursor;n||(n=this.cursor=this.fragment.tree.cursor(Ce.IncludeAnonymous|Ce.IgnoreMounts),n.firstChild());let s=e+this.fragment.offset;for(;n.to<=s;)if(!n.parent())return!1;for(;;){if(n.from>=s)return this.fragment.from<=r;if(!n.childAfter(s))return!1}}matches(e){let r=this.cursor.tree;for(;r&&r.type.isAnonymous&&r.children[0]instanceof x;)r=r.children[0];return r&&r.prop(D.contextHash)==e}takeNodes(e){let r=this.cursor,n=this.fragment.offset,s=this.fragmentEnd-(this.fragment.openEnd?1:0),i=e.absoluteLineStart,o=i,a=e.block.children.length,l=e.lineStart-e.block.from>>2,h=o,f=a;e:for(;;){if(r.to-n>Math.min(s,e.to)||r.type.isAnonymous&&r.tree&&(r.to-r.from>l||!It(r.tree))){if(r.type.isAnonymous&&r.firstChild())continue;break}let p=Ye(r.from-n,e.ranges);if(r.to-n<=e.ranges[e.rangeI].to)e.addNode(r.tree,p);else{let d=new x(e.parser.nodeSet.types[u.Paragraph],[],[],0,e.block.hashProp);e.reusePlaceholders.set(d,r.tree),e.addNode(d,p)}for((r.type.isAnonymous||r.type.is("Block"))&&(r.type.isAnonymous||Je.indexOf(r.type.id)<0?(o=r.to-n,a=e.block.children.length):(o=h,a=f),h=r.to-n,f=e.block.children.length);;){if(r.nextSibling())continue e;if(!r.parent()||!r.type.isAnonymous)break e}}for(;e.block.children.length>a;)e.block.children.pop(),e.block.positions.pop();return o-i}};function It(t){for(;t.type.isAnonymous;){let e=t.children[t.children.length-1];if(e instanceof x)t=e;else return!1}return t.type.is("Block")&&Je.indexOf(t.type.id)<0}function Ye(t,e){let r=t;for(let n=1;n_[t]),Object.keys(_).map(t=>qe[t]),Object.keys(_),Ct,Re,Object.keys(ee).map(t=>ee[t]),Object.keys(ee),[]);function Bt(t,e,r){let n=[];for(let s=t.firstChild,i=e;;s=s.nextSibling){let o=s?s.from:r;if(o>i&&n.push({from:i,to:o}),!s)break;i=s.to}return n}function et(t){let{codeParser:e,htmlParser:r}=t;return{wrap:wt((s,i)=>{let o=s.type.id;if(e&&(o==u.CodeBlock||o==u.FencedCode)){let a="";if(o==u.FencedCode){let h=s.node.getChild(u.CodeInfo);h&&(a=i.read(h.from,h.to))}let l=e(a);if(l)return{parser:l,overlay:h=>h.type.id==u.CodeText,bracketed:o==u.FencedCode}}else if(r&&(o==u.HTMLBlock||o==u.HTMLTag||o==u.CommentBlock))return{parser:r,overlay:Bt(s.node,s.from,s.to)};return null})}}var Mt={resolve:"Strikethrough",mark:"StrikethroughMark"},Ht={defineNodes:[{name:"Strikethrough",style:{"Strikethrough/...":m.strikethrough}},{name:"StrikethroughMark",style:m.processingInstruction}],parseInline:[{name:"Strikethrough",parse(t,e,r){if(e!=126||t.char(r+1)!=126||t.char(r+2)==126)return-1;let n=t.slice(r-1,r),s=t.slice(r+2,r+3),i=/\s|^$/.test(n),o=/\s|^$/.test(s),a=X.test(n),l=X.test(s);return t.addDelimiter(Mt,r,r+2,!o&&(!l||i||a),!i&&(!a||o||l))},after:"Emphasis"}]};function T(t,e,r=0,n,s=0){let i=0,o=!0,a=-1,l=-1,h=!1,f=()=>{n.push(t.elt("TableCell",s+a,s+l,t.parser.parseInline(e.slice(a,l),s+a)))};for(let p=r;p-1)&&i++,o=!1,n&&(a>-1&&f(),n.push(t.elt("TableDelimiter",p+s,p+s+1))),a=l=-1):(h||d!=32&&d!=9)&&(a<0&&(a=p),l=p+1),h=!h&&d==92}return a>-1&&(i++,n&&f()),i}function Be(t,e){for(let r=e;r\s]*\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/,K=class{constructor(){this.rows=null}nextLine(e,r,n){if(this.rows==null){this.rows=!1;let s;if((r.next==45||r.next==58||r.next==124)&&tt.test(s=r.text.slice(r.pos))){let i=[];T(e,n.content,0,i,n.start)==T(e,s,0)&&(this.rows=[e.elt("TableHeader",n.start,n.start+n.content.length,i),e.elt("TableDelimiter",e.lineStart+r.pos,e.lineStart+r.text.length)])}}else if(this.rows){let s=[];T(e,r.text,r.pos,s,e.lineStart),this.rows.push(e.elt("TableRow",e.lineStart+r.pos,e.lineStart+r.text.length,s))}return!1}finish(e,r){return this.rows?(e.addLeafElement(r,e.elt("Table",r.start,r.start+r.content.length,this.rows)),!0):!1}},vt={defineNodes:[{name:"Table",block:!0},{name:"TableHeader",style:{"TableHeader/...":m.heading}},"TableRow",{name:"TableCell",style:m.content},{name:"TableDelimiter",style:m.processingInstruction}],parseBlock:[{name:"Table",leaf(t,e){return Be(e.content,0)?new K:null},endLeaf(t,e,r){if(r.parsers.some(s=>s instanceof K)||!Be(e.text,e.basePos))return!1;let n=t.peekLine();return tt.test(n)&&T(t,e.text,e.basePos)==T(t,n,e.basePos)},before:"SetextHeading"}]},ue=class{nextLine(){return!1}finish(e,r){return e.addLeafElement(r,e.elt("Task",r.start,r.start+r.content.length,[e.elt("TaskMarker",r.start,r.start+3),...e.parser.parseInline(r.content.slice(3),r.start+3)])),!0}},Pt={defineNodes:[{name:"Task",block:!0,style:m.list},{name:"TaskMarker",style:m.atom}],parseBlock:[{name:"TaskList",leaf(t,e){return/^\[[ xX]\][ \t]/.test(e.content)&&t.parentType().name=="ListItem"?new ue:null},after:"SetextHeading"}]},Me=/(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy,He=/[\w-]+(\.[\w-]+)+(:\d+)?(\/[^\s<]*)?/gy,yt=/[\w-]+\.[\w-]+($|[/:])/,ve=/[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy,Pe=/\/[a-zA-Z\d@.]+/gy;function ye(t,e,r,n){let s=0;for(let i=e;i-1)return-1;let n=e+r[0].length;for(;;){let s=t[n-1],i;if(/[?!.,:*_~]/.test(s)||s==")"&&ye(t,e,n,")")>ye(t,e,n,"("))n--;else if(s==";"&&(i=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(t.slice(e,n))))n=e+i.index;else break}return n}function Ne(t,e){ve.lastIndex=e;let r=ve.exec(t);if(!r)return-1;let n=r[0][r[0].length-1];return n=="_"||n=="-"?-1:e+r[0].length-(n=="."?1:0)}var Ot={parseInline:[{name:"Autolink",parse(t,e,r){let n=r-t.offset;if(n&&/\w/.test(t.text[n-1]))return-1;Me.lastIndex=n;let s=Me.exec(t.text),i=-1;if(!s)return-1;if(s[1]||s[2]){if(i=Nt(t.text,n+s[0].length),i>-1&&t.hasOpenLink){let o=/([^\[\]]|\[[^\]]*\])*/.exec(t.text.slice(n,i));i=n+o[0].length}}else s[3]?i=Ne(t.text,n):(i=Ne(t.text,n+s[0].length),i>-1&&s[0]=="xmpp:"&&(Pe.lastIndex=i,s=Pe.exec(t.text),s&&(i=s.index+s[0].length)));return i<0?-1:(t.addElement(t.elt("URL",r,i+t.offset)),i+t.offset)}}]},rt=[vt,Pt,Ht,Ot];function nt(t,e,r){return(n,s,i)=>{if(s!=t||n.char(i+1)==t)return-1;let o=[n.elt(r,i,i+1)];for(let a=i+1;a"}}}),pt=new Vt,ct=We.configure({props:[ut.add(t=>!t.is("Block")||t.is("Document")||be(t)!=null||Kt(t)?void 0:(e,r)=>({from:r.doc.lineAt(e.from).to,to:e.to})),pt.add(be),Xt.add({Document:()=>null}),$t.add({Document:dt})]});function be(t){let e=/^(?:ATX|Setext)Heading(\d)$/.exec(t.name);return e?+e[1]:void 0}function Kt(t){return t.name=="OrderedList"||t.name=="BulletList"}function Jt(t,e){let r=t;for(;;){let n=r.nextSibling,s;if(!n||(s=be(n.type))!=null&&s<=e)break;r=n}return r.to}var Yt=Ut.of((t,e,r)=>{for(let n=j(t).resolveInner(r,-1);n&&!(n.fromr)return{from:r,to:i}}return null});function we(t){return new jt(dt,t,[],"markdown")}var Wt=we(ct),er=ct.configure([rt,it,st,ot,{props:[ut.add({Table:(t,e)=>({from:e.doc.lineAt(t.from).to,to:t.to})})]}]),Y=we(er);function tr(t,e){return r=>{if(r&&t){let n=null;if(r=/\S*/.exec(r)[0],typeof t=="function"?n=t(r):n=at.matchLanguageName(t,r,!0),n instanceof at)return n.support?n.support.language.parser:_t.getSkippingParser(n.load());if(n)return n.parser}return e?e.parser:null}}var $=class{constructor(e,r,n,s,i,o,a){this.node=e,this.from=r,this.to=n,this.spaceBefore=s,this.spaceAfter=i,this.type=o,this.item=a}blank(e,r=!0){let n=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(e!=null){for(;n.length0;s--)n+=" ";return n+(r?this.spaceAfter:"")}}marker(e,r){let n=this.node.name=="OrderedList"?String(+gt(this.item,e)[2]+r):"";return this.spaceBefore+n+this.type+this.spaceAfter}};function mt(t,e){let r=[],n=[];for(let s=t;s;s=s.parent){if(s.name=="FencedCode")return n;(s.name=="ListItem"||s.name=="Blockquote")&&r.push(s)}for(let s=r.length-1;s>=0;s--){let i=r[s],o,a=e.lineAt(i.from),l=i.from-a.from;if(i.name=="Blockquote"&&(o=/^ *>( ?)/.exec(a.text.slice(l))))n.push(new $(i,l,l+o[0].length,"",o[1],">",null));else if(i.name=="ListItem"&&i.parent.name=="OrderedList"&&(o=/^( *)\d+([.)])( *)/.exec(a.text.slice(l)))){let h=o[3],f=o[0].length;h.length>=4&&(h=h.slice(0,h.length-4),f-=4),n.push(new $(i.parent,l,l+f,o[1],h,o[2],i))}else if(i.name=="ListItem"&&i.parent.name=="BulletList"&&(o=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(a.text.slice(l)))){let h=o[4],f=o[0].length;h.length>4&&(h=h.slice(0,h.length-4),f-=4);let p=o[2];o[3]&&(p+=o[3].replace(/[xX]/," ")),n.push(new $(i.parent,l,l+f,o[1],h,p,i))}}return n}function gt(t,e){return/^(\s*)(\d+)(?=[.)])/.exec(e.sliceString(t.from,t.from+10))}function ke(t,e,r,n=0){for(let s=-1,i=t;;){if(i.name=="ListItem"){let a=gt(i,e),l=+a[2];if(s>=0){if(l!=s+1)return;r.push({from:i.from+a[1].length,to:i.from+a[0].length,insert:String(s+2+n)})}s=l}let o=i.nextSibling;if(!o)break;i=o}}function Se(t,e){let r=/^[ \t]*/.exec(t)[0].length;if(!r||e.facet(qt)!=" ")return t;let n=U(t,4,r),s="";for(let i=n;i>0;)i>=4?(s+=" ",i-=4):(s+=" ",i--);return s+t.slice(r)}var rr=(t={})=>({state:e,dispatch:r})=>{let n=j(e),{doc:s}=e,i=null,o=e.changeByRange(a=>{if(!a.empty||!Y.isActiveAt(e,a.from,-1)&&!Y.isActiveAt(e,a.from,1))return i={range:a};let l=a.from,h=s.lineAt(l),f=mt(n.resolveInner(l,-1),s);for(;f.length&&f[f.length-1].from>l-h.from;)f.pop();if(!f.length)return i={range:a};let p=f[f.length-1];if(p.to-p.spaceAfter.length>l-h.from)return i={range:a};let d=l>=p.to-p.spaceAfter.length&&!/\S/.test(h.text.slice(p.to));if(p.item&&d){if(p.item.from]*$/.test(h.text.slice(0,p.to)))return i={range:a};let w=p.node.firstChild,S=p.node.getChild("ListItem","ListItem");if(w.to>=l||S&&S.to0&&!/[^\s>]/.test(s.lineAt(h.from-1).text)||t.nonTightLists===!1){let b=f.length>1?f[f.length-2]:null,B,M="";b&&b.item?(B=h.from+b.from,M=b.marker(s,1)):B=h.from+(b?b.to:0);let O=[{from:B,to:l,insert:M}];return p.node.name=="OrderedList"&&ke(p.item,s,O,-2),b&&b.node.name=="OrderedList"&&ke(b.item,s,O),{range:N.cursor(B+M.length),changes:O}}else{let b=ft(f,e,h);return{range:N.cursor(l+b.length+1),changes:{from:h.from,insert:b+e.lineBreak}}}}if(p.node.name=="Blockquote"&&d&&h.from){let w=s.lineAt(h.from-1),S=/>\s*$/.exec(w.text);if(S&&S.index==p.from){let b=e.changes([{from:w.from+S.index,to:w.to},{from:h.from+p.from,to:h.to}]);return{range:a.map(b),changes:b}}}let c=[];p.node.name=="OrderedList"&&ke(p.item,s,c);let L=p.item&&p.item.from]*/.exec(h.text)[0].length>=p.to)for(let w=0,S=f.length-1;w<=S;w++)k+=w==S&&!L?f[w].marker(s,1):f[w].blank(wh.from&&/\s/.test(h.text.charAt(E-h.from-1));)E--;return k=Se(k,e),sr(p.node,e.doc)&&(k=ft(f,e,h)+e.lineBreak+k),c.push({from:E,to:l,insert:e.lineBreak+k}),{range:N.cursor(E+k.length+1),changes:c}});return i?!1:(r(e.update(o,{scrollIntoView:!0,userEvent:"input"})),!0)},nr=rr();function ht(t){return t.name=="QuoteMark"||t.name=="ListMark"}function sr(t,e){if(t.name!="OrderedList"&&t.name!="BulletList")return!1;let r=t.firstChild,n=t.getChild("ListItem","ListItem");if(!n)return!1;let s=e.lineAt(r.to),i=e.lineAt(n.from),o=/^[\s>]*$/.test(s.text);return s.number+(o?0:1){let r=j(t),n=null,s=t.changeByRange(i=>{let o=i.from,{doc:a}=t;if(i.empty&&Y.isActiveAt(t,i.from)){let l=a.lineAt(o),h=mt(ir(r,o),a);if(h.length){let f=h[h.length-1],p=f.to-f.spaceAfter.length+(f.spaceAfter?1:0);if(o-l.from>p&&!/\S/.test(l.text.slice(p,o-l.from)))return{range:N.cursor(l.from+p),changes:{from:l.from+p,to:o}};if(o-l.from==p&&(f.item&&l.from<=f.item.from||/^[\s>]*$/.test(l.text.slice(0,f.to)))){let d=l.from+f.from;if(f.item&&f.node.from{var r;let{main:n}=e.state.selection;if(n.empty)return!1;let s=(r=t.clipboardData)===null||r===void 0?void 0:r.getData("text/plain");if(!s||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(s)||(/^www\./.test(s)&&(s="https://"+s),!Y.isActiveAt(e.state,n.from,1)))return!1;let i=j(e.state),o=!1;return i.iterate({from:n.from,to:n.to,enter:a=>{(a.from>n.from||fr.test(a.name))&&(o=!0)},leave:a=>{a.to