@opentui/core 0.1.106 → 0.2.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.
@@ -1969,11 +1969,11 @@ class InternalKeyHandler extends KeyHandler {
1969
1969
  }
1970
1970
 
1971
1971
  // src/lib/RGBA.ts
1972
- var COLOR_TAG_RGB = 256;
1973
- var COLOR_TAG_DEFAULT = 257;
1974
1972
  var DEFAULT_FOREGROUND_RGB = [255, 255, 255];
1975
1973
  var DEFAULT_BACKGROUND_RGB = [0, 0, 0];
1976
- var RGBA_BUFFER_STRIDE = 5;
1974
+ var INTENT_RGB = 0;
1975
+ var INTENT_INDEXED = 1;
1976
+ var INTENT_DEFAULT = 2;
1977
1977
  var ANSI16_RGB = [
1978
1978
  [0, 0, 0],
1979
1979
  [128, 0, 0],
@@ -1993,33 +1993,22 @@ var ANSI16_RGB = [
1993
1993
  [255, 255, 255]
1994
1994
  ];
1995
1995
  var ANSI_256_CUBE_LEVELS = [0, 95, 135, 175, 215, 255];
1996
- function normalizeColorTag(tag) {
1997
- const normalizedTag = tag != null && Number.isFinite(tag) ? Math.round(tag) : COLOR_TAG_RGB;
1998
- if (normalizedTag === COLOR_TAG_RGB || normalizedTag === COLOR_TAG_DEFAULT) {
1999
- return normalizedTag;
2000
- }
2001
- if (Number.isInteger(normalizedTag) && normalizedTag >= 0 && normalizedTag <= 255) {
2002
- return normalizedTag;
2003
- }
2004
- return COLOR_TAG_RGB;
1996
+ function packMeta(intent, slot = 0) {
1997
+ return (slot & 255 | (intent & 255) << 8) >>> 0;
2005
1998
  }
2006
- function normalizeRGBABuffer(buffer) {
2007
- if (buffer.length === RGBA_BUFFER_STRIDE) {
2008
- buffer[4] = normalizeColorTag(buffer[4]);
2009
- return buffer;
2010
- }
2011
- const normalized = new Float32Array(RGBA_BUFFER_STRIDE);
2012
- normalized[0] = buffer[0] ?? 0;
2013
- normalized[1] = buffer[1] ?? 0;
2014
- normalized[2] = buffer[2] ?? 0;
2015
- normalized[3] = buffer[3] ?? 0;
2016
- normalized[4] = COLOR_TAG_RGB;
2017
- return normalized;
1999
+ function toU8(value) {
2000
+ return Math.round(Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0)) * 255);
2018
2001
  }
2019
- function withTag(rgba, tag) {
2020
- const tagged = RGBA.clone(rgba);
2021
- tagged.tag = tag;
2022
- return tagged;
2002
+ function toByte(value) {
2003
+ return Math.round(Math.max(0, Math.min(255, Number.isFinite(value) ? value : 0)));
2004
+ }
2005
+ function packRGBA8(r, g, b, a, meta) {
2006
+ return new Uint16Array([
2007
+ toByte(r) & 255 | (meta >>> 0 & 255) << 8,
2008
+ toByte(g) & 255 | (meta >>> 8 & 255) << 8,
2009
+ toByte(b) & 255 | (meta >>> 16 & 255) << 8,
2010
+ toByte(a) & 255 | (meta >>> 24 & 255) << 8
2011
+ ]);
2023
2012
  }
2024
2013
  function rgbaForAnsi256Index(index) {
2025
2014
  const [r, g, b] = ansi256IndexToRgb(index);
@@ -2046,81 +2035,86 @@ function ansi256IndexToRgb(index) {
2046
2035
  const value = 8 + (normalizedIndex - 232) * 10;
2047
2036
  return [value, value, value];
2048
2037
  }
2049
- function decodeColorTag(tag) {
2050
- if (tag === COLOR_TAG_DEFAULT) {
2051
- return { kind: "default" };
2052
- }
2053
- if (tag === COLOR_TAG_RGB) {
2054
- return { kind: "rgb" };
2055
- }
2056
- return { kind: "indexed", index: normalizeIndexedColorIndex(tag) };
2057
- }
2058
2038
 
2059
2039
  class RGBA {
2060
2040
  buffer;
2061
2041
  constructor(buffer) {
2062
- this.buffer = normalizeRGBABuffer(buffer);
2042
+ this.buffer = new Uint16Array(4);
2043
+ this.buffer.set(buffer.subarray(0, 4));
2063
2044
  }
2064
2045
  static fromArray(array) {
2065
2046
  return new RGBA(array);
2066
2047
  }
2067
- static fromValues(r, g, b, a = 1, tag = COLOR_TAG_RGB) {
2068
- return new RGBA(new Float32Array([r, g, b, a, normalizeColorTag(tag)]));
2048
+ static fromValues(r, g, b, a = 1) {
2049
+ return new RGBA(packRGBA8(toU8(r), toU8(g), toU8(b), toU8(a), packMeta(INTENT_RGB)));
2069
2050
  }
2070
2051
  static clone(rgba) {
2071
- return RGBA.fromValues(rgba.r, rgba.g, rgba.b, rgba.a, rgba.tag);
2052
+ return new RGBA(rgba.buffer);
2072
2053
  }
2073
- static fromInts(r, g, b, a = 255, tag = COLOR_TAG_RGB) {
2074
- return new RGBA(new Float32Array([r / 255, g / 255, b / 255, a / 255, normalizeColorTag(tag)]));
2054
+ static fromInts(r, g, b, a = 255) {
2055
+ return new RGBA(packRGBA8(r, g, b, a, packMeta(INTENT_RGB)));
2075
2056
  }
2076
2057
  static fromHex(hex) {
2077
2058
  return hexToRgb(hex);
2078
2059
  }
2079
2060
  static fromIndex(index, snapshot) {
2080
- const normalizedIndex = normalizeIndexedColorIndex(index);
2081
- return withTag(snapshot ? parseColor(snapshot) : rgbaForAnsi256Index(normalizedIndex), normalizedIndex);
2061
+ const normalized = normalizeIndexedColorIndex(index);
2062
+ const rgba = snapshot ? parseColor(snapshot) : rgbaForAnsi256Index(normalized);
2063
+ const [r, g, b, a] = rgba.toInts();
2064
+ return new RGBA(packRGBA8(r, g, b, a, packMeta(INTENT_INDEXED, normalized)));
2082
2065
  }
2083
2066
  static defaultForeground(snapshot) {
2084
- return withTag(snapshot ? parseColor(snapshot) : RGBA.fromInts(...DEFAULT_FOREGROUND_RGB), COLOR_TAG_DEFAULT);
2067
+ const rgba = snapshot ? parseColor(snapshot) : RGBA.fromInts(...DEFAULT_FOREGROUND_RGB);
2068
+ const [r, g, b, a] = rgba.toInts();
2069
+ return new RGBA(packRGBA8(r, g, b, a, packMeta(INTENT_DEFAULT)));
2085
2070
  }
2086
2071
  static defaultBackground(snapshot) {
2087
- return withTag(snapshot ? parseColor(snapshot) : RGBA.fromInts(...DEFAULT_BACKGROUND_RGB), COLOR_TAG_DEFAULT);
2088
- }
2089
- static getIntentTag(rgba) {
2090
- return rgba.tag;
2072
+ const rgba = snapshot ? parseColor(snapshot) : RGBA.fromInts(...DEFAULT_BACKGROUND_RGB);
2073
+ const [r, g, b, a] = rgba.toInts();
2074
+ return new RGBA(packRGBA8(r, g, b, a, packMeta(INTENT_DEFAULT)));
2091
2075
  }
2092
2076
  toInts() {
2093
- return [Math.round(this.r * 255), Math.round(this.g * 255), Math.round(this.b * 255), Math.round(this.a * 255)];
2077
+ return [this.buffer[0] & 255, this.buffer[1] & 255, this.buffer[2] & 255, this.buffer[3] & 255];
2094
2078
  }
2095
2079
  get r() {
2096
- return this.buffer[0];
2080
+ return (this.buffer[0] & 255) / 255;
2097
2081
  }
2098
2082
  set r(value) {
2099
- this.buffer[0] = value;
2083
+ this.buffer[0] = this.buffer[0] & 65280 | toU8(value);
2100
2084
  }
2101
2085
  get g() {
2102
- return this.buffer[1];
2086
+ return (this.buffer[1] & 255) / 255;
2103
2087
  }
2104
2088
  set g(value) {
2105
- this.buffer[1] = value;
2089
+ this.buffer[1] = this.buffer[1] & 65280 | toU8(value);
2106
2090
  }
2107
2091
  get b() {
2108
- return this.buffer[2];
2092
+ return (this.buffer[2] & 255) / 255;
2109
2093
  }
2110
2094
  set b(value) {
2111
- this.buffer[2] = value;
2095
+ this.buffer[2] = this.buffer[2] & 65280 | toU8(value);
2112
2096
  }
2113
2097
  get a() {
2114
- return this.buffer[3];
2098
+ return (this.buffer[3] & 255) / 255;
2115
2099
  }
2116
2100
  set a(value) {
2117
- this.buffer[3] = value;
2101
+ this.buffer[3] = this.buffer[3] & 65280 | toU8(value);
2102
+ }
2103
+ get meta() {
2104
+ return (this.buffer[0] >>> 8 | this.buffer[1] >>> 8 << 8 | this.buffer[2] >>> 8 << 16 | this.buffer[3] >>> 8 << 24) >>> 0;
2118
2105
  }
2119
- get tag() {
2120
- return normalizeColorTag(this.buffer[4]);
2106
+ get intent() {
2107
+ switch (this.meta >>> 8 & 255) {
2108
+ case INTENT_INDEXED:
2109
+ return "indexed";
2110
+ case INTENT_DEFAULT:
2111
+ return "default";
2112
+ default:
2113
+ return "rgb";
2114
+ }
2121
2115
  }
2122
- set tag(value) {
2123
- this.buffer[4] = normalizeColorTag(value);
2116
+ get slot() {
2117
+ return this.meta & 255;
2124
2118
  }
2125
2119
  map(fn) {
2126
2120
  return [fn(this.r), fn(this.g), fn(this.b), fn(this.a)];
@@ -2131,14 +2125,13 @@ class RGBA {
2131
2125
  equals(other) {
2132
2126
  if (!other)
2133
2127
  return false;
2134
- return this.r === other.r && this.g === other.g && this.b === other.b && this.a === other.a && this.tag === other.tag;
2128
+ return this.buffer[0] === other.buffer[0] && this.buffer[1] === other.buffer[1] && this.buffer[2] === other.buffer[2] && this.buffer[3] === other.buffer[3];
2135
2129
  }
2136
2130
  }
2137
2131
  function normalizeColorValue(value) {
2138
2132
  if (value == null)
2139
2133
  return null;
2140
- const rgba = parseColor(value);
2141
- return { rgba, tag: rgba.tag };
2134
+ return { rgba: parseColor(value) };
2142
2135
  }
2143
2136
  function hexToRgb(hex) {
2144
2137
  hex = hex.replace(/^#/, "");
@@ -2151,18 +2144,16 @@ function hexToRgb(hex) {
2151
2144
  console.warn(`Invalid hex color: ${hex}, defaulting to magenta`);
2152
2145
  return RGBA.fromValues(1, 0, 1, 1);
2153
2146
  }
2154
- const r = parseInt(hex.substring(0, 2), 16) / 255;
2155
- const g = parseInt(hex.substring(2, 4), 16) / 255;
2156
- const b = parseInt(hex.substring(4, 6), 16) / 255;
2157
- const a = hex.length === 8 ? parseInt(hex.substring(6, 8), 16) / 255 : 1;
2158
- return RGBA.fromValues(r, g, b, a);
2147
+ const r = parseInt(hex.substring(0, 2), 16);
2148
+ const g = parseInt(hex.substring(2, 4), 16);
2149
+ const b = parseInt(hex.substring(4, 6), 16);
2150
+ const a = hex.length === 8 ? parseInt(hex.substring(6, 8), 16) : 255;
2151
+ return RGBA.fromInts(r, g, b, a);
2159
2152
  }
2160
2153
  function rgbToHex(rgb) {
2161
- const components = rgb.a === 1 ? [rgb.r, rgb.g, rgb.b] : [rgb.r, rgb.g, rgb.b, rgb.a];
2162
- return "#" + components.map((x) => {
2163
- const hex = Math.floor(Math.max(0, Math.min(1, x) * 255)).toString(16);
2164
- return hex.length === 1 ? "0" + hex : hex;
2165
- }).join("");
2154
+ const [r, g, b, a] = rgb.toInts();
2155
+ const components = a === 255 ? [r, g, b] : [r, g, b, a];
2156
+ return "#" + components.map((x) => x.toString(16).padStart(2, "0")).join("");
2166
2157
  }
2167
2158
  function hsvToRgb(h, s, v) {
2168
2159
  let r = 0, g = 0, b = 0;
@@ -10911,7 +10902,6 @@ class OptimizedBuffer {
10911
10902
  _widthMethod;
10912
10903
  respectAlpha = false;
10913
10904
  _rawBuffers = null;
10914
- _rawColorTags = null;
10915
10905
  _destroyed = false;
10916
10906
  get ptr() {
10917
10907
  return this.bufferPtr;
@@ -10921,37 +10911,26 @@ class OptimizedBuffer {
10921
10911
  throw new Error(`Buffer ${this.id} is destroyed`);
10922
10912
  }
10923
10913
  ensureRawBufferViews() {
10924
- if (this._rawBuffers !== null && this._rawColorTags !== null) {
10914
+ if (this._rawBuffers !== null) {
10925
10915
  return;
10926
10916
  }
10927
10917
  const size = this._width * this._height;
10928
10918
  const charPtr = this.lib.bufferGetCharPtr(this.bufferPtr);
10929
10919
  const fgPtr = this.lib.bufferGetFgPtr(this.bufferPtr);
10930
10920
  const bgPtr = this.lib.bufferGetBgPtr(this.bufferPtr);
10931
- const fgTagPtr = this.lib.bufferGetFgTagPtr(this.bufferPtr);
10932
- const bgTagPtr = this.lib.bufferGetBgTagPtr(this.bufferPtr);
10933
10921
  const attributesPtr = this.lib.bufferGetAttributesPtr(this.bufferPtr);
10934
10922
  this._rawBuffers = {
10935
10923
  char: new Uint32Array(toArrayBuffer(charPtr, 0, size * 4)),
10936
- fg: new Float32Array(toArrayBuffer(fgPtr, 0, size * 4 * 4)),
10937
- bg: new Float32Array(toArrayBuffer(bgPtr, 0, size * 4 * 4)),
10924
+ fg: new Uint16Array(toArrayBuffer(fgPtr, 0, size * 4 * 2)),
10925
+ bg: new Uint16Array(toArrayBuffer(bgPtr, 0, size * 4 * 2)),
10938
10926
  attributes: new Uint32Array(toArrayBuffer(attributesPtr, 0, size * 4))
10939
10927
  };
10940
- this._rawColorTags = {
10941
- fg: new Uint16Array(toArrayBuffer(fgTagPtr, 0, size * 2)),
10942
- bg: new Uint16Array(toArrayBuffer(bgTagPtr, 0, size * 2))
10943
- };
10944
10928
  }
10945
10929
  get buffers() {
10946
10930
  this.guard();
10947
10931
  this.ensureRawBufferViews();
10948
10932
  return this._rawBuffers;
10949
10933
  }
10950
- get rawColorTags() {
10951
- this.guard();
10952
- this.ensureRawBufferViews();
10953
- return this._rawColorTags;
10954
- }
10955
10934
  constructor(lib, ptr2, width, height, options) {
10956
10935
  this.id = options.id || `fb_${OptimizedBuffer.fbIdCounter++}`;
10957
10936
  this.lib = lib;
@@ -10996,7 +10975,6 @@ class OptimizedBuffer {
10996
10975
  getSpanLines() {
10997
10976
  this.guard();
10998
10977
  const { char, fg: fg2, bg: bg2, attributes } = this.buffers;
10999
- const { fg: fgTag, bg: bgTag } = this.rawColorTags;
11000
10978
  const lines = [];
11001
10979
  const CHAR_FLAG_CONTINUATION = 3221225472 | 0;
11002
10980
  const CHAR_FLAG_MASK = 3221225472 | 0;
@@ -11011,8 +10989,8 @@ class OptimizedBuffer {
11011
10989
  for (let x = 0;x < this._width; x++) {
11012
10990
  const i = y * this._width + x;
11013
10991
  const cp = char[i];
11014
- const cellFg = RGBA.fromValues(fg2[i * 4], fg2[i * 4 + 1], fg2[i * 4 + 2], fg2[i * 4 + 3], fgTag[i]);
11015
- const cellBg = RGBA.fromValues(bg2[i * 4], bg2[i * 4 + 1], bg2[i * 4 + 2], bg2[i * 4 + 3], bgTag[i]);
10992
+ const cellFg = RGBA.fromArray(fg2.slice(i * 4, i * 4 + 4));
10993
+ const cellBg = RGBA.fromArray(bg2.slice(i * 4, i * 4 + 4));
11016
10994
  const cellAttrs = attributes[i] & 255;
11017
10995
  const isContinuation = (cp & CHAR_FLAG_MASK) === CHAR_FLAG_CONTINUATION;
11018
10996
  const cellChar = isContinuation ? "" : lineChars[charIdx++] ?? " ";
@@ -11140,7 +11118,6 @@ class OptimizedBuffer {
11140
11118
  this._width = width;
11141
11119
  this._height = height;
11142
11120
  this._rawBuffers = null;
11143
- this._rawColorTags = null;
11144
11121
  this.lib.bufferResize(this.bufferPtr, width, height);
11145
11122
  }
11146
11123
  drawBox(options) {
@@ -11812,7 +11789,7 @@ function defineStruct(fields, structDefOptions) {
11812
11789
  // src/zig-structs.ts
11813
11790
  import { ptr as ptr3, toArrayBuffer as toArrayBuffer3 } from "bun:ffi";
11814
11791
  var rgbaPackTransform = (rgba) => rgba ? ptr3(rgba.buffer) : null;
11815
- var rgbaUnpackTransform = (ptr4) => ptr4 ? RGBA.fromArray(new Float32Array(toArrayBuffer3(ptr4))) : undefined;
11792
+ var rgbaUnpackTransform = (ptr4) => ptr4 ? RGBA.fromArray(new Uint16Array(toArrayBuffer3(ptr4, 0, 8))) : undefined;
11816
11793
  var StyledChunkStruct = defineStruct([
11817
11794
  ["text", "char*"],
11818
11795
  ["text_len", "u64", { lengthOf: "text" }],
@@ -11834,8 +11811,6 @@ var StyledChunkStruct = defineStruct([
11834
11811
  unpackTransform: rgbaUnpackTransform
11835
11812
  }
11836
11813
  ],
11837
- ["fg_tag", "u16", { default: COLOR_TAG_RGB }],
11838
- ["bg_tag", "u16", { default: COLOR_TAG_RGB }],
11839
11814
  ["attributes", "u32", { default: 0 }],
11840
11815
  ["link", "char*", { default: "" }],
11841
11816
  ["link_len", "u64", { lengthOf: "link" }]
@@ -11847,17 +11822,13 @@ var StyledChunkStruct = defineStruct([
11847
11822
  return {
11848
11823
  ...chunk,
11849
11824
  fg: normalizedFg?.rgba ?? null,
11850
- bg: normalizedBg?.rgba ?? null,
11851
- fg_tag: normalizedFg?.tag ?? COLOR_TAG_RGB,
11852
- bg_tag: normalizedBg?.tag ?? COLOR_TAG_RGB
11825
+ bg: normalizedBg?.rgba ?? null
11853
11826
  };
11854
11827
  }
11855
11828
  return {
11856
11829
  ...chunk,
11857
11830
  fg: normalizedFg?.rgba ?? null,
11858
11831
  bg: normalizedBg?.rgba ?? null,
11859
- fg_tag: normalizedFg?.tag ?? COLOR_TAG_RGB,
11860
- bg_tag: normalizedBg?.tag ?? COLOR_TAG_RGB,
11861
11832
  link: chunk.link.url
11862
11833
  };
11863
11834
  }
@@ -12067,6 +12038,12 @@ function toPointer(value) {
12067
12038
  function toNumber(value) {
12068
12039
  return typeof value === "bigint" ? Number(value) : value;
12069
12040
  }
12041
+ function rgbaPtr(value) {
12042
+ return ptr4(value.buffer);
12043
+ }
12044
+ function optionalRgbaPtr(value) {
12045
+ return value ? rgbaPtr(value) : null;
12046
+ }
12070
12047
  function getOpenTUILib(libPath) {
12071
12048
  const resolvedLibPath = libPath || targetLibPath;
12072
12049
  const rawSymbols = dlopen(resolvedLibPath, {
@@ -12198,14 +12175,6 @@ function getOpenTUILib(libPath) {
12198
12175
  args: ["ptr"],
12199
12176
  returns: "ptr"
12200
12177
  },
12201
- bufferGetFgTagPtr: {
12202
- args: ["ptr"],
12203
- returns: "ptr"
12204
- },
12205
- bufferGetBgTagPtr: {
12206
- args: ["ptr"],
12207
- returns: "ptr"
12208
- },
12209
12178
  bufferGetAttributesPtr: {
12210
12179
  args: ["ptr"],
12211
12180
  returns: "ptr"
@@ -13375,7 +13344,7 @@ class FFIRenderLib {
13375
13344
  this.opentui.symbols.setClearOnShutdown(renderer, clear);
13376
13345
  }
13377
13346
  setBackgroundColor(renderer, color) {
13378
- this.opentui.symbols.setBackgroundColor(renderer, color.buffer);
13347
+ this.opentui.symbols.setBackgroundColor(renderer, rgbaPtr(color));
13379
13348
  }
13380
13349
  setRenderOffset(renderer, offset) {
13381
13350
  this.opentui.symbols.setRenderOffset(renderer, offset);
@@ -13417,16 +13386,11 @@ class FFIRenderLib {
13417
13386
  return new OptimizedBuffer(this, bufferPtr, width, height, { id: "current buffer", widthMethod: "unicode" });
13418
13387
  }
13419
13388
  rendererSetPaletteState(renderer, palette, defaultForeground, defaultBackground, paletteEpoch) {
13420
- const paletteBuffer = new Float32Array(palette.length * 4);
13389
+ const paletteBuffer = new Uint16Array(palette.length * 4);
13421
13390
  for (let index = 0;index < palette.length; index++) {
13422
- const color = palette[index];
13423
- const base = index * 4;
13424
- paletteBuffer[base] = color.r;
13425
- paletteBuffer[base + 1] = color.g;
13426
- paletteBuffer[base + 2] = color.b;
13427
- paletteBuffer[base + 3] = color.a;
13391
+ paletteBuffer.set(palette[index].buffer, index * 4);
13428
13392
  }
13429
- this.opentui.symbols.rendererSetPaletteState(renderer, paletteBuffer, palette.length, defaultForeground.buffer, defaultBackground.buffer, paletteEpoch >>> 0);
13393
+ this.opentui.symbols.rendererSetPaletteState(renderer, ptr4(paletteBuffer), palette.length, rgbaPtr(defaultForeground), rgbaPtr(defaultBackground), paletteEpoch >>> 0);
13430
13394
  }
13431
13395
  bufferGetCharPtr(buffer) {
13432
13396
  const ptr5 = this.opentui.symbols.bufferGetCharPtr(buffer);
@@ -13449,20 +13413,6 @@ class FFIRenderLib {
13449
13413
  }
13450
13414
  return ptr5;
13451
13415
  }
13452
- bufferGetFgTagPtr(buffer) {
13453
- const ptr5 = this.opentui.symbols.bufferGetFgTagPtr(buffer);
13454
- if (!ptr5) {
13455
- throw new Error("Failed to get fg tag pointer");
13456
- }
13457
- return ptr5;
13458
- }
13459
- bufferGetBgTagPtr(buffer) {
13460
- const ptr5 = this.opentui.symbols.bufferGetBgTagPtr(buffer);
13461
- if (!ptr5) {
13462
- throw new Error("Failed to get bg tag pointer");
13463
- }
13464
- return ptr5;
13465
- }
13466
13416
  bufferGetAttributesPtr(buffer) {
13467
13417
  const ptr5 = this.opentui.symbols.bufferGetAttributesPtr(buffer);
13468
13418
  if (!ptr5) {
@@ -13497,29 +13447,29 @@ class FFIRenderLib {
13497
13447
  return this.opentui.symbols.getBufferHeight(buffer);
13498
13448
  }
13499
13449
  bufferClear(buffer, color) {
13500
- this.opentui.symbols.bufferClear(buffer, color.buffer);
13450
+ this.opentui.symbols.bufferClear(buffer, rgbaPtr(color));
13501
13451
  }
13502
13452
  bufferDrawText(buffer, text, x, y, color, bgColor, attributes) {
13503
13453
  const textBytes = this.encoder.encode(text);
13504
13454
  const textLength = textBytes.byteLength;
13505
- const bg2 = bgColor ? bgColor.buffer : null;
13506
- const fg2 = color.buffer;
13455
+ const bg2 = optionalRgbaPtr(bgColor);
13456
+ const fg2 = rgbaPtr(color);
13507
13457
  this.opentui.symbols.bufferDrawText(buffer, textBytes, textLength, x, y, fg2, bg2, attributes ?? 0);
13508
13458
  }
13509
13459
  bufferSetCellWithAlphaBlending(buffer, x, y, char, color, bgColor, attributes) {
13510
13460
  const charPtr = char.codePointAt(0) ?? " ".codePointAt(0);
13511
- const bg2 = bgColor.buffer;
13512
- const fg2 = color.buffer;
13461
+ const bg2 = rgbaPtr(bgColor);
13462
+ const fg2 = rgbaPtr(color);
13513
13463
  this.opentui.symbols.bufferSetCellWithAlphaBlending(buffer, x, y, charPtr, fg2, bg2, attributes ?? 0);
13514
13464
  }
13515
13465
  bufferSetCell(buffer, x, y, char, color, bgColor, attributes) {
13516
13466
  const charPtr = char.codePointAt(0) ?? " ".codePointAt(0);
13517
- const bg2 = bgColor.buffer;
13518
- const fg2 = color.buffer;
13467
+ const bg2 = rgbaPtr(bgColor);
13468
+ const fg2 = rgbaPtr(color);
13519
13469
  this.opentui.symbols.bufferSetCell(buffer, x, y, charPtr, fg2, bg2, attributes ?? 0);
13520
13470
  }
13521
13471
  bufferFillRect(buffer, x, y, width, height, color) {
13522
- const bg2 = color.buffer;
13472
+ const bg2 = rgbaPtr(color);
13523
13473
  this.opentui.symbols.bufferFillRect(buffer, x, y, width, height, bg2);
13524
13474
  }
13525
13475
  bufferColorMatrix(buffer, matrixPtr, cellMaskPtr, cellMaskCount, strength, target) {
@@ -13536,17 +13486,17 @@ class FFIRenderLib {
13536
13486
  this.opentui.symbols.bufferDrawPackedBuffer(buffer, dataPtr, dataLen, posX, posY, terminalWidthCells, terminalHeightCells);
13537
13487
  }
13538
13488
  bufferDrawGrayscaleBuffer(buffer, posX, posY, intensitiesPtr, srcWidth, srcHeight, fg2, bg2) {
13539
- this.opentui.symbols.bufferDrawGrayscaleBuffer(buffer, posX, posY, intensitiesPtr, srcWidth, srcHeight, fg2?.buffer ?? null, bg2?.buffer ?? null);
13489
+ this.opentui.symbols.bufferDrawGrayscaleBuffer(buffer, posX, posY, intensitiesPtr, srcWidth, srcHeight, optionalRgbaPtr(fg2), optionalRgbaPtr(bg2));
13540
13490
  }
13541
13491
  bufferDrawGrayscaleBufferSupersampled(buffer, posX, posY, intensitiesPtr, srcWidth, srcHeight, fg2, bg2) {
13542
- this.opentui.symbols.bufferDrawGrayscaleBufferSupersampled(buffer, posX, posY, intensitiesPtr, srcWidth, srcHeight, fg2?.buffer ?? null, bg2?.buffer ?? null);
13492
+ this.opentui.symbols.bufferDrawGrayscaleBufferSupersampled(buffer, posX, posY, intensitiesPtr, srcWidth, srcHeight, optionalRgbaPtr(fg2), optionalRgbaPtr(bg2));
13543
13493
  }
13544
13494
  bufferDrawGrid(buffer, borderChars, borderFg, borderBg, columnOffsets, columnCount, rowOffsets, rowCount, options) {
13545
13495
  const optionsBuffer = GridDrawOptionsStruct.pack({
13546
13496
  drawInner: options.drawInner,
13547
13497
  drawOuter: options.drawOuter
13548
13498
  });
13549
- this.opentui.symbols.bufferDrawGrid(buffer, borderChars, borderFg.buffer, borderBg.buffer, columnOffsets, columnCount, rowOffsets, rowCount, ptr4(optionsBuffer));
13499
+ this.opentui.symbols.bufferDrawGrid(buffer, borderChars, rgbaPtr(borderFg), rgbaPtr(borderBg), columnOffsets, columnCount, rowOffsets, rowCount, ptr4(optionsBuffer));
13550
13500
  }
13551
13501
  bufferDrawBox(buffer, x, y, width, height, borderChars, packedOptions, borderColor, backgroundColor, title, bottomTitle) {
13552
13502
  const titleBytes = title ? this.encoder.encode(title) : null;
@@ -13555,7 +13505,7 @@ class FFIRenderLib {
13555
13505
  const bottomTitleBytes = bottomTitle ? this.encoder.encode(bottomTitle) : null;
13556
13506
  const bottomTitleLen = bottomTitle ? bottomTitleBytes.length : 0;
13557
13507
  const bottomTitlePtr = bottomTitle ? bottomTitleBytes : null;
13558
- this.opentui.symbols.bufferDrawBox(buffer, x, y, width, height, borderChars, packedOptions, borderColor.buffer, backgroundColor.buffer, titlePtr, titleLen, bottomTitlePtr, bottomTitleLen);
13508
+ this.opentui.symbols.bufferDrawBox(buffer, x, y, width, height, borderChars, packedOptions, rgbaPtr(borderColor), rgbaPtr(backgroundColor), titlePtr, titleLen, bottomTitlePtr, bottomTitleLen);
13559
13509
  }
13560
13510
  bufferResize(buffer, width, height) {
13561
13511
  this.opentui.symbols.bufferResize(buffer, width, height);
@@ -13582,7 +13532,7 @@ class FFIRenderLib {
13582
13532
  this.opentui.symbols.setCursorPosition(renderer, x, y, visible);
13583
13533
  }
13584
13534
  setCursorColor(renderer, color) {
13585
- this.opentui.symbols.setCursorColor(renderer, color.buffer);
13535
+ this.opentui.symbols.setCursorColor(renderer, rgbaPtr(color));
13586
13536
  }
13587
13537
  getCursorState(renderer) {
13588
13538
  const cursorBuffer = new ArrayBuffer(CursorStateStruct.size);
@@ -13753,11 +13703,11 @@ class FFIRenderLib {
13753
13703
  this.opentui.symbols.textBufferClear(buffer);
13754
13704
  }
13755
13705
  textBufferSetDefaultFg(buffer, fg2) {
13756
- const fgPtr = fg2 ? fg2.buffer : null;
13706
+ const fgPtr = optionalRgbaPtr(fg2);
13757
13707
  this.opentui.symbols.textBufferSetDefaultFg(buffer, fgPtr);
13758
13708
  }
13759
13709
  textBufferSetDefaultBg(buffer, bg2) {
13760
- const bgPtr = bg2 ? bg2.buffer : null;
13710
+ const bgPtr = optionalRgbaPtr(bg2);
13761
13711
  this.opentui.symbols.textBufferSetDefaultBg(buffer, bgPtr);
13762
13712
  }
13763
13713
  textBufferSetDefaultAttributes(buffer, attributes) {
@@ -13851,8 +13801,8 @@ class FFIRenderLib {
13851
13801
  this.opentui.symbols.destroyTextBufferView(view);
13852
13802
  }
13853
13803
  textBufferViewSetSelection(view, start, end, bgColor, fgColor) {
13854
- const bg2 = bgColor ? bgColor.buffer : null;
13855
- const fg2 = fgColor ? fgColor.buffer : null;
13804
+ const bg2 = optionalRgbaPtr(bgColor);
13805
+ const fg2 = optionalRgbaPtr(fgColor);
13856
13806
  this.opentui.symbols.textBufferViewSetSelection(view, start, end, bg2, fg2);
13857
13807
  }
13858
13808
  textBufferViewResetSelection(view) {
@@ -13871,18 +13821,18 @@ class FFIRenderLib {
13871
13821
  return this.opentui.symbols.textBufferViewGetSelectionInfo(view);
13872
13822
  }
13873
13823
  textBufferViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
13874
- const bg2 = bgColor ? bgColor.buffer : null;
13875
- const fg2 = fgColor ? fgColor.buffer : null;
13824
+ const bg2 = optionalRgbaPtr(bgColor);
13825
+ const fg2 = optionalRgbaPtr(fgColor);
13876
13826
  return this.opentui.symbols.textBufferViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2);
13877
13827
  }
13878
13828
  textBufferViewUpdateSelection(view, end, bgColor, fgColor) {
13879
- const bg2 = bgColor ? bgColor.buffer : null;
13880
- const fg2 = fgColor ? fgColor.buffer : null;
13829
+ const bg2 = optionalRgbaPtr(bgColor);
13830
+ const fg2 = optionalRgbaPtr(fgColor);
13881
13831
  this.opentui.symbols.textBufferViewUpdateSelection(view, end, bg2, fg2);
13882
13832
  }
13883
13833
  textBufferViewUpdateLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor) {
13884
- const bg2 = bgColor ? bgColor.buffer : null;
13885
- const fg2 = fgColor ? fgColor.buffer : null;
13834
+ const bg2 = optionalRgbaPtr(bgColor);
13835
+ const fg2 = optionalRgbaPtr(fgColor);
13886
13836
  return this.opentui.symbols.textBufferViewUpdateLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2);
13887
13837
  }
13888
13838
  textBufferViewResetLocalSelection(view) {
@@ -13971,7 +13921,7 @@ class FFIRenderLib {
13971
13921
  this.opentui.symbols.textBufferViewSetTabIndicator(view, indicator);
13972
13922
  }
13973
13923
  textBufferViewSetTabIndicatorColor(view, color) {
13974
- this.opentui.symbols.textBufferViewSetTabIndicatorColor(view, color.buffer);
13924
+ this.opentui.symbols.textBufferViewSetTabIndicatorColor(view, rgbaPtr(color));
13975
13925
  }
13976
13926
  textBufferViewSetTruncate(view, truncate) {
13977
13927
  this.opentui.symbols.textBufferViewSetTruncate(view, truncate);
@@ -14300,8 +14250,8 @@ class FFIRenderLib {
14300
14250
  return outBuffer.slice(0, len);
14301
14251
  }
14302
14252
  editorViewSetSelection(view, start, end, bgColor, fgColor) {
14303
- const bg2 = bgColor ? bgColor.buffer : null;
14304
- const fg2 = fgColor ? fgColor.buffer : null;
14253
+ const bg2 = optionalRgbaPtr(bgColor);
14254
+ const fg2 = optionalRgbaPtr(fgColor);
14305
14255
  this.opentui.symbols.editorViewSetSelection(view, start, end, bg2, fg2);
14306
14256
  }
14307
14257
  editorViewResetSelection(view) {
@@ -14317,18 +14267,18 @@ class FFIRenderLib {
14317
14267
  return { start, end };
14318
14268
  }
14319
14269
  editorViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor, updateCursor, followCursor) {
14320
- const bg2 = bgColor ? bgColor.buffer : null;
14321
- const fg2 = fgColor ? fgColor.buffer : null;
14270
+ const bg2 = optionalRgbaPtr(bgColor);
14271
+ const fg2 = optionalRgbaPtr(fgColor);
14322
14272
  return this.opentui.symbols.editorViewSetLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2, updateCursor, followCursor);
14323
14273
  }
14324
14274
  editorViewUpdateSelection(view, end, bgColor, fgColor) {
14325
- const bg2 = bgColor ? bgColor.buffer : null;
14326
- const fg2 = fgColor ? fgColor.buffer : null;
14275
+ const bg2 = optionalRgbaPtr(bgColor);
14276
+ const fg2 = optionalRgbaPtr(fgColor);
14327
14277
  this.opentui.symbols.editorViewUpdateSelection(view, end, bg2, fg2);
14328
14278
  }
14329
14279
  editorViewUpdateLocalSelection(view, anchorX, anchorY, focusX, focusY, bgColor, fgColor, updateCursor, followCursor) {
14330
- const bg2 = bgColor ? bgColor.buffer : null;
14331
- const fg2 = fgColor ? fgColor.buffer : null;
14280
+ const bg2 = optionalRgbaPtr(bgColor);
14281
+ const fg2 = optionalRgbaPtr(fgColor);
14332
14282
  return this.opentui.symbols.editorViewUpdateLocalSelection(view, anchorX, anchorY, focusX, focusY, bg2, fg2, updateCursor, followCursor);
14333
14283
  }
14334
14284
  editorViewResetLocalSelection(view) {
@@ -14476,7 +14426,7 @@ class FFIRenderLib {
14476
14426
  this.opentui.symbols.freeUnicode(encoded.ptr, encoded.data.length);
14477
14427
  }
14478
14428
  bufferDrawChar(buffer, char, x, y, fg2, bg2, attributes = 0) {
14479
- this.opentui.symbols.bufferDrawChar(buffer, char, x, y, fg2.buffer, bg2.buffer, attributes);
14429
+ this.opentui.symbols.bufferDrawChar(buffer, char, x, y, rgbaPtr(fg2), rgbaPtr(bg2), attributes);
14480
14430
  }
14481
14431
  registerNativeSpanFeedStream(stream, handler) {
14482
14432
  const callback = this.ensureNativeSpanFeedCallback();
@@ -14557,8 +14507,8 @@ class FFIRenderLib {
14557
14507
  }
14558
14508
  syntaxStyleRegister(style, name, fg2, bg2, attributes) {
14559
14509
  const nameBytes = this.encoder.encode(name);
14560
- const fgPtr = fg2 ? fg2.buffer : null;
14561
- const bgPtr = bg2 ? bg2.buffer : null;
14510
+ const fgPtr = optionalRgbaPtr(fg2);
14511
+ const bgPtr = optionalRgbaPtr(bg2);
14562
14512
  return this.opentui.symbols.syntaxStyleRegister(style, nameBytes, nameBytes.length, fgPtr, bgPtr, attributes);
14563
14513
  }
14564
14514
  syntaxStyleResolveByName(style, name) {
@@ -14583,7 +14533,7 @@ class FFIRenderLib {
14583
14533
  this.opentui.symbols.editorViewSetTabIndicator(view, indicator);
14584
14534
  }
14585
14535
  editorViewSetTabIndicatorColor(view, color) {
14586
- this.opentui.symbols.editorViewSetTabIndicatorColor(view, color.buffer);
14536
+ this.opentui.symbols.editorViewSetTabIndicatorColor(view, rgbaPtr(color));
14587
14537
  }
14588
14538
  onNativeEvent(name, handler) {
14589
14539
  this._nativeEvents.on(name, handler);
@@ -17064,9 +17014,11 @@ class SyntaxStyle {
17064
17014
  underline: style.underline,
17065
17015
  dim: style.dim
17066
17016
  });
17067
- const id = this.lib.syntaxStyleRegister(this.stylePtr, name, style.fg || null, style.bg || null, attributes);
17017
+ const fg2 = style.fg ? parseColor(style.fg) : null;
17018
+ const bg2 = style.bg ? parseColor(style.bg) : null;
17019
+ const id = this.lib.syntaxStyleRegister(this.stylePtr, name, fg2, bg2, attributes);
17068
17020
  this.nameCache.set(name, id);
17069
- this.styleDefs.set(name, style);
17021
+ this.styleDefs.set(name, { ...style, fg: fg2 ?? undefined, bg: bg2 ?? undefined });
17070
17022
  return id;
17071
17023
  }
17072
17024
  resolveStyleId(name) {
@@ -23668,7 +23620,7 @@ Captured external output:
23668
23620
  }
23669
23621
  syncNativePaletteState(colors) {
23670
23622
  const signature = buildTerminalPaletteSignature(colors);
23671
- if (this._publishedPaletteSignature !== null && this._publishedPaletteSignature !== signature) {
23623
+ if (this._publishedPaletteSignature !== signature) {
23672
23624
  this._paletteEpoch = this._paletteEpoch + 1 >>> 0;
23673
23625
  }
23674
23626
  this._publishedPaletteSignature = signature;
@@ -23753,7 +23705,7 @@ Captured external output:
23753
23705
  }
23754
23706
  }
23755
23707
 
23756
- export { __toESM, __commonJS, __export, __require, MeasureMode, exports_src, isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, COLOR_TAG_RGB, COLOR_TAG_DEFAULT, DEFAULT_FOREGROUND_RGB, DEFAULT_BACKGROUND_RGB, normalizeIndexedColorIndex, ansi256IndexToRgb, decodeColorTag, RGBA, normalizeColorValue, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, ATTRIBUTE_BASE_BITS, ATTRIBUTE_BASE_MASK, getBaseAttributes, DebugOverlayCorner, TargetChannel, 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, SystemClock, nonAlphanumericKeys, terminalNamedSingleStrokeKeys, parseKeypress, LinearScrollAccel, MacOSScrollAccel, 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, StdinParser, treeSitterToTextChunks, treeSitterToStyledText, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extensionToFiletype, basenameToFiletype, extToFiletype, pathToFiletype, infoStringToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, normalizeTerminalPalette, buildTerminalPaletteSignature, decodePasteBytes, stripAnsiSequences, detectLinks, TextBuffer, SpanInfoStruct, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, TextBufferView, EditBuffer, EditorView, convertThemeToStyles, SyntaxStyle, ANSI, BoxRenderable, TextBufferRenderable, CodeRenderable, isTextNodeRenderable, TextNodeRenderable, RootTextNodeRenderable, TextRenderable, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, EditBufferRenderableEvents, isEditBufferRenderable, EditBufferRenderable, calculateRenderGeometry, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
23708
+ export { __toESM, __commonJS, __export, __require, MeasureMode, exports_src, isValidBorderStyle, parseBorderStyle, BorderChars, getBorderFromSides, getBorderSides, borderCharsToArray, BorderCharArrays, KeyEvent, PasteEvent, KeyHandler, InternalKeyHandler, DEFAULT_FOREGROUND_RGB, DEFAULT_BACKGROUND_RGB, normalizeIndexedColorIndex, ansi256IndexToRgb, RGBA, normalizeColorValue, hexToRgb, rgbToHex, hsvToRgb, parseColor, fonts, measureText, getCharacterPositions, coordinateToCharacterIndex, renderFontToFrameBuffer, TextAttributes, ATTRIBUTE_BASE_BITS, ATTRIBUTE_BASE_MASK, getBaseAttributes, DebugOverlayCorner, TargetChannel, 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, SystemClock, nonAlphanumericKeys, terminalNamedSingleStrokeKeys, parseKeypress, LinearScrollAccel, MacOSScrollAccel, 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, StdinParser, treeSitterToTextChunks, treeSitterToStyledText, addDefaultParsers, TreeSitterClient, DataPathsManager, getDataPaths, extensionToFiletype, basenameToFiletype, extToFiletype, pathToFiletype, infoStringToFiletype, main, getTreeSitterClient, ExtmarksController, createExtmarksController, TerminalPalette, createTerminalPalette, normalizeTerminalPalette, buildTerminalPaletteSignature, decodePasteBytes, stripAnsiSequences, detectLinks, TextBuffer, SpanInfoStruct, LogLevel2 as LogLevel, setRenderLibPath, resolveRenderLib, OptimizedBuffer, h, isVNode, maybeMakeRenderable, wrapWithDelegates, instantiate, delegate, LayoutEvents, RenderableEvents, isRenderable, BaseRenderable, Renderable, RootRenderable, TextBufferView, EditBuffer, EditorView, convertThemeToStyles, SyntaxStyle, ANSI, BoxRenderable, TextBufferRenderable, CodeRenderable, isTextNodeRenderable, TextNodeRenderable, RootTextNodeRenderable, TextRenderable, defaultKeyAliases, mergeKeyAliases, mergeKeyBindings, getKeyBindingAction, buildKeyBindingsMap, capture, ConsolePosition, TerminalConsole, getObjectsInViewport, EditBufferRenderableEvents, isEditBufferRenderable, EditBufferRenderable, calculateRenderGeometry, buildKittyKeyboardFlags, MouseEvent, MouseButton, createCliRenderer, CliRenderEvents, RendererControlState, CliRenderer };
23757
23709
 
23758
- //# debugId=6BC89FBA0A359A5C64756E2164756E21
23759
- //# sourceMappingURL=index-jct3zgy3.js.map
23710
+ //# debugId=9856AC3785612B6364756E2164756E21
23711
+ //# sourceMappingURL=index-mw2x3082.js.map