@effect-tui/core 0.1.0 → 0.1.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.
Files changed (271) hide show
  1. package/README.md +31 -11
  2. package/dist/ansi.d.ts +127 -32
  3. package/dist/ansi.d.ts.map +1 -1
  4. package/dist/ansi.js +159 -37
  5. package/dist/ansi.js.map +1 -1
  6. package/dist/colors.d.ts +139 -0
  7. package/dist/colors.d.ts.map +1 -0
  8. package/dist/colors.js +339 -0
  9. package/dist/colors.js.map +1 -0
  10. package/dist/index.d.ts +6 -10
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +13 -11
  13. package/dist/index.js.map +1 -1
  14. package/dist/keys.d.ts +21 -0
  15. package/dist/keys.d.ts.map +1 -1
  16. package/dist/keys.js +199 -58
  17. package/dist/keys.js.map +1 -1
  18. package/dist/layout/axis-helpers.d.ts +19 -0
  19. package/dist/layout/axis-helpers.d.ts.map +1 -0
  20. package/dist/layout/axis-helpers.js +19 -0
  21. package/dist/layout/axis-helpers.js.map +1 -0
  22. package/dist/output.d.ts +59 -0
  23. package/dist/output.d.ts.map +1 -0
  24. package/dist/output.js +142 -0
  25. package/dist/output.js.map +1 -0
  26. package/dist/render/buffer.d.ts.map +1 -1
  27. package/dist/render/buffer.js +6 -25
  28. package/dist/render/buffer.js.map +1 -1
  29. package/dist/render/graphemes.d.ts +15 -0
  30. package/dist/render/graphemes.d.ts.map +1 -0
  31. package/dist/render/graphemes.js +28 -0
  32. package/dist/render/graphemes.js.map +1 -0
  33. package/dist/render/measure.d.ts +1 -0
  34. package/dist/render/measure.d.ts.map +1 -1
  35. package/dist/render/measure.js +14 -36
  36. package/dist/render/measure.js.map +1 -1
  37. package/dist/render/palette.d.ts.map +1 -1
  38. package/dist/render/palette.js +26 -1
  39. package/dist/render/palette.js.map +1 -1
  40. package/dist/render/segmenter.d.ts +8 -0
  41. package/dist/render/segmenter.d.ts.map +1 -0
  42. package/dist/render/segmenter.js +23 -0
  43. package/dist/render/segmenter.js.map +1 -0
  44. package/dist/render/surface.d.ts +6 -32
  45. package/dist/render/surface.d.ts.map +1 -1
  46. package/dist/render/surface.js +11 -80
  47. package/dist/render/surface.js.map +1 -1
  48. package/dist/runtime/backend_node.d.ts.map +1 -1
  49. package/dist/runtime/backend_node.js.map +1 -1
  50. package/dist/tailwind-colors.d.ts +291 -0
  51. package/dist/tailwind-colors.d.ts.map +1 -0
  52. package/dist/tailwind-colors.js +291 -0
  53. package/dist/tailwind-colors.js.map +1 -0
  54. package/dist/types.d.ts +15 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +3 -0
  57. package/dist/types.js.map +1 -0
  58. package/package.json +55 -55
  59. package/src/ansi.ts +201 -73
  60. package/src/colors.ts +468 -0
  61. package/src/index.ts +28 -14
  62. package/src/keys.ts +467 -287
  63. package/src/layout/axis-helpers.ts +33 -0
  64. package/src/output.ts +175 -0
  65. package/src/render/buffer.ts +161 -184
  66. package/src/render/graphemes.ts +34 -0
  67. package/src/render/measure.ts +15 -38
  68. package/src/render/palette.ts +98 -77
  69. package/src/render/segmenter.ts +27 -0
  70. package/src/render/surface.ts +139 -225
  71. package/src/runtime/backend_node.ts +71 -71
  72. package/src/tailwind-colors.ts +295 -0
  73. package/src/types.ts +18 -0
  74. package/dist/anim.d.ts +0 -4
  75. package/dist/anim.d.ts.map +0 -1
  76. package/dist/anim.js +0 -5
  77. package/dist/anim.js.map +0 -1
  78. package/dist/layout/linearStack.d.ts +0 -17
  79. package/dist/layout/linearStack.d.ts.map +0 -1
  80. package/dist/layout/linearStack.js +0 -86
  81. package/dist/layout/linearStack.js.map +0 -1
  82. package/dist/motion-value.d.ts +0 -58
  83. package/dist/motion-value.d.ts.map +0 -1
  84. package/dist/motion-value.js +0 -250
  85. package/dist/motion-value.js.map +0 -1
  86. package/dist/present/display.d.ts +0 -58
  87. package/dist/present/display.d.ts.map +0 -1
  88. package/dist/present/display.js +0 -168
  89. package/dist/present/display.js.map +0 -1
  90. package/dist/present/writers/fullscreen.d.ts +0 -19
  91. package/dist/present/writers/fullscreen.d.ts.map +0 -1
  92. package/dist/present/writers/fullscreen.js +0 -55
  93. package/dist/present/writers/fullscreen.js.map +0 -1
  94. package/dist/present/writers/inline.d.ts +0 -20
  95. package/dist/present/writers/inline.d.ts.map +0 -1
  96. package/dist/present/writers/inline.js +0 -92
  97. package/dist/present/writers/inline.js.map +0 -1
  98. package/dist/render/color-utils.d.ts +0 -18
  99. package/dist/render/color-utils.d.ts.map +0 -1
  100. package/dist/render/color-utils.js +0 -58
  101. package/dist/render/color-utils.js.map +0 -1
  102. package/dist/render/diff.d.ts +0 -30
  103. package/dist/render/diff.d.ts.map +0 -1
  104. package/dist/render/diff.js +0 -83
  105. package/dist/render/diff.js.map +0 -1
  106. package/dist/spring-physics.d.ts +0 -36
  107. package/dist/spring-physics.d.ts.map +0 -1
  108. package/dist/spring-physics.js +0 -113
  109. package/dist/spring-physics.js.map +0 -1
  110. package/dist/spring.d.ts +0 -73
  111. package/dist/spring.d.ts.map +0 -1
  112. package/dist/spring.js +0 -136
  113. package/dist/spring.js.map +0 -1
  114. package/dist/ui/containers/canvas.d.ts +0 -13
  115. package/dist/ui/containers/canvas.d.ts.map +0 -1
  116. package/dist/ui/containers/canvas.js +0 -16
  117. package/dist/ui/containers/canvas.js.map +0 -1
  118. package/dist/ui/containers/geometry-reader.d.ts +0 -17
  119. package/dist/ui/containers/geometry-reader.d.ts.map +0 -1
  120. package/dist/ui/containers/geometry-reader.js +0 -24
  121. package/dist/ui/containers/geometry-reader.js.map +0 -1
  122. package/dist/ui/containers/hstack.d.ts +0 -12
  123. package/dist/ui/containers/hstack.d.ts.map +0 -1
  124. package/dist/ui/containers/hstack.js +0 -28
  125. package/dist/ui/containers/hstack.js.map +0 -1
  126. package/dist/ui/containers/scroll.d.ts +0 -28
  127. package/dist/ui/containers/scroll.d.ts.map +0 -1
  128. package/dist/ui/containers/scroll.js +0 -97
  129. package/dist/ui/containers/scroll.js.map +0 -1
  130. package/dist/ui/containers/shared.d.ts +0 -12
  131. package/dist/ui/containers/shared.d.ts.map +0 -1
  132. package/dist/ui/containers/shared.js +0 -19
  133. package/dist/ui/containers/shared.js.map +0 -1
  134. package/dist/ui/containers/vstack.d.ts +0 -12
  135. package/dist/ui/containers/vstack.d.ts.map +0 -1
  136. package/dist/ui/containers/vstack.js +0 -28
  137. package/dist/ui/containers/vstack.js.map +0 -1
  138. package/dist/ui/containers/zstack.d.ts +0 -14
  139. package/dist/ui/containers/zstack.d.ts.map +0 -1
  140. package/dist/ui/containers/zstack.js +0 -36
  141. package/dist/ui/containers/zstack.js.map +0 -1
  142. package/dist/ui/core/geometry-store.d.ts +0 -22
  143. package/dist/ui/core/geometry-store.d.ts.map +0 -1
  144. package/dist/ui/core/geometry-store.js +0 -29
  145. package/dist/ui/core/geometry-store.js.map +0 -1
  146. package/dist/ui/core/geometry.d.ts +0 -34
  147. package/dist/ui/core/geometry.d.ts.map +0 -1
  148. package/dist/ui/core/geometry.js +0 -14
  149. package/dist/ui/core/geometry.js.map +0 -1
  150. package/dist/ui/core/view.d.ts +0 -25
  151. package/dist/ui/core/view.d.ts.map +0 -1
  152. package/dist/ui/core/view.js +0 -34
  153. package/dist/ui/core/view.js.map +0 -1
  154. package/dist/ui/index.d.ts +0 -44
  155. package/dist/ui/index.d.ts.map +0 -1
  156. package/dist/ui/index.js +0 -39
  157. package/dist/ui/index.js.map +0 -1
  158. package/dist/ui/inlinetext.d.ts +0 -24
  159. package/dist/ui/inlinetext.d.ts.map +0 -1
  160. package/dist/ui/inlinetext.js +0 -131
  161. package/dist/ui/inlinetext.js.map +0 -1
  162. package/dist/ui/install.d.ts +0 -22
  163. package/dist/ui/install.d.ts.map +0 -1
  164. package/dist/ui/install.js +0 -66
  165. package/dist/ui/install.js.map +0 -1
  166. package/dist/ui/markdown.d.ts +0 -40
  167. package/dist/ui/markdown.d.ts.map +0 -1
  168. package/dist/ui/markdown.js +0 -351
  169. package/dist/ui/markdown.js.map +0 -1
  170. package/dist/ui/modifiers/border.d.ts +0 -33
  171. package/dist/ui/modifiers/border.d.ts.map +0 -1
  172. package/dist/ui/modifiers/border.js +0 -82
  173. package/dist/ui/modifiers/border.js.map +0 -1
  174. package/dist/ui/modifiers/fill.d.ts +0 -14
  175. package/dist/ui/modifiers/fill.d.ts.map +0 -1
  176. package/dist/ui/modifiers/fill.js +0 -25
  177. package/dist/ui/modifiers/fill.js.map +0 -1
  178. package/dist/ui/modifiers/frame.d.ts +0 -23
  179. package/dist/ui/modifiers/frame.d.ts.map +0 -1
  180. package/dist/ui/modifiers/frame.js +0 -54
  181. package/dist/ui/modifiers/frame.js.map +0 -1
  182. package/dist/ui/modifiers/offset.d.ts +0 -15
  183. package/dist/ui/modifiers/offset.d.ts.map +0 -1
  184. package/dist/ui/modifiers/offset.js +0 -21
  185. package/dist/ui/modifiers/offset.js.map +0 -1
  186. package/dist/ui/modifiers/opacity.d.ts +0 -15
  187. package/dist/ui/modifiers/opacity.d.ts.map +0 -1
  188. package/dist/ui/modifiers/opacity.js +0 -95
  189. package/dist/ui/modifiers/opacity.js.map +0 -1
  190. package/dist/ui/modifiers/padding.d.ts +0 -20
  191. package/dist/ui/modifiers/padding.d.ts.map +0 -1
  192. package/dist/ui/modifiers/padding.js +0 -36
  193. package/dist/ui/modifiers/padding.js.map +0 -1
  194. package/dist/ui/modifiers/styled.d.ts +0 -14
  195. package/dist/ui/modifiers/styled.d.ts.map +0 -1
  196. package/dist/ui/modifiers/styled.js +0 -26
  197. package/dist/ui/modifiers/styled.js.map +0 -1
  198. package/dist/ui/primitives/rectangle.d.ts +0 -15
  199. package/dist/ui/primitives/rectangle.d.ts.map +0 -1
  200. package/dist/ui/primitives/rectangle.js +0 -23
  201. package/dist/ui/primitives/rectangle.js.map +0 -1
  202. package/dist/ui/primitives/spacer.d.ts +0 -13
  203. package/dist/ui/primitives/spacer.d.ts.map +0 -1
  204. package/dist/ui/primitives/spacer.js +0 -16
  205. package/dist/ui/primitives/spacer.js.map +0 -1
  206. package/dist/ui/primitives/text.d.ts +0 -15
  207. package/dist/ui/primitives/text.d.ts.map +0 -1
  208. package/dist/ui/primitives/text.js +0 -79
  209. package/dist/ui/primitives/text.js.map +0 -1
  210. package/dist/ui/primitives/wrapped-text.d.ts +0 -30
  211. package/dist/ui/primitives/wrapped-text.d.ts.map +0 -1
  212. package/dist/ui/primitives/wrapped-text.js +0 -117
  213. package/dist/ui/primitives/wrapped-text.js.map +0 -1
  214. package/dist/ui/shinytext.d.ts +0 -66
  215. package/dist/ui/shinytext.d.ts.map +0 -1
  216. package/dist/ui/shinytext.js +0 -99
  217. package/dist/ui/shinytext.js.map +0 -1
  218. package/dist/ui/text/layout.d.ts +0 -35
  219. package/dist/ui/text/layout.d.ts.map +0 -1
  220. package/dist/ui/text/layout.js +0 -102
  221. package/dist/ui/text/layout.js.map +0 -1
  222. package/dist/ui/textinput.d.ts +0 -140
  223. package/dist/ui/textinput.d.ts.map +0 -1
  224. package/dist/ui/textinput.js +0 -402
  225. package/dist/ui/textinput.js.map +0 -1
  226. package/dist/ui/view-constructors.d.ts +0 -72
  227. package/dist/ui/view-constructors.d.ts.map +0 -1
  228. package/dist/ui/view-constructors.js +0 -74
  229. package/dist/ui/view-constructors.js.map +0 -1
  230. package/src/anim.ts +0 -5
  231. package/src/layout/linearStack.ts +0 -115
  232. package/src/motion-value.ts +0 -335
  233. package/src/present/display.ts +0 -206
  234. package/src/present/writers/fullscreen.ts +0 -58
  235. package/src/present/writers/inline.ts +0 -101
  236. package/src/render/color-utils.ts +0 -60
  237. package/src/render/diff.ts +0 -95
  238. package/src/spring-physics.ts +0 -151
  239. package/src/spring.ts +0 -234
  240. package/src/ui/__snapshots__/wrappedtext.test.ts.snap +0 -57
  241. package/src/ui/containers/canvas.ts +0 -18
  242. package/src/ui/containers/geometry-reader.ts +0 -32
  243. package/src/ui/containers/hstack.ts +0 -33
  244. package/src/ui/containers/scroll.ts +0 -106
  245. package/src/ui/containers/shared.ts +0 -27
  246. package/src/ui/containers/vstack.ts +0 -34
  247. package/src/ui/containers/zstack.ts +0 -37
  248. package/src/ui/core/geometry-store.ts +0 -42
  249. package/src/ui/core/geometry.ts +0 -30
  250. package/src/ui/core/view.ts +0 -49
  251. package/src/ui/index.ts +0 -84
  252. package/src/ui/inlinetext.ts +0 -135
  253. package/src/ui/install.ts +0 -110
  254. package/src/ui/markdown.test.ts +0 -74
  255. package/src/ui/markdown.ts +0 -388
  256. package/src/ui/modifiers/border.ts +0 -100
  257. package/src/ui/modifiers/fill.ts +0 -28
  258. package/src/ui/modifiers/frame.ts +0 -74
  259. package/src/ui/modifiers/offset.ts +0 -23
  260. package/src/ui/modifiers/opacity.ts +0 -93
  261. package/src/ui/modifiers/padding.ts +0 -53
  262. package/src/ui/modifiers/styled.ts +0 -31
  263. package/src/ui/primitives/rectangle.ts +0 -25
  264. package/src/ui/primitives/spacer.ts +0 -18
  265. package/src/ui/primitives/text.ts +0 -85
  266. package/src/ui/primitives/wrapped-text.ts +0 -131
  267. package/src/ui/shinytext.ts +0 -159
  268. package/src/ui/text/layout.ts +0 -119
  269. package/src/ui/textinput.ts +0 -496
  270. package/src/ui/view-constructors.ts +0 -96
  271. package/src/ui/wrappedtext.test.ts +0 -138
package/README.md CHANGED
@@ -63,27 +63,47 @@ const surface = new Surface(process.stdout)
63
63
  surface.render(buffer)
64
64
  ```
65
65
 
66
- ## Spring Physics
66
+ ## Animation
67
67
 
68
- Analytical spring equations (matches framer-motion):
68
+ ### MotionValue
69
+
70
+ Observable values with spring physics (matches framer-motion):
69
71
 
70
72
  ```typescript
71
- import { Spring } from "@effect-tui/core"
73
+ import { motionValue } from "@effect-tui/core"
74
+
75
+ // Create motion value
76
+ const mv = motionValue(0)
77
+
78
+ // Subscribe to changes
79
+ mv.onChange((value) => console.log(value))
72
80
 
73
- // Create spring with target
74
- const spring = Spring.init(0)
75
- const animated = Spring.to(spring, 100, { visualDuration: 0.35, bounce: 0.2 })
81
+ // Animate to target with spring physics
82
+ mv.animate(100, { duration: 0.35, bounce: 0.2 })
76
83
 
77
- // Tick each frame
78
- const next = Spring.tick(animated, 16) // 16ms delta
79
- const value = Spring.value(next) // Current position
80
- const done = Spring.settled(next) // Animation complete?
84
+ // Read current value
85
+ const value = mv.get()
81
86
  ```
82
87
 
83
88
  **Parameters:**
84
- - `visualDuration` - Time to reach ~99% of target (seconds)
89
+ - `duration` - Time to reach ~99% of target (seconds)
85
90
  - `bounce` - Overshoot amount (0 = no bounce, 0.5 = bouncy)
86
91
 
92
+ ### Step
93
+
94
+ Frame-based discrete animation (used by ShinyText):
95
+
96
+ ```typescript
97
+ import { Step } from "@effect-tui/core"
98
+
99
+ // Create stepper cycling through 10 frames at 80ms/frame
100
+ let stepper = Step.init(10, 80)
101
+
102
+ // Tick with current timestamp
103
+ stepper = Step.tick(stepper, Date.now())
104
+ console.log(stepper.index) // Current frame index
105
+ ```
106
+
87
107
  ## Related
88
108
 
89
109
  - [@effect-tui/react](https://github.com/kitlangton/effect-tui/tree/main/packages/effect-tui-react) - React renderer for terminal UIs
package/dist/ansi.d.ts CHANGED
@@ -1,69 +1,164 @@
1
- /** Basic ANSI codes and helpers */
1
+ /** ANSI escape sequence primitives */
2
2
  export declare const ANSI: {
3
- /** Reset all attributes */
4
- readonly reset: "\u001B[0m";
5
3
  /** Cursor control */
6
4
  readonly cursor: {
5
+ /** Move cursor to 1-based row/column position */
6
+ readonly to: (x: number, y: number) => string;
7
+ /** Move cursor to 1-based column on current row */
8
+ readonly toCol: (col: number) => string;
9
+ /** Move cursor up by n rows */
10
+ readonly up: (n: number) => string;
11
+ /** Move cursor down by n rows */
12
+ readonly down: (n: number) => string;
7
13
  /** Hide cursor */
8
14
  readonly hide: "\u001B[?25l";
9
15
  /** Show cursor */
10
16
  readonly show: "\u001B[?25h";
17
+ /** Move cursor to start of current line */
18
+ readonly startOfLine: "\r";
11
19
  /** Move cursor to home position (1,1) */
12
20
  readonly home: "\u001B[H";
13
- /** Move cursor to 1-based row/column */
14
- readonly to: (row1: number, col1: number) => string;
15
- /** Move cursor to 1-based column on current row */
16
- readonly toCol: (col1: number) => string;
21
+ };
22
+ /** Line control */
23
+ readonly line: {
24
+ /** Clear entire line */
25
+ readonly clear: "\u001B[2K";
26
+ /** Clear from cursor to end of line */
27
+ readonly clearToEnd: "\u001B[0K";
17
28
  };
18
29
  /** Screen control */
19
30
  readonly screen: {
20
31
  /** Enter alternate screen buffer */
21
- readonly altEnter: "\u001B[?1049h";
32
+ readonly enterAlt: "\u001B[?1049h";
22
33
  /** Exit alternate screen buffer */
23
- readonly altExit: "\u001B[?1049l";
24
- /** Clear entire display */
34
+ readonly exitAlt: "\u001B[?1049l";
35
+ /** Clear entire screen */
25
36
  readonly clear: "\u001B[2J";
37
+ /** Clear from cursor to end of screen */
38
+ readonly clearToEnd: "\u001B[J";
26
39
  /** Clear scrollback buffer */
27
40
  readonly clearScrollback: "\u001B[3J";
28
41
  };
42
+ /** Mouse reporting */
43
+ readonly mouse: {
44
+ /** Enable SGR extended mouse mode with any-event tracking (scroll wheel support) */
45
+ readonly enable: "\u001B[?1003h\u001B[?1006h";
46
+ /** Disable mouse tracking */
47
+ readonly disable: "\u001B[?1006l\u001B[?1003l";
48
+ };
49
+ /** Bracketed paste mode */
50
+ readonly paste: {
51
+ /** Enable bracketed paste */
52
+ readonly enable: "\u001B[?2004h";
53
+ /** Disable bracketed paste */
54
+ readonly disable: "\u001B[?2004l";
55
+ /** Paste start marker */
56
+ readonly startMarker: "\u001B[200~";
57
+ /** Paste end marker */
58
+ readonly endMarker: "\u001B[201~";
59
+ };
60
+ /** Line reflow control (DEC mode 2028 - limited terminal support) */
61
+ readonly reflow: {
62
+ /** Disable line reflow on resize (Contour, some others) */
63
+ readonly disable: "\u001B[?2028l";
64
+ /** Enable line reflow on resize (default) */
65
+ readonly enable: "\u001B[?2028h";
66
+ };
67
+ /** Scroll region control (DECSTBM) */
68
+ readonly scrollRegion: {
69
+ /** Set scroll region to rows [top, bottom] (1-indexed, inclusive) */
70
+ readonly set: (top: number, bottom: number) => string;
71
+ /** Reset scroll region to full screen */
72
+ readonly reset: "\u001B[r";
73
+ };
74
+ /** Line insertion/deletion */
75
+ readonly lines: {
76
+ /** Insert n blank lines at cursor, pushing content down (IL) */
77
+ readonly insert: (n: number) => string;
78
+ /** Delete n lines at cursor, pulling content up (DL) */
79
+ readonly delete: (n: number) => string;
80
+ };
81
+ /** Cursor save/restore (DECSC/DECRC) */
82
+ readonly cursorState: {
83
+ /** Save cursor position and attributes */
84
+ readonly save: "\u001B7";
85
+ /** Restore cursor position and attributes */
86
+ readonly restore: "\u001B8";
87
+ };
88
+ /**
89
+ * Kitty keyboard protocol
90
+ * @see https://sw.kovidgoyal.net/kitty/keyboard-protocol/
91
+ * Enables enhanced key reporting with modifier detection for Ctrl+Shift+key combos
92
+ */
93
+ readonly keyboard: {
94
+ /**
95
+ * Enable Kitty keyboard protocol with flags.
96
+ * Flag 1 (disambiguate): Reports Ctrl+C as CSI sequence instead of raw ETX,
97
+ * allowing detection of Ctrl+Shift+C vs Ctrl+C.
98
+ * Supported by: Kitty, iTerm2 3.5+, WezTerm, Ghostty, foot, Contour, rio
99
+ * NOTE: Many terminals intercept Ctrl+Shift+C for their own copy - may need
100
+ * to configure terminal or use different keybinding.
101
+ */
102
+ readonly enable: (flags?: number) => string;
103
+ /** Disable/pop Kitty keyboard protocol */
104
+ readonly disable: "\u001B[<u";
105
+ /** Query current keyboard mode (response: CSI ? flags u) */
106
+ readonly query: "\u001B[?u";
107
+ };
108
+ /**
109
+ * xterm modifyOtherKeys mode
110
+ * @see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
111
+ * Alternative to Kitty protocol, supported by xterm and some other terminals.
112
+ */
113
+ readonly modifyOtherKeys: {
114
+ /** Enable mode 2 (full modifier reporting) */
115
+ readonly enable: "\u001B[>4;2m";
116
+ /** Disable modifyOtherKeys */
117
+ readonly disable: "\u001B[>4;0m";
118
+ };
119
+ /** Style/SGR reset */
120
+ readonly resetStyle: "\u001B[0m";
121
+ /** Build style SGR sequence */
122
+ readonly style: (s: {
123
+ fg?: number;
124
+ bg?: number;
125
+ bold?: boolean;
126
+ italic?: boolean;
127
+ underline?: boolean;
128
+ inverse?: boolean;
129
+ }) => string;
29
130
  /** Scrolling */
30
131
  readonly scroll: {
31
132
  /** Scroll up by n lines */
32
133
  readonly up: (n: number) => string;
33
134
  };
34
- /** Device Status Reports / queries */
135
+ /** Device Status Reports */
35
136
  readonly report: {
36
- /** Report Cursor Position (response: ESC [ row ; col R) */
137
+ /** Request cursor position (response: ESC [ row ; col R) */
37
138
  readonly cursorPosition: "\u001B[6n";
38
139
  };
39
- /** Bracketed paste mode */
40
- readonly paste: {
41
- readonly bracketed: {
42
- readonly on: "\u001B[?2004h";
43
- readonly off: "\u001B[?2004l";
44
- };
45
- };
46
- /** Mouse reporting toggles */
47
- readonly mouse: {
48
- /** Enable button tracking and SGR coordinates */
49
- readonly on: "\u001B[?1002h\u001B[?1006h";
50
- /** Disable SGR coords and button tracking */
51
- readonly off: "\u001B[?1006l\u001B[?1002l";
52
- };
53
140
  };
54
- /** Terminal session control utilities (compositions of ANSI primitives) */
141
+ /** High-level terminal control utilities (compositions of ANSI primitives) */
55
142
  export declare const Terminal: {
56
- /** Enter full-screen mode: alternate screen + hide cursor */
143
+ /** Enter full-screen mode: alternate screen + clear + hide cursor */
57
144
  readonly enterFullscreen: string;
58
- /** Exit full-screen mode: reset + show cursor + exit alternate screen */
145
+ /** Exit full-screen mode: show cursor + exit alternate screen */
59
146
  readonly exitFullscreen: string;
147
+ /** Hide cursor */
148
+ readonly hideCursor: "\u001B[?25l";
149
+ /** Show cursor */
150
+ readonly showCursor: "\u001B[?25h";
60
151
  /** Clear screen and move cursor to home */
61
152
  readonly clearAndHome: string;
62
- /** Convenience shorthands for common toggles */
153
+ /** Enable bracketed paste mode */
63
154
  readonly bracketedPasteOn: "\u001B[?2004h";
155
+ /** Disable bracketed paste mode */
64
156
  readonly bracketedPasteOff: "\u001B[?2004l";
65
- readonly mouseOn: "\u001B[?1002h\u001B[?1006h";
66
- readonly mouseOff: "\u001B[?1006l\u001B[?1002l";
157
+ /** Enable mouse tracking */
158
+ readonly mouseOn: "\u001B[?1003h\u001B[?1006h";
159
+ /** Disable mouse tracking */
160
+ readonly mouseOff: "\u001B[?1006l\u001B[?1003l";
161
+ /** Request cursor position report */
67
162
  readonly reportCursorPosition: "\u001B[6n";
68
163
  };
69
164
  //# sourceMappingURL=ansi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAKA,mCAAmC;AACnC,eAAO,MAAM,IAAI;IACf,2BAA2B;;IAG3B,qBAAqB;;QAEnB,kBAAkB;;QAElB,kBAAkB;;QAElB,yCAAyC;;QAEzC,wCAAwC;4BAC7B,MAAM,QAAQ,MAAM;QAC/B,mDAAmD;+BACrC,MAAM;;IAGtB,qBAAqB;;QAEnB,oCAAoC;;QAEpC,mCAAmC;;QAEnC,2BAA2B;;QAE3B,8BAA8B;;;IAIhC,gBAAgB;;QAEd,2BAA2B;yBACnB,MAAM;;IAGhB,sCAAsC;;QAEpC,2DAA2D;;;IAI7D,2BAA2B;;;;;;;IAQ3B,8BAA8B;;QAE5B,iDAAiD;;QAEjD,6CAA6C;;;CAGvC,CAAA;AAEV,2EAA2E;AAC3E,eAAO,MAAM,QAAQ;IACnB,6DAA6D;;IAG7D,yEAAyE;;IAGzE,2CAA2C;;IAG3C,gDAAgD;;;;;;CAMxC,CAAA"}
1
+ {"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAKA,sCAAsC;AACtC,eAAO,MAAM,IAAI;IAChB,qBAAqB;;QAEpB,iDAAiD;yBACzC,MAAM,KAAK,MAAM;QACzB,mDAAmD;8BACtC,MAAM;QACnB,+BAA+B;yBACvB,MAAM;QACd,iCAAiC;2BACvB,MAAM;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;IAEnC,4BAA4B;;IAE5B,6BAA6B;;IAE7B,qCAAqC;;CAE5B,CAAA"}
package/dist/ansi.js CHANGED
@@ -1,72 +1,194 @@
1
- // ANSI escape sequences and terminal control utilities
1
+ // ansi.ts — ANSI escape sequences for terminal control
2
2
  /** CSI prefix (ESC [) */
3
3
  const CSI = "\x1b[";
4
- /** Basic ANSI codes and helpers */
4
+ /** ANSI escape sequence primitives */
5
5
  export const ANSI = {
6
- /** Reset all attributes */
7
- reset: `${CSI}0m`,
8
6
  /** Cursor control */
9
7
  cursor: {
8
+ /** Move cursor to 1-based row/column position */
9
+ to: (x, y) => `${CSI}${y};${x}H`,
10
+ /** Move cursor to 1-based column on current row */
11
+ toCol: (col) => `${CSI}${col}G`,
12
+ /** Move cursor up by n rows */
13
+ up: (n) => (n > 0 ? `${CSI}${n}A` : ""),
14
+ /** Move cursor down by n rows */
15
+ down: (n) => (n > 0 ? `${CSI}${n}B` : ""),
10
16
  /** Hide cursor */
11
17
  hide: `${CSI}?25l`,
12
18
  /** Show cursor */
13
19
  show: `${CSI}?25h`,
20
+ /** Move cursor to start of current line */
21
+ startOfLine: "\r",
14
22
  /** Move cursor to home position (1,1) */
15
23
  home: `${CSI}H`,
16
- /** Move cursor to 1-based row/column */
17
- to: (row1, col1) => `${CSI}${row1};${col1}H`,
18
- /** Move cursor to 1-based column on current row */
19
- toCol: (col1) => `${CSI}${col1}G`,
24
+ },
25
+ /** Line control */
26
+ line: {
27
+ /** Clear entire line */
28
+ clear: `${CSI}2K`,
29
+ /** Clear from cursor to end of line */
30
+ clearToEnd: `${CSI}0K`,
20
31
  },
21
32
  /** Screen control */
22
33
  screen: {
23
34
  /** Enter alternate screen buffer */
24
- altEnter: `${CSI}?1049h`,
35
+ enterAlt: `${CSI}?1049h`,
25
36
  /** Exit alternate screen buffer */
26
- altExit: `${CSI}?1049l`,
27
- /** Clear entire display */
37
+ exitAlt: `${CSI}?1049l`,
38
+ /** Clear entire screen */
28
39
  clear: `${CSI}2J`,
40
+ /** Clear from cursor to end of screen */
41
+ clearToEnd: `${CSI}J`,
29
42
  /** Clear scrollback buffer */
30
43
  clearScrollback: `${CSI}3J`,
31
44
  },
45
+ /** Mouse reporting */
46
+ mouse: {
47
+ /** Enable SGR extended mouse mode with any-event tracking (scroll wheel support) */
48
+ enable: `${CSI}?1003h${CSI}?1006h`,
49
+ /** Disable mouse tracking */
50
+ disable: `${CSI}?1006l${CSI}?1003l`,
51
+ },
52
+ /** Bracketed paste mode */
53
+ paste: {
54
+ /** Enable bracketed paste */
55
+ enable: `${CSI}?2004h`,
56
+ /** Disable bracketed paste */
57
+ disable: `${CSI}?2004l`,
58
+ /** Paste start marker */
59
+ startMarker: `${CSI}200~`,
60
+ /** Paste end marker */
61
+ endMarker: `${CSI}201~`,
62
+ },
63
+ /** Line reflow control (DEC mode 2028 - limited terminal support) */
64
+ reflow: {
65
+ /** Disable line reflow on resize (Contour, some others) */
66
+ disable: `${CSI}?2028l`,
67
+ /** Enable line reflow on resize (default) */
68
+ enable: `${CSI}?2028h`,
69
+ },
70
+ /** Scroll region control (DECSTBM) */
71
+ scrollRegion: {
72
+ /** Set scroll region to rows [top, bottom] (1-indexed, inclusive) */
73
+ set: (top, bottom) => `${CSI}${top};${bottom}r`,
74
+ /** Reset scroll region to full screen */
75
+ reset: `${CSI}r`,
76
+ },
77
+ /** Line insertion/deletion */
78
+ lines: {
79
+ /** Insert n blank lines at cursor, pushing content down (IL) */
80
+ insert: (n) => (n > 0 ? `${CSI}${n}L` : ""),
81
+ /** Delete n lines at cursor, pulling content up (DL) */
82
+ delete: (n) => (n > 0 ? `${CSI}${n}M` : ""),
83
+ },
84
+ /** Cursor save/restore (DECSC/DECRC) */
85
+ cursorState: {
86
+ /** Save cursor position and attributes */
87
+ save: "\x1b7",
88
+ /** Restore cursor position and attributes */
89
+ restore: "\x1b8",
90
+ },
91
+ /**
92
+ * Kitty keyboard protocol
93
+ * @see https://sw.kovidgoyal.net/kitty/keyboard-protocol/
94
+ * Enables enhanced key reporting with modifier detection for Ctrl+Shift+key combos
95
+ */
96
+ keyboard: {
97
+ /**
98
+ * Enable Kitty keyboard protocol with flags.
99
+ * Flag 1 (disambiguate): Reports Ctrl+C as CSI sequence instead of raw ETX,
100
+ * allowing detection of Ctrl+Shift+C vs Ctrl+C.
101
+ * Supported by: Kitty, iTerm2 3.5+, WezTerm, Ghostty, foot, Contour, rio
102
+ * NOTE: Many terminals intercept Ctrl+Shift+C for their own copy - may need
103
+ * to configure terminal or use different keybinding.
104
+ */
105
+ enable: (flags = 1) => `${CSI}>${flags}u`,
106
+ /** Disable/pop Kitty keyboard protocol */
107
+ disable: `${CSI}<u`,
108
+ /** Query current keyboard mode (response: CSI ? flags u) */
109
+ query: `${CSI}?u`,
110
+ },
111
+ /**
112
+ * xterm modifyOtherKeys mode
113
+ * @see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
114
+ * Alternative to Kitty protocol, supported by xterm and some other terminals.
115
+ */
116
+ modifyOtherKeys: {
117
+ /** Enable mode 2 (full modifier reporting) */
118
+ enable: `${CSI}>4;2m`,
119
+ /** Disable modifyOtherKeys */
120
+ disable: `${CSI}>4;0m`,
121
+ },
122
+ /** Style/SGR reset */
123
+ resetStyle: `${CSI}0m`,
124
+ /** Build style SGR sequence */
125
+ style: (s) => {
126
+ const codes = [];
127
+ if (s.bold)
128
+ codes.push(1);
129
+ if (s.italic)
130
+ codes.push(3);
131
+ if (s.underline)
132
+ codes.push(4);
133
+ if (s.inverse)
134
+ codes.push(7);
135
+ if (s.fg !== undefined) {
136
+ if (s.fg < 256) {
137
+ codes.push(38, 5, s.fg);
138
+ }
139
+ else {
140
+ // Truecolor: decode from packed RGB
141
+ const r = (s.fg >> 16) & 0xff;
142
+ const g = (s.fg >> 8) & 0xff;
143
+ const b = s.fg & 0xff;
144
+ codes.push(38, 2, r, g, b);
145
+ }
146
+ }
147
+ if (s.bg !== undefined) {
148
+ if (s.bg < 256) {
149
+ codes.push(48, 5, s.bg);
150
+ }
151
+ else {
152
+ const r = (s.bg >> 16) & 0xff;
153
+ const g = (s.bg >> 8) & 0xff;
154
+ const b = s.bg & 0xff;
155
+ codes.push(48, 2, r, g, b);
156
+ }
157
+ }
158
+ return codes.length > 0 ? `${CSI}${codes.join(";")}m` : "";
159
+ },
32
160
  /** Scrolling */
33
161
  scroll: {
34
162
  /** Scroll up by n lines */
35
163
  up: (n) => `${CSI}${n}S`,
36
164
  },
37
- /** Device Status Reports / queries */
165
+ /** Device Status Reports */
38
166
  report: {
39
- /** Report Cursor Position (response: ESC [ row ; col R) */
167
+ /** Request cursor position (response: ESC [ row ; col R) */
40
168
  cursorPosition: `${CSI}6n`,
41
169
  },
42
- /** Bracketed paste mode */
43
- paste: {
44
- bracketed: {
45
- on: `${CSI}?2004h`,
46
- off: `${CSI}?2004l`,
47
- },
48
- },
49
- /** Mouse reporting toggles */
50
- mouse: {
51
- /** Enable button tracking and SGR coordinates */
52
- on: `${CSI}?1002h${CSI}?1006h`,
53
- /** Disable SGR coords and button tracking */
54
- off: `${CSI}?1006l${CSI}?1002l`,
55
- },
56
170
  };
57
- /** Terminal session control utilities (compositions of ANSI primitives) */
171
+ /** High-level terminal control utilities (compositions of ANSI primitives) */
58
172
  export const Terminal = {
59
- /** Enter full-screen mode: alternate screen + hide cursor */
60
- enterFullscreen: ANSI.screen.altEnter + ANSI.cursor.hide,
61
- /** Exit full-screen mode: reset + show cursor + exit alternate screen */
62
- exitFullscreen: ANSI.reset + ANSI.cursor.show + ANSI.screen.altExit,
173
+ /** Enter full-screen mode: alternate screen + clear + hide cursor */
174
+ enterFullscreen: ANSI.screen.enterAlt + ANSI.screen.clear + ANSI.cursor.hide,
175
+ /** Exit full-screen mode: show cursor + exit alternate screen */
176
+ exitFullscreen: ANSI.screen.exitAlt + ANSI.cursor.show,
177
+ /** Hide cursor */
178
+ hideCursor: ANSI.cursor.hide,
179
+ /** Show cursor */
180
+ showCursor: ANSI.cursor.show,
63
181
  /** Clear screen and move cursor to home */
64
182
  clearAndHome: ANSI.screen.clear + ANSI.cursor.home,
65
- /** Convenience shorthands for common toggles */
66
- bracketedPasteOn: ANSI.paste.bracketed.on,
67
- bracketedPasteOff: ANSI.paste.bracketed.off,
68
- mouseOn: ANSI.mouse.on,
69
- mouseOff: ANSI.mouse.off,
183
+ /** Enable bracketed paste mode */
184
+ bracketedPasteOn: ANSI.paste.enable,
185
+ /** Disable bracketed paste mode */
186
+ bracketedPasteOff: ANSI.paste.disable,
187
+ /** Enable mouse tracking */
188
+ mouseOn: ANSI.mouse.enable,
189
+ /** Disable mouse tracking */
190
+ mouseOff: ANSI.mouse.disable,
191
+ /** Request cursor position report */
70
192
  reportCursorPosition: ANSI.report.cursorPosition,
71
193
  };
72
194
  //# sourceMappingURL=ansi.js.map
package/dist/ansi.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ansi.js","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,yBAAyB;AACzB,MAAM,GAAG,GAAG,OAAO,CAAA;AAEnB,mCAAmC;AACnC,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,2BAA2B;IAC3B,KAAK,EAAE,GAAG,GAAG,IAAI;IAEjB,qBAAqB;IACrB,MAAM,EAAE;QACN,kBAAkB;QAClB,IAAI,EAAE,GAAG,GAAG,MAAM;QAClB,kBAAkB;QAClB,IAAI,EAAE,GAAG,GAAG,MAAM;QAClB,yCAAyC;QACzC,IAAI,EAAE,GAAG,GAAG,GAAG;QACf,wCAAwC;QACxC,EAAE,EAAE,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,IAAI,IAAI,IAAI,GAAG;QAC5D,mDAAmD;QACnD,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,IAAI,GAAG;KAC1C;IAED,qBAAqB;IACrB,MAAM,EAAE;QACN,oCAAoC;QACpC,QAAQ,EAAE,GAAG,GAAG,QAAQ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`#${string}` because enumerating all valid hex digit combinations
6
+ * (22^6 = 113M for 6-char hex) exceeds TypeScript's union type limits.
7
+ * The # prefix is validated at compile time; hex digits are validated at runtime.
8
+ */
9
+ export type HexColor = `#${string}`;
10
+ /** Base ANSI terminal color names */
11
+ export type BaseColorName = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
12
+ /**
13
+ * Color input type - the main public type for color props.
14
+ *
15
+ * Accepts:
16
+ * - Palette index: 0-255
17
+ * - RGB object: { r, g, b }
18
+ * - Named color: "red", "brightBlue", etc. (type-checked)
19
+ * - Hex color: "#f00", "#ff0000" (# prefix required)
20
+ */
21
+ export type Color = number | {
22
+ r: number;
23
+ g: number;
24
+ b: number;
25
+ } | BaseColorName | HexColor;
26
+ /** RGBA color with alpha channel - used for color springs/interpolation */
27
+ export type RGBA = {
28
+ r: number;
29
+ g: number;
30
+ b: number;
31
+ a: number;
32
+ };
33
+ /** Color input for springs (includes alpha variants) */
34
+ export type ColorInput = string | RGBA | {
35
+ r: number;
36
+ g: number;
37
+ b: number;
38
+ };
39
+ /** Standard ANSI color names mapped to 256-color indices */
40
+ export declare const BASE_NAMES: {
41
+ readonly black: 0;
42
+ readonly red: 1;
43
+ readonly green: 2;
44
+ readonly yellow: 3;
45
+ readonly blue: 4;
46
+ readonly magenta: 5;
47
+ readonly cyan: 6;
48
+ readonly white: 7;
49
+ readonly brightBlack: 8;
50
+ readonly brightRed: 9;
51
+ readonly brightGreen: 10;
52
+ readonly brightYellow: 11;
53
+ readonly brightBlue: 12;
54
+ readonly brightMagenta: 13;
55
+ readonly brightCyan: 14;
56
+ readonly brightWhite: 15;
57
+ };
58
+ /** Clamp a number to 0-255 range */
59
+ export declare function clamp255(n: number): number;
60
+ /** Clamp a number to 0-1 range */
61
+ export declare function clamp1(n: number): number;
62
+ /** Internal type for resolved colors (palette index or RGB) */
63
+ type ColorValue = number | {
64
+ r: number;
65
+ g: number;
66
+ b: number;
67
+ };
68
+ /**
69
+ * Parse flexible color inputs into a resolved color value.
70
+ * Supports: number (0-255), {r,g,b}, "#rgb", "#rrggbb", base names, gray0-23.
71
+ * Used by Palette and style systems.
72
+ */
73
+ export declare function parseColor(c: Color): ColorValue;
74
+ /**
75
+ * Parse any supported color format to RGBA (with alpha).
76
+ * Supports: hex (#rgb, #rrggbb, #rgba, #rrggbbaa), rgb(), rgba(), hsl(), hsla(), {r,g,b,a}.
77
+ * Used by color springs for interpolation.
78
+ */
79
+ export declare function parseColorRGBA(input: ColorInput): RGBA;
80
+ /**
81
+ * Convert HSL to RGBA.
82
+ * h: 0-360, s: 0-100, l: 0-100, a: 0-1
83
+ */
84
+ export declare function hslToRgba(h: number, s: number, l: number, a: number): RGBA;
85
+ /**
86
+ * Convert a 256-color index to RGB values (approximate xterm palette).
87
+ * 0-15: Standard ANSI, 16-231: 6x6x6 RGB cube, 232-255: Grayscale ramp
88
+ */
89
+ export declare function idxToRGB(idx: number): {
90
+ r: number;
91
+ g: number;
92
+ b: number;
93
+ };
94
+ /**
95
+ * Check if a value looks like a color input.
96
+ */
97
+ export declare function isColorInput(value: unknown): value is ColorInput;
98
+ type RGB = {
99
+ r: number;
100
+ g: number;
101
+ b: number;
102
+ };
103
+ type TailwindColorFn = (shade: TailwindShade) => RGB;
104
+ type TailwindColors = {
105
+ slate: TailwindColorFn;
106
+ gray: TailwindColorFn;
107
+ zinc: TailwindColorFn;
108
+ neutral: TailwindColorFn;
109
+ stone: TailwindColorFn;
110
+ red: TailwindColorFn;
111
+ orange: TailwindColorFn;
112
+ amber: TailwindColorFn;
113
+ yellow: TailwindColorFn;
114
+ lime: TailwindColorFn;
115
+ green: TailwindColorFn;
116
+ emerald: TailwindColorFn;
117
+ teal: TailwindColorFn;
118
+ cyan: TailwindColorFn;
119
+ sky: TailwindColorFn;
120
+ blue: TailwindColorFn;
121
+ indigo: TailwindColorFn;
122
+ violet: TailwindColorFn;
123
+ purple: TailwindColorFn;
124
+ fuchsia: TailwindColorFn;
125
+ pink: TailwindColorFn;
126
+ rose: TailwindColorFn;
127
+ };
128
+ type ColorsApi = typeof BASE_NAMES & {
129
+ rgb(r: number, g: number, b: number): RGB;
130
+ hex(hex: HexColor): RGB;
131
+ /** Gray - 24-level grayscale palette (0-23) */
132
+ gray(level: number): number;
133
+ /** Tailwind color palette */
134
+ tw: TailwindColors;
135
+ };
136
+ /** Convenience API for creating color values */
137
+ export declare const Colors: ColorsApi;
138
+ export {};
139
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,aAAa,EAA4B,MAAM,sBAAsB,CAAA;AAMnG;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAA;AAEnC,qCAAqC;AACrC,MAAM,MAAM,aAAa,GACtB,OAAO,GACP,KAAK,GACL,OAAO,GACP,QAAQ,GACR,MAAM,GACN,SAAS,GACT,MAAM,GACN,OAAO,GACP,aAAa,GACb,WAAW,GACX,aAAa,GACb,cAAc,GACd,YAAY,GACZ,eAAe,GACf,YAAY,GACZ,aAAa,CAAA;AAEhB;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,GAAG,QAAQ,CAAA;AAE3F,2EAA2E;AAC3E,MAAM,MAAM,IAAI,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjE,wDAAwD;AACxD,MAAM,MAAM,UAAU,GAAG,M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