termark 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import{getColourLevel as e,hasNoColour as t}from"./__internal/env.mjs";import{BOX_BORDERS as n}from"./__internal/styling.mjs";import{TermarkImpl as r,createProxy as i}from"./__internal/impl.mjs";import{ansiLowerCase as a,ansiUpperCase as o,areColoursSupported as s,stripAnsi as c,supports as l,supportsAtMost as u,transformPreserveAnsi as d}from"./utilities.mjs";const f=i(new r);function p(...e){let t={};for(let n of e)Object.assign(t,n(f));return i(new r,t)}function m(e,t={}){let{kind:r=`sharp`,style:i=e=>e,padding:a=1,margin:o=0}=t,s=n[r],l=Math.floor(a/4),u=Math.floor(o/4),d=e.split(`
2
- `),f=d.map(e=>c(e).length),p=Math.max(...f),m=s.tl+s.h.repeat(p+a*2)+s.tr,h=s.bl+s.h.repeat(p+a*2)+s.br,g=` `.repeat(o),_=`
3
- `.repeat(u),v=g+i(m)+g,y=g+i(h)+g,b=g+i(s.v),x=i(s.v)+g;return`${_}${v}\n${d.map(e=>{let t=c(e),n=e+` `.repeat(p-t.length),r=b+` `.repeat(a*2+t.length)+x,i=l===0?``:`${r}\n`.repeat(l),o=l===0?``:`\n${r}`.repeat(l),s=` `.repeat(a);return`${i}${b}${s}${n}${s}${x}${o}`}).join(`
4
- `)}\n${y}${_}`}function h(e,t){let n={};for(let t in e){let r=e[t];n[t]=f.hex(r)}if(t)for(let t in e){let r=e[t],i=`bg${t.slice(0,1).toUpperCase()}${t.slice(1)}`;n[i]=f.hex(r)}return p(()=>({...n}))}export{a as ansiLowerCase,o as ansiUpperCase,s as areColoursSupported,m as box,p as extend,f as fmt,h as fromColObject,e as getColourLevel,t as hasNoColour,c as stripAnsi,l as supports,u as supportsAtMost,d as transformPreserveAnsi};
1
+ function e(e){if(typeof globalThis.process?.env==`object`)return globalThis.process.env[e];if(typeof globalThis.Deno?.env?.get==`function`)try{return globalThis.Deno.env.get(e)}catch{return}}function t(){if(globalThis.process?.stdout?.isTTY)return!0;if(typeof globalThis.Deno?.stdout?.isTerminal==`function`)try{return globalThis.Deno.stdout?.isTerminal()}catch{return!1}return!1}function n(){let t=e(`NO_COLOR`)||e(`NODE_DISABLE_COLORS`);return t!==void 0&&t!==``}function r(){if(n())return 0;let r=e(`FORCE_COLOR`);if(r!==void 0)return r===`0`?0:r===`1`?1:r===`2`?2:r===`3`?3:1;if(!t())return e(`CI`)&&(e(`GITHUB_ACTIONS`)||e(`GITLAB_CI`))?1:0;let i=e(`TERM`);if(i===`dumb`)return 0;let a=e(`COLORTERM`);return a===`truecolor`||a===`24bit`||e(`TERM_PROGRAM`)===`vscode`?3:i&&/-256(color)?$/i.test(i)||e(`TERM_PROGRAM`)===`Apple_Terminal`?2:(i&&/color|ansi|cygwin|linux/i.test(i),1)}const i=/^#?([a-f\d]{3}|[a-f\d]{6})$/i;function a(e,t,n){return Math.min(Math.max(e,t),n)}function o(e,t){if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.min(Math.floor(n),e.length-2),i=n-r,a=e[r],o=e[r+1];return[Math.round(a[0]+(o[0]-a[0])*i),Math.round(a[1]+(o[1]-a[1])*i),Math.round(a[2]+(o[2]-a[2])*i)]}function s(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function c(e){let t=i.exec(e);if(!t)return[255,255,255];let n=t[1].replace(/^#/,``),r=3^n.length?n:n.split(``).map(e=>e+e).join(``),a=parseInt(r,16);return[a>>16&255,a>>8&255,a&255]}function l([e,t,n]){return e^t||t^n?16+36*Math.round(e/51)+6*Math.round(t/51)+Math.round(n/51):e<8?16:e>248?231:Math.round((e-8)*24/247)+232}function u(e){if(e<8)return 30+e;if(e<16)return 82+e;let t,n,r;if(e<232){let i=e-16,a=i%36;t=(i/36|0)/5,n=(a/6|0)/5,r=a%6/5}else t=n=r=((e-232)*10+8)/255;let i=Math.max(t,n,r)*2,a=Math.round(t),o=Math.round(n)<<1,s=Math.round(r)<<2,c=2^i?0:60;return 30+(s|o|a)+c}function d(e){return`\x1b[${e}m`}function f(e,t,n){return e.indexOf(n)===-1?`${t}${e}${n}`:`${t}${e.replaceAll(n,n+t)}${n}`}const p={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],blink:[5,25],inverse:[7,27],overline:[53,55],hidden:[8,28],strike:[9,29],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],brightBlack:[90,39],grey:[90,39],gray:[90,39],brightRed:[91,39],brightGreen:[92,39],brightYellow:[93,39],brightBlue:[94,39],brightMagenta:[95,39],brightCyan:[96,39],brightWhite:[97,39],bgBrightBlack:[100,49],bgGrey:[100,49],bgGray:[100,49],bgBrightRed:[101,49],bgBrightGreen:[102,49],bgBrightYellow:[103,49],bgBrightBlue:[104,49],bgBrightMagenta:[105,49],bgBrightCyan:[106,49],bgBrightWhite:[107,49]};function m(e,t,n){let r=Array.from(e),i=r.length,a=t?.map(e=>typeof e==`string`?c(e):e),s=n?.map(e=>typeof e==`string`?c(e):e);return r.map((e,t)=>{let n=i>1?t/(i-1):0,r=``,c=``;if(a){let[e,t,i]=o(a,n);r+=`\x1b[38;2;${e};${t};${i}m`,c=`\x1B[39m`+c}if(s){let[e,t,i]=o(s,n);r+=`\x1b[48;2;${e};${t};${i}m`,c=`\x1B[49m`+c}return r+e+c}).join(``)}function h(e){return e.type===`fg`?_(e.code,`fg`):e.type===`bg`?_(e.code,`bg`):e.type===`hex`?y(e.hex,`fg`):e.type===`bgHex`?y(e.hex,`bg`):e.type===`rgb`?v([e.r,e.g,e.b],`fg`):e.type===`bgRgb`?v([e.r,e.g,e.b],`bg`):[``,``]}function g(e,t){let n=t.filter(e=>typeof e!=`string`&&(e.type===`gradient`||e.type===`bgGradient`)),r=n.filter(e=>e.type===`gradient`).at(-1),i=n.filter(e=>e.type===`bgGradient`).at(-1);return t.reduce((t,n)=>{let a=r||i?m(e,r?.colours,i?.colours):t;if(typeof n==`string`)return f(a,d(p[n][0]),d(p[n][1]));{let[e,t]=h(n);return f(a,e,t)}},e)}function _(e,t){if(n()||r()===0)return[``,``];let i=a(e,0,255),o=d(t===`fg`?39:49);if(r()>=2)return[d(t===`fg`?`38;5;${i}`:`48;5;${i}`),o];{let e=u(i);return[d(t===`fg`?e:e+10),o]}}function v(e,t){if(n()||r()===0)return[``,``];let i=e.map(e=>a(e,0,255)),o=d(t===`fg`?39:49);if(r()===3){let e=i.join(`;`);return[d(t===`fg`?`38;2;${e}`:`48;2;${e}`),o]}if(r()===2){let e=l(i);return[d(t===`fg`?`38;5;${e}`:`48;5;${e}`),o]}{let n=u(l(e));return[d(t===`fg`?n:n+10),o]}}function y(e,t){return i.test(e)?v(c(e),t):[``,``]}function b(e,t){let n=`\x1B]8;;`;return`${n}${e}\\${t||e}${n}\\`}function x(e,t){return new Proxy(t=>g(t,e),{get(n,r){return r in p?x([...e,r],t):r===`fg`?n=>x([...e,{type:`fg`,code:n}],t):r===`bg`?n=>x([...e,{type:`bg`,code:n}],t):r===`hex`?n=>x([...e,{type:`hex`,hex:n}],t):r===`bgHex`?n=>x([...e,{type:`bgHex`,hex:n}],t):r===`rgb`?([n,r,i])=>x([...e,{type:`rgb`,r:n,g:r,b:i}],t):r===`bgRgb`?([n,r,i])=>x([...e,{type:`bgRgb`,r:n,g:r,b:i}],t):r===`gradient`?n=>x([...e,{type:`gradient`,colours:n}],t):r===`bgGradient`?n=>x([...e,{type:`bgGradient`,colours:n}],t):r===`link`?(t,n)=>b(t,g(n??t,e)):r===`text`?t=>g(t,e):r in t?n=>g(t[r](n),e):n[r]}})}const S=x([],{});function C(){return r()!==0}function w(e){return r()>=e}function T(e){return r()<=e}function E(e){return t=>{let n=/(\u{001B}\[[0-9;]*[A-PRZ])|(.+?)/giu,r=``;for(let i of t.matchAll(n)){let t=i[0];r+=t.charCodeAt(0)===27?t:e(t)}return r}}const D=E(e=>e.toUpperCase()),O=E(e=>e.toLowerCase());function k(e){return e.replace(/\u{001B}\[[0-9;]*m/gu,``)}const A={sharp:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`─`,v:`│`},rounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`│`},double:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`,h:`═`,v:`║`},heavy:{tl:`┏`,tr:`┓`,bl:`┗`,br:`┛`,h:`━`,v:`┃`},dashed:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`⹀`,v:`╎`},dotted:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`╌`,v:`┊`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`,h:`-`,v:`|`}};function j(e,t={}){let{kind:n=`sharp`,style:r=e=>e,padding:i=1,margin:a=0}=t,o=typeof n==`string`?A[n]:n,s=typeof i==`number`?Math.floor(i/4):i.top??0,c=typeof i==`number`?Math.floor(i/4):i.bottom??0,l=typeof a==`number`?Math.floor(a/4):a.top??0,u=typeof a==`number`?Math.floor(a/4):a.bottom??0,d=e.split(`
2
+ `),f=d.map(e=>k(e).length),p=Math.max(...f),m=o.tl+o.h.repeat(p+(typeof i==`number`?i*2:(i.left??0)+(i.right??0)))+o.tr,h=o.bl+o.h.repeat(p+(typeof i==`number`?i*2:(i.left??0)+(i.right??0)))+o.br,g=` `.repeat(typeof a==`number`?a:a.left??0),_=` `.repeat(typeof a==`number`?a:a.right??0),v=`
3
+ `.repeat(l),y=`
4
+ `.repeat(u),b=g+r(m)+_,x=g+r(h)+_,S=g+r(o.v),C=r(o.v)+_;return`${v}${b}\n${d.map(e=>{let t=k(e),n=e+` `.repeat(p-t.length),r=S+` `.repeat((typeof i==`number`?i*2:(i.left??0)+(i.right??0))+t.length)+C,a=i===0?``:`${r}\n`.repeat(s),o=i===0?``:`\n${r}`.repeat(c),l=` `.repeat(typeof i==`number`?i:i.left??0),u=` `.repeat(typeof i==`number`?i:i.right??0);return`${a}${S}${l}${n}${u}${C}${o}`}).join(`
5
+ `)}\n${x}${y}`}function M(e){if(Array.isArray(e)){let t={};for(let n of e)Object.assign(t,n(S));return x([],t)}return x([],e(S))}function N(e,t){let n=Object.entries(e).map(([e,t])=>[e,e=>S.hex(t).text(e)]),r=t?Object.entries(e).map(([e,t])=>[`bg${s(e)}`,e=>S.bgHex(t).text(e)]):null;return M(()=>Object.fromEntries([...n,...r??[]]))}export{O as ansiLowerCase,D as ansiUpperCase,C as areColoursSupported,j as box,M as extend,S as fmt,S as termark,N as fromColObject,r as getColorLevel,r as getColourLevel,n as hasNoColor,n as hasNoColour,b as link,k as stripAnsi,w as supports,T as supportsAtMost,E as transformPreserveAnsi};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "termark",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A basic library to format console output to the standard non-browser terminal.",
5
5
  "keywords": [
6
6
  "console",
@@ -12,6 +12,12 @@
12
12
  "homepage": "https://genesis.q-file.com/projects/termark",
13
13
  "license": "Apache-2.0",
14
14
  "author": "Miyazaki \"Q\" Hashimoto",
15
+ "contributors": [
16
+ {
17
+ "name": "Zoltán Miklós Ádám-Müller",
18
+ "email": "adam.muller.zoltan.miklos@proton.me"
19
+ }
20
+ ],
15
21
  "repository": {
16
22
  "type": "git",
17
23
  "url": "https://codeberg.org/Genesis_Software/termark.git"
@@ -27,25 +33,18 @@
27
33
  "require": "./dist/index.cjs"
28
34
  }
29
35
  },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
30
39
  "devDependencies": {
31
40
  "@types/node": "^24.3.0",
32
- "oxfmt": "^0.50.0",
33
- "oxlint": "^1.65.0",
34
- "tsdown": "^0.22.0",
35
- "tsx": "^4.22.0",
36
41
  "typescript": "^5.9.2",
37
- "vitest": "^4.1.6"
42
+ "vite-plus": "1.4.0"
38
43
  },
39
- "readme": "README.npm.md",
40
44
  "scripts": {
41
- "build": "tsdown --config .config/tsdown.config.ts",
42
- "format": "oxfmt --config .config/oxfmt.config.ts",
43
- "lint": "oxlint",
44
- "lint:fix": "oxlint --fix",
45
- "test": "vitest --config .config/vitest.config.ts",
46
- "demo:truecolor": "tsx examples/truecolor.ts",
47
- "demo:box": "tsx examples/box.ts",
48
- "demo:basic": "tsx examples/basic.ts",
49
- "demo:link": "tsx examples/link.ts"
45
+ "build": "vp pack",
46
+ "dev": "vp pack --watch",
47
+ "test": "vp test",
48
+ "check": "vp check"
50
49
  }
51
50
  }
package/README.npm.md DELETED
@@ -1,57 +0,0 @@
1
- <!-- NPM README file -->
2
-
3
- # Termark
4
-
5
- A basic library to format console output to the standard non-browser terminal.
6
-
7
- > _For full documentation, see [the repository](https://codeberg.org/Genesis_Software/termark)._
8
-
9
- ## Usage
10
-
11
- ### ESM & CJS compatibility
12
-
13
- Termark is compatible with both ESM and CJS:
14
-
15
- ```js
16
- // CJS:
17
- const { fmt } = require("termark");
18
-
19
- // ESM:
20
- import { fmt } from "termark";
21
- ```
22
-
23
- ### Basic example
24
-
25
- Most features of Termark are found in the `fmt` ("format") export:
26
-
27
- ```js
28
- import { fmt } from "termark";
29
-
30
- console.log(fmt.bold.blue("..."));
31
- ```
32
-
33
- ### Extensions
34
-
35
- Termark can be extended with custom methods via `extend`:
36
-
37
- ```js
38
- import { extend } from "termark";
39
-
40
- const myLib = extend((base) => ({
41
- orange: (str) => base.hex("#ffa500").text(str),
42
- }));
43
- ```
44
-
45
- **Note:** When modifying strings (e.g., `toUpperCase`), writing `str.toUpperCase` will make nesting not work. Instead, use `transformPreserveAnsi` or a function derived from it such as `ansiUpperCase` to transform strings so that nesting will work. Keep in mind that string transformations apply to nested strings as well.
46
-
47
- ```js
48
- import { extend, ansiUpperCase } from "termark";
49
-
50
- const myLib = extend((base) => ({
51
- shout: (str) => base.red.bold(ansiUpperCase(str)),
52
- }));
53
- ```
54
-
55
- ## Licence
56
-
57
- Termark's code is licenced under the [Apache licence version 2](https://www.apache.org/licenses/LICENSE-2.0).
@@ -1 +0,0 @@
1
- const e=require(`./util.cjs`);function t(t){let n=e.hexColourRegex.exec(t);if(!n)return[255,255,255];let r=n[1].replace(/^#/,``),i=3^r.length?r:r.split(``).map(e=>e+e).join(``),a=parseInt(i,16);return[a>>16&255,a>>8&255,a&255]}function n([e,t,n]){return e^t||t^n?16+36*Math.round(e/51)+6*Math.round(t/51)+Math.round(n/51):e<8?16:e>248?231:Math.round((e-8)*24/247)+232}function r(e){if(e<8)return 30+e;if(e<16)return 82+e;let t,n,r;if(e<232){let i=e-16,a=i%36;t=(i/36|0)/5,n=(a/6|0)/5,r=a%6/5}else t=n=r=((e-232)*10+8)/255;let i=Math.max(t,n,r)*2,a=Math.round(t),o=Math.round(n)<<1,s=Math.round(r)<<2,c=2^i?0:60;return 30+(s|o|a)+c}exports.ansi256To4bit=r,exports.hexToRgb=t,exports.rgbToAnsi256=n;
@@ -1 +0,0 @@
1
- import{hexColourRegex as e}from"./util.mjs";function t(t){let n=e.exec(t);if(!n)return[255,255,255];let r=n[1].replace(/^#/,``),i=3^r.length?r:r.split(``).map(e=>e+e).join(``),a=parseInt(i,16);return[a>>16&255,a>>8&255,a&255]}function n([e,t,n]){return e^t||t^n?16+36*Math.round(e/51)+6*Math.round(t/51)+Math.round(n/51):e<8?16:e>248?231:Math.round((e-8)*24/247)+232}function r(e){if(e<8)return 30+e;if(e<16)return 82+e;let t,n,r;if(e<232){let i=e-16,a=i%36;t=(i/36|0)/5,n=(a/6|0)/5,r=a%6/5}else t=n=r=((e-232)*10+8)/255;let i=Math.max(t,n,r)*2,a=Math.round(t),o=Math.round(n)<<1,s=Math.round(r)<<2,c=2^i?0:60;return 30+(s|o|a)+c}export{r as ansi256To4bit,t as hexToRgb,n as rgbToAnsi256};
@@ -1 +0,0 @@
1
- function e(e){if(typeof globalThis.process?.env==`object`)return globalThis.process.env[e];if(typeof globalThis.Deno?.env?.get==`function`)try{return globalThis.Deno.env.get(e)}catch{return}}function t(){if(globalThis.process?.stdout?.isTTY)return!0;if(typeof globalThis.Deno?.stdout?.isTerminal==`function`)try{return globalThis.Deno.stdout?.isTerminal()}catch{return!1}return!1}function n(){let t=e(`NO_COLOR`)||e(`NODE_DISABLE_COLORS`);return t!==void 0&&t!==``}function r(){if(n())return 0;let r=e(`FORCE_COLOR`);if(r!==void 0)return r===`0`?0:r===`1`?1:r===`2`?2:r===`3`?3:1;if(!t())return e(`CI`)&&(e(`GITHUB_ACTIONS`)||e(`GITLAB_CI`))?1:0;let i=e(`TERM`);if(i===`dumb`)return 0;let a=e(`COLORTERM`);return a===`truecolor`||a===`24bit`||e(`TERM_PROGRAM`)===`vscode`?3:i&&/-256(color)?$/i.test(i)||e(`TERM_PROGRAM`)===`Apple_Terminal`?2:(i&&/color|ansi|cygwin|linux/i.test(i),1)}exports.getColourLevel=r,exports.hasNoColour=n;
@@ -1,21 +0,0 @@
1
- import { ColourLevel } from "../types.mjs";
2
-
3
- //#region src/__internal/env.d.ts
4
- /**
5
- * Check whether `NO_COLOR` is an existing environment variable with any value that is not an empty string, thereby
6
- * disabling colours from being printed.
7
- *
8
- * This also checks the existence of the `NODE_DISABLE_COLORS` environment variable, behaving the same way if it
9
- * exists and not an empty string.
10
- *
11
- * @see https://no-color.org
12
- */
13
- declare function hasNoColour(): boolean;
14
- /**
15
- * Get the colour level of the terminal environment.
16
- *
17
- * @returns {@linkcode ColourLevel}
18
- */
19
- declare function getColourLevel(): ColourLevel;
20
- //#endregion
21
- export { getColourLevel, hasNoColour };
@@ -1 +0,0 @@
1
- function e(e){if(typeof globalThis.process?.env==`object`)return globalThis.process.env[e];if(typeof globalThis.Deno?.env?.get==`function`)try{return globalThis.Deno.env.get(e)}catch{return}}function t(){if(globalThis.process?.stdout?.isTTY)return!0;if(typeof globalThis.Deno?.stdout?.isTerminal==`function`)try{return globalThis.Deno.stdout?.isTerminal()}catch{return!1}return!1}function n(){let t=e(`NO_COLOR`)||e(`NODE_DISABLE_COLORS`);return t!==void 0&&t!==``}function r(){if(n())return 0;let r=e(`FORCE_COLOR`);if(r!==void 0)return r===`0`?0:r===`1`?1:r===`2`?2:r===`3`?3:1;if(!t())return e(`CI`)&&(e(`GITHUB_ACTIONS`)||e(`GITLAB_CI`))?1:0;let i=e(`TERM`);if(i===`dumb`)return 0;let a=e(`COLORTERM`);return a===`truecolor`||a===`24bit`||e(`TERM_PROGRAM`)===`vscode`?3:i&&/-256(color)?$/i.test(i)||e(`TERM_PROGRAM`)===`Apple_Terminal`?2:(i&&/color|ansi|cygwin|linux/i.test(i),1)}export{r as getColourLevel,n as hasNoColour};
@@ -1 +0,0 @@
1
- function e(e){return`\x1b[${e}m`}function t(e,t,n){return e.indexOf(n)===-1?`${t}${e}${n}`:`${t}${e.replaceAll(n,n+t)}${n}`}exports.formatForNesting=t,exports.toFormatter=e;
@@ -1 +0,0 @@
1
- function e(e){return`\x1b[${e}m`}function t(e,t,n){return e.indexOf(n)===-1?`${t}${e}${n}`:`${t}${e.replaceAll(n,n+t)}${n}`}export{t as formatForNesting,e as toFormatter};
@@ -1 +0,0 @@
1
- const e=require(`./format.cjs`),t=require(`./env.cjs`),n=require(`./styling.cjs`);var r=class n{constructor(e=[],t){this.$styles=[],this.$styles=e,t&&(this.$pending=t)}apply(t){return this.$styles.reduce((t,n)=>typeof n==`function`?n(t):e.formatForNesting(t,n.open.charCodeAt(0)===27?n.open:e.toFormatter(n.open),n.close.charCodeAt(0)===27?n.close:e.toFormatter(n.close)),t)}call(e){if(typeof e!=`string`)throw TypeError(`[Termark :: TypeError] Styling can be applied to strings only`);return(this.$pending??(e=>e))(this.apply(e))}get terminator(){let e=this.$pending??(e=>e);return t=>e(this.apply(t))}get link(){return t.hasNoColour()?(e,t)=>t===e?e:`${t} (${e})`:(e,t)=>{let n=`\x1B]8;;`,r=`${n}${e}\\${t||e}${n}\\`;return this.apply(r)}}add(e){return new n(this.$pending?[...this.$styles,this.$pending,e]:[...this.$styles,e])}setPending(e){return this.$pending?new n([...this.$styles,this.$pending],e):new n(this.$styles,e)}};function i(e,t={}){return new Proxy(t=>e.call(t),{get(r,a){if(a in n.BUILT_INS){let[r,o]=n.BUILT_INS[a],s={open:String(r),close:String(o)};return i(e.add(s),t)}if(a===`fg`)return t=>i(e.setPending(n.$ansi256(t,`fg`)));if(a===`bg`)return t=>i(e.setPending(n.$ansi256(t,`bg`)));if(a===`hex`)return r=>i(e.setPending(n.$hex(r,`fg`)),t);if(a===`rgb`)return r=>i(e.setPending(n.$rgb(r,`fg`)),t);if(a===`gradient`)return(...r)=>i(e.setPending(n.$gradient(r,`fg`)),t);if(a===`bgHex`)return r=>i(e.setPending(n.$hex(r,`bg`)),t);if(a===`bgRgb`)return r=>i(e.setPending(n.$rgb(r,`bg`)),t);if(a===`bgGradient`)return(...r)=>i(e.setPending(n.$gradient(r,`bg`)),t);if(a===`link`)return e.link;if(a in t)return i(e.add(t[a]),t);if(a===`text`)return e.terminator;throw Error(`[Termark :: Error] Unknown style ${a}`)},apply(t,n,r){return e.call(r[0])}})}exports.TermarkImpl=r,exports.createProxy=i;
@@ -1 +0,0 @@
1
- import{formatForNesting as e,toFormatter as t}from"./format.mjs";import{hasNoColour as n}from"./env.mjs";import{$ansi256 as r,$gradient as i,$hex as a,$rgb as o,BUILT_INS as s}from"./styling.mjs";var c=class r{constructor(e=[],t){this.$styles=[],this.$styles=e,t&&(this.$pending=t)}apply(n){return this.$styles.reduce((n,r)=>typeof r==`function`?r(n):e(n,r.open.charCodeAt(0)===27?r.open:t(r.open),r.close.charCodeAt(0)===27?r.close:t(r.close)),n)}call(e){if(typeof e!=`string`)throw TypeError(`[Termark :: TypeError] Styling can be applied to strings only`);return(this.$pending??(e=>e))(this.apply(e))}get terminator(){let e=this.$pending??(e=>e);return t=>e(this.apply(t))}get link(){return n()?(e,t)=>t===e?e:`${t} (${e})`:(e,t)=>{let n=`\x1B]8;;`,r=`${n}${e}\\${t||e}${n}\\`;return this.apply(r)}}add(e){return new r(this.$pending?[...this.$styles,this.$pending,e]:[...this.$styles,e])}setPending(e){return this.$pending?new r([...this.$styles,this.$pending],e):new r(this.$styles,e)}};function l(e,t={}){return new Proxy(t=>e.call(t),{get(n,c){if(c in s){let[n,r]=s[c],i={open:String(n),close:String(r)};return l(e.add(i),t)}if(c===`fg`)return t=>l(e.setPending(r(t,`fg`)));if(c===`bg`)return t=>l(e.setPending(r(t,`bg`)));if(c===`hex`)return n=>l(e.setPending(a(n,`fg`)),t);if(c===`rgb`)return n=>l(e.setPending(o(n,`fg`)),t);if(c===`gradient`)return(...n)=>l(e.setPending(i(n,`fg`)),t);if(c===`bgHex`)return n=>l(e.setPending(a(n,`bg`)),t);if(c===`bgRgb`)return n=>l(e.setPending(o(n,`bg`)),t);if(c===`bgGradient`)return(...n)=>l(e.setPending(i(n,`bg`)),t);if(c===`link`)return e.link;if(c in t)return l(e.add(t[c]),t);if(c===`text`)return e.terminator;throw Error(`[Termark :: Error] Unknown style ${c}`)},apply(t,n,r){return e.call(r[0])}})}export{c as TermarkImpl,l as createProxy};
@@ -1 +0,0 @@
1
- const e=require(`./format.cjs`),t=require(`./env.cjs`),n=require(`./util.cjs`),r=require(`./conversion.cjs`),i={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],blink:[5,25],inverse:[7,27],overline:[53,55],hidden:[8,28],strike:[9,29],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],brightBlack:[90,39],grey:[90,39],gray:[90,39],brightRed:[91,39],brightGreen:[92,39],brightYellow:[93,39],brightBlue:[94,39],brightMagenta:[95,39],brightCyan:[96,39],brightWhite:[97,39],bgBrightBlack:[100,49],bgGrey:[100,49],bgGray:[100,49],bgBrightRed:[101,49],bgBrightGreen:[102,49],bgBrightYellow:[103,49],bgBrightBlue:[104,49],bgBrightMagenta:[105,49],bgBrightCyan:[106,49],bgBrightWhite:[107,49]},a={sharp:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`─`,v:`│`},rounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`│`},double:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`,h:`═`,v:`║`},heavy:{tl:`┏`,tr:`┓`,bl:`┗`,br:`┛`,h:`━`,v:`┃`},dashed:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`⹀`,v:`╎`},dotted:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`╌`,v:`┊`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`,h:`-`,v:`|`}};function o(n,i){let a;if(t.getColourLevel()===3){let t=n.join(`;`);a=e.toFormatter(i===`fg`?`38;2;${t}`:`48;2;${t}`)}else if(t.getColourLevel()===2){let t=r.rgbToAnsi256(n);a=e.toFormatter(i===`fg`?`38;5;${t}`:`48;5;${t}`)}else{let t=r.ansi256To4bit(r.rgbToAnsi256(n));a=e.toFormatter(i===`fg`?t:t+10)}return a}function s(r,i){if(t.hasNoColour()||t.getColourLevel()===0)return e=>e;let a=o(r.map(e=>n.clamp(e,0,255)),i),s=e.toFormatter(i===`fg`?39:49);return t=>e.formatForNesting(t,a,s)}function c(e,t){return n.hexColourRegex.test(e)?s(r.hexToRgb(e),t):e=>e}function l(i,a){return t.hasNoColour()||t.getColourLevel()===0||i.length===0?e=>e:i.length===1?i.every(e=>typeof e==`string`)?c(i[0],a):s(i[0],a):t=>{let s=i.every(e=>typeof e==`string`)?i.map(e=>r.hexToRgb(e)):i,c=s.length,l=Math.min(t.length/(c-1)),u=``,d=e.toFormatter(a===`fg`?39:49);for(let e=0;e<t.length;e++){let r=Math.min(Math.floor(e/l),c-2),i=e%l/l,f=s[r],p=s[r+1],[m,h,g]=n.interpolate(f,p,i),_=o([m,h,g],a);u+=`${_}${t[e]}${d}`}return u}}function u(i,a){if(t.hasNoColour()||t.getColourLevel()===0)return e=>e;let o=n.clamp(i,0,255),s;if(t.getColourLevel()>=2)s=e.toFormatter(a===`fg`?`38;5;${o}`:`48;5;${o}`);else{let t=r.ansi256To4bit(o);s=e.toFormatter(a===`fg`?t:t+10)}let c=e.toFormatter(a===`fg`?39:49);return t=>e.formatForNesting(t,s,c)}exports.$ansi256=u,exports.$gradient=l,exports.$hex=c,exports.$rgb=s,exports.BOX_BORDERS=a,exports.BUILT_INS=i;
@@ -1,115 +0,0 @@
1
- //#region src/__internal/styling.d.ts
2
- /**
3
- * Built-in styles.
4
- */
5
- declare const BUILT_INS: {
6
- readonly reset: readonly [0, 0];
7
- readonly bold: readonly [1, 22];
8
- readonly dim: readonly [2, 22];
9
- readonly italic: readonly [3, 23];
10
- readonly underline: readonly [4, 24];
11
- readonly blink: readonly [5, 25];
12
- readonly inverse: readonly [7, 27];
13
- readonly overline: readonly [53, 55];
14
- readonly hidden: readonly [8, 28];
15
- readonly strike: readonly [9, 29];
16
- readonly black: readonly [30, 39];
17
- readonly red: readonly [31, 39];
18
- readonly green: readonly [32, 39];
19
- readonly yellow: readonly [33, 39];
20
- readonly blue: readonly [34, 39];
21
- readonly magenta: readonly [35, 39];
22
- readonly cyan: readonly [36, 39];
23
- readonly white: readonly [37, 39];
24
- readonly bgBlack: readonly [40, 49];
25
- readonly bgRed: readonly [41, 49];
26
- readonly bgGreen: readonly [42, 49];
27
- readonly bgYellow: readonly [43, 49];
28
- readonly bgBlue: readonly [44, 49];
29
- readonly bgMagenta: readonly [45, 49];
30
- readonly bgCyan: readonly [46, 49];
31
- readonly bgWhite: readonly [47, 49];
32
- readonly brightBlack: readonly [90, 39];
33
- readonly grey: readonly [90, 39];
34
- readonly gray: readonly [90, 39];
35
- readonly brightRed: readonly [91, 39];
36
- readonly brightGreen: readonly [92, 39];
37
- readonly brightYellow: readonly [93, 39];
38
- readonly brightBlue: readonly [94, 39];
39
- readonly brightMagenta: readonly [95, 39];
40
- readonly brightCyan: readonly [96, 39];
41
- readonly brightWhite: readonly [97, 39];
42
- readonly bgBrightBlack: readonly [100, 49];
43
- readonly bgGrey: readonly [100, 49];
44
- readonly bgGray: readonly [100, 49];
45
- readonly bgBrightRed: readonly [101, 49];
46
- readonly bgBrightGreen: readonly [102, 49];
47
- readonly bgBrightYellow: readonly [103, 49];
48
- readonly bgBrightBlue: readonly [104, 49];
49
- readonly bgBrightMagenta: readonly [105, 49];
50
- readonly bgBrightCyan: readonly [106, 49];
51
- readonly bgBrightWhite: readonly [107, 49];
52
- };
53
- /**
54
- * Styles for the borders of {@linkcode box}.
55
- */
56
- declare const BOX_BORDERS: {
57
- readonly sharp: {
58
- readonly tl: "┌";
59
- readonly tr: "┐";
60
- readonly bl: "└";
61
- readonly br: "┘";
62
- readonly h: "─";
63
- readonly v: "│";
64
- };
65
- readonly rounded: {
66
- readonly tl: "╭";
67
- readonly tr: "╮";
68
- readonly bl: "╰";
69
- readonly br: "╯";
70
- readonly h: "─";
71
- readonly v: "│";
72
- };
73
- readonly double: {
74
- readonly tl: "╔";
75
- readonly tr: "╗";
76
- readonly bl: "╚";
77
- readonly br: "╝";
78
- readonly h: "═";
79
- readonly v: "║";
80
- };
81
- readonly heavy: {
82
- readonly tl: "┏";
83
- readonly tr: "┓";
84
- readonly bl: "┗";
85
- readonly br: "┛";
86
- readonly h: "━";
87
- readonly v: "┃";
88
- };
89
- readonly dashed: {
90
- readonly tl: "┌";
91
- readonly tr: "┐";
92
- readonly bl: "└";
93
- readonly br: "┘";
94
- readonly h: "⹀";
95
- readonly v: "╎";
96
- };
97
- readonly dotted: {
98
- readonly tl: "┌";
99
- readonly tr: "┐";
100
- readonly bl: "└";
101
- readonly br: "┘";
102
- readonly h: "╌";
103
- readonly v: "┊";
104
- };
105
- readonly ascii: {
106
- readonly tl: "+";
107
- readonly tr: "+";
108
- readonly bl: "+";
109
- readonly br: "+";
110
- readonly h: "-";
111
- readonly v: "|";
112
- };
113
- };
114
- //#endregion
115
- export { BOX_BORDERS, BUILT_INS };
@@ -1 +0,0 @@
1
- import{formatForNesting as e,toFormatter as t}from"./format.mjs";import{getColourLevel as n,hasNoColour as r}from"./env.mjs";import{clamp as i,hexColourRegex as a,interpolate as o}from"./util.mjs";import{ansi256To4bit as s,hexToRgb as c,rgbToAnsi256 as l}from"./conversion.mjs";const u={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],blink:[5,25],inverse:[7,27],overline:[53,55],hidden:[8,28],strike:[9,29],black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],brightBlack:[90,39],grey:[90,39],gray:[90,39],brightRed:[91,39],brightGreen:[92,39],brightYellow:[93,39],brightBlue:[94,39],brightMagenta:[95,39],brightCyan:[96,39],brightWhite:[97,39],bgBrightBlack:[100,49],bgGrey:[100,49],bgGray:[100,49],bgBrightRed:[101,49],bgBrightGreen:[102,49],bgBrightYellow:[103,49],bgBrightBlue:[104,49],bgBrightMagenta:[105,49],bgBrightCyan:[106,49],bgBrightWhite:[107,49]},d={sharp:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`─`,v:`│`},rounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`│`},double:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`,h:`═`,v:`║`},heavy:{tl:`┏`,tr:`┓`,bl:`┗`,br:`┛`,h:`━`,v:`┃`},dashed:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`⹀`,v:`╎`},dotted:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`╌`,v:`┊`},ascii:{tl:`+`,tr:`+`,bl:`+`,br:`+`,h:`-`,v:`|`}};function f(e,r){let i;if(n()===3){let n=e.join(`;`);i=t(r===`fg`?`38;2;${n}`:`48;2;${n}`)}else if(n()===2){let n=l(e);i=t(r===`fg`?`38;5;${n}`:`48;5;${n}`)}else{let n=s(l(e));i=t(r===`fg`?n:n+10)}return i}function p(a,o){if(r()||n()===0)return e=>e;let s=f(a.map(e=>i(e,0,255)),o),c=t(o===`fg`?39:49);return t=>e(t,s,c)}function m(e,t){return a.test(e)?p(c(e),t):e=>e}function h(e,i){return r()||n()===0||e.length===0?e=>e:e.length===1?e.every(e=>typeof e==`string`)?m(e[0],i):p(e[0],i):n=>{let r=e.every(e=>typeof e==`string`)?e.map(e=>c(e)):e,a=r.length,s=Math.min(n.length/(a-1)),l=``,u=t(i===`fg`?39:49);for(let e=0;e<n.length;e++){let t=Math.min(Math.floor(e/s),a-2),c=e%s/s,d=r[t],p=r[t+1],[m,h,g]=o(d,p,c),_=f([m,h,g],i);l+=`${_}${n[e]}${u}`}return l}}function g(a,o){if(r()||n()===0)return e=>e;let c=i(a,0,255),l;if(n()>=2)l=t(o===`fg`?`38;5;${c}`:`48;5;${c}`);else{let e=s(c);l=t(o===`fg`?e:e+10)}let u=t(o===`fg`?39:49);return t=>e(t,l,u)}export{g as $ansi256,h as $gradient,m as $hex,p as $rgb,d as BOX_BORDERS,u as BUILT_INS};
@@ -1 +0,0 @@
1
- const e=/^#?([a-f\d]{3}|[a-f\d]{6})$/i;function t(e,t,n){return Math.min(Math.max(e,t),n)}function n(e,t,n){return[Math.round(e[0]+n*(t[0]-e[0])),Math.round(e[1]+n*(t[1]-e[1])),Math.round(e[2]+n*(t[2]-e[2]))]}exports.clamp=t,exports.hexColourRegex=e,exports.interpolate=n;
@@ -1 +0,0 @@
1
- const e=/^#?([a-f\d]{3}|[a-f\d]{6})$/i;function t(e,t,n){return Math.min(Math.max(e,t),n)}function n(e,t,n){return[Math.round(e[0]+n*(t[0]-e[0])),Math.round(e[1]+n*(t[1]-e[1])),Math.round(e[2]+n*(t[2]-e[2]))]}export{t as clamp,e as hexColourRegex,n as interpolate};
package/dist/types.d.mts DELETED
@@ -1,279 +0,0 @@
1
- import { BOX_BORDERS, BUILT_INS } from "./__internal/styling.mjs";
2
-
3
- //#region src/types.d.ts
4
- /**
5
- * Array with red, green, and blue colour values.
6
- */
7
- type RGB = [number, number, number];
8
- /**
9
- * A number representing the supported colour level.
10
- *
11
- * - `0` — No colours, just black-and-white text.
12
- * - `1` — Basic 4-bit (16) colours.
13
- * - `2` — 8-bit (256) colours.
14
- * - `3` — 24-bit (16m; `truecolor`) colours.
15
- */
16
- type ColourLevel = 0 | 1 | 2 | 3;
17
- /**
18
- * How an ANSI code (e.g., the code for making text bold) can be represented.
19
- *
20
- * `string | number` allow single numbers such as `21`, but also complex codes like `38;5;203`, which are
21
- * not representable by a number alone.
22
- */
23
- type ANSICode = string | number;
24
- interface TermarkToJSONReturn {
25
- text: string;
26
- openingCodes: string[];
27
- closingCodes: string[];
28
- }
29
- type StyleFn = (str: string) => string;
30
- interface StyleElement {
31
- open: string;
32
- close: string;
33
- }
34
- /**
35
- * Base built-in methods like `red` or `bold`.
36
- */
37
- type BuiltIn = keyof typeof BUILT_INS;
38
- /**
39
- * Methods that terminate a styling sequence.
40
- */
41
- interface Terminator {
42
- /**
43
- * Return a string that has been styled. Useful for methods like `hex` or `gradient`.
44
- *
45
- * @param str An input string.
46
- */
47
- text(str: string): string;
48
- }
49
- /**
50
- * Styling functions that take parameters.
51
- */
52
- interface ParamStyling {
53
- /**
54
- * Colour some text using a hex colour code.
55
- *
56
- * @example
57
- * ```ts
58
- * import { fmt } from "termark";
59
- *
60
- * const customHex = fmt.hex("#338cd1").text("Text");
61
- * ```
62
- *
63
- * @example Without leading hash (`#`)
64
- * ```ts
65
- * import { fmt } from "termark";
66
- *
67
- * const customHex = fmt.hex("008330").text("Text");
68
- * ```
69
- *
70
- * @param code A hex colour code.
71
- */
72
- hex(code: string): TermarkAPI;
73
- /**
74
- * Colour some text using red, green, and blue colour values.
75
- *
76
- * Each passed value is clamped so that values less than `0` are treated as `0` and values greater than `255` are
77
- * treated as `255`.
78
- *
79
- * @example
80
- * ```ts
81
- * import { fmt } from "termark";
82
- *
83
- * const rgbString = fmt.rgb([128, 5, 243]).text("Text");
84
- * ```
85
- *
86
- * @param colours An array of red, green, and blue colour values.
87
- */
88
- rgb(colours: RGB): TermarkAPI;
89
- /**
90
- * Make some text have a gradient.
91
- *
92
- * @example With hex colour codes
93
- * ```ts
94
- * import { fmt } from "termark";
95
- *
96
- * const textWithGradient = fmt.gradient("#80b3ff", "#338cd1").text("Text");
97
- * ```
98
- *
99
- * @example With RGB values
100
- * ```ts
101
- * import { fmt } from "termark";
102
- *
103
- * const textWithGradient = fmt.gradient([128, 179, 255], [51, 140, 209]).text("Text");
104
- * ```
105
- *
106
- * @param colours Colours for the gradient, either as hex colour codes or as RGB tuples (arrays).
107
- */
108
- gradient(...colours: string[] | RGB[]): TermarkAPI;
109
- /**
110
- * Use an ANSI number code to apply a specific colour to some text.
111
- *
112
- * This value is clamped so that values less than `0` are treated as `0` while values greater than `255` are treated
113
- * as `255`.
114
- *
115
- * @example
116
- * ```ts
117
- * import { fmt } from "termark";
118
- *
119
- * const ansi = fmt.fg(57).text("Text");
120
- * ```
121
- *
122
- * @param code An ANSI code for 8-bit colours.
123
- *
124
- * @see https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
125
- */
126
- fg(code: number): TermarkAPI;
127
- /**
128
- * Colour the background of some text using a hex colour code.
129
- *
130
- * @example
131
- * ```ts
132
- * import { fmt } from "termark";
133
- *
134
- * const customHex = fmt.bgHex("#338cd1").text("Text");
135
- * ```
136
- *
137
- * @example Without leading hash (`#`)
138
- * ```ts
139
- * import { fmt } from "termark";
140
- *
141
- * const customHex = fmt.bgHex("008330").text("Text");
142
- * ```
143
- *
144
- * @param code A hex colour code.
145
- */
146
- bgHex(code: string): TermarkAPI;
147
- /**
148
- * Colour the background of some text using red, green, and blue colour values.
149
- *
150
- * Each passed value is clamped so that values less than `0` are treated as `0` and values greater than `255` are
151
- * treated as `255`.
152
- *
153
- * @example
154
- * ```ts
155
- * import { fmt } from "termark";
156
- *
157
- * const rgbString = fmt.bgRgb([128, 5, 243]).text("Text");
158
- * ```
159
- *
160
- * @param colours An array of red, green, and blue colour values.
161
- */
162
- bgRgb(colours: RGB): TermarkAPI;
163
- /**
164
- * Make the background of some text have a gradient.
165
- *
166
- * @example With hex colour codes
167
- * ```ts
168
- * import { fmt } from "termark";
169
- *
170
- * const textWithGradient = fmt.bgGradient("#80b3ff", "#338cd1").text("Text");
171
- * ```
172
- *
173
- * @example With RGB values
174
- * ```ts
175
- * import { fmt } from "termark";
176
- *
177
- * const textWithGradient = fmt.bgGradient([128, 179, 255], [51, 140, 209]).text("Text");
178
- * ```
179
- *
180
- * @param colours Colours for the gradient, either as hex colour codes or as RGB tuples (arrays).
181
- */
182
- bgGradient(...colours: string[] | RGB[]): TermarkAPI;
183
- /**
184
- * Use an ANSI number code to apply a specific colour to the background of some text.
185
- *
186
- * This value is clamped so that values less than `0` are treated as `0` while values greater than `255` are treated
187
- * as `255`.
188
- *
189
- * @example
190
- * ```ts
191
- * import { fmt } from "termark";
192
- *
193
- * const ansi = fmt.bg(57).text("Text");
194
- * ```
195
- *
196
- * @param code An ANSI code for 8-bit colours.
197
- *
198
- * @see https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
199
- */
200
- bg(code: number): TermarkAPI;
201
- }
202
- type LinkFn = (url: string, text?: string) => string;
203
- /**
204
- * Miscellaneous features that don't fit other category.
205
- */
206
- interface MiscellaneousFns {
207
- /**
208
- * Construct an OSC 8 hyperlink by specifying a URL and optionally text to display.
209
- *
210
- * `link` acts as a style chain terminator and is called as the last element of such a chain.
211
- *
212
- * [OSC 8](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) may not be supported in all terminal
213
- * environments. See ["OSC 8 adoption in terminal emulators"](https://github.com/Alhadis/OSC8-Adoption/) for a list
214
- * of terminals that support OSC 8 hyperlinks. In terminals where OSC 8 hyperlinks aren't supported, the URL will
215
- * be shown as-is, along with the display text (if one was provided).
216
- *
217
- * @example
218
- * ```ts
219
- * import { fmt } from "termark";
220
- *
221
- * const plainLink = fmt.link("https://q-file.com");
222
- *
223
- * const styledLink = fmt.red.underline.link("https://q-file.com", "Website");
224
- * ```
225
- *
226
- * @param url A URL to some resource, which can be a webpage (`http://`, `https://`), a local file (`file://`), an
227
- * email address (`mailto:`), an FTP connection (`ftp://`), etc.
228
- * @param text An optional text to display. If omitted, `url` will be displayed.
229
- *
230
- * @see https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
231
- * @see https://notes.billmill.org/programming/bash/Hyperlink_escape_codes.html
232
- */
233
- link: LinkFn;
234
- }
235
- /**
236
- * The API provided by Termark, including all built-in functions as well as user-created extensions.
237
- */
238
- type TermarkAPI<Ext extends Record<string, any> = {}> = { [K in BuiltIn]: TermarkAPI<Ext> } & Ext & StyleFn & Terminator & ParamStyling & MiscellaneousFns;
239
- /**
240
- * Configuration options for {@linkcode box}.
241
- */
242
- interface BoxOptions {
243
- /**
244
- * @default "sharp"
245
- */
246
- kind?: keyof typeof BOX_BORDERS;
247
- /**
248
- * Styling to apply to the border such as making it blue.
249
- *
250
- * @default (str) => str
251
- */
252
- style?: StyleFn;
253
- /**
254
- * Padding to apply. Top-bottom padding will always be a quarter of left-right padding (that is, top-bottom padding
255
- * will increase by one for every four padding units).
256
- *
257
- * @default 0
258
- */
259
- padding?: number;
260
- /**
261
- * Spacing around the box. Top-bottom margin will always be a quarter of left-right margin (that is, top-bottom
262
- * margin will increase by one for every four margin units).
263
- *
264
- * @default 0
265
- */
266
- margin?: number;
267
- }
268
- /**
269
- * Object type to be passed into {@linkcode fromColObject}.
270
- *
271
- * Represents an object literal whose keys are colour names and whose values are hex colour codes.
272
- */
273
- type ColourObject = Record<string, string>;
274
- /**
275
- * The return-value of {@linkcode fromColObject}.
276
- */
277
- type FromColObjectReturn<R extends ColourObject, GenBg extends boolean | undefined> = { [K in keyof R as K | (GenBg extends true ? `bg${Capitalize<K & string>}` : never)]: StyleFn };
278
- //#endregion
279
- export { ANSICode, BoxOptions, BuiltIn, ColourLevel, ColourObject, FromColObjectReturn, LinkFn, MiscellaneousFns, ParamStyling, RGB, StyleElement, StyleFn, TermarkAPI, TermarkToJSONReturn, Terminator };
@@ -1 +0,0 @@
1
- const e=require(`./__internal/env.cjs`);function t(){return e.getColourLevel()!==0}function n(t){return e.getColourLevel()>=t}function r(t){return e.getColourLevel()<=t}function i(e){return t=>{let n=/(\u{001B}\[[0-9;]*[A-PRZ])|(.+?)/giu,r=``;for(let i of t.matchAll(n)){let t=i[0];r+=t.charCodeAt(0)===27?t:e(t)}return r}}const a=i(e=>e.toUpperCase()),o=i(e=>e.toLowerCase());function s(e){return e.replace(/\u{001B}\[[0-9;]*m/gu,``)}exports.ansiLowerCase=o,exports.ansiUpperCase=a,exports.areColoursSupported=t,exports.stripAnsi=s,exports.supports=n,exports.supportsAtMost=r,exports.transformPreserveAnsi=i;