@vui-rs/core 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/README.md +29 -0
- package/dist/char-width.d.ts +7 -0
- package/dist/char-width.js +20 -0
- package/dist/color-names.js +46 -0
- package/dist/color.d.ts +5 -0
- package/dist/color.js +57 -0
- package/dist/image-decode.d.ts +21 -0
- package/dist/image-decode.js +42 -0
- package/dist/index.d.ts +402 -0
- package/dist/index.js +27 -0
- package/dist/keys.d.ts +76 -0
- package/dist/keys.js +373 -0
- package/dist/named-colors.d.ts +7 -0
- package/dist/named-colors.js +20 -0
- package/dist/native/darwin-arm64/libvui_core.dylib +0 -0
- package/dist/native/darwin-x64/libvui_core.dylib +0 -0
- package/dist/native/ffi-symbols.d.ts +453 -0
- package/dist/native/ffi-symbols.js +680 -0
- package/dist/native/linux-arm64/libvui_core.so +0 -0
- package/dist/native/linux-x64/libvui_core.so +0 -0
- package/dist/native/load-native-lib.d.ts +384 -0
- package/dist/native/load-native-lib.js +63 -0
- package/dist/native/win32-x64/vui_core.dll +0 -0
- package/dist/node.d.ts +61 -0
- package/dist/node.js +157 -0
- package/dist/offscreen-buffer.d.ts +28 -0
- package/dist/offscreen-buffer.js +73 -0
- package/dist/renderer.d.ts +106 -0
- package/dist/renderer.js +186 -0
- package/dist/style.d.ts +48 -0
- package/dist/style.js +134 -0
- package/dist/terminal-session.d.ts +43 -0
- package/dist/terminal-session.js +82 -0
- package/dist/text/edit-buffer.d.ts +31 -0
- package/dist/text/edit-buffer.js +96 -0
- package/dist/text/editor-view.d.ts +22 -0
- package/dist/text/editor-view.js +48 -0
- package/dist/text/index.d.ts +5 -0
- package/dist/text/index.js +5 -0
- package/dist/text/text-buffer-view.d.ts +22 -0
- package/dist/text/text-buffer-view.js +49 -0
- package/dist/text/text-buffer.d.ts +16 -0
- package/dist/text/text-buffer.js +43 -0
- package/package.json +46 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { Attr, CELL_BYTES, EXPECTED_ABI_VERSION, EditMotion, EditMotionCode, LINK_SHIFT, NativeTextWrap, NativeTextWrapCode, NodeKindCode, STYLE_FFI_BYTES, Status, symbols } from "./ffi-symbols.js";
|
|
2
|
+
|
|
3
|
+
//#region src/native/load-native-lib.d.ts
|
|
4
|
+
declare function open(path: string): import("bun:ffi").Library<{
|
|
5
|
+
readonly vui_version: {
|
|
6
|
+
readonly args: readonly [];
|
|
7
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
8
|
+
};
|
|
9
|
+
readonly vui_abi_version: {
|
|
10
|
+
readonly args: readonly [];
|
|
11
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
12
|
+
};
|
|
13
|
+
readonly vui_char_width: {
|
|
14
|
+
readonly args: readonly [import("bun:ffi").FFIType.uint32_t];
|
|
15
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
16
|
+
};
|
|
17
|
+
readonly vui_renderer_new: {
|
|
18
|
+
readonly args: readonly [import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
19
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
20
|
+
};
|
|
21
|
+
readonly vui_renderer_free: {
|
|
22
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
23
|
+
readonly returns: import("bun:ffi").FFIType.void;
|
|
24
|
+
};
|
|
25
|
+
readonly vui_renderer_resize: {
|
|
26
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
27
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
28
|
+
};
|
|
29
|
+
readonly vui_renderer_back_buffer_ptr: {
|
|
30
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
31
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
32
|
+
};
|
|
33
|
+
readonly vui_renderer_buffer_len: {
|
|
34
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
35
|
+
readonly returns: "usize";
|
|
36
|
+
};
|
|
37
|
+
readonly vui_cell_size_bytes: {
|
|
38
|
+
readonly args: readonly [];
|
|
39
|
+
readonly returns: "usize";
|
|
40
|
+
};
|
|
41
|
+
readonly vui_buffer_draw_text: {
|
|
42
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.ptr, "usize", import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint16_t];
|
|
43
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
44
|
+
};
|
|
45
|
+
readonly vui_buffer_fill_rect: {
|
|
46
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
47
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
48
|
+
};
|
|
49
|
+
readonly vui_buffer_set_cell: {
|
|
50
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint16_t];
|
|
51
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
52
|
+
};
|
|
53
|
+
readonly vui_buffer_clear: {
|
|
54
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t];
|
|
55
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
56
|
+
};
|
|
57
|
+
readonly vui_renderer_render: {
|
|
58
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
59
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
60
|
+
};
|
|
61
|
+
readonly vui_renderer_flush: {
|
|
62
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
63
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
64
|
+
};
|
|
65
|
+
readonly vui_renderer_clear_links: {
|
|
66
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
67
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
68
|
+
};
|
|
69
|
+
readonly vui_renderer_stage_link: {
|
|
70
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint16_t, import("bun:ffi").FFIType.ptr, "usize"];
|
|
71
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
72
|
+
};
|
|
73
|
+
readonly vui_renderer_stage_passthrough: {
|
|
74
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, "usize"];
|
|
75
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
76
|
+
};
|
|
77
|
+
readonly vui_image_decode: {
|
|
78
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, "usize", import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
79
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
80
|
+
};
|
|
81
|
+
readonly vui_renderer_stage_image_placement: {
|
|
82
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.int32_t];
|
|
83
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
84
|
+
};
|
|
85
|
+
readonly vui_renderer_clear_image_placements: {
|
|
86
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
87
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
88
|
+
};
|
|
89
|
+
readonly vui_image_decode_bytes: {
|
|
90
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, "usize", import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
91
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
92
|
+
};
|
|
93
|
+
readonly vui_image_width: {
|
|
94
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
95
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
96
|
+
};
|
|
97
|
+
readonly vui_image_height: {
|
|
98
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
99
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
100
|
+
};
|
|
101
|
+
readonly vui_image_rgba_ptr: {
|
|
102
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
103
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
104
|
+
};
|
|
105
|
+
readonly vui_image_rgba_len: {
|
|
106
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
107
|
+
readonly returns: "usize";
|
|
108
|
+
};
|
|
109
|
+
readonly vui_image_free: {
|
|
110
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
111
|
+
readonly returns: import("bun:ffi").FFIType.void;
|
|
112
|
+
};
|
|
113
|
+
readonly vui_buffer_draw_text_clipped: {
|
|
114
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.ptr, "usize", import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint16_t, import("bun:ffi").FFIType.ptr];
|
|
115
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
116
|
+
};
|
|
117
|
+
readonly vui_buffer_fill_rect_clipped: {
|
|
118
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.ptr];
|
|
119
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
120
|
+
};
|
|
121
|
+
readonly vui_buffer_set_cell_clipped: {
|
|
122
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint16_t, import("bun:ffi").FFIType.ptr];
|
|
123
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
124
|
+
};
|
|
125
|
+
readonly vui_buffer_blit: {
|
|
126
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.ptr];
|
|
127
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
128
|
+
};
|
|
129
|
+
readonly vui_buffer_draw_textbuffer: {
|
|
130
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint8_t, import("bun:ffi").FFIType.uint16_t, import("bun:ffi").FFIType.ptr];
|
|
131
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
132
|
+
};
|
|
133
|
+
readonly vui_buffer_draw_editor: {
|
|
134
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.int32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint16_t, import("bun:ffi").FFIType.ptr];
|
|
135
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
136
|
+
};
|
|
137
|
+
readonly vui_textbuf_new: {
|
|
138
|
+
readonly args: readonly [];
|
|
139
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
140
|
+
};
|
|
141
|
+
readonly vui_textbuf_free: {
|
|
142
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
143
|
+
readonly returns: import("bun:ffi").FFIType.void;
|
|
144
|
+
};
|
|
145
|
+
readonly vui_textbuf_set_text: {
|
|
146
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, "usize"];
|
|
147
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
148
|
+
};
|
|
149
|
+
readonly vui_textbuf_set_runs: {
|
|
150
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, "usize", import("bun:ffi").FFIType.ptr, "usize"];
|
|
151
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
152
|
+
};
|
|
153
|
+
readonly vui_textbuf_line_count: {
|
|
154
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
155
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
156
|
+
};
|
|
157
|
+
readonly vui_textbuf_length: {
|
|
158
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
159
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
160
|
+
};
|
|
161
|
+
readonly vui_textview_new: {
|
|
162
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
163
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
164
|
+
};
|
|
165
|
+
readonly vui_textview_free: {
|
|
166
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
167
|
+
readonly returns: import("bun:ffi").FFIType.void;
|
|
168
|
+
};
|
|
169
|
+
readonly vui_textview_set_wrap: {
|
|
170
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint8_t];
|
|
171
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
172
|
+
};
|
|
173
|
+
readonly vui_textview_set_width: {
|
|
174
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t];
|
|
175
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
176
|
+
};
|
|
177
|
+
readonly vui_textview_measure: {
|
|
178
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint8_t, import("bun:ffi").FFIType.ptr];
|
|
179
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
180
|
+
};
|
|
181
|
+
readonly vui_editbuf_new: {
|
|
182
|
+
readonly args: readonly [];
|
|
183
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
184
|
+
};
|
|
185
|
+
readonly vui_editbuf_free: {
|
|
186
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
187
|
+
readonly returns: import("bun:ffi").FFIType.void;
|
|
188
|
+
};
|
|
189
|
+
readonly vui_editbuf_set_value: {
|
|
190
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, "usize"];
|
|
191
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
192
|
+
};
|
|
193
|
+
readonly vui_editbuf_value_len: {
|
|
194
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
195
|
+
readonly returns: "usize";
|
|
196
|
+
};
|
|
197
|
+
readonly vui_editbuf_copy_value: {
|
|
198
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, "usize"];
|
|
199
|
+
readonly returns: "usize";
|
|
200
|
+
};
|
|
201
|
+
readonly vui_editbuf_insert: {
|
|
202
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, "usize"];
|
|
203
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
204
|
+
};
|
|
205
|
+
readonly vui_editbuf_backspace: {
|
|
206
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
207
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
208
|
+
};
|
|
209
|
+
readonly vui_editbuf_delete: {
|
|
210
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
211
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
212
|
+
};
|
|
213
|
+
readonly vui_editbuf_newline: {
|
|
214
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
215
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
216
|
+
};
|
|
217
|
+
readonly vui_editbuf_move: {
|
|
218
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint8_t, import("bun:ffi").FFIType.uint8_t];
|
|
219
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
220
|
+
};
|
|
221
|
+
readonly vui_editbuf_select_all: {
|
|
222
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
223
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
224
|
+
};
|
|
225
|
+
readonly vui_editbuf_has_selection: {
|
|
226
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
227
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
228
|
+
};
|
|
229
|
+
readonly vui_editbuf_selected_len: {
|
|
230
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
231
|
+
readonly returns: "usize";
|
|
232
|
+
};
|
|
233
|
+
readonly vui_editbuf_copy_selected: {
|
|
234
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, "usize"];
|
|
235
|
+
readonly returns: "usize";
|
|
236
|
+
};
|
|
237
|
+
readonly vui_editbuf_delete_selection: {
|
|
238
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr];
|
|
239
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
240
|
+
};
|
|
241
|
+
readonly vui_editbuf_undo: {
|
|
242
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr];
|
|
243
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
244
|
+
};
|
|
245
|
+
readonly vui_editbuf_redo: {
|
|
246
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr];
|
|
247
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
248
|
+
};
|
|
249
|
+
readonly vui_editbuf_can_undo: {
|
|
250
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
251
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
252
|
+
};
|
|
253
|
+
readonly vui_editbuf_can_redo: {
|
|
254
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
255
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
256
|
+
};
|
|
257
|
+
readonly vui_editbuf_cursor: {
|
|
258
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.ptr];
|
|
259
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
260
|
+
};
|
|
261
|
+
readonly vui_editor_new: {
|
|
262
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
263
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
264
|
+
};
|
|
265
|
+
readonly vui_editor_free: {
|
|
266
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
267
|
+
readonly returns: import("bun:ffi").FFIType.void;
|
|
268
|
+
};
|
|
269
|
+
readonly vui_editor_set_wrap: {
|
|
270
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint8_t];
|
|
271
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
272
|
+
};
|
|
273
|
+
readonly vui_editor_set_viewport: {
|
|
274
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
275
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
276
|
+
};
|
|
277
|
+
readonly vui_editor_set_focused: {
|
|
278
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint8_t];
|
|
279
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
280
|
+
};
|
|
281
|
+
readonly vui_editor_move: {
|
|
282
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint8_t, import("bun:ffi").FFIType.uint8_t];
|
|
283
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
284
|
+
};
|
|
285
|
+
readonly vui_editor_measure: {
|
|
286
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint8_t, import("bun:ffi").FFIType.ptr];
|
|
287
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
288
|
+
};
|
|
289
|
+
readonly vui_cbuf_new: {
|
|
290
|
+
readonly args: readonly [import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
291
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
292
|
+
};
|
|
293
|
+
readonly vui_cbuf_free: {
|
|
294
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
295
|
+
readonly returns: import("bun:ffi").FFIType.void;
|
|
296
|
+
};
|
|
297
|
+
readonly vui_cbuf_resize: {
|
|
298
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
299
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
300
|
+
};
|
|
301
|
+
readonly vui_cbuf_ptr: {
|
|
302
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
303
|
+
readonly returns: import("bun:ffi").FFIType.ptr;
|
|
304
|
+
};
|
|
305
|
+
readonly vui_cbuf_len: {
|
|
306
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
307
|
+
readonly returns: "usize";
|
|
308
|
+
};
|
|
309
|
+
readonly vui_cbuf_clear: {
|
|
310
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t];
|
|
311
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
312
|
+
};
|
|
313
|
+
readonly vui_cbuf_draw_text: {
|
|
314
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.ptr, "usize", import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint16_t];
|
|
315
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
316
|
+
};
|
|
317
|
+
readonly vui_cbuf_fill_rect: {
|
|
318
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
319
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
320
|
+
};
|
|
321
|
+
readonly vui_cbuf_set_cell: {
|
|
322
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint16_t];
|
|
323
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
324
|
+
};
|
|
325
|
+
readonly vui_renderer_set_root: {
|
|
326
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
327
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
328
|
+
};
|
|
329
|
+
readonly vui_node_new: {
|
|
330
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint8_t];
|
|
331
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
332
|
+
};
|
|
333
|
+
readonly vui_node_free: {
|
|
334
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t];
|
|
335
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
336
|
+
};
|
|
337
|
+
readonly vui_node_append_child: {
|
|
338
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
339
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
340
|
+
};
|
|
341
|
+
readonly vui_node_insert_before: {
|
|
342
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
343
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
344
|
+
};
|
|
345
|
+
readonly vui_node_remove_child: {
|
|
346
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
347
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
348
|
+
};
|
|
349
|
+
readonly vui_node_set_text: {
|
|
350
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.ptr, "usize"];
|
|
351
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
352
|
+
};
|
|
353
|
+
readonly vui_node_set_text_runs: {
|
|
354
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.ptr, "usize", import("bun:ffi").FFIType.ptr, "usize"];
|
|
355
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
356
|
+
};
|
|
357
|
+
readonly vui_node_set_text_wrap: {
|
|
358
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint8_t];
|
|
359
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
360
|
+
};
|
|
361
|
+
readonly vui_node_set_style: {
|
|
362
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.ptr];
|
|
363
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
364
|
+
};
|
|
365
|
+
readonly vui_style_ffi_size: {
|
|
366
|
+
readonly args: readonly [];
|
|
367
|
+
readonly returns: "usize";
|
|
368
|
+
};
|
|
369
|
+
readonly vui_debug_tree_hash: {
|
|
370
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr];
|
|
371
|
+
readonly returns: import("bun:ffi").FFIType.uint64_t;
|
|
372
|
+
};
|
|
373
|
+
readonly vui_layout_compute: {
|
|
374
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.uint32_t];
|
|
375
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
376
|
+
};
|
|
377
|
+
readonly vui_node_rect: {
|
|
378
|
+
readonly args: readonly [import("bun:ffi").FFIType.ptr, import("bun:ffi").FFIType.uint32_t, import("bun:ffi").FFIType.ptr];
|
|
379
|
+
readonly returns: import("bun:ffi").FFIType.uint32_t;
|
|
380
|
+
};
|
|
381
|
+
}>;
|
|
382
|
+
type NativeLib = ReturnType<typeof open>;
|
|
383
|
+
//#endregion
|
|
384
|
+
export { NativeLib };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { symbols } from "./ffi-symbols.js";
|
|
2
|
+
import { dlopen, suffix } from "bun:ffi";
|
|
3
|
+
import { existsSync, statSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
//#region src/native/load-native-lib.ts
|
|
7
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const repoRoot = join(here, "..", "..", "..", "..");
|
|
9
|
+
function libFileName() {
|
|
10
|
+
return `${process.platform === "win32" ? "" : "lib"}vui_core.${suffix}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Library lookup order (the newest existing candidate actually wins — see
|
|
14
|
+
* `loadNativeLib`):
|
|
15
|
+
* 1. Published layout: dylib copied next to the loader inside `dist/` by the
|
|
16
|
+
* tsdown `copy` step (`dist/native/<arch>/`). The only candidate that exists
|
|
17
|
+
* in a published package.
|
|
18
|
+
* 2. Dev: stable copy produced by `scripts/build-native.ts` at the package's
|
|
19
|
+
* `native/<arch>/` dir.
|
|
20
|
+
* 3. Dev fallbacks: the cargo workspace build directory (release, then debug).
|
|
21
|
+
*
|
|
22
|
+
* `here` is `<pkg>/src/native` in dev and `<pkg>/dist/native` in a build — both
|
|
23
|
+
* sit at the same depth, so the relative joins resolve correctly either way.
|
|
24
|
+
*/
|
|
25
|
+
function candidatePaths() {
|
|
26
|
+
const file = libFileName();
|
|
27
|
+
const platformArch = `${process.platform}-${process.arch}`;
|
|
28
|
+
const buildDir = join(repoRoot, "target");
|
|
29
|
+
return [
|
|
30
|
+
join(here, platformArch, file),
|
|
31
|
+
join(here, "..", "..", "native", platformArch, file),
|
|
32
|
+
join(buildDir, "release", file),
|
|
33
|
+
join(buildDir, "debug", file)
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
function open(path) {
|
|
37
|
+
return dlopen(path, symbols);
|
|
38
|
+
}
|
|
39
|
+
let cached;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve, `dlopen`, ABI-check, and memoize the vui-core native library.
|
|
42
|
+
*
|
|
43
|
+
* When several candidates exist (e.g. a debug build alongside a stale release
|
|
44
|
+
* copy) the most recently modified one wins, so a fresh `cargo build` always
|
|
45
|
+
* takes precedence over an old artifact during iterative development.
|
|
46
|
+
*/
|
|
47
|
+
function loadNativeLib() {
|
|
48
|
+
if (cached) return cached;
|
|
49
|
+
const candidates = candidatePaths();
|
|
50
|
+
const existing = candidates.filter((p) => existsSync(p));
|
|
51
|
+
if (existing.length === 0) throw new Error("vui-core native library not found. Searched:\n" + candidates.map((p) => ` - ${p}`).join("\n") + "\nBuild it with: bun run build:native");
|
|
52
|
+
const lib = open(existing.reduce((newest, p) => statSync(p).mtimeMs > statSync(newest).mtimeMs ? p : newest));
|
|
53
|
+
const abi = lib.symbols.vui_abi_version();
|
|
54
|
+
if (abi !== 12) throw new Error(`vui-core ABI mismatch: native=${abi}, expected=12. Rebuild the native lib: bun run build:native`);
|
|
55
|
+
const cellBytes = Number(lib.symbols.vui_cell_size_bytes());
|
|
56
|
+
if (cellBytes !== 16) throw new Error(`vui-core Cell size mismatch: native=${cellBytes}, expected=16. Rebuild the native lib: bun run build:native`);
|
|
57
|
+
const styleBytes = Number(lib.symbols.vui_style_ffi_size());
|
|
58
|
+
if (styleBytes !== 236) throw new Error(`vui-core StyleFfi size mismatch: native=${styleBytes}, expected=236. Rebuild the native lib: bun run build:native`);
|
|
59
|
+
cached = lib;
|
|
60
|
+
return cached;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { loadNativeLib };
|
|
Binary file
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { NativeLib } from "./native/load-native-lib.js";
|
|
2
|
+
import { VuiStyle } from "./style.js";
|
|
3
|
+
import { Pointer } from "bun:ffi";
|
|
4
|
+
|
|
5
|
+
//#region src/node.d.ts
|
|
6
|
+
interface TextRun {
|
|
7
|
+
text: string;
|
|
8
|
+
fg?: number;
|
|
9
|
+
bg?: number;
|
|
10
|
+
attrs?: number;
|
|
11
|
+
}
|
|
12
|
+
type TextWrapName = 'word' | 'char' | 'nowrap';
|
|
13
|
+
/** Per-side insets (cells, fractional) reported by layout. */
|
|
14
|
+
interface RectEdges {
|
|
15
|
+
left: number;
|
|
16
|
+
right: number;
|
|
17
|
+
top: number;
|
|
18
|
+
bottom: number;
|
|
19
|
+
}
|
|
20
|
+
/** A node's computed taffy box: parent-relative origin + size + padding/border insets. */
|
|
21
|
+
interface LayoutRect {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
w: number;
|
|
25
|
+
h: number;
|
|
26
|
+
padding: RectEdges;
|
|
27
|
+
border: RectEdges;
|
|
28
|
+
}
|
|
29
|
+
declare class VuiNode {
|
|
30
|
+
#private;
|
|
31
|
+
readonly id: number;
|
|
32
|
+
/** Node-kind code mirrored for the structural hash (0 root, 1 box, 2 text). */
|
|
33
|
+
readonly kindCode: number;
|
|
34
|
+
/** JS mirror of the native child order — kept in lockstep by the tree ops. */
|
|
35
|
+
readonly children: VuiNode[];
|
|
36
|
+
constructor(lib: NativeLib, ptr: Pointer, id: number, kindCode: number);
|
|
37
|
+
setStyle(style: VuiStyle): this;
|
|
38
|
+
/**
|
|
39
|
+
* This node's computed layout box after `Renderer.computeLayout`, or `null` if
|
|
40
|
+
* layout hasn't run yet (or the handle is stale). The JS-host paint walk reads
|
|
41
|
+
* these to place each Renderable.
|
|
42
|
+
*/
|
|
43
|
+
layoutRect(): LayoutRect | null;
|
|
44
|
+
setText(text: string): this;
|
|
45
|
+
setTextRuns(runs: TextRun[]): this;
|
|
46
|
+
/**
|
|
47
|
+
* Text flow for a `<text>` node: `"word"` (default) breaks at word
|
|
48
|
+
* boundaries with char fallback, `"char"` wraps by grapheme, and `"nowrap"`
|
|
49
|
+
* keeps each physical line on one row and clips overflow.
|
|
50
|
+
*/
|
|
51
|
+
setTextWrap(mode: TextWrapName): this;
|
|
52
|
+
appendChild(child: VuiNode): this;
|
|
53
|
+
insertBefore(child: VuiNode, anchor: VuiNode): this;
|
|
54
|
+
removeChild(child: VuiNode): this;
|
|
55
|
+
/** Destroy this node and its subtree natively, and unlink it from the mirror. */
|
|
56
|
+
free(): void;
|
|
57
|
+
}
|
|
58
|
+
/** Structural hash of the host mirror, comparable to `Renderer.treeHash()`. */
|
|
59
|
+
declare function hostTreeHash(root: VuiNode): bigint;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { LayoutRect, RectEdges, TextRun, TextWrapName, VuiNode, hostTreeHash };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { NativeTextWrap, Status } from "./native/ffi-symbols.js";
|
|
2
|
+
import { packStyle } from "./style.js";
|
|
3
|
+
//#region src/node.ts
|
|
4
|
+
const encoder = new TextEncoder();
|
|
5
|
+
const rectScratch = new Float32Array(48 / 4);
|
|
6
|
+
function check(status, op) {
|
|
7
|
+
if (status !== Status.OK) throw new Error(`vui-core node ${op} failed with status ${status}`);
|
|
8
|
+
}
|
|
9
|
+
var VuiNode = class {
|
|
10
|
+
id;
|
|
11
|
+
/** Node-kind code mirrored for the structural hash (0 root, 1 box, 2 text). */
|
|
12
|
+
kindCode;
|
|
13
|
+
/** JS mirror of the native child order — kept in lockstep by the tree ops. */
|
|
14
|
+
children = [];
|
|
15
|
+
#parent;
|
|
16
|
+
#lib;
|
|
17
|
+
#ptr;
|
|
18
|
+
constructor(lib, ptr, id, kindCode) {
|
|
19
|
+
this.#lib = lib;
|
|
20
|
+
this.#ptr = ptr;
|
|
21
|
+
this.id = id;
|
|
22
|
+
this.kindCode = kindCode;
|
|
23
|
+
}
|
|
24
|
+
setStyle(style) {
|
|
25
|
+
const bytes = packStyle(style);
|
|
26
|
+
check(this.#lib.symbols.vui_node_set_style(this.#ptr, this.id, bytes), "set_style");
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* This node's computed layout box after `Renderer.computeLayout`, or `null` if
|
|
31
|
+
* layout hasn't run yet (or the handle is stale). The JS-host paint walk reads
|
|
32
|
+
* these to place each Renderable.
|
|
33
|
+
*/
|
|
34
|
+
layoutRect() {
|
|
35
|
+
if (this.#lib.symbols.vui_node_rect(this.#ptr, this.id, rectScratch) !== Status.OK) return null;
|
|
36
|
+
return {
|
|
37
|
+
x: rectScratch[0],
|
|
38
|
+
y: rectScratch[1],
|
|
39
|
+
w: rectScratch[2],
|
|
40
|
+
h: rectScratch[3],
|
|
41
|
+
padding: {
|
|
42
|
+
left: rectScratch[4],
|
|
43
|
+
right: rectScratch[5],
|
|
44
|
+
top: rectScratch[6],
|
|
45
|
+
bottom: rectScratch[7]
|
|
46
|
+
},
|
|
47
|
+
border: {
|
|
48
|
+
left: rectScratch[8],
|
|
49
|
+
right: rectScratch[9],
|
|
50
|
+
top: rectScratch[10],
|
|
51
|
+
bottom: rectScratch[11]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
setText(text) {
|
|
56
|
+
const bytes = encoder.encode(text);
|
|
57
|
+
check(this.#lib.symbols.vui_node_set_text(this.#ptr, this.id, bytes, bytes.byteLength), "set_text");
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
setTextRuns(runs) {
|
|
61
|
+
const { bytes, runBytes } = packTextRuns(runs);
|
|
62
|
+
check(this.#lib.symbols.vui_node_set_text_runs(this.#ptr, this.id, runBytes, runs.length, bytes, bytes.byteLength), "set_text_runs");
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Text flow for a `<text>` node: `"word"` (default) breaks at word
|
|
67
|
+
* boundaries with char fallback, `"char"` wraps by grapheme, and `"nowrap"`
|
|
68
|
+
* keeps each physical line on one row and clips overflow.
|
|
69
|
+
*/
|
|
70
|
+
setTextWrap(mode) {
|
|
71
|
+
check(this.#lib.symbols.vui_node_set_text_wrap(this.#ptr, this.id, wrapCode(mode)), "set_text_wrap");
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
appendChild(child) {
|
|
75
|
+
check(this.#lib.symbols.vui_node_append_child(this.#ptr, this.id, child.id), "append_child");
|
|
76
|
+
child.#detachFromParent();
|
|
77
|
+
child.#parent = this;
|
|
78
|
+
this.children.push(child);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
insertBefore(child, anchor) {
|
|
82
|
+
check(this.#lib.symbols.vui_node_insert_before(this.#ptr, this.id, child.id, anchor.id), "insert_before");
|
|
83
|
+
child.#detachFromParent();
|
|
84
|
+
child.#parent = this;
|
|
85
|
+
const at = this.children.indexOf(anchor);
|
|
86
|
+
if (at < 0) this.children.push(child);
|
|
87
|
+
else this.children.splice(at, 0, child);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
removeChild(child) {
|
|
91
|
+
check(this.#lib.symbols.vui_node_remove_child(this.#ptr, this.id, child.id), "remove_child");
|
|
92
|
+
child.#detachFromParent();
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/** Destroy this node and its subtree natively, and unlink it from the mirror. */
|
|
96
|
+
free() {
|
|
97
|
+
check(this.#lib.symbols.vui_node_free(this.#ptr, this.id), "free");
|
|
98
|
+
this.#detachFromParent();
|
|
99
|
+
}
|
|
100
|
+
#detachFromParent() {
|
|
101
|
+
if (!this.#parent) return;
|
|
102
|
+
const siblings = this.#parent.children;
|
|
103
|
+
const at = siblings.indexOf(this);
|
|
104
|
+
if (at >= 0) siblings.splice(at, 1);
|
|
105
|
+
this.#parent = void 0;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function packTextRuns(runs) {
|
|
109
|
+
const chunks = runs.map((r) => encoder.encode(r.text));
|
|
110
|
+
const total = chunks.reduce((n, c) => n + c.byteLength, 0);
|
|
111
|
+
const bytes = new Uint8Array(total);
|
|
112
|
+
const runBuf = /* @__PURE__ */ new ArrayBuffer(runs.length * 20);
|
|
113
|
+
const dv = new DataView(runBuf);
|
|
114
|
+
let off = 0;
|
|
115
|
+
runs.forEach((run, i) => {
|
|
116
|
+
const chunk = chunks[i];
|
|
117
|
+
bytes.set(chunk, off);
|
|
118
|
+
const base = i * 20;
|
|
119
|
+
dv.setUint32(base + 0, off, true);
|
|
120
|
+
dv.setUint32(base + 4, chunk.byteLength, true);
|
|
121
|
+
dv.setUint32(base + 8, (run.fg ?? 0) >>> 0, true);
|
|
122
|
+
dv.setUint32(base + 12, (run.bg ?? 0) >>> 0, true);
|
|
123
|
+
dv.setUint16(base + 16, (run.attrs ?? 0) & 65535, true);
|
|
124
|
+
dv.setUint8(base + 18, run.fg !== void 0 ? 1 : 0);
|
|
125
|
+
dv.setUint8(base + 19, run.bg !== void 0 ? 1 : 0);
|
|
126
|
+
off += chunk.byteLength;
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
bytes,
|
|
130
|
+
runBytes: new Uint8Array(runBuf)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function wrapCode(mode) {
|
|
134
|
+
if (mode === "nowrap") return NativeTextWrap.None;
|
|
135
|
+
if (mode === "char") return NativeTextWrap.Char;
|
|
136
|
+
return NativeTextWrap.Word;
|
|
137
|
+
}
|
|
138
|
+
const FNV_OFFSET = 14695981039346656037n;
|
|
139
|
+
const FNV_PRIME = 1099511628211n;
|
|
140
|
+
const U64 = 18446744073709551615n;
|
|
141
|
+
function mix(h, v) {
|
|
142
|
+
h ^= v & U64;
|
|
143
|
+
return h * FNV_PRIME & U64;
|
|
144
|
+
}
|
|
145
|
+
function hashNode(node, h) {
|
|
146
|
+
h = mix(h, BigInt(node.kindCode));
|
|
147
|
+
h = mix(h, BigInt(node.children.length));
|
|
148
|
+
for (const c of node.children) h = mix(h, BigInt(c.id));
|
|
149
|
+
for (const c of node.children) h = hashNode(c, h);
|
|
150
|
+
return h;
|
|
151
|
+
}
|
|
152
|
+
/** Structural hash of the host mirror, comparable to `Renderer.treeHash()`. */
|
|
153
|
+
function hostTreeHash(root) {
|
|
154
|
+
return hashNode(root, FNV_OFFSET);
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
export { VuiNode, hostTreeHash, packTextRuns };
|