(grapheme: string)
| 106 | } |
| 107 | |
| 108 | function getEmojiWidth(grapheme: string): number { |
| 109 | // Regional indicators: single = 1, pair = 2 |
| 110 | const first = grapheme.codePointAt(0)! |
| 111 | if (first >= 0x1f1e6 && first <= 0x1f1ff) { |
| 112 | let count = 0 |
| 113 | for (const _ of grapheme) count++ |
| 114 | return count === 1 ? 1 : 2 |
| 115 | } |
| 116 | |
| 117 | // Incomplete keycap: digit/symbol + VS16 without U+20E3 |
| 118 | if (grapheme.length === 2) { |
| 119 | const second = grapheme.codePointAt(1) |
| 120 | if ( |
| 121 | second === 0xfe0f && |
| 122 | ((first >= 0x30 && first <= 0x39) || first === 0x23 || first === 0x2a) |
| 123 | ) { |
| 124 | return 1 |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return 2 |
| 129 | } |
| 130 | |
| 131 | function isZeroWidth(codePoint: number): boolean { |
| 132 | // Fast path for common printable range |
no outgoing calls
no test coverage detected