@kingkoo1985/ink 6.6.6

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.
Files changed (225) hide show
  1. package/build/colorize.d.ts +4 -0
  2. package/build/colorize.js +59 -0
  3. package/build/colorize.js.map +1 -0
  4. package/build/components/AccessibilityContext.d.ts +3 -0
  5. package/build/components/AccessibilityContext.js +5 -0
  6. package/build/components/AccessibilityContext.js.map +1 -0
  7. package/build/components/App.d.ts +68 -0
  8. package/build/components/App.js +290 -0
  9. package/build/components/App.js.map +1 -0
  10. package/build/components/AppContext.d.ts +52 -0
  11. package/build/components/AppContext.js +16 -0
  12. package/build/components/AppContext.js.map +1 -0
  13. package/build/components/BackgroundContext.d.ts +4 -0
  14. package/build/components/BackgroundContext.js +3 -0
  15. package/build/components/BackgroundContext.js.map +1 -0
  16. package/build/components/Box.d.ts +171 -0
  17. package/build/components/Box.js +40 -0
  18. package/build/components/Box.js.map +1 -0
  19. package/build/components/ErrorOverview.d.ts +6 -0
  20. package/build/components/ErrorOverview.js +84 -0
  21. package/build/components/ErrorOverview.js.map +1 -0
  22. package/build/components/FocusContext.d.ts +16 -0
  23. package/build/components/FocusContext.js +16 -0
  24. package/build/components/FocusContext.js.map +1 -0
  25. package/build/components/Newline.d.ts +13 -0
  26. package/build/components/Newline.js +8 -0
  27. package/build/components/Newline.js.map +1 -0
  28. package/build/components/Spacer.d.ts +7 -0
  29. package/build/components/Spacer.js +11 -0
  30. package/build/components/Spacer.js.map +1 -0
  31. package/build/components/Static.d.ts +24 -0
  32. package/build/components/Static.js +29 -0
  33. package/build/components/Static.js.map +1 -0
  34. package/build/components/StaticRender.d.ts +8 -0
  35. package/build/components/StaticRender.js +19 -0
  36. package/build/components/StaticRender.js.map +1 -0
  37. package/build/components/StderrContext.d.ts +15 -0
  38. package/build/components/StderrContext.js +12 -0
  39. package/build/components/StderrContext.js.map +1 -0
  40. package/build/components/StdinContext.d.ts +22 -0
  41. package/build/components/StdinContext.js +16 -0
  42. package/build/components/StdinContext.js.map +1 -0
  43. package/build/components/StdoutContext.d.ts +15 -0
  44. package/build/components/StdoutContext.js +12 -0
  45. package/build/components/StdoutContext.js.map +1 -0
  46. package/build/components/Text.d.ts +63 -0
  47. package/build/components/Text.js +50 -0
  48. package/build/components/Text.js.map +1 -0
  49. package/build/components/Transform.d.ts +16 -0
  50. package/build/components/Transform.js +15 -0
  51. package/build/components/Transform.js.map +1 -0
  52. package/build/data-limited-lru-map.d.ts +20 -0
  53. package/build/data-limited-lru-map.js +65 -0
  54. package/build/data-limited-lru-map.js.map +1 -0
  55. package/build/debug-log.d.ts +2 -0
  56. package/build/debug-log.js +44 -0
  57. package/build/debug-log.js.map +1 -0
  58. package/build/devtools-window-polyfill.d.ts +1 -0
  59. package/build/devtools-window-polyfill.js +65 -0
  60. package/build/devtools-window-polyfill.js.map +1 -0
  61. package/build/devtools.d.ts +1 -0
  62. package/build/devtools.js +8 -0
  63. package/build/devtools.js.map +1 -0
  64. package/build/dom.d.ts +114 -0
  65. package/build/dom.js +169 -0
  66. package/build/dom.js.map +1 -0
  67. package/build/get-max-width.d.ts +3 -0
  68. package/build/get-max-width.js +10 -0
  69. package/build/get-max-width.js.map +1 -0
  70. package/build/hooks/use-app.d.ts +5 -0
  71. package/build/hooks/use-app.js +8 -0
  72. package/build/hooks/use-app.js.map +1 -0
  73. package/build/hooks/use-focus-manager.d.ts +28 -0
  74. package/build/hooks/use-focus-manager.js +17 -0
  75. package/build/hooks/use-focus-manager.js.map +1 -0
  76. package/build/hooks/use-focus.d.ts +29 -0
  77. package/build/hooks/use-focus.js +42 -0
  78. package/build/hooks/use-focus.js.map +1 -0
  79. package/build/hooks/use-input.d.ts +93 -0
  80. package/build/hooks/use-input.js +92 -0
  81. package/build/hooks/use-input.js.map +1 -0
  82. package/build/hooks/use-is-screen-reader-enabled.d.ts +5 -0
  83. package/build/hooks/use-is-screen-reader-enabled.js +11 -0
  84. package/build/hooks/use-is-screen-reader-enabled.js.map +1 -0
  85. package/build/hooks/use-stderr.d.ts +5 -0
  86. package/build/hooks/use-stderr.js +8 -0
  87. package/build/hooks/use-stderr.js.map +1 -0
  88. package/build/hooks/use-stdin.d.ts +5 -0
  89. package/build/hooks/use-stdin.js +8 -0
  90. package/build/hooks/use-stdin.js.map +1 -0
  91. package/build/hooks/use-stdout.d.ts +5 -0
  92. package/build/hooks/use-stdout.js +8 -0
  93. package/build/hooks/use-stdout.js.map +1 -0
  94. package/build/index.d.ts +38 -0
  95. package/build/index.js +27 -0
  96. package/build/index.js.map +1 -0
  97. package/build/ink.d.ts +110 -0
  98. package/build/ink.js +576 -0
  99. package/build/ink.js.map +1 -0
  100. package/build/instances.d.ts +3 -0
  101. package/build/instances.js +8 -0
  102. package/build/instances.js.map +1 -0
  103. package/build/layout.d.ts +18 -0
  104. package/build/layout.js +54 -0
  105. package/build/layout.js.map +1 -0
  106. package/build/log-update.d.ts +28 -0
  107. package/build/log-update.js +529 -0
  108. package/build/log-update.js.map +1 -0
  109. package/build/measure-element.d.ts +119 -0
  110. package/build/measure-element.js +825 -0
  111. package/build/measure-element.js.map +1 -0
  112. package/build/measure-text.d.ts +50 -0
  113. package/build/measure-text.js +237 -0
  114. package/build/measure-text.js.map +1 -0
  115. package/build/output.d.ts +242 -0
  116. package/build/output.js +607 -0
  117. package/build/output.js.map +1 -0
  118. package/build/parse-keypress.d.ts +14 -0
  119. package/build/parse-keypress.js +225 -0
  120. package/build/parse-keypress.js.map +1 -0
  121. package/build/reconciler.d.ts +4 -0
  122. package/build/reconciler.js +326 -0
  123. package/build/reconciler.js.map +1 -0
  124. package/build/render-background.d.ts +4 -0
  125. package/build/render-background.js +37 -0
  126. package/build/render-background.js.map +1 -0
  127. package/build/render-border.d.ts +4 -0
  128. package/build/render-border.js +81 -0
  129. package/build/render-border.js.map +1 -0
  130. package/build/render-cached.d.ts +18 -0
  131. package/build/render-cached.js +66 -0
  132. package/build/render-cached.js.map +1 -0
  133. package/build/render-container.d.ts +27 -0
  134. package/build/render-container.js +169 -0
  135. package/build/render-container.js.map +1 -0
  136. package/build/render-node-to-output.d.ts +32 -0
  137. package/build/render-node-to-output.js +177 -0
  138. package/build/render-node-to-output.js.map +1 -0
  139. package/build/render-screen-reader.d.ts +5 -0
  140. package/build/render-screen-reader.js +54 -0
  141. package/build/render-screen-reader.js.map +1 -0
  142. package/build/render-scrollbar.d.ts +23 -0
  143. package/build/render-scrollbar.js +70 -0
  144. package/build/render-scrollbar.js.map +1 -0
  145. package/build/render-sticky.d.ts +53 -0
  146. package/build/render-sticky.js +317 -0
  147. package/build/render-sticky.js.map +1 -0
  148. package/build/render-text-node.d.ts +20 -0
  149. package/build/render-text-node.js +155 -0
  150. package/build/render-text-node.js.map +1 -0
  151. package/build/render.d.ts +165 -0
  152. package/build/render.js +60 -0
  153. package/build/render.js.map +1 -0
  154. package/build/renderer.d.ts +24 -0
  155. package/build/renderer.js +292 -0
  156. package/build/renderer.js.map +1 -0
  157. package/build/replay.d.ts +59 -0
  158. package/build/replay.js +128 -0
  159. package/build/replay.js.map +1 -0
  160. package/build/resize-observer.d.ts +24 -0
  161. package/build/resize-observer.js +102 -0
  162. package/build/resize-observer.js.map +1 -0
  163. package/build/scroll.d.ts +11 -0
  164. package/build/scroll.js +123 -0
  165. package/build/scroll.js.map +1 -0
  166. package/build/selection.d.ts +52 -0
  167. package/build/selection.js +359 -0
  168. package/build/selection.js.map +1 -0
  169. package/build/serialization.d.ts +25 -0
  170. package/build/serialization.js +224 -0
  171. package/build/serialization.js.map +1 -0
  172. package/build/squash-text-nodes.d.ts +16 -0
  173. package/build/squash-text-nodes.js +58 -0
  174. package/build/squash-text-nodes.js.map +1 -0
  175. package/build/styled-line.d.ts +58 -0
  176. package/build/styled-line.js +629 -0
  177. package/build/styled-line.js.map +1 -0
  178. package/build/styles.d.ts +286 -0
  179. package/build/styles.js +257 -0
  180. package/build/styles.js.map +1 -0
  181. package/build/terminal-buffer.d.ts +57 -0
  182. package/build/terminal-buffer.js +507 -0
  183. package/build/terminal-buffer.js.map +1 -0
  184. package/build/text-wrap.d.ts +12 -0
  185. package/build/text-wrap.js +154 -0
  186. package/build/text-wrap.js.map +1 -0
  187. package/build/tokenize.d.ts +47 -0
  188. package/build/tokenize.js +419 -0
  189. package/build/tokenize.js.map +1 -0
  190. package/build/vertical-gap.d.ts +17 -0
  191. package/build/vertical-gap.js +20 -0
  192. package/build/vertical-gap.js.map +1 -0
  193. package/build/worker/animation-controller.d.ts +72 -0
  194. package/build/worker/animation-controller.js +128 -0
  195. package/build/worker/animation-controller.js.map +1 -0
  196. package/build/worker/ansi-utils.d.ts +16 -0
  197. package/build/worker/ansi-utils.js +40 -0
  198. package/build/worker/ansi-utils.js.map +1 -0
  199. package/build/worker/canvas.d.ts +49 -0
  200. package/build/worker/canvas.js +90 -0
  201. package/build/worker/canvas.js.map +1 -0
  202. package/build/worker/compositor.d.ts +33 -0
  203. package/build/worker/compositor.js +308 -0
  204. package/build/worker/compositor.js.map +1 -0
  205. package/build/worker/platform.d.ts +15 -0
  206. package/build/worker/platform.js +19 -0
  207. package/build/worker/platform.js.map +1 -0
  208. package/build/worker/render-worker.d.ts +112 -0
  209. package/build/worker/render-worker.js +944 -0
  210. package/build/worker/render-worker.js.map +1 -0
  211. package/build/worker/scene-manager.d.ts +26 -0
  212. package/build/worker/scene-manager.js +109 -0
  213. package/build/worker/scene-manager.js.map +1 -0
  214. package/build/worker/scroll-optimizer.d.ts +32 -0
  215. package/build/worker/scroll-optimizer.js +110 -0
  216. package/build/worker/scroll-optimizer.js.map +1 -0
  217. package/build/worker/terminal-writer.d.ts +116 -0
  218. package/build/worker/terminal-writer.js +708 -0
  219. package/build/worker/terminal-writer.js.map +1 -0
  220. package/build/worker/worker-entry.d.ts +6 -0
  221. package/build/worker/worker-entry.js +130 -0
  222. package/build/worker/worker-entry.js.map +1 -0
  223. package/license +9 -0
  224. package/package.json +208 -0
  225. package/readme.md +2353 -0
@@ -0,0 +1,224 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { FULL_WIDTH_MASK } from './tokenize.js';
3
+ import { StyledLine } from './styled-line.js';
4
+ const hasStylesMask = 0b0000_0010;
5
+ const fullWidthMask = 0b0000_0001;
6
+ const isRepeatedCharMask = 0b0000_0100;
7
+ const isAsciiMixedMask = 0b0000_1000;
8
+ export class Serializer {
9
+ // eslint-disable-next-line @typescript-eslint/ban-types
10
+ buffer;
11
+ currentSize = 0;
12
+ constructor(initialSize = 1024 * 1024) {
13
+ this.buffer = Buffer.allocUnsafe(initialSize);
14
+ }
15
+ serialize(lines) {
16
+ this.currentSize = 0;
17
+ this.writeUint32(lines.length);
18
+ for (const line of lines) {
19
+ this.writeLine(line);
20
+ }
21
+ const result = Buffer.allocUnsafe(this.currentSize);
22
+ this.buffer.copy(result, 0, 0, this.currentSize);
23
+ return result;
24
+ }
25
+ ensureCapacity(size) {
26
+ if (this.currentSize + size > this.buffer.length) {
27
+ const newSize = Math.max(this.buffer.length * 2, this.currentSize + size + 1024 * 1024);
28
+ const newBuffer = Buffer.allocUnsafe(newSize);
29
+ this.buffer.copy(newBuffer, 0, 0, this.currentSize);
30
+ this.buffer = newBuffer;
31
+ }
32
+ }
33
+ writeLine(line) {
34
+ if (line.length === 0) {
35
+ this.writeUint32(0);
36
+ return;
37
+ }
38
+ const spans = line.getSpans();
39
+ this.writeUint32(spans.length);
40
+ let offset = 0;
41
+ for (const span of spans) {
42
+ this.writeSpan(line, span, offset);
43
+ offset += span.length;
44
+ }
45
+ }
46
+ writeSpan(line, span, start) {
47
+ this.writeUint32(span.length);
48
+ const end = start + span.length;
49
+ const firstVal = line.getValue(start);
50
+ const firstFullWidth = line.getFullWidth(start);
51
+ let isRepeatedChar = true;
52
+ let isAsciiMixed = true;
53
+ for (let i = start; i < end; i++) {
54
+ const val = line.getValue(i);
55
+ if (val !== firstVal || line.getFullWidth(i) !== firstFullWidth) {
56
+ isRepeatedChar = false;
57
+ }
58
+ if (line.getFullWidth(i) || val.length !== 1) {
59
+ isAsciiMixed = false;
60
+ }
61
+ }
62
+ let flags = 0;
63
+ // A span has styles if its format flags are anything but 0 (or just full-width)
64
+ // Or if it has colors.
65
+ const hasStyles = (span.formatFlags & ~FULL_WIDTH_MASK) !== 0 ||
66
+ span.fgColor ||
67
+ span.bgColor ||
68
+ span.link;
69
+ if (hasStyles) {
70
+ flags |= hasStylesMask;
71
+ }
72
+ if (isRepeatedChar) {
73
+ flags |= isRepeatedCharMask;
74
+ }
75
+ else if (isAsciiMixed) {
76
+ flags |= isAsciiMixedMask;
77
+ }
78
+ this.writeUint8(flags);
79
+ if (hasStyles) {
80
+ this.writeUint8(span.formatFlags);
81
+ this.writeString(span.fgColor || '');
82
+ this.writeString(span.bgColor || '');
83
+ this.writeString(span.link || '');
84
+ }
85
+ if (isRepeatedChar) {
86
+ let charFlags = 0;
87
+ if (firstFullWidth) {
88
+ charFlags |= fullWidthMask;
89
+ }
90
+ this.writeUint8(charFlags);
91
+ this.writeString(firstVal || '');
92
+ }
93
+ else if (isAsciiMixed) {
94
+ let concat = '';
95
+ for (let i = start; i < end; i++) {
96
+ concat += line.getValue(i);
97
+ }
98
+ this.writeString(concat);
99
+ }
100
+ else {
101
+ for (let i = start; i < end; i++) {
102
+ let charFlags = 0;
103
+ if (line.getFullWidth(i)) {
104
+ charFlags |= fullWidthMask;
105
+ }
106
+ this.writeUint8(charFlags);
107
+ this.writeString(line.getValue(i) || '');
108
+ }
109
+ }
110
+ }
111
+ writeString(str) {
112
+ const len = Buffer.byteLength(str);
113
+ this.ensureCapacity(2 + len);
114
+ this.buffer.writeUint16LE(len, this.currentSize);
115
+ this.currentSize += 2;
116
+ this.buffer.write(str, this.currentSize, len, 'utf8');
117
+ this.currentSize += len;
118
+ }
119
+ writeUint32(value) {
120
+ this.ensureCapacity(4);
121
+ this.buffer.writeUint32LE(value, this.currentSize);
122
+ this.currentSize += 4;
123
+ }
124
+ writeUint8(value) {
125
+ this.ensureCapacity(1);
126
+ this.buffer.writeUint8(value, this.currentSize);
127
+ this.currentSize += 1;
128
+ }
129
+ }
130
+ export class Deserializer {
131
+ offset = 0;
132
+ // eslint-disable-next-line @typescript-eslint/ban-types
133
+ buf;
134
+ constructor(buffer) {
135
+ this.buf = Buffer.isBuffer(buffer)
136
+ ? buffer
137
+ : Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
138
+ }
139
+ deserialize() {
140
+ const lineCount = this.readUint32();
141
+ const lines = [];
142
+ for (let i = 0; i < lineCount; i++) {
143
+ lines.push(this.readLine());
144
+ }
145
+ return lines;
146
+ }
147
+ readLine() {
148
+ const spanCount = this.readUint32();
149
+ const line = new StyledLine();
150
+ for (let i = 0; i < spanCount; i++) {
151
+ this.readSpan(line);
152
+ }
153
+ return line;
154
+ }
155
+ readSpan(line) {
156
+ const spanLength = this.readUint32();
157
+ const flags = this.readUint8();
158
+ const hasStyles = (flags & hasStylesMask) !== 0;
159
+ const isRepeatedChar = (flags & isRepeatedCharMask) !== 0;
160
+ const isAsciiMixed = (flags & isAsciiMixedMask) !== 0;
161
+ let formatFlags = 0;
162
+ let fgColor;
163
+ let bgColor;
164
+ let link;
165
+ if (hasStyles) {
166
+ formatFlags = this.readUint8();
167
+ fgColor = this.readString() || undefined;
168
+ bgColor = this.readString() || undefined;
169
+ link = this.readString() || undefined;
170
+ }
171
+ if (isRepeatedChar) {
172
+ const charFlags = this.readUint8();
173
+ const fullWidth = (charFlags & fullWidthMask) !== 0;
174
+ const value = this.readString();
175
+ let ff = formatFlags;
176
+ if (fullWidth)
177
+ ff |= FULL_WIDTH_MASK;
178
+ for (let i = 0; i < spanLength; i++) {
179
+ line.pushChar(value, ff, fgColor, bgColor, link);
180
+ }
181
+ }
182
+ else if (isAsciiMixed) {
183
+ const value = this.readString();
184
+ for (let i = 0; i < spanLength; i++) {
185
+ line.pushChar(value[i], formatFlags, fgColor, bgColor, link);
186
+ }
187
+ }
188
+ else {
189
+ for (let i = 0; i < spanLength; i++) {
190
+ const charFlags = this.readUint8();
191
+ const fullWidth = (charFlags & fullWidthMask) !== 0;
192
+ const value = this.readString();
193
+ let ff = formatFlags;
194
+ if (fullWidth)
195
+ ff |= FULL_WIDTH_MASK;
196
+ else
197
+ ff &= ~FULL_WIDTH_MASK;
198
+ line.pushChar(value, ff, fgColor, bgColor, link);
199
+ }
200
+ }
201
+ }
202
+ readString() {
203
+ const len = this.readUint16();
204
+ const str = this.buf.toString('utf8', this.offset, this.offset + len);
205
+ this.offset += len;
206
+ return str;
207
+ }
208
+ readUint32() {
209
+ const value = this.buf.readUint32LE(this.offset);
210
+ this.offset += 4;
211
+ return value;
212
+ }
213
+ readUint16() {
214
+ const value = this.buf.readUint16LE(this.offset);
215
+ this.offset += 2;
216
+ return value;
217
+ }
218
+ readUint8() {
219
+ const value = this.buf.readUint8(this.offset);
220
+ this.offset += 1;
221
+ return value;
222
+ }
223
+ }
224
+ //# sourceMappingURL=serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAiB,MAAM,kBAAkB,CAAC;AAE5D,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AACvC,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAErC,MAAM,OAAO,UAAU;IACtB,wDAAwD;IAChD,MAAM,CAAS;IACf,WAAW,GAAG,CAAC,CAAC;IAExB,YAAY,WAAW,GAAG,IAAI,GAAG,IAAI;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED,SAAS,CAAC,KAA4B;QACrC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB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CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;QACjB,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
@@ -0,0 +1,16 @@
1
+ import { type DOMElement } from './dom.js';
2
+ import { type CharOffsetMap } from './measure-text.js';
3
+ export type { CharOffsetMap, CharOffsetRange } from './measure-text.js';
4
+ declare const squashTextNodes: (node: DOMElement) => string;
5
+ /**
6
+ * Squash text nodes with character offset mapping.
7
+ * This variant builds a CharOffsetMap that tracks the character position
8
+ * of each DOM node within the squashed text, used for text selection.
9
+ *
10
+ * The character counting method matches getPositionAtOffset() in measure-text.ts,
11
+ * ensuring consistent cursor and selection position calculations.
12
+ */
13
+ export declare const squashTextNodesWithMap: (node: DOMElement, map: CharOffsetMap, offsetRef: {
14
+ current: number;
15
+ }) => string;
16
+ export default squashTextNodes;
@@ -0,0 +1,58 @@
1
+ // Squashing text nodes allows to combine multiple text nodes into one and write
2
+ // to `Output` instance only once. For example, <Text>hello{' '}world</Text>
3
+ // is actually 3 text nodes, which would result 3 writes to `Output`.
4
+ //
5
+ // Also, this is necessary for libraries like ink-link (https://github.com/sindresorhus/ink-link),
6
+ // which need to wrap all children at once, instead of wrapping 3 text nodes separately.
7
+ const squashTextNodes = (node) => {
8
+ const map = new Map();
9
+ const offsetRef = { current: 0 };
10
+ return squashTextNodesWithMap(node, map, offsetRef);
11
+ };
12
+ /**
13
+ * Squash text nodes with character offset mapping.
14
+ * This variant builds a CharOffsetMap that tracks the character position
15
+ * of each DOM node within the squashed text, used for text selection.
16
+ *
17
+ * The character counting method matches getPositionAtOffset() in measure-text.ts,
18
+ * ensuring consistent cursor and selection position calculations.
19
+ */
20
+ export const squashTextNodesWithMap = (node, map, offsetRef) => {
21
+ let text = '';
22
+ for (let index = 0; index < node.childNodes.length; index++) {
23
+ const childNode = node.childNodes[index];
24
+ if (childNode === undefined) {
25
+ continue;
26
+ }
27
+ let nodeText = '';
28
+ const startOffset = offsetRef.current;
29
+ if (childNode.nodeName === '#text') {
30
+ nodeText = childNode.nodeValue;
31
+ map.set(childNode, {
32
+ start: startOffset,
33
+ end: startOffset + nodeText.length,
34
+ });
35
+ offsetRef.current += nodeText.length;
36
+ }
37
+ else {
38
+ if (childNode.nodeName === 'ink-text' ||
39
+ childNode.nodeName === 'ink-virtual-text') {
40
+ nodeText = squashTextNodesWithMap(childNode, map, offsetRef);
41
+ map.set(childNode, {
42
+ start: startOffset,
43
+ end: offsetRef.current,
44
+ });
45
+ }
46
+ // Since these text nodes are being concatenated, `Output` instance won't be able to
47
+ // apply children transform, so we have to do it manually here for each text node
48
+ if (nodeText.length > 0 &&
49
+ typeof childNode.internal_transform === 'function') {
50
+ nodeText = childNode.internal_transform(nodeText, index);
51
+ }
52
+ }
53
+ text += nodeText;
54
+ }
55
+ return text;
56
+ };
57
+ export default squashTextNodes;
58
+ //# sourceMappingURL=squash-text-nodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"squash-text-nodes.js","sourceRoot":"","sources":["../src/squash-text-nodes.ts"],"names":[],"mappings":"AAKA,gFAAgF;AAChF,4EAA4E;AAC5E,qEAAqE;AACrE,EAAE;AACF,kGAAkG;AAClG,wFAAwF;AACxF,MAAM,eAAe,GAAG,CAAC,IAAgB,EAAU,EAAE;IACpD,MAAM,GAAG,GAAkB,IAAI,GAAG,EAAE,CAAC;IACrC,MAAM,SAAS,GAAG,EAAC,OAAO,EAAE,CAAC,EAAC,CAAC;IAE/B,OAAO,sBAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACrC,IAAgB,EAChB,GAAkB,EAClB,SAA4B,EACnB,EAAE;IACX,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,UA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0 +1,58 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export type StyleSpan = {
7
+ length: number;
8
+ formatFlags: number;
9
+ fgColor?: string;
10
+ bgColor?: string;
11
+ link?: string;
12
+ };
13
+ export declare class StyledLine {
14
+ static empty(length: number): StyledLine;
15
+ static legacyCreateStyledLine(values?: string[], spans?: StyleSpan[]): StyledLine;
16
+ private static readonly emptyCache;
17
+ length: number;
18
+ private text;
19
+ private charData;
20
+ private spans;
21
+ constructor();
22
+ getValue(index: number): string;
23
+ getSpan(index: number): StyleSpan | undefined;
24
+ getFullWidth(index: number): boolean;
25
+ hasStyles(index: number): boolean;
26
+ getFormatFlags(index: number): number;
27
+ getFgColor(index: number): string | undefined;
28
+ getBgColor(index: number): string | undefined;
29
+ getLink(index: number): string | undefined;
30
+ setInverted(index: number, inverted: boolean): void;
31
+ setBackgroundColor(index: number, color: string | undefined): void;
32
+ setForegroundColor(index: number, color: string | undefined): void;
33
+ setChar(index: number, value: string, formatFlags: number, fgColor?: string, bgColor?: string, link?: string): void;
34
+ pushChar(value: string, formatFlags: number, fgColor?: string, bgColor?: string, link?: string): void;
35
+ clone(): StyledLine;
36
+ slice(start: number, end?: number): StyledLine;
37
+ combine(...others: StyledLine[]): StyledLine;
38
+ getTrimmedLength(): number;
39
+ trimEnd(): StyledLine;
40
+ equals(other: StyledLine): boolean;
41
+ getText(): string;
42
+ getSpans(): StyleSpan[];
43
+ getValues(): string[];
44
+ [Symbol.iterator](): Generator<{
45
+ value: string;
46
+ formatFlags: number;
47
+ fgColor: string | undefined;
48
+ bgColor: string | undefined;
49
+ link: string | undefined;
50
+ fullWidth: boolean;
51
+ hasStyles: boolean;
52
+ }, void, unknown>;
53
+ private ensureInitialized;
54
+ private applyValuesAndSpans;
55
+ private instanceConcat;
56
+ private splitSpansAt;
57
+ private mergeSpans;
58
+ }