@opentui/core 0.3.3 → 0.4.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.
Files changed (42) hide show
  1. package/NativeSpanFeed.d.ts +4 -0
  2. package/{index-mn090kzf.js → index-59t85rvq.js} +3153 -2503
  3. package/index-59t85rvq.js.map +84 -0
  4. package/index.js +11256 -77
  5. package/index.js.map +29 -3
  6. package/lib/selection.d.ts +2 -1
  7. package/lib/singleton.d.ts +1 -0
  8. package/lib/tree-sitter/client.d.ts +17 -1
  9. package/lib/tree-sitter/index.d.ts +1 -0
  10. package/lib/tree-sitter/types.d.ts +104 -1
  11. package/lib/tree-sitter/update-assets.js +8 -6
  12. package/lib/tree-sitter/update-assets.js.map +3 -3
  13. package/package.json +27 -34
  14. package/parser.worker.js +452 -78
  15. package/parser.worker.js.map +8 -7
  16. package/platform/ffi.d.ts +6 -3
  17. package/platform/test.d.ts +12 -0
  18. package/platform/worker.d.ts +26 -4
  19. package/platform/worker.node-test.d.ts +1 -0
  20. package/renderables/Code.d.ts +4 -0
  21. package/renderables/Markdown.d.ts +1 -0
  22. package/runtime-plugin-support-configure.js +36 -18
  23. package/runtime-plugin-support-configure.js.map +1 -9
  24. package/runtime-plugin-support-configure.node.js +15 -0
  25. package/runtime-plugin-support.js +4 -19
  26. package/runtime-plugin-support.js.map +1 -10
  27. package/runtime-plugin-support.node.js +15 -0
  28. package/runtime-plugin.js +473 -16
  29. package/runtime-plugin.js.map +1 -9
  30. package/runtime-plugin.node.js +15 -0
  31. package/testing/bun-test-node.d.ts +87 -0
  32. package/testing/mock-tree-sitter-client.d.ts +4 -0
  33. package/testing.js +15 -9
  34. package/testing.js.map +3 -3
  35. package/zig.d.ts +1 -1
  36. package/index-jh82sd41.js +0 -44
  37. package/index-jh82sd41.js.map +0 -10
  38. package/index-mbck6rbg.js +0 -421
  39. package/index-mbck6rbg.js.map +0 -10
  40. package/index-mn090kzf.js.map +0 -84
  41. package/index-qndc8vq8.js +0 -11670
  42. package/index-qndc8vq8.js.map +0 -35
@@ -1,4 +1,26 @@
1
- export declare const Worker: {
2
- new (scriptURL: string | URL, options?: WorkerOptions): Worker;
3
- prototype: Worker;
4
- };
1
+ export declare const WORKER_UNAVAILABLE = "OpenTUI tree-sitter workers are not available for this runtime yet.";
2
+ export interface WorkerMessageEvent<T = unknown> {
3
+ readonly data: T;
4
+ }
5
+ export interface WorkerErrorEvent {
6
+ readonly error?: unknown;
7
+ readonly message: string;
8
+ }
9
+ export type WorkerMessageHandler<T = unknown> = (event: WorkerMessageEvent<T>) => void | Promise<void>;
10
+ export type WorkerErrorHandler = (event: WorkerErrorEvent) => void;
11
+ export interface PlatformWorkerOptions {
12
+ name?: string;
13
+ }
14
+ export interface PlatformWorkerHandle {
15
+ onmessage: WorkerMessageHandler | null;
16
+ onerror: WorkerErrorHandler | null;
17
+ postMessage(value: unknown): void;
18
+ terminate(): void | Promise<number>;
19
+ addEventListener(type: "message" | "error", listener: WorkerMessageHandler | WorkerErrorHandler): void;
20
+ removeEventListener(type: "message" | "error", listener: WorkerMessageHandler | WorkerErrorHandler): void;
21
+ }
22
+ export type PlatformWorkerConstructor = new (specifier: string | URL, options?: PlatformWorkerOptions) => PlatformWorkerHandle;
23
+ export declare const Worker: PlatformWorkerConstructor;
24
+ export declare const isWorkerRuntime: boolean;
25
+ export declare function postWorkerMessage(value: unknown): void;
26
+ export declare function setWorkerMessageHandler<T>(handler: WorkerMessageHandler<T>): () => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { type LineInfo, type RenderContext } from "../types.js";
2
+ import { StyledText } from "../lib/styled-text.js";
2
3
  import { SyntaxStyle } from "../syntax-style.js";
3
4
  import { TreeSitterClient } from "../lib/tree-sitter/index.js";
4
5
  import { TextBufferRenderable, type TextBufferOptions } from "./TextBufferRenderable.js";
@@ -23,6 +24,7 @@ export interface CodeOptions extends TextBufferOptions {
23
24
  conceal?: boolean;
24
25
  drawUnstyledText?: boolean;
25
26
  streaming?: boolean;
27
+ initialStyledText?: StyledText;
26
28
  baseHighlight?: string;
27
29
  onHighlight?: OnHighlightCallback;
28
30
  onChunks?: OnChunksCallback;
@@ -39,6 +41,7 @@ export declare class CodeRenderable extends TextBufferRenderable {
39
41
  private _drawUnstyledText;
40
42
  private _shouldRenderTextBuffer;
41
43
  private _streaming;
44
+ private _initialStyledText?;
42
45
  private _hadInitialContent;
43
46
  private _lastHighlights;
44
47
  private _baseHighlight?;
@@ -70,6 +73,7 @@ export declare class CodeRenderable extends TextBufferRenderable {
70
73
  get drawUnstyledText(): boolean;
71
74
  set drawUnstyledText(value: boolean);
72
75
  get streaming(): boolean;
76
+ set initialStyledText(value: StyledText | undefined);
73
77
  set streaming(value: boolean);
74
78
  get treeSitterClient(): TreeSitterClient;
75
79
  set treeSitterClient(value: TreeSitterClient);
@@ -179,6 +179,7 @@ export declare class MarkdownRenderable extends Renderable {
179
179
  private getStyle;
180
180
  private createChunk;
181
181
  private createDefaultChunk;
182
+ private createInitialStyledText;
182
183
  private renderInlineContent;
183
184
  private renderInlineToken;
184
185
  private renderInlineTokenWithStyle;
@@ -1,18 +1,36 @@
1
- // @bun
2
- import {
3
- ensureRuntimePluginSupport
4
- } from "./index-jh82sd41.js";
5
- import {
6
- createRuntimePlugin,
7
- runtimeModuleIdForSpecifier
8
- } from "./index-mbck6rbg.js";
9
- import"./index-qndc8vq8.js";
10
- import"./index-mn090kzf.js";
11
- export {
12
- runtimeModuleIdForSpecifier,
13
- ensureRuntimePluginSupport,
14
- createRuntimePlugin
15
- };
16
-
17
- //# debugId=20E180CC53AAFA2A64756E2164756E21
18
- //# sourceMappingURL=runtime-plugin-support-configure.js.map
1
+ import { plugin as registerBunPlugin } from "bun";
2
+ import { createRuntimePlugin } from "./runtime-plugin.js";
3
+ const runtimePluginSupportInstalledKey = "__opentuiCoreRuntimePluginSupportInstalled__";
4
+ function normalizeRewriteKey(rewrite) {
5
+ return `${rewrite?.nodeModulesRuntimeSpecifiers ?? true}:${rewrite?.nodeModulesBareSpecifiers ?? false}`;
6
+ }
7
+ function assertCompatibleInstall(install, options) {
8
+ for (const specifier of Object.keys(options.additional ?? {})) {
9
+ if (!install.additionalSpecifiers.has(specifier)) {
10
+ throw new Error(`OpenTUI Core runtime plugin support is already installed without ${specifier}. Call ensureRuntimePluginSupport({ additional }) from @opentui/core/runtime-plugin-support/configure before importing @opentui/core/runtime-plugin-support.`);
11
+ }
12
+ }
13
+ if (options.core && options.core !== install.core) {
14
+ throw new Error("OpenTUI Core runtime plugin support is already installed with a different core runtime module.");
15
+ }
16
+ if (options.rewrite && normalizeRewriteKey(options.rewrite) !== install.rewriteKey) {
17
+ throw new Error("OpenTUI Core runtime plugin support is already installed with different rewrite options.");
18
+ }
19
+ }
20
+ export function ensureRuntimePluginSupport(options = {}) {
21
+ const state = globalThis;
22
+ const install = state[runtimePluginSupportInstalledKey];
23
+ if (install) {
24
+ assertCompatibleInstall(install, options);
25
+ return false;
26
+ }
27
+ registerBunPlugin(createRuntimePlugin(options));
28
+ state[runtimePluginSupportInstalledKey] = {
29
+ additionalSpecifiers: new Set(Object.keys(options.additional ?? {})),
30
+ core: options.core,
31
+ rewriteKey: normalizeRewriteKey(options.rewrite),
32
+ };
33
+ return true;
34
+ }
35
+ export { createRuntimePlugin, runtimeModuleIdForSpecifier } from "./runtime-plugin.js";
36
+ //# sourceMappingURL=runtime-plugin-support-configure.js.map
@@ -1,9 +1 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [
5
- ],
6
- "mappings": "",
7
- "debugId": "20E180CC53AAFA2A64756E2164756E21",
8
- "names": []
9
- }
1
+ {"version":3,"file":"runtime-plugin-support-configure.js","sourceRoot":"","sources":["runtime-plugin-support-configure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,KAAK,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAA4D,MAAM,qBAAqB,CAAA;AAE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AAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QACpE,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC;KACjD,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,15 @@
1
+ const errorMessage = "@opentui/core/runtime-plugin-support/configure is Bun-only and is not available in Node.js. Use Bun to import this entrypoint."
2
+
3
+ export function ensureRuntimePluginSupport() {
4
+ throw new Error("@opentui/core/runtime-plugin-support/configure is Bun-only and is not available in Node.js. Use Bun to import this entrypoint.")
5
+ }
6
+
7
+ export function createRuntimePlugin() {
8
+ throw new Error("@opentui/core/runtime-plugin-support/configure is Bun-only and is not available in Node.js. Use Bun to import this entrypoint.")
9
+ }
10
+
11
+ export function runtimeModuleIdForSpecifier() {
12
+ throw new Error("@opentui/core/runtime-plugin-support/configure is Bun-only and is not available in Node.js. Use Bun to import this entrypoint.")
13
+ }
14
+
15
+ throw new Error(errorMessage)
@@ -1,20 +1,5 @@
1
- // @bun
2
- import {
3
- ensureRuntimePluginSupport
4
- } from "./index-jh82sd41.js";
5
- import {
6
- createRuntimePlugin,
7
- runtimeModuleIdForSpecifier
8
- } from "./index-mbck6rbg.js";
9
- import"./index-qndc8vq8.js";
10
- import"./index-mn090kzf.js";
11
- // src/runtime-plugin-support.ts
1
+ import { ensureRuntimePluginSupport } from "./runtime-plugin-support-configure.js";
2
+ export { ensureRuntimePluginSupport };
3
+ export { createRuntimePlugin, runtimeModuleIdForSpecifier, } from "./runtime-plugin-support-configure.js";
12
4
  ensureRuntimePluginSupport();
13
- export {
14
- runtimeModuleIdForSpecifier,
15
- ensureRuntimePluginSupport,
16
- createRuntimePlugin
17
- };
18
-
19
- //# debugId=77F70D7DCCE5C8F764756E2164756E21
20
- //# sourceMappingURL=runtime-plugin-support.js.map
5
+ //# sourceMappingURL=runtime-plugin-support.js.map
@@ -1,10 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/runtime-plugin-support.ts"],
4
- "sourcesContent": [
5
- "import { ensureRuntimePluginSupport } from \"./runtime-plugin-support-configure.js\"\n\nexport { ensureRuntimePluginSupport }\nexport {\n createRuntimePlugin,\n runtimeModuleIdForSpecifier,\n type CreateRuntimePluginOptions,\n type RuntimeModuleEntry,\n type RuntimeModuleExports,\n type RuntimeModuleLoader,\n} from \"./runtime-plugin-support-configure.js\"\n\nensureRuntimePluginSupport()\n"
6
- ],
7
- "mappings": ";;;;;;;;;;;AAYA,2BAA2B;",
8
- "debugId": "77F70D7DCCE5C8F764756E2164756E21",
9
- "names": []
10
- }
1
+ {"version":3,"file":"runtime-plugin-support.js","sourceRoot":"","sources":["runtime-plugin-support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAA;AAElF,OAAO,EAAE,0BAA0B,EAAE,CAAA;AACrC,OAAO,EACL,mBAAmB,EACnB,2BAA2B,GAK5B,MAAM,uCAAuC,CAAA;AAE9C,0BAA0B,EAAE,CAAA"}
@@ -0,0 +1,15 @@
1
+ const errorMessage = "@opentui/core/runtime-plugin-support is Bun-only and is not available in Node.js. Use Bun to import this entrypoint."
2
+
3
+ export function ensureRuntimePluginSupport() {
4
+ throw new Error("@opentui/core/runtime-plugin-support is Bun-only and is not available in Node.js. Use Bun to import this entrypoint.")
5
+ }
6
+
7
+ export function createRuntimePlugin() {
8
+ throw new Error("@opentui/core/runtime-plugin-support is Bun-only and is not available in Node.js. Use Bun to import this entrypoint.")
9
+ }
10
+
11
+ export function runtimeModuleIdForSpecifier() {
12
+ throw new Error("@opentui/core/runtime-plugin-support is Bun-only and is not available in Node.js. Use Bun to import this entrypoint.")
13
+ }
14
+
15
+ throw new Error(errorMessage)