@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,61 +0,0 @@
1
- /**
2
- * The slot-height estimate of the PDF viewer's scroll column.
3
- *
4
- * The scroll column reserves space for unmounted pages. If the reservation is
5
- * wrong, every mount and unmount changes the column's height and the scrollbar
6
- * jumps — which is what the column first shipped, by reserving the raster
7
- * height rather than the displayed one.
8
- *
9
- * These pins hold the estimate to the CSS the image is actually under:
10
- * `max-width: 100%; height: auto`.
11
- */
12
- import { describe, it, expect } from 'vitest';
13
- import { estimateSlotHeight } from '../estimate-slot-height';
14
-
15
- // US Letter at scale 1.5: 918 × 1188 raster, aspect 792/612.
16
- const ASPECT = 792 / 612;
17
- const RASTER_W = 918;
18
-
19
- describe('estimateSlotHeight', () => {
20
- it('scales to the column when the column is narrower than the raster', () => {
21
- // The common case: `max-width: 100%` shrinks the image to the column.
22
- expect(estimateSlotHeight(600, RASTER_W, ASPECT)).toBe(
23
- Math.round(600 * ASPECT),
24
- );
25
- });
26
-
27
- it('never upscales past the raster — max-width shrinks only', () => {
28
- // A column wider than the raster leaves the image at natural size, so the
29
- // height stops growing. Reserving columnWidth * aspect here would over-
30
- // reserve and leave a gap under every page.
31
- expect(estimateSlotHeight(1600, RASTER_W, ASPECT)).toBe(
32
- Math.round(RASTER_W * ASPECT),
33
- );
34
- });
35
-
36
- it('is exactly the raster height when the column matches the raster', () => {
37
- expect(estimateSlotHeight(RASTER_W, RASTER_W, ASPECT)).toBe(
38
- Math.round(RASTER_W * ASPECT),
39
- );
40
- });
41
-
42
- it('does NOT use the raster height as a width-independent constant', () => {
43
- // The original defect, stated as a pin: the raster is 1188px tall, but in a
44
- // 600px column the page occupies ~776px. Reserving 1188 is what made the
45
- // column's height lurch on every mount.
46
- const rasterHeight = Math.round(RASTER_W * ASPECT); // 1188
47
- expect(estimateSlotHeight(600, RASTER_W, ASPECT)).not.toBe(rasterHeight);
48
- expect(estimateSlotHeight(600, RASTER_W, ASPECT)).toBeLessThan(
49
- rasterHeight,
50
- );
51
- });
52
-
53
- it('answers null until every measurement is in, rather than guessing', () => {
54
- // A wrong reservation is worse than none: an unsized slot is stable, a
55
- // mis-sized one moves when the page lands.
56
- expect(estimateSlotHeight(null, RASTER_W, ASPECT)).toBeNull();
57
- expect(estimateSlotHeight(600, null, ASPECT)).toBeNull();
58
- expect(estimateSlotHeight(600, RASTER_W, null)).toBeNull();
59
- expect(estimateSlotHeight(0, RASTER_W, ASPECT)).toBeNull();
60
- });
61
- });
@@ -1,110 +0,0 @@
1
- /**
2
- * rectsForPage axioms — the pure partition that distributes an annotation's
3
- * FragmentSelectors into per-page rects. Geometry (each coord → canvas pixels) is
4
- * covered separately by the pdf-coordinates transform axioms + the core codec axioms.
5
- *
6
- * The producer of multi-selector PDF annotations is AI detection (one
7
- * FragmentSelector per line); these synthetic fixtures stand in for it.
8
- */
9
- import { describe, it, expect } from 'vitest';
10
- import * as fc from 'fast-check';
11
- import { annotationId, resourceId, type Annotation } from '@xynolog/core';
12
- import { rectsForPage } from '../rects-for-page';
13
-
14
- const PAGES = 5;
15
-
16
- type Sel = { page: number; x: number; y: number; w: number; h: number };
17
-
18
- const selArb: fc.Arbitrary<Sel> = fc.record({
19
- page: fc.integer({ min: 1, max: PAGES }),
20
- x: fc.integer({ min: 0, max: 800 }),
21
- y: fc.integer({ min: 0, max: 800 }),
22
- w: fc.integer({ min: 1, max: 200 }),
23
- h: fc.integer({ min: 1, max: 60 }),
24
- });
25
- // A "document" is a list of annotations, each a list of 0..4 selectors.
26
- const docArb = fc.array(fc.array(selArb, { maxLength: 4 }), { maxLength: 6 });
27
-
28
- function build(doc: ReadonlyArray<ReadonlyArray<Sel>>): Annotation[] {
29
- return doc.map((sels, i): Annotation => ({
30
- '@context': 'http://www.w3.org/ns/anno.jsonld',
31
- type: 'Annotation',
32
- id: annotationId(`ann-${i}`),
33
- target: {
34
- source: resourceId('res-1'),
35
- selector: sels.map((s) => ({
36
- type: 'FragmentSelector' as const,
37
- value: `page=${s.page}&viewrect=${s.x},${s.y},${s.w},${s.h}`,
38
- conformsTo: 'http://tools.ietf.org/rfc/rfc3778',
39
- })),
40
- },
41
- motivation: 'highlighting',
42
- created: '2026-01-01T00:00:00.000Z',
43
- }));
44
- }
45
-
46
- const keysOn = (anns: Annotation[], page: number): string[] =>
47
- rectsForPage(anns, page).map((r) => `${r.annId}:${r.selectorIndex}`);
48
-
49
- describe('rectsForPage (multi-rect partition)', () => {
50
- it('completeness: every FragmentSelector renders exactly once across all pages', () => {
51
- fc.assert(
52
- fc.property(docArb, (doc) => {
53
- const anns = build(doc);
54
- const total = doc.reduce((n, sels) => n + sels.length, 0);
55
- let rendered = 0;
56
- for (let p = 1; p <= PAGES; p++)
57
- rendered += rectsForPage(anns, p).length;
58
- expect(rendered).toBe(total);
59
- }),
60
- );
61
- });
62
-
63
- it('page-locality: every rect on page p came from a selector with page === p', () => {
64
- fc.assert(
65
- fc.property(docArb, fc.integer({ min: 1, max: PAGES }), (doc, p) => {
66
- for (const r of rectsForPage(build(doc), p))
67
- expect(r.coord.page).toBe(p);
68
- }),
69
- );
70
- });
71
-
72
- it('key uniqueness: `${annId}:${selectorIndex}` is pairwise unique on any page', () => {
73
- fc.assert(
74
- fc.property(docArb, fc.integer({ min: 1, max: PAGES }), (doc, p) => {
75
- const keys = keysOn(build(doc), p);
76
- expect(new Set(keys).size).toBe(keys.length);
77
- }),
78
- );
79
- });
80
-
81
- it('order independence: reversing the annotation list preserves the rendered set per page', () => {
82
- fc.assert(
83
- fc.property(docArb, fc.integer({ min: 1, max: PAGES }), (doc, p) => {
84
- const anns = build(doc);
85
- expect([...keysOn([...anns].reverse(), p)].sort()).toEqual(
86
- [...keysOn(anns, p)].sort(),
87
- );
88
- }),
89
- );
90
- });
91
-
92
- it('single-selector invariance: a manual (one-selector) annotation → exactly one rect on its page', () => {
93
- const anns = build([[{ page: 2, x: 72, y: 720, w: 150, h: 12 }]]);
94
- const onPage2 = rectsForPage(anns, 2);
95
- expect(onPage2).toHaveLength(1);
96
- expect(onPage2[0].selectorIndex).toBe(0);
97
- expect(rectsForPage(anns, 1)).toHaveLength(0);
98
- });
99
-
100
- it('multi-line: a 3-selector annotation on one page → 3 distinctly-keyed rects', () => {
101
- const anns = build([
102
- [
103
- { page: 2, x: 72, y: 720, w: 150, h: 12 },
104
- { page: 2, x: 72, y: 700, w: 140, h: 12 },
105
- { page: 2, x: 72, y: 680, w: 90, h: 12 },
106
- ],
107
- ]);
108
- expect(keysOn(anns, 2)).toEqual(['ann-0:0', 'ann-0:1', 'ann-0:2']);
109
- });
110
- });
@@ -1,31 +0,0 @@
1
- /**
2
- * The height a page will occupy once rendered, computed BEFORE rendering it.
3
- *
4
- * The scrolling column reserves space for pages it has not mounted. If the
5
- * reserved height differs from the height the page actually takes, every mount
6
- * and unmount changes the column's total height and the scrollbar jumps under
7
- * the reader's cursor — the defect S1 shipped by reserving the *raster* height
8
- * (`getViewport({ scale }).height`) instead of the *displayed* one.
9
- *
10
- * This models the CSS the image is under exactly:
11
- *
12
- * .xynolog-pdf-annotation-canvas__image { max-width: 100%; height: auto; }
13
- *
14
- * `max-width` shrinks but never upscales, so the displayed width is
15
- * `min(columnWidth, rasterWidth)` and the height follows the page's aspect
16
- * ratio. Aspect is scale-invariant, so it can come from any viewport.
17
- *
18
- * @param columnWidth Measured inner width of the scroll column, in CSS px.
19
- * @param rasterWidth Width of the rendered raster, in px (`viewport(scale).width`).
20
- * @param aspect Page height ÷ width, from any viewport scale.
21
- * @returns Reserved height in CSS px, or null when a measurement is not in yet.
22
- */
23
- export function estimateSlotHeight(
24
- columnWidth: number | null,
25
- rasterWidth: number | null,
26
- aspect: number | null,
27
- ): number | null {
28
- if (!columnWidth || !rasterWidth || !aspect) return null;
29
- if (columnWidth <= 0 || rasterWidth <= 0 || aspect <= 0) return null;
30
- return Math.round(Math.min(columnWidth, rasterWidth) * aspect);
31
- }
@@ -1,50 +0,0 @@
1
- import type { Annotation, PdfCoordinate } from '@xynolog/core';
2
- import { getTargetSelector, parseFragmentSelector } from '@xynolog/core';
3
-
4
- /** One FragmentSelector rectangle to paint on a PDF page. */
5
- export interface PageRect {
6
- /** Owning annotation id — shared by every rect of a multi-line annotation (hover/click routing). */
7
- annId: Annotation['id'];
8
- /** Index within the annotation's FragmentSelectors — the stable half of the React key. */
9
- selectorIndex: number;
10
- /** PDF-point geometry for this rect. */
11
- coord: PdfCoordinate;
12
- /** Owning annotation (motivation colour, etc.). */
13
- annotation: Annotation;
14
- }
15
-
16
- /** Every FragmentSelector on a target, in order (`target.selector` may be one or an array). */
17
- function fragmentSelectors(target: Annotation['target']): { value: string }[] {
18
- const selector = getTargetSelector(target);
19
- if (!selector) return [];
20
- const selectors = Array.isArray(selector) ? selector : [selector];
21
- return selectors
22
- .filter((s) => s.type === 'FragmentSelector')
23
- .map((s) => s as { type: 'FragmentSelector'; value: string });
24
- }
25
-
26
- /**
27
- * The rectangles to paint on `pageNumber`: one entry per FragmentSelector whose
28
- * viewrect page matches. A multi-line (multi-selector) annotation therefore yields
29
- * one rect per line; a single-selector (manual) annotation yields exactly one.
30
- *
31
- * Pure — no React/DOM. `PdfAnnotationCanvas` maps this to `<rect>` keyed
32
- * `${annId}:${selectorIndex}`, and the rects-for-page axioms exercise it directly.
33
- * Geometry stays deferred: each `coord` still goes through `pdfToCanvasCoordinates`
34
- * at paint time (itself covered by the coordinate-transform axioms).
35
- */
36
- export function rectsForPage(
37
- annotations: Annotation[],
38
- pageNumber: number,
39
- ): PageRect[] {
40
- const rects: PageRect[] = [];
41
- for (const annotation of annotations) {
42
- fragmentSelectors(annotation.target).forEach((sel, selectorIndex) => {
43
- const coord = parseFragmentSelector(sel.value);
44
- if (coord && coord.page === pageNumber) {
45
- rects.push({ annId: annotation.id, selectorIndex, coord, annotation });
46
- }
47
- });
48
- }
49
- return rects;
50
- }
@@ -1,373 +0,0 @@
1
- 'use client';
2
-
3
- import type { EventMap, ResourceId } from '@xynolog/core';
4
- import { useRef, useEffect, useCallback, useMemo } from 'react';
5
- import { capabilitiesOf, textOffsets } from '@xynolog/core';
6
- import { ANNOTATORS } from '../../lib/annotation-registry';
7
- import { documentPositions } from '../../lib/codemirror-logic';
8
- import {
9
- buildTextSelectors,
10
- fallbackTextPosition,
11
- } from '../../lib/text-selection-handler';
12
- import {
13
- defaultAnnotateRenderers,
14
- type AnnotateMediaRenderers,
15
- } from './annotate-renderers';
16
- import { DownloadFileLink } from './DownloadFileLink';
17
- import {
18
- TranslationProvider,
19
- type TranslationSource,
20
- } from '../../contexts/TranslationContext';
21
- import { translationSourceOf } from '../../lib/translation-source';
22
- import { EditorView } from '@codemirror/view';
23
- import { HOVER_DELAY_MS, type XynologSession } from '@xynolog/sdk';
24
- import { useSessionEventSubscriptions } from '../../hooks/useSessionEventSubscriptions';
25
- import { scrollAnnotationIntoView } from '../../lib/scroll-utils';
26
- import {
27
- AnnotateToolbar,
28
- type ClickAction,
29
- type ShapeType,
30
- } from '../annotation/AnnotateToolbar';
31
- import type { Motivation } from '@xynolog/core';
32
- import type {
33
- AnnotationsCollection,
34
- AnnotationUIState,
35
- } from '../../types/annotation-props';
36
-
37
- // Re-export for convenience
38
- export type { ClickAction, ShapeType };
39
-
40
- interface Props {
41
- content: string;
42
- mimeType?: string;
43
- /** The '@id' of the shown resource — stamped as `source` on mark:requested (multi-viewer routing). */
44
- resourceUri: ResourceId;
45
- annotations: AnnotationsCollection;
46
- /** Zoom the rendered resource content, leaving the annotation toolbar at its normal size. */
47
- zoom?: number;
48
- uiState: AnnotationUIState;
49
- onUIStateChange?: (state: Partial<AnnotationUIState>) => void;
50
- editable?: boolean;
51
- enableWidgets?: boolean;
52
- getTargetResourceName?: (resourceId: string) => string | undefined;
53
- generatingReferenceId?: string | null;
54
- showLineNumbers?: boolean;
55
- hoverDelayMs?: number;
56
- annotateMode: boolean;
57
- /** Session for the shown resource — its client emits mark:* / mark.request; its bus feeds toolbar + beckon events. */
58
- session: XynologSession | null;
59
- /** Recently-created annotation ids to sparkle (host-provided). */
60
- sparkleAnnotationIds?: Set<string>;
61
- /** The bar's Mode control reports the chosen mode here (the owner applies it). */
62
- onModeChange?: (mode: boolean) => void;
63
- /** Render the built-in bar (default). false → no bar; selection capture and drawing stay live. */
64
- showToolbar?: boolean;
65
- /** Override the annotating media renderers (render mode → renderer); merged over the defaults. */
66
- renderers?: AnnotateMediaRenderers;
67
- }
68
-
69
- /**
70
- * The annotating view, given its language: it mounts the translation provider
71
- * its subtree reads. Inside `ResourceViewer` it is handed the viewer's own.
72
- */
73
- export function AnnotateView(props: Props & TranslationSource) {
74
- return (
75
- <TranslationProvider {...translationSourceOf(props)}>
76
- <AnnotateViewBody {...props} />
77
- </TranslationProvider>
78
- );
79
- }
80
-
81
- /**
82
- * View component for annotating resources with text selection and drawing
83
- *
84
- * @emits mark:requested - User requested to create annotation. Payload: { source: ResourceId, selector: Selector | Selector[], motivation: Motivation }
85
- * @subscribes beckon:hover - Annotation hovered. Payload: { annotationId: string | null }
86
- * @subscribes beckon:focus - Scroll to and highlight the annotation, or to the top when it names none, unless `resourceId` names a different resource. Payload: { resourceId: string, annotationId?: string }
87
- */
88
- function AnnotateViewBody({
89
- content,
90
- mimeType = 'text/plain',
91
- zoom = 1,
92
- resourceUri,
93
- annotations,
94
- uiState,
95
- onUIStateChange,
96
- enableWidgets = false,
97
- getTargetResourceName,
98
- generatingReferenceId,
99
- showLineNumbers = false,
100
- hoverDelayMs = HOVER_DELAY_MS,
101
- annotateMode,
102
- session,
103
- sparkleAnnotationIds,
104
- onModeChange,
105
- showToolbar = true,
106
- renderers,
107
- }: Props) {
108
- const containerRef = useRef<HTMLDivElement>(null);
109
- const contentRef = useRef<HTMLDivElement>(null);
110
-
111
- const render = capabilitiesOf(mimeType)?.render ?? 'none';
112
-
113
- // The content's conversions, made once for a content: an offset counts its
114
- // code points, and a selection is found at a position in the editor's
115
- // document, which counts UTF-16 code units and each line break as one.
116
- const offsets = useMemo(() => textOffsets(content), [content]);
117
- const positions = useMemo(
118
- () => documentPositions(content, offsets),
119
- [content, offsets],
120
- );
121
-
122
- const { highlights, references, assessments, comments, tags } = annotations;
123
-
124
- const allAnnotations = [
125
- ...highlights,
126
- ...references,
127
- ...assessments,
128
- ...comments,
129
- ...tags,
130
- ];
131
-
132
- // Extract UI state
133
- const {
134
- selectedMotivation,
135
- selectedClick,
136
- selectedShape,
137
- hoveredAnnotationId,
138
- scrollToAnnotationId,
139
- } = uiState;
140
-
141
- // Store onUIStateChange in ref to avoid dependency issues
142
- const onUIStateChangeRef = useRef(onUIStateChange);
143
- onUIStateChangeRef.current = onUIStateChange;
144
-
145
- // Toolbar callbacks: the presentational bar reports chosen values; route them up
146
- // through the existing onUIStateChange path (the owner applies them).
147
- const handleToolbarSelectionChange = useCallback(
148
- (motivation: Motivation | null) => {
149
- onUIStateChangeRef.current?.({ selectedMotivation: motivation });
150
- },
151
- [],
152
- );
153
-
154
- const handleToolbarClickActionChange = useCallback((action: ClickAction) => {
155
- onUIStateChangeRef.current?.({ selectedClick: action });
156
- }, []);
157
-
158
- const handleToolbarShapeChange = useCallback((shape: ShapeType) => {
159
- onUIStateChangeRef.current?.({ selectedShape: shape });
160
- }, []);
161
-
162
- const handleAnnotationHover = useCallback(
163
- ({ annotationId }: { annotationId: string | null }) => {
164
- onUIStateChangeRef.current?.({ hoveredAnnotationId: annotationId });
165
- },
166
- [],
167
- );
168
-
169
- // "Scroll to and highlight this annotation" — the same contract BrowseView
170
- // serves, so the behaviour does not depend on which view mode is active.
171
- // The `scrollToAnnotationId` prop path (uiState → renderer) stays as the
172
- // host-facing capability it is; this is the in-app producer's route.
173
- // A focus on another resource is not this view's: one on an annotation
174
- // there is ignored, and one on the resource alone is the host's to bring
175
- // forward. A focus on this resource and no annotation scrolls to its top.
176
- const handleFocus = useCallback(
177
- ({ annotationId, resourceId }: EventMap['beckon:focus']) => {
178
- if (resourceId !== resourceUri) return;
179
- if (annotationId === undefined) {
180
- if (!contentRef.current) return;
181
- contentRef.current.scrollTo({ top: 0, behavior: 'smooth' });
182
- return;
183
- }
184
- if (!containerRef.current) return;
185
- scrollAnnotationIntoView(annotationId, containerRef.current, {
186
- pulse: true,
187
- });
188
- },
189
- [resourceUri],
190
- );
191
-
192
- // Annotation hover (session-scoped). Toolbar preference changes flow through
193
- // props/callbacks, not the bus.
194
- useSessionEventSubscriptions(session, {
195
- 'beckon:hover': handleAnnotationHover,
196
- 'beckon:focus': handleFocus,
197
- });
198
-
199
- // Handle text annotation with sparkle or immediate creation
200
- useEffect(() => {
201
- const container = containerRef.current;
202
- if (!container) return;
203
-
204
- let clickedOnAnnotation = false;
205
-
206
- const handleMouseDown = (e: MouseEvent) => {
207
- // Check if mousedown was on an existing annotation
208
- const target = e.target as Element;
209
- clickedOnAnnotation = !!target.closest('[data-annotation-id]');
210
- };
211
-
212
- const handleMouseUp = (e: MouseEvent) => {
213
- // Skip if the mouseUp came from PDF or image canvas
214
- // (those components handle their own mark:requested events)
215
- const target = e.target as Element;
216
- if (
217
- target.closest('.xynolog-pdf-annotation-canvas') ||
218
- target.closest('.xynolog-svg-drawing-canvas')
219
- ) {
220
- return;
221
- }
222
-
223
- const selection = window.getSelection();
224
- if (!selection || selection.isCollapsed || !selection.toString()) {
225
- clickedOnAnnotation = false;
226
- return;
227
- }
228
-
229
- // If mousedown was on an existing annotation, don't trigger creation
230
- // The annotation's click handler will take care of it
231
- if (clickedOnAnnotation) {
232
- clickedOnAnnotation = false;
233
- return;
234
- }
235
- clickedOnAnnotation = false;
236
-
237
- if (!selectedMotivation) return;
238
-
239
- const range = selection.getRangeAt(0);
240
- const view = EditorView.findFromDOM(container);
241
-
242
- let selected: { start: number; end: number } | null;
243
-
244
- if (view) {
245
- // A selection that begins or ends outside the editor's text is not a
246
- // selection of the content.
247
- if (
248
- !view.contentDOM.contains(range.startContainer) ||
249
- !view.contentDOM.contains(range.endContainer)
250
- )
251
- return;
252
- // CodeMirror's posAtDOM gives the position in its document of a DOM
253
- // node/offset; both ends are asked, since the selection's own string
254
- // is not the content's text between them (a line break of the
255
- // document is the content's CRLF, and a widget's text is not content).
256
- selected = {
257
- start: positions.offsetAt(
258
- view.posAtDOM(range.startContainer, range.startOffset),
259
- ),
260
- end: positions.offsetAt(
261
- view.posAtDOM(range.endContainer, range.endOffset),
262
- ),
263
- };
264
- } else {
265
- // No editor (a host's own text renderer): where the content first has
266
- // the selected text. For text the content has more than once, that
267
- // may not be the place selected.
268
- selected = fallbackTextPosition(content, offsets, selection.toString());
269
- }
270
-
271
- if (!selected) return;
272
-
273
- const selectors = buildTextSelectors(
274
- content,
275
- offsets,
276
- selected.start,
277
- selected.end,
278
- );
279
- if (!selectors) return;
280
-
281
- session?.client.mark.request(resourceUri, selectors, selectedMotivation);
282
-
283
- // Clear selection after creating annotation
284
- selection.removeAllRanges();
285
- };
286
-
287
- container.addEventListener('mouseup', handleMouseUp);
288
- container.addEventListener('mousedown', handleMouseDown);
289
-
290
- return () => {
291
- container.removeEventListener('mouseup', handleMouseUp);
292
- container.removeEventListener('mousedown', handleMouseDown);
293
- };
294
- }, [selectedMotivation, content, offsets, positions, resourceUri]);
295
-
296
- // One shell for every render mode; the registry supplies the content.
297
- // A `switch` per mode would repeat this wrapper, the toolbar block and the
298
- // content div in each branch, so any toolbar prop change would have to be
299
- // made in every one and stay correct only by vigilance.
300
- const mediaRenderers: AnnotateMediaRenderers = {
301
- ...defaultAnnotateRenderers,
302
- ...renderers,
303
- };
304
- const Renderer = mediaRenderers[render];
305
-
306
- // A mode with no renderer, in neither the defaults nor the override,
307
- // gets no annotating surface. That is every type with no preview and every
308
- // registry miss — both read as 'none' above — and the browse side answers
309
- // them the same way, with its own no-preview fallback. Annotating a type
310
- // nothing here can render is not harmless, so the toolbar is deliberately
311
- // absent in this branch.
312
- if (!Renderer) {
313
- return (
314
- <div
315
- ref={containerRef}
316
- className="xynolog-annotate-view xynolog-annotate-view--unsupported"
317
- data-mime-type="unsupported"
318
- >
319
- <div className="xynolog-annotate-view__empty">
320
- <p className="xynolog-annotate-view__empty-message">
321
- Annotation not supported for {mimeType}
322
- </p>
323
- <DownloadFileLink resourceUri={resourceUri} session={session} />
324
- </div>
325
- </div>
326
- );
327
- }
328
-
329
- return (
330
- <div
331
- className="xynolog-annotate-view"
332
- data-mime-type={render}
333
- ref={containerRef}
334
- >
335
- {showToolbar && (
336
- <AnnotateToolbar
337
- selectedMotivation={selectedMotivation}
338
- selectedClick={selectedClick}
339
- selectedShape={selectedShape}
340
- mediaType={mimeType}
341
- annotateMode={annotateMode}
342
- annotators={ANNOTATORS}
343
- onModeChange={onModeChange}
344
- onClickActionChange={handleToolbarClickActionChange}
345
- onSelectionChange={handleToolbarSelectionChange}
346
- onShapeChange={handleToolbarShapeChange}
347
- />
348
- )}
349
- <div className="xynolog-annotate-view__content" ref={contentRef}>
350
- <div style={render === 'pdf' ? undefined : { zoom }}>
351
- <Renderer
352
- content={content}
353
- mimeType={mimeType}
354
- zoom={zoom}
355
- resourceUri={resourceUri}
356
- annotations={allAnnotations}
357
- session={session}
358
- drawingMode={selectedMotivation ? selectedShape : null}
359
- selectedMotivation={selectedMotivation}
360
- hoveredAnnotationId={hoveredAnnotationId}
361
- hoverDelayMs={hoverDelayMs}
362
- sparkleAnnotationIds={sparkleAnnotationIds}
363
- scrollToAnnotationId={scrollToAnnotationId}
364
- showLineNumbers={showLineNumbers}
365
- enableWidgets={enableWidgets}
366
- {...(getTargetResourceName && { getTargetResourceName })}
367
- generatingReferenceId={generatingReferenceId}
368
- />
369
- </div>
370
- </div>
371
- </div>
372
- );
373
- }