@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,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
+ });