@jitl/opentui-core 0.1.97-next.61f6679
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/3d/SpriteResourceManager.d.ts +74 -0
- package/3d/SpriteUtils.d.ts +13 -0
- package/3d/TextureUtils.d.ts +24 -0
- package/3d/ThreeRenderable.d.ts +40 -0
- package/3d/WGPURenderer.d.ts +61 -0
- package/3d/animation/ExplodingSpriteEffect.d.ts +71 -0
- package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +76 -0
- package/3d/animation/SpriteAnimator.d.ts +124 -0
- package/3d/animation/SpriteParticleGenerator.d.ts +62 -0
- package/3d/canvas.d.ts +44 -0
- package/3d/index.d.ts +12 -0
- package/3d/physics/PlanckPhysicsAdapter.d.ts +19 -0
- package/3d/physics/RapierPhysicsAdapter.d.ts +19 -0
- package/3d/physics/physics-interface.d.ts +27 -0
- package/3d.d.ts +2 -0
- package/3d.js +33843 -0
- package/3d.js.map +155 -0
- package/LICENSE +21 -0
- package/NativeSpanFeed.d.ts +41 -0
- package/README.md +65 -0
- package/Renderable.d.ts +334 -0
- package/Worker-vajwjk0s.js +94 -0
- package/Worker-vajwjk0s.js.map +10 -0
- package/animation/Timeline.d.ts +126 -0
- package/ansi.d.ts +13 -0
- package/assets/javascript/highlights.scm +205 -0
- package/assets/javascript/tree-sitter-javascript.wasm +0 -0
- package/assets/markdown/highlights.scm +150 -0
- package/assets/markdown/injections.scm +27 -0
- package/assets/markdown/tree-sitter-markdown.wasm +0 -0
- package/assets/markdown_inline/highlights.scm +115 -0
- package/assets/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
- package/assets/typescript/highlights.scm +604 -0
- package/assets/typescript/tree-sitter-typescript.wasm +0 -0
- package/assets/zig/highlights.scm +284 -0
- package/assets/zig/tree-sitter-zig.wasm +0 -0
- package/buffer.d.ts +111 -0
- package/compat/FFIType.d.ts +304 -0
- package/compat/Worker.d.ts +1 -0
- package/compat/bun-ffi-structs.d.ts +2 -0
- package/compat/ffi.d.ts +86 -0
- package/compat/nodejs/Worker.d.ts +16 -0
- package/compat/nodejs/bun-ffi-structs/index.d.ts +46 -0
- package/compat/nodejs/ffi.d.ts +21 -0
- package/compat/nodejs/registerBun.d.ts +1 -0
- package/compat/nodejs/registerResolveJs.d.ts +1 -0
- package/compat/nodejs/runtime.d.ts +7 -0
- package/compat/nodejs/test.d.ts +4 -0
- package/compat/nodejs/trampoline.worker.d.ts +1 -0
- package/compat/runtime.d.ts +8 -0
- package/compat/test.d.ts +1 -0
- package/compat/testHelpers.d.ts +18 -0
- package/console.d.ts +144 -0
- package/edit-buffer.d.ts +98 -0
- package/editor-view.d.ts +73 -0
- package/ffi-x3zvcksd.js +25 -0
- package/ffi-x3zvcksd.js.map +9 -0
- package/index-5yqvbmcz.js +220 -0
- package/index-5yqvbmcz.js.map +10 -0
- package/index-bnfz2g63.js +654 -0
- package/index-bnfz2g63.js.map +10 -0
- package/index-cbvybypy.js +43 -0
- package/index-cbvybypy.js.map +10 -0
- package/index-hjna9d1h.js +12074 -0
- package/index-hjna9d1h.js.map +42 -0
- package/index-jjp8mmgk.js +19991 -0
- package/index-jjp8mmgk.js.map +70 -0
- package/index-re3ntm60.js +51 -0
- package/index-re3ntm60.js.map +9 -0
- package/index-t16hn6zn.js +411 -0
- package/index-t16hn6zn.js.map +10 -0
- package/index-tkk6cmr2.js +650 -0
- package/index-tkk6cmr2.js.map +10 -0
- package/index.d.ts +23 -0
- package/index.js +480 -0
- package/index.js.map +9 -0
- package/lib/KeyHandler.d.ts +61 -0
- package/lib/RGBA.d.ts +26 -0
- package/lib/ascii.font.d.ts +508 -0
- package/lib/border.d.ts +51 -0
- package/lib/bunfs.d.ts +7 -0
- package/lib/clipboard.d.ts +17 -0
- package/lib/clock.d.ts +15 -0
- package/lib/data-paths.d.ts +26 -0
- package/lib/debounce.d.ts +42 -0
- package/lib/detect-links.d.ts +6 -0
- package/lib/env.d.ts +42 -0
- package/lib/extmarks-history.d.ts +17 -0
- package/lib/extmarks.d.ts +89 -0
- package/lib/hast-styled-text.d.ts +17 -0
- package/lib/index.d.ts +21 -0
- package/lib/keymapping.d.ts +25 -0
- package/lib/objects-in-viewport.d.ts +24 -0
- package/lib/output.capture.d.ts +24 -0
- package/lib/parse.keypress-kitty.d.ts +2 -0
- package/lib/parse.keypress.d.ts +26 -0
- package/lib/parse.mouse.d.ts +30 -0
- package/lib/paste.d.ts +7 -0
- package/lib/queue.d.ts +15 -0
- package/lib/renderable.validations.d.ts +12 -0
- package/lib/scroll-acceleration.d.ts +43 -0
- package/lib/selection.d.ts +64 -0
- package/lib/singleton.d.ts +7 -0
- package/lib/stdin-parser.d.ts +87 -0
- package/lib/styled-text.d.ts +63 -0
- package/lib/terminal-capability-detection.d.ts +30 -0
- package/lib/terminal-palette.d.ts +50 -0
- package/lib/tree-sitter/assets/update.d.ts +11 -0
- package/lib/tree-sitter/client.d.ts +47 -0
- package/lib/tree-sitter/default-parsers.d.ts +2 -0
- package/lib/tree-sitter/download-utils.d.ts +21 -0
- package/lib/tree-sitter/index.d.ts +8 -0
- package/lib/tree-sitter/parser.worker.d.ts +1 -0
- package/lib/tree-sitter/parsers-config.d.ts +53 -0
- package/lib/tree-sitter/resolve-ft.d.ts +5 -0
- package/lib/tree-sitter/types.d.ts +82 -0
- package/lib/tree-sitter-styled-text.d.ts +14 -0
- package/lib/validate-dir-name.d.ts +1 -0
- package/lib/yoga.options.d.ts +32 -0
- package/package.json +80 -0
- package/parser.worker.js +888 -0
- package/parser.worker.js.map +12 -0
- package/plugins/core-slot.d.ts +72 -0
- package/plugins/registry.d.ts +42 -0
- package/plugins/types.d.ts +34 -0
- package/post/effects.d.ts +147 -0
- package/post/filters.d.ts +65 -0
- package/post/matrices.d.ts +20 -0
- package/renderables/ASCIIFont.d.ts +52 -0
- package/renderables/Box.d.ts +81 -0
- package/renderables/Code.d.ts +78 -0
- package/renderables/Diff.d.ts +142 -0
- package/renderables/EditBufferRenderable.d.ts +237 -0
- package/renderables/FrameBuffer.d.ts +16 -0
- package/renderables/Input.d.ts +67 -0
- package/renderables/LineNumberRenderable.d.ts +78 -0
- package/renderables/Markdown.d.ts +181 -0
- package/renderables/ScrollBar.d.ts +77 -0
- package/renderables/ScrollBox.d.ts +124 -0
- package/renderables/Select.d.ts +115 -0
- package/renderables/Slider.d.ts +47 -0
- package/renderables/TabSelect.d.ts +96 -0
- package/renderables/Text.d.ts +36 -0
- package/renderables/TextBufferRenderable.d.ts +105 -0
- package/renderables/TextNode.d.ts +91 -0
- package/renderables/TextTable.d.ts +140 -0
- package/renderables/Textarea.d.ts +63 -0
- package/renderables/TimeToFirstDraw.d.ts +24 -0
- package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
- package/renderables/composition/VRenderable.d.ts +16 -0
- package/renderables/composition/constructs.d.ts +35 -0
- package/renderables/composition/vnode.d.ts +46 -0
- package/renderables/index.d.ts +23 -0
- package/renderables/markdown-parser.d.ts +10 -0
- package/renderer.d.ts +419 -0
- package/runtime-hdpkc6qf.js +220 -0
- package/runtime-hdpkc6qf.js.map +17 -0
- package/runtime-plugin-support.d.ts +3 -0
- package/runtime-plugin-support.js +31 -0
- package/runtime-plugin-support.js.map +10 -0
- package/runtime-plugin.d.ts +19 -0
- package/runtime-plugin.js +18 -0
- package/runtime-plugin.js.map +9 -0
- package/syntax-style.d.ts +54 -0
- package/testing/manual-clock.d.ts +17 -0
- package/testing/mock-keys.d.ts +81 -0
- package/testing/mock-mouse.d.ts +38 -0
- package/testing/mock-tree-sitter-client.d.ts +23 -0
- package/testing/spy.d.ts +7 -0
- package/testing/test-recorder.d.ts +61 -0
- package/testing/test-renderer.d.ts +23 -0
- package/testing.d.ts +6 -0
- package/testing.js +699 -0
- package/testing.js.map +15 -0
- package/text-buffer-view.d.ts +42 -0
- package/text-buffer.d.ts +67 -0
- package/types.d.ts +139 -0
- package/utils.d.ts +14 -0
- package/zig-structs.d.ts +155 -0
- package/zig.d.ts +353 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
FFIType
|
|
4
|
+
} from "./index-cbvybypy.js";
|
|
5
|
+
|
|
6
|
+
// src/compat/nodejs/ffi.ts
|
|
7
|
+
import koffi from "koffi";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
import { isArrayBuffer, isArrayBufferView } from "util/types";
|
|
10
|
+
import { unsafePointerOf, unsafeArrayBufferAt } from "unsafe-pointer";
|
|
11
|
+
var FFITypeStringToType = {
|
|
12
|
+
["char"]: 0 /* char */,
|
|
13
|
+
["int8_t"]: 1 /* int8_t */,
|
|
14
|
+
["i8"]: 1 /* i8 */,
|
|
15
|
+
["uint8_t"]: 2 /* uint8_t */,
|
|
16
|
+
["u8"]: 2 /* u8 */,
|
|
17
|
+
["int16_t"]: 3 /* int16_t */,
|
|
18
|
+
["i16"]: 3 /* i16 */,
|
|
19
|
+
["uint16_t"]: 4 /* uint16_t */,
|
|
20
|
+
["u16"]: 4 /* u16 */,
|
|
21
|
+
["int32_t"]: 5 /* int32_t */,
|
|
22
|
+
["i32"]: 5 /* i32 */,
|
|
23
|
+
["int"]: 5 /* int */,
|
|
24
|
+
["uint32_t"]: 6 /* uint32_t */,
|
|
25
|
+
["u32"]: 6 /* u32 */,
|
|
26
|
+
["int64_t"]: 7 /* int64_t */,
|
|
27
|
+
["i64"]: 7 /* i64 */,
|
|
28
|
+
["uint64_t"]: 8 /* uint64_t */,
|
|
29
|
+
["u64"]: 8 /* u64 */,
|
|
30
|
+
["double"]: 9 /* double */,
|
|
31
|
+
["f64"]: 9 /* f64 */,
|
|
32
|
+
["float"]: 10 /* float */,
|
|
33
|
+
["f32"]: 10 /* f32 */,
|
|
34
|
+
["bool"]: 11 /* bool */,
|
|
35
|
+
["ptr"]: 12 /* ptr */,
|
|
36
|
+
["pointer"]: 12 /* pointer */,
|
|
37
|
+
["void"]: 13 /* void */,
|
|
38
|
+
["cstring"]: 14 /* cstring */,
|
|
39
|
+
["function"]: 12 /* pointer */,
|
|
40
|
+
["usize"]: 8 /* uint64_t */,
|
|
41
|
+
["callback"]: 12 /* pointer */,
|
|
42
|
+
["napi_env"]: 18 /* napi_env */,
|
|
43
|
+
["napi_value"]: 19 /* napi_value */,
|
|
44
|
+
["buffer"]: 20 /* buffer */
|
|
45
|
+
};
|
|
46
|
+
var BunPtrType = koffi.pointer("BunPtr", koffi.opaque());
|
|
47
|
+
var NapiEnvType = koffi.opaque("NapiEnv");
|
|
48
|
+
var NapiValueType = koffi.opaque("NapiValue");
|
|
49
|
+
var BufferType = koffi.opaque("Buffer");
|
|
50
|
+
var ffiTypeToKoffiTypeMap = {
|
|
51
|
+
[0 /* char */]: koffi.types.char,
|
|
52
|
+
[1 /* int8_t */]: koffi.types.int8_t,
|
|
53
|
+
[2 /* uint8_t */]: koffi.types.uint8_t,
|
|
54
|
+
[3 /* int16_t */]: koffi.types.int16_t,
|
|
55
|
+
[4 /* uint16_t */]: koffi.types.uint16_t,
|
|
56
|
+
[5 /* int32_t */]: koffi.types.int32_t,
|
|
57
|
+
[6 /* uint32_t */]: koffi.types.uint32_t,
|
|
58
|
+
[7 /* int64_t */]: koffi.types.int64_t,
|
|
59
|
+
[8 /* uint64_t */]: koffi.types.uint64_t,
|
|
60
|
+
[9 /* double */]: koffi.types.double,
|
|
61
|
+
[10 /* float */]: koffi.types.float,
|
|
62
|
+
[11 /* bool */]: koffi.types.bool,
|
|
63
|
+
[12 /* ptr */]: BunPtrType,
|
|
64
|
+
[13 /* void */]: koffi.types.void,
|
|
65
|
+
[14 /* cstring */]: koffi.types.string,
|
|
66
|
+
[15 /* i64_fast */]: koffi.types.int64_t,
|
|
67
|
+
[16 /* u64_fast */]: koffi.types.uint64_t,
|
|
68
|
+
[17 /* function */]: BunPtrType,
|
|
69
|
+
[18 /* napi_env */]: NapiEnvType,
|
|
70
|
+
[19 /* napi_value */]: NapiValueType,
|
|
71
|
+
[20 /* buffer */]: BufferType
|
|
72
|
+
};
|
|
73
|
+
function ffiTypeToKoffiType(type) {
|
|
74
|
+
let numberType;
|
|
75
|
+
if (typeof type === "number") {
|
|
76
|
+
numberType = type;
|
|
77
|
+
} else {
|
|
78
|
+
numberType = FFITypeStringToType[type];
|
|
79
|
+
}
|
|
80
|
+
if (numberType === 18 /* napi_env */ || numberType === 19 /* napi_value */ || numberType === 14 /* cstring */) {
|
|
81
|
+
throw new Error(`Unsupported FFI type: ${FFIType[numberType]} (${type})`);
|
|
82
|
+
}
|
|
83
|
+
return ffiTypeToKoffiTypeMap[numberType];
|
|
84
|
+
}
|
|
85
|
+
function koffiPointerToNumber(pointer) {
|
|
86
|
+
if (pointer === null) {
|
|
87
|
+
return 0;
|
|
88
|
+
} else if (typeof pointer === "object") {
|
|
89
|
+
return Number(koffi.address(pointer));
|
|
90
|
+
} else if (typeof pointer === "bigint") {
|
|
91
|
+
return Number(pointer);
|
|
92
|
+
} else {
|
|
93
|
+
return pointer;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
class JSCallback {
|
|
98
|
+
#threadsafe;
|
|
99
|
+
#registeredCallback;
|
|
100
|
+
constructor(callback, definition) {
|
|
101
|
+
const ptrArgIndices = [];
|
|
102
|
+
if (definition.args) {
|
|
103
|
+
for (let i = 0;i < definition.args.length; i++) {
|
|
104
|
+
if (isPointerType(definition.args[i]))
|
|
105
|
+
ptrArgIndices.push(i);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const wrappedCallback = ptrArgIndices.length > 0 ? (...args) => {
|
|
109
|
+
for (const i of ptrArgIndices) {
|
|
110
|
+
args[i] = koffiPointerToNumber(args[i]);
|
|
111
|
+
}
|
|
112
|
+
return callback(...args);
|
|
113
|
+
} : callback;
|
|
114
|
+
const proto = koffi.proto(returnsToKoffiType(definition.returns), argsToKoffiTypes(definition.args));
|
|
115
|
+
this.#registeredCallback = koffi.register(wrappedCallback, koffi.pointer(proto));
|
|
116
|
+
this.#threadsafe = definition.threadsafe ?? false;
|
|
117
|
+
}
|
|
118
|
+
get ptr() {
|
|
119
|
+
if (!this.#registeredCallback) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return Number(koffi.address(this.#registeredCallback));
|
|
123
|
+
}
|
|
124
|
+
get threadsafe() {
|
|
125
|
+
return this.#threadsafe;
|
|
126
|
+
}
|
|
127
|
+
close() {
|
|
128
|
+
if (!this.#registeredCallback) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
koffi.unregister(this.#registeredCallback);
|
|
132
|
+
this.#registeredCallback = null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function argsToKoffiTypes(args) {
|
|
136
|
+
return args?.map(ffiTypeToKoffiType) ?? [];
|
|
137
|
+
}
|
|
138
|
+
function returnsToKoffiType(returns) {
|
|
139
|
+
return ffiTypeToKoffiType(returns ?? 13 /* void */);
|
|
140
|
+
}
|
|
141
|
+
function isPointerType(type) {
|
|
142
|
+
if (type === undefined)
|
|
143
|
+
return false;
|
|
144
|
+
const num = typeof type === "number" ? type : FFITypeStringToType[type];
|
|
145
|
+
return num === 12 /* ptr */;
|
|
146
|
+
}
|
|
147
|
+
function isBigIntType(type) {
|
|
148
|
+
if (type === undefined)
|
|
149
|
+
return false;
|
|
150
|
+
const num = typeof type === "number" ? type : FFITypeStringToType[type];
|
|
151
|
+
return num === 7 /* i64 */ || num === 8 /* u64 */ || num === 15 /* i64_fast */ || num === 16 /* u64_fast */;
|
|
152
|
+
}
|
|
153
|
+
var emptyPtrSentinel = new Uint8Array(1);
|
|
154
|
+
function pointerArgToKoffiPointerArg(arg) {
|
|
155
|
+
if (typeof arg === "number") {
|
|
156
|
+
return BigInt(arg);
|
|
157
|
+
}
|
|
158
|
+
if ((isArrayBufferView(arg) || isArrayBuffer(arg)) && arg.byteLength === 0) {
|
|
159
|
+
return emptyPtrSentinel;
|
|
160
|
+
}
|
|
161
|
+
return arg;
|
|
162
|
+
}
|
|
163
|
+
function ffiFunctionToKoffiFunction(lib, name, type) {
|
|
164
|
+
const func = lib.func(name, returnsToKoffiType(type.returns), argsToKoffiTypes(type.args));
|
|
165
|
+
const ptrArgIndices = [];
|
|
166
|
+
if (type.args) {
|
|
167
|
+
for (let i = 0;i < type.args.length; i++) {
|
|
168
|
+
if (isPointerType(type.args[i]))
|
|
169
|
+
ptrArgIndices.push(i);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const returnsPtr = isPointerType(type.returns);
|
|
173
|
+
const returnsBigInt = isBigIntType(type.returns);
|
|
174
|
+
if (ptrArgIndices.length === 0 && !returnsPtr && !returnsBigInt) {
|
|
175
|
+
return func;
|
|
176
|
+
}
|
|
177
|
+
const wrapper = (...args) => {
|
|
178
|
+
for (const i of ptrArgIndices) {
|
|
179
|
+
args[i] = pointerArgToKoffiPointerArg(args[i]);
|
|
180
|
+
}
|
|
181
|
+
const result = func(...args);
|
|
182
|
+
if (returnsPtr) {
|
|
183
|
+
return koffiPointerToNumber(result);
|
|
184
|
+
}
|
|
185
|
+
if (returnsBigInt) {
|
|
186
|
+
return BigInt(result);
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
};
|
|
190
|
+
Object.defineProperty(wrapper, "name", { value: name });
|
|
191
|
+
return wrapper;
|
|
192
|
+
}
|
|
193
|
+
var ptr = (value) => unsafePointerOf(value);
|
|
194
|
+
var toArrayBuffer = unsafeArrayBufferAt;
|
|
195
|
+
var suffix = koffi.extension.slice(1);
|
|
196
|
+
var dlopen = (name, symbols) => {
|
|
197
|
+
let loadPath;
|
|
198
|
+
if (typeof name === "string") {
|
|
199
|
+
loadPath = name;
|
|
200
|
+
} else if (name instanceof URL) {
|
|
201
|
+
loadPath = fileURLToPath(name);
|
|
202
|
+
} else {
|
|
203
|
+
throw new Error(`Unsupported FFI library name: ${name}`);
|
|
204
|
+
}
|
|
205
|
+
const lib = koffi.load(loadPath);
|
|
206
|
+
const library = {};
|
|
207
|
+
for (const [name2, ffiFunction] of Object.entries(symbols)) {
|
|
208
|
+
library[name2] = ffiFunctionToKoffiFunction(lib, name2, ffiFunction);
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
symbols: library,
|
|
212
|
+
close: () => lib.unload()
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
var __url = import.meta.url;
|
|
216
|
+
|
|
217
|
+
export { JSCallback, ptr, toArrayBuffer, suffix, dlopen, __url };
|
|
218
|
+
|
|
219
|
+
//# debugId=A9A0E9208D2214D664756E2164756E21
|
|
220
|
+
//# sourceMappingURL=index-5yqvbmcz.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/compat/nodejs/ffi.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import koffi from \"koffi\"\nimport { fileURLToPath } from \"node:url\"\nimport { isAnyArrayBuffer, isArrayBuffer, isArrayBufferView } from \"node:util/types\"\nimport type {\n ConvertFns,\n DlopenFunction,\n FFIFunction,\n FFITypeOrString,\n JSCallback as IJSCallback,\n Pointer,\n PtrFunction,\n ToArrayBufferFunction,\n} from \"../ffi.js\"\nimport { FFIType } from \"../FFIType.js\"\nimport { unsafePointerOf, unsafeArrayBufferAt } from \"unsafe-pointer\"\n\nexport { FFIType }\n\nconst FFITypeStringToType = {\n [\"char\"]: FFIType.char,\n [\"int8_t\"]: FFIType.int8_t,\n [\"i8\"]: FFIType.i8,\n [\"uint8_t\"]: FFIType.uint8_t,\n [\"u8\"]: FFIType.u8,\n [\"int16_t\"]: FFIType.int16_t,\n [\"i16\"]: FFIType.i16,\n [\"uint16_t\"]: FFIType.uint16_t,\n [\"u16\"]: FFIType.u16,\n [\"int32_t\"]: FFIType.int32_t,\n [\"i32\"]: FFIType.i32,\n [\"int\"]: FFIType.int,\n [\"uint32_t\"]: FFIType.uint32_t,\n [\"u32\"]: FFIType.u32,\n [\"int64_t\"]: FFIType.int64_t,\n [\"i64\"]: FFIType.i64,\n [\"uint64_t\"]: FFIType.uint64_t,\n [\"u64\"]: FFIType.u64,\n [\"double\"]: FFIType.double,\n [\"f64\"]: FFIType.f64,\n [\"float\"]: FFIType.float,\n [\"f32\"]: FFIType.f32,\n [\"bool\"]: FFIType.bool,\n [\"ptr\"]: FFIType.ptr,\n [\"pointer\"]: FFIType.pointer,\n [\"void\"]: FFIType.void,\n [\"cstring\"]: FFIType.cstring,\n [\"function\"]: FFIType.pointer, // for now\n [\"usize\"]: FFIType.uint64_t, // for now\n [\"callback\"]: FFIType.pointer, // for now\n [\"napi_env\"]: FFIType.napi_env,\n [\"napi_value\"]: FFIType.napi_value,\n [\"buffer\"]: FFIType.buffer,\n} as const\n\nconst BunPtrType = koffi.pointer(\"BunPtr\", koffi.opaque())\nconst NapiEnvType = koffi.opaque(\"NapiEnv\")\nconst NapiValueType = koffi.opaque(\"NapiValue\")\nconst BufferType = koffi.opaque(\"Buffer\")\n\nconst ffiTypeToKoffiTypeMap: Record<FFIType, koffi.TypeSpec> = {\n [FFIType.char]: koffi.types.char,\n [FFIType.int8_t]: koffi.types.int8_t,\n [FFIType.uint8_t]: koffi.types.uint8_t,\n [FFIType.int16_t]: koffi.types.int16_t,\n [FFIType.uint16_t]: koffi.types.uint16_t,\n [FFIType.int32_t]: koffi.types.int32_t,\n [FFIType.uint32_t]: koffi.types.uint32_t,\n [FFIType.int64_t]: koffi.types.int64_t,\n [FFIType.uint64_t]: koffi.types.uint64_t,\n [FFIType.double]: koffi.types.double,\n [FFIType.float]: koffi.types.float,\n [FFIType.bool]: koffi.types.bool,\n [FFIType.ptr]: BunPtrType,\n [FFIType.void]: koffi.types.void,\n [FFIType.cstring]: koffi.types.string,\n [FFIType.i64_fast]: koffi.types.int64_t,\n [FFIType.u64_fast]: koffi.types.uint64_t,\n [FFIType.function]: BunPtrType,\n [FFIType.napi_env]: NapiEnvType,\n [FFIType.napi_value]: NapiValueType,\n [FFIType.buffer]: BufferType,\n}\n\nfunction ffiTypeToKoffiType(type: FFITypeOrString): koffi.TypeSpec {\n let numberType: FFIType\n if (typeof type === \"number\") {\n numberType = type\n } else {\n numberType = FFITypeStringToType[type]\n }\n\n if (numberType === FFIType.napi_env || numberType === FFIType.napi_value || numberType === FFIType.cstring) {\n throw new Error(`Unsupported FFI type: ${FFIType[numberType]} (${type})`)\n }\n\n return ffiTypeToKoffiTypeMap[numberType]\n}\n\ntype KoffiExternal = object & { __koffi_external__: true }\n\nfunction koffiPointerToNumber(pointer: KoffiExternal | bigint | number | null): number {\n if (pointer === null) {\n return 0\n } else if (typeof pointer === \"object\") {\n return Number(koffi.address(pointer))\n } else if (typeof pointer === \"bigint\") {\n return Number(pointer)\n } else {\n return pointer\n }\n}\n\nexport class JSCallback implements IJSCallback {\n #threadsafe: boolean\n #registeredCallback: koffi.IKoffiRegisteredCallback | null\n\n constructor(callback: (...args: any[]) => any, definition: FFIFunction) {\n // Wrap callback to convert koffi External pointer args → numbers (Bun convention),\n // mirroring the conversion done for FFI function return values.\n const ptrArgIndices: number[] = []\n if (definition.args) {\n for (let i = 0; i < definition.args.length; i++) {\n if (isPointerType(definition.args[i])) ptrArgIndices.push(i)\n }\n }\n const wrappedCallback =\n ptrArgIndices.length > 0\n ? (...args: any[]) => {\n for (const i of ptrArgIndices) {\n args[i] = koffiPointerToNumber(args[i])\n }\n return callback(...args)\n }\n : callback\n\n const proto = koffi.proto(returnsToKoffiType(definition.returns), argsToKoffiTypes(definition.args))\n this.#registeredCallback = koffi.register(wrappedCallback, koffi.pointer(proto))\n this.#threadsafe = definition.threadsafe ?? false\n }\n\n get ptr(): Pointer | null {\n if (!this.#registeredCallback) {\n return null\n }\n return Number(koffi.address(this.#registeredCallback)) as Pointer\n }\n\n get threadsafe(): boolean {\n return this.#threadsafe\n }\n\n close() {\n if (!this.#registeredCallback) {\n return\n }\n koffi.unregister(this.#registeredCallback)\n this.#registeredCallback = null\n }\n}\n\nfunction argsToKoffiTypes(args: readonly FFITypeOrString[] | undefined): koffi.TypeSpec[] {\n return args?.map(ffiTypeToKoffiType) ?? []\n}\n\nfunction returnsToKoffiType(returns: FFITypeOrString | undefined): koffi.TypeSpec {\n return ffiTypeToKoffiType(returns ?? FFIType.void)\n}\n\nfunction isPointerType(type: FFITypeOrString | undefined): boolean {\n if (type === undefined) return false\n const num = typeof type === \"number\" ? type : FFITypeStringToType[type as keyof typeof FFITypeStringToType]\n return num === FFIType.ptr\n}\n\nfunction isBigIntType(type: FFITypeOrString | undefined): boolean {\n if (type === undefined) return false\n const num = typeof type === \"number\" ? type : FFITypeStringToType[type as keyof typeof FFITypeStringToType]\n return num === FFIType.i64 || num === FFIType.u64 || num === FFIType.i64_fast || num === FFIType.u64_fast\n}\n\n// koffi passes null for 0-length TypedArrays, but Bun passes a valid non-null\n// address. Native code may treat null as \"no data\" even when length is also\n// passed as 0. Use a static 1-byte sentinel so the pointer is always non-null.\nconst emptyPtrSentinel = new Uint8Array(1)\n\nfunction pointerArgToKoffiPointerArg(arg: unknown): unknown {\n if (typeof arg === \"number\") {\n // Real native address (e.g. from JSCallback.ptr or read from output buffer) —\n // koffi accepts BigInt for pointer params.\n return BigInt(arg)\n }\n\n if ((isArrayBufferView(arg) || isArrayBuffer(arg)) && arg.byteLength === 0) {\n return emptyPtrSentinel\n }\n\n return arg\n}\n\nfunction ffiFunctionToKoffiFunction<T extends (...args: unknown[]) => unknown>(\n lib: koffi.IKoffiLib,\n name: string,\n type: FFIFunction,\n): T & koffi.KoffiFunction {\n const func = lib.func(name, returnsToKoffiType(type.returns), argsToKoffiTypes(type.args))\n\n const ptrArgIndices: number[] = []\n if (type.args) {\n for (let i = 0; i < type.args.length; i++) {\n if (isPointerType(type.args[i])) ptrArgIndices.push(i)\n }\n }\n const returnsPtr = isPointerType(type.returns)\n // koffi may return small u64/i64 values as number instead of bigint;\n // Bun always returns bigint for these types.\n const returnsBigInt = isBigIntType(type.returns)\n\n if (ptrArgIndices.length === 0 && !returnsPtr && !returnsBigInt) {\n return func as T & koffi.KoffiFunction\n }\n\n const wrapper = (...args: unknown[]) => {\n for (const i of ptrArgIndices) {\n args[i] = pointerArgToKoffiPointerArg(args[i])\n }\n\n const result = func(...args)\n\n if (returnsPtr) {\n return koffiPointerToNumber(result)\n }\n\n if (returnsBigInt) {\n return BigInt(result)\n }\n\n return result\n }\n Object.defineProperty(wrapper, \"name\", { value: name })\n return wrapper as T & koffi.KoffiFunction\n}\n\n/**\n * Get Pointer address of a TypedArray or ArrayBuffer\n */\nexport const ptr: PtrFunction = (value) => unsafePointerOf(value as ArrayBuffer)\n\n/**\n * Get an ArrayBuffer aliasing the memory at the given Pointer number\n */\nexport const toArrayBuffer: ToArrayBufferFunction = unsafeArrayBufferAt\n\nexport const suffix: string = koffi.extension.slice(1)\n\nexport const dlopen: DlopenFunction = (name, symbols) => {\n let loadPath: string\n if (typeof name === \"string\") {\n loadPath = name\n } else if (name instanceof URL) {\n loadPath = fileURLToPath(name)\n } else {\n throw new Error(`Unsupported FFI library name: ${name}`)\n }\n const lib = koffi.load(loadPath)\n const library: Record<string, koffi.KoffiFunction> = {}\n for (const [name, ffiFunction] of Object.entries(symbols)) {\n // Idea: could use defineProperty to lazily create the koffi.func\n library[name] = ffiFunctionToKoffiFunction(lib, name, ffiFunction)\n }\n return {\n symbols: library as unknown as ConvertFns<typeof symbols>,\n close: () => lib.unload(),\n }\n}\n\nexport const __url = import.meta.url\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;AAAA;AACA;AACA;AAYA;AAIA,IAAM,sBAAsB;AAAA,GACzB;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,GACA;AAAA,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