@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/index.node.js CHANGED
@@ -43,7 +43,7 @@ import {
43
43
  mergeKeyAliases,
44
44
  mergeKeyBindings,
45
45
  wrapWithDelegates
46
- } from "./chunk-node-dcyj0dm5.js";
46
+ } from "./chunk-node-6bg8r2m7.js";
47
47
  import {
48
48
  ASCIIFontSelectionHelper,
49
49
  ATTRIBUTE_BASE_BITS,
@@ -203,7 +203,7 @@ import {
203
203
  visualizeRenderableTree,
204
204
  white,
205
205
  yellow
206
- } from "./chunk-node-zcz10bhr.js";
206
+ } from "./chunk-node-f647ts9q.js";
207
207
  // src/post/effects.ts
208
208
  function toU8(value) {
209
209
  return Math.round(Math.max(0, Math.min(1, Number.isFinite(value) ? value : 0)) * 255);
@@ -5703,7 +5703,8 @@ var STATUS_MESSAGES = [
5703
5703
  "out of memory",
5704
5704
  "image output buffer is too small",
5705
5705
  "internal image error",
5706
- "unsupported image feature"
5706
+ "unsupported image feature",
5707
+ "image is retained"
5707
5708
  ];
5708
5709
  var STATUS_CODES = [
5709
5710
  "internal-error",
@@ -5717,9 +5718,11 @@ var STATUS_CODES = [
5717
5718
  "out-of-memory",
5718
5719
  "output-too-small",
5719
5720
  "internal-error",
5720
- "unsupported-feature"
5721
+ "unsupported-feature",
5722
+ "busy"
5721
5723
  ];
5722
5724
  var INVALID_ARGUMENT_STATUS = 7;
5725
+ var BUSY_STATUS = 12;
5723
5726
 
5724
5727
  class ImageError extends Error {
5725
5728
  code;
@@ -5749,6 +5752,7 @@ var PIXEL_FORMAT_BGRA = {
5749
5752
  rgba8: false,
5750
5753
  bgra8: true
5751
5754
  };
5755
+ var PIXEL_ALPHA_IDS = { straight: 0, opaque: 1 };
5752
5756
  var MAX_ENCODED_BYTES = 64 * 1024 * 1024;
5753
5757
  function imageError(status) {
5754
5758
  return new ImageError(status);
@@ -5768,6 +5772,15 @@ function requireU32(value, name, allowZero = false) {
5768
5772
  }
5769
5773
  return value;
5770
5774
  }
5775
+ function pixelImportOptions(width, options) {
5776
+ const stride = requireU32(options.stride ?? width * 4, "stride");
5777
+ const bgra = requireMappedOption(PIXEL_FORMAT_BGRA, options.format ?? "rgba8", "pixel format");
5778
+ const alpha = requireMappedOption(PIXEL_ALPHA_IDS, options.alpha ?? "straight", "pixel alpha");
5779
+ if (options.colorSpace !== undefined && options.colorSpace !== "srgb") {
5780
+ throw new TypeError(`Unsupported pixel color space: ${String(options.colorSpace)}`);
5781
+ }
5782
+ return { stride, format: Number(bgra), alpha };
5783
+ }
5771
5784
  function requireI32(value, name) {
5772
5785
  if (!Number.isSafeInteger(value) || value < -2147483648 || value > 2147483647) {
5773
5786
  throw new RangeError(`${name} must be an i32 integer`);
@@ -5987,6 +6000,19 @@ class NativeImage {
5987
6000
  throw imageError(10);
5988
6001
  return NativeImage.fromHandle(lib, result.handle);
5989
6002
  }
6003
+ static fromPixels(pixels, width, height, options = {}) {
6004
+ if (!(pixels instanceof Uint8Array))
6005
+ throw new TypeError("pixels must be a Uint8Array");
6006
+ requireU32(width, "width");
6007
+ requireU32(height, "height");
6008
+ const { stride, format, alpha } = pixelImportOptions(width, options);
6009
+ const lib = resolveRenderLib();
6010
+ const result = lib.imageCreateFromPixels(pixels, width, height, stride, format, alpha);
6011
+ checkStatus(result.status);
6012
+ if (!result.handle)
6013
+ throw imageError(10);
6014
+ return NativeImage.fromHandle(lib, result.handle);
6015
+ }
5990
6016
  static fromHandle(lib, handle) {
5991
6017
  const result = lib.imageGetInfo(handle);
5992
6018
  if (result.status !== 0) {
@@ -6118,6 +6144,53 @@ class NativeImage {
6118
6144
  this.handle = null;
6119
6145
  }
6120
6146
  }
6147
+
6148
+ class NativeImagePool {
6149
+ lib;
6150
+ images = [];
6151
+ disposed = false;
6152
+ width;
6153
+ height;
6154
+ capacity;
6155
+ constructor(options) {
6156
+ this.width = requireU32(options.width, "width");
6157
+ this.height = requireU32(options.height, "height");
6158
+ this.capacity = requireU32(options.capacity ?? 3, "capacity");
6159
+ if (this.capacity > 8)
6160
+ throw new RangeError("capacity must be between 1 and 8");
6161
+ this.lib = resolveRenderLib();
6162
+ }
6163
+ publishRgba(pixels, stride = this.width * 4) {
6164
+ return this.publishPixels(pixels, { stride: requireU32(stride, "stride") });
6165
+ }
6166
+ publishPixels(pixels, options = {}) {
6167
+ if (this.disposed)
6168
+ throw new Error("NativeImagePool is disposed");
6169
+ if (!(pixels instanceof Uint8Array))
6170
+ throw new TypeError("pixels must be a Uint8Array");
6171
+ const { stride, format, alpha } = pixelImportOptions(this.width, options);
6172
+ for (const image2 of this.images) {
6173
+ const status = this.lib.imageUpdatePixels(image2.ptr, pixels, stride, format, alpha);
6174
+ if (status === BUSY_STATUS)
6175
+ continue;
6176
+ checkStatus(status);
6177
+ return image2.retain();
6178
+ }
6179
+ if (this.images.length === this.capacity)
6180
+ return null;
6181
+ const image = NativeImage.fromPixels(pixels, this.width, this.height, options);
6182
+ this.images.push(image);
6183
+ return image.retain();
6184
+ }
6185
+ dispose() {
6186
+ if (this.disposed)
6187
+ return;
6188
+ this.disposed = true;
6189
+ for (const image of this.images)
6190
+ image.dispose();
6191
+ this.images.length = 0;
6192
+ }
6193
+ }
6121
6194
  // src/renderables/FrameBuffer.ts
6122
6195
  class FrameBufferRenderable extends Renderable {
6123
6196
  frameBuffer;
@@ -12959,7 +13032,7 @@ class MarkdownRenderable extends Renderable {
12959
13032
  blockIndex++;
12960
13033
  continue;
12961
13034
  }
12962
- if (existing && !forceTableRefresh && existing.canUpdateInPlace && existing.token.type === block.token.type && this.canUpdateBlockRenderable(existing.renderable, block.token)) {
13035
+ if (existing && existing.canUpdateInPlace && existing.token.type === block.token.type && this.canUpdateBlockRenderable(existing.renderable, block.token)) {
12963
13036
  if (this._renderNode) {
12964
13037
  const custom = this.createTopLevelCustomRenderable(block, blockIndex);
12965
13038
  if (custom.renderable && !custom.canUpdateInPlace) {
@@ -15526,6 +15599,7 @@ export {
15526
15599
  OptimizedBuffer,
15527
15600
  NativeSpanFeed,
15528
15601
  NativeMeasureTargetKind,
15602
+ NativeImagePool,
15529
15603
  NativeImage,
15530
15604
  NativeClipboardStartStatus,
15531
15605
  NativeClipboardShutdownStatus,
@@ -15607,5 +15681,5 @@ export {
15607
15681
  ACHROMATOPSIA_MATRIX
15608
15682
  };
15609
15683
 
15610
- //# debugId=9F5430F160FB010564756E2164756E21
15684
+ //# debugId=A215C65C5C28D5BB64756E2164756E21
15611
15685
  //# sourceMappingURL=index.node.js.map