@opentui/core 0.5.8 → 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-kr27pp2p.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-mfda59vq.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);
@@ -218,6 +218,9 @@ function setRgb(buffer, base, r, g, b) {
218
218
  buffer[base + 2] = toU8(b);
219
219
  buffer[base + 3] = a;
220
220
  }
221
+ function isGraphemeCell(char) {
222
+ return char >>> 30 >= 2;
223
+ }
221
224
 
222
225
  class DistortionEffect {
223
226
  glitchChancePerSecond = 0.5;
@@ -402,6 +405,7 @@ class DistortionEffect {
402
405
  class VignetteEffect {
403
406
  _strength;
404
407
  precomputedAttenuationCellMask = null;
408
+ precomputedAttenuation = null;
405
409
  cachedWidth = -1;
406
410
  cachedHeight = -1;
407
411
  static zeroMatrix = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
@@ -413,12 +417,14 @@ class VignetteEffect {
413
417
  this.cachedWidth = -1;
414
418
  this.cachedHeight = -1;
415
419
  this.precomputedAttenuationCellMask = null;
420
+ this.precomputedAttenuation = null;
416
421
  }
417
422
  get strength() {
418
423
  return this._strength;
419
424
  }
420
425
  _computeFactors(width, height) {
421
426
  this.precomputedAttenuationCellMask = new Float32Array(width * height * 3);
427
+ this.precomputedAttenuation = new Float32Array(width * height);
422
428
  const centerX = width / 2;
423
429
  const centerY = height / 2;
424
430
  const maxDistSq = centerX * centerX + centerY * centerY;
@@ -436,17 +442,42 @@ class VignetteEffect {
436
442
  this.precomputedAttenuationCellMask[i++] = x;
437
443
  this.precomputedAttenuationCellMask[i++] = y;
438
444
  this.precomputedAttenuationCellMask[i++] = attenuation;
445
+ this.precomputedAttenuation[y * width + x] = attenuation;
439
446
  }
440
447
  }
441
448
  this.cachedWidth = width;
442
449
  this.cachedHeight = height;
443
450
  }
451
+ _preserveGraphemeRuns(buffer) {
452
+ const baseAttenuation = this.precomputedAttenuation;
453
+ const cellMask = this.precomputedAttenuationCellMask;
454
+ const chars = buffer.buffers.char;
455
+ const width = buffer.width;
456
+ for (let y = 0;y < buffer.height; y++) {
457
+ let x = 0;
458
+ while (x < width) {
459
+ const cell = y * width + x;
460
+ if (!isGraphemeCell(chars[cell])) {
461
+ cellMask[cell * 3 + 2] = baseAttenuation[cell];
462
+ x++;
463
+ continue;
464
+ }
465
+ const start = x;
466
+ while (x < width && isGraphemeCell(chars[y * width + x]))
467
+ x++;
468
+ const attenuation = baseAttenuation[y * width + start + Math.floor((x - start) / 2)];
469
+ for (let runX = start;runX < x; runX++)
470
+ cellMask[(y * width + runX) * 3 + 2] = attenuation;
471
+ }
472
+ }
473
+ }
444
474
  apply(buffer) {
445
475
  const width = buffer.width;
446
476
  const height = buffer.height;
447
477
  if (width !== this.cachedWidth || height !== this.cachedHeight || !this.precomputedAttenuationCellMask) {
448
478
  this._computeFactors(width, height);
449
479
  }
480
+ this._preserveGraphemeRuns(buffer);
450
481
  buffer.colorMatrix(VignetteEffect.zeroMatrix, this.precomputedAttenuationCellMask, 1, 3);
451
482
  }
452
483
  }
@@ -5672,7 +5703,8 @@ var STATUS_MESSAGES = [
5672
5703
  "out of memory",
5673
5704
  "image output buffer is too small",
5674
5705
  "internal image error",
5675
- "unsupported image feature"
5706
+ "unsupported image feature",
5707
+ "image is retained"
5676
5708
  ];
5677
5709
  var STATUS_CODES = [
5678
5710
  "internal-error",
@@ -5686,9 +5718,11 @@ var STATUS_CODES = [
5686
5718
  "out-of-memory",
5687
5719
  "output-too-small",
5688
5720
  "internal-error",
5689
- "unsupported-feature"
5721
+ "unsupported-feature",
5722
+ "busy"
5690
5723
  ];
5691
5724
  var INVALID_ARGUMENT_STATUS = 7;
5725
+ var BUSY_STATUS = 12;
5692
5726
 
5693
5727
  class ImageError extends Error {
5694
5728
  code;
@@ -5718,6 +5752,7 @@ var PIXEL_FORMAT_BGRA = {
5718
5752
  rgba8: false,
5719
5753
  bgra8: true
5720
5754
  };
5755
+ var PIXEL_ALPHA_IDS = { straight: 0, opaque: 1 };
5721
5756
  var MAX_ENCODED_BYTES = 64 * 1024 * 1024;
5722
5757
  function imageError(status) {
5723
5758
  return new ImageError(status);
@@ -5737,6 +5772,15 @@ function requireU32(value, name, allowZero = false) {
5737
5772
  }
5738
5773
  return value;
5739
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
+ }
5740
5784
  function requireI32(value, name) {
5741
5785
  if (!Number.isSafeInteger(value) || value < -2147483648 || value > 2147483647) {
5742
5786
  throw new RangeError(`${name} must be an i32 integer`);
@@ -5956,6 +6000,19 @@ class NativeImage {
5956
6000
  throw imageError(10);
5957
6001
  return NativeImage.fromHandle(lib, result.handle);
5958
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
+ }
5959
6016
  static fromHandle(lib, handle) {
5960
6017
  const result = lib.imageGetInfo(handle);
5961
6018
  if (result.status !== 0) {
@@ -6087,6 +6144,53 @@ class NativeImage {
6087
6144
  this.handle = null;
6088
6145
  }
6089
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
+ }
6090
6194
  // src/renderables/FrameBuffer.ts
6091
6195
  class FrameBufferRenderable extends Renderable {
6092
6196
  frameBuffer;
@@ -8320,12 +8424,13 @@ class EmbeddedTerminalRenderable extends Renderable {
8320
8424
  if (!this.handle)
8321
8425
  return new Uint8Array;
8322
8426
  const text = textualKey(key);
8427
+ const physical = physicalKey(key);
8323
8428
  return this.lib.embeddedTerminalEncodeKey(this.handle, {
8324
8429
  action: key.eventType === "release" ? "release" : key.repeated ? "repeat" : "press",
8325
- key: physicalKey(key),
8430
+ key: physical,
8326
8431
  mods: modifiers(key),
8327
8432
  text,
8328
- unshiftedCodepoint: key.baseCode ?? physicalUnshiftedCodepoint(key.code)
8433
+ unshiftedCodepoint: key.baseCode ?? physicalUnshiftedCodepoint(physical)
8329
8434
  });
8330
8435
  }
8331
8436
  encodePaste(bytes) {
@@ -8352,6 +8457,8 @@ class EmbeddedTerminalRenderable extends Renderable {
8352
8457
  this.requestRender();
8353
8458
  return false;
8354
8459
  }
8460
+ if (!this.selection && local.behavior === "cell" && local.anchorX === local.focusX && local.anchorY === local.focusY)
8461
+ return false;
8355
8462
  const point = (x, y) => {
8356
8463
  if (y < 0)
8357
8464
  return { x: 0, y: 0 };
@@ -8542,8 +8649,12 @@ function modifiers(input) {
8542
8649
  return value;
8543
8650
  }
8544
8651
  function physicalKey(key) {
8545
- if (key.code)
8652
+ if (key.code && !key.code.startsWith("["))
8546
8653
  return key.code;
8654
+ if (/^[a-z]$/i.test(key.name))
8655
+ return `Key${key.name.toUpperCase()}`;
8656
+ if (/^[0-9]$/.test(key.name))
8657
+ return `Digit${key.name}`;
8547
8658
  return {
8548
8659
  backspace: "Backspace",
8549
8660
  enter: "Enter",
@@ -12921,7 +13032,7 @@ class MarkdownRenderable extends Renderable {
12921
13032
  blockIndex++;
12922
13033
  continue;
12923
13034
  }
12924
- 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)) {
12925
13036
  if (this._renderNode) {
12926
13037
  const custom = this.createTopLevelCustomRenderable(block, blockIndex);
12927
13038
  if (custom.renderable && !custom.canUpdateInPlace) {
@@ -15488,6 +15599,7 @@ export {
15488
15599
  OptimizedBuffer,
15489
15600
  NativeSpanFeed,
15490
15601
  NativeMeasureTargetKind,
15602
+ NativeImagePool,
15491
15603
  NativeImage,
15492
15604
  NativeClipboardStartStatus,
15493
15605
  NativeClipboardShutdownStatus,
@@ -15569,5 +15681,5 @@ export {
15569
15681
  ACHROMATOPSIA_MATRIX
15570
15682
  };
15571
15683
 
15572
- //# debugId=9542D2256201683264756E2164756E21
15684
+ //# debugId=A215C65C5C28D5BB64756E2164756E21
15573
15685
  //# sourceMappingURL=index.node.js.map