@yaks/tui 0.0.0-stage → 0.2.36

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.
Files changed (121) hide show
  1. package/Frame.js +52 -0
  2. package/Frame.js.map +1 -0
  3. package/Frame.ts +92 -0
  4. package/Image.js +10 -0
  5. package/Image.js.map +1 -0
  6. package/Image.ts +22 -0
  7. package/LICENSE +202 -0
  8. package/README.md +524 -2
  9. package/RenderedCursor.js +103 -0
  10. package/RenderedCursor.js.map +1 -0
  11. package/RenderedCursor.ts +127 -0
  12. package/Scroll.js +88 -0
  13. package/Scroll.js.map +1 -0
  14. package/Scroll.ts +155 -0
  15. package/Textarea.js +186 -0
  16. package/Textarea.js.map +1 -0
  17. package/Textarea.ts +234 -0
  18. package/VirtualList.js +729 -0
  19. package/VirtualList.js.map +1 -0
  20. package/VirtualList.ts +838 -0
  21. package/_dist/Frame.d.ts +25 -0
  22. package/_dist/Frame.d.ts.map +1 -0
  23. package/_dist/Image.d.ts +13 -0
  24. package/_dist/Image.d.ts.map +1 -0
  25. package/_dist/RenderedCursor.d.ts +9 -0
  26. package/_dist/RenderedCursor.d.ts.map +1 -0
  27. package/_dist/Scroll.d.ts +30 -0
  28. package/_dist/Scroll.d.ts.map +1 -0
  29. package/_dist/Textarea.d.ts +26 -0
  30. package/_dist/Textarea.d.ts.map +1 -0
  31. package/_dist/VirtualList.d.ts +103 -0
  32. package/_dist/VirtualList.d.ts.map +1 -0
  33. package/_dist/guide.d.ts +21 -0
  34. package/_dist/guide.d.ts.map +1 -0
  35. package/_dist/history.d.ts +12 -0
  36. package/_dist/history.d.ts.map +1 -0
  37. package/_dist/input.d.ts +47 -0
  38. package/_dist/input.d.ts.map +1 -0
  39. package/_dist/interaction.d.ts +15 -0
  40. package/_dist/interaction.d.ts.map +1 -0
  41. package/_dist/keymap.d.ts +4 -0
  42. package/_dist/keymap.d.ts.map +1 -0
  43. package/_dist/mod.d.ts +42 -0
  44. package/_dist/mod.d.ts.map +1 -0
  45. package/_dist/mouse.d.ts +15 -0
  46. package/_dist/mouse.d.ts.map +1 -0
  47. package/_dist/paint.d.ts +86 -0
  48. package/_dist/paint.d.ts.map +1 -0
  49. package/_dist/print.d.ts +20 -0
  50. package/_dist/print.d.ts.map +1 -0
  51. package/_dist/run.d.ts +19 -0
  52. package/_dist/run.d.ts.map +1 -0
  53. package/_dist/screen.d.ts +22 -0
  54. package/_dist/screen.d.ts.map +1 -0
  55. package/_dist/scrollbar.d.ts +7 -0
  56. package/_dist/scrollbar.d.ts.map +1 -0
  57. package/_dist/testing.d.ts +19 -0
  58. package/_dist/testing.d.ts.map +1 -0
  59. package/_dist/theme.d.ts +11 -0
  60. package/_dist/theme.d.ts.map +1 -0
  61. package/_dist/visual.d.ts +28 -0
  62. package/_dist/visual.d.ts.map +1 -0
  63. package/deno.json +1 -0
  64. package/graphics.js +157 -0
  65. package/graphics.js.map +1 -0
  66. package/graphics.ts +191 -0
  67. package/grid.js +38 -0
  68. package/grid.js.map +1 -0
  69. package/grid.ts +46 -0
  70. package/guide.js +144 -0
  71. package/guide.js.map +1 -0
  72. package/guide.ts +169 -0
  73. package/history.js +58 -0
  74. package/history.js.map +1 -0
  75. package/history.ts +59 -0
  76. package/input.js +356 -0
  77. package/input.js.map +1 -0
  78. package/input.ts +324 -0
  79. package/interaction.js +180 -0
  80. package/interaction.js.map +1 -0
  81. package/interaction.ts +185 -0
  82. package/keymap.js +20 -0
  83. package/keymap.js.map +1 -0
  84. package/keymap.ts +23 -0
  85. package/mod.js +39 -0
  86. package/mod.js.map +1 -0
  87. package/mod.ts +92 -0
  88. package/mouse.js +65 -0
  89. package/mouse.js.map +1 -0
  90. package/mouse.ts +98 -0
  91. package/package.json +49 -4
  92. package/paint.js +1010 -0
  93. package/paint.js.map +1 -0
  94. package/paint.ts +1063 -0
  95. package/print.js +31 -0
  96. package/print.js.map +1 -0
  97. package/print.ts +40 -0
  98. package/run.js +220 -0
  99. package/run.js.map +1 -0
  100. package/run.ts +237 -0
  101. package/screen.js +97 -0
  102. package/screen.js.map +1 -0
  103. package/screen.ts +139 -0
  104. package/scrollbar.js +30 -0
  105. package/scrollbar.js.map +1 -0
  106. package/scrollbar.ts +33 -0
  107. package/table.js +134 -0
  108. package/table.js.map +1 -0
  109. package/table.ts +152 -0
  110. package/testing.js +86 -0
  111. package/testing.js.map +1 -0
  112. package/testing.ts +95 -0
  113. package/textRows.js +38 -0
  114. package/textRows.js.map +1 -0
  115. package/textRows.ts +31 -0
  116. package/theme.js +50 -0
  117. package/theme.js.map +1 -0
  118. package/theme.ts +39 -0
  119. package/visual.js +195 -0
  120. package/visual.js.map +1 -0
  121. package/visual.ts +209 -0
package/keymap.js ADDED
@@ -0,0 +1,20 @@
1
+ /** Graph-free keyboard mode routing. A mounted controller runs before focused widgets. */ /* @ts-types="npm:@types/react@19.3.0" */ import { useLayoutEffect, useRef } from "react";
2
+ let controllers = [];
3
+ export let interceptKey = (key)=>{
4
+ for(let i = controllers.length - 1; i >= 0; i--){
5
+ if (controllers[i](key)) return true;
6
+ }
7
+ return false;
8
+ };
9
+ export let useKeymap = (handler)=>{
10
+ let latest = useRef(handler);
11
+ latest.current = handler;
12
+ useLayoutEffect(()=>{
13
+ let dispatch = (key)=>latest.current(key);
14
+ controllers.push(dispatch);
15
+ return ()=>{
16
+ controllers.splice(controllers.indexOf(dispatch), 1);
17
+ };
18
+ }, []);
19
+ };
20
+ //# sourceMappingURL=keymap.js.map
package/keymap.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keymap.js","sources":["./keymap.ts"],"names":[],"mappings":"AAAA,wFAAwF,GACxF,uCAAuC,GAAG,SAAS,eAAe,EAAE,MAAM,gBAA0B;AAIpG,IAAI,cAAyB,EAAE;AAC/B,OAAO,IAAI,eAAe,CAAC;EACzB,IAAK,IAAI,IAAI,YAAY,MAAM,GAAG,GAAG,KAAK,GAAG,IAAK;IAChD,IAAI,WAAW,CAAC,EAAE,CAAC,MAAM,OAAO;EAClC;EACA,OAAO;AACT,EAAC;AACD,OAAO,IAAI,YAAY,CAAC;EACtB,IAAI,SAAS,OAAO;EACpB,OAAO,OAAO,GAAG;EACjB,gBAAgB;IACd,IAAI,WAAoB,CAAC,MAAQ,OAAO,OAAO,CAAC;IAChD,YAAY,IAAI,CAAC;IACjB,OAAO;MACL,YAAY,MAAM,CAAC,YAAY,OAAO,CAAC,WAAW;IACpD;EACF,GAAG,EAAE;AACP,EAAC"}
package/keymap.ts ADDED
@@ -0,0 +1,23 @@
1
+ /** Graph-free keyboard mode routing. A mounted controller runs before focused widgets. */
2
+ /* @ts-types="npm:@types/react@19.3.0" */ import { useLayoutEffect, useRef } from 'react'
3
+ import type { Key } from './input.ts'
4
+
5
+ type Handler = (key: Key) => boolean | void
6
+ let controllers: Handler[] = []
7
+ export let interceptKey = (key: Key): boolean => {
8
+ for (let i = controllers.length - 1; i >= 0; i--) {
9
+ if (controllers[i](key)) return true
10
+ }
11
+ return false
12
+ }
13
+ export let useKeymap = (handler: Handler): void => {
14
+ let latest = useRef(handler)
15
+ latest.current = handler
16
+ useLayoutEffect(() => {
17
+ let dispatch: Handler = (key) => latest.current(key)
18
+ controllers.push(dispatch)
19
+ return () => {
20
+ controllers.splice(controllers.indexOf(dispatch), 1)
21
+ }
22
+ }, [])
23
+ }
package/mod.js ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @yaks/tui renders a Preact tree to a terminal. Preact draws into a fake DOM
3
+ * (@yaks/dom); a backend turns that tree into what the screen shows. The
4
+ * backend that ships is a hand-written ANSI painter which repaints only the
5
+ * lines that changed, so a keystroke usually repaints a single line. Swap in
6
+ * another backend without changing a single widget.
7
+ *
8
+ * ```ts
9
+ * import { createElement as h } from 'react'
10
+ * import { Frame, Scroll, Textarea, run } from '@yaks/tui'
11
+ *
12
+ * let App = () =>
13
+ * h(Frame, { sidebar: [{ title: 'Status', Render: () => h('div', null, 'ok') }] },
14
+ * h(Scroll, { id: 'log', grow: '1' }, h('div', null, 'hello')),
15
+ * h(Textarea, { onSubmit: (text: string) => console.log(text) }))
16
+ *
17
+ * if (import.meta.main) await run(App)
18
+ * ```
19
+ *
20
+ * @module
21
+ */ export { dispatch, doc, install, onNavigate, onPaint, place, TElement, TNode, touch, TText } from "@yaks/dom";
22
+ export { decode, feed } from "./input.js";
23
+ export { ansi, ansiBackend, clip, clipboard, lay, printout, screenful, wrap } from "./paint.js";
24
+ export { base } from "./theme.js";
25
+ export { clear, measured, metrics, press, size, useKeys, useMetric } from "./screen.js";
26
+ export { quit, run, useHold } from "./run.js";
27
+ export { print } from "./print.js";
28
+ export { Scroll, scrolled } from "./Scroll.js";
29
+ export { bol, edit, eol, spot, Textarea } from "./Textarea.js";
30
+ export { Frame } from "./Frame.js";
31
+ export { VirtualList, VirtualWindow } from "./VirtualList.js";
32
+ export { hit, routeMouse } from "./mouse.js";
33
+ export { emptyVisual, useTextSurface, useVisualController } from "./visual.js";
34
+ export { Image, showing } from "./Image.js";
35
+ export { useKeymap } from "./keymap.js";
36
+ export { pressFocused, pressTo } from "./screen.js";
37
+ export { beginVisual, copyText, visualKey } from "./visual.js";
38
+ export { terminalFocused } from "./screen.js";
39
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;CAoBC,GAED,SACE,QAAQ,EACR,GAAG,EACH,OAAO,EACP,UAAU,EACV,OAAO,EACP,KAAK,EACL,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,yBACsB;AAC7B,SAAS,MAAM,EAAE,IAAI,qBAAyC;AAC9D,SACE,IAAI,EACJ,WAAW,EAEX,IAAI,EACJ,SAAS,EACT,GAAG,EAGH,QAAQ,EACR,SAAS,EAET,IAAI,qBACa;AACnB,SAAS,IAAI,qBAAoB;AAEjC,SACE,KAAK,EAEL,QAAQ,EACR,OAAO,EACP,KAAK,EACL,IAAI,EACJ,OAAO,EACP,SAAS,sBACS;AACpB,SAAS,IAAI,EAAE,GAAG,EAAE,OAAO,mBAAkB;AAC7C,SAAS,KAAK,qBAAoB;AAClC,SAAS,MAAM,EAAE,QAAQ,sBAAgC;AACzD,SAAS,GAAG,EAAa,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,wBAAuB;AACzE,SAAS,KAAK,qBAAgC;AAC9C,SAGE,WAAW,EACX,aAAa,2BACU;AAEzB,SAAS,GAAG,EAAmB,UAAU,qBAAoB;AAG7D,SACE,WAAW,EACX,cAAc,EACd,mBAAmB,sBAED;AAEpB,SAAS,KAAK,EAAoB,OAAO,qBAAoB;AAE7D,SAAS,SAAS,sBAAqB;AACvC,SAAS,YAAY,EAAE,OAAO,sBAAqB;AACnD,SAAS,WAAW,EAAE,QAAQ,EAAE,SAAS,sBAAqB;AAE9D,SAAS,eAAe,sBAAqB"}
package/mod.ts ADDED
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @yaks/tui renders a Preact tree to a terminal. Preact draws into a fake DOM
3
+ * (@yaks/dom); a backend turns that tree into what the screen shows. The
4
+ * backend that ships is a hand-written ANSI painter which repaints only the
5
+ * lines that changed, so a keystroke usually repaints a single line. Swap in
6
+ * another backend without changing a single widget.
7
+ *
8
+ * ```ts
9
+ * import { createElement as h } from 'react'
10
+ * import { Frame, Scroll, Textarea, run } from '@yaks/tui'
11
+ *
12
+ * let App = () =>
13
+ * h(Frame, { sidebar: [{ title: 'Status', Render: () => h('div', null, 'ok') }] },
14
+ * h(Scroll, { id: 'log', grow: '1' }, h('div', null, 'hello')),
15
+ * h(Textarea, { onSubmit: (text: string) => console.log(text) }))
16
+ *
17
+ * if (import.meta.main) await run(App)
18
+ * ```
19
+ *
20
+ * @module
21
+ */
22
+
23
+ export {
24
+ dispatch,
25
+ doc,
26
+ install,
27
+ onNavigate,
28
+ onPaint,
29
+ place,
30
+ TElement,
31
+ TNode,
32
+ touch,
33
+ TText,
34
+ } from '@yaks/dom'
35
+ export { decode, feed, type Key, type Name } from './input.js'
36
+ export {
37
+ ansi,
38
+ ansiBackend,
39
+ type Backend,
40
+ clip,
41
+ clipboard,
42
+ lay,
43
+ type Line,
44
+ type Metrics,
45
+ printout,
46
+ screenful,
47
+ type Seg,
48
+ wrap,
49
+ } from './paint.js'
50
+ export { base } from './theme.js'
51
+ export type { Sheet, Style } from 'jsr:@yaks/ui@0.2.36/sheet'
52
+ export {
53
+ clear,
54
+ type Keys,
55
+ measured,
56
+ metrics,
57
+ press,
58
+ size,
59
+ useKeys,
60
+ useMetric,
61
+ } from './screen.js'
62
+ export { quit, run, useHold } from './run.js'
63
+ export { print } from './print.js'
64
+ export { Scroll, scrolled, type View } from './Scroll.js'
65
+ export { bol, type Edit, edit, eol, spot, Textarea } from './Textarea.js'
66
+ export { Frame, type Panel } from './Frame.js'
67
+ export {
68
+ type Anchor,
69
+ type VirtualItem,
70
+ VirtualList,
71
+ VirtualWindow,
72
+ } from './VirtualList.js'
73
+
74
+ export { hit, type MouseEvent, routeMouse } from './mouse.js'
75
+ export type { Input, Mouse } from './input.js'
76
+
77
+ export {
78
+ emptyVisual,
79
+ useTextSurface,
80
+ useVisualController,
81
+ type VisualState,
82
+ } from './visual.js'
83
+
84
+ export { Image, type ImageSource, showing } from './Image.js'
85
+
86
+ export { useKeymap } from './keymap.js'
87
+ export { pressFocused, pressTo } from './screen.js'
88
+ export { beginVisual, copyText, visualKey } from './visual.js'
89
+
90
+ export { terminalFocused } from './screen.js'
91
+
92
+ export type { RenderedCursor, TextPoint } from './RenderedCursor.ts'
package/mouse.js ADDED
@@ -0,0 +1,65 @@
1
+ import { visualState } from "./visual.js";
2
+ /** Hit only cells present in the most recent clipped paint, not logical bounds. */ export let hit = (lines, x, y)=>{
3
+ if (x < 0 || y < 0 || !Number.isInteger(x) || !Number.isInteger(y)) return;
4
+ let left = 0;
5
+ for (let seg of lines[y] ?? []){
6
+ left += seg.text.length;
7
+ if (x < left) return seg.owner;
8
+ }
9
+ };
10
+ let pressed;
11
+ let clickable = (node)=>{
12
+ for(let at = node; at; at = at.parentNode ?? undefined){
13
+ if (typeof at.onclick == 'function' || at.parentNode && at.handlers.has('click')) return at;
14
+ }
15
+ return node;
16
+ };
17
+ /** Drop an unfinished gesture when the screen is unmounted. */ export let clearMouse = ()=>{
18
+ pressed = undefined;
19
+ };
20
+ /** Return true when consumed. A missed report never falls into keyboard focus. */ export let routeMouse = (report, lines)=>{
21
+ // Freeze normal navigation while reading a selection snapshot.
22
+ if (visualState()?.surface) {
23
+ pressed = undefined;
24
+ return true;
25
+ }
26
+ let target = hit(lines, report.x, report.y);
27
+ if (report.type == 'mousedown') {
28
+ pressed = report.button == 0 && !report.ctrl && !report.alt && !report.shift ? clickable(target) : undefined;
29
+ }
30
+ const click = report.type == 'mouseup' && report.button == 0 && target != null && pressed === clickable(target);
31
+ if (report.type == 'mouseup' || report.type == 'mousemove' || report.type == 'wheel') pressed = undefined;
32
+ if (!target) return false;
33
+ let event = {
34
+ ...report,
35
+ target,
36
+ currentTarget: null,
37
+ defaultPrevented: false,
38
+ cancelBubble: false,
39
+ preventDefault () {
40
+ this.defaultPrevented = true;
41
+ },
42
+ stopPropagation () {
43
+ this.cancelBubble = true;
44
+ }
45
+ };
46
+ const dispatch = ()=>{
47
+ for(let node = target; node; node = node.parentNode){
48
+ event.currentTarget = node;
49
+ let handler = node.handlers.get(event.type);
50
+ if (typeof handler == 'function' && handler.call(node, event) === true) {
51
+ event.preventDefault();
52
+ }
53
+ if (event.defaultPrevented || event.cancelBubble) break;
54
+ }
55
+ event.currentTarget = null;
56
+ return event.defaultPrevented || event.cancelBubble;
57
+ };
58
+ const consumed = dispatch();
59
+ if (!click) return consumed;
60
+ event.type = 'click';
61
+ event.defaultPrevented = false;
62
+ event.cancelBubble = false;
63
+ return dispatch() || consumed;
64
+ };
65
+ //# sourceMappingURL=mouse.js.map
package/mouse.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mouse.js","sources":["./mouse.ts"],"names":[],"mappings":"AAAA,SAAS,WAAW,sBAAqB;AAgBzC,iFAAiF,GACjF,OAAO,IAAI,MAAM,CACf,OACA,GACA;EAEA,IAAI,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,SAAS,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,IAAI;EACpE,IAAI,OAAO;EACX,KAAK,IAAI,OAAO,KAAK,CAAC,EAAE,IAAI,EAAE,CAAE;IAC9B,QAAQ,IAAI,IAAI,CAAC,MAAM;IACvB,IAAI,IAAI,MAAM,OAAO,IAAI,KAAK;EAChC;AACF,EAAC;AAED,IAAI;AACJ,IAAI,YAAY,CAAC;EACf,IAAK,IAAI,KAAK,MAAM,IAAI,KAAK,GAAG,UAAU,IAAI,UAAW;IACvD,IACE,OAAO,GAAG,OAAO,IAAI,cACrB,GAAG,UAAU,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,UACjC,OAAO;EACX;EACA,OAAO;AACT;AAEA,6DAA6D,GAC7D,OAAO,IAAI,aAAa;EACtB,UAAU;AACZ,EAAC;AAED,gFAAgF,GAChF,OAAO,IAAI,aAAa,CAAC,QAAe;EACtC,+DAA+D;EAC/D,IAAI,eAAe,SAAS;IAC1B,UAAU;IACV,OAAO;EACT;EACA,IAAI,SAAS,IAAI,OAAO,OAAO,CAAC,EAAE,OAAO,CAAC;EAC1C,IAAI,OAAO,IAAI,IAAI,aAAa;IAC9B,UAAU,OAAO,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,KAAK,GACxE,UAAU,UACV;EACN;EACA,MAAM,QAAQ,OAAO,IAAI,IAAI,aAAa,OAAO,MAAM,IAAI,KACzD,UAAU,QAAQ,YAAY,UAAU;EAC1C,IACE,OAAO,IAAI,IAAI,aAAa,OAAO,IAAI,IAAI,eAC3C,OAAO,IAAI,IAAI,SACf,UAAU;EACZ,IAAI,CAAC,QAAQ,OAAO;EACpB,IAAI,QAAoB;IACtB,GAAG,MAAM;IACT;IACA,eAAe;IACf,kBAAkB;IAClB,cAAc;IACd;MACE,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IACA;MACE,IAAI,CAAC,YAAY,GAAG;IACtB;EACF;EACA,MAAM,WAAW;IACf,IAAK,IAAI,OAAwB,QAAQ,MAAM,OAAO,KAAK,UAAU,CAAE;MACrE,MAAM,aAAa,GAAG;MACtB,IAAI,UAAU,KAAK,QAAQ,CAAC,GAAG,CAAC,MAAM,IAAI;MAC1C,IAAI,OAAO,WAAW,cAAc,QAAQ,IAAI,CAAC,MAAM,WAAW,MAAM;QACtE,MAAM,cAAc;MACtB;MACA,IAAI,MAAM,gBAAgB,IAAI,MAAM,YAAY,EAAE;IACpD;IACA,MAAM,aAAa,GAAG;IACtB,OAAO,MAAM,gBAAgB,IAAI,MAAM,YAAY;EACrD;EACA,MAAM,WAAW;EACjB,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,IAAI,GAAG;EACb,MAAM,gBAAgB,GAAG;EACzB,MAAM,YAAY,GAAG;EACrB,OAAO,cAAc;AACvB,EAAC"}
package/mouse.ts ADDED
@@ -0,0 +1,98 @@
1
+ import { visualState } from './visual.js'
2
+ import { TElement } from '@yaks/dom'
3
+ import type { Mouse } from './input.ts'
4
+ import type { Line } from './paint.ts'
5
+
6
+ /** DOM-compatible event delivered to Preact onWheel/onMouseDown/onMouseUp. */
7
+ export type MouseEvent = Omit<Mouse, 'type'> & {
8
+ type: Mouse['type'] | 'click'
9
+ target: TElement
10
+ currentTarget: TElement | null
11
+ defaultPrevented: boolean
12
+ cancelBubble: boolean
13
+ preventDefault(): void
14
+ stopPropagation(): void
15
+ }
16
+
17
+ /** Hit only cells present in the most recent clipped paint, not logical bounds. */
18
+ export let hit = (
19
+ lines: Line[],
20
+ x: number,
21
+ y: number,
22
+ ): TElement | undefined => {
23
+ if (x < 0 || y < 0 || !Number.isInteger(x) || !Number.isInteger(y)) return
24
+ let left = 0
25
+ for (let seg of lines[y] ?? []) {
26
+ left += seg.text.length
27
+ if (x < left) return seg.owner
28
+ }
29
+ }
30
+
31
+ let pressed: TElement | undefined
32
+ let clickable = (node: TElement | undefined): TElement | undefined => {
33
+ for (let at = node; at; at = at.parentNode ?? undefined) {
34
+ if (
35
+ typeof at.onclick == 'function' ||
36
+ at.parentNode && at.handlers.has('click')
37
+ ) return at
38
+ }
39
+ return node
40
+ }
41
+
42
+ /** Drop an unfinished gesture when the screen is unmounted. */
43
+ export let clearMouse = () => {
44
+ pressed = undefined
45
+ }
46
+
47
+ /** Return true when consumed. A missed report never falls into keyboard focus. */
48
+ export let routeMouse = (report: Mouse, lines: Line[]): boolean => {
49
+ // Freeze normal navigation while reading a selection snapshot.
50
+ if (visualState()?.surface) {
51
+ pressed = undefined
52
+ return true
53
+ }
54
+ let target = hit(lines, report.x, report.y)
55
+ if (report.type == 'mousedown') {
56
+ pressed = report.button == 0 && !report.ctrl && !report.alt && !report.shift
57
+ ? clickable(target)
58
+ : undefined
59
+ }
60
+ const click = report.type == 'mouseup' && report.button == 0 &&
61
+ target != null && pressed === clickable(target)
62
+ if (
63
+ report.type == 'mouseup' || report.type == 'mousemove' ||
64
+ report.type == 'wheel'
65
+ ) pressed = undefined
66
+ if (!target) return false
67
+ let event: MouseEvent = {
68
+ ...report,
69
+ target,
70
+ currentTarget: null,
71
+ defaultPrevented: false,
72
+ cancelBubble: false,
73
+ preventDefault() {
74
+ this.defaultPrevented = true
75
+ },
76
+ stopPropagation() {
77
+ this.cancelBubble = true
78
+ },
79
+ }
80
+ const dispatch = () => {
81
+ for (let node: TElement | null = target; node; node = node.parentNode) {
82
+ event.currentTarget = node
83
+ let handler = node.handlers.get(event.type)
84
+ if (typeof handler == 'function' && handler.call(node, event) === true) {
85
+ event.preventDefault()
86
+ }
87
+ if (event.defaultPrevented || event.cancelBubble) break
88
+ }
89
+ event.currentTarget = null
90
+ return event.defaultPrevented || event.cancelBubble
91
+ }
92
+ const consumed = dispatch()
93
+ if (!click) return consumed
94
+ event.type = 'click'
95
+ event.defaultPrevented = false
96
+ event.cancelBubble = false
97
+ return dispatch() || consumed
98
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@yaks/tui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/tui",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./_dist/mod.d.ts",
9
+ "default": "./mod.js"
10
+ },
11
+ "./print": {
12
+ "types": "./_dist/print.d.ts",
13
+ "default": "./print.js"
14
+ },
15
+ "./theme": {
16
+ "types": "./_dist/theme.d.ts",
17
+ "default": "./theme.js"
18
+ },
19
+ "./guide": {
20
+ "types": "./_dist/guide.d.ts",
21
+ "default": "./guide.js"
22
+ },
23
+ "./history": {
24
+ "types": "./_dist/history.d.ts",
25
+ "default": "./history.js"
26
+ },
27
+ "./interaction": {
28
+ "types": "./_dist/interaction.d.ts",
29
+ "default": "./interaction.js"
30
+ },
31
+ "./testing": {
32
+ "types": "./_dist/testing.d.ts",
33
+ "default": "./testing.js"
34
+ }
35
+ },
36
+ "license": "Apache-2.0",
37
+ "dependencies": {
38
+ "@yaks/dom": "0.2.36",
39
+ "@yaks/fp": "0.2.36",
40
+ "@yaks/process": "0.2.36",
41
+ "@yaks/react": "0.2.36",
42
+ "@yaks/text": "0.2.36",
43
+ "@yaks/ui": "0.2.36",
44
+ "@yaks/ux": "0.2.36",
45
+ "@preact/signals-core": "1.14.5",
46
+ "@types/react": "19.3.0",
47
+ "react": "19.3.0"
48
+ },
49
+ "description": "Renders React trees in a terminal through a replaceable backend, with a diffing ANSI painter and scrolling, input, and layout widgets.",
50
+ "repository": "https://github.com/yak-sh/yak.git"
51
+ }