@opentui/core 0.5.9 → 0.5.10

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/image.d.ts CHANGED
@@ -62,10 +62,16 @@ export interface RawImage {
62
62
  colorSpace: "srgb";
63
63
  alpha: "straight";
64
64
  }
65
+ export interface PixelImportOptions {
66
+ stride?: number;
67
+ format?: PixelFormat;
68
+ alpha?: "straight" | "opaque";
69
+ colorSpace?: "srgb";
70
+ }
65
71
  export interface OwnedRawImage extends RawImage {
66
72
  dispose(): void;
67
73
  }
68
- export type ImageErrorCode = "invalid-handle" | "unsupported-format" | "unsupported-color-space" | "malformed-data" | "dimension-limit" | "memory-limit" | "invalid-argument" | "out-of-memory" | "output-too-small" | "internal-error" | "unsupported-feature";
74
+ export type ImageErrorCode = "invalid-handle" | "unsupported-format" | "unsupported-color-space" | "malformed-data" | "dimension-limit" | "memory-limit" | "invalid-argument" | "out-of-memory" | "output-too-small" | "internal-error" | "unsupported-feature" | "busy";
69
75
  export declare class ImageError extends Error {
70
76
  readonly code: ImageErrorCode;
71
77
  readonly status: number;
@@ -80,6 +86,7 @@ export declare class NativeImage {
80
86
  static decode(data: Uint8Array | ArrayBuffer): NativeImage;
81
87
  static load(source: ImageSource, options?: ImageLoadOptions): Promise<NativeImage>;
82
88
  static fromRgba(pixels: Uint8Array, width: number, height: number, stride?: number): NativeImage;
89
+ static fromPixels(pixels: Uint8Array, width: number, height: number, options?: PixelImportOptions): NativeImage;
83
90
  private static fromHandle;
84
91
  private guard;
85
92
  get ptr(): ImageHandle;
@@ -105,3 +112,20 @@ export declare class NativeImage {
105
112
  }): void;
106
113
  dispose(): void;
107
114
  }
115
+ export interface NativeImagePoolOptions {
116
+ width: number;
117
+ height: number;
118
+ capacity?: number;
119
+ }
120
+ export declare class NativeImagePool {
121
+ private readonly lib;
122
+ private readonly images;
123
+ private disposed;
124
+ readonly width: number;
125
+ readonly height: number;
126
+ readonly capacity: number;
127
+ constructor(options: NativeImagePoolOptions);
128
+ publishRgba(pixels: Uint8Array, stride?: number): NativeImage | null;
129
+ publishPixels(pixels: Uint8Array, options?: PixelImportOptions): NativeImage | null;
130
+ dispose(): void;
131
+ }
package/index.bun.js CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  mergeKeyAliases,
45
45
  mergeKeyBindings,
46
46
  wrapWithDelegates
47
- } from "./chunk-bun-jxfx3h5k.js";
47
+ } from "./chunk-bun-bb3k0yt8.js";
48
48
  import {
49
49
  ASCIIFontSelectionHelper,
50
50
  ATTRIBUTE_BASE_BITS,
@@ -204,7 +204,7 @@ import {
204
204
  visualizeRenderableTree,
205
205
  white,
206
206
  yellow
207
- } from "./chunk-bun-b0662dgp.js";
207
+ } from "./chunk-bun-9gqvxy8c.js";
208
208
  // src/post/effects.ts
209
209
  function toU8(value) {
210
210
  return Math.round(Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0)) * 255);
@@ -5704,7 +5704,8 @@ var STATUS_MESSAGES = [
5704
5704
  "out of memory",
5705
5705
  "image output buffer is too small",
5706
5706
  "internal image error",
5707
- "unsupported image feature"
5707
+ "unsupported image feature",
5708
+ "image is retained"
5708
5709
  ];
5709
5710
  var STATUS_CODES = [
5710
5711
  "internal-error",
@@ -5718,9 +5719,11 @@ var STATUS_CODES = [
5718
5719
  "out-of-memory",
5719
5720
  "output-too-small",
5720
5721
  "internal-error",
5721
- "unsupported-feature"
5722
+ "unsupported-feature",
5723
+ "busy"
5722
5724
  ];
5723
5725
  var INVALID_ARGUMENT_STATUS = 7;
5726
+ var BUSY_STATUS = 12;
5724
5727
 
5725
5728
  class ImageError extends Error {
5726
5729
  code;
@@ -5750,6 +5753,7 @@ var PIXEL_FORMAT_BGRA = {
5750
5753
  rgba8: false,
5751
5754
  bgra8: true
5752
5755
  };
5756
+ var PIXEL_ALPHA_IDS = { straight: 0, opaque: 1 };
5753
5757
  var MAX_ENCODED_BYTES = 64 * 1024 * 1024;
5754
5758
  function imageError(status) {
5755
5759
  return new ImageError(status);
@@ -5769,6 +5773,15 @@ function requireU32(value, name, allowZero = false) {
5769
5773
  }
5770
5774
  return value;
5771
5775
  }
5776
+ function pixelImportOptions(width, options) {
5777
+ const stride = requireU32(options.stride ?? width * 4, "stride");
5778
+ const bgra = requireMappedOption(PIXEL_FORMAT_BGRA, options.format ?? "rgba8", "pixel format");
5779
+ const alpha = requireMappedOption(PIXEL_ALPHA_IDS, options.alpha ?? "straight", "pixel alpha");
5780
+ if (options.colorSpace !== undefined && options.colorSpace !== "srgb") {
5781
+ throw new TypeError(`Unsupported pixel color space: ${String(options.colorSpace)}`);
5782
+ }
5783
+ return { stride, format: Number(bgra), alpha };
5784
+ }
5772
5785
  function requireI32(value, name) {
5773
5786
  if (!Number.isSafeInteger(value) || value < -2147483648 || value > 2147483647) {
5774
5787
  throw new RangeError(`${name} must be an i32 integer`);
@@ -5988,6 +6001,19 @@ class NativeImage {
5988
6001
  throw imageError(10);
5989
6002
  return NativeImage.fromHandle(lib, result.handle);
5990
6003
  }
6004
+ static fromPixels(pixels, width, height, options = {}) {
6005
+ if (!(pixels instanceof Uint8Array))
6006
+ throw new TypeError("pixels must be a Uint8Array");
6007
+ requireU32(width, "width");
6008
+ requireU32(height, "height");
6009
+ const { stride, format, alpha } = pixelImportOptions(width, options);
6010
+ const lib = resolveRenderLib();
6011
+ const result = lib.imageCreateFromPixels(pixels, width, height, stride, format, alpha);
6012
+ checkStatus(result.status);
6013
+ if (!result.handle)
6014
+ throw imageError(10);
6015
+ return NativeImage.fromHandle(lib, result.handle);
6016
+ }
5991
6017
  static fromHandle(lib, handle) {
5992
6018
  const result = lib.imageGetInfo(handle);
5993
6019
  if (result.status !== 0) {
@@ -6119,6 +6145,53 @@ class NativeImage {
6119
6145
  this.handle = null;
6120
6146
  }
6121
6147
  }
6148
+
6149
+ class NativeImagePool {
6150
+ lib;
6151
+ images = [];
6152
+ disposed = false;
6153
+ width;
6154
+ height;
6155
+ capacity;
6156
+ constructor(options) {
6157
+ this.width = requireU32(options.width, "width");
6158
+ this.height = requireU32(options.height, "height");
6159
+ this.capacity = requireU32(options.capacity ?? 3, "capacity");
6160
+ if (this.capacity > 8)
6161
+ throw new RangeError("capacity must be between 1 and 8");
6162
+ this.lib = resolveRenderLib();
6163
+ }
6164
+ publishRgba(pixels, stride = this.width * 4) {
6165
+ return this.publishPixels(pixels, { stride: requireU32(stride, "stride") });
6166
+ }
6167
+ publishPixels(pixels, options = {}) {
6168
+ if (this.disposed)
6169
+ throw new Error("NativeImagePool is disposed");
6170
+ if (!(pixels instanceof Uint8Array))
6171
+ throw new TypeError("pixels must be a Uint8Array");
6172
+ const { stride, format, alpha } = pixelImportOptions(this.width, options);
6173
+ for (const image2 of this.images) {
6174
+ const status = this.lib.imageUpdatePixels(image2.ptr, pixels, stride, format, alpha);
6175
+ if (status === BUSY_STATUS)
6176
+ continue;
6177
+ checkStatus(status);
6178
+ return image2.retain();
6179
+ }
6180
+ if (this.images.length === this.capacity)
6181
+ return null;
6182
+ const image = NativeImage.fromPixels(pixels, this.width, this.height, options);
6183
+ this.images.push(image);
6184
+ return image.retain();
6185
+ }
6186
+ dispose() {
6187
+ if (this.disposed)
6188
+ return;
6189
+ this.disposed = true;
6190
+ for (const image of this.images)
6191
+ image.dispose();
6192
+ this.images.length = 0;
6193
+ }
6194
+ }
6122
6195
  // src/renderables/FrameBuffer.ts
6123
6196
  class FrameBufferRenderable extends Renderable {
6124
6197
  frameBuffer;
@@ -12960,7 +13033,7 @@ class MarkdownRenderable extends Renderable {
12960
13033
  blockIndex++;
12961
13034
  continue;
12962
13035
  }
12963
- if (existing && !forceTableRefresh && existing.canUpdateInPlace && existing.token.type === block.token.type && this.canUpdateBlockRenderable(existing.renderable, block.token)) {
13036
+ if (existing && existing.canUpdateInPlace && existing.token.type === block.token.type && this.canUpdateBlockRenderable(existing.renderable, block.token)) {
12964
13037
  if (this._renderNode) {
12965
13038
  const custom = this.createTopLevelCustomRenderable(block, blockIndex);
12966
13039
  if (custom.renderable && !custom.canUpdateInPlace) {
@@ -15527,6 +15600,7 @@ export {
15527
15600
  OptimizedBuffer,
15528
15601
  NativeSpanFeed,
15529
15602
  NativeMeasureTargetKind,
15603
+ NativeImagePool,
15530
15604
  NativeImage,
15531
15605
  NativeClipboardStartStatus,
15532
15606
  NativeClipboardShutdownStatus,
@@ -15608,5 +15682,5 @@ export {
15608
15682
  ACHROMATOPSIA_MATRIX
15609
15683
  };
15610
15684
 
15611
- //# debugId=281D25630B33385064756E2164756E21
15685
+ //# debugId=598A7BAC0738AEF164756E2164756E21
15612
15686
  //# sourceMappingURL=index.bun.js.map