@xynolog/react-ui 0.8.0 → 0.8.1

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 (235) hide show
  1. package/README.md +26 -46
  2. package/package.json +12 -9
  3. package/src/components/Button/Button.tsx +0 -188
  4. package/src/components/Button/__tests__/Button.test.tsx +0 -449
  5. package/src/components/CodeMirrorRenderer.tsx +0 -536
  6. package/src/components/DelegateProgress.tsx +0 -308
  7. package/src/components/ErrorBoundary.tsx +0 -174
  8. package/src/components/ItemFoundLog.tsx +0 -42
  9. package/src/components/LiveRegion.tsx +0 -261
  10. package/src/components/ProtectedErrorBoundary.tsx +0 -114
  11. package/src/components/ResizeHandle.tsx +0 -167
  12. package/src/components/ResourceTagsInline.tsx +0 -120
  13. package/src/components/SessionExpiryBanner.tsx +0 -74
  14. package/src/components/SessionTimer.tsx +0 -17
  15. package/src/components/StatusDisplay.tsx +0 -131
  16. package/src/components/Toast.tsx +0 -217
  17. package/src/components/Toolbar.tsx +0 -194
  18. package/src/components/UserMenuSkeleton.tsx +0 -13
  19. package/src/components/__tests__/DelegateProgress.denominator.test.tsx +0 -102
  20. package/src/components/__tests__/DelegateProgress.test.tsx +0 -649
  21. package/src/components/__tests__/ErrorBoundary.test.tsx +0 -565
  22. package/src/components/__tests__/LiveRegion.a11y.test.tsx +0 -258
  23. package/src/components/__tests__/LiveRegion.hooks.test.tsx +0 -140
  24. package/src/components/__tests__/ProtectedErrorBoundary.test.tsx +0 -225
  25. package/src/components/__tests__/ResizeHandle.test.tsx +0 -159
  26. package/src/components/__tests__/ResourceTagsInline.test.tsx +0 -325
  27. package/src/components/__tests__/SessionExpiryBanner.test.tsx +0 -124
  28. package/src/components/__tests__/SessionTimer.test.tsx +0 -199
  29. package/src/components/__tests__/StatusDisplay.test.tsx +0 -179
  30. package/src/components/__tests__/Toast.test.tsx +0 -96
  31. package/src/components/__tests__/Toolbar.test.tsx +0 -111
  32. package/src/components/__tests__/UserMenuSkeleton.test.tsx +0 -182
  33. package/src/components/annotation/AnchoredTextNotice.tsx +0 -36
  34. package/src/components/annotation/AnnotateToolbar.tsx +0 -531
  35. package/src/components/annotation/__tests__/AnnotateToolbar.display.test.tsx +0 -127
  36. package/src/components/annotation/__tests__/AnnotateToolbar.test.tsx +0 -304
  37. package/src/components/annotation-popups/JsonLdView.tsx +0 -127
  38. package/src/components/annotation-popups/SharedPopupElements.tsx +0 -131
  39. package/src/components/annotation-popups/__tests__/JsonLdView.test.tsx +0 -432
  40. package/src/components/annotation-popups/__tests__/SharedPopupElements.test.tsx +0 -297
  41. package/src/components/branding/XynologBranding.tsx +0 -41
  42. package/src/components/branding/__tests__/XynologBranding.test.tsx +0 -383
  43. package/src/components/error-states/ResourceErrorState.tsx +0 -30
  44. package/src/components/error-states/__tests__/ResourceErrorState.test.tsx +0 -102
  45. package/src/components/image-annotation/AnnotationOverlay.tsx +0 -307
  46. package/src/components/image-annotation/SvgDrawingCanvas.tsx +0 -514
  47. package/src/components/image-annotation/__tests__/AnnotationOverlay.click.test.tsx +0 -169
  48. package/src/components/image-annotation/__tests__/AnnotationOverlay.hover.test.tsx +0 -83
  49. package/src/components/image-annotation/__tests__/SvgDrawingCanvas.annotate-gate.test.tsx +0 -228
  50. package/src/components/image-annotation/__tests__/SvgDrawingCanvas.click.test.tsx +0 -204
  51. package/src/components/layout/LeftSidebar.tsx +0 -150
  52. package/src/components/layout/PageLayout.tsx +0 -49
  53. package/src/components/layout/SkipLinks.tsx +0 -36
  54. package/src/components/layout/UnifiedHeader.tsx +0 -151
  55. package/src/components/layout/__tests__/LeftSidebar.test.tsx +0 -426
  56. package/src/components/layout/__tests__/PageLayout.test.tsx +0 -311
  57. package/src/components/layout/__tests__/SkipLinks.a11y.test.tsx +0 -218
  58. package/src/components/layout/__tests__/UnifiedHeader.test.tsx +0 -555
  59. package/src/components/loading-states/ComposeLoadingState.tsx +0 -19
  60. package/src/components/loading-states/ResourceLoadingState.tsx +0 -13
  61. package/src/components/loading-states/__tests__/ComposeLoadingState.test.tsx +0 -37
  62. package/src/components/loading-states/__tests__/ResourceLoadingState.test.tsx +0 -31
  63. package/src/components/modals/ComposeStep.tsx +0 -245
  64. package/src/components/modals/ConfigureGatherStep.tsx +0 -110
  65. package/src/components/modals/ConfigureGenerationStep.tsx +0 -458
  66. package/src/components/modals/ConfigureSearchStep.tsx +0 -124
  67. package/src/components/modals/ContextSummary.tsx +0 -317
  68. package/src/components/modals/CorpusPane.tsx +0 -96
  69. package/src/components/modals/DiscardPrompt.tsx +0 -44
  70. package/src/components/modals/GatherContextStep.tsx +0 -480
  71. package/src/components/modals/KbIdentityConflictModal.tsx +0 -122
  72. package/src/components/modals/KeyboardShortcutsHelpModal.tsx +0 -238
  73. package/src/components/modals/PermissionDeniedModal.tsx +0 -207
  74. package/src/components/modals/ReferenceWizardModal.tsx +0 -656
  75. package/src/components/modals/ResourceGenerateModal.tsx +0 -457
  76. package/src/components/modals/SearchModal.tsx +0 -334
  77. package/src/components/modals/SearchResultsStep.tsx +0 -117
  78. package/src/components/modals/SessionEndedModal.tsx +0 -148
  79. package/src/components/modals/WizardFooter.tsx +0 -72
  80. package/src/components/modals/__tests__/ComposeStep.test.tsx +0 -187
  81. package/src/components/modals/__tests__/ConfigureGatherStep.test.tsx +0 -92
  82. package/src/components/modals/__tests__/ConfigureGenerationStep.test.tsx +0 -574
  83. package/src/components/modals/__tests__/ConfigureSearchStep.test.tsx +0 -124
  84. package/src/components/modals/__tests__/GatherContextStep.resource.test.tsx +0 -702
  85. package/src/components/modals/__tests__/KbIdentityConflictModal.test.tsx +0 -102
  86. package/src/components/modals/__tests__/KeyboardShortcutsHelpModal.test.tsx +0 -115
  87. package/src/components/modals/__tests__/PermissionDeniedModal.test.tsx +0 -218
  88. package/src/components/modals/__tests__/ReferenceWizardModal.test.tsx +0 -936
  89. package/src/components/modals/__tests__/ResourceGenerateModal.test.tsx +0 -532
  90. package/src/components/modals/__tests__/SearchModal.accessibility.test.tsx +0 -95
  91. package/src/components/modals/__tests__/SearchModal.basic.test.tsx +0 -84
  92. package/src/components/modals/__tests__/SearchModal.keyboard.test.tsx +0 -162
  93. package/src/components/modals/__tests__/SearchModal.search-wiring.test.tsx +0 -237
  94. package/src/components/modals/__tests__/SearchModal.translations.test.tsx +0 -91
  95. package/src/components/modals/__tests__/SearchResultsStep.test.tsx +0 -95
  96. package/src/components/modals/__tests__/SessionEndedModal.test.tsx +0 -171
  97. package/src/components/modals/__tests__/WizardFooter.test.tsx +0 -446
  98. package/src/components/modals/__tests__/search-modal-harness.ts +0 -82
  99. package/src/components/navigation/CollapsibleResourceNavigation.tsx +0 -364
  100. package/src/components/navigation/NavigationMenu.tsx +0 -66
  101. package/src/components/navigation/ObservableLink.tsx +0 -90
  102. package/src/components/navigation/SimpleNavigation.tsx +0 -169
  103. package/src/components/navigation/SortableResourceTab.tsx +0 -122
  104. package/src/components/navigation/__tests__/NavigationMenu.a11y.test.tsx +0 -302
  105. package/src/components/navigation/__tests__/NavigationMenu.test.tsx +0 -399
  106. package/src/components/navigation/__tests__/ObservableLink.test.tsx +0 -85
  107. package/src/components/navigation/__tests__/SimpleNavigation.test.tsx +0 -193
  108. package/src/components/navigation/__tests__/SortableResourceTab.test.tsx +0 -421
  109. package/src/components/pdf-annotation/PdfAnnotationCanvas.client.tsx +0 -10
  110. package/src/components/pdf-annotation/PdfAnnotationCanvas.tsx +0 -632
  111. package/src/components/pdf-annotation/PdfPageView.tsx +0 -527
  112. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.annotate-gate.test.tsx +0 -295
  113. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.pixels-before-anchoring.test.tsx +0 -166
  114. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.test.tsx +0 -1719
  115. package/src/components/pdf-annotation/__tests__/estimate-slot-height.test.ts +0 -61
  116. package/src/components/pdf-annotation/__tests__/rects-for-page.test.ts +0 -110
  117. package/src/components/pdf-annotation/estimate-slot-height.ts +0 -31
  118. package/src/components/pdf-annotation/rects-for-page.ts +0 -50
  119. package/src/components/resource/AnnotateView.tsx +0 -373
  120. package/src/components/resource/AnnotationHistory.tsx +0 -169
  121. package/src/components/resource/BrowseView.tsx +0 -440
  122. package/src/components/resource/DownloadFileLink.tsx +0 -53
  123. package/src/components/resource/HistoryEvent.tsx +0 -186
  124. package/src/components/resource/ResourceViewer.tsx +0 -617
  125. package/src/components/resource/__tests__/AnnotateView.code-point-offsets.test.tsx +0 -482
  126. package/src/components/resource/__tests__/AnnotateView.embeddable.test.tsx +0 -78
  127. package/src/components/resource/__tests__/AnnotateView.focus.test.tsx +0 -147
  128. package/src/components/resource/__tests__/AnnotateView.registry.test.tsx +0 -143
  129. package/src/components/resource/__tests__/AnnotationHistory.test.tsx +0 -257
  130. package/src/components/resource/__tests__/BrowseView.code-point-offsets.test.tsx +0 -123
  131. package/src/components/resource/__tests__/BrowseView.embeddable.test.tsx +0 -76
  132. package/src/components/resource/__tests__/BrowseView.links.test.tsx +0 -84
  133. package/src/components/resource/__tests__/BrowseView.overlay-async.test.tsx +0 -165
  134. package/src/components/resource/__tests__/BrowseView.reference-hover.test.tsx +0 -200
  135. package/src/components/resource/__tests__/BrowseView.registry.test.tsx +0 -57
  136. package/src/components/resource/__tests__/BrowseView.test.tsx +0 -915
  137. package/src/components/resource/__tests__/HistoryEvent.test.tsx +0 -571
  138. package/src/components/resource/__tests__/ResourceViewer.delete-failure.test.tsx +0 -103
  139. package/src/components/resource/__tests__/ResourceViewer.embeddable.test.tsx +0 -250
  140. package/src/components/resource/__tests__/ResourceViewer.mode-switch.test.tsx +0 -262
  141. package/src/components/resource/__tests__/ResourceViewer.multi-mount-invalidation.test.tsx +0 -166
  142. package/src/components/resource/__tests__/ResourceViewer.registry.test.tsx +0 -112
  143. package/src/components/resource/__tests__/ResourceViewer.toolbar-opt-out.test.tsx +0 -207
  144. package/src/components/resource/__tests__/ResourceViewer.toolbar-prefs.test.tsx +0 -274
  145. package/src/components/resource/__tests__/annotation-interactions.test.tsx +0 -116
  146. package/src/components/resource/__tests__/browse-renderers.dispatch.test.tsx +0 -183
  147. package/src/components/resource/__tests__/browse-renderers.test.tsx +0 -47
  148. package/src/components/resource/__tests__/download-link.test.tsx +0 -171
  149. package/src/components/resource/__tests__/event-formatting.test.ts +0 -379
  150. package/src/components/resource/__tests__/inline-embedding.test.tsx +0 -133
  151. package/src/components/resource/__tests__/media-completeness.test.tsx +0 -144
  152. package/src/components/resource/annotate-renderers.tsx +0 -186
  153. package/src/components/resource/browse-renderers.tsx +0 -133
  154. package/src/components/resource/event-formatting.ts +0 -393
  155. package/src/components/resource/panels/AssessmentEntry.tsx +0 -127
  156. package/src/components/resource/panels/AssessmentPanel.tsx +0 -309
  157. package/src/components/resource/panels/CollaborationPanel.tsx +0 -228
  158. package/src/components/resource/panels/CommentEntry.tsx +0 -242
  159. package/src/components/resource/panels/CommentsPanel.tsx +0 -320
  160. package/src/components/resource/panels/DelegateSection.tsx +0 -282
  161. package/src/components/resource/panels/DelegateShell.tsx +0 -134
  162. package/src/components/resource/panels/HighlightEntry.tsx +0 -83
  163. package/src/components/resource/panels/HighlightPanel.tsx +0 -212
  164. package/src/components/resource/panels/JsonLdPanel.tsx +0 -119
  165. package/src/components/resource/panels/PanelHeader.tsx +0 -22
  166. package/src/components/resource/panels/ReferenceEntry.tsx +0 -232
  167. package/src/components/resource/panels/ReferencesPanel.tsx +0 -626
  168. package/src/components/resource/panels/ResourceInfoPanel.tsx +0 -433
  169. package/src/components/resource/panels/StatisticsPanel.tsx +0 -145
  170. package/src/components/resource/panels/TagEntry.tsx +0 -87
  171. package/src/components/resource/panels/TaggingPanel.tsx +0 -554
  172. package/src/components/resource/panels/UnifiedAnnotationsPanel.tsx +0 -384
  173. package/src/components/resource/panels/__tests__/AssessmentEntry.test.tsx +0 -292
  174. package/src/components/resource/panels/__tests__/AssessmentPanel.test.tsx +0 -685
  175. package/src/components/resource/panels/__tests__/CollaborationPanel.test.tsx +0 -685
  176. package/src/components/resource/panels/__tests__/CommentEntry.test.tsx +0 -750
  177. package/src/components/resource/panels/__tests__/CommentsPanel.test.tsx +0 -877
  178. package/src/components/resource/panels/__tests__/DelegateSection.test.tsx +0 -623
  179. package/src/components/resource/panels/__tests__/DelegateShell.test.tsx +0 -212
  180. package/src/components/resource/panels/__tests__/HighlightEntry.test.tsx +0 -236
  181. package/src/components/resource/panels/__tests__/HighlightPanel.annotationProgress.test.tsx +0 -506
  182. package/src/components/resource/panels/__tests__/HighlightPanel.out-of-order.test.tsx +0 -132
  183. package/src/components/resource/panels/__tests__/JsonLdPanel.test.tsx +0 -230
  184. package/src/components/resource/panels/__tests__/PanelHeader.test.tsx +0 -54
  185. package/src/components/resource/panels/__tests__/ReferenceEntry.test.tsx +0 -578
  186. package/src/components/resource/panels/__tests__/ReferencesPanel.headless.test.tsx +0 -193
  187. package/src/components/resource/panels/__tests__/ReferencesPanel.observable-flow.test.tsx +0 -193
  188. package/src/components/resource/panels/__tests__/ReferencesPanel.test.tsx +0 -1080
  189. package/src/components/resource/panels/__tests__/ResourceInfoPanel.test.tsx +0 -812
  190. package/src/components/resource/panels/__tests__/ResourceInfoPanel.text-layer.test.tsx +0 -106
  191. package/src/components/resource/panels/__tests__/StatisticsPanel.test.tsx +0 -329
  192. package/src/components/resource/panels/__tests__/TagEntry.test.tsx +0 -250
  193. package/src/components/resource/panels/__tests__/TaggingPanel.test.tsx +0 -772
  194. package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.delegated-job.test.tsx +0 -207
  195. package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.failure.test.tsx +0 -89
  196. package/src/components/resource/panels/__tests__/agent-label.test.ts +0 -136
  197. package/src/components/resource/panels/agent-label.ts +0 -35
  198. package/src/components/settings/SettingsPanel.tsx +0 -251
  199. package/src/components/settings/__tests__/SettingsPanel.test.tsx +0 -260
  200. package/src/components/viewers/ImageViewer.tsx +0 -18
  201. package/src/components/viewers/__tests__/ImageViewer.test.tsx +0 -57
  202. package/src/components/viewers/index.ts +0 -1
  203. package/src/features/auth/__tests__/AuthErrorDisplay.test.tsx +0 -181
  204. package/src/features/auth/components/AuthErrorDisplay.tsx +0 -89
  205. package/src/features/moderate-entity-tags/__tests__/EntityTagsPage.test.tsx +0 -387
  206. package/src/features/moderate-entity-tags/components/EntityTagsPage.tsx +0 -161
  207. package/src/features/moderate-entity-tags/state/__tests__/entity-tags-state-unit.test.ts +0 -183
  208. package/src/features/moderate-entity-tags/state/entity-tags-state-unit.ts +0 -73
  209. package/src/features/moderate-recent/__tests__/RecentDocumentsPage.test.tsx +0 -422
  210. package/src/features/moderate-recent/components/RecentDocumentsPage.tsx +0 -117
  211. package/src/features/moderate-tag-schemas/__tests__/TagSchemasPage.test.tsx +0 -481
  212. package/src/features/moderate-tag-schemas/components/TagSchemasPage.tsx +0 -161
  213. package/src/features/resource-compose/__tests__/ResourceComposePage.test.tsx +0 -600
  214. package/src/features/resource-compose/__tests__/UploadProgressBar.test.tsx +0 -256
  215. package/src/features/resource-compose/components/ResourceComposePage.tsx +0 -809
  216. package/src/features/resource-compose/components/UploadProgressBar.tsx +0 -125
  217. package/src/features/resource-compose/state/__tests__/compose-page-state-unit.test.ts +0 -195
  218. package/src/features/resource-compose/state/compose-page-state-unit.ts +0 -187
  219. package/src/features/resource-discovery/__tests__/ResourceCard.test.tsx +0 -338
  220. package/src/features/resource-discovery/__tests__/ResourceDiscoveryPage.test.tsx +0 -449
  221. package/src/features/resource-discovery/components/ResourceCard.tsx +0 -80
  222. package/src/features/resource-discovery/components/ResourceDiscoveryPage.tsx +0 -330
  223. package/src/features/resource-discovery/state/__tests__/discover-state-unit.test.ts +0 -477
  224. package/src/features/resource-discovery/state/discover-state-unit.ts +0 -162
  225. package/src/features/resource-viewer/__tests__/ResourceViewerPage.content-loading.test.tsx +0 -260
  226. package/src/features/resource-viewer/__tests__/ResourceViewerPage.test.tsx +0 -570
  227. package/src/features/resource-viewer/__tests__/generation-params.test.ts +0 -49
  228. package/src/features/resource-viewer/components/ResourceViewerPage.tsx +0 -1058
  229. package/src/features/resource-viewer/generation-params.ts +0 -23
  230. package/src/features/resource-viewer/hooks/__tests__/useResourceViewedReport.test.tsx +0 -77
  231. package/src/features/resource-viewer/hooks/useResourceViewedReport.ts +0 -38
  232. package/src/features/resource-viewer/state/__tests__/resource-loader-state-unit.test.ts +0 -178
  233. package/src/features/resource-viewer/state/__tests__/resource-viewer-page-state-unit.test.ts +0 -505
  234. package/src/features/resource-viewer/state/resource-loader-state-unit.ts +0 -93
  235. package/src/features/resource-viewer/state/resource-viewer-page-state-unit.ts +0 -156
@@ -1,632 +0,0 @@
1
- 'use client';
2
-
3
- import type { ResourceId } from '@xynolog/core';
4
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
- import type { Annotation } from '@xynolog/core';
6
- import { estimateSlotHeight } from './estimate-slot-height';
7
- import { useAnchoredText } from '../../hooks/useAnchoredText';
8
- import { AnchoredTextNotice } from '../annotation/AnchoredTextNotice';
9
- import { PdfPageView, type PageDrawing } from './PdfPageView';
10
- import { useTranslations } from '../../contexts/TranslationContext';
11
- import { HOVER_DELAY_MS, type XynologSession } from '@xynolog/sdk';
12
- import type { Motivation } from '@xynolog/core';
13
- import {
14
- loadPdfDocument,
15
- type PDFDocumentProxy,
16
- } from '../../lib/browser-pdfjs';
17
- import './PdfAnnotationCanvas.css';
18
-
19
- export type DrawingMode = 'rectangle' | 'circle' | 'polygon' | null;
20
-
21
- /**
22
- * How the document's pages are laid out.
23
- *
24
- * `paged` is one page with Previous/Next. `scroll` is a virtualized column:
25
- * every page gets a slot so the scrollbar tells the truth about the
26
- * document's length, but only the pages near the viewport are mounted.
27
- *
28
- * Declared explicitly rather than inferred from `drawingMode`, which does NOT
29
- * distinguish the modes — AnnotateView passes `drawingMode={null}` whenever no
30
- * motivation is selected, so keying layout on it would flip a reader between
31
- * scrolling and paged views as they picked up and put down a tool.
32
- */
33
- export type PageLayout = 'paged' | 'scroll';
34
-
35
- /** How far outside the viewport a page starts loading, and stays loaded. */
36
- const PRELOAD_MARGIN = '100% 0px';
37
-
38
- /** Width of one page rectangle in the strip, in CSS px. Height follows the
39
- * document's own aspect ratio, so the strip looks like the document — wide
40
- * enough to carry a three-digit page number, which is what makes the strip
41
- * useful rather than merely positional on a long document. */
42
- const STRIP_PAGE_WIDTH = 30;
43
-
44
- /**
45
- * The axis pages advance along.
46
- *
47
- * ONE source for two consumers: the column scrolls along it, and the page
48
- * strip runs parallel to it. A strip that ran across the scroll direction
49
- * would read as a control for a movement the document does not make.
50
- *
51
- * Constant, because scrolling is vertical only. A horizontal-scrolling
52
- * setting would make this a value read from preferences — both consumers
53
- * follow automatically, which is the point of routing them through one name.
54
- */
55
- const SCROLL_AXIS: 'vertical' | 'horizontal' = 'vertical';
56
-
57
- /**
58
- * Scroll an element into view where the environment supports it.
59
- *
60
- * Same posture as this file's guarded observers: jsdom implements no layout
61
- * and therefore no `scrollIntoView`, and a viewer that throws in a test
62
- * harness (or an exotic embedding host) is worse than one that simply does
63
- * not scroll.
64
- */
65
- /** Scroll a target within the scrollport the PDF viewer owns. Avoid
66
- * scrollIntoView: it is allowed to move every scrollable ancestor, which
67
- * makes embedded/zoomed viewers sensitive to host layout. */
68
- function scrollWithin(
69
- scrollport: HTMLElement | null,
70
- target: HTMLElement | null,
71
- align: 'start' | 'nearest',
72
- ): void {
73
- if (!target) return;
74
- if (!scrollport || typeof scrollport.scrollTo !== 'function') {
75
- target.scrollIntoView?.({ block: align });
76
- return;
77
- }
78
- const portRect = scrollport.getBoundingClientRect();
79
- const targetRect = target.getBoundingClientRect();
80
- const top = targetRect.top - (portRect.top + scrollport.clientTop);
81
- const bottom =
82
- targetRect.bottom -
83
- (portRect.top + scrollport.clientTop + scrollport.clientHeight);
84
- if (align === 'nearest' && top >= 0 && bottom <= 0) return;
85
- scrollport.scrollTo({ top: scrollport.scrollTop + top, behavior: 'instant' });
86
- }
87
-
88
- /**
89
- * Get color for annotation based on motivation
90
- */
91
-
92
- interface PdfAnnotationCanvasProps {
93
- pdfUrl: string;
94
- /** The '@id' of the annotated resource — stamped as `source` on mark:requested (multi-viewer routing). */
95
- resourceUri: ResourceId;
96
- existingAnnotations?: Annotation[];
97
- drawingMode: DrawingMode;
98
- selectedMotivation?: Motivation | null;
99
- session?: XynologSession | null | undefined;
100
- hoveredAnnotationId?: string | null;
101
- selectedAnnotationId?: string | null;
102
- hoverDelayMs?: number;
103
- /** Scale rendered PDF pages without scaling the numbered page rail. */
104
- zoom?: number;
105
- /** Own the PDF scrollport; inline embeds leave scrolling to their host. */
106
- ownsScrollport?: boolean;
107
- /** `paged` (default) or the virtualized `scroll` column. See `PageLayout`. */
108
- pageLayout?: PageLayout;
109
- }
110
-
111
- /**
112
- * PDF annotation canvas with page navigation and rectangle drawing
113
- */
114
- export function PdfAnnotationCanvas({
115
- pdfUrl,
116
- resourceUri,
117
- existingAnnotations = [],
118
- drawingMode,
119
- selectedMotivation,
120
- session,
121
- hoveredAnnotationId,
122
- selectedAnnotationId,
123
- hoverDelayMs = HOVER_DELAY_MS,
124
- zoom = 1,
125
- ownsScrollport = true,
126
- pageLayout = 'paged',
127
- }: PdfAnnotationCanvasProps) {
128
- // PDF state
129
- const [pdfDoc, setPdfDoc] = useState<PDFDocumentProxy | null>(null);
130
- const [numPages, setNumPages] = useState<number>(0);
131
- const [pageNumber, setPageNumber] = useState(1);
132
- const [isLoading, setIsLoading] = useState(true);
133
- const [errorKey, setErrorKey] = useState<string | null>(null);
134
- const t = useTranslations('PdfViewer');
135
- /**
136
- * Page 1's shape, for reserving space in slots that have not mounted yet:
137
- * its aspect ratio and its raster width. NOT its raster height — the image
138
- * renders under `max-width: 100%; height: auto`, so its displayed height
139
- * depends on the column's width, and reserving raster pixels would make
140
- * the column's height lurch on every mount.
141
- */
142
- const [pageShape, setPageShape] = useState<{
143
- aspect: number;
144
- rasterWidth: number;
145
- } | null>(null);
146
- /** Measured inner width of the column — the other half of the reservation. */
147
- const [columnWidth, setColumnWidth] = useState<number | null>(null);
148
- const scrollportRef = useRef<HTMLDivElement>(null);
149
- const columnRef = useRef<HTMLDivElement>(null);
150
- const [scale] = useState(1.5); // Fixed scale for better quality
151
-
152
- /** Pages currently intersecting the viewport (plus the preload margin). */
153
- const [visiblePages, setVisiblePages] = useState<Set<number>>(new Set());
154
- /** Pages genuinely in view — observed with NO preload margin, so it answers
155
- * "what is the reader looking at" rather than "what should be loaded".
156
- * Drives the indicator and the rail; never the mount window. */
157
- const [onscreenPages, setOnscreenPages] = useState<Set<number>>(new Set());
158
- const slotRefs = useRef(new Map<number, HTMLElement>());
159
- const observerRef = useRef<IntersectionObserver | null>(null);
160
- const onscreenRef = useRef<IntersectionObserver | null>(null);
161
-
162
- // Load PDF document on mount
163
- useEffect(() => {
164
- let cancelled = false;
165
-
166
- async function loadPdf() {
167
- try {
168
- setIsLoading(true);
169
- setErrorKey(null);
170
-
171
- const doc = await loadPdfDocument(pdfUrl);
172
-
173
- if (cancelled) return;
174
-
175
- setPdfDoc(doc);
176
- setNumPages(doc.numPages);
177
- setIsLoading(false);
178
-
179
- // One extra getPage, for slot sizing: every slot takes page 1's
180
- // shape. Failure is not fatal: unsized slots still scroll, just less
181
- // faithfully.
182
- try {
183
- const first = await doc.getPage(1);
184
- if (cancelled) return;
185
- const natural = first.getViewport({ scale: 1.0 });
186
- setPageShape({
187
- aspect: natural.height / natural.width,
188
- rasterWidth: first.getViewport({ scale }).width,
189
- });
190
- } catch {
191
- /* leave unsized — an unsized slot is stable; a mis-sized one moves */
192
- }
193
- } catch (err) {
194
- if (cancelled) return;
195
-
196
- console.error('Error loading PDF:', err);
197
- setErrorKey('loadFailed');
198
- setIsLoading(false);
199
- }
200
- }
201
-
202
- loadPdf();
203
-
204
- return () => {
205
- cancelled = true;
206
- };
207
- }, [pdfUrl, scale]);
208
-
209
- /**
210
- * The document's text as Xynolog serves it — every PDF's, since a rectangle
211
- * on any page is quoted from it and from nowhere else. It is WHOLE-RESOURCE,
212
- * one artifact covering every page, so it is held here, once for the
213
- * document, and handed to each page: a 400-page document is asked for and
214
- * decoded once, however many pages mount and however often they turn.
215
- *
216
- * A person may draw only while it is held. A quote is cut when an annotation
217
- * is made and never again, so a rectangle drawn without the text would have
218
- * no quote for good.
219
- */
220
- const anchoredText = useAnchoredText(session, resourceUri);
221
- const drawing = useMemo<PageDrawing | null>(
222
- () =>
223
- anchoredText.status === 'held' && drawingMode
224
- ? { mode: drawingMode, text: anchoredText.text }
225
- : null,
226
- [anchoredText, drawingMode],
227
- );
228
-
229
- // The column's width decides every page's displayed height, so the
230
- // reservation cannot be computed without it.
231
- useEffect(() => {
232
- if (pageLayout !== 'scroll') return;
233
- const measure = () => {
234
- if (columnRef.current) setColumnWidth(columnRef.current.clientWidth);
235
- };
236
- measure();
237
- let observer: ResizeObserver | null = null;
238
- try {
239
- observer = new ResizeObserver(measure);
240
- if (columnRef.current) observer.observe(columnRef.current);
241
- } catch {
242
- window.addEventListener('resize', measure);
243
- }
244
- return () => {
245
- if (observer) observer.disconnect();
246
- else window.removeEventListener('resize', measure);
247
- };
248
- }, [pageLayout]);
249
-
250
- const slotHeight =
251
- estimateSlotHeight(
252
- columnWidth,
253
- pageShape?.rasterWidth ?? null,
254
- pageShape?.aspect ?? null,
255
- ) ??
256
- // Before the column has been measured there is still a sane reservation:
257
- // the raster's own height. Wrong in a narrow column, but every slot is
258
- // wrong by the SAME amount, so the column is at least internally
259
- // consistent until the first measurement lands.
260
- (pageShape ? Math.round(pageShape.rasterWidth * pageShape.aspect) : null);
261
-
262
- // The mount window. Slots report their own visibility; a page is mounted
263
- // while its slot intersects (widened by PRELOAD_MARGIN so the next page is
264
- // ready before it is reached), and unmounting is what frees its raster.
265
- useEffect(() => {
266
- if (pageLayout !== 'scroll' || numPages === 0) return;
267
-
268
- let observer: IntersectionObserver | null = null;
269
- try {
270
- observer = new IntersectionObserver(
271
- (entries) => {
272
- setVisiblePages((prev) => {
273
- const next = new Set(prev);
274
- for (const entry of entries) {
275
- const page = Number((entry.target as HTMLElement).dataset.page);
276
- if (!page) continue;
277
- if (entry.isIntersecting) next.add(page);
278
- else next.delete(page);
279
- }
280
- return next;
281
- });
282
- },
283
- {
284
- root: ownsScrollport ? scrollportRef.current : null,
285
- rootMargin: PRELOAD_MARGIN,
286
- },
287
- );
288
- } catch {
289
- // No IntersectionObserver: mount every page rather than none. Correct,
290
- // simply not virtualized — the same posture as the ResizeObserver
291
- // fallback in PdfPageView.
292
- setVisiblePages(
293
- new Set(Array.from({ length: numPages }, (_, i) => i + 1)),
294
- );
295
- return;
296
- }
297
-
298
- observerRef.current = observer;
299
- for (const el of slotRefs.current.values()) observer.observe(el);
300
-
301
- // A SECOND observer, with no preload margin, answers a different question:
302
- // which pages the reader can actually see. Two observers rather than one
303
- // set doing both jobs, because widening the mount window must never move
304
- // the page indicator.
305
- let onscreen: IntersectionObserver | null = null;
306
- try {
307
- onscreen = new IntersectionObserver(
308
- (entries) => {
309
- setOnscreenPages((prev) => {
310
- const next = new Set(prev);
311
- for (const entry of entries) {
312
- const page = Number((entry.target as HTMLElement).dataset.page);
313
- if (!page) continue;
314
- if (entry.isIntersecting) next.add(page);
315
- else next.delete(page);
316
- }
317
- return next;
318
- });
319
- },
320
- { root: ownsScrollport ? scrollportRef.current : null },
321
- );
322
- onscreenRef.current = onscreen;
323
- for (const el of slotRefs.current.values()) onscreen.observe(el);
324
- } catch {
325
- // Without an observer there is no notion of "on screen"; fall back to
326
- // page 1 so the indicator names something rather than nothing.
327
- setOnscreenPages(new Set([1]));
328
- }
329
-
330
- return () => {
331
- observer.disconnect();
332
- observerRef.current = null;
333
- onscreen?.disconnect();
334
- onscreenRef.current = null;
335
- };
336
- }, [ownsScrollport, pageLayout, numPages]);
337
-
338
- // One ref callback for every slot, stable across renders: React re-runs a
339
- // ref whose identity changes on every commit, and re-running this one is an
340
- // unobserve + observe — which a real IntersectionObserver answers with a
341
- // fresh notification, whose state update re-renders, whose commit
342
- // re-observes: a render loop on an idle page.
343
- const registerSlot = useCallback((el: HTMLDivElement) => {
344
- const page = Number(el.dataset.page);
345
- slotRefs.current.set(page, el);
346
- observerRef.current?.observe(el);
347
- onscreenRef.current?.observe(el);
348
- return () => {
349
- observerRef.current?.unobserve(el);
350
- onscreenRef.current?.unobserve(el);
351
- slotRefs.current.delete(page);
352
- };
353
- }, []);
354
-
355
- /** Keeps the current page's rectangle in view as the reader scrolls. */
356
- const currentTickRef = useRef<HTMLButtonElement>(null);
357
-
358
- const scrollToPage = useCallback(
359
- (page: number) => {
360
- scrollWithin(
361
- ownsScrollport ? scrollportRef.current : null,
362
- slotRefs.current.get(page) ?? null,
363
- 'start',
364
- );
365
- },
366
- [ownsScrollport],
367
- );
368
-
369
- // In the column the reader decides which page they are on by scrolling, so
370
- // the indicator reports rather than controls: the topmost page actually ON
371
- // SCREEN. NOT `visiblePages` — that set is deliberately widened by
372
- // PRELOAD_MARGIN to mount pages before they are reached, so reading it here
373
- // would name a page still a viewport away.
374
- const currentPage =
375
- pageLayout === 'scroll'
376
- ? onscreenPages.size > 0
377
- ? Math.min(...onscreenPages)
378
- : 1
379
- : pageNumber;
380
-
381
- /**
382
- * Left/Right step pages.
383
- *
384
- * Bound to the window rather than a focusable wrapper so it works without
385
- * the reader hunting for the viewer's focus — but that reach is exactly why
386
- * the guards matter more than the feature: a viewer that eats arrow keys
387
- * while someone is editing an annotation body, or mid-drag, is worse than
388
- * one with no shortcut at all.
389
- */
390
- useEffect(() => {
391
- if (numPages === 0) return;
392
- const BACK = ['ArrowLeft', 'PageUp'];
393
- const FORWARD = ['ArrowRight', 'PageDown'];
394
- const onKeyDown = (e: KeyboardEvent) => {
395
- // PageUp/PageDown jump a page; Left/Right do too, because they have no
396
- // native meaning in a vertical layout so taking them costs nothing.
397
- //
398
- // Up/Down are deliberately NOT here. They are the scroller's fine
399
- // movement, and a page can be taller than the viewport — taking them
400
- // would leave no keyboard way to reach the bottom of one. This is the
401
- // split Preview, Chrome's PDF viewer and Acrobat all use.
402
- if (!BACK.includes(e.key) && !FORWARD.includes(e.key)) return;
403
- if (e.metaKey || e.ctrlKey || e.altKey) return; // browser/OS navigation
404
- const el = e.target as HTMLElement | null;
405
- const tag = el?.tagName;
406
- if (
407
- tag === 'INPUT' ||
408
- tag === 'TEXTAREA' ||
409
- tag === 'SELECT' ||
410
- el?.isContentEditable
411
- )
412
- return;
413
-
414
- const next = FORWARD.includes(e.key) ? currentPage + 1 : currentPage - 1;
415
- if (next < 1 || next > numPages) return;
416
- e.preventDefault();
417
- if (pageLayout === 'scroll') scrollToPage(next);
418
- else setPageNumber(next);
419
- };
420
- window.addEventListener('keydown', onKeyDown);
421
- return () => window.removeEventListener('keydown', onKeyDown);
422
- }, [numPages, currentPage, pageLayout, scrollToPage]);
423
-
424
- const stripRef = useRef<HTMLDivElement>(null);
425
-
426
- // The rail scrolls inside the PDF viewer's own scrollport. Size it to that
427
- // explicit viewport rather than searching host ancestors or assuming 100vh.
428
- useEffect(() => {
429
- const strip = stripRef.current;
430
- const clip = scrollportRef.current;
431
- if (pageLayout !== 'scroll' || !ownsScrollport || !strip || !clip) return;
432
- const size = () => {
433
- strip.style.maxHeight = `${clip.clientHeight}px`;
434
- };
435
- size();
436
- let observer: ResizeObserver | null = null;
437
- try {
438
- observer = new ResizeObserver(size);
439
- observer.observe(clip);
440
- } catch {
441
- window.addEventListener('resize', size);
442
- }
443
- return () => {
444
- if (observer) observer.disconnect();
445
- else window.removeEventListener('resize', size);
446
- };
447
- }, [ownsScrollport, pageLayout, numPages, pageShape]);
448
-
449
- useEffect(() => {
450
- // `nearest` so following the reader never yanks the strip around; it
451
- // scrolls only when the current rectangle would otherwise leave view.
452
- scrollWithin(stripRef.current, currentTickRef.current, 'nearest');
453
-
454
- // Move focus with the current page, but ONLY when the strip already owns
455
- // focus. Otherwise a clicked rectangle keeps focus while the current-page
456
- // marker moves on, and the focus ring — which appears as soon as the
457
- // reader touches an arrow key and the browser switches to keyboard
458
- // modality — sits on a page that is no longer current: two rectangles
459
- // claiming to be "here". Guarding on ownership means scrolling with the
460
- // mouse never snatches focus from whatever the reader was doing.
461
- const active =
462
- typeof document !== 'undefined' ? document.activeElement : null;
463
- if (
464
- active &&
465
- stripRef.current?.contains(active) &&
466
- active !== currentTickRef.current
467
- ) {
468
- currentTickRef.current?.focus();
469
- }
470
- }, [currentPage]);
471
-
472
- const pageProps = {
473
- scale,
474
- zoom,
475
- resourceUri,
476
- existingAnnotations,
477
- drawing,
478
- selectedMotivation,
479
- session,
480
- hoveredAnnotationId,
481
- selectedAnnotationId,
482
- hoverDelayMs,
483
- };
484
-
485
- if (errorKey) {
486
- return (
487
- <div className="xynolog-pdf-annotation-canvas__error">{t(errorKey)}</div>
488
- );
489
- }
490
-
491
- return (
492
- <div
493
- ref={scrollportRef}
494
- className="xynolog-pdf-annotation-canvas"
495
- data-page-layout={pageLayout}
496
- data-resource-scrollport={
497
- pageLayout === 'scroll' && ownsScrollport ? '' : undefined
498
- }
499
- data-annotate-deferred={anchoredText.status === 'held' ? 'false' : 'true'}
500
- >
501
- {isLoading && (
502
- <div className="xynolog-pdf-annotation-canvas__loading">
503
- {t('loading')}
504
- </div>
505
- )}
506
- <AnchoredTextNotice status={anchoredText.status} />
507
-
508
- {pdfDoc && pageLayout === 'scroll' ? (
509
- <div
510
- className="xynolog-pdf-annotation-canvas__viewport"
511
- data-axis={SCROLL_AXIS}
512
- >
513
- {numPages > 0 && pageShape && (
514
- <div
515
- className="xynolog-pdf-annotation-canvas__strip"
516
- data-axis={SCROLL_AXIS}
517
- data-scroller="true"
518
- aria-orientation={SCROLL_AXIS}
519
- ref={stripRef}
520
- >
521
- {Array.from({ length: numPages }, (_, i) => i + 1).map((page) => (
522
- <button
523
- key={page}
524
- type="button"
525
- data-page={page}
526
- className="xynolog-pdf-annotation-canvas__strip-page"
527
- style={{
528
- height: `${Math.round(STRIP_PAGE_WIDTH * pageShape.aspect)}px`,
529
- }}
530
- aria-label={t('pageOf', { page, total: numPages })}
531
- tabIndex={page === currentPage ? 0 : -1}
532
- {...(page === currentPage
533
- ? { 'aria-current': 'page' as const }
534
- : {})}
535
- ref={page === currentPage ? currentTickRef : undefined}
536
- onClick={() => scrollToPage(page)}
537
- >
538
- {page}
539
- </button>
540
- ))}
541
- </div>
542
- )}
543
- <div
544
- className="xynolog-pdf-annotation-canvas__column"
545
- data-axis={SCROLL_AXIS}
546
- ref={columnRef}
547
- style={{ zoom }}
548
- >
549
- {Array.from({ length: numPages }, (_, i) => i + 1).map((page) => (
550
- <div
551
- key={page}
552
- ref={registerSlot}
553
- data-page={page}
554
- className="xynolog-pdf-annotation-canvas__slot"
555
- // min-height, and applied whether or not the page is mounted:
556
- // releasing it on mount would make the scrollbar jump. `min`
557
- // rather than a fixed height so a page that renders slightly
558
- // taller expands instead of clipping.
559
- style={slotHeight ? { minHeight: slotHeight } : undefined}
560
- >
561
- {visiblePages.has(page) && (
562
- <PdfPageView doc={pdfDoc} pageNumber={page} {...pageProps} />
563
- )}
564
- </div>
565
- ))}
566
- </div>
567
- </div>
568
- ) : (
569
- pdfDoc &&
570
- !isLoading && (
571
- // `key` is load-bearing: without it React reuses this instance
572
- // across page changes, so the previous page's raster and load error
573
- // survive into the next page — a stale overlay, a rectangle drawn
574
- // over one page and recorded against another, and an error that
575
- // never clears. Each page is a different thing; mounting it as one
576
- // resets all of it.
577
- <div style={{ zoom }}>
578
- <PdfPageView
579
- key={pageNumber}
580
- doc={pdfDoc}
581
- pageNumber={pageNumber}
582
- {...pageProps}
583
- />
584
- </div>
585
- )
586
- )}
587
-
588
- {/* Page navigation controls */}
589
- {numPages > 0 && (
590
- <nav
591
- className="xynolog-pdf-annotation-canvas__controls"
592
- aria-label={t('pagination')}
593
- >
594
- <button
595
- disabled={currentPage <= 1}
596
- onClick={() =>
597
- pageLayout === 'scroll'
598
- ? scrollToPage(currentPage - 1)
599
- : setPageNumber(pageNumber - 1)
600
- }
601
- className="xynolog-pdf-annotation-canvas__button"
602
- >
603
- {t('previous')}
604
- </button>
605
- {/*
606
- aria-live: the page number is the only feedback a page change gives,
607
- and in the scrolling column it changes without any control being
608
- activated at all — so a screen-reader user who scrolls would
609
- otherwise get silence.
610
- */}
611
- <span
612
- className="xynolog-pdf-annotation-canvas__page-info"
613
- aria-live="polite"
614
- >
615
- {t('pageOf', { page: currentPage, total: numPages })}
616
- </span>
617
- <button
618
- disabled={currentPage >= numPages}
619
- onClick={() =>
620
- pageLayout === 'scroll'
621
- ? scrollToPage(currentPage + 1)
622
- : setPageNumber(pageNumber + 1)
623
- }
624
- className="xynolog-pdf-annotation-canvas__button"
625
- >
626
- {t('next')}
627
- </button>
628
- </nav>
629
- )}
630
- </div>
631
- );
632
- }