@bigpixelrocket/uiok 0.4.0 → 0.6.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 (122) hide show
  1. package/CHANGELOG.md +63 -1
  2. package/dist/button/TextLink.d.ts +26 -3
  3. package/dist/button/TextLink.js +5 -3
  4. package/dist/button/button.css +7 -0
  5. package/dist/dialog/ModalDialog.js +8 -2
  6. package/dist/dialog/SectionedDialog.d.ts +37 -0
  7. package/dist/dialog/SectionedDialog.js +157 -0
  8. package/dist/dialog/dialog.css +102 -0
  9. package/dist/dialog/index.d.ts +4 -2
  10. package/dist/dialog/index.js +4 -2
  11. package/dist/frame/AppRoot.d.ts +1 -1
  12. package/dist/frame/AppRoot.js +2 -1
  13. package/dist/frame/Dock.d.ts +1 -1
  14. package/dist/frame/Dock.js +2 -1
  15. package/dist/frame/FilterChips.d.ts +5 -2
  16. package/dist/frame/FilterChips.js +35 -2
  17. package/dist/frame/FilterChips.logic.d.ts +24 -0
  18. package/dist/frame/FilterChips.logic.js +34 -0
  19. package/dist/frame/PageParts.d.ts +4 -3
  20. package/dist/frame/PageParts.js +10 -3
  21. package/dist/frame/SideBySide.d.ts +32 -0
  22. package/dist/frame/SideBySide.js +50 -0
  23. package/dist/frame/Tree.d.ts +9 -3
  24. package/dist/frame/Tree.js +8 -5
  25. package/dist/frame/WindowFrame.d.ts +1 -1
  26. package/dist/frame/WindowFrame.js +3 -1
  27. package/dist/frame/frame.css +74 -5
  28. package/dist/frame/index.d.ts +4 -2
  29. package/dist/frame/index.js +4 -2
  30. package/dist/grid/grid.css +1 -0
  31. package/dist/icon/ProductMark.d.ts +57 -0
  32. package/dist/icon/ProductMark.js +26 -0
  33. package/dist/icon/icon.css +53 -0
  34. package/dist/icon/index.d.ts +3 -1
  35. package/dist/icon/index.js +3 -1
  36. package/dist/keyboard/Keyboard.logic.js +20 -3
  37. package/dist/keychord/KeyChord.d.ts +17 -1
  38. package/dist/keychord/KeyChord.js +16 -1
  39. package/dist/keychord/ShortcutIndex.d.ts +49 -0
  40. package/dist/keychord/ShortcutIndex.js +28 -0
  41. package/dist/keychord/index.d.ts +8 -2
  42. package/dist/keychord/index.js +8 -2
  43. package/dist/keychord/keychord.css +101 -0
  44. package/dist/labels/dialog.d.ts +2 -0
  45. package/dist/labels/dialog.js +2 -1
  46. package/dist/labels/keys.d.ts +5 -0
  47. package/dist/labels/keys.js +2 -1
  48. package/dist/labels/settings.d.ts +6 -0
  49. package/dist/labels/settings.js +1 -0
  50. package/dist/listing/Listing.d.ts +95 -7
  51. package/dist/listing/Listing.js +57 -13
  52. package/dist/listing/ListingScope.d.ts +7 -0
  53. package/dist/listing/ListingScope.js +8 -0
  54. package/dist/listing/PaneMessage.d.ts +7 -4
  55. package/dist/listing/PaneMessage.js +11 -4
  56. package/dist/listing/Timeline.d.ts +51 -0
  57. package/dist/listing/Timeline.js +28 -0
  58. package/dist/listing/index.d.ts +4 -2
  59. package/dist/listing/index.js +3 -1
  60. package/dist/listing/listing.css +268 -25
  61. package/dist/log/Ansi.logic.d.ts +27 -0
  62. package/dist/log/Ansi.logic.js +203 -0
  63. package/dist/log/LogWell.d.ts +11 -2
  64. package/dist/log/LogWell.js +15 -3
  65. package/dist/log/index.d.ts +1 -0
  66. package/dist/log/index.js +1 -0
  67. package/dist/log/log.css +80 -0
  68. package/dist/menu/Menu.d.ts +133 -0
  69. package/dist/menu/Menu.js +351 -0
  70. package/dist/menu/Menu.logic.d.ts +83 -0
  71. package/dist/menu/Menu.logic.js +92 -0
  72. package/dist/menu/index.d.ts +6 -1
  73. package/dist/menu/index.js +6 -1
  74. package/dist/menu/menu.css +57 -0
  75. package/dist/palette/Palette.d.ts +3 -2
  76. package/dist/palette/Palette.js +8 -4
  77. package/dist/palette/PaletteRows.d.ts +138 -0
  78. package/dist/palette/PaletteRows.js +76 -0
  79. package/dist/palette/index.d.ts +5 -2
  80. package/dist/palette/index.js +5 -2
  81. package/dist/pane/Pane.d.ts +42 -6
  82. package/dist/pane/Pane.js +92 -5
  83. package/dist/pane/PaneFrame.d.ts +22 -1
  84. package/dist/pane/PaneFrame.js +42 -5
  85. package/dist/pane/PaneKeys.d.ts +5 -1
  86. package/dist/pane/PaneKeys.js +28 -3
  87. package/dist/pane/PaneKeys.logic.d.ts +25 -0
  88. package/dist/pane/PaneKeys.logic.js +30 -0
  89. package/dist/pane/index.d.ts +2 -2
  90. package/dist/pane/index.js +1 -1
  91. package/dist/pane/usePaneKeys.d.ts +8 -1
  92. package/dist/pane/usePaneKeys.js +32 -12
  93. package/dist/shell/SettingsDialog.d.ts +20 -2
  94. package/dist/shell/SettingsDialog.js +13 -3
  95. package/dist/shell/index.d.ts +1 -1
  96. package/dist/styles.css +18 -3
  97. package/dist/surface/FactList.d.ts +54 -0
  98. package/dist/surface/FactList.js +33 -0
  99. package/dist/surface/FactTable.d.ts +44 -0
  100. package/dist/surface/FactTable.js +33 -0
  101. package/dist/surface/index.d.ts +7 -2
  102. package/dist/surface/index.js +7 -2
  103. package/dist/surface/surface.css +139 -2
  104. package/dist/tabs/PageTabs.d.ts +6 -0
  105. package/dist/tabs/PageTabs.js +1 -1
  106. package/dist/tabs/tabs.css +14 -0
  107. package/dist/terminal/TerminalBox.d.ts +30 -0
  108. package/dist/terminal/TerminalBox.js +17 -0
  109. package/dist/terminal/ghostty/core.d.ts +12 -4
  110. package/dist/terminal/ghostty/core.js +12 -4
  111. package/dist/terminal/index.d.ts +6 -2
  112. package/dist/terminal/index.js +6 -2
  113. package/dist/terminal/terminal.css +29 -0
  114. package/dist/text/Code.d.ts +15 -0
  115. package/dist/text/Code.js +12 -0
  116. package/dist/text/index.d.ts +6 -1
  117. package/dist/text/index.js +6 -1
  118. package/dist/text/text.css +21 -0
  119. package/dist/themes/themes.generated.css +20 -0
  120. package/dist/themes/tokens.d.ts +1 -0
  121. package/dist/themes/tokens.js +16 -2
  122. package/package.json +1 -1
@@ -0,0 +1,203 @@
1
+ /** The eight ANSI colours by name, in SGR order (30–37, 40–47; 90–97 and 100–107 are the same names). */
2
+ export const ANSI_COLOURS = [
3
+ 'black',
4
+ 'red',
5
+ 'green',
6
+ 'yellow',
7
+ 'blue',
8
+ 'magenta',
9
+ 'cyan',
10
+ 'white'
11
+ ];
12
+ const ESC = 0x1b;
13
+ const BEL = 0x07;
14
+ /** The 8-bit string terminator (ST), the one-byte form of `ESC \`. */
15
+ const ST = 0x9c;
16
+ /** The 8-bit CSI, the one-byte form of `ESC [`. */
17
+ const CSI = 0x9b;
18
+ /** The 8-bit control-string introducers: DCS, SOS, OSC, PM, APC (`ESC P`, `X`, `]`, `^`, `_`). */
19
+ const STRING_INTRODUCERS = new Set([0x90, 0x98, 0x9d, 0x9e, 0x9f]);
20
+ /** Where a sequence or a control may start: `ESC`, or any 8-bit control (C1). */
21
+ // The escape and the 8-bit controls are what the pattern exists to find.
22
+ // eslint-disable-next-line no-control-regex
23
+ const CONTROL = /[\u001b\u0080-\u009f]/g;
24
+ /** Whether `code` lies in the inclusive byte range `low`–`high`. */
25
+ function within(code, low, high) {
26
+ return code >= low && code <= high;
27
+ }
28
+ /** Index of the first byte at or after `from` that is not in `low`–`high`. */
29
+ function skipRange(text, from, low, high) {
30
+ let at = from;
31
+ while (at < text.length && within(text.charCodeAt(at), low, high))
32
+ at += 1;
33
+ return at;
34
+ }
35
+ /**
36
+ * The end of a control string (OSC, DCS, SOS, PM, APC) whose payload starts
37
+ * at `from`: past its BEL or ST (`ESC \` or the 8-bit ST), at an escape
38
+ * that starts the next sequence, or at the end of the text when it never
39
+ * ends. Any other byte, an 8-bit control included, is payload (SOS may
40
+ * carry anything but SOS and ST), so none of it shows.
41
+ */
42
+ function controlStringEnd(text, from) {
43
+ for (let at = from; at < text.length; at += 1) {
44
+ const code = text.charCodeAt(at);
45
+ if (code === BEL || code === ST)
46
+ return at + 1;
47
+ if (code === ESC)
48
+ return text.charCodeAt(at + 1) === 0x5c ? at + 2 : at;
49
+ }
50
+ return text.length;
51
+ }
52
+ /**
53
+ * Reads the sequence starting at the `ESC` or 8-bit control at `start`,
54
+ * after ECMA-48: a CSI (`ESC [` or its 8-bit form, parameter bytes `0`–`?`,
55
+ * intermediate bytes space–`/`, a final byte `@`–`~`); an OSC (`ESC ]`) or
56
+ * DCS, SOS, PM, or APC (`ESC P`, `X`, `^`, `_`), or their 8-bit forms, a
57
+ * string to BEL or ST; any other escape (intermediates then one final
58
+ * byte); or a lone 8-bit control, dropped alone. A sequence cut off by the end of the text runs to
59
+ * the end; one broken by a control byte ends before it, so the `ESC` never
60
+ * shows. Only a CSI ending in `m`, with no intermediate and no private
61
+ * marker (`<`, `=`, `>`, `?`), is an SGR.
62
+ */
63
+ function readEscape(text, start) {
64
+ const lead = text.charCodeAt(start);
65
+ // The 8-bit forms: a CSI, a control string, or a lone control.
66
+ if (lead === CSI)
67
+ return readCsi(text, start + 1);
68
+ if (STRING_INTRODUCERS.has(lead))
69
+ return { end: controlStringEnd(text, start + 1) };
70
+ if (lead !== ESC)
71
+ return { end: start + 1 };
72
+ const kind = text.charCodeAt(start + 1);
73
+ if (kind === 0x5b)
74
+ return readCsi(text, start + 2);
75
+ if (kind === 0x5d || kind === 0x50 || kind === 0x58 || kind === 0x5e || kind === 0x5f) {
76
+ return { end: controlStringEnd(text, start + 2) };
77
+ }
78
+ const intermediatesEnd = skipRange(text, start + 1, 0x20, 0x2f);
79
+ if (intermediatesEnd >= text.length)
80
+ return { end: text.length };
81
+ return within(text.charCodeAt(intermediatesEnd), 0x30, 0x7e)
82
+ ? { end: intermediatesEnd + 1 }
83
+ : { end: intermediatesEnd };
84
+ }
85
+ /** Reads a CSI whose parameters start at `from` (after `ESC [` or the 8-bit CSI). */
86
+ function readCsi(text, from) {
87
+ const parametersEnd = skipRange(text, from, 0x30, 0x3f);
88
+ const intermediatesEnd = skipRange(text, parametersEnd, 0x20, 0x2f);
89
+ if (intermediatesEnd >= text.length)
90
+ return { end: text.length };
91
+ const final = text.charCodeAt(intermediatesEnd);
92
+ if (!within(final, 0x40, 0x7e))
93
+ return { end: intermediatesEnd };
94
+ const parameters = text.slice(from, parametersEnd);
95
+ const sgr = final === 0x6d && intermediatesEnd === parametersEnd && !/[<=>?]/.test(parameters)
96
+ ? parameters
97
+ : undefined;
98
+ return sgr === undefined ? { end: intermediatesEnd + 1 } : { end: intermediatesEnd + 1, sgr };
99
+ }
100
+ /**
101
+ * Applies one SGR's parameters to `style`. Parameters split on `;`; a
102
+ * group joined by `:` is one parameter with subparameters (`4:3` is a
103
+ * curly underline, `4:0` underline off, `38:2::r:g:b` a colour). Extended colours (38, 48, and
104
+ * the underline colour 58) name no ANSI colour, so each is skipped whole,
105
+ * in either form; any other colon group but underline's is ignored.
106
+ */
107
+ function applySgr(style, parameters) {
108
+ const groups = parameters.split(';');
109
+ let next = { ...style };
110
+ for (let index = 0; index < groups.length; index += 1) {
111
+ const group = groups[index] ?? '';
112
+ if (group.includes(':')) {
113
+ const [main, kind] = group.split(':', 2).map((part) => Number(part || 0));
114
+ if (main === 4 && kind === 0)
115
+ next.underline = false;
116
+ else if (main === 4 && kind !== undefined && kind >= 1 && kind <= 5)
117
+ next.underline = true;
118
+ continue;
119
+ }
120
+ const code = Number(group || 0);
121
+ if (code === 38 || code === 48 || code === 58) {
122
+ // 38;5;n or 38;2;r;g;b: the colour is the theme's to choose, so it is skipped whole.
123
+ // The mode is a number, so `02` is `2`.
124
+ const mode = Number(groups[index + 1] ?? '');
125
+ index += mode === 5 ? 2 : mode === 2 ? 4 : 1;
126
+ continue;
127
+ }
128
+ if (code === 0)
129
+ next = {};
130
+ else if (code === 1)
131
+ next.bold = true;
132
+ else if (code === 2)
133
+ next.dim = true;
134
+ else if (code === 3)
135
+ next.italic = true;
136
+ else if (code === 4)
137
+ next.underline = true;
138
+ else if (code === 7)
139
+ next.inverse = true;
140
+ else if (code === 22)
141
+ next = { ...next, bold: false, dim: false };
142
+ else if (code === 23)
143
+ next.italic = false;
144
+ else if (code === 24)
145
+ next.underline = false;
146
+ else if (code === 27)
147
+ next.inverse = false;
148
+ else if (code === 39)
149
+ delete next.fg;
150
+ else if (code === 49)
151
+ delete next.bg;
152
+ else if ((code >= 30 && code <= 37) || (code >= 90 && code <= 97)) {
153
+ next.fg = ANSI_COLOURS[code % 10];
154
+ }
155
+ else if ((code >= 40 && code <= 47) || (code >= 100 && code <= 107)) {
156
+ next.bg = ANSI_COLOURS[code % 10];
157
+ }
158
+ }
159
+ return next;
160
+ }
161
+ /** A segment of `text` in `style`, with inverse turned into a filled run and unset flags left out. */
162
+ function segment(text, style) {
163
+ const fg = style.inverse ? style.bg : style.fg;
164
+ const bg = style.inverse ? (style.fg ?? 'white') : style.bg;
165
+ return {
166
+ text,
167
+ ...(fg === undefined ? {} : { fg }),
168
+ ...(bg === undefined ? {} : { bg }),
169
+ ...(style.bold === true ? { bold: true } : {}),
170
+ ...(style.dim === true ? { dim: true } : {}),
171
+ ...(style.italic === true ? { italic: true } : {}),
172
+ ...(style.underline === true ? { underline: true } : {})
173
+ };
174
+ }
175
+ /**
176
+ * A log line's text as runs of one style each, read from its SGR escape
177
+ * sequences: the eight colours and their bright forms (as the same name),
178
+ * backgrounds, bold, dim, italic, underline, and inverse, each reset as
179
+ * SGR resets it, in the 7-bit form (`ESC [`) or the 8-bit one. Extended
180
+ * colours (256 and true colour) are skipped, and every other escape
181
+ * sequence, control string, 8-bit control, and cut-off escape is dropped, so the runs hold printable text alone. A line with no escape is
182
+ * one plain run. Linear in the text's length, and pure: the text is never
183
+ * read as markup.
184
+ */
185
+ export function ansiSegments(text) {
186
+ const segments = [];
187
+ let style = {};
188
+ let at = 0;
189
+ while (at < text.length) {
190
+ CONTROL.lastIndex = at;
191
+ const escape = CONTROL.exec(text)?.index ?? -1;
192
+ const textEnd = escape === -1 ? text.length : escape;
193
+ if (textEnd > at)
194
+ segments.push(segment(text.slice(at, textEnd), style));
195
+ if (escape === -1)
196
+ break;
197
+ const read = readEscape(text, escape);
198
+ if (read.sgr !== undefined)
199
+ style = applySgr(style, read.sgr);
200
+ at = read.end;
201
+ }
202
+ return segments;
203
+ }
@@ -21,6 +21,13 @@ export interface LogWellProps {
21
21
  readonly follow?: boolean;
22
22
  /** The words shown while the log has no line. */
23
23
  readonly empty?: string;
24
+ /**
25
+ * Reads the SGR escape sequences in each line whose text is a string
26
+ * (`ansiSegments`): its colours, backgrounds, bold, dim, italic, and
27
+ * underline, drawn in the theme's text tones; every other escape
28
+ * sequence is dropped. Off, a string is drawn as written.
29
+ */
30
+ readonly ansi?: boolean;
24
31
  }
25
32
  /**
26
33
  * A log in a well: each line in the code face, its source first in a
@@ -29,6 +36,8 @@ export interface LogWellProps {
29
36
  * host marks takes its tone. The words can be selected and copied. With
30
37
  * `follow`, a new line scrolls into view while the reader is at the foot.
31
38
  * It is a `log` region, so a screen reader hears new lines without being
32
- * moved; it takes the focus so the keys scroll it.
39
+ * moved; it takes the focus so the keys scroll it. With `ansi`, a line's
40
+ * SGR colours and weights are drawn in the theme's text tones, its other
41
+ * escape sequences dropped.
33
42
  */
34
- export declare function LogWell({ lines, label, sources, follow, empty }: LogWellProps): ReactElement;
43
+ export declare function LogWell({ lines, label, sources, follow, empty, ansi }: LogWellProps): ReactElement;
@@ -1,6 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useLayoutEffect, useRef } from 'react';
3
+ import { ansiSegments } from './Ansi.logic.js';
3
4
  import { logSourceColour, logSourceIndexes, logSourceWidth } from './LogWell.logic.js';
5
+ /** A line's text as styled runs, each colour painted by log.css from its data attributes. */
6
+ function AnsiText({ text }) {
7
+ return ansiSegments(text).map((run, index) => run.fg === undefined &&
8
+ run.bg === undefined &&
9
+ run.bold === undefined &&
10
+ run.dim === undefined &&
11
+ run.italic === undefined &&
12
+ run.underline === undefined ? (run.text) : (_jsx("span", { className: "log-ansi", "data-bg": run.bg, "data-bold": run.bold || undefined, "data-dim": run.dim || undefined, "data-fg": run.fg, "data-italic": run.italic || undefined, "data-underline": run.underline || undefined, children: run.text }, index)));
13
+ }
4
14
  /** How near the foot, in pixels, still counts as reading the newest line. */
5
15
  const FOOT_SLACK = 8;
6
16
  /**
@@ -10,9 +20,11 @@ const FOOT_SLACK = 8;
10
20
  * host marks takes its tone. The words can be selected and copied. With
11
21
  * `follow`, a new line scrolls into view while the reader is at the foot.
12
22
  * It is a `log` region, so a screen reader hears new lines without being
13
- * moved; it takes the focus so the keys scroll it.
23
+ * moved; it takes the focus so the keys scroll it. With `ansi`, a line's
24
+ * SGR colours and weights are drawn in the theme's text tones, its other
25
+ * escape sequences dropped.
14
26
  */
15
- export function LogWell({ lines, label, sources = [], follow = true, empty }) {
27
+ export function LogWell({ lines, label, sources = [], follow = true, empty, ansi = false }) {
16
28
  const well = useRef(null);
17
29
  const atFoot = useRef(true);
18
30
  const names = lines.map((line) => line.source);
@@ -34,6 +46,6 @@ export function LogWell({ lines, label, sources = [], follow = true, empty }) {
34
46
  const index = source === null ? undefined : indexes.get(source);
35
47
  return (_jsxs("div", { className: "log-line", "data-tone": line.tone, children: [width > 0 ? (_jsx("span", { className: "log-source", style: index === undefined
36
48
  ? undefined
37
- : { '--log-source': logSourceColour(index) }, children: source })) : null, width > 0 ? (_jsx("span", { "aria-hidden": true, className: "log-bar", children: "|" })) : null, _jsx("span", { className: "log-text", children: line.text })] }, line.key));
49
+ : { '--log-source': logSourceColour(index) }, children: source })) : null, width > 0 ? (_jsx("span", { "aria-hidden": true, className: "log-bar", children: "|" })) : null, _jsx("span", { className: "log-text", children: ansi && typeof line.text === 'string' ? _jsx(AnsiText, { text: line.text }) : line.text })] }, line.key));
38
50
  })] }));
39
51
  }
@@ -4,5 +4,6 @@
4
4
  * (`logSourceIndexes`, `logSourceColour`, `logSourceWidth`). Its look is
5
5
  * `log.css` in `@bigpixelrocket/uiok/styles.css`.
6
6
  */
7
+ export { ANSI_COLOURS, ansiSegments, type AnsiColour, type AnsiSegment } from './Ansi.logic.js';
7
8
  export { LogWell, type LogLine, type LogWellProps } from './LogWell.js';
8
9
  export { LOG_SOURCE_COLOURS, logSourceColour, logSourceIndexes, logSourceWidth } from './LogWell.logic.js';
package/dist/log/index.js CHANGED
@@ -4,5 +4,6 @@
4
4
  * (`logSourceIndexes`, `logSourceColour`, `logSourceWidth`). Its look is
5
5
  * `log.css` in `@bigpixelrocket/uiok/styles.css`.
6
6
  */
7
+ export { ANSI_COLOURS, ansiSegments } from './Ansi.logic.js';
7
8
  export { LogWell } from './LogWell.js';
8
9
  export { LOG_SOURCE_COLOURS, logSourceColour, logSourceIndexes, logSourceWidth } from './LogWell.logic.js';
package/dist/log/log.css CHANGED
@@ -55,3 +55,83 @@
55
55
  color: var(--text-dim);
56
56
  font-family: var(--font-ui);
57
57
  }
58
+
59
+ /* A line's SGR styling (LogWell's `ansi`): each ANSI colour drawn in the
60
+ theme's text tone nearest its meaning, each legible on the well, never
61
+ the terminal's own palette, which is tuned for the terminal's ground. A
62
+ background is a filled run in the tone's solid fill and its on-colour,
63
+ as a badge is. Black and white take the text's own two tones. */
64
+ .log-ansi[data-fg='black'] {
65
+ color: var(--text-dim);
66
+ }
67
+
68
+ .log-ansi[data-fg='red'] {
69
+ color: var(--danger-text);
70
+ }
71
+
72
+ .log-ansi[data-fg='green'] {
73
+ color: var(--success-text);
74
+ }
75
+
76
+ .log-ansi[data-fg='yellow'] {
77
+ color: var(--warning-text);
78
+ }
79
+
80
+ .log-ansi[data-fg='blue'] {
81
+ color: var(--accent-text);
82
+ }
83
+
84
+ .log-ansi[data-fg='magenta'] {
85
+ color: var(--log-source-2);
86
+ }
87
+
88
+ .log-ansi[data-fg='cyan'] {
89
+ color: var(--log-source-5);
90
+ }
91
+
92
+ .log-ansi[data-fg='white'] {
93
+ color: var(--text);
94
+ }
95
+
96
+ .log-ansi[data-bg] {
97
+ padding-inline: var(--space-1);
98
+ border-radius: var(--radius-xs);
99
+ background: var(--fill);
100
+ color: var(--text);
101
+ }
102
+
103
+ .log-ansi[data-bg='red'] {
104
+ background: var(--danger);
105
+ color: var(--on-danger);
106
+ }
107
+
108
+ .log-ansi[data-bg='green'] {
109
+ background: var(--success);
110
+ color: var(--on-success);
111
+ }
112
+
113
+ .log-ansi[data-bg='yellow'] {
114
+ background: var(--warning);
115
+ color: var(--on-warning);
116
+ }
117
+
118
+ .log-ansi:is([data-bg='blue'], [data-bg='magenta'], [data-bg='cyan']) {
119
+ background: var(--accent);
120
+ color: var(--on-accent);
121
+ }
122
+
123
+ .log-ansi[data-bold] {
124
+ font-weight: var(--font-weight-strong);
125
+ }
126
+
127
+ .log-ansi[data-dim]:not([data-bg]) {
128
+ color: var(--text-dim);
129
+ }
130
+
131
+ .log-ansi[data-italic] {
132
+ font-style: italic;
133
+ }
134
+
135
+ .log-ansi[data-underline] {
136
+ text-decoration: underline;
137
+ }
@@ -0,0 +1,133 @@
1
+ import type { LucideIcon } from 'lucide-react';
2
+ import { type ReactElement, type ReactNode } from 'react';
3
+ import type { Chord } from '../keyboard/Keyboard.logic.js';
4
+ import { type MenuPoint } from './Menu.logic.js';
5
+ /** An item of a menu: a verb that runs, or a place to go. */
6
+ export interface MenuItemEntry {
7
+ readonly kind?: 'item';
8
+ /** Names the item to `onPick`; unique in the menu. */
9
+ readonly id: string;
10
+ /** The verb or the place, in words: "Open in Terminal", "17 · 17.7". */
11
+ readonly label: string;
12
+ /** A lucide glyph in the icon column. */
13
+ readonly icon?: LucideIcon;
14
+ /** Anything else in the icon column (a `ProductMark`, a state dot), when `icon` is absent. */
15
+ readonly mark?: ReactNode;
16
+ /** The chord that runs the same verb, drawn as key caps at the row's end. */
17
+ readonly chord?: Chord;
18
+ /** A destructive verb (Delete, Remove): the danger tone, its glyph with it. */
19
+ readonly danger?: boolean;
20
+ /** Listed but not runnable now: dimmed and passed over by the keys. Say why in `tip`. */
21
+ readonly disabled?: boolean;
22
+ /**
23
+ * A setting the item turns on and off: true draws the check mark in the
24
+ * icon column (`menuitemcheckbox`); absent, it is a plain item.
25
+ */
26
+ readonly checked?: boolean;
27
+ /** Marks the current one (the place shown), with what current means as the dot's name: "Shown". */
28
+ readonly current?: string | null;
29
+ /** More about the item, or why it is disabled: its tooltip and description. */
30
+ readonly tip?: string;
31
+ }
32
+ /** A hairline between groups of items that need no name. */
33
+ export interface MenuSeparatorEntry {
34
+ readonly kind: 'separator';
35
+ }
36
+ /** A group's name over its items. */
37
+ export interface MenuHeadingEntry {
38
+ readonly kind: 'heading';
39
+ readonly label: string;
40
+ }
41
+ /**
42
+ * An item that opens a submenu beside it ("Copy As", opening Path and File
43
+ * URL): its glyph and words, and a chevron at its end in place of a chord.
44
+ * It runs nothing itself; its submenu's items do.
45
+ */
46
+ export interface MenuSubmenuEntry {
47
+ readonly kind: 'submenu';
48
+ /** Names the item; unique in the menu, its submenus' items included. Never passed to `onPick`. */
49
+ readonly id: string;
50
+ /** The submenu's name, in words: "Copy As", "Open With". */
51
+ readonly label: string;
52
+ /** A lucide glyph in the icon column. */
53
+ readonly icon?: LucideIcon;
54
+ /** Anything else in the icon column, when `icon` is absent. */
55
+ readonly mark?: ReactNode;
56
+ /** Listed but not openable now: dimmed and passed over by the keys. Say why in `tip`. */
57
+ readonly disabled?: boolean;
58
+ /** More about the item, or why it is disabled: its tooltip and description. */
59
+ readonly tip?: string;
60
+ /** The submenu's entries, in order: items, separators, and headings, never another submenu. */
61
+ readonly entries: readonly MenuLeafEntry[];
62
+ }
63
+ /** An entry a submenu can hold: any but another submenu, so a menu nests one level deep. */
64
+ export type MenuLeafEntry = MenuItemEntry | MenuSeparatorEntry | MenuHeadingEntry;
65
+ /** One entry of a menu, in order. */
66
+ export type MenuEntry = MenuLeafEntry | MenuSubmenuEntry;
67
+ /** Props for {@link Menu}. */
68
+ export interface MenuProps {
69
+ /** The menu's accessible name: "Actions", "Other versions". */
70
+ readonly label: string;
71
+ /** Its entries, in order. */
72
+ readonly entries: readonly MenuEntry[];
73
+ /** Opens it at a point in window coordinates (a secondary click). */
74
+ readonly at?: MenuPoint;
75
+ /**
76
+ * Drops it from an element (a crumb, a button), under its leading edge.
77
+ * Presses on the element do not close the menu, so the element can
78
+ * toggle it. Used when `at` is absent.
79
+ */
80
+ readonly anchor?: HTMLElement | null;
81
+ /**
82
+ * The item the cursor starts on (the current one), in the menu itself,
83
+ * not a submenu; the first that can run when absent.
84
+ */
85
+ readonly initial?: string | null;
86
+ /** The small size, for a menu of short commands (`.folder-menu-compact`). */
87
+ readonly compact?: boolean;
88
+ /**
89
+ * The direction it reads in, which its keys, a submenu's side, and the
90
+ * chevron follow; when absent, the direction of `anchor`, or of the place
91
+ * it is rendered in, as it opens (the document body it is drawn on may
92
+ * read the other way).
93
+ */
94
+ readonly dir?: 'ltr' | 'rtl';
95
+ /** Runs an item that can run, by its id, a submenu's items included; the caller closes the menu. */
96
+ readonly onPick: (id: string) => void;
97
+ /**
98
+ * Closes the menu, saying how it was dismissed: by a key in it (Escape,
99
+ * Tab), after which the caller puts the focus back where it was, or by a
100
+ * press or a focus elsewhere, which has its own destination.
101
+ */
102
+ readonly onClose: (by: 'keyboard' | 'pointer') => void;
103
+ }
104
+ /**
105
+ * A menu of verbs or places, opened at a point (a secondary click's) or
106
+ * dropped from an element (a crumb's ⌄, an Actions button): each item its
107
+ * glyph, its words, and its chord as key caps; a destructive one in the
108
+ * danger tone; a setting with its check; the current place with its dot;
109
+ * separators and group headings between them; and items that open a
110
+ * submenu beside them, one level deep. It is the menu look
111
+ * (`.folder-menu`) drawn through a portal on the document's body (or the
112
+ * element shown full screen), so no pane or dialog clips it, placed inside
113
+ * the window (`placeMenu`); React still carries its events to its owner.
114
+ *
115
+ * It takes the focus and holds the keys while open (`menuKeyAction`: ↑ ↓,
116
+ * Home, End, Return and Space, → and ←, Escape and Tab), which travel no
117
+ * further, so neither a dialog nor the page hears them; `data-native-keyboard`
118
+ * keeps the browser-key guard and a page's own key handlers out
119
+ * (`isNativeKeyboardTarget`), and `data-overlay` marks it an open overlay
120
+ * while it shows. A press on it never takes the focus from it; a press or
121
+ * a focus anywhere else closes it. A menu taller than the window less its
122
+ * margins scrolls, and the keys keep the cursor's item in view.
123
+ *
124
+ * A submenu opens beside its item (on the inline-end side, or the other
125
+ * when the window has no room there) when the pointer rests on the item or
126
+ * presses it, showing without the keys, or with the keys and its cursor on
127
+ * its first item that can run on → (← in a right-to-left page), Return,
128
+ * or Space. ← goes back to its item, and Escape closes the submenu alone;
129
+ * Tab closes the whole menu. The pointer crossing other items on its way
130
+ * into the submenu leaves it open for a moment, and moving over the
131
+ * submenu gives it the keys.
132
+ */
133
+ export declare function Menu({ label, entries, at, anchor, initial, compact, dir: dirGiven, onPick, onClose }: MenuProps): ReactElement;