@bigpixelrocket/uiok 0.3.0 → 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.
- package/CHANGELOG.md +23 -1
- package/dist/dialog/ConfirmDialog.d.ts +7 -1
- package/dist/dialog/ConfirmDialog.js +2 -2
- package/dist/dialog/ProgressDialog.d.ts +7 -1
- package/dist/dialog/ProgressDialog.js +2 -2
- package/dist/dialog/TypedNameDialog.d.ts +8 -0
- package/dist/field/Check.d.ts +9 -2
- package/dist/field/Check.js +5 -4
- package/dist/field/Controls.d.ts +198 -0
- package/dist/field/Controls.js +94 -0
- package/dist/field/FieldLayout.d.ts +126 -0
- package/dist/field/FieldLayout.js +89 -0
- package/dist/field/index.d.ts +9 -6
- package/dist/field/index.js +9 -6
- package/dist/frame/Dock.js +1 -1
- package/dist/frame/SidebarResizer.js +1 -1
- package/dist/frame/Tree.d.ts +9 -2
- package/dist/frame/Tree.js +29 -6
- package/dist/labels/UiokLabels.d.ts +3 -0
- package/dist/labels/UiokLabels.js +3 -1
- package/dist/labels/index.d.ts +1 -0
- package/dist/labels/index.js +1 -0
- package/dist/labels/viewer.d.ts +193 -0
- package/dist/labels/viewer.js +124 -0
- package/dist/listing/PaneMessage.d.ts +28 -0
- package/dist/listing/PaneMessage.js +12 -0
- package/dist/listing/index.d.ts +4 -2
- package/dist/listing/index.js +4 -2
- package/dist/styles.css +3 -0
- package/dist/surface/Card.d.ts +18 -0
- package/dist/surface/Card.js +10 -0
- package/dist/surface/Notice.d.ts +45 -0
- package/dist/surface/Notice.js +27 -0
- package/dist/surface/index.d.ts +5 -3
- package/dist/surface/index.js +5 -3
- package/dist/themes/themes.generated.css +1 -0
- package/dist/themes/tokens.js +4 -1
- package/dist/viewer/AudioView.d.ts +13 -0
- package/dist/viewer/AudioView.js +25 -0
- package/dist/viewer/HexJump.logic.d.ts +16 -0
- package/dist/viewer/HexJump.logic.js +27 -0
- package/dist/viewer/HexRows.logic.d.ts +55 -0
- package/dist/viewer/HexRows.logic.js +84 -0
- package/dist/viewer/HexSelection.logic.d.ts +57 -0
- package/dist/viewer/HexSelection.logic.js +68 -0
- package/dist/viewer/HexView.d.ts +10 -0
- package/dist/viewer/HexView.js +291 -0
- package/dist/viewer/HexViewport.logic.d.ts +61 -0
- package/dist/viewer/HexViewport.logic.js +79 -0
- package/dist/viewer/ImageView.d.ts +19 -0
- package/dist/viewer/ImageView.js +230 -0
- package/dist/viewer/ImageZoom.logic.d.ts +65 -0
- package/dist/viewer/ImageZoom.logic.js +119 -0
- package/dist/viewer/LatestRead.logic.d.ts +27 -0
- package/dist/viewer/LatestRead.logic.js +55 -0
- package/dist/viewer/MediaControls.d.ts +25 -0
- package/dist/viewer/MediaControls.js +183 -0
- package/dist/viewer/MediaPlayer.logic.d.ts +53 -0
- package/dist/viewer/MediaPlayer.logic.js +68 -0
- package/dist/viewer/PdfView.d.ts +23 -0
- package/dist/viewer/PdfView.js +25 -0
- package/dist/viewer/QuietFocus.d.ts +19 -0
- package/dist/viewer/QuietFocus.js +27 -0
- package/dist/viewer/ScaledScroll.logic.d.ts +30 -0
- package/dist/viewer/ScaledScroll.logic.js +28 -0
- package/dist/viewer/ScaledScrollbar.d.ts +19 -0
- package/dist/viewer/ScaledScrollbar.js +71 -0
- package/dist/viewer/SyntaxHighlighter.d.ts +29 -0
- package/dist/viewer/SyntaxHighlighter.js +144 -0
- package/dist/viewer/SyntaxLanguage.logic.d.ts +110 -0
- package/dist/viewer/SyntaxLanguage.logic.js +283 -0
- package/dist/viewer/SyntaxService.d.ts +75 -0
- package/dist/viewer/SyntaxService.js +49 -0
- package/dist/viewer/SyntaxSession.logic.d.ts +78 -0
- package/dist/viewer/SyntaxSession.logic.js +221 -0
- package/dist/viewer/SyntaxWorker.d.ts +6 -0
- package/dist/viewer/SyntaxWorker.js +8 -0
- package/dist/viewer/TextEncoding.logic.d.ts +35 -0
- package/dist/viewer/TextEncoding.logic.js +58 -0
- package/dist/viewer/TextRows.logic.d.ts +86 -0
- package/dist/viewer/TextRows.logic.js +241 -0
- package/dist/viewer/TextSelection.logic.d.ts +97 -0
- package/dist/viewer/TextSelection.logic.js +139 -0
- package/dist/viewer/TextView.d.ts +13 -0
- package/dist/viewer/TextView.js +448 -0
- package/dist/viewer/TextViewport.logic.d.ts +70 -0
- package/dist/viewer/TextViewport.logic.js +116 -0
- package/dist/viewer/VideoView.d.ts +18 -0
- package/dist/viewer/VideoView.js +53 -0
- package/dist/viewer/ViewerClipboard.d.ts +30 -0
- package/dist/viewer/ViewerClipboard.js +70 -0
- package/dist/viewer/ViewerFrame.logic.d.ts +61 -0
- package/dist/viewer/ViewerFrame.logic.js +130 -0
- package/dist/viewer/ViewerKeys.d.ts +16 -0
- package/dist/viewer/ViewerKeys.js +14 -0
- package/dist/viewer/ViewerScope.d.ts +12 -0
- package/dist/viewer/ViewerScope.js +22 -0
- package/dist/viewer/ViewerViews.d.ts +28 -0
- package/dist/viewer/ViewerViews.js +22 -0
- package/dist/viewer/ViewerWindow.d.ts +53 -0
- package/dist/viewer/ViewerWindow.js +219 -0
- package/dist/viewer/index.d.ts +12 -0
- package/dist/viewer/index.js +12 -0
- package/dist/viewer/types.d.ts +151 -0
- package/dist/viewer/types.js +26 -0
- package/dist/viewer/useElementHeight.d.ts +6 -0
- package/dist/viewer/useElementHeight.js +22 -0
- package/dist/viewer/useElementSize.d.ts +7 -0
- package/dist/viewer/useElementSize.js +24 -0
- package/dist/viewer/useEscapeToClear.d.ts +8 -0
- package/dist/viewer/useEscapeToClear.js +26 -0
- package/dist/viewer/useHexDocument.d.ts +41 -0
- package/dist/viewer/useHexDocument.js +144 -0
- package/dist/viewer/useMediaElement.d.ts +10 -0
- package/dist/viewer/useMediaElement.js +24 -0
- package/dist/viewer/useSyntaxHighlight.d.ts +24 -0
- package/dist/viewer/useSyntaxHighlight.js +133 -0
- package/dist/viewer/useTextDocument.d.ts +66 -0
- package/dist/viewer/useTextDocument.js +245 -0
- package/dist/viewer/viewer.css +645 -0
- package/package.json +7 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* One line that says something about a listing, where its rows stand: a
|
|
4
|
+
* hint, a refusal led by the danger glyph, a warning led by the warning
|
|
5
|
+
* glyph, or the line of a list with no rows, in the interface face from the
|
|
6
|
+
* rows' inset, inside a listing root. For what `Listing`'s `empty` and
|
|
7
|
+
* `PageNote` do not cover. Draws `.pane-message` (`.danger`, `.warning`,
|
|
8
|
+
* `.empty`).
|
|
9
|
+
*/
|
|
10
|
+
export function PaneMessage({ children, tone, live = false }) {
|
|
11
|
+
return (_jsx("p", { className: tone === undefined ? 'pane-message' : `pane-message ${tone}`, role: live ? 'status' : undefined, children: children }));
|
|
12
|
+
}
|
package/dist/listing/index.d.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* Listings: the column strip, rows and cells in the listing look (scoped by
|
|
3
3
|
* `.listing-root`), the row cursor they share with the keys, column widths,
|
|
4
4
|
* and the state, path, and terminal-well cells; `CurrentDot` marks the
|
|
5
|
-
* current one in a list,
|
|
6
|
-
* yet or one that could not load
|
|
5
|
+
* current one in a list, `EmptyState` fills a pane with nothing in it
|
|
6
|
+
* yet or one that could not load, and `PaneMessage` is one line about a
|
|
7
|
+
* listing (a hint, a refusal, a warning).
|
|
7
8
|
*/
|
|
8
9
|
export { type SortDirection } from '../labels/listing.js';
|
|
9
10
|
export { CurrentDot, type CurrentDotProps } from './CurrentDot.js';
|
|
10
11
|
export { EmptyState, type EmptyStateProps, type EmptyStateStep } from './EmptyState.js';
|
|
11
12
|
export { ACTION_COLUMN, Cell, column, ICON_LINK_PX, iconLinksColumn, linksColumn, Listing, PathCell, Row, RowCursorContext, StateMark, Strip, WellColumn, type CellProps, type ColumnSort, type ListingColumn, type ListingProps, type PathCellProps, type RowCursor, type RowProps, type StateMarkProps, type StateTone, type StripProps, type WellColumnProps } from './Listing.js';
|
|
13
|
+
export { PaneMessage, type PaneMessageProps, type PaneMessageTone } from './PaneMessage.js';
|
|
12
14
|
export { pathParts, type PathParts } from './PathParts.logic.js';
|
package/dist/listing/index.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* Listings: the column strip, rows and cells in the listing look (scoped by
|
|
3
3
|
* `.listing-root`), the row cursor they share with the keys, column widths,
|
|
4
4
|
* and the state, path, and terminal-well cells; `CurrentDot` marks the
|
|
5
|
-
* current one in a list,
|
|
6
|
-
* yet or one that could not load
|
|
5
|
+
* current one in a list, `EmptyState` fills a pane with nothing in it
|
|
6
|
+
* yet or one that could not load, and `PaneMessage` is one line about a
|
|
7
|
+
* listing (a hint, a refusal, a warning).
|
|
7
8
|
*/
|
|
8
9
|
export {} from '../labels/listing.js';
|
|
9
10
|
export { CurrentDot } from './CurrentDot.js';
|
|
10
11
|
export { EmptyState } from './EmptyState.js';
|
|
11
12
|
export { ACTION_COLUMN, Cell, column, ICON_LINK_PX, iconLinksColumn, linksColumn, Listing, PathCell, Row, RowCursorContext, StateMark, Strip, WellColumn } from './Listing.js';
|
|
13
|
+
export { PaneMessage } from './PaneMessage.js';
|
|
12
14
|
export { pathParts } from './PathParts.logic.js';
|
package/dist/styles.css
CHANGED
|
@@ -39,6 +39,9 @@
|
|
|
39
39
|
@import './shell/shell.css';
|
|
40
40
|
@import './frame/frame.css';
|
|
41
41
|
@import './log/log.css';
|
|
42
|
+
/* The file viewer (@bigpixelrocket/uiok/viewer): its header, text, hex,
|
|
43
|
+
image, and media views. */
|
|
44
|
+
@import './viewer/viewer.css';
|
|
42
45
|
|
|
43
46
|
/* ---- What the browser would otherwise draw in its own colours ---- */
|
|
44
47
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
/** Props for {@link Card}. */
|
|
3
|
+
export interface CardProps {
|
|
4
|
+
/** One subject's lines: a heading, facts, a field grid, actions. */
|
|
5
|
+
readonly children: ReactNode;
|
|
6
|
+
/**
|
|
7
|
+
* The card's accessible name, which makes it a `region` landmark; leave
|
|
8
|
+
* it out for a card that is one part of a page among many alike.
|
|
9
|
+
*/
|
|
10
|
+
readonly label?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A lifted panel that groups one subject's lines (an account, an update, a
|
|
14
|
+
* connection's summary), framed like every framed surface, at the surface
|
|
15
|
+
* inset at both ends whatever margins its first and last children bring.
|
|
16
|
+
* Draws `.card`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Card({ children, label }: CardProps): ReactElement;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A lifted panel that groups one subject's lines (an account, an update, a
|
|
4
|
+
* connection's summary), framed like every framed surface, at the surface
|
|
5
|
+
* inset at both ends whatever margins its first and last children bring.
|
|
6
|
+
* Draws `.card`.
|
|
7
|
+
*/
|
|
8
|
+
export function Card({ children, label }) {
|
|
9
|
+
return label === undefined ? (_jsx("div", { className: "card", children: children })) : (_jsx("section", { "aria-label": label, className: "card", children: children }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A notice's tone: `note` a plain fact, `success` a step that worked,
|
|
4
|
+
* `warning` a state that needs a second look, `danger` a failure.
|
|
5
|
+
*/
|
|
6
|
+
export type NoticeTone = 'note' | 'success' | 'warning' | 'danger';
|
|
7
|
+
/** Props for {@link Notice}. */
|
|
8
|
+
export interface NoticeProps {
|
|
9
|
+
/** The words: a sentence, which may hold `<code>` for a server's or a system's own words. */
|
|
10
|
+
readonly children: ReactNode;
|
|
11
|
+
/** The tone; `note` by default. */
|
|
12
|
+
readonly tone?: NoticeTone;
|
|
13
|
+
/**
|
|
14
|
+
* What leads the line: by default the tone's glyph (Info, CircleCheck,
|
|
15
|
+
* TriangleAlert, CircleAlert); another node in its place (a `Spinner`
|
|
16
|
+
* while work runs); or `null` for none.
|
|
17
|
+
*/
|
|
18
|
+
readonly glyph?: ReactNode;
|
|
19
|
+
/** Small buttons after the words, centred on their first line (a Reload, a Retry). */
|
|
20
|
+
readonly actions?: ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Sets the notice as the window's status line under a header: one line at
|
|
23
|
+
* the window's inset with a hairline under it, its words cut with an
|
|
24
|
+
* ellipsis in a narrow window and given whole as a tooltip. Give
|
|
25
|
+
* `cutText` the words as plain text for that tooltip.
|
|
26
|
+
*/
|
|
27
|
+
readonly band?: boolean;
|
|
28
|
+
/** The words as plain text, for the tooltip a `band` shows while it cuts them. */
|
|
29
|
+
readonly cutText?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The live-region role: `status` (the default) for a line assistive
|
|
32
|
+
* technology reads when it changes, `alert` for a failure it reads at
|
|
33
|
+
* once, or `null` for a notice that is part of the page as it loads.
|
|
34
|
+
*/
|
|
35
|
+
readonly role?: 'status' | 'alert' | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An application's status line, never a web page's alert: a small glyph in
|
|
39
|
+
* the tone's colour, the words in the text colour, and optional small
|
|
40
|
+
* buttons after them, with no fill, frame, or side bar. It sits on the
|
|
41
|
+
* surface it is about (a step, a field, a pane), or, as a `band`, under a
|
|
42
|
+
* window's header until its cause goes. Draws `.notice` (`.notice-danger`,
|
|
43
|
+
* `.notice-warning`, `.notice-success`, `.notice-card`).
|
|
44
|
+
*/
|
|
45
|
+
export declare function Notice({ children, tone, glyph, actions, band, cutText, role }: NoticeProps): ReactElement;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CircleAlert, CircleCheck, Info, TriangleAlert } from 'lucide-react';
|
|
3
|
+
import { ICON_MD } from '../icon/sizes.js';
|
|
4
|
+
import { cutTooltip } from '../tooltip/Tooltip.logic.js';
|
|
5
|
+
const TONE_GLYPH = {
|
|
6
|
+
note: Info,
|
|
7
|
+
success: CircleCheck,
|
|
8
|
+
warning: TriangleAlert,
|
|
9
|
+
danger: CircleAlert
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* An application's status line, never a web page's alert: a small glyph in
|
|
13
|
+
* the tone's colour, the words in the text colour, and optional small
|
|
14
|
+
* buttons after them, with no fill, frame, or side bar. It sits on the
|
|
15
|
+
* surface it is about (a step, a field, a pane), or, as a `band`, under a
|
|
16
|
+
* window's header until its cause goes. Draws `.notice` (`.notice-danger`,
|
|
17
|
+
* `.notice-warning`, `.notice-success`, `.notice-card`).
|
|
18
|
+
*/
|
|
19
|
+
export function Notice({ children, tone = 'note', glyph, actions, band = false, cutText, role = 'status' }) {
|
|
20
|
+
const Glyph = TONE_GLYPH[tone];
|
|
21
|
+
const classes = ['notice'];
|
|
22
|
+
if (tone !== 'note')
|
|
23
|
+
classes.push(`notice-${tone}`);
|
|
24
|
+
if (band)
|
|
25
|
+
classes.push('notice-card');
|
|
26
|
+
return (_jsxs("div", { className: classes.join(' '), role: role ?? undefined, children: [glyph === undefined ? (_jsx(Glyph, { "aria-hidden": true, size: ICON_MD })) : glyph === null ? null : (_jsx("span", { "aria-hidden": true, className: "notice-glyph", children: glyph })), _jsx("span", { className: "notice-text", ...(band ? cutTooltip(cutText) : {}), children: children }), actions ? _jsx("span", { className: "notice-actions", children: actions }) : null] }));
|
|
27
|
+
}
|
package/dist/surface/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Surfaces: `
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Surfaces: `Notice`, an application's status line in a tone; `Card`, a
|
|
3
|
+
* lifted panel for one subject's lines; `GroupSwatch`, a group's colour
|
|
4
|
+
* beside its name; and `Tag`, a small worded tag in a tone.
|
|
5
5
|
*/
|
|
6
|
+
export { Card, type CardProps } from './Card.js';
|
|
7
|
+
export { Notice, type NoticeProps, type NoticeTone } from './Notice.js';
|
|
6
8
|
export { GroupSwatch, type GroupSwatchProps } from './GroupSwatch.js';
|
|
7
9
|
export { Tag, type TagProps, type TagTone } from './Tag.js';
|
package/dist/surface/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Surfaces: `
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Surfaces: `Notice`, an application's status line in a tone; `Card`, a
|
|
3
|
+
* lifted panel for one subject's lines; `GroupSwatch`, a group's colour
|
|
4
|
+
* beside its name; and `Tag`, a small worded tag in a tone.
|
|
5
5
|
*/
|
|
6
|
+
export { Card } from './Card.js';
|
|
7
|
+
export { Notice } from './Notice.js';
|
|
6
8
|
export { GroupSwatch } from './GroupSwatch.js';
|
|
7
9
|
export { Tag } from './Tag.js';
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
--brand-plate: #11111b;
|
|
16
16
|
--brand-plate-dark: color-mix(in srgb, var(--accent) 70%, var(--brand-plate));
|
|
17
17
|
--brand-badge-dark: color-mix(in srgb, var(--success) 70%, var(--brand-plate));
|
|
18
|
+
--letterbox: #000000;
|
|
18
19
|
--ground: var(--bg);
|
|
19
20
|
--surface: var(--bg-panel);
|
|
20
21
|
--surface-header: var(--bg-header);
|
package/dist/themes/tokens.js
CHANGED
|
@@ -945,6 +945,8 @@ export const FIXED_TOKENS = {
|
|
|
945
945
|
'--brand-plate': BRAND_PLATE,
|
|
946
946
|
'--brand-plate-dark': 'color-mix(in srgb, var(--accent) 70%, var(--brand-plate))',
|
|
947
947
|
'--brand-badge-dark': 'color-mix(in srgb, var(--success) 70%, var(--brand-plate))',
|
|
948
|
+
// A video is letterboxed on black in every theme, as a media player shows it.
|
|
949
|
+
'--letterbox': BLACK,
|
|
948
950
|
// Surfaces: the three grounds by role. The body paints the ground once, a
|
|
949
951
|
// panel paints --surface, and what sits inside a panel paints no ground of
|
|
950
952
|
// its own. Surfaces that float over other content add --frost (the base
|
|
@@ -1248,7 +1250,8 @@ const BASE_TOKEN_NAMES = [
|
|
|
1248
1250
|
'--tree-level',
|
|
1249
1251
|
'--tree-indent',
|
|
1250
1252
|
'--log-source',
|
|
1251
|
-
'--log-source-width'
|
|
1253
|
+
'--log-source-width',
|
|
1254
|
+
'--text-gutter-width'
|
|
1252
1255
|
];
|
|
1253
1256
|
/** Every token name uiok defines: the fixed tokens, those a theme sets, and the stylesheet's own. */
|
|
1254
1257
|
const UIOK_TOKEN_NAMES = new Set([
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import type { ViewerViewProps } from './ViewerViews.js';
|
|
3
|
+
/**
|
|
4
|
+
* The audio view: Chromium plays the file straight from its media URL
|
|
5
|
+
* (`info.mediaUrl`) in an `<audio>` element, under the player's
|
|
6
|
+
* control bar (`MediaControls`), and nothing here decodes a format. Only
|
|
7
|
+
* the metadata loads when the window opens, and nothing plays until the
|
|
8
|
+
* user asks; a seek reads from the new position through a range request,
|
|
9
|
+
* never the whole file first. A file Chromium cannot play (a codec it
|
|
10
|
+
* lacks, a decode failure) hands the window to hex with a note saying why.
|
|
11
|
+
*/
|
|
12
|
+
declare function AudioView({ info, onFallback }: ViewerViewProps): ReactElement;
|
|
13
|
+
export default AudioView;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { AudioLines } from 'lucide-react';
|
|
4
|
+
import { useLabels } from '../labels/UiokProvider.js';
|
|
5
|
+
import MediaControls from './MediaControls.js';
|
|
6
|
+
import { mediaFallbackNote } from './MediaPlayer.logic.js';
|
|
7
|
+
import { useMediaElement } from './useMediaElement.js';
|
|
8
|
+
/** The stage's sound mark, larger than any control glyph: it stands in for a picture. */
|
|
9
|
+
const STAGE_GLYPH = 64;
|
|
10
|
+
/**
|
|
11
|
+
* The audio view: Chromium plays the file straight from its media URL
|
|
12
|
+
* (`info.mediaUrl`) in an `<audio>` element, under the player's
|
|
13
|
+
* control bar (`MediaControls`), and nothing here decodes a format. Only
|
|
14
|
+
* the metadata loads when the window opens, and nothing plays until the
|
|
15
|
+
* user asks; a seek reads from the new position through a range request,
|
|
16
|
+
* never the whole file first. A file Chromium cannot play (a codec it
|
|
17
|
+
* lacks, a decode failure) hands the window to hex with a note saying why.
|
|
18
|
+
*/
|
|
19
|
+
function AudioView({ info, onFallback }) {
|
|
20
|
+
const labels = useLabels().viewer;
|
|
21
|
+
const [audioRef, audio] = useMediaElement(info.mediaUrl);
|
|
22
|
+
const [player, setPlayer] = useState(null);
|
|
23
|
+
return (_jsxs("div", { className: "audio-view", ref: setPlayer, children: [_jsxs("div", { className: "audio-stage", children: [_jsx(AudioLines, { absoluteStrokeWidth: true, "aria-hidden": true, size: STAGE_GLYPH }), _jsx("audio", { "aria-label": info.name, onError: (event) => onFallback(mediaFallbackNote('audio', event.currentTarget.error?.code ?? null, labels)), preload: "metadata", ref: audioRef })] }), _jsx(MediaControls, { media: audio, player: player })] }));
|
|
24
|
+
}
|
|
25
|
+
export default AudioView;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jump to offset in the hex view. An offset is typed in hex, as the offset
|
|
3
|
+
* column prints it, with or without a `0x` prefix: `1F40` and `0x1F40` are
|
|
4
|
+
* the same byte. Decimal is not read, so a number never means two bytes.
|
|
5
|
+
* An offset past the file's last byte is refused with a message rather than
|
|
6
|
+
* moved, so a typo never lands somewhere that looks right.
|
|
7
|
+
*/
|
|
8
|
+
import type { ViewerLabels } from '../labels/viewer.js';
|
|
9
|
+
/** A byte to go to, or why the typed offset is not one. */
|
|
10
|
+
export type JumpResult = {
|
|
11
|
+
readonly offset: number;
|
|
12
|
+
} | {
|
|
13
|
+
readonly error: string;
|
|
14
|
+
};
|
|
15
|
+
/** The byte `input` names in a file of `sizeBytes` bytes, or why it names none. */
|
|
16
|
+
export declare function parseJumpOffset(input: string, sizeBytes: number, labels: ViewerLabels): JumpResult;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jump to offset in the hex view. An offset is typed in hex, as the offset
|
|
3
|
+
* column prints it, with or without a `0x` prefix: `1F40` and `0x1F40` are
|
|
4
|
+
* the same byte. Decimal is not read, so a number never means two bytes.
|
|
5
|
+
* An offset past the file's last byte is refused with a message rather than
|
|
6
|
+
* moved, so a typo never lands somewhere that looks right.
|
|
7
|
+
*/
|
|
8
|
+
import { formatOffset, offsetDigits } from './HexRows.logic.js';
|
|
9
|
+
const HEX_OFFSET = /^(?:0x)?([0-9a-f]+)$/i;
|
|
10
|
+
/** The byte `input` names in a file of `sizeBytes` bytes, or why it names none. */
|
|
11
|
+
export function parseJumpOffset(input, sizeBytes, labels) {
|
|
12
|
+
const match = HEX_OFFSET.exec(input.trim());
|
|
13
|
+
if (match?.[1] === undefined)
|
|
14
|
+
return { error: labels.hex.jumpInvalid };
|
|
15
|
+
if (sizeBytes <= 0)
|
|
16
|
+
return { error: labels.hex.jumpEmpty };
|
|
17
|
+
// Read as a bigint, so an offset too long for a number is still past the end.
|
|
18
|
+
const offset = BigInt(`0x${match[1]}`);
|
|
19
|
+
const last = sizeBytes - 1;
|
|
20
|
+
if (offset > BigInt(last)) {
|
|
21
|
+
const digits = offsetDigits(sizeBytes);
|
|
22
|
+
return {
|
|
23
|
+
error: labels.hex.jumpPastEnd(match[1].toUpperCase(), formatOffset(last, digits))
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { offset: Number(offset) };
|
|
27
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hex view's row layout. Row N holds bytes N×16 to N×16+15, printed as
|
|
3
|
+
*
|
|
4
|
+
* 00000000 4D 5A 50 00 02 00 00 00-04 00 0F 00 FF FF 00 00 MZP.............
|
|
5
|
+
*
|
|
6
|
+
* an offset of at least 8 uppercase hex digits (wider when the file's last
|
|
7
|
+
* offset needs more, the same width on every row), the 16 bytes in two groups
|
|
8
|
+
* of 8 joined by `-`, and the bytes again as text: printable ASCII as itself,
|
|
9
|
+
* every other byte as `.`. A short last row is padded so its text lines up.
|
|
10
|
+
*/
|
|
11
|
+
/** Bytes per row; row N starts at byte N × 16. */
|
|
12
|
+
export declare const BYTES_PER_ROW = 16;
|
|
13
|
+
/** Characters of the hex column: two digits a byte and one separator between bytes. */
|
|
14
|
+
export declare const HEX_COLUMN_CHARS: number;
|
|
15
|
+
/** Spaces between the offset and the hex column, and between the hex and text columns. */
|
|
16
|
+
export declare const COLUMN_GAP = " ";
|
|
17
|
+
/** The byte as two uppercase hex digits. */
|
|
18
|
+
export declare const hexByte: (byte: number) => string;
|
|
19
|
+
/** The byte as the text column prints it. */
|
|
20
|
+
export declare const textChar: (byte: number) => string;
|
|
21
|
+
/** Rows a file of `sizeBytes` bytes takes, the last one possibly short. */
|
|
22
|
+
export declare const rowCount: (sizeBytes: number) => number;
|
|
23
|
+
/**
|
|
24
|
+
* The offset column's width for a file: 8 digits, or as many as its last
|
|
25
|
+
* offset needs. A file of exactly 4 GB ends at FFFFFFFF and keeps 8; one byte
|
|
26
|
+
* more needs 9.
|
|
27
|
+
*/
|
|
28
|
+
export declare function offsetDigits(sizeBytes: number): number;
|
|
29
|
+
/** An offset in uppercase hex, zero-padded to `digits`. */
|
|
30
|
+
export declare const formatOffset: (offset: number, digits: number) => string;
|
|
31
|
+
/**
|
|
32
|
+
* A row's hex column: up to 16 bytes, a space between bytes and a `-`
|
|
33
|
+
* between the two groups, padded with spaces to the full column so the text
|
|
34
|
+
* column after it lines up on a short last row.
|
|
35
|
+
*/
|
|
36
|
+
export declare function hexColumn(bytes: Uint8Array): string;
|
|
37
|
+
/** A row's text column: one character a byte, padded with spaces to a full row. */
|
|
38
|
+
export declare function textColumn(bytes: Uint8Array): string;
|
|
39
|
+
/** A whole row as one line, the way the view lays it out. */
|
|
40
|
+
export declare function formatRow(offset: number, bytes: Uint8Array, digits: number): string;
|
|
41
|
+
/** Characters in a row's line: offset, gap, hex column, gap, text column. */
|
|
42
|
+
export declare const lineChars: (digits: number) => number;
|
|
43
|
+
/** Which column a byte was picked in, which decides the form copy takes. */
|
|
44
|
+
export type HexColumn = 'hex' | 'text';
|
|
45
|
+
/**
|
|
46
|
+
* The byte under character `char` of a row's line, counted from the line's
|
|
47
|
+
* start, and the column it is in. The offset and the gap after it point at
|
|
48
|
+
* the first byte; the gap between the columns splits between the hex
|
|
49
|
+
* column's last byte and the text column's first; anything past the text
|
|
50
|
+
* column points at the last byte.
|
|
51
|
+
*/
|
|
52
|
+
export declare function cellAt(char: number, digits: number): {
|
|
53
|
+
readonly column: HexColumn;
|
|
54
|
+
readonly index: number;
|
|
55
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hex view's row layout. Row N holds bytes N×16 to N×16+15, printed as
|
|
3
|
+
*
|
|
4
|
+
* 00000000 4D 5A 50 00 02 00 00 00-04 00 0F 00 FF FF 00 00 MZP.............
|
|
5
|
+
*
|
|
6
|
+
* an offset of at least 8 uppercase hex digits (wider when the file's last
|
|
7
|
+
* offset needs more, the same width on every row), the 16 bytes in two groups
|
|
8
|
+
* of 8 joined by `-`, and the bytes again as text: printable ASCII as itself,
|
|
9
|
+
* every other byte as `.`. A short last row is padded so its text lines up.
|
|
10
|
+
*/
|
|
11
|
+
/** Bytes per row; row N starts at byte N × 16. */
|
|
12
|
+
export const BYTES_PER_ROW = 16;
|
|
13
|
+
/** Bytes per group; a `-` joins the two groups of a row. */
|
|
14
|
+
const GROUP_BYTES = 8;
|
|
15
|
+
/** Characters of the hex column: two digits a byte and one separator between bytes. */
|
|
16
|
+
export const HEX_COLUMN_CHARS = BYTES_PER_ROW * 3 - 1;
|
|
17
|
+
/** Spaces between the offset and the hex column, and between the hex and text columns. */
|
|
18
|
+
export const COLUMN_GAP = ' ';
|
|
19
|
+
/** The fewest offset digits, enough for any offset below 4 GB. */
|
|
20
|
+
const MIN_OFFSET_DIGITS = 8;
|
|
21
|
+
const HEX_DIGITS = Array.from({ length: 256 }, (_, byte) => byte.toString(16).toUpperCase().padStart(2, '0'));
|
|
22
|
+
/** Printable ASCII, 0x20 to 0x7E, prints as itself; every other byte as `.`. */
|
|
23
|
+
const TEXT_CHARS = Array.from({ length: 256 }, (_, byte) => byte >= 0x20 && byte <= 0x7e ? String.fromCharCode(byte) : '.');
|
|
24
|
+
/** The byte as two uppercase hex digits. */
|
|
25
|
+
export const hexByte = (byte) => HEX_DIGITS[byte] ?? '??';
|
|
26
|
+
/** The byte as the text column prints it. */
|
|
27
|
+
export const textChar = (byte) => TEXT_CHARS[byte] ?? '.';
|
|
28
|
+
/** Rows a file of `sizeBytes` bytes takes, the last one possibly short. */
|
|
29
|
+
export const rowCount = (sizeBytes) => Math.ceil(sizeBytes / BYTES_PER_ROW);
|
|
30
|
+
/**
|
|
31
|
+
* The offset column's width for a file: 8 digits, or as many as its last
|
|
32
|
+
* offset needs. A file of exactly 4 GB ends at FFFFFFFF and keeps 8; one byte
|
|
33
|
+
* more needs 9.
|
|
34
|
+
*/
|
|
35
|
+
export function offsetDigits(sizeBytes) {
|
|
36
|
+
return Math.max(MIN_OFFSET_DIGITS, Math.max(0, sizeBytes - 1).toString(16).length);
|
|
37
|
+
}
|
|
38
|
+
/** An offset in uppercase hex, zero-padded to `digits`. */
|
|
39
|
+
export const formatOffset = (offset, digits) => offset.toString(16).toUpperCase().padStart(digits, '0');
|
|
40
|
+
/**
|
|
41
|
+
* A row's hex column: up to 16 bytes, a space between bytes and a `-`
|
|
42
|
+
* between the two groups, padded with spaces to the full column so the text
|
|
43
|
+
* column after it lines up on a short last row.
|
|
44
|
+
*/
|
|
45
|
+
export function hexColumn(bytes) {
|
|
46
|
+
let column = '';
|
|
47
|
+
for (let index = 0; index < BYTES_PER_ROW; index += 1) {
|
|
48
|
+
const byte = bytes[index];
|
|
49
|
+
if (index > 0)
|
|
50
|
+
column += index === GROUP_BYTES && byte !== undefined ? '-' : ' ';
|
|
51
|
+
column += byte === undefined ? ' ' : hexByte(byte);
|
|
52
|
+
}
|
|
53
|
+
return column;
|
|
54
|
+
}
|
|
55
|
+
/** A row's text column: one character a byte, padded with spaces to a full row. */
|
|
56
|
+
export function textColumn(bytes) {
|
|
57
|
+
let column = '';
|
|
58
|
+
for (let index = 0; index < BYTES_PER_ROW; index += 1) {
|
|
59
|
+
const byte = bytes[index];
|
|
60
|
+
column += byte === undefined ? ' ' : textChar(byte);
|
|
61
|
+
}
|
|
62
|
+
return column;
|
|
63
|
+
}
|
|
64
|
+
/** A whole row as one line, the way the view lays it out. */
|
|
65
|
+
export function formatRow(offset, bytes, digits) {
|
|
66
|
+
return [formatOffset(offset, digits), hexColumn(bytes), textColumn(bytes)].join(COLUMN_GAP);
|
|
67
|
+
}
|
|
68
|
+
/** Characters in a row's line: offset, gap, hex column, gap, text column. */
|
|
69
|
+
export const lineChars = (digits) => digits + COLUMN_GAP.length * 2 + HEX_COLUMN_CHARS + BYTES_PER_ROW;
|
|
70
|
+
/**
|
|
71
|
+
* The byte under character `char` of a row's line, counted from the line's
|
|
72
|
+
* start, and the column it is in. The offset and the gap after it point at
|
|
73
|
+
* the first byte; the gap between the columns splits between the hex
|
|
74
|
+
* column's last byte and the text column's first; anything past the text
|
|
75
|
+
* column points at the last byte.
|
|
76
|
+
*/
|
|
77
|
+
export function cellAt(char, digits) {
|
|
78
|
+
const hexStart = digits + COLUMN_GAP.length;
|
|
79
|
+
const textStart = hexStart + HEX_COLUMN_CHARS + COLUMN_GAP.length;
|
|
80
|
+
const clampIndex = (index) => Math.min(BYTES_PER_ROW - 1, Math.max(0, Math.floor(index)));
|
|
81
|
+
return char < textStart - 1
|
|
82
|
+
? { column: 'hex', index: clampIndex((char - hexStart) / 3) }
|
|
83
|
+
: { column: 'text', index: clampIndex(char - textStart) };
|
|
84
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hex view's selection and copy. A selection is a range of bytes, both
|
|
3
|
+
* ends included, kept in file terms so it survives scrolling, and remembers
|
|
4
|
+
* the column it was made in: Copy gives the hex digits for a selection made
|
|
5
|
+
* in the hex column and the text for one made in the text column, and the
|
|
6
|
+
* status bar copies either form. Copy reads at most one bounded read and
|
|
7
|
+
* refuses a larger selection with a message instead of reading more.
|
|
8
|
+
*/
|
|
9
|
+
import type { ViewerLabels } from '../labels/viewer.js';
|
|
10
|
+
import { type HexColumn } from './HexRows.logic.js';
|
|
11
|
+
/** Where a selection started and where it was taken to, both bytes included, and the column it was made in. */
|
|
12
|
+
export interface HexSelection {
|
|
13
|
+
readonly anchor: number;
|
|
14
|
+
readonly focus: number;
|
|
15
|
+
readonly column: HexColumn;
|
|
16
|
+
}
|
|
17
|
+
/** The largest selection copy reads, in bytes. */
|
|
18
|
+
export declare const MAX_HEX_COPY_BYTES: number;
|
|
19
|
+
/** Copy for a selection larger than copy will read. */
|
|
20
|
+
export declare function hexSelectionTooLarge(labels: ViewerLabels): string;
|
|
21
|
+
/** The selected bytes as [start, end): its first byte and one past its last. */
|
|
22
|
+
export declare function selectedRange(selection: HexSelection): {
|
|
23
|
+
readonly start: number;
|
|
24
|
+
readonly end: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The part of a row of `length` bytes from `rowOffset` a selection covers,
|
|
28
|
+
* as byte indexes [from, to) into the row, or null when it covers none.
|
|
29
|
+
*/
|
|
30
|
+
export declare function selectedCells(selection: HexSelection, rowOffset: number, length: number): {
|
|
31
|
+
readonly from: number;
|
|
32
|
+
readonly to: number;
|
|
33
|
+
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* The bytes copy reads for a selection, cut at `fileEnd`; null when that is
|
|
36
|
+
* more than copy will read.
|
|
37
|
+
*/
|
|
38
|
+
export declare function copyRange(selection: HexSelection, fileEnd: number): {
|
|
39
|
+
readonly offset: number;
|
|
40
|
+
readonly length: number;
|
|
41
|
+
} | null;
|
|
42
|
+
/** Bytes as copy gives them in hex: two uppercase digits each, a space between. */
|
|
43
|
+
export declare function hexCopy(bytes: Uint8Array): string;
|
|
44
|
+
/** Bytes as copy gives them as text: what the text column shows, `.` for every byte outside printable ASCII. */
|
|
45
|
+
export declare function textCopy(bytes: Uint8Array): string;
|
|
46
|
+
/** The steps Shift with an arrow takes the selection's moving end: a row up or down, a byte sideways. */
|
|
47
|
+
export declare const SELECTION_STEPS: {
|
|
48
|
+
readonly ArrowUp: number;
|
|
49
|
+
readonly ArrowDown: 16;
|
|
50
|
+
readonly ArrowLeft: -1;
|
|
51
|
+
readonly ArrowRight: 1;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The selection with its moving end taken `delta` bytes, kept inside a file
|
|
55
|
+
* of `fileEnd` bytes. With no selection, it starts at byte `from`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function extendSelection(selection: HexSelection | null, delta: number, from: number, fileEnd: number): HexSelection | null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hex view's selection and copy. A selection is a range of bytes, both
|
|
3
|
+
* ends included, kept in file terms so it survives scrolling, and remembers
|
|
4
|
+
* the column it was made in: Copy gives the hex digits for a selection made
|
|
5
|
+
* in the hex column and the text for one made in the text column, and the
|
|
6
|
+
* status bar copies either form. Copy reads at most one bounded read and
|
|
7
|
+
* refuses a larger selection with a message instead of reading more.
|
|
8
|
+
*/
|
|
9
|
+
import { VIEWER_MAX_READ_BYTES } from './types.js';
|
|
10
|
+
import { BYTES_PER_ROW, hexByte, textChar } from './HexRows.logic.js';
|
|
11
|
+
/** The largest selection copy reads, in bytes. */
|
|
12
|
+
export const MAX_HEX_COPY_BYTES = VIEWER_MAX_READ_BYTES;
|
|
13
|
+
/** Copy for a selection larger than copy will read. */
|
|
14
|
+
export function hexSelectionTooLarge(labels) {
|
|
15
|
+
return labels.hex.copyTooLarge(labels.size(MAX_HEX_COPY_BYTES));
|
|
16
|
+
}
|
|
17
|
+
/** The selected bytes as [start, end): its first byte and one past its last. */
|
|
18
|
+
export function selectedRange(selection) {
|
|
19
|
+
return {
|
|
20
|
+
start: Math.min(selection.anchor, selection.focus),
|
|
21
|
+
end: Math.max(selection.anchor, selection.focus) + 1
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The part of a row of `length` bytes from `rowOffset` a selection covers,
|
|
26
|
+
* as byte indexes [from, to) into the row, or null when it covers none.
|
|
27
|
+
*/
|
|
28
|
+
export function selectedCells(selection, rowOffset, length) {
|
|
29
|
+
const { start, end } = selectedRange(selection);
|
|
30
|
+
const from = Math.max(0, start - rowOffset);
|
|
31
|
+
const to = Math.min(length, end - rowOffset);
|
|
32
|
+
return to > from ? { from, to } : null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The bytes copy reads for a selection, cut at `fileEnd`; null when that is
|
|
36
|
+
* more than copy will read.
|
|
37
|
+
*/
|
|
38
|
+
export function copyRange(selection, fileEnd) {
|
|
39
|
+
const { start, end } = selectedRange(selection);
|
|
40
|
+
const length = Math.max(0, Math.min(end, fileEnd) - start);
|
|
41
|
+
return length <= MAX_HEX_COPY_BYTES ? { offset: start, length } : null;
|
|
42
|
+
}
|
|
43
|
+
/** Bytes as copy gives them in hex: two uppercase digits each, a space between. */
|
|
44
|
+
export function hexCopy(bytes) {
|
|
45
|
+
return Array.from(bytes, hexByte).join(' ');
|
|
46
|
+
}
|
|
47
|
+
/** Bytes as copy gives them as text: what the text column shows, `.` for every byte outside printable ASCII. */
|
|
48
|
+
export function textCopy(bytes) {
|
|
49
|
+
return Array.from(bytes, textChar).join('');
|
|
50
|
+
}
|
|
51
|
+
/** The steps Shift with an arrow takes the selection's moving end: a row up or down, a byte sideways. */
|
|
52
|
+
export const SELECTION_STEPS = {
|
|
53
|
+
ArrowUp: -BYTES_PER_ROW,
|
|
54
|
+
ArrowDown: BYTES_PER_ROW,
|
|
55
|
+
ArrowLeft: -1,
|
|
56
|
+
ArrowRight: 1
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The selection with its moving end taken `delta` bytes, kept inside a file
|
|
60
|
+
* of `fileEnd` bytes. With no selection, it starts at byte `from`.
|
|
61
|
+
*/
|
|
62
|
+
export function extendSelection(selection, delta, from, fileEnd) {
|
|
63
|
+
if (fileEnd <= 0)
|
|
64
|
+
return null;
|
|
65
|
+
const start = selection ?? { anchor: from, focus: from, column: 'hex' };
|
|
66
|
+
const focus = Math.max(0, Math.min(fileEnd - 1, start.focus + delta));
|
|
67
|
+
return { ...start, focus };
|
|
68
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import type { ViewerViewProps } from './ViewerViews.js';
|
|
3
|
+
/**
|
|
4
|
+
* The hex view: 16 bytes a row, as hex and as text, any row one bounded read
|
|
5
|
+
* away. A scaled scrollbar maps the thumb to a byte; ⌘L jumps to an offset;
|
|
6
|
+
* a byte range selected with the mouse (or Shift with the arrows) copies as
|
|
7
|
+
* hex or as text, up to one bounded read.
|
|
8
|
+
*/
|
|
9
|
+
declare function HexView({ reader, info }: Pick<ViewerViewProps, 'reader' | 'info'>): ReactElement;
|
|
10
|
+
export default HexView;
|