@gridland/web 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/dist/core.d.ts +535 -0
- package/dist/core.js +2736 -0
- package/dist/core.js.map +1 -0
- package/dist/index.d.ts +557 -0
- package/dist/index.js +2737 -0
- package/dist/index.js.map +1 -0
- package/dist/next-plugin.cjs +147 -0
- package/dist/next-plugin.cjs.map +1 -0
- package/dist/next-plugin.d.cts +22 -0
- package/dist/next-plugin.d.ts +22 -0
- package/dist/next-plugin.js +112 -0
- package/dist/next-plugin.js.map +1 -0
- package/dist/next.d.ts +337 -0
- package/dist/next.js +2596 -0
- package/dist/next.js.map +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +21 -0
- package/dist/utils.js.map +1 -0
- package/dist/vite-plugin.d.ts +15 -0
- package/dist/vite-plugin.js +192 -0
- package/dist/vite-plugin.js.map +1 -0
- package/package.json +70 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2737 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
7
|
+
}) : x)(function(x) {
|
|
8
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
+
});
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
24
|
+
|
|
25
|
+
// src/TUI.tsx
|
|
26
|
+
import {
|
|
27
|
+
useRef,
|
|
28
|
+
useEffect,
|
|
29
|
+
useState
|
|
30
|
+
} from "react";
|
|
31
|
+
|
|
32
|
+
// src/core-shims/index.ts
|
|
33
|
+
var core_shims_exports = {};
|
|
34
|
+
__export(core_shims_exports, {
|
|
35
|
+
ATTRIBUTE_BASE_BITS: () => ATTRIBUTE_BASE_BITS,
|
|
36
|
+
ATTRIBUTE_BASE_MASK: () => ATTRIBUTE_BASE_MASK,
|
|
37
|
+
BaseRenderable: () => BaseRenderable,
|
|
38
|
+
BorderCharArrays: () => BorderCharArrays,
|
|
39
|
+
BorderChars: () => BorderChars,
|
|
40
|
+
CliRenderEvents: () => CliRenderEvents,
|
|
41
|
+
CliRenderer: () => CliRenderer,
|
|
42
|
+
DebugOverlayCorner: () => DebugOverlayCorner,
|
|
43
|
+
InternalKeyHandler: () => BrowserInternalKeyHandler,
|
|
44
|
+
KeyHandler: () => BrowserKeyHandler,
|
|
45
|
+
LayoutEvents: () => LayoutEvents,
|
|
46
|
+
OptimizedBuffer: () => BrowserBuffer,
|
|
47
|
+
RGBA: () => RGBA,
|
|
48
|
+
Renderable: () => Renderable,
|
|
49
|
+
RenderableEvents: () => RenderableEvents,
|
|
50
|
+
RootRenderable: () => RootRenderable,
|
|
51
|
+
Selection: () => Selection,
|
|
52
|
+
StyledText: () => StyledText,
|
|
53
|
+
SyntaxStyle: () => BrowserSyntaxStyle,
|
|
54
|
+
TextAttributes: () => TextAttributes,
|
|
55
|
+
TextBuffer: () => BrowserTextBuffer,
|
|
56
|
+
TextBufferView: () => BrowserTextBufferView,
|
|
57
|
+
Timeline: () => Timeline,
|
|
58
|
+
Yoga: () => Yoga,
|
|
59
|
+
attributesWithLink: () => attributesWithLink,
|
|
60
|
+
bg: () => bg,
|
|
61
|
+
black: () => black,
|
|
62
|
+
blink: () => blink,
|
|
63
|
+
blue: () => blue,
|
|
64
|
+
bold: () => bold,
|
|
65
|
+
borderCharsToArray: () => borderCharsToArray,
|
|
66
|
+
convertGlobalToLocalSelection: () => convertGlobalToLocalSelection,
|
|
67
|
+
createCliRenderer: () => createCliRenderer,
|
|
68
|
+
createTextAttributes: () => createTextAttributes,
|
|
69
|
+
createTimeline: () => createTimeline,
|
|
70
|
+
cyan: () => cyan,
|
|
71
|
+
dim: () => dim,
|
|
72
|
+
engine: () => engine,
|
|
73
|
+
fg: () => fg,
|
|
74
|
+
getBaseAttributes: () => getBaseAttributes,
|
|
75
|
+
getBorderFromSides: () => getBorderFromSides,
|
|
76
|
+
getBorderSides: () => getBorderSides,
|
|
77
|
+
getLinkId: () => getLinkId,
|
|
78
|
+
green: () => green,
|
|
79
|
+
hexToRgb: () => hexToRgb,
|
|
80
|
+
hsvToRgb: () => hsvToRgb,
|
|
81
|
+
isDimensionType: () => isDimensionType,
|
|
82
|
+
isFlexBasisType: () => isFlexBasisType,
|
|
83
|
+
isMarginType: () => isMarginType,
|
|
84
|
+
isOverflowType: () => isOverflowType,
|
|
85
|
+
isPaddingType: () => isPaddingType,
|
|
86
|
+
isPositionType: () => isPositionType,
|
|
87
|
+
isPositionTypeType: () => isPositionTypeType,
|
|
88
|
+
isRenderable: () => isRenderable,
|
|
89
|
+
isSizeType: () => isSizeType,
|
|
90
|
+
isStyledText: () => isStyledText,
|
|
91
|
+
isValidBorderStyle: () => isValidBorderStyle,
|
|
92
|
+
italic: () => italic,
|
|
93
|
+
magenta: () => magenta,
|
|
94
|
+
maybeMakeRenderable: () => maybeMakeRenderable,
|
|
95
|
+
parseAlign: () => parseAlign,
|
|
96
|
+
parseAlignItems: () => parseAlignItems,
|
|
97
|
+
parseBorderStyle: () => parseBorderStyle,
|
|
98
|
+
parseColor: () => parseColor,
|
|
99
|
+
parseFlexDirection: () => parseFlexDirection,
|
|
100
|
+
parseJustify: () => parseJustify,
|
|
101
|
+
parseOverflow: () => parseOverflow,
|
|
102
|
+
parsePositionType: () => parsePositionType,
|
|
103
|
+
parseWrap: () => parseWrap,
|
|
104
|
+
red: () => red,
|
|
105
|
+
resolveRenderLib: () => resolveRenderLib,
|
|
106
|
+
reverse: () => reverse,
|
|
107
|
+
rgbToHex: () => rgbToHex,
|
|
108
|
+
strikethrough: () => strikethrough,
|
|
109
|
+
stringToStyledText: () => stringToStyledText,
|
|
110
|
+
t: () => t,
|
|
111
|
+
underline: () => underline,
|
|
112
|
+
validateOptions: () => validateOptions,
|
|
113
|
+
visualizeRenderableTree: () => visualizeRenderableTree,
|
|
114
|
+
white: () => white,
|
|
115
|
+
yellow: () => yellow
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// src/core-shims/rgba.ts
|
|
119
|
+
var RGBA = class _RGBA {
|
|
120
|
+
buffer;
|
|
121
|
+
constructor(buffer) {
|
|
122
|
+
this.buffer = buffer;
|
|
123
|
+
}
|
|
124
|
+
static fromArray(array) {
|
|
125
|
+
return new _RGBA(array);
|
|
126
|
+
}
|
|
127
|
+
static fromValues(r, g, b, a = 1) {
|
|
128
|
+
return new _RGBA(new Float32Array([r, g, b, a]));
|
|
129
|
+
}
|
|
130
|
+
static fromInts(r, g, b, a = 255) {
|
|
131
|
+
return new _RGBA(new Float32Array([r / 255, g / 255, b / 255, a / 255]));
|
|
132
|
+
}
|
|
133
|
+
static fromHex(hex) {
|
|
134
|
+
return hexToRgb(hex);
|
|
135
|
+
}
|
|
136
|
+
get r() {
|
|
137
|
+
return this.buffer[0];
|
|
138
|
+
}
|
|
139
|
+
set r(v) {
|
|
140
|
+
this.buffer[0] = v;
|
|
141
|
+
}
|
|
142
|
+
get g() {
|
|
143
|
+
return this.buffer[1];
|
|
144
|
+
}
|
|
145
|
+
set g(v) {
|
|
146
|
+
this.buffer[1] = v;
|
|
147
|
+
}
|
|
148
|
+
get b() {
|
|
149
|
+
return this.buffer[2];
|
|
150
|
+
}
|
|
151
|
+
set b(v) {
|
|
152
|
+
this.buffer[2] = v;
|
|
153
|
+
}
|
|
154
|
+
get a() {
|
|
155
|
+
return this.buffer[3];
|
|
156
|
+
}
|
|
157
|
+
set a(v) {
|
|
158
|
+
this.buffer[3] = v;
|
|
159
|
+
}
|
|
160
|
+
toInts() {
|
|
161
|
+
return [
|
|
162
|
+
Math.round(this.buffer[0] * 255),
|
|
163
|
+
Math.round(this.buffer[1] * 255),
|
|
164
|
+
Math.round(this.buffer[2] * 255),
|
|
165
|
+
Math.round(this.buffer[3] * 255)
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
map(fn) {
|
|
169
|
+
return [fn(this.buffer[0]), fn(this.buffer[1]), fn(this.buffer[2]), fn(this.buffer[3])];
|
|
170
|
+
}
|
|
171
|
+
toString() {
|
|
172
|
+
const [r, g, b, a] = this.toInts();
|
|
173
|
+
return `rgba(${r}, ${g}, ${b}, ${a / 255})`;
|
|
174
|
+
}
|
|
175
|
+
equals(other) {
|
|
176
|
+
if (!other) return false;
|
|
177
|
+
return this.buffer[0] === other.buffer[0] && this.buffer[1] === other.buffer[1] && this.buffer[2] === other.buffer[2] && this.buffer[3] === other.buffer[3];
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var CSS_COLOR_NAMES = {
|
|
181
|
+
black: "#000000",
|
|
182
|
+
white: "#ffffff",
|
|
183
|
+
red: "#ff0000",
|
|
184
|
+
green: "#008000",
|
|
185
|
+
blue: "#0000ff",
|
|
186
|
+
yellow: "#ffff00",
|
|
187
|
+
cyan: "#00ffff",
|
|
188
|
+
magenta: "#ff00ff",
|
|
189
|
+
silver: "#c0c0c0",
|
|
190
|
+
gray: "#808080",
|
|
191
|
+
grey: "#808080",
|
|
192
|
+
maroon: "#800000",
|
|
193
|
+
olive: "#808000",
|
|
194
|
+
lime: "#00ff00",
|
|
195
|
+
aqua: "#00ffff",
|
|
196
|
+
teal: "#008080",
|
|
197
|
+
navy: "#000080",
|
|
198
|
+
fuchsia: "#ff00ff",
|
|
199
|
+
purple: "#800080",
|
|
200
|
+
orange: "#ffa500",
|
|
201
|
+
transparent: "#00000000",
|
|
202
|
+
brightblack: "#808080",
|
|
203
|
+
brightred: "#ff5555",
|
|
204
|
+
brightgreen: "#55ff55",
|
|
205
|
+
brightyellow: "#ffff55",
|
|
206
|
+
brightblue: "#5555ff",
|
|
207
|
+
brightmagenta: "#ff55ff",
|
|
208
|
+
brightcyan: "#55ffff",
|
|
209
|
+
brightwhite: "#ffffff"
|
|
210
|
+
};
|
|
211
|
+
function hexToRgb(hex) {
|
|
212
|
+
hex = hex.replace(/^#/, "");
|
|
213
|
+
if (hex.length === 3) {
|
|
214
|
+
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
215
|
+
}
|
|
216
|
+
if (hex.length === 6) {
|
|
217
|
+
hex = hex + "ff";
|
|
218
|
+
}
|
|
219
|
+
const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
220
|
+
const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
221
|
+
const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
222
|
+
const a = parseInt(hex.substring(6, 8), 16) / 255;
|
|
223
|
+
return RGBA.fromValues(r, g, b, a);
|
|
224
|
+
}
|
|
225
|
+
function rgbToHex(rgb) {
|
|
226
|
+
const [r, g, b] = rgb.toInts();
|
|
227
|
+
return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
228
|
+
}
|
|
229
|
+
function hsvToRgb(h, s, v) {
|
|
230
|
+
const c = v * s;
|
|
231
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
232
|
+
const m = v - c;
|
|
233
|
+
let r = 0, g = 0, b = 0;
|
|
234
|
+
if (h < 60) {
|
|
235
|
+
r = c;
|
|
236
|
+
g = x;
|
|
237
|
+
b = 0;
|
|
238
|
+
} else if (h < 120) {
|
|
239
|
+
r = x;
|
|
240
|
+
g = c;
|
|
241
|
+
b = 0;
|
|
242
|
+
} else if (h < 180) {
|
|
243
|
+
r = 0;
|
|
244
|
+
g = c;
|
|
245
|
+
b = x;
|
|
246
|
+
} else if (h < 240) {
|
|
247
|
+
r = 0;
|
|
248
|
+
g = x;
|
|
249
|
+
b = c;
|
|
250
|
+
} else if (h < 300) {
|
|
251
|
+
r = x;
|
|
252
|
+
g = 0;
|
|
253
|
+
b = c;
|
|
254
|
+
} else {
|
|
255
|
+
r = c;
|
|
256
|
+
g = 0;
|
|
257
|
+
b = x;
|
|
258
|
+
}
|
|
259
|
+
return RGBA.fromValues(r + m, g + m, b + m, 1);
|
|
260
|
+
}
|
|
261
|
+
function parseColor(color) {
|
|
262
|
+
if (color instanceof RGBA) return color;
|
|
263
|
+
if (typeof color !== "string") return RGBA.fromValues(1, 1, 1, 1);
|
|
264
|
+
const lower = color.toLowerCase().trim();
|
|
265
|
+
if (CSS_COLOR_NAMES[lower]) {
|
|
266
|
+
return hexToRgb(CSS_COLOR_NAMES[lower]);
|
|
267
|
+
}
|
|
268
|
+
if (lower.startsWith("#")) {
|
|
269
|
+
return hexToRgb(lower);
|
|
270
|
+
}
|
|
271
|
+
const rgbaMatch = lower.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/);
|
|
272
|
+
if (rgbaMatch) {
|
|
273
|
+
return RGBA.fromInts(
|
|
274
|
+
parseInt(rgbaMatch[1]),
|
|
275
|
+
parseInt(rgbaMatch[2]),
|
|
276
|
+
parseInt(rgbaMatch[3]),
|
|
277
|
+
rgbaMatch[4] ? Math.round(parseFloat(rgbaMatch[4]) * 255) : 255
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return RGBA.fromValues(1, 1, 1, 1);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/core-shims/types.ts
|
|
284
|
+
var TextAttributes = {
|
|
285
|
+
NONE: 0,
|
|
286
|
+
BOLD: 1 << 0,
|
|
287
|
+
DIM: 1 << 1,
|
|
288
|
+
ITALIC: 1 << 2,
|
|
289
|
+
UNDERLINE: 1 << 3,
|
|
290
|
+
BLINK: 1 << 4,
|
|
291
|
+
INVERSE: 1 << 5,
|
|
292
|
+
HIDDEN: 1 << 6,
|
|
293
|
+
STRIKETHROUGH: 1 << 7
|
|
294
|
+
};
|
|
295
|
+
var ATTRIBUTE_BASE_BITS = 8;
|
|
296
|
+
var ATTRIBUTE_BASE_MASK = 255;
|
|
297
|
+
function getBaseAttributes(attr) {
|
|
298
|
+
return attr & 255;
|
|
299
|
+
}
|
|
300
|
+
var DebugOverlayCorner = /* @__PURE__ */ ((DebugOverlayCorner2) => {
|
|
301
|
+
DebugOverlayCorner2[DebugOverlayCorner2["topLeft"] = 0] = "topLeft";
|
|
302
|
+
DebugOverlayCorner2[DebugOverlayCorner2["topRight"] = 1] = "topRight";
|
|
303
|
+
DebugOverlayCorner2[DebugOverlayCorner2["bottomLeft"] = 2] = "bottomLeft";
|
|
304
|
+
DebugOverlayCorner2[DebugOverlayCorner2["bottomRight"] = 3] = "bottomRight";
|
|
305
|
+
return DebugOverlayCorner2;
|
|
306
|
+
})(DebugOverlayCorner || {});
|
|
307
|
+
|
|
308
|
+
// src/core-shims/index.ts
|
|
309
|
+
__reExport(core_shims_exports, Box_star);
|
|
310
|
+
__reExport(core_shims_exports, Text_star);
|
|
311
|
+
__reExport(core_shims_exports, TextNode_star);
|
|
312
|
+
__reExport(core_shims_exports, Code_star);
|
|
313
|
+
__reExport(core_shims_exports, Diff_star);
|
|
314
|
+
__reExport(core_shims_exports, Input_star);
|
|
315
|
+
__reExport(core_shims_exports, Select_star);
|
|
316
|
+
__reExport(core_shims_exports, TabSelect_star);
|
|
317
|
+
__reExport(core_shims_exports, Textarea_star);
|
|
318
|
+
__reExport(core_shims_exports, ScrollBox_star);
|
|
319
|
+
__reExport(core_shims_exports, ScrollBar_star);
|
|
320
|
+
__reExport(core_shims_exports, Slider_star);
|
|
321
|
+
__reExport(core_shims_exports, ASCIIFont_star);
|
|
322
|
+
__reExport(core_shims_exports, LineNumberRenderable_star);
|
|
323
|
+
__reExport(core_shims_exports, Markdown_star);
|
|
324
|
+
__reExport(core_shims_exports, FrameBuffer_star);
|
|
325
|
+
__reExport(core_shims_exports, TextBufferRenderable_star);
|
|
326
|
+
import {
|
|
327
|
+
Renderable,
|
|
328
|
+
BaseRenderable,
|
|
329
|
+
RootRenderable,
|
|
330
|
+
LayoutEvents,
|
|
331
|
+
RenderableEvents,
|
|
332
|
+
isRenderable
|
|
333
|
+
} from "../../../../opentui/packages/core/src/Renderable";
|
|
334
|
+
import {
|
|
335
|
+
BorderChars,
|
|
336
|
+
BorderCharArrays,
|
|
337
|
+
isValidBorderStyle,
|
|
338
|
+
parseBorderStyle,
|
|
339
|
+
getBorderFromSides,
|
|
340
|
+
getBorderSides,
|
|
341
|
+
borderCharsToArray
|
|
342
|
+
} from "../../../../opentui/packages/core/src/lib/border";
|
|
343
|
+
import {
|
|
344
|
+
StyledText,
|
|
345
|
+
isStyledText,
|
|
346
|
+
stringToStyledText,
|
|
347
|
+
t,
|
|
348
|
+
bold,
|
|
349
|
+
italic,
|
|
350
|
+
underline,
|
|
351
|
+
strikethrough,
|
|
352
|
+
dim,
|
|
353
|
+
reverse,
|
|
354
|
+
blink,
|
|
355
|
+
fg,
|
|
356
|
+
bg,
|
|
357
|
+
black,
|
|
358
|
+
red,
|
|
359
|
+
green,
|
|
360
|
+
yellow,
|
|
361
|
+
blue,
|
|
362
|
+
magenta,
|
|
363
|
+
cyan,
|
|
364
|
+
white
|
|
365
|
+
} from "../../../../opentui/packages/core/src/lib/styled-text";
|
|
366
|
+
import {
|
|
367
|
+
parseAlign,
|
|
368
|
+
parseAlignItems,
|
|
369
|
+
parseFlexDirection,
|
|
370
|
+
parseJustify,
|
|
371
|
+
parseOverflow,
|
|
372
|
+
parsePositionType,
|
|
373
|
+
parseWrap
|
|
374
|
+
} from "../../../../opentui/packages/core/src/lib/yoga.options";
|
|
375
|
+
import {
|
|
376
|
+
validateOptions,
|
|
377
|
+
isPositionType,
|
|
378
|
+
isDimensionType,
|
|
379
|
+
isFlexBasisType,
|
|
380
|
+
isSizeType,
|
|
381
|
+
isMarginType,
|
|
382
|
+
isPaddingType,
|
|
383
|
+
isPositionTypeType,
|
|
384
|
+
isOverflowType
|
|
385
|
+
} from "../../../../opentui/packages/core/src/lib/renderable.validations";
|
|
386
|
+
import {
|
|
387
|
+
Selection,
|
|
388
|
+
convertGlobalToLocalSelection
|
|
389
|
+
} from "../../../../opentui/packages/core/src/lib/selection";
|
|
390
|
+
import { maybeMakeRenderable } from "../../../../opentui/packages/core/src/renderables/composition/vnode";
|
|
391
|
+
import * as Box_star from "../../../../opentui/packages/core/src/renderables/Box";
|
|
392
|
+
import * as Text_star from "../../../../opentui/packages/core/src/renderables/Text";
|
|
393
|
+
import * as TextNode_star from "../../../../opentui/packages/core/src/renderables/TextNode";
|
|
394
|
+
import * as Code_star from "../../../../opentui/packages/core/src/renderables/Code";
|
|
395
|
+
import * as Diff_star from "../../../../opentui/packages/core/src/renderables/Diff";
|
|
396
|
+
import * as Input_star from "../../../../opentui/packages/core/src/renderables/Input";
|
|
397
|
+
import * as Select_star from "../../../../opentui/packages/core/src/renderables/Select";
|
|
398
|
+
import * as TabSelect_star from "../../../../opentui/packages/core/src/renderables/TabSelect";
|
|
399
|
+
import * as Textarea_star from "../../../../opentui/packages/core/src/renderables/Textarea";
|
|
400
|
+
import * as ScrollBox_star from "../../../../opentui/packages/core/src/renderables/ScrollBox";
|
|
401
|
+
import * as ScrollBar_star from "../../../../opentui/packages/core/src/renderables/ScrollBar";
|
|
402
|
+
import * as Slider_star from "../../../../opentui/packages/core/src/renderables/Slider";
|
|
403
|
+
import * as ASCIIFont_star from "../../../../opentui/packages/core/src/renderables/ASCIIFont";
|
|
404
|
+
import * as LineNumberRenderable_star from "../../../../opentui/packages/core/src/renderables/LineNumberRenderable";
|
|
405
|
+
import * as Markdown_star from "../../../../opentui/packages/core/src/renderables/Markdown";
|
|
406
|
+
import * as FrameBuffer_star from "../../../../opentui/packages/core/src/renderables/FrameBuffer";
|
|
407
|
+
import * as TextBufferRenderable_star from "../../../../opentui/packages/core/src/renderables/TextBufferRenderable";
|
|
408
|
+
|
|
409
|
+
// src/browser-text-buffer.ts
|
|
410
|
+
var BrowserTextBuffer = class _BrowserTextBuffer {
|
|
411
|
+
_text = "";
|
|
412
|
+
_chunks = [];
|
|
413
|
+
_defaultFg = null;
|
|
414
|
+
_defaultBg = null;
|
|
415
|
+
_defaultAttributes = 0;
|
|
416
|
+
_syntaxStyle = null;
|
|
417
|
+
_tabWidth = 4;
|
|
418
|
+
_widthMethod;
|
|
419
|
+
constructor(widthMethod) {
|
|
420
|
+
this._widthMethod = widthMethod;
|
|
421
|
+
}
|
|
422
|
+
static create(widthMethod) {
|
|
423
|
+
return new _BrowserTextBuffer(widthMethod);
|
|
424
|
+
}
|
|
425
|
+
// Compat property
|
|
426
|
+
get ptr() {
|
|
427
|
+
return 1;
|
|
428
|
+
}
|
|
429
|
+
get length() {
|
|
430
|
+
return this._text.length;
|
|
431
|
+
}
|
|
432
|
+
get byteSize() {
|
|
433
|
+
return new TextEncoder().encode(this._text).length;
|
|
434
|
+
}
|
|
435
|
+
setText(text) {
|
|
436
|
+
this._text = text;
|
|
437
|
+
this._chunks = [
|
|
438
|
+
{
|
|
439
|
+
__isChunk: true,
|
|
440
|
+
text,
|
|
441
|
+
fg: this._defaultFg ?? void 0,
|
|
442
|
+
bg: this._defaultBg ?? void 0,
|
|
443
|
+
attributes: this._defaultAttributes
|
|
444
|
+
}
|
|
445
|
+
];
|
|
446
|
+
}
|
|
447
|
+
append(text) {
|
|
448
|
+
this._text += text;
|
|
449
|
+
this._chunks.push({
|
|
450
|
+
__isChunk: true,
|
|
451
|
+
text,
|
|
452
|
+
fg: this._defaultFg ?? void 0,
|
|
453
|
+
bg: this._defaultBg ?? void 0,
|
|
454
|
+
attributes: this._defaultAttributes
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
setStyledText(styledText) {
|
|
458
|
+
this._chunks = styledText.chunks.map((chunk) => ({
|
|
459
|
+
__isChunk: true,
|
|
460
|
+
text: chunk.text,
|
|
461
|
+
fg: chunk.fg ?? this._defaultFg ?? void 0,
|
|
462
|
+
bg: chunk.bg ?? this._defaultBg ?? void 0,
|
|
463
|
+
attributes: chunk.attributes ?? this._defaultAttributes,
|
|
464
|
+
link: chunk.link
|
|
465
|
+
}));
|
|
466
|
+
this._text = this._chunks.map((c) => c.text).join("");
|
|
467
|
+
}
|
|
468
|
+
getPlainText() {
|
|
469
|
+
return this._text;
|
|
470
|
+
}
|
|
471
|
+
getTextRange(startOffset, endOffset) {
|
|
472
|
+
return this._text.slice(startOffset, endOffset);
|
|
473
|
+
}
|
|
474
|
+
getLineCount() {
|
|
475
|
+
if (this._text.length === 0) return 0;
|
|
476
|
+
return this._text.split("\n").length;
|
|
477
|
+
}
|
|
478
|
+
getChunks() {
|
|
479
|
+
return this._chunks;
|
|
480
|
+
}
|
|
481
|
+
setDefaultFg(fg2) {
|
|
482
|
+
this._defaultFg = fg2;
|
|
483
|
+
}
|
|
484
|
+
setDefaultBg(bg2) {
|
|
485
|
+
this._defaultBg = bg2;
|
|
486
|
+
}
|
|
487
|
+
setDefaultAttributes(attributes) {
|
|
488
|
+
this._defaultAttributes = attributes ?? 0;
|
|
489
|
+
}
|
|
490
|
+
resetDefaults() {
|
|
491
|
+
this._defaultFg = null;
|
|
492
|
+
this._defaultBg = null;
|
|
493
|
+
this._defaultAttributes = 0;
|
|
494
|
+
}
|
|
495
|
+
get defaultFg() {
|
|
496
|
+
return this._defaultFg;
|
|
497
|
+
}
|
|
498
|
+
get defaultBg() {
|
|
499
|
+
return this._defaultBg;
|
|
500
|
+
}
|
|
501
|
+
get defaultAttributes() {
|
|
502
|
+
return this._defaultAttributes;
|
|
503
|
+
}
|
|
504
|
+
setSyntaxStyle(style) {
|
|
505
|
+
this._syntaxStyle = style;
|
|
506
|
+
}
|
|
507
|
+
getSyntaxStyle() {
|
|
508
|
+
return this._syntaxStyle;
|
|
509
|
+
}
|
|
510
|
+
setTabWidth(width) {
|
|
511
|
+
this._tabWidth = width;
|
|
512
|
+
}
|
|
513
|
+
getTabWidth() {
|
|
514
|
+
return this._tabWidth;
|
|
515
|
+
}
|
|
516
|
+
addHighlightByCharRange(_highlight) {
|
|
517
|
+
}
|
|
518
|
+
addHighlight(_lineIdx, _highlight) {
|
|
519
|
+
}
|
|
520
|
+
removeHighlightsByRef(_hlRef) {
|
|
521
|
+
}
|
|
522
|
+
clearLineHighlights(_lineIdx) {
|
|
523
|
+
}
|
|
524
|
+
clearAllHighlights() {
|
|
525
|
+
}
|
|
526
|
+
getLineHighlights(_lineIdx) {
|
|
527
|
+
return [];
|
|
528
|
+
}
|
|
529
|
+
getHighlightCount() {
|
|
530
|
+
return 0;
|
|
531
|
+
}
|
|
532
|
+
loadFile(_path) {
|
|
533
|
+
}
|
|
534
|
+
clear() {
|
|
535
|
+
this._text = "";
|
|
536
|
+
this._chunks = [];
|
|
537
|
+
}
|
|
538
|
+
reset() {
|
|
539
|
+
this.clear();
|
|
540
|
+
this.resetDefaults();
|
|
541
|
+
}
|
|
542
|
+
destroy() {
|
|
543
|
+
this._text = "";
|
|
544
|
+
this._chunks = [];
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// src/browser-text-buffer-view.ts
|
|
549
|
+
var defaultFg = {
|
|
550
|
+
r: 1,
|
|
551
|
+
g: 1,
|
|
552
|
+
b: 1,
|
|
553
|
+
a: 1,
|
|
554
|
+
buffer: new Float32Array([1, 1, 1, 1])
|
|
555
|
+
};
|
|
556
|
+
var defaultBg = {
|
|
557
|
+
r: 0,
|
|
558
|
+
g: 0,
|
|
559
|
+
b: 0,
|
|
560
|
+
a: 0,
|
|
561
|
+
buffer: new Float32Array([0, 0, 0, 0])
|
|
562
|
+
};
|
|
563
|
+
var BrowserTextBufferView = class _BrowserTextBufferView {
|
|
564
|
+
textBuffer;
|
|
565
|
+
_wrapWidth = null;
|
|
566
|
+
_wrapMode = "word";
|
|
567
|
+
_viewportX = 0;
|
|
568
|
+
_viewportY = 0;
|
|
569
|
+
_viewportWidth = 0;
|
|
570
|
+
_viewportHeight = 0;
|
|
571
|
+
_truncate = false;
|
|
572
|
+
_selection = null;
|
|
573
|
+
_selectionBg;
|
|
574
|
+
_selectionFg;
|
|
575
|
+
constructor(textBuffer) {
|
|
576
|
+
this.textBuffer = textBuffer;
|
|
577
|
+
}
|
|
578
|
+
static create(textBuffer) {
|
|
579
|
+
return new _BrowserTextBufferView(textBuffer);
|
|
580
|
+
}
|
|
581
|
+
// Compat
|
|
582
|
+
get ptr() {
|
|
583
|
+
return 1;
|
|
584
|
+
}
|
|
585
|
+
get lineInfo() {
|
|
586
|
+
const lines = this.getAllWrappedLines();
|
|
587
|
+
const lineStarts = [];
|
|
588
|
+
const lineWidths = [];
|
|
589
|
+
const lineSources = [];
|
|
590
|
+
const lineWraps = [];
|
|
591
|
+
let maxWidth = 0;
|
|
592
|
+
let offset = 0;
|
|
593
|
+
for (let i = 0; i < lines.length; i++) {
|
|
594
|
+
lineStarts.push(offset);
|
|
595
|
+
const lineText = lines[i].map((c) => c.text).join("");
|
|
596
|
+
const w = lineText.length;
|
|
597
|
+
lineWidths.push(w);
|
|
598
|
+
lineSources.push(0);
|
|
599
|
+
lineWraps.push(0);
|
|
600
|
+
if (w > maxWidth) maxWidth = w;
|
|
601
|
+
offset += lineText.length + 1;
|
|
602
|
+
}
|
|
603
|
+
return { lineStarts, lineWidths, maxLineWidth: maxWidth, lineSources, lineWraps };
|
|
604
|
+
}
|
|
605
|
+
get logicalLineInfo() {
|
|
606
|
+
return this.lineInfo;
|
|
607
|
+
}
|
|
608
|
+
setSelection(start, end, bgColor, fgColor) {
|
|
609
|
+
this._selection = { start, end };
|
|
610
|
+
this._selectionBg = bgColor;
|
|
611
|
+
this._selectionFg = fgColor;
|
|
612
|
+
}
|
|
613
|
+
updateSelection(end, bgColor, fgColor) {
|
|
614
|
+
if (this._selection) {
|
|
615
|
+
this._selection.end = end;
|
|
616
|
+
}
|
|
617
|
+
if (bgColor) this._selectionBg = bgColor;
|
|
618
|
+
if (fgColor) this._selectionFg = fgColor;
|
|
619
|
+
}
|
|
620
|
+
resetSelection() {
|
|
621
|
+
this._selection = null;
|
|
622
|
+
}
|
|
623
|
+
getSelection() {
|
|
624
|
+
return this._selection;
|
|
625
|
+
}
|
|
626
|
+
hasSelection() {
|
|
627
|
+
return this._selection !== null;
|
|
628
|
+
}
|
|
629
|
+
setLocalSelection(_anchorX, _anchorY, _focusX, _focusY, _bgColor, _fgColor) {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
updateLocalSelection(_anchorX, _anchorY, _focusX, _focusY, _bgColor, _fgColor) {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
resetLocalSelection() {
|
|
636
|
+
}
|
|
637
|
+
getSelectedText() {
|
|
638
|
+
if (!this._selection) return "";
|
|
639
|
+
const text = this.textBuffer.getPlainText();
|
|
640
|
+
const start = Math.min(this._selection.start, this._selection.end);
|
|
641
|
+
const end = Math.max(this._selection.start, this._selection.end);
|
|
642
|
+
return text.slice(start, end);
|
|
643
|
+
}
|
|
644
|
+
getPlainText() {
|
|
645
|
+
return this.textBuffer.getPlainText();
|
|
646
|
+
}
|
|
647
|
+
setWrapWidth(width) {
|
|
648
|
+
this._wrapWidth = width;
|
|
649
|
+
}
|
|
650
|
+
setWrapMode(mode) {
|
|
651
|
+
this._wrapMode = mode;
|
|
652
|
+
}
|
|
653
|
+
setViewportSize(width, height) {
|
|
654
|
+
this._viewportWidth = width;
|
|
655
|
+
this._viewportHeight = height;
|
|
656
|
+
}
|
|
657
|
+
setViewport(x, y, width, height) {
|
|
658
|
+
this._viewportX = x;
|
|
659
|
+
this._viewportY = y;
|
|
660
|
+
this._viewportWidth = width;
|
|
661
|
+
this._viewportHeight = height;
|
|
662
|
+
}
|
|
663
|
+
setTabIndicator(_indicator) {
|
|
664
|
+
}
|
|
665
|
+
setTabIndicatorColor(_color) {
|
|
666
|
+
}
|
|
667
|
+
setTruncate(truncate) {
|
|
668
|
+
this._truncate = truncate;
|
|
669
|
+
}
|
|
670
|
+
getAllWrappedLines() {
|
|
671
|
+
const chunks = this.textBuffer.getChunks();
|
|
672
|
+
if (chunks.length === 0) return [];
|
|
673
|
+
const dfg = this.textBuffer.defaultFg ?? defaultFg;
|
|
674
|
+
const dbg = this.textBuffer.defaultBg ?? defaultBg;
|
|
675
|
+
const logicalLines = [[]];
|
|
676
|
+
for (const chunk of chunks) {
|
|
677
|
+
const parts = chunk.text.split("\n");
|
|
678
|
+
for (let i = 0; i < parts.length; i++) {
|
|
679
|
+
if (i > 0) {
|
|
680
|
+
logicalLines.push([]);
|
|
681
|
+
}
|
|
682
|
+
if (parts[i].length > 0) {
|
|
683
|
+
const vlc = {
|
|
684
|
+
text: parts[i],
|
|
685
|
+
fg: chunk.fg ?? dfg,
|
|
686
|
+
bg: chunk.bg ?? dbg,
|
|
687
|
+
attributes: chunk.attributes ?? 0
|
|
688
|
+
};
|
|
689
|
+
if (chunk.link) vlc.link = chunk.link;
|
|
690
|
+
logicalLines[logicalLines.length - 1].push(vlc);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (this._wrapMode === "none" || !this._wrapWidth || this._wrapWidth <= 0) {
|
|
695
|
+
return logicalLines;
|
|
696
|
+
}
|
|
697
|
+
const wrappedLines = [];
|
|
698
|
+
const wrapWidth = this._wrapWidth;
|
|
699
|
+
for (const logicalLine of logicalLines) {
|
|
700
|
+
const lineText = logicalLine.map((c) => c.text).join("");
|
|
701
|
+
if (lineText.length <= wrapWidth) {
|
|
702
|
+
wrappedLines.push(logicalLine);
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (this._wrapMode === "char") {
|
|
706
|
+
let pos = 0;
|
|
707
|
+
while (pos < lineText.length) {
|
|
708
|
+
const end = Math.min(pos + wrapWidth, lineText.length);
|
|
709
|
+
const sliceChunks = this.sliceChunks(logicalLine, pos, end);
|
|
710
|
+
wrappedLines.push(sliceChunks);
|
|
711
|
+
pos = end;
|
|
712
|
+
}
|
|
713
|
+
} else {
|
|
714
|
+
let pos = 0;
|
|
715
|
+
while (pos < lineText.length) {
|
|
716
|
+
let end = Math.min(pos + wrapWidth, lineText.length);
|
|
717
|
+
if (end < lineText.length) {
|
|
718
|
+
let breakPos = end;
|
|
719
|
+
while (breakPos > pos && lineText[breakPos] !== " ") {
|
|
720
|
+
breakPos--;
|
|
721
|
+
}
|
|
722
|
+
if (breakPos > pos) {
|
|
723
|
+
end = breakPos + 1;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const sliceChunks = this.sliceChunks(logicalLine, pos, end);
|
|
727
|
+
wrappedLines.push(sliceChunks);
|
|
728
|
+
pos = end;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return wrappedLines;
|
|
733
|
+
}
|
|
734
|
+
sliceChunks(chunks, start, end) {
|
|
735
|
+
const result = [];
|
|
736
|
+
let offset = 0;
|
|
737
|
+
for (const chunk of chunks) {
|
|
738
|
+
const chunkStart = offset;
|
|
739
|
+
const chunkEnd = offset + chunk.text.length;
|
|
740
|
+
if (chunkEnd <= start || chunkStart >= end) {
|
|
741
|
+
offset = chunkEnd;
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
const sliceStart = Math.max(0, start - chunkStart);
|
|
745
|
+
const sliceEnd = Math.min(chunk.text.length, end - chunkStart);
|
|
746
|
+
const slicedText = chunk.text.slice(sliceStart, sliceEnd);
|
|
747
|
+
if (slicedText.length > 0) {
|
|
748
|
+
const sliced = {
|
|
749
|
+
text: slicedText,
|
|
750
|
+
fg: chunk.fg,
|
|
751
|
+
bg: chunk.bg,
|
|
752
|
+
attributes: chunk.attributes
|
|
753
|
+
};
|
|
754
|
+
if (chunk.link) sliced.link = chunk.link;
|
|
755
|
+
result.push(sliced);
|
|
756
|
+
}
|
|
757
|
+
offset = chunkEnd;
|
|
758
|
+
}
|
|
759
|
+
return result;
|
|
760
|
+
}
|
|
761
|
+
measureForDimensions(width, height) {
|
|
762
|
+
const oldWrapWidth = this._wrapWidth;
|
|
763
|
+
if (width > 0 && this._wrapMode !== "none") {
|
|
764
|
+
this._wrapWidth = width;
|
|
765
|
+
} else if (width === 0) {
|
|
766
|
+
this._wrapWidth = null;
|
|
767
|
+
}
|
|
768
|
+
const lines = this.getAllWrappedLines();
|
|
769
|
+
this._wrapWidth = oldWrapWidth;
|
|
770
|
+
let maxWidth = 0;
|
|
771
|
+
for (const line of lines) {
|
|
772
|
+
const lineWidth = line.reduce((sum, c) => sum + c.text.length, 0);
|
|
773
|
+
if (lineWidth > maxWidth) maxWidth = lineWidth;
|
|
774
|
+
}
|
|
775
|
+
return {
|
|
776
|
+
lineCount: lines.length,
|
|
777
|
+
maxWidth
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
getVirtualLineCount() {
|
|
781
|
+
return this.getAllWrappedLines().length;
|
|
782
|
+
}
|
|
783
|
+
getVisibleLines() {
|
|
784
|
+
const allLines = this.getAllWrappedLines();
|
|
785
|
+
if (allLines.length === 0) return null;
|
|
786
|
+
const startLine = this._viewportY;
|
|
787
|
+
const endLine = this._viewportHeight > 0 ? Math.min(startLine + this._viewportHeight, allLines.length) : allLines.length;
|
|
788
|
+
const visibleLines = [];
|
|
789
|
+
for (let i = startLine; i < endLine; i++) {
|
|
790
|
+
if (i >= 0 && i < allLines.length) {
|
|
791
|
+
visibleLines.push({ chunks: allLines[i] });
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return visibleLines;
|
|
795
|
+
}
|
|
796
|
+
destroy() {
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
// src/browser-syntax-style.ts
|
|
801
|
+
var BrowserSyntaxStyle = class _BrowserSyntaxStyle {
|
|
802
|
+
_destroyed = false;
|
|
803
|
+
static create() {
|
|
804
|
+
return new _BrowserSyntaxStyle();
|
|
805
|
+
}
|
|
806
|
+
static fromTheme(_theme) {
|
|
807
|
+
return new _BrowserSyntaxStyle();
|
|
808
|
+
}
|
|
809
|
+
static fromStyles(_styles) {
|
|
810
|
+
return new _BrowserSyntaxStyle();
|
|
811
|
+
}
|
|
812
|
+
get ptr() {
|
|
813
|
+
return 0;
|
|
814
|
+
}
|
|
815
|
+
registerStyle(_name, _style) {
|
|
816
|
+
return 0;
|
|
817
|
+
}
|
|
818
|
+
resolveStyleId(_name) {
|
|
819
|
+
return null;
|
|
820
|
+
}
|
|
821
|
+
getStyleId(_name) {
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
824
|
+
getStyleCount() {
|
|
825
|
+
return 0;
|
|
826
|
+
}
|
|
827
|
+
clearNameCache() {
|
|
828
|
+
}
|
|
829
|
+
getStyle(_name) {
|
|
830
|
+
return void 0;
|
|
831
|
+
}
|
|
832
|
+
mergeStyles(..._styleNames) {
|
|
833
|
+
return { attributes: 0 };
|
|
834
|
+
}
|
|
835
|
+
clearCache() {
|
|
836
|
+
}
|
|
837
|
+
getCacheSize() {
|
|
838
|
+
return 0;
|
|
839
|
+
}
|
|
840
|
+
getAllStyles() {
|
|
841
|
+
return /* @__PURE__ */ new Map();
|
|
842
|
+
}
|
|
843
|
+
getRegisteredNames() {
|
|
844
|
+
return [];
|
|
845
|
+
}
|
|
846
|
+
destroy() {
|
|
847
|
+
this._destroyed = true;
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
// src/browser-render-context.ts
|
|
852
|
+
import { EventEmitter } from "events";
|
|
853
|
+
var BrowserKeyHandler = class extends EventEmitter {
|
|
854
|
+
constructor() {
|
|
855
|
+
super();
|
|
856
|
+
}
|
|
857
|
+
processInput(_data) {
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
var BrowserInternalKeyHandler = class extends BrowserKeyHandler {
|
|
862
|
+
renderableHandlers = /* @__PURE__ */ new Map();
|
|
863
|
+
onInternal(event, handler) {
|
|
864
|
+
if (!this.renderableHandlers.has(event)) {
|
|
865
|
+
this.renderableHandlers.set(event, /* @__PURE__ */ new Set());
|
|
866
|
+
}
|
|
867
|
+
this.renderableHandlers.get(event).add(handler);
|
|
868
|
+
}
|
|
869
|
+
offInternal(event, handler) {
|
|
870
|
+
const handlers = this.renderableHandlers.get(event);
|
|
871
|
+
if (handlers) {
|
|
872
|
+
handlers.delete(handler);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
emit(event, ...args) {
|
|
876
|
+
const hasGlobal = super.emit(event, ...args);
|
|
877
|
+
const renderableSet = this.renderableHandlers.get(event);
|
|
878
|
+
if (renderableSet && renderableSet.size > 0) {
|
|
879
|
+
for (const handler of [...renderableSet]) {
|
|
880
|
+
try {
|
|
881
|
+
handler(...args);
|
|
882
|
+
} catch (e) {
|
|
883
|
+
console.error(`[BrowserInternalKeyHandler] Error in ${event} handler:`, e);
|
|
884
|
+
}
|
|
885
|
+
if (args[0] && args[0].propagationStopped) break;
|
|
886
|
+
}
|
|
887
|
+
return true;
|
|
888
|
+
}
|
|
889
|
+
return hasGlobal;
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
var BrowserRenderContext = class extends EventEmitter {
|
|
893
|
+
_width;
|
|
894
|
+
_height;
|
|
895
|
+
_widthMethod;
|
|
896
|
+
_renderRequested = false;
|
|
897
|
+
_onRenderRequest = null;
|
|
898
|
+
_lifecyclePasses = /* @__PURE__ */ new Set();
|
|
899
|
+
_focusedRenderable = null;
|
|
900
|
+
keyInput;
|
|
901
|
+
_internalKeyInput;
|
|
902
|
+
constructor(width, height, widthMethod = "wcwidth") {
|
|
903
|
+
super();
|
|
904
|
+
this._width = width;
|
|
905
|
+
this._height = height;
|
|
906
|
+
this._widthMethod = widthMethod;
|
|
907
|
+
this.keyInput = new BrowserKeyHandler();
|
|
908
|
+
this._internalKeyInput = new BrowserInternalKeyHandler();
|
|
909
|
+
}
|
|
910
|
+
get width() {
|
|
911
|
+
return this._width;
|
|
912
|
+
}
|
|
913
|
+
get height() {
|
|
914
|
+
return this._height;
|
|
915
|
+
}
|
|
916
|
+
get widthMethod() {
|
|
917
|
+
return this._widthMethod;
|
|
918
|
+
}
|
|
919
|
+
get capabilities() {
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
get hasSelection() {
|
|
923
|
+
return false;
|
|
924
|
+
}
|
|
925
|
+
get currentFocusedRenderable() {
|
|
926
|
+
return this._focusedRenderable;
|
|
927
|
+
}
|
|
928
|
+
setOnRenderRequest(callback) {
|
|
929
|
+
this._onRenderRequest = callback;
|
|
930
|
+
}
|
|
931
|
+
resize(width, height) {
|
|
932
|
+
this._width = width;
|
|
933
|
+
this._height = height;
|
|
934
|
+
this.emit("resize", width, height);
|
|
935
|
+
}
|
|
936
|
+
// RenderContext interface methods
|
|
937
|
+
addToHitGrid(_x, _y, _width, _height, _id) {
|
|
938
|
+
}
|
|
939
|
+
pushHitGridScissorRect(_x, _y, _width, _height) {
|
|
940
|
+
}
|
|
941
|
+
popHitGridScissorRect() {
|
|
942
|
+
}
|
|
943
|
+
clearHitGridScissorRects() {
|
|
944
|
+
}
|
|
945
|
+
requestRender() {
|
|
946
|
+
if (this._renderRequested) return;
|
|
947
|
+
this._renderRequested = true;
|
|
948
|
+
this._onRenderRequest?.();
|
|
949
|
+
this._renderRequested = false;
|
|
950
|
+
}
|
|
951
|
+
setCursorPosition(_x, _y, _visible) {
|
|
952
|
+
}
|
|
953
|
+
setCursorStyle(_options) {
|
|
954
|
+
}
|
|
955
|
+
setCursorColor(_color) {
|
|
956
|
+
}
|
|
957
|
+
setMousePointer(_shape) {
|
|
958
|
+
}
|
|
959
|
+
requestLive() {
|
|
960
|
+
}
|
|
961
|
+
dropLive() {
|
|
962
|
+
}
|
|
963
|
+
getSelection() {
|
|
964
|
+
return null;
|
|
965
|
+
}
|
|
966
|
+
requestSelectionUpdate() {
|
|
967
|
+
}
|
|
968
|
+
focusRenderable(renderable) {
|
|
969
|
+
if (this._focusedRenderable && this._focusedRenderable !== renderable) {
|
|
970
|
+
this._focusedRenderable.blur?.();
|
|
971
|
+
}
|
|
972
|
+
this._focusedRenderable = renderable;
|
|
973
|
+
}
|
|
974
|
+
registerLifecyclePass(renderable) {
|
|
975
|
+
this._lifecyclePasses.add(renderable);
|
|
976
|
+
}
|
|
977
|
+
unregisterLifecyclePass(renderable) {
|
|
978
|
+
this._lifecyclePasses.delete(renderable);
|
|
979
|
+
}
|
|
980
|
+
getLifecyclePasses() {
|
|
981
|
+
return this._lifecyclePasses;
|
|
982
|
+
}
|
|
983
|
+
clearSelection() {
|
|
984
|
+
}
|
|
985
|
+
startSelection(_renderable, _x, _y) {
|
|
986
|
+
}
|
|
987
|
+
updateSelection(_currentRenderable, _x, _y, _options) {
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
|
|
991
|
+
// src/core-shims/index.ts
|
|
992
|
+
import {
|
|
993
|
+
CliRenderer,
|
|
994
|
+
CliRenderEvents,
|
|
995
|
+
createCliRenderer
|
|
996
|
+
} from "../../../../opentui/packages/core/src/renderer";
|
|
997
|
+
import {
|
|
998
|
+
Timeline,
|
|
999
|
+
engine,
|
|
1000
|
+
createTimeline
|
|
1001
|
+
} from "../../../../opentui/packages/core/src/animation/Timeline";
|
|
1002
|
+
import * as Yoga from "yoga-layout";
|
|
1003
|
+
function resolveRenderLib() {
|
|
1004
|
+
return null;
|
|
1005
|
+
}
|
|
1006
|
+
function createTextAttributes(opts = {}) {
|
|
1007
|
+
const TA = {
|
|
1008
|
+
NONE: 0,
|
|
1009
|
+
BOLD: 1,
|
|
1010
|
+
DIM: 2,
|
|
1011
|
+
ITALIC: 4,
|
|
1012
|
+
UNDERLINE: 8,
|
|
1013
|
+
BLINK: 16,
|
|
1014
|
+
INVERSE: 32,
|
|
1015
|
+
HIDDEN: 64,
|
|
1016
|
+
STRIKETHROUGH: 128
|
|
1017
|
+
};
|
|
1018
|
+
let attr = TA.NONE;
|
|
1019
|
+
if (opts.bold) attr |= TA.BOLD;
|
|
1020
|
+
if (opts.italic) attr |= TA.ITALIC;
|
|
1021
|
+
if (opts.underline) attr |= TA.UNDERLINE;
|
|
1022
|
+
if (opts.dim) attr |= TA.DIM;
|
|
1023
|
+
if (opts.blink) attr |= TA.BLINK;
|
|
1024
|
+
if (opts.inverse) attr |= TA.INVERSE;
|
|
1025
|
+
if (opts.hidden) attr |= TA.HIDDEN;
|
|
1026
|
+
if (opts.strikethrough) attr |= TA.STRIKETHROUGH;
|
|
1027
|
+
return attr;
|
|
1028
|
+
}
|
|
1029
|
+
function attributesWithLink(baseAttributes, linkId) {
|
|
1030
|
+
return baseAttributes & 255 | (linkId & 16777215) << 8;
|
|
1031
|
+
}
|
|
1032
|
+
function getLinkId(attributes) {
|
|
1033
|
+
return attributes >>> 8 & 16777215;
|
|
1034
|
+
}
|
|
1035
|
+
function visualizeRenderableTree(..._args) {
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// src/browser-buffer.ts
|
|
1039
|
+
var CONTINUATION = 3221225472;
|
|
1040
|
+
var BrowserBuffer = class _BrowserBuffer {
|
|
1041
|
+
id;
|
|
1042
|
+
respectAlpha;
|
|
1043
|
+
_width;
|
|
1044
|
+
_height;
|
|
1045
|
+
_widthMethod;
|
|
1046
|
+
// Cell data - same layout as native OptimizedBuffer
|
|
1047
|
+
char;
|
|
1048
|
+
fg;
|
|
1049
|
+
bg;
|
|
1050
|
+
attributes;
|
|
1051
|
+
scissorStack = [];
|
|
1052
|
+
opacityStack = [];
|
|
1053
|
+
// Link registry for clickable links
|
|
1054
|
+
linkRegistry = /* @__PURE__ */ new Map();
|
|
1055
|
+
nextLinkId = 1;
|
|
1056
|
+
constructor(width, height, options = {}) {
|
|
1057
|
+
this._width = width;
|
|
1058
|
+
this._height = height;
|
|
1059
|
+
this._widthMethod = options.widthMethod ?? "wcwidth";
|
|
1060
|
+
this.respectAlpha = options.respectAlpha ?? false;
|
|
1061
|
+
this.id = options.id ?? `browser-buffer-${Math.random().toString(36).slice(2, 8)}`;
|
|
1062
|
+
const size = width * height;
|
|
1063
|
+
this.char = new Uint32Array(size);
|
|
1064
|
+
this.fg = new Float32Array(size * 4);
|
|
1065
|
+
this.bg = new Float32Array(size * 4);
|
|
1066
|
+
this.attributes = new Uint32Array(size);
|
|
1067
|
+
this.char.fill(32);
|
|
1068
|
+
}
|
|
1069
|
+
static create(width, height, widthMethod, options) {
|
|
1070
|
+
return new _BrowserBuffer(width, height, { ...options, widthMethod });
|
|
1071
|
+
}
|
|
1072
|
+
get width() {
|
|
1073
|
+
return this._width;
|
|
1074
|
+
}
|
|
1075
|
+
get height() {
|
|
1076
|
+
return this._height;
|
|
1077
|
+
}
|
|
1078
|
+
get widthMethod() {
|
|
1079
|
+
return this._widthMethod;
|
|
1080
|
+
}
|
|
1081
|
+
get ptr() {
|
|
1082
|
+
return 0;
|
|
1083
|
+
}
|
|
1084
|
+
get buffers() {
|
|
1085
|
+
return {
|
|
1086
|
+
char: this.char,
|
|
1087
|
+
fg: this.fg,
|
|
1088
|
+
bg: this.bg,
|
|
1089
|
+
attributes: this.attributes
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
setRespectAlpha(respectAlpha) {
|
|
1093
|
+
this.respectAlpha = respectAlpha;
|
|
1094
|
+
}
|
|
1095
|
+
getNativeId() {
|
|
1096
|
+
return this.id;
|
|
1097
|
+
}
|
|
1098
|
+
registerLink(url) {
|
|
1099
|
+
const id = this.nextLinkId++;
|
|
1100
|
+
this.linkRegistry.set(id, url);
|
|
1101
|
+
return id;
|
|
1102
|
+
}
|
|
1103
|
+
getLinkUrl(linkId) {
|
|
1104
|
+
return this.linkRegistry.get(linkId);
|
|
1105
|
+
}
|
|
1106
|
+
isInScissor(x, y) {
|
|
1107
|
+
if (this.scissorStack.length === 0) return true;
|
|
1108
|
+
const rect = this.scissorStack[this.scissorStack.length - 1];
|
|
1109
|
+
return x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;
|
|
1110
|
+
}
|
|
1111
|
+
getCurrentOpacityMultiplier() {
|
|
1112
|
+
if (this.opacityStack.length === 0) return 1;
|
|
1113
|
+
return this.opacityStack[this.opacityStack.length - 1];
|
|
1114
|
+
}
|
|
1115
|
+
applyOpacity(color) {
|
|
1116
|
+
const multiplier = this.getCurrentOpacityMultiplier();
|
|
1117
|
+
if (multiplier >= 1) return color;
|
|
1118
|
+
return {
|
|
1119
|
+
r: color.r,
|
|
1120
|
+
g: color.g,
|
|
1121
|
+
b: color.b,
|
|
1122
|
+
a: color.a * multiplier,
|
|
1123
|
+
buffer: new Float32Array([color.r, color.g, color.b, color.a * multiplier]),
|
|
1124
|
+
toInts: color.toInts,
|
|
1125
|
+
equals: color.equals,
|
|
1126
|
+
map: color.map,
|
|
1127
|
+
toString: color.toString
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
clear(bg2) {
|
|
1131
|
+
const size = this._width * this._height;
|
|
1132
|
+
this.char.fill(32);
|
|
1133
|
+
this.attributes.fill(0);
|
|
1134
|
+
this.linkRegistry.clear();
|
|
1135
|
+
this.nextLinkId = 1;
|
|
1136
|
+
if (bg2) {
|
|
1137
|
+
for (let i = 0; i < size; i++) {
|
|
1138
|
+
const offset = i * 4;
|
|
1139
|
+
this.bg[offset] = bg2.r;
|
|
1140
|
+
this.bg[offset + 1] = bg2.g;
|
|
1141
|
+
this.bg[offset + 2] = bg2.b;
|
|
1142
|
+
this.bg[offset + 3] = bg2.a;
|
|
1143
|
+
this.fg[offset] = 0;
|
|
1144
|
+
this.fg[offset + 1] = 0;
|
|
1145
|
+
this.fg[offset + 2] = 0;
|
|
1146
|
+
this.fg[offset + 3] = 0;
|
|
1147
|
+
}
|
|
1148
|
+
} else {
|
|
1149
|
+
this.fg.fill(0);
|
|
1150
|
+
this.bg.fill(0);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
setCell(x, y, char, fgColor, bgColor, attr = 0) {
|
|
1154
|
+
if (x < 0 || x >= this._width || y < 0 || y >= this._height) return;
|
|
1155
|
+
if (!this.isInScissor(x, y)) return;
|
|
1156
|
+
const idx = y * this._width + x;
|
|
1157
|
+
const offset = idx * 4;
|
|
1158
|
+
const effectiveBg = this.applyOpacity(bgColor);
|
|
1159
|
+
const effectiveFg = this.applyOpacity(fgColor);
|
|
1160
|
+
this.char[idx] = char.codePointAt(0) ?? 32;
|
|
1161
|
+
this.attributes[idx] = attr;
|
|
1162
|
+
this.fg[offset] = effectiveFg.r;
|
|
1163
|
+
this.fg[offset + 1] = effectiveFg.g;
|
|
1164
|
+
this.fg[offset + 2] = effectiveFg.b;
|
|
1165
|
+
this.fg[offset + 3] = effectiveFg.a;
|
|
1166
|
+
this.bg[offset] = effectiveBg.r;
|
|
1167
|
+
this.bg[offset + 1] = effectiveBg.g;
|
|
1168
|
+
this.bg[offset + 2] = effectiveBg.b;
|
|
1169
|
+
this.bg[offset + 3] = effectiveBg.a;
|
|
1170
|
+
}
|
|
1171
|
+
setCellWithAlphaBlending(x, y, char, fgColor, bgColor, attr = 0) {
|
|
1172
|
+
this.setCell(x, y, char, fgColor, bgColor, attr);
|
|
1173
|
+
}
|
|
1174
|
+
drawChar(charCode, x, y, fgColor, bgColor, attr = 0) {
|
|
1175
|
+
if (x < 0 || x >= this._width || y < 0 || y >= this._height) return;
|
|
1176
|
+
if (!this.isInScissor(x, y)) return;
|
|
1177
|
+
const idx = y * this._width + x;
|
|
1178
|
+
const offset = idx * 4;
|
|
1179
|
+
const effectiveBg = this.applyOpacity(bgColor);
|
|
1180
|
+
const effectiveFg = this.applyOpacity(fgColor);
|
|
1181
|
+
this.char[idx] = charCode;
|
|
1182
|
+
this.attributes[idx] = attr;
|
|
1183
|
+
this.fg[offset] = effectiveFg.r;
|
|
1184
|
+
this.fg[offset + 1] = effectiveFg.g;
|
|
1185
|
+
this.fg[offset + 2] = effectiveFg.b;
|
|
1186
|
+
this.fg[offset + 3] = effectiveFg.a;
|
|
1187
|
+
this.bg[offset] = effectiveBg.r;
|
|
1188
|
+
this.bg[offset + 1] = effectiveBg.g;
|
|
1189
|
+
this.bg[offset + 2] = effectiveBg.b;
|
|
1190
|
+
this.bg[offset + 3] = effectiveBg.a;
|
|
1191
|
+
}
|
|
1192
|
+
drawText(text, x, y, fgColor, bgColor, attr = 0, _selection) {
|
|
1193
|
+
const transparentBg = {
|
|
1194
|
+
r: 0,
|
|
1195
|
+
g: 0,
|
|
1196
|
+
b: 0,
|
|
1197
|
+
a: 0,
|
|
1198
|
+
buffer: new Float32Array([0, 0, 0, 0])
|
|
1199
|
+
};
|
|
1200
|
+
const bg2 = bgColor ?? transparentBg;
|
|
1201
|
+
let curX = x;
|
|
1202
|
+
for (const ch of text) {
|
|
1203
|
+
if (curX >= this._width) break;
|
|
1204
|
+
if (curX >= 0) {
|
|
1205
|
+
this.setCell(curX, y, ch, fgColor, bg2, attr);
|
|
1206
|
+
}
|
|
1207
|
+
curX++;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
fillRect(x, y, width, height, bgColor) {
|
|
1211
|
+
for (let row = y; row < y + height && row < this._height; row++) {
|
|
1212
|
+
for (let col = x; col < x + width && col < this._width; col++) {
|
|
1213
|
+
if (col < 0 || row < 0) continue;
|
|
1214
|
+
if (!this.isInScissor(col, row)) continue;
|
|
1215
|
+
const idx = row * this._width + col;
|
|
1216
|
+
const offset = idx * 4;
|
|
1217
|
+
const effectiveBg = this.applyOpacity(bgColor);
|
|
1218
|
+
this.char[idx] = 32;
|
|
1219
|
+
this.bg[offset] = effectiveBg.r;
|
|
1220
|
+
this.bg[offset + 1] = effectiveBg.g;
|
|
1221
|
+
this.bg[offset + 2] = effectiveBg.b;
|
|
1222
|
+
this.bg[offset + 3] = effectiveBg.a;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
drawBox(options) {
|
|
1227
|
+
const {
|
|
1228
|
+
x,
|
|
1229
|
+
y,
|
|
1230
|
+
width,
|
|
1231
|
+
height,
|
|
1232
|
+
border,
|
|
1233
|
+
borderColor,
|
|
1234
|
+
backgroundColor,
|
|
1235
|
+
shouldFill = true,
|
|
1236
|
+
title,
|
|
1237
|
+
titleAlignment = "left"
|
|
1238
|
+
} = options;
|
|
1239
|
+
if (width <= 0 || height <= 0) return;
|
|
1240
|
+
const sides = {
|
|
1241
|
+
top: border === true || Array.isArray(border) && border.includes("top"),
|
|
1242
|
+
right: border === true || Array.isArray(border) && border.includes("right"),
|
|
1243
|
+
bottom: border === true || Array.isArray(border) && border.includes("bottom"),
|
|
1244
|
+
left: border === true || Array.isArray(border) && border.includes("left")
|
|
1245
|
+
};
|
|
1246
|
+
const borderChars = options.customBorderChars ?? this.getDefaultBorderChars(options.borderStyle);
|
|
1247
|
+
if (shouldFill) {
|
|
1248
|
+
const fillStartX = x + (sides.left ? 1 : 0);
|
|
1249
|
+
const fillStartY = y + (sides.top ? 1 : 0);
|
|
1250
|
+
const fillWidth = width - (sides.left ? 1 : 0) - (sides.right ? 1 : 0);
|
|
1251
|
+
const fillHeight = height - (sides.top ? 1 : 0) - (sides.bottom ? 1 : 0);
|
|
1252
|
+
if (fillWidth > 0 && fillHeight > 0) {
|
|
1253
|
+
this.fillRect(fillStartX, fillStartY, fillWidth, fillHeight, backgroundColor);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
if (!border) return;
|
|
1257
|
+
const transparent = { r: 0, g: 0, b: 0, a: 0, buffer: new Float32Array([0, 0, 0, 0]) };
|
|
1258
|
+
const topLeft = borderChars[0];
|
|
1259
|
+
const topRight = borderChars[1];
|
|
1260
|
+
const bottomLeft = borderChars[2];
|
|
1261
|
+
const bottomRight = borderChars[3];
|
|
1262
|
+
const horizontal = borderChars[4];
|
|
1263
|
+
const vertical = borderChars[5];
|
|
1264
|
+
if (sides.top) {
|
|
1265
|
+
if (sides.left) this.drawChar(topLeft, x, y, borderColor, transparent);
|
|
1266
|
+
for (let col = 1; col < width - 1; col++) {
|
|
1267
|
+
this.drawChar(horizontal, x + col, y, borderColor, transparent);
|
|
1268
|
+
}
|
|
1269
|
+
if (sides.right && width > 1) this.drawChar(topRight, x + width - 1, y, borderColor, transparent);
|
|
1270
|
+
}
|
|
1271
|
+
if (sides.bottom && height > 1) {
|
|
1272
|
+
if (sides.left) this.drawChar(bottomLeft, x, y + height - 1, borderColor, transparent);
|
|
1273
|
+
for (let col = 1; col < width - 1; col++) {
|
|
1274
|
+
this.drawChar(horizontal, x + col, y + height - 1, borderColor, transparent);
|
|
1275
|
+
}
|
|
1276
|
+
if (sides.right && width > 1)
|
|
1277
|
+
this.drawChar(bottomRight, x + width - 1, y + height - 1, borderColor, transparent);
|
|
1278
|
+
}
|
|
1279
|
+
if (sides.left) {
|
|
1280
|
+
for (let row = 1; row < height - 1; row++) {
|
|
1281
|
+
this.drawChar(vertical, x, y + row, borderColor, transparent);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
if (sides.right && width > 1) {
|
|
1285
|
+
for (let row = 1; row < height - 1; row++) {
|
|
1286
|
+
this.drawChar(vertical, x + width - 1, y + row, borderColor, transparent);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
if (title && sides.top && width > 4) {
|
|
1290
|
+
const maxTitleLen = width - 4;
|
|
1291
|
+
const truncatedTitle = title.length > maxTitleLen ? title.slice(0, maxTitleLen) : title;
|
|
1292
|
+
let titleX;
|
|
1293
|
+
if (titleAlignment === "center") {
|
|
1294
|
+
titleX = x + Math.floor((width - truncatedTitle.length) / 2);
|
|
1295
|
+
} else if (titleAlignment === "right") {
|
|
1296
|
+
titleX = x + width - truncatedTitle.length - 2;
|
|
1297
|
+
} else {
|
|
1298
|
+
titleX = x + 2;
|
|
1299
|
+
}
|
|
1300
|
+
this.drawText(truncatedTitle, titleX, y, borderColor, transparent);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
getDefaultBorderChars(borderStyle) {
|
|
1304
|
+
const styles = {
|
|
1305
|
+
rounded: [9581, 9582, 9584, 9583, 9472, 9474, 9516, 9524, 9500, 9508, 9532],
|
|
1306
|
+
single: [9484, 9488, 9492, 9496, 9472, 9474, 9516, 9524, 9500, 9508, 9532],
|
|
1307
|
+
double: [9556, 9559, 9562, 9565, 9552, 9553, 9574, 9577, 9568, 9571, 9580],
|
|
1308
|
+
heavy: [9487, 9491, 9495, 9499, 9473, 9475, 9523, 9531, 9507, 9515, 9547]
|
|
1309
|
+
};
|
|
1310
|
+
const chars = styles[borderStyle ?? "rounded"] ?? styles.rounded;
|
|
1311
|
+
return new Uint32Array(chars);
|
|
1312
|
+
}
|
|
1313
|
+
pushScissorRect(x, y, width, height) {
|
|
1314
|
+
if (this.scissorStack.length > 0) {
|
|
1315
|
+
const current = this.scissorStack[this.scissorStack.length - 1];
|
|
1316
|
+
const nx = Math.max(x, current.x);
|
|
1317
|
+
const ny = Math.max(y, current.y);
|
|
1318
|
+
const nw = Math.min(x + width, current.x + current.width) - nx;
|
|
1319
|
+
const nh = Math.min(y + height, current.y + current.height) - ny;
|
|
1320
|
+
this.scissorStack.push({ x: nx, y: ny, width: Math.max(0, nw), height: Math.max(0, nh) });
|
|
1321
|
+
} else {
|
|
1322
|
+
this.scissorStack.push({ x, y, width, height });
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
popScissorRect() {
|
|
1326
|
+
this.scissorStack.pop();
|
|
1327
|
+
}
|
|
1328
|
+
clearScissorRects() {
|
|
1329
|
+
this.scissorStack = [];
|
|
1330
|
+
}
|
|
1331
|
+
pushOpacity(opacity) {
|
|
1332
|
+
const current = this.getCurrentOpacityMultiplier();
|
|
1333
|
+
this.opacityStack.push(current * opacity);
|
|
1334
|
+
}
|
|
1335
|
+
popOpacity() {
|
|
1336
|
+
this.opacityStack.pop();
|
|
1337
|
+
}
|
|
1338
|
+
getCurrentOpacity() {
|
|
1339
|
+
return this.getCurrentOpacityMultiplier();
|
|
1340
|
+
}
|
|
1341
|
+
clearOpacity() {
|
|
1342
|
+
this.opacityStack = [];
|
|
1343
|
+
}
|
|
1344
|
+
resize(width, height) {
|
|
1345
|
+
this._width = width;
|
|
1346
|
+
this._height = height;
|
|
1347
|
+
const size = width * height;
|
|
1348
|
+
this.char = new Uint32Array(size);
|
|
1349
|
+
this.fg = new Float32Array(size * 4);
|
|
1350
|
+
this.bg = new Float32Array(size * 4);
|
|
1351
|
+
this.attributes = new Uint32Array(size);
|
|
1352
|
+
this.char.fill(32);
|
|
1353
|
+
}
|
|
1354
|
+
// Read buffer into CapturedLine[] for testing
|
|
1355
|
+
getSpanLines() {
|
|
1356
|
+
const lines = [];
|
|
1357
|
+
for (let row = 0; row < this._height; row++) {
|
|
1358
|
+
const spans = [];
|
|
1359
|
+
let currentSpan = null;
|
|
1360
|
+
for (let col = 0; col < this._width; col++) {
|
|
1361
|
+
const idx = row * this._width + col;
|
|
1362
|
+
const offset = idx * 4;
|
|
1363
|
+
if (this.attributes[idx] & CONTINUATION) continue;
|
|
1364
|
+
const charCode = this.char[idx];
|
|
1365
|
+
const ch = charCode === 0 ? " " : String.fromCodePoint(charCode);
|
|
1366
|
+
const fgR = this.fg[offset];
|
|
1367
|
+
const fgG = this.fg[offset + 1];
|
|
1368
|
+
const fgB = this.fg[offset + 2];
|
|
1369
|
+
const fgA = this.fg[offset + 3];
|
|
1370
|
+
const bgR = this.bg[offset];
|
|
1371
|
+
const bgG = this.bg[offset + 1];
|
|
1372
|
+
const bgB = this.bg[offset + 2];
|
|
1373
|
+
const bgA = this.bg[offset + 3];
|
|
1374
|
+
const attr = this.attributes[idx] & 255;
|
|
1375
|
+
const fg2 = {
|
|
1376
|
+
r: fgR,
|
|
1377
|
+
g: fgG,
|
|
1378
|
+
b: fgB,
|
|
1379
|
+
a: fgA,
|
|
1380
|
+
buffer: new Float32Array([fgR, fgG, fgB, fgA])
|
|
1381
|
+
};
|
|
1382
|
+
const bg2 = {
|
|
1383
|
+
r: bgR,
|
|
1384
|
+
g: bgG,
|
|
1385
|
+
b: bgB,
|
|
1386
|
+
a: bgA,
|
|
1387
|
+
buffer: new Float32Array([bgR, bgG, bgB, bgA])
|
|
1388
|
+
};
|
|
1389
|
+
if (currentSpan && currentSpan.fg.r === fgR && currentSpan.fg.g === fgG && currentSpan.fg.b === fgB && currentSpan.fg.a === fgA && currentSpan.bg.r === bgR && currentSpan.bg.g === bgG && currentSpan.bg.b === bgB && currentSpan.bg.a === bgA && currentSpan.attributes === attr) {
|
|
1390
|
+
currentSpan.text += ch;
|
|
1391
|
+
currentSpan.width += 1;
|
|
1392
|
+
} else {
|
|
1393
|
+
if (currentSpan) spans.push(currentSpan);
|
|
1394
|
+
currentSpan = { text: ch, fg: fg2, bg: bg2, attributes: attr, width: 1 };
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
if (currentSpan) spans.push(currentSpan);
|
|
1398
|
+
lines.push({ spans });
|
|
1399
|
+
}
|
|
1400
|
+
return lines;
|
|
1401
|
+
}
|
|
1402
|
+
// Draw a text buffer view into the buffer
|
|
1403
|
+
drawTextBufferView(view, x, y) {
|
|
1404
|
+
if (!view || !view.getVisibleLines) return;
|
|
1405
|
+
const lines = view.getVisibleLines();
|
|
1406
|
+
if (!lines) return;
|
|
1407
|
+
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
1408
|
+
const line = lines[lineIdx];
|
|
1409
|
+
if (!line) continue;
|
|
1410
|
+
let curX = x;
|
|
1411
|
+
for (const chunk of line.chunks) {
|
|
1412
|
+
const text = chunk.text;
|
|
1413
|
+
const fgColor = chunk.fg;
|
|
1414
|
+
const bgColor = chunk.bg;
|
|
1415
|
+
let attr = chunk.attributes ?? 0;
|
|
1416
|
+
if (chunk.link && chunk.link.url) {
|
|
1417
|
+
const linkId = this.registerLink(chunk.link.url);
|
|
1418
|
+
attr = attributesWithLink(attr, linkId);
|
|
1419
|
+
}
|
|
1420
|
+
for (const ch of text) {
|
|
1421
|
+
if (curX >= this._width) break;
|
|
1422
|
+
if (curX >= 0 && y + lineIdx >= 0 && y + lineIdx < this._height) {
|
|
1423
|
+
this.setCell(curX, y + lineIdx, ch, fgColor, bgColor, attr);
|
|
1424
|
+
}
|
|
1425
|
+
curX++;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
drawTextBuffer(textBufferView, x, y) {
|
|
1431
|
+
this.drawTextBufferView(textBufferView, x, y);
|
|
1432
|
+
}
|
|
1433
|
+
drawFrameBuffer(destX, destY, frameBuffer, sourceX = 0, sourceY = 0, sourceWidth, sourceHeight) {
|
|
1434
|
+
const sw = sourceWidth ?? frameBuffer.width;
|
|
1435
|
+
const sh = sourceHeight ?? frameBuffer.height;
|
|
1436
|
+
const srcChar = frameBuffer.char;
|
|
1437
|
+
const srcFg = frameBuffer.fg;
|
|
1438
|
+
const srcBg = frameBuffer.bg;
|
|
1439
|
+
const srcAttr = frameBuffer.attributes;
|
|
1440
|
+
const srcCols = frameBuffer.width;
|
|
1441
|
+
for (let row = 0; row < sh; row++) {
|
|
1442
|
+
const srcRow = sourceY + row;
|
|
1443
|
+
const dstRow = destY + row;
|
|
1444
|
+
if (srcRow < 0 || srcRow >= frameBuffer.height) continue;
|
|
1445
|
+
if (dstRow < 0 || dstRow >= this._height) continue;
|
|
1446
|
+
for (let col = 0; col < sw; col++) {
|
|
1447
|
+
const srcCol = sourceX + col;
|
|
1448
|
+
const dstCol = destX + col;
|
|
1449
|
+
if (srcCol < 0 || srcCol >= frameBuffer.width) continue;
|
|
1450
|
+
if (dstCol < 0 || dstCol >= this._width) continue;
|
|
1451
|
+
if (!this.isInScissor(dstCol, dstRow)) continue;
|
|
1452
|
+
const srcIdx = srcRow * srcCols + srcCol;
|
|
1453
|
+
const dstIdx = dstRow * this._width + dstCol;
|
|
1454
|
+
const srcOffset = srcIdx * 4;
|
|
1455
|
+
const dstOffset = dstIdx * 4;
|
|
1456
|
+
this.char[dstIdx] = srcChar[srcIdx];
|
|
1457
|
+
this.attributes[dstIdx] = srcAttr[srcIdx];
|
|
1458
|
+
const fgA = srcFg[srcOffset + 3];
|
|
1459
|
+
const opacityMul = this.getCurrentOpacityMultiplier();
|
|
1460
|
+
this.fg[dstOffset] = srcFg[srcOffset];
|
|
1461
|
+
this.fg[dstOffset + 1] = srcFg[srcOffset + 1];
|
|
1462
|
+
this.fg[dstOffset + 2] = srcFg[srcOffset + 2];
|
|
1463
|
+
this.fg[dstOffset + 3] = fgA * opacityMul;
|
|
1464
|
+
const bgA = srcBg[srcOffset + 3];
|
|
1465
|
+
this.bg[dstOffset] = srcBg[srcOffset];
|
|
1466
|
+
this.bg[dstOffset + 1] = srcBg[srcOffset + 1];
|
|
1467
|
+
this.bg[dstOffset + 2] = srcBg[srcOffset + 2];
|
|
1468
|
+
this.bg[dstOffset + 3] = bgA * opacityMul;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
drawEditorView(editorView, x, y) {
|
|
1473
|
+
if (!editorView) return;
|
|
1474
|
+
const viewport = editorView.getViewport();
|
|
1475
|
+
const text = editorView.getText();
|
|
1476
|
+
const lines = text.split("\n");
|
|
1477
|
+
const dfg = editorView.editBuffer?._defaultFg ?? {
|
|
1478
|
+
r: 1,
|
|
1479
|
+
g: 1,
|
|
1480
|
+
b: 1,
|
|
1481
|
+
a: 1,
|
|
1482
|
+
buffer: new Float32Array([1, 1, 1, 1])
|
|
1483
|
+
};
|
|
1484
|
+
const dbg = editorView.editBuffer?._defaultBg ?? {
|
|
1485
|
+
r: 0,
|
|
1486
|
+
g: 0,
|
|
1487
|
+
b: 0,
|
|
1488
|
+
a: 0,
|
|
1489
|
+
buffer: new Float32Array([0, 0, 0, 0])
|
|
1490
|
+
};
|
|
1491
|
+
const visibleRows = viewport.height > 0 ? viewport.height : this._height - y;
|
|
1492
|
+
if (text === "" && editorView._placeholderChunks && editorView._placeholderChunks.length > 0) {
|
|
1493
|
+
let curX = x;
|
|
1494
|
+
for (const chunk of editorView._placeholderChunks) {
|
|
1495
|
+
const chunkFg = chunk.fg ?? dfg;
|
|
1496
|
+
const chunkBg = chunk.bg ?? dbg;
|
|
1497
|
+
const attr = (chunk.attributes ?? 0) | 2;
|
|
1498
|
+
for (const ch of chunk.text) {
|
|
1499
|
+
if (curX >= this._width) break;
|
|
1500
|
+
if (curX >= 0 && y >= 0 && y < this._height) {
|
|
1501
|
+
this.setCell(curX, y, ch, chunkFg, chunkBg, attr);
|
|
1502
|
+
}
|
|
1503
|
+
curX++;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
} else {
|
|
1507
|
+
for (let row = 0; row < visibleRows; row++) {
|
|
1508
|
+
const lineIdx = viewport.offsetY + row;
|
|
1509
|
+
if (lineIdx < 0 || lineIdx >= lines.length) continue;
|
|
1510
|
+
const dstRow = y + row;
|
|
1511
|
+
if (dstRow < 0 || dstRow >= this._height) continue;
|
|
1512
|
+
const line = lines[lineIdx];
|
|
1513
|
+
for (let col = 0; col < line.length; col++) {
|
|
1514
|
+
const srcCol = viewport.offsetX + col;
|
|
1515
|
+
if (srcCol < 0 || srcCol >= line.length) continue;
|
|
1516
|
+
const dstCol = x + col;
|
|
1517
|
+
if (dstCol < 0 || dstCol >= this._width) break;
|
|
1518
|
+
this.setCell(dstCol, dstRow, line[srcCol], dfg, dbg, 0);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
const cursor = editorView.getVisualCursor();
|
|
1523
|
+
if (cursor) {
|
|
1524
|
+
const cursorX = x + cursor.visualCol;
|
|
1525
|
+
const cursorY = y + cursor.visualRow;
|
|
1526
|
+
if (cursorX >= 0 && cursorX < this._width && cursorY >= 0 && cursorY < this._height) {
|
|
1527
|
+
const idx = cursorY * this._width + cursorX;
|
|
1528
|
+
const charCode = this.char[idx];
|
|
1529
|
+
const ch = charCode === 0 || charCode === 32 ? " " : String.fromCodePoint(charCode);
|
|
1530
|
+
this.setCell(cursorX, cursorY, ch, dfg, dbg, 32);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
drawSuperSampleBuffer() {
|
|
1535
|
+
}
|
|
1536
|
+
drawPackedBuffer() {
|
|
1537
|
+
}
|
|
1538
|
+
drawGrayscaleBuffer() {
|
|
1539
|
+
}
|
|
1540
|
+
drawGrayscaleBufferSupersampled() {
|
|
1541
|
+
}
|
|
1542
|
+
drawGrid() {
|
|
1543
|
+
}
|
|
1544
|
+
encodeUnicode(_text) {
|
|
1545
|
+
return null;
|
|
1546
|
+
}
|
|
1547
|
+
freeUnicode() {
|
|
1548
|
+
}
|
|
1549
|
+
getRealCharBytes() {
|
|
1550
|
+
return new Uint8Array(0);
|
|
1551
|
+
}
|
|
1552
|
+
destroy() {
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
|
|
1556
|
+
// src/canvas-painter.ts
|
|
1557
|
+
var TextAttributes2 = {
|
|
1558
|
+
BOLD: 1 << 0,
|
|
1559
|
+
DIM: 1 << 1,
|
|
1560
|
+
ITALIC: 1 << 2,
|
|
1561
|
+
UNDERLINE: 1 << 3,
|
|
1562
|
+
UNDERLINE_DASHED: 1 << 4,
|
|
1563
|
+
INVERSE: 1 << 5,
|
|
1564
|
+
UNDERLINE_DOTTED: 1 << 6
|
|
1565
|
+
};
|
|
1566
|
+
var CONTINUATION2 = 3221225472;
|
|
1567
|
+
var BOX_DRAWING_MAP = {
|
|
1568
|
+
// Light lines
|
|
1569
|
+
9472: { left: true, right: true, type: "light" },
|
|
1570
|
+
// ─
|
|
1571
|
+
9474: { up: true, down: true, type: "light" },
|
|
1572
|
+
// │
|
|
1573
|
+
9484: { right: true, down: true, type: "light" },
|
|
1574
|
+
// ┌
|
|
1575
|
+
9488: { left: true, down: true, type: "light" },
|
|
1576
|
+
// ┐
|
|
1577
|
+
9492: { right: true, up: true, type: "light" },
|
|
1578
|
+
// └
|
|
1579
|
+
9496: { left: true, up: true, type: "light" },
|
|
1580
|
+
// ┘
|
|
1581
|
+
9500: { up: true, down: true, right: true, type: "light" },
|
|
1582
|
+
// ├
|
|
1583
|
+
9508: { up: true, down: true, left: true, type: "light" },
|
|
1584
|
+
// ┤
|
|
1585
|
+
9516: { left: true, right: true, down: true, type: "light" },
|
|
1586
|
+
// ┬
|
|
1587
|
+
9524: { left: true, right: true, up: true, type: "light" },
|
|
1588
|
+
// ┴
|
|
1589
|
+
9532: { left: true, right: true, up: true, down: true, type: "light" },
|
|
1590
|
+
// ┼
|
|
1591
|
+
// Heavy lines
|
|
1592
|
+
9473: { left: true, right: true, type: "heavy" },
|
|
1593
|
+
// ━
|
|
1594
|
+
9475: { up: true, down: true, type: "heavy" },
|
|
1595
|
+
// ┃
|
|
1596
|
+
9487: { right: true, down: true, type: "heavy" },
|
|
1597
|
+
// ┏
|
|
1598
|
+
9491: { left: true, down: true, type: "heavy" },
|
|
1599
|
+
// ┓
|
|
1600
|
+
9495: { right: true, up: true, type: "heavy" },
|
|
1601
|
+
// ┗
|
|
1602
|
+
9499: { left: true, up: true, type: "heavy" },
|
|
1603
|
+
// ┛
|
|
1604
|
+
9507: { up: true, down: true, right: true, type: "heavy" },
|
|
1605
|
+
// ┣
|
|
1606
|
+
9515: { up: true, down: true, left: true, type: "heavy" },
|
|
1607
|
+
// ┫
|
|
1608
|
+
9523: { left: true, right: true, down: true, type: "heavy" },
|
|
1609
|
+
// ┳
|
|
1610
|
+
9531: { left: true, right: true, up: true, type: "heavy" },
|
|
1611
|
+
// ┻
|
|
1612
|
+
9547: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1613
|
+
// ╋
|
|
1614
|
+
// Light/heavy mixed (treat as light for simplicity of joins)
|
|
1615
|
+
9485: { right: true, down: true, type: "heavy" },
|
|
1616
|
+
// ┍
|
|
1617
|
+
9486: { right: true, down: true, type: "heavy" },
|
|
1618
|
+
// ┎
|
|
1619
|
+
9489: { left: true, down: true, type: "heavy" },
|
|
1620
|
+
// ┑
|
|
1621
|
+
9490: { left: true, down: true, type: "heavy" },
|
|
1622
|
+
// ┒
|
|
1623
|
+
9493: { right: true, up: true, type: "heavy" },
|
|
1624
|
+
// ┕
|
|
1625
|
+
9494: { right: true, up: true, type: "heavy" },
|
|
1626
|
+
// ┖
|
|
1627
|
+
9497: { left: true, up: true, type: "heavy" },
|
|
1628
|
+
// ┙
|
|
1629
|
+
9498: { left: true, up: true, type: "heavy" },
|
|
1630
|
+
// ┚
|
|
1631
|
+
9501: { up: true, down: true, right: true, type: "heavy" },
|
|
1632
|
+
// ┝
|
|
1633
|
+
9502: { up: true, down: true, right: true, type: "light" },
|
|
1634
|
+
// ┞
|
|
1635
|
+
9503: { up: true, down: true, right: true, type: "light" },
|
|
1636
|
+
// ┟
|
|
1637
|
+
9504: { up: true, down: true, right: true, type: "heavy" },
|
|
1638
|
+
// ┠
|
|
1639
|
+
9505: { up: true, down: true, right: true, type: "heavy" },
|
|
1640
|
+
// ┡
|
|
1641
|
+
9506: { up: true, down: true, right: true, type: "heavy" },
|
|
1642
|
+
// ┢
|
|
1643
|
+
9509: { up: true, down: true, left: true, type: "heavy" },
|
|
1644
|
+
// ┥
|
|
1645
|
+
9510: { up: true, down: true, left: true, type: "light" },
|
|
1646
|
+
// ┦
|
|
1647
|
+
9511: { up: true, down: true, left: true, type: "light" },
|
|
1648
|
+
// ┧
|
|
1649
|
+
9512: { up: true, down: true, left: true, type: "heavy" },
|
|
1650
|
+
// ┨
|
|
1651
|
+
9513: { up: true, down: true, left: true, type: "heavy" },
|
|
1652
|
+
// ┩
|
|
1653
|
+
9514: { up: true, down: true, left: true, type: "heavy" },
|
|
1654
|
+
// ┪
|
|
1655
|
+
9517: { left: true, right: true, down: true, type: "heavy" },
|
|
1656
|
+
// ┭
|
|
1657
|
+
9518: { left: true, right: true, down: true, type: "heavy" },
|
|
1658
|
+
// ┮
|
|
1659
|
+
9519: { left: true, right: true, down: true, type: "heavy" },
|
|
1660
|
+
// ┯
|
|
1661
|
+
9520: { left: true, right: true, down: true, type: "heavy" },
|
|
1662
|
+
// ┰
|
|
1663
|
+
9521: { left: true, right: true, down: true, type: "heavy" },
|
|
1664
|
+
// ┱
|
|
1665
|
+
9522: { left: true, right: true, down: true, type: "heavy" },
|
|
1666
|
+
// ┲
|
|
1667
|
+
9525: { left: true, right: true, up: true, type: "heavy" },
|
|
1668
|
+
// ┵
|
|
1669
|
+
9526: { left: true, right: true, up: true, type: "heavy" },
|
|
1670
|
+
// ┶
|
|
1671
|
+
9527: { left: true, right: true, up: true, type: "heavy" },
|
|
1672
|
+
// ┷
|
|
1673
|
+
9528: { left: true, right: true, up: true, type: "heavy" },
|
|
1674
|
+
// ┸
|
|
1675
|
+
9529: { left: true, right: true, up: true, type: "heavy" },
|
|
1676
|
+
// ┹
|
|
1677
|
+
9530: { left: true, right: true, up: true, type: "heavy" },
|
|
1678
|
+
// ┺
|
|
1679
|
+
9533: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1680
|
+
// ┽
|
|
1681
|
+
9534: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1682
|
+
// ┾
|
|
1683
|
+
9535: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1684
|
+
// ┿
|
|
1685
|
+
9536: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1686
|
+
// ╀
|
|
1687
|
+
9537: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1688
|
+
// ╁
|
|
1689
|
+
9538: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1690
|
+
// ╂
|
|
1691
|
+
9539: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1692
|
+
// ╃
|
|
1693
|
+
9540: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1694
|
+
// ╄
|
|
1695
|
+
9541: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1696
|
+
// ╅
|
|
1697
|
+
9542: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1698
|
+
// ╆
|
|
1699
|
+
9543: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1700
|
+
// ╇
|
|
1701
|
+
9544: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1702
|
+
// ╈
|
|
1703
|
+
9545: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1704
|
+
// ╉
|
|
1705
|
+
9546: { left: true, right: true, up: true, down: true, type: "heavy" },
|
|
1706
|
+
// ╊
|
|
1707
|
+
// Dashed lines (render as solid light/heavy)
|
|
1708
|
+
9476: { left: true, right: true, type: "light" },
|
|
1709
|
+
// ┄
|
|
1710
|
+
9477: { left: true, right: true, type: "heavy" },
|
|
1711
|
+
// ┅
|
|
1712
|
+
9478: { up: true, down: true, type: "light" },
|
|
1713
|
+
// ┆
|
|
1714
|
+
9479: { up: true, down: true, type: "heavy" },
|
|
1715
|
+
// ┇
|
|
1716
|
+
9480: { left: true, right: true, type: "light" },
|
|
1717
|
+
// ┈
|
|
1718
|
+
9481: { left: true, right: true, type: "heavy" },
|
|
1719
|
+
// ┉
|
|
1720
|
+
9482: { up: true, down: true, type: "light" },
|
|
1721
|
+
// ┊
|
|
1722
|
+
9483: { up: true, down: true, type: "heavy" },
|
|
1723
|
+
// ┋
|
|
1724
|
+
// Double lines
|
|
1725
|
+
9552: { left: true, right: true, type: "double" },
|
|
1726
|
+
// ═
|
|
1727
|
+
9553: { up: true, down: true, type: "double" },
|
|
1728
|
+
// ║
|
|
1729
|
+
9554: { right: true, down: true, type: "double" },
|
|
1730
|
+
// ╒
|
|
1731
|
+
9555: { right: true, down: true, type: "double" },
|
|
1732
|
+
// ╓
|
|
1733
|
+
9556: { right: true, down: true, type: "double" },
|
|
1734
|
+
// ╔
|
|
1735
|
+
9557: { left: true, down: true, type: "double" },
|
|
1736
|
+
// ╕
|
|
1737
|
+
9558: { left: true, down: true, type: "double" },
|
|
1738
|
+
// ╖
|
|
1739
|
+
9559: { left: true, down: true, type: "double" },
|
|
1740
|
+
// ╗
|
|
1741
|
+
9560: { right: true, up: true, type: "double" },
|
|
1742
|
+
// ╘
|
|
1743
|
+
9561: { right: true, up: true, type: "double" },
|
|
1744
|
+
// ╙
|
|
1745
|
+
9562: { right: true, up: true, type: "double" },
|
|
1746
|
+
// ╚
|
|
1747
|
+
9563: { left: true, up: true, type: "double" },
|
|
1748
|
+
// ╛
|
|
1749
|
+
9564: { left: true, up: true, type: "double" },
|
|
1750
|
+
// ╜
|
|
1751
|
+
9565: { left: true, up: true, type: "double" },
|
|
1752
|
+
// ╝
|
|
1753
|
+
9566: { up: true, down: true, right: true, type: "double" },
|
|
1754
|
+
// ╞
|
|
1755
|
+
9567: { up: true, down: true, right: true, type: "double" },
|
|
1756
|
+
// ╟
|
|
1757
|
+
9568: { up: true, down: true, right: true, type: "double" },
|
|
1758
|
+
// ╠
|
|
1759
|
+
9569: { up: true, down: true, left: true, type: "double" },
|
|
1760
|
+
// ╡
|
|
1761
|
+
9570: { up: true, down: true, left: true, type: "double" },
|
|
1762
|
+
// ╢
|
|
1763
|
+
9571: { up: true, down: true, left: true, type: "double" },
|
|
1764
|
+
// ╣
|
|
1765
|
+
9572: { left: true, right: true, down: true, type: "double" },
|
|
1766
|
+
// ╤
|
|
1767
|
+
9573: { left: true, right: true, down: true, type: "double" },
|
|
1768
|
+
// ╥
|
|
1769
|
+
9574: { left: true, right: true, down: true, type: "double" },
|
|
1770
|
+
// ╦
|
|
1771
|
+
9575: { left: true, right: true, up: true, type: "double" },
|
|
1772
|
+
// ╧
|
|
1773
|
+
9576: { left: true, right: true, up: true, type: "double" },
|
|
1774
|
+
// ╨
|
|
1775
|
+
9577: { left: true, right: true, up: true, type: "double" },
|
|
1776
|
+
// ╩
|
|
1777
|
+
9578: { left: true, right: true, up: true, down: true, type: "double" },
|
|
1778
|
+
// ╪
|
|
1779
|
+
9579: { left: true, right: true, up: true, down: true, type: "double" },
|
|
1780
|
+
// ╫
|
|
1781
|
+
9580: { left: true, right: true, up: true, down: true, type: "double" },
|
|
1782
|
+
// ╬
|
|
1783
|
+
// Rounded corners
|
|
1784
|
+
9581: { right: true, down: true, type: "light", arc: "tl" },
|
|
1785
|
+
// ╭
|
|
1786
|
+
9582: { left: true, down: true, type: "light", arc: "tr" },
|
|
1787
|
+
// ╮
|
|
1788
|
+
9583: { left: true, up: true, type: "light", arc: "br" },
|
|
1789
|
+
// ╯
|
|
1790
|
+
9584: { right: true, up: true, type: "light", arc: "bl" },
|
|
1791
|
+
// ╰
|
|
1792
|
+
// Diagonal lines (render as simple connecting lines)
|
|
1793
|
+
9585: { type: "light" },
|
|
1794
|
+
// ╱ (forward slash)
|
|
1795
|
+
9586: { type: "light" },
|
|
1796
|
+
// ╲ (backslash)
|
|
1797
|
+
9587: { type: "light" },
|
|
1798
|
+
// ╳ (cross)
|
|
1799
|
+
// Half lines
|
|
1800
|
+
9588: { left: true, type: "light" },
|
|
1801
|
+
// ╴
|
|
1802
|
+
9589: { up: true, type: "light" },
|
|
1803
|
+
// ╵
|
|
1804
|
+
9590: { right: true, type: "light" },
|
|
1805
|
+
// ╶
|
|
1806
|
+
9591: { down: true, type: "light" },
|
|
1807
|
+
// ╷
|
|
1808
|
+
9592: { left: true, type: "heavy" },
|
|
1809
|
+
// ╸
|
|
1810
|
+
9593: { up: true, type: "heavy" },
|
|
1811
|
+
// ╹
|
|
1812
|
+
9594: { right: true, type: "heavy" },
|
|
1813
|
+
// ╺
|
|
1814
|
+
9595: { down: true, type: "heavy" },
|
|
1815
|
+
// ╻
|
|
1816
|
+
9596: { left: true, right: true, type: "light" },
|
|
1817
|
+
// ╼ (light left, heavy right)
|
|
1818
|
+
9597: { up: true, down: true, type: "light" },
|
|
1819
|
+
// ╽ (light up, heavy down)
|
|
1820
|
+
9598: { left: true, right: true, type: "heavy" },
|
|
1821
|
+
// ╾ (heavy left, light right)
|
|
1822
|
+
9599: { up: true, down: true, type: "heavy" }
|
|
1823
|
+
// ╿ (heavy up, light down)
|
|
1824
|
+
};
|
|
1825
|
+
var CanvasPainter = class {
|
|
1826
|
+
cellWidth = 0;
|
|
1827
|
+
cellHeight = 0;
|
|
1828
|
+
fontFamily;
|
|
1829
|
+
fontSize;
|
|
1830
|
+
baselineOffset = 0;
|
|
1831
|
+
constructor(options = {}) {
|
|
1832
|
+
this.fontFamily = options.fontFamily ?? "'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace";
|
|
1833
|
+
this.fontSize = options.fontSize ?? 14;
|
|
1834
|
+
}
|
|
1835
|
+
measureCell(ctx) {
|
|
1836
|
+
ctx.font = `${this.fontSize}px ${this.fontFamily}`;
|
|
1837
|
+
const metrics = ctx.measureText("M");
|
|
1838
|
+
this.cellWidth = metrics.width;
|
|
1839
|
+
this.cellHeight = Math.ceil(this.fontSize * 1.4);
|
|
1840
|
+
this.baselineOffset = Math.ceil(this.fontSize * 1.1);
|
|
1841
|
+
return { width: this.cellWidth, height: this.cellHeight };
|
|
1842
|
+
}
|
|
1843
|
+
getCellSize() {
|
|
1844
|
+
return { width: this.cellWidth, height: this.cellHeight };
|
|
1845
|
+
}
|
|
1846
|
+
paint(ctx, buffer, selection) {
|
|
1847
|
+
const { char, fg: fg2, bg: bg2, attributes } = buffer;
|
|
1848
|
+
const cols = buffer.width;
|
|
1849
|
+
const rows = buffer.height;
|
|
1850
|
+
const cw = this.cellWidth;
|
|
1851
|
+
const ch = this.cellHeight;
|
|
1852
|
+
for (let row = 0; row < rows; row++) {
|
|
1853
|
+
let runStartCol = 0;
|
|
1854
|
+
let runR = -1, runG = -1, runB = -1, runA = -1;
|
|
1855
|
+
for (let col = 0; col <= cols; col++) {
|
|
1856
|
+
let r = 0, g = 0, b = 0, a = 0;
|
|
1857
|
+
if (col < cols) {
|
|
1858
|
+
const idx = row * cols + col;
|
|
1859
|
+
const offset = idx * 4;
|
|
1860
|
+
const attr = attributes[idx] & 255;
|
|
1861
|
+
const isInverse = !!(attr & TextAttributes2.INVERSE);
|
|
1862
|
+
if (isInverse) {
|
|
1863
|
+
r = fg2[offset];
|
|
1864
|
+
g = fg2[offset + 1];
|
|
1865
|
+
b = fg2[offset + 2];
|
|
1866
|
+
a = fg2[offset + 3];
|
|
1867
|
+
} else {
|
|
1868
|
+
r = bg2[offset];
|
|
1869
|
+
g = bg2[offset + 1];
|
|
1870
|
+
b = bg2[offset + 2];
|
|
1871
|
+
a = bg2[offset + 3];
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
if (col < cols && r === runR && g === runG && b === runB && a === runA) {
|
|
1875
|
+
continue;
|
|
1876
|
+
}
|
|
1877
|
+
if (runA > 0 && col > runStartCol) {
|
|
1878
|
+
ctx.fillStyle = rgbaToCSS(runR, runG, runB, runA);
|
|
1879
|
+
ctx.fillRect(runStartCol * cw, row * ch, (col - runStartCol) * cw, ch);
|
|
1880
|
+
}
|
|
1881
|
+
runStartCol = col;
|
|
1882
|
+
runR = r;
|
|
1883
|
+
runG = g;
|
|
1884
|
+
runB = b;
|
|
1885
|
+
runA = a;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
for (let row = 0; row < rows; row++) {
|
|
1889
|
+
for (let col = 0; col < cols; col++) {
|
|
1890
|
+
const idx = row * cols + col;
|
|
1891
|
+
if (attributes[idx] & CONTINUATION2) continue;
|
|
1892
|
+
const charCode = char[idx];
|
|
1893
|
+
if (charCode === 0 || charCode === 32) continue;
|
|
1894
|
+
const offset = idx * 4;
|
|
1895
|
+
const attr = attributes[idx] & 255;
|
|
1896
|
+
const isInverse = !!(attr & TextAttributes2.INVERSE);
|
|
1897
|
+
let fgR, fgG, fgB, fgA;
|
|
1898
|
+
if (isInverse) {
|
|
1899
|
+
fgR = bg2[offset];
|
|
1900
|
+
fgG = bg2[offset + 1];
|
|
1901
|
+
fgB = bg2[offset + 2];
|
|
1902
|
+
fgA = bg2[offset + 3];
|
|
1903
|
+
if (fgA === 0) {
|
|
1904
|
+
fgR = 0;
|
|
1905
|
+
fgG = 0;
|
|
1906
|
+
fgB = 0;
|
|
1907
|
+
fgA = 1;
|
|
1908
|
+
}
|
|
1909
|
+
} else {
|
|
1910
|
+
fgR = fg2[offset];
|
|
1911
|
+
fgG = fg2[offset + 1];
|
|
1912
|
+
fgB = fg2[offset + 2];
|
|
1913
|
+
fgA = fg2[offset + 3];
|
|
1914
|
+
}
|
|
1915
|
+
if (fgA === 0) continue;
|
|
1916
|
+
const isBold = !!(attr & TextAttributes2.BOLD);
|
|
1917
|
+
const isItalic = !!(attr & TextAttributes2.ITALIC);
|
|
1918
|
+
const isDim = !!(attr & TextAttributes2.DIM);
|
|
1919
|
+
const isUnderline = !!(attr & TextAttributes2.UNDERLINE);
|
|
1920
|
+
const effectiveA = isDim ? fgA * 0.5 : fgA;
|
|
1921
|
+
if (charCode >= 9472 && charCode <= 9599) {
|
|
1922
|
+
const def = BOX_DRAWING_MAP[charCode];
|
|
1923
|
+
if (def) {
|
|
1924
|
+
const cellX = col * cw;
|
|
1925
|
+
const cellY = row * ch;
|
|
1926
|
+
const cx = cellX + cw / 2;
|
|
1927
|
+
const cy = cellY + ch / 2;
|
|
1928
|
+
ctx.strokeStyle = rgbaToCSS(fgR, fgG, fgB, effectiveA);
|
|
1929
|
+
ctx.lineCap = "square";
|
|
1930
|
+
if (def.type === "double") {
|
|
1931
|
+
const gap = Math.max(2, Math.round(cw / 5));
|
|
1932
|
+
ctx.lineWidth = 1;
|
|
1933
|
+
ctx.beginPath();
|
|
1934
|
+
if (def.left) {
|
|
1935
|
+
ctx.moveTo(cellX, cy - gap / 2);
|
|
1936
|
+
ctx.lineTo(cx, cy - gap / 2);
|
|
1937
|
+
ctx.moveTo(cellX, cy + gap / 2);
|
|
1938
|
+
ctx.lineTo(cx, cy + gap / 2);
|
|
1939
|
+
}
|
|
1940
|
+
if (def.right) {
|
|
1941
|
+
ctx.moveTo(cx, cy - gap / 2);
|
|
1942
|
+
ctx.lineTo(cellX + cw, cy - gap / 2);
|
|
1943
|
+
ctx.moveTo(cx, cy + gap / 2);
|
|
1944
|
+
ctx.lineTo(cellX + cw, cy + gap / 2);
|
|
1945
|
+
}
|
|
1946
|
+
if (def.up) {
|
|
1947
|
+
ctx.moveTo(cx - gap / 2, cellY);
|
|
1948
|
+
ctx.lineTo(cx - gap / 2, cy);
|
|
1949
|
+
ctx.moveTo(cx + gap / 2, cellY);
|
|
1950
|
+
ctx.lineTo(cx + gap / 2, cy);
|
|
1951
|
+
}
|
|
1952
|
+
if (def.down) {
|
|
1953
|
+
ctx.moveTo(cx - gap / 2, cy);
|
|
1954
|
+
ctx.lineTo(cx - gap / 2, cellY + ch);
|
|
1955
|
+
ctx.moveTo(cx + gap / 2, cy);
|
|
1956
|
+
ctx.lineTo(cx + gap / 2, cellY + ch);
|
|
1957
|
+
}
|
|
1958
|
+
ctx.stroke();
|
|
1959
|
+
} else if (def.arc) {
|
|
1960
|
+
const rx = cw / 2;
|
|
1961
|
+
const ry = ch / 2;
|
|
1962
|
+
ctx.lineWidth = 1;
|
|
1963
|
+
ctx.beginPath();
|
|
1964
|
+
if (def.arc === "tl") {
|
|
1965
|
+
ctx.ellipse(cellX + cw, cellY + ch, rx, ry, 0, Math.PI, Math.PI * 1.5);
|
|
1966
|
+
} else if (def.arc === "tr") {
|
|
1967
|
+
ctx.ellipse(cellX, cellY + ch, rx, ry, 0, Math.PI * 1.5, Math.PI * 2);
|
|
1968
|
+
} else if (def.arc === "bl") {
|
|
1969
|
+
ctx.ellipse(cellX + cw, cellY, rx, ry, 0, Math.PI * 0.5, Math.PI);
|
|
1970
|
+
} else if (def.arc === "br") {
|
|
1971
|
+
ctx.ellipse(cellX, cellY, rx, ry, 0, 0, Math.PI * 0.5);
|
|
1972
|
+
}
|
|
1973
|
+
ctx.stroke();
|
|
1974
|
+
} else if (charCode === 9585 || charCode === 9586 || charCode === 9587) {
|
|
1975
|
+
ctx.lineWidth = 1;
|
|
1976
|
+
ctx.beginPath();
|
|
1977
|
+
if (charCode === 9585 || charCode === 9587) {
|
|
1978
|
+
ctx.moveTo(cellX + cw, cellY);
|
|
1979
|
+
ctx.lineTo(cellX, cellY + ch);
|
|
1980
|
+
}
|
|
1981
|
+
if (charCode === 9586 || charCode === 9587) {
|
|
1982
|
+
ctx.moveTo(cellX, cellY);
|
|
1983
|
+
ctx.lineTo(cellX + cw, cellY + ch);
|
|
1984
|
+
}
|
|
1985
|
+
ctx.stroke();
|
|
1986
|
+
} else {
|
|
1987
|
+
ctx.lineWidth = def.type === "heavy" ? 2 : 1;
|
|
1988
|
+
ctx.beginPath();
|
|
1989
|
+
if (def.left) {
|
|
1990
|
+
ctx.moveTo(cellX, cy);
|
|
1991
|
+
ctx.lineTo(cx, cy);
|
|
1992
|
+
}
|
|
1993
|
+
if (def.right) {
|
|
1994
|
+
ctx.moveTo(cx, cy);
|
|
1995
|
+
ctx.lineTo(cellX + cw, cy);
|
|
1996
|
+
}
|
|
1997
|
+
if (def.up) {
|
|
1998
|
+
ctx.moveTo(cx, cellY);
|
|
1999
|
+
ctx.lineTo(cx, cy);
|
|
2000
|
+
}
|
|
2001
|
+
if (def.down) {
|
|
2002
|
+
ctx.moveTo(cx, cy);
|
|
2003
|
+
ctx.lineTo(cx, cellY + ch);
|
|
2004
|
+
}
|
|
2005
|
+
ctx.stroke();
|
|
2006
|
+
}
|
|
2007
|
+
continue;
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
ctx.fillStyle = rgbaToCSS(fgR, fgG, fgB, effectiveA);
|
|
2011
|
+
let fontStyle = "";
|
|
2012
|
+
if (isItalic) fontStyle += "italic ";
|
|
2013
|
+
if (isBold) fontStyle += "bold ";
|
|
2014
|
+
fontStyle += `${this.fontSize}px ${this.fontFamily}`;
|
|
2015
|
+
ctx.font = fontStyle;
|
|
2016
|
+
const character = String.fromCodePoint(charCode);
|
|
2017
|
+
const x = col * cw;
|
|
2018
|
+
const y = row * this.cellHeight + this.baselineOffset;
|
|
2019
|
+
ctx.fillText(character, x, y);
|
|
2020
|
+
if (isUnderline) {
|
|
2021
|
+
const isDashed = !!(attr & TextAttributes2.UNDERLINE_DASHED);
|
|
2022
|
+
const isDotted = !!(attr & TextAttributes2.UNDERLINE_DOTTED);
|
|
2023
|
+
ctx.strokeStyle = ctx.fillStyle;
|
|
2024
|
+
ctx.lineWidth = 1;
|
|
2025
|
+
const underlineY = row * this.cellHeight + this.baselineOffset + 2;
|
|
2026
|
+
if (isDotted) {
|
|
2027
|
+
ctx.lineCap = "round";
|
|
2028
|
+
ctx.setLineDash([0.5, 2.5]);
|
|
2029
|
+
} else if (isDashed) {
|
|
2030
|
+
ctx.setLineDash([2, 2]);
|
|
2031
|
+
}
|
|
2032
|
+
ctx.beginPath();
|
|
2033
|
+
ctx.moveTo(x, underlineY);
|
|
2034
|
+
ctx.lineTo(x + cw, underlineY);
|
|
2035
|
+
ctx.stroke();
|
|
2036
|
+
if (isDotted || isDashed) {
|
|
2037
|
+
ctx.setLineDash([]);
|
|
2038
|
+
ctx.lineCap = "butt";
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
if (selection?.active) {
|
|
2044
|
+
ctx.fillStyle = "rgba(51, 153, 255, 0.3)";
|
|
2045
|
+
for (let row = 0; row < rows; row++) {
|
|
2046
|
+
let runStart = -1;
|
|
2047
|
+
for (let col = 0; col <= cols; col++) {
|
|
2048
|
+
const selected = col < cols && selection.isSelected(col, row);
|
|
2049
|
+
if (selected && runStart === -1) {
|
|
2050
|
+
runStart = col;
|
|
2051
|
+
} else if (!selected && runStart !== -1) {
|
|
2052
|
+
ctx.fillRect(runStart * cw, row * ch, (col - runStart) * cw, ch);
|
|
2053
|
+
runStart = -1;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
2060
|
+
function rgbaToCSS(r, g, b, a) {
|
|
2061
|
+
const ri = Math.round(r * 255);
|
|
2062
|
+
const gi = Math.round(g * 255);
|
|
2063
|
+
const bi = Math.round(b * 255);
|
|
2064
|
+
return `rgba(${ri},${gi},${bi},${a})`;
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
// src/selection-manager.ts
|
|
2068
|
+
var SelectionManager = class {
|
|
2069
|
+
_startCol = 0;
|
|
2070
|
+
_startRow = 0;
|
|
2071
|
+
_endCol = 0;
|
|
2072
|
+
_endRow = 0;
|
|
2073
|
+
_active = false;
|
|
2074
|
+
_selecting = false;
|
|
2075
|
+
startSelection(col, row) {
|
|
2076
|
+
this._startCol = col;
|
|
2077
|
+
this._startRow = row;
|
|
2078
|
+
this._endCol = col;
|
|
2079
|
+
this._endRow = row;
|
|
2080
|
+
this._selecting = true;
|
|
2081
|
+
this._active = true;
|
|
2082
|
+
}
|
|
2083
|
+
updateSelection(col, row) {
|
|
2084
|
+
if (!this._selecting) return;
|
|
2085
|
+
this._endCol = col;
|
|
2086
|
+
this._endRow = row;
|
|
2087
|
+
}
|
|
2088
|
+
endSelection() {
|
|
2089
|
+
this._selecting = false;
|
|
2090
|
+
if (this._startCol === this._endCol && this._startRow === this._endRow) {
|
|
2091
|
+
this._active = false;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
clearSelection() {
|
|
2095
|
+
this._active = false;
|
|
2096
|
+
this._selecting = false;
|
|
2097
|
+
}
|
|
2098
|
+
get active() {
|
|
2099
|
+
return this._active;
|
|
2100
|
+
}
|
|
2101
|
+
get selecting() {
|
|
2102
|
+
return this._selecting;
|
|
2103
|
+
}
|
|
2104
|
+
/** Returns the selection range normalized to reading order (top-left to bottom-right) */
|
|
2105
|
+
getSelectedRange() {
|
|
2106
|
+
if (!this._active) return null;
|
|
2107
|
+
let startCol = this._startCol;
|
|
2108
|
+
let startRow = this._startRow;
|
|
2109
|
+
let endCol = this._endCol;
|
|
2110
|
+
let endRow = this._endRow;
|
|
2111
|
+
if (startRow > endRow || startRow === endRow && startCol > endCol) {
|
|
2112
|
+
const tmpCol = startCol;
|
|
2113
|
+
const tmpRow = startRow;
|
|
2114
|
+
startCol = endCol;
|
|
2115
|
+
startRow = endRow;
|
|
2116
|
+
endCol = tmpCol;
|
|
2117
|
+
endRow = tmpRow;
|
|
2118
|
+
}
|
|
2119
|
+
return { startCol, startRow, endCol, endRow };
|
|
2120
|
+
}
|
|
2121
|
+
isSelected(col, row) {
|
|
2122
|
+
const range = this.getSelectedRange();
|
|
2123
|
+
if (!range) return false;
|
|
2124
|
+
const { startCol, startRow, endCol, endRow } = range;
|
|
2125
|
+
if (row < startRow || row > endRow) return false;
|
|
2126
|
+
if (startRow === endRow) {
|
|
2127
|
+
return col >= startCol && col < endCol;
|
|
2128
|
+
}
|
|
2129
|
+
if (row === startRow) return col >= startCol;
|
|
2130
|
+
if (row === endRow) return col < endCol;
|
|
2131
|
+
return true;
|
|
2132
|
+
}
|
|
2133
|
+
getSelectedText(buffer) {
|
|
2134
|
+
const range = this.getSelectedRange();
|
|
2135
|
+
if (!range) return "";
|
|
2136
|
+
const { startCol, startRow, endCol, endRow } = range;
|
|
2137
|
+
const lines = [];
|
|
2138
|
+
for (let row = startRow; row <= endRow; row++) {
|
|
2139
|
+
let lineStart = row === startRow ? startCol : 0;
|
|
2140
|
+
let lineEnd = row === endRow ? endCol : buffer.width;
|
|
2141
|
+
let line = "";
|
|
2142
|
+
for (let col = lineStart; col < lineEnd && col < buffer.width; col++) {
|
|
2143
|
+
const idx = row * buffer.width + col;
|
|
2144
|
+
const charCode = buffer.char[idx];
|
|
2145
|
+
line += charCode === 0 ? " " : String.fromCodePoint(charCode);
|
|
2146
|
+
}
|
|
2147
|
+
lines.push(line.trimEnd());
|
|
2148
|
+
}
|
|
2149
|
+
return lines.join("\n");
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
|
|
2153
|
+
// src/browser-renderer.ts
|
|
2154
|
+
var RootRenderableClass = null;
|
|
2155
|
+
function setRootRenderableClass(cls) {
|
|
2156
|
+
RootRenderableClass = cls;
|
|
2157
|
+
}
|
|
2158
|
+
var BrowserRenderer = class _BrowserRenderer {
|
|
2159
|
+
canvas;
|
|
2160
|
+
ctx2d;
|
|
2161
|
+
buffer;
|
|
2162
|
+
renderContext;
|
|
2163
|
+
root;
|
|
2164
|
+
// RootRenderable
|
|
2165
|
+
painter;
|
|
2166
|
+
selection;
|
|
2167
|
+
cols;
|
|
2168
|
+
rows;
|
|
2169
|
+
cellWidth = 0;
|
|
2170
|
+
cellHeight = 0;
|
|
2171
|
+
rafId = null;
|
|
2172
|
+
lastTime = 0;
|
|
2173
|
+
needsRender = true;
|
|
2174
|
+
isDragOver = false;
|
|
2175
|
+
cleanupListeners = [];
|
|
2176
|
+
mouseDownCell = null;
|
|
2177
|
+
constructor(canvas, cols, rows) {
|
|
2178
|
+
this.canvas = canvas;
|
|
2179
|
+
this.cols = cols;
|
|
2180
|
+
this.rows = rows;
|
|
2181
|
+
const ctx2d = canvas.getContext("2d");
|
|
2182
|
+
if (!ctx2d) throw new Error("Could not get 2d context");
|
|
2183
|
+
this.ctx2d = ctx2d;
|
|
2184
|
+
this.painter = new CanvasPainter();
|
|
2185
|
+
const cellSize = this.painter.measureCell(this.ctx2d);
|
|
2186
|
+
this.cellWidth = cellSize.width;
|
|
2187
|
+
this.cellHeight = cellSize.height;
|
|
2188
|
+
const dpr = window.devicePixelRatio || 1;
|
|
2189
|
+
canvas.width = Math.ceil(cols * this.cellWidth * dpr);
|
|
2190
|
+
canvas.height = Math.ceil(rows * this.cellHeight * dpr);
|
|
2191
|
+
canvas.style.width = `${cols * this.cellWidth}px`;
|
|
2192
|
+
canvas.style.height = `${rows * this.cellHeight}px`;
|
|
2193
|
+
this.ctx2d.scale(dpr, dpr);
|
|
2194
|
+
canvas.style.cursor = "text";
|
|
2195
|
+
this.buffer = BrowserBuffer.create(cols, rows, "wcwidth");
|
|
2196
|
+
this.renderContext = new BrowserRenderContext(cols, rows);
|
|
2197
|
+
this.renderContext.setOnRenderRequest(() => {
|
|
2198
|
+
this.needsRender = true;
|
|
2199
|
+
});
|
|
2200
|
+
this.selection = new SelectionManager();
|
|
2201
|
+
if (!RootRenderableClass) {
|
|
2202
|
+
throw new Error("RootRenderableClass not set. Call setRootRenderableClass before creating BrowserRenderer.");
|
|
2203
|
+
}
|
|
2204
|
+
this.root = new RootRenderableClass(this.renderContext);
|
|
2205
|
+
this.setupDomListeners();
|
|
2206
|
+
}
|
|
2207
|
+
pixelToCell(clientX, clientY) {
|
|
2208
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
2209
|
+
const x = clientX - rect.left;
|
|
2210
|
+
const y = clientY - rect.top;
|
|
2211
|
+
const col = Math.floor(x / this.cellWidth);
|
|
2212
|
+
const row = Math.floor(y / this.cellHeight);
|
|
2213
|
+
return {
|
|
2214
|
+
col: Math.max(0, Math.min(col, this.cols - 1)),
|
|
2215
|
+
row: Math.max(0, Math.min(row, this.rows - 1))
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2218
|
+
setupDomListeners() {
|
|
2219
|
+
const onDragOver = (e) => {
|
|
2220
|
+
e.preventDefault();
|
|
2221
|
+
};
|
|
2222
|
+
this.canvas.addEventListener("dragover", onDragOver);
|
|
2223
|
+
this.cleanupListeners.push(() => this.canvas.removeEventListener("dragover", onDragOver));
|
|
2224
|
+
const onDrop = (e) => {
|
|
2225
|
+
e.preventDefault();
|
|
2226
|
+
const files = e.dataTransfer?.files;
|
|
2227
|
+
if (!files || files.length === 0) return;
|
|
2228
|
+
const file = files[0];
|
|
2229
|
+
this.isDragOver = false;
|
|
2230
|
+
this.renderContext.emit("drag-leave", void 0);
|
|
2231
|
+
file.text().then((content) => {
|
|
2232
|
+
this.renderContext.emit("file-drop", {
|
|
2233
|
+
name: file.name,
|
|
2234
|
+
content,
|
|
2235
|
+
type: file.type,
|
|
2236
|
+
size: file.size
|
|
2237
|
+
});
|
|
2238
|
+
});
|
|
2239
|
+
};
|
|
2240
|
+
this.canvas.addEventListener("drop", onDrop);
|
|
2241
|
+
this.cleanupListeners.push(() => this.canvas.removeEventListener("drop", onDrop));
|
|
2242
|
+
const onMouseDown = (e) => {
|
|
2243
|
+
if (e.button !== 0) return;
|
|
2244
|
+
this.canvas.focus();
|
|
2245
|
+
const { col, row } = this.pixelToCell(e.clientX, e.clientY);
|
|
2246
|
+
this.mouseDownCell = { col, row };
|
|
2247
|
+
this.selection.startSelection(col, row);
|
|
2248
|
+
this.needsRender = true;
|
|
2249
|
+
};
|
|
2250
|
+
this.canvas.addEventListener("mousedown", onMouseDown);
|
|
2251
|
+
this.cleanupListeners.push(() => this.canvas.removeEventListener("mousedown", onMouseDown));
|
|
2252
|
+
const onMouseMove = (e) => {
|
|
2253
|
+
const { col, row } = this.pixelToCell(e.clientX, e.clientY);
|
|
2254
|
+
const idx = row * this.buffer.width + col;
|
|
2255
|
+
if (idx >= 0 && idx < this.buffer.attributes.length) {
|
|
2256
|
+
const linkId = getLinkId(this.buffer.attributes[idx]);
|
|
2257
|
+
this.canvas.style.cursor = linkId > 0 ? "pointer" : "text";
|
|
2258
|
+
}
|
|
2259
|
+
if (!this.selection.selecting) return;
|
|
2260
|
+
this.selection.updateSelection(col, row);
|
|
2261
|
+
this.needsRender = true;
|
|
2262
|
+
};
|
|
2263
|
+
this.canvas.addEventListener("mousemove", onMouseMove);
|
|
2264
|
+
this.cleanupListeners.push(() => this.canvas.removeEventListener("mousemove", onMouseMove));
|
|
2265
|
+
const onMouseUp = (e) => {
|
|
2266
|
+
const wasSelecting = this.selection.selecting;
|
|
2267
|
+
if (wasSelecting) {
|
|
2268
|
+
this.selection.endSelection();
|
|
2269
|
+
this.needsRender = true;
|
|
2270
|
+
}
|
|
2271
|
+
if (e.button === 0 && this.mouseDownCell) {
|
|
2272
|
+
const { col, row } = this.pixelToCell(e.clientX, e.clientY);
|
|
2273
|
+
if (col === this.mouseDownCell.col && row === this.mouseDownCell.row) {
|
|
2274
|
+
const idx = row * this.buffer.width + col;
|
|
2275
|
+
if (idx >= 0 && idx < this.buffer.attributes.length) {
|
|
2276
|
+
const attr = this.buffer.attributes[idx];
|
|
2277
|
+
const linkId = getLinkId(attr);
|
|
2278
|
+
if (linkId > 0) {
|
|
2279
|
+
const url = this.buffer.getLinkUrl(linkId);
|
|
2280
|
+
if (url) {
|
|
2281
|
+
window.open(url, "_blank");
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
this.mouseDownCell = null;
|
|
2287
|
+
}
|
|
2288
|
+
};
|
|
2289
|
+
window.addEventListener("mouseup", onMouseUp);
|
|
2290
|
+
this.cleanupListeners.push(() => window.removeEventListener("mouseup", onMouseUp));
|
|
2291
|
+
const onDragEnter = (e) => {
|
|
2292
|
+
e.preventDefault();
|
|
2293
|
+
if (this.isDragOver) return;
|
|
2294
|
+
this.isDragOver = true;
|
|
2295
|
+
this.renderContext.emit("drag-enter", void 0);
|
|
2296
|
+
this.needsRender = true;
|
|
2297
|
+
};
|
|
2298
|
+
this.canvas.addEventListener("dragenter", onDragEnter);
|
|
2299
|
+
this.cleanupListeners.push(() => this.canvas.removeEventListener("dragenter", onDragEnter));
|
|
2300
|
+
const onDragLeave = (e) => {
|
|
2301
|
+
if (e.relatedTarget && this.canvas.contains(e.relatedTarget)) return;
|
|
2302
|
+
this.isDragOver = false;
|
|
2303
|
+
this.renderContext.emit("drag-leave", void 0);
|
|
2304
|
+
this.needsRender = true;
|
|
2305
|
+
};
|
|
2306
|
+
this.canvas.addEventListener("dragleave", onDragLeave);
|
|
2307
|
+
this.cleanupListeners.push(() => this.canvas.removeEventListener("dragleave", onDragLeave));
|
|
2308
|
+
const onPaste = (e) => {
|
|
2309
|
+
if (document.activeElement !== this.canvas) return;
|
|
2310
|
+
const text = e.clipboardData?.getData("text/plain");
|
|
2311
|
+
if (text) {
|
|
2312
|
+
e.preventDefault();
|
|
2313
|
+
this.renderContext.emit("paste", text);
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
2316
|
+
document.addEventListener("paste", onPaste);
|
|
2317
|
+
this.cleanupListeners.push(() => document.removeEventListener("paste", onPaste));
|
|
2318
|
+
}
|
|
2319
|
+
start() {
|
|
2320
|
+
this.lastTime = performance.now();
|
|
2321
|
+
this.loop();
|
|
2322
|
+
}
|
|
2323
|
+
stop() {
|
|
2324
|
+
if (this.rafId !== null) {
|
|
2325
|
+
cancelAnimationFrame(this.rafId);
|
|
2326
|
+
this.rafId = null;
|
|
2327
|
+
}
|
|
2328
|
+
for (const cleanup of this.cleanupListeners) {
|
|
2329
|
+
cleanup();
|
|
2330
|
+
}
|
|
2331
|
+
this.cleanupListeners = [];
|
|
2332
|
+
}
|
|
2333
|
+
loop = () => {
|
|
2334
|
+
this.rafId = requestAnimationFrame(this.loop);
|
|
2335
|
+
const now = performance.now();
|
|
2336
|
+
const deltaTime = now - this.lastTime;
|
|
2337
|
+
this.lastTime = now;
|
|
2338
|
+
if (!this.needsRender) return;
|
|
2339
|
+
this.needsRender = false;
|
|
2340
|
+
this.buffer.clear();
|
|
2341
|
+
const lifecyclePasses = this.renderContext.getLifecyclePasses();
|
|
2342
|
+
for (const renderable of lifecyclePasses) {
|
|
2343
|
+
if (renderable.onLifecyclePass) {
|
|
2344
|
+
renderable.onLifecyclePass();
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
this.root.calculateLayout();
|
|
2348
|
+
const renderList = [];
|
|
2349
|
+
this.root.updateLayout(deltaTime, renderList);
|
|
2350
|
+
for (const cmd of renderList) {
|
|
2351
|
+
switch (cmd.action) {
|
|
2352
|
+
case "pushScissorRect":
|
|
2353
|
+
this.buffer.pushScissorRect(cmd.x, cmd.y, cmd.width, cmd.height);
|
|
2354
|
+
break;
|
|
2355
|
+
case "popScissorRect":
|
|
2356
|
+
this.buffer.popScissorRect();
|
|
2357
|
+
break;
|
|
2358
|
+
case "pushOpacity":
|
|
2359
|
+
this.buffer.pushOpacity(cmd.opacity);
|
|
2360
|
+
break;
|
|
2361
|
+
case "popOpacity":
|
|
2362
|
+
this.buffer.popOpacity();
|
|
2363
|
+
break;
|
|
2364
|
+
case "render":
|
|
2365
|
+
cmd.renderable.render(this.buffer, deltaTime);
|
|
2366
|
+
break;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
this.buffer.clearScissorRects();
|
|
2370
|
+
this.buffer.clearOpacity();
|
|
2371
|
+
const dpr = window.devicePixelRatio || 1;
|
|
2372
|
+
this.ctx2d.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
2373
|
+
this.ctx2d.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
2374
|
+
this.painter.paint(this.ctx2d, this.buffer, this.selection);
|
|
2375
|
+
};
|
|
2376
|
+
resize(cols, rows) {
|
|
2377
|
+
this.cols = cols;
|
|
2378
|
+
this.rows = rows;
|
|
2379
|
+
const dpr = window.devicePixelRatio || 1;
|
|
2380
|
+
this.canvas.width = Math.ceil(cols * this.cellWidth * dpr);
|
|
2381
|
+
this.canvas.height = Math.ceil(rows * this.cellHeight * dpr);
|
|
2382
|
+
this.canvas.style.width = `${cols * this.cellWidth}px`;
|
|
2383
|
+
this.canvas.style.height = `${rows * this.cellHeight}px`;
|
|
2384
|
+
this.ctx2d.scale(dpr, dpr);
|
|
2385
|
+
this.buffer.resize(cols, rows);
|
|
2386
|
+
this.renderContext.resize(cols, rows);
|
|
2387
|
+
this.root.resize(cols, rows);
|
|
2388
|
+
this.needsRender = true;
|
|
2389
|
+
}
|
|
2390
|
+
static PREVENT_DEFAULT_KEYS = /* @__PURE__ */ new Set([
|
|
2391
|
+
"ArrowUp",
|
|
2392
|
+
"ArrowDown",
|
|
2393
|
+
"ArrowLeft",
|
|
2394
|
+
"ArrowRight",
|
|
2395
|
+
" ",
|
|
2396
|
+
"PageUp",
|
|
2397
|
+
"PageDown",
|
|
2398
|
+
"Tab",
|
|
2399
|
+
"Home",
|
|
2400
|
+
"End"
|
|
2401
|
+
]);
|
|
2402
|
+
static MODIFIER_KEYS = /* @__PURE__ */ new Set(["Alt", "Control", "Meta", "Shift"]);
|
|
2403
|
+
static KEY_MAP = {
|
|
2404
|
+
ArrowUp: "up",
|
|
2405
|
+
ArrowDown: "down",
|
|
2406
|
+
ArrowLeft: "left",
|
|
2407
|
+
ArrowRight: "right",
|
|
2408
|
+
Enter: "return",
|
|
2409
|
+
Backspace: "backspace",
|
|
2410
|
+
Delete: "delete",
|
|
2411
|
+
Tab: "tab",
|
|
2412
|
+
Escape: "escape",
|
|
2413
|
+
Home: "home",
|
|
2414
|
+
End: "end",
|
|
2415
|
+
" ": "space",
|
|
2416
|
+
PageUp: "pageup",
|
|
2417
|
+
PageDown: "pagedown"
|
|
2418
|
+
};
|
|
2419
|
+
handleKeyDown(event) {
|
|
2420
|
+
if (_BrowserRenderer.PREVENT_DEFAULT_KEYS.has(event.key)) {
|
|
2421
|
+
event.preventDefault();
|
|
2422
|
+
}
|
|
2423
|
+
if (this.selection.active && (event.key === "c" || event.key === "\xE7") && (event.metaKey || event.ctrlKey || event.altKey)) {
|
|
2424
|
+
const text = this.selection.getSelectedText(this.buffer);
|
|
2425
|
+
if (text) {
|
|
2426
|
+
navigator.clipboard.writeText(text).catch(() => {
|
|
2427
|
+
const ta = document.createElement("textarea");
|
|
2428
|
+
ta.value = text;
|
|
2429
|
+
ta.style.position = "fixed";
|
|
2430
|
+
ta.style.left = "-9999px";
|
|
2431
|
+
document.body.appendChild(ta);
|
|
2432
|
+
ta.select();
|
|
2433
|
+
document.execCommand("copy");
|
|
2434
|
+
document.body.removeChild(ta);
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
event.preventDefault();
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
const modifierOnly = _BrowserRenderer.MODIFIER_KEYS.has(event.key);
|
|
2441
|
+
if (this.selection.active && !modifierOnly) {
|
|
2442
|
+
this.selection.clearSelection();
|
|
2443
|
+
this.needsRender = true;
|
|
2444
|
+
}
|
|
2445
|
+
const keyEvent = {
|
|
2446
|
+
name: _BrowserRenderer.KEY_MAP[event.key] ?? (event.key.length === 1 ? event.key : event.key.toLowerCase()),
|
|
2447
|
+
ctrl: event.ctrlKey,
|
|
2448
|
+
meta: event.metaKey,
|
|
2449
|
+
shift: event.shiftKey,
|
|
2450
|
+
option: event.altKey,
|
|
2451
|
+
sequence: event.key,
|
|
2452
|
+
number: false,
|
|
2453
|
+
raw: event.key,
|
|
2454
|
+
eventType: "press",
|
|
2455
|
+
source: "raw",
|
|
2456
|
+
_defaultPrevented: false,
|
|
2457
|
+
_propagationStopped: false,
|
|
2458
|
+
get defaultPrevented() {
|
|
2459
|
+
return this._defaultPrevented;
|
|
2460
|
+
},
|
|
2461
|
+
get propagationStopped() {
|
|
2462
|
+
return this._propagationStopped;
|
|
2463
|
+
},
|
|
2464
|
+
preventDefault() {
|
|
2465
|
+
this._defaultPrevented = true;
|
|
2466
|
+
},
|
|
2467
|
+
stopPropagation() {
|
|
2468
|
+
this._propagationStopped = true;
|
|
2469
|
+
}
|
|
2470
|
+
};
|
|
2471
|
+
this.renderContext._internalKeyInput.emit("keypress", keyEvent);
|
|
2472
|
+
this.renderContext.keyInput.emit("keypress", keyEvent);
|
|
2473
|
+
}
|
|
2474
|
+
};
|
|
2475
|
+
|
|
2476
|
+
// src/browser-context.ts
|
|
2477
|
+
import { createContext, useContext } from "react";
|
|
2478
|
+
var BrowserContext = createContext(null);
|
|
2479
|
+
function useBrowserContext() {
|
|
2480
|
+
const ctx = useContext(BrowserContext);
|
|
2481
|
+
if (!ctx) {
|
|
2482
|
+
throw new Error("useBrowserContext must be used within a BrowserContext.Provider");
|
|
2483
|
+
}
|
|
2484
|
+
return ctx;
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
// src/create-browser-root.tsx
|
|
2488
|
+
import { _render } from "../../../opentui/packages/react/src/reconciler/reconciler";
|
|
2489
|
+
import { AppContext } from "../../../opentui/packages/react/src/components/app";
|
|
2490
|
+
import { ErrorBoundary } from "../../../opentui/packages/react/src/components/error-boundary";
|
|
2491
|
+
import { jsx } from "react/jsx-runtime";
|
|
2492
|
+
function createBrowserRoot(renderer) {
|
|
2493
|
+
let unmountFn = null;
|
|
2494
|
+
return {
|
|
2495
|
+
render(node) {
|
|
2496
|
+
const element = /* @__PURE__ */ jsx(BrowserContext.Provider, { value: { renderContext: renderer.renderContext }, children: /* @__PURE__ */ jsx(AppContext.Provider, { value: { keyHandler: renderer.renderContext.keyInput, renderer: null }, children: /* @__PURE__ */ jsx(ErrorBoundary, { children: node }) }) });
|
|
2497
|
+
unmountFn = _render(element, renderer.root);
|
|
2498
|
+
},
|
|
2499
|
+
unmount() {
|
|
2500
|
+
if (unmountFn) {
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
// src/TUI.tsx
|
|
2507
|
+
import { RootRenderable as RootRenderable2 } from "@opentui/core";
|
|
2508
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
2509
|
+
function TUI({
|
|
2510
|
+
children,
|
|
2511
|
+
style,
|
|
2512
|
+
className,
|
|
2513
|
+
fontSize = 14,
|
|
2514
|
+
fontFamily = "'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace",
|
|
2515
|
+
autoFocus = true,
|
|
2516
|
+
onReady
|
|
2517
|
+
}) {
|
|
2518
|
+
const containerRef = useRef(null);
|
|
2519
|
+
const canvasRef = useRef(null);
|
|
2520
|
+
const rendererRef = useRef(null);
|
|
2521
|
+
const rootRef = useRef(null);
|
|
2522
|
+
const [isClient, setIsClient] = useState(false);
|
|
2523
|
+
useEffect(() => {
|
|
2524
|
+
setIsClient(true);
|
|
2525
|
+
}, []);
|
|
2526
|
+
useEffect(() => {
|
|
2527
|
+
if (!isClient) return;
|
|
2528
|
+
const canvas = canvasRef.current;
|
|
2529
|
+
const container = containerRef.current;
|
|
2530
|
+
if (!canvas || !container) return;
|
|
2531
|
+
setRootRenderableClass(RootRenderable2);
|
|
2532
|
+
const painter = new CanvasPainter({ fontSize, fontFamily });
|
|
2533
|
+
const tempCtx = canvas.getContext("2d");
|
|
2534
|
+
const cellSize = painter.measureCell(tempCtx);
|
|
2535
|
+
const containerRect = container.getBoundingClientRect();
|
|
2536
|
+
const cols = Math.max(1, Math.floor(containerRect.width / cellSize.width));
|
|
2537
|
+
const rows = Math.max(1, Math.floor(containerRect.height / cellSize.height));
|
|
2538
|
+
const renderer = new BrowserRenderer(canvas, cols, rows);
|
|
2539
|
+
rendererRef.current = renderer;
|
|
2540
|
+
const root = createBrowserRoot(renderer);
|
|
2541
|
+
rootRef.current = root;
|
|
2542
|
+
root.render(children);
|
|
2543
|
+
renderer.start();
|
|
2544
|
+
canvas.tabIndex = 0;
|
|
2545
|
+
if (autoFocus) {
|
|
2546
|
+
canvas.focus();
|
|
2547
|
+
}
|
|
2548
|
+
onReady?.(renderer);
|
|
2549
|
+
const onKeyDown = (e) => {
|
|
2550
|
+
renderer.handleKeyDown(e);
|
|
2551
|
+
};
|
|
2552
|
+
canvas.addEventListener("keydown", onKeyDown);
|
|
2553
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
2554
|
+
for (const entry of entries) {
|
|
2555
|
+
const { width, height } = entry.contentRect;
|
|
2556
|
+
const newCols = Math.max(1, Math.floor(width / cellSize.width));
|
|
2557
|
+
const newRows = Math.max(1, Math.floor(height / cellSize.height));
|
|
2558
|
+
renderer.resize(newCols, newRows);
|
|
2559
|
+
}
|
|
2560
|
+
});
|
|
2561
|
+
resizeObserver.observe(container);
|
|
2562
|
+
return () => {
|
|
2563
|
+
canvas.removeEventListener("keydown", onKeyDown);
|
|
2564
|
+
resizeObserver.disconnect();
|
|
2565
|
+
renderer.stop();
|
|
2566
|
+
root.unmount();
|
|
2567
|
+
rendererRef.current = null;
|
|
2568
|
+
rootRef.current = null;
|
|
2569
|
+
};
|
|
2570
|
+
}, [isClient, fontSize, fontFamily]);
|
|
2571
|
+
useEffect(() => {
|
|
2572
|
+
if (rootRef.current) {
|
|
2573
|
+
rootRef.current.render(children);
|
|
2574
|
+
}
|
|
2575
|
+
}, [children]);
|
|
2576
|
+
if (!isClient) {
|
|
2577
|
+
return /* @__PURE__ */ jsx2("div", { style, className, children: /* @__PURE__ */ jsx2("div", { style: { width: "100%", height: "100%" } }) });
|
|
2578
|
+
}
|
|
2579
|
+
return /* @__PURE__ */ jsx2(
|
|
2580
|
+
"div",
|
|
2581
|
+
{
|
|
2582
|
+
ref: containerRef,
|
|
2583
|
+
style: {
|
|
2584
|
+
position: "relative",
|
|
2585
|
+
overflow: "hidden",
|
|
2586
|
+
...style
|
|
2587
|
+
},
|
|
2588
|
+
className,
|
|
2589
|
+
children: /* @__PURE__ */ jsx2(
|
|
2590
|
+
"canvas",
|
|
2591
|
+
{
|
|
2592
|
+
ref: canvasRef,
|
|
2593
|
+
style: {
|
|
2594
|
+
display: "block",
|
|
2595
|
+
width: "100%",
|
|
2596
|
+
height: "100%",
|
|
2597
|
+
outline: "none"
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
)
|
|
2601
|
+
}
|
|
2602
|
+
);
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
// src/mount.ts
|
|
2606
|
+
function mountGridland(canvas, element, options = {}) {
|
|
2607
|
+
const {
|
|
2608
|
+
fontSize = 14,
|
|
2609
|
+
fontFamily = "'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace",
|
|
2610
|
+
keyboard = true,
|
|
2611
|
+
autoResize = true
|
|
2612
|
+
} = options;
|
|
2613
|
+
const { RootRenderable: RootRenderable3 } = __require("@opentui/core");
|
|
2614
|
+
setRootRenderableClass(RootRenderable3);
|
|
2615
|
+
const painter = new CanvasPainter({ fontSize, fontFamily });
|
|
2616
|
+
const tempCtx = canvas.getContext("2d");
|
|
2617
|
+
const cellSize = painter.measureCell(tempCtx);
|
|
2618
|
+
let cols = options.cols ?? Math.max(1, Math.floor(canvas.clientWidth / cellSize.width));
|
|
2619
|
+
let rows = options.rows ?? Math.max(1, Math.floor(canvas.clientHeight / cellSize.height));
|
|
2620
|
+
const renderer = new BrowserRenderer(canvas, cols, rows);
|
|
2621
|
+
const root = createBrowserRoot(renderer);
|
|
2622
|
+
root.render(element);
|
|
2623
|
+
renderer.start();
|
|
2624
|
+
canvas.tabIndex = 0;
|
|
2625
|
+
let keydownHandler = null;
|
|
2626
|
+
if (keyboard) {
|
|
2627
|
+
keydownHandler = (e) => renderer.handleKeyDown(e);
|
|
2628
|
+
canvas.addEventListener("keydown", keydownHandler);
|
|
2629
|
+
}
|
|
2630
|
+
let resizeObserver = null;
|
|
2631
|
+
if (autoResize) {
|
|
2632
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
2633
|
+
for (const entry of entries) {
|
|
2634
|
+
const { width, height } = entry.contentRect;
|
|
2635
|
+
const newCols = Math.max(1, Math.floor(width / cellSize.width));
|
|
2636
|
+
const newRows = Math.max(1, Math.floor(height / cellSize.height));
|
|
2637
|
+
if (newCols !== cols || newRows !== rows) {
|
|
2638
|
+
cols = newCols;
|
|
2639
|
+
rows = newRows;
|
|
2640
|
+
renderer.resize(newCols, newRows);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
});
|
|
2644
|
+
resizeObserver.observe(canvas);
|
|
2645
|
+
}
|
|
2646
|
+
return {
|
|
2647
|
+
renderer,
|
|
2648
|
+
unmount() {
|
|
2649
|
+
if (keydownHandler) {
|
|
2650
|
+
canvas.removeEventListener("keydown", keydownHandler);
|
|
2651
|
+
}
|
|
2652
|
+
resizeObserver?.disconnect();
|
|
2653
|
+
renderer.stop();
|
|
2654
|
+
root.unmount();
|
|
2655
|
+
},
|
|
2656
|
+
resize(newCols, newRows) {
|
|
2657
|
+
cols = newCols;
|
|
2658
|
+
rows = newRows;
|
|
2659
|
+
renderer.resize(newCols, newRows);
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
// src/file-drop.ts
|
|
2665
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
2666
|
+
function useFileDrop(callback) {
|
|
2667
|
+
const { renderContext } = useBrowserContext();
|
|
2668
|
+
const [isDragOver, setIsDragOver] = useState2(false);
|
|
2669
|
+
useEffect2(() => {
|
|
2670
|
+
const handler = (file) => {
|
|
2671
|
+
callback(file);
|
|
2672
|
+
};
|
|
2673
|
+
const onDragEnter = () => setIsDragOver(true);
|
|
2674
|
+
const onDragLeave = () => setIsDragOver(false);
|
|
2675
|
+
renderContext.on("file-drop", handler);
|
|
2676
|
+
renderContext.on("drag-enter", onDragEnter);
|
|
2677
|
+
renderContext.on("drag-leave", onDragLeave);
|
|
2678
|
+
return () => {
|
|
2679
|
+
renderContext.off("file-drop", handler);
|
|
2680
|
+
renderContext.off("drag-enter", onDragEnter);
|
|
2681
|
+
renderContext.off("drag-leave", onDragLeave);
|
|
2682
|
+
};
|
|
2683
|
+
}, [renderContext, callback]);
|
|
2684
|
+
return { isDragOver };
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
// src/paste.ts
|
|
2688
|
+
import { useEffect as useEffect3 } from "react";
|
|
2689
|
+
function usePaste(callback) {
|
|
2690
|
+
const { renderContext } = useBrowserContext();
|
|
2691
|
+
useEffect3(() => {
|
|
2692
|
+
const handler = (text) => {
|
|
2693
|
+
callback(text);
|
|
2694
|
+
};
|
|
2695
|
+
renderContext.on("paste", handler);
|
|
2696
|
+
return () => {
|
|
2697
|
+
renderContext.off("paste", handler);
|
|
2698
|
+
};
|
|
2699
|
+
}, [renderContext, callback]);
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
// src/utils.ts
|
|
2703
|
+
function isBrowser() {
|
|
2704
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
2705
|
+
}
|
|
2706
|
+
function isCanvasSupported() {
|
|
2707
|
+
if (!isBrowser()) return false;
|
|
2708
|
+
const canvas = document.createElement("canvas");
|
|
2709
|
+
return !!canvas.getContext("2d");
|
|
2710
|
+
}
|
|
2711
|
+
function calculateGridSize(widthPx, heightPx, cellWidth, cellHeight) {
|
|
2712
|
+
return {
|
|
2713
|
+
cols: Math.max(1, Math.floor(widthPx / cellWidth)),
|
|
2714
|
+
rows: Math.max(1, Math.floor(heightPx / cellHeight))
|
|
2715
|
+
};
|
|
2716
|
+
}
|
|
2717
|
+
export {
|
|
2718
|
+
BrowserBuffer,
|
|
2719
|
+
BrowserContext,
|
|
2720
|
+
BrowserRenderContext,
|
|
2721
|
+
BrowserRenderer,
|
|
2722
|
+
BrowserSyntaxStyle,
|
|
2723
|
+
BrowserTextBuffer,
|
|
2724
|
+
BrowserTextBufferView,
|
|
2725
|
+
CanvasPainter,
|
|
2726
|
+
SelectionManager,
|
|
2727
|
+
TUI,
|
|
2728
|
+
calculateGridSize,
|
|
2729
|
+
createBrowserRoot,
|
|
2730
|
+
isBrowser,
|
|
2731
|
+
isCanvasSupported,
|
|
2732
|
+
mountGridland,
|
|
2733
|
+
useBrowserContext,
|
|
2734
|
+
useFileDrop,
|
|
2735
|
+
usePaste
|
|
2736
|
+
};
|
|
2737
|
+
//# sourceMappingURL=index.js.map
|