termark 2.1.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.
@@ -0,0 +1,492 @@
1
+ type RGB = [r: number, g: number, b: number];
2
+ /**
3
+ * A number representing the supported colour level.
4
+ *
5
+ * - `0` — No colours, just black-and-white text.
6
+ * - `1` — Basic 4-bit (16) colours.
7
+ * - `2` — 8-bit (256) colours.
8
+ * - `3` — 24-bit (16 mil; `truecolor`) colours.
9
+ */
10
+ type ColourLevel = 0 | 1 | 2 | 3;
11
+ type BaseStyle = "reset" | "bold" | "dim" | "italic" | "underline" | "blink" | "inverse" | "overline" | "hidden" | "strike" | "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "brightBlack" | "grey" | "gray" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite" | "bgBrightBlack" | "bgGrey" | "bgGray" | "bgBrightRed" | "bgBrightGreen" | "bgBrightYellow" | "bgBrightBlue" | "bgBrightMagenta" | "bgBrightCyan" | "bgBrightWhite";
12
+ type GradientStyle = {
13
+ type: "gradient";
14
+ colours: string[] | RGB[];
15
+ } | {
16
+ type: "bgGradient";
17
+ colours: string[] | RGB[];
18
+ };
19
+ type DynamicStyle = {
20
+ type: "fg";
21
+ code: number;
22
+ } | {
23
+ type: "bg";
24
+ code: number;
25
+ } | {
26
+ type: "hex";
27
+ hex: string;
28
+ } | {
29
+ type: "bgHex";
30
+ hex: string;
31
+ } | {
32
+ type: "rgb";
33
+ r: number;
34
+ b: number;
35
+ g: number;
36
+ } | {
37
+ type: "bgRgb";
38
+ r: number;
39
+ b: number;
40
+ g: number;
41
+ } | GradientStyle;
42
+ type StyleFn = (str: string) => string;
43
+ type AnyStyle = BaseStyle | DynamicStyle;
44
+ type StyleData = [open: string, close: string];
45
+ type Termark<ExtKey extends PropertyKey = string> = { [K in BaseStyle]: Termark<ExtKey>; } & { [K in ExtKey]: StyleFn; } & {
46
+ /**
47
+ * Apply a custom colour to the text using an ANSI colour code.
48
+ *
49
+ * @param code An ANSI colour code (0–255)
50
+ */
51
+ fg(code: number): Termark<ExtKey>;
52
+ /**
53
+ * Apply a custom background colour to the text using an ANSI colour code.
54
+ *
55
+ * @param code An ANSI colour code (0–255)
56
+ */
57
+ bg(code: number): Termark<ExtKey>;
58
+ /**
59
+ * Apply a custom colour to the text using a hex colour code.
60
+ *
61
+ * @param hex A hex colour code. The preceding `#` symbol is optional.
62
+ */
63
+ hex(hex: string): Termark<ExtKey>;
64
+ /**
65
+ * Apply a custom background colour to the text using a hex colour code.
66
+ *
67
+ * @param hex A hex colour code. The preceding `#` symbol is optional.
68
+ */
69
+ bgHex(hex: string): Termark<ExtKey>;
70
+ /**
71
+ * Apply a custom colour to the text using an RGB tuple.
72
+ *
73
+ * @param col An RGB tuple.
74
+ */
75
+ rgb(col: RGB): Termark<ExtKey>;
76
+ /**
77
+ * Apply a custom background colour to the text using an RGB tuple.
78
+ *
79
+ * @param col An RGB tuple.
80
+ */
81
+ bgRgb(col: RGB): Termark<ExtKey>;
82
+ /**
83
+ * Set the colour of the text to be a gradient.
84
+ *
85
+ * @param cols An array of colours. Each can be either a hex colour code (`#` optional) or an RGB tuple.
86
+ */
87
+ gradient(cols: Array<string | RGB>): Termark<ExtKey>;
88
+ /**
89
+ * Set the background colour of the text to be a gradient.
90
+ *
91
+ * @param cols An array of colours. Each can be either a hex colour code (`#` optional) or an RGB tuple.
92
+ */
93
+ bgGradient(cols: Array<string | RGB>): Termark<ExtKey>;
94
+ /**
95
+ * Construct an OSC 8 hyperlink.
96
+ *
97
+ * **Note:** Whether and how interactive the resulting hyperlink is entirely depends on the current terminal
98
+ * environment, not all support OSC 8 hyperlinks, especially not ones with custom display text. For a list of which
99
+ * terminal emulators support OSC 8 hyperlinks, see [here](https://github.com/Alhadis/OSC8-Adoption).
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { fmt } from "termark";
104
+ *
105
+ * const l = fmt.link("https://example.com", "Website");
106
+ * ```
107
+ *
108
+ * @example Styling the link
109
+ * ```ts
110
+ * import { fmt } from "termark";
111
+ *
112
+ * const l = fmt.green.bold.link("https://example.com", "Website");
113
+ * ```
114
+ *
115
+ * @param url The URL the hyperlink points to. Required.
116
+ * @param text Text to display instead of the URL. Optional; if omitted, `url` is displayed instead.
117
+ */
118
+ link(url: string, text?: string): string;
119
+ /**
120
+ * Terminate a style chain and apply all collected styles to `input`.
121
+ *
122
+ * Can be called by any
123
+ *
124
+ * @param input A string to apply styles to.
125
+ */
126
+ text(input: string): string;
127
+ } & ((input: string) => string);
128
+ /**
129
+ * Built-in box border kinds.
130
+ */
131
+ type BoxBorderKind = "sharp" | "rounded" | "double" | "heavy" | "dashed" | "dotted" | "ascii";
132
+ /**
133
+ * Type representing an object containing the characters that make up a box border.
134
+ */
135
+ interface BoxBorder {
136
+ /**
137
+ * Top left corner.
138
+ */
139
+ tl: string;
140
+ /**
141
+ * Top right corner.
142
+ */
143
+ tr: string;
144
+ /**
145
+ * Bottom left corner.
146
+ */
147
+ bl: string;
148
+ /**
149
+ * Bottom right corner.
150
+ */
151
+ br: string;
152
+ /**
153
+ * Top/bottom.
154
+ */
155
+ h: string;
156
+ /**
157
+ * Left/right.
158
+ */
159
+ v: string;
160
+ }
161
+ /**
162
+ * Custom box spacing (padding/margin). Values are in characters.
163
+ */
164
+ interface BoxSpacing {
165
+ /**
166
+ * @default 0
167
+ */
168
+ top?: number;
169
+ /**
170
+ * @default 0
171
+ */
172
+ bottom?: number;
173
+ /**
174
+ * @default 0
175
+ */
176
+ left?: number;
177
+ /**
178
+ * @default 0
179
+ */
180
+ right?: number;
181
+ }
182
+ interface BoxOptions {
183
+ /**
184
+ * What the border of the box should be made of.
185
+ *
186
+ * This can be a string representing a built-in border style, or an object for custom styling.
187
+ *
188
+ * @default "sharp"
189
+ */
190
+ kind?: BoxBorderKind | BoxBorder;
191
+ /**
192
+ * Styling to apply to the border.
193
+ *
194
+ * @example fmt.bold.blue
195
+ *
196
+ * @default (str) => str
197
+ */
198
+ style?: (str: string) => string;
199
+ /**
200
+ * Spacing (in characters) between the border and the content. Can be a number or an object to customize padding.
201
+ *
202
+ * When a number is provided, the top-bottom padding will always be a quarter of left-right padding.
203
+ *
204
+ * @default 1
205
+ */
206
+ padding?: number | BoxSpacing;
207
+ /**
208
+ * Spacing (in characters) around the outside of the box. Can be a number or an object to customize margin.
209
+ *
210
+ * When a number is provided, the top-bottom margin will always be a quarter of left-right margin.
211
+ *
212
+ * @default 0
213
+ */
214
+ margin?: number | BoxSpacing;
215
+ }
216
+ type ColourObject = Record<string, string>;
217
+ type FromColObjectReturn<R extends ColourObject, GenBg extends boolean | undefined> = GenBg extends true ? keyof R | `bg${Capitalize<keyof R & string>}` : keyof R;
218
+ /**
219
+ * Check whether `NO_COLOR` is an existing environment variable with any value that is not an empty string, thereby
220
+ * disabling colours from being printed.
221
+ *
222
+ * This also checks the existence of the `NODE_DISABLE_COLORS` environment variable, behaving the same way if it
223
+ * exists and not an empty string.
224
+ *
225
+ * @see https://no-color.org
226
+ */
227
+ export declare function hasNoColour(): boolean;
228
+ /**
229
+ * Get the colour level of the terminal environment.
230
+ *
231
+ * @returns {@linkcode ColourLevel}
232
+ */
233
+ export declare function getColourLevel(): ColourLevel;
234
+ /**
235
+ * Style some text for terminal output.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * import { fmt } from "termark";
240
+ *
241
+ * const styled = fmt.bold.green.italic("Text");
242
+ *
243
+ * console.log(styled);
244
+ * // => "Text" printed in bold, green (if colours are supported/enabled), and italic.
245
+ * ```
246
+ *
247
+ * Each member of the chain can be called by passing a string, or can be accessed to apply further styling.
248
+ * Use `.text()` to finally terminate the styling.
249
+ *
250
+ * @example Terminating the chain with `.text()`
251
+ * ```ts
252
+ * import { fmt } from "termark";
253
+ *
254
+ * const styled = fmt.underline.bgBlue.black.text("Text");
255
+ *
256
+ * console.log(styled);
257
+ * // => "Text" printed in black with a blue background, and underlined.
258
+ * ```
259
+ *
260
+ * `.text()` is primarily for methods, such as `hex`, `rgb`, or `gradient`, that would be inconvenient to use without
261
+ * it.
262
+ *
263
+ * @example `.text()` on `hex` vs. not using `.text()`
264
+ * ```ts
265
+ * import { fmt } from "termark";
266
+ *
267
+ * const custom = fmt.hex("#ffa500").text("orange");
268
+ *
269
+ * // Not using `.text()` is also possible, but less elegant:
270
+ *
271
+ * const withoutTextCall = fmt.hex("#80b3ff")("Text");
272
+ * ```
273
+ */
274
+ export declare const fmt: Termark;
275
+ /**
276
+ * Create a box around some text.
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * import { box } from "termark";
281
+ *
282
+ * const boxed = box("This text is boxed in.");
283
+ * ```
284
+ *
285
+ * Use `\n` to split the text along multiple lines.
286
+ *
287
+ * ---
288
+ *
289
+ * The inner text of the box can be styled with {@linkcode fmt} like regular terminal output.
290
+ *
291
+ * @example Styling inner text
292
+ * ```ts
293
+ * import { box, fmt } from "termark";
294
+ *
295
+ * const boxed = box(fmt.italic.blue("..."));
296
+ * ```
297
+ *
298
+ * ---
299
+ *
300
+ * The look of the box can be customized too, using the `options` parameter.
301
+ *
302
+ * @example Styling box
303
+ * ```ts
304
+ * import { box, fmt } from "termark";
305
+ *
306
+ * const boxed = box("...", {
307
+ * kind: "rounded", // can be an object with custom border characters
308
+ * style: fmt.bold.blue,
309
+ * padding: 2, // can be an object with custom spacing
310
+ * margin: 2, // can be an object with custom spacing
311
+ * });
312
+ * ```
313
+ *
314
+ * @param text The text within the box.
315
+ * @param options Configuration options.
316
+ * @returns A string that is the box.
317
+ */
318
+ export declare function box(text: string, options?: BoxOptions): string;
319
+ /**
320
+ * Extend the functionality of Termark with custom methods.
321
+ *
322
+ * **Note:** Methods created this way can only be used as the last item in the chain.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * import { extend } from "termark";
327
+ *
328
+ * const extended = extend((base) => ({
329
+ * shout: (str) => base.red.bold(str.toUpperCase()),
330
+ * orange: (str) => base.hex("#ffa500").text(str),
331
+ * }));
332
+ *
333
+ * console.log(
334
+ * extended.underline.shout("big red text"),
335
+ * extended.italic.orange("orange text"),
336
+ * );
337
+ * ```
338
+ *
339
+ * When not using arrow functions, it's possible to use an extension method within another extension method:
340
+ *
341
+ * @example Deriving methods from each other
342
+ * ```ts
343
+ * import { extend } from "termark";
344
+ *
345
+ * const extended = extend((base) => ({
346
+ * orange(str) {
347
+ * return base.hex("#ffa500").text(str);
348
+ * },
349
+ * uppercaseOrange(str) {
350
+ * return this.orange(str.toUpperCase());
351
+ * },
352
+ * }));
353
+ * ```
354
+ *
355
+ * @param fn A function that returns an object containing custom methods. This function has access to a
356
+ * {@linkcode Termark} instance so it does not need to be imported separately.
357
+ */
358
+ export declare function extend<E extends Record<PropertyKey, StyleFn>>(fn: (base: Termark) => E): Termark<keyof E>;
359
+ /**
360
+ * Generate colour-styling from an object literal. This primarily exists for use with
361
+ * [`css-color-names`](https://github.com/bahamas10/css-color-names).
362
+ *
363
+ * Because this function uses {@linkcode extend} under the hood, colour methods created this way must be called as the
364
+ * last one in the chain.
365
+ *
366
+ * @example Using `css-color-names`
367
+ * ```ts
368
+ * import cssColours from "css-color-names";
369
+ * import { fromColObject } from "termark";
370
+ *
371
+ * const css = fromColObject(cssColours);
372
+ *
373
+ * console.log(
374
+ * css.lemonchiffron("This text uses a CSS colour!"),
375
+ * css.bold.aliceblue("Works with other styles")
376
+ * );
377
+ * ```
378
+ *
379
+ * @example Enabling background colours
380
+ * ```ts
381
+ * import cssColours from "css-color-names";
382
+ * import { fromColObject } from "termark";
383
+ *
384
+ * const cssWithBg = fromColObject(cssColours, true);
385
+ * ```
386
+ *
387
+ * @example Using [`color-names`](https://github.com/meodai/color-names)
388
+ * ```ts
389
+ * import { colornames } from "color-name-list";
390
+ * import { fromColObject } from "termark";
391
+ *
392
+ * const mapped = colornames.reduce((acc, { name, hex }) => {
393
+ * acc[name] = hex;
394
+ * return acc;
395
+ * }, {});
396
+ *
397
+ * const colours = fromColObject(mapped);
398
+ *
399
+ * console.log(
400
+ * colours["100 Mph"]("This colour is from color-names"),
401
+ * colours.italic.Alaska("...")
402
+ * );
403
+ * ```
404
+ *
405
+ * @param obj An object whose keys are colour names (which will be used as the method name) and whose values are
406
+ * hex colour codes.
407
+ * @param generateBg Whether to generate background styling for all supplied colours. These will have the format
408
+ * `bgColourName` where `ColourName` is the original name of the colour, capitalized. This name is not formatted,
409
+ * so a name like `100 Mph` will retain its spaces.
410
+ */
411
+ export declare function fromColObject<R extends ColourObject, GenBg extends boolean | undefined = undefined>(obj: R, genBg?: GenBg): Termark<FromColObjectReturn<R, GenBg>>;
412
+ /**
413
+ * Construct an OSC 8 hyperlink.
414
+ *
415
+ * **Note:** Whether and how interactive the resulting hyperlink is entirely depends on the current terminal
416
+ * environment, not all support OSC 8 hyperlinks, especially not ones with custom display text. For a list of which
417
+ * terminal emulators support OSC 8 hyperlinks, see [here](https://github.com/Alhadis/OSC8-Adoption).
418
+ *
419
+ * @example
420
+ * ```ts
421
+ * import { link } from "termark";
422
+ *
423
+ * const l = link("https://example.com", "Website");
424
+ * ```
425
+ *
426
+ * @example Styled text
427
+ * ```ts
428
+ * import { link, fmt } from "termark";
429
+ *
430
+ * const l = link("https://example.com", fmt.italic.green("Website"));
431
+ * ```
432
+ *
433
+ * @param url The URL the hyperlink points to. Required.
434
+ * @param text Text to display instead of the URL. Optional; if omitted, `url` is displayed instead.
435
+ */
436
+ export declare function link(url: string, text?: string): string;
437
+ /**
438
+ * Check whether colours are supported in a given terminal environment.
439
+ *
440
+ * Use {@linkcode hasNoColour} for checking whether terminals that *could* support colour don't do so.
441
+ */
442
+ export declare function areColoursSupported(): boolean;
443
+ /**
444
+ * Check whether a terminal environment supports at least some level of colours.
445
+ *
446
+ * @param level A colour level.
447
+ */
448
+ export declare function supports(level: ColourLevel): boolean;
449
+ /**
450
+ * Check whether a terminal environment supports at most a given colour level.
451
+ *
452
+ * @param level A colour level.
453
+ */
454
+ export declare function supportsAtMost(level: ColourLevel): boolean;
455
+ /**
456
+ * Modify the plain text part of a string with ANSI escape sequences.
457
+ *
458
+ * @example Creating a `toUpperCase` method for ANSI strings
459
+ * ```ts
460
+ * import { transformPreserveAnsi } from "termark";
461
+ *
462
+ * const toUpperCase = transformPreserveAnsi((str) => str.toUpperCase());
463
+ * ```
464
+ *
465
+ * @param fn A function that transforms some string.
466
+ *
467
+ * @deprecated Function is no longer necessary.
468
+ */
469
+ export declare function transformPreserveAnsi(fn: (plain: string) => string): (str: string) => string;
470
+ /**
471
+ * Make some string upper-case while preserving ANSI escape sequences as-is.
472
+ *
473
+ * @str The string to transform.
474
+ *
475
+ * @deprecated Function is no longer necessary.
476
+ */
477
+ export declare const ansiUpperCase: (str: string) => string;
478
+ /**
479
+ * Make some string lower-case while preserving ANSI escape sequences as-is.
480
+ *
481
+ * @param str The string to transform.
482
+ *
483
+ * @deprecated Function is no longer necessary.
484
+ */
485
+ export declare const ansiLowerCase: (str: string) => string;
486
+ /**
487
+ * Remove ANSI escape sequences from some text.
488
+ *
489
+ * @param input The input to strip of ANSI escape sequences.
490
+ */
491
+ export declare function stripAnsi(input: string): string;
492
+ export { type AnyStyle, type BaseStyle, type BoxBorder, type BoxBorderKind, type BoxOptions, type BoxSpacing, type ColourLevel, type ColourObject, type DynamicStyle, type FromColObjectReturn, type GradientStyle, type RGB, type StyleData, type StyleFn, type Termark, fmt as termark, getColourLevel as getColorLevel, hasNoColour as hasNoColor };
package/dist/index.mjs CHANGED
@@ -1 +1,5 @@
1
- const r=()=>!process.env.NO_COLOR,e=()=>{const r=process.env.COLORTERM;return{is16bit:!!r&&(r.includes("ansi")&&!r.includes("256")),is256:!!r&&r.includes("ansi256"),isTrueColor:!!r&&(r.includes("truecolor")||r.includes("24bit"))}};function i(e,i,t){if("color"===t&&!r())return r=>r.toString();const o=`[${e}m`,n=`[${i}m`;return r=>{const e=r.toString().trim();return-1===e.indexOf(n)?`${o}${e}${n}`:`${o}${e.replaceAll(n,n+o)}${n}`}}function t(r,e,i){return[Math.round(r[0]+i*(e[0]-r[0])),Math.round(r[1]+i*(e[1]-r[1])),Math.round(r[2]+i*(e[2]-r[2]))]}function o(r,e,i){if("number"!=typeof r)throw new TypeError(`Parameter ${JSON.stringify(r)} must be a finite number, which it currently isn't!`);return Math.min(Math.max(r,e),i)}class n{constructor(){this.areColorsEnabled=r(),this.is8bitEnabled=e().is256,this.is24bitEnabled=e().isTrueColor,this.reset=i(0,0,"format"),this.bold=i(1,22,"format"),this.dim=i(2,22,"format"),this.italic=i(3,23,"format"),this.underline=i(4,24,"format"),this.blink=i(5,25,"format"),this.inverse=i(7,27,"format"),this.overline=i(53,55,"format"),this.hidden=i(8,28,"format"),this.strike=i(9,29,"format"),this.black=i(30,39,"color"),this.red=i(31,39,"color"),this.green=i(32,39,"color"),this.yellow=i(33,39,"color"),this.blue=i(34,39,"color"),this.magenta=i(35,39,"color"),this.cyan=i(36,39,"color"),this.white=i(37,39,"color"),this.blackBright=i(90,39,"color"),this.redBright=i(91,39,"color"),this.greenBright=i(92,39,"color"),this.yellowBright=i(93,39,"color"),this.blueBright=i(94,39,"color"),this.magentaBright=i(95,39,"color"),this.cyanBright=i(96,39,"color"),this.whiteBright=i(97,39,"color"),this.bgBlack=i(40,49,"color"),this.bgRed=i(41,49,"color"),this.bgGreen=i(42,49,"color"),this.bgYellow=i(43,49,"color"),this.bgBlue=i(44,49,"color"),this.bgMagenta=i(45,49,"color"),this.bgCyan=i(46,49,"color"),this.bgWhite=i(47,49,"color"),this.bgBlackBright=i(100,49,"color"),this.bgRedBright=i(101,49,"color"),this.bgGreenBright=i(102,49,"color"),this.bgYellowBright=i(103,49,"color"),this.bgBlueBright=i(104,49,"color"),this.bgMagentaBright=i(105,49,"color"),this.bgCyanBright=i(106,49,"color"),this.bgWhiteBright=i(107,49,"color")}static get init(){return new this.termarkInstance}ansi256(t,n){if(!e().is256||!r())return r=>r.toString();n=o(n,0,255);return i("text"===t?`38;5;${n}`:`48;5;${n}`,"text"===t?39:49,"color")}rgb(r,...t){if(!e().isTrueColor)return r=>r.toString();let n,s,l;Array.isArray(t[0])?(n=o(t[0][0],0,255),s=o(t[0][1],0,255),l=o(t[0][2],0,255)):(n=o(t[0],0,255),s=o(t[1],0,255),l=o(t[2],0,255));return i("text"===r?`38;2;${n};${s};${l}`:`48;2;${n};${s};${l}`,"text"===r?39:49,"color")}gradient(i,o){if(!r()||!e().isTrueColor)return r=>r.toString();const n="text"===i?"[38;2;":"[48;2;",s="text"===i?"":"";return r=>{const e=r.toString().trim(),i=o.length,l=Math.min(e.length/(i-1));let c="";for(let r=0;r<e.length;r++){const h=Math.min(Math.floor(r/l),i-2),a=r%l/l,g=t(o[h],o[h+1],a);c+=`${n}${g[0]};${g[1]};${g[2]}m${e[r]}${s}`}return c}}success(r,e=""){console.info(`${n.successPrefix} ${e}${n.init.green(r)}`)}info(r,e=""){console.info(`${n.infoPrefix} ${e}${n.init.blue(r)}`)}warn(r,e=""){console.warn(`${n.warnPrefix} ${e}${n.init.yellow(r)}`)}error(r,e=""){console.error(`${n.errorPrefix} ${e}${n.init.red(r)}`)}custom(r,e,t){return i(r,e,"asColor"===t?"color":"format")}static createTheme(...r){const e=[];return r.forEach(r=>e.push(r)),r=>{const i=r.toString();return e.reduce((r,e)=>e(r),i)}}static createLogger(r){var e,i,t,o,s,l,c,h;const a=void 0===(null===(e=r.success)||void 0===e?void 0:e.prefix)||""===r.success.prefix?n.successPrefix:!1===r.success.prefix?"":r.success.prefix,g=void 0===(null===(i=r.info)||void 0===i?void 0:i.prefix)||""===r.info.prefix?n.infoPrefix:!1===r.info.prefix?"":r.info.prefix,u=void 0===(null===(t=r.warn)||void 0===t?void 0:t.prefix)||""===r.warn.prefix?n.warnPrefix:!1===r.warn.prefix?"":r.warn.prefix,f=void 0===(null===(o=r.error)||void 0===o?void 0:o.prefix)||""===r.error.prefix?n.errorPrefix:!1===r.error.prefix?"":r.error.prefix,d=n.createTheme(...r.default),b=n.createTheme(...void 0!==(null===(s=r.success)||void 0===s?void 0:s.styles)&&0!==r.success.styles.length?r.success.styles:[n.init.green]),$=n.createTheme(...void 0!==(null===(l=r.info)||void 0===l?void 0:l.styles)&&0!==r.info.styles.length?r.info.styles:[n.init.blue]),m=n.createTheme(...void 0!==(null===(c=r.warn)||void 0===c?void 0:c.styles)&&0!==r.warn.styles.length?r.warn.styles:[n.init.yellow]),B=n.createTheme(...void 0!==(null===(h=r.error)||void 0===h?void 0:h.styles)&&0!==r.error.styles.length?r.error.styles:[n.init.red]);return{log(r,e=""){console.log(`${e}${d(r)}`)},success(r,e=""){console.info(`${a?a+" ":""}${e}${b(r)}`)},info(r,e=""){console.info(`${g?g+" ":""}${e}${$(r)}`)},warn(r,e=""){console.info(`${u?u+" ":""}${e}${m(r)}`)},error(r,e=""){console.info(`${f?f+" ":""}${e}${B(r)}`)}}}}n.termarkInstance=n,n.successPrefix=n.init.green(n.init.bold("[✓]")),n.infoPrefix=n.init.blue(n.init.bold("[i]")),n.warnPrefix=n.init.yellow(n.init.bold("[!]")),n.errorPrefix=n.init.red(n.init.bold("[X]"));const s=n.init,{areColorsEnabled:l,is8bitEnabled:c,is24bitEnabled:h,reset:a,bold:g,dim:u,italic:f,underline:d,blink:b,inverse:$,overline:m,hidden:B,strike:x,black:w,red:y,green:v,yellow:p,blue:k,magenta:C,cyan:M,white:P,blackBright:T,redBright:E,greenBright:S,yellowBright:O,blueBright:R,magentaBright:G,cyanBright:L,whiteBright:W,bgBlack:Y,bgRed:A,bgGreen:I,bgYellow:N,bgBlue:J,bgMagenta:X,bgCyan:_,bgWhite:j,bgBlackBright:q,bgRedBright:z,bgGreenBright:D,bgYellowBright:F,bgBlueBright:H,bgMagentaBright:K,bgCyanBright:Q,bgWhiteBright:U,ansi256:V,rgb:Z,gradient:rr,success:er,info:ir,warn:tr,error:or,custom:nr}=s,{createTheme:sr,createLogger:lr}=n;export{n as Termark,V as ansi256,l as areColorsEnabled,Y as bgBlack,q as bgBlackBright,J as bgBlue,H as bgBlueBright,_ as bgCyan,Q as bgCyanBright,I as bgGreen,D as bgGreenBright,X as bgMagenta,K as bgMagentaBright,A as bgRed,z as bgRedBright,j as bgWhite,U as bgWhiteBright,N as bgYellow,F as bgYellowBright,w as black,T as blackBright,b as blink,k as blue,R as blueBright,g as bold,lr as createLogger,sr as createTheme,nr as custom,M as cyan,L as cyanBright,s as default,u as dim,or as error,rr as gradient,v as green,S as greenBright,B as hidden,ir as info,$ as inverse,h as is24bitEnabled,c as is8bitEnabled,f as italic,C as magenta,G as magentaBright,m as overline,y as red,E as redBright,a as reset,Z as rgb,x as strike,er as success,d as underline,tr as warn,P as white,W as whiteBright,p as yellow,O as yellowBright};
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,39 +1,50 @@
1
1
  {
2
2
  "name": "termark",
3
- "version": "2.1.0",
4
- "main": "./dist/index.cjs",
5
- "module": "./dist/index.mjs",
6
- "exports": {
7
- ".": {
8
- "types": "./dist/index.d.ts",
9
- "import": "./dist/index.mjs",
10
- "require": "./dist/index.cjs"
11
- }
12
- },
3
+ "version": "3.0.1",
4
+ "description": "A basic library to format console output to the standard non-browser terminal.",
13
5
  "keywords": [
14
- "utility",
15
6
  "console",
7
+ "formatting",
16
8
  "node",
17
9
  "output",
18
- "formatting"
10
+ "utility"
19
11
  ],
20
- "author": "Miyazaki \"Q\" Hashimoto",
21
- "license": "Apache-2.0",
22
- "description": "A basic library to format console output to the standard non-browser terminal.",
23
12
  "homepage": "https://genesis.q-file.com/projects/termark",
13
+ "license": "Apache-2.0",
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
+ ],
24
21
  "repository": {
25
22
  "type": "git",
26
23
  "url": "https://codeberg.org/Genesis_Software/termark.git"
27
24
  },
25
+ "type": "module",
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.mjs",
28
+ "types": "./dist/index.d.mts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.mts",
32
+ "import": "./dist/index.mjs",
33
+ "require": "./dist/index.cjs"
34
+ }
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
28
39
  "devDependencies": {
29
- "@rollup/plugin-terser": "^0.4.4",
30
40
  "@types/node": "^24.3.0",
31
- "rollup": "^4.49.0",
32
- "rollup-plugin-typescript2": "^0.36.0",
33
- "typescript": "^5.9.2"
41
+ "typescript": "^5.9.2",
42
+ "vite-plus": "1.4.0"
34
43
  },
35
44
  "scripts": {
36
- "build": "rollup -c",
37
- "test": "node dist/index.mjs"
45
+ "build": "vp pack",
46
+ "dev": "vp pack --watch",
47
+ "test": "vp test",
48
+ "check": "vp check"
38
49
  }
39
50
  }