@jrichman/ink 6.4.13-beta.1 → 6.5.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/package.json +1 -1
- package/build/wrap-text.d.ts +0 -6
- package/build/wrap-text.js +0 -120
- package/build/wrap-text.js.map +0 -1
package/package.json
CHANGED
package/build/wrap-text.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type StyledChar } from '@alcalzone/ansi-tokenize';
|
|
2
|
-
export declare const sliceStyledChars: (styledChars: StyledChar[], begin: number, end?: number) => StyledChar[];
|
|
3
|
-
export declare const truncateStyledChars: (styledChars: StyledChar[], columns: number, options?: {
|
|
4
|
-
position?: "start" | "middle" | "end";
|
|
5
|
-
}) => StyledChar[];
|
|
6
|
-
export declare const wrapStyledChars: (styledChars: StyledChar[], columns: number) => StyledChar[][];
|
package/build/wrap-text.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { inkCharacterWidth, styledCharsWidth } from './measure-text.js';
|
|
2
|
-
export const sliceStyledChars = (styledChars, begin, end) => {
|
|
3
|
-
let width = 0;
|
|
4
|
-
const result = [];
|
|
5
|
-
for (const char of styledChars) {
|
|
6
|
-
const charWidth = inkCharacterWidth(char.value);
|
|
7
|
-
const charStart = width;
|
|
8
|
-
const charEnd = width + charWidth;
|
|
9
|
-
if (end !== undefined && charEnd > end) {
|
|
10
|
-
break;
|
|
11
|
-
}
|
|
12
|
-
if (charStart >= begin) {
|
|
13
|
-
result.push(char);
|
|
14
|
-
}
|
|
15
|
-
width += charWidth;
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
};
|
|
19
|
-
export const truncateStyledChars = (styledChars, columns, options = {}) => {
|
|
20
|
-
const { position = 'end' } = options;
|
|
21
|
-
const truncationCharacter = '…';
|
|
22
|
-
const truncationStyledChar = {
|
|
23
|
-
type: 'char',
|
|
24
|
-
value: truncationCharacter,
|
|
25
|
-
fullWidth: false,
|
|
26
|
-
styles: [],
|
|
27
|
-
};
|
|
28
|
-
if (columns < 1) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
if (columns === 1) {
|
|
32
|
-
return [truncationStyledChar];
|
|
33
|
-
}
|
|
34
|
-
const textWidth = styledCharsWidth(styledChars);
|
|
35
|
-
if (textWidth <= columns) {
|
|
36
|
-
return styledChars;
|
|
37
|
-
}
|
|
38
|
-
const truncationWidth = inkCharacterWidth(truncationCharacter);
|
|
39
|
-
if (position === 'start') {
|
|
40
|
-
const right = sliceStyledChars(styledChars, textWidth - columns + truncationWidth, textWidth);
|
|
41
|
-
return [truncationStyledChar, ...right];
|
|
42
|
-
}
|
|
43
|
-
if (position === 'middle') {
|
|
44
|
-
const leftWidth = Math.ceil(columns / 2);
|
|
45
|
-
const rightWidth = columns - leftWidth;
|
|
46
|
-
const left = sliceStyledChars(styledChars, 0, leftWidth - truncationWidth);
|
|
47
|
-
const right = sliceStyledChars(styledChars, textWidth - rightWidth, textWidth);
|
|
48
|
-
return [...left, truncationStyledChar, ...right];
|
|
49
|
-
}
|
|
50
|
-
const left = sliceStyledChars(styledChars, 0, columns - truncationWidth);
|
|
51
|
-
return [...left, truncationStyledChar];
|
|
52
|
-
};
|
|
53
|
-
const wrapWord = (rows, word, columns) => {
|
|
54
|
-
let currentLine = rows.at(-1);
|
|
55
|
-
let visible = styledCharsWidth(currentLine);
|
|
56
|
-
for (const character of word) {
|
|
57
|
-
const characterLength = inkCharacterWidth(character.value);
|
|
58
|
-
if (visible + characterLength > columns && visible > 0) {
|
|
59
|
-
rows.push([]);
|
|
60
|
-
currentLine = rows.at(-1);
|
|
61
|
-
visible = 0;
|
|
62
|
-
}
|
|
63
|
-
currentLine.push(character);
|
|
64
|
-
visible += characterLength;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
export const wrapStyledChars = (styledChars, columns) => {
|
|
68
|
-
const rows = [[]];
|
|
69
|
-
const words = [];
|
|
70
|
-
let currentWord = [];
|
|
71
|
-
for (const char of styledChars) {
|
|
72
|
-
if (char.value === ' ') {
|
|
73
|
-
if (currentWord.length > 0) {
|
|
74
|
-
words.push(currentWord);
|
|
75
|
-
}
|
|
76
|
-
currentWord = [];
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
currentWord.push(char);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (currentWord.length > 0) {
|
|
83
|
-
words.push(currentWord);
|
|
84
|
-
}
|
|
85
|
-
const space = {
|
|
86
|
-
type: 'char',
|
|
87
|
-
value: ' ',
|
|
88
|
-
fullWidth: false,
|
|
89
|
-
styles: [],
|
|
90
|
-
};
|
|
91
|
-
for (const [index, word] of words.entries()) {
|
|
92
|
-
const wordWidth = styledCharsWidth(word);
|
|
93
|
-
let rowWidth = styledCharsWidth(rows.at(-1));
|
|
94
|
-
if (index > 0) {
|
|
95
|
-
rows.at(-1).push(space);
|
|
96
|
-
rowWidth++;
|
|
97
|
-
}
|
|
98
|
-
if (wordWidth > columns) {
|
|
99
|
-
if (index > 0) {
|
|
100
|
-
rows[rows.length - 1] = rows.at(-1).slice(0, -1);
|
|
101
|
-
if (rows.at(-1).length > 0) {
|
|
102
|
-
rows.push([]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
wrapWord(rows, word, columns);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (rowWidth + wordWidth > columns && rowWidth > 0) {
|
|
109
|
-
if (index > 0) {
|
|
110
|
-
rows[rows.length - 1] = rows.at(-1).slice(0, -1);
|
|
111
|
-
}
|
|
112
|
-
rows.push(word);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
rows.at(-1).push(...word);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return rows;
|
|
119
|
-
};
|
|
120
|
-
//# sourceMappingURL=wrap-text.js.map
|
package/build/wrap-text.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrap-text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