@linghun/ink-runtime 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Linghun contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,11 @@
1
+ export * from "ink";
2
+ export * from "./ink-styles.js";
3
+ export * from "./terminal-input.js";
4
+ export * from "./terminal-modes.js";
5
+ export * from "./terminal-selection.js";
6
+ export * from "./useTerminalInput.js";
7
+ export * from "./useWheelInput.js";
8
+ export * from "./useMouseInput.js";
9
+ export * from "./usePasteInput.js";
10
+ export * from "./useTerminalResponse.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,723 @@
1
+ // src/index.ts
2
+ export * from "ink";
3
+
4
+ // src/terminal-input.ts
5
+ var ESC = "\x1B";
6
+ var CSI = `${ESC}[`;
7
+ var OSC = `${ESC}]`;
8
+ var DCS = `${ESC}P`;
9
+ var ST = `${ESC}\\`;
10
+ var PASTE_START = `${CSI}200~`;
11
+ var PASTE_END = `${CSI}201~`;
12
+ var SGR_MOUSE_RE = /^\x1B\[<(\d+);(\d+);(\d+)([mM])/u;
13
+ var ORPHAN_SGR_MOUSE_RE = /^\[<(\d+);(\d+);(\d+)([mM])/u;
14
+ var SGR_MOUSE_FRAGMENT_RE = /^(?:\x1B\[<\d*(?:;\d*){0,2}|\[<\d*(?:;\d*){0,2}|<\d*(?:;\d*){0,2}|;\d+;\d+[mM]|\d+;\d+;\d+[mM])$/u;
15
+ var COMPLETE_MOUSE_TAIL_RE = /^(?:\d+;\d+;\d+[mM]|;\d+;\d+[mM])$/u;
16
+ var TerminalInputTokenizer = class {
17
+ buffer = "";
18
+ feed(chunk) {
19
+ if (!chunk) return [];
20
+ this.buffer += chunk;
21
+ const events = [];
22
+ while (this.buffer.length > 0) {
23
+ const parsed = parseNext(this.buffer, false);
24
+ if (parsed.status === "pending") break;
25
+ events.push(parsed.event);
26
+ this.buffer = this.buffer.slice(parsed.length);
27
+ }
28
+ return events;
29
+ }
30
+ flush() {
31
+ const events = [];
32
+ while (this.buffer.length > 0) {
33
+ const parsed = parseNext(this.buffer, true);
34
+ if (parsed.status === "pending") {
35
+ events.push({ kind: "key", input: this.buffer });
36
+ this.buffer = "";
37
+ break;
38
+ }
39
+ events.push(parsed.event);
40
+ this.buffer = this.buffer.slice(parsed.length);
41
+ }
42
+ return events;
43
+ }
44
+ };
45
+ function createTerminalInputTokenizer() {
46
+ return new TerminalInputTokenizer();
47
+ }
48
+ function parseTerminalInput(input) {
49
+ const tokenizer = createTerminalInputTokenizer();
50
+ return [...tokenizer.feed(input), ...tokenizer.flush()];
51
+ }
52
+ function classifyParsedTerminalInput(input) {
53
+ const events = parseTerminalInput(input);
54
+ if (events.length === 0) return "keyboard";
55
+ if (events.some((event) => event.kind === "paste")) return "paste";
56
+ if (events.some((event) => event.kind === "terminal-response")) return "terminal-response";
57
+ if (events.some((event) => event.kind === "mouse" || event.kind === "wheel" || event.kind === "mouse-fragment")) {
58
+ return "mouse";
59
+ }
60
+ if (events.some((event) => event.kind === "unknown-escape")) return "unknown-escape";
61
+ return "keyboard";
62
+ }
63
+ function parseNext(input, flush) {
64
+ const paste = parseBracketedPaste(input, flush);
65
+ if (paste) return paste;
66
+ const sgrMouse = parseSgrMouse(input);
67
+ if (sgrMouse) return sgrMouse;
68
+ const orphanMouse = parseOrphanSgrMouse(input);
69
+ if (orphanMouse) return orphanMouse;
70
+ const orphanFocus = parseOrphanFocusReport(input);
71
+ if (orphanFocus) return orphanFocus;
72
+ const x10Mouse = parseX10Mouse(input, flush);
73
+ if (x10Mouse) return x10Mouse;
74
+ const control = parseControlSequence(input, flush);
75
+ if (control) return control;
76
+ if (!flush && isPendingMouseFragment(input)) return { status: "pending" };
77
+ if (isMouseFragment(input)) {
78
+ return { status: "parsed", event: { kind: "mouse-fragment", raw: input }, length: input.length };
79
+ }
80
+ const escapeIndex = input.indexOf(ESC);
81
+ const length = escapeIndex <= 0 ? 1 : escapeIndex;
82
+ return { status: "parsed", event: { kind: "key", input: input.slice(0, length) }, length };
83
+ }
84
+ function parseBracketedPaste(input, flush) {
85
+ if (!input.startsWith(PASTE_START)) return void 0;
86
+ const end = input.indexOf(PASTE_END, PASTE_START.length);
87
+ if (end < 0) {
88
+ if (!flush) return { status: "pending" };
89
+ return { status: "parsed", event: { kind: "unknown-escape", raw: input }, length: input.length };
90
+ }
91
+ const raw = input.slice(0, end + PASTE_END.length);
92
+ return {
93
+ status: "parsed",
94
+ event: { kind: "paste", text: input.slice(PASTE_START.length, end), raw },
95
+ length: raw.length
96
+ };
97
+ }
98
+ function parseSgrMouse(input) {
99
+ const match = SGR_MOUSE_RE.exec(input);
100
+ if (!match) return void 0;
101
+ return mouseEventFromSgr(match, match[0]);
102
+ }
103
+ function parseOrphanSgrMouse(input) {
104
+ const match = ORPHAN_SGR_MOUSE_RE.exec(input);
105
+ if (!match) return void 0;
106
+ return mouseEventFromSgr(match, `${ESC}${match[0]}`);
107
+ }
108
+ function parseOrphanFocusReport(input) {
109
+ if (input !== "[I" && input !== "[O") return void 0;
110
+ const response = `${ESC}${input}`;
111
+ return { status: "parsed", event: { kind: "terminal-response", response, raw: input }, length: input.length };
112
+ }
113
+ function mouseEventFromSgr(match, raw) {
114
+ const code = Number.parseInt(match[1] ?? "0", 10);
115
+ const x = Number.parseInt(match[2] ?? "0", 10);
116
+ const y = Number.parseInt(match[3] ?? "0", 10);
117
+ const suffix = match[4] ?? "M";
118
+ if ((code & 64) === 64) {
119
+ return {
120
+ status: "parsed",
121
+ event: { kind: "wheel", direction: (code & 1) === 1 ? "down" : "up", raw, x, y },
122
+ length: match[0].length
123
+ };
124
+ }
125
+ return {
126
+ status: "parsed",
127
+ event: { kind: "mouse", action: actionFromMouseCode(code, suffix === "m"), button: code & 3, raw, x, y },
128
+ length: match[0].length
129
+ };
130
+ }
131
+ function parseX10Mouse(input, flush) {
132
+ if (!input.startsWith(`${ESC}[M`)) return void 0;
133
+ if (input.length < 6) return flush ? void 0 : { status: "pending" };
134
+ const code = input.charCodeAt(3) - 32;
135
+ const x = input.charCodeAt(4) - 32;
136
+ const y = input.charCodeAt(5) - 32;
137
+ const raw = input.slice(0, 6);
138
+ if ((code & 64) === 64) {
139
+ return {
140
+ status: "parsed",
141
+ event: { kind: "wheel", direction: (code & 1) === 1 ? "down" : "up", raw, x, y },
142
+ length: 6
143
+ };
144
+ }
145
+ return {
146
+ status: "parsed",
147
+ event: { kind: "mouse", action: actionFromMouseCode(code, (code & 3) === 3), button: code & 3, raw, x, y },
148
+ length: 6
149
+ };
150
+ }
151
+ function parseControlSequence(input, flush) {
152
+ if (input.startsWith(CSI)) return parseCsi(input, flush);
153
+ if (input.startsWith(OSC)) return parseStringControl(input, OSC.length, flush);
154
+ if (input.startsWith(DCS)) return parseStringControl(input, DCS.length, flush);
155
+ if (input.startsWith(`${ESC}O`)) return parseSs3(input, flush);
156
+ if (!input.startsWith(ESC)) return void 0;
157
+ if (input.length === 1 && !flush) return { status: "pending" };
158
+ return { status: "parsed", event: { kind: "unknown-escape", raw: input.slice(0, Math.min(2, input.length)) }, length: Math.min(2, input.length) };
159
+ }
160
+ function parseCsi(input, flush) {
161
+ const finalIndex = findCsiFinalIndex(input);
162
+ if (finalIndex < 0) return flush ? void 0 : { status: "pending" };
163
+ const raw = input.slice(0, finalIndex + 1);
164
+ if (isTerminalResponse(raw)) {
165
+ return { status: "parsed", event: { kind: "terminal-response", response: raw, raw }, length: raw.length };
166
+ }
167
+ return { status: "parsed", event: { kind: "key", input: raw }, length: raw.length };
168
+ }
169
+ function parseStringControl(input, prefixLength, flush) {
170
+ const belIndex = input.indexOf("\x07", prefixLength);
171
+ const stIndex = input.indexOf(ST, prefixLength);
172
+ const end = firstNonNegative(belIndex, stIndex);
173
+ if (end < 0) return flush ? void 0 : { status: "pending" };
174
+ const length = end + (end === stIndex ? ST.length : 1);
175
+ const raw = input.slice(0, length);
176
+ return { status: "parsed", event: { kind: "terminal-response", response: raw, raw }, length };
177
+ }
178
+ function parseSs3(input, flush) {
179
+ if (input.length < 3) return flush ? void 0 : { status: "pending" };
180
+ return { status: "parsed", event: { kind: "key", input: input.slice(0, 3) }, length: 3 };
181
+ }
182
+ function findCsiFinalIndex(input) {
183
+ for (let index = 2; index < input.length; index += 1) {
184
+ const code = input.charCodeAt(index);
185
+ if (code >= 64 && code <= 126) return index;
186
+ }
187
+ return -1;
188
+ }
189
+ function isTerminalResponse(raw) {
190
+ const body = raw.slice(2);
191
+ if (body === "I" || body === "O") return true;
192
+ if (/^\?\d+(?:;\d+)*[cn]$/u.test(body)) return true;
193
+ if (/^>\d+(?:;\d+)*c$/u.test(body)) return true;
194
+ if (/^\d+(?:;\d+)*R$/u.test(body)) return true;
195
+ if (/^\?\d+(?:;\d+)*\$y$/u.test(body)) return true;
196
+ return false;
197
+ }
198
+ function actionFromMouseCode(code, releaseSuffix) {
199
+ if (releaseSuffix) return "release";
200
+ if ((code & 32) === 32 && (code & 3) === 3) return "hover";
201
+ if ((code & 32) === 32) return "drag";
202
+ if ((code & 3) === 3) return "release";
203
+ return "press";
204
+ }
205
+ function isPendingMouseFragment(input) {
206
+ return input === ESC || input === `${ESC}[` || input === `${ESC}[<` || input === "[" || input === "[<" || SGR_MOUSE_FRAGMENT_RE.test(input);
207
+ }
208
+ function isMouseFragment(input) {
209
+ if (SGR_MOUSE_FRAGMENT_RE.test(input)) return true;
210
+ return COMPLETE_MOUSE_TAIL_RE.test(input);
211
+ }
212
+ function firstNonNegative(a, b) {
213
+ if (a < 0) return b;
214
+ if (b < 0) return a;
215
+ return Math.min(a, b);
216
+ }
217
+
218
+ // src/terminal-modes.ts
219
+ var ENABLE_MODIFY_OTHER_KEYS = "\x1B[>4;2m";
220
+ var DISABLE_MODIFY_OTHER_KEYS = "\x1B[>4m";
221
+ var ENABLE_KITTY_KEYBOARD = "\x1B[>1u";
222
+ var DISABLE_KITTY_KEYBOARD = "\x1B[<u";
223
+ var ENABLE_SGR_MOUSE = "\x1B[?1000h\x1B[?1002h\x1B[?1003h\x1B[?1006h";
224
+ var DISABLE_SGR_MOUSE = "\x1B[?1006l\x1B[?1003l\x1B[?1002l\x1B[?1000l";
225
+ var ENABLE_FOCUS_EVENTS = "\x1B[?1004h";
226
+ var DISABLE_FOCUS_EVENTS = "\x1B[?1004l";
227
+ var ENABLE_BRACKETED_PASTE = "\x1B[?2004h";
228
+ var DISABLE_BRACKETED_PASTE = "\x1B[?2004l";
229
+ function enableTerminalInteractionModes(stdout, modes) {
230
+ if (modes.kittyKeyboard) writeBestEffort(stdout, ENABLE_KITTY_KEYBOARD);
231
+ if (modes.modifyOtherKeys) writeBestEffort(stdout, ENABLE_MODIFY_OTHER_KEYS);
232
+ if (modes.mouseTracking) writeBestEffort(stdout, ENABLE_SGR_MOUSE);
233
+ if (modes.focusEvents) writeBestEffort(stdout, ENABLE_FOCUS_EVENTS);
234
+ if (modes.bracketedPaste) writeBestEffort(stdout, ENABLE_BRACKETED_PASTE);
235
+ }
236
+ function disableTerminalInteractionModes(stdout, modes) {
237
+ if (modes.bracketedPaste) writeBestEffort(stdout, DISABLE_BRACKETED_PASTE);
238
+ if (modes.focusEvents) writeBestEffort(stdout, DISABLE_FOCUS_EVENTS);
239
+ if (modes.mouseTracking) writeBestEffort(stdout, DISABLE_SGR_MOUSE);
240
+ if (modes.modifyOtherKeys) writeBestEffort(stdout, DISABLE_MODIFY_OTHER_KEYS);
241
+ if (modes.kittyKeyboard) writeBestEffort(stdout, DISABLE_KITTY_KEYBOARD);
242
+ }
243
+ function createTerminalInteractionSession(stdout, modes) {
244
+ let enabled = false;
245
+ return {
246
+ enable: () => {
247
+ enableTerminalInteractionModes(stdout, modes);
248
+ enabled = true;
249
+ },
250
+ disable: () => {
251
+ if (!enabled) return;
252
+ disableTerminalInteractionModes(stdout, modes);
253
+ enabled = false;
254
+ },
255
+ reassert: () => {
256
+ if (!enabled) return;
257
+ reassertTerminalInteractionModes(stdout, modes);
258
+ }
259
+ };
260
+ }
261
+ function bindTerminalInteractionSignals(target, session) {
262
+ let listeningForSuspend = false;
263
+ const listenForSuspend = () => {
264
+ if (target.platform === "win32" || listeningForSuspend) return;
265
+ target.on?.("SIGTSTP", suspend);
266
+ listeningForSuspend = true;
267
+ };
268
+ const stopListeningForSuspend = () => {
269
+ if (!listeningForSuspend) return;
270
+ target.off?.("SIGTSTP", suspend);
271
+ listeningForSuspend = false;
272
+ };
273
+ const suspend = () => {
274
+ session.disable();
275
+ stopListeningForSuspend();
276
+ if (typeof target.pid === "number") target.kill?.(target.pid, "SIGTSTP");
277
+ };
278
+ const resume = () => {
279
+ session.enable();
280
+ listenForSuspend();
281
+ };
282
+ listenForSuspend();
283
+ target.on?.("SIGCONT", resume);
284
+ return {
285
+ dispose: () => {
286
+ stopListeningForSuspend();
287
+ target.off?.("SIGCONT", resume);
288
+ },
289
+ suspend,
290
+ resume
291
+ };
292
+ }
293
+ function reassertTerminalInteractionModes(stdout, modes) {
294
+ enableTerminalInteractionModes(stdout, modes);
295
+ }
296
+ function writeBestEffort(stdout, text) {
297
+ try {
298
+ stdout?.write(text);
299
+ } catch {
300
+ }
301
+ }
302
+
303
+ // src/terminal-selection.ts
304
+ var EDGE_AUTOSCROLL_LINES = 2;
305
+ var MULTI_CLICK_TIMEOUT_MS = 500;
306
+ var LOST_RELEASE_TIMEOUT_MS = 5e3;
307
+ var SGR_MOUSE_RE2 = /^?\[<(\d+);(\d+);(\d+)([mM])$/u;
308
+ function parseTerminalSelectionMouseEvent(input) {
309
+ const match = input.match(SGR_MOUSE_RE2);
310
+ if (!match) return void 0;
311
+ const code = Number.parseInt(match[1] ?? "", 10);
312
+ const x = Number.parseInt(match[2] ?? "", 10);
313
+ const y = Number.parseInt(match[3] ?? "", 10);
314
+ const suffix = match[4];
315
+ if (!Number.isFinite(code) || !Number.isFinite(x) || !Number.isFinite(y)) return void 0;
316
+ const action = actionFromCode(code, suffix === "m");
317
+ return {
318
+ x: Math.max(0, x - 1),
319
+ y: Math.max(0, y - 1),
320
+ button: buttonFromCode(code),
321
+ action
322
+ };
323
+ }
324
+ function isTerminalSelectionMouseInput(input) {
325
+ return SGR_MOUSE_RE2.test(input);
326
+ }
327
+ function isTerminalSelectionStale(state, now) {
328
+ if (!state?.dragging || !state.lastClickTime) return false;
329
+ return now - state.lastClickTime > LOST_RELEASE_TIMEOUT_MS;
330
+ }
331
+ function reduceTerminalSelection(input) {
332
+ const { event, geometry, rows } = input;
333
+ const copyOnSelect = input.copyOnSelect !== false;
334
+ if (event.action === "focus-out") return finishLostRelease(input, copyOnSelect);
335
+ if (!geometry || rows.length === 0) return { state: input.state, consumed: false };
336
+ if (event.button !== "left" && event.button !== "wheel-up" && event.button !== "wheel-down") {
337
+ return { state: input.state, consumed: false };
338
+ }
339
+ if (event.action === "wheel") return { state: input.state, consumed: false };
340
+ if (event.action === "hover") return input.state?.dragging ? finishLostRelease(input, copyOnSelect) : { state: input.state, consumed: false };
341
+ if (!isInsideTranscript(event, geometry)) {
342
+ if (input.state?.dragging && (event.action === "drag" || event.action === "up")) {
343
+ return finishOrUpdateOutOfBoundsDrag(input, copyOnSelect);
344
+ }
345
+ return { state: input.state, consumed: false };
346
+ }
347
+ const point = pointFromMouse(event, geometry, rows);
348
+ const scrollDelta = event.action === "drag" && input.state?.dragging ? autoScrollDeltaForMouse(event.y, geometry, input.scroll) : 0;
349
+ if (event.action === "down") {
350
+ const now = input.now ?? Date.now();
351
+ const clickCount = detectClickCount(input.state, point, now);
352
+ const targetRow = rows[point.row];
353
+ const lostReleaseCopy = finishPreviousDragForFreshPress(input.state, rows, copyOnSelect);
354
+ if (clickCount === 2 && targetRow && !targetRow.noSelect) {
355
+ const bounds = wordBoundsAt(targetRow, point.column);
356
+ const anchor = { row: point.row, column: bounds.start };
357
+ const focus = { row: point.row, column: bounds.end };
358
+ const next2 = {
359
+ dragging: true,
360
+ anchor,
361
+ focus,
362
+ anchorMode: "word",
363
+ lastClickTime: now,
364
+ lastClickRow: point.row,
365
+ clickCount,
366
+ moved: true
367
+ };
368
+ return { state: withSelectedText(next2, rows), copyText: lostReleaseCopy, consumed: true };
369
+ }
370
+ if (clickCount === 3 && targetRow && !targetRow.noSelect) {
371
+ const anchor = { row: point.row, column: 0 };
372
+ const focus = { row: point.row, column: targetRow.cells.length };
373
+ const next2 = {
374
+ dragging: true,
375
+ anchor,
376
+ focus,
377
+ anchorMode: "line",
378
+ lastClickTime: now,
379
+ lastClickRow: point.row,
380
+ clickCount,
381
+ moved: true
382
+ };
383
+ return { state: withSelectedText(next2, rows), copyText: lostReleaseCopy, consumed: true };
384
+ }
385
+ const next = {
386
+ dragging: true,
387
+ anchor: point,
388
+ focus: point,
389
+ anchorMode: "char",
390
+ lastClickTime: now,
391
+ lastClickRow: point.row,
392
+ clickCount,
393
+ moved: false
394
+ };
395
+ return { state: withSelectedText(next, rows), copyText: lostReleaseCopy, consumed: true };
396
+ }
397
+ if (event.action === "drag") {
398
+ if (!input.state?.dragging || !input.state.anchor) return { state: input.state, consumed: true };
399
+ let adjustedFocus = point;
400
+ if (input.state.anchorMode === "word") {
401
+ const targetRow = rows[point.row];
402
+ if (targetRow && !targetRow.noSelect) {
403
+ const bounds = wordBoundsAt(targetRow, point.column);
404
+ adjustedFocus = { row: point.row, column: point.row >= input.state.anchor.row ? bounds.end : bounds.start };
405
+ }
406
+ } else if (input.state.anchorMode === "line") {
407
+ const targetRow = rows[point.row];
408
+ if (targetRow) {
409
+ adjustedFocus = { row: point.row, column: point.row >= input.state.anchor.row ? targetRow.cells.length : 0 };
410
+ }
411
+ }
412
+ const next = {
413
+ ...input.state,
414
+ dragging: true,
415
+ focus: adjustedFocus,
416
+ lastCopyError: void 0,
417
+ moved: input.state.moved || input.state.anchor.row !== adjustedFocus.row || input.state.anchor.column !== adjustedFocus.column
418
+ };
419
+ return {
420
+ state: withSelectedText(next, rows),
421
+ scrollDelta,
422
+ consumed: true
423
+ };
424
+ }
425
+ if (event.action === "up") {
426
+ if (!input.state?.dragging || !input.state.anchor) return { state: void 0, consumed: true };
427
+ const moved = input.state.moved || input.state.anchor.row !== point.row || input.state.anchor.column !== point.column;
428
+ const next = withSelectedText({ ...input.state, dragging: false, focus: point, moved }, rows);
429
+ return settleSelection(next, rows, copyOnSelect);
430
+ }
431
+ return { state: input.state, consumed: false };
432
+ }
433
+ function terminalSelectionContainsRow(selection, rowIndex) {
434
+ if (!selection?.anchor || !selection.focus) return false;
435
+ const range = orderedPoints(selection.anchor, selection.focus);
436
+ return rowIndex >= range.start.row && rowIndex <= range.end.row;
437
+ }
438
+ function terminalSelectionLineIndexesForBlock(selection, rows, blockId) {
439
+ if (!selection?.anchor || !selection.focus) return [];
440
+ const selected = /* @__PURE__ */ new Set();
441
+ for (const row of rows) {
442
+ if (row.blockId !== blockId || row.lineInBlock === void 0) continue;
443
+ if (row.noSelect) continue;
444
+ if (terminalSelectionContainsRow(selection, row.index)) selected.add(row.lineInBlock);
445
+ }
446
+ return [...selected].sort((a, b) => a - b);
447
+ }
448
+ function terminalSelectionLineRangesForBlock(selection, rows, blockId) {
449
+ if (!selection?.anchor || !selection.focus) return [];
450
+ const range = orderedPoints(selection.anchor, selection.focus);
451
+ const selectedRows = rows.slice(range.start.row, range.end.row + 1);
452
+ const ranges = [];
453
+ for (let index = 0; index < selectedRows.length; index++) {
454
+ const row = selectedRows[index];
455
+ if (!row || row.noSelect || row.blockId !== blockId || row.lineInBlock === void 0) continue;
456
+ const start = selectedRows.length === 1 || index === 0 ? Math.max(0, range.start.column) : 0;
457
+ const end = selectedRows.length === 1 || index === selectedRows.length - 1 ? Math.max(start, range.end.column) : row.cells.length;
458
+ if (end <= start) continue;
459
+ const sourceColumnStart = row.sourceColumnStart ?? 0;
460
+ ranges.push({
461
+ lineIndex: row.lineInBlock,
462
+ startColumn: sourceColumnStart + start,
463
+ endColumn: sourceColumnStart + Math.min(end, row.cells.length)
464
+ });
465
+ }
466
+ return ranges;
467
+ }
468
+ function terminalSelectedTextFromRows(rows, anchor, focus) {
469
+ const range = orderedPoints(anchor, focus);
470
+ const selected = rows.slice(range.start.row, range.end.row + 1);
471
+ if (selected.length === 0) return "";
472
+ const parts = [];
473
+ for (let index = 0; index < selected.length; index++) {
474
+ const row = selected[index];
475
+ if (!row || row.noSelect) continue;
476
+ const text = selected.length === 1 ? sliceRowCells(row, range.start.column, range.end.column) : index === 0 ? sliceRowCells(row, range.start.column, void 0) : index === selected.length - 1 ? sliceRowCells(row, 0, range.end.column) : selectableTextFromRow(row);
477
+ if (parts.length > 0 && !row.softWrapped) parts.push("\n");
478
+ parts.push(text);
479
+ }
480
+ return parts.join("");
481
+ }
482
+ function finishPreviousDragForFreshPress(state, rows, copyOnSelect) {
483
+ if (!copyOnSelect || !state?.dragging || !state.anchor) return void 0;
484
+ const finished = withSelectedText({ ...state, dragging: false }, rows);
485
+ return copyableText(finished);
486
+ }
487
+ function finishLostRelease(input, copyOnSelect) {
488
+ if (!input.state?.dragging || !input.state.anchor) return { state: input.state, consumed: false };
489
+ const next = withSelectedText({ ...input.state, dragging: false }, input.rows);
490
+ return settleSelection(next, input.rows, copyOnSelect);
491
+ }
492
+ function finishOrUpdateOutOfBoundsDrag(input, copyOnSelect) {
493
+ const { event, geometry, rows } = input;
494
+ if (!geometry || !input.state?.anchor || rows.length === 0) return { state: void 0, consumed: true };
495
+ const point = pointFromMouse(event, geometry, rows);
496
+ if (event.action === "drag") {
497
+ const next2 = withSelectedText({ ...input.state, dragging: true, focus: point, moved: true }, rows);
498
+ return {
499
+ state: next2,
500
+ scrollDelta: autoScrollDeltaForMouse(event.y, geometry, input.scroll),
501
+ consumed: true
502
+ };
503
+ }
504
+ const next = withSelectedText({ ...input.state, dragging: false, focus: point, moved: true }, rows);
505
+ return settleSelection(next, rows, copyOnSelect);
506
+ }
507
+ function settleSelection(next, rows, copyOnSelect) {
508
+ if (!copyOnSelect) return { state: next, consumed: true };
509
+ const copyText = copyableText(next);
510
+ if (!copyText) {
511
+ return {
512
+ state: {
513
+ dragging: false,
514
+ lastClickTime: next.lastClickTime,
515
+ lastClickRow: next.lastClickRow,
516
+ clickCount: next.clickCount
517
+ },
518
+ consumed: true
519
+ };
520
+ }
521
+ return {
522
+ state: { ...next, copiedText: copyText },
523
+ copyText,
524
+ consumed: true
525
+ };
526
+ }
527
+ function copyableText(state) {
528
+ if (state.anchorMode === "char" && !state.moved) return void 0;
529
+ const text = state.selectedText?.trimEnd();
530
+ if (!text || text.trim().length === 0) return void 0;
531
+ return text;
532
+ }
533
+ function detectClickCount(state, point, now) {
534
+ if (!state?.lastClickTime || state.lastClickRow === void 0) return 1;
535
+ if (now - state.lastClickTime > MULTI_CLICK_TIMEOUT_MS) return 1;
536
+ if (state.lastClickRow !== point.row) return 1;
537
+ return (state.clickCount ?? 1) % 3 + 1;
538
+ }
539
+ function wordBoundsAt(row, column) {
540
+ const cells = row.cells.length > 0 ? row.cells : cellsFromText(row.text, row.noSelect === true);
541
+ const col = Math.max(0, Math.min(column, cells.length - 1));
542
+ const charAtCol = cells[col]?.selectableText ?? " ";
543
+ const cls = charClass(charAtCol);
544
+ let start = col;
545
+ while (start > 0 && charClass(cells[start - 1]?.selectableText ?? " ") === cls) start--;
546
+ let end = col;
547
+ while (end < cells.length - 1 && charClass(cells[end + 1]?.selectableText ?? " ") === cls) end++;
548
+ return { start, end: end + 1 };
549
+ }
550
+ function charClass(ch) {
551
+ if (/\s/.test(ch)) return "ws";
552
+ if (/[\w一-鿿㐀-䶿豈-﫿]/.test(ch)) return "word";
553
+ return "punct";
554
+ }
555
+ function withSelectedText(state, rows) {
556
+ if (!state.anchor || !state.focus) return state;
557
+ return { ...state, selectedText: terminalSelectedTextFromRows(rows, state.anchor, state.focus) };
558
+ }
559
+ function orderedPoints(a, b) {
560
+ if (a.row < b.row) return { start: a, end: b };
561
+ if (a.row > b.row) return { start: b, end: a };
562
+ return a.column <= b.column ? { start: a, end: b } : { start: b, end: a };
563
+ }
564
+ function sliceRowCells(row, start, end) {
565
+ const cells = row.cells.length > 0 ? row.cells : cellsFromText(row.text, row.noSelect === true);
566
+ return cells.slice(Math.max(0, start), end === void 0 ? void 0 : Math.max(0, end)).map((cell) => cell.noSelect ? "" : cell.selectableText).join("");
567
+ }
568
+ function selectableTextFromRow(row) {
569
+ return sliceRowCells(row, 0, void 0);
570
+ }
571
+ function cellsFromText(text, noSelect) {
572
+ return Array.from(text).map((char) => ({ char, selectableText: noSelect ? "" : char, width: 1, noSelect }));
573
+ }
574
+ function pointFromMouse(event, geometry, rows) {
575
+ const visibleRow = clamp(Math.floor(event.y - geometry.y), 0, Math.max(0, geometry.height - 1));
576
+ const row = clamp(geometry.topOffset + visibleRow, 0, Math.max(0, rows.length - 1));
577
+ const column = clamp(
578
+ Math.floor(event.x - geometry.x),
579
+ 0,
580
+ rows[row]?.cells.length ?? Array.from(rows[row]?.text ?? "").length
581
+ );
582
+ return { row, column };
583
+ }
584
+ function autoScrollDeltaForMouse(y, geometry, scroll) {
585
+ const maxOffset = Math.max(0, geometry.contentHeight - geometry.height);
586
+ const current = scroll?.scrollOffset ?? 0;
587
+ if (y < geometry.y && current < maxOffset) return Math.min(EDGE_AUTOSCROLL_LINES, maxOffset - current);
588
+ if (y >= geometry.y + geometry.height && current > 0) return -Math.min(EDGE_AUTOSCROLL_LINES, current);
589
+ return 0;
590
+ }
591
+ function isInsideTranscript(event, geometry) {
592
+ return event.x >= geometry.x && event.x < geometry.x + geometry.width && event.y >= geometry.y && event.y < geometry.y + geometry.height;
593
+ }
594
+ function clamp(value, min, max) {
595
+ if (value < min) return min;
596
+ if (value > max) return max;
597
+ return value;
598
+ }
599
+ function buttonFromCode(code) {
600
+ if ((code & 64) === 64) return (code & 1) === 1 ? "wheel-down" : "wheel-up";
601
+ if ((code & 3) === 0 || (code & 3) === 3) return "left";
602
+ return "other";
603
+ }
604
+ function actionFromCode(code, releaseSuffix) {
605
+ if ((code & 64) === 64) return "wheel";
606
+ if ((code & 32) === 32 && (code & 3) === 3 && !releaseSuffix) return "hover";
607
+ if (releaseSuffix || (code & 3) === 3) return "up";
608
+ if ((code & 32) === 32) return "drag";
609
+ return "down";
610
+ }
611
+
612
+ // src/useTerminalInput.ts
613
+ import { useInput } from "ink";
614
+ import { useCallback, useRef } from "react";
615
+ function useTerminalInput(callback, options = {}) {
616
+ const { isActive = true } = options;
617
+ const callbackRef = useRef(callback);
618
+ callbackRef.current = callback;
619
+ useInput(
620
+ useCallback((input) => {
621
+ const events = parseTerminalInput(input);
622
+ for (const event of events) {
623
+ callbackRef.current(event);
624
+ }
625
+ }, []),
626
+ { isActive }
627
+ );
628
+ }
629
+
630
+ // src/useWheelInput.ts
631
+ import { useCallback as useCallback2, useRef as useRef2 } from "react";
632
+ function useWheelInput(callback, options = {}) {
633
+ const callbackRef = useRef2(callback);
634
+ callbackRef.current = callback;
635
+ useTerminalInput(
636
+ useCallback2((event) => {
637
+ if (event.kind === "wheel") {
638
+ callbackRef.current(event);
639
+ }
640
+ }, []),
641
+ options
642
+ );
643
+ }
644
+
645
+ // src/useMouseInput.ts
646
+ import { useCallback as useCallback3, useRef as useRef3 } from "react";
647
+ function useMouseInput(callback, options = {}) {
648
+ const callbackRef = useRef3(callback);
649
+ callbackRef.current = callback;
650
+ useTerminalInput(
651
+ useCallback3((event) => {
652
+ if (event.kind === "mouse") {
653
+ callbackRef.current(event);
654
+ }
655
+ }, []),
656
+ options
657
+ );
658
+ }
659
+
660
+ // src/usePasteInput.ts
661
+ import { useCallback as useCallback4, useRef as useRef4 } from "react";
662
+ function usePasteInput(callback, options = {}) {
663
+ const callbackRef = useRef4(callback);
664
+ callbackRef.current = callback;
665
+ useTerminalInput(
666
+ useCallback4((event) => {
667
+ if (event.kind === "paste") {
668
+ callbackRef.current(event);
669
+ }
670
+ }, []),
671
+ options
672
+ );
673
+ }
674
+
675
+ // src/useTerminalResponse.ts
676
+ import { useCallback as useCallback5, useRef as useRef5 } from "react";
677
+ function useTerminalResponse(callback, options = {}) {
678
+ const callbackRef = useRef5(callback);
679
+ callbackRef.current = callback;
680
+ useTerminalInput(
681
+ useCallback5((event) => {
682
+ if (event.kind === "terminal-response") {
683
+ callbackRef.current(event);
684
+ }
685
+ }, []),
686
+ options
687
+ );
688
+ }
689
+ export {
690
+ DISABLE_BRACKETED_PASTE,
691
+ DISABLE_FOCUS_EVENTS,
692
+ DISABLE_KITTY_KEYBOARD,
693
+ DISABLE_MODIFY_OTHER_KEYS,
694
+ DISABLE_SGR_MOUSE,
695
+ ENABLE_BRACKETED_PASTE,
696
+ ENABLE_FOCUS_EVENTS,
697
+ ENABLE_KITTY_KEYBOARD,
698
+ ENABLE_MODIFY_OTHER_KEYS,
699
+ ENABLE_SGR_MOUSE,
700
+ TerminalInputTokenizer,
701
+ bindTerminalInteractionSignals,
702
+ classifyParsedTerminalInput,
703
+ createTerminalInputTokenizer,
704
+ createTerminalInteractionSession,
705
+ disableTerminalInteractionModes,
706
+ enableTerminalInteractionModes,
707
+ isTerminalSelectionMouseInput,
708
+ isTerminalSelectionStale,
709
+ parseTerminalInput,
710
+ parseTerminalSelectionMouseEvent,
711
+ reassertTerminalInteractionModes,
712
+ reduceTerminalSelection,
713
+ terminalSelectedTextFromRows,
714
+ terminalSelectionContainsRow,
715
+ terminalSelectionLineIndexesForBlock,
716
+ terminalSelectionLineRangesForBlock,
717
+ useMouseInput,
718
+ usePasteInput,
719
+ useTerminalInput,
720
+ useTerminalResponse,
721
+ useWheelInput,
722
+ writeBestEffort
723
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @linghun/ink-runtime style extensions — CCB-compatible `opaque` support.
3
+ *
4
+ * `opaque` fills a Box's interior (padding included) with spaces before
5
+ * rendering children, so nothing behind it shows through. Like `backgroundColor`
6
+ * but without emitting SGR codes — the terminal's default background is used.
7
+ *
8
+ * Useful for absolute-positioned overlays where Box padding/gaps would
9
+ * otherwise be transparent.
10
+ *
11
+ * ## Implementation
12
+ *
13
+ * The open-source ink 7 renderer does not natively process `opaque`. When a
14
+ * Box has a `backgroundColor`, ink fills its interior with that color, which
15
+ * provides opacity automatically. For pure `opaque` (no color), set
16
+ * `backgroundColor` to the terminal's default background (typically undefined
17
+ * for dark terminals, "white" for light).
18
+ *
19
+ * `OpaqueBoxProps` extends the standard ink `BoxProps` with the `opaque` flag
20
+ * for type-safe use in components that consume this package.
21
+ */
22
+ import type { BoxProps } from "ink";
23
+ export type OpaqueBoxProps = BoxProps & {
24
+ /** Fill interior with spaces so nothing behind shows through. */
25
+ readonly opaque?: boolean;
26
+ };
27
+ //# sourceMappingURL=ink-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ink-styles.d.ts","sourceRoot":"","sources":["../src/ink-styles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG;IACtC,iEAAiE;IACjE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC"}
@@ -0,0 +1,41 @@
1
+ export type ParsedTerminalInput = {
2
+ kind: "key";
3
+ input: string;
4
+ } | {
5
+ kind: "wheel";
6
+ direction: "up" | "down";
7
+ raw: string;
8
+ x: number;
9
+ y: number;
10
+ } | {
11
+ kind: "mouse";
12
+ action: "press" | "drag" | "release" | "hover";
13
+ button: number;
14
+ x: number;
15
+ y: number;
16
+ raw: string;
17
+ } | {
18
+ kind: "paste";
19
+ text: string;
20
+ raw: string;
21
+ } | {
22
+ kind: "terminal-response";
23
+ response: string;
24
+ raw: string;
25
+ } | {
26
+ kind: "mouse-fragment";
27
+ raw: string;
28
+ } | {
29
+ kind: "unknown-escape";
30
+ raw: string;
31
+ };
32
+ export type InputClassification = "keyboard" | "mouse" | "paste" | "terminal-response" | "unknown-escape";
33
+ export declare class TerminalInputTokenizer {
34
+ private buffer;
35
+ feed(chunk: string): ParsedTerminalInput[];
36
+ flush(): ParsedTerminalInput[];
37
+ }
38
+ export declare function createTerminalInputTokenizer(): TerminalInputTokenizer;
39
+ export declare function parseTerminalInput(input: string): ParsedTerminalInput[];
40
+ export declare function classifyParsedTerminalInput(input: string): InputClassification;
41
+ //# sourceMappingURL=terminal-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal-input.d.ts","sourceRoot":"","sources":["../src/terminal-input.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9E;IACE,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;CACb,GACD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5C,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,mBAAmB,GAAG,gBAAgB,CAAC;AAc1G,qBAAa,sBAAsB;IACjC,OAAO,CAAC,MAAM,CAAM;IAEpB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,EAAE;IAe1C,KAAK,IAAI,mBAAmB,EAAE;CAc/B;AAED,wBAAgB,4BAA4B,IAAI,sBAAsB,CAErE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAGvE;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAU9E"}
@@ -0,0 +1,42 @@
1
+ import type { Writable } from "node:stream";
2
+ export declare const ENABLE_MODIFY_OTHER_KEYS = "\u001B[>4;2m";
3
+ export declare const DISABLE_MODIFY_OTHER_KEYS = "\u001B[>4m";
4
+ export declare const ENABLE_KITTY_KEYBOARD = "\u001B[>1u";
5
+ export declare const DISABLE_KITTY_KEYBOARD = "\u001B[<u";
6
+ export declare const ENABLE_SGR_MOUSE = "\u001B[?1000h\u001B[?1002h\u001B[?1003h\u001B[?1006h";
7
+ export declare const DISABLE_SGR_MOUSE = "\u001B[?1006l\u001B[?1003l\u001B[?1002l\u001B[?1000l";
8
+ export declare const ENABLE_FOCUS_EVENTS = "\u001B[?1004h";
9
+ export declare const DISABLE_FOCUS_EVENTS = "\u001B[?1004l";
10
+ export declare const ENABLE_BRACKETED_PASTE = "\u001B[?2004h";
11
+ export declare const DISABLE_BRACKETED_PASTE = "\u001B[?2004l";
12
+ export type TerminalInteractionModes = {
13
+ kittyKeyboard: boolean;
14
+ modifyOtherKeys: boolean;
15
+ mouseTracking: boolean;
16
+ focusEvents: boolean;
17
+ bracketedPaste: boolean;
18
+ };
19
+ export declare function enableTerminalInteractionModes(stdout: Writable | undefined, modes: TerminalInteractionModes): void;
20
+ export declare function disableTerminalInteractionModes(stdout: Writable | undefined, modes: TerminalInteractionModes): void;
21
+ export type TerminalInteractionSession = {
22
+ enable: () => void;
23
+ disable: () => void;
24
+ reassert: () => void;
25
+ };
26
+ export type TerminalInteractionSignalTarget = {
27
+ platform?: string;
28
+ pid?: number;
29
+ on?: (event: string, listener: () => void) => unknown;
30
+ off?: (event: string, listener: () => void) => unknown;
31
+ kill?: (pid: number, signal: string) => unknown;
32
+ };
33
+ export type TerminalInteractionSignalBinding = {
34
+ dispose: () => void;
35
+ suspend: () => void;
36
+ resume: () => void;
37
+ };
38
+ export declare function createTerminalInteractionSession(stdout: Writable | undefined, modes: TerminalInteractionModes): TerminalInteractionSession;
39
+ export declare function bindTerminalInteractionSignals(target: TerminalInteractionSignalTarget, session: TerminalInteractionSession): TerminalInteractionSignalBinding;
40
+ export declare function reassertTerminalInteractionModes(stdout: Writable | undefined, modes: TerminalInteractionModes): void;
41
+ export declare function writeBestEffort(stdout: Writable | undefined, text: string): void;
42
+ //# sourceMappingURL=terminal-modes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal-modes.d.ts","sourceRoot":"","sources":["../src/terminal-modes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,eAAO,MAAM,wBAAwB,iBAAe,CAAC;AACrD,eAAO,MAAM,yBAAyB,eAAa,CAAC;AACpD,eAAO,MAAM,qBAAqB,eAAa,CAAC;AAChD,eAAO,MAAM,sBAAsB,cAAY,CAAC;AAChD,eAAO,MAAM,gBAAgB,yDAAiD,CAAC;AAC/E,eAAO,MAAM,iBAAiB,yDAAiD,CAAC;AAChF,eAAO,MAAM,mBAAmB,kBAAgB,CAAC;AACjD,eAAO,MAAM,oBAAoB,kBAAgB,CAAC;AAClD,eAAO,MAAM,sBAAsB,kBAAgB,CAAC;AACpD,eAAO,MAAM,uBAAuB,kBAAgB,CAAC;AAErD,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,QAAQ,GAAG,SAAS,EAC5B,KAAK,EAAE,wBAAwB,GAC9B,IAAI,CAMN;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,QAAQ,GAAG,SAAS,EAC5B,KAAK,EAAE,wBAAwB,GAC9B,IAAI,CAMN;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,OAAO,CAAC;IACtD,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK,OAAO,CAAC;IACvD,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAEF,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,QAAQ,GAAG,SAAS,EAC5B,KAAK,EAAE,wBAAwB,GAC9B,0BAA0B,CAiB5B;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,+BAA+B,EACvC,OAAO,EAAE,0BAA0B,GAClC,gCAAgC,CAgClC;AAED,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,QAAQ,GAAG,SAAS,EAC5B,KAAK,EAAE,wBAAwB,GAC9B,IAAI,CAEN;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMhF"}
@@ -0,0 +1,83 @@
1
+ export type TerminalSelectionMouseButton = "left" | "wheel-up" | "wheel-down" | "other";
2
+ export type TerminalSelectionMouseAction = "down" | "drag" | "up" | "wheel" | "hover" | "focus-out";
3
+ export type TerminalSelectionMouseEvent = {
4
+ x: number;
5
+ y: number;
6
+ button: TerminalSelectionMouseButton;
7
+ action: TerminalSelectionMouseAction;
8
+ };
9
+ export type TerminalSelectionViewportGeometry = {
10
+ x: number;
11
+ y: number;
12
+ width: number;
13
+ height: number;
14
+ contentHeight: number;
15
+ topOffset: number;
16
+ };
17
+ export type TerminalSelectionCell = {
18
+ char: string;
19
+ selectableText: string;
20
+ width: number;
21
+ noSelect?: boolean;
22
+ };
23
+ export type TerminalSelectionTextRow = {
24
+ index: number;
25
+ blockId?: string;
26
+ lineInBlock?: number;
27
+ text: string;
28
+ cells: TerminalSelectionCell[];
29
+ sourceColumnStart?: number;
30
+ softWrapped?: boolean;
31
+ noSelect?: boolean;
32
+ };
33
+ export type TerminalSelectionPoint = {
34
+ row: number;
35
+ column: number;
36
+ };
37
+ export type TerminalSelectionState = {
38
+ dragging: boolean;
39
+ anchor?: TerminalSelectionPoint;
40
+ focus?: TerminalSelectionPoint;
41
+ selectedText?: string;
42
+ copiedText?: string;
43
+ lastCopyError?: string;
44
+ anchorMode?: "char" | "word" | "line";
45
+ lastClickTime?: number;
46
+ lastClickRow?: number;
47
+ clickCount?: number;
48
+ moved?: boolean;
49
+ };
50
+ export type TerminalSelectionInput = {
51
+ state: TerminalSelectionState | undefined;
52
+ event: TerminalSelectionMouseEvent;
53
+ rows: TerminalSelectionTextRow[];
54
+ geometry?: TerminalSelectionViewportGeometry;
55
+ scroll?: {
56
+ scrollOffset: number;
57
+ stickToBottom: boolean;
58
+ viewportHeight?: number;
59
+ contentHeight?: number;
60
+ };
61
+ copyOnSelect?: boolean;
62
+ now?: number;
63
+ };
64
+ export type TerminalSelectionResult = {
65
+ state: TerminalSelectionState | undefined;
66
+ copyText?: string;
67
+ scrollDelta?: number;
68
+ consumed: boolean;
69
+ };
70
+ export type TerminalSelectionLineRange = {
71
+ lineIndex: number;
72
+ startColumn: number;
73
+ endColumn: number;
74
+ };
75
+ export declare function parseTerminalSelectionMouseEvent(input: string): TerminalSelectionMouseEvent | undefined;
76
+ export declare function isTerminalSelectionMouseInput(input: string): boolean;
77
+ export declare function isTerminalSelectionStale(state: TerminalSelectionState | undefined, now: number): boolean;
78
+ export declare function reduceTerminalSelection(input: TerminalSelectionInput): TerminalSelectionResult;
79
+ export declare function terminalSelectionContainsRow(selection: TerminalSelectionState | undefined, rowIndex: number): boolean;
80
+ export declare function terminalSelectionLineIndexesForBlock(selection: TerminalSelectionState | undefined, rows: TerminalSelectionTextRow[], blockId: string): number[];
81
+ export declare function terminalSelectionLineRangesForBlock(selection: TerminalSelectionState | undefined, rows: TerminalSelectionTextRow[], blockId: string): TerminalSelectionLineRange[];
82
+ export declare function terminalSelectedTextFromRows(rows: TerminalSelectionTextRow[], anchor: TerminalSelectionPoint, focus: TerminalSelectionPoint): string;
83
+ //# sourceMappingURL=terminal-selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal-selection.d.ts","sourceRoot":"","sources":["../src/terminal-selection.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,18 @@
1
+ import type { ParsedTerminalInput } from "./terminal-input.js";
2
+ import { type UseTerminalInputOptions } from "./useTerminalInput.js";
3
+ /**
4
+ * Phase 7 — Mouse input hook.
5
+ *
6
+ * Subscribes to mouse events only (press/drag/release/hover).
7
+ * Wheel events are NOT delivered here — use useWheelInput for those.
8
+ * Mouse fragments are silently consumed (never leak to text handlers).
9
+ *
10
+ * @param callback - Receives structured mouse event
11
+ * @param options.isActive - Whether the hook is active (default: true)
12
+ */
13
+ export type MouseEvent = Extract<ParsedTerminalInput, {
14
+ kind: "mouse";
15
+ }>;
16
+ export type MouseInputHandler = (event: MouseEvent) => void;
17
+ export declare function useMouseInput(callback: MouseInputHandler, options?: UseTerminalInputOptions): void;
18
+ //# sourceMappingURL=useMouseInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMouseInput.d.ts","sourceRoot":"","sources":["../src/useMouseInput.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEvF;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACzE,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAE5D,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,uBAA4B,GACpC,IAAI,CAYN"}
@@ -0,0 +1,17 @@
1
+ import type { ParsedTerminalInput } from "./terminal-input.js";
2
+ import { type UseTerminalInputOptions } from "./useTerminalInput.js";
3
+ /**
4
+ * Phase 7 — Paste input hook.
5
+ *
6
+ * Subscribes to bracketed paste events only. Delivers the paste text
7
+ * (already extracted from bracketed paste markers).
8
+ *
9
+ * @param callback - Receives paste text
10
+ * @param options.isActive - Whether the hook is active (default: true)
11
+ */
12
+ export type PasteEvent = Extract<ParsedTerminalInput, {
13
+ kind: "paste";
14
+ }>;
15
+ export type PasteInputHandler = (event: PasteEvent) => void;
16
+ export declare function usePasteInput(callback: PasteInputHandler, options?: UseTerminalInputOptions): void;
17
+ //# sourceMappingURL=usePasteInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePasteInput.d.ts","sourceRoot":"","sources":["../src/usePasteInput.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEvF;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACzE,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAE5D,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,uBAA4B,GACpC,IAAI,CAYN"}
@@ -0,0 +1,20 @@
1
+ import { type ParsedTerminalInput } from "./terminal-input.js";
2
+ /**
3
+ * Phase 7 — Structured terminal input hook.
4
+ *
5
+ * Wraps stock Ink useInput and parses raw stdin through the runtime tokenizer,
6
+ * delivering structured ParsedTerminalInput events instead of raw strings.
7
+ *
8
+ * This is the runtime-owned entry point for all terminal input classification.
9
+ * App components should consume this (or the specialized hooks) instead of
10
+ * calling useInput + manual classification.
11
+ *
12
+ * @param callback - Receives each ParsedTerminalInput event
13
+ * @param options.isActive - Whether the hook is active (default: true)
14
+ */
15
+ export type TerminalInputHandler = (event: ParsedTerminalInput) => void;
16
+ export type UseTerminalInputOptions = {
17
+ isActive?: boolean;
18
+ };
19
+ export declare function useTerminalInput(callback: TerminalInputHandler, options?: UseTerminalInputOptions): void;
20
+ //# sourceMappingURL=useTerminalInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTerminalInput.d.ts","sourceRoot":"","sources":["../src/useTerminalInput.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEnF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;AAExE,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,oBAAoB,EAC9B,OAAO,GAAE,uBAA4B,GACpC,IAAI,CAcN"}
@@ -0,0 +1,17 @@
1
+ import type { ParsedTerminalInput } from "./terminal-input.js";
2
+ import { type UseTerminalInputOptions } from "./useTerminalInput.js";
3
+ /**
4
+ * Phase 7 — Terminal response hook.
5
+ *
6
+ * Subscribes to terminal response events only (DA1/DA2/DECRPM/cursor-position
7
+ * reports, OSC replies, DCS replies). These never reach text input handlers.
8
+ *
9
+ * @param callback - Receives terminal response event
10
+ * @param options.isActive - Whether the hook is active (default: true)
11
+ */
12
+ export type TerminalResponseEvent = Extract<ParsedTerminalInput, {
13
+ kind: "terminal-response";
14
+ }>;
15
+ export type TerminalResponseHandler = (event: TerminalResponseEvent) => void;
16
+ export declare function useTerminalResponse(callback: TerminalResponseHandler, options?: UseTerminalInputOptions): void;
17
+ //# sourceMappingURL=useTerminalResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTerminalResponse.d.ts","sourceRoot":"","sources":["../src/useTerminalResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEvF;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC,mBAAmB,EAAE;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAAC;AAChG,MAAM,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAE7E,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,uBAAuB,EACjC,OAAO,GAAE,uBAA4B,GACpC,IAAI,CAYN"}
@@ -0,0 +1,16 @@
1
+ import type { ParsedTerminalInput } from "./terminal-input.js";
2
+ import { type UseTerminalInputOptions } from "./useTerminalInput.js";
3
+ /**
4
+ * Phase 7 — Wheel input hook.
5
+ *
6
+ * Subscribes to wheel events only. All other event kinds are ignored.
7
+ *
8
+ * @param callback - Receives wheel direction and coordinates
9
+ * @param options.isActive - Whether the hook is active (default: true)
10
+ */
11
+ export type WheelEvent = Extract<ParsedTerminalInput, {
12
+ kind: "wheel";
13
+ }>;
14
+ export type WheelInputHandler = (event: WheelEvent) => void;
15
+ export declare function useWheelInput(callback: WheelInputHandler, options?: UseTerminalInputOptions): void;
16
+ //# sourceMappingURL=useWheelInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWheelInput.d.ts","sourceRoot":"","sources":["../src/useWheelInput.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEvF;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACzE,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAE5D,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,uBAA4B,GACpC,IAAI,CAYN"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@linghun/ink-runtime",
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "!dist/**/*.test.*",
17
+ "!dist/**/tsconfig.tsbuildinfo"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "ink": "^7.0.3"
24
+ },
25
+ "peerDependencies": {
26
+ "react": "^18.0.0 || ^19.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/react": "^19.2.15",
30
+ "react": "^19.2.6"
31
+ },
32
+ "scripts": {
33
+ "build": "tsup src/index.ts --format esm --clean --external react && tsc -p tsconfig.json --emitDeclarationOnly --noEmit false --tsBuildInfoFile dist/tsconfig.tsbuildinfo",
34
+ "typecheck": "tsc -p tsconfig.json --noEmit"
35
+ }
36
+ }