import{s as k}from"./vendor-micromark-util-chunked-DrRIdSP-.js";class _{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,e){const s=e??Number.POSITIVE_INFINITY;return s<this.left.length?this.left.slice(t,s):t>this.left.length?this.right.slice(this.right.length-s+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-s+this.left.length).reverse())}splice(t,e,s){const f=e||0;this.setCursor(Math.trunc(t));const i=this.right.splice(this.right.length-f,Number.POSITIVE_INFINITY);return s&&I(this.left,s),i.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),I(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),I(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const e=this.left.splice(t,Number.POSITIVE_INFINITY);I(this.right,e.reverse())}else{const e=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);I(this.left,e.reverse())}}}function I(g,t){let e=0;if(t.length<1e4)g.push(...t);else for(;e<t.length;)g.push(...t.slice(e,e+1e4)),e+=1e4}function E(g){const t={};let e=-1,s,f,i,r,u,l,c;const o=new _(g);for(;++e<o.length;){for(;e in t;)e=t[e];if(s=o.get(e),e&&s[1].type==="chunkFlow"&&o.get(e-1)[1].type==="listItemPrefix"&&(l=s[1]._tokenizer.events,i=0,i<l.length&&l[i][1].type==="lineEndingBlank"&&(i+=2),i<l.length&&l[i][1].type==="content"))for(;++i<l.length&&l[i][1].type!=="content";)l[i][1].type==="chunkText"&&(l[i][1]._isInFirstContentOfListItem=!0,i++);if(s[0]==="enter")s[1].contentType&&(Object.assign(t,y(o,e)),e=t[e],c=!0);else if(s[1]._container){for(i=e,f=void 0;i--;)if(r=o.get(i),r[1].type==="lineEnding"||r[1].type==="lineEndingBlank")r[0]==="enter"&&(f&&(o.get(f)[1].type="lineEndingBlank"),r[1].type="lineEnding",f=i);else if(!(r[1].type==="linePrefix"||r[1].type==="listItemIndent"))break;f&&(s[1].end={...o.get(f)[1].start},u=o.slice(f,e),u.unshift(s),o.splice(f,e-f+1,u))}}return k(g,0,Number.POSITIVE_INFINITY,o.slice(0)),!c}function y(g,t){const e=g.get(t)[1],s=g.get(t)[2];let f=t-1;const i=[];let r=e._tokenizer;r||(r=s.parser[e.contentType](e.start),e._contentTypeTextTrailing&&(r._contentTypeTextTrailing=!0));const u=r.events,l=[],c={};let o,d,h=-1,n=e,a=0,m=0;const p=[m];for(;n;){for(;g.get(++f)[1]!==n;);i.push(f),n._tokenizer||(o=s.sliceStream(n),n.next||o.push(null),d&&r.defineSkip(n.start),n._isInFirstContentOfListItem&&(r._gfmTasklistFirstContentOfListItem=!0),r.write(o),n._isInFirstContentOfListItem&&(r._gfmTasklistFirstContentOfListItem=void 0)),d=n,n=n.next}for(n=e;++h<u.length;)u[h][0]==="exit"&&u[h-1][0]==="enter"&&u[h][1].type===u[h-1][1].type&&u[h][1].start.line!==u[h][1].end.line&&(m=h+1,p.push(m),n._tokenizer=void 0,n.previous=void 0,n=n.next);for(r.events=[],n?(n._tokenizer=void 0,n.previous=void 0):p.pop(),h=p.length;h--;){const N=u.slice(p[h],p[h+1]),T=i.pop();l.push([T,T+N.length-1]),g.splice(T,2,N)}for(l.reverse(),h=-1;++h<l.length;)c[a+l[h][0]]=a+l[h][1],a+=l[h][1]-l[h][0]-1;return c}export{E as s};
