@astra-spec/ui 0.0.3 → 0.0.5
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 +173 -20
- package/TOKENS.md +17 -8
- package/components.css +1 -0
- package/dist/blocks/decisions-list.d.ts +0 -1
- package/dist/blocks/decisions-list.d.ts.map +1 -1
- package/dist/blocks/decisions-list.js +1 -5
- package/dist/blocks/decisions-list.js.map +1 -1
- package/dist/blocks/findings-list.d.ts.map +1 -1
- package/dist/blocks/findings-list.js +2 -1
- package/dist/blocks/findings-list.js.map +1 -1
- package/dist/blocks/index.d.ts +3 -3
- package/dist/blocks/index.d.ts.map +1 -1
- package/dist/blocks/index.js +2 -2
- package/dist/blocks/index.js.map +1 -1
- package/dist/blocks/inputs-list.js +1 -1
- package/dist/blocks/inputs-list.js.map +1 -1
- package/dist/blocks/outputs-list.d.ts +2 -2
- package/dist/blocks/outputs-list.d.ts.map +1 -1
- package/dist/blocks/outputs-list.js +15 -19
- package/dist/blocks/outputs-list.js.map +1 -1
- package/dist/blocks/section.d.ts +1 -4
- package/dist/blocks/section.d.ts.map +1 -1
- package/dist/blocks/section.js +3 -13
- package/dist/blocks/section.js.map +1 -1
- package/dist/components/artifact-preview.d.ts +2 -54
- package/dist/components/artifact-preview.d.ts.map +1 -1
- package/dist/components/artifact-preview.js +2 -107
- package/dist/components/artifact-preview.js.map +1 -1
- package/dist/components/decision-detail.d.ts +1 -1
- package/dist/components/decision-detail.d.ts.map +1 -1
- package/dist/components/decision-detail.js.map +1 -1
- package/dist/components/finding-detail.d.ts +2 -2
- package/dist/components/finding-detail.d.ts.map +1 -1
- package/dist/components/finding-detail.js.map +1 -1
- package/dist/components/index.d.ts +9 -13
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +6 -8
- package/dist/components/index.js.map +1 -1
- package/dist/components/input-detail.d.ts +1 -2
- package/dist/components/input-detail.d.ts.map +1 -1
- package/dist/components/input-detail.js +0 -3
- package/dist/components/input-detail.js.map +1 -1
- package/dist/components/insight-detail.d.ts +2 -8
- package/dist/components/insight-detail.d.ts.map +1 -1
- package/dist/components/insight-detail.js +5 -11
- package/dist/components/insight-detail.js.map +1 -1
- package/dist/components/insight-trigger.d.ts +1 -1
- package/dist/components/insight-trigger.d.ts.map +1 -1
- package/dist/components/insight-trigger.js +3 -2
- package/dist/components/insight-trigger.js.map +1 -1
- package/dist/components/output-detail.d.ts +2 -7
- package/dist/components/output-detail.d.ts.map +1 -1
- package/dist/components/output-detail.js +3 -30
- package/dist/components/output-detail.js.map +1 -1
- package/dist/components/output-dialog.d.ts +2 -2
- package/dist/components/output-dialog.d.ts.map +1 -1
- package/dist/components/output-dialog.js +2 -1
- package/dist/components/output-dialog.js.map +1 -1
- package/dist/components/paper-detail.d.ts +14 -14
- package/dist/components/paper-detail.d.ts.map +1 -1
- package/dist/components/paper-detail.js +49 -29
- package/dist/components/paper-detail.js.map +1 -1
- package/dist/components/paper-pdf-viewer.d.ts +19 -0
- package/dist/components/paper-pdf-viewer.d.ts.map +1 -0
- package/dist/components/paper-pdf-viewer.js +250 -0
- package/dist/components/paper-pdf-viewer.js.map +1 -0
- package/dist/components/record-dialog.d.ts +7 -5
- package/dist/components/record-dialog.d.ts.map +1 -1
- package/dist/components/record-dialog.js +7 -5
- package/dist/components/record-dialog.js.map +1 -1
- package/dist/components/record-preview.d.ts +2 -2
- package/dist/components/record-preview.d.ts.map +1 -1
- package/dist/components/record-preview.js +9 -8
- package/dist/components/record-preview.js.map +1 -1
- package/dist/components/relation-items.d.ts +1 -1
- package/dist/components/relation-items.d.ts.map +1 -1
- package/dist/components/relation-items.js +10 -3
- package/dist/components/relation-items.js.map +1 -1
- package/dist/{components/use-detail-stack.d.ts → lib/detail-stack.d.ts} +17 -2
- package/dist/lib/detail-stack.d.ts.map +1 -0
- package/dist/{components/use-detail-stack.js → lib/detail-stack.js} +15 -2
- package/dist/lib/detail-stack.js.map +1 -0
- package/dist/lib/index.d.ts +14 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +9 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/labels.d.ts +20 -0
- package/dist/lib/labels.d.ts.map +1 -1
- package/dist/lib/labels.js +20 -0
- package/dist/lib/labels.js.map +1 -1
- package/dist/lib/pdf-quote.d.ts +47 -0
- package/dist/lib/pdf-quote.d.ts.map +1 -0
- package/dist/lib/pdf-quote.js +154 -0
- package/dist/lib/pdf-quote.js.map +1 -0
- package/dist/lib/pdf-runtime.d.ts +102 -0
- package/dist/lib/pdf-runtime.d.ts.map +1 -0
- package/dist/lib/pdf-runtime.js +48 -0
- package/dist/lib/pdf-runtime.js.map +1 -0
- package/dist/lib/preview-data.d.ts +55 -0
- package/dist/lib/preview-data.d.ts.map +1 -0
- package/dist/lib/preview-data.js +108 -0
- package/dist/lib/preview-data.js.map +1 -0
- package/dist/lib/prose.d.ts +37 -0
- package/dist/lib/prose.d.ts.map +1 -0
- package/dist/lib/prose.js +60 -0
- package/dist/lib/prose.js.map +1 -0
- package/dist/lib/use-isomorphic-layout-effect.d.ts +4 -0
- package/dist/lib/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/dist/lib/use-isomorphic-layout-effect.js +4 -0
- package/dist/lib/use-isomorphic-layout-effect.js.map +1 -0
- package/dist/lib/use-output-expanded.d.ts +7 -0
- package/dist/lib/use-output-expanded.d.ts.map +1 -0
- package/dist/lib/use-output-expanded.js +29 -0
- package/dist/lib/use-output-expanded.js.map +1 -0
- package/dist/model/index.d.ts +5 -3
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +3 -2
- package/dist/model/index.js.map +1 -1
- package/dist/model/kind.d.ts +9 -0
- package/dist/model/kind.d.ts.map +1 -0
- package/dist/model/kind.js +25 -0
- package/dist/model/kind.js.map +1 -0
- package/dist/model/papers.d.ts +6 -6
- package/dist/model/papers.d.ts.map +1 -1
- package/dist/model/papers.js +8 -0
- package/dist/model/papers.js.map +1 -1
- package/dist/model/records.d.ts +5 -1
- package/dist/model/records.d.ts.map +1 -1
- package/dist/model/records.js +9 -0
- package/dist/model/records.js.map +1 -1
- package/dist/primitives/badge.d.ts +1 -1
- package/dist/primitives/badge.d.ts.map +1 -1
- package/dist/primitives/button.js +1 -1
- package/dist/primitives/button.js.map +1 -1
- package/dist/primitives/dialog.d.ts +1 -1
- package/dist/primitives/dialog.d.ts.map +1 -1
- package/dist/primitives/dialog.js +3 -3
- package/dist/primitives/dialog.js.map +1 -1
- package/dist/primitives/index.d.ts +8 -9
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +4 -5
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/inline-reference.d.ts +9 -0
- package/dist/primitives/inline-reference.d.ts.map +1 -0
- package/dist/primitives/inline-reference.js +14 -0
- package/dist/primitives/inline-reference.js.map +1 -0
- package/dist/primitives/kind-glyph.d.ts +8 -0
- package/dist/primitives/kind-glyph.d.ts.map +1 -0
- package/dist/primitives/kind-glyph.js +9 -0
- package/dist/primitives/kind-glyph.js.map +1 -0
- package/dist/primitives/preview-popover.d.ts +2 -2
- package/dist/primitives/preview-popover.d.ts.map +1 -1
- package/dist/primitives/preview-popover.js +1 -1
- package/dist/primitives/preview-popover.js.map +1 -1
- package/dist/primitives/prose.d.ts +1 -35
- package/dist/primitives/prose.d.ts.map +1 -1
- package/dist/primitives/prose.js +2 -58
- package/dist/primitives/prose.js.map +1 -1
- package/dist/primitives/record-list.d.ts +1 -1
- package/dist/primitives/record-list.d.ts.map +1 -1
- package/dist/primitives/record-list.js +3 -2
- package/dist/primitives/record-list.js.map +1 -1
- package/dist/primitives/relation-list.d.ts +1 -1
- package/dist/primitives/relation-list.d.ts.map +1 -1
- package/dist/primitives/relation-list.js +3 -2
- package/dist/primitives/relation-list.js.map +1 -1
- package/dist/primitives/slot.d.ts.map +1 -0
- package/dist/{lib → primitives}/slot.js +1 -1
- package/dist/primitives/slot.js.map +1 -0
- package/dist/primitives/surface-header.d.ts +1 -1
- package/dist/primitives/surface-header.d.ts.map +1 -1
- package/dist/views/inventory.d.ts +7 -5
- package/dist/views/inventory.d.ts.map +1 -1
- package/dist/views/inventory.js +5 -4
- package/dist/views/inventory.js.map +1 -1
- package/isolate.css +7 -0
- package/package.json +15 -3
- package/primitives.css +2 -0
- package/src/blocks/decisions-list.tsx +1 -6
- package/src/blocks/findings-list.tsx +2 -1
- package/src/blocks/index.ts +2 -3
- package/src/blocks/inputs-list.tsx +1 -1
- package/src/blocks/outputs-list.tsx +53 -30
- package/src/blocks/section.tsx +3 -15
- package/src/components/artifact-preview.tsx +6 -161
- package/src/components/decision-detail.tsx +2 -1
- package/src/components/finding-detail.tsx +3 -2
- package/src/components/index.ts +10 -30
- package/src/components/input-detail.tsx +2 -5
- package/src/components/insight-detail.tsx +20 -35
- package/src/components/insight-trigger.tsx +5 -3
- package/src/components/output-detail.tsx +17 -38
- package/src/components/output-dialog.tsx +4 -3
- package/src/components/paper-detail.tsx +121 -66
- package/src/components/paper-pdf-viewer.tsx +319 -0
- package/src/components/record-dialog.tsx +15 -10
- package/src/components/record-preview.tsx +12 -17
- package/src/components/relation-items.ts +15 -5
- package/src/{components/use-detail-stack.ts → lib/detail-stack.ts} +24 -1
- package/src/lib/index.ts +22 -0
- package/src/lib/labels.tsx +40 -0
- package/src/lib/pdf-quote.ts +189 -0
- package/src/lib/pdf-runtime.ts +131 -0
- package/src/lib/preview-data.ts +155 -0
- package/src/lib/prose.tsx +87 -0
- package/src/lib/use-isomorphic-layout-effect.ts +4 -0
- package/src/lib/use-output-expanded.ts +27 -0
- package/src/model/index.ts +4 -2
- package/src/model/kind.ts +33 -0
- package/src/model/papers.ts +9 -7
- package/src/model/records.ts +12 -0
- package/src/primitives/badge.tsx +1 -1
- package/src/primitives/button.tsx +1 -1
- package/src/primitives/dialog.tsx +3 -5
- package/src/primitives/index.ts +8 -17
- package/src/primitives/inline-reference.tsx +25 -0
- package/src/primitives/kind-glyph.tsx +24 -0
- package/src/primitives/preview-popover.tsx +3 -3
- package/src/primitives/prose.tsx +1 -86
- package/src/primitives/record-list.tsx +3 -4
- package/src/primitives/relation-list.tsx +4 -7
- package/src/{lib → primitives}/slot.tsx +1 -1
- package/src/primitives/surface-header.tsx +1 -1
- package/src/views/inventory.tsx +12 -8
- package/styles/blocks/analysis-tree.css +6 -6
- package/styles/blocks/decisions-list.css +10 -10
- package/styles/blocks/outputs-list.css +272 -45
- package/styles/blocks/papers-list.css +14 -14
- package/styles/blocks/records.css +13 -13
- package/styles/components/artifact-preview.css +21 -21
- package/styles/components/decision-detail.css +23 -23
- package/styles/components/evidence.css +4 -9
- package/styles/components/finding-detail.css +11 -11
- package/styles/components/input-detail.css +11 -11
- package/styles/components/insight-detail.css +57 -95
- package/styles/components/insight-list.css +9 -9
- package/styles/components/insight-trigger.css +5 -8
- package/styles/components/output-detail.css +74 -189
- package/styles/components/paper-detail.css +90 -109
- package/styles/components/paper-doi.css +5 -14
- package/styles/components/paper-pdf-viewer.css +120 -0
- package/styles/components/record-preview.css +444 -268
- package/styles/primitives/badge.css +2 -2
- package/styles/primitives/button.css +25 -25
- package/styles/primitives/count-heading.css +5 -5
- package/styles/primitives/detail-layout.css +25 -25
- package/styles/primitives/dialog.css +86 -86
- package/styles/primitives/empty-state.css +1 -1
- package/styles/primitives/inline-reference.css +37 -0
- package/styles/primitives/kind-glyph.css +31 -0
- package/styles/primitives/kind.css +6 -0
- package/styles/primitives/preview-popover.css +6 -11
- package/styles/primitives/prose.css +1 -1
- package/styles/primitives/record-list.css +46 -62
- package/styles/primitives/relation-list.css +20 -42
- package/styles/primitives/surface-header.css +20 -16
- package/styles/tokens.css +26 -8
- package/styles/views/inventory.css +27 -29
- package/dist/components/detail-entry.d.ts +0 -15
- package/dist/components/detail-entry.d.ts.map +0 -1
- package/dist/components/detail-entry.js +0 -14
- package/dist/components/detail-entry.js.map +0 -1
- package/dist/components/use-detail-stack.d.ts.map +0 -1
- package/dist/components/use-detail-stack.js.map +0 -1
- package/dist/lib/slot.d.ts.map +0 -1
- package/dist/lib/slot.js.map +0 -1
- package/dist/primitives/kind.d.ts +0 -6
- package/dist/primitives/kind.d.ts.map +0 -1
- package/dist/primitives/kind.js +0 -14
- package/dist/primitives/kind.js.map +0 -1
- package/src/components/detail-entry.ts +0 -19
- package/src/primitives/kind.ts +0 -19
- /package/dist/{lib → primitives}/slot.d.ts +0 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { forwardRef, useCallback, useEffect, useRef, useState, type HTMLAttributes } from 'react';
|
|
2
|
+
import { cn } from '../lib/cn.js';
|
|
3
|
+
import { useLabels } from '../lib/labels.js';
|
|
4
|
+
import { useIsomorphicLayoutEffect } from '../lib/use-isomorphic-layout-effect.js';
|
|
5
|
+
import {
|
|
6
|
+
highlightMatch,
|
|
7
|
+
locateQuote,
|
|
8
|
+
pageText,
|
|
9
|
+
type PdfPassage,
|
|
10
|
+
type PdfPassageLocation,
|
|
11
|
+
type PdfTextCache,
|
|
12
|
+
} from '../lib/pdf-quote.js';
|
|
13
|
+
import type { PdfDocument, PdfJs, PdfJsLoader, PdfLoadingTask, PdfRenderTask, PdfTextLayer } from '../lib/pdf-runtime.js';
|
|
14
|
+
|
|
15
|
+
export type { PdfPassage } from '../lib/pdf-quote.js';
|
|
16
|
+
|
|
17
|
+
export type PdfLoadState = 'loading' | 'ready' | 'error';
|
|
18
|
+
|
|
19
|
+
export interface PaperPdfViewerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
20
|
+
pdfUrl: string;
|
|
21
|
+
/** Names the viewer for assistive technology. */
|
|
22
|
+
title: string;
|
|
23
|
+
/** Called once per document; a later identity is ignored, so an inline function is fine. */
|
|
24
|
+
loadPdfJs: PdfJsLoader;
|
|
25
|
+
/** Scrolls to and highlights a passage once the document is readable; a new `key` repeats the request. */
|
|
26
|
+
passage?: PdfPassage | undefined;
|
|
27
|
+
/** Reports loading, readiness, or failure with its reason. The latest callback is used; identity is not tracked. */
|
|
28
|
+
onLoadStateChange?: ((state: PdfLoadState, error?: unknown) => void) | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface Loaded {
|
|
32
|
+
pdf: PdfDocument;
|
|
33
|
+
runtime: PdfJs;
|
|
34
|
+
text: PdfTextCache;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface Focus extends PdfPassageLocation {
|
|
38
|
+
key: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** iOS Safari's canvas area limit (4096 x 4096); CSS scales a smaller backing store up to the page shell. */
|
|
42
|
+
const MAX_CANVAS_PIXELS = 16_777_216;
|
|
43
|
+
const ZOOM_MIN = 0.5;
|
|
44
|
+
const ZOOM_MAX = 2;
|
|
45
|
+
const ZOOM_STEP = 0.25;
|
|
46
|
+
|
|
47
|
+
function Page({ loaded, number, width, zoom, focus }: {
|
|
48
|
+
loaded: Loaded;
|
|
49
|
+
number: number;
|
|
50
|
+
width: number;
|
|
51
|
+
zoom: number;
|
|
52
|
+
focus: Focus | undefined;
|
|
53
|
+
}) {
|
|
54
|
+
const { pdf: labels } = useLabels();
|
|
55
|
+
const shellRef = useRef<HTMLDivElement>(null);
|
|
56
|
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
57
|
+
const textRef = useRef<HTMLDivElement>(null);
|
|
58
|
+
const [nearby, setNearby] = useState(number === 1);
|
|
59
|
+
const [aspectRatio, setAspectRatio] = useState(612 / 792);
|
|
60
|
+
const [failed, setFailed] = useState(false);
|
|
61
|
+
// The rendered text layer lives in a ref so the render effect's cleanup can
|
|
62
|
+
// drop it synchronously; the version re-runs the highlight effect once a
|
|
63
|
+
// render attempt has settled, so a locate request never lands on detached
|
|
64
|
+
// spans and still brings a page without a text layer into view.
|
|
65
|
+
const layerRef = useRef<PdfTextLayer | undefined>(undefined);
|
|
66
|
+
const settledRef = useRef(false);
|
|
67
|
+
const [renderVersion, setRenderVersion] = useState(0);
|
|
68
|
+
const scrolledRequest = useRef<string | undefined>(undefined);
|
|
69
|
+
const active = nearby || focus !== undefined;
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const shell = shellRef.current;
|
|
73
|
+
if (!shell) return;
|
|
74
|
+
const observer = new IntersectionObserver(
|
|
75
|
+
(entries) => { setNearby(entries.some((entry) => entry.isIntersecting)); },
|
|
76
|
+
{ root: shell.parentElement, rootMargin: '600px' },
|
|
77
|
+
);
|
|
78
|
+
observer.observe(shell);
|
|
79
|
+
return () => { observer.disconnect(); };
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
// Shells keep their geometry whether or not they are rasterized, so mixed page sizes scroll correctly.
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
let disposed = false;
|
|
85
|
+
void loaded.pdf.getPage(number).then((page) => {
|
|
86
|
+
if (disposed) return;
|
|
87
|
+
const viewport = page.getViewport({ scale: 1 });
|
|
88
|
+
setAspectRatio(viewport.width / viewport.height);
|
|
89
|
+
}).catch(() => { /* Rendering reports errors for pages the reader visits. */ });
|
|
90
|
+
return () => { disposed = true; };
|
|
91
|
+
}, [loaded, number]);
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!active || width === 0) return;
|
|
95
|
+
const canvas = canvasRef.current;
|
|
96
|
+
const text = textRef.current;
|
|
97
|
+
if (!canvas || !text) return;
|
|
98
|
+
let disposed = false;
|
|
99
|
+
let task: PdfRenderTask | undefined;
|
|
100
|
+
let layer: PdfTextLayer | undefined;
|
|
101
|
+
setFailed(false);
|
|
102
|
+
void (async () => {
|
|
103
|
+
let rasterized = false;
|
|
104
|
+
try {
|
|
105
|
+
const page = await loaded.pdf.getPage(number);
|
|
106
|
+
if (disposed) return;
|
|
107
|
+
const base = page.getViewport({ scale: 1 });
|
|
108
|
+
const viewport = page.getViewport({ scale: width * zoom / base.width });
|
|
109
|
+
const context = canvas.getContext('2d');
|
|
110
|
+
if (!context) throw new Error('Canvas rendering is unavailable.');
|
|
111
|
+
const ratio = Math.min(
|
|
112
|
+
window.devicePixelRatio || 1,
|
|
113
|
+
2,
|
|
114
|
+
Math.sqrt(MAX_CANVAS_PIXELS / (viewport.width * viewport.height)),
|
|
115
|
+
);
|
|
116
|
+
// Rounded down, so the backing store never exceeds the cap the ratio was derived from.
|
|
117
|
+
canvas.width = Math.floor(viewport.width * ratio);
|
|
118
|
+
canvas.height = Math.floor(viewport.height * ratio);
|
|
119
|
+
text.replaceChildren();
|
|
120
|
+
// pdf.js 4.8 sizes the text layer from --scale-factor; later text layers read --total-scale-factor.
|
|
121
|
+
text.style.setProperty('--scale-factor', String(viewport.scale));
|
|
122
|
+
text.style.setProperty('--total-scale-factor', String(viewport.scale));
|
|
123
|
+
task = page.render({ canvasContext: context, viewport, transform: [ratio, 0, 0, ratio, 0, 0] });
|
|
124
|
+
await task.promise;
|
|
125
|
+
task = undefined;
|
|
126
|
+
rasterized = true;
|
|
127
|
+
if (disposed) return;
|
|
128
|
+
const content = await pageText(loaded.pdf, number, loaded.text);
|
|
129
|
+
if (disposed) return;
|
|
130
|
+
layer = new loaded.runtime.TextLayer({ textContentSource: content, container: text, viewport });
|
|
131
|
+
await layer.render();
|
|
132
|
+
const rendered = layer;
|
|
133
|
+
layer = undefined;
|
|
134
|
+
if (disposed) return;
|
|
135
|
+
layerRef.current = rendered;
|
|
136
|
+
} catch {
|
|
137
|
+
// A page without extractable text still shows its canvas.
|
|
138
|
+
if (!disposed && !rasterized) setFailed(true);
|
|
139
|
+
}
|
|
140
|
+
if (disposed) return;
|
|
141
|
+
settledRef.current = true;
|
|
142
|
+
setRenderVersion((version) => version + 1);
|
|
143
|
+
})();
|
|
144
|
+
return () => {
|
|
145
|
+
disposed = true;
|
|
146
|
+
layerRef.current = undefined;
|
|
147
|
+
settledRef.current = false;
|
|
148
|
+
// Only work still in flight is cancelled; settled tasks were released above.
|
|
149
|
+
task?.cancel();
|
|
150
|
+
layer?.cancel();
|
|
151
|
+
canvas.width = 0;
|
|
152
|
+
canvas.height = 0;
|
|
153
|
+
text.replaceChildren();
|
|
154
|
+
};
|
|
155
|
+
}, [active, loaded, number, width, zoom]);
|
|
156
|
+
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
// Clear the previous request even when the next one lands on the same page.
|
|
159
|
+
if (!focus) scrolledRequest.current = undefined;
|
|
160
|
+
if (!active || !settledRef.current) return;
|
|
161
|
+
const layer = layerRef.current;
|
|
162
|
+
// pdf.js keeps a span for every item, attached only when the item has text.
|
|
163
|
+
layer?.textDivs.forEach((div, index) => { div.textContent = layer.textContentItemsStr[index] ?? ''; });
|
|
164
|
+
if (!focus) return;
|
|
165
|
+
const mark = layer && focus.match ? highlightMatch(layer.textContentItemsStr, layer.textDivs, focus.match) : undefined;
|
|
166
|
+
// Zoom and resize rebuild the marks without taking the reader back to a
|
|
167
|
+
// passage they have already located and scrolled away from.
|
|
168
|
+
if (scrolledRequest.current !== focus.key) {
|
|
169
|
+
(mark ?? shellRef.current)?.scrollIntoView({ block: 'center' });
|
|
170
|
+
scrolledRequest.current = focus.key;
|
|
171
|
+
}
|
|
172
|
+
}, [active, renderVersion, focus]);
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<div ref={shellRef} className="astra-paper-pdf__page" data-page={number} role="group"
|
|
176
|
+
aria-label={labels.page(number)} style={{ width: width * zoom, aspectRatio }}>
|
|
177
|
+
<canvas ref={canvasRef} aria-hidden="true" />
|
|
178
|
+
<div ref={textRef} className="astra-paper-pdf__text" />
|
|
179
|
+
{failed ? <p role="alert">{labels.pageError(number)}</p> : null}
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Continuous PDF reading and passage navigation; the host supplies pdf.js through `loadPdfJs`. */
|
|
185
|
+
export const PaperPdfViewer = forwardRef<HTMLDivElement, PaperPdfViewerProps>(function PaperPdfViewer(props, ref) {
|
|
186
|
+
// A new URL is a new document: geometry, text cache and requests start over.
|
|
187
|
+
return <DocumentViewer key={props.pdfUrl} {...props} ref={ref} />;
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const DocumentViewer = forwardRef<HTMLDivElement, PaperPdfViewerProps>(function DocumentViewer({
|
|
191
|
+
pdfUrl, title, loadPdfJs, passage, onLoadStateChange, className, ...props
|
|
192
|
+
}, ref) {
|
|
193
|
+
const { pdf: labels } = useLabels();
|
|
194
|
+
// One load per mounted document, with the loader present at mount.
|
|
195
|
+
const [loader] = useState(() => loadPdfJs);
|
|
196
|
+
const [result, setResult] = useState<{ status: 'ready'; loaded: Loaded } | { status: 'error'; error: unknown }>();
|
|
197
|
+
const loaded = result?.status === 'ready' ? result.loaded : undefined;
|
|
198
|
+
const [located, setLocated] = useState<{ request: PdfPassage; focus: Focus | undefined }>();
|
|
199
|
+
const [zoom, setZoom] = useState(1);
|
|
200
|
+
const [width, setWidth] = useState(0);
|
|
201
|
+
const scrollRef = useRef<HTMLDivElement>(null);
|
|
202
|
+
const anchorRef = useRef<{ shell: HTMLElement; fraction: number } | undefined>(undefined);
|
|
203
|
+
const report = useRef(onLoadStateChange);
|
|
204
|
+
useEffect(() => { report.current = onLoadStateChange; });
|
|
205
|
+
|
|
206
|
+
const rememberPosition = useCallback(() => {
|
|
207
|
+
const scroll = scrollRef.current;
|
|
208
|
+
if (!scroll) return;
|
|
209
|
+
const top = scroll.getBoundingClientRect().top;
|
|
210
|
+
for (const shell of scroll.querySelectorAll<HTMLElement>('[data-page]')) {
|
|
211
|
+
const bounds = shell.getBoundingClientRect();
|
|
212
|
+
if (bounds.bottom > top && bounds.height > 0) {
|
|
213
|
+
anchorRef.current = { shell, fraction: (top - bounds.top) / bounds.height };
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}, []);
|
|
218
|
+
|
|
219
|
+
// Before paint, so a zoom step never flashes the page at the wrong offset.
|
|
220
|
+
useIsomorphicLayoutEffect(() => {
|
|
221
|
+
const scroll = scrollRef.current;
|
|
222
|
+
const anchor = anchorRef.current;
|
|
223
|
+
if (scroll && anchor) {
|
|
224
|
+
const bounds = anchor.shell.getBoundingClientRect();
|
|
225
|
+
scroll.scrollTop += bounds.top - scroll.getBoundingClientRect().top + bounds.height * anchor.fraction;
|
|
226
|
+
anchorRef.current = undefined;
|
|
227
|
+
}
|
|
228
|
+
}, [zoom, width]);
|
|
229
|
+
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
const node = scrollRef.current;
|
|
232
|
+
if (!node) return;
|
|
233
|
+
const resize = () => { rememberPosition(); setWidth(Math.max(100, node.clientWidth - 32)); };
|
|
234
|
+
resize();
|
|
235
|
+
const observer = new ResizeObserver(resize);
|
|
236
|
+
observer.observe(node);
|
|
237
|
+
return () => { observer.disconnect(); };
|
|
238
|
+
}, [rememberPosition]);
|
|
239
|
+
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
let disposed = false;
|
|
242
|
+
let task: PdfLoadingTask | undefined;
|
|
243
|
+
const release = () => {
|
|
244
|
+
const current = task;
|
|
245
|
+
task = undefined;
|
|
246
|
+
void current?.destroy().catch(() => { /* The document is already unavailable. */ });
|
|
247
|
+
};
|
|
248
|
+
void (async () => {
|
|
249
|
+
try {
|
|
250
|
+
const runtime = await loader();
|
|
251
|
+
if (disposed) return;
|
|
252
|
+
task = runtime.getDocument({ url: pdfUrl });
|
|
253
|
+
const pdf = await task.promise;
|
|
254
|
+
if (!disposed) setResult({ status: 'ready', loaded: { pdf, runtime, text: new Map() } });
|
|
255
|
+
} catch (error) {
|
|
256
|
+
release();
|
|
257
|
+
if (!disposed) setResult({ status: 'error', error });
|
|
258
|
+
}
|
|
259
|
+
})();
|
|
260
|
+
return () => {
|
|
261
|
+
disposed = true;
|
|
262
|
+
release();
|
|
263
|
+
};
|
|
264
|
+
}, [loader, pdfUrl]);
|
|
265
|
+
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
report.current?.(result?.status ?? 'loading', result?.status === 'error' ? result.error : undefined);
|
|
268
|
+
}, [result]);
|
|
269
|
+
|
|
270
|
+
const key = passage?.key;
|
|
271
|
+
const quote = passage?.quote;
|
|
272
|
+
const page = passage?.page;
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
if (!loaded || key === undefined) return;
|
|
275
|
+
const abort = new AbortController();
|
|
276
|
+
void locateQuote(loaded.pdf, { quote, page }, loaded.text, abort.signal).then((location) => {
|
|
277
|
+
if (!abort.signal.aborted) setLocated({ request: { key, quote, page }, focus: location && { ...location, key } });
|
|
278
|
+
});
|
|
279
|
+
return () => { abort.abort(); };
|
|
280
|
+
}, [loaded, key, quote, page]);
|
|
281
|
+
// A result answers one request; an edited quote or page under the same key is a new search.
|
|
282
|
+
const current = located && located.request.key === key && located.request.quote === quote && located.request.page === page
|
|
283
|
+
? located
|
|
284
|
+
: undefined;
|
|
285
|
+
const focus = current?.focus;
|
|
286
|
+
|
|
287
|
+
const status = result?.status === 'error' ? labels.loadError
|
|
288
|
+
: !loaded ? labels.loading
|
|
289
|
+
: key === undefined ? labels.pageCount(loaded.pdf.numPages)
|
|
290
|
+
: !current ? labels.searching
|
|
291
|
+
: !focus ? labels.quoteNotFound
|
|
292
|
+
: focus.match
|
|
293
|
+
? (focus.match.complete ? labels.quoteHighlighted : labels.partialQuoteHighlighted)(focus.page, loaded.pdf.numPages)
|
|
294
|
+
: labels.citedPageFallback(focus.page, loaded.pdf.numPages);
|
|
295
|
+
|
|
296
|
+
const zoomBy = (step: number) => { rememberPosition(); setZoom((value) => value + step); };
|
|
297
|
+
|
|
298
|
+
return (
|
|
299
|
+
<div data-slot="paper-pdf-viewer" role="group" aria-label={labels.viewer(title)} {...props} ref={ref}
|
|
300
|
+
className={cn('astra-paper-pdf', className)}>
|
|
301
|
+
<div className="astra-paper-pdf__toolbar">
|
|
302
|
+
<span role="status">{status}</span>
|
|
303
|
+
<button type="button" disabled={!loaded || zoom <= ZOOM_MIN} aria-label={labels.zoomOut}
|
|
304
|
+
onClick={() => { zoomBy(-ZOOM_STEP); }}>−</button>
|
|
305
|
+
<span>{labels.zoomLevel(Math.round(zoom * 100))}</span>
|
|
306
|
+
<button type="button" disabled={!loaded || zoom >= ZOOM_MAX} aria-label={labels.zoomIn}
|
|
307
|
+
onClick={() => { zoomBy(ZOOM_STEP); }}>+</button>
|
|
308
|
+
</div>
|
|
309
|
+
{/* Keyboard focus lets readers scroll the PDF with arrows and Page Up/Down. */}
|
|
310
|
+
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */}
|
|
311
|
+
<div ref={scrollRef} className="astra-paper-pdf__scroll" role="region" tabIndex={0} aria-label={labels.pages}>
|
|
312
|
+
{loaded ? Array.from({ length: loaded.pdf.numPages }, (_, index) => (
|
|
313
|
+
<Page key={index} loaded={loaded} number={index + 1} width={width} zoom={zoom}
|
|
314
|
+
focus={focus?.page === index + 1 ? focus : undefined} />
|
|
315
|
+
)) : null}
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
});
|
|
@@ -15,15 +15,18 @@ import { decisionInsights, findingEvidence, informedDecisions, outputRelations }
|
|
|
15
15
|
import { useLabels } from '../lib/labels.js';
|
|
16
16
|
import type { ArtifactRenderer } from './artifact-preview.js';
|
|
17
17
|
import { DetailDialog, type DetailDialogProps, type DialogLayout } from '../primitives/dialog.js';
|
|
18
|
-
import type { SurfaceKind } from '../
|
|
19
|
-
import type { TextRenderer } from '../
|
|
18
|
+
import type { SurfaceKind } from '../model/kind.js';
|
|
19
|
+
import type { TextRenderer } from '../lib/prose.js';
|
|
20
20
|
import { DecisionDetail } from './decision-detail.js';
|
|
21
|
-
import type { DetailEntry } from '
|
|
21
|
+
import type { DetailEntry } from '../lib/detail-stack.js';
|
|
22
22
|
import { FindingDetail } from './finding-detail.js';
|
|
23
23
|
import { InputDetail } from './input-detail.js';
|
|
24
|
-
import { InsightDetail
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
24
|
+
import { InsightDetail } from './insight-detail.js';
|
|
25
|
+
import { primaryLiteratureEvidence } from '../model/papers.js';
|
|
26
|
+
import { OutputDetail, OutputDialogActions } from './output-detail.js';
|
|
27
|
+
import { useOutputExpanded } from '../lib/use-output-expanded.js';
|
|
28
|
+
import { PaperDetail, PaperDialogActions, type OpenPaperFileHandler } from './paper-detail.js';
|
|
29
|
+
import type { PdfJsLoader } from '../lib/pdf-runtime.js';
|
|
27
30
|
|
|
28
31
|
export interface RecordDialogProps extends Pick<DetailDialogProps, 'mode' | 'backText' | 'className' | 'onBack' | 'onClose'> {
|
|
29
32
|
entry: DetailEntry;
|
|
@@ -34,7 +37,8 @@ export interface RecordDialogProps extends Pick<DetailDialogProps, 'mode' | 'bac
|
|
|
34
37
|
paperMetadata?: InventoryPaperMetadataMap | undefined;
|
|
35
38
|
renderArtifact?: ArtifactRenderer | undefined;
|
|
36
39
|
renderText?: TextRenderer | undefined;
|
|
37
|
-
|
|
40
|
+
loadPdfJs?: PdfJsLoader | undefined;
|
|
41
|
+
onOpenPaperFile?: OpenPaperFileHandler | undefined;
|
|
38
42
|
onOpenArtifact?: ((output: ResolvedOutput) => void | Promise<void>) | undefined;
|
|
39
43
|
onFetchPaper?: ((doi: string) => void) | undefined;
|
|
40
44
|
/** Navigation to another record from within the detail (drill-down). */
|
|
@@ -66,7 +70,8 @@ export function RecordDialog({
|
|
|
66
70
|
paperMetadata = {},
|
|
67
71
|
renderArtifact,
|
|
68
72
|
renderText,
|
|
69
|
-
|
|
73
|
+
loadPdfJs,
|
|
74
|
+
onOpenPaperFile,
|
|
70
75
|
onOpenArtifact,
|
|
71
76
|
onFetchPaper,
|
|
72
77
|
onOpenRecord,
|
|
@@ -101,14 +106,14 @@ export function RecordDialog({
|
|
|
101
106
|
kindLabel: labels.kinds.paper,
|
|
102
107
|
title: paper.title,
|
|
103
108
|
layout: 'reader',
|
|
104
|
-
actions: <PaperDialogActions record={paper} />,
|
|
109
|
+
actions: <PaperDialogActions record={paper} onOpenPaperFile={onOpenPaperFile} />,
|
|
105
110
|
body: (
|
|
106
111
|
<PaperDetail
|
|
107
112
|
record={paper}
|
|
108
113
|
metadata={paperMetadataFor(paper.doi, paperMetadata)}
|
|
109
114
|
focusInsight={isInsight(focusRecord) ? focusRecord : undefined}
|
|
110
115
|
renderText={renderText}
|
|
111
|
-
|
|
116
|
+
loadPdfJs={loadPdfJs}
|
|
112
117
|
onFetchPaper={onFetchPaper}
|
|
113
118
|
onOpenInsight={openInsight}
|
|
114
119
|
onOpenDecision={openDecision}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KindGlyph } from '../primitives/kind-glyph.js';
|
|
1
2
|
import type {
|
|
2
3
|
AnalysisIndex,
|
|
3
4
|
ResolvedAnalysisDocument,
|
|
@@ -20,12 +21,13 @@ import { useLabels } from '../lib/labels.js';
|
|
|
20
21
|
import { doiHref } from '../model/doi.js';
|
|
21
22
|
import { analysisTitle, recordTitle } from '../model/records.js';
|
|
22
23
|
import { decisionInsights } from '../model/relations.js';
|
|
23
|
-
import { Prose
|
|
24
|
-
import {
|
|
24
|
+
import { Prose } from '../primitives/prose.js';
|
|
25
|
+
import type { TextRenderer } from '../lib/prose.js';
|
|
26
|
+
import { type SurfaceKind } from '../model/kind.js';
|
|
25
27
|
import { SurfaceHeader } from '../primitives/surface-header.js';
|
|
26
28
|
import type { ArtifactRenderer } from './artifact-preview.js';
|
|
27
|
-
import { primaryLiteratureEvidence } from '
|
|
28
|
-
import type { OpenRecordHandler } from '
|
|
29
|
+
import { primaryLiteratureEvidence } from '../model/papers.js';
|
|
30
|
+
import type { OpenRecordHandler } from '../lib/detail-stack.js';
|
|
29
31
|
|
|
30
32
|
export interface RecordPreviewTarget {
|
|
31
33
|
record: ResolvedRecord;
|
|
@@ -114,7 +116,7 @@ function relationTitle(record: ResolvedRecord): string {
|
|
|
114
116
|
function KindEyebrow({ kind, label }: { kind: SurfaceKind; label: ReactNode }) {
|
|
115
117
|
return (
|
|
116
118
|
<span className="astra-record-preview__kind">
|
|
117
|
-
<
|
|
119
|
+
<KindGlyph kind={kind} />
|
|
118
120
|
{label}
|
|
119
121
|
</span>
|
|
120
122
|
);
|
|
@@ -125,7 +127,7 @@ function PreviewHeader({
|
|
|
125
127
|
kindLabel,
|
|
126
128
|
title,
|
|
127
129
|
}: {
|
|
128
|
-
kind
|
|
130
|
+
kind?: SurfaceKind | undefined;
|
|
129
131
|
kindLabel: ReactNode;
|
|
130
132
|
title?: ReactNode | undefined;
|
|
131
133
|
}) {
|
|
@@ -134,7 +136,7 @@ function PreviewHeader({
|
|
|
134
136
|
density="compact"
|
|
135
137
|
kind={kind}
|
|
136
138
|
titleAs="h3"
|
|
137
|
-
eyebrow={<KindEyebrow kind={kind} label={kindLabel} />}
|
|
139
|
+
eyebrow={kind ? <KindEyebrow kind={kind} label={kindLabel} /> : kindLabel}
|
|
138
140
|
title={title}
|
|
139
141
|
className="astra-record-preview__header"
|
|
140
142
|
/>
|
|
@@ -183,9 +185,7 @@ function RelatedRecord({
|
|
|
183
185
|
const label = relationTitle(record);
|
|
184
186
|
const copy = (
|
|
185
187
|
<>
|
|
186
|
-
<
|
|
187
|
-
{surfaceGlyph(record.kind)}
|
|
188
|
-
</span>
|
|
188
|
+
<KindGlyph className="astra-record-preview__relation-glyph" kind={record.kind} />
|
|
189
189
|
<span className="astra-record-preview__relation-label">{label}</span>
|
|
190
190
|
{detail != null ? (
|
|
191
191
|
<small className="astra-record-preview__relation-detail">{detail}</small>
|
|
@@ -369,12 +369,7 @@ function FindingPreview({
|
|
|
369
369
|
className="astra-record-preview__relation-trigger"
|
|
370
370
|
data-kind="output"
|
|
371
371
|
>
|
|
372
|
-
<
|
|
373
|
-
className="astra-record-preview__relation-glyph"
|
|
374
|
-
aria-hidden="true"
|
|
375
|
-
>
|
|
376
|
-
{surfaceGlyph('output')}
|
|
377
|
-
</span>
|
|
372
|
+
<KindGlyph className="astra-record-preview__relation-glyph" kind="output" />
|
|
378
373
|
<span className="astra-record-preview__relation-label">
|
|
379
374
|
{evidence.artifact}
|
|
380
375
|
</span>
|
|
@@ -652,7 +647,6 @@ function ValuePreview({
|
|
|
652
647
|
return (
|
|
653
648
|
<>
|
|
654
649
|
<PreviewHeader
|
|
655
|
-
kind={record.kind}
|
|
656
650
|
kindLabel={kindLabel}
|
|
657
651
|
title={
|
|
658
652
|
<span className="astra-record-preview__value">
|
|
@@ -734,6 +728,7 @@ export const RecordPreview = forwardRef<HTMLElement, RecordPreviewProps>(
|
|
|
734
728
|
<article
|
|
735
729
|
data-slot="record-preview"
|
|
736
730
|
data-entry-kind={entry.kind}
|
|
731
|
+
data-value-product={entry.kind === 'value' && entry.product ? '' : undefined}
|
|
737
732
|
data-kind={previewKind(entry)}
|
|
738
733
|
{...props}
|
|
739
734
|
ref={ref}
|
|
@@ -2,8 +2,11 @@ import type { ResolvedAnalysisNode, ResolvedRecord } from '@astra-spec/sdk';
|
|
|
2
2
|
import type { LinkedRecord } from '../model/relations.js';
|
|
3
3
|
import { recordTitle } from '../model/records.js';
|
|
4
4
|
import type { RelationItem } from '../primitives/relation-list.js';
|
|
5
|
+
import type { OpenRecordHandler } from '../lib/detail-stack.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
// Glue between model records and the RelationList primitive: it needs both
|
|
8
|
+
// `recordTitle` from model and the item shape from primitives, which no lower
|
|
9
|
+
// layer can see together, so it stays here beside the components that use it.
|
|
7
10
|
|
|
8
11
|
/** Builds a relation-list item for a record, with navigation when the caller handles it. */
|
|
9
12
|
export function relationItemForRecord(
|
|
@@ -24,8 +27,15 @@ export function relationItemForRecord(
|
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
/** Builds relation-list items for linked records; unresolved links show their path. */
|
|
27
|
-
export function relationItemsForLinks(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
export function relationItemsForLinks(
|
|
31
|
+
links: LinkedRecord[],
|
|
32
|
+
onOpen: OpenRecordHandler | undefined,
|
|
33
|
+
): RelationItem[] {
|
|
34
|
+
return links.map((link) => {
|
|
35
|
+
const { record, analysis } = link;
|
|
36
|
+
if (!record) {
|
|
37
|
+
return { key: link.canonicalPath, label: link.canonicalPath, identifier: link.canonicalPath };
|
|
38
|
+
}
|
|
39
|
+
return relationItemForRecord(record, analysis, onOpen);
|
|
40
|
+
});
|
|
31
41
|
}
|
|
@@ -1,6 +1,29 @@
|
|
|
1
|
+
/** Navigation state for record details: what a detail surface shows, and the stack that drives drill-down. */
|
|
1
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
3
|
import type { ResolvedAnalysisNode, ResolvedRecord } from '@astra-spec/sdk';
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
/** What a detail surface is showing: a record, or a paper (optionally focused on an insight). */
|
|
6
|
+
export type DetailEntry =
|
|
7
|
+
| { kind: 'record'; canonicalPath: string; analysisPath: string }
|
|
8
|
+
| { kind: 'paper'; doi: string; analysisPath: string; focusInsightPath?: string | undefined };
|
|
9
|
+
|
|
10
|
+
export function recordEntry(canonicalPath: string, analysisPath: string): DetailEntry {
|
|
11
|
+
return { kind: 'record', canonicalPath, analysisPath };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function paperEntry(doi: string, analysisPath: string, focusInsightPath?: string): DetailEntry {
|
|
15
|
+
return { kind: 'paper', doi, analysisPath, ...(focusInsightPath ? { focusInsightPath } : {}) };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function sameEntry(left: DetailEntry, right: DetailEntry): boolean {
|
|
19
|
+
if (left.kind !== right.kind || left.analysisPath !== right.analysisPath) return false;
|
|
20
|
+
return left.kind === 'record'
|
|
21
|
+
? left.canonicalPath === (right as Extract<DetailEntry, { kind: 'record' }>).canonicalPath
|
|
22
|
+
: left.doi === (right as Extract<DetailEntry, { kind: 'paper' }>).doi;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Opens a record, shown within the analysis that owns it; the shape every drill-down callback shares. */
|
|
26
|
+
export type OpenRecordHandler = (record: ResolvedRecord, analysis: ResolvedAnalysisNode) => void;
|
|
4
27
|
|
|
5
28
|
export interface DetailStackOptions {
|
|
6
29
|
/** Controlled stack; pair with `onChange`. */
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Machinery behind the elements: class names, labels, navigation state, prose rendering, preview data, and the pdf.js contract. */
|
|
2
|
+
export { cn } from './cn.js';
|
|
3
|
+
export { LabelsProvider, defaultLabels, mergeLabels, useLabels } from './labels.js';
|
|
4
|
+
export type { AstraLabelOverrides, AstraLabels, LabelsProviderProps } from './labels.js';
|
|
5
|
+
export { paperEntry, recordEntry, sameEntry, useDetailStack } from './detail-stack.js';
|
|
6
|
+
export type { DetailEntry, DetailStack, DetailStackOptions, OpenRecordHandler } from './detail-stack.js';
|
|
7
|
+
export { parseProse, renderProse } from './prose.js';
|
|
8
|
+
export type { ProseContext, ProseField, ProseMathMacros, ProseRenderOptions, ProseToken, TextRenderer } from './prose.js';
|
|
9
|
+
export { metricPreviewFromJson, tablePreviewFromDelimited, tablePreviewFromRows } from './preview-data.js';
|
|
10
|
+
export type {
|
|
11
|
+
ArtifactPreviewData,
|
|
12
|
+
DelimitedPreviewOptions,
|
|
13
|
+
ImagePreviewData,
|
|
14
|
+
LoadingPreviewData,
|
|
15
|
+
MetricPreviewData,
|
|
16
|
+
TablePreviewData,
|
|
17
|
+
TextPreviewData,
|
|
18
|
+
UnavailablePreviewData,
|
|
19
|
+
} from './preview-data.js';
|
|
20
|
+
export { useOutputExpanded } from './use-output-expanded.js';
|
|
21
|
+
export { pdfJsWithWorker } from './pdf-runtime.js';
|
|
22
|
+
export type { PdfJs, PdfJsLoader, PdfJsWorkerModule } from './pdf-runtime.js';
|
package/src/lib/labels.tsx
CHANGED
|
@@ -44,6 +44,26 @@ export interface AstraLabels {
|
|
|
44
44
|
openPaper: string;
|
|
45
45
|
locate: string;
|
|
46
46
|
};
|
|
47
|
+
/** PDF reading, evidence navigation, and accessible viewer controls. */
|
|
48
|
+
pdf: {
|
|
49
|
+
loading: string;
|
|
50
|
+
loadError: string;
|
|
51
|
+
unavailable: string;
|
|
52
|
+
searching: string;
|
|
53
|
+
quoteNotFound: string;
|
|
54
|
+
pages: string;
|
|
55
|
+
zoomIn: string;
|
|
56
|
+
zoomOut: string;
|
|
57
|
+
zoomLevel: (percent: number) => string;
|
|
58
|
+
viewer: (title: string) => string;
|
|
59
|
+
page: (page: number) => string;
|
|
60
|
+
pageError: (page: number) => string;
|
|
61
|
+
pageCount: (count: number) => string;
|
|
62
|
+
quoteHighlighted: (page: number, count: number) => string;
|
|
63
|
+
partialQuoteHighlighted: (page: number, count: number) => string;
|
|
64
|
+
citedPageFallback: (page: number, count: number) => string;
|
|
65
|
+
locatePassage: (passage: number) => string;
|
|
66
|
+
};
|
|
47
67
|
/** Copy used only by the compact RecordPreview surface. */
|
|
48
68
|
preview: {
|
|
49
69
|
optionDetail: string;
|
|
@@ -109,6 +129,25 @@ export const defaultLabels: AstraLabels = {
|
|
|
109
129
|
openPaper: 'Open',
|
|
110
130
|
locate: 'Locate',
|
|
111
131
|
},
|
|
132
|
+
pdf: {
|
|
133
|
+
loading: 'Loading PDF…',
|
|
134
|
+
loadError: 'The PDF could not be loaded.',
|
|
135
|
+
unavailable: 'Embedded PDF viewing is unavailable. Open the PDF to read it.',
|
|
136
|
+
searching: 'Locating quote in the PDF…',
|
|
137
|
+
quoteNotFound: 'The quoted passage was not found in the PDF text.',
|
|
138
|
+
pages: 'PDF pages',
|
|
139
|
+
zoomIn: 'Zoom PDF in',
|
|
140
|
+
zoomOut: 'Zoom PDF out',
|
|
141
|
+
zoomLevel: (percent) => `${percent}%`,
|
|
142
|
+
viewer: (title) => `PDF viewer for ${title}`,
|
|
143
|
+
page: (page) => `Page ${page}`,
|
|
144
|
+
pageError: (page) => `Page ${page} could not be rendered.`,
|
|
145
|
+
pageCount: (count) => (count === 1 ? '1 page' : `${count} pages`),
|
|
146
|
+
quoteHighlighted: (page, count) => `Quote highlighted on page ${page} of ${count}`,
|
|
147
|
+
partialQuoteHighlighted: (page, count) => `Partial quote highlighted on page ${page} of ${count}`,
|
|
148
|
+
citedPageFallback: (page, count) => `Exact quote not found; showing cited page ${page} of ${count}`,
|
|
149
|
+
locatePassage: (passage) => `Locate source passage ${passage} in paper`,
|
|
150
|
+
},
|
|
112
151
|
preview: {
|
|
113
152
|
optionDetail: 'Option detail',
|
|
114
153
|
supportedBy: 'Supported by',
|
|
@@ -148,6 +187,7 @@ function merge(base: AstraLabels, overrides: AstraLabelOverrides): AstraLabels {
|
|
|
148
187
|
kinds: { ...base.kinds, ...defined(overrides.kinds ?? {}) },
|
|
149
188
|
empty: { ...base.empty, ...defined(overrides.empty ?? {}) },
|
|
150
189
|
actions: { ...base.actions, ...defined(overrides.actions ?? {}) },
|
|
190
|
+
pdf: { ...base.pdf, ...defined(overrides.pdf ?? {}) },
|
|
151
191
|
preview: { ...base.preview, ...defined(overrides.preview ?? {}) },
|
|
152
192
|
} as AstraLabels;
|
|
153
193
|
}
|