@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 +24 -0
- package/README.md +259 -0
- package/dist/ansi.d.ts +82 -0
- package/dist/ansi.d.ts.map +1 -0
- package/dist/border.d.ts +54 -0
- package/dist/border.d.ts.map +1 -0
- package/dist/color.d.ts +86 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/index.cjs +2408 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2309 -0
- package/dist/layout.d.ts +28 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/style.d.ts +247 -0
- package/dist/style.d.ts.map +1 -0
- package/package.json +70 -0
- package/src/ansi.ts +292 -0
- package/src/border.ts +168 -0
- package/src/color.ts +294 -0
- package/src/index.ts +44 -0
- package/src/layout.ts +206 -0
- package/src/style.ts +1131 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Black: () => Black,
|
|
24
|
+
Blue: () => Blue,
|
|
25
|
+
Bottom: () => Bottom,
|
|
26
|
+
BrightBlack: () => BrightBlack,
|
|
27
|
+
BrightBlue: () => BrightBlue,
|
|
28
|
+
BrightCyan: () => BrightCyan,
|
|
29
|
+
BrightGreen: () => BrightGreen,
|
|
30
|
+
BrightMagenta: () => BrightMagenta,
|
|
31
|
+
BrightRed: () => BrightRed,
|
|
32
|
+
BrightWhite: () => BrightWhite,
|
|
33
|
+
BrightYellow: () => BrightYellow,
|
|
34
|
+
Center: () => Center,
|
|
35
|
+
Cyan: () => Cyan,
|
|
36
|
+
Green: () => Green,
|
|
37
|
+
Left: () => Left,
|
|
38
|
+
Magenta: () => Magenta,
|
|
39
|
+
NO_COLOR: () => NO_COLOR,
|
|
40
|
+
Red: () => Red,
|
|
41
|
+
Right: () => Right,
|
|
42
|
+
SGR: () => SGR,
|
|
43
|
+
Style: () => Style,
|
|
44
|
+
Top: () => Top,
|
|
45
|
+
White: () => White,
|
|
46
|
+
Yellow: () => Yellow,
|
|
47
|
+
alpha: () => alpha,
|
|
48
|
+
ansi256ToRGB: () => ansi256ToRGB,
|
|
49
|
+
asciiBorder: () => asciiBorder,
|
|
50
|
+
bgAnsi256: () => bgAnsi256,
|
|
51
|
+
bgBasic: () => bgBasic,
|
|
52
|
+
bgColor: () => bgColor,
|
|
53
|
+
blockBorder: () => blockBorder,
|
|
54
|
+
colorToRGB: () => colorToRGB,
|
|
55
|
+
complementary: () => complementary,
|
|
56
|
+
darken: () => darken,
|
|
57
|
+
doubleBorder: () => doubleBorder,
|
|
58
|
+
fgAnsi256: () => fgAnsi256,
|
|
59
|
+
fgBasic: () => fgBasic,
|
|
60
|
+
fgColor: () => fgColor,
|
|
61
|
+
getBottomSize: () => getBottomSize,
|
|
62
|
+
getFirstRune: () => getFirstRune,
|
|
63
|
+
getLeftSize: () => getLeftSize,
|
|
64
|
+
getLines: () => getLines,
|
|
65
|
+
getRightSize: () => getRightSize,
|
|
66
|
+
getTopSize: () => getTopSize,
|
|
67
|
+
hiddenBorder: () => hiddenBorder,
|
|
68
|
+
innerHalfBlockBorder: () => innerHalfBlockBorder,
|
|
69
|
+
isDarkColor: () => isDarkColor,
|
|
70
|
+
isNoBorder: () => isNoBorder,
|
|
71
|
+
joinHorizontal: () => joinHorizontal,
|
|
72
|
+
joinVertical: () => joinVertical,
|
|
73
|
+
lightDark: () => lightDark,
|
|
74
|
+
lighten: () => lighten,
|
|
75
|
+
markdownBorder: () => markdownBorder,
|
|
76
|
+
maxRuneWidth: () => maxRuneWidth,
|
|
77
|
+
newStyle: () => newStyle,
|
|
78
|
+
noBorder: () => noBorder,
|
|
79
|
+
normalBorder: () => normalBorder,
|
|
80
|
+
outerHalfBlockBorder: () => outerHalfBlockBorder,
|
|
81
|
+
parseColor: () => parseColor,
|
|
82
|
+
parseHex: () => parseHex,
|
|
83
|
+
place: () => place,
|
|
84
|
+
placeHorizontal: () => placeHorizontal,
|
|
85
|
+
placeVertical: () => placeVertical,
|
|
86
|
+
resetHyperlink: () => resetHyperlink,
|
|
87
|
+
roundedBorder: () => roundedBorder,
|
|
88
|
+
setHyperlink: () => setHyperlink,
|
|
89
|
+
stringWidth: () => stringWidth,
|
|
90
|
+
stripAnsi: () => stripAnsi,
|
|
91
|
+
styled: () => styled,
|
|
92
|
+
thickBorder: () => thickBorder,
|
|
93
|
+
truncate: () => truncate,
|
|
94
|
+
ulAnsi256: () => ulAnsi256,
|
|
95
|
+
ulColor: () => ulColor
|
|
96
|
+
});
|
|
97
|
+
module.exports = __toCommonJS(index_exports);
|
|
98
|
+
|
|
99
|
+
// src/ansi.ts
|
|
100
|
+
var ESC = "\x1B";
|
|
101
|
+
var CSI = `${ESC}[`;
|
|
102
|
+
var SGR = {
|
|
103
|
+
reset: `${CSI}0m`,
|
|
104
|
+
bold: `${CSI}1m`,
|
|
105
|
+
faint: `${CSI}2m`,
|
|
106
|
+
italic: `${CSI}3m`,
|
|
107
|
+
underline: `${CSI}4m`,
|
|
108
|
+
blink: `${CSI}5m`,
|
|
109
|
+
reverse: `${CSI}7m`,
|
|
110
|
+
strikethrough: `${CSI}9m`,
|
|
111
|
+
// Underline styles (not universally supported)
|
|
112
|
+
underlineNone: `${CSI}24m`,
|
|
113
|
+
underlineSingle: `${CSI}4m`,
|
|
114
|
+
underlineDouble: `${CSI}4:2m`,
|
|
115
|
+
underlineCurly: `${CSI}4:3m`,
|
|
116
|
+
underlineDotted: `${CSI}4:4m`,
|
|
117
|
+
underlineDashed: `${CSI}4:5m`,
|
|
118
|
+
// Reset specific attributes
|
|
119
|
+
resetBold: `${CSI}22m`,
|
|
120
|
+
resetItalic: `${CSI}23m`,
|
|
121
|
+
resetUnderline: `${CSI}24m`,
|
|
122
|
+
resetBlink: `${CSI}25m`,
|
|
123
|
+
resetReverse: `${CSI}27m`,
|
|
124
|
+
resetStrikethrough: `${CSI}29m`
|
|
125
|
+
};
|
|
126
|
+
function fgColor(r, g, b) {
|
|
127
|
+
return `${CSI}38;2;${r};${g};${b}m`;
|
|
128
|
+
}
|
|
129
|
+
function fgAnsi256(n) {
|
|
130
|
+
return `${CSI}38;5;${n}m`;
|
|
131
|
+
}
|
|
132
|
+
function fgBasic(n) {
|
|
133
|
+
if (n < 8) return `${CSI}${30 + n}m`;
|
|
134
|
+
return `${CSI}${90 + (n - 8)}m`;
|
|
135
|
+
}
|
|
136
|
+
function bgColor(r, g, b) {
|
|
137
|
+
return `${CSI}48;2;${r};${g};${b}m`;
|
|
138
|
+
}
|
|
139
|
+
function bgAnsi256(n) {
|
|
140
|
+
return `${CSI}48;5;${n}m`;
|
|
141
|
+
}
|
|
142
|
+
function bgBasic(n) {
|
|
143
|
+
if (n < 8) return `${CSI}${40 + n}m`;
|
|
144
|
+
return `${CSI}${100 + (n - 8)}m`;
|
|
145
|
+
}
|
|
146
|
+
function ulColor(r, g, b) {
|
|
147
|
+
return `${CSI}58;2;${r};${g};${b}m`;
|
|
148
|
+
}
|
|
149
|
+
function ulAnsi256(n) {
|
|
150
|
+
return `${CSI}58;5;${n}m`;
|
|
151
|
+
}
|
|
152
|
+
function setHyperlink(url, params) {
|
|
153
|
+
const p = params ? params : "";
|
|
154
|
+
return `${ESC}]8;${p};${url}${ESC}\\`;
|
|
155
|
+
}
|
|
156
|
+
function resetHyperlink() {
|
|
157
|
+
return `${ESC}]8;;${ESC}\\`;
|
|
158
|
+
}
|
|
159
|
+
var ANSI_REGEX = /[\x1b\x9b][[()#;?]*(?:[0-9]{1,4}(?:[;:][0-9]{0,4})*)?[0-9A-ORZcf-nqry=><~]|\x1b\]8;[^\x1b]*\x1b\\/g;
|
|
160
|
+
function stripAnsi(str) {
|
|
161
|
+
return str.replace(ANSI_REGEX, "");
|
|
162
|
+
}
|
|
163
|
+
function stringWidth(str) {
|
|
164
|
+
const stripped = stripAnsi(str);
|
|
165
|
+
let width = 0;
|
|
166
|
+
for (let i = 0; i < stripped.length; i++) {
|
|
167
|
+
const code = stripped.charCodeAt(i);
|
|
168
|
+
if (code >= 768 && code <= 879) continue;
|
|
169
|
+
if (code >= 6832 && code <= 6911) continue;
|
|
170
|
+
if (code >= 7616 && code <= 7679) continue;
|
|
171
|
+
if (code >= 8400 && code <= 8447) continue;
|
|
172
|
+
if (code >= 65056 && code <= 65071) continue;
|
|
173
|
+
if (code >= 55296 && code <= 56319) {
|
|
174
|
+
const next = stripped.charCodeAt(i + 1);
|
|
175
|
+
if (next >= 56320 && next <= 57343) {
|
|
176
|
+
const cp = (code - 55296) * 1024 + (next - 56320) + 65536;
|
|
177
|
+
if (cp >= 131072 && cp <= 262143) {
|
|
178
|
+
width += 2;
|
|
179
|
+
} else {
|
|
180
|
+
width += 1;
|
|
181
|
+
}
|
|
182
|
+
i++;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (isFullWidth(code)) {
|
|
187
|
+
width += 2;
|
|
188
|
+
} else if (code === 9) {
|
|
189
|
+
width += 4;
|
|
190
|
+
} else {
|
|
191
|
+
width += 1;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return width;
|
|
195
|
+
}
|
|
196
|
+
function isFullWidth(code) {
|
|
197
|
+
return code >= 4352 && code <= 4447 || // Hangul Jamo
|
|
198
|
+
code >= 11904 && code <= 12350 || // CJK Radicals, Kangxi, Ideographic Description
|
|
199
|
+
code >= 12352 && code <= 13247 || // Hiragana, Katakana, Bopomofo, etc.
|
|
200
|
+
code >= 13312 && code <= 19903 || // CJK Unified Ideographs Extension A
|
|
201
|
+
code >= 19968 && code <= 42191 || // CJK Unified Ideographs, Yi
|
|
202
|
+
code >= 44032 && code <= 55203 || // Hangul Syllables
|
|
203
|
+
code >= 63744 && code <= 64255 || // CJK Compatibility Ideographs
|
|
204
|
+
code >= 65072 && code <= 65135 || // CJK Compatibility Forms, Small Form Variants
|
|
205
|
+
code >= 65281 && code <= 65376 || // Fullwidth Forms
|
|
206
|
+
code >= 65504 && code <= 65510;
|
|
207
|
+
}
|
|
208
|
+
function truncate(str, maxWidth) {
|
|
209
|
+
if (maxWidth <= 0) return "";
|
|
210
|
+
if (stringWidth(str) <= maxWidth) return str;
|
|
211
|
+
let width = 0;
|
|
212
|
+
let result = "";
|
|
213
|
+
let inEscape = false;
|
|
214
|
+
let escapeSeq = "";
|
|
215
|
+
for (let i = 0; i < str.length; i++) {
|
|
216
|
+
const ch = str[i];
|
|
217
|
+
if (inEscape) {
|
|
218
|
+
escapeSeq += ch;
|
|
219
|
+
if (/[A-Za-z~]/.test(ch) || escapeSeq.startsWith("\x1B]") && ch === "\\" && escapeSeq[escapeSeq.length - 2] === "\x1B") {
|
|
220
|
+
result += escapeSeq;
|
|
221
|
+
inEscape = false;
|
|
222
|
+
escapeSeq = "";
|
|
223
|
+
}
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (ch === "\x1B" || ch === "\x9B") {
|
|
227
|
+
inEscape = true;
|
|
228
|
+
escapeSeq = ch;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const code = ch.charCodeAt(0);
|
|
232
|
+
const charWidth = isFullWidth(code) ? 2 : 1;
|
|
233
|
+
if (width + charWidth > maxWidth) break;
|
|
234
|
+
width += charWidth;
|
|
235
|
+
result += ch;
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
function styled(str, opts) {
|
|
240
|
+
let prefix = "";
|
|
241
|
+
let suffix = "";
|
|
242
|
+
if (opts.bold) {
|
|
243
|
+
prefix += SGR.bold;
|
|
244
|
+
}
|
|
245
|
+
if (opts.faint) {
|
|
246
|
+
prefix += SGR.faint;
|
|
247
|
+
}
|
|
248
|
+
if (opts.italic) {
|
|
249
|
+
prefix += SGR.italic;
|
|
250
|
+
}
|
|
251
|
+
if (opts.underline || opts.underlineStyle && opts.underlineStyle !== "none") {
|
|
252
|
+
const style = opts.underlineStyle || "single";
|
|
253
|
+
switch (style) {
|
|
254
|
+
case "single":
|
|
255
|
+
prefix += SGR.underlineSingle;
|
|
256
|
+
break;
|
|
257
|
+
case "double":
|
|
258
|
+
prefix += SGR.underlineDouble;
|
|
259
|
+
break;
|
|
260
|
+
case "curly":
|
|
261
|
+
prefix += SGR.underlineCurly;
|
|
262
|
+
break;
|
|
263
|
+
case "dotted":
|
|
264
|
+
prefix += SGR.underlineDotted;
|
|
265
|
+
break;
|
|
266
|
+
case "dashed":
|
|
267
|
+
prefix += SGR.underlineDashed;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (opts.blink) {
|
|
272
|
+
prefix += SGR.blink;
|
|
273
|
+
}
|
|
274
|
+
if (opts.reverse) {
|
|
275
|
+
prefix += SGR.reverse;
|
|
276
|
+
}
|
|
277
|
+
if (opts.strikethrough) {
|
|
278
|
+
prefix += SGR.strikethrough;
|
|
279
|
+
}
|
|
280
|
+
if (opts.fg) {
|
|
281
|
+
prefix += colorToFg(opts.fg);
|
|
282
|
+
}
|
|
283
|
+
if (opts.bg) {
|
|
284
|
+
prefix += colorToBg(opts.bg);
|
|
285
|
+
}
|
|
286
|
+
if (opts.ul) {
|
|
287
|
+
prefix += colorToUl(opts.ul);
|
|
288
|
+
}
|
|
289
|
+
if (prefix) {
|
|
290
|
+
suffix = SGR.reset;
|
|
291
|
+
}
|
|
292
|
+
return prefix + str + suffix;
|
|
293
|
+
}
|
|
294
|
+
function colorToFg(c) {
|
|
295
|
+
switch (c.type) {
|
|
296
|
+
case "basic":
|
|
297
|
+
return fgBasic(c.value);
|
|
298
|
+
case "ansi256":
|
|
299
|
+
return fgAnsi256(c.value);
|
|
300
|
+
case "rgb":
|
|
301
|
+
return fgColor(c.r, c.g, c.b);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function colorToBg(c) {
|
|
305
|
+
switch (c.type) {
|
|
306
|
+
case "basic":
|
|
307
|
+
return bgBasic(c.value);
|
|
308
|
+
case "ansi256":
|
|
309
|
+
return bgAnsi256(c.value);
|
|
310
|
+
case "rgb":
|
|
311
|
+
return bgColor(c.r, c.g, c.b);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function colorToUl(c) {
|
|
315
|
+
switch (c.type) {
|
|
316
|
+
case "basic":
|
|
317
|
+
return ulAnsi256(c.value);
|
|
318
|
+
// underline color uses 256 encoding for basic too
|
|
319
|
+
case "ansi256":
|
|
320
|
+
return ulAnsi256(c.value);
|
|
321
|
+
case "rgb":
|
|
322
|
+
return ulColor(c.r, c.g, c.b);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// src/color.ts
|
|
327
|
+
var NO_COLOR = /* @__PURE__ */ Symbol("NoColor");
|
|
328
|
+
var Black = 0;
|
|
329
|
+
var Red = 1;
|
|
330
|
+
var Green = 2;
|
|
331
|
+
var Yellow = 3;
|
|
332
|
+
var Blue = 4;
|
|
333
|
+
var Magenta = 5;
|
|
334
|
+
var Cyan = 6;
|
|
335
|
+
var White = 7;
|
|
336
|
+
var BrightBlack = 8;
|
|
337
|
+
var BrightRed = 9;
|
|
338
|
+
var BrightGreen = 10;
|
|
339
|
+
var BrightYellow = 11;
|
|
340
|
+
var BrightBlue = 12;
|
|
341
|
+
var BrightMagenta = 13;
|
|
342
|
+
var BrightCyan = 14;
|
|
343
|
+
var BrightWhite = 15;
|
|
344
|
+
function parseColor(c) {
|
|
345
|
+
if (c === null || c === void 0 || c === NO_COLOR) return null;
|
|
346
|
+
if (typeof c === "number") {
|
|
347
|
+
if (c < 0) c = -c;
|
|
348
|
+
if (c < 16) return { type: "basic", value: c };
|
|
349
|
+
if (c < 256) return { type: "ansi256", value: c };
|
|
350
|
+
return {
|
|
351
|
+
type: "rgb",
|
|
352
|
+
value: 0,
|
|
353
|
+
r: c >> 16 & 255,
|
|
354
|
+
g: c >> 8 & 255,
|
|
355
|
+
b: c & 255
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (typeof c === "string") {
|
|
359
|
+
if (c.startsWith("#")) {
|
|
360
|
+
const rgb = parseHex(c);
|
|
361
|
+
if (!rgb) return null;
|
|
362
|
+
return { type: "rgb", value: 0, ...rgb };
|
|
363
|
+
}
|
|
364
|
+
const n = parseInt(c, 10);
|
|
365
|
+
if (!isNaN(n)) {
|
|
366
|
+
return parseColor(n);
|
|
367
|
+
}
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
if (typeof c === "object" && "r" in c && "g" in c && "b" in c) {
|
|
371
|
+
return { type: "rgb", value: 0, r: c.r, g: c.g, b: c.b };
|
|
372
|
+
}
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
function parseHex(hex) {
|
|
376
|
+
if (!hex.startsWith("#")) return null;
|
|
377
|
+
if (hex.length === 7) {
|
|
378
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
379
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
380
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
381
|
+
if (isNaN(r) || isNaN(g) || isNaN(b)) return null;
|
|
382
|
+
return { r, g, b };
|
|
383
|
+
}
|
|
384
|
+
if (hex.length === 4) {
|
|
385
|
+
const r = parseInt(hex[1], 16) * 17;
|
|
386
|
+
const g = parseInt(hex[2], 16) * 17;
|
|
387
|
+
const b = parseInt(hex[3], 16) * 17;
|
|
388
|
+
if (isNaN(r) || isNaN(g) || isNaN(b)) return null;
|
|
389
|
+
return { r, g, b };
|
|
390
|
+
}
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
function colorToRGB(c) {
|
|
394
|
+
const cv = parseColor(c);
|
|
395
|
+
if (!cv) return null;
|
|
396
|
+
if (cv.type === "rgb") return { r: cv.r, g: cv.g, b: cv.b };
|
|
397
|
+
if (cv.type === "ansi256") return ansi256ToRGB(cv.value);
|
|
398
|
+
if (cv.type === "basic") return ansi256ToRGB(cv.value);
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
var ANSI_16_COLORS = [
|
|
402
|
+
{ r: 0, g: 0, b: 0 },
|
|
403
|
+
// Black
|
|
404
|
+
{ r: 170, g: 0, b: 0 },
|
|
405
|
+
// Red
|
|
406
|
+
{ r: 0, g: 170, b: 0 },
|
|
407
|
+
// Green
|
|
408
|
+
{ r: 170, g: 85, b: 0 },
|
|
409
|
+
// Yellow
|
|
410
|
+
{ r: 0, g: 0, b: 170 },
|
|
411
|
+
// Blue
|
|
412
|
+
{ r: 170, g: 0, b: 170 },
|
|
413
|
+
// Magenta
|
|
414
|
+
{ r: 0, g: 170, b: 170 },
|
|
415
|
+
// Cyan
|
|
416
|
+
{ r: 170, g: 170, b: 170 },
|
|
417
|
+
// White
|
|
418
|
+
{ r: 85, g: 85, b: 85 },
|
|
419
|
+
// Bright Black
|
|
420
|
+
{ r: 255, g: 85, b: 85 },
|
|
421
|
+
// Bright Red
|
|
422
|
+
{ r: 85, g: 255, b: 85 },
|
|
423
|
+
// Bright Green
|
|
424
|
+
{ r: 255, g: 255, b: 85 },
|
|
425
|
+
// Bright Yellow
|
|
426
|
+
{ r: 85, g: 85, b: 255 },
|
|
427
|
+
// Bright Blue
|
|
428
|
+
{ r: 255, g: 85, b: 255 },
|
|
429
|
+
// Bright Magenta
|
|
430
|
+
{ r: 85, g: 255, b: 255 },
|
|
431
|
+
// Bright Cyan
|
|
432
|
+
{ r: 255, g: 255, b: 255 }
|
|
433
|
+
// Bright White
|
|
434
|
+
];
|
|
435
|
+
function ansi256ToRGB(index) {
|
|
436
|
+
if (index < 16) return ANSI_16_COLORS[index];
|
|
437
|
+
if (index < 232) {
|
|
438
|
+
const i = index - 16;
|
|
439
|
+
const r = Math.floor(i / 36);
|
|
440
|
+
const g = Math.floor(i % 36 / 6);
|
|
441
|
+
const b = i % 6;
|
|
442
|
+
return {
|
|
443
|
+
r: r ? r * 40 + 55 : 0,
|
|
444
|
+
g: g ? g * 40 + 55 : 0,
|
|
445
|
+
b: b ? b * 40 + 55 : 0
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
const v = (index - 232) * 10 + 8;
|
|
449
|
+
return { r: v, g: v, b: v };
|
|
450
|
+
}
|
|
451
|
+
function isDarkColor(c) {
|
|
452
|
+
const rgb = colorToRGB(c);
|
|
453
|
+
if (!rgb) return true;
|
|
454
|
+
const max = Math.max(rgb.r, rgb.g, rgb.b) / 255;
|
|
455
|
+
const min = Math.min(rgb.r, rgb.g, rgb.b) / 255;
|
|
456
|
+
const l = (max + min) / 2;
|
|
457
|
+
return l < 0.5;
|
|
458
|
+
}
|
|
459
|
+
function lightDark(isDark) {
|
|
460
|
+
return (light, dark) => isDark ? dark : light;
|
|
461
|
+
}
|
|
462
|
+
function complementary(c) {
|
|
463
|
+
const rgb = colorToRGB(c);
|
|
464
|
+
if (!rgb) return null;
|
|
465
|
+
const { h, s, v } = rgbToHsv(rgb.r, rgb.g, rgb.b);
|
|
466
|
+
const newH = (h + 180) % 360;
|
|
467
|
+
const result = hsvToRgb(newH, s, v);
|
|
468
|
+
return result;
|
|
469
|
+
}
|
|
470
|
+
function darken(c, percent) {
|
|
471
|
+
const rgb = colorToRGB(c);
|
|
472
|
+
if (!rgb) return null;
|
|
473
|
+
const mult = 1 - clamp(percent, 0, 1);
|
|
474
|
+
return {
|
|
475
|
+
r: Math.round(rgb.r * mult),
|
|
476
|
+
g: Math.round(rgb.g * mult),
|
|
477
|
+
b: Math.round(rgb.b * mult)
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function lighten(c, percent) {
|
|
481
|
+
const rgb = colorToRGB(c);
|
|
482
|
+
if (!rgb) return null;
|
|
483
|
+
const add = 255 * clamp(percent, 0, 1);
|
|
484
|
+
return {
|
|
485
|
+
r: Math.min(255, Math.round(rgb.r + add)),
|
|
486
|
+
g: Math.min(255, Math.round(rgb.g + add)),
|
|
487
|
+
b: Math.min(255, Math.round(rgb.b + add))
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function alpha(c, a) {
|
|
491
|
+
const rgb = colorToRGB(c);
|
|
492
|
+
if (!rgb) return null;
|
|
493
|
+
const al = clamp(a, 0, 1);
|
|
494
|
+
return {
|
|
495
|
+
r: Math.round(rgb.r * al),
|
|
496
|
+
g: Math.round(rgb.g * al),
|
|
497
|
+
b: Math.round(rgb.b * al)
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function clamp(v, lo, hi) {
|
|
501
|
+
return Math.min(hi, Math.max(lo, v));
|
|
502
|
+
}
|
|
503
|
+
function rgbToHsv(r, g, b) {
|
|
504
|
+
r /= 255;
|
|
505
|
+
g /= 255;
|
|
506
|
+
b /= 255;
|
|
507
|
+
const max = Math.max(r, g, b);
|
|
508
|
+
const min = Math.min(r, g, b);
|
|
509
|
+
const d = max - min;
|
|
510
|
+
let h = 0;
|
|
511
|
+
const s = max === 0 ? 0 : d / max;
|
|
512
|
+
const v = max;
|
|
513
|
+
if (d !== 0) {
|
|
514
|
+
if (max === r) h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
515
|
+
else if (max === g) h = ((b - r) / d + 2) / 6;
|
|
516
|
+
else h = ((r - g) / d + 4) / 6;
|
|
517
|
+
}
|
|
518
|
+
return { h: h * 360, s, v };
|
|
519
|
+
}
|
|
520
|
+
function hsvToRgb(h, s, v) {
|
|
521
|
+
h = (h % 360 + 360) % 360;
|
|
522
|
+
const c = v * s;
|
|
523
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
524
|
+
const m = v - c;
|
|
525
|
+
let r = 0, g = 0, b = 0;
|
|
526
|
+
if (h < 60) {
|
|
527
|
+
r = c;
|
|
528
|
+
g = x;
|
|
529
|
+
} else if (h < 120) {
|
|
530
|
+
r = x;
|
|
531
|
+
g = c;
|
|
532
|
+
} else if (h < 180) {
|
|
533
|
+
g = c;
|
|
534
|
+
b = x;
|
|
535
|
+
} else if (h < 240) {
|
|
536
|
+
g = x;
|
|
537
|
+
b = c;
|
|
538
|
+
} else if (h < 300) {
|
|
539
|
+
r = x;
|
|
540
|
+
b = c;
|
|
541
|
+
} else {
|
|
542
|
+
r = c;
|
|
543
|
+
b = x;
|
|
544
|
+
}
|
|
545
|
+
return {
|
|
546
|
+
r: Math.round((r + m) * 255),
|
|
547
|
+
g: Math.round((g + m) * 255),
|
|
548
|
+
b: Math.round((b + m) * 255)
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// src/border.ts
|
|
553
|
+
function border(b) {
|
|
554
|
+
return {
|
|
555
|
+
top: "",
|
|
556
|
+
bottom: "",
|
|
557
|
+
left: "",
|
|
558
|
+
right: "",
|
|
559
|
+
topLeft: "",
|
|
560
|
+
topRight: "",
|
|
561
|
+
bottomLeft: "",
|
|
562
|
+
bottomRight: "",
|
|
563
|
+
middleLeft: "",
|
|
564
|
+
middleRight: "",
|
|
565
|
+
middle: "",
|
|
566
|
+
middleTop: "",
|
|
567
|
+
middleBottom: "",
|
|
568
|
+
...b
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
var noBorder = border({});
|
|
572
|
+
function normalBorder() {
|
|
573
|
+
return border({
|
|
574
|
+
top: "\u2500",
|
|
575
|
+
bottom: "\u2500",
|
|
576
|
+
left: "\u2502",
|
|
577
|
+
right: "\u2502",
|
|
578
|
+
topLeft: "\u250C",
|
|
579
|
+
topRight: "\u2510",
|
|
580
|
+
bottomLeft: "\u2514",
|
|
581
|
+
bottomRight: "\u2518",
|
|
582
|
+
middleLeft: "\u251C",
|
|
583
|
+
middleRight: "\u2524",
|
|
584
|
+
middle: "\u253C",
|
|
585
|
+
middleTop: "\u252C",
|
|
586
|
+
middleBottom: "\u2534"
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
function roundedBorder() {
|
|
590
|
+
return border({
|
|
591
|
+
top: "\u2500",
|
|
592
|
+
bottom: "\u2500",
|
|
593
|
+
left: "\u2502",
|
|
594
|
+
right: "\u2502",
|
|
595
|
+
topLeft: "\u256D",
|
|
596
|
+
topRight: "\u256E",
|
|
597
|
+
bottomLeft: "\u2570",
|
|
598
|
+
bottomRight: "\u256F",
|
|
599
|
+
middleLeft: "\u251C",
|
|
600
|
+
middleRight: "\u2524",
|
|
601
|
+
middle: "\u253C",
|
|
602
|
+
middleTop: "\u252C",
|
|
603
|
+
middleBottom: "\u2534"
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
function blockBorder() {
|
|
607
|
+
return border({
|
|
608
|
+
top: "\u2588",
|
|
609
|
+
bottom: "\u2588",
|
|
610
|
+
left: "\u2588",
|
|
611
|
+
right: "\u2588",
|
|
612
|
+
topLeft: "\u2588",
|
|
613
|
+
topRight: "\u2588",
|
|
614
|
+
bottomLeft: "\u2588",
|
|
615
|
+
bottomRight: "\u2588",
|
|
616
|
+
middleLeft: "\u2588",
|
|
617
|
+
middleRight: "\u2588",
|
|
618
|
+
middle: "\u2588",
|
|
619
|
+
middleTop: "\u2588",
|
|
620
|
+
middleBottom: "\u2588"
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
function outerHalfBlockBorder() {
|
|
624
|
+
return border({
|
|
625
|
+
top: "\u2580",
|
|
626
|
+
bottom: "\u2584",
|
|
627
|
+
left: "\u258C",
|
|
628
|
+
right: "\u2590",
|
|
629
|
+
topLeft: "\u259B",
|
|
630
|
+
topRight: "\u259C",
|
|
631
|
+
bottomLeft: "\u2599",
|
|
632
|
+
bottomRight: "\u259F"
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
function innerHalfBlockBorder() {
|
|
636
|
+
return border({
|
|
637
|
+
top: "\u2584",
|
|
638
|
+
bottom: "\u2580",
|
|
639
|
+
left: "\u2590",
|
|
640
|
+
right: "\u258C",
|
|
641
|
+
topLeft: "\u2597",
|
|
642
|
+
topRight: "\u2596",
|
|
643
|
+
bottomLeft: "\u259D",
|
|
644
|
+
bottomRight: "\u2598"
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
function thickBorder() {
|
|
648
|
+
return border({
|
|
649
|
+
top: "\u2501",
|
|
650
|
+
bottom: "\u2501",
|
|
651
|
+
left: "\u2503",
|
|
652
|
+
right: "\u2503",
|
|
653
|
+
topLeft: "\u250F",
|
|
654
|
+
topRight: "\u2513",
|
|
655
|
+
bottomLeft: "\u2517",
|
|
656
|
+
bottomRight: "\u251B",
|
|
657
|
+
middleLeft: "\u2523",
|
|
658
|
+
middleRight: "\u252B",
|
|
659
|
+
middle: "\u254B",
|
|
660
|
+
middleTop: "\u2533",
|
|
661
|
+
middleBottom: "\u253B"
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
function doubleBorder() {
|
|
665
|
+
return border({
|
|
666
|
+
top: "\u2550",
|
|
667
|
+
bottom: "\u2550",
|
|
668
|
+
left: "\u2551",
|
|
669
|
+
right: "\u2551",
|
|
670
|
+
topLeft: "\u2554",
|
|
671
|
+
topRight: "\u2557",
|
|
672
|
+
bottomLeft: "\u255A",
|
|
673
|
+
bottomRight: "\u255D",
|
|
674
|
+
middleLeft: "\u2560",
|
|
675
|
+
middleRight: "\u2563",
|
|
676
|
+
middle: "\u256C",
|
|
677
|
+
middleTop: "\u2566",
|
|
678
|
+
middleBottom: "\u2569"
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
function hiddenBorder() {
|
|
682
|
+
return border({
|
|
683
|
+
top: " ",
|
|
684
|
+
bottom: " ",
|
|
685
|
+
left: " ",
|
|
686
|
+
right: " ",
|
|
687
|
+
topLeft: " ",
|
|
688
|
+
topRight: " ",
|
|
689
|
+
bottomLeft: " ",
|
|
690
|
+
bottomRight: " ",
|
|
691
|
+
middleLeft: " ",
|
|
692
|
+
middleRight: " ",
|
|
693
|
+
middle: " ",
|
|
694
|
+
middleTop: " ",
|
|
695
|
+
middleBottom: " "
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
function markdownBorder() {
|
|
699
|
+
return border({
|
|
700
|
+
top: "-",
|
|
701
|
+
bottom: "-",
|
|
702
|
+
left: "|",
|
|
703
|
+
right: "|",
|
|
704
|
+
topLeft: "|",
|
|
705
|
+
topRight: "|",
|
|
706
|
+
bottomLeft: "|",
|
|
707
|
+
bottomRight: "|",
|
|
708
|
+
middleLeft: "|",
|
|
709
|
+
middleRight: "|",
|
|
710
|
+
middle: "|",
|
|
711
|
+
middleTop: "|",
|
|
712
|
+
middleBottom: "|"
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
function asciiBorder() {
|
|
716
|
+
return border({
|
|
717
|
+
top: "-",
|
|
718
|
+
bottom: "-",
|
|
719
|
+
left: "|",
|
|
720
|
+
right: "|",
|
|
721
|
+
topLeft: "+",
|
|
722
|
+
topRight: "+",
|
|
723
|
+
bottomLeft: "+",
|
|
724
|
+
bottomRight: "+",
|
|
725
|
+
middleLeft: "+",
|
|
726
|
+
middleRight: "+",
|
|
727
|
+
middle: "+",
|
|
728
|
+
middleTop: "+",
|
|
729
|
+
middleBottom: "+"
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
function maxRuneWidth(str) {
|
|
733
|
+
if (!str) return 0;
|
|
734
|
+
if (str.length === 1) return stringWidth(str);
|
|
735
|
+
let width = 0;
|
|
736
|
+
for (const ch of str) {
|
|
737
|
+
width = Math.max(width, stringWidth(ch));
|
|
738
|
+
}
|
|
739
|
+
return width;
|
|
740
|
+
}
|
|
741
|
+
function getBorderEdgeWidth(...parts) {
|
|
742
|
+
let max = 0;
|
|
743
|
+
for (const part of parts) {
|
|
744
|
+
max = Math.max(max, maxRuneWidth(part));
|
|
745
|
+
}
|
|
746
|
+
return max;
|
|
747
|
+
}
|
|
748
|
+
function getTopSize(b) {
|
|
749
|
+
return getBorderEdgeWidth(b.topLeft, b.top, b.topRight);
|
|
750
|
+
}
|
|
751
|
+
function getRightSize(b) {
|
|
752
|
+
return getBorderEdgeWidth(b.topRight, b.right, b.bottomRight);
|
|
753
|
+
}
|
|
754
|
+
function getBottomSize(b) {
|
|
755
|
+
return getBorderEdgeWidth(b.bottomLeft, b.bottom, b.bottomRight);
|
|
756
|
+
}
|
|
757
|
+
function getLeftSize(b) {
|
|
758
|
+
return getBorderEdgeWidth(b.topLeft, b.left, b.bottomLeft);
|
|
759
|
+
}
|
|
760
|
+
function isNoBorder(b) {
|
|
761
|
+
return !b.top && !b.bottom && !b.left && !b.right && !b.topLeft && !b.topRight && !b.bottomLeft && !b.bottomRight;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/style.ts
|
|
765
|
+
var Top = 0;
|
|
766
|
+
var Bottom = 1;
|
|
767
|
+
var Center = 0.5;
|
|
768
|
+
var Left = 0;
|
|
769
|
+
var Right = 1;
|
|
770
|
+
function clampPos(p) {
|
|
771
|
+
return Math.min(1, Math.max(0, p));
|
|
772
|
+
}
|
|
773
|
+
function whichSidesInt(...args) {
|
|
774
|
+
switch (args.length) {
|
|
775
|
+
case 1:
|
|
776
|
+
return { top: args[0], right: args[0], bottom: args[0], left: args[0] };
|
|
777
|
+
case 2:
|
|
778
|
+
return { top: args[0], right: args[1], bottom: args[0], left: args[1] };
|
|
779
|
+
case 3:
|
|
780
|
+
return { top: args[0], right: args[1], bottom: args[2], left: args[1] };
|
|
781
|
+
case 4:
|
|
782
|
+
return { top: args[0], right: args[1], bottom: args[2], left: args[3] };
|
|
783
|
+
default:
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
function whichSidesBool(...args) {
|
|
788
|
+
switch (args.length) {
|
|
789
|
+
case 1:
|
|
790
|
+
return { top: args[0], right: args[0], bottom: args[0], left: args[0] };
|
|
791
|
+
case 2:
|
|
792
|
+
return { top: args[0], right: args[1], bottom: args[0], left: args[1] };
|
|
793
|
+
case 3:
|
|
794
|
+
return { top: args[0], right: args[1], bottom: args[2], left: args[1] };
|
|
795
|
+
case 4:
|
|
796
|
+
return { top: args[0], right: args[1], bottom: args[2], left: args[3] };
|
|
797
|
+
default:
|
|
798
|
+
return null;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function whichSidesColor(...args) {
|
|
802
|
+
switch (args.length) {
|
|
803
|
+
case 1:
|
|
804
|
+
return { top: args[0], right: args[0], bottom: args[0], left: args[0] };
|
|
805
|
+
case 2:
|
|
806
|
+
return { top: args[0], right: args[1], bottom: args[0], left: args[1] };
|
|
807
|
+
case 3:
|
|
808
|
+
return { top: args[0], right: args[1], bottom: args[2], left: args[1] };
|
|
809
|
+
case 4:
|
|
810
|
+
return { top: args[0], right: args[1], bottom: args[2], left: args[3] };
|
|
811
|
+
default:
|
|
812
|
+
return null;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
function getLines(s) {
|
|
816
|
+
s = s.replace(/\t/g, " ").replace(/\r\n/g, "\n");
|
|
817
|
+
const lines = s.split("\n");
|
|
818
|
+
let widest = 0;
|
|
819
|
+
for (const l of lines) {
|
|
820
|
+
const w = stringWidth(l);
|
|
821
|
+
if (w > widest) widest = w;
|
|
822
|
+
}
|
|
823
|
+
return { lines, widest };
|
|
824
|
+
}
|
|
825
|
+
function alignTextHorizontal(str, pos, width, wsStyle) {
|
|
826
|
+
const { lines, widest } = getLines(str);
|
|
827
|
+
const parts = [];
|
|
828
|
+
for (const l of lines) {
|
|
829
|
+
const lineWidth = stringWidth(l);
|
|
830
|
+
const shortAmount = Math.max(0, widest - lineWidth) + Math.max(0, width - Math.max(widest, lineWidth));
|
|
831
|
+
if (shortAmount > 0) {
|
|
832
|
+
const p = clampPos(pos);
|
|
833
|
+
if (p <= 0) {
|
|
834
|
+
parts.push(l + styledSpaces(shortAmount, wsStyle));
|
|
835
|
+
} else if (p >= 1) {
|
|
836
|
+
parts.push(styledSpaces(shortAmount, wsStyle) + l);
|
|
837
|
+
} else {
|
|
838
|
+
const leftPad = Math.floor(shortAmount * p);
|
|
839
|
+
const rightPad = shortAmount - leftPad;
|
|
840
|
+
parts.push(styledSpaces(leftPad, wsStyle) + l + styledSpaces(rightPad, wsStyle));
|
|
841
|
+
}
|
|
842
|
+
} else {
|
|
843
|
+
parts.push(l);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return parts.join("\n");
|
|
847
|
+
}
|
|
848
|
+
function alignTextVertical(str, pos, height) {
|
|
849
|
+
const strHeight = str.split("\n").length;
|
|
850
|
+
if (height <= strHeight) return str;
|
|
851
|
+
const gap = height - strHeight;
|
|
852
|
+
const p = clampPos(pos);
|
|
853
|
+
if (p <= 0) {
|
|
854
|
+
return str + "\n".repeat(gap);
|
|
855
|
+
} else if (p >= 1) {
|
|
856
|
+
return "\n".repeat(gap) + str;
|
|
857
|
+
} else {
|
|
858
|
+
const topPad = Math.round(gap * (1 - p));
|
|
859
|
+
const bottomPad = gap - topPad;
|
|
860
|
+
return "\n".repeat(topPad) + str + "\n".repeat(bottomPad);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
function styledSpaces(n, wsStyle, ch = " ") {
|
|
864
|
+
if (n <= 0) return "";
|
|
865
|
+
const sp = ch.repeat(n);
|
|
866
|
+
if (wsStyle) return styled(sp, wsStyle);
|
|
867
|
+
return sp;
|
|
868
|
+
}
|
|
869
|
+
function padLeft(str, n, wsStyle, ch = " ") {
|
|
870
|
+
if (n <= 0) return str;
|
|
871
|
+
const sp = styledSpaces(n, wsStyle, ch);
|
|
872
|
+
return str.split("\n").map((line) => sp + line).join("\n");
|
|
873
|
+
}
|
|
874
|
+
function padRight(str, n, wsStyle, ch = " ") {
|
|
875
|
+
if (n <= 0) return str;
|
|
876
|
+
const sp = styledSpaces(n, wsStyle, ch);
|
|
877
|
+
return str.split("\n").map((line) => line + sp).join("\n");
|
|
878
|
+
}
|
|
879
|
+
function wordWrap(str, width) {
|
|
880
|
+
if (width <= 0) return str;
|
|
881
|
+
const inputLines = str.split("\n");
|
|
882
|
+
const out = [];
|
|
883
|
+
for (const line of inputLines) {
|
|
884
|
+
if (stringWidth(line) <= width) {
|
|
885
|
+
out.push(line);
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
const words = line.split(/(\s+)/);
|
|
889
|
+
let current = "";
|
|
890
|
+
for (const word of words) {
|
|
891
|
+
const combined = current + word;
|
|
892
|
+
if (stringWidth(combined) <= width) {
|
|
893
|
+
current = combined;
|
|
894
|
+
} else {
|
|
895
|
+
if (current) out.push(current);
|
|
896
|
+
if (stringWidth(word) > width) {
|
|
897
|
+
let rem = word;
|
|
898
|
+
while (stringWidth(rem) > width) {
|
|
899
|
+
let cut = "";
|
|
900
|
+
for (const ch of rem) {
|
|
901
|
+
if (stringWidth(cut + ch) > width) break;
|
|
902
|
+
cut += ch;
|
|
903
|
+
}
|
|
904
|
+
if (!cut) {
|
|
905
|
+
cut = rem[0];
|
|
906
|
+
rem = rem.slice(1);
|
|
907
|
+
} else {
|
|
908
|
+
rem = rem.slice(cut.length);
|
|
909
|
+
}
|
|
910
|
+
out.push(cut);
|
|
911
|
+
}
|
|
912
|
+
current = rem;
|
|
913
|
+
} else {
|
|
914
|
+
current = word;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
if (current) out.push(current);
|
|
919
|
+
}
|
|
920
|
+
return out.join("\n");
|
|
921
|
+
}
|
|
922
|
+
function renderHorizontalEdge(left, middle, right, width) {
|
|
923
|
+
if (!middle) middle = " ";
|
|
924
|
+
const leftW = stringWidth(left);
|
|
925
|
+
const rightW = stringWidth(right);
|
|
926
|
+
const runes = [...middle];
|
|
927
|
+
let j = 0;
|
|
928
|
+
let result = left;
|
|
929
|
+
let i = 0;
|
|
930
|
+
const target = width - leftW - rightW;
|
|
931
|
+
while (i < target) {
|
|
932
|
+
const r = runes[j % runes.length];
|
|
933
|
+
result += r;
|
|
934
|
+
i += stringWidth(r);
|
|
935
|
+
j++;
|
|
936
|
+
}
|
|
937
|
+
result += right;
|
|
938
|
+
return result;
|
|
939
|
+
}
|
|
940
|
+
function getFirstRune(s) {
|
|
941
|
+
if (!s) return s;
|
|
942
|
+
return [...s][0];
|
|
943
|
+
}
|
|
944
|
+
var TAB_WIDTH_DEFAULT = 4;
|
|
945
|
+
var Style = class _Style {
|
|
946
|
+
// Track which properties have been explicitly set
|
|
947
|
+
_set = /* @__PURE__ */ new Set();
|
|
948
|
+
// Internal string value (for SetString / toString)
|
|
949
|
+
_value = "";
|
|
950
|
+
// Boolean attrs
|
|
951
|
+
_bold = false;
|
|
952
|
+
_italic = false;
|
|
953
|
+
_strikethrough = false;
|
|
954
|
+
_reverse = false;
|
|
955
|
+
_blink = false;
|
|
956
|
+
_faint = false;
|
|
957
|
+
_underlineSpaces = false;
|
|
958
|
+
_strikethroughSpaces = false;
|
|
959
|
+
_colorWhitespace = false;
|
|
960
|
+
// Underline
|
|
961
|
+
_underlineStyle = "none";
|
|
962
|
+
// Colors
|
|
963
|
+
_fg = null;
|
|
964
|
+
_bg = null;
|
|
965
|
+
_ulColor = null;
|
|
966
|
+
// Dimensions
|
|
967
|
+
_width = 0;
|
|
968
|
+
_height = 0;
|
|
969
|
+
_maxWidth = 0;
|
|
970
|
+
_maxHeight = 0;
|
|
971
|
+
// Alignment
|
|
972
|
+
_alignH = 0;
|
|
973
|
+
_alignV = 0;
|
|
974
|
+
// Padding
|
|
975
|
+
_paddingTop = 0;
|
|
976
|
+
_paddingRight = 0;
|
|
977
|
+
_paddingBottom = 0;
|
|
978
|
+
_paddingLeft = 0;
|
|
979
|
+
// Margin
|
|
980
|
+
_marginTop = 0;
|
|
981
|
+
_marginRight = 0;
|
|
982
|
+
_marginBottom = 0;
|
|
983
|
+
_marginLeft = 0;
|
|
984
|
+
_marginBg = null;
|
|
985
|
+
// Border
|
|
986
|
+
_borderStyle = noBorder;
|
|
987
|
+
_borderTop = false;
|
|
988
|
+
_borderRight = false;
|
|
989
|
+
_borderBottom = false;
|
|
990
|
+
_borderLeft = false;
|
|
991
|
+
_borderTopFg = null;
|
|
992
|
+
_borderRightFg = null;
|
|
993
|
+
_borderBottomFg = null;
|
|
994
|
+
_borderLeftFg = null;
|
|
995
|
+
_borderTopBg = null;
|
|
996
|
+
_borderRightBg = null;
|
|
997
|
+
_borderBottomBg = null;
|
|
998
|
+
_borderLeftBg = null;
|
|
999
|
+
// Other
|
|
1000
|
+
_inline = false;
|
|
1001
|
+
_tabWidth = TAB_WIDTH_DEFAULT;
|
|
1002
|
+
_transform = null;
|
|
1003
|
+
_link = "";
|
|
1004
|
+
_linkParams = "";
|
|
1005
|
+
_paddingChar = " ";
|
|
1006
|
+
/** Clone this style into a new instance. */
|
|
1007
|
+
_clone() {
|
|
1008
|
+
const s = new _Style();
|
|
1009
|
+
s._set = new Set(this._set);
|
|
1010
|
+
s._value = this._value;
|
|
1011
|
+
s._bold = this._bold;
|
|
1012
|
+
s._italic = this._italic;
|
|
1013
|
+
s._strikethrough = this._strikethrough;
|
|
1014
|
+
s._reverse = this._reverse;
|
|
1015
|
+
s._blink = this._blink;
|
|
1016
|
+
s._faint = this._faint;
|
|
1017
|
+
s._underlineSpaces = this._underlineSpaces;
|
|
1018
|
+
s._strikethroughSpaces = this._strikethroughSpaces;
|
|
1019
|
+
s._colorWhitespace = this._colorWhitespace;
|
|
1020
|
+
s._underlineStyle = this._underlineStyle;
|
|
1021
|
+
s._fg = this._fg;
|
|
1022
|
+
s._bg = this._bg;
|
|
1023
|
+
s._ulColor = this._ulColor;
|
|
1024
|
+
s._width = this._width;
|
|
1025
|
+
s._height = this._height;
|
|
1026
|
+
s._maxWidth = this._maxWidth;
|
|
1027
|
+
s._maxHeight = this._maxHeight;
|
|
1028
|
+
s._alignH = this._alignH;
|
|
1029
|
+
s._alignV = this._alignV;
|
|
1030
|
+
s._paddingTop = this._paddingTop;
|
|
1031
|
+
s._paddingRight = this._paddingRight;
|
|
1032
|
+
s._paddingBottom = this._paddingBottom;
|
|
1033
|
+
s._paddingLeft = this._paddingLeft;
|
|
1034
|
+
s._marginTop = this._marginTop;
|
|
1035
|
+
s._marginRight = this._marginRight;
|
|
1036
|
+
s._marginBottom = this._marginBottom;
|
|
1037
|
+
s._marginLeft = this._marginLeft;
|
|
1038
|
+
s._marginBg = this._marginBg;
|
|
1039
|
+
s._borderStyle = this._borderStyle;
|
|
1040
|
+
s._borderTop = this._borderTop;
|
|
1041
|
+
s._borderRight = this._borderRight;
|
|
1042
|
+
s._borderBottom = this._borderBottom;
|
|
1043
|
+
s._borderLeft = this._borderLeft;
|
|
1044
|
+
s._borderTopFg = this._borderTopFg;
|
|
1045
|
+
s._borderRightFg = this._borderRightFg;
|
|
1046
|
+
s._borderBottomFg = this._borderBottomFg;
|
|
1047
|
+
s._borderLeftFg = this._borderLeftFg;
|
|
1048
|
+
s._borderTopBg = this._borderTopBg;
|
|
1049
|
+
s._borderRightBg = this._borderRightBg;
|
|
1050
|
+
s._borderBottomBg = this._borderBottomBg;
|
|
1051
|
+
s._borderLeftBg = this._borderLeftBg;
|
|
1052
|
+
s._inline = this._inline;
|
|
1053
|
+
s._tabWidth = this._tabWidth;
|
|
1054
|
+
s._transform = this._transform;
|
|
1055
|
+
s._link = this._link;
|
|
1056
|
+
s._linkParams = this._linkParams;
|
|
1057
|
+
s._paddingChar = this._paddingChar;
|
|
1058
|
+
return s;
|
|
1059
|
+
}
|
|
1060
|
+
// -----------------------------------------------------------------------
|
|
1061
|
+
// Setters (all return new Style)
|
|
1062
|
+
// -----------------------------------------------------------------------
|
|
1063
|
+
setString(...strs) {
|
|
1064
|
+
const s = this._clone();
|
|
1065
|
+
s._value = strs.join(" ");
|
|
1066
|
+
return s;
|
|
1067
|
+
}
|
|
1068
|
+
bold(v) {
|
|
1069
|
+
const s = this._clone();
|
|
1070
|
+
s._bold = v;
|
|
1071
|
+
s._set.add("bold");
|
|
1072
|
+
return s;
|
|
1073
|
+
}
|
|
1074
|
+
italic(v) {
|
|
1075
|
+
const s = this._clone();
|
|
1076
|
+
s._italic = v;
|
|
1077
|
+
s._set.add("italic");
|
|
1078
|
+
return s;
|
|
1079
|
+
}
|
|
1080
|
+
strikethrough(v) {
|
|
1081
|
+
const s = this._clone();
|
|
1082
|
+
s._strikethrough = v;
|
|
1083
|
+
s._set.add("strikethrough");
|
|
1084
|
+
return s;
|
|
1085
|
+
}
|
|
1086
|
+
reverse(v) {
|
|
1087
|
+
const s = this._clone();
|
|
1088
|
+
s._reverse = v;
|
|
1089
|
+
s._set.add("reverse");
|
|
1090
|
+
return s;
|
|
1091
|
+
}
|
|
1092
|
+
blink(v) {
|
|
1093
|
+
const s = this._clone();
|
|
1094
|
+
s._blink = v;
|
|
1095
|
+
s._set.add("blink");
|
|
1096
|
+
return s;
|
|
1097
|
+
}
|
|
1098
|
+
faint(v) {
|
|
1099
|
+
const s = this._clone();
|
|
1100
|
+
s._faint = v;
|
|
1101
|
+
s._set.add("faint");
|
|
1102
|
+
return s;
|
|
1103
|
+
}
|
|
1104
|
+
underline(v) {
|
|
1105
|
+
return v ? this.underlineStyle("single") : this.underlineStyle("none");
|
|
1106
|
+
}
|
|
1107
|
+
underlineStyle(u) {
|
|
1108
|
+
const s = this._clone();
|
|
1109
|
+
s._underlineStyle = u;
|
|
1110
|
+
s._set.add("underline");
|
|
1111
|
+
return s;
|
|
1112
|
+
}
|
|
1113
|
+
foreground(c) {
|
|
1114
|
+
const s = this._clone();
|
|
1115
|
+
s._fg = c;
|
|
1116
|
+
s._set.add("fg");
|
|
1117
|
+
return s;
|
|
1118
|
+
}
|
|
1119
|
+
background(c) {
|
|
1120
|
+
const s = this._clone();
|
|
1121
|
+
s._bg = c;
|
|
1122
|
+
s._set.add("bg");
|
|
1123
|
+
return s;
|
|
1124
|
+
}
|
|
1125
|
+
underlineColor(c) {
|
|
1126
|
+
const s = this._clone();
|
|
1127
|
+
s._ulColor = c;
|
|
1128
|
+
s._set.add("ulColor");
|
|
1129
|
+
return s;
|
|
1130
|
+
}
|
|
1131
|
+
width(n) {
|
|
1132
|
+
const s = this._clone();
|
|
1133
|
+
s._width = Math.max(0, n);
|
|
1134
|
+
s._set.add("width");
|
|
1135
|
+
return s;
|
|
1136
|
+
}
|
|
1137
|
+
height(n) {
|
|
1138
|
+
const s = this._clone();
|
|
1139
|
+
s._height = Math.max(0, n);
|
|
1140
|
+
s._set.add("height");
|
|
1141
|
+
return s;
|
|
1142
|
+
}
|
|
1143
|
+
maxWidth(n) {
|
|
1144
|
+
const s = this._clone();
|
|
1145
|
+
s._maxWidth = Math.max(0, n);
|
|
1146
|
+
s._set.add("maxWidth");
|
|
1147
|
+
return s;
|
|
1148
|
+
}
|
|
1149
|
+
maxHeight(n) {
|
|
1150
|
+
const s = this._clone();
|
|
1151
|
+
s._maxHeight = Math.max(0, n);
|
|
1152
|
+
s._set.add("maxHeight");
|
|
1153
|
+
return s;
|
|
1154
|
+
}
|
|
1155
|
+
align(...pos) {
|
|
1156
|
+
let s = this._clone();
|
|
1157
|
+
if (pos.length > 0) {
|
|
1158
|
+
s._alignH = pos[0];
|
|
1159
|
+
s._set.add("alignH");
|
|
1160
|
+
}
|
|
1161
|
+
if (pos.length > 1) {
|
|
1162
|
+
s._alignV = pos[1];
|
|
1163
|
+
s._set.add("alignV");
|
|
1164
|
+
}
|
|
1165
|
+
return s;
|
|
1166
|
+
}
|
|
1167
|
+
alignHorizontal(p) {
|
|
1168
|
+
const s = this._clone();
|
|
1169
|
+
s._alignH = p;
|
|
1170
|
+
s._set.add("alignH");
|
|
1171
|
+
return s;
|
|
1172
|
+
}
|
|
1173
|
+
alignVertical(p) {
|
|
1174
|
+
const s = this._clone();
|
|
1175
|
+
s._alignV = p;
|
|
1176
|
+
s._set.add("alignV");
|
|
1177
|
+
return s;
|
|
1178
|
+
}
|
|
1179
|
+
padding(...args) {
|
|
1180
|
+
const sides = whichSidesInt(...args);
|
|
1181
|
+
if (!sides) return this;
|
|
1182
|
+
const s = this._clone();
|
|
1183
|
+
s._paddingTop = Math.max(0, sides.top);
|
|
1184
|
+
s._set.add("paddingTop");
|
|
1185
|
+
s._paddingRight = Math.max(0, sides.right);
|
|
1186
|
+
s._set.add("paddingRight");
|
|
1187
|
+
s._paddingBottom = Math.max(0, sides.bottom);
|
|
1188
|
+
s._set.add("paddingBottom");
|
|
1189
|
+
s._paddingLeft = Math.max(0, sides.left);
|
|
1190
|
+
s._set.add("paddingLeft");
|
|
1191
|
+
return s;
|
|
1192
|
+
}
|
|
1193
|
+
paddingTop(n) {
|
|
1194
|
+
const s = this._clone();
|
|
1195
|
+
s._paddingTop = Math.max(0, n);
|
|
1196
|
+
s._set.add("paddingTop");
|
|
1197
|
+
return s;
|
|
1198
|
+
}
|
|
1199
|
+
paddingRight(n) {
|
|
1200
|
+
const s = this._clone();
|
|
1201
|
+
s._paddingRight = Math.max(0, n);
|
|
1202
|
+
s._set.add("paddingRight");
|
|
1203
|
+
return s;
|
|
1204
|
+
}
|
|
1205
|
+
paddingBottom(n) {
|
|
1206
|
+
const s = this._clone();
|
|
1207
|
+
s._paddingBottom = Math.max(0, n);
|
|
1208
|
+
s._set.add("paddingBottom");
|
|
1209
|
+
return s;
|
|
1210
|
+
}
|
|
1211
|
+
paddingLeft(n) {
|
|
1212
|
+
const s = this._clone();
|
|
1213
|
+
s._paddingLeft = Math.max(0, n);
|
|
1214
|
+
s._set.add("paddingLeft");
|
|
1215
|
+
return s;
|
|
1216
|
+
}
|
|
1217
|
+
margin(...args) {
|
|
1218
|
+
const sides = whichSidesInt(...args);
|
|
1219
|
+
if (!sides) return this;
|
|
1220
|
+
const s = this._clone();
|
|
1221
|
+
s._marginTop = Math.max(0, sides.top);
|
|
1222
|
+
s._set.add("marginTop");
|
|
1223
|
+
s._marginRight = Math.max(0, sides.right);
|
|
1224
|
+
s._set.add("marginRight");
|
|
1225
|
+
s._marginBottom = Math.max(0, sides.bottom);
|
|
1226
|
+
s._set.add("marginBottom");
|
|
1227
|
+
s._marginLeft = Math.max(0, sides.left);
|
|
1228
|
+
s._set.add("marginLeft");
|
|
1229
|
+
return s;
|
|
1230
|
+
}
|
|
1231
|
+
marginTop(n) {
|
|
1232
|
+
const s = this._clone();
|
|
1233
|
+
s._marginTop = Math.max(0, n);
|
|
1234
|
+
s._set.add("marginTop");
|
|
1235
|
+
return s;
|
|
1236
|
+
}
|
|
1237
|
+
marginRight(n) {
|
|
1238
|
+
const s = this._clone();
|
|
1239
|
+
s._marginRight = Math.max(0, n);
|
|
1240
|
+
s._set.add("marginRight");
|
|
1241
|
+
return s;
|
|
1242
|
+
}
|
|
1243
|
+
marginBottom(n) {
|
|
1244
|
+
const s = this._clone();
|
|
1245
|
+
s._marginBottom = Math.max(0, n);
|
|
1246
|
+
s._set.add("marginBottom");
|
|
1247
|
+
return s;
|
|
1248
|
+
}
|
|
1249
|
+
marginLeft(n) {
|
|
1250
|
+
const s = this._clone();
|
|
1251
|
+
s._marginLeft = Math.max(0, n);
|
|
1252
|
+
s._set.add("marginLeft");
|
|
1253
|
+
return s;
|
|
1254
|
+
}
|
|
1255
|
+
marginBackground(c) {
|
|
1256
|
+
const s = this._clone();
|
|
1257
|
+
s._marginBg = c;
|
|
1258
|
+
s._set.add("marginBg");
|
|
1259
|
+
return s;
|
|
1260
|
+
}
|
|
1261
|
+
border(b, ...sides) {
|
|
1262
|
+
const s = this._clone();
|
|
1263
|
+
s._borderStyle = b;
|
|
1264
|
+
s._set.add("borderStyle");
|
|
1265
|
+
const bs = whichSidesBool(...sides);
|
|
1266
|
+
if (bs) {
|
|
1267
|
+
s._borderTop = bs.top;
|
|
1268
|
+
s._set.add("borderTop");
|
|
1269
|
+
s._borderRight = bs.right;
|
|
1270
|
+
s._set.add("borderRight");
|
|
1271
|
+
s._borderBottom = bs.bottom;
|
|
1272
|
+
s._set.add("borderBottom");
|
|
1273
|
+
s._borderLeft = bs.left;
|
|
1274
|
+
s._set.add("borderLeft");
|
|
1275
|
+
} else {
|
|
1276
|
+
s._borderTop = true;
|
|
1277
|
+
s._set.add("borderTop");
|
|
1278
|
+
s._borderRight = true;
|
|
1279
|
+
s._set.add("borderRight");
|
|
1280
|
+
s._borderBottom = true;
|
|
1281
|
+
s._set.add("borderBottom");
|
|
1282
|
+
s._borderLeft = true;
|
|
1283
|
+
s._set.add("borderLeft");
|
|
1284
|
+
}
|
|
1285
|
+
return s;
|
|
1286
|
+
}
|
|
1287
|
+
borderStyle(b) {
|
|
1288
|
+
const s = this._clone();
|
|
1289
|
+
s._borderStyle = b;
|
|
1290
|
+
s._set.add("borderStyle");
|
|
1291
|
+
return s;
|
|
1292
|
+
}
|
|
1293
|
+
borderTop(v) {
|
|
1294
|
+
const s = this._clone();
|
|
1295
|
+
s._borderTop = v;
|
|
1296
|
+
s._set.add("borderTop");
|
|
1297
|
+
return s;
|
|
1298
|
+
}
|
|
1299
|
+
borderRight(v) {
|
|
1300
|
+
const s = this._clone();
|
|
1301
|
+
s._borderRight = v;
|
|
1302
|
+
s._set.add("borderRight");
|
|
1303
|
+
return s;
|
|
1304
|
+
}
|
|
1305
|
+
borderBottom(v) {
|
|
1306
|
+
const s = this._clone();
|
|
1307
|
+
s._borderBottom = v;
|
|
1308
|
+
s._set.add("borderBottom");
|
|
1309
|
+
return s;
|
|
1310
|
+
}
|
|
1311
|
+
borderLeft(v) {
|
|
1312
|
+
const s = this._clone();
|
|
1313
|
+
s._borderLeft = v;
|
|
1314
|
+
s._set.add("borderLeft");
|
|
1315
|
+
return s;
|
|
1316
|
+
}
|
|
1317
|
+
borderForeground(...colors) {
|
|
1318
|
+
if (colors.length === 0) return this;
|
|
1319
|
+
const sides = whichSidesColor(...colors);
|
|
1320
|
+
if (!sides) return this;
|
|
1321
|
+
const s = this._clone();
|
|
1322
|
+
s._borderTopFg = sides.top;
|
|
1323
|
+
s._set.add("borderTopFg");
|
|
1324
|
+
s._borderRightFg = sides.right;
|
|
1325
|
+
s._set.add("borderRightFg");
|
|
1326
|
+
s._borderBottomFg = sides.bottom;
|
|
1327
|
+
s._set.add("borderBottomFg");
|
|
1328
|
+
s._borderLeftFg = sides.left;
|
|
1329
|
+
s._set.add("borderLeftFg");
|
|
1330
|
+
return s;
|
|
1331
|
+
}
|
|
1332
|
+
borderTopForeground(c) {
|
|
1333
|
+
const s = this._clone();
|
|
1334
|
+
s._borderTopFg = c;
|
|
1335
|
+
s._set.add("borderTopFg");
|
|
1336
|
+
return s;
|
|
1337
|
+
}
|
|
1338
|
+
borderRightForeground(c) {
|
|
1339
|
+
const s = this._clone();
|
|
1340
|
+
s._borderRightFg = c;
|
|
1341
|
+
s._set.add("borderRightFg");
|
|
1342
|
+
return s;
|
|
1343
|
+
}
|
|
1344
|
+
borderBottomForeground(c) {
|
|
1345
|
+
const s = this._clone();
|
|
1346
|
+
s._borderBottomFg = c;
|
|
1347
|
+
s._set.add("borderBottomFg");
|
|
1348
|
+
return s;
|
|
1349
|
+
}
|
|
1350
|
+
borderLeftForeground(c) {
|
|
1351
|
+
const s = this._clone();
|
|
1352
|
+
s._borderLeftFg = c;
|
|
1353
|
+
s._set.add("borderLeftFg");
|
|
1354
|
+
return s;
|
|
1355
|
+
}
|
|
1356
|
+
borderBackground(...colors) {
|
|
1357
|
+
if (colors.length === 0) return this;
|
|
1358
|
+
const sides = whichSidesColor(...colors);
|
|
1359
|
+
if (!sides) return this;
|
|
1360
|
+
const s = this._clone();
|
|
1361
|
+
s._borderTopBg = sides.top;
|
|
1362
|
+
s._set.add("borderTopBg");
|
|
1363
|
+
s._borderRightBg = sides.right;
|
|
1364
|
+
s._set.add("borderRightBg");
|
|
1365
|
+
s._borderBottomBg = sides.bottom;
|
|
1366
|
+
s._set.add("borderBottomBg");
|
|
1367
|
+
s._borderLeftBg = sides.left;
|
|
1368
|
+
s._set.add("borderLeftBg");
|
|
1369
|
+
return s;
|
|
1370
|
+
}
|
|
1371
|
+
borderTopBackground(c) {
|
|
1372
|
+
const s = this._clone();
|
|
1373
|
+
s._borderTopBg = c;
|
|
1374
|
+
s._set.add("borderTopBg");
|
|
1375
|
+
return s;
|
|
1376
|
+
}
|
|
1377
|
+
borderRightBackground(c) {
|
|
1378
|
+
const s = this._clone();
|
|
1379
|
+
s._borderRightBg = c;
|
|
1380
|
+
s._set.add("borderRightBg");
|
|
1381
|
+
return s;
|
|
1382
|
+
}
|
|
1383
|
+
borderBottomBackground(c) {
|
|
1384
|
+
const s = this._clone();
|
|
1385
|
+
s._borderBottomBg = c;
|
|
1386
|
+
s._set.add("borderBottomBg");
|
|
1387
|
+
return s;
|
|
1388
|
+
}
|
|
1389
|
+
borderLeftBackground(c) {
|
|
1390
|
+
const s = this._clone();
|
|
1391
|
+
s._borderLeftBg = c;
|
|
1392
|
+
s._set.add("borderLeftBg");
|
|
1393
|
+
return s;
|
|
1394
|
+
}
|
|
1395
|
+
inline(v) {
|
|
1396
|
+
const s = this._clone();
|
|
1397
|
+
s._inline = v;
|
|
1398
|
+
s._set.add("inline");
|
|
1399
|
+
return s;
|
|
1400
|
+
}
|
|
1401
|
+
tabWidth(n) {
|
|
1402
|
+
const s = this._clone();
|
|
1403
|
+
s._tabWidth = n <= -1 ? -1 : n;
|
|
1404
|
+
s._set.add("tabWidth");
|
|
1405
|
+
return s;
|
|
1406
|
+
}
|
|
1407
|
+
transform(fn) {
|
|
1408
|
+
const s = this._clone();
|
|
1409
|
+
s._transform = fn;
|
|
1410
|
+
s._set.add("transform");
|
|
1411
|
+
return s;
|
|
1412
|
+
}
|
|
1413
|
+
hyperlink(url, params) {
|
|
1414
|
+
const s = this._clone();
|
|
1415
|
+
s._link = url;
|
|
1416
|
+
s._set.add("link");
|
|
1417
|
+
if (params !== void 0) {
|
|
1418
|
+
s._linkParams = params;
|
|
1419
|
+
s._set.add("linkParams");
|
|
1420
|
+
}
|
|
1421
|
+
return s;
|
|
1422
|
+
}
|
|
1423
|
+
underlineSpaces(v) {
|
|
1424
|
+
const s = this._clone();
|
|
1425
|
+
s._underlineSpaces = v;
|
|
1426
|
+
s._set.add("underlineSpaces");
|
|
1427
|
+
return s;
|
|
1428
|
+
}
|
|
1429
|
+
strikethroughSpaces(v) {
|
|
1430
|
+
const s = this._clone();
|
|
1431
|
+
s._strikethroughSpaces = v;
|
|
1432
|
+
s._set.add("strikethroughSpaces");
|
|
1433
|
+
return s;
|
|
1434
|
+
}
|
|
1435
|
+
colorWhitespace(v) {
|
|
1436
|
+
const s = this._clone();
|
|
1437
|
+
s._colorWhitespace = v;
|
|
1438
|
+
s._set.add("colorWhitespace");
|
|
1439
|
+
return s;
|
|
1440
|
+
}
|
|
1441
|
+
paddingChar(ch) {
|
|
1442
|
+
const s = this._clone();
|
|
1443
|
+
s._paddingChar = ch || " ";
|
|
1444
|
+
s._set.add("paddingChar");
|
|
1445
|
+
return s;
|
|
1446
|
+
}
|
|
1447
|
+
// -----------------------------------------------------------------------
|
|
1448
|
+
// Copy — returns a full copy preserving ALL properties
|
|
1449
|
+
// -----------------------------------------------------------------------
|
|
1450
|
+
copy() {
|
|
1451
|
+
return this._clone();
|
|
1452
|
+
}
|
|
1453
|
+
// -----------------------------------------------------------------------
|
|
1454
|
+
// Unset methods — remove a property from the set so it reverts to default
|
|
1455
|
+
// -----------------------------------------------------------------------
|
|
1456
|
+
unsetBold() {
|
|
1457
|
+
const s = this._clone();
|
|
1458
|
+
s._set.delete("bold");
|
|
1459
|
+
s._bold = false;
|
|
1460
|
+
return s;
|
|
1461
|
+
}
|
|
1462
|
+
unsetItalic() {
|
|
1463
|
+
const s = this._clone();
|
|
1464
|
+
s._set.delete("italic");
|
|
1465
|
+
s._italic = false;
|
|
1466
|
+
return s;
|
|
1467
|
+
}
|
|
1468
|
+
unsetUnderline() {
|
|
1469
|
+
const s = this._clone();
|
|
1470
|
+
s._set.delete("underline");
|
|
1471
|
+
s._underlineStyle = "none";
|
|
1472
|
+
return s;
|
|
1473
|
+
}
|
|
1474
|
+
unsetUnderlineSpaces() {
|
|
1475
|
+
const s = this._clone();
|
|
1476
|
+
s._set.delete("underlineSpaces");
|
|
1477
|
+
s._underlineSpaces = false;
|
|
1478
|
+
return s;
|
|
1479
|
+
}
|
|
1480
|
+
unsetStrikethrough() {
|
|
1481
|
+
const s = this._clone();
|
|
1482
|
+
s._set.delete("strikethrough");
|
|
1483
|
+
s._strikethrough = false;
|
|
1484
|
+
return s;
|
|
1485
|
+
}
|
|
1486
|
+
unsetStrikethroughSpaces() {
|
|
1487
|
+
const s = this._clone();
|
|
1488
|
+
s._set.delete("strikethroughSpaces");
|
|
1489
|
+
s._strikethroughSpaces = false;
|
|
1490
|
+
return s;
|
|
1491
|
+
}
|
|
1492
|
+
unsetReverse() {
|
|
1493
|
+
const s = this._clone();
|
|
1494
|
+
s._set.delete("reverse");
|
|
1495
|
+
s._reverse = false;
|
|
1496
|
+
return s;
|
|
1497
|
+
}
|
|
1498
|
+
unsetBlink() {
|
|
1499
|
+
const s = this._clone();
|
|
1500
|
+
s._set.delete("blink");
|
|
1501
|
+
s._blink = false;
|
|
1502
|
+
return s;
|
|
1503
|
+
}
|
|
1504
|
+
unsetFaint() {
|
|
1505
|
+
const s = this._clone();
|
|
1506
|
+
s._set.delete("faint");
|
|
1507
|
+
s._faint = false;
|
|
1508
|
+
return s;
|
|
1509
|
+
}
|
|
1510
|
+
unsetInline() {
|
|
1511
|
+
const s = this._clone();
|
|
1512
|
+
s._set.delete("inline");
|
|
1513
|
+
s._inline = false;
|
|
1514
|
+
return s;
|
|
1515
|
+
}
|
|
1516
|
+
unsetForeground() {
|
|
1517
|
+
const s = this._clone();
|
|
1518
|
+
s._set.delete("fg");
|
|
1519
|
+
s._fg = null;
|
|
1520
|
+
return s;
|
|
1521
|
+
}
|
|
1522
|
+
unsetBackground() {
|
|
1523
|
+
const s = this._clone();
|
|
1524
|
+
s._set.delete("bg");
|
|
1525
|
+
s._bg = null;
|
|
1526
|
+
return s;
|
|
1527
|
+
}
|
|
1528
|
+
unsetUnderlineColor() {
|
|
1529
|
+
const s = this._clone();
|
|
1530
|
+
s._set.delete("ulColor");
|
|
1531
|
+
s._ulColor = null;
|
|
1532
|
+
return s;
|
|
1533
|
+
}
|
|
1534
|
+
unsetWidth() {
|
|
1535
|
+
const s = this._clone();
|
|
1536
|
+
s._set.delete("width");
|
|
1537
|
+
s._width = 0;
|
|
1538
|
+
return s;
|
|
1539
|
+
}
|
|
1540
|
+
unsetHeight() {
|
|
1541
|
+
const s = this._clone();
|
|
1542
|
+
s._set.delete("height");
|
|
1543
|
+
s._height = 0;
|
|
1544
|
+
return s;
|
|
1545
|
+
}
|
|
1546
|
+
unsetMaxWidth() {
|
|
1547
|
+
const s = this._clone();
|
|
1548
|
+
s._set.delete("maxWidth");
|
|
1549
|
+
s._maxWidth = 0;
|
|
1550
|
+
return s;
|
|
1551
|
+
}
|
|
1552
|
+
unsetMaxHeight() {
|
|
1553
|
+
const s = this._clone();
|
|
1554
|
+
s._set.delete("maxHeight");
|
|
1555
|
+
s._maxHeight = 0;
|
|
1556
|
+
return s;
|
|
1557
|
+
}
|
|
1558
|
+
unsetPaddingTop() {
|
|
1559
|
+
const s = this._clone();
|
|
1560
|
+
s._set.delete("paddingTop");
|
|
1561
|
+
s._paddingTop = 0;
|
|
1562
|
+
return s;
|
|
1563
|
+
}
|
|
1564
|
+
unsetPaddingRight() {
|
|
1565
|
+
const s = this._clone();
|
|
1566
|
+
s._set.delete("paddingRight");
|
|
1567
|
+
s._paddingRight = 0;
|
|
1568
|
+
return s;
|
|
1569
|
+
}
|
|
1570
|
+
unsetPaddingBottom() {
|
|
1571
|
+
const s = this._clone();
|
|
1572
|
+
s._set.delete("paddingBottom");
|
|
1573
|
+
s._paddingBottom = 0;
|
|
1574
|
+
return s;
|
|
1575
|
+
}
|
|
1576
|
+
unsetPaddingLeft() {
|
|
1577
|
+
const s = this._clone();
|
|
1578
|
+
s._set.delete("paddingLeft");
|
|
1579
|
+
s._paddingLeft = 0;
|
|
1580
|
+
return s;
|
|
1581
|
+
}
|
|
1582
|
+
unsetPaddingChar() {
|
|
1583
|
+
const s = this._clone();
|
|
1584
|
+
s._set.delete("paddingChar");
|
|
1585
|
+
s._paddingChar = " ";
|
|
1586
|
+
return s;
|
|
1587
|
+
}
|
|
1588
|
+
unsetMarginTop() {
|
|
1589
|
+
const s = this._clone();
|
|
1590
|
+
s._set.delete("marginTop");
|
|
1591
|
+
s._marginTop = 0;
|
|
1592
|
+
return s;
|
|
1593
|
+
}
|
|
1594
|
+
unsetMarginRight() {
|
|
1595
|
+
const s = this._clone();
|
|
1596
|
+
s._set.delete("marginRight");
|
|
1597
|
+
s._marginRight = 0;
|
|
1598
|
+
return s;
|
|
1599
|
+
}
|
|
1600
|
+
unsetMarginBottom() {
|
|
1601
|
+
const s = this._clone();
|
|
1602
|
+
s._set.delete("marginBottom");
|
|
1603
|
+
s._marginBottom = 0;
|
|
1604
|
+
return s;
|
|
1605
|
+
}
|
|
1606
|
+
unsetMarginLeft() {
|
|
1607
|
+
const s = this._clone();
|
|
1608
|
+
s._set.delete("marginLeft");
|
|
1609
|
+
s._marginLeft = 0;
|
|
1610
|
+
return s;
|
|
1611
|
+
}
|
|
1612
|
+
unsetBorderTop() {
|
|
1613
|
+
const s = this._clone();
|
|
1614
|
+
s._set.delete("borderTop");
|
|
1615
|
+
s._borderTop = false;
|
|
1616
|
+
return s;
|
|
1617
|
+
}
|
|
1618
|
+
unsetBorderRight() {
|
|
1619
|
+
const s = this._clone();
|
|
1620
|
+
s._set.delete("borderRight");
|
|
1621
|
+
s._borderRight = false;
|
|
1622
|
+
return s;
|
|
1623
|
+
}
|
|
1624
|
+
unsetBorderBottom() {
|
|
1625
|
+
const s = this._clone();
|
|
1626
|
+
s._set.delete("borderBottom");
|
|
1627
|
+
s._borderBottom = false;
|
|
1628
|
+
return s;
|
|
1629
|
+
}
|
|
1630
|
+
unsetBorderLeft() {
|
|
1631
|
+
const s = this._clone();
|
|
1632
|
+
s._set.delete("borderLeft");
|
|
1633
|
+
s._borderLeft = false;
|
|
1634
|
+
return s;
|
|
1635
|
+
}
|
|
1636
|
+
unsetBorderStyle() {
|
|
1637
|
+
const s = this._clone();
|
|
1638
|
+
s._set.delete("borderStyle");
|
|
1639
|
+
s._borderStyle = noBorder;
|
|
1640
|
+
return s;
|
|
1641
|
+
}
|
|
1642
|
+
unsetTabWidth() {
|
|
1643
|
+
const s = this._clone();
|
|
1644
|
+
s._set.delete("tabWidth");
|
|
1645
|
+
s._tabWidth = TAB_WIDTH_DEFAULT;
|
|
1646
|
+
return s;
|
|
1647
|
+
}
|
|
1648
|
+
unsetTransform() {
|
|
1649
|
+
const s = this._clone();
|
|
1650
|
+
s._set.delete("transform");
|
|
1651
|
+
s._transform = null;
|
|
1652
|
+
return s;
|
|
1653
|
+
}
|
|
1654
|
+
unsetHyperlink() {
|
|
1655
|
+
const s = this._clone();
|
|
1656
|
+
s._set.delete("link");
|
|
1657
|
+
s._link = "";
|
|
1658
|
+
s._set.delete("linkParams");
|
|
1659
|
+
s._linkParams = "";
|
|
1660
|
+
return s;
|
|
1661
|
+
}
|
|
1662
|
+
unsetColorWhitespace() {
|
|
1663
|
+
const s = this._clone();
|
|
1664
|
+
s._set.delete("colorWhitespace");
|
|
1665
|
+
s._colorWhitespace = false;
|
|
1666
|
+
return s;
|
|
1667
|
+
}
|
|
1668
|
+
// -----------------------------------------------------------------------
|
|
1669
|
+
// Getters
|
|
1670
|
+
// -----------------------------------------------------------------------
|
|
1671
|
+
getBold() {
|
|
1672
|
+
return this._set.has("bold") ? this._bold : false;
|
|
1673
|
+
}
|
|
1674
|
+
getItalic() {
|
|
1675
|
+
return this._set.has("italic") ? this._italic : false;
|
|
1676
|
+
}
|
|
1677
|
+
getUnderline() {
|
|
1678
|
+
return this._underlineStyle !== "none";
|
|
1679
|
+
}
|
|
1680
|
+
getUnderlineStyle() {
|
|
1681
|
+
return this._underlineStyle;
|
|
1682
|
+
}
|
|
1683
|
+
getStrikethrough() {
|
|
1684
|
+
return this._set.has("strikethrough") ? this._strikethrough : false;
|
|
1685
|
+
}
|
|
1686
|
+
getReverse() {
|
|
1687
|
+
return this._set.has("reverse") ? this._reverse : false;
|
|
1688
|
+
}
|
|
1689
|
+
getBlink() {
|
|
1690
|
+
return this._set.has("blink") ? this._blink : false;
|
|
1691
|
+
}
|
|
1692
|
+
getFaint() {
|
|
1693
|
+
return this._set.has("faint") ? this._faint : false;
|
|
1694
|
+
}
|
|
1695
|
+
getForeground() {
|
|
1696
|
+
return this._set.has("fg") ? this._fg : null;
|
|
1697
|
+
}
|
|
1698
|
+
getBackground() {
|
|
1699
|
+
return this._set.has("bg") ? this._bg : null;
|
|
1700
|
+
}
|
|
1701
|
+
getUnderlineColor() {
|
|
1702
|
+
return this._set.has("ulColor") ? this._ulColor : null;
|
|
1703
|
+
}
|
|
1704
|
+
getWidth() {
|
|
1705
|
+
return this._set.has("width") ? this._width : 0;
|
|
1706
|
+
}
|
|
1707
|
+
getHeight() {
|
|
1708
|
+
return this._set.has("height") ? this._height : 0;
|
|
1709
|
+
}
|
|
1710
|
+
getMaxWidth() {
|
|
1711
|
+
return this._set.has("maxWidth") ? this._maxWidth : 0;
|
|
1712
|
+
}
|
|
1713
|
+
getMaxHeight() {
|
|
1714
|
+
return this._set.has("maxHeight") ? this._maxHeight : 0;
|
|
1715
|
+
}
|
|
1716
|
+
getAlignHorizontal() {
|
|
1717
|
+
return this._set.has("alignH") ? this._alignH : Left;
|
|
1718
|
+
}
|
|
1719
|
+
getAlignVertical() {
|
|
1720
|
+
return this._set.has("alignV") ? this._alignV : Top;
|
|
1721
|
+
}
|
|
1722
|
+
getInline() {
|
|
1723
|
+
return this._set.has("inline") ? this._inline : false;
|
|
1724
|
+
}
|
|
1725
|
+
getTabWidth() {
|
|
1726
|
+
return this._set.has("tabWidth") ? this._tabWidth : TAB_WIDTH_DEFAULT;
|
|
1727
|
+
}
|
|
1728
|
+
getUnderlineSpaces() {
|
|
1729
|
+
return this._set.has("underlineSpaces") ? this._underlineSpaces : false;
|
|
1730
|
+
}
|
|
1731
|
+
getStrikethroughSpaces() {
|
|
1732
|
+
return this._set.has("strikethroughSpaces") ? this._strikethroughSpaces : false;
|
|
1733
|
+
}
|
|
1734
|
+
getColorWhitespace() {
|
|
1735
|
+
return this._set.has("colorWhitespace") ? this._colorWhitespace : false;
|
|
1736
|
+
}
|
|
1737
|
+
getTransform() {
|
|
1738
|
+
return this._set.has("transform") ? this._transform : null;
|
|
1739
|
+
}
|
|
1740
|
+
getPaddingChar() {
|
|
1741
|
+
return this._set.has("paddingChar") ? this._paddingChar : " ";
|
|
1742
|
+
}
|
|
1743
|
+
getHyperlink() {
|
|
1744
|
+
return { link: this._set.has("link") ? this._link : "", params: this._set.has("linkParams") ? this._linkParams : "" };
|
|
1745
|
+
}
|
|
1746
|
+
getPadding() {
|
|
1747
|
+
return {
|
|
1748
|
+
top: this._set.has("paddingTop") ? this._paddingTop : 0,
|
|
1749
|
+
right: this._set.has("paddingRight") ? this._paddingRight : 0,
|
|
1750
|
+
bottom: this._set.has("paddingBottom") ? this._paddingBottom : 0,
|
|
1751
|
+
left: this._set.has("paddingLeft") ? this._paddingLeft : 0
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
getPaddingTop() {
|
|
1755
|
+
return this._set.has("paddingTop") ? this._paddingTop : 0;
|
|
1756
|
+
}
|
|
1757
|
+
getPaddingRight() {
|
|
1758
|
+
return this._set.has("paddingRight") ? this._paddingRight : 0;
|
|
1759
|
+
}
|
|
1760
|
+
getPaddingBottom() {
|
|
1761
|
+
return this._set.has("paddingBottom") ? this._paddingBottom : 0;
|
|
1762
|
+
}
|
|
1763
|
+
getPaddingLeft() {
|
|
1764
|
+
return this._set.has("paddingLeft") ? this._paddingLeft : 0;
|
|
1765
|
+
}
|
|
1766
|
+
getHorizontalPadding() {
|
|
1767
|
+
return this.getPaddingLeft() + this.getPaddingRight();
|
|
1768
|
+
}
|
|
1769
|
+
getVerticalPadding() {
|
|
1770
|
+
return this.getPaddingTop() + this.getPaddingBottom();
|
|
1771
|
+
}
|
|
1772
|
+
getMargin() {
|
|
1773
|
+
return {
|
|
1774
|
+
top: this._set.has("marginTop") ? this._marginTop : 0,
|
|
1775
|
+
right: this._set.has("marginRight") ? this._marginRight : 0,
|
|
1776
|
+
bottom: this._set.has("marginBottom") ? this._marginBottom : 0,
|
|
1777
|
+
left: this._set.has("marginLeft") ? this._marginLeft : 0
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
getMarginTop() {
|
|
1781
|
+
return this._set.has("marginTop") ? this._marginTop : 0;
|
|
1782
|
+
}
|
|
1783
|
+
getMarginRight() {
|
|
1784
|
+
return this._set.has("marginRight") ? this._marginRight : 0;
|
|
1785
|
+
}
|
|
1786
|
+
getMarginBottom() {
|
|
1787
|
+
return this._set.has("marginBottom") ? this._marginBottom : 0;
|
|
1788
|
+
}
|
|
1789
|
+
getMarginLeft() {
|
|
1790
|
+
return this._set.has("marginLeft") ? this._marginLeft : 0;
|
|
1791
|
+
}
|
|
1792
|
+
getHorizontalMargins() {
|
|
1793
|
+
return this.getMarginLeft() + this.getMarginRight();
|
|
1794
|
+
}
|
|
1795
|
+
getVerticalMargins() {
|
|
1796
|
+
return this.getMarginTop() + this.getMarginBottom();
|
|
1797
|
+
}
|
|
1798
|
+
getBorderStyle() {
|
|
1799
|
+
return this._set.has("borderStyle") ? this._borderStyle : noBorder;
|
|
1800
|
+
}
|
|
1801
|
+
getBorderTop() {
|
|
1802
|
+
return this._set.has("borderTop") ? this._borderTop : false;
|
|
1803
|
+
}
|
|
1804
|
+
getBorderRight() {
|
|
1805
|
+
return this._set.has("borderRight") ? this._borderRight : false;
|
|
1806
|
+
}
|
|
1807
|
+
getBorderBottom() {
|
|
1808
|
+
return this._set.has("borderBottom") ? this._borderBottom : false;
|
|
1809
|
+
}
|
|
1810
|
+
getBorderLeft() {
|
|
1811
|
+
return this._set.has("borderLeft") ? this._borderLeft : false;
|
|
1812
|
+
}
|
|
1813
|
+
/** True when border style is set but no individual side bools are set. */
|
|
1814
|
+
_isBorderStyleSetWithoutSides() {
|
|
1815
|
+
const b = this.getBorderStyle();
|
|
1816
|
+
const anySideSet = this._set.has("borderTop") || this._set.has("borderRight") || this._set.has("borderBottom") || this._set.has("borderLeft");
|
|
1817
|
+
return !isNoBorder(b) && !anySideSet;
|
|
1818
|
+
}
|
|
1819
|
+
getBorderTopSize() {
|
|
1820
|
+
if (this._isBorderStyleSetWithoutSides()) return 1;
|
|
1821
|
+
if (!this.getBorderTop()) return 0;
|
|
1822
|
+
return getTopSize(this.getBorderStyle());
|
|
1823
|
+
}
|
|
1824
|
+
getBorderRightSize() {
|
|
1825
|
+
if (this._isBorderStyleSetWithoutSides()) return 1;
|
|
1826
|
+
if (!this.getBorderRight()) return 0;
|
|
1827
|
+
return getRightSize(this.getBorderStyle());
|
|
1828
|
+
}
|
|
1829
|
+
getBorderBottomSize() {
|
|
1830
|
+
if (this._isBorderStyleSetWithoutSides()) return 1;
|
|
1831
|
+
if (!this.getBorderBottom()) return 0;
|
|
1832
|
+
return getBottomSize(this.getBorderStyle());
|
|
1833
|
+
}
|
|
1834
|
+
getBorderLeftSize() {
|
|
1835
|
+
if (this._isBorderStyleSetWithoutSides()) return 1;
|
|
1836
|
+
if (!this.getBorderLeft()) return 0;
|
|
1837
|
+
return getLeftSize(this.getBorderStyle());
|
|
1838
|
+
}
|
|
1839
|
+
getHorizontalBorderSize() {
|
|
1840
|
+
return this.getBorderLeftSize() + this.getBorderRightSize();
|
|
1841
|
+
}
|
|
1842
|
+
getVerticalBorderSize() {
|
|
1843
|
+
return this.getBorderTopSize() + this.getBorderBottomSize();
|
|
1844
|
+
}
|
|
1845
|
+
getHorizontalFrameSize() {
|
|
1846
|
+
return this.getHorizontalMargins() + this.getHorizontalPadding() + this.getHorizontalBorderSize();
|
|
1847
|
+
}
|
|
1848
|
+
getVerticalFrameSize() {
|
|
1849
|
+
return this.getVerticalMargins() + this.getVerticalPadding() + this.getVerticalBorderSize();
|
|
1850
|
+
}
|
|
1851
|
+
getFrameSize() {
|
|
1852
|
+
return { x: this.getHorizontalFrameSize(), y: this.getVerticalFrameSize() };
|
|
1853
|
+
}
|
|
1854
|
+
// -----------------------------------------------------------------------
|
|
1855
|
+
// Inherit
|
|
1856
|
+
// -----------------------------------------------------------------------
|
|
1857
|
+
/** Copy explicitly-set values from `other` that are NOT set on this style. Margins/padding are not inherited. */
|
|
1858
|
+
inherit(other) {
|
|
1859
|
+
const s = this._clone();
|
|
1860
|
+
const skip = /* @__PURE__ */ new Set(["paddingTop", "paddingRight", "paddingBottom", "paddingLeft", "marginTop", "marginRight", "marginBottom", "marginLeft"]);
|
|
1861
|
+
for (const key of other._set) {
|
|
1862
|
+
if (skip.has(key)) continue;
|
|
1863
|
+
if (key === "bg" && !s._set.has("marginBg") && !other._set.has("marginBg")) {
|
|
1864
|
+
s._marginBg = other._bg;
|
|
1865
|
+
s._set.add("marginBg");
|
|
1866
|
+
}
|
|
1867
|
+
if (s._set.has(key)) continue;
|
|
1868
|
+
s["_" + this._keyToField(key)] = other["_" + this._keyToField(key)];
|
|
1869
|
+
s._set.add(key);
|
|
1870
|
+
}
|
|
1871
|
+
return s;
|
|
1872
|
+
}
|
|
1873
|
+
_keyToField(key) {
|
|
1874
|
+
const map = {
|
|
1875
|
+
bold: "bold",
|
|
1876
|
+
italic: "italic",
|
|
1877
|
+
strikethrough: "strikethrough",
|
|
1878
|
+
reverse: "reverse",
|
|
1879
|
+
blink: "blink",
|
|
1880
|
+
faint: "faint",
|
|
1881
|
+
underlineSpaces: "underlineSpaces",
|
|
1882
|
+
strikethroughSpaces: "strikethroughSpaces",
|
|
1883
|
+
colorWhitespace: "colorWhitespace",
|
|
1884
|
+
underline: "underlineStyle",
|
|
1885
|
+
fg: "fg",
|
|
1886
|
+
bg: "bg",
|
|
1887
|
+
ulColor: "ulColor",
|
|
1888
|
+
width: "width",
|
|
1889
|
+
height: "height",
|
|
1890
|
+
maxWidth: "maxWidth",
|
|
1891
|
+
maxHeight: "maxHeight",
|
|
1892
|
+
alignH: "alignH",
|
|
1893
|
+
alignV: "alignV",
|
|
1894
|
+
paddingTop: "paddingTop",
|
|
1895
|
+
paddingRight: "paddingRight",
|
|
1896
|
+
paddingBottom: "paddingBottom",
|
|
1897
|
+
paddingLeft: "paddingLeft",
|
|
1898
|
+
marginTop: "marginTop",
|
|
1899
|
+
marginRight: "marginRight",
|
|
1900
|
+
marginBottom: "marginBottom",
|
|
1901
|
+
marginLeft: "marginLeft",
|
|
1902
|
+
marginBg: "marginBg",
|
|
1903
|
+
borderStyle: "borderStyle",
|
|
1904
|
+
borderTop: "borderTop",
|
|
1905
|
+
borderRight: "borderRight",
|
|
1906
|
+
borderBottom: "borderBottom",
|
|
1907
|
+
borderLeft: "borderLeft",
|
|
1908
|
+
borderTopFg: "borderTopFg",
|
|
1909
|
+
borderRightFg: "borderRightFg",
|
|
1910
|
+
borderBottomFg: "borderBottomFg",
|
|
1911
|
+
borderLeftFg: "borderLeftFg",
|
|
1912
|
+
borderTopBg: "borderTopBg",
|
|
1913
|
+
borderRightBg: "borderRightBg",
|
|
1914
|
+
borderBottomBg: "borderBottomBg",
|
|
1915
|
+
borderLeftBg: "borderLeftBg",
|
|
1916
|
+
inline: "inline",
|
|
1917
|
+
tabWidth: "tabWidth",
|
|
1918
|
+
transform: "transform",
|
|
1919
|
+
link: "link",
|
|
1920
|
+
linkParams: "linkParams",
|
|
1921
|
+
paddingChar: "paddingChar"
|
|
1922
|
+
};
|
|
1923
|
+
return map[key] || key;
|
|
1924
|
+
}
|
|
1925
|
+
// -----------------------------------------------------------------------
|
|
1926
|
+
// Render
|
|
1927
|
+
// -----------------------------------------------------------------------
|
|
1928
|
+
/** Render the style applied to the given strings (joined with space). */
|
|
1929
|
+
render(...strs) {
|
|
1930
|
+
if (this._value) strs = [this._value, ...strs];
|
|
1931
|
+
let str = strs.join(" ");
|
|
1932
|
+
const hasUnderline = this._underlineStyle !== "none";
|
|
1933
|
+
const isBold = this._set.has("bold") && this._bold;
|
|
1934
|
+
const isItalic = this._set.has("italic") && this._italic;
|
|
1935
|
+
const isStrikethrough = this._set.has("strikethrough") && this._strikethrough;
|
|
1936
|
+
const isReverse = this._set.has("reverse") && this._reverse;
|
|
1937
|
+
const isBlink = this._set.has("blink") && this._blink;
|
|
1938
|
+
const isFaint = this._set.has("faint") && this._faint;
|
|
1939
|
+
const fg = this._set.has("fg") ? parseColor(this._fg) : null;
|
|
1940
|
+
const bg = this._set.has("bg") ? parseColor(this._bg) : null;
|
|
1941
|
+
const ul = this._set.has("ulColor") ? parseColor(this._ulColor) : null;
|
|
1942
|
+
const w = this._set.has("width") ? this._width : 0;
|
|
1943
|
+
const h = this._set.has("height") ? this._height : 0;
|
|
1944
|
+
const hAlign = this._set.has("alignH") ? this._alignH : Left;
|
|
1945
|
+
const vAlign = this._set.has("alignV") ? this._alignV : Top;
|
|
1946
|
+
const topPad = this._set.has("paddingTop") ? this._paddingTop : 0;
|
|
1947
|
+
const rightPad = this._set.has("paddingRight") ? this._paddingRight : 0;
|
|
1948
|
+
const bottomPad = this._set.has("paddingBottom") ? this._paddingBottom : 0;
|
|
1949
|
+
const leftPad = this._set.has("paddingLeft") ? this._paddingLeft : 0;
|
|
1950
|
+
const hBorderSize = this.getHorizontalBorderSize();
|
|
1951
|
+
const vBorderSize = this.getVerticalBorderSize();
|
|
1952
|
+
const colorWS = this._set.has("colorWhitespace") ? this._colorWhitespace : true;
|
|
1953
|
+
const isInline = this._set.has("inline") ? this._inline : false;
|
|
1954
|
+
const mw = this._set.has("maxWidth") ? this._maxWidth : 0;
|
|
1955
|
+
const mh = this._set.has("maxHeight") ? this._maxHeight : 0;
|
|
1956
|
+
const ulSpaces = this._set.has("underlineSpaces") && this._underlineSpaces || hasUnderline && (!this._set.has("underlineSpaces") || this._underlineSpaces);
|
|
1957
|
+
const stSpaces = this._set.has("strikethroughSpaces") && this._strikethroughSpaces || isStrikethrough && (!this._set.has("strikethroughSpaces") || this._strikethroughSpaces);
|
|
1958
|
+
const styleWhitespace = isReverse;
|
|
1959
|
+
const useSpaceStyler = hasUnderline && !ulSpaces || isStrikethrough && !stSpaces || ulSpaces || stSpaces;
|
|
1960
|
+
const transform = this._set.has("transform") ? this._transform : null;
|
|
1961
|
+
const link = this._set.has("link") ? this._link : "";
|
|
1962
|
+
const linkParams = this._set.has("linkParams") ? this._linkParams : "";
|
|
1963
|
+
if (transform) str = transform(str);
|
|
1964
|
+
if (this._set.size === 0) return this._maybeConvertTabs(str);
|
|
1965
|
+
const teOpts = {};
|
|
1966
|
+
const teSpaceOpts = {};
|
|
1967
|
+
const teWSOpts = {};
|
|
1968
|
+
if (isBold) teOpts.bold = true;
|
|
1969
|
+
if (isItalic) teOpts.italic = true;
|
|
1970
|
+
if (hasUnderline) {
|
|
1971
|
+
teOpts.underline = true;
|
|
1972
|
+
teOpts.underlineStyle = this._underlineStyle;
|
|
1973
|
+
}
|
|
1974
|
+
if (isReverse) {
|
|
1975
|
+
teOpts.reverse = true;
|
|
1976
|
+
teWSOpts.reverse = true;
|
|
1977
|
+
}
|
|
1978
|
+
if (isBlink) teOpts.blink = true;
|
|
1979
|
+
if (isFaint) teOpts.faint = true;
|
|
1980
|
+
if (isStrikethrough) teOpts.strikethrough = true;
|
|
1981
|
+
if (fg) {
|
|
1982
|
+
teOpts.fg = fg;
|
|
1983
|
+
if (styleWhitespace) teWSOpts.fg = fg;
|
|
1984
|
+
if (useSpaceStyler) teSpaceOpts.fg = fg;
|
|
1985
|
+
}
|
|
1986
|
+
if (bg) {
|
|
1987
|
+
teOpts.bg = bg;
|
|
1988
|
+
if (colorWS) teWSOpts.bg = bg;
|
|
1989
|
+
if (useSpaceStyler) teSpaceOpts.bg = bg;
|
|
1990
|
+
}
|
|
1991
|
+
if (ul) {
|
|
1992
|
+
teOpts.ul = ul;
|
|
1993
|
+
if (colorWS) teWSOpts.ul = ul;
|
|
1994
|
+
if (useSpaceStyler) teSpaceOpts.ul = ul;
|
|
1995
|
+
}
|
|
1996
|
+
if (ulSpaces) teSpaceOpts.underline = true;
|
|
1997
|
+
if (stSpaces) teSpaceOpts.strikethrough = true;
|
|
1998
|
+
str = this._maybeConvertTabs(str);
|
|
1999
|
+
str = str.replace(/\r\n/g, "\n");
|
|
2000
|
+
if (isInline) str = str.replace(/\n/g, "");
|
|
2001
|
+
let width = w - hBorderSize;
|
|
2002
|
+
let height = h - vBorderSize;
|
|
2003
|
+
if (!isInline && width > 0) {
|
|
2004
|
+
const wrapAt = width - leftPad - rightPad;
|
|
2005
|
+
str = wordWrap(str, wrapAt);
|
|
2006
|
+
}
|
|
2007
|
+
{
|
|
2008
|
+
const lines = str.split("\n");
|
|
2009
|
+
const rendered = [];
|
|
2010
|
+
for (const line of lines) {
|
|
2011
|
+
if (useSpaceStyler) {
|
|
2012
|
+
let buf = "";
|
|
2013
|
+
for (const ch of line) {
|
|
2014
|
+
if (ch === " " || ch === " ") {
|
|
2015
|
+
buf += styled(ch, teSpaceOpts);
|
|
2016
|
+
} else {
|
|
2017
|
+
buf += styled(ch, teOpts);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
rendered.push(buf);
|
|
2021
|
+
} else {
|
|
2022
|
+
rendered.push(line ? styled(line, teOpts) : line);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
str = rendered.join("\n");
|
|
2026
|
+
if (link) {
|
|
2027
|
+
str = setHyperlink(link, linkParams || void 0) + str + resetHyperlink();
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
if (!isInline) {
|
|
2031
|
+
const wsStyle = colorWS || styleWhitespace ? teWSOpts : null;
|
|
2032
|
+
const padCh = this._set.has("paddingChar") ? this._paddingChar : " ";
|
|
2033
|
+
if (leftPad > 0) str = padLeft(str, leftPad, wsStyle, padCh);
|
|
2034
|
+
if (rightPad > 0) str = padRight(str, rightPad, wsStyle, padCh);
|
|
2035
|
+
if (topPad > 0) str = "\n".repeat(topPad) + str;
|
|
2036
|
+
if (bottomPad > 0) str = str + "\n".repeat(bottomPad);
|
|
2037
|
+
}
|
|
2038
|
+
if (height > 0) str = alignTextVertical(str, vAlign, height);
|
|
2039
|
+
{
|
|
2040
|
+
const numLines = str.split("\n").length - 1;
|
|
2041
|
+
if (numLines > 0 || width > 0) {
|
|
2042
|
+
const wsStyle = colorWS || styleWhitespace ? teWSOpts : null;
|
|
2043
|
+
str = alignTextHorizontal(str, hAlign, width, wsStyle);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
if (!isInline) {
|
|
2047
|
+
str = this._applyBorder(str);
|
|
2048
|
+
str = this._applyMargins(str, isInline);
|
|
2049
|
+
}
|
|
2050
|
+
if (mw > 0) {
|
|
2051
|
+
str = str.split("\n").map((line) => truncate(line, mw)).join("\n");
|
|
2052
|
+
}
|
|
2053
|
+
if (mh > 0) {
|
|
2054
|
+
const lines = str.split("\n");
|
|
2055
|
+
if (lines.length > mh) str = lines.slice(0, mh).join("\n");
|
|
2056
|
+
}
|
|
2057
|
+
return str;
|
|
2058
|
+
}
|
|
2059
|
+
// -----------------------------------------------------------------------
|
|
2060
|
+
// Internal: tab conversion
|
|
2061
|
+
// -----------------------------------------------------------------------
|
|
2062
|
+
_maybeConvertTabs(str) {
|
|
2063
|
+
const tw = this._set.has("tabWidth") ? this._tabWidth : TAB_WIDTH_DEFAULT;
|
|
2064
|
+
if (tw === -1) return str;
|
|
2065
|
+
if (tw === 0) return str.replace(/\t/g, "");
|
|
2066
|
+
return str.replace(/\t/g, " ".repeat(tw));
|
|
2067
|
+
}
|
|
2068
|
+
// -----------------------------------------------------------------------
|
|
2069
|
+
// Internal: border rendering
|
|
2070
|
+
// -----------------------------------------------------------------------
|
|
2071
|
+
_applyBorder(str) {
|
|
2072
|
+
let borderDef = this.getBorderStyle();
|
|
2073
|
+
let hasT = this.getBorderTop();
|
|
2074
|
+
let hasR = this.getBorderRight();
|
|
2075
|
+
let hasB = this.getBorderBottom();
|
|
2076
|
+
let hasL = this.getBorderLeft();
|
|
2077
|
+
if (this._isBorderStyleSetWithoutSides()) {
|
|
2078
|
+
hasT = true;
|
|
2079
|
+
hasR = true;
|
|
2080
|
+
hasB = true;
|
|
2081
|
+
hasL = true;
|
|
2082
|
+
}
|
|
2083
|
+
if (isNoBorder(borderDef) || !hasT && !hasR && !hasB && !hasL) return str;
|
|
2084
|
+
borderDef = { ...borderDef };
|
|
2085
|
+
const { lines, widest } = getLines(str);
|
|
2086
|
+
let width = widest;
|
|
2087
|
+
if (hasL) {
|
|
2088
|
+
if (!borderDef.left) borderDef.left = " ";
|
|
2089
|
+
width += maxRuneWidth(borderDef.left);
|
|
2090
|
+
}
|
|
2091
|
+
if (hasR) {
|
|
2092
|
+
if (!borderDef.right) borderDef.right = " ";
|
|
2093
|
+
width += maxRuneWidth(borderDef.right);
|
|
2094
|
+
}
|
|
2095
|
+
if (hasT && hasL && !borderDef.topLeft) borderDef.topLeft = " ";
|
|
2096
|
+
if (hasT && hasR && !borderDef.topRight) borderDef.topRight = " ";
|
|
2097
|
+
if (hasB && hasL && !borderDef.bottomLeft) borderDef.bottomLeft = " ";
|
|
2098
|
+
if (hasB && hasR && !borderDef.bottomRight) borderDef.bottomRight = " ";
|
|
2099
|
+
if (hasT) {
|
|
2100
|
+
if (!hasL && !hasR) {
|
|
2101
|
+
borderDef.topLeft = "";
|
|
2102
|
+
borderDef.topRight = "";
|
|
2103
|
+
} else if (!hasL) {
|
|
2104
|
+
borderDef.topLeft = "";
|
|
2105
|
+
} else if (!hasR) {
|
|
2106
|
+
borderDef.topRight = "";
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
if (hasB) {
|
|
2110
|
+
if (!hasL && !hasR) {
|
|
2111
|
+
borderDef.bottomLeft = "";
|
|
2112
|
+
borderDef.bottomRight = "";
|
|
2113
|
+
} else if (!hasL) {
|
|
2114
|
+
borderDef.bottomLeft = "";
|
|
2115
|
+
} else if (!hasR) {
|
|
2116
|
+
borderDef.bottomRight = "";
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
borderDef.topLeft = getFirstRune(borderDef.topLeft);
|
|
2120
|
+
borderDef.topRight = getFirstRune(borderDef.topRight);
|
|
2121
|
+
borderDef.bottomLeft = getFirstRune(borderDef.bottomLeft);
|
|
2122
|
+
borderDef.bottomRight = getFirstRune(borderDef.bottomRight);
|
|
2123
|
+
const topFg = this._set.has("borderTopFg") ? parseColor(this._borderTopFg) : null;
|
|
2124
|
+
const rightFg = this._set.has("borderRightFg") ? parseColor(this._borderRightFg) : null;
|
|
2125
|
+
const bottomFg = this._set.has("borderBottomFg") ? parseColor(this._borderBottomFg) : null;
|
|
2126
|
+
const leftFg = this._set.has("borderLeftFg") ? parseColor(this._borderLeftFg) : null;
|
|
2127
|
+
const topBg = this._set.has("borderTopBg") ? parseColor(this._borderTopBg) : null;
|
|
2128
|
+
const rightBg = this._set.has("borderRightBg") ? parseColor(this._borderRightBg) : null;
|
|
2129
|
+
const bottomBg = this._set.has("borderBottomBg") ? parseColor(this._borderBottomBg) : null;
|
|
2130
|
+
const leftBg = this._set.has("borderLeftBg") ? parseColor(this._borderLeftBg) : null;
|
|
2131
|
+
let out = "";
|
|
2132
|
+
if (hasT) {
|
|
2133
|
+
const top = renderHorizontalEdge(borderDef.topLeft, borderDef.top, borderDef.topRight, width);
|
|
2134
|
+
out += styleBorderStr(top, topFg, topBg) + "\n";
|
|
2135
|
+
}
|
|
2136
|
+
const leftRunes = [...borderDef.left];
|
|
2137
|
+
const rightRunes = [...borderDef.right];
|
|
2138
|
+
let li = 0, ri = 0;
|
|
2139
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2140
|
+
if (hasL) {
|
|
2141
|
+
const r = leftRunes[li % leftRunes.length];
|
|
2142
|
+
li++;
|
|
2143
|
+
out += styleBorderStr(r, leftFg, leftBg);
|
|
2144
|
+
}
|
|
2145
|
+
out += lines[i];
|
|
2146
|
+
if (hasR) {
|
|
2147
|
+
const r = rightRunes[ri % rightRunes.length];
|
|
2148
|
+
ri++;
|
|
2149
|
+
out += styleBorderStr(r, rightFg, rightBg);
|
|
2150
|
+
}
|
|
2151
|
+
if (i < lines.length - 1) out += "\n";
|
|
2152
|
+
}
|
|
2153
|
+
if (hasB) {
|
|
2154
|
+
const bottom = renderHorizontalEdge(borderDef.bottomLeft, borderDef.bottom, borderDef.bottomRight, width);
|
|
2155
|
+
out += "\n" + styleBorderStr(bottom, bottomFg, bottomBg);
|
|
2156
|
+
}
|
|
2157
|
+
return out;
|
|
2158
|
+
}
|
|
2159
|
+
// -----------------------------------------------------------------------
|
|
2160
|
+
// Internal: margin rendering
|
|
2161
|
+
// -----------------------------------------------------------------------
|
|
2162
|
+
_applyMargins(str, isInline) {
|
|
2163
|
+
const topM = this._set.has("marginTop") ? this._marginTop : 0;
|
|
2164
|
+
const rightM = this._set.has("marginRight") ? this._marginRight : 0;
|
|
2165
|
+
const bottomM = this._set.has("marginBottom") ? this._marginBottom : 0;
|
|
2166
|
+
const leftM = this._set.has("marginLeft") ? this._marginLeft : 0;
|
|
2167
|
+
const marginBg = this._set.has("marginBg") ? parseColor(this._marginBg) : null;
|
|
2168
|
+
const marginStyle = marginBg ? { bg: marginBg } : null;
|
|
2169
|
+
if (leftM > 0) str = padLeft(str, leftM, marginStyle);
|
|
2170
|
+
if (rightM > 0) str = padRight(str, rightM, marginStyle);
|
|
2171
|
+
if (!isInline) {
|
|
2172
|
+
const { widest: totalWidth } = getLines(str);
|
|
2173
|
+
const blankLine = marginStyle ? styled(" ".repeat(totalWidth), marginStyle) : " ".repeat(totalWidth);
|
|
2174
|
+
if (topM > 0) {
|
|
2175
|
+
str = (blankLine + "\n").repeat(topM) + str;
|
|
2176
|
+
}
|
|
2177
|
+
if (bottomM > 0) {
|
|
2178
|
+
str = str + ("\n" + blankLine).repeat(bottomM);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
return str;
|
|
2182
|
+
}
|
|
2183
|
+
// -----------------------------------------------------------------------
|
|
2184
|
+
// toString
|
|
2185
|
+
// -----------------------------------------------------------------------
|
|
2186
|
+
toString() {
|
|
2187
|
+
return this.render();
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
function styleBorderStr(border2, fg, bg) {
|
|
2191
|
+
if (!fg && !bg) return border2;
|
|
2192
|
+
return styled(border2, { fg, bg });
|
|
2193
|
+
}
|
|
2194
|
+
function newStyle() {
|
|
2195
|
+
return new Style();
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
// src/layout.ts
|
|
2199
|
+
function joinHorizontal(pos, ...strs) {
|
|
2200
|
+
if (strs.length === 0) return "";
|
|
2201
|
+
if (strs.length === 1) return strs[0];
|
|
2202
|
+
const blocks = [];
|
|
2203
|
+
const maxWidths = [];
|
|
2204
|
+
let maxHeight = 0;
|
|
2205
|
+
for (let i = 0; i < strs.length; i++) {
|
|
2206
|
+
const { lines, widest } = getLines(strs[i]);
|
|
2207
|
+
blocks.push(lines);
|
|
2208
|
+
maxWidths.push(widest);
|
|
2209
|
+
if (lines.length > maxHeight) maxHeight = lines.length;
|
|
2210
|
+
}
|
|
2211
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
2212
|
+
if (blocks[i].length >= maxHeight) continue;
|
|
2213
|
+
const extra = maxHeight - blocks[i].length;
|
|
2214
|
+
const empties = new Array(extra).fill("");
|
|
2215
|
+
const p = Math.min(1, Math.max(0, pos));
|
|
2216
|
+
if (p <= 0) {
|
|
2217
|
+
blocks[i] = [...blocks[i], ...empties];
|
|
2218
|
+
} else if (p >= 1) {
|
|
2219
|
+
blocks[i] = [...empties, ...blocks[i]];
|
|
2220
|
+
} else {
|
|
2221
|
+
const split = Math.round(extra * p);
|
|
2222
|
+
const top = extra - split;
|
|
2223
|
+
const bottom = extra - top;
|
|
2224
|
+
blocks[i] = [
|
|
2225
|
+
...new Array(top).fill(""),
|
|
2226
|
+
...blocks[i],
|
|
2227
|
+
...new Array(bottom).fill("")
|
|
2228
|
+
];
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
const result = [];
|
|
2232
|
+
for (let row = 0; row < maxHeight; row++) {
|
|
2233
|
+
let line = "";
|
|
2234
|
+
for (let col = 0; col < blocks.length; col++) {
|
|
2235
|
+
const cell = blocks[col][row] || "";
|
|
2236
|
+
line += cell;
|
|
2237
|
+
const pad = maxWidths[col] - stringWidth(cell);
|
|
2238
|
+
if (pad > 0) line += " ".repeat(pad);
|
|
2239
|
+
}
|
|
2240
|
+
result.push(line);
|
|
2241
|
+
}
|
|
2242
|
+
return result.join("\n");
|
|
2243
|
+
}
|
|
2244
|
+
function joinVertical(pos, ...strs) {
|
|
2245
|
+
if (strs.length === 0) return "";
|
|
2246
|
+
if (strs.length === 1) return strs[0];
|
|
2247
|
+
const blocks = [];
|
|
2248
|
+
let maxWidth = 0;
|
|
2249
|
+
for (const str of strs) {
|
|
2250
|
+
const { lines, widest } = getLines(str);
|
|
2251
|
+
blocks.push(lines);
|
|
2252
|
+
if (widest > maxWidth) maxWidth = widest;
|
|
2253
|
+
}
|
|
2254
|
+
const result = [];
|
|
2255
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
2256
|
+
for (let j = 0; j < blocks[i].length; j++) {
|
|
2257
|
+
const line = blocks[i][j];
|
|
2258
|
+
const gap = maxWidth - stringWidth(line);
|
|
2259
|
+
if (gap <= 0) {
|
|
2260
|
+
result.push(line);
|
|
2261
|
+
} else {
|
|
2262
|
+
const p = Math.min(1, Math.max(0, pos));
|
|
2263
|
+
if (p <= 0) {
|
|
2264
|
+
result.push(line + " ".repeat(gap));
|
|
2265
|
+
} else if (p >= 1) {
|
|
2266
|
+
result.push(" ".repeat(gap) + line);
|
|
2267
|
+
} else {
|
|
2268
|
+
const split = Math.round(gap * p);
|
|
2269
|
+
const left = gap - split;
|
|
2270
|
+
const right = gap - left;
|
|
2271
|
+
result.push(" ".repeat(left) + line + " ".repeat(right));
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
return result.join("\n");
|
|
2277
|
+
}
|
|
2278
|
+
function place(width, height, hPos, vPos, str) {
|
|
2279
|
+
return placeVertical(height, vPos, placeHorizontal(width, hPos, str));
|
|
2280
|
+
}
|
|
2281
|
+
function placeHorizontal(width, pos, str) {
|
|
2282
|
+
const { lines, widest: contentWidth } = getLines(str);
|
|
2283
|
+
const gap = width - contentWidth;
|
|
2284
|
+
if (gap <= 0) return str;
|
|
2285
|
+
const result = [];
|
|
2286
|
+
for (const line of lines) {
|
|
2287
|
+
const short = Math.max(0, contentWidth - stringWidth(line));
|
|
2288
|
+
const totalGap = gap + short;
|
|
2289
|
+
const p = Math.min(1, Math.max(0, pos));
|
|
2290
|
+
if (p <= 0) {
|
|
2291
|
+
result.push(line + " ".repeat(totalGap));
|
|
2292
|
+
} else if (p >= 1) {
|
|
2293
|
+
result.push(" ".repeat(totalGap) + line);
|
|
2294
|
+
} else {
|
|
2295
|
+
const split = Math.round(totalGap * p);
|
|
2296
|
+
const left = totalGap - split;
|
|
2297
|
+
const right = totalGap - left;
|
|
2298
|
+
result.push(" ".repeat(left) + line + " ".repeat(right));
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
return result.join("\n");
|
|
2302
|
+
}
|
|
2303
|
+
function placeVertical(height, pos, str) {
|
|
2304
|
+
const contentHeight = str.split("\n").length;
|
|
2305
|
+
const gap = height - contentHeight;
|
|
2306
|
+
if (gap <= 0) return str;
|
|
2307
|
+
const { widest: width } = getLines(str);
|
|
2308
|
+
const emptyLine = " ".repeat(width);
|
|
2309
|
+
const p = Math.min(1, Math.max(0, pos));
|
|
2310
|
+
if (p <= 0) {
|
|
2311
|
+
const bottom = [];
|
|
2312
|
+
for (let i = 0; i < gap; i++) bottom.push(emptyLine);
|
|
2313
|
+
return str + "\n" + bottom.join("\n");
|
|
2314
|
+
} else if (p >= 1) {
|
|
2315
|
+
const top = [];
|
|
2316
|
+
for (let i = 0; i < gap; i++) top.push(emptyLine);
|
|
2317
|
+
return top.join("\n") + "\n" + str;
|
|
2318
|
+
} else {
|
|
2319
|
+
const split = Math.round(gap * p);
|
|
2320
|
+
const topCount = gap - split;
|
|
2321
|
+
const bottomCount = gap - topCount;
|
|
2322
|
+
const topLines = [];
|
|
2323
|
+
for (let i = 0; i < topCount; i++) topLines.push(emptyLine);
|
|
2324
|
+
const bottomLines = [];
|
|
2325
|
+
for (let i = 0; i < bottomCount; i++) bottomLines.push(emptyLine);
|
|
2326
|
+
let result = "";
|
|
2327
|
+
if (topLines.length > 0) result += topLines.join("\n") + "\n";
|
|
2328
|
+
result += str;
|
|
2329
|
+
if (bottomLines.length > 0) result += "\n" + bottomLines.join("\n");
|
|
2330
|
+
return result;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2334
|
+
0 && (module.exports = {
|
|
2335
|
+
Black,
|
|
2336
|
+
Blue,
|
|
2337
|
+
Bottom,
|
|
2338
|
+
BrightBlack,
|
|
2339
|
+
BrightBlue,
|
|
2340
|
+
BrightCyan,
|
|
2341
|
+
BrightGreen,
|
|
2342
|
+
BrightMagenta,
|
|
2343
|
+
BrightRed,
|
|
2344
|
+
BrightWhite,
|
|
2345
|
+
BrightYellow,
|
|
2346
|
+
Center,
|
|
2347
|
+
Cyan,
|
|
2348
|
+
Green,
|
|
2349
|
+
Left,
|
|
2350
|
+
Magenta,
|
|
2351
|
+
NO_COLOR,
|
|
2352
|
+
Red,
|
|
2353
|
+
Right,
|
|
2354
|
+
SGR,
|
|
2355
|
+
Style,
|
|
2356
|
+
Top,
|
|
2357
|
+
White,
|
|
2358
|
+
Yellow,
|
|
2359
|
+
alpha,
|
|
2360
|
+
ansi256ToRGB,
|
|
2361
|
+
asciiBorder,
|
|
2362
|
+
bgAnsi256,
|
|
2363
|
+
bgBasic,
|
|
2364
|
+
bgColor,
|
|
2365
|
+
blockBorder,
|
|
2366
|
+
colorToRGB,
|
|
2367
|
+
complementary,
|
|
2368
|
+
darken,
|
|
2369
|
+
doubleBorder,
|
|
2370
|
+
fgAnsi256,
|
|
2371
|
+
fgBasic,
|
|
2372
|
+
fgColor,
|
|
2373
|
+
getBottomSize,
|
|
2374
|
+
getFirstRune,
|
|
2375
|
+
getLeftSize,
|
|
2376
|
+
getLines,
|
|
2377
|
+
getRightSize,
|
|
2378
|
+
getTopSize,
|
|
2379
|
+
hiddenBorder,
|
|
2380
|
+
innerHalfBlockBorder,
|
|
2381
|
+
isDarkColor,
|
|
2382
|
+
isNoBorder,
|
|
2383
|
+
joinHorizontal,
|
|
2384
|
+
joinVertical,
|
|
2385
|
+
lightDark,
|
|
2386
|
+
lighten,
|
|
2387
|
+
markdownBorder,
|
|
2388
|
+
maxRuneWidth,
|
|
2389
|
+
newStyle,
|
|
2390
|
+
noBorder,
|
|
2391
|
+
normalBorder,
|
|
2392
|
+
outerHalfBlockBorder,
|
|
2393
|
+
parseColor,
|
|
2394
|
+
parseHex,
|
|
2395
|
+
place,
|
|
2396
|
+
placeHorizontal,
|
|
2397
|
+
placeVertical,
|
|
2398
|
+
resetHyperlink,
|
|
2399
|
+
roundedBorder,
|
|
2400
|
+
setHyperlink,
|
|
2401
|
+
stringWidth,
|
|
2402
|
+
stripAnsi,
|
|
2403
|
+
styled,
|
|
2404
|
+
thickBorder,
|
|
2405
|
+
truncate,
|
|
2406
|
+
ulAnsi256,
|
|
2407
|
+
ulColor
|
|
2408
|
+
});
|