@bigpixelrocket/uiok 0.0.0-stage → 0.1.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/CHANGELOG.md +38 -0
- package/LICENSE +21 -0
- package/NOTICE +569 -0
- package/README.md +44 -2
- package/dist/VisuallyHidden.d.ts +13 -0
- package/dist/VisuallyHidden.js +13 -0
- package/dist/activity/ActivityBar.d.ts +29 -0
- package/dist/activity/ActivityBar.js +21 -0
- package/dist/activity/activity.css +43 -0
- package/dist/activity/index.d.ts +2 -0
- package/dist/activity/index.js +2 -0
- package/dist/button/Button.d.ts +26 -0
- package/dist/button/Button.js +14 -0
- package/dist/button/IconButton.d.ts +18 -0
- package/dist/button/IconButton.js +14 -0
- package/dist/button/button.css +95 -0
- package/dist/button/index.d.ts +3 -0
- package/dist/button/index.js +3 -0
- package/dist/charts/Drawing.d.ts +27 -0
- package/dist/charts/Drawing.js +117 -0
- package/dist/charts/Drawing.logic.d.ts +2 -0
- package/dist/charts/Drawing.logic.js +22 -0
- package/dist/charts/Line.logic.d.ts +33 -0
- package/dist/charts/Line.logic.js +72 -0
- package/dist/charts/LineChart.d.ts +34 -0
- package/dist/charts/LineChart.js +100 -0
- package/dist/charts/Pie.logic.d.ts +16 -0
- package/dist/charts/Pie.logic.js +28 -0
- package/dist/charts/PieChart.d.ts +20 -0
- package/dist/charts/PieChart.js +16 -0
- package/dist/charts/ResultChart.d.ts +47 -0
- package/dist/charts/ResultChart.js +175 -0
- package/dist/charts/ResultChart.logic.d.ts +42 -0
- package/dist/charts/ResultChart.logic.js +165 -0
- package/dist/charts/Scatter.logic.d.ts +55 -0
- package/dist/charts/Scatter.logic.js +134 -0
- package/dist/charts/ScatterChart.d.ts +36 -0
- package/dist/charts/ScatterChart.js +99 -0
- package/dist/charts/charts.css +310 -0
- package/dist/charts/index.d.ts +14 -0
- package/dist/charts/index.js +11 -0
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +8 -0
- package/dist/clock/index.d.ts +2 -0
- package/dist/clock/index.js +2 -0
- package/dist/clock/useClock.d.ts +14 -0
- package/dist/clock/useClock.js +57 -0
- package/dist/datetime/DateTimePicker.d.ts +50 -0
- package/dist/datetime/DateTimePicker.js +98 -0
- package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
- package/dist/datetime/DateTimePicker.logic.js +103 -0
- package/dist/datetime/datetime.css +115 -0
- package/dist/datetime/index.d.ts +7 -0
- package/dist/datetime/index.js +7 -0
- package/dist/dialog/ConfirmDialog.d.ts +73 -0
- package/dist/dialog/ConfirmDialog.js +30 -0
- package/dist/dialog/DialogLegend.d.ts +21 -0
- package/dist/dialog/DialogLegend.js +28 -0
- package/dist/dialog/DialogLegend.logic.d.ts +145 -0
- package/dist/dialog/DialogLegend.logic.js +71 -0
- package/dist/dialog/ModalDialog.d.ts +101 -0
- package/dist/dialog/ModalDialog.js +184 -0
- package/dist/dialog/dialog.css +283 -0
- package/dist/dialog/index.d.ts +8 -0
- package/dist/dialog/index.js +8 -0
- package/dist/filter/FilterEscape.d.ts +16 -0
- package/dist/filter/FilterEscape.js +15 -0
- package/dist/filter/FilterIcon.d.ts +8 -0
- package/dist/filter/FilterIcon.js +11 -0
- package/dist/filter/filter.css +42 -0
- package/dist/filter/index.d.ts +3 -0
- package/dist/filter/index.js +3 -0
- package/dist/grid/DataGrid.d.ts +149 -0
- package/dist/grid/DataGrid.js +373 -0
- package/dist/grid/DataGrid.logic.d.ts +57 -0
- package/dist/grid/DataGrid.logic.js +121 -0
- package/dist/grid/grid.css +206 -0
- package/dist/grid/index.d.ts +7 -0
- package/dist/grid/index.js +7 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/keyboard/BrowserKeys.d.ts +15 -0
- package/dist/keyboard/BrowserKeys.js +28 -0
- package/dist/keyboard/KeyChord.logic.d.ts +25 -0
- package/dist/keyboard/KeyChord.logic.js +50 -0
- package/dist/keyboard/Keyboard.logic.d.ts +84 -0
- package/dist/keyboard/Keyboard.logic.js +137 -0
- package/dist/keyboard/OverlayWatch.d.ts +28 -0
- package/dist/keyboard/OverlayWatch.js +119 -0
- package/dist/keyboard/PageSelectAll.d.ts +14 -0
- package/dist/keyboard/PageSelectAll.js +22 -0
- package/dist/keyboard/index.d.ts +9 -0
- package/dist/keyboard/index.js +9 -0
- package/dist/keychord/KeyChord.d.ts +16 -0
- package/dist/keychord/KeyChord.js +55 -0
- package/dist/keychord/index.d.ts +2 -0
- package/dist/keychord/index.js +2 -0
- package/dist/keychord/keychord.css +41 -0
- package/dist/labels/UiokLabels.d.ts +41 -0
- package/dist/labels/UiokLabels.js +31 -0
- package/dist/labels/UiokProvider.d.ts +44 -0
- package/dist/labels/UiokProvider.js +54 -0
- package/dist/labels/charts.d.ts +34 -0
- package/dist/labels/charts.js +15 -0
- package/dist/labels/dateTime.d.ts +32 -0
- package/dist/labels/dateTime.js +14 -0
- package/dist/labels/dialog.d.ts +18 -0
- package/dist/labels/dialog.js +6 -0
- package/dist/labels/index.d.ts +13 -0
- package/dist/labels/index.js +13 -0
- package/dist/labels/keys.d.ts +28 -0
- package/dist/labels/keys.js +53 -0
- package/dist/labels/legend.d.ts +21 -0
- package/dist/labels/legend.js +7 -0
- package/dist/labels/listing.d.ts +16 -0
- package/dist/labels/listing.js +8 -0
- package/dist/labels/pager.d.ts +32 -0
- package/dist/labels/pager.js +20 -0
- package/dist/labels/palette.d.ts +17 -0
- package/dist/labels/palette.js +6 -0
- package/dist/labels/selectAll.d.ts +15 -0
- package/dist/labels/selectAll.js +6 -0
- package/dist/labels/terminal.d.ts +25 -0
- package/dist/labels/terminal.js +9 -0
- package/dist/legend/KeyLegend.logic.d.ts +84 -0
- package/dist/legend/KeyLegend.logic.js +109 -0
- package/dist/legend/KeyLegendStrip.d.ts +36 -0
- package/dist/legend/KeyLegendStrip.js +82 -0
- package/dist/legend/index.d.ts +3 -0
- package/dist/legend/index.js +3 -0
- package/dist/legend/legend.css +148 -0
- package/dist/listing/CurrentDot.d.ts +15 -0
- package/dist/listing/CurrentDot.js +13 -0
- package/dist/listing/Listing.d.ts +230 -0
- package/dist/listing/Listing.js +265 -0
- package/dist/listing/PathParts.logic.d.ts +17 -0
- package/dist/listing/PathParts.logic.js +18 -0
- package/dist/listing/index.d.ts +10 -0
- package/dist/listing/index.js +10 -0
- package/dist/listing/listing.css +867 -0
- package/dist/menu/MenuQuery.logic.d.ts +69 -0
- package/dist/menu/MenuQuery.logic.js +75 -0
- package/dist/menu/fuzzyMatch.d.ts +31 -0
- package/dist/menu/fuzzyMatch.js +296 -0
- package/dist/menu/index.d.ts +9 -0
- package/dist/menu/index.js +9 -0
- package/dist/menu/menu.css +203 -0
- package/dist/menu/useBellBeat.d.ts +8 -0
- package/dist/menu/useBellBeat.js +26 -0
- package/dist/namecut/NameCut.d.ts +22 -0
- package/dist/namecut/NameCut.js +28 -0
- package/dist/namecut/NameCut.logic.d.ts +51 -0
- package/dist/namecut/NameCut.logic.js +120 -0
- package/dist/namecut/index.d.ts +3 -0
- package/dist/namecut/index.js +3 -0
- package/dist/namecut/namecut.css +67 -0
- package/dist/pager/Pager.d.ts +37 -0
- package/dist/pager/Pager.js +38 -0
- package/dist/pager/Pager.logic.d.ts +13 -0
- package/dist/pager/Pager.logic.js +63 -0
- package/dist/pager/index.d.ts +7 -0
- package/dist/pager/index.js +7 -0
- package/dist/pager/pager.css +62 -0
- package/dist/palette/Palette.d.ts +79 -0
- package/dist/palette/Palette.js +60 -0
- package/dist/palette/index.d.ts +6 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/palette.css +159 -0
- package/dist/pane/PaneActions.d.ts +104 -0
- package/dist/pane/PaneActions.js +62 -0
- package/dist/pane/PaneFrame.d.ts +51 -0
- package/dist/pane/PaneFrame.js +28 -0
- package/dist/pane/PaneKeys.d.ts +41 -0
- package/dist/pane/PaneKeys.js +104 -0
- package/dist/pane/PaneKeys.logic.d.ts +95 -0
- package/dist/pane/PaneKeys.logic.js +109 -0
- package/dist/pane/index.d.ts +11 -0
- package/dist/pane/index.js +11 -0
- package/dist/pane/usePaneKeys.d.ts +141 -0
- package/dist/pane/usePaneKeys.js +313 -0
- package/dist/run/RunHeader.d.ts +50 -0
- package/dist/run/RunHeader.js +31 -0
- package/dist/run/RunProgress.logic.d.ts +29 -0
- package/dist/run/RunProgress.logic.js +34 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/index.js +3 -0
- package/dist/run/run.css +190 -0
- package/dist/segmented/SegmentedChoice.d.ts +22 -0
- package/dist/segmented/SegmentedChoice.js +31 -0
- package/dist/segmented/index.d.ts +2 -0
- package/dist/segmented/index.js +2 -0
- package/dist/segmented/segmented.css +49 -0
- package/dist/selectall/CheckRange.logic.d.ts +8 -0
- package/dist/selectall/CheckRange.logic.js +23 -0
- package/dist/selectall/SelectAllBar.d.ts +25 -0
- package/dist/selectall/SelectAllBar.js +24 -0
- package/dist/selectall/index.d.ts +7 -0
- package/dist/selectall/index.js +7 -0
- package/dist/selectall/selectall.css +31 -0
- package/dist/store/KeepUnchanged.logic.d.ts +19 -0
- package/dist/store/KeepUnchanged.logic.js +33 -0
- package/dist/store/SameProps.d.ts +15 -0
- package/dist/store/SameProps.js +46 -0
- package/dist/store/ValueStore.d.ts +17 -0
- package/dist/store/ValueStore.js +23 -0
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.js +8 -0
- package/dist/store/useStableHandlers.d.ts +13 -0
- package/dist/store/useStableHandlers.js +22 -0
- package/dist/styles.css +85 -0
- package/dist/tabs/PageTabs.d.ts +38 -0
- package/dist/tabs/PageTabs.js +33 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +2 -0
- package/dist/tabs/tabs.css +64 -0
- package/dist/terminal/Terminal.d.ts +104 -0
- package/dist/terminal/Terminal.js +309 -0
- package/dist/terminal/Terminal.logic.d.ts +66 -0
- package/dist/terminal/Terminal.logic.js +156 -0
- package/dist/terminal/TerminalMenu.d.ts +36 -0
- package/dist/terminal/TerminalMenu.js +87 -0
- package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
- package/dist/terminal/TerminalMenu.logic.js +68 -0
- package/dist/terminal/TerminalScrollback.d.ts +10 -0
- package/dist/terminal/TerminalScrollback.js +11 -0
- package/dist/terminal/ghostty/LICENSE +21 -0
- package/dist/terminal/ghostty/core.d.ts +315 -0
- package/dist/terminal/ghostty/core.js +1189 -0
- package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
- package/dist/terminal/ghostty/fallbackColors.js +23 -0
- package/dist/terminal/ghostty/fonts/LICENSE +21 -0
- package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
- package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
- package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
- package/dist/terminal/ghostty/links.logic.d.ts +39 -0
- package/dist/terminal/ghostty/links.logic.js +84 -0
- package/dist/terminal/ghostty/renderer.d.ts +98 -0
- package/dist/terminal/ghostty/renderer.js +481 -0
- package/dist/terminal/ghostty/runtime.d.ts +126 -0
- package/dist/terminal/ghostty/runtime.js +346 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
- package/dist/terminal/ghostty/surface.d.ts +285 -0
- package/dist/terminal/ghostty/surface.js +1565 -0
- package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
- package/dist/terminal/ghostty/surface.logic.js +392 -0
- package/dist/terminal/ghostty/vendor/LICENSE +21 -0
- package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
- package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
- package/dist/terminal/index.d.ts +12 -0
- package/dist/terminal/index.js +12 -0
- package/dist/terminal/terminal.css +169 -0
- package/dist/text/MarkedText.d.ts +14 -0
- package/dist/text/MarkedText.js +11 -0
- package/dist/text/highlightSegments.d.ts +13 -0
- package/dist/text/highlightSegments.js +29 -0
- package/dist/text/index.d.ts +3 -0
- package/dist/text/index.js +3 -0
- package/dist/text/text.css +11 -0
- package/dist/themes/attributes.d.ts +21 -0
- package/dist/themes/attributes.js +41 -0
- package/dist/themes/catalog.d.ts +125 -0
- package/dist/themes/catalog.js +940 -0
- package/dist/themes/color.d.ts +29 -0
- package/dist/themes/color.js +52 -0
- package/dist/themes/ids.d.ts +139 -0
- package/dist/themes/ids.js +59 -0
- package/dist/themes/index.d.ts +12 -0
- package/dist/themes/index.js +12 -0
- package/dist/themes/themes.generated.css +1830 -0
- package/dist/themes/tokens.d.ts +189 -0
- package/dist/themes/tokens.js +462 -0
- package/dist/tooltip/Tooltip.d.ts +21 -0
- package/dist/tooltip/Tooltip.js +105 -0
- package/dist/tooltip/Tooltip.logic.d.ts +49 -0
- package/dist/tooltip/Tooltip.logic.js +50 -0
- package/dist/tooltip/index.d.ts +3 -0
- package/dist/tooltip/index.js +3 -0
- package/dist/tooltip/tooltip.css +45 -0
- package/package.json +91 -4
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal component's pure decisions: its theme from the stylesheet's
|
|
3
|
+
* terminal tokens (with the 256-color palette derived from the 16 ANSI
|
|
4
|
+
* colors), its font stack from `--font-mono` and its size and line pitch,
|
|
5
|
+
* the bytes its line-editing actions send, and how often the bell may flash.
|
|
6
|
+
*/
|
|
7
|
+
import { FALLBACK_TERMINAL_THEME } from './ghostty/fallbackColors.js';
|
|
8
|
+
/**
|
|
9
|
+
* The terminal's text size in CSS pixels: the listing's, so a terminal
|
|
10
|
+
* beside a listing reads at the same size.
|
|
11
|
+
*/
|
|
12
|
+
export const TERMINAL_FONT_SIZE = 13;
|
|
13
|
+
/**
|
|
14
|
+
* The terminal's line pitch in CSS pixels: a little roomier than the size
|
|
15
|
+
* alone, and tighter than the listing's 24px rows, which hold one item each
|
|
16
|
+
* rather than running text.
|
|
17
|
+
*/
|
|
18
|
+
export const TERMINAL_LINE_HEIGHT = 19;
|
|
19
|
+
/**
|
|
20
|
+
* The stylesheet tokens the theme reads, which every theme of the catalog
|
|
21
|
+
* sets (`src/themes/tokens.ts`) as hex or `rgb()`.
|
|
22
|
+
*/
|
|
23
|
+
const TERMINAL_THEME_TOKENS = {
|
|
24
|
+
background: '--terminal-bg',
|
|
25
|
+
foreground: '--terminal-fg',
|
|
26
|
+
cursor: '--terminal-cursor',
|
|
27
|
+
selection: '--terminal-selection',
|
|
28
|
+
/** `--terminal-ansi-0` through `--terminal-ansi-15`: SGR 30-37, then 90-97. */
|
|
29
|
+
ansiPrefix: '--terminal-ansi-'
|
|
30
|
+
};
|
|
31
|
+
const ANSI_COLOR_COUNT = 16;
|
|
32
|
+
/** The xterm color cube's channel levels for palette entries 16-231. */
|
|
33
|
+
const CUBE_LEVELS = [0, 95, 135, 175, 215, 255];
|
|
34
|
+
function channel(value) {
|
|
35
|
+
const trimmed = value.trim();
|
|
36
|
+
const number = trimmed.endsWith('%')
|
|
37
|
+
? (Number.parseFloat(trimmed) / 100) * 255
|
|
38
|
+
: Number.parseFloat(trimmed);
|
|
39
|
+
return Number.isFinite(number) ? Math.round(Math.max(0, Math.min(255, number))) : null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parses the color forms the terminal tokens use: `#rgb`, `#rrggbb`, and
|
|
43
|
+
* `rgb()`/`rgba()` in comma or space syntax (alpha ignored). Anything else
|
|
44
|
+
* is null, for the caller to resolve another way.
|
|
45
|
+
*/
|
|
46
|
+
export function parseCssColor(value) {
|
|
47
|
+
const text = value.trim().toLowerCase();
|
|
48
|
+
const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/.exec(text)?.[1];
|
|
49
|
+
if (hex !== undefined) {
|
|
50
|
+
const digits = hex.length === 3
|
|
51
|
+
? [...hex].map((digit) => digit + digit)
|
|
52
|
+
: [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)];
|
|
53
|
+
const [r, g, b] = digits.map((pair) => Number.parseInt(pair, 16));
|
|
54
|
+
return { r: r ?? 0, g: g ?? 0, b: b ?? 0 };
|
|
55
|
+
}
|
|
56
|
+
const functional = /^rgba?\(([^)]*)\)$/.exec(text)?.[1];
|
|
57
|
+
if (functional === undefined)
|
|
58
|
+
return null;
|
|
59
|
+
const parts = functional
|
|
60
|
+
.split(/[\s,/]+/)
|
|
61
|
+
.filter((part) => part.length > 0)
|
|
62
|
+
.slice(0, 3)
|
|
63
|
+
.map(channel);
|
|
64
|
+
const [r, g, b] = parts;
|
|
65
|
+
if (parts.length !== 3 || r == null || g == null || b == null)
|
|
66
|
+
return null;
|
|
67
|
+
return { r, g, b };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The full 256-color palette for 16 ANSI colors: those 16, then xterm's
|
|
71
|
+
* 6x6x6 color cube and 24-step gray ramp, which programs address by index.
|
|
72
|
+
*/
|
|
73
|
+
function terminalPalette(ansi) {
|
|
74
|
+
if (ansi.length !== ANSI_COLOR_COUNT) {
|
|
75
|
+
throw new Error(`A terminal palette starts from ${ANSI_COLOR_COUNT} ANSI colors`);
|
|
76
|
+
}
|
|
77
|
+
const palette = [...ansi];
|
|
78
|
+
for (let index = 0; index < 216; index += 1) {
|
|
79
|
+
palette.push({
|
|
80
|
+
r: CUBE_LEVELS[Math.floor(index / 36)] ?? 0,
|
|
81
|
+
g: CUBE_LEVELS[Math.floor(index / 6) % 6] ?? 0,
|
|
82
|
+
b: CUBE_LEVELS[index % 6] ?? 0
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
for (let index = 0; index < 24; index += 1) {
|
|
86
|
+
const level = 8 + index * 10;
|
|
87
|
+
palette.push({ r: level, g: level, b: level });
|
|
88
|
+
}
|
|
89
|
+
return palette;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The theme the stylesheet's terminal tokens describe. `read` returns a
|
|
93
|
+
* token's value; `parse` resolves a value to a color, or null. Missing
|
|
94
|
+
* defaults fall back to Catppuccin Mocha (`FALLBACK_TERMINAL_THEME`); missing ANSI colors leave Ghostty's
|
|
95
|
+
* own palette in place.
|
|
96
|
+
*/
|
|
97
|
+
export function terminalThemeFromTokens(read, parse = parseCssColor) {
|
|
98
|
+
const color = (token, fallback) => parse(read(token)) ?? fallback;
|
|
99
|
+
const selection = read(TERMINAL_THEME_TOKENS.selection).trim();
|
|
100
|
+
const ansi = Array.from({ length: ANSI_COLOR_COUNT }, (_, index) => parse(read(`${TERMINAL_THEME_TOKENS.ansiPrefix}${index}`)));
|
|
101
|
+
const complete = ansi.every((entry) => entry !== null);
|
|
102
|
+
return {
|
|
103
|
+
background: color(TERMINAL_THEME_TOKENS.background, FALLBACK_TERMINAL_THEME.background),
|
|
104
|
+
foreground: color(TERMINAL_THEME_TOKENS.foreground, FALLBACK_TERMINAL_THEME.foreground),
|
|
105
|
+
cursor: color(TERMINAL_THEME_TOKENS.cursor, FALLBACK_TERMINAL_THEME.cursor),
|
|
106
|
+
selectionBackground: selection.length > 0 ? selection : (FALLBACK_TERMINAL_THEME.selectionBackground ?? ''),
|
|
107
|
+
...(complete ? { palette: terminalPalette(ansi) } : {})
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The `--font-mono` stack without the CSS-only generic keywords (such as
|
|
112
|
+
* `ui-monospace` and `system-ui`) that make a canvas font string invalid;
|
|
113
|
+
* undefined when nothing named is left, for the engine's default stack.
|
|
114
|
+
*/
|
|
115
|
+
export function terminalFontFamilyFromCss(value) {
|
|
116
|
+
const families = value
|
|
117
|
+
.split(',')
|
|
118
|
+
.map((family) => family.trim())
|
|
119
|
+
.filter((family) => family.length > 0 && !/^(ui-[a-z-]+|system-ui)$/i.test(family));
|
|
120
|
+
return families.length > 0 ? families.join(', ') : undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* How long the visual bell shows, in milliseconds: the flash's fade, or the
|
|
124
|
+
* static edge tint that takes its place under reduced motion. `Terminal.css`
|
|
125
|
+
* fades over the same time.
|
|
126
|
+
*/
|
|
127
|
+
export const BELL_FLASH_MS = 250;
|
|
128
|
+
/**
|
|
129
|
+
* The shortest time between two flashes of the visual bell, in milliseconds.
|
|
130
|
+
* Bells inside it fold into the flash that opened it, so a program ringing
|
|
131
|
+
* without pause flashes at most twice a second instead of strobing, and a
|
|
132
|
+
* flash always ends before the next one starts.
|
|
133
|
+
*/
|
|
134
|
+
export const BELL_INTERVAL_MS = 500;
|
|
135
|
+
/**
|
|
136
|
+
* Whether a bell at `now` flashes, given when the last flash started (null
|
|
137
|
+
* for none yet): only once the interval since then has passed.
|
|
138
|
+
*/
|
|
139
|
+
export function bellFlashes(lastFlashAt, now) {
|
|
140
|
+
return lastFlashAt === null || now - lastFlashAt >= BELL_INTERVAL_MS;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Readline and zsh line-editor bytes for the editing actions; clear sends
|
|
144
|
+
* nothing, since the screen clears itself and the program is not told.
|
|
145
|
+
*/
|
|
146
|
+
const ACTION_INPUT = {
|
|
147
|
+
'line-start': '\u0001',
|
|
148
|
+
'line-end': '\u0005',
|
|
149
|
+
'word-back': '\u001bb',
|
|
150
|
+
'word-forward': '\u001bf',
|
|
151
|
+
'delete-to-line-start': '\u0015'
|
|
152
|
+
};
|
|
153
|
+
/** The bytes an action sends the shell, or null for clear, which only the screen does. */
|
|
154
|
+
export function terminalActionInput(action) {
|
|
155
|
+
return action === 'clear' ? null : ACTION_INPUT[action];
|
|
156
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type TerminalMenuBox, type TerminalMenuItem, type TerminalMenuVerb } from './TerminalMenu.logic.js';
|
|
3
|
+
/** What opens the menu, and what its choices reach. */
|
|
4
|
+
export interface TerminalMenuProps {
|
|
5
|
+
/** The point the secondary click landed on, in window coordinates. */
|
|
6
|
+
readonly at: {
|
|
7
|
+
readonly x: number;
|
|
8
|
+
readonly y: number;
|
|
9
|
+
};
|
|
10
|
+
/** The terminal's screen, in window coordinates, which the menu stays over when it fits. */
|
|
11
|
+
readonly within: TerminalMenuBox;
|
|
12
|
+
/** The items to list, in order (`terminalMenuItems`). */
|
|
13
|
+
readonly items: readonly TerminalMenuItem[];
|
|
14
|
+
/** The menu's accessible name, read by assistive technology only. */
|
|
15
|
+
readonly label: string;
|
|
16
|
+
/** Runs an enabled item's verb; the caller closes the menu. */
|
|
17
|
+
readonly onRun: (verb: TerminalMenuVerb) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Closes the menu, saying how it was dismissed: by a key pressed in it,
|
|
20
|
+
* after which the terminal takes the keys back, or by a press or a focus
|
|
21
|
+
* elsewhere, which has its own destination.
|
|
22
|
+
*/
|
|
23
|
+
readonly onClose: (by: 'keyboard' | 'pointer') => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The terminal's menu: Copy and Paste with their chords, in the menu look,
|
|
27
|
+
* opened at the point a secondary click landed.
|
|
28
|
+
*
|
|
29
|
+
* It holds the keys while open (↑ ↓, Return and Space, Escape;
|
|
30
|
+
* `terminalMenuKeyAction`), which travel no further, so neither a dialog
|
|
31
|
+
* around the terminal nor the page hears them; `data-native-keyboard` keeps
|
|
32
|
+
* a page's own key handlers out, and `data-overlay` marks it an open overlay
|
|
33
|
+
* (`OVERLAY_SELECTOR`) while it shows. A press on it never takes the focus
|
|
34
|
+
* from it; a press or a focus anywhere else closes it.
|
|
35
|
+
*/
|
|
36
|
+
export declare function TerminalMenu({ at, within, items, label, onRun, onClose }: TerminalMenuProps): ReactElement;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ClipboardPaste, Copy } from 'lucide-react';
|
|
3
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
4
|
+
import { KeyChord } from '../keychord/KeyChord.js';
|
|
5
|
+
import { movedPickableCursor, pickableCursor } from '../menu/MenuQuery.logic.js';
|
|
6
|
+
import { placeTerminalMenu, terminalMenuKeyAction } from './TerminalMenu.logic.js';
|
|
7
|
+
/** Each verb's glyph. */
|
|
8
|
+
const ICONS = {
|
|
9
|
+
copy: Copy,
|
|
10
|
+
paste: ClipboardPaste
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The terminal's menu: Copy and Paste with their chords, in the menu look,
|
|
14
|
+
* opened at the point a secondary click landed.
|
|
15
|
+
*
|
|
16
|
+
* It holds the keys while open (↑ ↓, Return and Space, Escape;
|
|
17
|
+
* `terminalMenuKeyAction`), which travel no further, so neither a dialog
|
|
18
|
+
* around the terminal nor the page hears them; `data-native-keyboard` keeps
|
|
19
|
+
* a page's own key handlers out, and `data-overlay` marks it an open overlay
|
|
20
|
+
* (`OVERLAY_SELECTOR`) while it shows. A press on it never takes the focus
|
|
21
|
+
* from it; a press or a focus anywhere else closes it.
|
|
22
|
+
*/
|
|
23
|
+
export function TerminalMenu({ at, within, items, label, onRun, onClose }) {
|
|
24
|
+
const rootRef = useRef(null);
|
|
25
|
+
const itemId = useId();
|
|
26
|
+
const [pointed, setPointed] = useState(null);
|
|
27
|
+
const rows = items.map((item) => ({ key: item.verb, taken: !item.enabled }));
|
|
28
|
+
const cursor = pickableCursor(rows, pointed);
|
|
29
|
+
const cursorItem = cursor === null ? null : (items[cursor] ?? null);
|
|
30
|
+
const onCloseRef = useRef(onClose);
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
onCloseRef.current = onClose;
|
|
33
|
+
});
|
|
34
|
+
// Placed after layout, when its own size is known, and given the keys.
|
|
35
|
+
useLayoutEffect(() => {
|
|
36
|
+
const menu = rootRef.current;
|
|
37
|
+
if (menu === null)
|
|
38
|
+
return;
|
|
39
|
+
const place = placeTerminalMenu(at, { width: menu.offsetWidth, height: menu.offsetHeight }, within, { width: window.innerWidth, height: window.innerHeight });
|
|
40
|
+
menu.style.left = `${place.left}px`;
|
|
41
|
+
menu.style.top = `${place.top}px`;
|
|
42
|
+
menu.focus({ preventScroll: true });
|
|
43
|
+
}, [at, within]);
|
|
44
|
+
// A press outside closes it; the press goes on to whatever it landed on.
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const listener = (event) => {
|
|
47
|
+
if (!(event.target instanceof Node) || !rootRef.current?.contains(event.target)) {
|
|
48
|
+
onCloseRef.current('pointer');
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
document.addEventListener('mousedown', listener, true);
|
|
52
|
+
return () => document.removeEventListener('mousedown', listener, true);
|
|
53
|
+
}, []);
|
|
54
|
+
const run = (item) => {
|
|
55
|
+
if (item?.enabled === true)
|
|
56
|
+
onRun(item.verb);
|
|
57
|
+
};
|
|
58
|
+
return (_jsx("div", { "aria-activedescendant": cursor === null ? undefined : `${itemId}-${cursor}`, "aria-label": label, className: "terminal-menu", "data-native-keyboard": true, "data-overlay": true,
|
|
59
|
+
// The focus left for somewhere else: another control, or another window.
|
|
60
|
+
onBlur: (event) => {
|
|
61
|
+
if (!(event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget))) {
|
|
62
|
+
onClose('pointer');
|
|
63
|
+
}
|
|
64
|
+
}, onContextMenu: (event) => event.preventDefault(), onKeyDown: (event) => {
|
|
65
|
+
const action = terminalMenuKeyAction(event);
|
|
66
|
+
if (action === null)
|
|
67
|
+
return;
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
event.stopPropagation();
|
|
70
|
+
if (action.kind === 'close')
|
|
71
|
+
onClose('keyboard');
|
|
72
|
+
else if (action.kind === 'run')
|
|
73
|
+
run(cursorItem);
|
|
74
|
+
else {
|
|
75
|
+
const next = movedPickableCursor(rows, cursor, action.delta);
|
|
76
|
+
setPointed(next === null ? null : (items[next]?.verb ?? null));
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
// A press on an item must not take the focus from the menu, which holds the keys.
|
|
80
|
+
onMouseDown: (event) => event.preventDefault(), ref: rootRef, role: "menu", tabIndex: -1, children: items.map((item, index) => {
|
|
81
|
+
const Icon = ICONS[item.verb];
|
|
82
|
+
return (_jsxs("div", { "aria-disabled": !item.enabled, className: index === cursor ? 'terminal-menu-item cursor' : 'terminal-menu-item', id: `${itemId}-${index}`, onClick: () => run(item), onMouseMove: () => {
|
|
83
|
+
if (item.enabled)
|
|
84
|
+
setPointed(item.verb);
|
|
85
|
+
}, role: "menuitem", children: [_jsx("span", { className: "terminal-menu-icon", children: _jsx(Icon, { "aria-hidden": true, size: 13 }) }), _jsx("span", { className: "terminal-menu-label", children: item.label }), _jsx(KeyChord, { chord: item.chord })] }, item.verb));
|
|
86
|
+
}) }));
|
|
87
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal's menu, which a secondary click opens: its items, the keys it
|
|
3
|
+
* answers, and where it opens. Pure, so the component only draws.
|
|
4
|
+
*/
|
|
5
|
+
import type { Chord } from '../keyboard/Keyboard.logic.js';
|
|
6
|
+
import type { TerminalLabels } from '../labels/terminal.js';
|
|
7
|
+
/** What an item of the terminal's menu does. There is no Cut: a terminal's text cannot be cut. */
|
|
8
|
+
export type TerminalMenuVerb = 'copy' | 'paste';
|
|
9
|
+
/** One item of the terminal's menu. */
|
|
10
|
+
export interface TerminalMenuItem {
|
|
11
|
+
readonly verb: TerminalMenuVerb;
|
|
12
|
+
readonly label: string;
|
|
13
|
+
/** The chord that runs the same verb elsewhere (an Edit menu's), which the item shows. */
|
|
14
|
+
readonly chord: Chord;
|
|
15
|
+
/** A disabled item is listed, dimmed, and passed over by the keys. */
|
|
16
|
+
readonly enabled: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** What the menu's items depend on when it opens. */
|
|
19
|
+
export interface TerminalMenuState {
|
|
20
|
+
/** No program to paste into: a log. */
|
|
21
|
+
readonly readOnly: boolean;
|
|
22
|
+
/** Whether the terminal has text selected for Copy. */
|
|
23
|
+
readonly hasSelection: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The chords the menu shows beside Copy and Paste: the app's own chords for
|
|
27
|
+
* those verbs, so the menu teaches the keys that do the same thing.
|
|
28
|
+
*/
|
|
29
|
+
export type TerminalMenuChords = Readonly<Record<TerminalMenuVerb, Chord>>;
|
|
30
|
+
/** macOS's Copy and Paste chords, ⌘C and ⌘V: what a terminal shows when its host names none. */
|
|
31
|
+
export declare const DEFAULT_TERMINAL_MENU_CHORDS: TerminalMenuChords;
|
|
32
|
+
/**
|
|
33
|
+
* Copy, while there is a selection, and Paste, unless the terminal is
|
|
34
|
+
* read-only, titled from `labels` and showing `chords`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function terminalMenuItems(state: TerminalMenuState, labels: Pick<TerminalLabels, 'copy' | 'paste'>, chords: TerminalMenuChords): readonly TerminalMenuItem[];
|
|
37
|
+
/** A key the open menu answers: move the cursor, run its item, or close. */
|
|
38
|
+
export type TerminalMenuKeyAction = {
|
|
39
|
+
readonly kind: 'move';
|
|
40
|
+
readonly delta: number;
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'run';
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: 'close';
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The menu's keys, all without modifiers: ↑ and ↓ move, Return and Space run
|
|
48
|
+
* the cursor's item, and Escape closes. Anything else is left alone.
|
|
49
|
+
*/
|
|
50
|
+
export declare function terminalMenuKeyAction(event: Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey' | 'altKey' | 'shiftKey'>): TerminalMenuKeyAction | null;
|
|
51
|
+
/** A rectangle in window coordinates. */
|
|
52
|
+
export interface TerminalMenuBox {
|
|
53
|
+
readonly left: number;
|
|
54
|
+
readonly top: number;
|
|
55
|
+
readonly right: number;
|
|
56
|
+
readonly bottom: number;
|
|
57
|
+
}
|
|
58
|
+
/** Clear space the menu keeps from the edges of the box it opens in. */
|
|
59
|
+
export declare const TERMINAL_MENU_MARGIN = 4;
|
|
60
|
+
/**
|
|
61
|
+
* Where the menu's top left corner goes, in window coordinates: at the
|
|
62
|
+
* point clicked, pulled back inside the terminal so it stays over the screen
|
|
63
|
+
* it acts on, or inside the window along an edge the terminal is too small
|
|
64
|
+
* for.
|
|
65
|
+
*/
|
|
66
|
+
export declare function placeTerminalMenu(at: {
|
|
67
|
+
readonly x: number;
|
|
68
|
+
readonly y: number;
|
|
69
|
+
}, size: {
|
|
70
|
+
readonly width: number;
|
|
71
|
+
readonly height: number;
|
|
72
|
+
}, terminal: TerminalMenuBox, viewport: {
|
|
73
|
+
readonly width: number;
|
|
74
|
+
readonly height: number;
|
|
75
|
+
}): {
|
|
76
|
+
readonly left: number;
|
|
77
|
+
readonly top: number;
|
|
78
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal's menu, which a secondary click opens: its items, the keys it
|
|
3
|
+
* answers, and where it opens. Pure, so the component only draws.
|
|
4
|
+
*/
|
|
5
|
+
/** macOS's Copy and Paste chords, ⌘C and ⌘V: what a terminal shows when its host names none. */
|
|
6
|
+
export const DEFAULT_TERMINAL_MENU_CHORDS = {
|
|
7
|
+
copy: { key: 'c', meta: true },
|
|
8
|
+
paste: { key: 'v', meta: true }
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Copy, while there is a selection, and Paste, unless the terminal is
|
|
12
|
+
* read-only, titled from `labels` and showing `chords`.
|
|
13
|
+
*/
|
|
14
|
+
export function terminalMenuItems(state, labels, chords) {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
verb: 'copy',
|
|
18
|
+
label: labels.copy,
|
|
19
|
+
chord: chords.copy,
|
|
20
|
+
enabled: state.hasSelection
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
verb: 'paste',
|
|
24
|
+
label: labels.paste,
|
|
25
|
+
chord: chords.paste,
|
|
26
|
+
enabled: !state.readOnly
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The menu's keys, all without modifiers: ↑ and ↓ move, Return and Space run
|
|
32
|
+
* the cursor's item, and Escape closes. Anything else is left alone.
|
|
33
|
+
*/
|
|
34
|
+
export function terminalMenuKeyAction(event) {
|
|
35
|
+
if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey)
|
|
36
|
+
return null;
|
|
37
|
+
switch (event.key) {
|
|
38
|
+
case 'ArrowUp':
|
|
39
|
+
return { kind: 'move', delta: -1 };
|
|
40
|
+
case 'ArrowDown':
|
|
41
|
+
return { kind: 'move', delta: 1 };
|
|
42
|
+
case 'Enter':
|
|
43
|
+
case ' ':
|
|
44
|
+
return { kind: 'run' };
|
|
45
|
+
case 'Escape':
|
|
46
|
+
return { kind: 'close' };
|
|
47
|
+
default:
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Clear space the menu keeps from the edges of the box it opens in. */
|
|
52
|
+
export const TERMINAL_MENU_MARGIN = 4;
|
|
53
|
+
/**
|
|
54
|
+
* Where the menu's top left corner goes, in window coordinates: at the
|
|
55
|
+
* point clicked, pulled back inside the terminal so it stays over the screen
|
|
56
|
+
* it acts on, or inside the window along an edge the terminal is too small
|
|
57
|
+
* for.
|
|
58
|
+
*/
|
|
59
|
+
export function placeTerminalMenu(at, size, terminal, viewport) {
|
|
60
|
+
const fit = (value, extent, start, end, room) => {
|
|
61
|
+
const [low, high] = end - start >= extent + 2 * TERMINAL_MENU_MARGIN ? [start, end] : [0, room];
|
|
62
|
+
return Math.max(low + TERMINAL_MENU_MARGIN, Math.min(value, high - TERMINAL_MENU_MARGIN - extent));
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
left: fit(at.x, size.width, terminal.left, terminal.right, viewport.width),
|
|
66
|
+
top: fit(at.y, size.height, terminal.top, terminal.bottom, viewport.height)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The rows of history a terminal keeps above its screen when no provider says otherwise. */
|
|
2
|
+
export declare const DEFAULT_TERMINAL_SCROLLBACK_LINES = 10000;
|
|
3
|
+
/**
|
|
4
|
+
* The rows of history every terminal under it keeps above its screen, so an
|
|
5
|
+
* app sets one length (a preference, say) for all its terminals. Every
|
|
6
|
+
* terminal follows it: one already open takes a change at once, and a
|
|
7
|
+
* shorter length drops its oldest lines. Without a provider a terminal keeps
|
|
8
|
+
* `DEFAULT_TERMINAL_SCROLLBACK_LINES`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TerminalScrollbackContext: import("react").Context<number>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
/** The rows of history a terminal keeps above its screen when no provider says otherwise. */
|
|
3
|
+
export const DEFAULT_TERMINAL_SCROLLBACK_LINES = 10_000;
|
|
4
|
+
/**
|
|
5
|
+
* The rows of history every terminal under it keeps above its screen, so an
|
|
6
|
+
* app sets one length (a preference, say) for all its terminals. Every
|
|
7
|
+
* terminal follows it: one already open takes a change at once, and a
|
|
8
|
+
* shorter length drops its oldest lines. Without a provider a terminal keeps
|
|
9
|
+
* `DEFAULT_TERMINAL_SCROLLBACK_LINES`.
|
|
10
|
+
*/
|
|
11
|
+
export const TerminalScrollbackContext = createContext(DEFAULT_TERMINAL_SCROLLBACK_LINES);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 T3 Tools Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|