@rightkit/document-core 0.1.2 → 0.2.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 (126) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +31 -7
  3. package/dist/app/chrome.js +1 -1
  4. package/dist/app/documentPrinting.d.ts +0 -6
  5. package/dist/app/documentPrinting.js +0 -18
  6. package/dist/app/shell/nativeMenu.d.ts +3 -2
  7. package/dist/app/shell/nativeMenu.js +8 -5
  8. package/dist/documents/perfEventCounters.d.ts +0 -8
  9. package/dist/documents/perfEventCounters.js +2 -1
  10. package/dist/documents/preview/previewFrame.d.ts +2 -1
  11. package/dist/documents/preview/previewFrame.js +9 -7
  12. package/dist/documents/searchUtils.js +1 -1
  13. package/dist/host.d.ts +36 -0
  14. package/dist/host.js +54 -0
  15. package/dist/index.d.ts +1 -46
  16. package/dist/index.js +1 -46
  17. package/dist/settings/themes.js +1 -1
  18. package/dist/state/bridgeEvents.d.ts +1 -1
  19. package/dist/state/bridgeEvents.js +7 -4
  20. package/dist/state/recentUrls.js +4 -3
  21. package/dist/state/tauriBridge.d.ts +3 -47
  22. package/dist/state/tauriBridge.js +6 -162
  23. package/dist/styles.css +2 -2
  24. package/package.json +16 -87
  25. package/dist/app/shortcutChords.d.ts +0 -6
  26. package/dist/app/shortcutChords.js +0 -14
  27. package/dist/app/useCloseFindOnSurfaceChange.d.ts +0 -14
  28. package/dist/app/useCloseFindOnSurfaceChange.js +0 -23
  29. package/dist/app/useEditText.d.ts +0 -6
  30. package/dist/app/useEditText.js +0 -10
  31. package/dist/appName.d.ts +0 -2
  32. package/dist/appName.js +0 -8
  33. package/dist/documents/FullscreenIcon.d.ts +0 -4
  34. package/dist/documents/FullscreenIcon.js +0 -7
  35. package/dist/documents/mdx/mdxRuntimeScript.d.ts +0 -2
  36. package/dist/documents/mdx/mdxRuntimeScript.js +0 -3
  37. package/dist/documents/mdx/mdxRuntimeScript.txt +0 -584
  38. package/dist/documents/pdf/MacPdfReadPane.d.ts +0 -23
  39. package/dist/documents/pdf/MacPdfReadPane.js +0 -708
  40. package/dist/documents/pdf/NativePdfDocument.d.ts +0 -9
  41. package/dist/documents/pdf/NativePdfDocument.js +0 -41
  42. package/dist/documents/pdf/PdfInlineTextEditor.d.ts +0 -53
  43. package/dist/documents/pdf/PdfInlineTextEditor.js +0 -225
  44. package/dist/documents/pdf/PdfOcrLayer.d.ts +0 -4
  45. package/dist/documents/pdf/PdfOcrLayer.js +0 -30
  46. package/dist/documents/pdf/PdfOutline.d.ts +0 -6
  47. package/dist/documents/pdf/PdfOutline.js +0 -12
  48. package/dist/documents/pdf/PdfPasswordPrompt.d.ts +0 -5
  49. package/dist/documents/pdf/PdfPasswordPrompt.js +0 -24
  50. package/dist/documents/pdf/PdfThumbnails.d.ts +0 -8
  51. package/dist/documents/pdf/PdfThumbnails.js +0 -201
  52. package/dist/documents/pdf/PdfToolbar.d.ts +0 -47
  53. package/dist/documents/pdf/PdfToolbar.js +0 -76
  54. package/dist/documents/pdf/PdfViewer.d.ts +0 -36
  55. package/dist/documents/pdf/PdfViewer.js +0 -1522
  56. package/dist/documents/pdf/PdfViewerBody.d.ts +0 -22
  57. package/dist/documents/pdf/PdfViewerBody.js +0 -42
  58. package/dist/documents/pdf/macPdfNativeBridge.d.ts +0 -118
  59. package/dist/documents/pdf/macPdfNativeBridge.js +0 -134
  60. package/dist/documents/pdf/nearestVisiblePdfPage.d.ts +0 -2
  61. package/dist/documents/pdf/nearestVisiblePdfPage.js +0 -22
  62. package/dist/documents/pdf/pdfBench.d.ts +0 -88
  63. package/dist/documents/pdf/pdfBench.js +0 -535
  64. package/dist/documents/pdf/pdfBenchAutopilot.d.ts +0 -48
  65. package/dist/documents/pdf/pdfBenchAutopilot.js +0 -154
  66. package/dist/documents/pdf/pdfBenchTransport.d.ts +0 -21
  67. package/dist/documents/pdf/pdfBenchTransport.js +0 -233
  68. package/dist/documents/pdf/pdfEditModel.d.ts +0 -294
  69. package/dist/documents/pdf/pdfEditModel.js +0 -105
  70. package/dist/documents/pdf/pdfEditor.d.ts +0 -100
  71. package/dist/documents/pdf/pdfEditor.js +0 -68
  72. package/dist/documents/pdf/pdfOcr.d.ts +0 -36
  73. package/dist/documents/pdf/pdfOcr.js +0 -88
  74. package/dist/documents/pdf/pdfOcrEdit.d.ts +0 -32
  75. package/dist/documents/pdf/pdfOcrEdit.js +0 -138
  76. package/dist/documents/pdf/pdfPrinting.d.ts +0 -28
  77. package/dist/documents/pdf/pdfPrinting.js +0 -110
  78. package/dist/documents/pdf/pdfSave.d.ts +0 -87
  79. package/dist/documents/pdf/pdfSave.js +0 -250
  80. package/dist/documents/pdf/pdfShared.d.ts +0 -16
  81. package/dist/documents/pdf/pdfShared.js +0 -20
  82. package/dist/documents/pdf/pdfToMarkdown.d.ts +0 -11
  83. package/dist/documents/pdf/pdfToMarkdown.js +0 -67
  84. package/dist/documents/pdf/pdfjsLibGlobal.d.ts +0 -1
  85. package/dist/documents/pdf/pdfjsLibGlobal.js +0 -12
  86. package/dist/documents/pdf/toolbarIcons.d.ts +0 -18
  87. package/dist/documents/pdf/toolbarIcons.js +0 -31
  88. package/dist/documents/pdf/usePdfDocumentLoader.d.ts +0 -40
  89. package/dist/documents/pdf/usePdfDocumentLoader.js +0 -243
  90. package/dist/documents/pdf/usePdfEditSession.d.ts +0 -88
  91. package/dist/documents/pdf/usePdfEditSession.js +0 -341
  92. package/dist/documents/pdf/usePdfEditor.d.ts +0 -59
  93. package/dist/documents/pdf/usePdfEditor.js +0 -317
  94. package/dist/documents/pdf/usePdfFit.d.ts +0 -19
  95. package/dist/documents/pdf/usePdfFit.js +0 -55
  96. package/dist/documents/pdf/usePdfOcr.d.ts +0 -38
  97. package/dist/documents/pdf/usePdfOcr.js +0 -337
  98. package/dist/documents/pdf/usePdfPreviewRecompose.d.ts +0 -28
  99. package/dist/documents/pdf/usePdfPreviewRecompose.js +0 -256
  100. package/dist/documents/pdf/usePdfSavePlan.d.ts +0 -61
  101. package/dist/documents/pdf/usePdfSavePlan.js +0 -287
  102. package/dist/documents/pdf/usePdfSearch.d.ts +0 -31
  103. package/dist/documents/pdf/usePdfSearch.js +0 -367
  104. package/dist/documents/pdf/usePdfViewControls.d.ts +0 -72
  105. package/dist/documents/pdf/usePdfViewControls.js +0 -152
  106. package/dist/documents/scopedSelectAll.d.ts +0 -5
  107. package/dist/documents/scopedSelectAll.js +0 -77
  108. package/dist/documents/txt/cmScroll.d.ts +0 -11
  109. package/dist/documents/txt/cmScroll.js +0 -52
  110. package/dist/documents/useMirroredEditText.d.ts +0 -15
  111. package/dist/documents/useMirroredEditText.js +0 -29
  112. package/dist/documents/useSplitResize.d.ts +0 -7
  113. package/dist/documents/useSplitResize.js +0 -37
  114. package/dist/settings/rk-settings.css +0 -38
  115. package/dist/settings/sections/EditorSection.d.ts +0 -1
  116. package/dist/settings/sections/EditorSection.js +0 -18
  117. package/dist/settings/sections/FileAssociationsSection.d.ts +0 -1
  118. package/dist/settings/sections/FileAssociationsSection.js +0 -5
  119. package/dist/settings/sections/MacFileAssociationsBlock.d.ts +0 -33
  120. package/dist/settings/sections/MacFileAssociationsBlock.js +0 -151
  121. package/dist/settings/sections/ThemeSection.d.ts +0 -1
  122. package/dist/settings/sections/ThemeSection.js +0 -31
  123. package/dist/settings/sections/TypographySection.d.ts +0 -1
  124. package/dist/settings/sections/TypographySection.js +0 -19
  125. package/dist/settings/sections/onOff.d.ts +0 -11
  126. package/dist/settings/sections/onOff.js +0 -8
@@ -1,22 +0,0 @@
1
- import type { MutableRefObject, RefObject, WheelEventHandler } from "react";
2
- import type { PDFDocumentProxy } from "pdfjs-dist";
3
- import type { OutlineNode, Size } from "./pdfShared.js";
4
- import type { OcrLine } from "./pdfOcr.js";
5
- export declare function PdfViewerBody({ panel, outline, pdfDoc, numPages, current, rotation, base, pageSizes, scale, renderErrors, ocrLinesByPage, scrollRef, slotRefs, onSelectDestination, onSelectPage, onWheel, }: {
6
- panel: null | "outline" | "thumbs";
7
- outline: OutlineNode[] | null;
8
- pdfDoc: PDFDocumentProxy | null;
9
- numPages: number;
10
- current: number;
11
- rotation: number;
12
- base: Size | null;
13
- pageSizes: Map<number, Size>;
14
- scale: number;
15
- renderErrors: Map<number, string>;
16
- ocrLinesByPage: ReadonlyMap<number, OcrLine[]>;
17
- scrollRef: RefObject<HTMLDivElement | null>;
18
- slotRefs: MutableRefObject<Map<number, HTMLDivElement>>;
19
- onSelectDestination: (dest: string | unknown[] | null) => void;
20
- onSelectPage: (page: number) => void;
21
- onWheel?: WheelEventHandler<HTMLDivElement>;
22
- }): import("react").JSX.Element;
@@ -1,42 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { PdfOutline } from "./PdfOutline.js";
3
- import { PdfThumbnails } from "./PdfThumbnails.js";
4
- import { PdfOcrLayer } from "./PdfOcrLayer.js";
5
- export function PdfViewerBody({ panel, outline, pdfDoc, numPages, current, rotation, base, pageSizes, scale, renderErrors, ocrLinesByPage, scrollRef, slotRefs, onSelectDestination, onSelectPage, onWheel, }) {
6
- return (_jsxs("div", { className: "relative flex min-h-0 flex-1", children: [panel && (_jsxs("aside", { className: `no-print shrink-0 overflow-hidden border-r border-line bg-panel ${panel === "outline" ? "w-64" : "w-44"}`, children: [panel === "outline" && outline && outline.length > 0 && (_jsx("div", { className: "h-full overflow-auto py-2 text-xs", children: _jsx(PdfOutline, { nodes: outline, onSelect: onSelectDestination }) })), panel === "thumbs" && pdfDoc && (_jsx(PdfThumbnails, { pdf: pdfDoc, numPages: numPages, current: current, rotation: rotation, onSelect: onSelectPage }))] })), _jsx("div", { ref: scrollRef, role: "region", "aria-label": "PDF pages", onWheel: onWheel, className: "min-h-0 flex-1 overflow-auto bg-ink/40 outline-none", children: _jsx("div", { className: "flex min-w-full flex-col items-start gap-4 py-6", children: base &&
7
- Array.from({ length: numPages }, (_, i) => i + 1).map((n) => {
8
- const fallback = rotation % 180 !== 0 ? { w: base.h, h: base.w } : base;
9
- const sz = pageSizes.get(n) ?? fallback;
10
- return (_jsxs("div", { "data-page": n, ref: (el) => {
11
- if (el)
12
- slotRefs.current.set(n, el);
13
- else
14
- slotRefs.current.delete(n);
15
- }, className: "relative mx-auto bg-white shadow",
16
- // T4-5 (conservative fix — see docs/PERF-AUDIT-2026-07-15.md): rather than
17
- // mounting/unmounting slot DOM nodes as the user scrolls (true windowing), keep
18
- // every slot mounted but tell the engine off-screen ones don't need layout/paint
19
- // work. `content-visibility: auto` skips style/layout/paint for subtrees the
20
- // browser judges "not relevant to the user" while still keeping the element (and
21
- // its box, since we already set an explicit width/height) in normal flow — so
22
- // `slotRefs`, `goToPage`'s `scrollIntoView`, the initial-view restore effect, and
23
- // the canvas IntersectionObserver in PdfViewer.tsx all keep working unchanged, with
24
- // zero risk to scroll-to-page/current-page tracking. True remove-from-DOM
25
- // windowing was not implemented: page heights are per-page-measured (mixed
26
- // orientation docs — see the "D1" comment in PdfViewer.tsx's renderPage) rather
27
- // than uniform, so an accurate windowed slot list needs an offset-aware version of
28
- // `thumbnailWindow()` (see @rightkit/pdf-ui) PLUS teaching
29
- // `goToPage`/the restore effect/the IntersectionObserver's `observe()` calls to
30
- // handle a target page whose slot isn't currently mounted — doable, but risky to
31
- // ship unverified (no way to interactively confirm scroll-to-page/search-jump/
32
- // outline-nav still land correctly in this pass). `content-visibility` is a no-op
33
- // in engines that don't support it (graceful degradation), so this is safe on both
34
- // WebView2 and WKWebView regardless of version.
35
- style: {
36
- width: sz.w * scale,
37
- height: sz.h * scale,
38
- contentVisibility: "auto",
39
- containIntrinsicSize: `${sz.w * scale}px ${sz.h * scale}px`,
40
- }, children: [ocrLinesByPage.has(n) && _jsx(PdfOcrLayer, { lines: ocrLinesByPage.get(n) ?? [] }), renderErrors.has(n) && (_jsxs("div", { className: "absolute inset-0 flex items-center justify-center bg-[var(--reader-surface)] p-4 text-center text-xs text-danger", children: ["Page ", n, " render error: ", renderErrors.get(n)] }))] }, n));
41
- }) }) })] }));
42
- }
@@ -1,118 +0,0 @@
1
- /** Rectangle for the native PDFKit view, in window CSS pixels. */
2
- export interface NativePdfFrame {
3
- x: number;
4
- y: number;
5
- width: number;
6
- height: number;
7
- }
8
- export interface NativePdfOutlineNode {
9
- title: string;
10
- page: number | null;
11
- children: NativePdfOutlineNode[];
12
- }
13
- export type NativePdfEditingAction = {
14
- kind: "annotation";
15
- mode: "freeText" | "ink" | "highlight" | "stamp";
16
- } | {
17
- kind: "text";
18
- } | {
19
- kind: "stamp";
20
- file: File;
21
- } | {
22
- kind: "ocr";
23
- } | {
24
- kind: "ocr-document";
25
- };
26
- export interface NativePdfState {
27
- owner: string;
28
- page: number;
29
- numPages: number;
30
- scale: number;
31
- fit: "width" | "page" | null;
32
- rotation: number;
33
- /** Native panel state survives pane eviction & parked-reader reuse. */
34
- panel?: "outline" | "thumbs" | null;
35
- locked: boolean;
36
- hasOutline: boolean;
37
- outline: NativePdfOutlineNode[];
38
- }
39
- export type NativePdfResourcePhase = "active" | "parked" | "released";
40
- export interface NativePdfResourceEvent {
41
- owner: string;
42
- path: string;
43
- identity: string | null;
44
- generation: number;
45
- phase: NativePdfResourcePhase;
46
- reason: string;
47
- activeCount: number;
48
- parkedCount: number;
49
- releasedCount: number;
50
- }
51
- export interface NativePdfOpenArgs {
52
- owner: string;
53
- path: string;
54
- frame: NativePdfFrame;
55
- readerRgb?: [number, number, number];
56
- initialView: {
57
- page?: number;
58
- scale?: number;
59
- fit?: "width" | "page" | null;
60
- rotation?: number;
61
- };
62
- password?: string;
63
- }
64
- export interface NativePdfUpdateArgs {
65
- owner: string;
66
- frame?: NativePdfFrame;
67
- readerRgb?: [number, number, number];
68
- page?: number;
69
- scale?: number;
70
- /** An empty string clears a fit mode. */
71
- fit?: "width" | "page" | "";
72
- rotation?: number;
73
- /** Empty string means no side panel. */
74
- panel?: "" | "thumbs" | "outline";
75
- visible?: boolean;
76
- }
77
- export interface NativePdfFindArgs {
78
- owner: string;
79
- query?: string;
80
- matchCase?: boolean;
81
- wholeWord?: boolean;
82
- direction?: 1 | -1;
83
- index?: number;
84
- clear?: boolean;
85
- }
86
- export interface NativePdfSearchResult {
87
- count: number;
88
- activeIndex: number;
89
- }
90
- export interface NativePdfKeyEvent {
91
- /** Native key events may omit owner because window has one native PDF host. */
92
- owner?: string;
93
- key: string;
94
- code: string;
95
- metaKey: boolean;
96
- ctrlKey: boolean;
97
- altKey: boolean;
98
- shiftKey: boolean;
99
- }
100
- export interface NativePdfError extends Error {
101
- /** The shell's stable code, for example `unsupported`, `not_open`, `stale_owner`. */
102
- code?: string;
103
- }
104
- export declare function nativePdfOpen(args: NativePdfOpenArgs): Promise<NativePdfState>;
105
- export declare function nativePdfUpdate(args: NativePdfUpdateArgs): Promise<NativePdfState>;
106
- export declare function nativePdfState(owner: string): Promise<NativePdfState>;
107
- export type NativePdfCloseReason = "terminal-close" | "reload" | "edit-handoff" | "fallback" | "open-replaced";
108
- export declare function nativePdfClose(owner: string, path?: string, reason?: NativePdfCloseReason): Promise<void>;
109
- /** Close any native reader for a path when its app tab is genuinely removed. */
110
- export declare function nativePdfClosePath(path: string, reason?: NativePdfCloseReason): Promise<void>;
111
- export declare function nativePdfSuspend(owner: string, path: string): Promise<void>;
112
- export declare function nativePdfFind(args: NativePdfFindArgs): Promise<NativePdfSearchResult>;
113
- export declare function nativePdfPrint(owner: string): Promise<boolean>;
114
- export declare function listenNativePdfState(onState: (state: NativePdfState) => void): Promise<() => void>;
115
- export declare function listenNativePdfResource(onResource: (event: NativePdfResourceEvent) => void): Promise<() => void>;
116
- export declare function listenNativePdfKey(onKey: (event: NativePdfKeyEvent) => void): Promise<() => void>;
117
- /** Release frontend observation on HMR/test reset; it does not send a native command. */
118
- export declare function resetNativePdfBridgeForTests(): void;
@@ -1,134 +0,0 @@
1
- import { invoke } from "@tauri-apps/api/core";
2
- import { listen } from "@tauri-apps/api/event";
3
- import { getCurrentWindow } from "@tauri-apps/api/window";
4
- import { acquireResource, updateResource } from "../../app/resourceCensus.js";
5
- // The shell's rightkit_pdf_* commands and events (rightkit-tauri-shell pdf_host). Failures cross
6
- // IPC as `{ code, message }`, not as an Error or a string.
7
- const CMD = {
8
- open: "rightkit_pdf_open",
9
- update: "rightkit_pdf_update",
10
- state: "rightkit_pdf_state",
11
- close: "rightkit_pdf_close",
12
- suspend: "rightkit_pdf_suspend",
13
- find: "rightkit_pdf_find",
14
- print: "rightkit_pdf_print",
15
- };
16
- const EVENT_STATE = "rightkit://pdf-state";
17
- const EVENT_RESOURCE = "rightkit://pdf-resource";
18
- const EVENT_KEY = "rightkit://pdf-key";
19
- function toError(cause) {
20
- if (cause instanceof Error)
21
- return cause;
22
- if (cause && typeof cause === "object" && typeof cause.message === "string") {
23
- const error = new Error(cause.message);
24
- const code = cause.code;
25
- if (typeof code === "string")
26
- error.code = code;
27
- return error;
28
- }
29
- return new Error(String(cause));
30
- }
31
- async function call(command, args) {
32
- try {
33
- return await invoke(command, args);
34
- }
35
- catch (cause) {
36
- throw toError(cause);
37
- }
38
- }
39
- // Native PDFKit views are window-owned. Serializing every lifecycle command prevents a queued
40
- // StrictMode cleanup (or a document switch) from racing a newer open and reusing an old native view.
41
- let queue = Promise.resolve();
42
- let resourceListener = null;
43
- let resourceEpoch = 0;
44
- const resourceHandles = new Map();
45
- // PDFKit generations survive tab reactivation, unlike React owners. Keep this listener
46
- // outside pane lifetime so native expiry and terminal-close events remain observable.
47
- function ensureResourceListener() {
48
- if (!resourceListener) {
49
- const epoch = resourceEpoch;
50
- resourceListener = listenNativePdfResource((event) => {
51
- if (epoch !== resourceEpoch)
52
- return;
53
- const release = resourceHandles.get(event.generation);
54
- if (event.phase === "released") {
55
- release?.();
56
- resourceHandles.delete(event.generation);
57
- return;
58
- }
59
- const kind = event.phase === "parked" ? "pdf-native-parked-reader" : "pdf-native-reader";
60
- if (release) {
61
- updateResource(release, { kind });
62
- }
63
- else {
64
- resourceHandles.set(event.generation, acquireResource({ kind, documentPath: event.path, format: "pdf" }));
65
- }
66
- }).catch((error) => {
67
- if (epoch === resourceEpoch)
68
- resourceListener = null;
69
- throw error;
70
- });
71
- }
72
- return resourceListener;
73
- }
74
- function enqueue(task) {
75
- const run = queue.then(task, task);
76
- queue = run.then(() => undefined, () => undefined);
77
- return run;
78
- }
79
- export function nativePdfOpen(args) {
80
- return enqueue(async () => {
81
- await ensureResourceListener();
82
- return call(CMD.open, { ...args });
83
- });
84
- }
85
- export function nativePdfUpdate(args) {
86
- return enqueue(() => call(CMD.update, { ...args }));
87
- }
88
- export function nativePdfState(owner) {
89
- return enqueue(() => call(CMD.state, { owner }));
90
- }
91
- export function nativePdfClose(owner, path, reason = "terminal-close") {
92
- return enqueue(() => call(CMD.close, {
93
- owner,
94
- ...(path === undefined ? {} : { path }),
95
- reason,
96
- }));
97
- }
98
- /** Close any native reader for a path when its app tab is genuinely removed. */
99
- export function nativePdfClosePath(path, reason = "terminal-close") {
100
- return nativePdfClose("", path, reason);
101
- }
102
- export function nativePdfSuspend(owner, path) {
103
- return enqueue(() => call(CMD.suspend, { owner, path }));
104
- }
105
- export function nativePdfFind(args) {
106
- return enqueue(() => call(CMD.find, { ...args }).then((result) => ({
107
- count: result.count,
108
- activeIndex: result.activeIndex ?? -1,
109
- })));
110
- }
111
- export function nativePdfPrint(owner) {
112
- return enqueue(() => call(CMD.print, { owner }));
113
- }
114
- export async function listenNativePdfState(onState) {
115
- return listen(EVENT_STATE, (event) => onState(event.payload));
116
- }
117
- export async function listenNativePdfResource(onResource) {
118
- return listen(EVENT_RESOURCE, (event) => onResource(event.payload), { target: { kind: "WebviewWindow", label: getCurrentWindow().label } });
119
- }
120
- export async function listenNativePdfKey(onKey) {
121
- return listen(EVENT_KEY, (event) => onKey(event.payload));
122
- }
123
- /** Release frontend observation on HMR/test reset; it does not send a native command. */
124
- export function resetNativePdfBridgeForTests() {
125
- queue = Promise.resolve();
126
- resourceEpoch++;
127
- void resourceListener?.then((unlisten) => unlisten()).catch(() => { });
128
- resourceListener = null;
129
- for (const release of resourceHandles.values())
130
- release();
131
- resourceHandles.clear();
132
- }
133
- if (import.meta.hot)
134
- import.meta.hot.dispose(resetNativePdfBridgeForTests);
@@ -1,2 +0,0 @@
1
- /** Pure page-picking helper, kept free of pdf.js so it is testable without a DOM-bound viewer. */
2
- export declare function nearestVisiblePdfPage(root: HTMLElement, slots: ReadonlyMap<number, HTMLElement>, visiblePages: ReadonlySet<number>, fallbackPage: number): number;
@@ -1,22 +0,0 @@
1
- /** Pure page-picking helper, kept free of pdf.js so it is testable without a DOM-bound viewer. */
2
- export function nearestVisiblePdfPage(root, slots, visiblePages, fallbackPage) {
3
- const rootRect = root.getBoundingClientRect();
4
- const centerY = rootRect.top + rootRect.height / 2;
5
- let bestPage = fallbackPage;
6
- let bestDistance = Number.POSITIVE_INFINITY;
7
- const pages = visiblePages.size > 0 ? visiblePages : slots.keys();
8
- for (const page of pages) {
9
- const slot = slots.get(page);
10
- if (!slot)
11
- continue;
12
- const rect = slot.getBoundingClientRect();
13
- if (rect.bottom < rootRect.top || rect.top > rootRect.bottom)
14
- continue;
15
- const distance = Math.abs(rect.top + rect.height / 2 - centerY);
16
- if (distance < bestDistance) {
17
- bestDistance = distance;
18
- bestPage = page;
19
- }
20
- }
21
- return bestPage;
22
- }
@@ -1,88 +0,0 @@
1
- import { type ResourceCensus } from "../../app/resourceCensus.js";
2
- export type PdfBenchLoadMode = "buffer" | "url-native" | "custom-range";
3
- export interface PdfBenchStreamStats {
4
- readonly enabled: boolean;
5
- readonly resource_bytes: number;
6
- readonly head_requests: number;
7
- readonly full_get_requests: number;
8
- readonly range_get_requests: number;
9
- readonly rejected_range_requests: number;
10
- readonly full_bytes_read: number;
11
- readonly range_bytes_read: number;
12
- readonly total_bytes_read: number;
13
- readonly max_response_bytes: number;
14
- }
15
- export interface PdfBenchProcessMemory {
16
- /** RSS for the app process only; this is not total webview memory. */
17
- readonly app_process_rss_bytes: number;
18
- /** RSS summed across the app process tree; this is not total webview memory. */
19
- readonly app_process_tree_rss_bytes: number;
20
- readonly process_count: number;
21
- }
22
- export interface PdfBenchRuntimeStats {
23
- readonly js_heap_used_bytes: number | null;
24
- readonly js_heap_total_bytes: number | null;
25
- readonly js_heap_limit_bytes: number | null;
26
- readonly longtask_count: number;
27
- readonly longtask_duration_ms: number;
28
- }
29
- export interface PdfBenchSnapshot {
30
- readonly at_ms: number;
31
- readonly stream: PdfBenchStreamStats | null;
32
- readonly process_memory: PdfBenchProcessMemory | null;
33
- readonly runtime: PdfBenchRuntimeStats;
34
- readonly resources: ResourceCensus;
35
- }
36
- export interface PdfBenchResult {
37
- readonly schema_version: 1;
38
- readonly mode: PdfBenchLoadMode;
39
- readonly run_id: string;
40
- readonly launch_kind: string | null;
41
- readonly run_index: number | null;
42
- readonly run_total: number | null;
43
- readonly started_at: string;
44
- readonly platform: string;
45
- readonly user_agent: string;
46
- readonly pdfjs_version: string;
47
- readonly document_ready_ms: number | null;
48
- readonly first_canvas_ms: number | null;
49
- readonly first_canvas_page: number | null;
50
- readonly baseline_memory: PdfBenchProcessMemory | null;
51
- readonly baseline_runtime: PdfBenchRuntimeStats;
52
- readonly first_canvas_snapshot: PdfBenchSnapshot | null;
53
- readonly late_page_target: number | null;
54
- readonly late_page_request_ms: number | null;
55
- readonly late_page_ms: number | null;
56
- readonly late_page_snapshot: PdfBenchSnapshot | null;
57
- readonly settled_snapshot: PdfBenchSnapshot | null;
58
- readonly fixture_label: string | null;
59
- readonly source_filename: string | null;
60
- readonly fixture_bytes: number | null;
61
- readonly fixture_sha256: string | null;
62
- readonly fixture_identity_status: "missing" | "pending" | "matched" | "mismatch";
63
- readonly error: string | null;
64
- }
65
- export declare function isPdfBenchEnabled(): boolean;
66
- export declare function getPdfBenchLoadMode(): PdfBenchLoadMode;
67
- export declare function registerPdfBenchLatePageNavigator(navigator: ((requested: number) => number | null) | null): void;
68
- export declare function beginPdfBench(url: string, pdfjsVersion: string, mode?: PdfBenchLoadMode): Promise<void>;
69
- export declare function markPdfBenchDocumentReady(url: string): void;
70
- export declare function markPdfBenchFirstCanvasPaint(url: string | undefined, page: number): void;
71
- export declare function markPdfBenchError(url: string, error: unknown): void;
72
- declare global {
73
- interface Window {
74
- vrPdfBench?: {
75
- status(): unknown;
76
- enable(mode?: PdfBenchLoadMode, reload?: boolean): void;
77
- disable(reload?: boolean): void;
78
- setMode(mode: PdfBenchLoadMode, reload?: boolean): void;
79
- report(): Promise<PdfBenchResult | null>;
80
- history(): PdfBenchResult[];
81
- clearHistory(): void;
82
- download(): Promise<unknown>;
83
- autopilot(label?: string, repeats?: number): void;
84
- autopilotStatus(): unknown;
85
- stopAutopilot(): void;
86
- };
87
- }
88
- }