import{s as t}from"./micromark-util-chunked-3k3e5hER.js";class e{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 i=null==e?Number.POSITIVE_INFINITY:e;return i<this.left.length?this.left.slice(t,i):t>this.left.length?this.right.slice(this.right.length-i+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-i+this.left.length).reverse())}splice(t,e,s){const n=e||0;this.setCursor(Math.trunc(t));const h=this.right.splice(this.right.length-n,Number.POSITIVE_INFINITY);return s&&i(this.left,s),h.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&&0===this.right.length||t<0&&0===this.left.length))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(t,e){let i=0;if(e.length<1e4)t.push(...e);else for(;i<e.length;)t.push(...e.slice(i,i+1e4)),i+=1e4}function s(i){const s={};let h,r,l,g,o,f,c,p=-1;const u=new e(i);for(;++p<u.length;){for(;p in s;)p=s[p];if(h=u.get(p),p&&"chunkFlow"===h[1].type&&"listItemPrefix"===u.get(p-1)[1].type&&(f=h[1]._tokenizer.events,l=0,l<f.length&&"lineEndingBlank"===f[l][1].type&&(l+=2),l<f.length&&"content"===f[l][1].type))for(;++l<f.length&&"content"!==f[l][1].type;)"chunkText"===f[l][1].type&&(f[l][1]._isInFirstContentOfListItem=!0,l++);if("enter"===h[0])h[1].contentType&&(Object.assign(s,n(u,p)),p=s[p],c=!0);else if(h[1]._container){for(l=p,r=void 0;l--;)if(g=u.get(l),"lineEnding"===g[1].type||"lineEndingBlank"===g[1].type)"enter"===g[0]&&(r&&(u.get(r)[1].type="lineEndingBlank"),g[1].type="lineEnding",r=l);else if("linePrefix"!==g[1].type&&"listItemIndent"!==g[1].type)break;r&&(h[1].end={...u.get(r)[1].start},o=u.slice(r,p),o.unshift(h),u.splice(r,p-r+1,o))}}return t(i,0,Number.POSITIVE_INFINITY,u.slice(0)),!c}function n(t,e){const i=t.get(e)[1],s=t.get(e)[2];let n=e-1;const h=[];let r=i._tokenizer;r||(r=s.parser[i.contentType](i.start),i._contentTypeTextTrailing&&(r._contentTypeTextTrailing=!0));const l=r.events,g=[],o={};let f,c,p=-1,u=i,I=0,a=0;const T=[a];for(;u;){for(;t.get(++n)[1]!==u;);h.push(n),u._tokenizer||(f=s.sliceStream(u),u.next||f.push(null),c&&r.defineSkip(u.start),u._isInFirstContentOfListItem&&(r._gfmTasklistFirstContentOfListItem=!0),r.write(f),u._isInFirstContentOfListItem&&(r._gfmTasklistFirstContentOfListItem=void 0)),c=u,u=u.next}for(u=i;++p<l.length;)"exit"===l[p][0]&&"enter"===l[p-1][0]&&l[p][1].type===l[p-1][1].type&&l[p][1].start.line!==l[p][1].end.line&&(a=p+1,T.push(a),u._tokenizer=void 0,u.previous=void 0,u=u.next);for(r.events=[],u?(u._tokenizer=void 0,u.previous=void 0):T.pop(),p=T.length;p--;){const e=l.slice(T[p],T[p+1]),i=h.pop();g.push([i,i+e.length-1]),t.splice(i,2,e)}for(g.reverse(),p=-1;++p<g.length;)o[I+g[p][0]]=I+g[p][1],I+=g[p][1]-g[p][0]-1;return o}export{s};
