@bigpixelrocket/uiok 0.3.0 → 0.5.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 (178) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/dist/button/TextLink.d.ts +19 -3
  3. package/dist/button/TextLink.js +4 -3
  4. package/dist/dialog/ConfirmDialog.d.ts +7 -1
  5. package/dist/dialog/ConfirmDialog.js +2 -2
  6. package/dist/dialog/ModalDialog.js +8 -2
  7. package/dist/dialog/ProgressDialog.d.ts +7 -1
  8. package/dist/dialog/ProgressDialog.js +2 -2
  9. package/dist/dialog/TypedNameDialog.d.ts +8 -0
  10. package/dist/field/Check.d.ts +9 -2
  11. package/dist/field/Check.js +5 -4
  12. package/dist/field/Controls.d.ts +198 -0
  13. package/dist/field/Controls.js +94 -0
  14. package/dist/field/FieldLayout.d.ts +126 -0
  15. package/dist/field/FieldLayout.js +89 -0
  16. package/dist/field/index.d.ts +9 -6
  17. package/dist/field/index.js +9 -6
  18. package/dist/frame/Dock.js +1 -1
  19. package/dist/frame/SidebarResizer.js +1 -1
  20. package/dist/frame/Tree.d.ts +17 -4
  21. package/dist/frame/Tree.js +34 -9
  22. package/dist/frame/WindowFrame.js +2 -1
  23. package/dist/frame/frame.css +26 -4
  24. package/dist/icon/ProductMark.d.ts +57 -0
  25. package/dist/icon/ProductMark.js +26 -0
  26. package/dist/icon/icon.css +53 -0
  27. package/dist/icon/index.d.ts +3 -1
  28. package/dist/icon/index.js +3 -1
  29. package/dist/labels/UiokLabels.d.ts +3 -0
  30. package/dist/labels/UiokLabels.js +3 -1
  31. package/dist/labels/index.d.ts +1 -0
  32. package/dist/labels/index.js +1 -0
  33. package/dist/labels/settings.d.ts +6 -0
  34. package/dist/labels/settings.js +1 -0
  35. package/dist/labels/viewer.d.ts +193 -0
  36. package/dist/labels/viewer.js +124 -0
  37. package/dist/listing/Listing.d.ts +60 -4
  38. package/dist/listing/Listing.js +39 -10
  39. package/dist/listing/ListingScope.d.ts +7 -0
  40. package/dist/listing/ListingScope.js +8 -0
  41. package/dist/listing/PaneMessage.d.ts +28 -0
  42. package/dist/listing/PaneMessage.js +12 -0
  43. package/dist/listing/Timeline.d.ts +51 -0
  44. package/dist/listing/Timeline.js +28 -0
  45. package/dist/listing/index.d.ts +7 -3
  46. package/dist/listing/index.js +6 -2
  47. package/dist/listing/listing.css +185 -22
  48. package/dist/log/Ansi.logic.d.ts +27 -0
  49. package/dist/log/Ansi.logic.js +203 -0
  50. package/dist/log/LogWell.d.ts +11 -2
  51. package/dist/log/LogWell.js +15 -3
  52. package/dist/log/index.d.ts +1 -0
  53. package/dist/log/index.js +1 -0
  54. package/dist/log/log.css +80 -0
  55. package/dist/menu/Menu.d.ts +89 -0
  56. package/dist/menu/Menu.js +143 -0
  57. package/dist/menu/Menu.logic.d.ts +56 -0
  58. package/dist/menu/Menu.logic.js +64 -0
  59. package/dist/menu/index.d.ts +5 -1
  60. package/dist/menu/index.js +5 -1
  61. package/dist/menu/menu.css +51 -0
  62. package/dist/palette/Palette.d.ts +3 -2
  63. package/dist/palette/Palette.js +8 -4
  64. package/dist/palette/PaletteRows.d.ts +129 -0
  65. package/dist/palette/PaletteRows.js +74 -0
  66. package/dist/palette/index.d.ts +5 -2
  67. package/dist/palette/index.js +5 -2
  68. package/dist/pane/PaneFrame.d.ts +22 -1
  69. package/dist/pane/PaneFrame.js +42 -5
  70. package/dist/pane/index.d.ts +1 -1
  71. package/dist/shell/SettingsDialog.d.ts +20 -2
  72. package/dist/shell/SettingsDialog.js +13 -3
  73. package/dist/shell/index.d.ts +1 -1
  74. package/dist/styles.css +4 -0
  75. package/dist/surface/Card.d.ts +18 -0
  76. package/dist/surface/Card.js +10 -0
  77. package/dist/surface/FactTable.d.ts +44 -0
  78. package/dist/surface/FactTable.js +33 -0
  79. package/dist/surface/Notice.d.ts +45 -0
  80. package/dist/surface/Notice.js +27 -0
  81. package/dist/surface/index.d.ts +7 -3
  82. package/dist/surface/index.js +7 -3
  83. package/dist/surface/surface.css +64 -0
  84. package/dist/tabs/PageTabs.d.ts +6 -0
  85. package/dist/tabs/PageTabs.js +1 -1
  86. package/dist/tabs/tabs.css +14 -0
  87. package/dist/terminal/TerminalBox.d.ts +30 -0
  88. package/dist/terminal/TerminalBox.js +17 -0
  89. package/dist/terminal/index.d.ts +3 -1
  90. package/dist/terminal/index.js +3 -1
  91. package/dist/terminal/terminal.css +29 -0
  92. package/dist/themes/themes.generated.css +21 -0
  93. package/dist/themes/tokens.d.ts +1 -0
  94. package/dist/themes/tokens.js +16 -1
  95. package/dist/viewer/AudioView.d.ts +13 -0
  96. package/dist/viewer/AudioView.js +25 -0
  97. package/dist/viewer/HexJump.logic.d.ts +16 -0
  98. package/dist/viewer/HexJump.logic.js +27 -0
  99. package/dist/viewer/HexRows.logic.d.ts +55 -0
  100. package/dist/viewer/HexRows.logic.js +84 -0
  101. package/dist/viewer/HexSelection.logic.d.ts +57 -0
  102. package/dist/viewer/HexSelection.logic.js +68 -0
  103. package/dist/viewer/HexView.d.ts +10 -0
  104. package/dist/viewer/HexView.js +291 -0
  105. package/dist/viewer/HexViewport.logic.d.ts +61 -0
  106. package/dist/viewer/HexViewport.logic.js +79 -0
  107. package/dist/viewer/ImageView.d.ts +19 -0
  108. package/dist/viewer/ImageView.js +230 -0
  109. package/dist/viewer/ImageZoom.logic.d.ts +65 -0
  110. package/dist/viewer/ImageZoom.logic.js +119 -0
  111. package/dist/viewer/LatestRead.logic.d.ts +27 -0
  112. package/dist/viewer/LatestRead.logic.js +55 -0
  113. package/dist/viewer/MediaControls.d.ts +25 -0
  114. package/dist/viewer/MediaControls.js +183 -0
  115. package/dist/viewer/MediaPlayer.logic.d.ts +53 -0
  116. package/dist/viewer/MediaPlayer.logic.js +68 -0
  117. package/dist/viewer/PdfView.d.ts +23 -0
  118. package/dist/viewer/PdfView.js +25 -0
  119. package/dist/viewer/QuietFocus.d.ts +19 -0
  120. package/dist/viewer/QuietFocus.js +27 -0
  121. package/dist/viewer/ScaledScroll.logic.d.ts +30 -0
  122. package/dist/viewer/ScaledScroll.logic.js +28 -0
  123. package/dist/viewer/ScaledScrollbar.d.ts +19 -0
  124. package/dist/viewer/ScaledScrollbar.js +71 -0
  125. package/dist/viewer/SyntaxHighlighter.d.ts +29 -0
  126. package/dist/viewer/SyntaxHighlighter.js +144 -0
  127. package/dist/viewer/SyntaxLanguage.logic.d.ts +110 -0
  128. package/dist/viewer/SyntaxLanguage.logic.js +283 -0
  129. package/dist/viewer/SyntaxService.d.ts +75 -0
  130. package/dist/viewer/SyntaxService.js +49 -0
  131. package/dist/viewer/SyntaxSession.logic.d.ts +78 -0
  132. package/dist/viewer/SyntaxSession.logic.js +221 -0
  133. package/dist/viewer/SyntaxWorker.d.ts +6 -0
  134. package/dist/viewer/SyntaxWorker.js +8 -0
  135. package/dist/viewer/TextEncoding.logic.d.ts +35 -0
  136. package/dist/viewer/TextEncoding.logic.js +58 -0
  137. package/dist/viewer/TextRows.logic.d.ts +86 -0
  138. package/dist/viewer/TextRows.logic.js +241 -0
  139. package/dist/viewer/TextSelection.logic.d.ts +97 -0
  140. package/dist/viewer/TextSelection.logic.js +139 -0
  141. package/dist/viewer/TextView.d.ts +13 -0
  142. package/dist/viewer/TextView.js +448 -0
  143. package/dist/viewer/TextViewport.logic.d.ts +70 -0
  144. package/dist/viewer/TextViewport.logic.js +116 -0
  145. package/dist/viewer/VideoView.d.ts +18 -0
  146. package/dist/viewer/VideoView.js +53 -0
  147. package/dist/viewer/ViewerClipboard.d.ts +30 -0
  148. package/dist/viewer/ViewerClipboard.js +70 -0
  149. package/dist/viewer/ViewerFrame.logic.d.ts +61 -0
  150. package/dist/viewer/ViewerFrame.logic.js +130 -0
  151. package/dist/viewer/ViewerKeys.d.ts +16 -0
  152. package/dist/viewer/ViewerKeys.js +14 -0
  153. package/dist/viewer/ViewerScope.d.ts +12 -0
  154. package/dist/viewer/ViewerScope.js +22 -0
  155. package/dist/viewer/ViewerViews.d.ts +28 -0
  156. package/dist/viewer/ViewerViews.js +22 -0
  157. package/dist/viewer/ViewerWindow.d.ts +53 -0
  158. package/dist/viewer/ViewerWindow.js +219 -0
  159. package/dist/viewer/index.d.ts +12 -0
  160. package/dist/viewer/index.js +12 -0
  161. package/dist/viewer/types.d.ts +151 -0
  162. package/dist/viewer/types.js +26 -0
  163. package/dist/viewer/useElementHeight.d.ts +6 -0
  164. package/dist/viewer/useElementHeight.js +22 -0
  165. package/dist/viewer/useElementSize.d.ts +7 -0
  166. package/dist/viewer/useElementSize.js +24 -0
  167. package/dist/viewer/useEscapeToClear.d.ts +8 -0
  168. package/dist/viewer/useEscapeToClear.js +26 -0
  169. package/dist/viewer/useHexDocument.d.ts +41 -0
  170. package/dist/viewer/useHexDocument.js +144 -0
  171. package/dist/viewer/useMediaElement.d.ts +10 -0
  172. package/dist/viewer/useMediaElement.js +24 -0
  173. package/dist/viewer/useSyntaxHighlight.d.ts +24 -0
  174. package/dist/viewer/useSyntaxHighlight.js +133 -0
  175. package/dist/viewer/useTextDocument.d.ts +66 -0
  176. package/dist/viewer/useTextDocument.js +245 -0
  177. package/dist/viewer/viewer.css +645 -0
  178. package/package.json +7 -1
@@ -0,0 +1,183 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { Maximize, Minimize, Pause, Play, Volume2, VolumeX } from 'lucide-react';
4
+ import { IconButton } from '../button/IconButton.js';
5
+ import { tooltip } from '../tooltip/Tooltip.logic.js';
6
+ import { ICON_MD } from '../icon/index.js';
7
+ import { useLabels } from '../labels/UiokProvider.js';
8
+ import { formatMediaTime, mediaKeyAction, seekTarget } from './MediaPlayer.logic.js';
9
+ import { isViewerEvent } from './ViewerScope.js';
10
+ const EMPTY = {
11
+ ready: false,
12
+ paused: true,
13
+ currentTime: 0,
14
+ duration: NaN,
15
+ volume: 1,
16
+ muted: false
17
+ };
18
+ const snapshot = (media) => ({
19
+ ready: media.readyState >= HTMLMediaElement.HAVE_METADATA,
20
+ paused: media.paused,
21
+ currentTime: media.currentTime,
22
+ duration: media.duration,
23
+ volume: media.volume,
24
+ muted: media.muted
25
+ });
26
+ /** The element's events that change anything the bar shows. */
27
+ const STATE_EVENTS = [
28
+ 'loadedmetadata',
29
+ 'durationchange',
30
+ 'emptied',
31
+ 'play',
32
+ 'pause',
33
+ 'ended',
34
+ 'timeupdate',
35
+ 'seeking',
36
+ 'seeked',
37
+ 'volumechange'
38
+ ];
39
+ /**
40
+ * Starts playback, which only a user's click or key ever calls. A refused
41
+ * start (a file that fails to decode, or a pause that interrupts it) needs
42
+ * no handling here: the element's error event hands the view to hex, and a
43
+ * pause is what was asked for.
44
+ */
45
+ const play = (media) => {
46
+ void media.play().catch(() => undefined);
47
+ };
48
+ /**
49
+ * The share of a slider's trough uiok's `.range` fills in the accent, from
50
+ * the value's share of its span; a span not known yet fills none.
51
+ */
52
+ const rangeFill = (share) => ({
53
+ '--range-fill': `${Number.isFinite(share) ? Math.min(Math.max(share, 0), 1) * 100 : 0}%`
54
+ });
55
+ /** Elements that act on Space or the arrows themselves while they have focus. */
56
+ const OPERABLE = 'button, input, select, textarea, a[href], [contenteditable]';
57
+ /**
58
+ * Whether the player answers a key aimed at `target`: anything inside the
59
+ * player, or a target no key operates (the page, a stage). A focused control
60
+ * outside the player (the mode switcher, Reload) keeps its own keys, so
61
+ * Space presses it as it would anywhere else.
62
+ */
63
+ const isPlayerKeyTarget = (target, player) => !(target instanceof Element) ||
64
+ (player?.contains(target) ?? false) ||
65
+ target.closest(OPERABLE) === null;
66
+ /**
67
+ * The media player's control bar, under the audio and video views: play and
68
+ * pause, the elapsed time, a seek bar, the duration, any facts the view
69
+ * adds, mute and volume, and for a video full screen. Every control drives
70
+ * `media`, the element the view renders, and the bar shows what the element
71
+ * reports, so Chromium does all the playing and seeking (through range
72
+ * requests on the media URL). Nothing starts playback but the user. The
73
+ * player's keys (Space, ← and →, Home and End, and F for a video:
74
+ * `mediaKeyAction`) work while focus is inside the player or on nothing a
75
+ * key operates, except that the volume slider keeps its own arrows, Home,
76
+ * and End. Escape leaves full screen, as Chromium does on its own.
77
+ */
78
+ function MediaControls({ media, player, fullscreen = false, children }) {
79
+ const allLabels = useLabels();
80
+ const labels = allLabels.viewer;
81
+ const keyNames = allLabels.keys.names;
82
+ const [state, setState] = useState(EMPTY);
83
+ const [isFullscreen, setIsFullscreen] = useState(false);
84
+ const volumeSlider = useRef(null);
85
+ useEffect(() => {
86
+ if (!media)
87
+ return;
88
+ const update = () => setState(snapshot(media));
89
+ update();
90
+ for (const type of STATE_EVENTS)
91
+ media.addEventListener(type, update);
92
+ return () => {
93
+ for (const type of STATE_EVENTS)
94
+ media.removeEventListener(type, update);
95
+ };
96
+ }, [media]);
97
+ const toggle = useCallback(() => {
98
+ if (!media)
99
+ return;
100
+ if (media.paused)
101
+ play(media);
102
+ else
103
+ media.pause();
104
+ }, [media]);
105
+ useEffect(() => {
106
+ if (!fullscreen || !player)
107
+ return;
108
+ const update = () => setIsFullscreen(document.fullscreenElement === player);
109
+ update();
110
+ document.addEventListener('fullscreenchange', update);
111
+ return () => document.removeEventListener('fullscreenchange', update);
112
+ }, [fullscreen, player]);
113
+ // A refused request (the window cannot go full screen right now) leaves
114
+ // the player as it was, which is all there is to say about it.
115
+ const toggleFullscreen = useCallback(() => {
116
+ if (!player)
117
+ return;
118
+ if (document.fullscreenElement)
119
+ void document.exitFullscreen().catch(() => undefined);
120
+ else
121
+ void player.requestFullscreen().catch(() => undefined);
122
+ }, [player]);
123
+ const seekTo = useCallback((time) => {
124
+ if (!media)
125
+ return;
126
+ media.currentTime = time;
127
+ setState(snapshot(media));
128
+ }, [media]);
129
+ useEffect(() => {
130
+ if (!media)
131
+ return;
132
+ const onKeyDown = (event) => {
133
+ const action = mediaKeyAction(event);
134
+ if (!action || !isViewerEvent(event))
135
+ return;
136
+ if (!isPlayerKeyTarget(event.target, player))
137
+ return;
138
+ if (action.kind === 'fullscreen' && !fullscreen)
139
+ return;
140
+ // The volume slider moves by its own arrows and ends.
141
+ if (action.kind !== 'toggle' && event.target === volumeSlider.current)
142
+ return;
143
+ event.preventDefault();
144
+ if (action.kind === 'toggle') {
145
+ if (!event.repeat)
146
+ toggle();
147
+ }
148
+ else if (action.kind === 'fullscreen') {
149
+ if (!event.repeat)
150
+ toggleFullscreen();
151
+ }
152
+ else if (action.kind === 'seek') {
153
+ seekTo(seekTarget(media.currentTime, action.by, media.duration));
154
+ }
155
+ else if (action.to === 'start') {
156
+ seekTo(0);
157
+ }
158
+ else if (Number.isFinite(media.duration)) {
159
+ seekTo(media.duration);
160
+ }
161
+ };
162
+ window.addEventListener('keydown', onKeyDown);
163
+ return () => window.removeEventListener('keydown', onKeyDown);
164
+ }, [fullscreen, media, player, seekTo, toggle, toggleFullscreen]);
165
+ const { ready, paused, currentTime, duration, volume, muted } = state;
166
+ const seekable = ready && Number.isFinite(duration) && duration > 0;
167
+ const elapsed = formatMediaTime(ready ? currentTime : NaN, duration);
168
+ const total = formatMediaTime(ready ? duration : NaN, duration);
169
+ const silent = muted || volume === 0;
170
+ const playLabel = paused ? labels.media.play : labels.media.pause;
171
+ const muteLabel = muted ? labels.media.unmute : labels.media.mute;
172
+ const fullscreenLabel = isFullscreen ? labels.media.exitFullScreen : labels.media.enterFullScreen;
173
+ return (_jsxs("footer", { className: "media-controls", children: [_jsx(IconButton, { "aria-label": playLabel, disabled: !ready, onClick: toggle, size: "small", ...tooltip(playLabel, keyNames[' '] ?? ' '), children: paused ? _jsx(Play, { size: ICON_MD }) : _jsx(Pause, { size: ICON_MD }) }), _jsx("span", { className: "media-time", children: elapsed }), _jsx("input", { "aria-label": labels.media.seek, "aria-valuetext": labels.media.seekValue(elapsed, total), className: "media-seek range", disabled: !seekable, max: seekable ? duration : 0, min: 0, onChange: (event) => seekTo(Number(event.currentTarget.value)), step: "any", style: rangeFill(seekable ? Math.min(currentTime, duration) / duration : 0), type: "range", value: seekable ? Math.min(currentTime, duration) : 0 }), _jsx("span", { className: "media-time", children: total }), children, _jsx(IconButton, { "aria-label": muteLabel, disabled: !media, onClick: () => {
174
+ if (media)
175
+ media.muted = !media.muted;
176
+ }, size: "small", ...tooltip(muteLabel), children: silent ? _jsx(VolumeX, { size: ICON_MD }) : _jsx(Volume2, { size: ICON_MD }) }), _jsx("input", { "aria-label": labels.media.volume, className: "media-volume range", disabled: !media, max: 1, min: 0, onChange: (event) => {
177
+ if (!media)
178
+ return;
179
+ media.volume = Number(event.currentTarget.value);
180
+ media.muted = false;
181
+ }, ref: volumeSlider, step: 0.05, style: rangeFill(muted ? 0 : volume), type: "range", value: muted ? 0 : volume }), fullscreen && (_jsx(IconButton, { "aria-label": fullscreenLabel, disabled: !player, onClick: toggleFullscreen, size: "small", ...tooltip(fullscreenLabel, 'F'), children: isFullscreen ? _jsx(Minimize, { size: ICON_MD }) : _jsx(Maximize, { size: ICON_MD }) }))] }));
182
+ }
183
+ export default MediaControls;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Pure decisions behind the viewer's media player (`MediaControls.tsx`):
3
+ * how a time reads, what a key asks of the player, where a seek lands, and
4
+ * what the window says when Chromium cannot play the file. Nothing here
5
+ * touches a media element.
6
+ */
7
+ import type { ViewerLabels } from '../labels/viewer.js';
8
+ /** How far ← and → move the playhead. */
9
+ export declare const MEDIA_SEEK_STEP_SECONDS = 5;
10
+ /** A time on the player's clock: `1:05`, or `1:02:05` when the file runs an hour or more. */
11
+ export declare function formatMediaTime(seconds: number, duration: number): string;
12
+ /**
13
+ * What a key asks of the player: play or pause, move the playhead by
14
+ * seconds, go to an end, or enter or leave full screen (a video's player only).
15
+ */
16
+ export type MediaKeyAction = {
17
+ readonly kind: 'toggle';
18
+ } | {
19
+ readonly kind: 'seek';
20
+ readonly by: number;
21
+ } | {
22
+ readonly kind: 'jump';
23
+ readonly to: 'start' | 'end';
24
+ } | {
25
+ readonly kind: 'fullscreen';
26
+ };
27
+ /** The parts of a keystroke the player reads. */
28
+ export interface MediaKey {
29
+ readonly key: string;
30
+ readonly metaKey: boolean;
31
+ readonly ctrlKey: boolean;
32
+ readonly altKey: boolean;
33
+ readonly shiftKey: boolean;
34
+ }
35
+ /**
36
+ * The player's keys, all bare: Space plays or pauses, ← and → seek five
37
+ * seconds, Home and End go to the start and the end, and F enters or leaves
38
+ * full screen. Any modifier leaves the key to the window, so the system's
39
+ * chords and the native menu keep theirs.
40
+ */
41
+ export declare function mediaKeyAction(event: MediaKey): MediaKeyAction | null;
42
+ /**
43
+ * Where a seek from `current` by `by` seconds lands: never before the start,
44
+ * nor past the end when the duration is known (a stream still being read
45
+ * may not know it yet).
46
+ */
47
+ export declare function seekTarget(current: number, by: number, duration: number): number;
48
+ /**
49
+ * Why a media view gave way to hex, from the `MediaError` code Chromium
50
+ * reported (null when it reported none): a format it does not play, a file
51
+ * it could not decode, or any other failure to play.
52
+ */
53
+ export declare function mediaFallbackNote(noun: 'audio' | 'video', code: number | null, labels: ViewerLabels): string;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Pure decisions behind the viewer's media player (`MediaControls.tsx`):
3
+ * how a time reads, what a key asks of the player, where a seek lands, and
4
+ * what the window says when Chromium cannot play the file. Nothing here
5
+ * touches a media element.
6
+ */
7
+ /** How far ← and → move the playhead. */
8
+ export const MEDIA_SEEK_STEP_SECONDS = 5;
9
+ /** A time on the player's clock: `1:05`, or `1:02:05` when the file runs an hour or more. */
10
+ export function formatMediaTime(seconds, duration) {
11
+ if (!Number.isFinite(seconds) || seconds < 0)
12
+ return '--:--';
13
+ const whole = Math.floor(seconds);
14
+ const hours = Math.floor(whole / 3600);
15
+ const minutes = Math.floor((whole % 3600) / 60);
16
+ const secs = String(whole % 60).padStart(2, '0');
17
+ return hours > 0 || (Number.isFinite(duration) && duration >= 3600)
18
+ ? `${hours}:${String(minutes).padStart(2, '0')}:${secs}`
19
+ : `${minutes}:${secs}`;
20
+ }
21
+ const KEY_ACTIONS = {
22
+ ' ': { kind: 'toggle' },
23
+ ArrowLeft: { kind: 'seek', by: -MEDIA_SEEK_STEP_SECONDS },
24
+ ArrowRight: { kind: 'seek', by: MEDIA_SEEK_STEP_SECONDS },
25
+ Home: { kind: 'jump', to: 'start' },
26
+ End: { kind: 'jump', to: 'end' },
27
+ // Caps Lock reports the letter in capitals without Shift.
28
+ f: { kind: 'fullscreen' },
29
+ F: { kind: 'fullscreen' }
30
+ };
31
+ /**
32
+ * The player's keys, all bare: Space plays or pauses, ← and → seek five
33
+ * seconds, Home and End go to the start and the end, and F enters or leaves
34
+ * full screen. Any modifier leaves the key to the window, so the system's
35
+ * chords and the native menu keep theirs.
36
+ */
37
+ export function mediaKeyAction(event) {
38
+ if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey)
39
+ return null;
40
+ return Object.hasOwn(KEY_ACTIONS, event.key) ? (KEY_ACTIONS[event.key] ?? null) : null;
41
+ }
42
+ /**
43
+ * Where a seek from `current` by `by` seconds lands: never before the start,
44
+ * nor past the end when the duration is known (a stream still being read
45
+ * may not know it yet).
46
+ */
47
+ export function seekTarget(current, by, duration) {
48
+ const target = Math.max(0, current + by);
49
+ return Number.isFinite(duration) ? Math.min(target, duration) : target;
50
+ }
51
+ /** `MediaError.code` values (the DOM constants, kept here so the module stays pure). */
52
+ const MEDIA_ERR_DECODE = 3;
53
+ const MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
54
+ /**
55
+ * Why a media view gave way to hex, from the `MediaError` code Chromium
56
+ * reported (null when it reported none): a format it does not play, a file
57
+ * it could not decode, or any other failure to play.
58
+ */
59
+ export function mediaFallbackNote(noun, code, labels) {
60
+ switch (code) {
61
+ case MEDIA_ERR_SRC_NOT_SUPPORTED:
62
+ return labels.media.fallbackFormat(noun);
63
+ case MEDIA_ERR_DECODE:
64
+ return labels.media.fallbackDecode(noun);
65
+ default:
66
+ return labels.media.fallbackPlay(noun);
67
+ }
68
+ }
@@ -0,0 +1,23 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { ViewerFileInfo } from './types.js';
3
+ import type { ViewerViewProps } from './ViewerViews.js';
4
+ /**
5
+ * Where the PDF view loads the document: the file's media URL with its name
6
+ * as a last segment, which Chromium's PDF viewer shows as the toolbar's
7
+ * title (a document's own title metadata wins). The reader's media URL must
8
+ * therefore serve the file whatever segment follows it (`ViewerFileInfo`'s
9
+ * `mediaUrl`); a `blob:` URL cannot, since its path is fixed.
10
+ */
11
+ export declare function pdfDocumentUrl(info: ViewerFileInfo): string;
12
+ /**
13
+ * The PDF view: the browser's built-in PDF viewer, in a frame loaded from
14
+ * the file's media URL (`pdfDocumentUrl`). In Chromium that viewer brings
15
+ * page thumbnails, continuous scroll, go to page, zoom and fit, and text
16
+ * selection and copy, and its own message for a file it cannot open;
17
+ * nothing here parses or renders PDF. Whether its toolbar's Download may
18
+ * save a file is the host's decision, not the view's. The frame is not
19
+ * sandboxed (the PDF viewer does not run in one), so the reader's URL must
20
+ * answer only with the PDF itself (`docs/components/viewer.md`).
21
+ */
22
+ declare function PdfView({ info }: ViewerViewProps): ReactElement;
23
+ export default PdfView;
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Where the PDF view loads the document: the file's media URL with its name
4
+ * as a last segment, which Chromium's PDF viewer shows as the toolbar's
5
+ * title (a document's own title metadata wins). The reader's media URL must
6
+ * therefore serve the file whatever segment follows it (`ViewerFileInfo`'s
7
+ * `mediaUrl`); a `blob:` URL cannot, since its path is fixed.
8
+ */
9
+ export function pdfDocumentUrl(info) {
10
+ return `${info.mediaUrl}/${encodeURIComponent(info.name)}`;
11
+ }
12
+ /**
13
+ * The PDF view: the browser's built-in PDF viewer, in a frame loaded from
14
+ * the file's media URL (`pdfDocumentUrl`). In Chromium that viewer brings
15
+ * page thumbnails, continuous scroll, go to page, zoom and fit, and text
16
+ * selection and copy, and its own message for a file it cannot open;
17
+ * nothing here parses or renders PDF. Whether its toolbar's Download may
18
+ * save a file is the host's decision, not the view's. The frame is not
19
+ * sandboxed (the PDF viewer does not run in one), so the reader's URL must
20
+ * answer only with the PDF itself (`docs/components/viewer.md`).
21
+ */
22
+ function PdfView({ info }) {
23
+ return (_jsx("div", { className: "pdf-view", children: _jsx("iframe", { className: "pdf-view-document", src: pdfDocumentUrl(info), title: info.name }) }));
24
+ }
25
+ export default PdfView;
@@ -0,0 +1,19 @@
1
+ import type { FocusEvent } from 'react';
2
+ /**
3
+ * The text and hex views take the focus as their window opens, so the keys
4
+ * scroll the document without a click first. That focus is the window's, not
5
+ * the user's, so it draws no ring: the rows carry `data-quiet-focus` until
6
+ * the focus first leaves them inside the window, and the frame's ring rule
7
+ * (`.viewer-rows-frame` in ViewerWindow.css) leaves quiet rows out. Focus the
8
+ * user brings back by keyboard (Tab, or Escape out of the offset field) then
9
+ * shows the ring; a pointer press, which focuses the rows from code after a
10
+ * mouse interaction, does not.
11
+ */
12
+ /** Focuses the rows as the window opens, marked so they draw no ring. */
13
+ export declare function focusQuietly(element: HTMLElement | null): void;
14
+ /**
15
+ * Ends the quiet focus once the focus leaves the rows for something else in
16
+ * the window. A blur because the window itself lost the focus keeps it, so
17
+ * coming back to the window shows no ring either.
18
+ */
19
+ export declare function endQuietFocus(event: FocusEvent<HTMLElement>): void;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The text and hex views take the focus as their window opens, so the keys
3
+ * scroll the document without a click first. That focus is the window's, not
4
+ * the user's, so it draws no ring: the rows carry `data-quiet-focus` until
5
+ * the focus first leaves them inside the window, and the frame's ring rule
6
+ * (`.viewer-rows-frame` in ViewerWindow.css) leaves quiet rows out. Focus the
7
+ * user brings back by keyboard (Tab, or Escape out of the offset field) then
8
+ * shows the ring; a pointer press, which focuses the rows from code after a
9
+ * mouse interaction, does not.
10
+ */
11
+ /** Focuses the rows as the window opens, marked so they draw no ring. */
12
+ export function focusQuietly(element) {
13
+ if (element === null)
14
+ return;
15
+ element.dataset.quietFocus = '';
16
+ element.focus();
17
+ }
18
+ /**
19
+ * Ends the quiet focus once the focus leaves the rows for something else in
20
+ * the window. A blur because the window itself lost the focus keeps it, so
21
+ * coming back to the window shows no ring either.
22
+ */
23
+ export function endQuietFocus(event) {
24
+ if (event.relatedTarget === null && !event.currentTarget.ownerDocument.hasFocus())
25
+ return;
26
+ delete event.currentTarget.dataset.quietFocus;
27
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The scaled scrollbar of the text and hex views. A page element tops out
3
+ * near 33 million pixels, which a few million rows exceed, so the views draw
4
+ * no full-height list: the thumb's place on its track maps to a byte of the
5
+ * file instead, and dragging it jumps to that byte.
6
+ */
7
+ /** The smallest thumb, so a huge file's thumb can still be grabbed. */
8
+ export declare const MIN_THUMB_PX = 24;
9
+ /** What the scrollbar maps between: a span of bytes, the part in view, and where the view starts. */
10
+ export interface ScrollSpan {
11
+ /** Bytes the scrollbar spans, the file's text without any byte order mark. */
12
+ readonly total: number;
13
+ /** Bytes the screen shows, which sizes the thumb. */
14
+ readonly visible: number;
15
+ /** Track height in pixels. */
16
+ readonly trackPx: number;
17
+ }
18
+ /** The thumb's height and its distance from the top of the track, in pixels. */
19
+ export interface ThumbGeometry {
20
+ readonly heightPx: number;
21
+ readonly topPx: number;
22
+ }
23
+ /** The thumb for a view starting `position` bytes into the span. */
24
+ export declare function thumbGeometry(span: ScrollSpan, position: number): ThumbGeometry;
25
+ /**
26
+ * The byte, counted into the span, that a thumb dragged to `topPx` points
27
+ * at: the inverse of `thumbGeometry`. The top of the track is the first
28
+ * byte; the bottom is the last screen.
29
+ */
30
+ export declare function positionForThumb(span: ScrollSpan, topPx: number): number;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The scaled scrollbar of the text and hex views. A page element tops out
3
+ * near 33 million pixels, which a few million rows exceed, so the views draw
4
+ * no full-height list: the thumb's place on its track maps to a byte of the
5
+ * file instead, and dragging it jumps to that byte.
6
+ */
7
+ /** The smallest thumb, so a huge file's thumb can still be grabbed. */
8
+ export const MIN_THUMB_PX = 24;
9
+ const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
10
+ const thumbHeight = ({ total, visible, trackPx }) => clamp(total > 0 ? (trackPx * visible) / total : trackPx, Math.min(MIN_THUMB_PX, trackPx), trackPx);
11
+ /** How far the view can move: the span less what one screen shows. */
12
+ const scrollable = ({ total, visible }) => Math.max(0, total - visible);
13
+ /** The thumb for a view starting `position` bytes into the span. */
14
+ export function thumbGeometry(span, position) {
15
+ const heightPx = thumbHeight(span);
16
+ const room = span.trackPx - heightPx;
17
+ const range = scrollable(span);
18
+ return { heightPx, topPx: range > 0 ? room * clamp(position / range, 0, 1) : 0 };
19
+ }
20
+ /**
21
+ * The byte, counted into the span, that a thumb dragged to `topPx` points
22
+ * at: the inverse of `thumbGeometry`. The top of the track is the first
23
+ * byte; the bottom is the last screen.
24
+ */
25
+ export function positionForThumb(span, topPx) {
26
+ const room = span.trackPx - thumbHeight(span);
27
+ return room > 0 ? Math.round(scrollable(span) * clamp(topPx / room, 0, 1)) : 0;
28
+ }
@@ -0,0 +1,19 @@
1
+ import { type ReactElement } from 'react';
2
+ /**
3
+ * The text and hex views' scrollbar. Its thumb sits where `position` falls
4
+ * in a span of `total` units of which `visible` show (bytes, in both views);
5
+ * dragging the thumb reports the position it points at, and a click on the
6
+ * track above or below the thumb asks for a page that way. A span that
7
+ * shows whole draws the track alone: the gutter stays, the thumb goes.
8
+ * The thumb shows only while the view scrolls or the pointer is on the
9
+ * bar (`data-scrolling`, which ScaledScrollbar.css reads).
10
+ */
11
+ declare function ScaledScrollbar({ total, visible, position, onDrag, onPage }: {
12
+ readonly total: number;
13
+ readonly visible: number;
14
+ readonly position: number;
15
+ /** The position, counted into the span, the dragged thumb points at. */
16
+ readonly onDrag: (position: number) => void;
17
+ readonly onPage: (direction: -1 | 1) => void;
18
+ }): ReactElement;
19
+ export default ScaledScrollbar;
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { positionForThumb, thumbGeometry } from './ScaledScroll.logic.js';
4
+ import { useElementHeight } from './useElementHeight.js';
5
+ /** Track height before the track is measured (or where it never is). */
6
+ const FALLBACK_TRACK_PX = 600;
7
+ /** How long the thumb stays after the last scroll, as the terminal's does. */
8
+ const SCROLLBAR_LINGER_MS = 1000;
9
+ /**
10
+ * Whether the view moved within the last moment. The bar rests hidden, as
11
+ * the platform's overlay bar does, and shows while `position` changes and
12
+ * for {@link SCROLLBAR_LINGER_MS} after; the first position never shows it.
13
+ */
14
+ function useScrolling(position) {
15
+ const [scrolling, setScrolling] = useState(false);
16
+ const shown = useRef(position);
17
+ useEffect(() => {
18
+ if (shown.current === position)
19
+ return undefined;
20
+ shown.current = position;
21
+ setScrolling(true);
22
+ const timer = window.setTimeout(() => setScrolling(false), SCROLLBAR_LINGER_MS);
23
+ return () => window.clearTimeout(timer);
24
+ }, [position]);
25
+ return scrolling;
26
+ }
27
+ /**
28
+ * The text and hex views' scrollbar. Its thumb sits where `position` falls
29
+ * in a span of `total` units of which `visible` show (bytes, in both views);
30
+ * dragging the thumb reports the position it points at, and a click on the
31
+ * track above or below the thumb asks for a page that way. A span that
32
+ * shows whole draws the track alone: the gutter stays, the thumb goes.
33
+ * The thumb shows only while the view scrolls or the pointer is on the
34
+ * bar (`data-scrolling`, which ScaledScrollbar.css reads).
35
+ */
36
+ function ScaledScrollbar({ total, visible, position, onDrag, onPage }) {
37
+ const [trackRef, trackHeight] = useElementHeight();
38
+ const span = { total, visible, trackPx: trackHeight ?? FALLBACK_TRACK_PX };
39
+ const thumb = thumbGeometry(span, position);
40
+ const scrolling = useScrolling(position);
41
+ const onThumbDown = (event) => {
42
+ if (event.button !== 0)
43
+ return;
44
+ event.preventDefault();
45
+ event.stopPropagation();
46
+ const grabbedAt = event.clientY - thumb.topPx;
47
+ const target = event.currentTarget;
48
+ target.setPointerCapture(event.pointerId);
49
+ const onMove = (move) => {
50
+ onDrag(positionForThumb(span, move.clientY - grabbedAt));
51
+ };
52
+ // Losing the capture ends the drag too: it follows pointerup, and comes
53
+ // alone when the system cancels the pointer.
54
+ const onUp = () => {
55
+ target.removeEventListener('pointermove', onMove);
56
+ target.removeEventListener('pointerup', onUp);
57
+ target.removeEventListener('lostpointercapture', onUp);
58
+ };
59
+ target.addEventListener('pointermove', onMove);
60
+ target.addEventListener('pointerup', onUp);
61
+ target.addEventListener('lostpointercapture', onUp);
62
+ };
63
+ const onTrackDown = (event) => {
64
+ if (event.button !== 0)
65
+ return;
66
+ const bounds = event.currentTarget.getBoundingClientRect();
67
+ onPage(event.clientY - bounds.top < thumb.topPx ? -1 : 1);
68
+ };
69
+ return (_jsx("div", { "aria-hidden": "true", className: "scaled-scrollbar", "data-scrolling": scrolling ? '' : undefined, onPointerDown: onTrackDown, ref: trackRef, children: _jsx("div", { className: "scaled-scrollbar-thumb", hidden: visible >= total, onPointerDown: onThumbDown, style: { height: thumb.heightPx, transform: `translateY(${thumb.topPx}px)` } }) }));
70
+ }
71
+ export default ScaledScrollbar;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Shiki bound to the text view: the shipped grammars, each loaded only when a
3
+ * file needs it, the theme, and the line tokenizer the syntax session runs.
4
+ *
5
+ * Shiki runs on its JavaScript regex engine, so highlighting needs no
6
+ * WebAssembly and the viewer's CSP grants none. `SyntaxHighlighter.test.ts`
7
+ * compiles every pattern of every grammar here with that engine.
8
+ *
9
+ * The theme is Catppuccin Mocha, the app's own palette. Its colors become
10
+ * the palette's role names (`--syntax-mauve`, `--syntax-peach`), which every
11
+ * theme of the catalog sets (`@bigpixelrocket/uiok/themes`), so a token
12
+ * follows the window's theme without being tokenized again. A line's tokens cover
13
+ * only its styled text; the rest draws in the text's own color.
14
+ */
15
+ import { type LanguageRegistration } from '@shikijs/primitive';
16
+ import { type StateStack } from '@shikijs/primitive/textmate';
17
+ import type { SyntaxLanguageId } from './SyntaxLanguage.logic.js';
18
+ import type { LineTokenizer } from './SyntaxSession.logic.js';
19
+ type GrammarModule = Promise<{
20
+ readonly default: LanguageRegistration[];
21
+ }>;
22
+ /** Each shipped grammar, as a chunk of its own that loads on first use. */
23
+ export declare const SYNTAX_GRAMMARS: Readonly<Record<SyntaxLanguageId, () => GrammarModule>>;
24
+ /**
25
+ * Loads `language`'s grammar (and the grammars it embeds) and the theme,
26
+ * and returns a tokenizer over them. Rejects when a chunk fails to load.
27
+ */
28
+ export declare function loadLineTokenizer(language: SyntaxLanguageId): Promise<LineTokenizer<StateStack>>;
29
+ export {};