/**
 * @name string-collapse-leading-whitespace
 * @fileoverview Collapse the leading and trailing whitespace of a string
 * @version 7.1.3
 * @author Roy Revelt
 * @license MIT
 * {@link https://codsen.com/os/string-collapse-leading-whitespace/}
 */

var a="7.1.3";var E=a;function D(l,u=1){let g="\xA0";function $(e){return Array.from(e).reverse().join("")}function p(e,r,o){let t=o?`
`:"\r",i=o?"\r":`
`;if(!e)return e;let m=0,c=0,s="";for(let n=0,f=e.length;n<f;n++)(e[n]===t||e[n]===i&&e[n-1]!==t)&&c++,`\r
`.includes(e[n])||e[n]===g?(m=0,e[n]===g?s+=e[n]:e[n]===t?c<=r&&(s+=e[n],e[n+1]===i&&(s+=e[n+1],n++)):e[n]===i&&e?.[n-1]!==t&&c<=r&&(s+=e[n])):(m++,!e[n+1]&&!c&&(s+=" "));return s}if(typeof l=="string"&&l.length){let e=1;typeof+u=="number"&&Number.isInteger(+u)&&+u>=0&&(e=+u);let r="",o="";if(!l.trim())r=l;else if(!l[0].trim()){for(let t=0,i=l.length;t<i;t++)if(l[t].trim()){r=l.slice(0,t);break}}if(l.trim()&&(l.slice(-1).trim()===""||l.slice(-1)===g)){for(let t=l.length;t--;)if(l[t].trim()){o=l.slice(t+1);break}}return`${p(r,e,!1)}${l.trim()}${$(p($(o),e,!0))}`}return l}export{D as collWhitespace,E as version};
