@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,1719 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PdfAnnotationCanvas Component Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for PDF annotation canvas component including:
|
|
5
|
+
* - Rendering states (loading, error, success)
|
|
6
|
+
* - Page navigation controls
|
|
7
|
+
* - Annotation display
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
11
|
+
import { screen, waitFor, fireEvent, act } from '@testing-library/react';
|
|
12
|
+
import userEvent from '@testing-library/user-event';
|
|
13
|
+
import { PdfAnnotationCanvas } from '../PdfAnnotationCanvas';
|
|
14
|
+
import { TranslationProvider } from '../../../contexts/TranslationContext';
|
|
15
|
+
import { defaultMocks, renderInEnglish } from '../../../test-utils';
|
|
16
|
+
import { resourceId, annotationId, parseFragmentSelector } from '@xynolog/core';
|
|
17
|
+
import { pdfToCanvasCoordinates } from '../../../lib/pdf-coordinates';
|
|
18
|
+
import {
|
|
19
|
+
loadPdfDocument,
|
|
20
|
+
renderPdfPageToDataUrl,
|
|
21
|
+
} from '../../../lib/browser-pdfjs';
|
|
22
|
+
|
|
23
|
+
import type { Annotation, AnchoredTextAnswer } from '@xynolog/core';
|
|
24
|
+
|
|
25
|
+
// The document's anchored text, as Xynolog serves it: the canvas asks for it
|
|
26
|
+
// and reads no page's text itself. Geometry is PDF points, bottom-left origin:
|
|
27
|
+
// "Hello world" sits on one line of page 1 at y=700, "elsewhere" a hundred
|
|
28
|
+
// points below it.
|
|
29
|
+
const SERVED_TEXT: AnchoredTextAnswer = {
|
|
30
|
+
kind: 'extracted',
|
|
31
|
+
method: 'pdf-text-layer',
|
|
32
|
+
text: 'Hello world\nelsewhere\n',
|
|
33
|
+
items: [
|
|
34
|
+
{ start: 0, end: 5, page: 1, x: 72, y: 700, width: 30, height: 12 },
|
|
35
|
+
{ start: 6, end: 11, page: 1, x: 106, y: 700, width: 32, height: 12 },
|
|
36
|
+
{ start: 12, end: 21, page: 1, x: 72, y: 600, width: 54, height: 12 },
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// A pdf.js page as the canvas uses one: a viewport to measure and a render to
|
|
41
|
+
// draw. It has no `getTextContent` — a canvas that asked for one would throw.
|
|
42
|
+
const mockPage = () => ({
|
|
43
|
+
getViewport: vi.fn().mockReturnValue({
|
|
44
|
+
width: 612,
|
|
45
|
+
height: 792,
|
|
46
|
+
scale: 1.0,
|
|
47
|
+
rotation: 0,
|
|
48
|
+
}),
|
|
49
|
+
render: vi.fn().mockReturnValue({
|
|
50
|
+
promise: Promise.resolve(),
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Mock browser-pdfjs module
|
|
55
|
+
vi.mock('../../../lib/browser-pdfjs', () => ({
|
|
56
|
+
loadPdfDocument: vi.fn().mockResolvedValue({
|
|
57
|
+
numPages: 3,
|
|
58
|
+
getPage: vi.fn().mockResolvedValue({
|
|
59
|
+
getViewport: vi.fn().mockReturnValue({
|
|
60
|
+
width: 612,
|
|
61
|
+
height: 792,
|
|
62
|
+
scale: 1.0,
|
|
63
|
+
rotation: 0,
|
|
64
|
+
}),
|
|
65
|
+
render: vi.fn().mockReturnValue({
|
|
66
|
+
promise: Promise.resolve(),
|
|
67
|
+
}),
|
|
68
|
+
}),
|
|
69
|
+
}),
|
|
70
|
+
renderPdfPageToDataUrl: vi.fn().mockResolvedValue({
|
|
71
|
+
dataUrl: 'data:image/png;base64,mock',
|
|
72
|
+
width: 612,
|
|
73
|
+
height: 792,
|
|
74
|
+
}),
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* jsdom has no IntersectionObserver. This stub records what the component
|
|
79
|
+
* observes and hands the test the callback, so a "scroll" is an explicit
|
|
80
|
+
* fire() rather than a simulated layout — jsdom has no layout either.
|
|
81
|
+
*/
|
|
82
|
+
function stubIntersectionObserver() {
|
|
83
|
+
// (element, callback) PAIRS, not a map keyed by element: the component runs
|
|
84
|
+
// two observers over the same slots — one widened for preloading, one bare
|
|
85
|
+
// for "what is on screen" — and a map would keep only the last registered.
|
|
86
|
+
const observed: Array<{ el: Element; cb: IntersectionObserverCallback }> = [];
|
|
87
|
+
const margins = new Map<IntersectionObserverCallback, string>();
|
|
88
|
+
let observeCalls = 0;
|
|
89
|
+
class FakeIO {
|
|
90
|
+
constructor(
|
|
91
|
+
private cb: IntersectionObserverCallback,
|
|
92
|
+
options?: IntersectionObserverInit,
|
|
93
|
+
) {
|
|
94
|
+
margins.set(cb, options?.rootMargin ?? '0px');
|
|
95
|
+
}
|
|
96
|
+
observe(el: Element) {
|
|
97
|
+
observeCalls++;
|
|
98
|
+
observed.push({ el, cb: this.cb });
|
|
99
|
+
}
|
|
100
|
+
unobserve(el: Element) {
|
|
101
|
+
for (let i = observed.length - 1; i >= 0; i--) {
|
|
102
|
+
if (observed[i]!.el === el && observed[i]!.cb === this.cb)
|
|
103
|
+
observed.splice(i, 1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
disconnect() {
|
|
107
|
+
for (let i = observed.length - 1; i >= 0; i--) {
|
|
108
|
+
if (observed[i]!.cb === this.cb) observed.splice(i, 1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
takeRecords() {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
vi.stubGlobal('IntersectionObserver', FakeIO);
|
|
116
|
+
|
|
117
|
+
/** Deliver one entry per observed slot to the observers `match` selects:
|
|
118
|
+
* intersecting for `visible`, not for the rest. Refuses a visible page no
|
|
119
|
+
* selected observer has registered — that entry would reach nobody, and the
|
|
120
|
+
* test would only find out a second later, from an empty mount list. */
|
|
121
|
+
function fireFor(visible: number[], match: (rootMargin: string) => boolean) {
|
|
122
|
+
const byCb = new Map<
|
|
123
|
+
IntersectionObserverCallback,
|
|
124
|
+
IntersectionObserverEntry[]
|
|
125
|
+
>();
|
|
126
|
+
const reached = new Set<number>();
|
|
127
|
+
for (const { el, cb } of observed) {
|
|
128
|
+
if (!match(margins.get(cb) ?? '0px')) continue;
|
|
129
|
+
const page = Number((el as HTMLElement).dataset.page);
|
|
130
|
+
reached.add(page);
|
|
131
|
+
byCb.set(cb, [
|
|
132
|
+
...(byCb.get(cb) ?? []),
|
|
133
|
+
{
|
|
134
|
+
target: el,
|
|
135
|
+
isIntersecting: visible.includes(page),
|
|
136
|
+
} as unknown as IntersectionObserverEntry,
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
const unreached = visible.filter((page) => !reached.has(page));
|
|
140
|
+
if (unreached.length > 0) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`fire([${visible}]): no observer has registered page ${unreached} yet — wait on io.observedPages() first`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
act(() => {
|
|
146
|
+
for (const [cb, entries] of byCb) cb(entries, {} as IntersectionObserver);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Only the bare observer — what the reader can actually see. */
|
|
151
|
+
function fireOnscreen(visible: number[]) {
|
|
152
|
+
fireFor(visible, (m) => m === '0px');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Pages currently registered with an observer, deduped. The slots — and the
|
|
157
|
+
* strip, which lands in the same commit — reach the DOM one effect BEFORE
|
|
158
|
+
* `observe()` runs on them, so a wait on the DOM can pass with nothing
|
|
159
|
+
* registered. Whether the test then fires before or after the effect is a
|
|
160
|
+
* race between React's scheduler and waitFor's closing 0ms timer, which CI
|
|
161
|
+
* load decides. Wait on this instead. (Both observers are created in the
|
|
162
|
+
* same effect pass, so a page appearing here means both have it.)
|
|
163
|
+
*/
|
|
164
|
+
function observedPages(): number[] {
|
|
165
|
+
const pages = new Set(
|
|
166
|
+
observed.map(({ el }) => Number((el as HTMLElement).dataset.page)),
|
|
167
|
+
);
|
|
168
|
+
return [...pages].sort((a, b) => a - b);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
fireOnscreen,
|
|
173
|
+
observedPages,
|
|
174
|
+
/** Every `observe()` so far, re-registrations included — `observedPages`
|
|
175
|
+
* cannot see an unobserve followed by an observe of the same slot. */
|
|
176
|
+
observeCalls: () => observeCalls,
|
|
177
|
+
/**
|
|
178
|
+
* Fire both observers: these pages are mounted AND on screen — the
|
|
179
|
+
* ordinary case. A test that needs the two to differ (a page preloaded
|
|
180
|
+
* but not yet visible) calls `fireOnscreen` afterwards to narrow it.
|
|
181
|
+
*/
|
|
182
|
+
fire(visible: number[]) {
|
|
183
|
+
fireFor(visible, () => true);
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
describe('PdfAnnotationCanvas', () => {
|
|
189
|
+
const mockResourceId = resourceId('123');
|
|
190
|
+
const mockPdfUrl = 'https://example.com/resources/123.pdf';
|
|
191
|
+
|
|
192
|
+
afterEach(() => {
|
|
193
|
+
// Stubs must not leak into other files sharing this Vitest environment.
|
|
194
|
+
vi.unstubAllGlobals();
|
|
195
|
+
// ...and prototype spies must not leak into later tests in THIS file.
|
|
196
|
+
vi.restoreAllMocks();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
beforeEach(() => {
|
|
200
|
+
vi.clearAllMocks();
|
|
201
|
+
|
|
202
|
+
// jsdom doesn't fire image onLoad or support clientWidth/clientHeight.
|
|
203
|
+
// Mock requestAnimationFrame to run callbacks synchronously and
|
|
204
|
+
// provide dimensions on the image element so the SVG overlay renders.
|
|
205
|
+
vi.stubGlobal('requestAnimationFrame', (cb: FrameRequestCallback) => {
|
|
206
|
+
cb(0);
|
|
207
|
+
return 0;
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('renders loading state initially', () => {
|
|
212
|
+
renderInEnglish(
|
|
213
|
+
<PdfAnnotationCanvas
|
|
214
|
+
resourceUri={resourceId('res-1')}
|
|
215
|
+
pdfUrl={mockPdfUrl}
|
|
216
|
+
drawingMode={null}
|
|
217
|
+
/>,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
expect(screen.getByText(/loading pdf/i)).toBeInTheDocument();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('renders page navigation controls after loading', async () => {
|
|
224
|
+
renderInEnglish(
|
|
225
|
+
<PdfAnnotationCanvas
|
|
226
|
+
resourceUri={resourceId('res-1')}
|
|
227
|
+
pdfUrl={mockPdfUrl}
|
|
228
|
+
drawingMode={null}
|
|
229
|
+
/>,
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
await waitFor(() => {
|
|
233
|
+
expect(screen.getByText(/page 1 of 3/i)).toBeInTheDocument();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(
|
|
237
|
+
screen.getByRole('button', { name: /previous/i }),
|
|
238
|
+
).toBeInTheDocument();
|
|
239
|
+
expect(screen.getByRole('button', { name: /next/i })).toBeInTheDocument();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test('previous button is disabled on first page', async () => {
|
|
243
|
+
renderInEnglish(
|
|
244
|
+
<PdfAnnotationCanvas
|
|
245
|
+
resourceUri={resourceId('res-1')}
|
|
246
|
+
pdfUrl={mockPdfUrl}
|
|
247
|
+
drawingMode={null}
|
|
248
|
+
/>,
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
await waitFor(() => {
|
|
252
|
+
expect(screen.getByText(/page 1 of 3/i)).toBeInTheDocument();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
const prevButton = screen.getByRole('button', { name: /previous/i });
|
|
256
|
+
expect(prevButton).toBeDisabled();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('next button is disabled on last page', async () => {
|
|
260
|
+
renderInEnglish(
|
|
261
|
+
<PdfAnnotationCanvas
|
|
262
|
+
resourceUri={resourceId('res-1')}
|
|
263
|
+
pdfUrl={mockPdfUrl}
|
|
264
|
+
drawingMode={null}
|
|
265
|
+
/>,
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
const user = userEvent.setup();
|
|
269
|
+
|
|
270
|
+
await waitFor(() => {
|
|
271
|
+
expect(screen.getByText(/page 1 of 3/i)).toBeInTheDocument();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const nextButton = screen.getByRole('button', { name: /next/i });
|
|
275
|
+
|
|
276
|
+
// Navigate to last page
|
|
277
|
+
await user.click(nextButton);
|
|
278
|
+
await user.click(nextButton);
|
|
279
|
+
|
|
280
|
+
await waitFor(() => {
|
|
281
|
+
expect(screen.getByText(/page 3 of 3/i)).toBeInTheDocument();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(nextButton).toBeDisabled();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('renders existing annotations', async () => {
|
|
288
|
+
const mockAnnotations: Annotation[] = [
|
|
289
|
+
{
|
|
290
|
+
'@context': 'http://www.w3.org/ns/anno.jsonld',
|
|
291
|
+
type: 'Annotation',
|
|
292
|
+
id: annotationId('ann-1'),
|
|
293
|
+
target: {
|
|
294
|
+
source: mockResourceId,
|
|
295
|
+
selector: {
|
|
296
|
+
type: 'FragmentSelector',
|
|
297
|
+
value: 'page=1&viewrect=100,200,150,100',
|
|
298
|
+
conformsTo: 'http://tools.ietf.org/rfc/rfc3778',
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
motivation: 'highlighting',
|
|
302
|
+
created: new Date().toISOString(),
|
|
303
|
+
},
|
|
304
|
+
];
|
|
305
|
+
|
|
306
|
+
renderInEnglish(
|
|
307
|
+
<PdfAnnotationCanvas
|
|
308
|
+
resourceUri={resourceId('res-1')}
|
|
309
|
+
pdfUrl={mockPdfUrl}
|
|
310
|
+
existingAnnotations={mockAnnotations}
|
|
311
|
+
drawingMode={null}
|
|
312
|
+
/>,
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
await waitFor(() => {
|
|
316
|
+
expect(screen.getByText(/page 1 of 3/i)).toBeInTheDocument();
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// jsdom doesn't fire image onLoad or provide clientWidth/clientHeight.
|
|
320
|
+
// Wait for the image element to appear, then simulate load with dimensions.
|
|
321
|
+
await waitFor(() => {
|
|
322
|
+
const img = document.querySelector(
|
|
323
|
+
'.xynolog-pdf-annotation-canvas__image',
|
|
324
|
+
) as HTMLImageElement;
|
|
325
|
+
expect(img).toBeInTheDocument();
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const img = document.querySelector(
|
|
329
|
+
'.xynolog-pdf-annotation-canvas__image',
|
|
330
|
+
) as HTMLImageElement;
|
|
331
|
+
Object.defineProperty(img, 'clientWidth', {
|
|
332
|
+
value: 612,
|
|
333
|
+
configurable: true,
|
|
334
|
+
});
|
|
335
|
+
Object.defineProperty(img, 'clientHeight', {
|
|
336
|
+
value: 792,
|
|
337
|
+
configurable: true,
|
|
338
|
+
});
|
|
339
|
+
fireEvent.load(img);
|
|
340
|
+
|
|
341
|
+
await waitFor(() => {
|
|
342
|
+
// Annotation should be rendered in SVG
|
|
343
|
+
const svg = document.querySelector('.xynolog-pdf-annotation-canvas__svg');
|
|
344
|
+
expect(svg).toBeInTheDocument();
|
|
345
|
+
|
|
346
|
+
const rects = svg?.querySelectorAll('rect');
|
|
347
|
+
expect(rects?.length).toBeGreaterThan(0);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test('passes the annotation rect as browse.click second argument', async () => {
|
|
352
|
+
const click = vi.fn();
|
|
353
|
+
const session = {
|
|
354
|
+
client: {
|
|
355
|
+
browse: {
|
|
356
|
+
click,
|
|
357
|
+
resourceAnchoredText: vi.fn().mockResolvedValue(SERVED_TEXT),
|
|
358
|
+
},
|
|
359
|
+
beckon: { hover: vi.fn() },
|
|
360
|
+
},
|
|
361
|
+
} as unknown as import('@xynolog/sdk').XynologSession;
|
|
362
|
+
|
|
363
|
+
const mockAnnotations: Annotation[] = [
|
|
364
|
+
{
|
|
365
|
+
'@context': 'http://www.w3.org/ns/anno.jsonld',
|
|
366
|
+
type: 'Annotation',
|
|
367
|
+
id: annotationId('ann-1'),
|
|
368
|
+
target: {
|
|
369
|
+
source: mockResourceId,
|
|
370
|
+
selector: {
|
|
371
|
+
type: 'FragmentSelector',
|
|
372
|
+
value: 'page=1&viewrect=100,200,150,100',
|
|
373
|
+
conformsTo: 'http://tools.ietf.org/rfc/rfc3778',
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
motivation: 'highlighting',
|
|
377
|
+
created: new Date().toISOString(),
|
|
378
|
+
},
|
|
379
|
+
];
|
|
380
|
+
|
|
381
|
+
renderInEnglish(
|
|
382
|
+
<PdfAnnotationCanvas
|
|
383
|
+
resourceUri={resourceId('res-1')}
|
|
384
|
+
pdfUrl={mockPdfUrl}
|
|
385
|
+
existingAnnotations={mockAnnotations}
|
|
386
|
+
drawingMode={null}
|
|
387
|
+
session={session}
|
|
388
|
+
/>,
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
await waitFor(() => {
|
|
392
|
+
const img = document.querySelector(
|
|
393
|
+
'.xynolog-pdf-annotation-canvas__image',
|
|
394
|
+
) as HTMLImageElement;
|
|
395
|
+
expect(img).toBeInTheDocument();
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
const img = document.querySelector(
|
|
399
|
+
'.xynolog-pdf-annotation-canvas__image',
|
|
400
|
+
) as HTMLImageElement;
|
|
401
|
+
Object.defineProperty(img, 'clientWidth', {
|
|
402
|
+
value: 612,
|
|
403
|
+
configurable: true,
|
|
404
|
+
});
|
|
405
|
+
Object.defineProperty(img, 'clientHeight', {
|
|
406
|
+
value: 792,
|
|
407
|
+
configurable: true,
|
|
408
|
+
});
|
|
409
|
+
fireEvent.load(img);
|
|
410
|
+
|
|
411
|
+
await waitFor(() => {
|
|
412
|
+
const rects = document
|
|
413
|
+
.querySelector('.xynolog-pdf-annotation-canvas__svg')
|
|
414
|
+
?.querySelectorAll('rect');
|
|
415
|
+
expect(rects?.length).toBeGreaterThan(0);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
const annotationRect = document
|
|
419
|
+
.querySelector('.xynolog-pdf-annotation-canvas__svg')!
|
|
420
|
+
.querySelector('rect')!;
|
|
421
|
+
fireEvent.click(annotationRect);
|
|
422
|
+
|
|
423
|
+
expect(click).toHaveBeenCalledTimes(1);
|
|
424
|
+
expect(click.mock.calls[0]?.[0]).toBe('ann-1');
|
|
425
|
+
const anchorRect = click.mock.calls[0]?.[1];
|
|
426
|
+
expect(anchorRect).toBeDefined();
|
|
427
|
+
expect(typeof anchorRect.width).toBe('number');
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test('drawing-path hit-test emits browse.click with the annotation viewport rect', async () => {
|
|
431
|
+
// In drawing mode, a sub-10px click on an existing annotation
|
|
432
|
+
// goes through the mouse-up hit-test, which owns the PDF→display
|
|
433
|
+
// coordinate transform. Expected rect computed with the same lib
|
|
434
|
+
// functions the component uses (scale is 1: display 612×792 == page).
|
|
435
|
+
const click = vi.fn();
|
|
436
|
+
const session = {
|
|
437
|
+
client: {
|
|
438
|
+
browse: {
|
|
439
|
+
click,
|
|
440
|
+
resourceAnchoredText: vi.fn().mockResolvedValue(SERVED_TEXT),
|
|
441
|
+
},
|
|
442
|
+
beckon: { hover: vi.fn() },
|
|
443
|
+
},
|
|
444
|
+
} as unknown as import('@xynolog/sdk').XynologSession;
|
|
445
|
+
|
|
446
|
+
const fragmentValue = 'page=1&viewrect=100,200,150,100';
|
|
447
|
+
const mockAnnotations: Annotation[] = [
|
|
448
|
+
{
|
|
449
|
+
'@context': 'http://www.w3.org/ns/anno.jsonld',
|
|
450
|
+
type: 'Annotation',
|
|
451
|
+
id: annotationId('ann-hit-1'),
|
|
452
|
+
target: {
|
|
453
|
+
source: mockResourceId,
|
|
454
|
+
selector: {
|
|
455
|
+
type: 'FragmentSelector',
|
|
456
|
+
value: fragmentValue,
|
|
457
|
+
conformsTo: 'http://tools.ietf.org/rfc/rfc3778',
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
motivation: 'highlighting',
|
|
461
|
+
created: new Date().toISOString(),
|
|
462
|
+
},
|
|
463
|
+
];
|
|
464
|
+
|
|
465
|
+
renderInEnglish(
|
|
466
|
+
<PdfAnnotationCanvas
|
|
467
|
+
resourceUri={resourceId('res-1')}
|
|
468
|
+
pdfUrl={mockPdfUrl}
|
|
469
|
+
existingAnnotations={mockAnnotations}
|
|
470
|
+
drawingMode="rectangle"
|
|
471
|
+
selectedMotivation="highlighting"
|
|
472
|
+
session={session}
|
|
473
|
+
/>,
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
await waitFor(() => {
|
|
477
|
+
const img = document.querySelector(
|
|
478
|
+
'.xynolog-pdf-annotation-canvas__image',
|
|
479
|
+
) as HTMLImageElement;
|
|
480
|
+
expect(img).toBeInTheDocument();
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
const img = document.querySelector(
|
|
484
|
+
'.xynolog-pdf-annotation-canvas__image',
|
|
485
|
+
) as HTMLImageElement;
|
|
486
|
+
Object.defineProperty(img, 'clientWidth', {
|
|
487
|
+
value: 612,
|
|
488
|
+
configurable: true,
|
|
489
|
+
});
|
|
490
|
+
Object.defineProperty(img, 'clientHeight', {
|
|
491
|
+
value: 792,
|
|
492
|
+
configurable: true,
|
|
493
|
+
});
|
|
494
|
+
fireEvent.load(img);
|
|
495
|
+
|
|
496
|
+
await waitFor(() => {
|
|
497
|
+
const rects = document
|
|
498
|
+
.querySelector('.xynolog-pdf-annotation-canvas__svg')
|
|
499
|
+
?.querySelectorAll('rect');
|
|
500
|
+
expect(rects?.length).toBeGreaterThan(0);
|
|
501
|
+
});
|
|
502
|
+
// The hit-test runs on a gesture the canvas takes, and it takes one only
|
|
503
|
+
// while it holds the document's text.
|
|
504
|
+
await waitFor(() => {
|
|
505
|
+
expect(
|
|
506
|
+
document.querySelector('.xynolog-pdf-annotation-canvas'),
|
|
507
|
+
).toHaveAttribute('data-annotate-deferred', 'false');
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const pdfCoord = parseFragmentSelector(fragmentValue)!;
|
|
511
|
+
const displayRect = pdfToCanvasCoordinates(pdfCoord, 792, 1.0);
|
|
512
|
+
|
|
513
|
+
// Sub-10px gesture at the annotation's display-rect center (image rect is
|
|
514
|
+
// zeros in jsdom, so client coordinates are display coordinates).
|
|
515
|
+
const canvasContainer = document.querySelector(
|
|
516
|
+
'.xynolog-pdf-annotation-canvas__container',
|
|
517
|
+
)!;
|
|
518
|
+
const clickX = displayRect.x + displayRect.width / 2;
|
|
519
|
+
const clickY = displayRect.y + displayRect.height / 2;
|
|
520
|
+
fireEvent.mouseDown(canvasContainer, { clientX: clickX, clientY: clickY });
|
|
521
|
+
fireEvent.mouseUp(canvasContainer, { clientX: clickX, clientY: clickY });
|
|
522
|
+
|
|
523
|
+
expect(click).toHaveBeenCalledTimes(1);
|
|
524
|
+
expect(click.mock.calls[0]?.[0]).toBe('ann-hit-1');
|
|
525
|
+
expect(click.mock.calls[0]?.[1]).toMatchObject({
|
|
526
|
+
left: displayRect.x,
|
|
527
|
+
top: displayRect.y,
|
|
528
|
+
width: displayRect.width,
|
|
529
|
+
height: displayRect.height,
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Drives the drag → mark.request path far enough to inspect the selector,
|
|
535
|
+
* on a document for which Xynolog answers `answer`: an answer that gives
|
|
536
|
+
* the canvas the text, since the drag waits until the canvas holds it.
|
|
537
|
+
* `drag` is in canvas pixels; at scale 1 with a 612×792 page these are also
|
|
538
|
+
* display coordinates, since jsdom's getBoundingClientRect returns zeros.
|
|
539
|
+
*/
|
|
540
|
+
async function drawRectangle(
|
|
541
|
+
drag: { fromX: number; fromY: number; toX: number; toY: number },
|
|
542
|
+
answer: AnchoredTextAnswer,
|
|
543
|
+
onPage = 1,
|
|
544
|
+
) {
|
|
545
|
+
const request = vi.fn();
|
|
546
|
+
const session = {
|
|
547
|
+
client: {
|
|
548
|
+
mark: { request },
|
|
549
|
+
beckon: { hover: vi.fn() },
|
|
550
|
+
browse: { resourceAnchoredText: vi.fn().mockResolvedValue(answer) },
|
|
551
|
+
},
|
|
552
|
+
} as unknown as import('@xynolog/sdk').XynologSession;
|
|
553
|
+
|
|
554
|
+
renderInEnglish(
|
|
555
|
+
<PdfAnnotationCanvas
|
|
556
|
+
resourceUri={resourceId('res-1')}
|
|
557
|
+
pdfUrl={mockPdfUrl}
|
|
558
|
+
drawingMode="rectangle"
|
|
559
|
+
selectedMotivation="highlighting"
|
|
560
|
+
session={session}
|
|
561
|
+
/>,
|
|
562
|
+
);
|
|
563
|
+
|
|
564
|
+
await waitFor(() => {
|
|
565
|
+
expect(screen.getByText(/page 1 of 3/i)).toBeInTheDocument();
|
|
566
|
+
});
|
|
567
|
+
for (let page = 2; page <= onPage; page++) {
|
|
568
|
+
fireEvent.click(screen.getByRole('button', { name: /next/i }));
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const pageImage = () =>
|
|
572
|
+
document.querySelector(
|
|
573
|
+
`.xynolog-pdf-annotation-canvas__image[alt="PDF page ${onPage}"]`,
|
|
574
|
+
);
|
|
575
|
+
await waitFor(() => {
|
|
576
|
+
expect(pageImage()).toBeInTheDocument();
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
const img = pageImage() as HTMLImageElement;
|
|
580
|
+
Object.defineProperty(img, 'clientWidth', {
|
|
581
|
+
value: 612,
|
|
582
|
+
configurable: true,
|
|
583
|
+
});
|
|
584
|
+
Object.defineProperty(img, 'clientHeight', {
|
|
585
|
+
value: 792,
|
|
586
|
+
configurable: true,
|
|
587
|
+
});
|
|
588
|
+
fireEvent.load(img);
|
|
589
|
+
|
|
590
|
+
await waitFor(() => {
|
|
591
|
+
expect(
|
|
592
|
+
document.querySelector('.xynolog-pdf-annotation-canvas'),
|
|
593
|
+
).toHaveAttribute('data-annotate-deferred', 'false');
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
const container = document.querySelector(
|
|
597
|
+
'.xynolog-pdf-annotation-canvas__container',
|
|
598
|
+
)!;
|
|
599
|
+
fireEvent.mouseDown(container, {
|
|
600
|
+
clientX: drag.fromX,
|
|
601
|
+
clientY: drag.fromY,
|
|
602
|
+
});
|
|
603
|
+
fireEvent.mouseMove(container, { clientX: drag.toX, clientY: drag.toY });
|
|
604
|
+
fireEvent.mouseUp(container, { clientX: drag.toX, clientY: drag.toY });
|
|
605
|
+
|
|
606
|
+
return request;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** A box a little larger than a line of text: what a hand draws around it. */
|
|
610
|
+
function aroundLine(line: {
|
|
611
|
+
page: number;
|
|
612
|
+
x: number;
|
|
613
|
+
y: number;
|
|
614
|
+
width: number;
|
|
615
|
+
height: number;
|
|
616
|
+
}) {
|
|
617
|
+
const box = pdfToCanvasCoordinates(line, 792, 1.0);
|
|
618
|
+
return {
|
|
619
|
+
fromX: box.x - 2,
|
|
620
|
+
fromY: box.y - 2,
|
|
621
|
+
toX: box.x + box.width + 8,
|
|
622
|
+
toY: box.y + box.height + 4,
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// The "Hello world" line: PDF y=700..712 flips to canvas y=80..92 on a
|
|
627
|
+
// 792pt page.
|
|
628
|
+
const HELLO_WORLD_LINE = { page: 1, x: 72, y: 700, width: 66, height: 12 };
|
|
629
|
+
|
|
630
|
+
// A hand-drawn rectangle that stores geometry and nothing else shows blank
|
|
631
|
+
// in every panel that quotes an annotation.
|
|
632
|
+
test('a drawn rectangle carries the text it was drawn around', async () => {
|
|
633
|
+
const request = await drawRectangle(
|
|
634
|
+
aroundLine(HELLO_WORLD_LINE),
|
|
635
|
+
SERVED_TEXT,
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
await waitFor(() => expect(request).toHaveBeenCalledTimes(1));
|
|
639
|
+
|
|
640
|
+
const [source, selector, motivation] = request.mock.calls[0];
|
|
641
|
+
expect(source).toBe(resourceId('res-1'));
|
|
642
|
+
expect(motivation).toBe('highlighting');
|
|
643
|
+
expect(selector).toEqual([
|
|
644
|
+
{
|
|
645
|
+
type: 'FragmentSelector',
|
|
646
|
+
conformsTo: 'http://tools.ietf.org/rfc/rfc3778',
|
|
647
|
+
value: expect.stringContaining('page=1&viewrect='),
|
|
648
|
+
},
|
|
649
|
+
{ type: 'TextQuoteSelector', exact: 'Hello world' },
|
|
650
|
+
]);
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
// A PDF's text has one producer. This page has a text layer pdf.js could
|
|
654
|
+
// read, and it says something ELSE: a canvas that read it would quote the
|
|
655
|
+
// layer's words, or never ask Xynolog at all.
|
|
656
|
+
test("the quote is cut from the served text — pdf.js is never asked for the page's text", async () => {
|
|
657
|
+
const getTextContent = vi.fn().mockResolvedValue({
|
|
658
|
+
items: [
|
|
659
|
+
{
|
|
660
|
+
str: 'words pdf.js read',
|
|
661
|
+
transform: [1, 0, 0, 1, 72, 700],
|
|
662
|
+
width: 66,
|
|
663
|
+
height: 12,
|
|
664
|
+
hasEOL: true,
|
|
665
|
+
},
|
|
666
|
+
],
|
|
667
|
+
});
|
|
668
|
+
vi.mocked(loadPdfDocument).mockResolvedValueOnce({
|
|
669
|
+
numPages: 3,
|
|
670
|
+
getPage: vi.fn().mockResolvedValue({ ...mockPage(), getTextContent }),
|
|
671
|
+
} as unknown as Awaited<ReturnType<typeof loadPdfDocument>>);
|
|
672
|
+
|
|
673
|
+
const request = await drawRectangle(
|
|
674
|
+
aroundLine(HELLO_WORLD_LINE),
|
|
675
|
+
SERVED_TEXT,
|
|
676
|
+
);
|
|
677
|
+
|
|
678
|
+
await waitFor(() => expect(request).toHaveBeenCalledTimes(1));
|
|
679
|
+
expect(request.mock.calls[0][1]).toEqual([
|
|
680
|
+
expect.objectContaining({ type: 'FragmentSelector' }),
|
|
681
|
+
{ type: 'TextQuoteSelector', exact: 'Hello world' },
|
|
682
|
+
]);
|
|
683
|
+
expect(getTextContent).not.toHaveBeenCalled();
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
test('a rectangle over blank space carries geometry only', async () => {
|
|
687
|
+
// Between the two lines of text — nothing under the box. An empty-string
|
|
688
|
+
// quote would assert the box was drawn around nothing, so emit no quote.
|
|
689
|
+
const request = await drawRectangle(
|
|
690
|
+
{ fromX: 40, fromY: 120, toX: 200, toY: 150 },
|
|
691
|
+
SERVED_TEXT,
|
|
692
|
+
);
|
|
693
|
+
|
|
694
|
+
await waitFor(() => expect(request).toHaveBeenCalledTimes(1));
|
|
695
|
+
|
|
696
|
+
const selector = request.mock.calls[0][1];
|
|
697
|
+
expect(selector).toHaveLength(1);
|
|
698
|
+
expect(selector[0].type).toBe('FragmentSelector');
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
// The served text is the whole document's, not a page's: offsets run on
|
|
702
|
+
// from one page into the next, and each run names its page. Both pages
|
|
703
|
+
// here put a line at the same place, so only a run's page decides which
|
|
704
|
+
// line a rectangle quotes. The character that ends page 1's line is one
|
|
705
|
+
// code point and two UTF-16 units, so page 2's offsets are not positions in
|
|
706
|
+
// the JavaScript string: a canvas that sliced the text itself would cut
|
|
707
|
+
// "\nsecon" where the word is "second".
|
|
708
|
+
test("a rectangle on page 2 quotes page 2's words out of the whole document's text", async () => {
|
|
709
|
+
const request = await drawRectangle(
|
|
710
|
+
aroundLine({ ...HELLO_WORLD_LINE, page: 2 }),
|
|
711
|
+
{
|
|
712
|
+
kind: 'extracted',
|
|
713
|
+
method: 'pdf-text-layer',
|
|
714
|
+
text: 'first \u{1D49C}\nsecond page\n',
|
|
715
|
+
items: [
|
|
716
|
+
{ start: 0, end: 5, page: 1, x: 72, y: 700, width: 30, height: 12 },
|
|
717
|
+
{ start: 6, end: 7, page: 1, x: 106, y: 700, width: 32, height: 12 },
|
|
718
|
+
{ start: 8, end: 14, page: 2, x: 72, y: 700, width: 30, height: 12 },
|
|
719
|
+
{
|
|
720
|
+
start: 15,
|
|
721
|
+
end: 19,
|
|
722
|
+
page: 2,
|
|
723
|
+
x: 106,
|
|
724
|
+
y: 700,
|
|
725
|
+
width: 32,
|
|
726
|
+
height: 12,
|
|
727
|
+
},
|
|
728
|
+
],
|
|
729
|
+
},
|
|
730
|
+
2,
|
|
731
|
+
);
|
|
732
|
+
|
|
733
|
+
await waitFor(() => expect(request).toHaveBeenCalledTimes(1));
|
|
734
|
+
expect(request.mock.calls[0][1]).toEqual([
|
|
735
|
+
expect.objectContaining({
|
|
736
|
+
type: 'FragmentSelector',
|
|
737
|
+
value: expect.stringContaining('page=2&viewrect='),
|
|
738
|
+
}),
|
|
739
|
+
{ type: 'TextQuoteSelector', exact: 'second page' },
|
|
740
|
+
]);
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
// The served text is WHOLE-RESOURCE — one artifact covering every page —
|
|
744
|
+
// so a page that asked for it would refetch and re-decode the entire
|
|
745
|
+
// document's geometry on every page turn. On a 400-page document that is
|
|
746
|
+
// the difference between one decode and one per interaction. The canvas
|
|
747
|
+
// holds it once and hands it to each page.
|
|
748
|
+
test('the whole-resource text is asked for once per document, not once per page-turn', async () => {
|
|
749
|
+
const resourceAnchoredText = vi.fn().mockResolvedValue(SERVED_TEXT);
|
|
750
|
+
const session = {
|
|
751
|
+
client: { beckon: { hover: vi.fn() }, browse: { resourceAnchoredText } },
|
|
752
|
+
} as unknown as import('@xynolog/sdk').XynologSession;
|
|
753
|
+
|
|
754
|
+
renderInEnglish(
|
|
755
|
+
<PdfAnnotationCanvas
|
|
756
|
+
resourceUri={resourceId('res-1')}
|
|
757
|
+
pdfUrl={mockPdfUrl}
|
|
758
|
+
drawingMode={null}
|
|
759
|
+
session={session}
|
|
760
|
+
/>,
|
|
761
|
+
);
|
|
762
|
+
|
|
763
|
+
const user = userEvent.setup();
|
|
764
|
+
await waitFor(() => {
|
|
765
|
+
expect(screen.getByText(/page 1 of 3/i)).toBeInTheDocument();
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
await user.click(screen.getByRole('button', { name: /next/i }));
|
|
769
|
+
await waitFor(() => {
|
|
770
|
+
expect(screen.getByText(/page 2 of 3/i)).toBeInTheDocument();
|
|
771
|
+
});
|
|
772
|
+
await user.click(screen.getByRole('button', { name: /next/i }));
|
|
773
|
+
await waitFor(() => {
|
|
774
|
+
expect(screen.getByText(/page 3 of 3/i)).toBeInTheDocument();
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
// Three render calls: all three pages loaded.
|
|
778
|
+
await waitFor(() => {
|
|
779
|
+
expect(vi.mocked(renderPdfPageToDataUrl)).toHaveBeenCalledTimes(3);
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
expect(resourceAnchoredText).toHaveBeenCalledTimes(1);
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
// Browse mode scrolls: every page has a slot so
|
|
786
|
+
// the scrollbar is honest about the document's length, but only a window of
|
|
787
|
+
// pages is MOUNTED — unmounting is what releases a page's raster, so the
|
|
788
|
+
// window IS the memory budget.
|
|
789
|
+
describe('scroll layout (browse mode)', () => {
|
|
790
|
+
const fivePageDoc = () =>
|
|
791
|
+
vi.mocked(loadPdfDocument).mockResolvedValueOnce({
|
|
792
|
+
numPages: 5,
|
|
793
|
+
getPage: vi.fn().mockResolvedValue(mockPage()),
|
|
794
|
+
} as unknown as Awaited<ReturnType<typeof loadPdfDocument>>);
|
|
795
|
+
|
|
796
|
+
const mountedPages = () =>
|
|
797
|
+
[...document.querySelectorAll('.xynolog-pdf-annotation-canvas__image')]
|
|
798
|
+
.map((img) => Number((img as HTMLImageElement).alt.replace(/\D+/g, '')))
|
|
799
|
+
.sort((a, b) => a - b);
|
|
800
|
+
|
|
801
|
+
test('gives every page a slot but mounts only the visible window', async () => {
|
|
802
|
+
const io = stubIntersectionObserver();
|
|
803
|
+
fivePageDoc();
|
|
804
|
+
|
|
805
|
+
renderInEnglish(
|
|
806
|
+
<PdfAnnotationCanvas
|
|
807
|
+
resourceUri={resourceId('res-1')}
|
|
808
|
+
pdfUrl={mockPdfUrl}
|
|
809
|
+
drawingMode={null}
|
|
810
|
+
pageLayout="scroll"
|
|
811
|
+
/>,
|
|
812
|
+
);
|
|
813
|
+
|
|
814
|
+
await waitFor(() => {
|
|
815
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
816
|
+
});
|
|
817
|
+
// Nothing rasterized before anything is visible.
|
|
818
|
+
expect(mountedPages()).toEqual([]);
|
|
819
|
+
|
|
820
|
+
io.fire([1, 2]);
|
|
821
|
+
await waitFor(() => expect(mountedPages()).toEqual([1, 2]));
|
|
822
|
+
expect(
|
|
823
|
+
document.querySelectorAll('.xynolog-pdf-annotation-canvas__slot'),
|
|
824
|
+
).toHaveLength(5);
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
test('releases a page that scrolls out of the window', async () => {
|
|
828
|
+
const io = stubIntersectionObserver();
|
|
829
|
+
fivePageDoc();
|
|
830
|
+
|
|
831
|
+
renderInEnglish(
|
|
832
|
+
<PdfAnnotationCanvas
|
|
833
|
+
resourceUri={resourceId('res-1')}
|
|
834
|
+
pdfUrl={mockPdfUrl}
|
|
835
|
+
drawingMode={null}
|
|
836
|
+
pageLayout="scroll"
|
|
837
|
+
/>,
|
|
838
|
+
);
|
|
839
|
+
await waitFor(() => {
|
|
840
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
io.fire([1, 2]);
|
|
844
|
+
await waitFor(() => expect(mountedPages()).toEqual([1, 2]));
|
|
845
|
+
|
|
846
|
+
io.fire([4, 5]);
|
|
847
|
+
await waitFor(() => expect(mountedPages()).toEqual([4, 5]));
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
test('a re-render does not re-register the slots with the observers', async () => {
|
|
851
|
+
// A real IntersectionObserver answers every observe() — a re-observe
|
|
852
|
+
// after unobserve included — with a fresh notification. Re-registering
|
|
853
|
+
// the slots on each commit therefore closes a loop: notification →
|
|
854
|
+
// state → render → re-register → notification. In Chromium on an idle
|
|
855
|
+
// 30-page document that is 120 commits/s, 7,200 observe() calls/s.
|
|
856
|
+
// This stub does not notify on observe(), so the loop cannot show here;
|
|
857
|
+
// the re-registration that feeds it can.
|
|
858
|
+
const io = stubIntersectionObserver();
|
|
859
|
+
fivePageDoc();
|
|
860
|
+
|
|
861
|
+
renderInEnglish(
|
|
862
|
+
<PdfAnnotationCanvas
|
|
863
|
+
resourceUri={resourceId('res-1')}
|
|
864
|
+
pdfUrl={mockPdfUrl}
|
|
865
|
+
drawingMode={null}
|
|
866
|
+
pageLayout="scroll"
|
|
867
|
+
/>,
|
|
868
|
+
);
|
|
869
|
+
await waitFor(() => {
|
|
870
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
871
|
+
});
|
|
872
|
+
const registrations = io.observeCalls();
|
|
873
|
+
|
|
874
|
+
io.fire([1, 2]);
|
|
875
|
+
await waitFor(() => expect(mountedPages()).toEqual([1, 2]));
|
|
876
|
+
|
|
877
|
+
expect(io.observeCalls()).toBe(registrations);
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
test('still asks for the whole-resource text once, across many mounted pages', async () => {
|
|
881
|
+
// Asked once however many page views mount and unmount: the text is
|
|
882
|
+
// the canvas's to hold, and no page asks for it.
|
|
883
|
+
const io = stubIntersectionObserver();
|
|
884
|
+
fivePageDoc();
|
|
885
|
+
|
|
886
|
+
const resourceAnchoredText = vi.fn().mockResolvedValue(SERVED_TEXT);
|
|
887
|
+
const session = {
|
|
888
|
+
client: {
|
|
889
|
+
beckon: { hover: vi.fn() },
|
|
890
|
+
browse: { resourceAnchoredText },
|
|
891
|
+
},
|
|
892
|
+
} as unknown as import('@xynolog/sdk').XynologSession;
|
|
893
|
+
|
|
894
|
+
renderInEnglish(
|
|
895
|
+
<PdfAnnotationCanvas
|
|
896
|
+
resourceUri={resourceId('res-1')}
|
|
897
|
+
pdfUrl={mockPdfUrl}
|
|
898
|
+
drawingMode={null}
|
|
899
|
+
pageLayout="scroll"
|
|
900
|
+
session={session}
|
|
901
|
+
/>,
|
|
902
|
+
);
|
|
903
|
+
await waitFor(() => {
|
|
904
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
io.fire([1, 2, 3]);
|
|
908
|
+
await waitFor(() => expect(mountedPages()).toEqual([1, 2, 3]));
|
|
909
|
+
io.fire([3, 4, 5]);
|
|
910
|
+
await waitFor(() => expect(mountedPages()).toEqual([3, 4, 5]));
|
|
911
|
+
|
|
912
|
+
expect(resourceAnchoredText).toHaveBeenCalledTimes(1);
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
test('a slot keeps its reserved height when its page mounts', async () => {
|
|
916
|
+
// Releasing the reservation on mount makes the column's total height
|
|
917
|
+
// change on every scroll — the scrollbar jumps and resizes under the
|
|
918
|
+
// cursor. The reservation must survive mounting so the column's
|
|
919
|
+
// geometry never depends on which pages are mounted.
|
|
920
|
+
const io = stubIntersectionObserver();
|
|
921
|
+
fivePageDoc();
|
|
922
|
+
|
|
923
|
+
renderInEnglish(
|
|
924
|
+
<PdfAnnotationCanvas
|
|
925
|
+
resourceUri={resourceId('res-1')}
|
|
926
|
+
pdfUrl={mockPdfUrl}
|
|
927
|
+
drawingMode={null}
|
|
928
|
+
pageLayout="scroll"
|
|
929
|
+
/>,
|
|
930
|
+
);
|
|
931
|
+
await waitFor(() => {
|
|
932
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
const slotOf = (page: number) =>
|
|
936
|
+
document.querySelector(
|
|
937
|
+
`.xynolog-pdf-annotation-canvas__slot[data-page="${page}"]`,
|
|
938
|
+
) as HTMLElement;
|
|
939
|
+
|
|
940
|
+
// Read whichever property expresses the reservation, so the pin is
|
|
941
|
+
// about the CONTRACT (space is reserved, and mounting does not release
|
|
942
|
+
// it) rather than about which CSS property implements it.
|
|
943
|
+
const reserved = (el: HTMLElement) =>
|
|
944
|
+
el.style.minHeight || el.style.height;
|
|
945
|
+
|
|
946
|
+
io.fire([1]);
|
|
947
|
+
await waitFor(() => expect(mountedPages()).toEqual([1]));
|
|
948
|
+
|
|
949
|
+
// Page 5 is unmounted and must hold space open.
|
|
950
|
+
expect(reserved(slotOf(5))).not.toBe('');
|
|
951
|
+
// Page 1 is mounted and must hold exactly the same space, or the
|
|
952
|
+
// column's height changes as pages come and go.
|
|
953
|
+
expect(reserved(slotOf(1))).toBe(reserved(slotOf(5)));
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
test('a rectangle drawn on a scrolled page carries THAT page number', async () => {
|
|
957
|
+
// The drag lives in the page view, so page identity comes from the
|
|
958
|
+
// component that owns the pixels rather than from a shared `pageNumber`
|
|
959
|
+
// — the invariant that makes a column safe to draw on at all.
|
|
960
|
+
const io = stubIntersectionObserver();
|
|
961
|
+
fivePageDoc();
|
|
962
|
+
|
|
963
|
+
const request = vi.fn();
|
|
964
|
+
const session = {
|
|
965
|
+
client: {
|
|
966
|
+
mark: { request },
|
|
967
|
+
beckon: { hover: vi.fn() },
|
|
968
|
+
browse: {
|
|
969
|
+
resourceAnchoredText: vi.fn().mockResolvedValue(SERVED_TEXT),
|
|
970
|
+
},
|
|
971
|
+
},
|
|
972
|
+
} as unknown as import('@xynolog/sdk').XynologSession;
|
|
973
|
+
|
|
974
|
+
renderInEnglish(
|
|
975
|
+
<PdfAnnotationCanvas
|
|
976
|
+
resourceUri={resourceId('res-1')}
|
|
977
|
+
pdfUrl={mockPdfUrl}
|
|
978
|
+
drawingMode="rectangle"
|
|
979
|
+
selectedMotivation="highlighting"
|
|
980
|
+
session={session}
|
|
981
|
+
pageLayout="scroll"
|
|
982
|
+
/>,
|
|
983
|
+
);
|
|
984
|
+
await waitFor(() => {
|
|
985
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
io.fire([2, 3]);
|
|
989
|
+
await waitFor(() => expect(mountedPages()).toEqual([2, 3]));
|
|
990
|
+
await waitFor(() => {
|
|
991
|
+
expect(
|
|
992
|
+
document.querySelector('.xynolog-pdf-annotation-canvas'),
|
|
993
|
+
).toHaveAttribute('data-annotate-deferred', 'false');
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
// Draw on page 3's container, not page 2's.
|
|
997
|
+
const slot3 = document.querySelector(
|
|
998
|
+
'.xynolog-pdf-annotation-canvas__slot[data-page="3"]',
|
|
999
|
+
)!;
|
|
1000
|
+
const img = slot3.querySelector(
|
|
1001
|
+
'.xynolog-pdf-annotation-canvas__image',
|
|
1002
|
+
) as HTMLImageElement;
|
|
1003
|
+
Object.defineProperty(img, 'clientWidth', {
|
|
1004
|
+
value: 612,
|
|
1005
|
+
configurable: true,
|
|
1006
|
+
});
|
|
1007
|
+
Object.defineProperty(img, 'clientHeight', {
|
|
1008
|
+
value: 792,
|
|
1009
|
+
configurable: true,
|
|
1010
|
+
});
|
|
1011
|
+
fireEvent.load(img);
|
|
1012
|
+
|
|
1013
|
+
const container = slot3.querySelector(
|
|
1014
|
+
'.xynolog-pdf-annotation-canvas__container',
|
|
1015
|
+
)!;
|
|
1016
|
+
fireEvent.mouseDown(container, { clientX: 40, clientY: 40 });
|
|
1017
|
+
fireEvent.mouseMove(container, { clientX: 200, clientY: 160 });
|
|
1018
|
+
fireEvent.mouseUp(container, { clientX: 200, clientY: 160 });
|
|
1019
|
+
|
|
1020
|
+
await waitFor(() => expect(request).toHaveBeenCalledTimes(1));
|
|
1021
|
+
expect(request.mock.calls[0][1][0].value).toContain('page=3');
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
test('annotate mode scrolls too — the primary mode is not left on the pager', async () => {
|
|
1025
|
+
// The registries are the seam: both ask for the column.
|
|
1026
|
+
const io = stubIntersectionObserver();
|
|
1027
|
+
fivePageDoc();
|
|
1028
|
+
|
|
1029
|
+
const session = {
|
|
1030
|
+
client: {
|
|
1031
|
+
beckon: { hover: vi.fn() },
|
|
1032
|
+
browse: {
|
|
1033
|
+
resourceAnchoredText: vi.fn().mockResolvedValue(SERVED_TEXT),
|
|
1034
|
+
},
|
|
1035
|
+
},
|
|
1036
|
+
} as unknown as import('@xynolog/sdk').XynologSession;
|
|
1037
|
+
|
|
1038
|
+
renderInEnglish(
|
|
1039
|
+
<PdfAnnotationCanvas
|
|
1040
|
+
resourceUri={resourceId('res-1')}
|
|
1041
|
+
pdfUrl={mockPdfUrl}
|
|
1042
|
+
drawingMode="rectangle"
|
|
1043
|
+
selectedMotivation="highlighting"
|
|
1044
|
+
session={session}
|
|
1045
|
+
pageLayout="scroll"
|
|
1046
|
+
/>,
|
|
1047
|
+
);
|
|
1048
|
+
|
|
1049
|
+
await waitFor(() => {
|
|
1050
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1051
|
+
});
|
|
1052
|
+
io.fire([1]);
|
|
1053
|
+
await waitFor(() => expect(mountedPages()).toEqual([1]));
|
|
1054
|
+
// Drawing still works in the column: the container is the page's own.
|
|
1055
|
+
await waitFor(() => {
|
|
1056
|
+
expect(
|
|
1057
|
+
document.querySelector('.xynolog-pdf-annotation-canvas__container'),
|
|
1058
|
+
).toHaveAttribute('data-drawing-mode', 'rectangle');
|
|
1059
|
+
});
|
|
1060
|
+
});
|
|
1061
|
+
|
|
1062
|
+
// A strip of proportional rectangles — one per page, current
|
|
1063
|
+
// highlighted, click to jump. Deliberately NOT thumbnails: it needs no
|
|
1064
|
+
// rasterization, only the page count and the aspect ratio the slot
|
|
1065
|
+
// reservation already uses, so it costs nothing next to the document
|
|
1066
|
+
// itself. It answers "where am I in this document", which neither the
|
|
1067
|
+
// pager nor the scrollbar does.
|
|
1068
|
+
test('renders one strip rectangle per page, marking the current one', async () => {
|
|
1069
|
+
const io = stubIntersectionObserver();
|
|
1070
|
+
fivePageDoc();
|
|
1071
|
+
|
|
1072
|
+
renderInEnglish(
|
|
1073
|
+
<PdfAnnotationCanvas
|
|
1074
|
+
resourceUri={resourceId('res-1')}
|
|
1075
|
+
pdfUrl={mockPdfUrl}
|
|
1076
|
+
drawingMode={null}
|
|
1077
|
+
pageLayout="scroll"
|
|
1078
|
+
/>,
|
|
1079
|
+
);
|
|
1080
|
+
await waitFor(() => {
|
|
1081
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
const ticks = () =>
|
|
1085
|
+
document.querySelectorAll('.xynolog-pdf-annotation-canvas__strip-page');
|
|
1086
|
+
await waitFor(() => expect(ticks()).toHaveLength(5));
|
|
1087
|
+
|
|
1088
|
+
io.fire([3, 4]);
|
|
1089
|
+
await waitFor(() => {
|
|
1090
|
+
expect(document.querySelector('[aria-current="page"]')).toHaveAttribute(
|
|
1091
|
+
'data-page',
|
|
1092
|
+
'3',
|
|
1093
|
+
);
|
|
1094
|
+
});
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
test('the strip sizes itself to the PDF viewer scrollport', async () => {
|
|
1098
|
+
const io = stubIntersectionObserver();
|
|
1099
|
+
fivePageDoc();
|
|
1100
|
+
|
|
1101
|
+
const host = document.createElement('div');
|
|
1102
|
+
document.body.appendChild(host);
|
|
1103
|
+
|
|
1104
|
+
renderInEnglish(
|
|
1105
|
+
<PdfAnnotationCanvas
|
|
1106
|
+
resourceUri={resourceId('res-1')}
|
|
1107
|
+
pdfUrl={mockPdfUrl}
|
|
1108
|
+
drawingMode={null}
|
|
1109
|
+
pageLayout="scroll"
|
|
1110
|
+
/>,
|
|
1111
|
+
{ container: host },
|
|
1112
|
+
);
|
|
1113
|
+
const viewer = host.querySelector(
|
|
1114
|
+
'.xynolog-pdf-annotation-canvas',
|
|
1115
|
+
) as HTMLElement;
|
|
1116
|
+
Object.defineProperty(viewer, 'clientHeight', {
|
|
1117
|
+
value: 513,
|
|
1118
|
+
configurable: true,
|
|
1119
|
+
});
|
|
1120
|
+
window.dispatchEvent(new Event('resize'));
|
|
1121
|
+
await waitFor(() => {
|
|
1122
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1123
|
+
expect(
|
|
1124
|
+
document.querySelectorAll(
|
|
1125
|
+
'.xynolog-pdf-annotation-canvas__strip-page',
|
|
1126
|
+
),
|
|
1127
|
+
).toHaveLength(5);
|
|
1128
|
+
});
|
|
1129
|
+
io.fire([1]);
|
|
1130
|
+
|
|
1131
|
+
const strip = document.querySelector(
|
|
1132
|
+
'.xynolog-pdf-annotation-canvas__strip',
|
|
1133
|
+
) as HTMLElement;
|
|
1134
|
+
await waitFor(() => expect(strip.style.maxHeight).toBe('513px'));
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
test('clicking a strip rectangle jumps to that page', async () => {
|
|
1138
|
+
const io = stubIntersectionObserver();
|
|
1139
|
+
fivePageDoc();
|
|
1140
|
+
const scrollIntoView = vi
|
|
1141
|
+
.spyOn(Element.prototype, 'scrollIntoView')
|
|
1142
|
+
.mockImplementation(() => {});
|
|
1143
|
+
|
|
1144
|
+
renderInEnglish(
|
|
1145
|
+
<PdfAnnotationCanvas
|
|
1146
|
+
resourceUri={resourceId('res-1')}
|
|
1147
|
+
pdfUrl={mockPdfUrl}
|
|
1148
|
+
drawingMode={null}
|
|
1149
|
+
pageLayout="scroll"
|
|
1150
|
+
/>,
|
|
1151
|
+
);
|
|
1152
|
+
await waitFor(() => {
|
|
1153
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1154
|
+
expect(
|
|
1155
|
+
document.querySelectorAll(
|
|
1156
|
+
'.xynolog-pdf-annotation-canvas__strip-page',
|
|
1157
|
+
),
|
|
1158
|
+
).toHaveLength(5);
|
|
1159
|
+
});
|
|
1160
|
+
io.fire([1]);
|
|
1161
|
+
|
|
1162
|
+
const tick4 = document.querySelector(
|
|
1163
|
+
'.xynolog-pdf-annotation-canvas__strip-page[data-page="4"]',
|
|
1164
|
+
)!;
|
|
1165
|
+
fireEvent.click(tick4);
|
|
1166
|
+
|
|
1167
|
+
expect(scrollIntoView).toHaveBeenCalled();
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
// Arrow keys step pages. The guards are the substance: a viewer that
|
|
1171
|
+
// steals arrow keys from a text field is worse than one with no shortcut.
|
|
1172
|
+
test('PageUp/PageDown step pages; Up/Down are left to scroll', async () => {
|
|
1173
|
+
// The convention every mainstream viewer follows (Preview, Chrome's PDF
|
|
1174
|
+
// viewer, Acrobat): PageUp/PageDown jump a page, Up/Down scroll finely.
|
|
1175
|
+
// Taking Up/Down would leave no keyboard way to reach the bottom of a
|
|
1176
|
+
// page taller than the viewport.
|
|
1177
|
+
const io = stubIntersectionObserver();
|
|
1178
|
+
fivePageDoc();
|
|
1179
|
+
const scrollIntoView = vi
|
|
1180
|
+
.spyOn(Element.prototype, 'scrollIntoView')
|
|
1181
|
+
.mockImplementation(() => {});
|
|
1182
|
+
|
|
1183
|
+
renderInEnglish(
|
|
1184
|
+
<PdfAnnotationCanvas
|
|
1185
|
+
resourceUri={resourceId('res-1')}
|
|
1186
|
+
pdfUrl={mockPdfUrl}
|
|
1187
|
+
drawingMode={null}
|
|
1188
|
+
pageLayout="scroll"
|
|
1189
|
+
/>,
|
|
1190
|
+
);
|
|
1191
|
+
await waitFor(() => {
|
|
1192
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1193
|
+
});
|
|
1194
|
+
io.fire([2]);
|
|
1195
|
+
await waitFor(() => expect(mountedPages()).toEqual([2]));
|
|
1196
|
+
|
|
1197
|
+
scrollIntoView.mockClear();
|
|
1198
|
+
fireEvent.keyDown(window, { key: 'PageDown' });
|
|
1199
|
+
expect(scrollIntoView).toHaveBeenCalled();
|
|
1200
|
+
|
|
1201
|
+
scrollIntoView.mockClear();
|
|
1202
|
+
fireEvent.keyDown(window, { key: 'PageUp' });
|
|
1203
|
+
expect(scrollIntoView).toHaveBeenCalled();
|
|
1204
|
+
|
|
1205
|
+
// Up/Down belong to the scroller, not to us.
|
|
1206
|
+
scrollIntoView.mockClear();
|
|
1207
|
+
fireEvent.keyDown(window, { key: 'ArrowDown' });
|
|
1208
|
+
fireEvent.keyDown(window, { key: 'ArrowUp' });
|
|
1209
|
+
expect(scrollIntoView).not.toHaveBeenCalled();
|
|
1210
|
+
|
|
1211
|
+
// The same guard as the horizontal pair: never steal from a text field.
|
|
1212
|
+
const input = document.createElement('input');
|
|
1213
|
+
document.body.appendChild(input);
|
|
1214
|
+
input.focus();
|
|
1215
|
+
scrollIntoView.mockClear();
|
|
1216
|
+
fireEvent.keyDown(input, { key: 'PageDown' });
|
|
1217
|
+
expect(scrollIntoView).not.toHaveBeenCalled();
|
|
1218
|
+
input.remove();
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1221
|
+
test('Left/Right step pages, and never steal keys from a text field', async () => {
|
|
1222
|
+
const io = stubIntersectionObserver();
|
|
1223
|
+
fivePageDoc();
|
|
1224
|
+
const scrollIntoView = vi
|
|
1225
|
+
.spyOn(Element.prototype, 'scrollIntoView')
|
|
1226
|
+
.mockImplementation(() => {});
|
|
1227
|
+
|
|
1228
|
+
renderInEnglish(
|
|
1229
|
+
<PdfAnnotationCanvas
|
|
1230
|
+
resourceUri={resourceId('res-1')}
|
|
1231
|
+
pdfUrl={mockPdfUrl}
|
|
1232
|
+
drawingMode={null}
|
|
1233
|
+
pageLayout="scroll"
|
|
1234
|
+
/>,
|
|
1235
|
+
);
|
|
1236
|
+
await waitFor(() => {
|
|
1237
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1238
|
+
});
|
|
1239
|
+
io.fire([1]);
|
|
1240
|
+
await waitFor(() => expect(mountedPages()).toEqual([1]));
|
|
1241
|
+
|
|
1242
|
+
scrollIntoView.mockClear();
|
|
1243
|
+
fireEvent.keyDown(window, { key: 'ArrowRight' });
|
|
1244
|
+
expect(scrollIntoView).toHaveBeenCalled();
|
|
1245
|
+
|
|
1246
|
+
// Typing in an input must not page the document underneath it.
|
|
1247
|
+
const input = document.createElement('input');
|
|
1248
|
+
document.body.appendChild(input);
|
|
1249
|
+
input.focus();
|
|
1250
|
+
scrollIntoView.mockClear();
|
|
1251
|
+
fireEvent.keyDown(input, { key: 'ArrowRight' });
|
|
1252
|
+
expect(scrollIntoView).not.toHaveBeenCalled();
|
|
1253
|
+
input.remove();
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
test('focus follows the current page when the strip owns focus', async () => {
|
|
1257
|
+
// Click a page in the strip, then arrow away: a focus ring that stays
|
|
1258
|
+
// behind on the clicked rectangle while the current-page marker moves
|
|
1259
|
+
// leaves two rectangles claiming to be "here". (The ring only appears
|
|
1260
|
+
// after the arrow press because that is when the browser switches to
|
|
1261
|
+
// keyboard modality and the clicked button starts matching
|
|
1262
|
+
// :focus-visible.) Focus must travel with the current page — but ONLY
|
|
1263
|
+
// when the strip already had it, so scrolling with the mouse never
|
|
1264
|
+
// snatches focus away from whatever the reader was doing.
|
|
1265
|
+
const io = stubIntersectionObserver();
|
|
1266
|
+
fivePageDoc();
|
|
1267
|
+
vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(
|
|
1268
|
+
() => {},
|
|
1269
|
+
);
|
|
1270
|
+
|
|
1271
|
+
renderInEnglish(
|
|
1272
|
+
<PdfAnnotationCanvas
|
|
1273
|
+
resourceUri={resourceId('res-1')}
|
|
1274
|
+
pdfUrl={mockPdfUrl}
|
|
1275
|
+
drawingMode={null}
|
|
1276
|
+
pageLayout="scroll"
|
|
1277
|
+
/>,
|
|
1278
|
+
);
|
|
1279
|
+
await waitFor(() => {
|
|
1280
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1281
|
+
expect(
|
|
1282
|
+
document.querySelectorAll(
|
|
1283
|
+
'.xynolog-pdf-annotation-canvas__strip-page',
|
|
1284
|
+
),
|
|
1285
|
+
).toHaveLength(5);
|
|
1286
|
+
});
|
|
1287
|
+
io.fire([1]);
|
|
1288
|
+
await waitFor(() => expect(mountedPages()).toEqual([1]));
|
|
1289
|
+
|
|
1290
|
+
const tick = (page: number) =>
|
|
1291
|
+
document.querySelector(
|
|
1292
|
+
`.xynolog-pdf-annotation-canvas__strip-page[data-page="${page}"]`,
|
|
1293
|
+
) as HTMLButtonElement;
|
|
1294
|
+
|
|
1295
|
+
tick(2).focus();
|
|
1296
|
+
fireEvent.click(tick(2));
|
|
1297
|
+
io.fire([3]);
|
|
1298
|
+
|
|
1299
|
+
await waitFor(() =>
|
|
1300
|
+
expect(tick(3)).toHaveAttribute('aria-current', 'page'),
|
|
1301
|
+
);
|
|
1302
|
+
expect(document.activeElement).toBe(tick(3));
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1305
|
+
test('the strip is one tab stop, not one per page', async () => {
|
|
1306
|
+
// A 400-page document must not put 400 stops in the tab order. The
|
|
1307
|
+
// ARIA pattern: the current item is tabbable, the rest are reachable
|
|
1308
|
+
// with arrows (which already page the document).
|
|
1309
|
+
const io = stubIntersectionObserver();
|
|
1310
|
+
fivePageDoc();
|
|
1311
|
+
vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(
|
|
1312
|
+
() => {},
|
|
1313
|
+
);
|
|
1314
|
+
|
|
1315
|
+
renderInEnglish(
|
|
1316
|
+
<PdfAnnotationCanvas
|
|
1317
|
+
resourceUri={resourceId('res-1')}
|
|
1318
|
+
pdfUrl={mockPdfUrl}
|
|
1319
|
+
drawingMode={null}
|
|
1320
|
+
pageLayout="scroll"
|
|
1321
|
+
/>,
|
|
1322
|
+
);
|
|
1323
|
+
await waitFor(() => {
|
|
1324
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1325
|
+
expect(
|
|
1326
|
+
document.querySelectorAll(
|
|
1327
|
+
'.xynolog-pdf-annotation-canvas__strip-page',
|
|
1328
|
+
),
|
|
1329
|
+
).toHaveLength(5);
|
|
1330
|
+
});
|
|
1331
|
+
io.fire([1]);
|
|
1332
|
+
|
|
1333
|
+
const tabbable = [
|
|
1334
|
+
...document.querySelectorAll(
|
|
1335
|
+
'.xynolog-pdf-annotation-canvas__strip-page',
|
|
1336
|
+
),
|
|
1337
|
+
].filter((el) => (el as HTMLElement).tabIndex === 0);
|
|
1338
|
+
expect(tabbable).toHaveLength(1);
|
|
1339
|
+
expect(tabbable[0]).toHaveAttribute('data-page', '1');
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
test('the strip runs along the same axis as the scrolling, beside the column', async () => {
|
|
1343
|
+
// Pages scroll vertically, so a horizontal strip reads across a
|
|
1344
|
+
// direction the document does not move in. The strip's axis follows the
|
|
1345
|
+
// scroll axis — which is also what would make horizontal scrolling a
|
|
1346
|
+
// change of one value rather than a second layout.
|
|
1347
|
+
const io = stubIntersectionObserver();
|
|
1348
|
+
fivePageDoc();
|
|
1349
|
+
vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(
|
|
1350
|
+
() => {},
|
|
1351
|
+
);
|
|
1352
|
+
|
|
1353
|
+
renderInEnglish(
|
|
1354
|
+
<PdfAnnotationCanvas
|
|
1355
|
+
resourceUri={resourceId('res-1')}
|
|
1356
|
+
pdfUrl={mockPdfUrl}
|
|
1357
|
+
drawingMode={null}
|
|
1358
|
+
pageLayout="scroll"
|
|
1359
|
+
/>,
|
|
1360
|
+
);
|
|
1361
|
+
await waitFor(() => {
|
|
1362
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1363
|
+
expect(
|
|
1364
|
+
document.querySelectorAll(
|
|
1365
|
+
'.xynolog-pdf-annotation-canvas__strip-page',
|
|
1366
|
+
),
|
|
1367
|
+
).toHaveLength(5);
|
|
1368
|
+
});
|
|
1369
|
+
io.fire([1]);
|
|
1370
|
+
|
|
1371
|
+
const column = document.querySelector(
|
|
1372
|
+
'.xynolog-pdf-annotation-canvas__column',
|
|
1373
|
+
)!;
|
|
1374
|
+
const strip = document.querySelector(
|
|
1375
|
+
'.xynolog-pdf-annotation-canvas__strip',
|
|
1376
|
+
)!;
|
|
1377
|
+
|
|
1378
|
+
// One axis, declared in one place, read by both.
|
|
1379
|
+
expect(column).toHaveAttribute('data-axis', 'vertical');
|
|
1380
|
+
expect(strip).toHaveAttribute('data-axis', 'vertical');
|
|
1381
|
+
// Tells assistive tech which arrow keys apply to the strip.
|
|
1382
|
+
expect(strip).toHaveAttribute('aria-orientation', 'vertical');
|
|
1383
|
+
// The strip leads: it hugs the left edge of the content, the
|
|
1384
|
+
// conventional place for a page rail (Preview, Acrobat), and the
|
|
1385
|
+
// reader's eye finds it before the page rather than after it.
|
|
1386
|
+
expect(strip.nextElementSibling).toBe(column);
|
|
1387
|
+
expect(strip.parentElement).toHaveClass(
|
|
1388
|
+
'xynolog-pdf-annotation-canvas__viewport',
|
|
1389
|
+
);
|
|
1390
|
+
});
|
|
1391
|
+
|
|
1392
|
+
test('each strip rectangle shows its page number', async () => {
|
|
1393
|
+
// At 70 pages the rectangles are indistinguishable from one another —
|
|
1394
|
+
// the strip shows position but not WHICH page, which is most of what a
|
|
1395
|
+
// reader wants from it on a long document.
|
|
1396
|
+
const io = stubIntersectionObserver();
|
|
1397
|
+
fivePageDoc();
|
|
1398
|
+
vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(
|
|
1399
|
+
() => {},
|
|
1400
|
+
);
|
|
1401
|
+
|
|
1402
|
+
renderInEnglish(
|
|
1403
|
+
<PdfAnnotationCanvas
|
|
1404
|
+
resourceUri={resourceId('res-1')}
|
|
1405
|
+
pdfUrl={mockPdfUrl}
|
|
1406
|
+
drawingMode={null}
|
|
1407
|
+
pageLayout="scroll"
|
|
1408
|
+
/>,
|
|
1409
|
+
);
|
|
1410
|
+
await waitFor(() => {
|
|
1411
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1412
|
+
expect(
|
|
1413
|
+
document.querySelectorAll(
|
|
1414
|
+
'.xynolog-pdf-annotation-canvas__strip-page',
|
|
1415
|
+
),
|
|
1416
|
+
).toHaveLength(5);
|
|
1417
|
+
});
|
|
1418
|
+
io.fire([1]);
|
|
1419
|
+
|
|
1420
|
+
const tick = (page: number) =>
|
|
1421
|
+
document.querySelector(
|
|
1422
|
+
`.xynolog-pdf-annotation-canvas__strip-page[data-page="${page}"]`,
|
|
1423
|
+
)!;
|
|
1424
|
+
expect(tick(1)).toHaveTextContent('1');
|
|
1425
|
+
expect(tick(5)).toHaveTextContent('5');
|
|
1426
|
+
|
|
1427
|
+
// The accessible name keeps the context the bare digit loses, and
|
|
1428
|
+
// still contains the visible text (WCAG 2.5.3 Label in Name).
|
|
1429
|
+
expect(tick(5)).toHaveAttribute(
|
|
1430
|
+
'aria-label',
|
|
1431
|
+
expect.stringContaining('5'),
|
|
1432
|
+
);
|
|
1433
|
+
});
|
|
1434
|
+
|
|
1435
|
+
test('zoom scales PDF pages without scaling the numbered page rail', async () => {
|
|
1436
|
+
const io = stubIntersectionObserver();
|
|
1437
|
+
fivePageDoc();
|
|
1438
|
+
|
|
1439
|
+
renderInEnglish(
|
|
1440
|
+
<PdfAnnotationCanvas
|
|
1441
|
+
resourceUri={resourceId('res-1')}
|
|
1442
|
+
pdfUrl={mockPdfUrl}
|
|
1443
|
+
drawingMode={null}
|
|
1444
|
+
pageLayout="scroll"
|
|
1445
|
+
zoom={1.75}
|
|
1446
|
+
/>,
|
|
1447
|
+
);
|
|
1448
|
+
await waitFor(() => expect(io.observedPages()).toHaveLength(5));
|
|
1449
|
+
|
|
1450
|
+
const column = document.querySelector(
|
|
1451
|
+
'.xynolog-pdf-annotation-canvas__column',
|
|
1452
|
+
) as HTMLElement;
|
|
1453
|
+
const strip = document.querySelector(
|
|
1454
|
+
'.xynolog-pdf-annotation-canvas__strip',
|
|
1455
|
+
) as HTMLElement;
|
|
1456
|
+
expect(column.style.zoom).toBe('1.75');
|
|
1457
|
+
expect(strip.style.zoom).toBe('');
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1460
|
+
test('the column does not add a second scrollbar inside the scrolling pane', async () => {
|
|
1461
|
+
// The strip and a nested column scrollbar would be two controls for one
|
|
1462
|
+
// movement. The pane the viewer sits in already scrolls (flex: 1;
|
|
1463
|
+
// min-height: 0), so the column must not declare a viewport-relative
|
|
1464
|
+
// height of its own — that produces scroll-within-scroll.
|
|
1465
|
+
const io = stubIntersectionObserver();
|
|
1466
|
+
fivePageDoc();
|
|
1467
|
+
vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(
|
|
1468
|
+
() => {},
|
|
1469
|
+
);
|
|
1470
|
+
|
|
1471
|
+
renderInEnglish(
|
|
1472
|
+
<PdfAnnotationCanvas
|
|
1473
|
+
resourceUri={resourceId('res-1')}
|
|
1474
|
+
pdfUrl={mockPdfUrl}
|
|
1475
|
+
drawingMode={null}
|
|
1476
|
+
pageLayout="scroll"
|
|
1477
|
+
/>,
|
|
1478
|
+
);
|
|
1479
|
+
await waitFor(() => {
|
|
1480
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1481
|
+
});
|
|
1482
|
+
io.fire([1]);
|
|
1483
|
+
|
|
1484
|
+
// jsdom applies no stylesheet, so assert the CONTRACT the CSS keys off:
|
|
1485
|
+
// the column declares the axis but claims no scroll role of its own.
|
|
1486
|
+
const column = document.querySelector(
|
|
1487
|
+
'.xynolog-pdf-annotation-canvas__column',
|
|
1488
|
+
)!;
|
|
1489
|
+
expect(column).toHaveAttribute('data-axis', 'vertical');
|
|
1490
|
+
expect(column).not.toHaveAttribute('data-scroller');
|
|
1491
|
+
// The strip is the one that scrolls independently, and silently.
|
|
1492
|
+
expect(
|
|
1493
|
+
document.querySelector('.xynolog-pdf-annotation-canvas__strip'),
|
|
1494
|
+
).toHaveAttribute('data-scroller', 'true');
|
|
1495
|
+
});
|
|
1496
|
+
|
|
1497
|
+
test('the indicator reports a page the reader can SEE, not a preloaded one', async () => {
|
|
1498
|
+
// The mount window deliberately reaches a viewport beyond the view
|
|
1499
|
+
// (PRELOAD_MARGIN) so pages arrive early. Deriving the current page
|
|
1500
|
+
// from that same set makes the indicator name a page that is still
|
|
1501
|
+
// off-screen — it must come from actual visibility.
|
|
1502
|
+
const io = stubIntersectionObserver();
|
|
1503
|
+
fivePageDoc();
|
|
1504
|
+
vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(
|
|
1505
|
+
() => {},
|
|
1506
|
+
);
|
|
1507
|
+
|
|
1508
|
+
renderInEnglish(
|
|
1509
|
+
<PdfAnnotationCanvas
|
|
1510
|
+
resourceUri={resourceId('res-1')}
|
|
1511
|
+
pdfUrl={mockPdfUrl}
|
|
1512
|
+
drawingMode={null}
|
|
1513
|
+
pageLayout="scroll"
|
|
1514
|
+
/>,
|
|
1515
|
+
);
|
|
1516
|
+
await waitFor(() => {
|
|
1517
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
// Pages 1-3 are within the preload window; only 3 is actually on screen.
|
|
1521
|
+
io.fire([1, 2, 3]);
|
|
1522
|
+
io.fireOnscreen([3]);
|
|
1523
|
+
|
|
1524
|
+
await waitFor(() => {
|
|
1525
|
+
expect(document.querySelector('[aria-current="page"]')).toHaveAttribute(
|
|
1526
|
+
'data-page',
|
|
1527
|
+
'3',
|
|
1528
|
+
);
|
|
1529
|
+
});
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
test("paged navigation does not carry one page's state onto the next", async () => {
|
|
1533
|
+
// A single PdfPageView reused in the paged layout as `pageNumber`
|
|
1534
|
+
// changes would keep its state across the switch: the previous page's
|
|
1535
|
+
// raster shows briefly under the new page's overlay, a drag over it
|
|
1536
|
+
// would be recorded against the new page, and a load failure sticks
|
|
1537
|
+
// forever because nothing clears it. Each page is a different thing and
|
|
1538
|
+
// must mount as one.
|
|
1539
|
+
// Reject by PAGE, not by call order: the parent also calls getPage(1)
|
|
1540
|
+
// to measure the document's shape, so a `...Once` rejection would be
|
|
1541
|
+
// consumed there and never reach the page view.
|
|
1542
|
+
const failingDoc = {
|
|
1543
|
+
numPages: 3,
|
|
1544
|
+
getPage: vi.fn((n: number) =>
|
|
1545
|
+
n === 1
|
|
1546
|
+
? Promise.reject(new Error('page 1 is broken'))
|
|
1547
|
+
: Promise.resolve(mockPage()),
|
|
1548
|
+
),
|
|
1549
|
+
};
|
|
1550
|
+
vi.mocked(loadPdfDocument).mockResolvedValueOnce(
|
|
1551
|
+
failingDoc as unknown as Awaited<ReturnType<typeof loadPdfDocument>>,
|
|
1552
|
+
);
|
|
1553
|
+
|
|
1554
|
+
renderInEnglish(
|
|
1555
|
+
<PdfAnnotationCanvas
|
|
1556
|
+
resourceUri={resourceId('res-1')}
|
|
1557
|
+
pdfUrl={mockPdfUrl}
|
|
1558
|
+
drawingMode={null}
|
|
1559
|
+
/>,
|
|
1560
|
+
);
|
|
1561
|
+
|
|
1562
|
+
await waitFor(() => {
|
|
1563
|
+
expect(
|
|
1564
|
+
document.querySelector('.xynolog-pdf-annotation-canvas__error'),
|
|
1565
|
+
).toBeInTheDocument();
|
|
1566
|
+
});
|
|
1567
|
+
|
|
1568
|
+
fireEvent.click(screen.getByRole('button', { name: /next/i }));
|
|
1569
|
+
|
|
1570
|
+
// Page 2 loads fine; the failure belonged to page 1 and must not persist.
|
|
1571
|
+
await waitFor(() => {
|
|
1572
|
+
expect(
|
|
1573
|
+
document.querySelector('.xynolog-pdf-annotation-canvas__error'),
|
|
1574
|
+
).not.toBeInTheDocument();
|
|
1575
|
+
});
|
|
1576
|
+
});
|
|
1577
|
+
|
|
1578
|
+
test('without IntersectionObserver every page mounts — degraded, not broken', async () => {
|
|
1579
|
+
// The virtualization is an optimization, not a correctness requirement.
|
|
1580
|
+
// An environment without the observer must show the whole document
|
|
1581
|
+
// rather than nothing.
|
|
1582
|
+
fivePageDoc();
|
|
1583
|
+
vi.stubGlobal('IntersectionObserver', undefined);
|
|
1584
|
+
vi.spyOn(Element.prototype, 'scrollIntoView').mockImplementation(
|
|
1585
|
+
() => {},
|
|
1586
|
+
);
|
|
1587
|
+
|
|
1588
|
+
renderInEnglish(
|
|
1589
|
+
<PdfAnnotationCanvas
|
|
1590
|
+
resourceUri={resourceId('res-1')}
|
|
1591
|
+
pdfUrl={mockPdfUrl}
|
|
1592
|
+
drawingMode={null}
|
|
1593
|
+
pageLayout="scroll"
|
|
1594
|
+
/>,
|
|
1595
|
+
);
|
|
1596
|
+
|
|
1597
|
+
await waitFor(() => {
|
|
1598
|
+
expect(
|
|
1599
|
+
document.querySelectorAll('.xynolog-pdf-annotation-canvas__image'),
|
|
1600
|
+
).toHaveLength(5);
|
|
1601
|
+
});
|
|
1602
|
+
});
|
|
1603
|
+
|
|
1604
|
+
test('the pager still works in the column, and modifiers are left alone', async () => {
|
|
1605
|
+
const io = stubIntersectionObserver();
|
|
1606
|
+
fivePageDoc();
|
|
1607
|
+
const scrollIntoView = vi
|
|
1608
|
+
.spyOn(Element.prototype, 'scrollIntoView')
|
|
1609
|
+
.mockImplementation(() => {});
|
|
1610
|
+
|
|
1611
|
+
renderInEnglish(
|
|
1612
|
+
<PdfAnnotationCanvas
|
|
1613
|
+
resourceUri={resourceId('res-1')}
|
|
1614
|
+
pdfUrl={mockPdfUrl}
|
|
1615
|
+
drawingMode={null}
|
|
1616
|
+
pageLayout="scroll"
|
|
1617
|
+
/>,
|
|
1618
|
+
);
|
|
1619
|
+
await waitFor(() => {
|
|
1620
|
+
expect(io.observedPages()).toHaveLength(5);
|
|
1621
|
+
});
|
|
1622
|
+
io.fire([3]);
|
|
1623
|
+
await waitFor(() => {
|
|
1624
|
+
expect(document.querySelector('[aria-current="page"]')).toHaveAttribute(
|
|
1625
|
+
'data-page',
|
|
1626
|
+
'3',
|
|
1627
|
+
);
|
|
1628
|
+
});
|
|
1629
|
+
|
|
1630
|
+
scrollIntoView.mockClear();
|
|
1631
|
+
fireEvent.click(screen.getByRole('button', { name: /previous/i }));
|
|
1632
|
+
expect(scrollIntoView).toHaveBeenCalled();
|
|
1633
|
+
|
|
1634
|
+
// Cmd/Ctrl/Alt + arrow belongs to the browser and the OS.
|
|
1635
|
+
scrollIntoView.mockClear();
|
|
1636
|
+
fireEvent.keyDown(window, { key: 'ArrowRight', metaKey: true });
|
|
1637
|
+
fireEvent.keyDown(window, { key: 'PageDown', ctrlKey: true });
|
|
1638
|
+
expect(scrollIntoView).not.toHaveBeenCalled();
|
|
1639
|
+
});
|
|
1640
|
+
|
|
1641
|
+
test('keeps the paged layout when no layout is requested', async () => {
|
|
1642
|
+
renderInEnglish(
|
|
1643
|
+
<PdfAnnotationCanvas
|
|
1644
|
+
resourceUri={resourceId('res-1')}
|
|
1645
|
+
pdfUrl={mockPdfUrl}
|
|
1646
|
+
drawingMode="rectangle"
|
|
1647
|
+
selectedMotivation="highlighting"
|
|
1648
|
+
/>,
|
|
1649
|
+
);
|
|
1650
|
+
|
|
1651
|
+
await waitFor(() => {
|
|
1652
|
+
expect(screen.getByText(/page 1 of 3/i)).toBeInTheDocument();
|
|
1653
|
+
});
|
|
1654
|
+
expect(
|
|
1655
|
+
document.querySelectorAll('.xynolog-pdf-annotation-canvas__slot'),
|
|
1656
|
+
).toHaveLength(0);
|
|
1657
|
+
expect(screen.getByRole('button', { name: /next/i })).toBeInTheDocument();
|
|
1658
|
+
});
|
|
1659
|
+
});
|
|
1660
|
+
|
|
1661
|
+
// The viewer chrome is translated: Previous/Next, the page indicator, and
|
|
1662
|
+
// both failure lines. The mock translation manager echoes "<namespace>.<key>",
|
|
1663
|
+
// so asserting the echo proves the string came from translations rather
|
|
1664
|
+
// than from a literal that happens to read the same in English.
|
|
1665
|
+
describe('viewer chrome', () => {
|
|
1666
|
+
const renderTranslated = (ui: React.ReactElement) =>
|
|
1667
|
+
renderInEnglish(
|
|
1668
|
+
<TranslationProvider
|
|
1669
|
+
translationManager={defaultMocks.translationManager}
|
|
1670
|
+
>
|
|
1671
|
+
{ui}
|
|
1672
|
+
</TranslationProvider>,
|
|
1673
|
+
);
|
|
1674
|
+
|
|
1675
|
+
test('takes its controls and page indicator from translations', async () => {
|
|
1676
|
+
renderTranslated(
|
|
1677
|
+
<PdfAnnotationCanvas
|
|
1678
|
+
resourceUri={resourceId('res-1')}
|
|
1679
|
+
pdfUrl={mockPdfUrl}
|
|
1680
|
+
drawingMode={null}
|
|
1681
|
+
/>,
|
|
1682
|
+
);
|
|
1683
|
+
|
|
1684
|
+
await waitFor(() => {
|
|
1685
|
+
expect(
|
|
1686
|
+
screen.getByRole('button', { name: 'PdfViewer.previous' }),
|
|
1687
|
+
).toBeInTheDocument();
|
|
1688
|
+
});
|
|
1689
|
+
expect(
|
|
1690
|
+
screen.getByRole('button', { name: 'PdfViewer.next' }),
|
|
1691
|
+
).toBeInTheDocument();
|
|
1692
|
+
expect(screen.getByText(/PdfViewer\.pageOf/)).toBeInTheDocument();
|
|
1693
|
+
expect(screen.queryByText('Previous')).not.toBeInTheDocument();
|
|
1694
|
+
expect(screen.queryByText(/^Page 1 of 3$/)).not.toBeInTheDocument();
|
|
1695
|
+
});
|
|
1696
|
+
|
|
1697
|
+
test('announces page changes — a silent indicator is invisible to a screen reader', async () => {
|
|
1698
|
+
renderTranslated(
|
|
1699
|
+
<PdfAnnotationCanvas
|
|
1700
|
+
resourceUri={resourceId('res-1')}
|
|
1701
|
+
pdfUrl={mockPdfUrl}
|
|
1702
|
+
drawingMode={null}
|
|
1703
|
+
/>,
|
|
1704
|
+
);
|
|
1705
|
+
|
|
1706
|
+
await waitFor(() => {
|
|
1707
|
+
expect(
|
|
1708
|
+
document.querySelector('.xynolog-pdf-annotation-canvas__page-info'),
|
|
1709
|
+
).toBeInTheDocument();
|
|
1710
|
+
});
|
|
1711
|
+
const indicator = document.querySelector(
|
|
1712
|
+
'.xynolog-pdf-annotation-canvas__page-info',
|
|
1713
|
+
)!;
|
|
1714
|
+
expect(indicator).toHaveAttribute('aria-live', 'polite');
|
|
1715
|
+
// The pager is a navigation landmark, not loose buttons in the page.
|
|
1716
|
+
expect(screen.getByRole('navigation')).toBeInTheDocument();
|
|
1717
|
+
});
|
|
1718
|
+
});
|
|
1719
|
+
});
|