import{E as x,h as w,P as z,l as G}from"./cm-state-X9WpHEQO.js";import{E as K,k as _}from"./cm-view-CiSFjroV.js";import{p as j,o as Q,s as A,q as J,c as N,i as Y,f as F,d as Z,r as W,t as D,P as ee}from"./cm-language-CDsY7zq0.js";import{C as te}from"./cm-autocomplete-t9rzw_D0.js";import{M as re,p as ne,a as oe,G as ie,S as le,b as se,E as ae}from"./vendor-lezer-markdown-DG8DLr3V.js";import{html as fe,htmlCompletionSource as me}from"./cm-lang-html-BwlfE-a6.js";import{N as ue}from"./vendor-lezer-common-tVQBIsvN.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-style-mod-Bs6eFhZE.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-DuEf3ZFH.js";import"./vendor-lezer-html-D-6QB8dd.js";import"./vendor-lezer-lr-eZ5kYecM.js";import"./cm-lang-css-NVaY7c0M.js";import"./vendor-lezer-css-BMlSRxbI.js";import"./cm-lang-javascript-E0JyLAes.js";import"./vendor-lezer-javascript-BsA5KTFy.js";const R=Q({commentTokens:{block:{open:""}}}),$=new ue,H=oe.configure({props:[F.add(r=>!r.is("Block")||r.is("Document")||P(r)!=null||ce(r)?void 0:(n,o)=>({from:o.doc.lineAt(n.from).to,to:n.to})),$.add(P),Z.add({Document:()=>null}),W.add({Document:R})]});function P(r){let n=/^(?:ATX|Setext)Heading(\d)$/.exec(r.name);return n?+n[1]:void 0}function ce(r){return r.name=="OrderedList"||r.name=="BulletList"}function pe(r,n){let o=r;for(;;){let t=o.nextSibling,e;if(!t||(e=P(t.type))!=null&&e<=n)break;o=t}return o.to}const de=J.of((r,n,o)=>{for(let t=A(r).resolveInner(o,-1);t&&!(t.fromo)return{from:o,to:i}}return null});function E(r){return new j(R,r,[],"markdown")}const he=E(H),ge=H.configure([ie,le,se,ae,{props:[F.add({Table:(r,n)=>({from:n.doc.lineAt(r.from).to,to:r.to})})]}]),b=E(ge);function ke(r,n){return o=>{if(o&&r){let t=null;if(o=/\S*/.exec(o)[0],typeof r=="function"?t=r(o):t=D.matchLanguageName(r,o,!0),t instanceof D)return t.support?t.support.language.parser:ee.getSkippingParser(t.load());if(t)return t.parser}return n?n.parser:null}}class v{constructor(n,o,t,e,i,f,m){this.node=n,this.from=o,this.to=t,this.spaceBefore=e,this.spaceAfter=i,this.type=f,this.item=m}blank(n,o=!0){let t=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(n!=null){for(;t.length0;e--)t+=" ";return t+(o?this.spaceAfter:"")}}marker(n,o){let t=this.node.name=="OrderedList"?String(+V(this.item,n)[2]+o):"";return this.spaceBefore+t+this.type+this.spaceAfter}}function U(r,n){let o=[],t=[];for(let e=r;e;e=e.parent){if(e.name=="FencedCode")return t;(e.name=="ListItem"||e.name=="Blockquote")&&o.push(e)}for(let e=o.length-1;e>=0;e--){let i=o[e],f,m=n.lineAt(i.from),s=i.from-m.from;if(i.name=="Blockquote"&&(f=/^ *>( ?)/.exec(m.text.slice(s))))t.push(new v(i,s,s+f[0].length,"",f[1],">",null));else if(i.name=="ListItem"&&i.parent.name=="OrderedList"&&(f=/^( *)\d+([.)])( *)/.exec(m.text.slice(s)))){let a=f[3],l=f[0].length;a.length>=4&&(a=a.slice(0,a.length-4),l-=4),t.push(new v(i.parent,s,s+l,f[1],a,f[2],i))}else if(i.name=="ListItem"&&i.parent.name=="BulletList"&&(f=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(m.text.slice(s)))){let a=f[4],l=f[0].length;a.length>4&&(a=a.slice(0,a.length-4),l-=4);let u=f[2];f[3]&&(u+=f[3].replace(/[xX]/," ")),t.push(new v(i.parent,s,s+l,f[1],a,u,i))}}return t}function V(r,n){return/^(\s*)(\d+)(?=[.)])/.exec(n.sliceString(r.from,r.from+10))}function I(r,n,o,t=0){for(let e=-1,i=r;;){if(i.name=="ListItem"){let m=V(i,n),s=+m[2];if(e>=0){if(s!=e+1)return;o.push({from:i.from+m[1].length,to:i.from+m[0].length,insert:String(e+2+t)})}e=s}let f=i.nextSibling;if(!f)break;i=f}}function T(r,n){let o=/^[ \t]*/.exec(r)[0].length;if(!o||n.facet(Y)!=" ")return r;let t=w(r,4,o),e="";for(let i=t;i>0;)i>=4?(e+=" ",i-=4):(e+=" ",i--);return e+r.slice(o)}const xe=(r={})=>({state:n,dispatch:o})=>{let t=A(n),{doc:e}=n,i=null,f=n.changeByRange(m=>{if(!m.empty||!b.isActiveAt(n,m.from,-1)&&!b.isActiveAt(n,m.from,1))return i={range:m};let s=m.from,a=e.lineAt(s),l=U(t.resolveInner(s,-1),e);for(;l.length&&l[l.length-1].from>s-a.from;)l.pop();if(!l.length)return i={range:m};let u=l[l.length-1];if(u.to-u.spaceAfter.length>s-a.from)return i={range:m};let d=s>=u.to-u.spaceAfter.length&&!/\S/.test(a.text.slice(u.to));if(u.item&&d){let p=u.node.firstChild,h=u.node.getChild("ListItem","ListItem");if(p.to>=s||h&&h.to0&&!/[^\s>]/.test(e.lineAt(a.from-1).text)||r.nonTightLists===!1){let c=l.length>1?l[l.length-2]:null,C,B="";c&&c.item?(C=a.from+c.from,B=c.marker(e,1)):C=a.from+(c?c.to:0);let S=[{from:C,to:s,insert:B}];return u.node.name=="OrderedList"&&I(u.item,e,S,-2),c&&c.node.name=="OrderedList"&&I(c.item,e,S),{range:x.cursor(C+B.length),changes:S}}else{let c=q(l,n,a);return{range:x.cursor(s+c.length+1),changes:{from:a.from,insert:c+n.lineBreak}}}}if(u.node.name=="Blockquote"&&d&&a.from){let p=e.lineAt(a.from-1),h=/>\s*$/.exec(p.text);if(h&&h.index==u.from){let c=n.changes([{from:p.from+h.index,to:p.to},{from:a.from+u.from,to:a.to}]);return{range:m.map(c),changes:c}}}let g=[];u.node.name=="OrderedList"&&I(u.item,e,g);let M=u.item&&u.item.from]*/.exec(a.text)[0].length>=u.to)for(let p=0,h=l.length-1;p<=h;p++)k+=p==h&&!M?l[p].marker(e,1):l[p].blank(pa.from&&/\s/.test(a.text.charAt(L-a.from-1));)L--;return k=T(k,n),we(u.node,n.doc)&&(k=q(l,n,a)+n.lineBreak+k),g.push({from:L,to:s,insert:n.lineBreak+k}),{range:x.cursor(L+k.length+1),changes:g}});return i?!1:(o(n.update(f,{scrollIntoView:!0,userEvent:"input"})),!0)},Le=xe();function O(r){return r.name=="QuoteMark"||r.name=="ListMark"}function we(r,n){if(r.name!="OrderedList"&&r.name!="BulletList")return!1;let o=r.firstChild,t=r.getChild("ListItem","ListItem");if(!t)return!1;let e=n.lineAt(o.to),i=n.lineAt(t.from),f=/^[\s>]*$/.test(e.text);return e.number+(f?0:1){let o=A(r),t=null,e=r.changeByRange(i=>{let f=i.from,{doc:m}=r;if(i.empty&&b.isActiveAt(r,i.from)){let s=m.lineAt(f),a=U(Ae(o,f),m);if(a.length){let l=a[a.length-1],u=l.to-l.spaceAfter.length+(l.spaceAfter?1:0);if(f-s.from>u&&!/\S/.test(s.text.slice(u,f-s.from)))return{range:x.cursor(s.from+u),changes:{from:s.from+u,to:f}};if(f-s.from==u&&(!l.item||s.from<=l.item.from||!/\S/.test(s.text.slice(0,l.to)))){let d=s.from+l.from;if(l.item&&l.node.from{var o;let{main:t}=n.state.selection;if(t.empty)return!1;let e=(o=r.clipboardData)===null||o===void 0?void 0:o.getData("text/plain");if(!e||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(e)||(/^www\./.test(e)&&(e="https://"+e),!b.isActiveAt(n.state,t.from,1)))return!1;let i=A(n.state),f=!1;return i.iterate({from:t.from,to:t.to,enter:m=>{(m.from>t.from||ve.test(m.name))&&(f=!0)},leave:m=>{m.to