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