@ruckc/truss-pdf 0.0.0-stage → 1.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -2
- package/dist/PdfDialog.svelte +72 -0
- package/dist/PdfDialog.svelte.d.ts +15 -0
- package/dist/PdfReview.svelte +174 -0
- package/dist/PdfReview.svelte.d.ts +120 -0
- package/dist/PdfViewer.svelte +1184 -0
- package/dist/PdfViewer.svelte.d.ts +92 -0
- package/dist/ReviewPanel.svelte +591 -0
- package/dist/ReviewPanel.svelte.d.ts +126 -0
- package/dist/assets.d.ts +9 -0
- package/dist/assets.js +29 -0
- package/dist/bidi.d.ts +2 -0
- package/dist/bidi.js +9 -0
- package/dist/cssvars.d.ts +12 -0
- package/dist/cssvars.js +32 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +7 -0
- package/dist/labels.d.ts +6 -0
- package/dist/labels.js +23 -0
- package/dist/pages.d.ts +54 -0
- package/dist/pages.js +171 -0
- package/dist/paging.d.ts +18 -0
- package/dist/paging.js +110 -0
- package/dist/pdfjs.d.ts +40 -0
- package/dist/pdfjs.js +49 -0
- package/dist/quote-match.d.ts +30 -0
- package/dist/quote-match.js +145 -0
- package/dist/types.d.ts +142 -0
- package/dist/types.js +1 -0
- package/package.json +54 -5
package/README.md
CHANGED
|
@@ -1,3 +1,123 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ruckc/truss-pdf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A PDF viewer for [Truss UI](https://truss.ruck.io), built on [pdf.js](https://mozilla.github.io/pdf.js/) with hardened defaults for untrusted files: one page at a time, whole-page paging, a selectable text layer, jumps to a page, region, quote or destination, annotation overlays the host controls, and a review workflow (next / previous through a list of items, with host-defined actions).
|
|
4
|
+
|
|
5
|
+
Docs: <https://truss.ruck.io/docs/packages>
|
|
6
|
+
|
|
7
|
+
> **Publishing note.** This package's first version is published by hand (`npm publish --workspace packages/pdf`); only after that does the release workflow's OIDC trusted publishing take it over. Until then it is deliberately left out of the `npm publish` command in `.releaserc.json` (its version still moves in lockstep through `scripts/set-version.mjs`).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @ruckc/truss-pdf @ruckc/truss-ui
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`svelte` (^5.20) and `@ruckc/truss-ui` are peer dependencies; `pdfjs-dist` (6.x) is a dependency, loaded lazily in the browser (never on the server, never in the main bundle).
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```svelte
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { PdfViewer, type PdfAnnotation, type PdfTarget } from '@ruckc/truss-pdf';
|
|
22
|
+
|
|
23
|
+
let page = $state(1);
|
|
24
|
+
let selected = $state<string | null>(null);
|
|
25
|
+
let target = $state<PdfTarget | null>({ page: 4, quote: 'the termination clause applies' });
|
|
26
|
+
let annotations = $state<PdfAnnotation[]>([
|
|
27
|
+
{ id: 'f1', page: 2, target: { boxes: [{ x: 72, y: 600, width: 300, height: 40 }] }, tone: 'danger', label: 'Hidden text' },
|
|
28
|
+
{ id: 'f2', page: 4, target: { quote: 'ignore previous instructions' }, tone: 'warning', label: 'Prompt injection' }
|
|
29
|
+
]);
|
|
30
|
+
let viewer: ReturnType<typeof PdfViewer>;
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<PdfViewer bind:this={viewer} src="/files/report.pdf" title="report.pdf" bind:page bind:selected {annotations} {target}
|
|
34
|
+
ontarget={(result, t) => result !== 'found' && console.info('not found exactly', t)}
|
|
35
|
+
onselect={(id) => console.info('selected', id)} />
|
|
36
|
+
|
|
37
|
+
<button onclick={() => viewer.goTo({ annotation: 'f2', focus: true })}>Next finding</button>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- **Source**: `src` is a URL, an `ArrayBuffer` or a `Uint8Array` (copied before pdf.js transfers it to its worker).
|
|
41
|
+
- **Viewing**: `mode="page" | "fit-width"` (bindable); buttons, PgUp/PgDn, the arrows (they scroll a tall page in fit width), Home/End, the wheel and trackpad (one page per gesture) and swipes turn whole pages; the page box jumps to a page. The text layer can be selected and copied.
|
|
42
|
+
- **Jumps** (`target` prop, re-applied when `targetKey` changes, or `goTo(target)` which resolves with `'found' | 'partial' | 'missing'`): `{ page }`; `{ page, x, y, width, height }` in PDF user space (points, origin bottom-left, rotation and crop box handled), outlined and centred; `{ page?, quote, strict? }`, matched fuzzily (case, accents, ligatures, punctuation, whitespace and line-end hyphens do not matter, `…` elisions match piecewise, the longest run of words is a `partial` match), searched on `page` first then the nearest pages; `{ dest }`, a named destination or an outline title; `{ annotation, focus? }`.
|
|
43
|
+
- **Annotations**: `annotations` (update the array; selection is kept by id) are drawn over the page, never into the PDF. `tone` maps to the intent tokens, `muted` quiets one, the label shows on hover and focus and names it, click / Enter / Space select it (`bind:selected`, `onselect`), and Tab reaches them in reading order.
|
|
44
|
+
- **Creating**: with `oncreate`, the toolbar offers a draw-a-box tool and "annotate the selected text"; it is called with `{ page, boxes, text }` in user space. Storing it is up to you.
|
|
45
|
+
- **Links of the document**: internal links jump; `http(s)` and `mailto` links open in a new tab with `rel="noopener noreferrer"`, or call `onlink(url)` instead so you can confirm first. Other schemes are never clickable.
|
|
46
|
+
- `PdfDialog` wraps the viewer in a full-size `Dialog` with the same props and `goTo`.
|
|
47
|
+
|
|
48
|
+
## Review workflow
|
|
49
|
+
|
|
50
|
+
`ReviewPanel` steps through a list of items about the document (integrity findings, redactions, comments, a QA checklist) and drives the viewer; `PdfReview` lays the two out side by side.
|
|
51
|
+
|
|
52
|
+
```svelte
|
|
53
|
+
<script lang="ts">
|
|
54
|
+
import { PdfReview, type ReviewItem, type ReviewAction, type ReviewFilter } from '@ruckc/truss-pdf';
|
|
55
|
+
|
|
56
|
+
type Finding = ReviewItem & { excerpt?: string };
|
|
57
|
+
let findings = $state<Finding[]>([
|
|
58
|
+
{ id: 'f1', page: 2, annotation: 'a1', title: 'Hidden text', status: 'open', tone: 'danger', excerpt: '…' },
|
|
59
|
+
{ id: 'f2', title: 'JavaScript on open', status: 'open' } // no page: the "Document" group
|
|
60
|
+
]);
|
|
61
|
+
const filters: ReviewFilter<Finding>[] = [
|
|
62
|
+
{ id: 'open', label: 'Open', match: (f) => f.status === 'open' },
|
|
63
|
+
{ id: 'done', label: 'Reviewed', match: (f) => f.status !== 'open' },
|
|
64
|
+
{ id: 'all', label: 'All', match: () => true }
|
|
65
|
+
];
|
|
66
|
+
const actions: ReviewAction<Finding>[] = [
|
|
67
|
+
{ id: 'accept', label: 'Accept', shortcut: 'a', tone: 'success', applies: (f) => f.status === 'open',
|
|
68
|
+
confirm: (f) => ({ title: 'Send this text to the judges?', excerpt: f.excerpt, note: true }) },
|
|
69
|
+
{ id: 'dismiss', label: 'Dismiss', shortcut: 'd', tone: 'neutral', applies: (f) => f.status === 'open' },
|
|
70
|
+
{ id: 'reopen', label: 'Reopen', shortcut: 'r', applies: (f) => f.status !== 'open' }
|
|
71
|
+
];
|
|
72
|
+
async function onaction(action: string, f: Finding, { note }: { note?: string }) {
|
|
73
|
+
await api.review(f.id, action, note); // a rejection shows a toast; the panel is busy meanwhile
|
|
74
|
+
findings = findings.map((x) => (x.id === f.id ? { ...x, status: action === 'reopen' ? 'open' : action } : x));
|
|
75
|
+
}
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<PdfReview src={url} title="submission.pdf" {annotations} items={findings} {filters} {actions} {onaction} bind:current>
|
|
79
|
+
{#snippet detail(f)}<blockquote>{f.excerpt}</blockquote>{/snippet}
|
|
80
|
+
</PdfReview>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- **Items** (`ReviewItem`): `{ id, page?, annotation?, target?, title, description?, tone?, status }`, plus any fields of your own (the panel is generic and hands the item back to `filters`, `actions`, `onaction` and `detail`). Items without a `page` are listed first, in a "Document" group; the rest are grouped by page, in your order within a page. That order is the navigation order.
|
|
84
|
+
- **Filters**: `filters: { id, label, match }[]` become segments with their counts (`bind:filter`); without them there is one "All" segment. `statuses` gives each status a label and a tone for its tag.
|
|
85
|
+
- **Navigation**: Previous / Next, an "n of m" indicator, and `j` / `k` and `]` / `[` (ignored in text fields, contenteditables and dialogs, with a modifier, and while an action runs). Moving to an item scrolls its `annotation` into view and selects it (`goTo({ annotation })`), else goes to its `target`, else to its `page`; a document-level item leaves the viewer where it is. `onnavigate(item, result)` reports the outcome. `bind:current` is the selected item's id (set it to move there); a click on an annotation in the viewer selects its item.
|
|
86
|
+
- **Actions**: `actions: { id, label, shortcut?, tone?, applies?, confirm?, bulk?, confirmBulk? }[]` are buttons for the selected item, with their shortcuts. `onaction(id, item, { note })` may return a promise: the panel is busy (`aria-busy`, buttons and keys off) until it settles, and a rejection shows a danger toast (mount the core `Toaster`). When `confirm(item)` returns `{ title, message?, excerpt?, confirmLabel?, tone?, note? }`, a dialog asks first; the excerpt is quoted as bidi-isolated text, and `note` (`true`, or `{ label?, placeholder?, required?, value? }`) adds a note field whose text `onaction` receives.
|
|
87
|
+
- **Auto-advance and optimistic updates**: update `items` after an action. The selection follows its `id` across updates; when the selected item leaves the filter (or the list), the item that takes its place is selected, the previous one when it was the last, and an empty state when none are left.
|
|
88
|
+
- **Detail**: the `detail` snippet renders your content for the selected item (an excerpt, notes, an analysis).
|
|
89
|
+
- **Bulk**: `bulk` adds checkboxes (`bind:checked`), a check-all box, and a bar with the actions marked `bulk: true`, each run on the checked items it applies to through `onbulkaction(id, items, { note })` (with `confirmBulk(items)` asked first).
|
|
90
|
+
- **Accessibility**: each page's group is a list named by its heading, and the selected row is `aria-current`. A polite live region announces each move ("2 of 5: Hidden text") and each outcome ("Accept: Hidden text. 3 of 4: …"). Every text is a label (`ReviewPanelLabels`, `PdfReviewLabels`), and item titles, descriptions, excerpts and statuses are bidi-isolated text, never HTML.
|
|
91
|
+
- **Layout**: `PdfReview` puts the viewer and the panel in a core `SplitPane` (`panelWidth`, the divider resizes it) and stacks the panel under the viewer at or below `breakpoint` (the app-wide narrow breakpoint by default). Its props are the viewer's (`src`, `title`, `annotations`, `bind:page`, `bind:mode`, `bind:selected`, any other in `viewerProps`, the toolbar snippet as `toolbar`, `viewerLabels`) and the panel's; `goTo`, `next`, `previous` and `handleKey` are forwarded.
|
|
92
|
+
- **Keys and scope**: the review keys are heard inside the `PdfReview` (or the `ReviewPanel` on its own), so two reviews on a page never fight. For page-wide keys call `handleKey(e)` from your own `svelte:window` listener (and pass `keys={false}`). A standalone `ReviewPanel` beside a `PdfViewer` takes `viewer` (the viewer instance) and shares `bind:selected` with it.
|
|
93
|
+
|
|
94
|
+
## Security defaults
|
|
95
|
+
|
|
96
|
+
- `getDocument` always gets `isEvalSupported: false` and `enableXfa: false` (after any other option, so nothing overrides them).
|
|
97
|
+
- No document JavaScript: no scripting manager is created and the PDF's own annotation layer (forms, actions) is never rendered. QuickJS (pdf.js's scripting sandbox) is not even bundled.
|
|
98
|
+
- No `{@html}`: labels, quotes, titles and link addresses are text nodes or attributes, wrapped in Unicode bidi isolates (`isolate()`), so a right-to-left override cannot disguise them.
|
|
99
|
+
- pdf.js logs errors only (`configurePdf({ verbosity })`), so a hostile file cannot flood the console.
|
|
100
|
+
|
|
101
|
+
## Assets and configuration
|
|
102
|
+
|
|
103
|
+
Under Vite nothing needs configuring: the worker comes from `pdfjs-dist/build/pdf.worker.min.mjs?url`, and the CMaps, standard fonts and wasm decoders are hashed assets served on demand. Elsewhere, or to serve them from your own path or CDN:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { configurePdf } from '@ruckc/truss-pdf';
|
|
107
|
+
configurePdf({ workerSrc: '/pdfjs/pdf.worker.min.mjs', cMapUrl: '/pdfjs/cmaps/', standardFontDataUrl: '/pdfjs/standard_fonts/', wasmUrl: '/pdfjs/wasm/' });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Copy those files from `node_modules/pdfjs-dist/` (`build/`, `cmaps/`, `standard_fonts/`, `wasm/`). With your own URLs pdf.js fetches them from its worker, which also enables ICC colour management (the bundled default leaves it off). `configurePdf({ loader })` loads another pdf.js build.
|
|
111
|
+
|
|
112
|
+
## Strict CSP
|
|
113
|
+
|
|
114
|
+
No `'unsafe-inline'` is needed in `style-src`: the package sets dynamic values through the CSSOM, and so does pdf.js for its text layer. Allow the worker in `worker-src` (`'self'` for the bundled one) and the PDF and data files in `connect-src`. The JPEG 2000 and JBIG2 image decoders are WebAssembly and need `'wasm-unsafe-eval'` in `script-src`; without it those images are not drawn (pdf.js's JavaScript fallbacks are only reachable with your own `wasmUrl`, as scripts that `script-src` must allow). The Truss documentation's Content Security Policy page has the details.
|
|
115
|
+
|
|
116
|
+
## Planned
|
|
117
|
+
|
|
118
|
+
- A plain-text mode with the same jump, highlight and review API for non-PDF documents (text extracted from DOCX, per page).
|
|
119
|
+
- Exporting annotations as real PDF annotations.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A `PdfViewer` in a full-size core `Dialog` (EvalBot's original form). Every viewer prop is passed through; `goTo` is forwarded.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import type { ComponentProps } from 'svelte';
|
|
7
|
+
import { Dialog } from '@ruckc/truss-ui';
|
|
8
|
+
import PdfViewer from './PdfViewer.svelte';
|
|
9
|
+
import { isolate } from './bidi.js';
|
|
10
|
+
import type { PdfGoToResult, PdfTarget } from './types.js';
|
|
11
|
+
|
|
12
|
+
let {
|
|
13
|
+
open = $bindable(false),
|
|
14
|
+
title,
|
|
15
|
+
page = $bindable(1),
|
|
16
|
+
mode = $bindable('page'),
|
|
17
|
+
selected = $bindable(null),
|
|
18
|
+
pageCount = $bindable(0),
|
|
19
|
+
...rest
|
|
20
|
+
}: Omit<ComponentProps<typeof PdfViewer>, 'height'> & {
|
|
21
|
+
/** Whether the dialog is open. Bindable. The document is loaded while it is open and released when it closes. */
|
|
22
|
+
open?: boolean;
|
|
23
|
+
/** The dialog title (the document's name; bidi-isolated). */
|
|
24
|
+
title: string;
|
|
25
|
+
} = $props();
|
|
26
|
+
|
|
27
|
+
let viewer = $state<ReturnType<typeof PdfViewer>>();
|
|
28
|
+
|
|
29
|
+
/** `PdfViewer.goTo` of the dialog's viewer (`missing` while the dialog is closed). */
|
|
30
|
+
export function goTo(t: PdfTarget): Promise<PdfGoToResult> {
|
|
31
|
+
return viewer ? viewer.goTo(t) : Promise.resolve('missing');
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<Dialog bind:open title={isolate(title)} size="full" class="tr-pdf-dialog">
|
|
36
|
+
{#if open}
|
|
37
|
+
<PdfViewer bind:this={viewer} bind:page bind:mode bind:selected bind:pageCount {title} {...rest} height="100%" class="tr-pdf-dialog-viewer" />
|
|
38
|
+
{/if}
|
|
39
|
+
</Dialog>
|
|
40
|
+
|
|
41
|
+
<style>
|
|
42
|
+
:global(dialog.tr-dialog.tr-pdf-dialog[data-size='full']) {
|
|
43
|
+
--tr-max-h: calc(100dvh - 24px);
|
|
44
|
+
width: calc(100vw - 24px);
|
|
45
|
+
height: calc(100dvh - 24px);
|
|
46
|
+
max-height: calc(100dvh - 24px);
|
|
47
|
+
}
|
|
48
|
+
:global(dialog.tr-dialog.tr-pdf-dialog .body) {
|
|
49
|
+
padding: 0;
|
|
50
|
+
overflow: hidden;
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
flex: 1;
|
|
54
|
+
min-height: 0;
|
|
55
|
+
}
|
|
56
|
+
:global(.tr-pdf.tr-pdf-dialog-viewer) {
|
|
57
|
+
flex: 1;
|
|
58
|
+
border: 0;
|
|
59
|
+
border-radius: 0;
|
|
60
|
+
}
|
|
61
|
+
@media (max-width: 600px) {
|
|
62
|
+
:global(dialog.tr-dialog.tr-pdf-dialog[data-size='full']) {
|
|
63
|
+
--tr-max-h: 100dvh;
|
|
64
|
+
inset: 0;
|
|
65
|
+
width: 100vw;
|
|
66
|
+
height: 100dvh;
|
|
67
|
+
max-height: 100dvh;
|
|
68
|
+
border-radius: 0;
|
|
69
|
+
border: 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import PdfViewer from './PdfViewer.svelte';
|
|
3
|
+
import type { PdfGoToResult, PdfTarget } from './types.js';
|
|
4
|
+
type $$ComponentProps = Omit<ComponentProps<typeof PdfViewer>, 'height'> & {
|
|
5
|
+
/** Whether the dialog is open. Bindable. The document is loaded while it is open and released when it closes. */
|
|
6
|
+
open?: boolean;
|
|
7
|
+
/** The dialog title (the document's name; bidi-isolated). */
|
|
8
|
+
title: string;
|
|
9
|
+
};
|
|
10
|
+
/** A `PdfViewer` in a full-size core `Dialog` (EvalBot's original form). Every viewer prop is passed through; `goTo` is forwarded. */
|
|
11
|
+
declare const PdfDialog: import("svelte").Component<$$ComponentProps, {
|
|
12
|
+
goTo: (t: PdfTarget) => Promise<PdfGoToResult>;
|
|
13
|
+
}, "open" | "selected" | "mode" | "page" | "pageCount">;
|
|
14
|
+
type PdfDialog = ReturnType<typeof PdfDialog>;
|
|
15
|
+
export default PdfDialog;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A `PdfViewer` and a `ReviewPanel` side by side in a core `SplitPane` (the divider resizes the panel); at or below `breakpoint` the panel
|
|
4
|
+
stacks under the viewer. The review keys (`j`/`k`, `[`/`]` and the actions' shortcuts) work anywhere inside it, outside text fields, and
|
|
5
|
+
only there, so two reviews on a page do not fight. `goTo`, `next`, `previous` and `handleKey` are forwarded.
|
|
6
|
+
-->
|
|
7
|
+
<script module lang="ts">
|
|
8
|
+
export type PdfReviewLabels = {
|
|
9
|
+
/** Accessible name of the divider between the viewer and the panel. */
|
|
10
|
+
resize: string;
|
|
11
|
+
};
|
|
12
|
+
const DEFAULTS: PdfReviewLabels = { resize: 'Resize the review panel' };
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script lang="ts" generics="T extends ReviewItem">
|
|
16
|
+
import type { ComponentProps, Snippet } from 'svelte';
|
|
17
|
+
import { SplitPane } from '@ruckc/truss-ui';
|
|
18
|
+
import PdfViewer, { type PdfViewerLabels } from './PdfViewer.svelte';
|
|
19
|
+
import ReviewPanel, { type ReviewPanelLabels } from './ReviewPanel.svelte';
|
|
20
|
+
import { useLabels } from './labels.js';
|
|
21
|
+
import { cssvars } from './cssvars.js';
|
|
22
|
+
import type { PdfAnnotation, PdfGoToResult, PdfSource, PdfTarget, ReviewAction, ReviewActionDetail, ReviewFilter, ReviewItem, ReviewStatuses } from './types.js';
|
|
23
|
+
|
|
24
|
+
type Viewer = ComponentProps<typeof PdfViewer>;
|
|
25
|
+
|
|
26
|
+
let {
|
|
27
|
+
src,
|
|
28
|
+
title,
|
|
29
|
+
annotations = [],
|
|
30
|
+
page = $bindable(1),
|
|
31
|
+
mode = $bindable('page'),
|
|
32
|
+
selected = $bindable(null),
|
|
33
|
+
items,
|
|
34
|
+
filters,
|
|
35
|
+
filter = $bindable(),
|
|
36
|
+
current = $bindable(null),
|
|
37
|
+
checked = $bindable([]),
|
|
38
|
+
actions,
|
|
39
|
+
onaction,
|
|
40
|
+
onbulkaction,
|
|
41
|
+
onnavigate,
|
|
42
|
+
statuses,
|
|
43
|
+
bulk,
|
|
44
|
+
detail,
|
|
45
|
+
toolbar,
|
|
46
|
+
viewerProps,
|
|
47
|
+
keys = true,
|
|
48
|
+
height = '40rem',
|
|
49
|
+
panelWidth = '360px',
|
|
50
|
+
breakpoint,
|
|
51
|
+
labels,
|
|
52
|
+
viewerLabels,
|
|
53
|
+
class: klass,
|
|
54
|
+
...rest
|
|
55
|
+
}: {
|
|
56
|
+
/** The document (`PdfViewer.src`). */
|
|
57
|
+
src?: PdfSource | null;
|
|
58
|
+
/** The document's name (`PdfViewer.title`). */
|
|
59
|
+
title?: string;
|
|
60
|
+
/** The viewer's overlays; `ReviewItem.annotation` refers to their ids. */
|
|
61
|
+
annotations?: PdfAnnotation[];
|
|
62
|
+
/** The page on screen. Bindable. */
|
|
63
|
+
page?: number;
|
|
64
|
+
/** The viewer's zoom mode. Bindable. */
|
|
65
|
+
mode?: 'page' | 'fit-width';
|
|
66
|
+
/** The selected annotation, shared by the viewer and the panel. Bindable. */
|
|
67
|
+
selected?: string | null;
|
|
68
|
+
/** What to review (`ReviewPanel.items`). */
|
|
69
|
+
items: T[];
|
|
70
|
+
/** The filter segments (`ReviewPanel.filters`). */
|
|
71
|
+
filters?: ReviewFilter<T>[];
|
|
72
|
+
/** The id of the active filter. Bindable. */
|
|
73
|
+
filter?: string;
|
|
74
|
+
/** The id of the selected item. Bindable. */
|
|
75
|
+
current?: string | null;
|
|
76
|
+
/** The ids of the checked items (with `bulk`). Bindable. */
|
|
77
|
+
checked?: string[];
|
|
78
|
+
/** The actions offered on the selected item (`ReviewPanel.actions`). */
|
|
79
|
+
actions?: ReviewAction<T>[];
|
|
80
|
+
/** Runs an action (`ReviewPanel.onaction`). */
|
|
81
|
+
onaction?: (action: string, item: T, detail: ReviewActionDetail) => unknown;
|
|
82
|
+
/** Runs a bulk action (`ReviewPanel.onbulkaction`). */
|
|
83
|
+
onbulkaction?: (action: string, items: T[], detail: ReviewActionDetail) => unknown;
|
|
84
|
+
/** Called after each move with the item and the outcome of `goTo`. */
|
|
85
|
+
onnavigate?: (item: T, result: PdfGoToResult) => void;
|
|
86
|
+
/** Label and tone of each status. */
|
|
87
|
+
statuses?: ReviewStatuses;
|
|
88
|
+
/** Checkboxes and a bulk bar. */
|
|
89
|
+
bulk?: boolean;
|
|
90
|
+
/** Host content for the selected item. */
|
|
91
|
+
detail?: Snippet<[T]>;
|
|
92
|
+
/** Handle the review keys pressed anywhere inside the review (default true). */
|
|
93
|
+
keys?: boolean;
|
|
94
|
+
/** Extra controls at the end of the viewer's toolbar (the viewer's `actions` snippet). */
|
|
95
|
+
toolbar?: Snippet;
|
|
96
|
+
/** Any other `PdfViewer` prop (`oncreate`, `onlink`, `ontarget`...). */
|
|
97
|
+
viewerProps?: Omit<Viewer, 'src' | 'title' | 'annotations' | 'page' | 'mode' | 'selected' | 'actions' | 'labels' | 'height'>;
|
|
98
|
+
/** CSS height of the whole review (px when a number). */
|
|
99
|
+
height?: number | string;
|
|
100
|
+
/** Width of the panel while side by side (a CSS length; the divider changes it). */
|
|
101
|
+
panelWidth?: string;
|
|
102
|
+
/** Viewport width at or below which the panel stacks under the viewer (default: the app-wide narrow breakpoint). */
|
|
103
|
+
breakpoint?: number | string;
|
|
104
|
+
/** The panel's labels (`ReviewPanelLabels`) and the divider's (`resize`). */
|
|
105
|
+
labels?: Partial<ReviewPanelLabels & PdfReviewLabels>;
|
|
106
|
+
viewerLabels?: Partial<PdfViewerLabels>;
|
|
107
|
+
class?: string;
|
|
108
|
+
[attr: `data-${string}`]: unknown;
|
|
109
|
+
} = $props();
|
|
110
|
+
|
|
111
|
+
const L = useLabels('PdfReview', DEFAULTS, () => labels);
|
|
112
|
+
let viewer = $state<ReturnType<typeof PdfViewer>>();
|
|
113
|
+
let panel = $state<ReturnType<typeof ReviewPanel<T>>>();
|
|
114
|
+
|
|
115
|
+
/** `PdfViewer.goTo` of the review's viewer. */
|
|
116
|
+
export const goTo = (t: PdfTarget): Promise<PdfGoToResult> => viewer!.goTo(t);
|
|
117
|
+
/** Selects the next item. */
|
|
118
|
+
export const next = () => panel!.next();
|
|
119
|
+
/** Selects the previous item. */
|
|
120
|
+
export const previous = () => panel!.previous();
|
|
121
|
+
/** `ReviewPanel.handleKey`: pass it the keys of a wider area (a `svelte:window` listener) to make the review keys page-wide. */
|
|
122
|
+
export const handleKey = (e: KeyboardEvent) => panel!.handleKey(e);
|
|
123
|
+
const cssLen = (v: number | string) => (typeof v === 'number' ? `${v}px` : v);
|
|
124
|
+
</script>
|
|
125
|
+
|
|
126
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
127
|
+
<div {...rest} class={['tr-pdf-review', klass]} onkeydown={(e) => keys && handleKey(e)} {@attach cssvars(() => ({ '--review-h': cssLen(height) }))}>
|
|
128
|
+
<SplitPane sizeFrom="second" size={panelWidth} minFirst={240} minSecond={260} narrow="stack" narrowSize="60%" {breakpoint} label={L.resize}>
|
|
129
|
+
{#snippet first()}
|
|
130
|
+
<PdfViewer {...viewerProps} bind:this={viewer} {src} {title} {annotations} bind:page bind:mode bind:selected actions={toolbar} labels={viewerLabels} height="100%" class="tr-pdf-review-viewer" />
|
|
131
|
+
{/snippet}
|
|
132
|
+
{#snippet second()}
|
|
133
|
+
<ReviewPanel
|
|
134
|
+
bind:this={panel}
|
|
135
|
+
{viewer}
|
|
136
|
+
{items}
|
|
137
|
+
{filters}
|
|
138
|
+
bind:filter
|
|
139
|
+
bind:current
|
|
140
|
+
bind:selected
|
|
141
|
+
bind:checked
|
|
142
|
+
{actions}
|
|
143
|
+
{onaction}
|
|
144
|
+
{onbulkaction}
|
|
145
|
+
{onnavigate}
|
|
146
|
+
{statuses}
|
|
147
|
+
{bulk}
|
|
148
|
+
{detail}
|
|
149
|
+
{labels}
|
|
150
|
+
keys={false}
|
|
151
|
+
/>
|
|
152
|
+
{/snippet}
|
|
153
|
+
</SplitPane>
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<style>
|
|
157
|
+
.tr-pdf-review {
|
|
158
|
+
display: flex;
|
|
159
|
+
flex-direction: column;
|
|
160
|
+
height: var(--review-h, 40rem);
|
|
161
|
+
min-height: 20rem;
|
|
162
|
+
border: 1px solid var(--tr-outline-variant);
|
|
163
|
+
border-radius: var(--tr-radius-md, 8px);
|
|
164
|
+
overflow: hidden;
|
|
165
|
+
}
|
|
166
|
+
.tr-pdf-review > :global(*) {
|
|
167
|
+
flex: 1;
|
|
168
|
+
min-height: 0;
|
|
169
|
+
}
|
|
170
|
+
:global(.tr-pdf.tr-pdf-review-viewer) {
|
|
171
|
+
border: 0;
|
|
172
|
+
border-radius: 0;
|
|
173
|
+
}
|
|
174
|
+
</style>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export type PdfReviewLabels = {
|
|
2
|
+
/** Accessible name of the divider between the viewer and the panel. */
|
|
3
|
+
resize: string;
|
|
4
|
+
};
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
|
+
import { type PdfViewerLabels } from './PdfViewer.svelte';
|
|
7
|
+
import { type ReviewPanelLabels } from './ReviewPanel.svelte';
|
|
8
|
+
import type { PdfAnnotation, PdfGoToResult, PdfSource, PdfTarget, ReviewAction, ReviewActionDetail, ReviewFilter, ReviewItem, ReviewStatuses } from './types.js';
|
|
9
|
+
declare function $$render<T extends ReviewItem>(): {
|
|
10
|
+
props: {
|
|
11
|
+
[attr: `data-${string}`]: unknown;
|
|
12
|
+
/** The document (`PdfViewer.src`). */
|
|
13
|
+
src?: PdfSource | null;
|
|
14
|
+
/** The document's name (`PdfViewer.title`). */
|
|
15
|
+
title?: string;
|
|
16
|
+
/** The viewer's overlays; `ReviewItem.annotation` refers to their ids. */
|
|
17
|
+
annotations?: PdfAnnotation[];
|
|
18
|
+
/** The page on screen. Bindable. */
|
|
19
|
+
page?: number;
|
|
20
|
+
/** The viewer's zoom mode. Bindable. */
|
|
21
|
+
mode?: "page" | "fit-width";
|
|
22
|
+
/** The selected annotation, shared by the viewer and the panel. Bindable. */
|
|
23
|
+
selected?: string | null;
|
|
24
|
+
/** What to review (`ReviewPanel.items`). */
|
|
25
|
+
items: T[];
|
|
26
|
+
/** The filter segments (`ReviewPanel.filters`). */
|
|
27
|
+
filters?: ReviewFilter<T>[];
|
|
28
|
+
/** The id of the active filter. Bindable. */
|
|
29
|
+
filter?: string;
|
|
30
|
+
/** The id of the selected item. Bindable. */
|
|
31
|
+
current?: string | null;
|
|
32
|
+
/** The ids of the checked items (with `bulk`). Bindable. */
|
|
33
|
+
checked?: string[];
|
|
34
|
+
/** The actions offered on the selected item (`ReviewPanel.actions`). */
|
|
35
|
+
actions?: ReviewAction<T>[];
|
|
36
|
+
/** Runs an action (`ReviewPanel.onaction`). */
|
|
37
|
+
onaction?: (action: string, item: T, detail: ReviewActionDetail) => unknown;
|
|
38
|
+
/** Runs a bulk action (`ReviewPanel.onbulkaction`). */
|
|
39
|
+
onbulkaction?: (action: string, items: T[], detail: ReviewActionDetail) => unknown;
|
|
40
|
+
/** Called after each move with the item and the outcome of `goTo`. */
|
|
41
|
+
onnavigate?: (item: T, result: PdfGoToResult) => void;
|
|
42
|
+
/** Label and tone of each status. */
|
|
43
|
+
statuses?: ReviewStatuses;
|
|
44
|
+
/** Checkboxes and a bulk bar. */
|
|
45
|
+
bulk?: boolean;
|
|
46
|
+
/** Host content for the selected item. */
|
|
47
|
+
detail?: Snippet<[T]>;
|
|
48
|
+
/** Handle the review keys pressed anywhere inside the review (default true). */
|
|
49
|
+
keys?: boolean;
|
|
50
|
+
/** Extra controls at the end of the viewer's toolbar (the viewer's `actions` snippet). */
|
|
51
|
+
toolbar?: Snippet;
|
|
52
|
+
/** Any other `PdfViewer` prop (`oncreate`, `onlink`, `ontarget`...). */
|
|
53
|
+
viewerProps?: Omit<Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, "children" | "class" | "title"> & {
|
|
54
|
+
src?: PdfSource | null;
|
|
55
|
+
page?: number;
|
|
56
|
+
pageCount?: number;
|
|
57
|
+
mode?: "page" | "fit-width";
|
|
58
|
+
annotations?: PdfAnnotation[];
|
|
59
|
+
selected?: string | null;
|
|
60
|
+
onselect?: (id: string) => void;
|
|
61
|
+
oncreate?: (detail: import("./types.js").PdfCreateDetail) => void;
|
|
62
|
+
target?: PdfTarget | null;
|
|
63
|
+
targetKey?: unknown;
|
|
64
|
+
ontarget?: (result: PdfGoToResult, target: PdfTarget) => void;
|
|
65
|
+
onlink?: (url: string) => void;
|
|
66
|
+
title?: string;
|
|
67
|
+
height?: number | string;
|
|
68
|
+
toolbar?: boolean;
|
|
69
|
+
actions?: Snippet;
|
|
70
|
+
labels?: Partial<PdfViewerLabels>;
|
|
71
|
+
class?: string;
|
|
72
|
+
}, "src" | "title" | "annotations" | "page" | "mode" | "selected" | "actions" | "labels" | "height">;
|
|
73
|
+
/** CSS height of the whole review (px when a number). */
|
|
74
|
+
height?: number | string;
|
|
75
|
+
/** Width of the panel while side by side (a CSS length; the divider changes it). */
|
|
76
|
+
panelWidth?: string;
|
|
77
|
+
/** Viewport width at or below which the panel stacks under the viewer (default: the app-wide narrow breakpoint). */
|
|
78
|
+
breakpoint?: number | string;
|
|
79
|
+
/** The panel's labels (`ReviewPanelLabels`) and the divider's (`resize`). */
|
|
80
|
+
labels?: Partial<ReviewPanelLabels & PdfReviewLabels>;
|
|
81
|
+
viewerLabels?: Partial<PdfViewerLabels>;
|
|
82
|
+
class?: string;
|
|
83
|
+
};
|
|
84
|
+
exports: {
|
|
85
|
+
/** `PdfViewer.goTo` of the review's viewer. */ goTo: (t: PdfTarget) => Promise<PdfGoToResult>;
|
|
86
|
+
/** Selects the next item. */ next: () => void;
|
|
87
|
+
/** Selects the previous item. */ previous: () => void;
|
|
88
|
+
/** `ReviewPanel.handleKey`: pass it the keys of a wider area (a `svelte:window` listener) to make the review keys page-wide. */ handleKey: (e: KeyboardEvent) => boolean;
|
|
89
|
+
};
|
|
90
|
+
bindings: "filter" | "checked" | "selected" | "mode" | "current" | "page";
|
|
91
|
+
slots: {};
|
|
92
|
+
events: {};
|
|
93
|
+
};
|
|
94
|
+
declare class __sveltets_Render<T extends ReviewItem> {
|
|
95
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
96
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
97
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
98
|
+
bindings(): "filter" | "checked" | "selected" | "mode" | "current" | "page";
|
|
99
|
+
exports(): {
|
|
100
|
+
/** `PdfViewer.goTo` of the review's viewer. */ goTo: (t: PdfTarget) => Promise<PdfGoToResult>;
|
|
101
|
+
/** Selects the next item. */ next: () => void;
|
|
102
|
+
/** Selects the previous item. */ previous: () => void;
|
|
103
|
+
/** `ReviewPanel.handleKey`: pass it the keys of a wider area (a `svelte:window` listener) to make the review keys page-wide. */ handleKey: (e: KeyboardEvent) => boolean;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
interface $$IsomorphicComponent {
|
|
107
|
+
new <T extends ReviewItem>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
108
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
109
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
110
|
+
<T extends ReviewItem>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
111
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A `PdfViewer` and a `ReviewPanel` side by side in a core `SplitPane` (the divider resizes the panel); at or below `breakpoint` the panel
|
|
115
|
+
* stacks under the viewer. The review keys (`j`/`k`, `[`/`]` and the actions' shortcuts) work anywhere inside it, outside text fields, and
|
|
116
|
+
* only there, so two reviews on a page do not fight. `goTo`, `next`, `previous` and `handleKey` are forwarded.
|
|
117
|
+
*/
|
|
118
|
+
declare const PdfReview: $$IsomorphicComponent;
|
|
119
|
+
type PdfReview<T extends ReviewItem> = InstanceType<typeof PdfReview<T>>;
|
|
120
|
+
export default PdfReview;
|