UNPKG

2.06 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("debug")):"function"==typeof define&&define.amd?define(["exports","debug"],t):t((e=e||self).textWrap={},e.Debug)}(this,function(e,t){"use strict";const n=(t=t&&t.hasOwnProperty("default")?t.default:t)("AC"),s=t("FC"),i=t("BR"),o=t("BL"),r=t("ML");t.log=console.debug.bind(console),t.formatters.c=e=>e();const a={continuationIndent:"",tabLength:4,wrapOn:120,allowedExceedingCharacters:/\s/,breakableCharacters:/[^\w\xA0]/};e.DEF_WRAP_STYLE=a,e.default=class{constructor(e=a){this.debug={enable:t.enable,disable:t.disable,setLog:e=>t.log=e},function e(t,n,s){for(const[i,o]of Object.entries(s)){const s=void 0===n?void 0:n[i];if("object"!=typeof o||null===o||Array.isArray(o))t[i]=void 0===s?o:s;else{if(void 0===s||s===o){t[i]=o;continue}t[i]={},e(t[i],s,o)}}}(this,e,a),this.tabLength_1=this.tabLength-1}wrap(e,t){const a=[],d=this.tabLength,c=e.length,l=t+this.continuationIndent,f=this.getVisualLength(l,0);let h=0,u="";for(let t,r=0,b=0,g=0,p=0,L=0,x=!1;r<c;++r){if(t=e[r],n("%s / %d",t,b+="\t"===t?d-b%d:1),"\n"===t){o("vLen: %d / draftVLen: %d / fastCheck: %s",b,g,x),x=!1,p=r+1,g=b=0;continue}const w=!this.breakableCharacters.test(t);if(b>this.wrapOn){if(s(x),x||-1===p&&L===h||-1!==p&&!(L-p>f||this.getVisualLength(e.slice(p,L))>f)){if(x=!0,s("draftMarker: %d, start: %d",L,p),w)continue;s(""),x=!1}else if(!this.allowedExceedingCharacters.test(t)){a.push(L),u+=e.slice(h,L)+"\n"+l;const t=f+(b-g);if(i("[%d, %d) / vLen: %d / nextVLen: %d\n%c",h,L,b,t,()=>e.slice(h,L)),h=L,p=-1,b=t,w){g=f;continue}}}else if(w)continue;for(++r;r<c;++r){const t=e[r];if(!this.allowedExceedingCharacters.test(t)||"\n"===t||"\r"===t)break;b+="\t"===t?d-b%d:1}L=r--,g=b}return r("previousMarker: %d\n%s",h,u),{markers:a,wrappedText:u+e.slice(h,c)}}getVisualLength(e,t=0){let n,s=0,i=0;for(;;){if(-1===(n=e.indexOf("\t",s)))return i+(e.length-s);i+=n-s,i+=this.tabLength-(i+t)%this.tabLength,s=n+1}}},Object.defineProperty(e,"__esModule",{value:!0})});
2//# sourceMappingURL=main.umd.js.map