const e=require("string-width"),t=require("strip-ansi"),n=require("ansi-styles"),r=new Set(["","›"]),i=e=>`${r.values().next().value}[${e}m`,o=e=>`${r.values().next().value}]8;;${e}`,s=(n,i,o)=>{const s=[...i];let l=!1,h=!1,u=e(t(n[n.length-1]));for(const[t,i]of s.entries()){const c=e(i);u+c<=o?n[n.length-1]+=i:(n.push(i),u=0),r.has(i)&&(l=!0,h=s.slice(t+1).join("").startsWith("]8;;")),l?h?""===i&&(l=!1,h=!1):"m"===i&&(l=!1):(u+=c)===o&&t0&&n.length>1&&(n[n.length-2]+=n.pop())},l=(t,l,h={})=>{if(!1!==h.trim&&""===t.trim())return"";let u,c,p="";const a=(t=>t.split(" ").map(t=>e(t)))(t);let g=[""];for(const[n,r]of t.split(" ").entries()){!1!==h.trim&&(g[g.length-1]=g[g.length-1].trimStart());let t=e(g[g.length-1]);if(0!==n&&(t>=l&&(!1===h.wordWrap||!1===h.trim)&&(g.push(""),t=0),(t>0||!1===h.trim)&&(g[g.length-1]+=" ",t++)),h.hard&&a[n]>l){const e=l-t,i=1+Math.floor((a[n]-e-1)/l);Math.floor((a[n]-1)/l)l&&t>0&&a[n]>0){if(!1===h.wordWrap&&tl&&!1===h.wordWrap?s(g,r,l):g[g.length-1]+=r}}!1!==h.trim&&(g=g.map(t=>(t=>{const n=t.split(" ");let r=n.length;for(;r>0&&!(e(n[r-1])>0);)r--;return r===n.length?t:n.slice(0,r).join(" ")+n.slice(r).join("")})(t)));const m=[...g.join("\n")];for(const[e,t]of m.entries()){if(p+=t,r.has(t)){const{groups:t}=new RegExp("(?:\\[(?\\d+)m|\\]8;;(?.*))").exec(m.slice(e).join(""))||{groups:{}};if(void 0!==t.code){const e=Number.parseFloat(t.code);u=39===e?void 0:e}else void 0!==t.uri&&(c=0===t.uri.length?void 0:t.uri)}const s=n.codes.get(Number(u));"\n"===m[e+1]?(c&&(p+=o("")),u&&s&&(p+=i(s))):"\n"===t&&(u&&s&&(p+=i(u)),c&&(p+=o(c)))}return p};module.exports=function(e,t,n){return String(e).normalize().replace(/\r\n/g,"\n").split("\n").map(e=>l(e,t,n)).join("\n")};