@opentui/core 0.1.30 → 0.1.32

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.
Files changed (40) hide show
  1. package/3d.js +1 -1
  2. package/Renderable.d.ts +4 -4
  3. package/assets/markdown/highlights.scm +150 -0
  4. package/assets/markdown/injections.scm +27 -0
  5. package/assets/markdown/tree-sitter-markdown.wasm +0 -0
  6. package/assets/markdown_inline/highlights.scm +115 -0
  7. package/assets/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  8. package/edit-buffer.d.ts +13 -12
  9. package/editor-view.d.ts +10 -0
  10. package/{index-0qmm1k4p.js → index-3f9h747j.js} +1424 -186
  11. package/index-3f9h747j.js.map +56 -0
  12. package/index.js +314 -83
  13. package/index.js.map +14 -14
  14. package/lib/KeyHandler.d.ts +4 -1
  15. package/lib/extmarks-history.d.ts +17 -0
  16. package/lib/extmarks.d.ts +88 -0
  17. package/lib/index.d.ts +2 -0
  18. package/lib/parse.keypress.d.ts +2 -1
  19. package/lib/stdin-buffer.d.ts +42 -0
  20. package/lib/tree-sitter/client.d.ts +1 -0
  21. package/lib/tree-sitter/parsers-config.d.ts +38 -0
  22. package/lib/tree-sitter/types.d.ts +18 -1
  23. package/lib/tree-sitter-styled-text.d.ts +9 -2
  24. package/package.json +9 -9
  25. package/parser.worker.js +250 -27
  26. package/parser.worker.js.map +3 -3
  27. package/renderables/Box.d.ts +1 -0
  28. package/renderables/Code.d.ts +14 -0
  29. package/renderables/EditBufferRenderable.d.ts +20 -4
  30. package/renderables/TextBufferRenderable.d.ts +10 -0
  31. package/renderables/Textarea.d.ts +21 -13
  32. package/renderer.d.ts +1 -0
  33. package/syntax-style.d.ts +2 -0
  34. package/testing/mock-keys.d.ts +22 -61
  35. package/testing.js +36 -78
  36. package/testing.js.map +3 -3
  37. package/text-buffer-view.d.ts +2 -0
  38. package/text-buffer.d.ts +3 -0
  39. package/zig.d.ts +29 -7
  40. package/index-0qmm1k4p.js.map +0 -53
@@ -10,6 +10,7 @@ export declare class KeyEvent implements ParsedKey {
10
10
  number: boolean;
11
11
  raw: string;
12
12
  eventType: KeyEventType;
13
+ source: "raw" | "kitty";
13
14
  code?: string;
14
15
  super?: boolean;
15
16
  hyper?: boolean;
@@ -37,11 +38,13 @@ export type KeyHandlerEventMap = {
37
38
  export declare class KeyHandler extends EventEmitter<KeyHandlerEventMap> {
38
39
  protected stdin: NodeJS.ReadStream;
39
40
  protected useKittyKeyboard: boolean;
40
- protected listener: (key: Buffer) => void;
41
41
  protected pasteMode: boolean;
42
42
  protected pasteBuffer: string[];
43
43
  private suspended;
44
+ private stdinBuffer;
45
+ private dataListener;
44
46
  constructor(stdin?: NodeJS.ReadStream, useKittyKeyboard?: boolean);
47
+ private processSequence;
45
48
  destroy(): void;
46
49
  suspend(): void;
47
50
  resume(): void;
@@ -0,0 +1,17 @@
1
+ import type { Extmark } from "./extmarks";
2
+ export interface ExtmarksSnapshot {
3
+ extmarks: Map<number, Extmark>;
4
+ nextId: number;
5
+ }
6
+ export declare class ExtmarksHistory {
7
+ private undoStack;
8
+ private redoStack;
9
+ saveSnapshot(extmarks: Map<number, Extmark>, nextId: number): void;
10
+ undo(): ExtmarksSnapshot | null;
11
+ redo(): ExtmarksSnapshot | null;
12
+ pushRedo(snapshot: ExtmarksSnapshot): void;
13
+ pushUndo(snapshot: ExtmarksSnapshot): void;
14
+ clear(): void;
15
+ canUndo(): boolean;
16
+ canRedo(): boolean;
17
+ }
@@ -0,0 +1,88 @@
1
+ import type { EditBuffer } from "../edit-buffer";
2
+ import type { EditorView } from "../editor-view";
3
+ export interface Extmark {
4
+ id: number;
5
+ start: number;
6
+ end: number;
7
+ virtual: boolean;
8
+ styleId?: number;
9
+ priority?: number;
10
+ data?: any;
11
+ typeId: number;
12
+ }
13
+ export interface ExtmarkOptions {
14
+ start: number;
15
+ end: number;
16
+ virtual?: boolean;
17
+ styleId?: number;
18
+ priority?: number;
19
+ data?: any;
20
+ typeId?: number;
21
+ metadata?: any;
22
+ }
23
+ /**
24
+ * WARNING: This is simulating extmarks in the edit buffer
25
+ * and will move to a real native implementation in the future.
26
+ * Use with caution.
27
+ */
28
+ export declare class ExtmarksController {
29
+ private editBuffer;
30
+ private editorView;
31
+ private extmarks;
32
+ private extmarksByTypeId;
33
+ private metadata;
34
+ private nextId;
35
+ private destroyed;
36
+ private history;
37
+ private typeNameToId;
38
+ private typeIdToName;
39
+ private nextTypeId;
40
+ private originalMoveCursorLeft;
41
+ private originalMoveCursorRight;
42
+ private originalSetCursorByOffset;
43
+ private originalMoveUpVisual;
44
+ private originalMoveDownVisual;
45
+ private originalDeleteCharBackward;
46
+ private originalDeleteChar;
47
+ private originalInsertText;
48
+ private originalInsertChar;
49
+ private originalDeleteRange;
50
+ private originalSetText;
51
+ private originalClear;
52
+ private originalNewLine;
53
+ private originalDeleteLine;
54
+ private originalEditorViewDeleteSelectedText;
55
+ private originalUndo;
56
+ private originalRedo;
57
+ constructor(editBuffer: EditBuffer, editorView: EditorView);
58
+ private wrapCursorMovement;
59
+ private wrapDeletion;
60
+ private wrapInsertion;
61
+ private wrapEditorViewDeleteSelectedText;
62
+ private setupContentChangeListener;
63
+ private deleteExtmarkById;
64
+ private findVirtualExtmarkContaining;
65
+ private adjustExtmarksAfterInsertion;
66
+ adjustExtmarksAfterDeletion(deleteOffset: number, length: number): void;
67
+ private offsetToPosition;
68
+ private positionToOffset;
69
+ private updateHighlights;
70
+ private offsetToCharOffset;
71
+ create(options: ExtmarkOptions): number;
72
+ delete(id: number): boolean;
73
+ get(id: number): Extmark | null;
74
+ getAll(): Extmark[];
75
+ getVirtual(): Extmark[];
76
+ getAtOffset(offset: number): Extmark[];
77
+ getAllForTypeId(typeId: number): Extmark[];
78
+ clear(): void;
79
+ private saveSnapshot;
80
+ private restoreSnapshot;
81
+ private wrapUndoRedo;
82
+ registerType(typeName: string): number;
83
+ getTypeId(typeName: string): number | null;
84
+ getTypeName(typeId: number): string | null;
85
+ getMetadataFor(extmarkId: number): any;
86
+ destroy(): void;
87
+ }
88
+ export declare function createExtmarksController(editBuffer: EditBuffer, editorView: EditorView): ExtmarksController;
package/lib/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./hast-styled-text";
5
5
  export * from "./RGBA";
6
6
  export * from "./parse.keypress";
7
7
  export * from "./scroll-acceleration";
8
+ export * from "./stdin-buffer";
8
9
  export * from "./styled-text";
9
10
  export * from "./yoga.options";
10
11
  export * from "./parse.mouse";
@@ -13,3 +14,4 @@ export * from "./env";
13
14
  export * from "./tree-sitter-styled-text";
14
15
  export * from "./tree-sitter";
15
16
  export * from "./data-paths";
17
+ export * from "./extmarks";
@@ -11,6 +11,7 @@ export interface ParsedKey {
11
11
  number: boolean;
12
12
  raw: string;
13
13
  eventType: KeyEventType;
14
+ source: "raw" | "kitty";
14
15
  code?: string;
15
16
  super?: boolean;
16
17
  hyper?: boolean;
@@ -21,4 +22,4 @@ export interface ParsedKey {
21
22
  export type ParseKeypressOptions = {
22
23
  useKittyKeyboard?: boolean;
23
24
  };
24
- export declare const parseKeypress: (s?: Buffer | string, options?: ParseKeypressOptions) => ParsedKey;
25
+ export declare const parseKeypress: (s?: Buffer | string, options?: ParseKeypressOptions) => ParsedKey | null;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * StdinBuffer wraps a stdin stream and emits complete sequences.
3
+ *
4
+ * This is necessary because stdin data events can arrive in partial chunks,
5
+ * especially for escape sequences like mouse events. Without buffering,
6
+ * partial sequences can be misinterpreted as regular keypresses.
7
+ *
8
+ * For example, the mouse SGR sequence `\x1b[<35;20;5m` might arrive as:
9
+ * - Event 1: `\x1b`
10
+ * - Event 2: `[<35`
11
+ * - Event 3: `;20;5m`
12
+ *
13
+ * The buffer accumulates these until a complete sequence is detected.
14
+ */
15
+ import { EventEmitter } from "events";
16
+ export type StdinBufferOptions = {
17
+ /**
18
+ * Maximum time to wait for sequence completion (default: 10ms)
19
+ * After this time, the buffer is flushed even if incomplete
20
+ */
21
+ timeout?: number;
22
+ };
23
+ export type StdinBufferEventMap = {
24
+ data: [string];
25
+ };
26
+ /**
27
+ * Wraps a stdin stream and emits complete sequences via the 'data' event.
28
+ * Handles partial escape sequences that arrive across multiple chunks.
29
+ */
30
+ export declare class StdinBuffer extends EventEmitter<StdinBufferEventMap> {
31
+ private buffer;
32
+ private timeout;
33
+ private readonly timeoutMs;
34
+ private readonly stdin;
35
+ private readonly stdinListener;
36
+ constructor(stdin: NodeJS.ReadStream, options?: StdinBufferOptions);
37
+ private handleData;
38
+ flush(): string[];
39
+ clear(): void;
40
+ getBuffer(): string;
41
+ destroy(): void;
42
+ }
@@ -43,4 +43,5 @@ export declare class TreeSitterClient extends EventEmitter<TreeSitterClientEvent
43
43
  getAllBuffers(): BufferState[];
44
44
  isInitialized(): boolean;
45
45
  setDataPath(dataPath: string): Promise<void>;
46
+ clearCache(): Promise<void>;
46
47
  }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * This file contains the configuration for the defaulttree-sitter parsers.
3
+ * It is used by ./assets/update.ts to generate the default-parsers.ts file.
4
+ * For changes here to be reflected in the default-parsers.ts file, you need to run `bun run ./assets/update.ts`
5
+ */
6
+ declare const _default: {
7
+ parsers: ({
8
+ filetype: string;
9
+ wasm: string;
10
+ queries: {
11
+ highlights: string[];
12
+ injections?: undefined;
13
+ };
14
+ injectionMapping?: undefined;
15
+ } | {
16
+ filetype: string;
17
+ wasm: string;
18
+ queries: {
19
+ highlights: string[];
20
+ injections: string[];
21
+ };
22
+ injectionMapping: {
23
+ nodeTypes: {
24
+ inline: string;
25
+ pipe_table_cell: string;
26
+ };
27
+ infoStringMap: {
28
+ javascript: string;
29
+ js: string;
30
+ typescript: string;
31
+ ts: string;
32
+ markdown: string;
33
+ md: string;
34
+ };
35
+ };
36
+ })[];
37
+ };
38
+ export default _default;
@@ -8,13 +8,30 @@ export interface HighlightResponse {
8
8
  highlights: HighlightRange[];
9
9
  droppedHighlights: HighlightRange[];
10
10
  }
11
- export type SimpleHighlight = [number, number, string];
11
+ export interface HighlightMeta {
12
+ isInjection?: boolean;
13
+ injectionLang?: string;
14
+ containsInjection?: boolean;
15
+ conceal?: string | null;
16
+ concealLines?: string | null;
17
+ }
18
+ export type SimpleHighlight = [number, number, string, HighlightMeta?];
19
+ export interface InjectionMapping {
20
+ nodeTypes?: {
21
+ [nodeType: string]: string;
22
+ };
23
+ infoStringMap?: {
24
+ [infoString: string]: string;
25
+ };
26
+ }
12
27
  export interface FiletypeParserOptions {
13
28
  filetype: string;
14
29
  queries: {
15
30
  highlights: string[];
31
+ injections?: string[];
16
32
  };
17
33
  wasm: string;
34
+ injectionMapping?: InjectionMapping;
18
35
  }
19
36
  export interface BufferState {
20
37
  id: number;
@@ -3,5 +3,12 @@ import { StyledText } from "./styled-text";
3
3
  import { SyntaxStyle } from "../syntax-style";
4
4
  import { TreeSitterClient } from "./tree-sitter/client";
5
5
  import type { SimpleHighlight } from "./tree-sitter/types";
6
- export declare function treeSitterToTextChunks(content: string, highlights: SimpleHighlight[], syntaxStyle: SyntaxStyle): TextChunk[];
7
- export declare function treeSitterToStyledText(content: string, filetype: string, syntaxStyle: SyntaxStyle, client: TreeSitterClient): Promise<StyledText>;
6
+ interface ConcealOptions {
7
+ enabled: boolean;
8
+ }
9
+ export declare function treeSitterToTextChunks(content: string, highlights: SimpleHighlight[], syntaxStyle: SyntaxStyle, options?: ConcealOptions): TextChunk[];
10
+ export interface TreeSitterToStyledTextOptions {
11
+ conceal?: ConcealOptions;
12
+ }
13
+ export declare function treeSitterToStyledText(content: string, filetype: string, syntaxStyle: SyntaxStyle, client: TreeSitterClient, options?: TreeSitterToStyledTextOptions): Promise<StyledText>;
14
+ export {};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
7
- "version": "0.1.30",
7
+ "version": "0.1.32",
8
8
  "description": "OpenTUI is a TypeScript library for building terminal user interfaces (TUIs)",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -45,21 +45,21 @@
45
45
  "@types/three": "0.177.0",
46
46
  "commander": "^13.1.0",
47
47
  "typescript": "^5",
48
- "web-tree-sitter": "^0.26.0"
48
+ "web-tree-sitter": "0.25.10"
49
49
  },
50
50
  "peerDependencies": {
51
- "web-tree-sitter": ">=0.26.0"
51
+ "web-tree-sitter": "0.25.10"
52
52
  },
53
53
  "optionalDependencies": {
54
54
  "@dimforge/rapier2d-simd-compat": "^0.17.3",
55
55
  "bun-webgpu": "0.1.3",
56
56
  "planck": "^1.4.2",
57
57
  "three": "0.177.0",
58
- "@opentui/core-darwin-x64": "0.1.30",
59
- "@opentui/core-darwin-arm64": "0.1.30",
60
- "@opentui/core-linux-x64": "0.1.30",
61
- "@opentui/core-linux-arm64": "0.1.30",
62
- "@opentui/core-win32-x64": "0.1.30",
63
- "@opentui/core-win32-arm64": "0.1.30"
58
+ "@opentui/core-darwin-x64": "0.1.32",
59
+ "@opentui/core-darwin-arm64": "0.1.32",
60
+ "@opentui/core-linux-x64": "0.1.32",
61
+ "@opentui/core-linux-arm64": "0.1.32",
62
+ "@opentui/core-win32-x64": "0.1.32",
63
+ "@opentui/core-win32-arm64": "0.1.32"
64
64
  }
65
65
  }