@opentui/core 0.0.0-20250923-da12fb15 → 0.0.0-20250924-d06b64fa

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
@@ -5,7 +5,7 @@ import {
5
5
  __export,
6
6
  __require,
7
7
  __toESM
8
- } from "./index-ce0mn4wa.js";
8
+ } from "./index-6kvgbzah.js";
9
9
 
10
10
  // ../../node_modules/omggif/omggif.js
11
11
  var require_omggif = __commonJS((exports) => {
@@ -1,3 +1,4 @@
1
+ import type { CliRenderer } from "../renderer";
1
2
  export interface TimelineOptions {
2
3
  duration?: number;
3
4
  loop?: boolean;
@@ -111,7 +112,7 @@ declare class TimelineEngine {
111
112
  defaults: {
112
113
  frameRate: number;
113
114
  };
114
- attach(renderer: any): void;
115
+ attach(renderer: CliRenderer): void;
115
116
  detach(): void;
116
117
  private updateLiveState;
117
118
  private onTimelineStateChange;
@@ -4814,6 +4814,166 @@ class ASCIIFontSelectionHelper {
4814
4814
  return previousSelection?.start !== this.localSelection?.start || previousSelection?.end !== this.localSelection?.end;
4815
4815
  }
4816
4816
  }
4817
+
4818
+ // src/lib/singleton.ts
4819
+ var singletonCacheSymbol = Symbol.for("@opentui/core/singleton");
4820
+ function singleton(key, factory) {
4821
+ const bag = globalThis[singletonCacheSymbol] ??= {};
4822
+ if (!(key in bag)) {
4823
+ bag[key] = factory();
4824
+ }
4825
+ return bag[key];
4826
+ }
4827
+
4828
+ // src/lib/env.ts
4829
+ var envRegistry = {};
4830
+ function registerEnvVar(config) {
4831
+ const existing = envRegistry[config.name];
4832
+ if (existing) {
4833
+ if (existing.description !== config.description || existing.type !== config.type || existing.default !== config.default) {
4834
+ throw new Error(`Environment variable "${config.name}" is already registered with different configuration. ` + `Existing: ${JSON.stringify(existing)}, New: ${JSON.stringify(config)}`);
4835
+ }
4836
+ return;
4837
+ }
4838
+ envRegistry[config.name] = config;
4839
+ }
4840
+ function normalizeBoolean(value) {
4841
+ const lowerValue = value.toLowerCase();
4842
+ return ["true", "1", "on", "yes"].includes(lowerValue);
4843
+ }
4844
+ function parseEnvValue(config) {
4845
+ const envValue = process.env[config.name];
4846
+ if (envValue === undefined && config.default !== undefined) {
4847
+ return config.default;
4848
+ }
4849
+ if (envValue === undefined) {
4850
+ throw new Error(`Required environment variable ${config.name} is not set. ${config.description}`);
4851
+ }
4852
+ switch (config.type) {
4853
+ case "boolean":
4854
+ return typeof envValue === "boolean" ? envValue : normalizeBoolean(envValue);
4855
+ case "number":
4856
+ const numValue = Number(envValue);
4857
+ if (isNaN(numValue)) {
4858
+ throw new Error(`Environment variable ${config.name} must be a valid number, got: ${envValue}`);
4859
+ }
4860
+ return numValue;
4861
+ case "string":
4862
+ default:
4863
+ return envValue;
4864
+ }
4865
+ }
4866
+
4867
+ class EnvStore {
4868
+ parsedValues = new Map;
4869
+ get(key) {
4870
+ if (this.parsedValues.has(key)) {
4871
+ return this.parsedValues.get(key);
4872
+ }
4873
+ if (!(key in envRegistry)) {
4874
+ throw new Error(`Environment variable ${key} is not registered.`);
4875
+ }
4876
+ try {
4877
+ const value = parseEnvValue(envRegistry[key]);
4878
+ this.parsedValues.set(key, value);
4879
+ return value;
4880
+ } catch (error) {
4881
+ throw new Error(`Failed to parse env var ${key}: ${error instanceof Error ? error.message : String(error)}`);
4882
+ }
4883
+ }
4884
+ has(key) {
4885
+ return key in envRegistry;
4886
+ }
4887
+ }
4888
+ var envStore = singleton("env-store", () => new EnvStore);
4889
+ function generateEnvMarkdown() {
4890
+ const configs = Object.values(envRegistry);
4891
+ if (configs.length === 0) {
4892
+ return `# Environment Variables
4893
+
4894
+ No environment variables registered.
4895
+ `;
4896
+ }
4897
+ let markdown = `# Environment Variables
4898
+
4899
+ `;
4900
+ for (const config of configs) {
4901
+ markdown += `## ${config.name}
4902
+
4903
+ `;
4904
+ markdown += `${config.description}
4905
+
4906
+ `;
4907
+ markdown += `**Type:** \`${config.type || "string"}\`
4908
+ `;
4909
+ if (config.default !== undefined) {
4910
+ const defaultValue = typeof config.default === "string" ? `"${config.default}"` : String(config.default);
4911
+ markdown += `**Default:** \`${defaultValue}\`
4912
+ `;
4913
+ } else {
4914
+ markdown += `**Default:** *Required*
4915
+ `;
4916
+ }
4917
+ markdown += `
4918
+ `;
4919
+ }
4920
+ return markdown;
4921
+ }
4922
+ function generateEnvColored() {
4923
+ const configs = Object.values(envRegistry);
4924
+ if (configs.length === 0) {
4925
+ return `\x1B[1;36mEnvironment Variables\x1B[0m
4926
+
4927
+ No environment variables registered.
4928
+ `;
4929
+ }
4930
+ let output = `\x1B[1;36mEnvironment Variables\x1B[0m
4931
+
4932
+ `;
4933
+ for (const config of configs) {
4934
+ output += `\x1B[1;33m${config.name}\x1B[0m
4935
+ `;
4936
+ output += `${config.description}
4937
+ `;
4938
+ output += `\x1B[32mType:\x1B[0m \x1B[36m${config.type || "string"}\x1B[0m
4939
+ `;
4940
+ if (config.default !== undefined) {
4941
+ const defaultValue = typeof config.default === "string" ? `"${config.default}"` : String(config.default);
4942
+ output += `\x1B[32mDefault:\x1B[0m \x1B[35m${defaultValue}\x1B[0m
4943
+ `;
4944
+ } else {
4945
+ output += `\x1B[32mDefault:\x1B[0m \x1B[31mRequired\x1B[0m
4946
+ `;
4947
+ }
4948
+ output += `
4949
+ `;
4950
+ }
4951
+ return output;
4952
+ }
4953
+ var env = new Proxy({}, {
4954
+ get(target, prop) {
4955
+ if (typeof prop !== "string") {
4956
+ return;
4957
+ }
4958
+ return envStore.get(prop);
4959
+ },
4960
+ has(target, prop) {
4961
+ return envStore.has(prop);
4962
+ },
4963
+ ownKeys() {
4964
+ return Object.keys(envRegistry);
4965
+ },
4966
+ getOwnPropertyDescriptor(target, prop) {
4967
+ if (envStore.has(prop)) {
4968
+ return {
4969
+ enumerable: true,
4970
+ configurable: true,
4971
+ get: () => envStore.get(prop)
4972
+ };
4973
+ }
4974
+ return;
4975
+ }
4976
+ });
4817
4977
  // src/zig.ts
4818
4978
  import { dlopen, toArrayBuffer as toArrayBuffer2, JSCallback, ptr } from "bun:ffi";
4819
4979
  import { existsSync } from "fs";
@@ -5020,6 +5180,18 @@ var targetLibPath = module.default;
5020
5180
  if (!existsSync(targetLibPath)) {
5021
5181
  throw new Error(`opentui is not supported on the current platform: ${process.platform}-${process.arch}`);
5022
5182
  }
5183
+ registerEnvVar({
5184
+ name: "OTUI_DEBUG_FFI",
5185
+ description: "Enable debug logging for the FFI bindings.",
5186
+ type: "boolean",
5187
+ default: false
5188
+ });
5189
+ registerEnvVar({
5190
+ name: "OTUI_TRACE_FFI",
5191
+ description: "Enable tracing for the FFI bindings.",
5192
+ type: "boolean",
5193
+ default: false
5194
+ });
5023
5195
  function getOpenTUILib(libPath) {
5024
5196
  const resolvedLibPath = libPath || targetLibPath;
5025
5197
  const rawSymbols = dlopen(resolvedLibPath, {
@@ -5360,7 +5532,7 @@ function getOpenTUILib(libPath) {
5360
5532
  returns: "void"
5361
5533
  }
5362
5534
  });
5363
- if (process.env.DEBUG_FFI === "true" || process.env.TRACE_FFI === "true") {
5535
+ if (env.OTUI_DEBUG_FFI || env.OTUI_TRACE_FFI) {
5364
5536
  return {
5365
5537
  symbols: convertToDebugSymbols(rawSymbols.symbols)
5366
5538
  };
@@ -5374,7 +5546,7 @@ function convertToDebugSymbols(symbols) {
5374
5546
  Object.entries(symbols).forEach(([key, value]) => {
5375
5547
  debugSymbols[key] = value;
5376
5548
  });
5377
- if (process.env.DEBUG_FFI === "true") {
5549
+ if (env.OTUI_DEBUG_FFI) {
5378
5550
  Object.entries(symbols).forEach(([key, value]) => {
5379
5551
  if (typeof value === "function") {
5380
5552
  debugSymbols[key] = (...args) => {
@@ -5386,7 +5558,7 @@ function convertToDebugSymbols(symbols) {
5386
5558
  }
5387
5559
  });
5388
5560
  }
5389
- if (process.env.TRACE_FFI === "true") {
5561
+ if (env.OTUI_TRACE_FFI) {
5390
5562
  hasTracing = true;
5391
5563
  Object.entries(symbols).forEach(([key, value]) => {
5392
5564
  if (typeof value === "function") {
@@ -7547,16 +7719,6 @@ class CapturedWritableStream extends Writable {
7547
7719
  }
7548
7720
  }
7549
7721
 
7550
- // src/singleton.ts
7551
- var singletonCacheSymbol = Symbol.for("@opentui/core/singleton");
7552
- function singleton(key, factory) {
7553
- const bag = globalThis[singletonCacheSymbol] ??= {};
7554
- if (!(key in bag)) {
7555
- bag[key] = factory();
7556
- }
7557
- return bag[key];
7558
- }
7559
-
7560
7722
  // src/console.ts
7561
7723
  function getCallerInfo() {
7562
7724
  const err = new Error;
@@ -7577,6 +7739,18 @@ function getCallerInfo() {
7577
7739
  return { functionName, fullPath, fileName, lineNumber, columnNumber };
7578
7740
  }
7579
7741
  var capture = singleton("ConsoleCapture", () => new Capture);
7742
+ registerEnvVar({
7743
+ name: "OTUI_USE_CONSOLE",
7744
+ description: "Whether to use the console. Will not capture console output if set to false.",
7745
+ type: "boolean",
7746
+ default: true
7747
+ });
7748
+ registerEnvVar({
7749
+ name: "SHOW_CONSOLE",
7750
+ description: "Show the console at startup if set to true.",
7751
+ type: "boolean",
7752
+ default: false
7753
+ });
7580
7754
 
7581
7755
  class TerminalConsoleCache extends EventEmitter4 {
7582
7756
  _cachedLogs = [];
@@ -7594,7 +7768,7 @@ class TerminalConsoleCache extends EventEmitter4 {
7594
7768
  this.overrideConsoleMethods();
7595
7769
  }
7596
7770
  setupConsoleCapture() {
7597
- if (process.env.OTUI_USE_CONSOLE === "false")
7771
+ if (!env.OTUI_USE_CONSOLE)
7598
7772
  return;
7599
7773
  const mockStdout = new CapturedWritableStream("stdout", capture);
7600
7774
  const mockStderr = new CapturedWritableStream("stderr", capture);
@@ -7759,7 +7933,7 @@ class TerminalConsole extends EventEmitter4 {
7759
7933
  terminalConsoleCache.on("entry", (logEntry) => {
7760
7934
  this._handleNewLog(logEntry);
7761
7935
  });
7762
- if (process.env.SHOW_CONSOLE === "true") {
7936
+ if (env.SHOW_CONSOLE) {
7763
7937
  this.show();
7764
7938
  }
7765
7939
  }
@@ -8237,6 +8411,19 @@ function getObjectsInViewport(viewport, objects, direction = "column", padding =
8237
8411
  }
8238
8412
 
8239
8413
  // src/renderer.ts
8414
+ registerEnvVar({
8415
+ name: "OTUI_DUMP_CAPTURES",
8416
+ description: "Dump captured output when the renderer exits.",
8417
+ type: "boolean",
8418
+ default: false
8419
+ });
8420
+ registerEnvVar({
8421
+ name: "OTUI_NO_NATIVE_RENDER",
8422
+ description: "Disable native rendering. This will not actually output ansi and is useful for debugging.",
8423
+ type: "boolean",
8424
+ default: false
8425
+ });
8426
+
8240
8427
  class MouseEvent {
8241
8428
  type;
8242
8429
  button;
@@ -8468,8 +8655,8 @@ Captured output:
8468
8655
  }
8469
8656
  exitHandler = (() => {
8470
8657
  this.destroy();
8471
- if (true) {
8472
- this.dumpOutputCache(`=== UNHANDLED OUTPUT (this is only printed in non-production environments) ===
8658
+ if (env.OTUI_DUMP_CAPTURES) {
8659
+ this.dumpOutputCache(`=== CAPTURED OUTPUT ===
8473
8660
  `);
8474
8661
  }
8475
8662
  }).bind(this);
@@ -8535,7 +8722,7 @@ Captured output:
8535
8722
  global.window = {};
8536
8723
  }
8537
8724
  global.window.requestAnimationFrame = requestAnimationFrame;
8538
- if (process.env.OTUI_NO_NATIVE_RENDER === "true") {
8725
+ if (env.OTUI_NO_NATIVE_RENDER) {
8539
8726
  this.renderNative = () => {
8540
8727
  if (this._splitHeight > 0) {
8541
8728
  this.flushStdoutCache(this._splitHeight);
@@ -9385,7 +9572,7 @@ Captured output:
9385
9572
  }
9386
9573
  }
9387
9574
 
9388
- export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, KeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, 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, t, SyntaxStyle, hastToStyledText, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, CliRenderer };
9575
+ export { __toESM, __commonJS, __export, __require, Edge, Gutter, exports_src, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, nonAlphanumericKeys, parseKeypress, ANSI, KeyHandler, RGBA, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, DebugOverlayCorner, createTextAttributes, 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, t, SyntaxStyle, hastToStyledText, parseAlign, parseBoxSizing, parseDimension, parseDirection, parseDisplay, parseEdge, parseFlexDirection, parseGutter, parseJustify, parseLogLevel, parseMeasureMode, parseOverflow, parsePositionType, parseUnit, parseWrap, MouseParser, Selection, convertGlobalToLocalSelection, ASCIIFontSelectionHelper, envRegistry, registerEnvVar, generateEnvMarkdown, generateEnvColored, env, TextBuffer, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, isValidPercentage, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, CliRenderer };
9389
9576
 
9390
- //# debugId=E1BF4DFE4379457164756E2164756E21
9391
- //# sourceMappingURL=index-ce0mn4wa.js.map
9577
+ //# debugId=FA47EE78BCA83E8664756E2164756E21
9578
+ //# sourceMappingURL=index-6kvgbzah.js.map