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