@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,53 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, 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
+ const UNKNOWN = { kind: 'unknown' };
11
+ /** The element's picture as it reports it now. */
12
+ const pictureOf = (video) => {
13
+ if (video.readyState < HTMLMediaElement.HAVE_METADATA)
14
+ return UNKNOWN;
15
+ return video.videoWidth > 0 && video.videoHeight > 0
16
+ ? { kind: 'size', width: video.videoWidth, height: video.videoHeight }
17
+ : { kind: 'none' };
18
+ };
19
+ /** The element's events after which its picture may differ: metadata in, a new frame size, a source dropped. */
20
+ const PICTURE_EVENTS = ['loadedmetadata', 'resize', 'emptied'];
21
+ /**
22
+ * The video view: Chromium plays the file straight from its media URL
23
+ * (`info.mediaUrl`) in a `<video>` fitted to the window with its
24
+ * aspect kept, under the player's control bar (`MediaControls`), and nothing
25
+ * here decodes or demuxes a format. Only the metadata loads when the window
26
+ * opens, and nothing plays until the user asks; a seek reads from the new
27
+ * position through a range request, so a video of many gigabytes costs no
28
+ * more to open than a short one. The bar gives the picture's pixel size
29
+ * once the metadata is in, and F shows the player full screen. A file whose
30
+ * picture Chromium cannot show but whose sound it plays shows the audio
31
+ * view's mark and says so, instead of an empty frame. A file Chromium cannot
32
+ * play at all (a container or codecs it lacks, a decode failure) hands the
33
+ * window to hex with a note.
34
+ */
35
+ function VideoView({ info, onFallback }) {
36
+ const labels = useLabels().viewer;
37
+ const [videoRef, video] = useMediaElement(info.mediaUrl);
38
+ const [player, setPlayer] = useState(null);
39
+ const [picture, setPicture] = useState(UNKNOWN);
40
+ useEffect(() => {
41
+ if (!video)
42
+ return;
43
+ const update = () => setPicture(pictureOf(video));
44
+ for (const type of PICTURE_EVENTS)
45
+ video.addEventListener(type, update);
46
+ return () => {
47
+ for (const type of PICTURE_EVENTS)
48
+ video.removeEventListener(type, update);
49
+ };
50
+ }, [video]);
51
+ return (_jsxs("div", { className: "video-view", ref: setPlayer, children: [_jsxs("div", { className: "video-stage", "data-picture": picture.kind, children: [picture.kind === 'none' && (_jsxs("div", { className: "video-no-picture", children: [_jsx(AudioLines, { absoluteStrokeWidth: true, "aria-hidden": true, size: STAGE_GLYPH }), _jsx("p", { children: labels.media.noPicture })] })), _jsx("video", { "aria-label": info.name, onError: (event) => onFallback(mediaFallbackNote('video', event.currentTarget.error?.code ?? null, labels)), preload: "metadata", ref: videoRef })] }), _jsx(MediaControls, { fullscreen: true, media: video, player: player, children: picture.kind === 'size' && (_jsx("span", { className: "media-facts", children: labels.media.pixelSize(labels.number(picture.width), labels.number(picture.height)) })) })] }));
52
+ }
53
+ export default VideoView;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * How the text and hex views put a selection on the clipboard. A view's copy
3
+ * answers at once from the bytes it holds, after one bounded read, or with
4
+ * why it will not copy; this delivers each answer and says what happened in
5
+ * the view's status line.
6
+ */
7
+ import type { ViewerLabels } from '../labels/viewer.js';
8
+ /** A view's answer to copy: the text, a read that ends with it, or why there is none. */
9
+ export type ViewerCopy = {
10
+ readonly text: string;
11
+ } | {
12
+ readonly pending: Promise<string>;
13
+ } | {
14
+ readonly error: string;
15
+ };
16
+ /**
17
+ * A view's copy tickets: each copy takes one, and a copy whose text arrives
18
+ * late writes only while its ticket is the newest and the view is still
19
+ * mounted, so an older read, or one of a file the viewer has left, never
20
+ * overwrites a newer copy.
21
+ */
22
+ export declare function useCopyTickets(): () => () => boolean;
23
+ /**
24
+ * Puts `copied` on the clipboard: through `clipboardData` when the Edit
25
+ * menu's copy event supplied it and the text is ready, otherwise written
26
+ * once it is, while `current` (the copy's ticket) still holds. `say` shows a
27
+ * message in the view's status line, or clears it (null) once the copy is
28
+ * done.
29
+ */
30
+ export declare function deliverCopy(copied: ViewerCopy, clipboardData: DataTransfer | null, say: (message: string | null) => void, labels: ViewerLabels, current?: () => boolean): void;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * How the text and hex views put a selection on the clipboard. A view's copy
3
+ * answers at once from the bytes it holds, after one bounded read, or with
4
+ * why it will not copy; this delivers each answer and says what happened in
5
+ * the view's status line.
6
+ */
7
+ import { useCallback, useEffect, useRef } from 'react';
8
+ /**
9
+ * A view's copy tickets: each copy takes one, and a copy whose text arrives
10
+ * late writes only while its ticket is the newest and the view is still
11
+ * mounted, so an older read, or one of a file the viewer has left, never
12
+ * overwrites a newer copy.
13
+ */
14
+ export function useCopyTickets() {
15
+ const mounted = useRef(false);
16
+ const latest = useRef(0);
17
+ useEffect(() => {
18
+ mounted.current = true;
19
+ return () => {
20
+ mounted.current = false;
21
+ };
22
+ }, []);
23
+ return useCallback(() => {
24
+ latest.current += 1;
25
+ const ticket = latest.current;
26
+ return () => mounted.current && latest.current === ticket;
27
+ }, []);
28
+ }
29
+ /**
30
+ * Puts `copied` on the clipboard: through `clipboardData` when the Edit
31
+ * menu's copy event supplied it and the text is ready, otherwise written
32
+ * once it is, while `current` (the copy's ticket) still holds. `say` shows a
33
+ * message in the view's status line, or clears it (null) once the copy is
34
+ * done.
35
+ */
36
+ export function deliverCopy(copied, clipboardData, say, labels, current = () => true) {
37
+ if ('error' in copied) {
38
+ say(copied.error);
39
+ return;
40
+ }
41
+ if ('text' in copied && clipboardData !== null) {
42
+ clipboardData.setData('text/plain', copied.text);
43
+ say(null);
44
+ return;
45
+ }
46
+ let text;
47
+ if ('text' in copied) {
48
+ text = Promise.resolve(copied.text);
49
+ }
50
+ else {
51
+ say(labels.copying);
52
+ text = copied.pending;
53
+ }
54
+ // A read ends after the copy event, so the text goes to the clipboard on
55
+ // its own; a failed read explains itself. A copy a newer one overtook, or
56
+ // one of a view that has gone, writes and says nothing.
57
+ text
58
+ .then((value) => current()
59
+ ? navigator.clipboard.writeText(value).then(() => true, () => {
60
+ throw new Error(labels.copyFailed);
61
+ })
62
+ : false)
63
+ .then((written) => {
64
+ if (written && current())
65
+ say(null);
66
+ }, (error) => {
67
+ if (current())
68
+ say(error instanceof Error ? error.message : labels.copyFailed);
69
+ });
70
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Pure decisions behind the viewer window's frame: which modes a kind of
3
+ * content offers and in what order, what the frame says about the file, and
4
+ * what it says when the file changes on disk.
5
+ */
6
+ import type { ViewerContentKind, ViewerContentType, ViewerFileChange, ViewerFileInfo } from './types.js';
7
+ import type { ViewerLabels, ViewerModeLabels } from '../labels/viewer.js';
8
+ /**
9
+ * The views a file can be shown in. Each content kind offers some of them as
10
+ * modes; the view registry (`ViewerViews.tsx`) maps each to its component.
11
+ */
12
+ export type ViewerViewId = 'text' | 'hex' | 'image' | 'audio' | 'video' | 'pdf';
13
+ /** One entry of the mode switcher: the view it shows and the name it goes by there. */
14
+ export interface ViewerMode {
15
+ readonly view: ViewerViewId;
16
+ /** Which of the `viewer.modes` labels names it. */
17
+ readonly label: keyof ViewerModeLabels;
18
+ }
19
+ /**
20
+ * The modes each kind offers, the one it opens in first. Every kind can fall
21
+ * back to hex; a binary file has nothing else. An SVG opens in the image
22
+ * view, which the browser renders it in as an `<img>`, and its source is the
23
+ * text view.
24
+ */
25
+ export declare const VIEWER_MODES: Readonly<Record<ViewerContentKind, readonly ViewerMode[]>>;
26
+ /**
27
+ * The view to show after the content was (re)detected: the current one when
28
+ * the kind still offers it, else the kind's first.
29
+ */
30
+ export declare function viewForKind(kind: ViewerContentKind, current: ViewerViewId | null): ViewerViewId;
31
+ /**
32
+ * The view a native view hands the window to when the browser cannot show the
33
+ * file. An SVG is markup, so a broken one (malformed XML, or text that only
34
+ * carries the name) shows its source, where the fault can be read; any other
35
+ * kind shows hex.
36
+ */
37
+ export declare function fallbackViewFor(kind: ViewerContentKind): ViewerViewId;
38
+ /** The content in a word or two: "Text", "PNG image", "QuickTime video", "PDF document". */
39
+ export declare function contentLabel(content: ViewerContentType, labels: ViewerLabels): string;
40
+ /**
41
+ * The frame's line about the file: the archive or the server it came from,
42
+ * when it came from one, first, so a narrow window cuts the date before it;
43
+ * then size, content, and when it was last modified.
44
+ */
45
+ export declare function fileFacts(info: ViewerFileInfo, labels: ViewerLabels): string;
46
+ /** The exact size for the facts' tooltip: "1,234,567 bytes". */
47
+ export declare function exactSize(sizeBytes: number, labels: ViewerLabels): string;
48
+ /**
49
+ * The facts' tooltip: the exact size, and for a file from an archive or a
50
+ * server, where there the file is and that the window shows a read-only copy.
51
+ */
52
+ export declare function factsTitle(info: ViewerFileInfo, labels: ViewerLabels): string;
53
+ /**
54
+ * What the frame says when the file on disk is no longer the one the window
55
+ * shows, and whether Reload can bring it in; null while nothing changed. A
56
+ * removed file has nothing to reload, so the window keeps what it opened.
57
+ */
58
+ export declare function changeNotice(change: ViewerFileChange, labels: ViewerLabels): {
59
+ readonly text: string;
60
+ readonly canReload: boolean;
61
+ } | null;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Pure decisions behind the viewer window's frame: which modes a kind of
3
+ * content offers and in what order, what the frame says about the file, and
4
+ * what it says when the file changes on disk.
5
+ */
6
+ const mode = (view, label) => ({ view, label });
7
+ const HEX = mode('hex', 'hex');
8
+ /**
9
+ * The modes each kind offers, the one it opens in first. Every kind can fall
10
+ * back to hex; a binary file has nothing else. An SVG opens in the image
11
+ * view, which the browser renders it in as an `<img>`, and its source is the
12
+ * text view.
13
+ */
14
+ export const VIEWER_MODES = {
15
+ text: [mode('text', 'text'), HEX],
16
+ binary: [HEX],
17
+ image: [mode('image', 'image'), HEX],
18
+ svg: [mode('image', 'image'), mode('text', 'source'), HEX],
19
+ audio: [mode('audio', 'player'), HEX],
20
+ video: [mode('video', 'player'), HEX],
21
+ pdf: [mode('pdf', 'document'), HEX]
22
+ };
23
+ /**
24
+ * The view to show after the content was (re)detected: the current one when
25
+ * the kind still offers it, else the kind's first.
26
+ */
27
+ export function viewForKind(kind, current) {
28
+ const modes = VIEWER_MODES[kind];
29
+ return modes.find((mode) => mode.view === current)?.view ?? modes[0]?.view ?? 'hex';
30
+ }
31
+ /**
32
+ * The view a native view hands the window to when the browser cannot show the
33
+ * file. An SVG is markup, so a broken one (malformed XML, or text that only
34
+ * carries the name) shows its source, where the fault can be read; any other
35
+ * kind shows hex.
36
+ */
37
+ export function fallbackViewFor(kind) {
38
+ return kind === 'svg' ? 'text' : 'hex';
39
+ }
40
+ /** Format names for the media types the detection reports, as people say them; never translated. */
41
+ const FORMAT_NAMES = {
42
+ 'image/png': 'PNG',
43
+ 'image/apng': 'APNG',
44
+ 'image/jpeg': 'JPEG',
45
+ 'image/gif': 'GIF',
46
+ 'image/webp': 'WebP',
47
+ 'image/avif': 'AVIF',
48
+ 'image/bmp': 'BMP',
49
+ 'image/x-icon': 'ICO',
50
+ 'audio/mpeg': 'MP3',
51
+ 'audio/mp4': 'MPEG-4',
52
+ 'audio/aac': 'AAC',
53
+ 'audio/wav': 'WAV',
54
+ 'audio/flac': 'FLAC',
55
+ 'audio/ogg': 'Ogg',
56
+ 'audio/webm': 'WebM',
57
+ 'audio/x-matroska': 'Matroska',
58
+ 'video/mp4': 'MPEG-4',
59
+ 'video/quicktime': 'QuickTime',
60
+ 'video/webm': 'WebM',
61
+ 'video/ogg': 'Ogg',
62
+ 'video/x-matroska': 'Matroska'
63
+ };
64
+ /** The content in a word or two: "Text", "PNG image", "QuickTime video", "PDF document". */
65
+ export function contentLabel(content, labels) {
66
+ const format = FORMAT_NAMES[content.mimeType];
67
+ switch (content.kind) {
68
+ case 'text':
69
+ return labels.content.text;
70
+ case 'binary':
71
+ return labels.content.binary;
72
+ case 'svg':
73
+ return labels.content.svg;
74
+ case 'pdf':
75
+ return labels.content.pdf;
76
+ case 'image':
77
+ return labels.content.image(format ?? null);
78
+ case 'audio':
79
+ return labels.content.audio(format ?? null);
80
+ case 'video':
81
+ return labels.content.video(format ?? null);
82
+ }
83
+ }
84
+ /**
85
+ * The frame's line about the file: the archive or the server it came from,
86
+ * when it came from one, first, so a narrow window cuts the date before it;
87
+ * then size, content, and when it was last modified.
88
+ */
89
+ export function fileFacts(info, labels) {
90
+ const modified = labels.dateTime(info.modifiedMs);
91
+ return [
92
+ info.origin && labels.inArchive(info.origin.archiveName),
93
+ labels.size(info.sizeBytes),
94
+ contentLabel(info.content, labels),
95
+ modified && labels.modified(modified)
96
+ ]
97
+ .filter(Boolean)
98
+ .join(' · ');
99
+ }
100
+ /** The exact size for the facts' tooltip: "1,234,567 bytes". */
101
+ export function exactSize(sizeBytes, labels) {
102
+ return labels.exactSize(sizeBytes);
103
+ }
104
+ /**
105
+ * The facts' tooltip: the exact size, and for a file from an archive or a
106
+ * server, where there the file is and that the window shows a read-only copy.
107
+ */
108
+ export function factsTitle(info, labels) {
109
+ const size = exactSize(info.sizeBytes, labels);
110
+ return info.origin
111
+ ? `${size}\n${labels.readOnlyCopy(info.origin.entryPath, info.origin.archiveName)}`
112
+ : size;
113
+ }
114
+ /**
115
+ * What the frame says when the file on disk is no longer the one the window
116
+ * shows, and whether Reload can bring it in; null while nothing changed. A
117
+ * removed file has nothing to reload, so the window keeps what it opened.
118
+ */
119
+ export function changeNotice(change, labels) {
120
+ switch (change) {
121
+ case 'none':
122
+ return null;
123
+ case 'modified':
124
+ return { text: labels.change.modified, canReload: true };
125
+ case 'replaced':
126
+ return { text: labels.change.replaced, canReload: true };
127
+ case 'removed':
128
+ return { text: labels.change.removed, canReload: false };
129
+ }
130
+ }
@@ -0,0 +1,16 @@
1
+ /** The parts of a keystroke a viewer's close test reads, as the DOM names them. */
2
+ export interface ViewerKeyStroke {
3
+ readonly key: string;
4
+ readonly altKey: boolean;
5
+ readonly ctrlKey: boolean;
6
+ readonly metaKey: boolean;
7
+ readonly shiftKey: boolean;
8
+ readonly repeat: boolean;
9
+ }
10
+ /**
11
+ * Whether a keystroke closes a viewer by default: Escape alone, never a
12
+ * held key's repeats. An app whose own chord opens the viewer adds it, so
13
+ * the keys that bring a viewer up also put it away:
14
+ * `(stroke) => isViewerCloseKey(stroke) || (stroke.metaKey && stroke.key === 'y')`.
15
+ */
16
+ export declare function isViewerCloseKey(stroke: ViewerKeyStroke): boolean;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Whether a keystroke closes a viewer by default: Escape alone, never a
3
+ * held key's repeats. An app whose own chord opens the viewer adds it, so
4
+ * the keys that bring a viewer up also put it away:
5
+ * `(stroke) => isViewerCloseKey(stroke) || (stroke.metaKey && stroke.key === 'y')`.
6
+ */
7
+ export function isViewerCloseKey(stroke) {
8
+ return (stroke.key === 'Escape' &&
9
+ !stroke.repeat &&
10
+ !stroke.altKey &&
11
+ !stroke.ctrlKey &&
12
+ !stroke.metaKey &&
13
+ !stroke.shiftKey);
14
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Whether a key or copy event the viewer hears on the window is its own:
3
+ * aimed at something inside the viewer, or at nothing (no element, the
4
+ * page's body or root), as in a window that shows only the viewer with
5
+ * nothing focused. An event aimed at a control of the host's page beside
6
+ * the viewer (a search field, a drawer) stays the page's, so the viewer
7
+ * neither closes on its Escape nor copies over its Copy. The aim is read
8
+ * from the event's composed path, so a viewer inside an open shadow root,
9
+ * whose events reach the window retargeted to the shadow host, still knows
10
+ * them for its own.
11
+ */
12
+ export declare function isViewerEvent(event: Event): boolean;
@@ -0,0 +1,22 @@
1
+ /** The viewer's window and each view's root: where a key or copy is the viewer's. */
2
+ const VIEWER_ROOTS = '.viewer-window, .text-view, .hex-view, .image-view, .audio-view, .video-view';
3
+ /**
4
+ * Whether a key or copy event the viewer hears on the window is its own:
5
+ * aimed at something inside the viewer, or at nothing (no element, the
6
+ * page's body or root), as in a window that shows only the viewer with
7
+ * nothing focused. An event aimed at a control of the host's page beside
8
+ * the viewer (a search field, a drawer) stays the page's, so the viewer
9
+ * neither closes on its Escape nor copies over its Copy. The aim is read
10
+ * from the event's composed path, so a viewer inside an open shadow root,
11
+ * whose events reach the window retargeted to the shadow host, still knows
12
+ * them for its own.
13
+ */
14
+ export function isViewerEvent(event) {
15
+ const element = (event.composedPath().at(0) ?? event.target);
16
+ if (element === null || typeof element.closest !== 'function')
17
+ return true;
18
+ const page = element.ownerDocument;
19
+ if (element === page.body || element === page.documentElement)
20
+ return true;
21
+ return element.closest(VIEWER_ROOTS) !== null;
22
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The viewer's view registry: one component per view the mode switcher can
3
+ * show (`ViewerFrame.logic.ts` lists which views each content kind offers).
4
+ * Adding a view means adding its entry here and nothing else; the frame
5
+ * mounts whatever the entry names, keyed by the file's generation, so a
6
+ * reload starts every view afresh.
7
+ */
8
+ import type { ComponentType } from 'react';
9
+ import type { ViewerReader, ViewerFileInfo } from './types.js';
10
+ import type { ViewerViewId } from './ViewerFrame.logic.js';
11
+ /** What every view receives: the viewer's reader and the file as opened (or last reloaded). */
12
+ export interface ViewerViewProps {
13
+ /** Reads bounded byte ranges of the window's one file. */
14
+ readonly reader: ViewerReader;
15
+ /** Size, content, modification date, and media URL when the window opened or last reloaded. */
16
+ readonly info: ViewerFileInfo;
17
+ /**
18
+ * Hands the window to the kind's fallback view (`fallbackViewFor`: source
19
+ * for an SVG, hex for anything else) with `note` saying why, for a native
20
+ * view whose file Chromium could not show (an image that fails to decode,
21
+ * audio or video it cannot play). The frame ignores a call from a view it
22
+ * has since replaced on a reload, so a late error from the old file's
23
+ * player never moves the new one to hex.
24
+ */
25
+ readonly onFallback: (note: string) => void;
26
+ }
27
+ /** Every view's component. */
28
+ export declare const VIEWER_VIEWS: Readonly<Record<ViewerViewId, ComponentType<ViewerViewProps>>>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The viewer's view registry: one component per view the mode switcher can
3
+ * show (`ViewerFrame.logic.ts` lists which views each content kind offers).
4
+ * Adding a view means adding its entry here and nothing else; the frame
5
+ * mounts whatever the entry names, keyed by the file's generation, so a
6
+ * reload starts every view afresh.
7
+ */
8
+ import AudioView from './AudioView.js';
9
+ import HexView from './HexView.js';
10
+ import ImageView from './ImageView.js';
11
+ import PdfView from './PdfView.js';
12
+ import TextView from './TextView.js';
13
+ import VideoView from './VideoView.js';
14
+ /** Every view's component. */
15
+ export const VIEWER_VIEWS = {
16
+ text: TextView,
17
+ hex: HexView,
18
+ image: ImageView,
19
+ audio: AudioView,
20
+ video: VideoView,
21
+ pdf: PdfView
22
+ };
@@ -0,0 +1,53 @@
1
+ import { type ReactElement } from 'react';
2
+ import { type ViewerReader } from './types.js';
3
+ import { type ViewerKeyStroke } from './ViewerKeys.js';
4
+ import { type SyntaxWorkerFactory } from './SyntaxService.js';
5
+ /** Props for {@link ViewerWindow}. */
6
+ export interface ViewerWindowProps {
7
+ /**
8
+ * How the viewer reaches its one file; null shows the `unreachable`
9
+ * failure, for a page that was opened without one.
10
+ */
11
+ readonly reader: ViewerReader | null;
12
+ /**
13
+ * Puts the viewer away (a separate window calls `window.close()`), on
14
+ * the close keys whatever the viewer shows, a failure included.
15
+ */
16
+ readonly onClose: () => void;
17
+ /**
18
+ * Which keystrokes close the viewer; Escape alone by default
19
+ * (`isViewerCloseKey`). A key a view takes first stays the view's:
20
+ * Escape clearing a selection or the hex view's offset field. In full
21
+ * screen, Escape is the browser's, to leave it.
22
+ */
23
+ readonly isCloseKey?: (stroke: ViewerKeyStroke) => boolean;
24
+ /**
25
+ * Whether the window's own buttons sit at the header's leading end, as
26
+ * macOS draws its traffic lights over a hidden title bar: the file's name
27
+ * then starts clear of them (`--traffic-light-inset`). The header is a
28
+ * drag region either way, its mode switch excepted.
29
+ */
30
+ readonly trafficLights?: boolean;
31
+ /**
32
+ * Starts the text view's highlighting worker. By default the viewer's own
33
+ * worker, Shiki on its JavaScript regex engine, with each grammar loaded
34
+ * only when a file needs it; null shows text plain and starts no worker.
35
+ */
36
+ readonly syntaxWorker?: SyntaxWorkerFactory | null;
37
+ }
38
+ /**
39
+ * A read-only file viewer filling its window: a header with the file's
40
+ * name, size, kind, and modification date and a switch between the modes
41
+ * its kind offers, and the view for the chosen mode (text with syntax
42
+ * highlighting and line numbers, hex, image, audio, video, or PDF), each
43
+ * reading only the bytes on screen through `reader`. The file is inspected
44
+ * once as the viewer opens and again each time its window comes to the
45
+ * front; when its source no longer matches, a notice says so and offers
46
+ * Reload, while the view keeps what it has. A native view that cannot show
47
+ * the file hands over to its kind's fallback (source for an SVG, hex
48
+ * otherwise) with a note saying why. Its keys and Copy listen on the window
49
+ * and answer when aimed inside it or at nothing, leaving the page's own
50
+ * controls theirs (`isViewerEvent`), so mount one per window or
51
+ * document; a new `reader` starts it afresh on that file.
52
+ */
53
+ export declare function ViewerWindow(props: ViewerWindowProps): ReactElement;