@effect-tui/react 0.13.0 → 0.14.0

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 (120) hide show
  1. package/README.md +11 -7
  2. package/dist/jsx-runtime.d.ts +1 -2
  3. package/dist/jsx-runtime.d.ts.map +1 -1
  4. package/dist/src/components/Markdown.js +7 -7
  5. package/dist/src/components/Markdown.js.map +1 -1
  6. package/dist/src/components/MultilineTextInput.d.ts.map +1 -1
  7. package/dist/src/components/MultilineTextInput.js +11 -0
  8. package/dist/src/components/MultilineTextInput.js.map +1 -1
  9. package/dist/src/components/TextInput.d.ts.map +1 -1
  10. package/dist/src/components/TextInput.js +15 -0
  11. package/dist/src/components/TextInput.js.map +1 -1
  12. package/dist/src/hosts/base.d.ts +16 -0
  13. package/dist/src/hosts/base.d.ts.map +1 -1
  14. package/dist/src/hosts/base.js +30 -0
  15. package/dist/src/hosts/base.js.map +1 -1
  16. package/dist/src/hosts/box.d.ts.map +1 -1
  17. package/dist/src/hosts/box.js +7 -8
  18. package/dist/src/hosts/box.js.map +1 -1
  19. package/dist/src/hosts/canvas.d.ts.map +1 -1
  20. package/dist/src/hosts/canvas.js +5 -3
  21. package/dist/src/hosts/canvas.js.map +1 -1
  22. package/dist/src/hosts/codeblock.d.ts.map +1 -1
  23. package/dist/src/hosts/codeblock.js +5 -4
  24. package/dist/src/hosts/codeblock.js.map +1 -1
  25. package/dist/src/hosts/flex-container.d.ts.map +1 -1
  26. package/dist/src/hosts/flex-container.js +5 -8
  27. package/dist/src/hosts/flex-container.js.map +1 -1
  28. package/dist/src/hosts/index.d.ts +1 -1
  29. package/dist/src/hosts/index.d.ts.map +1 -1
  30. package/dist/src/hosts/index.js +2 -3
  31. package/dist/src/hosts/index.js.map +1 -1
  32. package/dist/src/hosts/overlay-item.js +2 -2
  33. package/dist/src/hosts/overlay-item.js.map +1 -1
  34. package/dist/src/hosts/overlay.d.ts.map +1 -1
  35. package/dist/src/hosts/overlay.js +6 -11
  36. package/dist/src/hosts/overlay.js.map +1 -1
  37. package/dist/src/hosts/scroll.d.ts +4 -0
  38. package/dist/src/hosts/scroll.d.ts.map +1 -1
  39. package/dist/src/hosts/scroll.js +32 -24
  40. package/dist/src/hosts/scroll.js.map +1 -1
  41. package/dist/src/hosts/spacer.d.ts.map +1 -1
  42. package/dist/src/hosts/spacer.js +1 -3
  43. package/dist/src/hosts/spacer.js.map +1 -1
  44. package/dist/src/hosts/text.d.ts +24 -45
  45. package/dist/src/hosts/text.d.ts.map +1 -1
  46. package/dist/src/hosts/text.js +69 -215
  47. package/dist/src/hosts/text.js.map +1 -1
  48. package/dist/src/hosts/zstack.d.ts.map +1 -1
  49. package/dist/src/hosts/zstack.js +4 -10
  50. package/dist/src/hosts/zstack.js.map +1 -1
  51. package/dist/src/reconciler/types.d.ts +2 -0
  52. package/dist/src/reconciler/types.d.ts.map +1 -1
  53. package/dist/src/renderer/core/FrameBuilder.d.ts.map +1 -1
  54. package/dist/src/renderer/core/FrameBuilder.js +2 -0
  55. package/dist/src/renderer/core/FrameBuilder.js.map +1 -1
  56. package/dist/src/renderer/input/InputProcessor.d.ts.map +1 -1
  57. package/dist/src/renderer/input/InputProcessor.js +5 -2
  58. package/dist/src/renderer/input/InputProcessor.js.map +1 -1
  59. package/dist/src/renderer/lifecycle/RenderCache.d.ts +3 -0
  60. package/dist/src/renderer/lifecycle/RenderCache.d.ts.map +1 -0
  61. package/dist/src/renderer/lifecycle/RenderCache.js +9 -0
  62. package/dist/src/renderer/lifecycle/RenderCache.js.map +1 -0
  63. package/dist/src/renderer/lifecycle/index.d.ts +1 -0
  64. package/dist/src/renderer/lifecycle/index.d.ts.map +1 -1
  65. package/dist/src/renderer/lifecycle/index.js +1 -0
  66. package/dist/src/renderer/lifecycle/index.js.map +1 -1
  67. package/dist/src/renderer-types.d.ts +1 -1
  68. package/dist/src/renderer-types.d.ts.map +1 -1
  69. package/dist/src/renderer.d.ts.map +1 -1
  70. package/dist/src/renderer.js +4 -14
  71. package/dist/src/renderer.js.map +1 -1
  72. package/dist/src/test/render-tui.d.ts.map +1 -1
  73. package/dist/src/test/render-tui.js +1 -0
  74. package/dist/src/test/render-tui.js.map +1 -1
  75. package/dist/src/utils/alignment.d.ts +4 -0
  76. package/dist/src/utils/alignment.d.ts.map +1 -1
  77. package/dist/src/utils/alignment.js +12 -0
  78. package/dist/src/utils/alignment.js.map +1 -1
  79. package/dist/src/utils/index.d.ts +3 -2
  80. package/dist/src/utils/index.d.ts.map +1 -1
  81. package/dist/src/utils/index.js +3 -2
  82. package/dist/src/utils/index.js.map +1 -1
  83. package/dist/src/utils/styles.d.ts +6 -1
  84. package/dist/src/utils/styles.d.ts.map +1 -1
  85. package/dist/src/utils/styles.js +9 -0
  86. package/dist/src/utils/styles.js.map +1 -1
  87. package/dist/src/utils/text-wrap.d.ts +10 -0
  88. package/dist/src/utils/text-wrap.d.ts.map +1 -0
  89. package/dist/src/utils/text-wrap.js +64 -0
  90. package/dist/src/utils/text-wrap.js.map +1 -0
  91. package/dist/tsconfig.tsbuildinfo +1 -1
  92. package/jsx-runtime.ts +1 -2
  93. package/package.json +2 -2
  94. package/src/components/Markdown.tsx +7 -7
  95. package/src/components/MultilineTextInput.tsx +14 -0
  96. package/src/components/TextInput.tsx +18 -0
  97. package/src/hosts/base.ts +35 -0
  98. package/src/hosts/box.ts +7 -8
  99. package/src/hosts/canvas.ts +5 -3
  100. package/src/hosts/codeblock.ts +5 -4
  101. package/src/hosts/flex-container.ts +5 -7
  102. package/src/hosts/index.ts +1 -4
  103. package/src/hosts/overlay-item.ts +2 -2
  104. package/src/hosts/overlay.ts +6 -12
  105. package/src/hosts/scroll.ts +34 -24
  106. package/src/hosts/spacer.ts +1 -3
  107. package/src/hosts/text.ts +89 -256
  108. package/src/hosts/zstack.ts +4 -11
  109. package/src/reconciler/types.ts +3 -0
  110. package/src/renderer/core/FrameBuilder.ts +3 -0
  111. package/src/renderer/input/InputProcessor.ts +5 -2
  112. package/src/renderer/lifecycle/RenderCache.ts +13 -0
  113. package/src/renderer/lifecycle/index.ts +1 -0
  114. package/src/renderer-types.ts +1 -1
  115. package/src/renderer.ts +6 -22
  116. package/src/test/render-tui.ts +1 -0
  117. package/src/utils/alignment.ts +18 -0
  118. package/src/utils/index.ts +3 -1
  119. package/src/utils/styles.ts +18 -1
  120. package/src/utils/text-wrap.ts +66 -0
@@ -2,7 +2,8 @@
2
2
  * Style utilities for building palette-compatible style objects.
3
3
  */
4
4
 
5
- import { type Color, type ColorValue, type Palette, parseColor, type StyleSpec } from "@effect-tui/core"
5
+ import type { CellBuffer, Color, ColorValue, Palette, StyleSpec } from "@effect-tui/core"
6
+ import { parseColor } from "@effect-tui/core"
6
7
 
7
8
  export interface StyleOptions {
8
9
  fg?: ColorValue
@@ -64,6 +65,7 @@ export function resolveBgStyle(palette: Palette, bg?: Color): { value?: ColorVal
64
65
 
65
66
  import { getInheritedBg } from "../hosts/base.js"
66
67
  import type { HostInstance } from "../reconciler/types.js"
68
+ import type { Rect } from "../reconciler/types.js"
67
69
 
68
70
  /**
69
71
  * Resolve background style, inheriting from parent if not explicitly set.
@@ -77,3 +79,18 @@ export function resolveInheritedBgStyle(
77
79
  const bg = explicitBg ?? getInheritedBg(parent)
78
80
  return resolveBgStyle(palette, bg)
79
81
  }
82
+
83
+ /**
84
+ * Fill a rect with background color, inheriting from parent if needed.
85
+ */
86
+ export function fillRectWithInheritedBg(
87
+ buffer: CellBuffer,
88
+ palette: Palette,
89
+ rect: Rect,
90
+ explicitBg: Color | undefined,
91
+ parent: HostInstance | null,
92
+ ): void {
93
+ if (rect.w <= 0 || rect.h <= 0) return
94
+ const { styleId } = resolveInheritedBgStyle(palette, explicitBg, parent)
95
+ buffer.fillRect(rect.x, rect.y, rect.w, rect.h, " ".codePointAt(0)!, styleId)
96
+ }
@@ -0,0 +1,66 @@
1
+ import { displayWidth } from "@effect-tui/core"
2
+
3
+ type SpanLike = { text: string }
4
+
5
+ /**
6
+ * Wrap spans into lines, breaking at word boundaries.
7
+ * Preserves span styling by cloning span objects with updated text.
8
+ */
9
+ export function wrapSpans<T extends SpanLike>(spans: T[], maxWidth: number): T[][] {
10
+ const lines: T[][] = [[]]
11
+ let lineWidth = 0
12
+
13
+ for (const span of spans) {
14
+ // Split span text into words (keeping whitespace as separate tokens)
15
+ const tokens = span.text.split(/(\s+)/)
16
+
17
+ for (const token of tokens) {
18
+ if (!token) continue
19
+ const tokenWidth = displayWidth(token)
20
+ const isWhitespace = /^\s+$/.test(token)
21
+
22
+ if (lineWidth + tokenWidth <= maxWidth) {
23
+ // Token fits on current line
24
+ lines[lines.length - 1].push({ ...span, text: token })
25
+ lineWidth += tokenWidth
26
+ } else if (isWhitespace) {
27
+ // Skip whitespace at line break
28
+ continue
29
+ } else if (tokenWidth <= maxWidth) {
30
+ // Start new line with this token
31
+ lines.push([{ ...span, text: token }])
32
+ lineWidth = tokenWidth
33
+ } else {
34
+ // Token is longer than maxWidth - break by character
35
+ let charLine = ""
36
+ let charLineWidth = 0
37
+ for (const ch of token) {
38
+ const chWidth = displayWidth(ch)
39
+ if (lineWidth + charLineWidth + chWidth > maxWidth && (charLine || lineWidth > 0)) {
40
+ if (charLine) {
41
+ lines[lines.length - 1].push({ ...span, text: charLine })
42
+ }
43
+ lines.push([])
44
+ lineWidth = 0
45
+ charLine = ch
46
+ charLineWidth = chWidth
47
+ } else {
48
+ charLine += ch
49
+ charLineWidth += chWidth
50
+ }
51
+ }
52
+ if (charLine) {
53
+ lines[lines.length - 1].push({ ...span, text: charLine })
54
+ lineWidth += charLineWidth
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ // Remove empty lines at the end
61
+ while (lines.length > 0 && lines[lines.length - 1].length === 0) {
62
+ lines.pop()
63
+ }
64
+
65
+ return lines.length > 0 ? lines : [[]]
66
+ }