@vincemakes/kiso-tui-cells 0.1.41
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/dist/approval-panel.d.ts +109 -0
- package/dist/approval-panel.js +144 -0
- package/dist/components.d.ts +298 -0
- package/dist/components.js +979 -0
- package/dist/diff.d.ts +32 -0
- package/dist/diff.js +122 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +21 -0
- package/dist/render.d.ts +129 -0
- package/dist/render.js +295 -0
- package/dist/width.d.ts +21 -0
- package/dist/width.js +67 -0
- package/package.json +57 -0
package/dist/width.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The display-width primitives — the SINGLE width authority (TUI v5
|
|
3
|
+
* #16e: "charWidth is the width authority"). The eastAsianWidth table
|
|
4
|
+
* is a ~40-line subset (CJK ideographs/kana/hangul/fullwidth/common
|
|
5
|
+
* wide symbols = 2, everything else = 1 — the box-drawing/brick glyphs
|
|
6
|
+
* █▀▄▞▸ are narrow). Known limitation, documented in the README: emoji
|
|
7
|
+
* ZWJ clusters are not guaranteed perfect — each code point counts as
|
|
8
|
+
* its width. Zero dependencies (importable from any module).
|
|
9
|
+
*/
|
|
10
|
+
/** A code point's display width: 2 for the wide ranges, 1 otherwise. */
|
|
11
|
+
export function charWidth(cp) {
|
|
12
|
+
if (cp >= 0x1100 && cp <= 0x115f)
|
|
13
|
+
return 2; // hangul jamo
|
|
14
|
+
if (cp >= 0x2e80 && cp <= 0x303e)
|
|
15
|
+
return 2; // radicals .. CJK punctuation
|
|
16
|
+
if (cp >= 0x3041 && cp <= 0x33ff)
|
|
17
|
+
return 2; // kana, CJK compat
|
|
18
|
+
if (cp >= 0x3400 && cp <= 0x4dbf)
|
|
19
|
+
return 2; // CJK ext A
|
|
20
|
+
if (cp >= 0x4e00 && cp <= 0x9fff)
|
|
21
|
+
return 2; // CJK unified
|
|
22
|
+
if (cp >= 0xa000 && cp <= 0xa4cf)
|
|
23
|
+
return 2; // yi
|
|
24
|
+
if (cp >= 0xa960 && cp <= 0xa97f)
|
|
25
|
+
return 2; // hangul jamo ext
|
|
26
|
+
if (cp >= 0xac00 && cp <= 0xd7a3)
|
|
27
|
+
return 2; // hangul syllables
|
|
28
|
+
if (cp >= 0xf900 && cp <= 0xfaff)
|
|
29
|
+
return 2; // CJK compat ideographs
|
|
30
|
+
if (cp >= 0xfe10 && cp <= 0xfe19)
|
|
31
|
+
return 2; // vertical forms
|
|
32
|
+
if (cp >= 0xfe30 && cp <= 0xfe6f)
|
|
33
|
+
return 2; // CJK compat forms
|
|
34
|
+
if (cp >= 0xff00 && cp <= 0xff60)
|
|
35
|
+
return 2; // fullwidth forms
|
|
36
|
+
if (cp >= 0xffe0 && cp <= 0xffe6)
|
|
37
|
+
return 2; // fullwidth signs
|
|
38
|
+
if (cp >= 0x1f300 && cp <= 0x1f64f)
|
|
39
|
+
return 2; // emoji (misc + emoticons)
|
|
40
|
+
if (cp >= 0x1f900 && cp <= 0x1f9ff)
|
|
41
|
+
return 2; // supplemental emoji
|
|
42
|
+
if (cp >= 0x20000 && cp <= 0x3fffd)
|
|
43
|
+
return 2; // CJK ext B..G
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
/** Display width of a code-point array (cursor math, scrolling). */
|
|
47
|
+
export function widthOf(chars) {
|
|
48
|
+
let w = 0;
|
|
49
|
+
for (const cp of chars)
|
|
50
|
+
w += charWidth(cp);
|
|
51
|
+
return w;
|
|
52
|
+
}
|
|
53
|
+
/** Display width of a string. */
|
|
54
|
+
export function displayWidth(text) {
|
|
55
|
+
let w = 0;
|
|
56
|
+
for (const ch of text)
|
|
57
|
+
w += charWidth(ch.codePointAt(0));
|
|
58
|
+
return w;
|
|
59
|
+
}
|
|
60
|
+
/** A LEAD's display width — the prompt / the panel's phase lead,
|
|
61
|
+
* ANSI-stripped. W23: the ONE width authority shared by the editor
|
|
62
|
+
* (selfRender, #reflow), the compositor's #inputRow, and editCol — a
|
|
63
|
+
* lead can never measure differently at two call sites (the frame-
|
|
64
|
+
* derived column contract: wallL + leadWidth(lead) + cells + 1). */
|
|
65
|
+
export function leadWidth(lead) {
|
|
66
|
+
return displayWidth(lead.replace(/\x1b\[[0-9;]*m/g, ""));
|
|
67
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vincemakes/kiso-tui-cells",
|
|
3
|
+
"version": "0.1.41",
|
|
4
|
+
"description": "kiso tui-cells — the components cell renderer (components, diff, width, the render slice). Zero runtime dependencies: input is data, output is bytes.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./components": {
|
|
13
|
+
"types": "./dist/components.d.ts",
|
|
14
|
+
"default": "./dist/components.js"
|
|
15
|
+
},
|
|
16
|
+
"./diff": {
|
|
17
|
+
"types": "./dist/diff.d.ts",
|
|
18
|
+
"default": "./dist/diff.js"
|
|
19
|
+
},
|
|
20
|
+
"./approval-panel": {
|
|
21
|
+
"types": "./dist/approval-panel.d.ts",
|
|
22
|
+
"default": "./dist/approval-panel.js"
|
|
23
|
+
},
|
|
24
|
+
"./width": {
|
|
25
|
+
"types": "./dist/width.d.ts",
|
|
26
|
+
"default": "./dist/width.js"
|
|
27
|
+
},
|
|
28
|
+
"./render": {
|
|
29
|
+
"types": "./dist/render.d.ts",
|
|
30
|
+
"default": "./dist/render.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.build.json",
|
|
40
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
41
|
+
"test": "vitest run"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^26.1.2",
|
|
45
|
+
"typescript": "^5.7.2",
|
|
46
|
+
"vitest": "^3.0.0"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/vincemakes/kiso.git",
|
|
51
|
+
"directory": "packages/tui-cells"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/vincemakes/kiso/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/vincemakes/kiso/tree/main/packages/tui-cells#readme"
|
|
57
|
+
}
|