@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.
- package/README.md +11 -7
- package/dist/jsx-runtime.d.ts +1 -2
- package/dist/jsx-runtime.d.ts.map +1 -1
- package/dist/src/components/Markdown.js +7 -7
- package/dist/src/components/Markdown.js.map +1 -1
- package/dist/src/components/MultilineTextInput.d.ts.map +1 -1
- package/dist/src/components/MultilineTextInput.js +11 -0
- package/dist/src/components/MultilineTextInput.js.map +1 -1
- package/dist/src/components/TextInput.d.ts.map +1 -1
- package/dist/src/components/TextInput.js +15 -0
- package/dist/src/components/TextInput.js.map +1 -1
- package/dist/src/hosts/base.d.ts +16 -0
- package/dist/src/hosts/base.d.ts.map +1 -1
- package/dist/src/hosts/base.js +30 -0
- package/dist/src/hosts/base.js.map +1 -1
- package/dist/src/hosts/box.d.ts.map +1 -1
- package/dist/src/hosts/box.js +7 -8
- package/dist/src/hosts/box.js.map +1 -1
- package/dist/src/hosts/canvas.d.ts.map +1 -1
- package/dist/src/hosts/canvas.js +5 -3
- package/dist/src/hosts/canvas.js.map +1 -1
- package/dist/src/hosts/codeblock.d.ts.map +1 -1
- package/dist/src/hosts/codeblock.js +5 -4
- package/dist/src/hosts/codeblock.js.map +1 -1
- package/dist/src/hosts/flex-container.d.ts.map +1 -1
- package/dist/src/hosts/flex-container.js +5 -8
- package/dist/src/hosts/flex-container.js.map +1 -1
- package/dist/src/hosts/index.d.ts +1 -1
- package/dist/src/hosts/index.d.ts.map +1 -1
- package/dist/src/hosts/index.js +2 -3
- package/dist/src/hosts/index.js.map +1 -1
- package/dist/src/hosts/overlay-item.js +2 -2
- package/dist/src/hosts/overlay-item.js.map +1 -1
- package/dist/src/hosts/overlay.d.ts.map +1 -1
- package/dist/src/hosts/overlay.js +6 -11
- package/dist/src/hosts/overlay.js.map +1 -1
- package/dist/src/hosts/scroll.d.ts +4 -0
- package/dist/src/hosts/scroll.d.ts.map +1 -1
- package/dist/src/hosts/scroll.js +32 -24
- package/dist/src/hosts/scroll.js.map +1 -1
- package/dist/src/hosts/spacer.d.ts.map +1 -1
- package/dist/src/hosts/spacer.js +1 -3
- package/dist/src/hosts/spacer.js.map +1 -1
- package/dist/src/hosts/text.d.ts +24 -45
- package/dist/src/hosts/text.d.ts.map +1 -1
- package/dist/src/hosts/text.js +69 -215
- package/dist/src/hosts/text.js.map +1 -1
- package/dist/src/hosts/zstack.d.ts.map +1 -1
- package/dist/src/hosts/zstack.js +4 -10
- package/dist/src/hosts/zstack.js.map +1 -1
- package/dist/src/reconciler/types.d.ts +2 -0
- package/dist/src/reconciler/types.d.ts.map +1 -1
- package/dist/src/renderer/core/FrameBuilder.d.ts.map +1 -1
- package/dist/src/renderer/core/FrameBuilder.js +2 -0
- package/dist/src/renderer/core/FrameBuilder.js.map +1 -1
- package/dist/src/renderer/input/InputProcessor.d.ts.map +1 -1
- package/dist/src/renderer/input/InputProcessor.js +5 -2
- package/dist/src/renderer/input/InputProcessor.js.map +1 -1
- package/dist/src/renderer/lifecycle/RenderCache.d.ts +3 -0
- package/dist/src/renderer/lifecycle/RenderCache.d.ts.map +1 -0
- package/dist/src/renderer/lifecycle/RenderCache.js +9 -0
- package/dist/src/renderer/lifecycle/RenderCache.js.map +1 -0
- package/dist/src/renderer/lifecycle/index.d.ts +1 -0
- package/dist/src/renderer/lifecycle/index.d.ts.map +1 -1
- package/dist/src/renderer/lifecycle/index.js +1 -0
- package/dist/src/renderer/lifecycle/index.js.map +1 -1
- package/dist/src/renderer-types.d.ts +1 -1
- package/dist/src/renderer-types.d.ts.map +1 -1
- package/dist/src/renderer.d.ts.map +1 -1
- package/dist/src/renderer.js +4 -14
- package/dist/src/renderer.js.map +1 -1
- package/dist/src/test/render-tui.d.ts.map +1 -1
- package/dist/src/test/render-tui.js +1 -0
- package/dist/src/test/render-tui.js.map +1 -1
- package/dist/src/utils/alignment.d.ts +4 -0
- package/dist/src/utils/alignment.d.ts.map +1 -1
- package/dist/src/utils/alignment.js +12 -0
- package/dist/src/utils/alignment.js.map +1 -1
- package/dist/src/utils/index.d.ts +3 -2
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +3 -2
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/styles.d.ts +6 -1
- package/dist/src/utils/styles.d.ts.map +1 -1
- package/dist/src/utils/styles.js +9 -0
- package/dist/src/utils/styles.js.map +1 -1
- package/dist/src/utils/text-wrap.d.ts +10 -0
- package/dist/src/utils/text-wrap.d.ts.map +1 -0
- package/dist/src/utils/text-wrap.js +64 -0
- package/dist/src/utils/text-wrap.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jsx-runtime.ts +1 -2
- package/package.json +2 -2
- package/src/components/Markdown.tsx +7 -7
- package/src/components/MultilineTextInput.tsx +14 -0
- package/src/components/TextInput.tsx +18 -0
- package/src/hosts/base.ts +35 -0
- package/src/hosts/box.ts +7 -8
- package/src/hosts/canvas.ts +5 -3
- package/src/hosts/codeblock.ts +5 -4
- package/src/hosts/flex-container.ts +5 -7
- package/src/hosts/index.ts +1 -4
- package/src/hosts/overlay-item.ts +2 -2
- package/src/hosts/overlay.ts +6 -12
- package/src/hosts/scroll.ts +34 -24
- package/src/hosts/spacer.ts +1 -3
- package/src/hosts/text.ts +89 -256
- package/src/hosts/zstack.ts +4 -11
- package/src/reconciler/types.ts +3 -0
- package/src/renderer/core/FrameBuilder.ts +3 -0
- package/src/renderer/input/InputProcessor.ts +5 -2
- package/src/renderer/lifecycle/RenderCache.ts +13 -0
- package/src/renderer/lifecycle/index.ts +1 -0
- package/src/renderer-types.ts +1 -1
- package/src/renderer.ts +6 -22
- package/src/test/render-tui.ts +1 -0
- package/src/utils/alignment.ts +18 -0
- package/src/utils/index.ts +3 -1
- package/src/utils/styles.ts +18 -1
- package/src/utils/text-wrap.ts +66 -0
package/src/utils/styles.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Style utilities for building palette-compatible style objects.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
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
|
+
}
|