@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.
Files changed (120) hide show
  1. package/dist/chart/line-chart.d.ts.map +1 -1
  2. package/dist/chart/line-chart.js +3 -2
  3. package/dist/control/select.d.ts.map +1 -1
  4. package/dist/control/select.js +4 -2
  5. package/dist/control/switch.d.ts.map +1 -1
  6. package/dist/control/switch.js +7 -2
  7. package/dist/control/text-area.d.ts +2 -0
  8. package/dist/control/text-area.d.ts.map +1 -1
  9. package/dist/control/text-area.js +16 -8
  10. package/dist/data/code-viewer.d.ts +2 -0
  11. package/dist/data/code-viewer.d.ts.map +1 -1
  12. package/dist/data/code-viewer.js +9 -1
  13. package/dist/data/index.d.ts +9 -0
  14. package/dist/data/index.d.ts.map +1 -1
  15. package/dist/data/index.js +11 -4
  16. package/dist/data/list.d.ts +9 -0
  17. package/dist/data/list.d.ts.map +1 -1
  18. package/dist/data/list.js +23 -5
  19. package/dist/data/log-viewer.d.ts.map +1 -1
  20. package/dist/data/log-viewer.js +7 -2
  21. package/dist/data/markdown-view.d.ts.map +1 -1
  22. package/dist/data/markdown-view.js +6 -2
  23. package/dist/data/pagination.d.ts.map +1 -1
  24. package/dist/data/pagination.js +6 -2
  25. package/dist/data/tree.d.ts +2 -0
  26. package/dist/data/tree.d.ts.map +1 -1
  27. package/dist/data/tree.js +8 -2
  28. package/dist/display/card.d.ts.map +1 -1
  29. package/dist/display/card.js +12 -0
  30. package/dist/display/color-text.d.ts +13 -1
  31. package/dist/display/color-text.d.ts.map +1 -1
  32. package/dist/display/color-text.js +28 -6
  33. package/dist/display/error-state.d.ts.map +1 -1
  34. package/dist/display/error-state.js +4 -3
  35. package/dist/display/font-text.d.ts +72 -0
  36. package/dist/display/font-text.d.ts.map +1 -0
  37. package/dist/display/font-text.js +35 -0
  38. package/dist/display/fonts.d.ts +138 -0
  39. package/dist/display/fonts.d.ts.map +1 -0
  40. package/dist/display/fonts.js +893 -0
  41. package/dist/display/gard.d.ts +26 -0
  42. package/dist/display/gard.d.ts.map +1 -0
  43. package/dist/display/gard.js +479 -0
  44. package/dist/display/index.d.ts +3 -0
  45. package/dist/display/index.d.ts.map +1 -1
  46. package/dist/display/index.js +7 -0
  47. package/dist/display/key-value.d.ts +25 -5
  48. package/dist/display/key-value.d.ts.map +1 -1
  49. package/dist/display/key-value.js +13 -3
  50. package/dist/display/pagga.d.ts +29 -0
  51. package/dist/display/pagga.d.ts.map +1 -0
  52. package/dist/display/pagga.js +101 -0
  53. package/dist/display/pattern.d.ts +117 -0
  54. package/dist/display/pattern.d.ts.map +1 -0
  55. package/dist/display/pattern.js +257 -0
  56. package/dist/display/spinner.d.ts +2 -0
  57. package/dist/display/spinner.d.ts.map +1 -1
  58. package/dist/display/spinner.js +3 -2
  59. package/dist/form/danger-zone.d.ts.map +1 -1
  60. package/dist/form/danger-zone.js +7 -3
  61. package/dist/form/form-actions.d.ts.map +1 -1
  62. package/dist/form/form-actions.js +3 -2
  63. package/dist/navigation/menu.d.ts +2 -0
  64. package/dist/navigation/menu.d.ts.map +1 -1
  65. package/dist/navigation/menu.js +22 -8
  66. package/dist/navigation/tabs.d.ts +2 -0
  67. package/dist/navigation/tabs.d.ts.map +1 -1
  68. package/dist/navigation/tabs.js +12 -2
  69. package/dist/overlay/command-palette.d.ts.map +1 -1
  70. package/dist/overlay/command-palette.js +55 -15
  71. package/dist/overlay/dialog.d.ts +11 -0
  72. package/dist/overlay/dialog.d.ts.map +1 -1
  73. package/dist/overlay/dialog.js +24 -1
  74. package/dist/overlay/index.d.ts.map +1 -1
  75. package/dist/overlay/index.js +11 -19
  76. package/dist/overlay/path-picker.d.ts.map +1 -1
  77. package/dist/overlay/path-picker.js +19 -11
  78. package/dist/overlay/prompt-dialog.d.ts.map +1 -1
  79. package/dist/overlay/prompt-dialog.js +5 -4
  80. package/dist/panel/index.d.ts.map +1 -1
  81. package/dist/panel/index.js +8 -7
  82. package/dist/panel/resource-panel.d.ts.map +1 -1
  83. package/dist/panel/resource-panel.js +9 -5
  84. package/dist/surface/mount-view.d.ts.map +1 -1
  85. package/dist/surface/mount-view.js +3 -2
  86. package/package.json +2 -2
  87. package/src/chart/line-chart.ts +3 -2
  88. package/src/control/select.ts +4 -2
  89. package/src/control/switch.ts +9 -2
  90. package/src/control/text-area.ts +18 -7
  91. package/src/data/code-viewer.ts +10 -1
  92. package/src/data/index.ts +12 -3
  93. package/src/data/list.ts +24 -4
  94. package/src/data/log-viewer.ts +7 -1
  95. package/src/data/markdown-view.ts +10 -1
  96. package/src/data/pagination.ts +6 -2
  97. package/src/data/tree.ts +9 -2
  98. package/src/display/card.ts +12 -0
  99. package/src/display/color-text.ts +33 -10
  100. package/src/display/error-state.ts +4 -3
  101. package/src/display/font-text.tsx +94 -0
  102. package/src/display/fonts.ts +990 -0
  103. package/src/display/gard.ts +475 -0
  104. package/src/display/index.ts +7 -0
  105. package/src/display/key-value.ts +44 -6
  106. package/src/display/pagga.ts +102 -0
  107. package/src/display/pattern.tsx +427 -0
  108. package/src/display/spinner.ts +5 -2
  109. package/src/form/danger-zone.ts +7 -3
  110. package/src/form/form-actions.ts +5 -2
  111. package/src/navigation/menu.ts +23 -8
  112. package/src/navigation/tabs.ts +13 -2
  113. package/src/overlay/command-palette.ts +66 -14
  114. package/src/overlay/dialog.ts +37 -1
  115. package/src/overlay/index.ts +11 -19
  116. package/src/overlay/path-picker.ts +23 -10
  117. package/src/overlay/prompt-dialog.ts +5 -4
  118. package/src/panel/index.ts +9 -7
  119. package/src/panel/resource-panel.ts +9 -4
  120. package/src/surface/mount-view.ts +3 -2
@@ -0,0 +1,72 @@
1
+ import type { BoxProps } from '@textui/core';
2
+ import type { Font } from './fonts.js';
3
+ /**
4
+ * `wrap` is not `BoxProps.wrap`.
5
+ *
6
+ * On a `text` it means where a line of *characters* is cut, and the whole point
7
+ * of this component is that the block it draws is not a line of characters: its
8
+ * rows are the rows of the letters, so cutting one at column sixty cuts every
9
+ * letter in it in half. `wrap` here means the one thing that can be done
10
+ * instead - break the *text* between its words, measured in the font - and it
11
+ * has no `char`, because a banner broken mid-word is not a banner. The drawn
12
+ * rows are handed to the `text` node as `wrap: 'none'` always; a caller cannot
13
+ * reach that.
14
+ */
15
+ export interface FontTextProps extends Omit<BoxProps, 'wrap'> {
16
+ /** The text to draw. A newline is a line, and each is a line of banner. */
17
+ content: string;
18
+ /**
19
+ * The font to draw it in. The shipped `block` table by default.
20
+ *
21
+ * A font may name a substitute for a terminal that cannot draw its glyphs -
22
+ * `fallback` - and that is used here in place of it. There is no guessing one
23
+ * for a table the library has never seen, which is why the font says.
24
+ */
25
+ font?: Font;
26
+ /**
27
+ * Break the text between its words so the drawn banner fits the box.
28
+ *
29
+ * `'none'` - the default - draws the text as it was written, however wide
30
+ * that is: a banner is usually a size somebody picked, and at a width the
31
+ * caller did not intend, letters that reflow are worse than letters that
32
+ * overflow. `'word'` asks the box for its width and breaks the text to it,
33
+ * words first and a word too wide for a line of its own spent a character at
34
+ * a time, which is the only place a letter boundary is ever crossed.
35
+ *
36
+ * It measures the box, so the first frame - which has no width yet - draws
37
+ * one unbroken line, exactly as `'none'` would.
38
+ */
39
+ wrap?: 'none' | 'word';
40
+ /**
41
+ * Blank rows between one line of the block and the next. One by default.
42
+ *
43
+ * Not `gap`, which every box already has and means the space between its
44
+ * *children*: this is the space between the rows of one drawing. `0` butts
45
+ * the lines together, which for a font with a ground of its own - `pagga`'s
46
+ * `░`, `tmplt`'s rules - merges them into one texture; a larger number is air
47
+ * between them, and reads as two lines rather than as one.
48
+ *
49
+ * A newline in `content` is a line, and so is a wrap when `wrap: 'word'` is
50
+ * breaking the text: the gap is the same one either way.
51
+ */
52
+ lineGap?: number;
53
+ }
54
+ /**
55
+ * Text as block letters.
56
+ *
57
+ * The shape only: a string in, the same string drawn in the font's glyphs out,
58
+ * as a `text` node that inherits its colour like any other. Colouring the
59
+ * letters cell by cell - a ramp across a banner, a palette down it - is
60
+ * [`ColorText`](color-text.md), and handing it this output is the pair the two
61
+ * were split for.
62
+ *
63
+ * The letters are laid out by [`banner`](fonts.ts), which measures in the font
64
+ * rather than in cells, so the tracking is the font's and a glyph is
65
+ * proportional to what it actually draws. A character the font has no glyph for
66
+ * becomes a word space, so a missing letter shows as a gap rather than quietly
67
+ * closing up, and the placeholders a table is written in - `#`, `%`, `^`, `v` -
68
+ * are filled from the theme's own glyphs, which is what keeps a banner legible
69
+ * on a terminal that can only do ascii.
70
+ */
71
+ export declare const FontText: (props: FontTextProps) => import("@textui/core").RenderOutput;
72
+ //# sourceMappingURL=font-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"font-text.d.ts","sourceRoot":"","sources":["../../src/display/font-text.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3D,2EAA2E;IAC3E,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,+DAmBnB,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { defineComponent, h, useCapabilities, useMeasure, useTheme } from '@textui/core';
2
+ import { banner, DEFAULT_FONT, fontAt, inkGlyphs } from './fonts.js';
3
+ /**
4
+ * Text as block letters.
5
+ *
6
+ * The shape only: a string in, the same string drawn in the font's glyphs out,
7
+ * as a `text` node that inherits its colour like any other. Colouring the
8
+ * letters cell by cell - a ramp across a banner, a palette down it - is
9
+ * [`ColorText`](color-text.md), and handing it this output is the pair the two
10
+ * were split for.
11
+ *
12
+ * The letters are laid out by [`banner`](fonts.ts), which measures in the font
13
+ * rather than in cells, so the tracking is the font's and a glyph is
14
+ * proportional to what it actually draws. A character the font has no glyph for
15
+ * becomes a word space, so a missing letter shows as a gap rather than quietly
16
+ * closing up, and the placeholders a table is written in - `#`, `%`, `^`, `v` -
17
+ * are filled from the theme's own glyphs, which is what keeps a banner legible
18
+ * on a terminal that can only do ascii.
19
+ */
20
+ export const FontText = defineComponent('FontText', (props) => {
21
+ const theme = useTheme();
22
+ const capabilities = useCapabilities();
23
+ const measured = useMeasure();
24
+ const { content, font: chosen, wrap, lineGap, ...rest } = props;
25
+ const unicode = capabilities.unicode !== 'ascii';
26
+ const picked = chosen ?? DEFAULT_FONT;
27
+ const font = !unicode && picked.fallback ? fontAt(picked.fallback) : picked;
28
+ const width = wrap === 'word' ? measured.width : undefined;
29
+ const drawn = banner(content, font, inkGlyphs(theme.glyphs, unicode), width ?? Number.POSITIVE_INFINITY, lineGap);
30
+ // `wrap: 'none'` *after* the spread, so the lines `banner` decided on are the
31
+ // lines drawn. Every one of them is a row of letters; a text node wrapping
32
+ // one cuts letters in half, and a caller who passed a `TextWrap` through
33
+ // `...rest` would be doing exactly that.
34
+ return h('text', { content: drawn, ...rest, wrap: 'none' });
35
+ });
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Block fonts, and the engine that draws text in them.
3
+ *
4
+ * A font is data: a table of glyphs, a tracking and a space width. `banner()`
5
+ * lays a string out in one and answers with plain text, which is the shape
6
+ * half only - `ColorText` colours it cell by cell, and the two are deliberately
7
+ * separate, because a banner wants a ramp across it and prose does not.
8
+ * [`FontText`](font-text.tsx) is the one-liner over this: text and a font in,
9
+ * letters out.
10
+ *
11
+ * These ship so that component has something to draw with; the tables are data
12
+ * an application can replace, and `Font` is the whole contract.
13
+ *
14
+ * There is one hand-drawn table and three transforms of it, which is the other
15
+ * thing worth showing: a bitmap font is a grid of characters, and a grid of
16
+ * characters can be sheared, doubled or duplicated by ten lines of code. Every
17
+ * font below has both cases, because the table does.
18
+ *
19
+ * A glyph is a grid of characters. Four of them are placeholders the renderer
20
+ * fills in from the theme - `#` a full cell, `%` a lighter one, `^` the top
21
+ * half of a cell and `v` the bottom half - and every other character is drawn
22
+ * as itself, which is what lets `dots`, `stars` and `mini` be made of dots,
23
+ * stars and pipes rather than of blocks. A space is nothing. Blank columns at
24
+ * either edge are trimmed when a glyph is used, so the letters are
25
+ * proportional rather than a fixed pitch.
26
+ */
27
+ type Grid = string[];
28
+ export interface Font {
29
+ id: string;
30
+ title: string;
31
+ /** What is different about it, for the panel under the list. */
32
+ note: string;
33
+ glyphs: Record<string, Grid>;
34
+ /** Columns between two letters. */
35
+ tracking: number;
36
+ /** Columns a word space takes. */
37
+ space: number;
38
+ /**
39
+ * Two sets of letters, or one.
40
+ *
41
+ * Everything off the five-row table has `both`, because the table does and a
42
+ * transform of it cannot lose a case. `mini` has one set and folds - at three
43
+ * rows there is no room under a cap for an x-height.
44
+ */
45
+ cases: 'both' | 'folded';
46
+ /**
47
+ * Whether this font's glyphs are written in placeholders.
48
+ *
49
+ * The ones off the five-row table are: `#` and `%` and the two halves, filled
50
+ * in from the theme at paint time. The hand-drawn tables are not - they are
51
+ * already what they look like - and it matters, because a literal `#` in one
52
+ * of them would otherwise be swapped for a full block, which is how the
53
+ * character `#` would come out as a solid bar.
54
+ */
55
+ placeholders?: boolean;
56
+ /**
57
+ * Which row of the glyph box the letters sit on.
58
+ *
59
+ * Only needed where it is not the last one: `gard` keeps two blank rows
60
+ * under its baseline for the descenders, so a character drawn on the last
61
+ * row would hang below every letter beside it. Used for the stand-in a
62
+ * missing character gets, which has to land on the line like anything else.
63
+ */
64
+ baseline?: number;
65
+ /**
66
+ * The font to draw instead where this one's characters do not exist.
67
+ *
68
+ * Only `tmplt` needs one. Every other font here is made of placeholders the
69
+ * theme fills in, or of characters a teletype has - box-drawing is neither,
70
+ * and there is no `#` to downgrade a `┏` to. So it names a stand-in of the
71
+ * same height rather than putting a row of question marks on the screen.
72
+ */
73
+ fallback?: string;
74
+ }
75
+ export declare const FONTS: Font[];
76
+ export declare function fontAt(id: string): Font;
77
+ /** The font that is drawn in when a caller names none: the hand-drawn table. */
78
+ export declare const DEFAULT_FONT: Font;
79
+ /** The tallest glyph in a font, which is how many rows a line of it takes. */
80
+ export declare function heightOf(font: Font): number;
81
+ /**
82
+ * The four characters a glyph's placeholders are drawn in.
83
+ *
84
+ * `fill` and `shade` are theme glyphs; the two halves are not, because the
85
+ * theme has no name for half a cell. What they all share is that the *font*
86
+ * names a role and something else decides what the terminal can show - which
87
+ * is the rule the whole catalog follows, and the reason `half` degrades to
88
+ * quotes and underscores instead of putting a row of question marks on the
89
+ * screen that needs the banner most.
90
+ */
91
+ export interface InkGlyphs {
92
+ fill: string;
93
+ shade: string;
94
+ top: string;
95
+ bottom: string;
96
+ }
97
+ export declare function inkGlyphs(glyphs: {
98
+ progressFull: string;
99
+ progressEmpty: string;
100
+ }, unicode?: boolean): InkGlyphs;
101
+ /** What the fonts are drawn in where nothing has said otherwise. */
102
+ export declare const PLAIN_GLYPHS: InkGlyphs;
103
+ /**
104
+ * Text as block letters.
105
+ *
106
+ * Newlines are lines: each one becomes its own block of rows, stacked with
107
+ * `lineGap` blank rows between them so two lines of banner do not read as one.
108
+ * A character with no glyph becomes a word space, so a missing one shows as a
109
+ * gap the reader can see rather than silently closing up.
110
+ */
111
+ export declare function bannerLines(text: string, font: Font, ink?: InkGlyphs, width?: number): string[];
112
+ /**
113
+ * The same banner, one string per line.
114
+ *
115
+ * For a caller that has to place the lines itself, and the case that makes it
116
+ * necessary is centring: a multi-line block is centred once, as a block, so its
117
+ * shorter lines start at the widest line's edge and read as left-aligned. One
118
+ * `ColorText` per line - each `alignBlock` and `textAlign="center"` - centres
119
+ * every line over its own width while keeping the rows of each in step.
120
+ *
121
+ * The catch is the ink: a [`ColorText`](color-text.md) starts its ink at its
122
+ * own first cell, so a block drawn as several pieces restarts a `cycle` (and a
123
+ * `{ gradient }` measures each piece rather than the lot). That is a reason to
124
+ * keep one component for a continuous ramp, and this for centring.
125
+ */
126
+ export declare function banner(text: string, font: Font, ink?: InkGlyphs, width?: number,
127
+ /**
128
+ * Blank rows between one line and the next. One by default.
129
+ *
130
+ * Counts the *empty* rows, so `0` butts two lines together and `2` leaves two
131
+ * rows of air. It applies to every line the block has, wrapped or written -
132
+ * the break between two lines of a sentence is the same break as the one
133
+ * between two paragraphs, which is what makes a wrapped banner read as a
134
+ * block of its own rather than as one long line that ran out of room.
135
+ */
136
+ lineGap?: number): string;
137
+ export {};
138
+ //# sourceMappingURL=fonts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fonts.d.ts","sourceRoot":"","sources":["../../src/display/fonts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH,KAAK,IAAI,GAAG,MAAM,EAAE,CAAC;AAyerB,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7B,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzB;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,KAAK,EAAE,IAAI,EAgHvB,CAAC;AAGF,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAEvC;AAED,gFAAgF;AAChF,eAAO,MAAM,YAAY,EAAE,IAAsB,CAAC;AAElD,8EAA8E;AAC9E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE3C;AAkGD;;;;;;;;;GASG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,EACvD,OAAO,UAAO,GACb,SAAS,CAOX;AAED,oEAAoE;AACpE,eAAO,MAAM,YAAY,EAAE,SAA4D,CAAC;AAExF;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,GAAG,GAAE,SAAwB,EAC7B,KAAK,SAAW,GACf,MAAM,EAAE,CAMV;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,GAAG,GAAE,SAAwB,EAC7B,KAAK,SAAW;AAChB;;;;;;;;GAQG;AACH,OAAO,SAAI,GACV,MAAM,CAGR"}