const e=require(`./paths-Bcdg3ma0.cjs`),t=require(`./paths-a2-BgYPx.cjs`),n=require(`./sessions-Bc5xPyOc.cjs`),r=require(`./logger-ElHF9OXJ.cjs`),i=require(`./local-roots-BJwbkkZr.cjs`);let a=require(`node:path`);a=e.p(a);let o=require(`node:fs/promises`);o=e.p(o);let s=require(`node:url`),c=require(`markdown-it`);c=e.p(c);function l(e){let t=[],n,r=0;for(;r<=e.length;){let i=e.indexOf(`
`,r),a=i===-1?e.length:i,o=e.slice(r,a),s=o.match(/^( {0,3})(`{3,}|~{3,})(.*)$/);if(s){let e=s[1],i=s[2],c=i[0],l=i.length;if(!n)n={start:r,markerChar:c,markerLen:l,openLine:o,marker:i,indent:e};else if(n.markerChar===c&&l>=n.markerLen){let e=a;t.push({start:n.start,end:e,openLine:n.openLine,marker:n.marker,indent:n.indent}),n=void 0}}if(i===-1)break;r=i+1}return n&&t.push({start:n.start,end:e.length,openLine:n.openLine,marker:n.marker,indent:n.indent}),t}function u(e,t){let n=0,r=e.length-1;for(;n<=r;){let i=Math.floor((n+r)/2),a=e[i];if(!a)break;if(t<=a.start){r=i-1;continue}if(t>=a.end){n=i+1;continue}return a}}function d(e,t){return!u(e,t)}function f(e,t,n){if(!e)return[];if(t<=0||e.length<=t)return[e];let r=[],i=e;for(;i.length>t;){let e=n(i.slice(0,t)),a=Number.isFinite(e)&&e>0&&e<=t?e:t,o=i.slice(0,a).trimEnd();o.length>0&&r.push(o);let s=a<i.length&&/\s/.test(i[a]),c=Math.min(i.length,a+(s?1:0));i=i.slice(c).trimStart()}return i.length&&r.push(i),r}const p=`length`;function m(e,r){if(!e)return;let i=t.zt(r),a=e.accounts;if(a&&typeof a==`object`){let e=n.Us(a,i);if(typeof e?.textChunkLimit==`number`)return e.textChunkLimit}return e.textChunkLimit}function h(e,t,n,r){let i=typeof r?.fallbackLimit==`number`&&r.fallbackLimit>0?r.fallbackLimit:4e3,a=(()=>{if(!(!t||t===`webchat`))return m(e?.channels?.[t]??e?.[t],n)})();return typeof a==`number`&&a>0?a:i}function g(e,r){if(!e)return;let i=t.zt(r),a=e.accounts;if(a&&typeof a==`object`){let e=n.Us(a,i);if(e?.chunkMode)return e.chunkMode}return e.chunkMode}function _(e,t,n){return!t||t===`webchat`?p:g(e?.channels?.[t]??e?.[t],n)??p}function v(e,t,n){if(!e)return[];if(t<=0)return e.trim()?[e]:[];let r=n?.splitLongLines!==!1,i=n?.trimLines!==!1,a=te(e,n?.isSafeBreak),o=[],s=0;for(let e of a){let n=e.trim();if(!n){s+=1;continue}let a=Math.max(0,t-1),c=s>0?Math.min(s,a):0,l=c>0?`
`.repeat(c):``;s=0;let u=i?n:e;if(!r||u.length+l.length<=t){o.push(l+u);continue}let d=Math.max(1,t-l.length),f=u.slice(0,d);o.push(l+f);let p=u.slice(d);p&&o.push(...S(p,t))}return s>0&&o.length>0&&(o[o.length-1]+=`
`.repeat(s)),o}function y(e,t,n){if(!e)return[];if(t<=0)return[e];let r=n?.splitLongParagraphs!==!1,i=e.replace(/\r\n?/g,`
`);if(!/\n[\t ]*\n+/.test(i))return i.length<=t||!r?[i]:S(i,t);let a=l(i),o=[],s=/\n[\t ]*\n+/g,c=0;for(let e of i.matchAll(s)){let t=e.index??0;d(a,t)&&(o.push(i.slice(c,t)),c=t+e[0].length)}o.push(i.slice(c));let u=[];for(let e of o){let n=e.replace(/\s+$/g,``);n.trim()&&(n.length<=t?u.push(n):r?u.push(...S(n,t)):u.push(n))}return u}function b(e,t,n){return n===`newline`?y(e,t):S(e,t)}function ee(e,t,n){if(n===`newline`){let n=y(e,t,{splitLongParagraphs:!1}),r=[];for(let e of n){let n=C(e,t);!n.length&&e?r.push(e):r.push(...n)}return r}return C(e,t)}function te(e,t=()=>!0){let n=[],r=0;for(let i=0;i<e.length;i++)e[i]===`
`&&t(i)&&(n.push(e.slice(r,i)),r=i+1);return n.push(e.slice(r)),n}function x(e,t){if(!e)return[];if(t<=0||e.length<=t)return[e]}function S(e,t){return x(e,t)||f(e,t,e=>{let{lastNewline:t,lastWhitespace:n}=w(e,0,e.length);return t>0?t:n})}function C(e,t){let n=x(e,t);if(n)return n;let r=[],i=l(e),a=0,o;for(;a<e.length;){let n=o?`${o.openLine}\n`:``,s=Math.max(1,t-n.length);if(e.length-a<=s){let t=`${n}${e.slice(a)}`;t.length>0&&r.push(t);break}let c=Math.min(e.length,a+s),l=re(e,a,c,i),f=l>a?l:c,p=d(i,f)?void 0:u(i,f),m=p;if(p){let t=`${p.indent}${p.marker}`,n=a+(s-(t.length+1));if(n<=a)m=void 0,f=c;else{let r=Math.min(e.length,Math.max(a+1,p.start+p.openLine.length+2)),o=a+(s-t.length),l=!1,d=e.lastIndexOf(`
`,Math.max(a,o-1));for(;d>=a;){let t=d+1;if(t<r)break;let n=u(i,t);if(n&&n.start===p.start){f=t,l=!0;break}d=e.lastIndexOf(`
`,d-1)}l||(r>o?(m=void 0,f=c):f=Math.max(r,n))}let r=u(i,f);m=r&&r.start===p.start?r:void 0}let h=e.slice(a,f);if(!h)break;let g=`${n}${h}`,_=f<e.length&&/\s/.test(e[f]),v=Math.min(e.length,f+(_?1:0));if(m){let e=`${m.indent}${m.marker}`;g=g.endsWith(`
`)?`${g}${e}`:`${g}\n${e}`,o=m}else v=ne(e,v),o=void 0;r.push(g),a=v}return r}function ne(e,t=0){let n=t;for(;n<e.length&&e[n]===`
`;)n++;return n}function re(e,t,n,r){let{lastNewline:i,lastWhitespace:a}=w(e,t,n,e=>d(r,e));return i>t?i:a>t?a:-1}function w(e,t,n,r=()=>!0){let i=-1,a=-1,o=0;for(let s=t;s<n;s++){if(!r(s))continue;let t=e[s];if(t===`(`){o+=1;continue}if(t===`)`&&o>0){--o;continue}o===0&&(t===`
`?i=s:/\s/.test(t)&&(a=s))}return{lastNewline:i,lastWhitespace:a}}const ie=new Map([[`signal`,`bullets`],[`whatsapp`,`bullets`],[`mattermost`,`off`]]),T=e=>e===`off`||e===`bullets`||e===`code`;function ae(e,r){if(!e)return;let i=t.zt(r),a=e.accounts;if(a&&typeof a==`object`){let e=n.Us(a,i)?.markdown?.tables;if(T(e))return e}let o=e.markdown?.tables;return T(o)?o:void 0}function oe(e){let t=n.mo(e.channel),r=t?ie.get(t)??`code`:`code`;return!t||!e.cfg?r:ae(e.cfg.channels?.[t]??e.cfg?.[t],e.accountId)??r}function E(e){return typeof e.maxBytesOrOptions==`number`||e.maxBytesOrOptions===void 0?{maxBytes:e.maxBytesOrOptions,optimizeImages:e.optimizeImages,ssrfPolicy:e.options?.ssrfPolicy,localRoots:e.options?.localRoots}:{...e.maxBytesOrOptions,optimizeImages:e.optimizeImages?e.maxBytesOrOptions.optimizeImages??!0:!1}}var D=class extends Error{constructor(e,t,n){super(t,n),this.code=e,this.name=`LocalMediaAccessError`}};function O(){return i.n()}async function se(e,t){if(t===`any`)return;let n=t??O(),r;try{r=await o.default.realpath(e)}catch{r=a.default.resolve(e)}if(t===void 0){let t=n.find(e=>a.default.basename(e)===`workspace`);if(t){let n=a.default.dirname(t),i=a.default.relative(n,r);if(i&&!i.startsWith(`..`)&&!a.default.isAbsolute(i)&&(i.split(a.default.sep)[0]??``).startsWith(`workspace-`))throw new D(`path-not-allowed`,`Local media path is not under an allowed directory: ${e}`)}}for(let e of n){let t;try{t=await o.default.realpath(e)}catch{t=a.default.resolve(e)}if(t===a.default.parse(t).root)throw new D(`invalid-root`,`Invalid localRoots entry (refuses filesystem root): ${e}. Pass a narrower directory.`);if(r===t||r.startsWith(t+a.default.sep))return}throw new D(`path-not-allowed`,`Local media path is not under an allowed directory: ${e}`)}const ce=/^image\/hei[cf]$/i,k=/\.(heic|heif)$/i;function A(e,t=2){return(e/1048576).toFixed(t)}function j(e,t,n){return`${e} exceeds ${A(t,0)}MB limit (got ${A(n)}MB)`}function M(e,t,n){return`${e} could not be reduced below ${A(t,0)}MB (got ${A(n)}MB)`}function N(e){return!!(e.contentType&&ce.test(e.contentType.trim())||e.fileName&&k.test(e.fileName.trim()))}function le(e){if(!e)return;let t=e.trim();if(!t)return e;let n=a.default.parse(t);return!n.ext||k.test(n.ext)?a.default.format({dir:n.dir,name:n.name||t,ext:`.jpg`}):a.default.format({dir:n.dir,name:n.name,ext:`.jpg`})}function ue(e){if(r.B()&&!(e.optimized.optimizedSize>=e.originalSize)){if(e.optimized.format===`png`){r.R(`Optimized PNG (preserving alpha) from ${A(e.originalSize)}MB to ${A(e.optimized.optimizedSize)}MB (side≤${e.optimized.resizeSide}px)`);return}r.R(`Optimized media from ${A(e.originalSize)}MB to ${A(e.optimized.optimizedSize)}MB (side≤${e.optimized.resizeSide}px, q=${e.optimized.quality})`)}}async function de(e){let{buffer:t,cap:i,meta:a}=e;if((a?.contentType===`image/png`||a?.fileName?.toLowerCase().endsWith(`.png`))&&await n.Zr(t)){let e=await n.Qr(t,i);if(e.buffer.length<=i)return{...e,format:`png`};r.B()&&r.R(`PNG with alpha still exceeds ${A(i,0)}MB after optimization; falling back to JPEG`)}return{...await me(t,i,a),format:`jpeg`}}async function P(e,n={}){let{maxBytes:o,optimizeImages:c=!0,ssrfPolicy:l,localRoots:u,sandboxValidated:d=!1,readFile:f}=n;if(e=e.replace(/^\s*MEDIA\s*:\s*/i,``),e.startsWith(`file://`))try{e=(0,s.fileURLToPath)(e)}catch{throw new D(`invalid-file-url`,`Invalid file:// URL: ${e}`)}let p=async(e,t,n)=>{let r=e.length,i=await de({buffer:e,cap:t,meta:n});if(ue({originalSize:r,optimized:i}),i.buffer.length>t)throw Error(M(`Media`,t,i.buffer.length));let a=i.format===`png`?`image/png`:`image/jpeg`,o=i.format===`jpeg`&&n&&N(n)?le(n.fileName):n?.fileName;return{buffer:i.buffer,contentType:a,kind:`image`,fileName:o}},m=async e=>{let n=o===void 0?t.y(e.kind??`document`):o;if(e.kind===`image`){let t=e.contentType===`image/gif`;if(t||!c){if(e.buffer.length>n)throw Error(j(t?`GIF`:`Media`,n,e.buffer.length));return{buffer:e.buffer,contentType:e.contentType,kind:e.kind,fileName:e.fileName}}return{...await p(e.buffer,n,{contentType:e.contentType,fileName:e.fileName})}}if(e.buffer.length>n)throw Error(j(`Media`,n,e.buffer.length));return{buffer:e.buffer,contentType:e.contentType??void 0,kind:e.kind,fileName:e.fileName}};if(/^https?:\/\//i.test(e)){let n=t.y(`document`),{buffer:r,contentType:a,fileName:s}=await i.i({url:e,maxBytes:o===void 0?n:c?Math.max(o,n):o,ssrfPolicy:l});return await m({buffer:r,contentType:a,kind:t.g(a),fileName:s})}if(e.startsWith(`~`)&&(e=r.y(e)),(d||u===`any`)&&!f)throw new D(`unsafe-bypass`,`Refusing localRoots bypass without readFile override. Use sandboxValidated with readFile, or pass explicit localRoots.`);d||u===`any`||await se(e,u);let h;if(f)h=await f(e);else try{h=(await t.D({filePath:e})).buffer}catch(n){throw n instanceof t.x?n.code===`not-found`?new D(`not-found`,`Local media file not found: ${e}`,{cause:n}):n.code===`not-file`?new D(`not-file`,`Local media path is not a file: ${e}`,{cause:n}):new D(`invalid-path`,`Local media path is not safe to read: ${e}`,{cause:n}):n}let g=await t.u({buffer:h,filePath:e}),_=t.g(g),v=a.default.basename(e)||void 0;if(v&&!a.default.extname(v)&&g){let e=t.d(g);e&&(v=`${v}${e}`)}return await m({buffer:h,contentType:g,kind:_,fileName:v})}async function fe(e,t,n){return await P(e,E({maxBytesOrOptions:t,options:n,optimizeImages:!0}))}async function pe(e,t,n){return await P(e,E({maxBytesOrOptions:t,options:n,optimizeImages:!1}))}async function me(e,t,r={}){let i=e;if(N(r))try{i=await n.Yr(e)}catch(e){throw Error(`HEIC image conversion failed: ${String(e)}`,{cause:e})}let a=[2048,1536,1280,1024,800],o=[80,70,60,50,40],s=null;for(let e of a)for(let r of o)try{let a=await n.$r({buffer:i,maxSide:e,quality:r,withoutEnlargement:!0}),o=a.length;if((!s||o<s.size)&&(s={buffer:a,size:o,resizeSide:e,quality:r}),o<=t)return{buffer:a,optimizedSize:o,resizeSide:e,quality:r}}catch{}if(s)return{buffer:s.buffer,optimizedSize:s.size,resizeSide:s.resizeSide,quality:s.quality};throw Error(`Failed to optimize image`)}function F(e){let t=new c.default({html:!1,linkify:e.linkify??!0,breaks:!1,typographer:!1});return t.enable(`strikethrough`),e.tableMode&&e.tableMode!==`off`?t.enable(`table`):t.disable(`table`),e.autolink===!1&&t.disable(`autolink`),t}function I(e,t){if(e.attrGet)return e.attrGet(t);if(e.attrs){for(let[n,r]of e.attrs)if(n===t)return r}return null}function L(e,t){return{...e,type:`text`,content:t,children:void 0}}function R(e){for(let t of e)t.children&&t.children.length>0&&(t.children=z(t.children))}function z(e){let t=0;for(let n of e){if(n.type!==`text`)continue;let e=n.content??``,r=0;for(;r<e.length;){let n=e.indexOf(`||`,r);if(n===-1)break;t+=1,r=n+2}}if(t<2)return e;let n=t-t%2,r=[],i={spoilerOpen:!1},a=0;for(let t of e){if(t.type!==`text`){r.push(t);continue}let e=t.content??``;if(!e.includes(`||`)){r.push(t);continue}let o=0;for(;o<e.length;){let s=e.indexOf(`||`,o);if(s===-1){o<e.length&&r.push(L(t,e.slice(o)));break}if(a>=n){r.push(L(t,e.slice(o)));break}s>o&&r.push(L(t,e.slice(o,s))),a+=1,i.spoilerOpen=!i.spoilerOpen,r.push({type:i.spoilerOpen?`spoiler_open`:`spoiler_close`}),o=s+2}}return r}function he(){return{text:``,styles:[],openStyles:[],links:[],linkStack:[]}}function B(e){return e.table?.currentCell??e}function V(e,t){if(!t)return;let n=B(e);n.text+=t}function H(e,t){let n=B(e);n.openStyles.push({style:t,start:n.text.length})}function U(e,t){let n=B(e);for(let e=n.openStyles.length-1;e>=0;--e)if(n.openStyles[e]?.style===t){let r=n.openStyles[e].start;n.openStyles.splice(e,1);let i=n.text.length;i>r&&n.styles.push({start:r,end:i,style:t});return}}function W(e){e.env.listStack.length>0||e.table||(e.text+=`

`)}function ge(e){let t=e.env.listStack,n=t[t.length-1];if(!n)return;n.index+=1;let r=`  `.repeat(Math.max(0,t.length-1)),i=n.type===`ordered`?`${n.index}. `:`• `;e.text+=`${r}${i}`}function _e(e,t){if(!t)return;let n=B(e),r=n.text.length;n.text+=t,n.styles.push({start:r,end:r+t.length,style:`code`})}function ve(e,t){let n=t??``;n.endsWith(`
`)||(n=`${n}\n`);let r=B(e),i=r.text.length;r.text+=n,r.styles.push({start:i,end:i+n.length,style:`code_block`}),e.env.listStack.length===0&&(r.text+=`
`)}function ye(e){let t=B(e),n=t.linkStack.pop();if(!n?.href)return;let r=n.href.trim();if(!r)return;let i=n.labelStart,a=t.text.length;if(a<=i){t.links.push({start:i,end:a,href:r});return}t.links.push({start:i,end:a,href:r})}function be(){return{headers:[],rows:[],currentRow:[],currentCell:null,inHeader:!1}}function xe(e){return Y(e),{text:e.text,styles:e.styles,links:e.links}}function G(e){let t=e.text,n=0,r=t.length;for(;n<r&&/\s/.test(t[n]??``);)n+=1;for(;r>n&&/\s/.test(t[r-1]??``);)--r;if(n===0&&r===t.length)return e;let i=t.slice(n,r),a=i.length,o=[];for(let t of e.styles){let e=Math.max(0,t.start-n),r=Math.min(a,t.end-n);r>e&&o.push({start:e,end:r,style:t.style})}let s=[];for(let t of e.links){let e=Math.max(0,t.start-n),r=Math.min(a,t.end-n);r>e&&s.push({start:e,end:r,href:t.href})}return{text:i,styles:o,links:s}}function K(e,t){if(!t.text)return;let n=e.text.length;e.text+=t.text;for(let r of t.styles)e.styles.push({start:n+r.start,end:n+r.end,style:r.style});for(let r of t.links)e.links.push({start:n+r.start,end:n+r.end,href:r.href})}function Se(e,t){t.text&&(e.text+=t.text)}function q(e,t){let{header:n,value:r,columnIndex:i,includeColumnFallback:a}=t;r?.text&&(e.text+=`• `,n?.text?(K(e,n),e.text+=`: `):a&&(e.text+=`Column ${i}: `),K(e,r),e.text+=`
`)}function Ce(e){if(!e.table)return;let t=e.table.headers.map(G),n=e.table.rows.map(e=>e.map(G));if(!(t.length===0&&n.length===0))if(t.length>1&&n.length>0)for(let r of n){if(r.length===0)continue;let n=r[0];if(n?.text){let t=e.text.length;K(e,n);let r=e.text.length;r>t&&e.styles.push({start:t,end:r,style:`bold`}),e.text+=`
`}for(let n=1;n<r.length;n++)q(e,{header:t[n],value:r[n],columnIndex:n,includeColumnFallback:!0});e.text+=`
`}else for(let r of n){for(let n=0;n<r.length;n++)q(e,{header:t[n],value:r[n],columnIndex:n,includeColumnFallback:!1});e.text+=`
`}}function we(e){if(!e.table)return;let t=e.table.headers.map(G),n=e.table.rows.map(e=>e.map(G)),r=Math.max(t.length,...n.map(e=>e.length));if(r===0)return;let i=Array.from({length:r},()=>0),a=e=>{for(let t=0;t<r;t+=1){let n=e[t]?.text.length??0;i[t]<n&&(i[t]=n)}};a(t);for(let e of n)a(e);let o=e.text.length,s=t=>{e.text+=`|`;for(let n=0;n<r;n+=1){e.text+=` `;let r=t[n];r&&Se(e,r);let a=i[n]-(r?.text.length??0);a>0&&(e.text+=` `.repeat(a)),e.text+=` |`}e.text+=`
`};s(t),(()=>{e.text+=`|`;for(let t=0;t<r;t+=1){let n=Math.max(3,i[t]);e.text+=` ${`-`.repeat(n)} |`}e.text+=`
`})();for(let e of n)s(e);let c=e.text.length;c>o&&e.styles.push({start:o,end:c,style:`code_block`}),e.env.listStack.length===0&&(e.text+=`
`)}function J(e,t){for(let n of e)switch(n.type){case`inline`:n.children&&J(n.children,t);break;case`text`:V(t,n.content??``);break;case`em_open`:H(t,`italic`);break;case`em_close`:U(t,`italic`);break;case`strong_open`:H(t,`bold`);break;case`strong_close`:U(t,`bold`);break;case`s_open`:H(t,`strikethrough`);break;case`s_close`:U(t,`strikethrough`);break;case`code_inline`:_e(t,n.content??``);break;case`spoiler_open`:t.enableSpoilers&&H(t,`spoiler`);break;case`spoiler_close`:t.enableSpoilers&&U(t,`spoiler`);break;case`link_open`:{let e=I(n,`href`)??``,r=B(t);r.linkStack.push({href:e,labelStart:r.text.length});break}case`link_close`:ye(t);break;case`image`:V(t,n.content??``);break;case`softbreak`:case`hardbreak`:V(t,`
`);break;case`paragraph_close`:W(t);break;case`heading_open`:t.headingStyle===`bold`&&H(t,`bold`);break;case`heading_close`:t.headingStyle===`bold`&&U(t,`bold`),W(t);break;case`blockquote_open`:t.blockquotePrefix&&(t.text+=t.blockquotePrefix),H(t,`blockquote`);break;case`blockquote_close`:U(t,`blockquote`);break;case`bullet_list_open`:t.env.listStack.length>0&&(t.text+=`
`),t.env.listStack.push({type:`bullet`,index:0});break;case`bullet_list_close`:t.env.listStack.pop(),t.env.listStack.length===0&&(t.text+=`
`);break;case`ordered_list_open`:{t.env.listStack.length>0&&(t.text+=`
`);let e=Number(I(n,`start`)??`1`);t.env.listStack.push({type:`ordered`,index:e-1});break}case`ordered_list_close`:t.env.listStack.pop(),t.env.listStack.length===0&&(t.text+=`
`);break;case`list_item_open`:ge(t);break;case`list_item_close`:t.text.endsWith(`
`)||(t.text+=`
`);break;case`code_block`:case`fence`:ve(t,n.content??``);break;case`html_block`:case`html_inline`:V(t,n.content??``);break;case`table_open`:t.tableMode!==`off`&&(t.table=be(),t.hasTables=!0);break;case`table_close`:t.table&&(t.tableMode===`bullets`?Ce(t):t.tableMode===`code`&&we(t)),t.table=null;break;case`thead_open`:t.table&&(t.table.inHeader=!0);break;case`thead_close`:t.table&&(t.table.inHeader=!1);break;case`tbody_open`:case`tbody_close`:break;case`tr_open`:t.table&&(t.table.currentRow=[]);break;case`tr_close`:t.table&&(t.table.inHeader?t.table.headers=t.table.currentRow:t.table.rows.push(t.table.currentRow),t.table.currentRow=[]);break;case`th_open`:case`td_open`:t.table&&(t.table.currentCell=he());break;case`th_close`:case`td_close`:t.table?.currentCell&&(t.table.currentRow.push(xe(t.table.currentCell)),t.table.currentCell=null);break;case`hr`:t.text+=`───

`;break;default:n.children&&J(n.children,t);break}}function Y(e){for(let t=e.openStyles.length-1;t>=0;--t){let n=e.openStyles[t],r=e.text.length;r>n.start&&e.styles.push({start:n.start,end:r,style:n.style})}e.openStyles=[]}function X(e,t){let n=[];for(let r of e){let e=Math.max(0,Math.min(r.start,t)),i=Math.max(e,Math.min(r.end,t));i>e&&n.push({start:e,end:i,style:r.style})}return n}function Te(e,t){let n=[];for(let r of e){let e=Math.max(0,Math.min(r.start,t)),i=Math.max(e,Math.min(r.end,t));i>e&&n.push({start:e,end:i,href:r.href})}return n}function Z(e){let t=[...e].toSorted((e,t)=>e.start===t.start?e.end===t.end?e.style.localeCompare(t.style):e.end-t.end:e.start-t.start),n=[];for(let e of t){let t=n[n.length-1];if(t&&t.style===e.style&&(e.start<t.end||e.start===t.end&&e.style!==`blockquote`)){t.end=Math.max(t.end,e.end);continue}n.push({...e})}return n}function Q(e,t,n){let r=Math.max(e.start,t),i=Math.min(e.end,n);return i<=r?null:{start:r,end:i}}function Ee(e,t,n){if(e.length===0)return[];let r=[];for(let i of e){let e=Q(i,t,n);e&&r.push({start:e.start-t,end:e.end-t,style:i.style})}return Z(r)}function De(e,t,n){if(e.length===0)return[];let r=[];for(let i of e){let e=Q(i,t,n);e&&r.push({start:e.start-t,end:e.end-t,href:i.href})}return r}function Oe(e,t={}){return $(e,t).ir}function $(e,t={}){let n={listStack:[]},r=F(t).parse(e??``,n);t.enableSpoilers&&R(r);let i=t.tableMode??`off`,a={text:``,styles:[],openStyles:[],links:[],linkStack:[],env:n,headingStyle:t.headingStyle??`none`,blockquotePrefix:t.blockquotePrefix??``,enableSpoilers:t.enableSpoilers??!1,tableMode:i,table:null,hasTables:!1};J(r,a),Y(a);let o=a.text.trimEnd().length,s=0;for(let e of a.styles)e.style===`code_block`&&e.end>s&&(s=e.end);let c=Math.max(o,s);return{ir:{text:c===a.text.length?a.text:a.text.slice(0,c),styles:Z(X(a.styles,c)),links:Te(a.links,c)},hasTables:a.hasTables}}function ke(e,t){if(!e.text)return[];if(t<=0||e.text.length<=t)return[e];let n=S(e.text,t),r=[],i=0;return n.forEach((t,n)=>{if(!t)return;if(n>0)for(;i<e.text.length&&/\s/.test(e.text[i]??``);)i+=1;let a=i,o=Math.min(e.text.length,a+t.length);r.push({text:t,styles:Ee(e.styles,a,o),links:De(e.links,a,o)}),i=o}),r}Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return l}});
