@opentui/core 0.5.2 → 0.5.4

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-kq7as74d.js";
46
+ } from "./chunk-node-tq0x9mbj.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-aj3n20gq.js";
206
+ } from "./chunk-node-crchpns1.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);
@@ -14830,6 +14830,30 @@ class TabSelectRenderable extends Renderable {
14830
14830
  }
14831
14831
  }
14832
14832
  // src/renderables/TimeToFirstDraw.ts
14833
+ var graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
14834
+ function measureCellWidth(buffer, text) {
14835
+ const encoded = buffer.encodeUnicode(text);
14836
+ if (!encoded)
14837
+ return 0;
14838
+ try {
14839
+ return encoded.data.reduce((width, glyph) => width + glyph.width, 0);
14840
+ } finally {
14841
+ buffer.freeUnicode(encoded);
14842
+ }
14843
+ }
14844
+ function truncateToCellWidth(buffer, text, maxWidth) {
14845
+ let visibleText = "";
14846
+ let visibleWidth = 0;
14847
+ for (const { segment } of graphemeSegmenter.segment(text)) {
14848
+ const segmentWidth = measureCellWidth(buffer, segment);
14849
+ if (visibleWidth + segmentWidth > maxWidth)
14850
+ break;
14851
+ visibleText += segment;
14852
+ visibleWidth += segmentWidth;
14853
+ }
14854
+ return { text: visibleText, width: visibleWidth };
14855
+ }
14856
+
14833
14857
  class TimeToFirstDrawRenderable extends Renderable {
14834
14858
  _runtimeMs = null;
14835
14859
  textColor;
@@ -14882,9 +14906,9 @@ class TimeToFirstDrawRenderable extends Renderable {
14882
14906
  }
14883
14907
  const content = `${this.label}: ${this._runtimeMs.toFixed(this.precision)}ms`;
14884
14908
  const maxWidth = Math.max(this.width, 1);
14885
- const visibleContent = content.length > maxWidth ? content.slice(0, maxWidth) : content;
14886
- const centeredX = this.x + Math.max(0, Math.floor((maxWidth - visibleContent.length) / 2));
14887
- buffer.drawText(visibleContent, centeredX, this.y, this.textColor);
14909
+ const visibleContent = truncateToCellWidth(buffer, content, maxWidth);
14910
+ const centeredX = this.x + Math.max(0, Math.floor((maxWidth - visibleContent.width) / 2));
14911
+ buffer.drawText(visibleContent.text, centeredX, this.y, this.textColor);
14888
14912
  }
14889
14913
  normalizePrecision(value) {
14890
14914
  if (!Number.isFinite(value)) {
@@ -15172,5 +15196,5 @@ export {
15172
15196
  ACHROMATOPSIA_MATRIX
15173
15197
  };
15174
15198
 
15175
- //# debugId=461568FAFCC40A8864756E2164756E21
15199
+ //# debugId=C3D27E9A5375901564756E2164756E21
15176
15200
  //# sourceMappingURL=index.node.js.map