@crustjs/style 0.0.1 → 0.0.2
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 +2 -0
- package/dist/index.d.ts +74 -87
- package/dist/index.js +113 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ import { style } from "@crustjs/style";
|
|
|
21
21
|
console.log(style.bold("Build succeeded"));
|
|
22
22
|
console.log(style.red("Error: missing argument"));
|
|
23
23
|
console.log(style.dim("hint: use --help for usage"));
|
|
24
|
+
console.log(style.bold.red("Critical failure"));
|
|
24
25
|
```
|
|
25
26
|
|
|
26
27
|
## Primitive Styling
|
|
@@ -70,6 +71,7 @@ const auto = createStyle({ mode: "auto" });
|
|
|
70
71
|
// Always emit ANSI codes
|
|
71
72
|
const color = createStyle({ mode: "always" });
|
|
72
73
|
console.log(color.red("always red"));
|
|
74
|
+
console.log(color.bold.red("always bold red"));
|
|
73
75
|
|
|
74
76
|
// Never emit ANSI codes — returns plain text
|
|
75
77
|
const plain = createStyle({ mode: "never" });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
declare namespace codes {
|
|
2
|
+
export { yellow, white, underline, strikethrough, reset, red, magenta, italic, inverse, hidden, green, gray, dim, cyan, brightYellow, brightWhite, brightRed, brightMagenta, brightGreen, brightCyan, brightBlue, bold, blue, black, bgYellow, bgWhite, bgRed, bgMagenta, bgGreen, bgCyan, bgBrightYellow, bgBrightWhite, bgBrightRed, bgBrightMagenta, bgBrightGreen, bgBrightCyan, bgBrightBlue, bgBrightBlack, bgBlue, bgBlack, AnsiPair };
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* An ANSI style pair consisting of an opening and closing escape sequence.
|
|
3
6
|
*
|
|
@@ -36,29 +39,29 @@ declare const cyan: AnsiPair;
|
|
|
36
39
|
declare const white: AnsiPair;
|
|
37
40
|
/** Bright black (gray). */
|
|
38
41
|
declare const gray: AnsiPair;
|
|
39
|
-
declare const
|
|
40
|
-
declare const
|
|
41
|
-
declare const
|
|
42
|
-
declare const
|
|
43
|
-
declare const
|
|
44
|
-
declare const
|
|
45
|
-
declare const
|
|
46
|
-
declare const
|
|
47
|
-
declare const
|
|
48
|
-
declare const
|
|
49
|
-
declare const
|
|
50
|
-
declare const
|
|
51
|
-
declare const
|
|
52
|
-
declare const
|
|
53
|
-
declare const
|
|
54
|
-
declare const
|
|
55
|
-
declare const
|
|
56
|
-
declare const
|
|
57
|
-
declare const
|
|
58
|
-
declare const
|
|
59
|
-
declare const
|
|
60
|
-
declare const
|
|
61
|
-
declare const
|
|
42
|
+
declare const brightRed: AnsiPair;
|
|
43
|
+
declare const brightGreen: AnsiPair;
|
|
44
|
+
declare const brightYellow: AnsiPair;
|
|
45
|
+
declare const brightBlue: AnsiPair;
|
|
46
|
+
declare const brightMagenta: AnsiPair;
|
|
47
|
+
declare const brightCyan: AnsiPair;
|
|
48
|
+
declare const brightWhite: AnsiPair;
|
|
49
|
+
declare const bgBlack: AnsiPair;
|
|
50
|
+
declare const bgRed: AnsiPair;
|
|
51
|
+
declare const bgGreen: AnsiPair;
|
|
52
|
+
declare const bgYellow: AnsiPair;
|
|
53
|
+
declare const bgBlue: AnsiPair;
|
|
54
|
+
declare const bgMagenta: AnsiPair;
|
|
55
|
+
declare const bgCyan: AnsiPair;
|
|
56
|
+
declare const bgWhite: AnsiPair;
|
|
57
|
+
declare const bgBrightBlack: AnsiPair;
|
|
58
|
+
declare const bgBrightRed: AnsiPair;
|
|
59
|
+
declare const bgBrightGreen: AnsiPair;
|
|
60
|
+
declare const bgBrightYellow: AnsiPair;
|
|
61
|
+
declare const bgBrightBlue: AnsiPair;
|
|
62
|
+
declare const bgBrightMagenta: AnsiPair;
|
|
63
|
+
declare const bgBrightCyan: AnsiPair;
|
|
64
|
+
declare const bgBrightWhite: AnsiPair;
|
|
62
65
|
/**
|
|
63
66
|
* Options for {@link unorderedList}.
|
|
64
67
|
*/
|
|
@@ -279,6 +282,8 @@ interface TableOptions {
|
|
|
279
282
|
* ```
|
|
280
283
|
*/
|
|
281
284
|
declare function table(headers: string[], rows: string[][], options?: TableOptions): string;
|
|
285
|
+
declare const styleMethodPairs: Omit<typeof codes, "reset">;
|
|
286
|
+
type StyleMethodName = keyof typeof styleMethodPairs;
|
|
282
287
|
/**
|
|
283
288
|
* Color emission mode for the style engine.
|
|
284
289
|
*
|
|
@@ -326,56 +331,37 @@ interface StyleOptions {
|
|
|
326
331
|
*/
|
|
327
332
|
type StyleFn = (text: string) => string;
|
|
328
333
|
/**
|
|
334
|
+
* Shared style method surface used by style instances and chainable style
|
|
335
|
+
* functions.
|
|
336
|
+
*/
|
|
337
|
+
type StyleMethodMap = { readonly [K in StyleMethodName2] : ChainableStyleFn };
|
|
338
|
+
/**
|
|
339
|
+
* A callable style function that also exposes all style methods for chaining.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* style.bold.red("error");
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
interface ChainableStyleFn extends StyleMethodMap {
|
|
347
|
+
(text: string): string;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Style method name used by the chain builder implementation.
|
|
351
|
+
*/
|
|
352
|
+
type StyleMethodName2 = StyleMethodName;
|
|
353
|
+
/**
|
|
329
354
|
* A configured style instance with mode-aware styling functions.
|
|
330
355
|
*
|
|
331
356
|
* In `"never"` mode, all functions return plain text without ANSI codes.
|
|
332
357
|
* In `"always"` mode, ANSI codes are always emitted.
|
|
333
358
|
* In `"auto"` mode, behavior depends on terminal capability detection.
|
|
334
359
|
*/
|
|
335
|
-
interface StyleInstance {
|
|
360
|
+
interface StyleInstance extends StyleMethodMap {
|
|
336
361
|
/** Whether ANSI codes will be emitted by this instance. */
|
|
337
362
|
readonly enabled: boolean;
|
|
338
363
|
/** Apply an arbitrary ANSI pair to text, respecting the color mode. */
|
|
339
364
|
readonly apply: (text: string, pair: AnsiPair) => string;
|
|
340
|
-
readonly bold: StyleFn;
|
|
341
|
-
readonly dim: StyleFn;
|
|
342
|
-
readonly italic: StyleFn;
|
|
343
|
-
readonly underline: StyleFn;
|
|
344
|
-
readonly inverse: StyleFn;
|
|
345
|
-
readonly hidden: StyleFn;
|
|
346
|
-
readonly strikethrough: StyleFn;
|
|
347
|
-
readonly black: StyleFn;
|
|
348
|
-
readonly red: StyleFn;
|
|
349
|
-
readonly green: StyleFn;
|
|
350
|
-
readonly yellow: StyleFn;
|
|
351
|
-
readonly blue: StyleFn;
|
|
352
|
-
readonly magenta: StyleFn;
|
|
353
|
-
readonly cyan: StyleFn;
|
|
354
|
-
readonly white: StyleFn;
|
|
355
|
-
readonly gray: StyleFn;
|
|
356
|
-
readonly brightRed: StyleFn;
|
|
357
|
-
readonly brightGreen: StyleFn;
|
|
358
|
-
readonly brightYellow: StyleFn;
|
|
359
|
-
readonly brightBlue: StyleFn;
|
|
360
|
-
readonly brightMagenta: StyleFn;
|
|
361
|
-
readonly brightCyan: StyleFn;
|
|
362
|
-
readonly brightWhite: StyleFn;
|
|
363
|
-
readonly bgBlack: StyleFn;
|
|
364
|
-
readonly bgRed: StyleFn;
|
|
365
|
-
readonly bgGreen: StyleFn;
|
|
366
|
-
readonly bgYellow: StyleFn;
|
|
367
|
-
readonly bgBlue: StyleFn;
|
|
368
|
-
readonly bgMagenta: StyleFn;
|
|
369
|
-
readonly bgCyan: StyleFn;
|
|
370
|
-
readonly bgWhite: StyleFn;
|
|
371
|
-
readonly bgBrightBlack: StyleFn;
|
|
372
|
-
readonly bgBrightRed: StyleFn;
|
|
373
|
-
readonly bgBrightGreen: StyleFn;
|
|
374
|
-
readonly bgBrightYellow: StyleFn;
|
|
375
|
-
readonly bgBrightBlue: StyleFn;
|
|
376
|
-
readonly bgBrightMagenta: StyleFn;
|
|
377
|
-
readonly bgBrightCyan: StyleFn;
|
|
378
|
-
readonly bgBrightWhite: StyleFn;
|
|
379
365
|
}
|
|
380
366
|
/**
|
|
381
367
|
* Resolve whether ANSI color codes should be emitted.
|
|
@@ -424,51 +410,51 @@ declare function white2(text: string): string;
|
|
|
424
410
|
/** Apply gray (bright black) foreground color. */
|
|
425
411
|
declare function gray2(text: string): string;
|
|
426
412
|
/** Apply bright red foreground color. */
|
|
427
|
-
declare function
|
|
413
|
+
declare function brightRed2(text: string): string;
|
|
428
414
|
/** Apply bright green foreground color. */
|
|
429
|
-
declare function
|
|
415
|
+
declare function brightGreen2(text: string): string;
|
|
430
416
|
/** Apply bright yellow foreground color. */
|
|
431
|
-
declare function
|
|
417
|
+
declare function brightYellow2(text: string): string;
|
|
432
418
|
/** Apply bright blue foreground color. */
|
|
433
|
-
declare function
|
|
419
|
+
declare function brightBlue2(text: string): string;
|
|
434
420
|
/** Apply bright magenta foreground color. */
|
|
435
|
-
declare function
|
|
421
|
+
declare function brightMagenta2(text: string): string;
|
|
436
422
|
/** Apply bright cyan foreground color. */
|
|
437
|
-
declare function
|
|
423
|
+
declare function brightCyan2(text: string): string;
|
|
438
424
|
/** Apply bright white foreground color. */
|
|
439
|
-
declare function
|
|
425
|
+
declare function brightWhite2(text: string): string;
|
|
440
426
|
/** Apply black background color. */
|
|
441
|
-
declare function
|
|
427
|
+
declare function bgBlack2(text: string): string;
|
|
442
428
|
/** Apply red background color. */
|
|
443
|
-
declare function
|
|
429
|
+
declare function bgRed2(text: string): string;
|
|
444
430
|
/** Apply green background color. */
|
|
445
|
-
declare function
|
|
431
|
+
declare function bgGreen2(text: string): string;
|
|
446
432
|
/** Apply yellow background color. */
|
|
447
|
-
declare function
|
|
433
|
+
declare function bgYellow2(text: string): string;
|
|
448
434
|
/** Apply blue background color. */
|
|
449
|
-
declare function
|
|
435
|
+
declare function bgBlue2(text: string): string;
|
|
450
436
|
/** Apply magenta background color. */
|
|
451
|
-
declare function
|
|
437
|
+
declare function bgMagenta2(text: string): string;
|
|
452
438
|
/** Apply cyan background color. */
|
|
453
|
-
declare function
|
|
439
|
+
declare function bgCyan2(text: string): string;
|
|
454
440
|
/** Apply white background color. */
|
|
455
|
-
declare function
|
|
441
|
+
declare function bgWhite2(text: string): string;
|
|
456
442
|
/** Apply bright black background color. */
|
|
457
|
-
declare function
|
|
443
|
+
declare function bgBrightBlack2(text: string): string;
|
|
458
444
|
/** Apply bright red background color. */
|
|
459
|
-
declare function
|
|
445
|
+
declare function bgBrightRed2(text: string): string;
|
|
460
446
|
/** Apply bright green background color. */
|
|
461
|
-
declare function
|
|
447
|
+
declare function bgBrightGreen2(text: string): string;
|
|
462
448
|
/** Apply bright yellow background color. */
|
|
463
|
-
declare function
|
|
449
|
+
declare function bgBrightYellow2(text: string): string;
|
|
464
450
|
/** Apply bright blue background color. */
|
|
465
|
-
declare function
|
|
451
|
+
declare function bgBrightBlue2(text: string): string;
|
|
466
452
|
/** Apply bright magenta background color. */
|
|
467
|
-
declare function
|
|
453
|
+
declare function bgBrightMagenta2(text: string): string;
|
|
468
454
|
/** Apply bright cyan background color. */
|
|
469
|
-
declare function
|
|
455
|
+
declare function bgBrightCyan2(text: string): string;
|
|
470
456
|
/** Apply bright white background color. */
|
|
471
|
-
declare function
|
|
457
|
+
declare function bgBrightWhite2(text: string): string;
|
|
472
458
|
/**
|
|
473
459
|
* Create a configured style instance with mode-aware styling functions.
|
|
474
460
|
*
|
|
@@ -490,6 +476,7 @@ declare function bgBrightWhite3(text: string): string;
|
|
|
490
476
|
* // Force color output
|
|
491
477
|
* const color = createStyle({ mode: "always" });
|
|
492
478
|
* console.log(color.red("error"));
|
|
479
|
+
* console.log(color.bold.red("critical"));
|
|
493
480
|
*
|
|
494
481
|
* // Disable all styling
|
|
495
482
|
* const plain = createStyle({ mode: "never" });
|
|
@@ -962,4 +949,4 @@ declare function createMarkdownTheme(options?: CreateMarkdownThemeOptions): Mark
|
|
|
962
949
|
* ```
|
|
963
950
|
*/
|
|
964
951
|
declare const defaultTheme: MarkdownTheme;
|
|
965
|
-
export { yellow as yellowCode, yellow2 as yellow, wrapText, white as whiteCode, white2 as white, visibleWidth, unorderedList, underline as underlineCode, underline2 as underline, taskList, table, style, stripAnsi, strikethrough as strikethroughCode, strikethrough2 as strikethrough, resolveCapability, reset, red as redCode, red2 as red, padStart, padEnd, orderedList, magenta as magentaCode, magenta2 as magenta, italic as italicCode, italic2 as italic, inverse as inverseCode, inverse2 as inverse, hidden as hiddenCode, hidden2 as hidden, green as greenCode, green2 as green, gray as grayCode, gray2 as gray, dim as dimCode, dim2 as dim, defaultTheme, cyan as cyanCode, cyan2 as cyan, createStyle, createMarkdownTheme, composeStyles, center, buildDefaultMarkdownTheme,
|
|
952
|
+
export { yellow as yellowCode, yellow2 as yellow, wrapText, white as whiteCode, white2 as white, visibleWidth, unorderedList, underline as underlineCode, underline2 as underline, taskList, table, style, stripAnsi, strikethrough as strikethroughCode, strikethrough2 as strikethrough, resolveCapability, reset, red as redCode, red2 as red, padStart, padEnd, orderedList, magenta as magentaCode, magenta2 as magenta, italic as italicCode, italic2 as italic, inverse as inverseCode, inverse2 as inverse, hidden as hiddenCode, hidden2 as hidden, green as greenCode, green2 as green, gray as grayCode, gray2 as gray, dim as dimCode, dim2 as dim, defaultTheme, cyan as cyanCode, cyan2 as cyan, createStyle, createMarkdownTheme, composeStyles, center, buildDefaultMarkdownTheme, brightYellow as brightYellowCode, brightYellow2 as brightYellow, brightWhite as brightWhiteCode, brightWhite2 as brightWhite, brightRed as brightRedCode, brightRed2 as brightRed, brightMagenta as brightMagentaCode, brightMagenta2 as brightMagenta, brightGreen as brightGreenCode, brightGreen2 as brightGreen, brightCyan as brightCyanCode, brightCyan2 as brightCyan, brightBlue as brightBlueCode, brightBlue2 as brightBlue, bold as boldCode, bold2 as bold, blue as blueCode, blue2 as blue, black as blackCode, black2 as black, bgYellow as bgYellowCode, bgYellow2 as bgYellow, bgWhite as bgWhiteCode, bgWhite2 as bgWhite, bgRed as bgRedCode, bgRed2 as bgRed, bgMagenta as bgMagentaCode, bgMagenta2 as bgMagenta, bgGreen as bgGreenCode, bgGreen2 as bgGreen, bgCyan as bgCyanCode, bgCyan2 as bgCyan, bgBrightYellow as bgBrightYellowCode, bgBrightYellow2 as bgBrightYellow, bgBrightWhite as bgBrightWhiteCode, bgBrightWhite2 as bgBrightWhite, bgBrightRed as bgBrightRedCode, bgBrightRed2 as bgBrightRed, bgBrightMagenta as bgBrightMagentaCode, bgBrightMagenta2 as bgBrightMagenta, bgBrightGreen as bgBrightGreenCode, bgBrightGreen2 as bgBrightGreen, bgBrightCyan as bgBrightCyanCode, bgBrightCyan2 as bgBrightCyan, bgBrightBlue as bgBrightBlueCode, bgBrightBlue2 as bgBrightBlue, bgBrightBlack as bgBrightBlackCode, bgBrightBlack2 as bgBrightBlack, bgBlue as bgBlueCode, bgBlue2 as bgBlue, bgBlack as bgBlackCode, bgBlack2 as bgBlack, applyStyle, WrapOptions, UnorderedListOptions, ThemeSlotFn, TaskListOptions, TaskListItem, TableOptions, StyleOptions, StyleInstance, StyleFn, PartialMarkdownTheme, OrderedListOptions, MarkdownTheme, CreateMarkdownThemeOptions, ColumnAlignment, ColorMode, CapabilityOverrides, AnsiPair };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
2
13
|
// src/ansiCodes.ts
|
|
14
|
+
var exports_ansiCodes = {};
|
|
15
|
+
__export(exports_ansiCodes, {
|
|
16
|
+
yellow: () => yellow,
|
|
17
|
+
white: () => white,
|
|
18
|
+
underline: () => underline,
|
|
19
|
+
strikethrough: () => strikethrough,
|
|
20
|
+
reset: () => reset,
|
|
21
|
+
red: () => red,
|
|
22
|
+
magenta: () => magenta,
|
|
23
|
+
italic: () => italic,
|
|
24
|
+
inverse: () => inverse,
|
|
25
|
+
hidden: () => hidden,
|
|
26
|
+
green: () => green,
|
|
27
|
+
gray: () => gray,
|
|
28
|
+
dim: () => dim,
|
|
29
|
+
cyan: () => cyan,
|
|
30
|
+
brightYellow: () => brightYellow,
|
|
31
|
+
brightWhite: () => brightWhite,
|
|
32
|
+
brightRed: () => brightRed,
|
|
33
|
+
brightMagenta: () => brightMagenta,
|
|
34
|
+
brightGreen: () => brightGreen,
|
|
35
|
+
brightCyan: () => brightCyan,
|
|
36
|
+
brightBlue: () => brightBlue,
|
|
37
|
+
bold: () => bold,
|
|
38
|
+
blue: () => blue,
|
|
39
|
+
black: () => black,
|
|
40
|
+
bgYellow: () => bgYellow,
|
|
41
|
+
bgWhite: () => bgWhite,
|
|
42
|
+
bgRed: () => bgRed,
|
|
43
|
+
bgMagenta: () => bgMagenta,
|
|
44
|
+
bgGreen: () => bgGreen,
|
|
45
|
+
bgCyan: () => bgCyan,
|
|
46
|
+
bgBrightYellow: () => bgBrightYellow,
|
|
47
|
+
bgBrightWhite: () => bgBrightWhite,
|
|
48
|
+
bgBrightRed: () => bgBrightRed,
|
|
49
|
+
bgBrightMagenta: () => bgBrightMagenta,
|
|
50
|
+
bgBrightGreen: () => bgBrightGreen,
|
|
51
|
+
bgBrightCyan: () => bgBrightCyan,
|
|
52
|
+
bgBrightBlue: () => bgBrightBlue,
|
|
53
|
+
bgBrightBlack: () => bgBrightBlack,
|
|
54
|
+
bgBlue: () => bgBlue,
|
|
55
|
+
bgBlack: () => bgBlack
|
|
56
|
+
});
|
|
3
57
|
function pair(open, close) {
|
|
4
58
|
return { open: `\x1B[${open}m`, close: `\x1B[${close}m` };
|
|
5
59
|
}
|
|
@@ -348,58 +402,74 @@ function bgBrightCyan2(text) {
|
|
|
348
402
|
function bgBrightWhite2(text) {
|
|
349
403
|
return applyStyle(text, bgBrightWhite);
|
|
350
404
|
}
|
|
405
|
+
// src/styleMethodRegistry.ts
|
|
406
|
+
function readStyleMethodPairs() {
|
|
407
|
+
const { reset: _reset, ...pairs } = exports_ansiCodes;
|
|
408
|
+
return pairs;
|
|
409
|
+
}
|
|
410
|
+
var styleMethodPairs = Object.freeze(readStyleMethodPairs());
|
|
411
|
+
var styleMethodNames = Object.freeze(Object.keys(styleMethodPairs));
|
|
412
|
+
function stylePairFor(name) {
|
|
413
|
+
return styleMethodPairs[name];
|
|
414
|
+
}
|
|
415
|
+
|
|
351
416
|
// src/createStyle.ts
|
|
352
|
-
function
|
|
353
|
-
if (enabled) {
|
|
354
|
-
return
|
|
417
|
+
function applyChain(text, methodNames, enabled) {
|
|
418
|
+
if (!enabled || text === "") {
|
|
419
|
+
return text;
|
|
420
|
+
}
|
|
421
|
+
let result = text;
|
|
422
|
+
for (let i = methodNames.length - 1;i >= 0; i--) {
|
|
423
|
+
const methodName = methodNames[i];
|
|
424
|
+
if (methodName === undefined) {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
result = applyStyle(result, stylePairFor(methodName));
|
|
428
|
+
}
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
function buildChainableStyleFactory(enabled) {
|
|
432
|
+
const cache = new Map;
|
|
433
|
+
function makeKey(methodNames) {
|
|
434
|
+
return methodNames.join("|");
|
|
435
|
+
}
|
|
436
|
+
function createChainableStyle(methodNames) {
|
|
437
|
+
const key = makeKey(methodNames);
|
|
438
|
+
const cached = cache.get(key);
|
|
439
|
+
if (cached) {
|
|
440
|
+
return cached;
|
|
441
|
+
}
|
|
442
|
+
const styleFn = (text) => applyChain(text, methodNames, enabled);
|
|
443
|
+
cache.set(key, styleFn);
|
|
444
|
+
for (const name of styleMethodNames) {
|
|
445
|
+
Object.defineProperty(styleFn, name, {
|
|
446
|
+
configurable: false,
|
|
447
|
+
enumerable: true,
|
|
448
|
+
get() {
|
|
449
|
+
return createChainableStyle([...methodNames, name]);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
return Object.freeze(styleFn);
|
|
454
|
+
}
|
|
455
|
+
return createChainableStyle;
|
|
456
|
+
}
|
|
457
|
+
function buildStyleMethods(createChainableStyle) {
|
|
458
|
+
const methods = {};
|
|
459
|
+
for (const methodName of styleMethodNames) {
|
|
460
|
+
methods[methodName] = createChainableStyle([methodName]);
|
|
355
461
|
}
|
|
356
|
-
return
|
|
462
|
+
return methods;
|
|
357
463
|
}
|
|
358
464
|
function createStyle(options) {
|
|
359
465
|
const mode = options?.mode ?? "auto";
|
|
360
466
|
const enabled = resolveCapability(mode, options?.overrides);
|
|
467
|
+
const createChainableStyle = buildChainableStyleFactory(enabled);
|
|
468
|
+
const methods = buildStyleMethods(createChainableStyle);
|
|
361
469
|
const instance = {
|
|
362
470
|
enabled,
|
|
363
471
|
apply: enabled ? (text, pair2) => applyStyle(text, pair2) : (text, _pair) => text,
|
|
364
|
-
|
|
365
|
-
dim: makeStyleFn(dim, enabled),
|
|
366
|
-
italic: makeStyleFn(italic, enabled),
|
|
367
|
-
underline: makeStyleFn(underline, enabled),
|
|
368
|
-
inverse: makeStyleFn(inverse, enabled),
|
|
369
|
-
hidden: makeStyleFn(hidden, enabled),
|
|
370
|
-
strikethrough: makeStyleFn(strikethrough, enabled),
|
|
371
|
-
black: makeStyleFn(black, enabled),
|
|
372
|
-
red: makeStyleFn(red, enabled),
|
|
373
|
-
green: makeStyleFn(green, enabled),
|
|
374
|
-
yellow: makeStyleFn(yellow, enabled),
|
|
375
|
-
blue: makeStyleFn(blue, enabled),
|
|
376
|
-
magenta: makeStyleFn(magenta, enabled),
|
|
377
|
-
cyan: makeStyleFn(cyan, enabled),
|
|
378
|
-
white: makeStyleFn(white, enabled),
|
|
379
|
-
gray: makeStyleFn(gray, enabled),
|
|
380
|
-
brightRed: makeStyleFn(brightRed, enabled),
|
|
381
|
-
brightGreen: makeStyleFn(brightGreen, enabled),
|
|
382
|
-
brightYellow: makeStyleFn(brightYellow, enabled),
|
|
383
|
-
brightBlue: makeStyleFn(brightBlue, enabled),
|
|
384
|
-
brightMagenta: makeStyleFn(brightMagenta, enabled),
|
|
385
|
-
brightCyan: makeStyleFn(brightCyan, enabled),
|
|
386
|
-
brightWhite: makeStyleFn(brightWhite, enabled),
|
|
387
|
-
bgBlack: makeStyleFn(bgBlack, enabled),
|
|
388
|
-
bgRed: makeStyleFn(bgRed, enabled),
|
|
389
|
-
bgGreen: makeStyleFn(bgGreen, enabled),
|
|
390
|
-
bgYellow: makeStyleFn(bgYellow, enabled),
|
|
391
|
-
bgBlue: makeStyleFn(bgBlue, enabled),
|
|
392
|
-
bgMagenta: makeStyleFn(bgMagenta, enabled),
|
|
393
|
-
bgCyan: makeStyleFn(bgCyan, enabled),
|
|
394
|
-
bgWhite: makeStyleFn(bgWhite, enabled),
|
|
395
|
-
bgBrightBlack: makeStyleFn(bgBrightBlack, enabled),
|
|
396
|
-
bgBrightRed: makeStyleFn(bgBrightRed, enabled),
|
|
397
|
-
bgBrightGreen: makeStyleFn(bgBrightGreen, enabled),
|
|
398
|
-
bgBrightYellow: makeStyleFn(bgBrightYellow, enabled),
|
|
399
|
-
bgBrightBlue: makeStyleFn(bgBrightBlue, enabled),
|
|
400
|
-
bgBrightMagenta: makeStyleFn(bgBrightMagenta, enabled),
|
|
401
|
-
bgBrightCyan: makeStyleFn(bgBrightCyan, enabled),
|
|
402
|
-
bgBrightWhite: makeStyleFn(bgBrightWhite, enabled)
|
|
472
|
+
...methods
|
|
403
473
|
};
|
|
404
474
|
return Object.freeze(instance);
|
|
405
475
|
}
|