termark 2.0.0 → 3.0.0

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/README.md CHANGED
@@ -1,259 +1,180 @@
1
- # ![Termark](https://static.q-file.com/projects/termark/termark.svg)
2
-
3
- Termark is a basic library to format console output to the standard non-browser terminal.
4
-
5
- ## Features & Highlights
6
-
7
- - Zero dependencies
8
- - [ESM & CJS compatible](#esm--cjs-compatibility)
9
- - [NO_COLOR](https://no-color.org/)-friendly
10
- - [Default and named imports]
11
- - [Basic ANSI styling](#basic-ansi-styling) (`dim`, `bold`, `italic`, …)
12
- - [4-bit](#4-bit-colours) ($2^4 = 16$) colours (`red`, `cyan`, `blueBright`, …)
13
- - [8-bit](#8-bit-colours) ($2^8 = 256$) colours (`ansi256()`)
14
- - [24-bit](#24-bit-colours) ($2^{24} = 16777216$; `truecolor`) colours (`rgb()`)
15
- - [Gradients](#gradients) (`gradient()`)
16
- - Built-in [terminal logging methods](#built-in-terminal-logging-methods) (`success()`, `info()`, `warn()`, `error()`)
17
- - [Template strings](#template-strings) & [nested styles](#nested-styles) (``` green`Success: File ${cyan`plans.txt`} created successfully!` ```)
18
- - [Colour-detection utilities](#colour-detection-utilities) (`areColorsEnabled`, `is8bitEnabled`, `is24bitEnabled`)
19
- - [Usage as an object or as a class](#class-v-object)
20
-
21
- ## Installation
22
-
23
- ```bash
24
- npm install termark
25
- ```
26
-
27
- ## ESM & CJS compatibility
28
-
29
- Termark is compatible with both ECMAScript modules (`import`/`export` syntax), and CommonJS:
30
-
31
- ```js
32
- // CJS:
33
- const termark = require('termark');
34
-
35
- // ESM:
36
- import termark from 'termark';
37
- ```
38
-
39
- ## Default & named imports
40
-
41
- Termark offers both a default import that has access to all properties and methods, or you can import each one individually:
42
-
43
- ```ts
44
- // Default import:
45
- import termark from 'termark';
46
-
47
- termark.info('This is the default import, where all properties and methods are accessible.');
48
-
49
- // Named imports:
50
- import { success, inverse } from 'termark';
51
-
52
- success(
53
- inverse('This text with a green background is achieved with named imports!')
54
- )
55
- ```
56
-
57
- ## Usage
58
-
59
- Here's a quick reference for every feature Termark provides:
60
-
61
- ```ts
62
- import termark from 'termark';
63
-
64
- console.log(
65
- termark.red('This is red text.'),
66
- termark.bgGreen('This text has a green background.'),
67
- termark.cyan`There's support for template strings as well`,
68
- termark.ansi256('text', 33)('This single function handles text and background colour!'),
69
- termark.rgb('background', 42, 122, 255)('This is some dark blue text'),
70
- termark.gradient('text', [[53, 72, 172], [200, 230, 121]])('Gradients are also possible.'),
71
- termark.areColorsEnabled,
72
- termark.is8bitEnabled,
73
- termark.is24bitEnabled
74
- );
75
- ```
76
-
77
- ### Basic ANSI styling
78
-
79
- ```ts
80
- import termark from 'termark';
81
-
82
- termark.reset('...');
83
- termark.bold('...');
84
- termark.dim('...');
85
- termark.italic('...');
86
- termark.underline('...');
87
- termark.blink('...');
88
- termark.inverse('...');
89
- termark.overline('...');
90
- termark.hidden('...');
91
- termark.strike('...');
92
- ```
93
-
94
- ### 4-bit colours
95
-
96
- ```ts
97
- import termark from 'termark';
98
-
99
- termark.black('...');
100
- termark.red('...');
101
- termark.green('...');
102
- termark.yellow('...');
103
- termark.blue('...');
104
- termark.magenta('...');
105
- termark.white('...');
106
-
107
- termark.blackBright('...');
108
- termark.redBright('...');
109
- termark.greenBright('...');
110
- termark.yellowBright('...');
111
- termark.blueBright('...');
112
- termark.magentaBright('...');
113
- termark.whiteBright('...');
114
-
115
- termark.bgBlack('...');
116
- termark.bgRed('...');
117
- termark.bgGreen('...');
118
- termark.bgYellow('...');
119
- termark.bgBlue('...');
120
- termark.bgMagenta('...');
121
- termark.bgWhite('...');
122
-
123
- termark.bgBlackBright('...');
124
- termark.bgRedBright('...');
125
- termark.bgGreenBright('...');
126
- termark.bgYellowBright('...');
127
- termark.bgBlueBright('...');
128
- termark.bgMagentaBright('...');
129
- termark.bgWhiteBright('...');
130
- ```
131
-
132
- ### 8-bit colours
133
-
134
- ```ts
135
- import termark from 'termark';
136
-
137
- termark.ansi256('text', 33)('...');
138
- termark.ansi256('background', 200)('...');
139
- ```
140
-
141
- ### 24-bit colours
142
-
143
- ```ts
144
- import termark from 'termark';
145
-
146
- // You can specify your RGB values as an array:
147
- termark.rgb('text', [182, 22, 234])('...');
148
- termark.rgb('background', [200, 0, 184])('...');
149
-
150
- // ...or as a simple list of three values:
151
- termark.rgb('text', 182, 22, 234)('...');
152
- termark.rgb('background', 200, 0, 184)('...');
153
-
154
-
155
- // This method is compatible with `color-convert`:
156
- import convert from 'color-convert';
157
-
158
- termark.rgb('text', convert.hex.rgb('008330'))('...');
159
- ```
160
-
161
- ### Gradients
162
-
163
- **Please note that gradients do not support nested styling.**
164
-
165
- ```ts
166
- import termark from 'termark';
167
-
168
- termark.gradient('text', [[200, 123, 0], [0, 255, 255], [177, 209, 10]])('...');
169
- termark.gradient('background', [[123, 75, 204], [255, 255, 255], [0, 44, 55]])('...');
170
- ```
171
-
172
- ### Built-in terminal logging methods
173
-
174
- ```ts
175
- import termark from 'termark';
176
-
177
- termark.success('...'); // Logs some message in green as an info message.
178
- termark.info('...'); // Logs some message in blue as an info message.
179
- termark.warning('...'); // Logs some message in yellow as a warning.
180
- termark.error('...'); // Logs some message in red as an error.
181
-
182
- // These also support prefixes for branding purposes:
183
-
184
- const brandPrefix = termark.blue('Example') + termark.blackBright(' - ');
185
-
186
- termark.error('File not found', brandPrefix);
187
- ```
188
-
189
- ### Template strings
190
-
191
- ```ts
192
- import termark from 'termark';
193
-
194
- // Instead of using this:
195
- termark.blue('...');
196
-
197
- // ...you can use this:
198
- termark.blue`...`;
199
- ```
200
-
201
- ### Nested styles
202
-
203
- ```ts
204
- import termark from 'termark';
205
-
206
- termark.blue(
207
- 'This is some blue text ' +
208
- termark.yellow('That becomes yellow,') +
209
- ' that becomes blue again.'
210
- );
211
- ```
212
-
213
- ### Colour-detection utilities
214
-
215
- ```ts
216
- import termark from 'termark';
217
-
218
- termark.areColorsEnabled; // Check whether terminal colours are enabled.
219
- termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled.
220
- termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled.
221
- ```
222
-
223
- ### Class v. Object
224
-
225
- You can use Termark by importing the object, or you can import the class:
226
-
227
- ```ts
228
- import { Termark } from 'termark';
229
-
230
- const termark = new Termark(); // This is the same as importing the `termark` object.
231
- termark.success('Termark is working!');
232
-
233
- // Alternatively, you could do this:
234
- Termark.init.success('This work, too!');
235
- ```
236
-
237
- `Termark.init` enables using the `Termark` class as the default `termark` object.
238
-
239
- ## Licence
240
-
241
- Termark's code is licenced under the [Apache licence version 2](https://www.apache.org/licenses/LICENSE-2.0).
242
- The full licence text is present in these source files.
243
- In addition, this snippet of text is present at the top of all files:
244
-
245
- ```txt
246
- Copyright 2025 Q
247
-
248
- Licensed under the Apache License, Version 2.0 (the "License");
249
- you may not use this file except in compliance with the License.
250
- You may obtain a copy of the License at
251
-
252
- http://www.apache.org/licenses/LICENSE-2.0
253
-
254
- Unless required by applicable law or agreed to in writing, software
255
- distributed under the License is distributed on an "AS IS" BASIS,
256
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
257
- See the License for the specific language governing permissions and
258
- limitations under the License.
259
- ```
1
+ <div align="center">
2
+ <img alt="Termark" src="logo.webp" title="Termark logo" />
3
+ </div>
4
+
5
+ Termark is a basic library to format console output to the standard non-browser terminal.
6
+
7
+ <!-- TOC -->
8
+
9
+ - [Features](#features)
10
+ - [Usage](#usage)
11
+ - [Installation](#installation)
12
+ - [ESM & CJS compatibility](#esm--cjs-compatibility)
13
+ - [Basic usage](#basic-usage)
14
+ - [Licence](#licence)
15
+ <!-- TOC -->
16
+
17
+ ## Features
18
+
19
+ - **Familiar syntax** (`fmt.bold.brightRed.bgBlue("...")`)
20
+ - **ESM & CJS compatibility**
21
+ - [**NO_COLOR**](https://no-color.org/)-friendly
22
+ - [**FORCE_COLOR**](https://force-color.org/)-friendly
23
+ - **`truecolor` support** including gradients
24
+ - **Automatic colour-support detection** with **step-wise fallback** (truecolor → 8-bit → 4-bit → plain text)
25
+ - **Extensible** via `extend`; includes **built-in support** for `css-color-names` via `fromColObject`
26
+ - **Runtime-agnostic** (currently supported: Node, Bun, Deno)
27
+
28
+ ## Usage
29
+
30
+ ### Installation
31
+
32
+ Termark can be installed via any package manager that can interact with the NPM registry:
33
+
34
+ ```bash
35
+ # NPM
36
+ npm i termark
37
+
38
+ # PNPM
39
+ pnpm add termark
40
+
41
+ # Deno
42
+ deno add npm:termark
43
+
44
+ # Bun
45
+ bun add termark
46
+ ```
47
+
48
+ ### ESM & CJS compatibility
49
+
50
+ Termark is compatible with ECMAScript modules (`import`/`export` syntax) and CommonJS:
51
+
52
+ ```js
53
+ // CJS:
54
+ const { fmt } = require("termark");
55
+
56
+ // ESM:
57
+ import { fmt } from "termark";
58
+ ```
59
+
60
+ ### Basic usage
61
+
62
+ All exports of Termark are named exports, with the primary tool being `fmt` ("format"):
63
+
64
+ ```ts
65
+ import { fmt } from "termark";
66
+
67
+ // Basic chaining syntax
68
+ console.log(fmt.blue.bold("Text"));
69
+
70
+ // Nesting style
71
+ console.log(fmt.bold.red(`Error: This ${fmt.brightCyan("file")} is corrupted!`));
72
+ ```
73
+
74
+ ### Advanced colouring
75
+
76
+ Termark features methods like `hex` and `rgb` as well as the powerful `gradient` for advanced, versatile colouring. All of these methods feature `bg*` variants.
77
+
78
+ ```ts
79
+ import { fmt } from "termark";
80
+
81
+ // Hex and RGB colour-mapping
82
+ console.log(fmt.hex("#80b3ff").text("Light blue text"));
83
+ console.log(fmt.rgb([0, 255, 128]).text("Light green text"));
84
+
85
+ // Gradients (supports hex string/RGB tuple arrays)
86
+ const sunset = ["#ff5e62", "#f96"];
87
+ console.log(fmt.gradient(sunset).text("Beautiful terminal gradient"));
88
+
89
+ // Background variants (`bgHex`, `bgRgb`, `bgGradient`)
90
+ console.log(fmt.bgHex("#222").white("..."));
91
+ ```
92
+
93
+ Termark also features the ability to use singular 8-bit colour codes to style outputs with `fg` and `bg`.
94
+
95
+ ```ts
96
+ import { fmt } from "termark";
97
+
98
+ console.log(fmt.fg(57).text("..."));
99
+ ```
100
+
101
+ **Note:** The `.text()` method is designed for `hex`, `rgb`, `gradient`, and `fg` when they are the last in the chain or when no other styling is needed. However, technically _all_ styling chains can be terminated by `.text()`, e.g., `fmt.bold.red.text("...")`. `.text()` exists to eliminate the need to write `hex("#338cd1")("Coloured text")`, which is still an option, but it's not elegant.
102
+
103
+ ### Layout utilities
104
+
105
+ Termark features a powerful `box` method which lets you encase your text in a, well, box.
106
+
107
+ ```ts
108
+ import { fmt, box } from "termark";
109
+
110
+ const myBox = box(fmt.bold.brightGreen("Deployment successful!"), {
111
+ kind: "rounded",
112
+ padding: 2, // Vertical padding only increases every four units.
113
+ margin: 3, // Vertical margin only increases every four units.
114
+ style: fmt.hex("#ffa500"), // Orange border
115
+ });
116
+
117
+ console.log(myBox);
118
+ ```
119
+
120
+ ### Extensibility
121
+
122
+ **Note:** All extensions of Termark must be called as the last one in a given chain, and a string must be passed.
123
+
124
+ #### via `extend`
125
+
126
+ With the `extend` function, any kind of method can be created as an extension of Termark, such as shortcuts to styles.
127
+
128
+ ```ts
129
+ import { extend, ansiUpperCase } from "termark";
130
+
131
+ const myLib = extend((base) => ({
132
+ // Formatting extensions
133
+ shout: (str) => base.red.bold(ansiUpperCase(str)),
134
+ // Colouring extensions
135
+ orange: (str) => base.hex("#ffa500").text(str),
136
+ }));
137
+
138
+ console.log(myLib.shout("This text is in red bold and all-caps"));
139
+ ```
140
+
141
+ **Note:** When transforming text such as making it upper-case, use `transformPreserveAnsi` or a function derived from it (such as `ansiUpperCase` in the above example) if you plan to nest styles. Keep in mind that transformations apply to nested styles, too; for `shout` above, all nested text will be upper-case too by default.
142
+
143
+ #### via `fromColObject`
144
+
145
+ The `fromColObject` function enables mapping mass colour dictionaries into styling methods. Excellent for packages like [`css-color-names`](https://github.com/bahamas10/css-color-names) or [`color-names`](https://github.com/meodai/color-names) (the latter with some additional work).
146
+
147
+ ```ts
148
+ import { fromColObject } from "termark";
149
+ import cssColours from "css-color-names";
150
+
151
+ const extendedWithCss = fromColObject(cssColours);
152
+ ```
153
+
154
+ By default, background styling methods aren't created. To do that, simply pass `true` for the second parameter.
155
+
156
+ ```ts
157
+ import { fromColObject } from "termark";
158
+ import cssColours from "css-color-names";
159
+
160
+ const withBg = fromColObject(cssColours, true);
161
+ ```
162
+
163
+ ### Hyperlinks
164
+
165
+ Hyperlinks are achieved by Termark with the help of [OSC 8](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda). Currently, it is non-standard, and may not be supported in every terminal.
166
+
167
+ ```ts
168
+ import { fmt } from "termark";
169
+
170
+ const link = fmt.link("https://q-file.com");
171
+ const linkWithText = fmt.link("https://q-file.com", "Website");
172
+
173
+ const styled = fmt.hex("#a7f").link("https://q-file.com", "Website");
174
+ ```
175
+
176
+ `link` must be called as the last element in the chain.
177
+
178
+ ## Licence
179
+
180
+ Termark's code is licenced under the [Apache licence version 2](https://www.apache.org/licenses/LICENSE-2.0).
package/README.npm.md ADDED
@@ -0,0 +1,57 @@
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).
@@ -0,0 +1 @@
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;
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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;
@@ -0,0 +1,21 @@
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 };
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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;
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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;
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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;