@textui/widgets 0.6.1 → 0.8.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/dist/chart/line-chart.d.ts.map +1 -1
- package/dist/chart/line-chart.js +3 -2
- package/dist/control/select.d.ts.map +1 -1
- package/dist/control/select.js +4 -2
- package/dist/control/switch.d.ts.map +1 -1
- package/dist/control/switch.js +7 -2
- package/dist/control/text-area.d.ts +2 -0
- package/dist/control/text-area.d.ts.map +1 -1
- package/dist/control/text-area.js +16 -8
- package/dist/data/code-viewer.d.ts +2 -0
- package/dist/data/code-viewer.d.ts.map +1 -1
- package/dist/data/code-viewer.js +9 -1
- package/dist/data/index.d.ts +9 -0
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js +11 -4
- package/dist/data/list.d.ts +9 -0
- package/dist/data/list.d.ts.map +1 -1
- package/dist/data/list.js +23 -5
- package/dist/data/log-viewer.d.ts.map +1 -1
- package/dist/data/log-viewer.js +7 -2
- package/dist/data/markdown-view.d.ts.map +1 -1
- package/dist/data/markdown-view.js +6 -2
- package/dist/data/pagination.d.ts.map +1 -1
- package/dist/data/pagination.js +6 -2
- package/dist/data/tree.d.ts +2 -0
- package/dist/data/tree.d.ts.map +1 -1
- package/dist/data/tree.js +8 -2
- package/dist/display/card.d.ts.map +1 -1
- package/dist/display/card.js +12 -0
- package/dist/display/color-text.d.ts +13 -1
- package/dist/display/color-text.d.ts.map +1 -1
- package/dist/display/color-text.js +28 -6
- package/dist/display/error-state.d.ts.map +1 -1
- package/dist/display/error-state.js +4 -3
- package/dist/display/font-text.d.ts +72 -0
- package/dist/display/font-text.d.ts.map +1 -0
- package/dist/display/font-text.js +35 -0
- package/dist/display/fonts.d.ts +138 -0
- package/dist/display/fonts.d.ts.map +1 -0
- package/dist/display/fonts.js +893 -0
- package/dist/display/gard.d.ts +26 -0
- package/dist/display/gard.d.ts.map +1 -0
- package/dist/display/gard.js +479 -0
- package/dist/display/index.d.ts +3 -0
- package/dist/display/index.d.ts.map +1 -1
- package/dist/display/index.js +7 -0
- package/dist/display/key-value.d.ts +25 -5
- package/dist/display/key-value.d.ts.map +1 -1
- package/dist/display/key-value.js +13 -3
- package/dist/display/pagga.d.ts +29 -0
- package/dist/display/pagga.d.ts.map +1 -0
- package/dist/display/pagga.js +101 -0
- package/dist/display/pattern.d.ts +117 -0
- package/dist/display/pattern.d.ts.map +1 -0
- package/dist/display/pattern.js +257 -0
- package/dist/display/spinner.d.ts +2 -0
- package/dist/display/spinner.d.ts.map +1 -1
- package/dist/display/spinner.js +3 -2
- package/dist/form/danger-zone.d.ts.map +1 -1
- package/dist/form/danger-zone.js +7 -3
- package/dist/form/form-actions.d.ts.map +1 -1
- package/dist/form/form-actions.js +3 -2
- package/dist/navigation/menu.d.ts +2 -0
- package/dist/navigation/menu.d.ts.map +1 -1
- package/dist/navigation/menu.js +22 -8
- package/dist/navigation/tabs.d.ts +2 -0
- package/dist/navigation/tabs.d.ts.map +1 -1
- package/dist/navigation/tabs.js +12 -2
- package/dist/overlay/command-palette.d.ts.map +1 -1
- package/dist/overlay/command-palette.js +55 -15
- package/dist/overlay/dialog.d.ts +11 -0
- package/dist/overlay/dialog.d.ts.map +1 -1
- package/dist/overlay/dialog.js +24 -1
- package/dist/overlay/index.d.ts.map +1 -1
- package/dist/overlay/index.js +11 -19
- package/dist/overlay/path-picker.d.ts.map +1 -1
- package/dist/overlay/path-picker.js +19 -11
- package/dist/overlay/prompt-dialog.d.ts.map +1 -1
- package/dist/overlay/prompt-dialog.js +5 -4
- package/dist/panel/index.d.ts.map +1 -1
- package/dist/panel/index.js +8 -7
- package/dist/panel/resource-panel.d.ts.map +1 -1
- package/dist/panel/resource-panel.js +9 -5
- package/dist/surface/mount-view.d.ts.map +1 -1
- package/dist/surface/mount-view.js +3 -2
- package/package.json +2 -2
- package/src/chart/line-chart.ts +3 -2
- package/src/control/select.ts +4 -2
- package/src/control/switch.ts +9 -2
- package/src/control/text-area.ts +18 -7
- package/src/data/code-viewer.ts +10 -1
- package/src/data/index.ts +12 -3
- package/src/data/list.ts +24 -4
- package/src/data/log-viewer.ts +7 -1
- package/src/data/markdown-view.ts +10 -1
- package/src/data/pagination.ts +6 -2
- package/src/data/tree.ts +9 -2
- package/src/display/card.ts +12 -0
- package/src/display/color-text.ts +33 -10
- package/src/display/error-state.ts +4 -3
- package/src/display/font-text.tsx +94 -0
- package/src/display/fonts.ts +990 -0
- package/src/display/gard.ts +475 -0
- package/src/display/index.ts +7 -0
- package/src/display/key-value.ts +44 -6
- package/src/display/pagga.ts +102 -0
- package/src/display/pattern.tsx +427 -0
- package/src/display/spinner.ts +5 -2
- package/src/form/danger-zone.ts +7 -3
- package/src/form/form-actions.ts +5 -2
- package/src/navigation/menu.ts +23 -8
- package/src/navigation/tabs.ts +13 -2
- package/src/overlay/command-palette.ts +66 -14
- package/src/overlay/dialog.ts +37 -1
- package/src/overlay/index.ts +11 -19
- package/src/overlay/path-picker.ts +23 -10
- package/src/overlay/prompt-dialog.ts +5 -4
- package/src/panel/index.ts +9 -7
- package/src/panel/resource-panel.ts +9 -4
- package/src/surface/mount-view.ts +3 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { BoxProps } from '@textui/core';
|
|
2
|
+
import { defineComponent, h, useCapabilities, useMeasure, useTheme } from '@textui/core';
|
|
3
|
+
import { banner, DEFAULT_FONT, fontAt, inkGlyphs } from './fonts.js';
|
|
4
|
+
import type { Font } from './fonts.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `wrap` is not `BoxProps.wrap`.
|
|
8
|
+
*
|
|
9
|
+
* On a `text` it means where a line of *characters* is cut, and the whole point
|
|
10
|
+
* of this component is that the block it draws is not a line of characters: its
|
|
11
|
+
* rows are the rows of the letters, so cutting one at column sixty cuts every
|
|
12
|
+
* letter in it in half. `wrap` here means the one thing that can be done
|
|
13
|
+
* instead - break the *text* between its words, measured in the font - and it
|
|
14
|
+
* has no `char`, because a banner broken mid-word is not a banner. The drawn
|
|
15
|
+
* rows are handed to the `text` node as `wrap: 'none'` always; a caller cannot
|
|
16
|
+
* reach that.
|
|
17
|
+
*/
|
|
18
|
+
export interface FontTextProps extends Omit<BoxProps, 'wrap'> {
|
|
19
|
+
/** The text to draw. A newline is a line, and each is a line of banner. */
|
|
20
|
+
content: string;
|
|
21
|
+
/**
|
|
22
|
+
* The font to draw it in. The shipped `block` table by default.
|
|
23
|
+
*
|
|
24
|
+
* A font may name a substitute for a terminal that cannot draw its glyphs -
|
|
25
|
+
* `fallback` - and that is used here in place of it. There is no guessing one
|
|
26
|
+
* for a table the library has never seen, which is why the font says.
|
|
27
|
+
*/
|
|
28
|
+
font?: Font;
|
|
29
|
+
/**
|
|
30
|
+
* Break the text between its words so the drawn banner fits the box.
|
|
31
|
+
*
|
|
32
|
+
* `'none'` - the default - draws the text as it was written, however wide
|
|
33
|
+
* that is: a banner is usually a size somebody picked, and at a width the
|
|
34
|
+
* caller did not intend, letters that reflow are worse than letters that
|
|
35
|
+
* overflow. `'word'` asks the box for its width and breaks the text to it,
|
|
36
|
+
* words first and a word too wide for a line of its own spent a character at
|
|
37
|
+
* a time, which is the only place a letter boundary is ever crossed.
|
|
38
|
+
*
|
|
39
|
+
* It measures the box, so the first frame - which has no width yet - draws
|
|
40
|
+
* one unbroken line, exactly as `'none'` would.
|
|
41
|
+
*/
|
|
42
|
+
wrap?: 'none' | 'word';
|
|
43
|
+
/**
|
|
44
|
+
* Blank rows between one line of the block and the next. One by default.
|
|
45
|
+
*
|
|
46
|
+
* Not `gap`, which every box already has and means the space between its
|
|
47
|
+
* *children*: this is the space between the rows of one drawing. `0` butts
|
|
48
|
+
* the lines together, which for a font with a ground of its own - `pagga`'s
|
|
49
|
+
* `░`, `tmplt`'s rules - merges them into one texture; a larger number is air
|
|
50
|
+
* between them, and reads as two lines rather than as one.
|
|
51
|
+
*
|
|
52
|
+
* A newline in `content` is a line, and so is a wrap when `wrap: 'word'` is
|
|
53
|
+
* breaking the text: the gap is the same one either way.
|
|
54
|
+
*/
|
|
55
|
+
lineGap?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Text as block letters.
|
|
60
|
+
*
|
|
61
|
+
* The shape only: a string in, the same string drawn in the font's glyphs out,
|
|
62
|
+
* as a `text` node that inherits its colour like any other. Colouring the
|
|
63
|
+
* letters cell by cell - a ramp across a banner, a palette down it - is
|
|
64
|
+
* [`ColorText`](color-text.md), and handing it this output is the pair the two
|
|
65
|
+
* were split for.
|
|
66
|
+
*
|
|
67
|
+
* The letters are laid out by [`banner`](fonts.ts), which measures in the font
|
|
68
|
+
* rather than in cells, so the tracking is the font's and a glyph is
|
|
69
|
+
* proportional to what it actually draws. A character the font has no glyph for
|
|
70
|
+
* becomes a word space, so a missing letter shows as a gap rather than quietly
|
|
71
|
+
* closing up, and the placeholders a table is written in - `#`, `%`, `^`, `v` -
|
|
72
|
+
* are filled from the theme's own glyphs, which is what keeps a banner legible
|
|
73
|
+
* on a terminal that can only do ascii.
|
|
74
|
+
*/
|
|
75
|
+
export const FontText = defineComponent<FontTextProps>('FontText', (props) => {
|
|
76
|
+
const theme = useTheme();
|
|
77
|
+
const capabilities = useCapabilities();
|
|
78
|
+
const measured = useMeasure();
|
|
79
|
+
const { content, font: chosen, wrap, lineGap, ...rest } = props;
|
|
80
|
+
|
|
81
|
+
const unicode = capabilities.unicode !== 'ascii';
|
|
82
|
+
const picked = chosen ?? DEFAULT_FONT;
|
|
83
|
+
const font = !unicode && picked.fallback ? fontAt(picked.fallback) : picked;
|
|
84
|
+
const width = wrap === 'word' ? measured.width : undefined;
|
|
85
|
+
const drawn = banner(
|
|
86
|
+
content, font, inkGlyphs(theme.glyphs, unicode), width ?? Number.POSITIVE_INFINITY, lineGap,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// `wrap: 'none'` *after* the spread, so the lines `banner` decided on are the
|
|
90
|
+
// lines drawn. Every one of them is a row of letters; a text node wrapping
|
|
91
|
+
// one cuts letters in half, and a caller who passed a `TextWrap` through
|
|
92
|
+
// `...rest` would be doing exactly that.
|
|
93
|
+
return h('text', { content: drawn, ...rest, wrap: 'none' });
|
|
94
|
+
});
|