@claude-code-kit/ink-renderer 0.1.1 → 0.2.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 +115 -13
- package/dist/index.mjs +114 -12
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -80,9 +80,96 @@ var import_stream = require("stream");
|
|
|
80
80
|
// src/ink.tsx
|
|
81
81
|
var import_auto_bind = __toESM(require("auto-bind"));
|
|
82
82
|
var import_fs3 = require("fs");
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
|
|
84
|
+
// src/lodash-replacements.ts
|
|
85
|
+
function noop() {
|
|
86
|
+
}
|
|
87
|
+
function throttle(func, wait, options = {}) {
|
|
88
|
+
let timerId;
|
|
89
|
+
let lastCallTime;
|
|
90
|
+
let lastInvokeTime = 0;
|
|
91
|
+
let lastArgs;
|
|
92
|
+
let result;
|
|
93
|
+
const leading = options.leading !== false;
|
|
94
|
+
const trailing = options.trailing !== false;
|
|
95
|
+
function invokeFunc(time) {
|
|
96
|
+
lastInvokeTime = time;
|
|
97
|
+
const args = lastArgs;
|
|
98
|
+
lastArgs = void 0;
|
|
99
|
+
result = func(...args);
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
function startTimer(pendingFunc, remainingWait2) {
|
|
103
|
+
timerId = setTimeout(pendingFunc, remainingWait2);
|
|
104
|
+
}
|
|
105
|
+
function shouldInvoke(time) {
|
|
106
|
+
const timeSinceLastCall = lastCallTime === void 0 ? wait : time - lastCallTime;
|
|
107
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
108
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || timeSinceLastInvoke >= wait;
|
|
109
|
+
}
|
|
110
|
+
function remainingWait(time) {
|
|
111
|
+
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
112
|
+
return Math.max(0, wait - timeSinceLastCall);
|
|
113
|
+
}
|
|
114
|
+
function timerExpired() {
|
|
115
|
+
const time = Date.now();
|
|
116
|
+
if (shouldInvoke(time)) {
|
|
117
|
+
trailingEdge(time);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
startTimer(timerExpired, remainingWait(time));
|
|
121
|
+
}
|
|
122
|
+
function trailingEdge(time) {
|
|
123
|
+
timerId = void 0;
|
|
124
|
+
if (trailing && lastArgs) {
|
|
125
|
+
invokeFunc(time);
|
|
126
|
+
}
|
|
127
|
+
lastArgs = void 0;
|
|
128
|
+
}
|
|
129
|
+
function leadingEdge(time) {
|
|
130
|
+
lastInvokeTime = time;
|
|
131
|
+
startTimer(timerExpired, wait);
|
|
132
|
+
if (leading) {
|
|
133
|
+
invokeFunc(time);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const throttled = function(...args) {
|
|
137
|
+
const time = Date.now();
|
|
138
|
+
const isInvoking = shouldInvoke(time);
|
|
139
|
+
lastArgs = args;
|
|
140
|
+
lastCallTime = time;
|
|
141
|
+
if (isInvoking) {
|
|
142
|
+
if (timerId === void 0) {
|
|
143
|
+
leadingEdge(time);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (timerId === void 0) {
|
|
148
|
+
startTimer(timerExpired, wait);
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
throttled.cancel = function() {
|
|
153
|
+
if (timerId !== void 0) {
|
|
154
|
+
clearTimeout(timerId);
|
|
155
|
+
}
|
|
156
|
+
lastInvokeTime = 0;
|
|
157
|
+
lastArgs = void 0;
|
|
158
|
+
lastCallTime = void 0;
|
|
159
|
+
timerId = void 0;
|
|
160
|
+
};
|
|
161
|
+
throttled.flush = function() {
|
|
162
|
+
if (timerId === void 0) {
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
trailingEdge(Date.now());
|
|
166
|
+
return result;
|
|
167
|
+
};
|
|
168
|
+
return throttled;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/ink.tsx
|
|
172
|
+
var import_constants4 = require("react-reconciler/constants.js");
|
|
86
173
|
var import_signal_exit = require("signal-exit");
|
|
87
174
|
var import_yoga_layout3 = require("@claude-code-kit/shared/yoga-layout");
|
|
88
175
|
var import_shared13 = require("@claude-code-kit/shared");
|
|
@@ -172,6 +259,22 @@ var colorize = (str, color, type) => {
|
|
|
172
259
|
const thirdValue = Number(matches[3]);
|
|
173
260
|
return type === "foreground" ? import_chalk.default.rgb(firstValue, secondValue, thirdValue)(str) : import_chalk.default.bgRgb(firstValue, secondValue, thirdValue)(str);
|
|
174
261
|
}
|
|
262
|
+
const PLAIN_ANSI = {
|
|
263
|
+
black: type === "foreground" ? import_chalk.default.black : import_chalk.default.bgBlack,
|
|
264
|
+
red: type === "foreground" ? import_chalk.default.red : import_chalk.default.bgRed,
|
|
265
|
+
green: type === "foreground" ? import_chalk.default.green : import_chalk.default.bgGreen,
|
|
266
|
+
yellow: type === "foreground" ? import_chalk.default.yellow : import_chalk.default.bgYellow,
|
|
267
|
+
blue: type === "foreground" ? import_chalk.default.blue : import_chalk.default.bgBlue,
|
|
268
|
+
magenta: type === "foreground" ? import_chalk.default.magenta : import_chalk.default.bgMagenta,
|
|
269
|
+
cyan: type === "foreground" ? import_chalk.default.cyan : import_chalk.default.bgCyan,
|
|
270
|
+
white: type === "foreground" ? import_chalk.default.white : import_chalk.default.bgWhite,
|
|
271
|
+
gray: type === "foreground" ? import_chalk.default.gray : import_chalk.default.bgBlackBright,
|
|
272
|
+
grey: type === "foreground" ? import_chalk.default.gray : import_chalk.default.bgBlackBright
|
|
273
|
+
};
|
|
274
|
+
const fn = PLAIN_ANSI[color];
|
|
275
|
+
if (fn) {
|
|
276
|
+
return fn(str);
|
|
277
|
+
}
|
|
175
278
|
return str;
|
|
176
279
|
};
|
|
177
280
|
function applyTextStyles(text, styles2) {
|
|
@@ -2153,7 +2256,7 @@ function findOwnerChainAtRow(root, y) {
|
|
|
2153
2256
|
}
|
|
2154
2257
|
|
|
2155
2258
|
// src/events/dispatcher.ts
|
|
2156
|
-
var import_constants = require("react-reconciler/constants");
|
|
2259
|
+
var import_constants = require("react-reconciler/constants.js");
|
|
2157
2260
|
var import_shared3 = require("@claude-code-kit/shared");
|
|
2158
2261
|
|
|
2159
2262
|
// src/events/event-handlers.ts
|
|
@@ -7986,8 +8089,7 @@ function dropSubtreeCache(node) {
|
|
|
7986
8089
|
var render_node_to_output_default = renderNodeToOutput;
|
|
7987
8090
|
|
|
7988
8091
|
// src/render-to-screen.ts
|
|
7989
|
-
var
|
|
7990
|
-
var import_constants3 = require("react-reconciler/constants");
|
|
8092
|
+
var import_constants3 = require("react-reconciler/constants.js");
|
|
7991
8093
|
var import_shared11 = require("@claude-code-kit/shared");
|
|
7992
8094
|
var timing = { reconcile: 0, yoga: 0, paint: 0, scan: 0, calls: 0 };
|
|
7993
8095
|
function scanPositions(screen, query) {
|
|
@@ -8384,7 +8486,7 @@ var Ink = class {
|
|
|
8384
8486
|
stylePool: this.stylePool
|
|
8385
8487
|
});
|
|
8386
8488
|
const deferredRender = () => queueMicrotask(this.onRender);
|
|
8387
|
-
this.scheduleRender = (
|
|
8489
|
+
this.scheduleRender = throttle(deferredRender, FRAME_INTERVAL_MS, {
|
|
8388
8490
|
leading: true,
|
|
8389
8491
|
trailing: true
|
|
8390
8492
|
});
|
|
@@ -8430,13 +8532,13 @@ var Ink = class {
|
|
|
8430
8532
|
false,
|
|
8431
8533
|
null,
|
|
8432
8534
|
"id",
|
|
8433
|
-
|
|
8535
|
+
noop,
|
|
8434
8536
|
// onUncaughtError
|
|
8435
|
-
|
|
8537
|
+
noop,
|
|
8436
8538
|
// onCaughtError
|
|
8437
|
-
|
|
8539
|
+
noop,
|
|
8438
8540
|
// onRecoverableError
|
|
8439
|
-
|
|
8541
|
+
noop
|
|
8440
8542
|
// onDefaultTransitionIndicator
|
|
8441
8543
|
);
|
|
8442
8544
|
if (false) {
|
|
@@ -9227,7 +9329,7 @@ var Ink = class {
|
|
|
9227
9329
|
render(node) {
|
|
9228
9330
|
this.currentNode = node;
|
|
9229
9331
|
const tree = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(App, { stdin: this.options.stdin, stdout: this.options.stdout, stderr: this.options.stderr, exitOnCtrlC: this.options.exitOnCtrlC, onExit: this.unmount, terminalColumns: this.terminalColumns, terminalRows: this.terminalRows, selection: this.selection, onSelectionChange: this.notifySelectionChange, onClickAt: this.dispatchClick, onHoverAt: this.dispatchHover, getHyperlinkAt: this.getHyperlinkAt, onOpenHyperlink: this.openHyperlink, onMultiClick: this.handleMultiClick, onSelectionDrag: this.handleSelectionDrag, onStdinResume: this.reassertTerminalModes, onCursorDeclaration: this.setCursorDeclaration, dispatchKeyboardEvent: this.dispatchKeyboardEvent, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TerminalWriteProvider, { value: this.writeRaw, children: node }) });
|
|
9230
|
-
reconciler_default.updateContainerSync(tree, this.container, null,
|
|
9332
|
+
reconciler_default.updateContainerSync(tree, this.container, null, noop);
|
|
9231
9333
|
reconciler_default.flushSyncWork();
|
|
9232
9334
|
}
|
|
9233
9335
|
unmount(error) {
|
|
@@ -9263,7 +9365,7 @@ var Ink = class {
|
|
|
9263
9365
|
clearTimeout(this.drainTimer);
|
|
9264
9366
|
this.drainTimer = null;
|
|
9265
9367
|
}
|
|
9266
|
-
reconciler_default.updateContainerSync(null, this.container, null,
|
|
9368
|
+
reconciler_default.updateContainerSync(null, this.container, null, noop);
|
|
9267
9369
|
reconciler_default.flushSyncWork();
|
|
9268
9370
|
instances_default.delete(this.options.stdout);
|
|
9269
9371
|
this.rootNode.yogaNode?.free();
|
package/dist/index.mjs
CHANGED
|
@@ -5,9 +5,96 @@ import { Stream } from "stream";
|
|
|
5
5
|
// src/ink.tsx
|
|
6
6
|
import autoBind from "auto-bind";
|
|
7
7
|
import { closeSync, constants as fsConstants, openSync, readSync, writeSync } from "fs";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
|
|
9
|
+
// src/lodash-replacements.ts
|
|
10
|
+
function noop() {
|
|
11
|
+
}
|
|
12
|
+
function throttle(func, wait, options = {}) {
|
|
13
|
+
let timerId;
|
|
14
|
+
let lastCallTime;
|
|
15
|
+
let lastInvokeTime = 0;
|
|
16
|
+
let lastArgs;
|
|
17
|
+
let result;
|
|
18
|
+
const leading = options.leading !== false;
|
|
19
|
+
const trailing = options.trailing !== false;
|
|
20
|
+
function invokeFunc(time) {
|
|
21
|
+
lastInvokeTime = time;
|
|
22
|
+
const args = lastArgs;
|
|
23
|
+
lastArgs = void 0;
|
|
24
|
+
result = func(...args);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function startTimer(pendingFunc, remainingWait2) {
|
|
28
|
+
timerId = setTimeout(pendingFunc, remainingWait2);
|
|
29
|
+
}
|
|
30
|
+
function shouldInvoke(time) {
|
|
31
|
+
const timeSinceLastCall = lastCallTime === void 0 ? wait : time - lastCallTime;
|
|
32
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
33
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || timeSinceLastInvoke >= wait;
|
|
34
|
+
}
|
|
35
|
+
function remainingWait(time) {
|
|
36
|
+
const timeSinceLastCall = time - (lastCallTime ?? 0);
|
|
37
|
+
return Math.max(0, wait - timeSinceLastCall);
|
|
38
|
+
}
|
|
39
|
+
function timerExpired() {
|
|
40
|
+
const time = Date.now();
|
|
41
|
+
if (shouldInvoke(time)) {
|
|
42
|
+
trailingEdge(time);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
startTimer(timerExpired, remainingWait(time));
|
|
46
|
+
}
|
|
47
|
+
function trailingEdge(time) {
|
|
48
|
+
timerId = void 0;
|
|
49
|
+
if (trailing && lastArgs) {
|
|
50
|
+
invokeFunc(time);
|
|
51
|
+
}
|
|
52
|
+
lastArgs = void 0;
|
|
53
|
+
}
|
|
54
|
+
function leadingEdge(time) {
|
|
55
|
+
lastInvokeTime = time;
|
|
56
|
+
startTimer(timerExpired, wait);
|
|
57
|
+
if (leading) {
|
|
58
|
+
invokeFunc(time);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const throttled = function(...args) {
|
|
62
|
+
const time = Date.now();
|
|
63
|
+
const isInvoking = shouldInvoke(time);
|
|
64
|
+
lastArgs = args;
|
|
65
|
+
lastCallTime = time;
|
|
66
|
+
if (isInvoking) {
|
|
67
|
+
if (timerId === void 0) {
|
|
68
|
+
leadingEdge(time);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (timerId === void 0) {
|
|
73
|
+
startTimer(timerExpired, wait);
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
throttled.cancel = function() {
|
|
78
|
+
if (timerId !== void 0) {
|
|
79
|
+
clearTimeout(timerId);
|
|
80
|
+
}
|
|
81
|
+
lastInvokeTime = 0;
|
|
82
|
+
lastArgs = void 0;
|
|
83
|
+
lastCallTime = void 0;
|
|
84
|
+
timerId = void 0;
|
|
85
|
+
};
|
|
86
|
+
throttled.flush = function() {
|
|
87
|
+
if (timerId === void 0) {
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
trailingEdge(Date.now());
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
93
|
+
return throttled;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/ink.tsx
|
|
97
|
+
import { ConcurrentRoot } from "react-reconciler/constants.js";
|
|
11
98
|
import { onExit } from "signal-exit";
|
|
12
99
|
import { getYogaCounters as getYogaCounters2 } from "@claude-code-kit/shared/yoga-layout";
|
|
13
100
|
import { logForDebugging as logForDebugging7 } from "@claude-code-kit/shared";
|
|
@@ -97,6 +184,22 @@ var colorize = (str, color, type) => {
|
|
|
97
184
|
const thirdValue = Number(matches[3]);
|
|
98
185
|
return type === "foreground" ? chalk.rgb(firstValue, secondValue, thirdValue)(str) : chalk.bgRgb(firstValue, secondValue, thirdValue)(str);
|
|
99
186
|
}
|
|
187
|
+
const PLAIN_ANSI = {
|
|
188
|
+
black: type === "foreground" ? chalk.black : chalk.bgBlack,
|
|
189
|
+
red: type === "foreground" ? chalk.red : chalk.bgRed,
|
|
190
|
+
green: type === "foreground" ? chalk.green : chalk.bgGreen,
|
|
191
|
+
yellow: type === "foreground" ? chalk.yellow : chalk.bgYellow,
|
|
192
|
+
blue: type === "foreground" ? chalk.blue : chalk.bgBlue,
|
|
193
|
+
magenta: type === "foreground" ? chalk.magenta : chalk.bgMagenta,
|
|
194
|
+
cyan: type === "foreground" ? chalk.cyan : chalk.bgCyan,
|
|
195
|
+
white: type === "foreground" ? chalk.white : chalk.bgWhite,
|
|
196
|
+
gray: type === "foreground" ? chalk.gray : chalk.bgBlackBright,
|
|
197
|
+
grey: type === "foreground" ? chalk.gray : chalk.bgBlackBright
|
|
198
|
+
};
|
|
199
|
+
const fn = PLAIN_ANSI[color];
|
|
200
|
+
if (fn) {
|
|
201
|
+
return fn(str);
|
|
202
|
+
}
|
|
100
203
|
return str;
|
|
101
204
|
};
|
|
102
205
|
function applyTextStyles(text, styles2) {
|
|
@@ -2095,7 +2198,7 @@ import {
|
|
|
2095
2198
|
DefaultEventPriority,
|
|
2096
2199
|
DiscreteEventPriority,
|
|
2097
2200
|
NoEventPriority
|
|
2098
|
-
} from "react-reconciler/constants";
|
|
2201
|
+
} from "react-reconciler/constants.js";
|
|
2099
2202
|
import { logError } from "@claude-code-kit/shared";
|
|
2100
2203
|
|
|
2101
2204
|
// src/events/event-handlers.ts
|
|
@@ -7937,8 +8040,7 @@ function dropSubtreeCache(node) {
|
|
|
7937
8040
|
var render_node_to_output_default = renderNodeToOutput;
|
|
7938
8041
|
|
|
7939
8042
|
// src/render-to-screen.ts
|
|
7940
|
-
import
|
|
7941
|
-
import { LegacyRoot } from "react-reconciler/constants";
|
|
8043
|
+
import { LegacyRoot } from "react-reconciler/constants.js";
|
|
7942
8044
|
import { logForDebugging as logForDebugging5 } from "@claude-code-kit/shared";
|
|
7943
8045
|
var timing = { reconcile: 0, yoga: 0, paint: 0, scan: 0, calls: 0 };
|
|
7944
8046
|
function scanPositions(screen, query) {
|
|
@@ -8381,13 +8483,13 @@ var Ink = class {
|
|
|
8381
8483
|
false,
|
|
8382
8484
|
null,
|
|
8383
8485
|
"id",
|
|
8384
|
-
|
|
8486
|
+
noop,
|
|
8385
8487
|
// onUncaughtError
|
|
8386
|
-
|
|
8488
|
+
noop,
|
|
8387
8489
|
// onCaughtError
|
|
8388
|
-
|
|
8490
|
+
noop,
|
|
8389
8491
|
// onRecoverableError
|
|
8390
|
-
|
|
8492
|
+
noop
|
|
8391
8493
|
// onDefaultTransitionIndicator
|
|
8392
8494
|
);
|
|
8393
8495
|
if (false) {
|
|
@@ -9178,7 +9280,7 @@ var Ink = class {
|
|
|
9178
9280
|
render(node) {
|
|
9179
9281
|
this.currentNode = node;
|
|
9180
9282
|
const tree = /* @__PURE__ */ jsx7(App, { stdin: this.options.stdin, stdout: this.options.stdout, stderr: this.options.stderr, exitOnCtrlC: this.options.exitOnCtrlC, onExit: this.unmount, terminalColumns: this.terminalColumns, terminalRows: this.terminalRows, selection: this.selection, onSelectionChange: this.notifySelectionChange, onClickAt: this.dispatchClick, onHoverAt: this.dispatchHover, getHyperlinkAt: this.getHyperlinkAt, onOpenHyperlink: this.openHyperlink, onMultiClick: this.handleMultiClick, onSelectionDrag: this.handleSelectionDrag, onStdinResume: this.reassertTerminalModes, onCursorDeclaration: this.setCursorDeclaration, dispatchKeyboardEvent: this.dispatchKeyboardEvent, children: /* @__PURE__ */ jsx7(TerminalWriteProvider, { value: this.writeRaw, children: node }) });
|
|
9181
|
-
reconciler_default.updateContainerSync(tree, this.container, null,
|
|
9283
|
+
reconciler_default.updateContainerSync(tree, this.container, null, noop);
|
|
9182
9284
|
reconciler_default.flushSyncWork();
|
|
9183
9285
|
}
|
|
9184
9286
|
unmount(error) {
|
|
@@ -9214,7 +9316,7 @@ var Ink = class {
|
|
|
9214
9316
|
clearTimeout(this.drainTimer);
|
|
9215
9317
|
this.drainTimer = null;
|
|
9216
9318
|
}
|
|
9217
|
-
reconciler_default.updateContainerSync(null, this.container, null,
|
|
9319
|
+
reconciler_default.updateContainerSync(null, this.container, null, noop);
|
|
9218
9320
|
reconciler_default.flushSyncWork();
|
|
9219
9321
|
instances_default.delete(this.options.stdout);
|
|
9220
9322
|
this.rootNode.yogaNode?.free();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claude-code-kit/ink-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Terminal rendering engine extracted from Claude Code — React reconciler + Yoga layout + TTY output",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"emoji-regex": "*",
|
|
28
28
|
"get-east-asian-width": "*",
|
|
29
29
|
"indent-string": "*",
|
|
30
|
-
"lodash-es": "*",
|
|
31
30
|
"semver": "*",
|
|
32
31
|
"signal-exit": "*",
|
|
33
32
|
"stack-utils": "*",
|
|
@@ -36,7 +35,7 @@
|
|
|
36
35
|
"type-fest": "*",
|
|
37
36
|
"usehooks-ts": "*",
|
|
38
37
|
"wrap-ansi": "*",
|
|
39
|
-
"@claude-code-kit/shared": "0.
|
|
38
|
+
"@claude-code-kit/shared": "0.2.0"
|
|
40
39
|
},
|
|
41
40
|
"peerDependencies": {
|
|
42
41
|
"react": ">=18.0.0",
|
|
@@ -74,6 +73,6 @@
|
|
|
74
73
|
"scripts": {
|
|
75
74
|
"build": "tsup",
|
|
76
75
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
77
|
-
"lint": "
|
|
76
|
+
"lint": "biome check src/"
|
|
78
77
|
}
|
|
79
78
|
}
|