@oakoliver/lipgloss 1.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/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Antonio Oliveira
4
+
5
+ Based on Lip Gloss by Charmbracelet, Inc., licensed under MIT.
6
+ Original: https://github.com/charmbracelet/lipgloss
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,259 @@
1
+ # lipgloss
2
+
3
+ CSS-like terminal styling for JavaScript. Zero dependencies, multi-runtime (Node.js, Bun, Deno).
4
+
5
+ Ported from [charmbracelet/lipgloss](https://github.com/charmbracelet/lipgloss) (Go) to TypeScript.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @oakoliver/lipgloss
11
+ # or
12
+ bun add @oakoliver/lipgloss
13
+ # or
14
+ deno add npm:@oakoliver/lipgloss
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```ts
20
+ import { newStyle, normalBorder, roundedBorder, Center } from '@oakoliver/lipgloss';
21
+
22
+ // Create a style
23
+ const style = newStyle()
24
+ .bold(true)
25
+ .foreground('#FF6B6B')
26
+ .background('#2D2D2D')
27
+ .padding(1, 2)
28
+ .border(roundedBorder())
29
+ .borderForeground('#FF6B6B')
30
+ .width(40)
31
+ .align(Center);
32
+
33
+ console.log(style.render('Hello, Lipgloss!'));
34
+ ```
35
+
36
+ ## Features
37
+
38
+ - **Fluent, immutable API** — every setter returns a new `Style` (safe to share and compose)
39
+ - **CSS-like box model** — padding, margin, border, width, height, alignment
40
+ - **10 built-in border styles** — normal, rounded, block, thick, double, hidden, ASCII, markdown, and more
41
+ - **Full ANSI color support** — basic 16, 256-color palette, and 24-bit RGB
42
+ - **Text attributes** — bold, italic, underline (5 styles), strikethrough, reverse, blink, faint
43
+ - **Layout utilities** — `joinHorizontal`, `joinVertical`, `place`, `placeHorizontal`, `placeVertical`
44
+ - **Color utilities** — `complementary`, `darken`, `lighten`, `isDarkColor`, `lightDark`, `alpha`
45
+ - **Zero dependencies** — pure TypeScript, works everywhere
46
+ - **TypeScript-first** — full type declarations included
47
+
48
+ ## API
49
+
50
+ ### Style
51
+
52
+ ```ts
53
+ import { newStyle, Style } from '@oakoliver/lipgloss';
54
+
55
+ const s = newStyle();
56
+ ```
57
+
58
+ Every setter returns a new `Style` instance (immutable):
59
+
60
+ ```ts
61
+ const base = newStyle().foreground('#7D56F4');
62
+ const title = base.bold(true).padding(0, 1);
63
+ const body = base.faint(true);
64
+ ```
65
+
66
+ #### Text Attributes
67
+
68
+ ```ts
69
+ s.bold(true)
70
+ s.italic(true)
71
+ s.underline(true)
72
+ s.underlineStyle('curly') // 'none' | 'single' | 'double' | 'curly' | 'dotted' | 'dashed'
73
+ s.strikethrough(true)
74
+ s.reverse(true)
75
+ s.blink(true)
76
+ s.faint(true)
77
+ ```
78
+
79
+ #### Colors
80
+
81
+ ```ts
82
+ // Hex (#RGB or #RRGGBB)
83
+ s.foreground('#ff0000')
84
+ s.background('#2D2D2D')
85
+ s.underlineColor('#00ff00')
86
+
87
+ // ANSI basic (0-15)
88
+ import { Red, BrightCyan } from '@oakoliver/lipgloss';
89
+ s.foreground(Red)
90
+
91
+ // ANSI 256 (16-255)
92
+ s.foreground(196)
93
+
94
+ // RGB object
95
+ s.foreground({ r: 255, g: 107, b: 107 })
96
+ ```
97
+
98
+ #### Dimensions
99
+
100
+ ```ts
101
+ s.width(40) // fixed width (content wraps/pads to fit)
102
+ s.height(5) // fixed height
103
+ s.maxWidth(80) // truncate lines exceeding this
104
+ s.maxHeight(24) // truncate output exceeding this many lines
105
+ ```
106
+
107
+ #### Alignment
108
+
109
+ ```ts
110
+ import { Left, Center, Right, Top, Bottom } from '@oakoliver/lipgloss';
111
+
112
+ s.align(Center) // horizontal only
113
+ s.align(Center, Bottom) // horizontal and vertical
114
+ s.alignHorizontal(Right)
115
+ s.alignVertical(Top)
116
+ ```
117
+
118
+ #### Padding & Margin (CSS shorthand)
119
+
120
+ ```ts
121
+ s.padding(1) // all sides
122
+ s.padding(1, 2) // vertical, horizontal
123
+ s.padding(1, 2, 3, 4) // top, right, bottom, left
124
+ s.paddingTop(1)
125
+ s.paddingLeft(2)
126
+
127
+ s.margin(1, 2)
128
+ s.marginBackground('#333') // color the margin area
129
+ ```
130
+
131
+ #### Borders
132
+
133
+ ```ts
134
+ import {
135
+ normalBorder, roundedBorder, blockBorder, thickBorder,
136
+ doubleBorder, hiddenBorder, asciiBorder, markdownBorder,
137
+ outerHalfBlockBorder, innerHalfBlockBorder,
138
+ } from '@oakoliver/lipgloss';
139
+
140
+ s.border(roundedBorder()) // all sides
141
+ s.border(normalBorder(), true, false) // top+bottom only
142
+ s.border(normalBorder(), true, true, true, true) // explicit all
143
+
144
+ s.borderForeground('#FF6B6B') // all sides same color
145
+ s.borderForeground('#f00', '#0f0', '#00f', '#ff0') // CSS shorthand
146
+ s.borderBackground('#2D2D2D')
147
+ ```
148
+
149
+ #### Other
150
+
151
+ ```ts
152
+ s.inline(true) // strip newlines
153
+ s.tabWidth(2) // tab stop width (default 4, -1 to preserve tabs)
154
+ s.transform(s => s.toUpperCase())
155
+ s.hyperlink('https://example.com')
156
+ s.setString('prefix') // prepend when rendering
157
+ s.colorWhitespace(true) // apply bg color to padding spaces
158
+ s.underlineSpaces(true)
159
+ s.strikethroughSpaces(true)
160
+ ```
161
+
162
+ #### Rendering
163
+
164
+ ```ts
165
+ const output = style.render('Hello, World!');
166
+ console.log(output);
167
+
168
+ // render() joins multiple args with space
169
+ style.render('Hello,', 'World!');
170
+
171
+ // toString() renders the setString value
172
+ const s = newStyle().setString('Hello').bold(true);
173
+ console.log(`${s}`); // bold "Hello"
174
+ ```
175
+
176
+ #### Inherit
177
+
178
+ Copy style properties from another style (padding/margin excluded):
179
+
180
+ ```ts
181
+ const parent = newStyle().bold(true).foreground('#FF6B6B');
182
+ const child = newStyle().italic(true).inherit(parent);
183
+ // child is now bold + italic + #FF6B6B foreground
184
+ ```
185
+
186
+ #### Getters
187
+
188
+ Every property has a corresponding getter:
189
+
190
+ ```ts
191
+ s.getBold() // boolean
192
+ s.getForeground() // Color | null
193
+ s.getWidth() // number
194
+ s.getPadding() // { top, right, bottom, left }
195
+ s.getHorizontalFrameSize() // margin + border + padding (horizontal)
196
+ s.getFrameSize() // { x, y }
197
+ ```
198
+
199
+ ### Layout
200
+
201
+ ```ts
202
+ import {
203
+ joinHorizontal, joinVertical,
204
+ place, placeHorizontal, placeVertical,
205
+ Top, Bottom, Center, Left, Right,
206
+ } from '@oakoliver/lipgloss';
207
+
208
+ // Join blocks side by side (vertical alignment)
209
+ joinHorizontal(Top, blockA, blockB, blockC);
210
+ joinHorizontal(Center, blockA, blockB);
211
+
212
+ // Stack blocks vertically (horizontal alignment)
213
+ joinVertical(Left, blockA, blockB);
214
+ joinVertical(Center, blockA, blockB);
215
+
216
+ // Place content in an unstyled box
217
+ place(80, 24, Center, Center, 'Hello');
218
+ placeHorizontal(80, Center, 'Hello');
219
+ placeVertical(24, Center, 'Hello');
220
+ ```
221
+
222
+ ### Color Utilities
223
+
224
+ ```ts
225
+ import {
226
+ parseColor, colorToRGB, isDarkColor,
227
+ lightDark, complementary, darken, lighten, alpha,
228
+ } from '@oakoliver/lipgloss';
229
+
230
+ isDarkColor('#1a1a2e') // true
231
+ isDarkColor('#ffffff') // false
232
+
233
+ const pick = lightDark(isDarkColor('#1a1a2e'));
234
+ pick('#333', '#eee') // returns '#eee' (dark background → use light color)
235
+
236
+ complementary('#ff0000') // ~cyan
237
+ darken('#ff6b6b', 0.3) // 30% darker
238
+ lighten('#333333', 0.2) // 20% lighter
239
+ alpha('#ff0000', 0.5) // { r: 128, g: 0, b: 0 }
240
+ ```
241
+
242
+ ### ANSI Utilities
243
+
244
+ ```ts
245
+ import { stripAnsi, stringWidth, truncate, styled, SGR } from '@oakoliver/lipgloss';
246
+
247
+ stripAnsi('\x1b[1mHello\x1b[0m') // 'Hello'
248
+ stringWidth('\x1b[1mHello\x1b[0m') // 5 (ignores ANSI, handles CJK)
249
+ truncate(longString, 40) // truncate to 40 visible chars
250
+ styled('Hi', { bold: true, fg: { type: 'rgb', value: 0, r: 255, g: 0, b: 0 } })
251
+ ```
252
+
253
+ ## Attribution
254
+
255
+ This is a TypeScript port of [charmbracelet/lipgloss](https://github.com/charmbracelet/lipgloss), originally written in Go by [Charmbracelet, Inc.](https://charm.sh). Licensed under MIT.
256
+
257
+ ## License
258
+
259
+ MIT
package/dist/ansi.d.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * ANSI escape code utilities for terminal styling.
3
+ * Pure TypeScript implementation — no dependencies.
4
+ */
5
+ /** SGR (Select Graphic Rendition) codes */
6
+ export declare const SGR: {
7
+ readonly reset: "\u001B[0m";
8
+ readonly bold: "\u001B[1m";
9
+ readonly faint: "\u001B[2m";
10
+ readonly italic: "\u001B[3m";
11
+ readonly underline: "\u001B[4m";
12
+ readonly blink: "\u001B[5m";
13
+ readonly reverse: "\u001B[7m";
14
+ readonly strikethrough: "\u001B[9m";
15
+ readonly underlineNone: "\u001B[24m";
16
+ readonly underlineSingle: "\u001B[4m";
17
+ readonly underlineDouble: "\u001B[4:2m";
18
+ readonly underlineCurly: "\u001B[4:3m";
19
+ readonly underlineDotted: "\u001B[4:4m";
20
+ readonly underlineDashed: "\u001B[4:5m";
21
+ readonly resetBold: "\u001B[22m";
22
+ readonly resetItalic: "\u001B[23m";
23
+ readonly resetUnderline: "\u001B[24m";
24
+ readonly resetBlink: "\u001B[25m";
25
+ readonly resetReverse: "\u001B[27m";
26
+ readonly resetStrikethrough: "\u001B[29m";
27
+ };
28
+ /** Set foreground color using ANSI basic (0-7), bright (8-15), 256, or RGB */
29
+ export declare function fgColor(r: number, g: number, b: number): string;
30
+ export declare function fgAnsi256(n: number): string;
31
+ export declare function fgBasic(n: number): string;
32
+ /** Set background color using ANSI basic (0-7), bright (8-15), 256, or RGB */
33
+ export declare function bgColor(r: number, g: number, b: number): string;
34
+ export declare function bgAnsi256(n: number): string;
35
+ export declare function bgBasic(n: number): string;
36
+ /** Set underline color (not universally supported) */
37
+ export declare function ulColor(r: number, g: number, b: number): string;
38
+ export declare function ulAnsi256(n: number): string;
39
+ /** OSC hyperlink escape sequences */
40
+ export declare function setHyperlink(url: string, params?: string): string;
41
+ export declare function resetHyperlink(): string;
42
+ export declare function stripAnsi(str: string): string;
43
+ /**
44
+ * Measure the visible (printable) width of a string, ignoring ANSI codes.
45
+ * This is a simplified implementation that handles common cases.
46
+ * For full Unicode width support, a proper East Asian Width implementation
47
+ * would be needed, but this covers the vast majority of use cases.
48
+ */
49
+ export declare function stringWidth(str: string): number;
50
+ /**
51
+ * Truncate a string to a maximum visible width, stripping ANSI codes as needed.
52
+ */
53
+ export declare function truncate(str: string, maxWidth: number): string;
54
+ /**
55
+ * Build an ANSI styled string by wrapping content in SGR sequences.
56
+ */
57
+ export interface AnsiStyleOptions {
58
+ bold?: boolean;
59
+ faint?: boolean;
60
+ italic?: boolean;
61
+ underline?: boolean;
62
+ underlineStyle?: UnderlineStyle;
63
+ blink?: boolean;
64
+ reverse?: boolean;
65
+ strikethrough?: boolean;
66
+ fg?: ColorValue | null;
67
+ bg?: ColorValue | null;
68
+ ul?: ColorValue | null;
69
+ }
70
+ export type UnderlineStyle = 'none' | 'single' | 'double' | 'curly' | 'dotted' | 'dashed';
71
+ export interface ColorValue {
72
+ type: 'basic' | 'ansi256' | 'rgb';
73
+ value: number;
74
+ r?: number;
75
+ g?: number;
76
+ b?: number;
77
+ }
78
+ /**
79
+ * Apply ANSI styling to a string.
80
+ */
81
+ export declare function styled(str: string, opts: AnsiStyleOptions): string;
82
+ //# sourceMappingURL=ansi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,2CAA2C;AAC3C,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;CA0BN,CAAC;AAEX,8EAA8E;AAC9E,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGzC;AAED,8EAA8E;AAC9E,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGzC;AAED,sDAAsD;AACtD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CA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AM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAoClE"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Border definitions and built-in border styles.
3
+ */
4
+ /** Border character set */
5
+ export interface Border {
6
+ top: string;
7
+ bottom: string;
8
+ left: string;
9
+ right: string;
10
+ topLeft: string;
11
+ topRight: string;
12
+ bottomLeft: string;
13
+ bottomRight: string;
14
+ middleLeft: string;
15
+ middleRight: string;
16
+ middle: string;
17
+ middleTop: string;
18
+ middleBottom: string;
19
+ }
20
+ /** No border */
21
+ export declare const noBorder: Border;
22
+ /** Standard border with 90-degree corners */
23
+ export declare function normalBorder(): Border;
24
+ /** Rounded corners */
25
+ export declare function roundedBorder(): Border;
26
+ /** Full block border */
27
+ export declare function blockBorder(): Border;
28
+ /** Outer half-block border */
29
+ export declare function outerHalfBlockBorder(): Border;
30
+ /** Inner half-block border */
31
+ export declare function innerHalfBlockBorder(): Border;
32
+ /** Thick border */
33
+ export declare function thickBorder(): Border;
34
+ /** Double-line border */
35
+ export declare function doubleBorder(): Border;
36
+ /** Hidden border (spaces) — maintains layout without visible borders */
37
+ export declare function hiddenBorder(): Border;
38
+ /** Markdown-style table border */
39
+ export declare function markdownBorder(): Border;
40
+ /** ASCII border using +, -, | characters */
41
+ export declare function asciiBorder(): Border;
42
+ /** Get the max rune width of a border edge string */
43
+ export declare function maxRuneWidth(str: string): number;
44
+ /** Get the size of the top edge of the border */
45
+ export declare function getTopSize(b: Border): number;
46
+ /** Get the size of the right edge of the border */
47
+ export declare function getRightSize(b: Border): number;
48
+ /** Get the size of the bottom edge of the border */
49
+ export declare function getBottomSize(b: Border): number;
50
+ /** Get the size of the left edge of the border */
51
+ export declare function getLeftSize(b: Border): number;
52
+ /** Check if a border is the "no border" (all empty strings) */
53
+ export declare function isNoBorder(b: Border): boolean;
54
+ //# sourceMappingURL=border.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"border.d.ts","sourceRoot":"","sources":["../src/border.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,2BAA2B;AAC3B,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAWD,gBAAgB;AAChB,eAAO,MAAM,QAAQ,EAAE,MAAmB,CAAC;AAE3C,6CAA6C;AAC7C,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED,sBAAsB;AACtB,wBAAgB,aAAa,IAAI,MAAM,CAMtC;AAED,wBAAwB;AACxB,wBAAgB,WAAW,IAAI,MAAM,CAMpC;AAED,8BAA8B;AAC9B,wBAAgB,oBAAoB,IAAI,MAAM,CAK7C;AAED,8BAA8B;AAC9B,wBAAgB,oBAAoB,IAAI,MAAM,CAK7C;AAED,mBAAmB;AACnB,wBAAgB,WAAW,IAAI,MAAM,CAMpC;AAED,yBAAyB;AACzB,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED,wEAAwE;AACxE,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED,kCAAkC;AAClC,wBAAgB,cAAc,IAAI,MAAM,CAMvC;AAED,4CAA4C;AAC5C,wBAAgB,WAAW,IAAI,MAAM,CAMpC;AAED,qDAAqD;AACrD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQhD;AAWD,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,mDAAmD;AACnD,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,oDAAoD;AACpD,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAG7C"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Color types and utilities for terminal styling.
3
+ */
4
+ import type { ColorValue } from './ansi.js';
5
+ /**
6
+ * Represents no color — terminal default.
7
+ */
8
+ export declare const NO_COLOR: unique symbol;
9
+ export type NoColor = typeof NO_COLOR;
10
+ /**
11
+ * RGB color representation.
12
+ */
13
+ export interface RGBColor {
14
+ r: number;
15
+ g: number;
16
+ b: number;
17
+ }
18
+ /**
19
+ * A color that can be used in styling.
20
+ * - null/undefined/NO_COLOR = no color (terminal default)
21
+ * - number 0-15 = ANSI basic color
22
+ * - number 16-255 = ANSI 256 color
23
+ * - string "#RRGGBB" or "#RGB" = hex color
24
+ * - RGBColor = explicit RGB
25
+ */
26
+ export type Color = string | number | RGBColor | NoColor | null | undefined;
27
+ /** ANSI basic color constants (0-15) */
28
+ export declare const Black = 0;
29
+ export declare const Red = 1;
30
+ export declare const Green = 2;
31
+ export declare const Yellow = 3;
32
+ export declare const Blue = 4;
33
+ export declare const Magenta = 5;
34
+ export declare const Cyan = 6;
35
+ export declare const White = 7;
36
+ export declare const BrightBlack = 8;
37
+ export declare const BrightRed = 9;
38
+ export declare const BrightGreen = 10;
39
+ export declare const BrightYellow = 11;
40
+ export declare const BrightBlue = 12;
41
+ export declare const BrightMagenta = 13;
42
+ export declare const BrightCyan = 14;
43
+ export declare const BrightWhite = 15;
44
+ /**
45
+ * Parse a color specification into an internal ColorValue.
46
+ * Returns null for "no color".
47
+ */
48
+ export declare function parseColor(c: Color): ColorValue | null;
49
+ /**
50
+ * Parse a hex color string (#RGB or #RRGGBB) into RGB values.
51
+ */
52
+ export declare function parseHex(hex: string): RGBColor | null;
53
+ /**
54
+ * Convert any Color to RGB values (approximation for ANSI colors).
55
+ */
56
+ export declare function colorToRGB(c: Color): RGBColor | null;
57
+ /**
58
+ * Convert ANSI 256 color index to approximate RGB.
59
+ */
60
+ export declare function ansi256ToRGB(index: number): RGBColor;
61
+ /**
62
+ * Determine if a color is "dark" based on luminance.
63
+ */
64
+ export declare function isDarkColor(c: Color): boolean;
65
+ /**
66
+ * LightDark returns a function that picks a color based on background darkness.
67
+ */
68
+ export declare function lightDark(isDark: boolean): (light: Color, dark: Color) => Color;
69
+ /**
70
+ * Returns the complementary color (180 degrees on the color wheel).
71
+ */
72
+ export declare function complementary(c: Color): Color;
73
+ /**
74
+ * Darken a color by a percentage (0-1).
75
+ */
76
+ export declare function darken(c: Color, percent: number): Color;
77
+ /**
78
+ * Lighten a color by a percentage (0-1).
79
+ */
80
+ export declare function lighten(c: Color, percent: number): Color;
81
+ /**
82
+ * Adjust alpha (0 = transparent, 1 = opaque). Returns an RGBColor
83
+ * (terminal colors don't truly support alpha, but useful for blending).
84
+ */
85
+ export declare function alpha(c: Color, a: number): RGBColor | null;
86
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,MAA0B,CAAC;AACzD,MAAM,MAAM,OAAO,GAAG,OAAO,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,QAAQ;IAC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