@bigpixelrocket/uiok 0.2.3 → 0.4.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 (215) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/dist/charts/Sparkline.d.ts +20 -0
  3. package/dist/charts/Sparkline.js +12 -0
  4. package/dist/charts/Sparkline.logic.d.ts +9 -0
  5. package/dist/charts/Sparkline.logic.js +27 -0
  6. package/dist/charts/charts.css +17 -0
  7. package/dist/charts/index.d.ts +2 -0
  8. package/dist/charts/index.js +2 -0
  9. package/dist/dialog/ConfirmDialog.d.ts +17 -1
  10. package/dist/dialog/ConfirmDialog.js +4 -3
  11. package/dist/dialog/ModalDialog.d.ts +8 -0
  12. package/dist/dialog/ModalDialog.js +4 -2
  13. package/dist/dialog/ProgressDialog.d.ts +40 -0
  14. package/dist/dialog/ProgressDialog.js +40 -0
  15. package/dist/dialog/TypedNameDialog.d.ts +44 -0
  16. package/dist/dialog/TypedNameDialog.js +17 -0
  17. package/dist/dialog/index.d.ts +5 -2
  18. package/dist/dialog/index.js +4 -1
  19. package/dist/field/Check.d.ts +9 -2
  20. package/dist/field/Check.js +5 -4
  21. package/dist/field/Controls.d.ts +198 -0
  22. package/dist/field/Controls.js +94 -0
  23. package/dist/field/FieldLayout.d.ts +126 -0
  24. package/dist/field/FieldLayout.js +89 -0
  25. package/dist/field/Switch.d.ts +26 -0
  26. package/dist/field/Switch.js +20 -0
  27. package/dist/field/index.d.ts +10 -6
  28. package/dist/field/index.js +10 -6
  29. package/dist/frame/AppRoot.d.ts +44 -0
  30. package/dist/frame/AppRoot.js +26 -0
  31. package/dist/frame/Dock.d.ts +88 -0
  32. package/dist/frame/Dock.js +129 -0
  33. package/dist/frame/FilterChips.d.ts +28 -0
  34. package/dist/frame/FilterChips.js +14 -0
  35. package/dist/frame/PageParts.d.ts +69 -0
  36. package/dist/frame/PageParts.js +60 -0
  37. package/dist/frame/PaneSplit.d.ts +74 -0
  38. package/dist/frame/PaneSplit.js +197 -0
  39. package/dist/frame/SidebarResizer.d.ts +35 -0
  40. package/dist/frame/SidebarResizer.js +43 -0
  41. package/dist/frame/StatusNotice.d.ts +20 -0
  42. package/dist/frame/StatusNotice.js +13 -0
  43. package/dist/frame/Tree.d.ts +147 -0
  44. package/dist/frame/Tree.js +164 -0
  45. package/dist/frame/TreeToggle.d.ts +18 -0
  46. package/dist/frame/TreeToggle.js +17 -0
  47. package/dist/frame/WindowFrame.d.ts +57 -0
  48. package/dist/frame/WindowFrame.js +19 -0
  49. package/dist/frame/frame.css +801 -0
  50. package/dist/frame/index.d.ts +22 -0
  51. package/dist/frame/index.js +22 -0
  52. package/dist/frame/sharedRef.d.ts +8 -0
  53. package/dist/frame/sharedRef.js +26 -0
  54. package/dist/index.d.ts +3 -0
  55. package/dist/index.js +3 -0
  56. package/dist/labels/UiokLabels.d.ts +6 -0
  57. package/dist/labels/UiokLabels.js +5 -1
  58. package/dist/labels/dialog.d.ts +12 -0
  59. package/dist/labels/dialog.js +7 -1
  60. package/dist/labels/index.d.ts +2 -0
  61. package/dist/labels/index.js +2 -0
  62. package/dist/labels/settings.d.ts +46 -0
  63. package/dist/labels/settings.js +29 -0
  64. package/dist/labels/viewer.d.ts +193 -0
  65. package/dist/labels/viewer.js +124 -0
  66. package/dist/listing/EmptyState.d.ts +40 -0
  67. package/dist/listing/EmptyState.js +14 -0
  68. package/dist/listing/PaneMessage.d.ts +28 -0
  69. package/dist/listing/PaneMessage.js +12 -0
  70. package/dist/listing/index.d.ts +5 -1
  71. package/dist/listing/index.js +5 -1
  72. package/dist/listing/listing.css +66 -2
  73. package/dist/log/LogWell.d.ts +34 -0
  74. package/dist/log/LogWell.js +39 -0
  75. package/dist/log/LogWell.logic.d.ts +16 -0
  76. package/dist/log/LogWell.logic.js +26 -0
  77. package/dist/log/index.d.ts +8 -0
  78. package/dist/log/index.js +8 -0
  79. package/dist/log/log.css +57 -0
  80. package/dist/pane/Pane.d.ts +49 -0
  81. package/dist/pane/Pane.js +17 -0
  82. package/dist/pane/PaneKeys.d.ts +10 -3
  83. package/dist/pane/PaneKeys.js +26 -7
  84. package/dist/pane/index.d.ts +4 -2
  85. package/dist/pane/index.js +4 -2
  86. package/dist/pane/usePaneKeys.js +9 -11
  87. package/dist/shell/AboutWindow.d.ts +21 -0
  88. package/dist/shell/AboutWindow.js +10 -0
  89. package/dist/shell/LanguageChoice.d.ts +27 -0
  90. package/dist/shell/LanguageChoice.js +17 -0
  91. package/dist/shell/LoadFailure.d.ts +22 -0
  92. package/dist/shell/LoadFailure.js +15 -0
  93. package/dist/shell/Lockup.d.ts +52 -0
  94. package/dist/shell/Lockup.js +30 -0
  95. package/dist/shell/SettingsDialog.d.ts +97 -0
  96. package/dist/shell/SettingsDialog.js +219 -0
  97. package/dist/shell/SettingsDialog.logic.d.ts +33 -0
  98. package/dist/shell/SettingsDialog.logic.js +42 -0
  99. package/dist/shell/SettingsFiles.d.ts +55 -0
  100. package/dist/shell/SettingsFiles.js +30 -0
  101. package/dist/shell/SettingsPageKeys.d.ts +42 -0
  102. package/dist/shell/SettingsPageKeys.js +70 -0
  103. package/dist/shell/SettingsSubsection.d.ts +34 -0
  104. package/dist/shell/SettingsSubsection.js +30 -0
  105. package/dist/shell/SignIn.d.ts +61 -0
  106. package/dist/shell/SignIn.js +36 -0
  107. package/dist/shell/ThemePicker.d.ts +74 -0
  108. package/dist/shell/ThemePicker.js +96 -0
  109. package/dist/shell/ThemePicker.logic.d.ts +13 -0
  110. package/dist/shell/ThemePicker.logic.js +26 -0
  111. package/dist/shell/TitleBar.d.ts +44 -0
  112. package/dist/shell/TitleBar.js +23 -0
  113. package/dist/shell/UpdatePill.d.ts +26 -0
  114. package/dist/shell/UpdatePill.js +17 -0
  115. package/dist/shell/Updates.d.ts +99 -0
  116. package/dist/shell/Updates.js +72 -0
  117. package/dist/shell/index.d.ts +27 -0
  118. package/dist/shell/index.js +27 -0
  119. package/dist/shell/shell.css +243 -4
  120. package/dist/styles.css +5 -0
  121. package/dist/surface/Card.d.ts +18 -0
  122. package/dist/surface/Card.js +10 -0
  123. package/dist/surface/Notice.d.ts +45 -0
  124. package/dist/surface/Notice.js +27 -0
  125. package/dist/surface/index.d.ts +5 -3
  126. package/dist/surface/index.js +5 -3
  127. package/dist/themes/catalog.js +4 -0
  128. package/dist/themes/themes.generated.css +245 -0
  129. package/dist/themes/tokens.d.ts +17 -5
  130. package/dist/themes/tokens.js +67 -1
  131. package/dist/tokens.css +11 -0
  132. package/dist/viewer/AudioView.d.ts +13 -0
  133. package/dist/viewer/AudioView.js +25 -0
  134. package/dist/viewer/HexJump.logic.d.ts +16 -0
  135. package/dist/viewer/HexJump.logic.js +27 -0
  136. package/dist/viewer/HexRows.logic.d.ts +55 -0
  137. package/dist/viewer/HexRows.logic.js +84 -0
  138. package/dist/viewer/HexSelection.logic.d.ts +57 -0
  139. package/dist/viewer/HexSelection.logic.js +68 -0
  140. package/dist/viewer/HexView.d.ts +10 -0
  141. package/dist/viewer/HexView.js +291 -0
  142. package/dist/viewer/HexViewport.logic.d.ts +61 -0
  143. package/dist/viewer/HexViewport.logic.js +79 -0
  144. package/dist/viewer/ImageView.d.ts +19 -0
  145. package/dist/viewer/ImageView.js +230 -0
  146. package/dist/viewer/ImageZoom.logic.d.ts +65 -0
  147. package/dist/viewer/ImageZoom.logic.js +119 -0
  148. package/dist/viewer/LatestRead.logic.d.ts +27 -0
  149. package/dist/viewer/LatestRead.logic.js +55 -0
  150. package/dist/viewer/MediaControls.d.ts +25 -0
  151. package/dist/viewer/MediaControls.js +183 -0
  152. package/dist/viewer/MediaPlayer.logic.d.ts +53 -0
  153. package/dist/viewer/MediaPlayer.logic.js +68 -0
  154. package/dist/viewer/PdfView.d.ts +23 -0
  155. package/dist/viewer/PdfView.js +25 -0
  156. package/dist/viewer/QuietFocus.d.ts +19 -0
  157. package/dist/viewer/QuietFocus.js +27 -0
  158. package/dist/viewer/ScaledScroll.logic.d.ts +30 -0
  159. package/dist/viewer/ScaledScroll.logic.js +28 -0
  160. package/dist/viewer/ScaledScrollbar.d.ts +19 -0
  161. package/dist/viewer/ScaledScrollbar.js +71 -0
  162. package/dist/viewer/SyntaxHighlighter.d.ts +29 -0
  163. package/dist/viewer/SyntaxHighlighter.js +144 -0
  164. package/dist/viewer/SyntaxLanguage.logic.d.ts +110 -0
  165. package/dist/viewer/SyntaxLanguage.logic.js +283 -0
  166. package/dist/viewer/SyntaxService.d.ts +75 -0
  167. package/dist/viewer/SyntaxService.js +49 -0
  168. package/dist/viewer/SyntaxSession.logic.d.ts +78 -0
  169. package/dist/viewer/SyntaxSession.logic.js +221 -0
  170. package/dist/viewer/SyntaxWorker.d.ts +6 -0
  171. package/dist/viewer/SyntaxWorker.js +8 -0
  172. package/dist/viewer/TextEncoding.logic.d.ts +35 -0
  173. package/dist/viewer/TextEncoding.logic.js +58 -0
  174. package/dist/viewer/TextRows.logic.d.ts +86 -0
  175. package/dist/viewer/TextRows.logic.js +241 -0
  176. package/dist/viewer/TextSelection.logic.d.ts +97 -0
  177. package/dist/viewer/TextSelection.logic.js +139 -0
  178. package/dist/viewer/TextView.d.ts +13 -0
  179. package/dist/viewer/TextView.js +448 -0
  180. package/dist/viewer/TextViewport.logic.d.ts +70 -0
  181. package/dist/viewer/TextViewport.logic.js +116 -0
  182. package/dist/viewer/VideoView.d.ts +18 -0
  183. package/dist/viewer/VideoView.js +53 -0
  184. package/dist/viewer/ViewerClipboard.d.ts +30 -0
  185. package/dist/viewer/ViewerClipboard.js +70 -0
  186. package/dist/viewer/ViewerFrame.logic.d.ts +61 -0
  187. package/dist/viewer/ViewerFrame.logic.js +130 -0
  188. package/dist/viewer/ViewerKeys.d.ts +16 -0
  189. package/dist/viewer/ViewerKeys.js +14 -0
  190. package/dist/viewer/ViewerScope.d.ts +12 -0
  191. package/dist/viewer/ViewerScope.js +22 -0
  192. package/dist/viewer/ViewerViews.d.ts +28 -0
  193. package/dist/viewer/ViewerViews.js +22 -0
  194. package/dist/viewer/ViewerWindow.d.ts +53 -0
  195. package/dist/viewer/ViewerWindow.js +219 -0
  196. package/dist/viewer/index.d.ts +12 -0
  197. package/dist/viewer/index.js +12 -0
  198. package/dist/viewer/types.d.ts +151 -0
  199. package/dist/viewer/types.js +26 -0
  200. package/dist/viewer/useElementHeight.d.ts +6 -0
  201. package/dist/viewer/useElementHeight.js +22 -0
  202. package/dist/viewer/useElementSize.d.ts +7 -0
  203. package/dist/viewer/useElementSize.js +24 -0
  204. package/dist/viewer/useEscapeToClear.d.ts +8 -0
  205. package/dist/viewer/useEscapeToClear.js +26 -0
  206. package/dist/viewer/useHexDocument.d.ts +41 -0
  207. package/dist/viewer/useHexDocument.js +144 -0
  208. package/dist/viewer/useMediaElement.d.ts +10 -0
  209. package/dist/viewer/useMediaElement.js +24 -0
  210. package/dist/viewer/useSyntaxHighlight.d.ts +24 -0
  211. package/dist/viewer/useSyntaxHighlight.js +133 -0
  212. package/dist/viewer/useTextDocument.d.ts +66 -0
  213. package/dist/viewer/useTextDocument.js +245 -0
  214. package/dist/viewer/viewer.css +645 -0
  215. package/package.json +7 -1
@@ -0,0 +1,291 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
3
+ import { Button } from '../button/Button.js';
4
+ import { tooltip } from '../tooltip/Tooltip.logic.js';
5
+ import { useLabels } from '../labels/UiokProvider.js';
6
+ import { parseJumpOffset } from './HexJump.logic.js';
7
+ import { BYTES_PER_ROW, cellAt, COLUMN_GAP, formatOffset, hexColumn, lineChars, offsetDigits, textColumn } from './HexRows.logic.js';
8
+ import { extendSelection, selectedCells, selectedRange, SELECTION_STEPS } from './HexSelection.logic.js';
9
+ import { hexScrollRange, rowOfByte } from './HexViewport.logic.js';
10
+ import { endQuietFocus, focusQuietly } from './QuietFocus.js';
11
+ import ScaledScrollbar from './ScaledScrollbar.js';
12
+ import { screenRows as clampScreenRows } from './TextViewport.logic.js';
13
+ import { useElementHeight } from './useElementHeight.js';
14
+ import { useEscapeToClear } from './useEscapeToClear.js';
15
+ import { useHexDocument } from './useHexDocument.js';
16
+ import { deliverCopy, useCopyTickets } from './ViewerClipboard.js';
17
+ import { isViewerEvent } from './ViewerScope.js';
18
+ /** One row's height in pixels; the stylesheet's row height and line height match it. */
19
+ const ROW_PX = 18;
20
+ /** Rows before the layout is measured (or where it never is). */
21
+ const FALLBACK_ROWS = 40;
22
+ /** How often a drag held past the top or bottom edge scrolls one row. */
23
+ const DRAG_SCROLL_MS = 50;
24
+ /** A column's characters, split where the selection starts and ends so the selected part can be marked. */
25
+ function Cells({ text, span, className, primary }) {
26
+ if (span === null)
27
+ return _jsx("span", { className: className, children: text });
28
+ return (_jsxs("span", { className: className, children: [text.slice(0, span.from), _jsx("span", { className: primary ? 'hex-selected hex-selected-primary' : 'hex-selected', children: text.slice(span.from, span.to) }), text.slice(span.to)] }));
29
+ }
30
+ /** One row: offset, hex column, text column, with the selected bytes marked in both. */
31
+ function Row({ row, digits, selection }) {
32
+ const cells = selection ? selectedCells(selection, row.offset, row.bytes.length) : null;
33
+ // A byte is two digits and the separator after it; the last selected byte's separator is not selected.
34
+ const hexSpan = cells && { from: cells.from * 3, to: cells.to * 3 - 1 };
35
+ return (_jsx("div", { className: "hex-row", "data-offset": row.offset, children: _jsxs("span", { className: "hex-line", children: [_jsx("span", { className: "hex-offset", children: formatOffset(row.offset, digits) }), COLUMN_GAP, _jsx(Cells, { className: "hex-bytes", primary: selection?.column === 'hex', span: hexSpan, text: hexColumn(row.bytes) }), COLUMN_GAP, _jsx(Cells, { className: "hex-text", primary: selection?.column === 'text', span: cells, text: textColumn(row.bytes) })] }) }));
36
+ }
37
+ /**
38
+ * The hex view: 16 bytes a row, as hex and as text, any row one bounded read
39
+ * away. A scaled scrollbar maps the thumb to a byte; ⌘L jumps to an offset;
40
+ * a byte range selected with the mouse (or Shift with the arrows) copies as
41
+ * hex or as text, up to one bounded read.
42
+ */
43
+ function HexView({ reader, info }) {
44
+ const labels = useLabels().viewer;
45
+ const takeCopyTicket = useCopyTickets();
46
+ const [selection, setSelection] = useState(null);
47
+ const [message, setMessage] = useState(null);
48
+ const clearSelection = useCallback(() => setSelection(null), []);
49
+ useEscapeToClear(selection !== null, clearSelection);
50
+ const [jump, setJump] = useState(null);
51
+ const [rowsRef, rowsHeight] = useElementHeight();
52
+ const screenRows = clampScreenRows(rowsHeight === null ? FALLBACK_ROWS : Math.ceil(rowsHeight / ROW_PX));
53
+ const fullRows = clampScreenRows(rowsHeight === null ? FALLBACK_ROWS : Math.floor(rowsHeight / ROW_PX));
54
+ const view = useMemo(() => ({ screenRows, fullRows }), [screenRows, fullRows]);
55
+ const hexDocument = useHexDocument(reader, info, view);
56
+ const { screen, go, scroll } = hexDocument;
57
+ const rowsElement = useRef(null);
58
+ const jumpField = useRef(null);
59
+ const wheelRemainder = useRef(0);
60
+ const drag = useRef(null);
61
+ const digits = offsetDigits(info.sizeBytes);
62
+ const top = screen?.top ?? 0;
63
+ const end = screen?.end ?? info.sizeBytes;
64
+ const page = Math.max(1, fullRows - 1);
65
+ // Pointer handlers outlive a render (a drag scrolls on a timer), so they
66
+ // read the screen through a ref.
67
+ const shown = useRef(screen);
68
+ useLayoutEffect(() => {
69
+ shown.current = screen;
70
+ });
71
+ /**
72
+ * Brings byte `offset` into view: scrolled the least, as a selection's
73
+ * moving end follows the keys, or with its row on top, as a jump lands.
74
+ */
75
+ const reveal = useCallback((offset, placement) => {
76
+ const row = rowOfByte(offset);
77
+ if (row < top || (placement === 'top' && row >= top + fullRows))
78
+ go(row);
79
+ else if (row >= top + fullRows)
80
+ go(row - fullRows + 1);
81
+ }, [fullRows, go, top]);
82
+ // Copy answers the Edit menu, whose Copy item copies natively in the page;
83
+ // the jump field keeps its own copy.
84
+ useEffect(() => {
85
+ const onCopy = (event) => {
86
+ // A copy the page makes itself (the jump field, a field beside the
87
+ // viewer, nothing selected here) is the newest: a copy of ours still
88
+ // reading must not land on the clipboard after it.
89
+ if (selection === null ||
90
+ document.activeElement === jumpField.current ||
91
+ !isViewerEvent(event)) {
92
+ takeCopyTicket();
93
+ return;
94
+ }
95
+ event.preventDefault();
96
+ deliverCopy(hexDocument.copy(selection, selection.column), event.clipboardData, setMessage, labels, takeCopyTicket());
97
+ };
98
+ window.addEventListener('copy', onCopy);
99
+ return () => window.removeEventListener('copy', onCopy);
100
+ }, [hexDocument, labels, selection, takeCopyTicket]);
101
+ const copyAs = (column) => {
102
+ if (selection !== null)
103
+ deliverCopy(hexDocument.copy(selection, column), null, setMessage, labels, takeCopyTicket());
104
+ };
105
+ const openJump = () => {
106
+ setJump('');
107
+ setMessage(null);
108
+ };
109
+ const closeJump = () => {
110
+ setJump(null);
111
+ rowsElement.current?.focus();
112
+ };
113
+ const submitJump = () => {
114
+ const result = parseJumpOffset(jump ?? '', end, labels);
115
+ if ('error' in result) {
116
+ setMessage(result.error);
117
+ return;
118
+ }
119
+ setSelection({ anchor: result.offset, focus: result.offset, column: 'hex' });
120
+ setMessage(null);
121
+ reveal(result.offset, 'top');
122
+ closeJump();
123
+ };
124
+ const jumpOpen = jump !== null;
125
+ useEffect(() => {
126
+ if (jumpOpen)
127
+ jumpField.current?.focus();
128
+ }, [jumpOpen]);
129
+ const onKeyDown = (event) => {
130
+ const command = event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
131
+ const shift = event.shiftKey && !event.metaKey && !event.ctrlKey && !event.altKey;
132
+ const plain = !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
133
+ const step = SELECTION_STEPS[event.key];
134
+ let handled = true;
135
+ if (command && event.key === 'a') {
136
+ if (end > 0)
137
+ setSelection({ anchor: 0, focus: end - 1, column: 'hex' });
138
+ setMessage(null);
139
+ }
140
+ else if (command && event.key === 'l')
141
+ openJump();
142
+ else if (command && event.key === 'ArrowUp')
143
+ go(0);
144
+ else if (command && event.key === 'ArrowDown')
145
+ go(Infinity);
146
+ else if (shift && step !== undefined) {
147
+ const next = extendSelection(selection, step, top * BYTES_PER_ROW, end);
148
+ setSelection(next);
149
+ if (next)
150
+ reveal(next.focus, 'nearest');
151
+ }
152
+ else if (!plain)
153
+ handled = false;
154
+ else if (event.key === 'ArrowDown')
155
+ scroll(1);
156
+ else if (event.key === 'ArrowUp')
157
+ scroll(-1);
158
+ else if (event.key === 'PageDown')
159
+ scroll(page);
160
+ else if (event.key === 'PageUp')
161
+ scroll(-page);
162
+ else if (event.key === 'Home')
163
+ go(0);
164
+ else if (event.key === 'End')
165
+ go(Infinity);
166
+ else
167
+ handled = false;
168
+ if (handled)
169
+ event.preventDefault();
170
+ };
171
+ const onWheel = (event) => {
172
+ const unit = event.deltaMode === 1 ? ROW_PX : event.deltaMode === 2 ? page * ROW_PX : 1;
173
+ wheelRemainder.current += event.deltaY * unit;
174
+ const rows = Math.trunc(wheelRemainder.current / ROW_PX);
175
+ wheelRemainder.current -= rows * ROW_PX;
176
+ if (rows !== 0)
177
+ scroll(rows);
178
+ };
179
+ /**
180
+ * The byte under a pointer and the column it is in. A pointer outside the
181
+ * rows points at the nearest row along that edge; within a row, the
182
+ * character under it decides the byte (`cellAt`), from the row's
183
+ * monospaced line.
184
+ */
185
+ const byteAt = useCallback((clientX, clientY) => {
186
+ const box = rowsElement.current;
187
+ const rows = shown.current?.rows ?? [];
188
+ if (box === null || rows.length === 0)
189
+ return null;
190
+ const bounds = box.getBoundingClientRect();
191
+ const index = Math.max(0, Math.min(rows.length - 1, Math.floor((clientY - bounds.top) / ROW_PX)));
192
+ const row = rows[index];
193
+ const line = box.querySelectorAll('.hex-line')[index];
194
+ if (row === undefined || line === undefined)
195
+ return null;
196
+ const lineBounds = line.getBoundingClientRect();
197
+ const charPx = lineBounds.width / lineChars(digits);
198
+ const char = charPx > 0 ? Math.floor((clientX - lineBounds.left) / charPx) : 0;
199
+ const cell = cellAt(char, digits);
200
+ return {
201
+ offset: row.offset + Math.min(cell.index, row.bytes.length - 1),
202
+ column: cell.column
203
+ };
204
+ }, [digits]);
205
+ // The window opens on its bytes, so the keys scroll them without a click first.
206
+ // That focus is the window's own, so it draws no ring (QuietFocus.ts).
207
+ useEffect(() => {
208
+ focusQuietly(rowsElement.current);
209
+ }, []);
210
+ const endDrag = useCallback(() => {
211
+ if (drag.current?.timer)
212
+ clearInterval(drag.current.timer);
213
+ drag.current = null;
214
+ }, []);
215
+ useEffect(() => endDrag, [endDrag]);
216
+ const onMouseDown = (event) => {
217
+ if (event.button !== 0)
218
+ return;
219
+ // The page's own selection would cover only the rows in the DOM, so the
220
+ // view keeps its own and the native one never starts.
221
+ event.preventDefault();
222
+ rowsElement.current?.focus();
223
+ const hit = byteAt(event.clientX, event.clientY);
224
+ if (hit === null)
225
+ return;
226
+ setMessage(null);
227
+ setSelection((current) => event.shiftKey && current !== null
228
+ ? { ...current, focus: hit.offset }
229
+ : { anchor: hit.offset, focus: hit.offset, column: hit.column });
230
+ const box = rowsElement.current?.getBoundingClientRect();
231
+ const state = {
232
+ x: event.clientX,
233
+ y: event.clientY,
234
+ timer: null
235
+ };
236
+ drag.current = state;
237
+ const extend = () => {
238
+ const focus = byteAt(state.x, state.y);
239
+ if (focus)
240
+ setSelection((current) => (current ? { ...current, focus: focus.offset } : null));
241
+ };
242
+ const onMove = (move) => {
243
+ state.x = move.clientX;
244
+ state.y = move.clientY;
245
+ extend();
246
+ const outside = box !== undefined && (move.clientY < box.top || move.clientY >= box.bottom);
247
+ if (outside && state.timer === null) {
248
+ state.timer = setInterval(() => {
249
+ const above = box !== undefined && state.y < box.top;
250
+ scroll(above ? -1 : 1);
251
+ extend();
252
+ }, DRAG_SCROLL_MS);
253
+ }
254
+ else if (!outside && state.timer !== null) {
255
+ clearInterval(state.timer);
256
+ state.timer = null;
257
+ }
258
+ };
259
+ const onUp = () => {
260
+ window.removeEventListener('mousemove', onMove);
261
+ window.removeEventListener('mouseup', onUp);
262
+ endDrag();
263
+ };
264
+ window.addEventListener('mousemove', onMove);
265
+ window.addEventListener('mouseup', onUp);
266
+ };
267
+ if (hexDocument.failure !== null && screen === null) {
268
+ return (_jsx("p", { className: "viewer-failure", role: "alert", children: hexDocument.failure }));
269
+ }
270
+ const rows = screen?.rows ?? [];
271
+ const range = hexScrollRange(end, fullRows);
272
+ const selected = selection && selectedRange(selection);
273
+ const position = selected === null
274
+ ? labels.hex.top(formatOffset(top * BYTES_PER_ROW, digits))
275
+ : labels.hex.selection(formatOffset(selected.start, digits), formatOffset(selected.end - 1, digits), selected.end - selected.start);
276
+ return (_jsxs("div", { className: "hex-view", children: [_jsxs("div", { className: "hex-view-body viewer-rows-frame", children: [_jsxs("div", { "aria-label": labels.hex.rows(info.name), "aria-readonly": "true", onBlur: endQuietFocus, className: "hex-rows scroll-fade-x", onKeyDown: onKeyDown, onMouseDown: onMouseDown, onWheel: onWheel, ref: (element) => {
277
+ rowsElement.current = element;
278
+ rowsRef(element);
279
+ }, role: "textbox", tabIndex: 0, children: [screen !== null && rows.length === 0 ? (_jsx("p", { className: "hex-empty", children: labels.empty })) : null, rows.map((row) => (_jsx(Row, { digits: digits, row: row, selection: selection }, row.offset)))] }), _jsx(ScaledScrollbar, { onDrag: (byte) => go(rowOfByte(byte)), onPage: (direction) => scroll(direction * page), position: top * BYTES_PER_ROW, total: range.total, visible: range.visible })] }), _jsx("p", { "aria-live": "polite", className: "hex-message", children: message ?? hexDocument.failure ?? '' }), _jsxs("footer", { className: "viewer-status hex-status", children: [_jsx("span", { className: "hex-position", children: position }), selection !== null ? (_jsxs(_Fragment, { children: [_jsx(Button, { onClick: () => copyAs('hex'), size: "small", children: labels.hex.copyHex }), _jsx(Button, { onClick: () => copyAs('text'), size: "small", children: labels.hex.copyText })] })) : null, jump === null ? (_jsx(Button, { onClick: openJump, size: "small", ...tooltip(labels.hex.jump, '⌘L'), children: labels.hex.jump })) : (_jsx("input", { "aria-label": labels.hex.jumpLabel, className: "hex-jump field field-sm", onBlur: () => setJump(null), onChange: (event) => setJump(event.target.value), onKeyDown: (event) => {
280
+ if (event.key === 'Enter') {
281
+ event.preventDefault();
282
+ submitJump();
283
+ }
284
+ else if (event.key === 'Escape') {
285
+ event.preventDefault();
286
+ setMessage(null);
287
+ closeJump();
288
+ }
289
+ }, placeholder: labels.hex.jumpPlaceholder, ref: jumpField, spellCheck: false, value: jump }))] })] }));
290
+ }
291
+ export default HexView;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * What the hex view shows and what it must read to show it. Row N starts at
3
+ * byte N × 16, so the screen is named by its top row alone and any row is
4
+ * one bounded read away; a move of any length just changes the top row, so
5
+ * moves made while a read is in flight add up without carrying a remainder.
6
+ */
7
+ /**
8
+ * Bytes one read asks for: 4,096 rows around the screen, so scrolling a few
9
+ * screens either way needs no other read, and a fling's reads stay cheap.
10
+ */
11
+ export declare const HEX_READ_BYTES: number;
12
+ /** Bytes the view holds from one read: `bytes` from `offset`, and whether they reach the file's end. */
13
+ export interface HexChunk {
14
+ readonly offset: number;
15
+ readonly bytes: Uint8Array;
16
+ readonly eof: boolean;
17
+ }
18
+ /** One row on screen: its first byte's offset and its bytes, 16 or fewer on the last row. */
19
+ export interface HexRow {
20
+ readonly offset: number;
21
+ readonly bytes: Uint8Array;
22
+ }
23
+ /**
24
+ * Where the readable bytes end after a read, given `end`, where they ended
25
+ * before it: less when the read reached the end of a file that has since
26
+ * shrunk, and never more, since the view does not tail a file that grew.
27
+ * Null when the read came back empty from past the end, which says the file
28
+ * is shorter but not by how much: the view then asks the file's size rather
29
+ * than step back a read at a time.
30
+ */
31
+ export declare function endAfterRead(chunk: HexChunk, end: number): number | null;
32
+ /** The last top row: the one that shows the file's last row at the bottom of a screen of `fullRows` whole rows. */
33
+ export declare const lastTopRow: (end: number, fullRows: number) => number;
34
+ /** A top row kept between the first row and the last screen; Infinity is the last screen. */
35
+ export declare const clampTop: (row: number, end: number, fullRows: number) => number;
36
+ /**
37
+ * The one read for a screen starting at row `top`: `HEX_READ_BYTES` from a
38
+ * row boundary, centred on the screen so it serves moves either way.
39
+ */
40
+ export declare function readWindowFor(top: number, screenRows: number): {
41
+ readonly offset: number;
42
+ readonly length: number;
43
+ };
44
+ /**
45
+ * Whether `chunk` holds the screen starting at row `top`: its first byte,
46
+ * and every byte through the screen's last or the end of the file.
47
+ */
48
+ export declare function covers(chunk: HexChunk | null, top: number, screenRows: number): boolean;
49
+ /** Up to `screenRows` rows from row `top` that `chunk` holds, stopping at `end`. */
50
+ export declare function rowsFrom(chunk: HexChunk, top: number, screenRows: number, end: number): HexRow[];
51
+ /**
52
+ * What the scrollbar spans for a file of `sizeBytes` on a screen of
53
+ * `fullRows` whole rows: bytes rounded up to whole rows, so the bottom of the
54
+ * track is the last screen.
55
+ */
56
+ export declare const hexScrollRange: (sizeBytes: number, fullRows: number) => {
57
+ readonly total: number;
58
+ readonly visible: number;
59
+ };
60
+ /** The row holding a byte, which is where a thumb pointing at that byte lands. */
61
+ export declare const rowOfByte: (offset: number) => number;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * What the hex view shows and what it must read to show it. Row N starts at
3
+ * byte N × 16, so the screen is named by its top row alone and any row is
4
+ * one bounded read away; a move of any length just changes the top row, so
5
+ * moves made while a read is in flight add up without carrying a remainder.
6
+ */
7
+ import { BYTES_PER_ROW, rowCount } from './HexRows.logic.js';
8
+ /**
9
+ * Bytes one read asks for: 4,096 rows around the screen, so scrolling a few
10
+ * screens either way needs no other read, and a fling's reads stay cheap.
11
+ */
12
+ export const HEX_READ_BYTES = 64 * 1024;
13
+ /**
14
+ * Where the readable bytes end after a read, given `end`, where they ended
15
+ * before it: less when the read reached the end of a file that has since
16
+ * shrunk, and never more, since the view does not tail a file that grew.
17
+ * Null when the read came back empty from past the end, which says the file
18
+ * is shorter but not by how much: the view then asks the file's size rather
19
+ * than step back a read at a time.
20
+ */
21
+ export function endAfterRead(chunk, end) {
22
+ if (!chunk.eof)
23
+ return end;
24
+ if (chunk.bytes.length === 0 && chunk.offset > 0)
25
+ return null;
26
+ return Math.min(end, chunk.offset + chunk.bytes.length);
27
+ }
28
+ /** The last top row: the one that shows the file's last row at the bottom of a screen of `fullRows` whole rows. */
29
+ export const lastTopRow = (end, fullRows) => Math.max(0, rowCount(end) - Math.max(1, fullRows));
30
+ /** A top row kept between the first row and the last screen; Infinity is the last screen. */
31
+ export const clampTop = (row, end, fullRows) => Math.max(0, Math.min(Math.floor(row), lastTopRow(end, fullRows)));
32
+ /**
33
+ * The one read for a screen starting at row `top`: `HEX_READ_BYTES` from a
34
+ * row boundary, centred on the screen so it serves moves either way.
35
+ */
36
+ export function readWindowFor(top, screenRows) {
37
+ const screenBytes = screenRows * BYTES_PER_ROW;
38
+ const before = Math.max(0, Math.floor((HEX_READ_BYTES - screenBytes) / 2));
39
+ const start = Math.max(0, top * BYTES_PER_ROW - before);
40
+ return { offset: start - (start % BYTES_PER_ROW), length: HEX_READ_BYTES };
41
+ }
42
+ /**
43
+ * Whether `chunk` holds the screen starting at row `top`: its first byte,
44
+ * and every byte through the screen's last or the end of the file.
45
+ */
46
+ export function covers(chunk, top, screenRows) {
47
+ if (chunk === null)
48
+ return false;
49
+ const from = top * BYTES_PER_ROW;
50
+ const to = (top + screenRows) * BYTES_PER_ROW;
51
+ return chunk.offset <= from && (chunk.eof || chunk.offset + chunk.bytes.length >= to);
52
+ }
53
+ /** Up to `screenRows` rows from row `top` that `chunk` holds, stopping at `end`. */
54
+ export function rowsFrom(chunk, top, screenRows, end) {
55
+ const held = chunk.offset + chunk.bytes.length;
56
+ const rows = [];
57
+ for (let index = 0; index < screenRows; index += 1) {
58
+ const offset = (top + index) * BYTES_PER_ROW;
59
+ const stop = Math.min(offset + BYTES_PER_ROW, end, held);
60
+ if (offset < chunk.offset || offset >= stop)
61
+ break;
62
+ rows.push({
63
+ offset,
64
+ bytes: chunk.bytes.subarray(offset - chunk.offset, stop - chunk.offset)
65
+ });
66
+ }
67
+ return rows;
68
+ }
69
+ /**
70
+ * What the scrollbar spans for a file of `sizeBytes` on a screen of
71
+ * `fullRows` whole rows: bytes rounded up to whole rows, so the bottom of the
72
+ * track is the last screen.
73
+ */
74
+ export const hexScrollRange = (sizeBytes, fullRows) => ({
75
+ total: rowCount(sizeBytes) * BYTES_PER_ROW,
76
+ visible: Math.max(1, fullRows) * BYTES_PER_ROW
77
+ });
78
+ /** The row holding a byte, which is where a thumb pointing at that byte lands. */
79
+ export const rowOfByte = (offset) => Math.floor(offset / BYTES_PER_ROW);
@@ -0,0 +1,19 @@
1
+ import { type ReactElement } from 'react';
2
+ import type { ViewerViewProps } from './ViewerViews.js';
3
+ /**
4
+ * The image view: Chromium decodes the file straight from its media URL
5
+ * (`info.mediaUrl`) into an `<img>`, so animated GIF, APNG, and
6
+ * WebP play, and nothing here parses the format. An SVG shows the same way,
7
+ * and as an image Chromium runs none of its scripts and loads nothing it
8
+ * references. It opens fitted to the window, over a checkerboard that shows
9
+ * through transparency. ⌘+ and ⌘- step the zoom about the centre, ⌘0 shows
10
+ * actual size, ⌘9 fits again; Command with the wheel, or a pinch, zooms
11
+ * about the pointer; a drag, the wheel, or the arrows pan an image larger
12
+ * than the window. The status bar
13
+ * gives the pixel dimensions, read from the decoded image, and the zoom.
14
+ * An SVG with no size of its own says so instead, and fits by filling the
15
+ * window, since it has no actual size to keep. A file Chromium cannot decode
16
+ * hands the window to its fallback view with a note: hex, or an SVG's source.
17
+ */
18
+ declare function ImageView({ info, onFallback }: ViewerViewProps): ReactElement;
19
+ export default ImageView;