pi-supernova 0.0.4 → 0.0.6

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/render-measure.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Width / truncate primitives shared by render.js and omp-frame.js.
2
+ * Width / truncate primitives used by the compact renderer.
3
3
  * Self-contained so path-install never depends on a host truncate that can
4
4
  * append ellipsis after cutting to maxWidth (Pi 92>91 crash class).
5
5
  */
@@ -27,6 +27,10 @@ export function measureWidth(text) {
27
27
 
28
28
  function codePointWidth(cp) {
29
29
  if (cp <= 0x1f || (cp >= 0x7f && cp <= 0x9f)) return 0;
30
+ if (cp === 0xfe0f) return 1; // Emoji presentation can widen an otherwise narrow symbol.
31
+ if (cp === 0x200d || (cp >= 0x0300 && cp <= 0x036f) || (cp >= 0x1ab0 && cp <= 0x1aff) ||
32
+ (cp >= 0x1dc0 && cp <= 0x1dff) || (cp >= 0x20d0 && cp <= 0x20ff) ||
33
+ (cp >= 0xfe00 && cp <= 0xfe0e) || (cp >= 0xfe20 && cp <= 0xfe2f)) return 0;
30
34
  // Fullwidth / wide ranges (CJK, Hangul, emoji blocks we actually emit).
31
35
  if (cp >= 0x1100 && cp <= 0x115f) return 2;
32
36
  if (cp === 0x2329 || cp === 0x232a) return 2;
@@ -37,8 +41,7 @@ function codePointWidth(cp) {
37
41
  if (cp >= 0xfe30 && cp <= 0xfe6f) return 2;
38
42
  if (cp >= 0xff00 && cp <= 0xff60) return 2;
39
43
  if (cp >= 0xffe0 && cp <= 0xffe6) return 2;
40
- if (cp >= 0x1f300 && cp <= 0x1f64f) return 2;
41
- if (cp >= 0x1f900 && cp <= 0x1f9ff) return 2;
44
+ if (cp >= 0x1f000 && cp <= 0x1faff) return 2;
42
45
  if (cp >= 0x20000 && cp <= 0x3fffd) return 2;
43
46
  // Ambiguous emoji/symbols pi-tui treats as wide (⚡ U+26A1 was the 92>91 footgun).
44
47
  if (cp === 0x26a1 || cp === 0x2b50 || cp === 0x2728) return 2;
@@ -107,18 +110,21 @@ export function wrapPlainToWidth(plain, width) {
107
110
  let visible = 0;
108
111
  let lastBreak = -1;
109
112
  while (end < text.length) {
110
- const ch = text[end];
113
+ const cp = text.codePointAt(end);
114
+ const ch = String.fromCodePoint(cp);
111
115
  const cw = measureWidth(ch);
112
116
  if (visible + cw > w) break;
113
117
  visible += cw;
114
- if (ch === "/" || ch === " ") lastBreak = end + 1;
115
- end++;
118
+ end += ch.length;
119
+ if (ch === "/" || ch === " ") lastBreak = end;
116
120
  }
117
121
  if (end === i) {
118
- end = i + 1;
119
- } else if (end < text.length && lastBreak > i + Math.floor(w * 0.35)) {
120
- end = lastBreak;
122
+ const ch = String.fromCodePoint(text.codePointAt(i));
123
+ lines.push(hardTruncate(ch, w));
124
+ i += ch.length;
125
+ continue;
121
126
  }
127
+ if (end < text.length && lastBreak > i + Math.floor(w * 0.35)) end = lastBreak;
122
128
  lines.push(text.slice(i, end));
123
129
  i = end;
124
130
  }