@visulima/boxen
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,1 +1,8 @@ | ||
## @visulima/boxen [1.0.1](https://github.com/visulima/visulima/compare/@visulima/boxen@1.0.0...@visulima/boxen@1.0.1) (2024-03-09) | ||
### Bug Fixes | ||
* added missing type module to the package.json ([510c5b7](https://github.com/visulima/visulima/commit/510c5b7e9cdca2b6de104d0b6b0f5ad2fbf50956)) | ||
## @visulima/boxen 1.0.0 (2024-03-06) | ||
@@ -2,0 +9,0 @@ |
@@ -1,23 +0,14 @@ | ||
'use strict'; | ||
import N from 'cli-boxes'; | ||
import d from 'string-width'; | ||
import k from 'terminal-size'; | ||
import R from 'wrap-ansi'; | ||
var F = require('cli-boxes'); | ||
var d = require('string-width'); | ||
var D = require('terminal-size'); | ||
var k = require('wrap-ansi'); | ||
var E=(r,i)=>Math.floor((r-i)/2),j=(r,i)=>r-i,p=(r,i={})=>{let e=i.align??"center";if(e==="left")return r;let t=i.split??` | ||
`,a=i.pad??" ",n=e==="right"?j:E,l=!1;Array.isArray(r)||(l=!0,r=String(r).split(t));let m,f=0;return r=r.map(s=>(s=String(s),m=d(s),f=Math.max(m,f),{str:s,width:m})).map(s=>Array.from({length:n(f,s.width)+1}).join(a)+s.str),l?r.join(t):r};var M=r=>{let i=0;for(let e of r.split(` | ||
`))i=Math.max(i,d(e));return i};var u=` | ||
`,c=" ",y="none",S=r=>typeof r=="number"?{bottom:r,left:r*3,right:r*3,top:r}:{bottom:0,left:0,right:0,top:0,...r},L=r=>r===y?0:2,P=r=>{let i=["topLeft","topRight","bottomRight","bottomLeft","left","right","top","bottom"],e;if(r===y){r={};for(let t of i)r[t]="";}if(typeof r=="string"){let t=N[r];if(t===void 0)throw new TypeError(`Invalid border style: ${r}`);e=t;}else {typeof r.vertical=="string"&&(r.left=r.vertical,r.right=r.vertical),typeof r.horizontal=="string"&&(r.top=r.horizontal,r.bottom=r.horizontal);for(let t of i)if(r[t]===null||typeof r[t]!="string")throw new TypeError(`Invalid border style: ${t}`);e=r;}return e},A=(r,i,e,t,a)=>{let n="";r=i(r);let l=d(r);switch(a){case"left":{n=r+t(e.slice(l),d(e.slice(l)));break}case"right":{n=t(e.slice(l+2),d(e.slice(l))+2)+" "+r+" ";break}default:{if(e=e.slice(l),e.length%2===1)e=e.slice(Math.floor(e.length/2)),n=t(e.slice(1),d(e.slice(1)))+r+t(e,d(e));else {e=e.slice(e.length/2);let m=d(e);n=t(e,m)+r+t(e,m);}break}}return n},I=(r,{height:i,padding:e,textAlignment:t,width:a})=>{r=p(r,{align:t});let n=r.split(u),l=M(r),m=a-e.left-e.right;if(l>m){let h=[];for(let T of n){let g=R(T,m,{hard:!0}),o=p(g,{align:t}).split(` | ||
`),x=Math.max(...o.map(w=>d(w)));for(let w of o){let C;switch(t){case"center":{C=c.repeat((m-x)/2)+w;break}case"right":{C=c.repeat(m-x)+w;break}default:{C=w;break}}h.push(C);}}n=h;}t==="center"&&l<m?n=n.map(h=>c.repeat((m-l)/2)+h):t==="right"&&l<m&&(n=n.map(h=>c.repeat(m-l)+h));let f=c.repeat(e.left),s=c.repeat(e.right);return n=n.map(h=>{let T=f+h+s;return T+c.repeat(a-d(T))}),e.top>0&&(n=[...Array.from({length:e.top}).fill(c.repeat(a)),...n]),e.bottom>0&&(n=[...n,...Array.from({length:e.bottom}).fill(c.repeat(a))]),i&&n.length>i?n=n.slice(0,i):i&&n.length<i&&(n=[...n,...Array.from({length:i-n.length}).fill(c.repeat(a))]),n.join(u)},$=(r,i,e,t)=>{let a=(g,b,o)=>t.borderColor?t.borderColor(g,b,o):g,n=g=>t.headerTextColor?t.headerTextColor(g):g,l=g=>t.footerTextColor?t.footerTextColor(g):g,m=g=>t.textColor?t.textColor(g):g,f=P(t.borderStyle),s=c.repeat(t.margin.left);if(t.float==="center"){let g=Math.max((e-i-L(t.borderStyle))/2,0);s=c.repeat(g);}else if(t.float==="right"){let g=Math.max(e-i-t.margin.right-L(t.borderStyle),0);s=c.repeat(g);}let h="";if(t.margin.top&&(h+=u.repeat(t.margin.top)),t.borderStyle!==y||t.headerText){let g=a(f.top.repeat(i),"top",i);t.headerText&&(g=A(t.headerText,n,f.top.repeat(i),(o,x)=>a(o,"top",x),t.headerAlignment));let b=a(s+f.topLeft,"topLeft",d(s+f.topLeft));h+=b+g+a(f.topRight,"topRight",d(f.topRight))+u;}let T=r.split(u);if(h+=T.map(g=>s+a(f.left,"left",d(f.left))+m(g)+a(f.right,"right",d(f.right))).join(u),t.borderStyle!==y||t.footerText){let g=u+a(s+f.bottomLeft,"bottomLeft",d(s+f.bottomLeft)),b=a(f.bottom.repeat(i),"bottom",i);t.footerText&&(b=A(t.footerText,l,f.bottom.repeat(i),(o,x)=>a(o,"bottom",x),t.footerAlignment)),h+=g+b+a(f.bottomRight,"bottomRight",d(f.bottomRight));}return t.margin.bottom&&(h+=u.repeat(t.margin.bottom)),h},W=r=>{if(r.fullscreen){let i=k();typeof r.fullscreen=="function"&&(i=r.fullscreen(i.columns,i.rows)),r.width||(r.width=i.columns),r.height||(r.height=i.rows);}return r.width&&(r.width=Math.max(1,r.width-L(r.borderStyle))),r.height&&(r.height=Math.max(1,r.height-L(r.borderStyle))),r},D=(r,i)=>i===y?r:` ${r} `,q=(r,i,e)=>{e=W(e);let t=e.width!==void 0,a=L(e.borderStyle),n=i-e.margin.left-e.margin.right-a,l=M(R(r,i-a,{hard:!0,trim:!1}))+e.padding.left+e.padding.right;if(e.headerText&&t?(e.headerText=e.headerText.slice(0,Math.max(0,e.width-2)),e.headerText&&(e.headerText=D(e.headerText,e.borderStyle))):e.headerText&&(e.headerText=e.headerText.slice(0,Math.max(0,n-2)),e.headerText&&(e.headerText=D(e.headerText,e.borderStyle),d(e.headerText)>l&&(e.width=d(e.headerText)))),e.width=e.width||l,!t){if(e.margin.left&&e.margin.right&&e.width>n){let f=(i-e.width-a)/(e.margin.left+e.margin.right);e.margin.left=Math.max(0,Math.floor(e.margin.left*f)),e.margin.right=Math.max(0,Math.floor(e.margin.right*f));}e.width=Math.min(e.width,i-a-e.margin.left-e.margin.right);}return e.width-(e.padding.left+e.padding.right)<=0&&(e.padding.left=0,e.padding.right=0),e.height&&e.height-(e.padding.top+e.padding.bottom)<=0&&(e.padding.top=0,e.padding.bottom=0),e},ee=(r,i={})=>{if(i.borderColor!==void 0&&typeof i.borderColor!="function")throw new Error('"borderColor" is not a valid function');if(i.textColor!==void 0&&typeof i.textColor!="function")throw new Error('"backgroundColor" is not a valid function');let e={borderStyle:"single",dimBorder:!1,float:"left",footerAlignment:"right",headerAlignment:"left",textAlignment:"left",transformTabToSpace:4,...i};e.padding=S(i.padding??0),e.margin=S(i.margin),e.transformTabToSpace&&(r=r.replaceAll(" "," ".repeat(e.transformTabToSpace)));let{columns:t}=k();return e=q(r,t,e),$(I(r,e),e.width,t,e)}; | ||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
var F__default = /*#__PURE__*/_interopDefault(F); | ||
var d__default = /*#__PURE__*/_interopDefault(d); | ||
var D__default = /*#__PURE__*/_interopDefault(D); | ||
var k__default = /*#__PURE__*/_interopDefault(k); | ||
var v=(r,i)=>Math.floor((r-i)/2),E=(r,i)=>r-i,p=(r,i={})=>{let e=i.align??"center";if(e==="left")return r;let t=i.split??` | ||
`,a=i.pad??" ",n=e==="right"?E:v,l=!1;Array.isArray(r)||(l=!0,r=String(r).split(t));let m,f=0;return r=r.map(s=>(s=String(s),m=d__default.default(s),f=Math.max(m,f),{str:s,width:m})).map(s=>Array.from({length:n(f,s.width)+1}).join(a)+s.str),l?r.join(t):r};var M=r=>{let i=0;for(let e of r.split(` | ||
`))i=Math.max(i,d__default.default(e));return i};var u=` | ||
`,c=" ",y="none",O=r=>typeof r=="number"?{bottom:r,left:r*3,right:r*3,top:r}:{bottom:0,left:0,right:0,top:0,...r},L=r=>r===y?0:2,N=r=>{let i=["topLeft","topRight","bottomRight","bottomLeft","left","right","top","bottom"],e;if(r===y){r={};for(let t of i)r[t]="";}if(typeof r=="string"){let t=F__default.default[r];if(t===void 0)throw new TypeError(`Invalid border style: ${r}`);e=t;}else {typeof r.vertical=="string"&&(r.left=r.vertical,r.right=r.vertical),typeof r.horizontal=="string"&&(r.top=r.horizontal,r.bottom=r.horizontal);for(let t of i)if(r[t]===null||typeof r[t]!="string")throw new TypeError(`Invalid border style: ${t}`);e=r;}return e},S=(r,i,e,t,a)=>{let n="";r=i(r);let l=d__default.default(r);switch(a){case"left":{n=r+t(e.slice(l),d__default.default(e.slice(l)));break}case"right":{n=t(e.slice(l+2),d__default.default(e.slice(l))+2)+" "+r+" ";break}default:{if(e=e.slice(l),e.length%2===1)e=e.slice(Math.floor(e.length/2)),n=t(e.slice(1),d__default.default(e.slice(1)))+r+t(e,d__default.default(e));else {e=e.slice(e.length/2);let m=d__default.default(e);n=t(e,m)+r+t(e,m);}break}}return n},P=(r,{height:i,padding:e,textAlignment:t,width:a})=>{r=p(r,{align:t});let n=r.split(u),l=M(r),m=a-e.left-e.right;if(l>m){let h=[];for(let T of n){let g=k__default.default(T,m,{hard:!0}),o=p(g,{align:t}).split(` | ||
`),x=Math.max(...o.map(w=>d__default.default(w)));for(let w of o){let C;switch(t){case"center":{C=c.repeat((m-x)/2)+w;break}case"right":{C=c.repeat(m-x)+w;break}default:{C=w;break}}h.push(C);}}n=h;}t==="center"&&l<m?n=n.map(h=>c.repeat((m-l)/2)+h):t==="right"&&l<m&&(n=n.map(h=>c.repeat(m-l)+h));let f=c.repeat(e.left),s=c.repeat(e.right);return n=n.map(h=>{let T=f+h+s;return T+c.repeat(a-d__default.default(T))}),e.top>0&&(n=[...Array.from({length:e.top}).fill(c.repeat(a)),...n]),e.bottom>0&&(n=[...n,...Array.from({length:e.bottom}).fill(c.repeat(a))]),i&&n.length>i?n=n.slice(0,i):i&&n.length<i&&(n=[...n,...Array.from({length:i-n.length}).fill(c.repeat(a))]),n.join(u)},I=(r,i,e,t)=>{let a=(g,b,o)=>t.borderColor?t.borderColor(g,b,o):g,n=g=>t.headerTextColor?t.headerTextColor(g):g,l=g=>t.footerTextColor?t.footerTextColor(g):g,m=g=>t.textColor?t.textColor(g):g,f=N(t.borderStyle),s=c.repeat(t.margin.left);if(t.float==="center"){let g=Math.max((e-i-L(t.borderStyle))/2,0);s=c.repeat(g);}else if(t.float==="right"){let g=Math.max(e-i-t.margin.right-L(t.borderStyle),0);s=c.repeat(g);}let h="";if(t.margin.top&&(h+=u.repeat(t.margin.top)),t.borderStyle!==y||t.headerText){let g=a(f.top.repeat(i),"top",i);t.headerText&&(g=S(t.headerText,n,f.top.repeat(i),(o,x)=>a(o,"top",x),t.headerAlignment));let b=a(s+f.topLeft,"topLeft",d__default.default(s+f.topLeft));h+=b+g+a(f.topRight,"topRight",d__default.default(f.topRight))+u;}let T=r.split(u);if(h+=T.map(g=>s+a(f.left,"left",d__default.default(f.left))+m(g)+a(f.right,"right",d__default.default(f.right))).join(u),t.borderStyle!==y||t.footerText){let g=u+a(s+f.bottomLeft,"bottomLeft",d__default.default(s+f.bottomLeft)),b=a(f.bottom.repeat(i),"bottom",i);t.footerText&&(b=S(t.footerText,l,f.bottom.repeat(i),(o,x)=>a(o,"bottom",x),t.footerAlignment)),h+=g+b+a(f.bottomRight,"bottomRight",d__default.default(f.bottomRight));}return t.margin.bottom&&(h+=u.repeat(t.margin.bottom)),h},$=r=>{if(r.fullscreen){let i=D__default.default();typeof r.fullscreen=="function"&&(i=r.fullscreen(i.columns,i.rows)),r.width||(r.width=i.columns),r.height||(r.height=i.rows);}return r.width&&(r.width=Math.max(1,r.width-L(r.borderStyle))),r.height&&(r.height=Math.max(1,r.height-L(r.borderStyle))),r},A=(r,i)=>i===y?r:` ${r} `,W=(r,i,e)=>{e=$(e);let t=e.width!==void 0,a=L(e.borderStyle),n=i-e.margin.left-e.margin.right-a,l=M(k__default.default(r,i-a,{hard:!0,trim:!1}))+e.padding.left+e.padding.right;if(e.headerText&&t?(e.headerText=e.headerText.slice(0,Math.max(0,e.width-2)),e.headerText&&(e.headerText=A(e.headerText,e.borderStyle))):e.headerText&&(e.headerText=e.headerText.slice(0,Math.max(0,n-2)),e.headerText&&(e.headerText=A(e.headerText,e.borderStyle),d__default.default(e.headerText)>l&&(e.width=d__default.default(e.headerText)))),e.width=e.width||l,!t){if(e.margin.left&&e.margin.right&&e.width>n){let f=(i-e.width-a)/(e.margin.left+e.margin.right);e.margin.left=Math.max(0,Math.floor(e.margin.left*f)),e.margin.right=Math.max(0,Math.floor(e.margin.right*f));}e.width=Math.min(e.width,i-a-e.margin.left-e.margin.right);}return e.width-(e.padding.left+e.padding.right)<=0&&(e.padding.left=0,e.padding.right=0),e.height&&e.height-(e.padding.top+e.padding.bottom)<=0&&(e.padding.top=0,e.padding.bottom=0),e},z=(r,i={})=>{if(i.borderColor!==void 0&&typeof i.borderColor!="function")throw new Error('"borderColor" is not a valid function');if(i.textColor!==void 0&&typeof i.textColor!="function")throw new Error('"backgroundColor" is not a valid function');let e={borderStyle:"single",dimBorder:!1,float:"left",footerAlignment:"right",headerAlignment:"left",textAlignment:"left",transformTabToSpace:4,...i};e.padding=O(i.padding??0),e.margin=O(i.margin),e.transformTabToSpace&&(r=r.replaceAll(" "," ".repeat(e.transformTabToSpace)));let{columns:t}=D__default.default();return e=W(r,t,e),I(P(r,e),e.width,t,e)}; | ||
exports.boxen = z; | ||
export { ee as boxen }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -23,3 +23,3 @@ MIT License | ||
--------------------- | ||
--- | ||
@@ -42,3 +42,3 @@ File: src/align.ts | ||
--------------------- | ||
--- | ||
@@ -45,0 +45,0 @@ File: src/index.ts |
{ | ||
"name": "@visulima/boxen", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Util.format-like string formatting utility.", | ||
@@ -14,3 +14,2 @@ "keywords": [ | ||
"boxen", | ||
"box", | ||
"terminal", | ||
@@ -46,11 +45,12 @@ "term", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
}, | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"import": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
} | ||
@@ -60,4 +60,4 @@ }, | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"source": "src/index.ts", | ||
@@ -76,7 +76,7 @@ "types": "dist/index.d.ts", | ||
"dev": "pnpm run build --watch", | ||
"lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.js", | ||
"lint:eslint:fix": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.js --fix", | ||
"lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs", | ||
"lint:eslint:fix": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs --fix", | ||
"lint:packagejson": "publint --strict", | ||
"lint:prettier": "prettier --config=.prettierrc.js --check .", | ||
"lint:prettier:fix": "prettier --config=.prettierrc.js --write .", | ||
"lint:prettier": "prettier --config=.prettierrc.cjs --check .", | ||
"lint:prettier:fix": "prettier --config=.prettierrc.cjs --write .", | ||
"lint:types": "tsc --noEmit", | ||
@@ -91,8 +91,7 @@ "test": "vitest run", | ||
"cli-boxes": "^3.0.0", | ||
"string-width": "^7.1.0", | ||
"terminal-size": "^4.0.0", | ||
"string-width": "^7.1.0", | ||
"wrap-ansi": "^9.0.0" | ||
}, | ||
"devDependencies": { | ||
"@visulima/colorize": "1.3.0", | ||
"@anolilab/eslint-config": "^15.0.3", | ||
@@ -104,2 +103,3 @@ "@anolilab/prettier-config": "^5.0.14", | ||
"@types/node": "18.18.14", | ||
"@visulima/colorize": "1.3.0", | ||
"@vitest/coverage-v8": "^1.3.1", | ||
@@ -121,3 +121,3 @@ "@vitest/ui": "^1.3.1", | ||
"tsup": "^8.0.2", | ||
"typescript": "^5.3.3", | ||
"typescript": "^5.4.2", | ||
"vitest": "^1.3.1" | ||
@@ -124,0 +124,0 @@ }, |
@@ -149,3 +149,3 @@ <div align="center"> | ||
); | ||
```` | ||
``` | ||
@@ -271,3 +271,3 @@ ##### borderStyle | ||
```js | ||
import { red } from "@visulima/colorize" | ||
import { red } from "@visulima/colorize"; | ||
import { boxen } from "@visulima/boxen"; | ||
@@ -336,2 +336,3 @@ | ||
``` | ||
##### footerColor | ||
@@ -342,3 +343,3 @@ | ||
```js | ||
import { red } from "@visulima/colorize" | ||
import { red } from "@visulima/colorize"; | ||
import { boxen } from "@visulima/boxen"; | ||
@@ -470,4 +471,5 @@ | ||
Type: `(text: string) => string`\ | ||
```js | ||
import { bgRed } from "@visulima/colorize" | ||
import { bgRed } from "@visulima/colorize"; | ||
import { boxen } from "@visulima/boxen"; | ||
@@ -474,0 +476,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
93088
523
Yes