@opentuah/core 0.1.88 → 0.1.90

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.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  RGBA,
4
4
  Renderable
5
- } from "./index-1n3xjscm.js";
5
+ } from "./index-bsnn7gyg.js";
6
6
 
7
7
  // src/3d/WGPURenderer.ts
8
8
  import { PerspectiveCamera, Color, NoToneMapping, LinearSRGBColorSpace } from "three";
@@ -0,0 +1,41 @@
1
+ import { type Pointer } from "bun:ffi";
2
+ import type { NativeSpanFeedOptions } from "./zig-structs";
3
+ export type { GrowthPolicy, NativeSpanFeedOptions, NativeSpanFeedStats } from "./zig-structs";
4
+ export type DataHandler = (data: Uint8Array) => void | Promise<void>;
5
+ /**
6
+ * Zero-copy wrapper over Zig memory; not a full stream interface.
7
+ */
8
+ export declare class NativeSpanFeed {
9
+ static create(options?: NativeSpanFeedOptions): NativeSpanFeed;
10
+ static attach(streamPtr: bigint | number, _options?: NativeSpanFeedOptions): NativeSpanFeed;
11
+ readonly streamPtr: Pointer;
12
+ private readonly lib;
13
+ private readonly eventHandler;
14
+ private chunkMap;
15
+ private chunkSizes;
16
+ private dataHandlers;
17
+ private errorHandlers;
18
+ private drainBuffer;
19
+ private stateBuffer;
20
+ private closed;
21
+ private destroyed;
22
+ private draining;
23
+ private pendingDataAvailable;
24
+ private pendingClose;
25
+ private closing;
26
+ private pendingAsyncHandlers;
27
+ private inCallback;
28
+ private closeQueued;
29
+ private constructor();
30
+ private ensureDrainBuffer;
31
+ onData(handler: DataHandler): () => void;
32
+ onError(handler: (code: number) => void): () => void;
33
+ close(): void;
34
+ private processPendingClose;
35
+ private performClose;
36
+ private finalizeDestroy;
37
+ private handleEvent;
38
+ private decrementRefcount;
39
+ private drainOnce;
40
+ drainAll(): void;
41
+ }
package/README.md CHANGED
@@ -42,6 +42,10 @@ bun run bench:native
42
42
 
43
43
  See [src/zig/bench.zig](src/zig/bench.zig) for available options like `--filter` and `--mem`.
44
44
 
45
+ NativeSpanFeed TypeScript benchmarks:
46
+
47
+ - [src/benchmark/native-span-feed-benchmark.md](src/benchmark/native-span-feed-benchmark.md)
48
+
45
49
  ## CLI Renderer
46
50
 
47
51
  ### Renderables
@@ -4908,6 +4908,7 @@ class MouseParser {
4908
4908
  const y = str.charCodeAt(5) - 33;
4909
4909
  const button = buttonByte & 3;
4910
4910
  const isScroll = (buttonByte & 64) !== 0;
4911
+ const isMotion = (buttonByte & 32) !== 0;
4911
4912
  const scrollDirection = !isScroll ? undefined : MouseParser.SCROLL_DIRECTIONS[button];
4912
4913
  const modifiers = {
4913
4914
  shift: (buttonByte & 4) !== 0,
@@ -4924,6 +4925,9 @@ class MouseParser {
4924
4925
  direction: scrollDirection,
4925
4926
  delta: 1
4926
4927
  };
4928
+ } else if (isMotion) {
4929
+ type = "move";
4930
+ actualButton = button === 3 ? -1 : button;
4927
4931
  } else {
4928
4932
  type = button === 3 ? "up" : "down";
4929
4933
  actualButton = button === 3 ? 0 : button;
@@ -8102,6 +8106,45 @@ var CursorStateStruct = defineStruct([
8102
8106
  ["b", "f32"],
8103
8107
  ["a", "f32"]
8104
8108
  ]);
8109
+ var GrowthPolicyEnum = defineEnum({ grow: 0, block: 1 }, "u8");
8110
+ var NativeSpanFeedOptionsStruct = defineStruct([
8111
+ ["chunkSize", "u32", { default: 64 * 1024 }],
8112
+ ["initialChunks", "u32", { default: 2 }],
8113
+ ["maxBytes", "u64", { default: 0n }],
8114
+ ["growthPolicy", GrowthPolicyEnum, { default: "grow" }],
8115
+ ["autoCommitOnFull", "bool_u8", { default: true }],
8116
+ ["spanQueueCapacity", "u32", { default: 0 }]
8117
+ ]);
8118
+ var NativeSpanFeedStatsStruct = defineStruct([
8119
+ ["bytesWritten", "u64"],
8120
+ ["spansCommitted", "u64"],
8121
+ ["chunks", "u32"],
8122
+ ["pendingSpans", "u32"]
8123
+ ]);
8124
+ var SpanInfoStruct = defineStruct([
8125
+ ["chunkPtr", "pointer"],
8126
+ ["offset", "u32"],
8127
+ ["len", "u32"],
8128
+ ["chunkIndex", "u32"],
8129
+ ["reserved", "u32", { default: 0 }]
8130
+ ], {
8131
+ reduceValue: (value) => ({
8132
+ chunkPtr: value.chunkPtr,
8133
+ offset: value.offset,
8134
+ len: value.len,
8135
+ chunkIndex: value.chunkIndex
8136
+ })
8137
+ });
8138
+ var ReserveInfoStruct = defineStruct([
8139
+ ["ptr", "pointer"],
8140
+ ["len", "u32"],
8141
+ ["reserved", "u32", { default: 0 }]
8142
+ ], {
8143
+ reduceValue: (value) => ({
8144
+ ptr: value.ptr,
8145
+ len: value.len
8146
+ })
8147
+ });
8105
8148
 
8106
8149
  // src/zig.ts
8107
8150
  var targetLibPath;
@@ -8109,12 +8152,7 @@ try {
8109
8152
  const module = await import(`@opentuah/core-${process.platform}-${process.arch}/index.ts`);
8110
8153
  targetLibPath = module.default;
8111
8154
  } catch {
8112
- if (process.platform === "linux") {
8113
- const module = await import(`@opentuah/core-linux-musl-${process.arch}/index.ts`);
8114
- targetLibPath = module.default;
8115
- } else {
8116
- throw new Error(`opentui is not supported on the current platform: ${process.platform}-${process.arch}`);
8117
- }
8155
+ throw new Error(`opentui is not supported on the current platform: ${process.platform}-${process.arch}`);
8118
8156
  }
8119
8157
  if (isBunfsPath(targetLibPath)) {
8120
8158
  targetLibPath = targetLibPath.replace("../", "");
@@ -8161,6 +8199,18 @@ registerEnvVar({
8161
8199
  var globalTraceSymbols = null;
8162
8200
  var globalFFILogWriter = null;
8163
8201
  var exitHandlerRegistered = false;
8202
+ function toPointer(value) {
8203
+ if (typeof value === "bigint") {
8204
+ if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
8205
+ throw new Error("Pointer exceeds safe integer range");
8206
+ }
8207
+ return Number(value);
8208
+ }
8209
+ return value;
8210
+ }
8211
+ function toNumber(value) {
8212
+ return typeof value === "bigint" ? Number(value) : value;
8213
+ }
8164
8214
  function getOpenTUILib(libPath) {
8165
8215
  const resolvedLibPath = libPath || targetLibPath;
8166
8216
  const rawSymbols = dlopen(resolvedLibPath, {
@@ -9076,6 +9126,54 @@ function getOpenTUILib(libPath) {
9076
9126
  vtermPtyToText: {
9077
9127
  args: ["ptr", "usize", "u16", "u16", "ptr", "usize"],
9078
9128
  returns: "usize"
9129
+ },
9130
+ createNativeSpanFeed: {
9131
+ args: ["ptr"],
9132
+ returns: "ptr"
9133
+ },
9134
+ attachNativeSpanFeed: {
9135
+ args: ["ptr"],
9136
+ returns: "i32"
9137
+ },
9138
+ destroyNativeSpanFeed: {
9139
+ args: ["ptr"],
9140
+ returns: "void"
9141
+ },
9142
+ streamWrite: {
9143
+ args: ["ptr", "ptr", "u64"],
9144
+ returns: "i32"
9145
+ },
9146
+ streamCommit: {
9147
+ args: ["ptr"],
9148
+ returns: "i32"
9149
+ },
9150
+ streamDrainSpans: {
9151
+ args: ["ptr", "ptr", "u32"],
9152
+ returns: "u32"
9153
+ },
9154
+ streamClose: {
9155
+ args: ["ptr"],
9156
+ returns: "i32"
9157
+ },
9158
+ streamReserve: {
9159
+ args: ["ptr", "u32", "ptr"],
9160
+ returns: "i32"
9161
+ },
9162
+ streamCommitReserved: {
9163
+ args: ["ptr", "u32"],
9164
+ returns: "i32"
9165
+ },
9166
+ streamSetOptions: {
9167
+ args: ["ptr", "ptr"],
9168
+ returns: "i32"
9169
+ },
9170
+ streamGetStats: {
9171
+ args: ["ptr", "ptr"],
9172
+ returns: "i32"
9173
+ },
9174
+ streamSetCallback: {
9175
+ args: ["ptr", "ptr"],
9176
+ returns: "void"
9079
9177
  }
9080
9178
  });
9081
9179
  if (env.OTUI_DEBUG_FFI || env.OTUI_TRACE_FFI) {
@@ -9241,6 +9339,8 @@ class FFIRenderLib {
9241
9339
  eventCallbackWrapper;
9242
9340
  _nativeEvents = new EventEmitter5;
9243
9341
  _anyEventHandlers = [];
9342
+ nativeSpanFeedCallbackWrapper = null;
9343
+ nativeSpanFeedHandlers = new Map;
9244
9344
  constructor(libPath) {
9245
9345
  this.opentui = getOpenTUILib(libPath);
9246
9346
  this.setupLogging();
@@ -9330,6 +9430,25 @@ class FFIRenderLib {
9330
9430
  }
9331
9431
  this.setEventCallback(eventCallback.ptr);
9332
9432
  }
9433
+ ensureNativeSpanFeedCallback() {
9434
+ if (this.nativeSpanFeedCallbackWrapper) {
9435
+ return this.nativeSpanFeedCallbackWrapper;
9436
+ }
9437
+ const callback = new JSCallback((streamPtr, eventId, arg0, arg1) => {
9438
+ const handler = this.nativeSpanFeedHandlers.get(toPointer(streamPtr));
9439
+ if (handler) {
9440
+ handler(eventId, arg0, arg1);
9441
+ }
9442
+ }, {
9443
+ args: ["ptr", "u32", "ptr", "u64"],
9444
+ returns: "void"
9445
+ });
9446
+ this.nativeSpanFeedCallbackWrapper = callback;
9447
+ if (!callback.ptr) {
9448
+ throw new Error("Failed to create native span feed callback");
9449
+ }
9450
+ return callback;
9451
+ }
9333
9452
  setEventCallback(callbackPtr) {
9334
9453
  this.opentui.symbols.setEventCallback(callbackPtr);
9335
9454
  }
@@ -10361,6 +10480,73 @@ class FFIRenderLib {
10361
10480
  bufferDrawChar(buffer, char, x, y, fg2, bg2, attributes = 0) {
10362
10481
  this.opentui.symbols.bufferDrawChar(buffer, char, x, y, fg2.buffer, bg2.buffer, attributes);
10363
10482
  }
10483
+ registerNativeSpanFeedStream(stream, handler) {
10484
+ const callback = this.ensureNativeSpanFeedCallback();
10485
+ this.nativeSpanFeedHandlers.set(toPointer(stream), handler);
10486
+ this.opentui.symbols.streamSetCallback(stream, callback.ptr);
10487
+ }
10488
+ unregisterNativeSpanFeedStream(stream) {
10489
+ this.opentui.symbols.streamSetCallback(stream, null);
10490
+ this.nativeSpanFeedHandlers.delete(toPointer(stream));
10491
+ }
10492
+ createNativeSpanFeed(options) {
10493
+ const optionsBuffer = options == null ? null : NativeSpanFeedOptionsStruct.pack(options);
10494
+ const streamPtr = this.opentui.symbols.createNativeSpanFeed(optionsBuffer ? ptr3(optionsBuffer) : null);
10495
+ if (!streamPtr) {
10496
+ throw new Error("Failed to create stream");
10497
+ }
10498
+ return toPointer(streamPtr);
10499
+ }
10500
+ attachNativeSpanFeed(stream) {
10501
+ return this.opentui.symbols.attachNativeSpanFeed(stream);
10502
+ }
10503
+ destroyNativeSpanFeed(stream) {
10504
+ this.opentui.symbols.destroyNativeSpanFeed(stream);
10505
+ this.nativeSpanFeedHandlers.delete(toPointer(stream));
10506
+ }
10507
+ streamWrite(stream, data) {
10508
+ const bytes = typeof data === "string" ? this.encoder.encode(data) : data;
10509
+ return this.opentui.symbols.streamWrite(stream, ptr3(bytes), bytes.length);
10510
+ }
10511
+ streamCommit(stream) {
10512
+ return this.opentui.symbols.streamCommit(stream);
10513
+ }
10514
+ streamDrainSpans(stream, outBuffer, maxSpans) {
10515
+ const count = this.opentui.symbols.streamDrainSpans(stream, ptr3(outBuffer), maxSpans);
10516
+ return toNumber(count);
10517
+ }
10518
+ streamClose(stream) {
10519
+ return this.opentui.symbols.streamClose(stream);
10520
+ }
10521
+ streamSetOptions(stream, options) {
10522
+ const optionsBuffer = NativeSpanFeedOptionsStruct.pack(options);
10523
+ return this.opentui.symbols.streamSetOptions(stream, ptr3(optionsBuffer));
10524
+ }
10525
+ streamGetStats(stream) {
10526
+ const statsBuffer = new ArrayBuffer(NativeSpanFeedStatsStruct.size);
10527
+ const status = this.opentui.symbols.streamGetStats(stream, ptr3(statsBuffer));
10528
+ if (status !== 0) {
10529
+ return null;
10530
+ }
10531
+ const stats = NativeSpanFeedStatsStruct.unpack(statsBuffer);
10532
+ return {
10533
+ bytesWritten: typeof stats.bytesWritten === "bigint" ? stats.bytesWritten : BigInt(stats.bytesWritten),
10534
+ spansCommitted: typeof stats.spansCommitted === "bigint" ? stats.spansCommitted : BigInt(stats.spansCommitted),
10535
+ chunks: stats.chunks,
10536
+ pendingSpans: stats.pendingSpans
10537
+ };
10538
+ }
10539
+ streamReserve(stream, minLen) {
10540
+ const reserveBuffer = new ArrayBuffer(ReserveInfoStruct.size);
10541
+ const status = this.opentui.symbols.streamReserve(stream, minLen, ptr3(reserveBuffer));
10542
+ if (status !== 0) {
10543
+ return { status, info: null };
10544
+ }
10545
+ return { status, info: ReserveInfoStruct.unpack(reserveBuffer) };
10546
+ }
10547
+ streamCommitReserved(stream, length) {
10548
+ return this.opentui.symbols.streamCommitReserved(stream, length);
10549
+ }
10364
10550
  createSyntaxStyle() {
10365
10551
  const stylePtr = this.opentui.symbols.createSyntaxStyle();
10366
10552
  if (!stylePtr) {
@@ -15076,7 +15262,7 @@ Captured output:
15076
15262
  }
15077
15263
  }
15078
15264
 
15079
- export { isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, ATTRIBUTE_BASE_BITS, ATTRIBUTE_BASE_MASK, getBaseAttributes, DebugOverlayCorner, createTextAttributes, attributesWithLink, getLinkId, visualizeRenderableTree, isStyledText, StyledText, stringToStyledText, black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bold, italic, underline, strikethrough, dim, reverse, blink, fg, bg, link, t, hastToStyledText, LinearScrollAccel, MacOSScrollAccel, StdinBuffer, parseAlign, parseAlignItems, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, clearEnvCache, generateEnvMarkdown, generateEnvColored, env, treeSitterToTextChunks, treeSitterToStyledText, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extToFiletype, pathToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, VTermStyleFlags, vtermDataToStyledText, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, ANSI, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingKey, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
15265
+ export { isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, ATTRIBUTE_BASE_BITS, ATTRIBUTE_BASE_MASK, getBaseAttributes, DebugOverlayCorner, createTextAttributes, attributesWithLink, getLinkId, visualizeRenderableTree, isStyledText, StyledText, stringToStyledText, black, red, green, yellow, blue, magenta, cyan, white, brightBlack, brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bold, italic, underline, strikethrough, dim, reverse, blink, fg, bg, link, t, hastToStyledText, LinearScrollAccel, MacOSScrollAccel, StdinBuffer, parseAlign, parseAlignItems, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, clearEnvCache, generateEnvMarkdown, generateEnvColored, env, treeSitterToTextChunks, treeSitterToStyledText, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extToFiletype, pathToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, VTermStyleFlags, vtermDataToStyledText, TextBuffer, SpanInfoStruct, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, ANSI, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingKey, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
15080
15266
 
15081
- //# debugId=C15A319C5711EB2964756E2164756E21
15082
- //# sourceMappingURL=index-1n3xjscm.js.map
15267
+ //# debugId=35AC0EA10B5E556464756E2164756E21
15268
+ //# sourceMappingURL=index-bsnn7gyg.js.map