@xynolog/react-ui 0.0.0-stage → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +379 -2
- package/dist/PdfAnnotationCanvas.client-S64VRLUN.css +193 -0
- package/dist/PdfAnnotationCanvas.client-V7R4NXFO.js +799 -0
- package/dist/ar-AIV7P4FL.js +594 -0
- package/dist/bn-J2OR57PB.js +594 -0
- package/dist/chunk-4L3TYOIV.js +172 -0
- package/dist/chunk-BM76QBIO.js +594 -0
- package/dist/chunk-D2O46PZQ.js +240 -0
- package/dist/chunk-O23TLLXW.js +42 -0
- package/dist/chunk-WGTUIB6C.js +304 -0
- package/dist/cs-JNEAMHFB.js +594 -0
- package/dist/da-UY5ZRVTZ.js +594 -0
- package/dist/de-EETVXC42.js +594 -0
- package/dist/el-S5YKDMTL.js +594 -0
- package/dist/en-3YQWF45H.js +61 -0
- package/dist/es-GHA7S27R.js +594 -0
- package/dist/fa-JTR3GF6I.js +594 -0
- package/dist/fi-CQZ7BW57.js +594 -0
- package/dist/fr-OJH2WIY7.js +594 -0
- package/dist/he-2DBXWA2V.js +594 -0
- package/dist/hi-NZP7B55I.js +594 -0
- package/dist/id-4KXFKWOI.js +594 -0
- package/dist/index.css +4134 -0
- package/dist/index.d.ts +4040 -0
- package/dist/index.js +29638 -0
- package/dist/it-XBMYGKKY.js +594 -0
- package/dist/ja-OVHZS3EH.js +594 -0
- package/dist/ko-NW2MVM5L.js +594 -0
- package/dist/ms-RXLPBZLK.js +594 -0
- package/dist/nl-77CTBEDA.js +594 -0
- package/dist/no-RAPO56SE.js +594 -0
- package/dist/pl-XCFXZCTT.js +594 -0
- package/dist/pt-EMBE27IS.js +594 -0
- package/dist/ro-M7QLJBYN.js +594 -0
- package/dist/sv-ST6CITQY.js +594 -0
- package/dist/test-utils.css +112 -0
- package/dist/test-utils.d.ts +126 -0
- package/dist/test-utils.js +13119 -0
- package/dist/th-EEQGL3G7.js +594 -0
- package/dist/tr-5FYHZQKD.js +594 -0
- package/dist/uk-VTWDC467.js +594 -0
- package/dist/vi-ISBKJ66X.js +594 -0
- package/dist/zh-2AW2N66Z.js +594 -0
- package/package.json +129 -4
- package/src/components/Button/Button.tsx +188 -0
- package/src/components/Button/__tests__/Button.test.tsx +449 -0
- package/src/components/CodeMirrorRenderer.tsx +536 -0
- package/src/components/DelegateProgress.tsx +308 -0
- package/src/components/ErrorBoundary.tsx +174 -0
- package/src/components/ItemFoundLog.tsx +42 -0
- package/src/components/LiveRegion.tsx +261 -0
- package/src/components/ProtectedErrorBoundary.css +121 -0
- package/src/components/ProtectedErrorBoundary.tsx +114 -0
- package/src/components/ResizeHandle.tsx +167 -0
- package/src/components/ResourceTagsInline.tsx +120 -0
- package/src/components/SessionExpiryBanner.css +67 -0
- package/src/components/SessionExpiryBanner.tsx +74 -0
- package/src/components/SessionTimer.tsx +17 -0
- package/src/components/StatusDisplay.css +439 -0
- package/src/components/StatusDisplay.tsx +131 -0
- package/src/components/Toast.css +136 -0
- package/src/components/Toast.tsx +217 -0
- package/src/components/Toolbar.tsx +194 -0
- package/src/components/UserMenuSkeleton.tsx +13 -0
- package/src/components/__tests__/DelegateProgress.denominator.test.tsx +102 -0
- package/src/components/__tests__/DelegateProgress.test.tsx +649 -0
- package/src/components/__tests__/ErrorBoundary.test.tsx +565 -0
- package/src/components/__tests__/LiveRegion.a11y.test.tsx +258 -0
- package/src/components/__tests__/LiveRegion.hooks.test.tsx +140 -0
- package/src/components/__tests__/ProtectedErrorBoundary.test.tsx +225 -0
- package/src/components/__tests__/ResizeHandle.test.tsx +159 -0
- package/src/components/__tests__/ResourceTagsInline.test.tsx +325 -0
- package/src/components/__tests__/SessionExpiryBanner.test.tsx +124 -0
- package/src/components/__tests__/SessionTimer.test.tsx +199 -0
- package/src/components/__tests__/StatusDisplay.test.tsx +179 -0
- package/src/components/__tests__/Toast.test.tsx +96 -0
- package/src/components/__tests__/Toolbar.test.tsx +111 -0
- package/src/components/__tests__/UserMenuSkeleton.test.tsx +182 -0
- package/src/components/annotation/AnchoredTextNotice.tsx +36 -0
- package/src/components/annotation/AnnotateToolbar.tsx +531 -0
- package/src/components/annotation/__tests__/AnnotateToolbar.display.test.tsx +127 -0
- package/src/components/annotation/__tests__/AnnotateToolbar.test.tsx +304 -0
- package/src/components/annotation/annotation-entries.css +138 -0
- package/src/components/annotation/annotations.css +93 -0
- package/src/components/annotation/references.css +300 -0
- package/src/components/annotation-popups/JsonLdView.tsx +127 -0
- package/src/components/annotation-popups/SharedPopupElements.tsx +131 -0
- package/src/components/annotation-popups/__tests__/JsonLdView.test.tsx +432 -0
- package/src/components/annotation-popups/__tests__/SharedPopupElements.test.tsx +297 -0
- package/src/components/branding/Branding.css +129 -0
- package/src/components/branding/XynologBranding.tsx +41 -0
- package/src/components/branding/__tests__/XynologBranding.test.tsx +383 -0
- package/src/components/error-states/ResourceErrorState.tsx +30 -0
- package/src/components/error-states/__tests__/ResourceErrorState.test.tsx +102 -0
- package/src/components/error-states/errors.css +34 -0
- package/src/components/image-annotation/AnnotationOverlay.tsx +307 -0
- package/src/components/image-annotation/SvgDrawingCanvas.tsx +514 -0
- package/src/components/image-annotation/__tests__/AnnotationOverlay.click.test.tsx +169 -0
- package/src/components/image-annotation/__tests__/AnnotationOverlay.hover.test.tsx +83 -0
- package/src/components/image-annotation/__tests__/SvgDrawingCanvas.annotate-gate.test.tsx +228 -0
- package/src/components/image-annotation/__tests__/SvgDrawingCanvas.click.test.tsx +204 -0
- package/src/components/layout/Header.css +99 -0
- package/src/components/layout/LeftSidebar.css +115 -0
- package/src/components/layout/LeftSidebar.tsx +150 -0
- package/src/components/layout/PageLayout.tsx +49 -0
- package/src/components/layout/ResizeHandle.css +110 -0
- package/src/components/layout/SkipLinks.css +84 -0
- package/src/components/layout/SkipLinks.tsx +36 -0
- package/src/components/layout/UnifiedHeader.tsx +151 -0
- package/src/components/layout/__tests__/LeftSidebar.test.tsx +426 -0
- package/src/components/layout/__tests__/PageLayout.test.tsx +311 -0
- package/src/components/layout/__tests__/SkipLinks.a11y.test.tsx +218 -0
- package/src/components/layout/__tests__/UnifiedHeader.test.tsx +555 -0
- package/src/components/loading-states/ComposeLoadingState.tsx +19 -0
- package/src/components/loading-states/ResourceLoadingState.tsx +13 -0
- package/src/components/loading-states/__tests__/ComposeLoadingState.test.tsx +37 -0
- package/src/components/loading-states/__tests__/ResourceLoadingState.test.tsx +31 -0
- package/src/components/loading-states/loading.css +42 -0
- package/src/components/modals/ComposeStep.tsx +245 -0
- package/src/components/modals/ConfigureGatherStep.tsx +110 -0
- package/src/components/modals/ConfigureGenerationStep.tsx +458 -0
- package/src/components/modals/ConfigureSearchStep.tsx +124 -0
- package/src/components/modals/ContextSummary.tsx +317 -0
- package/src/components/modals/CorpusPane.tsx +96 -0
- package/src/components/modals/DiscardPrompt.tsx +44 -0
- package/src/components/modals/GatherContextStep.tsx +480 -0
- package/src/components/modals/KbIdentityConflictModal.tsx +122 -0
- package/src/components/modals/KeyboardShortcutsHelpModal.tsx +238 -0
- package/src/components/modals/PermissionDeniedModal.tsx +207 -0
- package/src/components/modals/ReferenceWizardModal.tsx +656 -0
- package/src/components/modals/ResourceGenerateModal.tsx +457 -0
- package/src/components/modals/SearchModal.css +1019 -0
- package/src/components/modals/SearchModal.tsx +334 -0
- package/src/components/modals/SearchResultsStep.tsx +117 -0
- package/src/components/modals/SessionEndedModal.tsx +148 -0
- package/src/components/modals/WizardFooter.tsx +72 -0
- package/src/components/modals/__tests__/ComposeStep.test.tsx +187 -0
- package/src/components/modals/__tests__/ConfigureGatherStep.test.tsx +92 -0
- package/src/components/modals/__tests__/ConfigureGenerationStep.test.tsx +574 -0
- package/src/components/modals/__tests__/ConfigureSearchStep.test.tsx +124 -0
- package/src/components/modals/__tests__/GatherContextStep.resource.test.tsx +702 -0
- package/src/components/modals/__tests__/KbIdentityConflictModal.test.tsx +102 -0
- package/src/components/modals/__tests__/KeyboardShortcutsHelpModal.test.tsx +115 -0
- package/src/components/modals/__tests__/PermissionDeniedModal.test.tsx +218 -0
- package/src/components/modals/__tests__/ReferenceWizardModal.test.tsx +936 -0
- package/src/components/modals/__tests__/ResourceGenerateModal.test.tsx +532 -0
- package/src/components/modals/__tests__/SearchModal.accessibility.test.tsx +95 -0
- package/src/components/modals/__tests__/SearchModal.basic.test.tsx +84 -0
- package/src/components/modals/__tests__/SearchModal.keyboard.test.tsx +162 -0
- package/src/components/modals/__tests__/SearchModal.search-wiring.test.tsx +237 -0
- package/src/components/modals/__tests__/SearchModal.translations.test.tsx +91 -0
- package/src/components/modals/__tests__/SearchResultsStep.test.tsx +95 -0
- package/src/components/modals/__tests__/SessionEndedModal.test.tsx +171 -0
- package/src/components/modals/__tests__/WizardFooter.test.tsx +446 -0
- package/src/components/modals/__tests__/search-modal-harness.ts +82 -0
- package/src/components/modals/modals.css +655 -0
- package/src/components/navigation/CollapsibleResourceNavigation.css +10 -0
- package/src/components/navigation/CollapsibleResourceNavigation.tsx +364 -0
- package/src/components/navigation/NavigationMenu.css +59 -0
- package/src/components/navigation/NavigationMenu.tsx +66 -0
- package/src/components/navigation/NavigationTabs.css +466 -0
- package/src/components/navigation/ObservableLink.tsx +90 -0
- package/src/components/navigation/SimpleNavigation.css +9 -0
- package/src/components/navigation/SimpleNavigation.tsx +169 -0
- package/src/components/navigation/SortableResourceTab.tsx +122 -0
- package/src/components/navigation/__tests__/NavigationMenu.a11y.test.tsx +302 -0
- package/src/components/navigation/__tests__/NavigationMenu.test.tsx +399 -0
- package/src/components/navigation/__tests__/ObservableLink.test.tsx +85 -0
- package/src/components/navigation/__tests__/SimpleNavigation.test.tsx +193 -0
- package/src/components/navigation/__tests__/SortableResourceTab.test.tsx +421 -0
- package/src/components/pdf-annotation/PdfAnnotationCanvas.client.tsx +10 -0
- package/src/components/pdf-annotation/PdfAnnotationCanvas.css +288 -0
- package/src/components/pdf-annotation/PdfAnnotationCanvas.tsx +632 -0
- package/src/components/pdf-annotation/PdfPageView.tsx +527 -0
- package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.annotate-gate.test.tsx +295 -0
- package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.pixels-before-anchoring.test.tsx +166 -0
- package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.test.tsx +1719 -0
- package/src/components/pdf-annotation/__tests__/estimate-slot-height.test.ts +61 -0
- package/src/components/pdf-annotation/__tests__/rects-for-page.test.ts +110 -0
- package/src/components/pdf-annotation/estimate-slot-height.ts +31 -0
- package/src/components/pdf-annotation/rects-for-page.ts +50 -0
- package/src/components/resource/AnnotateView.tsx +373 -0
- package/src/components/resource/AnnotationHistory.tsx +169 -0
- package/src/components/resource/BrowseView.tsx +440 -0
- package/src/components/resource/DownloadFileLink.tsx +53 -0
- package/src/components/resource/HistoryEvent.tsx +186 -0
- package/src/components/resource/ResourceViewer.tsx +617 -0
- package/src/components/resource/__tests__/AnnotateView.code-point-offsets.test.tsx +482 -0
- package/src/components/resource/__tests__/AnnotateView.embeddable.test.tsx +78 -0
- package/src/components/resource/__tests__/AnnotateView.focus.test.tsx +147 -0
- package/src/components/resource/__tests__/AnnotateView.registry.test.tsx +143 -0
- package/src/components/resource/__tests__/AnnotationHistory.test.tsx +257 -0
- package/src/components/resource/__tests__/BrowseView.code-point-offsets.test.tsx +123 -0
- package/src/components/resource/__tests__/BrowseView.embeddable.test.tsx +76 -0
- package/src/components/resource/__tests__/BrowseView.links.test.tsx +84 -0
- package/src/components/resource/__tests__/BrowseView.overlay-async.test.tsx +165 -0
- package/src/components/resource/__tests__/BrowseView.reference-hover.test.tsx +200 -0
- package/src/components/resource/__tests__/BrowseView.registry.test.tsx +57 -0
- package/src/components/resource/__tests__/BrowseView.test.tsx +915 -0
- package/src/components/resource/__tests__/HistoryEvent.test.tsx +571 -0
- package/src/components/resource/__tests__/ResourceViewer.delete-failure.test.tsx +103 -0
- package/src/components/resource/__tests__/ResourceViewer.embeddable.test.tsx +250 -0
- package/src/components/resource/__tests__/ResourceViewer.mode-switch.test.tsx +262 -0
- package/src/components/resource/__tests__/ResourceViewer.multi-mount-invalidation.test.tsx +166 -0
- package/src/components/resource/__tests__/ResourceViewer.registry.test.tsx +112 -0
- package/src/components/resource/__tests__/ResourceViewer.toolbar-opt-out.test.tsx +207 -0
- package/src/components/resource/__tests__/ResourceViewer.toolbar-prefs.test.tsx +274 -0
- package/src/components/resource/__tests__/annotation-interactions.test.tsx +116 -0
- package/src/components/resource/__tests__/browse-renderers.dispatch.test.tsx +183 -0
- package/src/components/resource/__tests__/browse-renderers.test.tsx +47 -0
- package/src/components/resource/__tests__/download-link.test.tsx +171 -0
- package/src/components/resource/__tests__/event-formatting.test.ts +379 -0
- package/src/components/resource/__tests__/inline-embedding.test.tsx +133 -0
- package/src/components/resource/__tests__/media-completeness.test.tsx +144 -0
- package/src/components/resource/annotate-renderers.tsx +186 -0
- package/src/components/resource/browse-renderers.tsx +133 -0
- package/src/components/resource/event-formatting.ts +393 -0
- package/src/components/resource/panels/AssessmentEntry.tsx +127 -0
- package/src/components/resource/panels/AssessmentPanel.tsx +309 -0
- package/src/components/resource/panels/CollaborationPanel.css +184 -0
- package/src/components/resource/panels/CollaborationPanel.tsx +228 -0
- package/src/components/resource/panels/CommentEntry.tsx +242 -0
- package/src/components/resource/panels/CommentsPanel.tsx +320 -0
- package/src/components/resource/panels/DelegateSection.css +330 -0
- package/src/components/resource/panels/DelegateSection.tsx +282 -0
- package/src/components/resource/panels/DelegateShell.tsx +134 -0
- package/src/components/resource/panels/HighlightEntry.tsx +83 -0
- package/src/components/resource/panels/HighlightPanel.tsx +212 -0
- package/src/components/resource/panels/JsonLdPanel.css +37 -0
- package/src/components/resource/panels/JsonLdPanel.tsx +119 -0
- package/src/components/resource/panels/PanelHeader.tsx +22 -0
- package/src/components/resource/panels/ReferenceEntry.tsx +232 -0
- package/src/components/resource/panels/ReferencesPanel.css +108 -0
- package/src/components/resource/panels/ReferencesPanel.tsx +626 -0
- package/src/components/resource/panels/ResourceInfoPanel.css +183 -0
- package/src/components/resource/panels/ResourceInfoPanel.tsx +433 -0
- package/src/components/resource/panels/StatisticsPanel.css +127 -0
- package/src/components/resource/panels/StatisticsPanel.tsx +145 -0
- package/src/components/resource/panels/TagEntry.tsx +87 -0
- package/src/components/resource/panels/TaggingPanel.tsx +554 -0
- package/src/components/resource/panels/UnifiedAnnotationsPanel.css +129 -0
- package/src/components/resource/panels/UnifiedAnnotationsPanel.tsx +384 -0
- package/src/components/resource/panels/__tests__/AssessmentEntry.test.tsx +292 -0
- package/src/components/resource/panels/__tests__/AssessmentPanel.test.tsx +685 -0
- package/src/components/resource/panels/__tests__/CollaborationPanel.test.tsx +685 -0
- package/src/components/resource/panels/__tests__/CommentEntry.test.tsx +750 -0
- package/src/components/resource/panels/__tests__/CommentsPanel.test.tsx +877 -0
- package/src/components/resource/panels/__tests__/DelegateSection.test.tsx +623 -0
- package/src/components/resource/panels/__tests__/DelegateShell.test.tsx +212 -0
- package/src/components/resource/panels/__tests__/HighlightEntry.test.tsx +236 -0
- package/src/components/resource/panels/__tests__/HighlightPanel.annotationProgress.test.tsx +506 -0
- package/src/components/resource/panels/__tests__/HighlightPanel.out-of-order.test.tsx +132 -0
- package/src/components/resource/panels/__tests__/JsonLdPanel.test.tsx +230 -0
- package/src/components/resource/panels/__tests__/PanelHeader.test.tsx +54 -0
- package/src/components/resource/panels/__tests__/ReferenceEntry.test.tsx +578 -0
- package/src/components/resource/panels/__tests__/ReferencesPanel.headless.test.tsx +193 -0
- package/src/components/resource/panels/__tests__/ReferencesPanel.observable-flow.test.tsx +193 -0
- package/src/components/resource/panels/__tests__/ReferencesPanel.test.tsx +1080 -0
- package/src/components/resource/panels/__tests__/ResourceInfoPanel.test.tsx +812 -0
- package/src/components/resource/panels/__tests__/ResourceInfoPanel.text-layer.test.tsx +106 -0
- package/src/components/resource/panels/__tests__/StatisticsPanel.test.tsx +329 -0
- package/src/components/resource/panels/__tests__/TagEntry.test.tsx +250 -0
- package/src/components/resource/panels/__tests__/TaggingPanel.test.tsx +772 -0
- package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.delegated-job.test.tsx +207 -0
- package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.failure.test.tsx +89 -0
- package/src/components/resource/panels/__tests__/agent-label.test.ts +136 -0
- package/src/components/resource/panels/agent-label.ts +35 -0
- package/src/components/settings/SettingsPanel.css +92 -0
- package/src/components/settings/SettingsPanel.tsx +251 -0
- package/src/components/settings/__tests__/SettingsPanel.test.tsx +260 -0
- package/src/components/toolbar/Toolbar.css +245 -0
- package/src/components/viewers/ImageViewer.tsx +18 -0
- package/src/components/viewers/__tests__/ImageViewer.test.tsx +57 -0
- package/src/components/viewers/index.ts +1 -0
- package/src/features/auth/__tests__/AuthErrorDisplay.test.tsx +181 -0
- package/src/features/auth/auth.css +120 -0
- package/src/features/auth/components/AuthErrorDisplay.tsx +89 -0
- package/src/features/moderate-entity-tags/__tests__/EntityTagsPage.test.tsx +387 -0
- package/src/features/moderate-entity-tags/components/EntityTagsPage.tsx +161 -0
- package/src/features/moderate-entity-tags/state/__tests__/entity-tags-state-unit.test.ts +183 -0
- package/src/features/moderate-entity-tags/state/entity-tags-state-unit.ts +73 -0
- package/src/features/moderate-recent/__tests__/RecentDocumentsPage.test.tsx +422 -0
- package/src/features/moderate-recent/components/RecentDocumentsPage.tsx +117 -0
- package/src/features/moderate-tag-schemas/__tests__/TagSchemasPage.test.tsx +481 -0
- package/src/features/moderate-tag-schemas/components/TagSchemasPage.tsx +161 -0
- package/src/features/resource-compose/__tests__/ResourceComposePage.test.tsx +600 -0
- package/src/features/resource-compose/__tests__/UploadProgressBar.test.tsx +256 -0
- package/src/features/resource-compose/components/ResourceComposePage.tsx +809 -0
- package/src/features/resource-compose/components/UploadProgressBar.tsx +125 -0
- package/src/features/resource-compose/state/__tests__/compose-page-state-unit.test.ts +195 -0
- package/src/features/resource-compose/state/compose-page-state-unit.ts +187 -0
- package/src/features/resource-discovery/__tests__/ResourceCard.test.tsx +338 -0
- package/src/features/resource-discovery/__tests__/ResourceDiscoveryPage.test.tsx +449 -0
- package/src/features/resource-discovery/components/ResourceCard.tsx +80 -0
- package/src/features/resource-discovery/components/ResourceDiscoveryPage.tsx +330 -0
- package/src/features/resource-discovery/state/__tests__/discover-state-unit.test.ts +477 -0
- package/src/features/resource-discovery/state/discover-state-unit.ts +162 -0
- package/src/features/resource-viewer/__tests__/ResourceViewerPage.content-loading.test.tsx +260 -0
- package/src/features/resource-viewer/__tests__/ResourceViewerPage.test.tsx +570 -0
- package/src/features/resource-viewer/__tests__/generation-params.test.ts +49 -0
- package/src/features/resource-viewer/components/ResourceViewerPage.tsx +1058 -0
- package/src/features/resource-viewer/generation-params.ts +23 -0
- package/src/features/resource-viewer/hooks/__tests__/useResourceViewedReport.test.tsx +77 -0
- package/src/features/resource-viewer/hooks/useResourceViewedReport.ts +38 -0
- package/src/features/resource-viewer/state/__tests__/resource-loader-state-unit.test.ts +178 -0
- package/src/features/resource-viewer/state/__tests__/resource-viewer-page-state-unit.test.ts +505 -0
- package/src/features/resource-viewer/state/resource-loader-state-unit.ts +93 -0
- package/src/features/resource-viewer/state/resource-viewer-page-state-unit.ts +156 -0
- package/src/styles/base/reset.css +105 -0
- package/src/styles/base/utilities.css +35 -0
- package/src/styles/core/badges.css +17 -0
- package/src/styles/core/buttons.css +772 -0
- package/src/styles/core/checkboxes.css +85 -0
- package/src/styles/core/forms.css +237 -0
- package/src/styles/core/index.css +43 -0
- package/src/styles/core/indicators.css +24 -0
- package/src/styles/core/inputs.css +164 -0
- package/src/styles/core/progress.css +85 -0
- package/src/styles/core/selects.css +119 -0
- package/src/styles/core/sliders.css +180 -0
- package/src/styles/core/tags.css +86 -0
- package/src/styles/core/textareas.css +104 -0
- package/src/styles/core/toggles.css +82 -0
- package/src/styles/features/compose.css +341 -0
- package/src/styles/features/entity-tags.css +140 -0
- package/src/styles/features/recent-docs.css +97 -0
- package/src/styles/features/resource-discovery.css +349 -0
- package/src/styles/features/resource-viewer.css +609 -0
- package/src/styles/features/resource.css +483 -0
- package/src/styles/features/schemas.css +222 -0
- package/src/styles/index.css +84 -0
- package/src/styles/layout/layout.css +28 -0
- package/src/styles/motivations/motivation-assessment.css +179 -0
- package/src/styles/motivations/motivation-comment.css +164 -0
- package/src/styles/motivations/motivation-highlight.css +132 -0
- package/src/styles/motivations/motivation-reference.css +167 -0
- package/src/styles/motivations/motivation-tag.css +182 -0
- package/src/styles/panels/history-panel.css +212 -0
- package/src/styles/panels/user-panel.css +21 -0
- package/src/styles/patterns/cards.css +26 -0
- package/src/styles/patterns/panel-helpers.css +32 -0
- package/src/styles/patterns/panels-base.css +272 -0
- package/src/styles/utilities/contrast.css +280 -0
- package/src/styles/utilities/focus-extended.css +276 -0
- package/src/styles/utilities/focus.css +41 -0
- package/src/styles/utilities/motion-overrides.css +286 -0
- package/src/styles/utilities/motion.css +184 -0
- package/src/styles/utilities/semantic-indicators.css +254 -0
- package/src/styles/variables.css +410 -0
- package/translations/ar.json +534 -0
- package/translations/bn.json +534 -0
- package/translations/cs.json +534 -0
- package/translations/da.json +534 -0
- package/translations/de.json +534 -0
- package/translations/el.json +534 -0
- package/translations/en.json +534 -0
- package/translations/es.json +534 -0
- package/translations/fa.json +534 -0
- package/translations/fi.json +534 -0
- package/translations/fr.json +534 -0
- package/translations/he.json +534 -0
- package/translations/hi.json +534 -0
- package/translations/id.json +534 -0
- package/translations/it.json +534 -0
- package/translations/ja.json +534 -0
- package/translations/ko.json +534 -0
- package/translations/ms.json +534 -0
- package/translations/nl.json +534 -0
- package/translations/no.json +534 -0
- package/translations/pl.json +534 -0
- package/translations/pt.json +534 -0
- package/translations/ro.json +534 -0
- package/translations/sv.json +534 -0
- package/translations/th.json +534 -0
- package/translations/tr.json +534 -0
- package/translations/uk.json +534 -0
- package/translations/vi.json +534 -0
- package/translations/zh.json +534 -0
|
@@ -0,0 +1,632 @@
|
|
|
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
|
+
}
|