@internetarchive/bookreader 5.0.0-12-fixsorting-8 → 5.0.0-121
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/BookReader/474.js +2 -0
- package/BookReader/474.js.map +1 -0
- package/BookReader/BookReader.css +670 -1190
- package/BookReader/bergamot-translator-worker.js +2966 -0
- package/BookReader/bergamot-translator-worker.wasm +0 -0
- package/BookReader/hypothesis/LICENSE +50 -0
- package/BookReader/hypothesis/README.md +55 -0
- package/BookReader/hypothesis/build/boot-template.js +1 -0
- package/BookReader/hypothesis/build/boot.js +1 -0
- package/BookReader/hypothesis/build/manifest.json +20 -0
- package/BookReader/hypothesis/build/scripts/annotator.bundle.js +199 -0
- package/BookReader/hypothesis/build/scripts/annotator.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/scripts/sidebar.bundle.js +811 -0
- package/BookReader/hypothesis/build/scripts/sidebar.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js +437 -0
- package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/styles/annotator.css +4 -0
- package/BookReader/hypothesis/build/styles/annotator.css.map +1 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/highlights.css +2 -0
- package/BookReader/hypothesis/build/styles/highlights.css.map +1 -0
- package/BookReader/hypothesis/build/styles/katex.min.css +3 -0
- package/BookReader/hypothesis/build/styles/katex.min.css.map +1 -0
- package/BookReader/hypothesis/build/styles/pdfjs-overrides.css +14 -0
- package/BookReader/hypothesis/build/styles/pdfjs-overrides.css.map +1 -0
- package/BookReader/hypothesis/build/styles/sidebar.css +4 -0
- package/BookReader/hypothesis/build/styles/sidebar.css.map +1 -0
- package/BookReader/hypothesis/build/styles/ui-playground.css +4 -0
- package/BookReader/hypothesis/build/styles/ui-playground.css.map +1 -0
- package/BookReader/hypothesis/package.json +126 -0
- package/BookReader/ia-bookreader.js +1886 -0
- package/BookReader/{BookReader.js.LICENSE.txt → ia-bookreader.js.LICENSE.txt} +26 -20
- package/BookReader/ia-bookreader.js.map +1 -0
- package/BookReader/icons/1up.svg +1 -12
- package/BookReader/icons/2up.svg +1 -15
- package/BookReader/icons/advance.svg +3 -26
- package/BookReader/icons/chevron-right.svg +1 -1
- package/BookReader/icons/close-circle-dark.svg +1 -1
- package/BookReader/icons/close-circle.svg +1 -1
- package/BookReader/icons/fullscreen.svg +1 -17
- package/BookReader/icons/fullscreen_exit.svg +1 -17
- package/BookReader/icons/hamburger.svg +1 -15
- package/BookReader/icons/left-arrow.svg +1 -12
- package/BookReader/icons/magnify-minus.svg +1 -16
- package/BookReader/icons/magnify-plus.svg +1 -17
- package/BookReader/icons/magnify.svg +1 -15
- package/BookReader/icons/pause.svg +1 -23
- package/BookReader/icons/play.svg +1 -22
- package/BookReader/icons/playback-speed.svg +1 -34
- package/BookReader/icons/read-aloud.svg +1 -22
- package/BookReader/icons/review.svg +3 -22
- package/BookReader/icons/slider-toggle.svg +1 -0
- package/BookReader/icons/thumbnails.svg +1 -17
- package/BookReader/icons/voice.svg +1 -0
- package/BookReader/icons/volume-full.svg +1 -22
- package/BookReader/images/BRicons.svg +5 -94
- package/BookReader/images/books_graphic.svg +1 -177
- package/BookReader/images/hypothesis.ico +0 -0
- package/BookReader/images/icon_book.svg +1 -12
- package/BookReader/images/icon_bookmark.svg +1 -12
- package/BookReader/images/icon_experiment.svg +1 -0
- package/BookReader/images/icon_gear.svg +1 -14
- package/BookReader/images/icon_hamburger.svg +1 -20
- package/BookReader/images/icon_home.svg +1 -21
- package/BookReader/images/icon_info.svg +1 -11
- package/BookReader/images/icon_one_page.svg +1 -8
- package/BookReader/images/icon_pause.svg +1 -1
- package/BookReader/images/icon_play.svg +1 -1
- package/BookReader/images/icon_playback-rate.svg +1 -15
- package/BookReader/images/icon_search_button.svg +1 -8
- package/BookReader/images/icon_share.svg +1 -9
- package/BookReader/images/icon_skip-ahead.svg +1 -6
- package/BookReader/images/icon_skip-back.svg +2 -13
- package/BookReader/images/icon_speaker.svg +1 -18
- package/BookReader/images/icon_speaker_open.svg +1 -10
- package/BookReader/images/icon_thumbnails.svg +1 -12
- package/BookReader/images/icon_toc.svg +1 -5
- package/BookReader/images/icon_two_pages.svg +1 -9
- package/BookReader/images/marker_chap-off.svg +1 -11
- package/BookReader/images/marker_chap-on.svg +1 -11
- package/BookReader/images/marker_srch-on.svg +1 -11
- package/BookReader/images/translate.svg +1 -0
- package/BookReader/images/unviewable_page.png +0 -0
- package/BookReader/jquery-3.js +2 -0
- package/BookReader/jquery-3.js.LICENSE.txt +24 -0
- package/BookReader/plugins/plugin.archive_analytics.js +1 -172
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js +1 -165
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +19 -301
- package/BookReader/plugins/plugin.chapters.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.experiments.js +3 -0
- package/BookReader/plugins/plugin.experiments.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.experiments.js.map +1 -0
- package/BookReader/plugins/plugin.iframe.js +1 -74
- package/BookReader/plugins/plugin.iframe.js.map +1 -1
- package/BookReader/plugins/plugin.iiif.js +2 -0
- package/BookReader/plugins/plugin.iiif.js.map +1 -0
- package/BookReader/plugins/plugin.resume.js +1 -368
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +2 -1385
- package/BookReader/plugins/plugin.search.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +2 -1080
- package/BookReader/plugins/plugin.text_selection.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.translate.js +3 -0
- package/BookReader/plugins/plugin.translate.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.translate.js.map +1 -0
- package/BookReader/plugins/plugin.tts.js +2 -9193
- package/BookReader/plugins/plugin.tts.js.LICENSE.txt +2 -0
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -269
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -379
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
- package/BookReader/plugins/translator-worker.js +2 -0
- package/BookReader/plugins/translator-worker.js.map +1 -0
- package/BookReader/silence.mp3 +0 -0
- package/BookReader/translator-worker.js +475 -0
- package/BookReader/webcomponents-bundle.js +3 -0
- package/BookReader/webcomponents-bundle.js.LICENSE.txt +9 -0
- package/BookReader/webcomponents-bundle.js.map +1 -0
- package/README.md +17 -4
- package/dist/esm/ia-bookreader.js +3 -0
- package/dist/esm/ia-bookreader.js.LICENSE.txt +17 -0
- package/dist/esm/ia-bookreader.js.map +1 -0
- package/dist/esm/plugins/plugin.archive_analytics.js +2 -0
- package/dist/esm/plugins/plugin.archive_analytics.js.map +1 -0
- package/dist/esm/plugins/plugin.autoplay.js +2 -0
- package/dist/esm/plugins/plugin.autoplay.js.map +1 -0
- package/dist/esm/plugins/plugin.chapters.js +2 -0
- package/dist/esm/plugins/plugin.chapters.js.map +1 -0
- package/dist/esm/plugins/plugin.experiments.js +2 -0
- package/dist/esm/plugins/plugin.experiments.js.map +1 -0
- package/dist/esm/plugins/plugin.iframe.js +2 -0
- package/dist/esm/plugins/plugin.iframe.js.map +1 -0
- package/dist/esm/plugins/plugin.iiif.js +2 -0
- package/dist/esm/plugins/plugin.iiif.js.map +1 -0
- package/dist/esm/plugins/plugin.resume.js +2 -0
- package/dist/esm/plugins/plugin.resume.js.map +1 -0
- package/dist/esm/plugins/plugin.search.js +2 -0
- package/dist/esm/plugins/plugin.search.js.map +1 -0
- package/dist/esm/plugins/plugin.text_selection.js +2 -0
- package/dist/esm/plugins/plugin.text_selection.js.map +1 -0
- package/dist/esm/plugins/plugin.translate.js +2 -0
- package/dist/esm/plugins/plugin.translate.js.map +1 -0
- package/dist/esm/plugins/plugin.tts.js +2 -0
- package/dist/esm/plugins/plugin.tts.js.map +1 -0
- package/dist/esm/plugins/plugin.url.js +2 -0
- package/dist/esm/plugins/plugin.url.js.map +1 -0
- package/dist/esm/plugins/plugin.vendor-fullscreen.js +2 -0
- package/dist/esm/plugins/plugin.vendor-fullscreen.js.map +1 -0
- package/jsconfig.json +18 -0
- package/package.json +113 -71
- package/src/BookReader/BookModel.js +92 -46
- package/src/BookReader/DragScrollable.js +233 -0
- package/src/BookReader/ImageCache.js +49 -16
- package/src/BookReader/Mode1Up.js +66 -365
- package/src/BookReader/Mode1UpLit.js +392 -0
- package/src/BookReader/Mode2Up.js +87 -1315
- package/src/BookReader/Mode2UpLit.js +786 -0
- package/src/BookReader/ModeAbstract.js +43 -0
- package/src/BookReader/ModeCoordinateSpace.js +29 -0
- package/src/BookReader/ModeSmoothZoom.js +312 -0
- package/src/BookReader/ModeThumb.js +29 -15
- package/src/BookReader/Navbar/Navbar.js +204 -84
- package/src/BookReader/PageContainer.js +120 -23
- package/src/BookReader/ReduceSet.js +2 -2
- package/src/BookReader/Toolbar/Toolbar.js +18 -40
- package/src/BookReader/events.js +3 -3
- package/src/BookReader/options.js +105 -18
- package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
- package/src/BookReader/utils/ScrollClassAdder.js +31 -0
- package/src/BookReader/utils/SelectionObserver.js +72 -0
- package/src/BookReader/utils/classes.js +1 -1
- package/src/BookReader/utils.js +136 -12
- package/src/BookReader.js +732 -1231
- package/src/BookReaderPlugin.js +52 -0
- package/src/assets/icons/magnify-minus.svg +3 -7
- package/src/assets/icons/magnify-plus.svg +3 -7
- package/src/assets/icons/slider-toggle.svg +1 -0
- package/src/assets/icons/voice.svg +1 -0
- package/src/assets/images/hypothesis.ico +0 -0
- package/src/assets/images/icon_experiment.svg +1 -0
- package/src/assets/images/translate.svg +1 -0
- package/src/assets/images/unviewable_page.png +0 -0
- package/src/assets/silence.mp3 +0 -0
- package/src/css/BookReader.scss +1 -5
- package/src/css/_BRBookmarks.scss +1 -1
- package/src/css/_BRComponent.scss +1 -1
- package/src/css/_BRicon.scss +8 -2
- package/src/css/_BRmain.scss +16 -3
- package/src/css/_BRnav.scss +74 -70
- package/src/css/_BRpages.scss +174 -42
- package/src/css/_BRsearch.scss +69 -30
- package/src/css/_BRtoolbar.scss +5 -5
- package/src/css/_TextSelection.scss +249 -25
- package/src/css/_colorbox.scss +2 -2
- package/src/css/_controls.scss +24 -7
- package/src/css/_icons.scss +8 -1
- package/src/{BookNavigator/assets → css}/button-base.js +2 -2
- package/src/css/icon_checkmark.js +9 -0
- package/src/css/sharedStyles.js +15 -0
- package/src/ia-bookreader/downloads/downloads-provider.js +81 -0
- package/src/{BookNavigator → ia-bookreader}/downloads/downloads.js +25 -5
- package/src/ia-bookreader/ia-bookreader.js +686 -0
- package/src/ia-bookreader/sharing.js +27 -0
- package/src/ia-bookreader/viewable-files.js +98 -0
- package/src/{BookNavigator → ia-bookreader}/visual-adjustments/visual-adjustments-provider.js +17 -17
- package/src/{BookNavigator → ia-bookreader}/visual-adjustments/visual-adjustments.js +75 -67
- package/src/{BookNavigator → plugins}/bookmarks/bookmark-button.js +4 -3
- package/src/{BookNavigator/assets → plugins/bookmarks}/bookmark-colors.js +1 -1
- package/src/{BookNavigator → plugins}/bookmarks/bookmark-edit.js +43 -31
- package/src/{BookNavigator → plugins}/bookmarks/bookmarks-list.js +48 -49
- package/src/{BookNavigator → plugins}/bookmarks/bookmarks-loginCTA.js +3 -3
- package/src/plugins/bookmarks/bookmarks-provider.js +63 -0
- package/src/{BookNavigator → plugins/bookmarks}/delete-modal-actions.js +1 -1
- package/src/{BookNavigator → plugins}/bookmarks/ia-bookmarks.js +117 -68
- package/src/plugins/plugin.archive_analytics.js +84 -78
- package/src/plugins/plugin.autoplay.js +99 -104
- package/src/plugins/plugin.chapters.js +323 -205
- package/src/plugins/plugin.experiments.js +375 -0
- package/src/plugins/plugin.iframe.js +36 -37
- package/src/plugins/plugin.iiif.js +147 -0
- package/src/plugins/plugin.resume.js +54 -51
- package/src/plugins/plugin.text_selection.js +464 -219
- package/src/plugins/plugin.vendor-fullscreen.js +5 -5
- package/src/plugins/search/plugin.search.js +347 -397
- package/src/{BookNavigator → plugins}/search/search-provider.js +59 -27
- package/src/{BookNavigator → plugins}/search/search-results.js +105 -76
- package/src/plugins/search/utils.js +50 -0
- package/src/plugins/search/view.js +51 -69
- package/src/plugins/translate/TranslationManager.js +164 -0
- package/src/plugins/translate/plugin.translate.js +559 -0
- package/src/plugins/tts/AbstractTTSEngine.js +78 -49
- package/src/plugins/tts/FestivalTTSEngine.js +20 -30
- package/src/plugins/tts/PageChunk.js +117 -23
- package/src/plugins/tts/PageChunkIterator.js +11 -17
- package/src/plugins/tts/WebTTSEngine.js +132 -92
- package/src/plugins/tts/plugin.tts.js +341 -351
- package/src/plugins/tts/utils.js +76 -67
- package/src/plugins/url/UrlPlugin.js +213 -0
- package/src/plugins/{plugin.url.js → url/plugin.url.js} +54 -18
- package/src/util/TextSelectionManager.js +1471 -0
- package/src/util/browserSniffing.js +42 -1
- package/src/util/cache.js +20 -0
- package/src/util/docCookies.js +21 -2
- package/src/util/dom.js +88 -0
- package/src/util/generators.js +89 -0
- package/src/util/lit.js +15 -0
- package/src/util/strings.js +11 -0
- package/.babelrc +0 -12
- package/.dependabot/config.yml +0 -6
- package/.eslintrc.js +0 -50
- package/.gitattributes +0 -2
- package/.github/ISSUE_TEMPLATE/bug.md +0 -32
- package/.github/ISSUE_TEMPLATE/feature-request.md +0 -30
- package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +0 -15
- package/.github/workflows/node.js.yml +0 -37
- package/.github/workflows/npm-publish.yml +0 -47
- package/.testcaferc.json +0 -5
- package/BookReader/BookReader.js +0 -21613
- package/BookReader/BookReader.js.map +0 -1
- package/BookReader/bookreader-component-bundle.js +0 -14497
- package/BookReader/bookreader-component-bundle.js.LICENSE.txt +0 -38
- package/BookReader/bookreader-component-bundle.js.map +0 -1
- package/BookReader/jquery-1.10.1.js +0 -108
- package/BookReader/jquery-1.10.1.js.LICENSE.txt +0 -24
- package/BookReader/plugins/plugin.menu_toggle.js +0 -369
- package/BookReader/plugins/plugin.menu_toggle.js.map +0 -1
- package/BookReader/plugins/plugin.mobile_nav.js +0 -335
- package/BookReader/plugins/plugin.mobile_nav.js.map +0 -1
- package/BookReaderDemo/BookReaderDemo.css +0 -41
- package/BookReaderDemo/BookReaderJSAdvanced.js +0 -115
- package/BookReaderDemo/BookReaderJSAutoplay.js +0 -56
- package/BookReaderDemo/BookReaderJSSimple.js +0 -55
- package/BookReaderDemo/IIIFBookReader.js +0 -207
- package/BookReaderDemo/assets/v5/Bookreader-logo-cool-grad.svg +0 -1
- package/BookReaderDemo/assets/v5/Bookreader-logo-flat.svg +0 -1
- package/BookReaderDemo/assets/v5/Bookreader-logo-hex-cool-grad.png +0 -0
- package/BookReaderDemo/assets/v5/Bookreader-logo-hex-flat.png +0 -0
- package/BookReaderDemo/assets/v5/Bookreader-logo-lines.png +0 -0
- package/BookReaderDemo/assets/v5/Bookreader-logo-lines.svg +0 -1
- package/BookReaderDemo/assets/v5/Bookreader-logo-warm.svg +0 -1
- package/BookReaderDemo/assets/v5/bookreader-logo-renders@1x.png +0 -0
- package/BookReaderDemo/assets/v5/bookreader-logo-renders@2x.png +0 -0
- package/BookReaderDemo/assets/v5/bookreader-v5-screenshot.png +0 -0
- package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
- package/BookReaderDemo/demo-advanced.html +0 -33
- package/BookReaderDemo/demo-autoplay.html +0 -38
- package/BookReaderDemo/demo-embed-iframe-src.html +0 -84
- package/BookReaderDemo/demo-embed.html +0 -26
- package/BookReaderDemo/demo-fullscreen-mobile.html +0 -36
- package/BookReaderDemo/demo-fullscreen.html +0 -33
- package/BookReaderDemo/demo-iiif.html +0 -34
- package/BookReaderDemo/demo-iiif.js +0 -26
- package/BookReaderDemo/demo-internetarchive.html +0 -74
- package/BookReaderDemo/demo-multiple.html +0 -43
- package/BookReaderDemo/demo-plugin-menu-toggle.html +0 -34
- package/BookReaderDemo/demo-preview-pages.html +0 -1092
- package/BookReaderDemo/demo-simple.html +0 -34
- package/BookReaderDemo/demo-vendor-fullscreen.html +0 -36
- package/BookReaderDemo/immersion-1up.html +0 -64
- package/BookReaderDemo/immersion-mode.html +0 -35
- package/BookReaderDemo/toggle_controls.html +0 -53
- package/BookReaderDemo/view_mode.html +0 -39
- package/BookReaderDemo/viewmode-cycle.html +0 -41
- package/CHANGELOG.md +0 -499
- package/CONTRIBUTING.md +0 -7
- package/codecov.yml +0 -17
- package/index.html +0 -31
- package/karma.conf.js +0 -23
- package/screenshot.png +0 -0
- package/scripts/postversion.js +0 -10
- package/scripts/preversion.js +0 -14
- package/scripts/version.js +0 -26
- package/src/BookNavigator/BookModel.js +0 -14
- package/src/BookNavigator/BookNavigator.js +0 -459
- package/src/BookNavigator/assets/book-loader.js +0 -27
- package/src/BookNavigator/assets/icon_checkmark.js +0 -6
- package/src/BookNavigator/assets/icon_close.js +0 -3
- package/src/BookNavigator/assets/icon_sort_ascending.js +0 -5
- package/src/BookNavigator/assets/icon_sort_descending.js +0 -5
- package/src/BookNavigator/assets/icon_sort_neutral.js +0 -5
- package/src/BookNavigator/assets/icon_volumes.js +0 -11
- package/src/BookNavigator/bookmarks/bookmarks-provider.js +0 -53
- package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
- package/src/BookNavigator/downloads/downloads-provider.js +0 -66
- package/src/BookNavigator/search/a-search-result.js +0 -55
- package/src/BookNavigator/volumes/volumes-provider.js +0 -83
- package/src/BookNavigator/volumes/volumes.js +0 -178
- package/src/BookReader/DebugConsole.js +0 -54
- package/src/BookReaderComponent/BookReaderComponent.js +0 -112
- package/src/ItemNavigator/ItemNavigator.js +0 -376
- package/src/ItemNavigator/providers/sharing.js +0 -33
- package/src/css/_MobileNav.scss +0 -194
- package/src/dragscrollable-br.js +0 -261
- package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
- package/src/plugins/plugin.mobile_nav.js +0 -287
- package/tests/BookReader/BookModel.test.js +0 -312
- package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
- package/tests/BookReader/DebugConsole.test.js +0 -25
- package/tests/BookReader/ImageCache.test.js +0 -150
- package/tests/BookReader/Mode1Up.test.js +0 -164
- package/tests/BookReader/Mode2Up.test.js +0 -247
- package/tests/BookReader/Navbar/Navbar.test.js +0 -169
- package/tests/BookReader/PageContainer.test.js +0 -115
- package/tests/BookReader/ReduceSet.test.js +0 -38
- package/tests/BookReader/Toolbar/Toolbar.test.js +0 -26
- package/tests/BookReader/utils/classes.test.js +0 -88
- package/tests/BookReader/utils.test.js +0 -109
- package/tests/BookReader.options.test.js +0 -39
- package/tests/BookReader.test.js +0 -301
- package/tests/e2e/README.md +0 -75
- package/tests/e2e/autoplay.test.js +0 -13
- package/tests/e2e/base.test.js +0 -35
- package/tests/e2e/helpers/base.js +0 -263
- package/tests/e2e/helpers/debug.js +0 -13
- package/tests/e2e/helpers/desktopSearch.js +0 -72
- package/tests/e2e/helpers/mobileSearch.js +0 -85
- package/tests/e2e/helpers/mockSearch.js +0 -93
- package/tests/e2e/helpers/rightToLeft.js +0 -29
- package/tests/e2e/ia-production/ia-prod-base.js +0 -17
- package/tests/e2e/models/BookReader.js +0 -11
- package/tests/e2e/models/Navigation.js +0 -56
- package/tests/e2e/rightToLeft.test.js +0 -20
- package/tests/e2e/viewmode.test.js +0 -37
- package/tests/karma/BookNavigator/book-navigator.test.js +0 -139
- package/tests/karma/BookNavigator/bookmarks/bookmark-edit.test.js +0 -133
- package/tests/karma/BookNavigator/bookmarks/bookmarks-list.test.js +0 -222
- package/tests/karma/BookNavigator/search/search-provider.test.js +0 -23
- package/tests/karma/BookNavigator/search/search-results.test.js +0 -240
- package/tests/karma/BookNavigator/sharing/sharing-provider.test.js +0 -40
- package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
- package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +0 -141
- package/tests/karma/BookNavigator/volumes/volumes.test.js +0 -98
- package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
- package/tests/plugins/plugin.archive_analytics.test.js +0 -23
- package/tests/plugins/plugin.autoplay.test.js +0 -52
- package/tests/plugins/plugin.chapters.test.js +0 -130
- package/tests/plugins/plugin.iframe.test.js +0 -42
- package/tests/plugins/plugin.mobile_nav.test.js +0 -66
- package/tests/plugins/plugin.resume.test.js +0 -98
- package/tests/plugins/plugin.text_selection.test.js +0 -203
- package/tests/plugins/plugin.url.test.js +0 -129
- package/tests/plugins/plugin.vendor-fullscreen.test.js +0 -65
- package/tests/plugins/search/plugin.search.test.js +0 -173
- package/tests/plugins/search/plugin.search.view.test.js +0 -106
- package/tests/plugins/tts/AbstractTTSEngine.test.js +0 -153
- package/tests/plugins/tts/FestivalTTSEngine.test.js +0 -59
- package/tests/plugins/tts/PageChunk.test.js +0 -57
- package/tests/plugins/tts/PageChunkIterator.test.js +0 -179
- package/tests/plugins/tts/WebTTSEngine.test.js +0 -126
- package/tests/plugins/tts/utils.test.js +0 -133
- package/tests/util/browserSniffing.test.js +0 -56
- package/tests/util/docCookies.test.js +0 -15
- package/tests/util/strings.test.js +0 -63
- package/tests/utils.js +0 -42
- package/webpack.config.js +0 -86
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
!function(){"use strict";var t,e,n,o,i,r,s,a,l,c,h,d,u={},f=[],p=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,g=Array.isArray;function _(t,e){for(var n in e)t[n]=e[n];return t}function m(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function b(t,o,i,r,s){var a={type:t,props:o,key:i,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==s?++n:s,__i:-1,__u:0};return null==s&&null!=e.vnode&&e.vnode(a),a}function y(t){return t.children}function w(t,e){this.props=t,this.context=e}function v(t,e){if(null==e)return t.__?v(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if(null!=(n=t.__k[e])&&null!=n.__e)return n.__e;return"function"==typeof t.type?v(t):null}function x(t){var e,n;if(null!=(t=t.__)&&null!=t.__c){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if(null!=(n=t.__k[e])&&null!=n.__e){t.__e=t.__c.base=n.__e;break}return x(t)}}function C(t){(!t.__d&&(t.__d=!0)&&o.push(t)&&!S.__r++||i!=e.debounceRendering)&&((i=e.debounceRendering)||r)(S)}function S(){
|
|
2
|
+
for(var t,n,i,r,a,l,c,h=1;o.length;)o.length>h&&o.sort(s),t=o.shift(),h=o.length,t.__d&&(i=void 0,r=void 0,a=(r=(n=t).__v).__e,l=[],c=[],n.__P&&((i=_({},r)).__v=r.__v+1,e.vnode&&e.vnode(i),T(n.__P,i,r,n.__n,n.__P.namespaceURI,32&r.__u?[a]:null,l,null==a?v(r):a,!!(32&r.__u),c),i.__v=r.__v,i.__.__k[i.__i]=i,L(l,i,c),r.__e=r.__=null,i.__e!=a&&x(i)));S.__r=0}function A(t,e,n,o,i,r,s,a,l,c,h){var d,p,_,m,w,x,C,S=o&&o.__k||f,A=e.length;for(l=function(t,e,n,o,i){var r,s,a,l,c,h=n.length,d=h,u=0;for(t.__k=new Array(i),r=0;r<i;r++)null!=(s=e[r])&&"boolean"!=typeof s&&"function"!=typeof s?("string"==typeof s||"number"==typeof s||"bigint"==typeof s||s.constructor==String?s=t.__k[r]=b(null,s,null,null,null):g(s)?s=t.__k[r]=b(y,{children:s},null,null,null):null==s.constructor&&s.__b>0?s=t.__k[r]=b(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):t.__k[r]=s,l=r+u,s.__=t,s.__b=t.__b+1,-1!=(c=s.__i=M(s,n,l,d))&&(d--,(a=n[c])&&(a.__u|=2)),null==a||null==a.__v?(-1==c&&(i>h?u--:i<h&&u++),
|
|
3
|
+
"function"!=typeof s.type&&(s.__u|=4)):c!=l&&(c==l-1?u--:c==l+1?u++:(c>l?u--:u++,s.__u|=4))):t.__k[r]=null;if(d)for(r=0;r<h;r++)null!=(a=n[r])&&0==(2&a.__u)&&(a.__e==o&&(o=v(a)),D(a,a));return o}(n,e,S,l,A),d=0;d<A;d++)null!=(_=n.__k[d])&&(p=-1==_.__i?u:S[_.__i]||u,_.__i=d,x=T(t,_,p,i,r,s,a,l,c,h),m=_.__e,_.ref&&p.ref!=_.ref&&(p.ref&&B(p.ref,null,_),h.push(_.ref,_.__c||m,_)),null==w&&null!=m&&(w=m),(C=!!(4&_.__u))||p.__k===_.__k?l=k(_,l,t,C):"function"==typeof _.type&&void 0!==x?l=x:m&&(l=m.nextSibling),_.__u&=-7);return n.__e=w,l}function k(t,e,n,o){var i,r;if("function"==typeof t.type){for(i=t.__k,r=0;i&&r<i.length;r++)i[r]&&(i[r].__=t,e=k(i[r],e,n,o));return e}t.__e!=e&&(o&&(e&&t.type&&!e.parentNode&&(e=v(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do{e=e&&e.nextSibling}while(null!=e&&8==e.nodeType);return e}function M(t,e,n,o){var i,r,s,a=t.key,l=t.type,c=e[n],h=null!=c&&0==(2&c.__u);if(null===c&&null==a||h&&a==c.key&&l==c.type)return n;if(o>(h?1:0))for(i=n-1,
|
|
4
|
+
r=n+1;i>=0||r<e.length;)if(null!=(c=e[s=i>=0?i--:r++])&&0==(2&c.__u)&&a==c.key&&l==c.type)return s;return-1}function R(t,e,n){"-"==e[0]?t.setProperty(e,null==n?"":n):t[e]=null==n?"":"number"!=typeof n||p.test(e)?n:n+"px"}function E(t,e,n,o,i){var r,s;t:if("style"==e)if("string"==typeof n)t.style.cssText=n;else{if("string"==typeof o&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||R(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||R(t.style,e,n[e])}else if("o"==e[0]&&"n"==e[1])r=e!=(e=e.replace(a,"$1")),s=e.toLowerCase(),e=s in t||"onFocusOut"==e||"onFocusIn"==e?s.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+r]=n,n?o?n.u=o.u:(n.u=l,t.addEventListener(e,r?h:c,r)):t.removeEventListener(e,r?h:c,r);else{if("http://www.w3.org/2000/svg"==i)e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=e&&"height"!=e&&"href"!=e&&"list"!=e&&"form"!=e&&"tabIndex"!=e&&"download"!=e&&"rowSpan"!=e&&"colSpan"!=e&&"role"!=e&&"popover"!=e&&e in t)try{t[e]=null==n?"":n;break t}catch(t){}
|
|
5
|
+
"function"==typeof n||(null==n||!1===n&&"-"!=e[4]?t.removeAttribute(e):t.setAttribute(e,"popover"==e&&1==n?"":n))}}function P(t){return function(n){if(this.l){var o=this.l[n.type+t];if(null==n.t)n.t=l++;else if(n.t<o.u)return;return o(e.event?e.event(n):n)}}}function T(t,n,o,i,r,s,a,l,c,h){var d,u,f,p,b,v,x,C,S,k,M,R,E,P,T,L,B,D=n.type;if(null!=n.constructor)return null;128&o.__u&&(c=!!(32&o.__u),s=[l=n.__e=o.__e]),(d=e.__b)&&d(n);t:if("function"==typeof D)try{if(C=n.props,S="prototype"in D&&D.prototype.render,k=(d=D.contextType)&&i[d.__c],M=d?k?k.props.value:d.__:i,o.__c?x=(u=n.__c=o.__c).__=u.__E:(S?n.__c=u=new D(C,M):(n.__c=u=new w(C,M),u.constructor=D,u.render=F),k&&k.sub(u),u.state||(u.state={}),u.__n=i,f=u.__d=!0,u.__h=[],u._sb=[]),S&&null==u.__s&&(u.__s=u.state),S&&null!=D.getDerivedStateFromProps&&(u.__s==u.state&&(u.__s=_({},u.__s)),_(u.__s,D.getDerivedStateFromProps(C,u.__s))),p=u.props,b=u.state,u.__v=n,f)S&&null==D.getDerivedStateFromProps&&null!=u.componentWillMount&&u.componentWillMount(),
|
|
6
|
+
S&&null!=u.componentDidMount&&u.__h.push(u.componentDidMount);else{if(S&&null==D.getDerivedStateFromProps&&C!==p&&null!=u.componentWillReceiveProps&&u.componentWillReceiveProps(C,M),n.__v==o.__v||!u.__e&&null!=u.shouldComponentUpdate&&!1===u.shouldComponentUpdate(C,u.__s,M)){for(n.__v!=o.__v&&(u.props=C,u.state=u.__s,u.__d=!1),n.__e=o.__e,n.__k=o.__k,n.__k.some((function(t){t&&(t.__=n)})),R=0;R<u._sb.length;R++)u.__h.push(u._sb[R]);u._sb=[],u.__h.length&&a.push(u);break t}null!=u.componentWillUpdate&&u.componentWillUpdate(C,u.__s,M),S&&null!=u.componentDidUpdate&&u.__h.push((function(){u.componentDidUpdate(p,b,v)}))}if(u.context=M,u.props=C,u.__P=t,u.__e=!1,E=e.__r,P=0,S){for(u.state=u.__s,u.__d=!1,E&&E(n),d=u.render(u.props,u.state,u.context),T=0;T<u._sb.length;T++)u.__h.push(u._sb[T]);u._sb=[]}else do{u.__d=!1,E&&E(n),d=u.render(u.props,u.state,u.context),u.state=u.__s}while(u.__d&&++P<25);u.state=u.__s,null!=u.getChildContext&&(i=_(_({},i),u.getChildContext())),
|
|
7
|
+
S&&!f&&null!=u.getSnapshotBeforeUpdate&&(v=u.getSnapshotBeforeUpdate(p,b)),L=d,null!=d&&d.type===y&&null==d.key&&(L=O(d.props.children)),l=A(t,g(L)?L:[L],n,o,i,r,s,a,l,c,h),u.base=n.__e,n.__u&=-161,u.__h.length&&a.push(u),x&&(u.__E=u.__=null)}catch(t){if(n.__v=null,c||null!=s)if(t.then){for(n.__u|=c?160:128;l&&8==l.nodeType&&l.nextSibling;)l=l.nextSibling;s[s.indexOf(l)]=null,n.__e=l}else{for(B=s.length;B--;)m(s[B]);N(n)}else n.__e=o.__e,n.__k=o.__k,t.then||N(n);e.__e(t,n,o)}else null==s&&n.__v==o.__v?(n.__k=o.__k,n.__e=o.__e):l=n.__e=I(o.__e,n,o,i,r,s,a,c,h);return(d=e.diffed)&&d(n),128&n.__u?void 0:l}function N(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(N)}function L(t,n,o){for(var i=0;i<o.length;i++)B(o[i],o[++i],o[++i]);e.__c&&e.__c(n,t),t.some((function(n){try{t=n.__h,n.__h=[],t.some((function(t){t.call(n)}))}catch(t){e.__e(t,n.__v)}}))}function O(t){return"object"!=typeof t||null==t||t.__b&&t.__b>0?t:g(t)?t.map(O):_({},t)}function I(n,o,i,r,s,a,l,c,h){
|
|
8
|
+
var d,f,p,_,b,y,w,x=i.props||u,C=o.props,S=o.type;if("svg"==S?s="http://www.w3.org/2000/svg":"math"==S?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),null!=a)for(d=0;d<a.length;d++)if((b=a[d])&&"setAttribute"in b==!!S&&(S?b.localName==S:3==b.nodeType)){n=b,a[d]=null;break}if(null==n){if(null==S)return document.createTextNode(C);n=document.createElementNS(s,S,C.is&&C),c&&(e.__m&&e.__m(o,a),c=!1),a=null}if(null==S)x===C||c&&n.data==C||(n.data=C);else{if(a=a&&t.call(n.childNodes),!c&&null!=a)for(x={},d=0;d<n.attributes.length;d++)x[(b=n.attributes[d]).name]=b.value;for(d in x)if(b=x[d],"children"==d);else if("dangerouslySetInnerHTML"==d)p=b;else if(!(d in C)){if("value"==d&&"defaultValue"in C||"checked"==d&&"defaultChecked"in C)continue;E(n,d,null,b,s)}for(d in C)b=C[d],"children"==d?_=b:"dangerouslySetInnerHTML"==d?f=b:"value"==d?y=b:"checked"==d?w=b:c&&"function"!=typeof b||x[d]===b||E(n,d,b,x[d],s);if(f)c||p&&(f.__html==p.__html||f.__html==n.innerHTML)||(n.innerHTML=f.__html),
|
|
9
|
+
o.__k=[];else if(p&&(n.innerHTML=""),A("template"==o.type?n.content:n,g(_)?_:[_],o,i,r,"foreignObject"==S?"http://www.w3.org/1999/xhtml":s,a,l,a?a[0]:i.__k&&v(i,0),c,h),null!=a)for(d=a.length;d--;)m(a[d]);c||(d="value","progress"==S&&null==y?n.removeAttribute("value"):null!=y&&(y!==n[d]||"progress"==S&&!y||"option"==S&&y!=x[d])&&E(n,d,y,x[d],s),d="checked",null!=w&&w!=n[d]&&E(n,d,w,x[d],s))}return n}function B(t,n,o){try{if("function"==typeof t){var i="function"==typeof t.__u;i&&t.__u(),i&&null==n||(t.__u=t(n))}else t.current=n}catch(t){e.__e(t,o)}}function D(t,n,o){var i,r;if(e.unmount&&e.unmount(t),(i=t.ref)&&(i.current&&i.current!=t.__e||B(i,null,n)),null!=(i=t.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(t){e.__e(t,n)}i.base=i.__P=null}if(i=t.__k)for(r=0;r<i.length;r++)i[r]&&D(i[r],n,o||"function"!=typeof t.type);o||m(t.__e),t.__c=t.__=t.__e=void 0}function F(t,e,n){return this.constructor(t,n)}function H(n,o,i){var r,s,a;o==document&&(o=document.documentElement),e.__&&e.__(n,o),
|
|
10
|
+
r=!1?null:o.__k,s=[],a=[],T(o,n=o.__k=function(e,n,o){var i,r,s,a={};for(s in n)"key"==s?i=n[s]:"ref"==s?r=n[s]:a[s]=n[s];if(arguments.length>2&&(a.children=arguments.length>3?t.call(arguments,2):o),"function"==typeof e&&null!=e.defaultProps)for(s in e.defaultProps)void 0===a[s]&&(a[s]=e.defaultProps[s]);return b(e,a,i,r,null)}(y,null,[n]),r||u,u,o.namespaceURI,r?null:o.firstChild?t.call(o.childNodes):null,s,r?r.__e:o.firstChild,false,a),L(s,n,a)}function V(t){function e(t){var n,o;return this.getChildContext||(n=new Set,(o={})[e.__c]=this,this.getChildContext=function(){return o},this.componentWillUnmount=function(){n=null},this.shouldComponentUpdate=function(t){this.props.value!=t.value&&n.forEach((function(t){t.__e=!0,C(t)}))},this.sub=function(t){n.add(t);var e=t.componentWillUnmount;t.componentWillUnmount=function(){n&&n.delete(t),e&&e.call(t)}}),t.children}return e.__c="__cC"+d++,e.__=t,e.Provider=e.__l=(e.Consumer=function(t,e){return t.children(e)}).contextType=e,e}t=f.slice,e={__e:function(t,e,n,o){
|
|
11
|
+
for(var i,r,s;e=e.__;)if((i=e.__c)&&!i.__)try{if((r=i.constructor)&&null!=r.getDerivedStateFromError&&(i.setState(r.getDerivedStateFromError(t)),s=i.__d),null!=i.componentDidCatch&&(i.componentDidCatch(t,o||{}),s=i.__d),s)return i.__E=i}catch(e){t=e}throw t}},n=0,w.prototype.setState=function(t,e){var n;n=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=_({},this.state),"function"==typeof t&&(t=t(_({},n),this.props)),t&&_(n,t),null!=t&&this.__v&&(e&&this._sb.push(e),C(this))},w.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),C(this))},w.prototype.render=y,o=[],r="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,s=function(t,e){return t.__v.__b-e.__v.__b},S.__r=0,a=/(PointerCapture)$|Capture$/i,l=0,c=P(!1),h=P(!0),d=0;var z,U,$,q,W=0,j=[],K=e,X=K.__b,Y=K.__r,G=K.diffed,Q=K.__c,J=K.unmount,Z=K.__;function tt(t,e){K.__h&&K.__h(U,t,W||e),W=0;var n=U.__H||(U.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function et(t){
|
|
12
|
+
return W=1,function(t,e,n){var o=tt(z++,2);if(o.t=t,!o.__c&&(o.__=[gt(void 0,e),function(t){var e=o.__N?o.__N[0]:o.__[0],n=o.t(e,t);e!==n&&(o.__N=[n,o.__[1]],o.__c.setState({}))}],o.__c=U,!U.__f)){var i=function(t,e,n){if(!o.__c.__H)return!0;var i=o.__c.__H.__.filter((function(t){return!!t.__c}));if(i.every((function(t){return!t.__N})))return!r||r.call(this,t,e,n);var s=o.__c.props!==t;return i.forEach((function(t){if(t.__N){var e=t.__[0];t.__=t.__N,t.__N=void 0,e!==t.__[0]&&(s=!0)}})),r&&r.call(this,t,e,n)||s};U.__f=!0;var r=U.shouldComponentUpdate,s=U.componentWillUpdate;U.componentWillUpdate=function(t,e,n){if(this.__e){var o=r;r=void 0,i(t,e,n),r=o}s&&s.call(this,t,e,n)},U.shouldComponentUpdate=i}return o.__N||o.__}(gt,t)}function nt(t,e){var n=tt(z++,3);!K.__s&&pt(n.__H,e)&&(n.__=t,n.u=e,U.__H.__h.push(n))}function ot(t,e){var n=tt(z++,4);!K.__s&&pt(n.__H,e)&&(n.__=t,n.u=e,U.__h.push(n))}function it(t){return W=5,rt((function(){return{current:t}}),[])}function rt(t,e){var n=tt(z++,7)
|
|
13
|
+
;return pt(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function st(t,e){return W=8,rt((function(){return t}),e)}function at(t){var e=U.context[t.__c],n=tt(z++,9);return n.c=t,e?(null==n.__&&(n.__=!0,e.sub(U)),e.props.value):t.__}function lt(){var t=tt(z++,11);if(!t.__){for(var e=U.__v;null!==e&&!e.__m&&null!==e.__;)e=e.__;var n=e.__m||(e.__m=[0,0]);t.__="P"+n[0]+"-"+n[1]++}return t.__}function ct(){for(var t;t=j.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(ut),t.__H.__h.forEach(ft),t.__H.__h=[]}catch(e){t.__H.__h=[],K.__e(e,t.__v)}}K.__b=function(t){U=null,X&&X(t)},K.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Z&&Z(t,e)},K.__r=function(t){Y&&Y(t),z=0;var e=(U=t.__c).__H;e&&($===U?(e.__h=[],U.__h=[],e.__.forEach((function(t){t.__N&&(t.__=t.__N),t.u=t.__N=void 0}))):(e.__h.forEach(ut),e.__h.forEach(ft),e.__h=[],z=0)),$=U},K.diffed=function(t){G&&G(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(1!==j.push(e)&&q===K.requestAnimationFrame||((q=K.requestAnimationFrame)||dt)(ct)),
|
|
14
|
+
e.__H.__.forEach((function(t){t.u&&(t.__H=t.u),t.u=void 0}))),$=U=null},K.__c=function(t,e){e.some((function(t){try{t.__h.forEach(ut),t.__h=t.__h.filter((function(t){return!t.__||ft(t)}))}catch(n){e.some((function(t){t.__h&&(t.__h=[])})),e=[],K.__e(n,t.__v)}})),Q&&Q(t,e)},K.unmount=function(t){J&&J(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach((function(t){try{ut(t)}catch(t){e=t}})),n.__H=void 0,e&&K.__e(e,n.__v))};var ht="function"==typeof requestAnimationFrame;function dt(t){var e,n=function(){clearTimeout(o),ht&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,35);ht&&(e=requestAnimationFrame(n))}function ut(t){var e=U,n=t.__c;"function"==typeof n&&(t.__c=void 0,n()),U=e}function ft(t){var e=U;t.__c=t.__(),U=e}function pt(t,e){return!t||t.length!==e.length||e.some((function(e,n){return e!==t[n]}))}function gt(t,e){return"function"==typeof e?e(t):e}function _t(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e)
|
|
15
|
+
;if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}class mt{constructor(){_t(this,"_listeners",void 0),this._listeners=new Map}add(t,e,n,o){t.addEventListener(e,n,o);const i=Symbol();return this._listeners.set(i,{eventTarget:t,eventType:e,listener:n,options:o}),i}remove(t){const e=this._listeners.get(t);if(e){const{eventTarget:n,eventType:o,listener:i,options:r}=e;n.removeEventListener(o,i,r),this._listeners.delete(t)}}removeAll(){this._listeners.forEach((({eventTarget:t,eventType:e,listener:n,options:o})=>{t.removeEventListener(e,n,o)})),this._listeners.clear()}}function bt(t){t.focus()}function yt(t,{autofocus:e=!1,loop:n=!0,horizontal:o=!0,vertical:i=!0,selector:r="a,button",containerVisible:s=!0,focusElement:a=bt}={}){const l=it(null),c=function(t){const e=it({callback:t,
|
|
16
|
+
call:(...t)=>e.current.callback(...t)});return e.current.callback=t,e.current.call}(a);nt((()=>{if(!s)return()=>{};if(!t.current)throw new Error("Container ref not set");const a=t.current,h=()=>{const t=Array.from(a.querySelectorAll(r)).filter((t=>null!==t.offsetParent&&!function(t){return"boolean"==typeof t.disabled&&t.disabled}(t)));return document.activeElement===a&&t.unshift(a),t},d=(t=h(),e=-1,n=!1,o)=>{e<0&&(e=t.findIndex((t=>0===t.tabIndex)))<0&&(e=0);for(const[i,r]of t.entries())r.tabIndex=i===e?0:-1,i===e&&n&&(l.current=r,c(r,o))},u=h(),f=l.current?u.indexOf(l.current):0;d(u,f,e);const p=new mt;p.add(a,"focusin",(t=>{if(t.target===a&&l.current)return void c(l.current);const n=h(),o=n.indexOf(t.target);o>=0&&d(n,o,e)})),p.add(a,"keydown",(t=>{const e=h();let r=e.findIndex((t=>0===t.tabIndex)),s=!1;o&&"ArrowLeft"===t.key||i&&"ArrowUp"===t.key?(0===r?r=n?e.length-1:r:--r,s=!0):o&&"ArrowRight"===t.key||i&&"ArrowDown"===t.key?(r===e.length-1?r=n?0:r:++r,s=!0):"Home"===t.key?(r=0,
|
|
17
|
+
s=!0):"End"===t.key&&(r=e.length-1,s=!0),s&&(d(e,r,!0,t),t.preventDefault(),t.stopPropagation())}));const g=new MutationObserver((()=>{d()}));return g.observe(a,{subtree:!0,attributes:!0,attributeFilter:["disabled"],childList:!0}),()=>{p.removeAll(),g.disconnect()}}),[e,t,c,o,n,r,i,s])}function wt(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e);if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}class vt{constructor(t){wt(this,"_target",void 0),wt(this,"_value",void 0),this._target=t,this._value=null}get current(){return this._value}set current(t){this._value=t,this._updateTarget()}get target(){return this._target}set target(t){t!==this._target&&(this._target=t,this._updateTarget())}
|
|
18
|
+
_updateTarget(){const t=this._value;"function"==typeof this._target?this._target(t):this._target&&(this._target.current=t)}}function xt(t){const e=it(new vt(t));return e.current.target=t,e.current}var Ct=0;function St(t,n,o,i,r,s){n||(n={});var a,l,c=n;if("ref"in c)for(l in c={},n)"ref"==l?a=n[l]:c[l]=n[l];var h={type:t,props:c,key:o,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ct,__i:-1,__u:0,__source:r,__self:s};if("function"==typeof t&&(a=t.defaultProps))for(l in a)void 0===c[l]&&(c[l]=a[l]);return e.vnode&&e.vnode(h),h}var At="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function kt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Mt,Rt={exports:{}};var Et,Pt=(Mt||(Mt=1,Et=Rt,function(){var t={}.hasOwnProperty;function e(){for(var t="",e=0;e<arguments.length;e++){var i=arguments[e];i&&(t=o(t,n(i)))}return t}function n(n){
|
|
19
|
+
if("string"==typeof n||"number"==typeof n)return n;if("object"!=typeof n)return"";if(Array.isArray(n))return e.apply(null,n);if(n.toString!==Object.prototype.toString&&!n.toString.toString().includes("[native code]"))return n.toString();var i="";for(var r in n)t.call(n,r)&&n[r]&&(i=o(i,r));return i}function o(t,e){return e?t?t+" "+e:t+e:t}Et.exports?(e.default=e,Et.exports=e):window.classNames=e}()),Rt.exports),Tt=kt(Pt);function Nt({children:t,classes:e,elementRef:n,active:o=!1,variant:i="raised",width:r="full",...s}){return St("div",{"data-component":"Card",...s,ref:n,className:Tt("rounded-lg border bg-white",{"shadow hover:shadow-md":"raised"===i,"shadow-md":o&&"raised"===i},{"w-full":"full"===r,"w-auto":"auto"===r},e),children:t})}function Lt({children:t,classes:e,elementRef:n,size:o="md",...i}){return St("div",{"data-component":"CardContent",...i,ref:n,className:Tt({"p-3 space-y-4":"md"===o,"p-2 space-y-3":"sm"===o,"p-4 space-y-6":"lg"===o},e),children:t})}function Ot(t){return St("svg",{
|
|
20
|
+
xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"AnnotateIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",
|
|
21
|
+
d:"M14 0a2 2 0 0 1 2 2v13a1 1 0 0 1-1.555.832l-4.262-1.757A1 1 0 0 0 9.802 14H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm-2.109 3.5h-.484l-.14.006-.122.018a.7.7 0 0 0-.2.071l-.076.054-.108.1-.097.1-1.632 1.999-.091.12-.084.129a2.6 2.6 0 0 0-.291.722l-.03.142-.027.218-.009.223v2.646l.01.086.027.08a.54.54 0 0 0 .236.236l.067.028.07.017.074.005h2.907l.074-.005.094-.025a.5.5 0 0 0 .169-.108.5.5 0 0 0 .082-.096l.029-.051.027-.081.01-.086V7.336l-.006-.073-.018-.068a.44.44 0 0 0-.124-.178.6.6 0 0 0-.103-.074l-.055-.026-.087-.024-.092-.009h-.579l-.057-.006-.054-.017a.3.3 0 0 1-.096-.07.2.2 0 0 1-.045-.078l-.004-.04.01-.043.022-.043 1.311-2.227.047-.09.037-.106a.5.5 0 0 0-.06-.394.53.53 0 0 0-.255-.22l-.084-.028-.092-.016zm-5.924 0h-.424l-.121.006-.108.018a.6.6 0 0 0-.174.071l-.067.054-.095.1-.084.1-1.429 1.999-.08.12-.096.174a2.8 2.8 0 0 0-.232.677l-.025.142-.024.218L3 7.402v2.646l.008.086.024.08a.5.5 0 0 0 .097.148q.052.055.11.088l.058.028.062.017.065.005h2.543l.065-.005.082-.025a.515.515 0 0 0 .22-.204l.025-.051.024-.081.008-.086V7.336l-.005-.073-.023-.09a.487.487 0 0 0-.191-.23l-.048-.026-.076-.024-.08-.009H5.46l-.05-.006-.047-.017a.3.3 0 0 1-.084-.07.2.2 0 0 1-.04-.078l-.003-.04.008-.043.02-.043L6.411 4.36l.04-.09.033-.106a.55.55 0 0 0-.053-.394.5.5 0 0 0-.222-.22l-.074-.028-.08-.016z"
|
|
22
|
+
})]})})}function It(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"CancelIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"m12.322 5.085-.08.087-2.828 2.827 2.829 2.83a1 1 0 0 1-1.32 1.497l-.095-.083L8 9.414l-2.828 2.829c-.915.914-2.272-.388-1.494-1.328l.08-.087L6.584 8 3.757 5.172a1 1 0 0 1 1.32-1.498l.095.083L8 6.585l2.828-2.828c.886-.885 2.188.309 1.56 1.239z"})]})})}function Bt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"CaretDownIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M3.293 5.293a1 1 0 0 1 1.32-.083l.094.083L8 8.585l3.293-3.292a1 1 0 0 1 1.32-.083l.094.083a1 1 0 0 1 .083 1.32l-.083.094-4 4a1 1 0 0 1-1.32.083l-.094-.083-4-4a1 1 0 0 1 0-1.414"
|
|
23
|
+
})]})})}function Dt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"CaretLeftIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M9.293 3.293a1 1 0 0 1 1.497 1.32l-.083.094L7.415 8l3.292 3.293a1 1 0 0 1 .083 1.32l-.083.094a1 1 0 0 1-1.32.083l-.094-.083-4-4a1 1 0 0 1-.083-1.32l.083-.094z"})]})})}function Ft(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"CaretRightIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M5.293 3.293a1 1 0 0 1 1.32-.083l.094.083 4 4a1 1 0 0 1 .083 1.32l-.083.094-4 4a1 1 0 0 1-1.497-1.32l.083-.094L8.585 8 5.293 4.707a1 1 0 0 1-.083-1.32z"})]})})}function Ht(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",
|
|
24
|
+
"aria-hidden":"true",viewBox:"0 0 16 16","data-component":"CautionIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M8 0c.767 0 1.432.455 1.794 1.148l5.917 11.326c.386.738.36 1.573.071 2.23-.286.651-.926 1.296-1.864 1.296H2.082c-.938 0-1.578-.645-1.864-1.295a2.6 2.6 0 0 1 .07-2.23L6.207 1.147C6.568.455 7.233 0 8 0m0 2.038-.021.036L2.06 13.4a.6.6 0 0 0-.012.5.3.3 0 0 0 .062.1H13.89a.3.3 0 0 0 .061-.1.6.6 0 0 0-.012-.5L8.02 2.074zm5.874 11.972q0 0 .01-.006-.01.007-.01.006m-11.748 0q0 .002-.01-.006z"}),St("path",{fill:"currentColor",d:"M8 5a1 1 0 0 1 1 1v3a1 1 0 0 1-2 0V6a1 1 0 0 1 1-1M9 12a1 1 0 1 1-2 0 1 1 0 0 1 2 0"})]})})}function Vt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"CheckIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",
|
|
25
|
+
d:"M12.18 2.427a1 1 0 0 1 1.705 1.04l-.066.106-7 10a1 1 0 0 1-1.606.045l-.07-.104-3-5A1 1 0 0 1 3.792 7.39l.065.097 2.207 3.677z"})]})})}function zt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"CheckboxIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M0 2.5A2.5 2.5 0 0 1 2.5 0h11A2.5 2.5 0 0 1 16 2.5v11a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 13.5zM2.5 1A1.5 1.5 0 0 0 1 2.5v11A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-11A1.5 1.5 0 0 0 13.5 1z","clip-rule":"evenodd"})]})})}function Ut(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"CheckboxCheckedFilledIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",
|
|
26
|
+
d:"M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2zm10.18 3.636a.75.75 0 0 0-1.044.184l-4.588 6.552-1.655-2.758-.05-.072a.75.75 0 0 0-1.236.844l2.25 3.75.053.078a.75.75 0 0 0 1.204-.034l5.25-7.5.05-.08a.75.75 0 0 0-.234-.964","clip-rule":"evenodd"})]})})}function $t(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"HideIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"m1.613.21.094.083 14 14a1 1 0 0 1-1.32 1.497l-.094-.083-14-14A1 1 0 0 1 1.613.21m.583 4.845a1 1 0 0 1 .292 1.384C2.165 6.935 2 7.46 2 8c0 2.123 2.628 4 6 4q.33 0 .657-.024a1 1 0 0 1 .147 1.994Q8.405 14 8 14c-4.36 0-8-2.6-8-6 0-.937.283-1.84.812-2.653a1 1 0 0 1 1.384-.292M16 8c0-3.4-3.64-6-8-6q-.405 0-.804.03a1 1 0 1 0 .147 1.994Q7.668 4 8 4c3.372 0 6 1.877 6 4 0 .539-.165 1.065-.488 1.561a1 1 0 1 0 1.676 1.092C15.718 9.84 16 8.937 16 8"})]})})}
|
|
27
|
+
function qt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"HighlightIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M13 1a1 1 0 0 0-1-1h-2l-.117.007a1 1 0 0 0-.75 1.493A1 1 0 0 0 9 2v6l.009.134a1 1 0 0 0 .125.365.996.996 0 0 0 .374 1.37A1 1 0 0 0 9.5 10v2l.006.114c.087.814 1.098 1.196 1.701.593l1-1 .087-.099A1 1 0 0 0 12.5 11l.001-1.134a1 1 0 0 0 .365-1.366A1 1 0 0 0 13 8V2l-.009-.134a1 1 0 0 0-.125-.365A1 1 0 0 0 13 1m0 14a1 1 0 0 0-1-1H1l-.117.007A1 1 0 0 0 1 16h11l.117-.007A1 1 0 0 0 13 15"})]})})}function Wt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","data-component":"MenuCollapseIcon",...t,children:St("path",{fill:"currentColor",d:"m8.54 4.205 6.23 5.87a.69.69 0 0 1 0 1.03l-.72.68a.8.8 0 0 1-1.09 0L8 7.135l-4.96 4.65a.8.8 0 0 1-1.09 0l-.73-.69a.69.69 0 0 1 0-1.02l6.24-5.87a.8.8 0 0 1 1.08 0"})
|
|
28
|
+
})}function jt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16","data-component":"MenuExpandIcon",...t,children:St("path",{fill:"currentColor",d:"M7.456 11.788 1.226 5.92a.695.695 0 0 1 0-1.025l.726-.684a.804.804 0 0 1 1.087-.001L8 8.861l4.961-4.65a.804.804 0 0 1 1.087.001l.727.684c.3.283.3.742 0 1.025l-6.23 5.867a.804.804 0 0 1-1.09 0z"})})}function Kt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"NoteIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M14 0a2 2 0 0 1 1.995 1.85L16 2v7a1 1 0 0 1-.31.724l-.09.076-8 6a1 1 0 0 1-.471.192L7 16H2a2 2 0 0 1-1.995-1.85L0 14V2A2 2 0 0 1 1.85.005L2 0zm0 2H2v12h4V9a1 1 0 0 1 .883-.993L7 8h7zm-6 8h4l-4 3z"})]})})}function Xt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16",
|
|
29
|
+
"data-component":"PinIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M3 1a1 1 0 0 1 1-1h8a1 1 0 1 1 0 2 .5.5 0 0 0-.5.5v.146a.5.5 0 0 0 .053.224l1.341 2.683c.07.139.106.292.106.447v3a1 1 0 0 1-1 1H9.024l.093 4.977a1 1 0 0 1-2 .046L7.024 10H4a1 1 0 0 1-1-1V6a1 1 0 0 1 .106-.447L4.447 2.87a.5.5 0 0 0 .053-.224V2.5A.5.5 0 0 0 4 2a1 1 0 0 1-1-1m4 1a.5.5 0 0 0-.5.5V3a1 1 0 0 1-.106.447L5.053 6.13A.5.5 0 0 0 5 6.355V7.5a.5.5 0 0 0 .5.5h5a.5.5 0 0 0 .5-.5V6.354a.5.5 0 0 0-.053-.224L9.606 3.448A1 1 0 0 1 9.5 3v-.5A.5.5 0 0 0 9 2z","clip-rule":"evenodd"})]})})}function Yt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"9","data-component":"PointerDownIcon",...t,children:St("path",{stroke:"currentColor",d:"m15.5 0-7 8-8-8"})})}function Gt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"9","data-component":"PointerUpIcon",...t,children:St("path",{stroke:"currentColor",
|
|
30
|
+
d:"m.5 9 7-8 8 8"})})}function Qt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"RadioIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8","clip-rule":"evenodd"})]})})}function Jt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"RadioCheckedIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8","clip-rule":"evenodd"}),St("path",{fill:"currentColor",d:"M14 8A6 6 0 1 1 2 8a6 6 0 0 1 12 0"})]})})}function Zt(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16",
|
|
31
|
+
"data-component":"SelectionIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M2.5 0h-1A1.5 1.5 0 0 0 0 1.5v1a1.5 1.5 0 0 0 1 1.415v8.17A1.5 1.5 0 0 0 0 13.5v1A1.5 1.5 0 0 0 1.5 16h1a1.5 1.5 0 0 0 1.415-1h8.17a1.5 1.5 0 0 0 1.415 1h1a1.5 1.5 0 0 0 1.5-1.5v-1a1.5 1.5 0 0 0-1-1.415v-8.17A1.5 1.5 0 0 0 16 2.5v-1A1.5 1.5 0 0 0 14.5 0h-1a1.5 1.5 0 0 0-1.415 1h-8.17A1.5 1.5 0 0 0 2.5 0m9.585 13c.151-.426.489-.764.915-.915v-8.17A1.5 1.5 0 0 1 12.085 3h-8.17c-.151.426-.489.764-.915.915v8.17c.426.151.764.489.915.915zM1 1.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zM1.5 13a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5zM13 1.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5zm.5 11.5a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h1a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5z","clip-rule":"evenodd"})]})})}function te(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",
|
|
32
|
+
width:"16",height:"16","aria-hidden":"true",viewBox:"0 0 16 16","data-component":"ShowIcon",...t,children:St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor",d:"M8 2c4.36 0 8 2.6 8 6s-3.64 6-8 6-8-2.6-8-6 3.64-6 8-6m0 2C4.628 4 2 5.877 2 8s2.628 4 6 4 6-1.877 6-4-2.628-4-6-4m2 4a2 2 0 1 0-4 0 2 2 0 0 0 4 0"})]})})}function ee({children:t,classes:e,elementRef:n,expanded:o,pressed:i,title:r,icon:s,size:a="md",variant:l="secondary",unstyled:c=!1,role:h,...d}){const u=!c,f=u&&"custom"!==l,p=u&&"custom"!==a,g={"aria-label":r};return"tab"===h?g["aria-selected"]=i:(g["aria-pressed"]=i,g["aria-expanded"]=o),St("button",{role:null!=h?h:"button","data-component":"Button",type:"button",...g,...d,className:Tt({"focus-visible:ring focus-visible:outline-none transition-colors whitespace-nowrap flex items-center":u},f&&{"font-semibold rounded":!0,
|
|
33
|
+
"text-grey-7 bg-grey-1 enabled:hover:text-grey-9 enabled:hover:bg-grey-2 aria-pressed:text-grey-9 aria-expanded:text-grey-9":"secondary"===l,"text-grey-1 bg-grey-7 enabled:hover:bg-grey-8 disabled:text-grey-4":"primary"===l},p&&{"p-2 gap-x-2":"md"===a,"p-1 gap-x-1":"xs"===a,"p-1.5 gap-x-1.5":"sm"===a,"p-2.5 gap-x-1.5":"lg"===a},e),ref:n,title:r,children:[s&&St(s,{className:"w-em h-em"}),t]})}V({}),V({});const ne=Tt("input-group:border input-group:rounded-none","input-group:first:rounded-l input-group:last:rounded-r","input-group:ml-[-1px] input-group:first:ml-0","focus:z-1");function oe({children:t,classes:e,elementRef:n,pressed:o,expanded:i,icon:r,size:s="md",title:a,variant:l="secondary",unstyled:c=!1,...h}){const d=!c;return St(ee,{"data-component":"IconButton",...h,classes:Tt({"focus-visible:ring focus-visible:outline-none transition-colors rounded whitespace-nowrap":d,"flex items-center justify-center":d},d&&ne,d&&"custom"!==l&&{
|
|
34
|
+
"text-grey-7 bg-transparent enabled:hover:text-grey-9 aria-pressed:text-brand aria-expanded:text-brand":"secondary"===l,"text-brand bg-transparent enabled:hover:text-grey-9 disabled:text-grey-7":"primary"===l,"text-grey-7 bg-grey-2 enabled:hover:text-grey-9 enabled:hover:bg-grey-3 disabled:text-grey-5 aria-pressed:bg-grey-3 aria-expanded:bg-grey-3":"dark"===l},d&&"custom"!==s&&{"gap-x-2 touch:min-w-touch-minimum touch:min-h-touch-minimum":!0,"p-2":"md"===s,"p-1":"xs"===s,"p-1.5":"sm"===s,"p-2.5":"lg"===s},e),elementRef:n,title:a,pressed:o,expanded:i,unstyled:!0,children:[r&&St(r,{className:"w-em h-em"}),t]})}function ie({children:t,elementRef:e,containerRef:n,checked:o,icon:i,checkedIcon:r,disabled:s,onChange:a,id:l,type:c,containerClasses:h,...d}){const u=o?r:i;return St("label",{className:Tt("relative flex items-center gap-x-1.5",{"cursor-pointer":!s,"opacity-70":s},h),htmlFor:l,"data-composite-component":"checkbox"===c?"Checkbox":"RadioButton",ref:n,children:[St("input",{...d,type:c,ref:e,
|
|
35
|
+
className:Tt("peer","absolute w-em h-em","opacity-[.00001]",{"cursor-pointer":!s}),checked:o,disabled:s,id:l,onChange:a}),St(u,{className:Tt("peer-focus-visible:ring","w-em h-em","min-w-min min-h-min")}),St("span",{children:t})]})}function re({checked:t,defaultChecked:e=!1,icon:n=zt,checkedIcon:o=Ut,onChange:i,...r}){const s="boolean"==typeof t,[a,l]=et(e);return St(ie,{icon:n,checkedIcon:o,type:"checkbox",checked:s?t:a,onChange:function(t){null==i||i.call(this,t),s||l(t.target.checked)},...r})}const se=V(null);function ae({value:t,children:e,subtitle:n,disabled:o}){const i=at(se);if(!i)throw new Error("RadioGroup.Radio can only be used as RadioGroup child");const{selected:r,disabled:s=o,onChange:a}=i,l=!s&&r===t;return St("div",{role:"radio","aria-checked":l,"aria-disabled":s,className:Tt("focus-visible:ring focus-visible:outline-none rounded-lg px-3 py-2 flex-1 group",{"hover:bg-grey-3/25 aria-checked:bg-grey-3/50 cursor-pointer":!s,"opacity-70":s}),"data-value":t,onClick:s?void 0:()=>a(t),
|
|
36
|
+
onKeyDown:s?void 0:e=>{["Enter"," "].includes(e.key)&&(e.preventDefault(),a(t))},tabIndex:-1,children:[St("div",{className:"flex items-center gap-x-1.5",children:[St(l?Jt:Qt,{}),St("span",{className:Tt("flex items-center gap-x-1.5",{"text-grey-7 group-hover:text-grey-8 group-aria-checked:text-grey-8":!s}),children:e})]}),n&&St("div",{className:Tt("pl-4 ml-1.5 mt-1 text-sm",{"text-grey-6 group-hover:text-grey-7 group-aria-checked:text-grey-7":!s}),children:n})]})}ae.displayName="RadioGroup.Radio",Object.assign((function({direction:t="horizontal",children:e,selected:n,onChange:o,disabled:i,"aria-label":r,"aria-labelledby":s,name:a}){const l=it(null);return yt(l,{loop:!1,selector:'[role="radio"]:not([aria-disabled="true"])',focusElement:t=>{o(t.dataset.value),t.focus()}}),St(se.Provider,{value:{selected:n,disabled:i,onChange:o},children:[St("div",{"aria-label":r,"aria-labelledby":s,ref:l,role:"radiogroup",className:Tt("w-full flex gap-1.5",{"flex-col":"vertical"===t}),children:e}),a&&St("input",{type:"hidden",
|
|
37
|
+
"data-testid":"hidden-input",name:a,value:n,disabled:i})]})}),{Radio:ae,displayName:"RadioGroup"});const le=3,ce=8;function he(t,e,n,o,i){nt((()=>{if(!i)return()=>{};const e=t.current,o=t=>{"open"===t.oldState&&"closed"===t.newState&&n()};return e.addEventListener("toggle",o),()=>e.removeEventListener("toggle",o)}),[i,n,t]);const r=o&&!i;!function(t,e,{enabled:n=!0}={}){nt((()=>{if(!n)return()=>{};const o=document.body,i=new mt,r=n=>{t.current&&!n.composedPath().includes(t.current)&&e(n)};return i.add(o,"mousedown",r),i.add(o,"click",r),()=>{i.removeAll()}}),[t,n,e])}(t,(t=>{t.composedPath().includes(e.current)||n()}),{enabled:r}),function(t,e,{enabled:n=!0}={}){nt((()=>{if(!n)return()=>{};const o=document.body,i=new mt;return i.add(o,"keydown",(n=>{t.includes(n.key)&&e(n)})),()=>{i.removeAll()}}),[n,e,t])}(["Escape"],n,{enabled:r})}
|
|
38
|
+
function de({anchorElementRef:t,children:e,open:n,onClose:o,align:i="left",placement:r="below",arrow:s=!1,classes:a,variant:l="panel",onScroll:c,elementRef:h,asNativePopover:d=HTMLElement.prototype.hasOwnProperty("popover")}){const u=xt(h),f=function(t,e,{open:n,asNativePopover:o,alignToRight:i,placement:r,arrow:s}){const[a,l]=et(r),c=st((()=>{const n=t.current,a=e.current,c=t=>{Object.assign(n.style,t);const e=Object.keys(t);return()=>e.map((t=>n.style[t]=""))},h=window.innerHeight,{top:d,bottom:u,left:f,height:p,width:g}=a.getBoundingClientRect(),_=h-u,{height:m,width:b}=n.getBoundingClientRect(),y="above"===r&&(d>m||_<d)||"below"===r&&_<m&&d>_;l(y?"above":"below");const w=s?le+8:le;if(!o)return c(y?{bottom:"100%",marginBottom:`${w}px`}:{top:"100%",marginTop:`${w}px`});const{top:v,width:x}=document.body.getBoundingClientRect(),C=Math.abs(v),S=(i?f+g:x-f)-ce;let A=f;return b>S?A=i?ce:A-(b-S):i&&b>g&&(A-=b-g),c({minWidth:`${g}px`,top:y?C+d-m-w+"px":`${C+d+p+w}px`,left:`${Math.max(ce,A)}px`})}),[t,e,r,s,o,i])
|
|
39
|
+
;return ot((()=>{if(!n)return()=>{};const e=t.current;o&&e.togglePopover(!0);const i=c();if(!o)return i;const r=new mt;r.add(document.body,"scroll",c,{capture:!0});const s=new ResizeObserver(c);return s.observe(e),()=>{o&&(null==e||e.togglePopover(!1)),i(),r.removeAll(),s.disconnect()}}),[c,o,n,t]),a}(u,t,{open:n,placement:r,arrow:s,alignToRight:"right"===i,asNativePopover:d});return he(u,t,o,n,d),function({popoverRef:t,open:e}){ot((()=>{const n=t.current,o=e?document.activeElement:null;return n&&o?()=>{const t=document.activeElement;t&&!n.contains(t)&&t!==document.body||o.focus()}:()=>{}}),[t,e])}({open:n,popoverRef:u}),St("div",{className:Tt("absolute z-5","panel"===l&&["max-h-80 ","rounded border bg-white shadow hover:shadow-md focus-within:shadow-md",!s&&"overflow-y-auto overflow-x-hidden"],s&&"overflow-visible",d&&["max-w-[calc(100%-16px)]","p-0 m-0"],!d&&{hidden:!n,"right-0":"right"===i,"min-w-full":!0},a),ref:u,popover:d&&"auto",onScroll:c,"data-testid":"popover","data-component":"Popover",
|
|
40
|
+
children:[n&&s&&St("div",{className:Tt("absolute z-10","fill-white text-grey-3",{"top-full":"above"===f,"bottom-full":"below"===f,"left-2":"left"===i,"right-2":"right"===i}),"data-testid":"arrow",children:St("below"===f?Gt:Yt,{})}),n&&e]})}const ue=V(null);function fe(t,e){return"function"==typeof t?t(e):t}function pe({value:t,children:e,disabled:n=!1,classes:o,elementRef:i,title:r}){const s=it(null),a=it(null),l=xt(i),c=t=>t.target===s.current||t.target===a.current,h=at(ue);if(!h)throw new Error("Select.Option can only be used as Select or MultiSelect child");const{selectValue:d,value:u,multiple:f}=h,p=rt((()=>!n&&(f?u.includes(t)||0===u.length&&void 0===t:u===t)),[u,n,f,t]),g=st((()=>{const e={closeListbox:!0};d(f?void 0!==t?[t]:[]:t,e)}),[f,d,t]),_=st((()=>{if(!f)return;const e={closeListbox:void 0===t};if(void 0===t)return void d([],e);const n=u.indexOf(t);if(-1===n)d([...u,t],e);else{const t=[...u];t.splice(n,1),d(t,e)}}),[u,f,d,t]);return St("li",{
|
|
41
|
+
className:Tt("w-full ring-inset outline-none rounded-none select-none","px-1 mb-1 first:mt-1 whitespace-nowrap group",{"text-grey-4":n,"cursor-pointer":!n},o),onClick:t=>{n||c(t)||g()},onKeyDown:t=>{n||(["Enter"," "].includes(t.key)&&!c(t)?(t.preventDefault(),g()):s.current&&"ArrowRight"===t.key&&(t.preventDefault(),s.current.focus()))},role:"option","aria-disabled":n,"aria-selected":p,tabIndex:p?0:-1,ref:l,title:r,children:St("div",{className:Tt("flex justify-between items-center","w-full rounded",{"hover:bg-grey-1 group-focus-visible:ring":!n,"bg-grey-1 hover:bg-grey-2":p}),children:[St("div",{className:Tt("py-2 pl-3",{truncate:"truncate"===h.listboxOverflow,"whitespace-normal":"wrap"===h.listboxOverflow}),children:fe(e,{selected:p,disabled:n})}),!f&&St("div",{className:"px-3",children:St(Vt,{className:Tt("text-grey-6 scale-125",{"opacity-0":!p})})}),f&&St(re,{containerClasses:Tt("self-stretch px-3","text-lg",{"text-grey-6":p,"text-grey-3 hover:text-grey-6":!p}),checked:p,checkedIcon:Ut,elementRef:s,
|
|
42
|
+
containerRef:a,onChange:_,onKeyDown:t=>{var e;"ArrowLeft"===t.key&&(t.preventDefault(),null===(e=l.current)||void 0===e||e.focus())}})]})})}function ge({buttonContent:t,value:e,onChange:n,children:o,disabled:i,elementRef:r,buttonId:s,buttonClasses:a,popoverClasses:l,containerClasses:c,onPopoverScroll:h,alignListbox:d="left",multiple:u,listboxOverflow:f="truncate","aria-label":p,"aria-labelledby":g,listboxAsPopover:_}){const m=it(null),b=it(null),[y,w]=et(!1),v=st((()=>w(!1)),[w]),x=lt(),C=xt(r),S=lt(),A=st(((t,e)=>{n(t),e.closeListbox&&v()}),[n,v]);return function(t,e,{enabled:n=!0}={}){nt((()=>{if(!n||!t.current)return()=>{};const o=new mt;return o.add(t.current,"focusout",(n=>{const o=n;t.current&&!t.current.contains(o.relatedTarget)&&e(o)})),()=>{o.removeAll()}}),[t,n,e])}(m,v),yt(b,{horizontal:!1,loop:!1,autofocus:!0,containerVisible:y,selector:'[role="option"]:not([aria-disabled="true"])'}),St("div",{className:Tt("relative w-full border rounded",{"border-grey-5":y},ne,c),ref:m,children:[St("button",{
|
|
43
|
+
id:null!=s?s:S,className:Tt("focus-visible:ring focus-visible:outline-none transition-colors whitespace-nowrap","w-full flex items-center justify-between gap-x-2","bg-grey-0 disabled:bg-grey-1 disabled:text-grey-6","text-left","rounded-[inherit]",a),type:"button",role:"combobox",disabled:i,"aria-expanded":y,"aria-haspopup":"listbox","aria-controls":x,"aria-label":p,"aria-labelledby":g,ref:C,onClick:()=>w((t=>!t)),onKeyDown:t=>{"ArrowDown"!==t.key||y||(t.preventDefault(),w(!0))},"data-testid":"select-toggle-button",children:[St("div",{className:"pl-2 py-2 truncate grow",children:t}),St("div",{className:"pr-2 py-2 text-grey-6",children:St(y?Wt:jt,{})})]}),St(ue.Provider,{value:{value:e,selectValue:A,multiple:u,listboxOverflow:f},children:St(de,{anchorElementRef:m,open:y,onClose:v,asNativePopover:_,align:d,classes:l,onScroll:h,children:St("ul",{role:"listbox",id:x,ref:b,"aria-multiselectable":u,"aria-labelledby":null!=s?s:S,"aria-orientation":"vertical",children:o})})})]})}
|
|
44
|
+
function _e({children:t,classes:e,elementRef:n,icon:o,status:i="notice",size:r="md",variant:s="outlined",unstyled:a=!1,...l}){const c=!a,h=c&&"custom"!==s,d=c&&"custom"!==r;let u=o;if(!u)switch(i){case"success":u=Vt;break;case"error":u=It;break;default:u=Ht}const f=h&&d;return St("div",{"data-component":"Callout",...l,ref:n,className:Tt(c&&"flex items-center border",h&&{"rounded border":!0,"shadow hover:shadow-md cursor-pointer":"raised"===s,"border-yellow-notice":"notice"===i,"border-green-success":"success"===i,"border-red-error":"error"===i},h&&{"bg-yellow-notice":"notice"===i&&f,"bg-green-success":"success"===i&&f,"bg-red-error":"error"===i&&f,"bg-white":!f},e),children:[f&&St("div",{className:Tt({"p-2":"md"===r,"p-1.5":"sm"===r,"p-3":"lg"===r}),children:St(u,{"data-testid":"callout-icon",className:Tt("text-white",{"w-[1.25em] h-[1.25em]":"md"===r,"w-[0.85em] h-[0.85em]":"sm"===r,"w-[1.5em] h-[1.5em]":"lg"===r})})}),St("div",{className:Tt(d&&{"p-2":"md"===r,"py-1.5 px-2":"sm"===r,"p-3":"lg"===r
|
|
45
|
+
},c&&"grow",h&&"bg-white rounded-r"),children:t})]})}function me({message:t,onDismiss:e}){return St(_e,{classes:Tt({"sr-only":t.visuallyHidden}),status:t.type,onClick:()=>e(t.id),variant:"raised",children:t.message})}pe.displayName="Select.Option",Object.assign((function(t){return ge({...t,multiple:!1})}),{Option:pe,displayName:"Select"}),Object.assign((function(t){return ge({...t,multiple:!0})}),{Option:pe,displayName:"MultiSelect"}),V({}),V(null);const be=({direction:t,onTransitionEnd:e,children:n,transitionClasses:o={}})=>{const i="out"===t,r=it(null),s=rt((()=>{const{transitionIn:t="animate-fade-in",transitionOut:e="animate-fade-out"}=o;return{[t]:!i,[e]:i}}),[i,o]);return St("div",{"data-testid":"animation-container",onAnimationEnd:n=>{n.target===r.current&&(null==e||e(null!=t?t:"in"))},ref:r,className:Tt("relative w-full container",s),children:n})};function ye({messages:t,onMessageDismiss:e,transitionClasses:n,setTimeout_:o=setTimeout}){
|
|
46
|
+
const[i,r]=et([]),s=it(new Map),a=st((t=>r((e=>[...e,t]))),[]),l=st((t=>{const e=o((()=>{a(t),s.current.delete(t)}),5e3);s.current.set(t,e)}),[a,o]),c=st(((t,n)=>{var o;const i=null===(o=n.autoDismiss)||void 0===o||o;"in"===t&&i&&l(n.id),"out"===t&&(e(n.id),r((t=>t.filter((t=>t!==n.id)))))}),[l,e]);return ot((()=>{const t=s.current;return()=>{t.forEach((t=>clearTimeout(t)))}}),[]),St("ul",{"aria-live":"polite","aria-relevant":"additions",className:"w-full space-y-2","data-component":"ToastMessages",children:t.map((t=>{const e=i.includes(t.id);return St("li",{className:Tt({"mb-2":!t.visuallyHidden}),children:St(be,{direction:e?"out":"in",onTransitionEnd:e=>c(e,t),transitionClasses:n,children:St(me,{message:t,onDismiss:a})})},t.id)}))})}function we({children:t,classes:e,elementRef:n,underline:o="none",unstyled:i=!1,variant:r="brand",...s}){const a=!i;return St("a",{"data-component":"Link",rel:"noopener noreferrer",...s,className:Tt(a&&{"focus-visible:ring focus-visible:outline-none rounded":!0,
|
|
47
|
+
"no-underline hover:no-underline":"none"===o,"underline hover:underline":"always"===o,"no-underline hover:underline":"hover"===o},a&&"custom"!==r&&{"text-brand hover:text-brand-dark":"brand"===r,"text-color-text-light hover:text-brand":"text-light"===r,"text-color-text hover:text-brand-dark":"text"===r},e),ref:n,children:t})}function ve({children:t,classes:e,elementRef:n,expanded:o,pressed:i,title:r,direction:s,...a}){return St(ee,{"data-component":"PointerButton",...a,elementRef:n,classes:Tt("relative w-[26px] h-[16px]","flex items-center justify-center","bg-white rounded-[4px] border","before:absolute before:border-transparent","after:absolute after:border-transparent","text-[10px] text-color-text-light leading-none font-semibold",{"shadow-[1px_1px_1px_rgba(0,0,0,0.1)]":"down"!==s,"shadow-[1px_0px_1px_rgba(0,0,0,0.1)]":"down"===s},{"rounded-r-[4px] rounded-l-[2px]":"left"===s,"before:right-full before:top-1/2 after:right-full after:top-1/2":"left"===s,
|
|
48
|
+
"before:mt-[-8px] before:border-8 before:border-r-[5px] before:border-r-grey-3":"left"===s,"after:mt-[-7px] after:border-[7px] after:border-r-[4px] after:border-r-white":"left"===s},{"z-1 rounded-t-px-sm rounded-b-px":"up"===s,"before:top-auto before:left-1/2 before:bottom-full after:top-auto after:left-1/2 after:bottom-full":"up"===s,"before:ml-[-13px] before:border-[13px] before:border-b-[6px] before:border-b-grey-3":"up"===s,"after:ml-[-12px] after:border-[12px] after:border-b-[5px] after:border-b-white":"up"===s},{"z-1 rounded-t-px rounded-b-px-sm":"down"===s,"before:top-full before:left-1/2 after:top-full after:left-1/2":"down"===s,"before:ml-[-13px] before:border-[13px] before:border-t-[6px] before:border-t-grey-3":"down"===s,"after:ml-[-12px] after:border-[12px] after:border-t-[5px] after:border-t-white":"down"===s},e),expanded:o,pressed:i,title:r,variant:"custom",size:"custom",children:t})}function xe(t){const e=t.toString(16);return 1===e.length?"0"+e:e}function Ce(t){const e=new Uint8Array(t/2)
|
|
49
|
+
;return window.crypto.getRandomValues(e),Array.from(e).map(xe).join("")}function Se(t){if(null===t||"object"!=typeof t)return!1;for(const e of["frame1","frame2","type","requestId"])if("string"!=typeof t[e])return!1;return!0}class Ae extends Error{constructor(t){super(t)}}class ke{constructor({hostFrame:t,source:e,sourceId:n}){this._hostFrame=t,this._source=e,this._sourceId=n,this._listeners=new mt}destroy(){this._listeners.removeAll()}async discover(t){const e=Ce(6);return new Promise(((n,o)=>{const i=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:t,type:"request",requestId:e,sourceId:this._sourceId},"*")},r=setInterval(i,250),s=setTimeout((()=>{clearInterval(r),o(new Ae(`Unable to establish ${this._source}-${t} communication channel`))}),2e4),a=this._listeners.add(window,"message",(i=>{const{data:l,ports:c}=i;Se(l)&&l.requestId===e&&"request"!==l.type&&(clearInterval(r),clearTimeout(s),this._listeners.remove(a),
|
|
50
|
+
"string"==typeof l.error?o(new Ae(l.error)):c.length>0?n(c[0]):o(new Ae(`${this._source}-${t} port request failed`)))}));i()}))}}class Me{#t=[];destroy(){this.#t=[]}on(t,e){this.#t.push({name:t,callback:e})}off(t,e){this.#t=this.#t.filter((n=>!(n.name===t&&n.callback===e)))}emit(t,...e){for(const n of this.#t){if(n.name!==t)continue;(0,n.callback)(...e)}}}let Re=null;function Ee(t){return t instanceof Error?{message:t.message,stack:t.stack}:{message:String(t),stack:void 0}}function Pe(t,e){if(!Re)return;const n={type:"hypothesis-error",error:t instanceof Error?t:Ee(t),context:e};try{try{Re.postMessage(n,"*")}catch(t){if(!(t instanceof DOMException&&"DataCloneError"===t.name))throw t;n.error=Ee(n.error),Re.postMessage(n,"*")}}catch(t){console.warn("Unable to report Hypothesis error",t)}}function Te(t){Re=t}class Ne{constructor(t){this._hypothesisAppsOrigin=t,this._emitter=new Me,this._handledRequests=new Set,this._sidebarHostChannel=new MessageChannel,this._sidebarConnected=!1,this._listeners=new mt,
|
|
51
|
+
this._allowedMessages=[{allowedOrigin:"*",frame1:"guest",frame2:"host",type:"request"},{allowedOrigin:"*",frame1:"guest",frame2:"sidebar",type:"request"},{allowedOrigin:this._hypothesisAppsOrigin,frame1:"sidebar",frame2:"host",type:"request"},{allowedOrigin:this._hypothesisAppsOrigin,frame1:"notebook",frame2:"sidebar",type:"request"}],this._listen()}_listen(){const t="Handling port request",e=new Set,n=n=>{e.has(n)||(e.add(n),Pe(new Error(n),t))};var o,i;this._listeners.add(window,"message",(o=t=>{const{data:e,origin:o,source:i}=t;if(!i)return;if(!Se(e)||"request"!==e.type)return;const{frame1:r,frame2:s,requestId:a,sourceId:l}=e,c=`${r}-${s}`;if(!function(t){return!(null===t||t instanceof MessagePort||window.ServiceWorker&&t instanceof ServiceWorker)}(i))return void n(`Ignored port request for channel ${c} from non-Window source`);if(void 0===this._allowedMessages.find((({allowedOrigin:t,...n})=>this._messageMatches({allowedMessage:n,allowedOrigin:t,data:e,origin:o
|
|
52
|
+
}))))return void n(`Ignored invalid port request for channel ${c} from ${o}`);if(this._handledRequests.has(a))return;this._handledRequests.add(a);const h="null"===o?"*":o,d="sidebar-host"===c?this._sidebarHostChannel:new MessageChannel,u={frame1:r,frame2:s,type:"offer",requestId:a,sourceId:l};if(d===this._sidebarHostChannel){if(this._sidebarConnected)return console.warn("Ignoring second request from Hypothesis sidebar to connect to host frame"),u.error="Received duplicate port request",void i.postMessage(u,h);this._sidebarConnected=!0}i.postMessage(u,h,[d.port1]),"sidebar"===s?this._sidebarHostChannel.port2.postMessage(u,[d.port2]):"host"===s&&this._emitter.emit("frameConnected",r,d.port2)},i=t,(...t)=>{try{return o(...t)}catch(t){throw Pe(t,i),t}}))}_messageMatches({allowedMessage:t,allowedOrigin:e,data:n,origin:o}){return("*"===e||o===e)&&function(t,e){return!!Se(t)&&JSON.stringify(t,Object.keys(e).sort())===JSON.stringify(e,Object.keys(e).sort())}(n,t)}on(t,e){this._emitter.on(t,e)}destroy(){
|
|
53
|
+
this._listeners.removeAll()}}const Le="1.0.0",Oe="frame-rpc";function Ie(t,e=[],n=-1){return{protocol:Oe,version:Le,arguments:e,method:t,sequence:n}}function Be(t,e,n=[],o=-1){t.postMessage(Ie(e,n,o))}class De{constructor({currentWindow:t=window,forceUnloadListener:e=!1}={}){this._port=null,this._methods=new Map,this._sequence=1,this._callbacks=new Map,this._listeners=new mt,"onclose"in MessagePort.prototype&&!e||this._listeners.add(t,"unload",(t=>{t instanceof CustomEvent||this._port&&Be(this._port,"close")})),this._pendingCalls=[],this._destroyed=!1,this._receivedCloseEvent=!1}on(t,e){if(this._port)throw new Error("Cannot add a method handler after a port is connected");this._methods.set(t,e)}connect(t){this._port=t,this._listeners.add(t,"message",(t=>this._handle(t))),this._listeners.add(t,"close",(()=>{t.dispatchEvent(new MessageEvent("message",{data:Ie("close")}))})),t.start(),Be(t,"connect");for(const[t,e]of this._pendingCalls)this.call(t,...e);this._pendingCalls=[]}destroy(){
|
|
54
|
+
this._port&&(Be(this._port,"close"),this._port.close()),this._destroyed=!0,this._listeners.removeAll()}call(t,...e){if(this._port||this._pendingCalls.push([t,e]),!this._port||this._destroyed)return;const n=this._sequence++,o=e[e.length-1];"function"==typeof o&&(this._callbacks.set(n,o),e=e.slice(0,-1)),Be(this._port,t,e,n)}_parseMessage({data:t}){return t&&"object"==typeof t?t.protocol!==Oe||t.version!==Le?null:Array.isArray(t.arguments)?t:null:null}_handle(t){const e=this._parseMessage(t),n=this._port;if(e&&n)if("method"in e){if("close"===e.method){if(this._receivedCloseEvent)return;this._receivedCloseEvent=!0}const t=this._methods.get(e.method);if(!t)return;const o=(...t)=>{const o={arguments:t,protocol:Oe,response:e.sequence,version:Le};n.postMessage(o)};t(...e.arguments,o)}else if("response"in e){const t=this._callbacks.get(e.response);this._callbacks.delete(e.response),t&&t(...e.arguments)}}}function Fe(t){if("string"==typeof t&&"false"===t.trim().toLocaleLowerCase())return!1;const e=Number(t)
|
|
55
|
+
;return isNaN(e)?"string"==typeof t:Boolean(e)}function He(t){for(var e={},n=t.querySelectorAll("script.js-hypothesis-config"),o=0;o<n.length;o++){var i=void 0;try{i=JSON.parse(n[o].textContent||"")}catch(t){console.warn("Could not parse settings from js-hypothesis-config tags",t),i={}}Object.assign(e,i)}return e}function Ve(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function ze(t){return t.width<=0||t.height<=0}function Ue(t,e,n,o){return Math.max(t,n)<Math.min(e,o)}function $e(t,e){return!ze(t)&&!ze(e)&&(Ue(t.left,t.right,e.left,e.right)&&Ue(t.top,t.bottom,e.top,e.bottom))}function qe(t,e){return Ue(t.top,t.bottom,e.top,e.bottom)}function We(t,e){return Ue(t.left,t.right,e.left,e.right)}function je(t,e){if(ze(t))return e;if(ze(e))return t;const n=Math.min(t.left,e.left),o=Math.min(t.top,e.top),i=Math.max(t.right,e.right),r=Math.max(t.bottom,e.bottom);return new DOMRect(n,o,i-n,r-o)}function Ke(t){return new DOMPoint((t.left+t.right)/2,(t.top+t.bottom)/2)}function Xe(t){
|
|
56
|
+
return t.nodeType===Node.ELEMENT_NODE}function Ye(t){return t.nodeType===Node.TEXT_NODE}function Ge(t){if(!(t&&t instanceof HTMLElement))return!1;const e=t;return!!["INPUT","TEXTAREA"].includes(e.tagName.toUpperCase())||(!!e.isContentEditable||!(!["textbox","searchbox","combobox"].includes(e.getAttribute?.("role")||"")&&!e.closest?.('[role="textbox"], [role="searchbox"], [role="combobox"]')))}const Qe=["p",".para"];let Je;function Ze(t,e=0,n=t.data.length){return Je||(Je=document.createRange()),Je.setStart(t,e),Je.setEnd(t,n),Je.getBoundingClientRect()}function tn(t){const e=t.getBoundingClientRect();return e.x-=t.scrollLeft,e.y-=t.scrollTop,e.height=Math.max(e.height,t.scrollHeight),e.width=Math.max(e.width,t.scrollWidth),e}function*en(t,e,n){let o=t.firstChild;for(;o;){if(Xe(o)){const t=$e(tn(o),e);n(o)&&t&&(yield*en(o,e,n))}else Ye(o)&&$e(Ze(o),e)&&(yield o);o=o.nextSibling}}function nn(t,e){let n=null;const o=t=>!function(t){switch(getComputedStyle(t).position){case"fixed":case"sticky":return!0;default:
|
|
57
|
+
return!1}}(t);t:for(const s of en(t,e,o)){let t=0;for(const o of s.data.split(/\b/)){if(/\S/.test(o)){const a=t,l=t+o.length,c=Ze(s,a,l);if(r=c,!ze(i=e)&&!ze(r)&&r.left>=i.left&&r.right<=i.right&&r.top>=i.top&&r.bottom<=i.bottom){n=document.createRange(),n.setStart(s,a),n.setEnd(s,l);break t}}t+=o.length}}var i,r;return n}function on(t,e=document.documentElement,n=new DOMRect(0,0,window.innerWidth,window.innerHeight)){const o=nn(e,n);if(!o)return t(),0;const i=o.getBoundingClientRect().top;t();const r=o.getBoundingClientRect().top-i;return e.scrollTop+=r,r}function rn(t,e,n){const o=t.document.querySelector(`link[type="application/annotator+${n}"][rel="${e}"]`);if(!o)throw new Error(`No application/annotator+${n} (rel="${e}") link in the document`);if(!o.href)throw new Error(`application/annotator+${n} (rel="${e}") link has no href`);return o.href}function sn(t){return"string"==typeof t?t:null}function an(t){const e=function(t){if(!Ve(t,"hypothesisConfig"))return{};if("function"!=typeof t.hypothesisConfig){
|
|
58
|
+
const t="https://h.readthedocs.io/projects/client/en/latest/publishers/config/#window.hypothesisConfig";return console.warn("hypothesisConfig must be a function, see: "+t),{}}return t.hypothesisConfig()}(t),n=Fe(e.ignoreOtherConfiguration)?{}:He(t.document);function o(t){return Ve(e,t)?e[t]:Ve(n,t)?n[t]:void 0}return{get annotations(){return sn(n.annotations)||function(){const e=t.location.href.match(/#annotations:([A-Za-z0-9_-]+)$/);return e?e[1]:null}()},get clientUrl(){return rn(t,"hypothesis-client","javascript")},get group(){return sn(n.group)||function(){const e=t.location.href.match(/#annotations:group:([A-Za-z0-9_-]+)$/);return e?e[1]:null}()},get notebookAppUrl(){return rn(t,"notebook","html")},get profileAppUrl(){return rn(t,"profile","html")},get showHighlights(){return function(){const t=o("showHighlights");switch(t){case"always":case"never":case"whenSidebarOpen":return t;case!0:return"always";case!1:return"never";default:return"always"}}()},get sidebarAppUrl(){return rn(t,"sidebar","html")},
|
|
59
|
+
get query(){return sn(n.query)||function(){const e=t.location.href.match(/#annotations:(query|q):(.+)$/i);if(e)try{return decodeURIComponent(e[2])}catch{}return null}()},get sideBySide(){return function(){const t=o("sideBySide");if(!function(t){return null!==t&&"object"==typeof t}(t))return{mode:"auto"};const e="mode"in t&&function(t){return"string"==typeof t&&["auto","manual"].includes(t)}(t.mode)?t.mode:"auto";return"auto"===e?{mode:e}:{mode:e,isActive:"isActive"in t&&"function"==typeof t.isActive?t.isActive:void 0}}()},hostPageSetting:o}}const ln=(t,e)=>t.hostPageSetting(e),cn={annotations:{allowInBrowserExt:!0,defaultValue:null,getValue:t=>t.annotations},appType:{allowInBrowserExt:!0,defaultValue:null,getValue:ln},branding:{defaultValue:null,allowInBrowserExt:!1,getValue:ln},bucketContainerSelector:{defaultValue:null,allowInBrowserExt:!1,getValue:ln},clientUrl:{allowInBrowserExt:!0,defaultValue:null,getValue:t=>t.clientUrl},contentInfoBanner:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},
|
|
60
|
+
contentReady:{allowInBrowserExt:!0,defaultValue:null,getValue:ln},enableExperimentalNewNoteButton:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},group:{allowInBrowserExt:!0,defaultValue:null,getValue:t=>t.group},focus:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},theme:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},usernameUrl:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},onLayoutChange:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},openSidebar:{allowInBrowserExt:!0,defaultValue:!1,coerce:Fe,getValue:ln},query:{allowInBrowserExt:!0,defaultValue:null,getValue:t=>t.query},requestConfigFromFrame:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},services:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},showHighlights:{allowInBrowserExt:!1,defaultValue:"always",getValue:t=>t.showHighlights},notebookAppUrl:{allowInBrowserExt:!0,defaultValue:null,getValue:t=>t.notebookAppUrl},profileAppUrl:{allowInBrowserExt:!0,defaultValue:null,getValue:t=>t.profileAppUrl},sidebarAppUrl:{
|
|
61
|
+
allowInBrowserExt:!0,defaultValue:null,getValue:t=>t.sidebarAppUrl},subFrameIdentifier:{allowInBrowserExt:!0,defaultValue:null,getValue:ln},externalContainerSelector:{allowInBrowserExt:!1,defaultValue:null,getValue:ln},sideBySide:{allowInBrowserExt:!0,getValue:t=>t.sideBySide},commentsMode:{defaultValue:!1,allowInBrowserExt:!1,getValue:ln},groupsAllowlist:{allowInBrowserExt:!1,getValue:ln}};function hn(t,e=window){const n=an(e),o={};for(const r of function(t){const e={annotator:["clientUrl","contentInfoBanner","contentReady","subFrameIdentifier","sideBySide","commentsMode"],sidebar:["appType","annotations","branding","bucketContainerSelector","enableExperimentalNewNoteButton","externalContainerSelector","focus","group","onLayoutChange","openSidebar","query","requestConfigFromFrame","services","showHighlights","sidebarAppUrl","theme","usernameUrl","commentsMode","groupsAllowlist"],notebook:["branding","group","notebookAppUrl","requestConfigFromFrame","services","theme","usernameUrl"],profile:["profileAppUrl"]}
|
|
62
|
+
;return"all"===t?Object.values(e).flat():e[t]}(t)){const t=cn[r],s=void 0!==t.defaultValue,a=!((i=rn(e,"sidebar","html")).startsWith("http://")||i.startsWith("https://"));if(!t.allowInBrowserExt&&a){s&&(o[r]=t.defaultValue);continue}const l=t.getValue(n,r);void 0!==l?o[r]=t.coerce?t.coerce(l):l:s&&(o[r]=t.defaultValue)}var i;return o}const dn={alt:1,ctrl:2,meta:4,shift:8};function un(t,e){if(!(t instanceof KeyboardEvent))return!1;const n=e.split("+").map((t=>t.toLowerCase()));let o=0,i=null;for(const t of n){const e=dn[t];if(e)o|=e;else{if(null!==i)throw new Error("Multiple non-modifier keys specified");i=t}}if(!i)throw new Error(`Invalid shortcut: ${e}`);return((t.ctrlKey?dn.ctrl:0)|(t.metaKey?dn.meta:0)|(t.altKey?dn.alt:0)|(t.shiftKey?dn.shift:0))===o&&t.key.toLowerCase()===i}function fn(t,e,{rootElement:n=document.documentElement??void 0,ignoreWhenEditable:o=!1}={}){const i=n=>{var i;o&&(i=n.target,i instanceof HTMLElement&&(i.isContentEditable||["INPUT","TEXTAREA"].includes(i.tagName)))||un(n,t)&&e(n)}
|
|
63
|
+
;return n?(n.addEventListener("keydown",i),()=>n.removeEventListener("keydown",i)):()=>{}}function pn(t,e,{rootElement:n,ignoreWhenEditable:o}={}){nt((()=>{if(t)return fn(t,e,{rootElement:n,ignoreWhenEditable:o})}),[t,e,n,o])}const gn={applyUpdates:"l",openSearch:"/",annotateSelection:"a",highlightSelection:"h",toggleHighlights:"ctrl+shift+h",showSelection:"s",hideAdder:"Escape",activateRectMove:"ctrl+shift+y",activateRectResize:"ctrl+shift+j",activatePoint:"ctrl+shift+u"};let _n={...gn};const mn=new Set;function bn(t){const e={};return Object.keys(gn).forEach((n=>{const o=t[n];"string"!=typeof o&&null!==o||(e[n]=o)})),e}function yn(){return{..._n}}function wn(t){_n={...gn,...bn(t)},function(){const t={..._n};for(const e of mn)e(t)}()}function vn(){const[t,e]=et((()=>yn()));return nt((()=>{return t=e,mn.add(t),t({..._n}),()=>{mn.delete(t)};var t}),[]),t}const xn=(t=window)=>t.matchMedia("(pointer: coarse)").matches;function Cn({badgeCount:t}){return St("span",{className:Tt("rounded px-1 py-0.5","bg-current"),
|
|
64
|
+
children:St("span",{className:"font-bold text-color-text-inverted",children:t})})}function Sn({arrowDirection:t}){return St("div",{className:Tt("absolute left-1/2 -translate-x-1/2 z-2","fill-white text-grey-3",{"top-0 -translate-y-full":"up"===t}),children:St("up"===t?Gt:Yt,{})})}function An({badgeCount:t,icon:e,label:n,onClick:o,shortcut:i}){pn(i,o);const r=i?`${n} (${i})`:n;return St(ee,{classes:Tt("text-grey-7","group-hover:text-grey-5","hover:group-hover:text-grey-9"),onClick:o,title:r,size:"custom",variant:"custom",children:St("div",{className:Tt("flex flex-col items-center gap-y-1 py-2.5 px-2","text-annotator-sm leading-none"),children:[e&&St(e,{className:"text-annotator-lg",title:r}),"number"==typeof t&&St(Cn,{badgeCount:t}),St("span",{"data-testid":"adder-button-label",children:n})]})})}function kn({annotationCount:t,isVisible:e}){return St("div",{className:"sr-only",children:[St("span",{"aria-live":"polite","aria-atomic":"true",role:"status","data-testid":"annotation-count-announce",
|
|
65
|
+
children:t>0&&St("span",{children:[t," ",1===t?"annotation":"annotations"," for this selection."]})}),St("ul",{"aria-live":"polite","data-testid":"annotate-shortcuts-announce",children:e&&St(y,{children:[t>0&&St("li",{children:["Press ","'S'"," to show annotations."]}),St("li",{children:["Press ","'A'"," to annotate."]}),St("li",{children:["Press ","'H'"," to highlight."]})]})})]})}function Mn({arrowDirection:t,isVisible:e,onCommand:n,annotationCount:o=0}){const i=vn(),r=e?i.annotateSelection:null,s=e?i.highlightSelection:null,a=e?i.showSelection:null;return pn(e?i.hideAdder:null,(()=>n("hide"))),St("div",{className:Tt("all-initial","border border-solid border-grey-3","absolute select-none bg-white rounded shadow-intense","opacity-5",{"animate-adder-pop-up":"up"===t&&e,"animate-adder-pop-down":"down"===t&&e}),"data-component":"AdderToolbar",dir:"ltr",style:{visibility:e?"visible":"hidden"},children:[St("div",{className:Tt("flex group"),children:[St(An,{icon:Ot,onClick:()=>n("annotate"),label:"Annotate",
|
|
66
|
+
shortcut:r}),St(An,{icon:qt,onClick:()=>n("highlight"),label:"Highlight",shortcut:s}),o>0&&St(y,{children:[St("div",{className:Tt("m-1.5 border-r border-grey-4 border-solid")}),St(An,{badgeCount:o,onClick:()=>n("show"),label:"Show",shortcut:a})]})]}),St(Sn,{arrowDirection:t}),St(kn,{annotationCount:o,isVisible:e})]})}let Rn;function En(t){const e=t.attachShadow({mode:"open"}),n=function(t){const e=document.querySelector('link[rel="preload"][href*="/build/styles/annotator.css"]')?.href;if(!e)return Promise.resolve();const n=document.createElement("link");if(n.rel="stylesheet",n.href=e,n.crossOrigin="anonymous",n.removeAttribute=()=>{},t.appendChild(n),void 0===Rn){Rn=new CSSStyleSheet;const t=Rn;n.addEventListener("load",(()=>{if(n.sheet){for(const e of n.sheet.rules)e instanceof CSSPropertyRule&&t.insertRule(e.cssText);document.adoptedStyleSheets.push(t)}}),{once:!0})}return new Promise((t=>{n.addEventListener("load",(()=>t()))}))}(e);return{shadowRoot:e,stylesLoaded:n}}class Pn{constructor(t,e){
|
|
67
|
+
const n=`hypothesis-${t}`;this._element=document.createElement(n);const{shadowRoot:o}=En(this._element);this._shadowRoot=o,this._render=e}destroy(){H(null,this._shadowRoot),this._element.remove()}get element(){return this._element}render(){H(this._render(),this._shadowRoot)}}let Tn=function(t){return t[t.DOWN=1]="DOWN",t[t.UP=2]="UP",t}({});function Nn(t){return t.toString()+"px"}class Ln{constructor(t,e){this._view=t.ownerDocument.defaultView,this._isVisible=!1,this._arrowDirection="up",this._annotationsForSelection=[],this._onAnnotate=e.onAnnotate,this._onHighlight=e.onHighlight,this._onShowAnnotations=e.onShowAnnotations,this._container=new Pn("adder",(()=>this._render())),t.appendChild(this._container.element),Object.assign(this._container.element.style,{position:"absolute",top:0,left:0}),this._container.render()}get annotationsForSelection(){return this._annotationsForSelection}set annotationsForSelection(t){this._annotationsForSelection=t,this._container.render()}hide(){this._isVisible=!1,
|
|
68
|
+
this._container.render(),Object.assign(this._container.element.style,{top:0,left:0})}destroy(){this._container.destroy()}show(t,e){const{left:n,top:o,arrowDirection:i}=this._calculateTarget(t,e);this._showAt(n,o),this._isVisible=!0,this._arrowDirection=i===Tn.UP?"up":"down",this._container.render()}_firstChild(){return this._container.element.shadowRoot.firstChild}_width(){return this._firstChild().getBoundingClientRect().width}_height(){return this._firstChild().getBoundingClientRect().height}_calculateTarget(t,e){let n,o,i;n=e&&!xn()?Tn.DOWN:Tn.UP;const r=Math.min(20,t.width),s=this._width(),a=xn()?10:0,l=this._height();return i=e?t.left-s/2+r:t.left+t.width-s/2-r,t.top-l<0&&n===Tn.DOWN?n=Tn.UP:t.top+l>this._view.innerHeight&&(n=Tn.DOWN),o=n===Tn.UP?t.top+t.height+10+a:t.top-l-10,i=Math.max(i,0),i=Math.min(i,this._view.innerWidth-s),o=Math.max(o,0),o=Math.min(o,this._view.innerHeight-l),{top:o,left:i,arrowDirection:n}}_findZindex(t,e){if(void 0===document.elementsFromPoint)return 32768
|
|
69
|
+
;const n=this._width(),o=this._height(),i=t=>{const e=parseInt(getComputedStyle(t).zIndex);return Number.isInteger(e)?e:0},r=[...new Set([...document.elementsFromPoint(t,e),...document.elementsFromPoint(t,e+o),...document.elementsFromPoint(t+n/2,e+o/2),...document.elementsFromPoint(t+n,e),...document.elementsFromPoint(t+n,e+o)])].map(i).filter(Number.isInteger);let s=0;for(const t of document.querySelectorAll("hypothesis-highlight"))s=Math.max(s,i(t));return r.push(s),Math.max(...r)+1}_showAt(t,e){const n=function(t){let e=t.parentElement;for(;e.parentElement&&"static"===getComputedStyle(e).position;)e=e.parentElement;return e}(this._container.element).getBoundingClientRect(),o=this._findZindex(t,e);Object.assign(this._container.element.style,{left:Nn(t-n.left),top:Nn(e-n.top),zIndex:o})}_render(){return St(Mn,{isVisible:this._isVisible,arrowDirection:this._arrowDirection,onCommand:t=>{switch(t){case"annotate":this._onAnnotate(),this.hide();break;case"highlight":this._onHighlight(),this.hide();break
|
|
70
|
+
;case"show":this._onShowAnnotations(this.annotationsForSelection);break;case"hide":this.hide()}},annotationCount:this.annotationsForSelection.length})}}var On=function(t){return t[t.Forwards=1]="Forwards",t[t.Backwards=2]="Backwards",t}(On||{});function In(t,e,n){const o=n===On.Forwards?e:e-1;if(""!==t.charAt(o).trim())return e;let i,r;if(n===On.Backwards?(i=t.substring(0,e),r=i.trimEnd()):(i=t.substring(e),r=i.trimStart()),!r.length)return-1;const s=i.length-r.length;return n===On.Backwards?e-s:e+s}function Bn(t,e){const n=t.commonAncestorContainer.ownerDocument.createNodeIterator(t.commonAncestorContainer,NodeFilter.SHOW_TEXT),o=e===On.Forwards?t.startContainer:t.endContainer,i=e===On.Forwards?t.endContainer:t.startContainer;let r=n.nextNode();for(;r&&r!==o;)r=n.nextNode();e===On.Backwards&&(r=n.previousNode());let s=-1;const a=()=>{if(r=e===On.Forwards?n.nextNode():n.previousNode(),r){const t=r.textContent,n=e===On.Forwards?0:t.length;s=In(t,n,e)}};for(;r&&-1===s&&r!==i;)a();if(r&&s>=0)return{node:r,
|
|
71
|
+
offset:s};throw new RangeError("No text nodes with non-whitespace text found in range")}function Dn(t){switch(t.nodeType){case Node.ELEMENT_NODE:case Node.TEXT_NODE:return t.textContent?.length??0;default:return 0}}function Fn(t){let e=t.previousSibling,n=0;for(;e;)n+=Dn(e),e=e.previousSibling;return n}function Hn(t,...e){let n=e.shift();const o=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT),i=[];let r,s=o.nextNode(),a=0;for(;void 0!==n&&s;)r=s,a+r.data.length>n?(i.push({node:r,offset:n-a}),n=e.shift()):(s=o.nextNode(),a+=r.data.length);for(;void 0!==n&&r&&a===n;)i.push({node:r,offset:r.data.length}),n=e.shift();if(void 0!==n)throw new RangeError("Offset exceeds text length");return i}let Vn=function(t){return t[t.FORWARDS=1]="FORWARDS",t[t.BACKWARDS=2]="BACKWARDS",t}({});class zn{constructor(t,e){if(e<0)throw new Error("Offset is invalid");this.element=t,this.offset=e}relativeTo(t){if(!t.contains(this.element))throw new Error("Parent is not an ancestor of current element")
|
|
72
|
+
;let e=this.element,n=this.offset;for(;e!==t;)n+=Fn(e),e=e.parentElement;return new zn(e,n)}resolve(t={}){try{return Hn(this.element,this.offset)[0]}catch(e){if(0===this.offset&&void 0!==t.direction){const n=document.createTreeWalker(this.element.getRootNode(),NodeFilter.SHOW_TEXT);n.currentNode=this.element;const o=t.direction===Vn.FORWARDS,i=o?n.nextNode():n.previousNode();if(!i)throw e;return{node:i,offset:o?0:i.data.length}}throw e}}static fromCharOffset(t,e){switch(t.nodeType){case Node.TEXT_NODE:return zn.fromPoint(t,e);case Node.ELEMENT_NODE:return new zn(t,e);default:throw new Error("Node is not an element or text node")}}static fromPoint(t,e){switch(t.nodeType){case Node.TEXT_NODE:{if(e<0||e>t.data.length)throw new Error("Text node offset is out of range");if(!t.parentElement)throw new Error("Text node has no parent");const n=Fn(t)+e;return new zn(t.parentElement,n)}case Node.ELEMENT_NODE:{if(e<0||e>t.childNodes.length)throw new Error("Child node offset is out of range");let n=0
|
|
73
|
+
;for(let o=0;o<e;o++)n+=Dn(t.childNodes[o]);return new zn(t,n)}default:throw new Error("Point is not in an element or text node")}}}class Un{constructor(t,e){this.start=t,this.end=e}relativeTo(t){return new Un(this.start.relativeTo(t),this.end.relativeTo(t))}toRange(){let t,e;this.start.element===this.end.element&&this.start.offset<=this.end.offset?[t,e]=Hn(this.start.element,this.start.offset,this.end.offset):(t=this.start.resolve({direction:Vn.FORWARDS}),e=this.end.resolve({direction:Vn.BACKWARDS}));const n=new Range;return n.setStart(t.node,t.offset),n.setEnd(e.node,e.offset),n}static fromRange(t){const e=zn.fromPoint(t.startContainer,t.startOffset),n=zn.fromPoint(t.endContainer,t.endOffset);return new Un(e,n)}static fromOffsets(t,e,n){return new Un(new zn(t,e),new zn(t,n))}static trimmedRange(t){return function(t){if(!t.toString().trim().length)throw new RangeError("Range contains no non-whitespace text")
|
|
74
|
+
;if(t.startContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range startContainer is not a text node");if(t.endContainer.nodeType!==Node.TEXT_NODE)throw new RangeError("Range endContainer is not a text node");const e=t.cloneRange();let n=!1,o=!1;const i={start:In(t.startContainer.textContent,t.startOffset,On.Forwards),end:In(t.endContainer.textContent,t.endOffset,On.Backwards)};if(i.start>=0&&(e.setStart(t.startContainer,i.start),n=!0),i.end>0&&(e.setEnd(t.endContainer,i.end),o=!0),n&&o)return e;if(!n){const{node:t,offset:n}=Bn(e,On.Forwards);t&&n>=0&&e.setStart(t,n)}if(!o){const{node:t,offset:n}=Bn(e,On.Backwards);t&&n>0&&e.setEnd(t,n)}return e}(Un.fromRange(t).toRange())}}const $n=".annotator-placeholder";function qn(t){return!!t.parentElement&&null!==t.parentElement.closest($n)}function Wn(t,e){const n=new Range;return t.compareBoundaryPoints(Range.START_TO_START,e)<=0?n.setStart(t.startContainer,t.startOffset):n.setStart(e.startContainer,e.startOffset),
|
|
75
|
+
t.compareBoundaryPoints(Range.END_TO_END,e)>=0?n.setEnd(t.endContainer,t.endOffset):n.setEnd(e.endContainer,e.endOffset),n}function jn(t=document.getSelection()){if(!t||0===t.rangeCount)return null;let e=t.getRangeAt(0);for(let n=1;n<t.rangeCount;n++)e=Wn(e,t.getRangeAt(n));return e.collapsed?null:e}function Kn(t){if(t.focusNode===t.anchorNode)return t.focusOffset<t.anchorOffset;return jn(t).startContainer===t.focusNode}function Xn(t,e){try{const n=e.nodeValue?.length??e.childNodes.length;return t.comparePoint(e,0)<=0&&t.comparePoint(e,n)>=0}catch{return!1}}function Yn(t,e){const n=t.commonAncestorContainer,o=n.ownerDocument.createNodeIterator(n,NodeFilter.SHOW_ALL);let i;for(;i=o.nextNode();)Xn(t,i)&&e(i)}function Gn(t){const e=jn(t);if(!e)return null;const n=function(t){const e=[];return Yn(t,(t=>{Ye(t)&&!t.textContent.match(/^\s*$/)&&e.push(t)})),e.flatMap((e=>{const n=e.ownerDocument.createRange();if(n.selectNodeContents(e),e===t.startContainer&&n.setStart(e,t.startOffset),
|
|
76
|
+
e===t.endContainer&&n.setEnd(e,t.endOffset),n.collapsed)return[];const o=Array.from(n.getClientRects());return n.detach(),o}))}(e);return 0===n.length?null:Kn(t)?n[0]:n[n.length-1]}const Qn="http://www.w3.org/2000/svg",Jn=["user-annotations","user-highlights","other-content"];class Zn{constructor(t=document.body){this.root=t}highlightShape(t){const{shape:e,anchor:n}=t,o=document.createElement("hypothesis-highlight");if(o.className="hypothesis-shape-highlight","rect"===e.type){const t=e.right-e.left,n=e.bottom-e.top;o.style.left=100*e.left+"%",o.style.top=100*e.top+"%",o.style.width=`calc(${100*t}% - 6px)`,o.style.height=`calc(${100*n}% - 6px)`}else if("point"===e.type){const t=7;o.style.left=`calc(${100*e.x}% - ${t+3}px)`,o.style.top=`calc(${100*e.y}% - ${t+3}px)`,o.style.width=2*t+"px",o.style.height=2*t+"px",o.style.borderRadius="50%"}return n.append(o),[o]}highlightRange(t,e){const n=function(t){if(t.collapsed)return[];let e=t.commonAncestorContainer;e&&e.nodeType!==Node.ELEMENT_NODE&&(e=e.parentElement)
|
|
77
|
+
;if(!e)return[];const n=[],o=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);let i;for(;i=o.nextNode();){if(!Xn(t,i))continue;const e=i;e===t.startContainer&&t.startOffset>0?e.splitText(t.startOffset):(e===t.endContainer&&t.endOffset<e.data.length&&e.splitText(t.endOffset),n.push(e))}return n}(t),o=n.length>0&&qn(n[0]);let i=[],r=null,s=null;n.forEach((t=>{r&&r.nextSibling===t?s.push(t):(s=[t],i.push(s)),r=t}));const a=/^\s*$/;i=i.filter((t=>{const e=t[0].parentElement;return 1===e?.childNodes.length&&"SPAN"===e?.tagName||t.some((t=>!a.test(t.data)))}));const l=[];return i.forEach((t=>{const n=document.createElement("hypothesis-highlight");n.className=Tt("hypothesis-highlight",e);t[0].parentNode.replaceChild(n,t[0]),t.forEach((t=>n.appendChild(t))),l.push(n)})),o||function(t,e){if(0===t.length)return;const n=function(t){const e=t.closest(".page");if(!e)return null;const n=e.querySelector(".canvasWrapper > canvas");if(!n)return null;return n}(t[0]);if(!n||!n.parentElement)return
|
|
78
|
+
;let o=n.parentElement.querySelector(".hypothesis-highlight-layer");if(!o){o=document.createElementNS(Qn,"svg"),o.setAttribute("class","hypothesis-highlight-layer"),n.parentElement.appendChild(o),n.parentElement.style.position="relative";const t=o.style;t.position="absolute",t.left="0",t.top="0",t.width="100%",t.height="100%",t.mixBlendMode="multiply"}const i=n.getBoundingClientRect(),r=t.map((t=>{const n=t.getBoundingClientRect(),o=document.createElementNS(Qn,"rect"),r=(n.left-i.left)/i.width,s=(n.top-i.top)/i.height,a=n.width/i.width,l=n.height/i.height;return o.setAttribute("x",100*r+"%"),o.setAttribute("y",100*s+"%"),o.setAttribute("width",100*a+"%"),o.setAttribute("height",100*l+"%"),o.setAttribute("class",Tt("hypothesis-svg-highlight",e)),t.classList.add("is-transparent"),t.svgHighlight=o,o}));o.append(...r)}(l,e),l}removeAllHighlights(){const t=Array.from(this.root.querySelectorAll("hypothesis-highlight"));this.removeHighlights(t)}removeHighlights(t){!function(t,e){t.forEach((t=>{
|
|
79
|
+
t.svgHighlight?eo(t.svgHighlight,e):t.classList.toggle("hypothesis-highlight-focused",e)}))}(t,!1);for(const e of t){if(e.parentNode){to(e,Array.from(e.childNodes))}e.svgHighlight&&e.svgHighlight.remove()}}setHighlightsFocused(t,e){t.forEach((t=>{t.svgHighlight?eo(t.svgHighlight,e):t.classList.toggle("hypothesis-highlight-focused",e)}))}setHighlightsVisible(t){this.root.classList.toggle(no,t)}getHighlightsFromPoint(t,e){return oo(t,e)}}function to(t,e){const n=t.parentNode;e.forEach((e=>n.insertBefore(e,t))),t.remove()}function eo(t,e){const n=t.parentNode,o=t.getAttribute("data-focused-id");if(Boolean(o)!==e)if(e){t.setAttribute("data-focused-id",Ce(8));const e=t.cloneNode();e.setAttribute("data-is-focused","data-is-focused"),n.append(e)}else{const e=n.querySelector(`[data-focused-id="${o}"][data-is-focused]`);e?.remove(),t.removeAttribute("data-focused-id")}}const no="hypothesis-highlights-always-on";function oo(t,e){
|
|
80
|
+
const n=`.${no}`,o=document.elementsFromPoint(t,e).filter((t=>"hypothesis-highlight"===t.localName&&t.closest(n))),i=[];for(const o of document.querySelectorAll("hypothesis-highlight.hypothesis-shape-highlight")){if(!o.closest(n))continue;const r=o.getBoundingClientRect();t>=r.left&&t<r.right&&e>=r.top&&e<r.bottom&&i.push(o)}return[...o,...i]}function io(t){ao(so(t)),function(t){for(const[e,n]of function(t){const e=new Map;for(const n of(t??document).getElementsByClassName("hypothesis-highlight-layer"))e.set(n,Array.from(n.querySelectorAll(".hypothesis-svg-highlight")));return e}(t)){n.every(((t,e,n)=>0===e||lo(t)>=lo(n[e-1])))||(n.sort(((t,e)=>lo(t)-lo(e))),e.replaceChildren(...n))}}(t)}const ro=t=>"hypothesis-highlight"===t.tagName.toLowerCase();function so(t){let e;return e=ro(t)?Array.from(t.children).filter(ro):Array.from(t.getElementsByTagName("hypothesis-highlight")).filter((t=>!t.parentElement||!ro(t.parentElement))),e}function ao(t,e="",n=0,o=0){for(const i of t){
|
|
81
|
+
const t=Jn.find((t=>i.classList.contains(t)))??"other-content",r=e&&t===e?o+1:0;i.setAttribute("data-nesting-level",`${n}`),i.setAttribute("data-cluster-level",`${r}`),i.svgHighlight&&(i.svgHighlight.setAttribute("data-nesting-level",`${n}`),i.svgHighlight.setAttribute("data-cluster-level",`${r}`)),ao(so(i),t,n+1,r)}}function lo(t){return t.getAttribute("data-is-focused")?Number.MAX_SAFE_INTEGER:parseInt(t.getAttribute("data-nesting-level")??"0",10)}function co(t){const e=[];return t.forEach((({annotation:t,highlights:n})=>{if(!n?.length)return;const{top:o,bottom:i}=function(t){const e=t.map((t=>t.getBoundingClientRect()));return e.reduce(((t,e)=>({top:Math.min(t.top,e.top),left:Math.min(t.left,e.left),bottom:Math.max(t.bottom,e.bottom),right:Math.max(t.right,e.right)})))}(n);o>=i||e.push({tag:t.$tag,top:o,bottom:i})})),e.sort(((t,e)=>t.top-e.top)),e}class ho{constructor({contentContainer:t,hostRPC:e}){this._hostRPC=e,this._updatePending=!1,this._anchors=[],this._listeners=new mt,
|
|
82
|
+
this._listeners.add(window,"resize",(()=>this.update())),this._listeners.add(window,"scroll",(()=>this.update())),this._listeners.add(t,"scroll",(()=>this.update()),{capture:!0})}destroy(){this._listeners.removeAll()}update(t){t&&(this._anchors=t),this._updatePending||(this._updatePending=!0,requestAnimationFrame((()=>{const t=co(this._anchors);this._hostRPC.call("anchorsChanged",t),this._updatePending=!1})))}}const uo=["top-left","top-right","bottom-right","bottom-left"];function fo(t,e="short"){const n=t??"top-left";return"long"===e?`${n} corner pinned`:n}function po({mode:t,tool:e,x:n,y:o,width:i,height:r,keyboardActive:s,pinnedCorner:a}){if(!s||!e)return null;let l=""
|
|
83
|
+
;if("point"===e)l="move"===t&&"number"==typeof n&&"number"==typeof o?`Pin position: ${Math.round(n)}, ${Math.round(o)}`:"resize"===t?"Pin annotation mode. Use arrow keys to move.":"Pin annotation mode. Use arrow keys to move, Enter to confirm.";else if("rect"===e)if("move"===t&&"number"==typeof n&&"number"==typeof o&&"number"==typeof i&&"number"==typeof r)l=`Rectangle position: ${Math.round(n)}, ${Math.round(o)}. Size: ${Math.round(i)} by ${Math.round(r)} pixels`;else if("resize"===t&&"number"==typeof i&&"number"==typeof r){const t=fo(a,"long");l=`Rectangle size: ${Math.round(i)} by ${Math.round(r)} pixels. ${t}. Press Tab to change pinned corner.`}else l="rect"===t?"Rectangle annotation mode. Click the mode button to switch to Move or Resize mode.":"Rectangle annotation mode. Use arrow keys to move, Ctrl+Shift+J to resize, Enter to confirm.";return St("div",{"aria-live":"polite","aria-atomic":"true",role:"status",className:"sr-only","data-testid":"draw-tool-announcer",children:l&&St("span",{children:l})})}
|
|
84
|
+
function go({mode:t,keyboardActive:e,pinnedCorner:n}){if(!e||!t)return null;const o="move"===t?"Move":"resize"===t?"Resize":"Rectangle";let i;if("move"===t)i="Use arrow keys to move, click mode button to switch modes, Enter to confirm";else if("resize"===t){i=`Use arrow keys to resize (${fo(n,"short")} corner pinned), Tab to change corner, click mode button to switch modes, Enter to confirm`}else i="Rectangle mode. Click the mode button to switch to Move or Resize mode.";return St("div",{className:"fixed bottom-4 left-4 bg-white border border-grey-3 rounded shadow-lg p-3 z-50 pointer-events-none","data-testid":"draw-tool-keyboard-indicator",role:"status",children:[St("div",{className:"text-sm font-semibold text-grey-9",children:["Keyboard mode: ",o]}),St("div",{className:"text-xs text-grey-6 mt-1",children:i})]})}function _o(t){return{type:"rect",left:Math.min(t.left,t.right),top:Math.min(t.top,t.bottom),right:Math.max(t.left,t.right),bottom:Math.max(t.top,t.bottom)}}function mo(t,e){
|
|
85
|
+
const n=_o(t),o=n.right-n.left,i=n.bottom-n.top,r=Math.max(e.minLeft,Math.min(n.left,e.maxRight-o)),s=Math.max(e.minTop,Math.min(n.top,e.maxBottom-i));return{type:"rect",left:r,top:s,right:r+o,bottom:s+i}}function bo(t){switch(t){case"top-left":return{top:!1,right:!0,bottom:!0,left:!1};case"top-right":return{top:!1,right:!1,bottom:!0,left:!0};case"bottom-right":return{top:!0,right:!1,bottom:!1,left:!0};case"bottom-left":return{top:!0,right:!0,bottom:!1,left:!1};default:return{top:!0,right:!0,bottom:!0,left:!0}}}const yo="#374151";function wo({shape:t,waitingForSecondClick:e,firstClickPoint:n,keyboardMode:o,keyboardActive:i,pinnedCorner:r}){if("rect"===t?.type){if(e&&n){const{x:t,y:e}=n;return St(y,{children:[St("circle",{stroke:"grey","stroke-width":"2px",fill:"none",cx:t,cy:e,r:8}),St("line",{stroke:"grey","stroke-width":"1px",x1:t-12,y1:e,x2:t+12,y2:e}),St("line",{stroke:"grey","stroke-width":"1px",x1:t,y1:e-12,x2:t,y2:e+12})]})}const s=_o(t),a=s.right-s.left,l=s.bottom-s.top,c="resize"===o&&i?bo(r):{
|
|
86
|
+
top:!1,right:!1,bottom:!1,left:!1};return St(y,{children:[St("rect",{stroke:"white","stroke-dasharray":"5","stroke-width":"1px",fill:"grey","fill-opacity":"0.5",x:s.left,y:s.top,width:a,height:l}),St("rect",{stroke:"grey","stroke-dasharray":"5","stroke-dashoffset":"5","stroke-width":"1px",fill:"none",x:s.left,y:s.top,width:a,height:l}),"resize"===o&&i&&St(y,{children:[St("line",{x1:s.left,y1:s.top,x2:s.right,y2:s.top,stroke:c.top?yo:"transparent","stroke-width":"3px","stroke-dasharray":"5","stroke-dashoffset":"5"}),St("line",{x1:s.right,y1:s.top,x2:s.right,y2:s.bottom,stroke:c.right?yo:"transparent","stroke-width":"3px","stroke-dasharray":"5","stroke-dashoffset":"5"}),St("line",{x1:s.left,y1:s.bottom,x2:s.right,y2:s.bottom,stroke:c.bottom?yo:"transparent","stroke-width":"3px","stroke-dasharray":"5","stroke-dashoffset":"5"}),St("line",{x1:s.left,y1:s.top,x2:s.left,y2:s.bottom,stroke:c.left?yo:"transparent","stroke-width":"3px","stroke-dasharray":"5","stroke-dashoffset":"5"})]})]})}if("point"===t?.type){
|
|
87
|
+
const e=t;return St("circle",{stroke:"black","stroke-width":"1px",fill:"yellow",cx:e.x,cy:e.y,r:5})}return null}class vo extends Error{constructor(t,e="Drawing failed"){super(e),this.kind=t}}class xo{_waitingForSecondClick=!1;_hasMoved=!1;_dragThreshold=5;_keyboardMode=null;_keyboardActive=!1;_pinnedCorner="top-left";_keyboardMoveIncrement=10;_keyboardMoveIncrementLarge=50;_defaultRectangleSize=30;_minRectangleSize=20;_maxRectangleSizeRatio=.95;_rectInitiatedByKeyboard=!1;constructor(t){this._container=t,this._tool="rect",this._announcerContainer=document.createElement("div"),this._announcerContainer.setAttribute("data-testid","draw-tool-announcer-container"),t.appendChild(this._announcerContainer),this._indicatorContainer=document.createElement("div"),this._indicatorContainer.setAttribute("data-testid","draw-tool-indicator-container"),t.appendChild(this._indicatorContainer)}destroy(){this.cancel(),this._announcerContainer?.remove(),this._announcerContainer=void 0,this._indicatorContainer?.remove(),
|
|
88
|
+
this._indicatorContainer=void 0,this._removeScrollListener()}getKeyboardModeState(){const t=this._keyboardActive&&null===this._keyboardMode?"rect":this._keyboardMode;return{keyboardActive:this._keyboardActive,keyboardMode:t}}async draw(t,e){this._tool=t,this.cancel("restarted");const n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("data-testid","surface"),n.style.cursor="crosshair",n.style.touchAction="none",n.style.position="absolute",n.setAttribute("width","100%"),n.setAttribute("height","100%"),n.style.left="0px",n.style.top="0px",n.style.zIndex="10",this._container.append(n),this._surface=n;const{promise:o,resolve:i,reject:r}=function(){let t,e;return{promise:new Promise(((n,o)=>{t=n,e=o})),resolve:t,reject:e}}();return this._drawEnd=i,this._drawError=r,this._waitingForSecondClick=!1,this._firstClickPoint=void 0,this._hasMoved=!1,this._rectInitiatedByKeyboard=!1,this._surface.addEventListener("pointerdown",(t=>{switch(this._tool){case"rect":
|
|
89
|
+
if(this._rectInitiatedByKeyboard=!1,this._waitingForSecondClick&&this._firstClickPoint)return this._shape={type:"rect",left:this._firstClickPoint.x,top:this._firstClickPoint.y,right:t.clientX,bottom:t.clientY},this._waitingForSecondClick=!1,this._firstClickPoint=void 0,i(_o(this._shape)),this._abortDraw?.abort(),void t.stopPropagation();this._shape={type:"rect",left:t.clientX,top:t.clientY,right:t.clientX,bottom:t.clientY},this._hasMoved=!1,this._renderSurface();break;case"point":this._shape={type:"point",x:t.clientX,y:t.clientY}}this._renderSurface()})),this._surface.addEventListener("pointermove",(t=>{if(this._rectInitiatedByKeyboard&&"rect"===this._shape?.type)return this._shape=void 0,this._rectInitiatedByKeyboard=!1,this._waitingForSecondClick=!1,this._firstClickPoint=void 0,this._hasMoved=!1,this._deactivateKeyboardMode(),void this._renderSurface();if(this._shape){switch(this._shape.type){case"rect":if(!this._hasMoved){const e=Math.abs(t.clientX-this._shape.left),n=Math.abs(t.clientY-this._shape.top)
|
|
90
|
+
;this._hasMoved=e>=this._dragThreshold||n>=this._dragThreshold}this._shape.right=t.clientX,this._shape.bottom=t.clientY;break;case"point":this._shape.x=t.clientX,this._shape.y=t.clientY}this._renderSurface()}})),this._surface.addEventListener("pointerup",(t=>{if(this._waitingForSecondClick)t.stopPropagation();else if(this._shape){switch(this._shape.type){case"rect":if(this._hasMoved)this._shape.right=t.clientX,this._shape.bottom=t.clientY,i(_o(this._shape));else{const e=Math.abs(t.clientX-this._shape.left),n=Math.abs(t.clientY-this._shape.top);if(e<this._dragThreshold&&n<this._dragThreshold)return this._firstClickPoint={x:this._shape.left,y:this._shape.top},this._waitingForSecondClick=!0,this._renderSurface(),void t.stopPropagation();this._shape.right=t.clientX,this._shape.bottom=t.clientY,i(_o(this._shape))}break;case"point":this._shape.x=t.clientX,this._shape.y=t.clientY,i(this._shape)}this._abortDraw?.abort(),t.stopPropagation()}})),this._surface.addEventListener("wheel",(t=>{
|
|
91
|
+
let e=Math.abs(t.deltaY),n=Math.abs(t.deltaX);for(const o of document.elementsFromPoint(t.clientX,t.clientY)){const i=o.scrollLeft;o.scrollLeft+=n*Math.sign(t.deltaX),n-=Math.abs(o.scrollLeft-i);const r=o.scrollTop;o.scrollTop+=e*Math.sign(t.deltaY),e-=Math.abs(o.scrollTop-r)}})),this._abortDraw=new AbortController,document.body.addEventListener("keydown",(t=>{if(!Ge(t.target)){if("Escape"===t.key)return this._keyboardActive&&this._deactivateKeyboardMode(),this._drawError&&this._drawError(new vo("canceled","Drawing canceled")),void this._abortDraw?.abort();if(this._keyboardActive){if("Tab"===t.key&&"resize"===this._keyboardMode&&"rect"===this._tool){t.preventDefault(),t.stopPropagation();const e=(uo.indexOf(this._pinnedCorner)+1)%uo.length;return this._pinnedCorner=uo[e],this._updateAnnouncer(),void this._renderSurface()}if("Enter"===t.key)return t.preventDefault(),t.stopPropagation(),void(this._shape&&("rect"===this._shape.type?i(_o(this._shape)):i(this._shape),this._deactivateKeyboardMode(),
|
|
92
|
+
this._abortDraw?.abort()));if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(t.key)){t.preventDefault(),t.stopPropagation();const e=t.metaKey||t.ctrlKey?this._keyboardMoveIncrementLarge:this._keyboardMoveIncrement;this._handleArrowKey(t.key,e)}else;}}}),{signal:this._abortDraw.signal}),this._abortDraw.signal.onabort=()=>{this._surface?.remove(),this._shape=void 0,this._surface=void 0,this._drawError=void 0,this._drawEnd=void 0,this._abortDraw=void 0,this._waitingForSecondClick=!1,this._firstClickPoint=void 0,this._hasMoved=!1,this._rectInitiatedByKeyboard=!1,this._deactivateKeyboardMode()},e&&(this._activateKeyboardMode(),this._keyboardMode=e,this._updateAnnouncer()),this._renderSurface(),o}static _RESERVED_VIEWPORT_TOP=40;_updateRectanglePosition(){this._shape=function(t,e,n,o){const{defaultRectangleSize:i,reservedViewportTop:r}=o,s=t.getBoundingClientRect(),a=t.scrollLeft||0,l=t.scrollTop||0;let c=a,h=l;const d=t.querySelectorAll(".page");let u=null,f=0;for(const t of d){
|
|
93
|
+
const e=t.getBoundingClientRect(),n=Math.max(e.top,s.top,r),o=Math.min(e.bottom,s.bottom),i=Math.max(e.left,s.left),a=Math.min(e.right,s.right),l=Math.max(0,a-i)*Math.max(0,o-n);l>0&&e.bottom>s.top+50&&e.top<s.bottom-50&&l>f&&(f=l,u=t)}if(u){const t=u.getBoundingClientRect(),e=Math.max(t.top,s.top,r);c=Math.max(t.left,s.left)-s.left+a,h=e-s.top+l,c+=10,h+=10}else c+=10,h=Math.max(l+10,r-s.top+l+10);if(e&&"rect"===e.type)return{type:"rect",left:c,top:h,right:c+(e.right-e.left),bottom:h+(e.bottom-e.top)};return"point"===n?{type:"point",x:c,y:h}:{type:"rect",left:c,top:h,right:c+i,bottom:h+i}}(this._container,this._shape,this._tool,{defaultRectangleSize:this._defaultRectangleSize,reservedViewportTop:xo._RESERVED_VIEWPORT_TOP}),this._renderSurface()}_setupScrollListener(){this._removeScrollListener(),this._scrollListener=()=>{void 0!==this._scrollDebounceTimeout&&window.clearTimeout(this._scrollDebounceTimeout),this._scrollDebounceTimeout=window.setTimeout((()=>{
|
|
94
|
+
this._keyboardActive&&"rect"===this._shape?.type&&(this._updateRectanglePosition(),this._updateAnnouncer())}),50)},this._container.addEventListener("scroll",this._scrollListener,{passive:!0})}_removeScrollListener(){this._scrollListener&&(this._container.removeEventListener("scroll",this._scrollListener),this._scrollListener=void 0),void 0!==this._scrollDebounceTimeout&&(window.clearTimeout(this._scrollDebounceTimeout),this._scrollDebounceTimeout=void 0)}_activateKeyboardMode(){this._keyboardActive=!0,this._keyboardMode=null,this._pinnedCorner="top-left",this._shape||(this._updateRectanglePosition(),this._rectInitiatedByKeyboard=!0),this._setupScrollListener(),this._updateAnnouncer()}_deactivateKeyboardMode(){this._keyboardActive=!1,this._keyboardMode=null,this._pinnedCorner="top-left",this._removeScrollListener(),this._updateAnnouncer()}_handleArrowKey(t,e){if(!this._shape||!this._keyboardMode)return;const n=function(t,e){const n=t.getBoundingClientRect(),o=t.scrollLeft||0,i=t.scrollTop||0;return{minLeft:o,
|
|
95
|
+
minTop:i+Math.max(0,e-n.top),maxRight:o+t.clientWidth,maxBottom:i+t.clientHeight}}(this._container,xo._RESERVED_VIEWPORT_TOP);if("point"===this._shape.type&&"move"===this._keyboardMode)return this._shape=function(t,e,n,o){switch(e){case"ArrowUp":return{...t,y:Math.max(o.minTop,t.y-n)};case"ArrowDown":return{...t,y:Math.min(o.maxBottom,t.y+n)};case"ArrowLeft":return{...t,x:Math.max(o.minLeft,t.x-n)};case"ArrowRight":return{...t,x:Math.min(o.maxRight,t.x+n)};default:return t}}(this._shape,t,e,n),this._renderSurface(),void this._updateAnnouncer();if("rect"===this._shape.type){const o=_o(this._shape);if("move"===this._keyboardMode)return this._shape=mo(function(t,e,n,o){const{left:i,top:r,right:s,bottom:a}=t;switch(e){case"ArrowUp":{const t=Math.max(o.minTop,r-n);return{type:"rect",left:i,top:t,right:s,bottom:a-(r-t)}}case"ArrowDown":{const t=Math.min(o.maxBottom,a+n);return{type:"rect",left:i,top:r+(t-a),right:s,bottom:t}}case"ArrowLeft":{const t=Math.max(o.minLeft,i-n);return{type:"rect",left:t,top:r,
|
|
96
|
+
right:s-(i-t),bottom:a}}case"ArrowRight":{const t=Math.min(o.maxRight,s+n);return{type:"rect",left:i+(t-s),top:r,right:t,bottom:a}}default:return t}}(o,t,e,n),n),this._renderSurface(),void this._updateAnnouncer();if("resize"===this._keyboardMode){if(!function(t,e){const n=bo(e);switch(t){case"ArrowUp":return n.top||n.bottom;case"ArrowDown":return n.bottom||n.top;case"ArrowLeft":return n.left||n.right;case"ArrowRight":return n.right||n.left;default:return!1}}(t,this._pinnedCorner))return;const i=n.maxRight-n.minLeft,r=n.maxBottom-n.minTop,s={minWidth:this._minRectangleSize,minHeight:this._minRectangleSize,maxWidth:i*this._maxRectangleSizeRatio,maxHeight:r*this._maxRectangleSizeRatio,increment:e};this._shape=mo(function(t,e,n,o){const{left:i,top:r,right:s,bottom:a}=t,{minWidth:l,minHeight:c,maxWidth:h,maxHeight:d,increment:u}=o,f={...t};switch(n){case"top-left":switch(e){case"ArrowRight":{const t=Math.min(i+h,s+u);f.right=t;break}case"ArrowDown":{const t=Math.min(r+d,a+u);f.bottom=t;break}case"ArrowLeft":
|
|
97
|
+
f.right=Math.max(i+l,s-u);break;case"ArrowUp":f.bottom=Math.max(r+c,a-u)}break;case"top-right":switch(e){case"ArrowRight":f.left=Math.min(s-l,i+u);break;case"ArrowDown":{const t=Math.min(r+d,a+u);f.bottom=t;break}case"ArrowLeft":{const t=Math.max(s-h,i-u);f.left=t;break}case"ArrowUp":f.bottom=Math.max(r+c,a-u)}break;case"bottom-right":switch(e){case"ArrowRight":f.left=Math.min(s-l,i+u);break;case"ArrowDown":f.top=Math.min(a-c,r+u);break;case"ArrowLeft":{const t=Math.max(s-h,i-u);f.left=t;break}case"ArrowUp":{const t=Math.max(a-d,r-u);f.top=t;break}}break;case"bottom-left":switch(e){case"ArrowRight":{const t=Math.min(i+h,s+u);f.right=t;break}case"ArrowDown":f.top=Math.min(a-c,r+u);break;case"ArrowLeft":f.right=Math.max(i+l,s-u);break;case"ArrowUp":{const t=Math.max(a-d,r-u);f.top=t;break}}}return f}(o,t,this._pinnedCorner,s),n),this._renderSurface(),this._updateAnnouncer()}}}setOnKeyboardModeChange(t){this._onKeyboardModeChange=t}setKeyboardMode(t){
|
|
98
|
+
this._surface&&(this._keyboardActive||this._activateKeyboardMode(),this._keyboardMode!==t&&(this._keyboardMode=t,"resize"===t&&(this._pinnedCorner="top-left"),this._updateAnnouncer(),this._renderSurface()))}_updateAnnouncer(){if(!this._announcerContainer||!this._indicatorContainer)return;let t,e,n,o;if(this._shape)if("point"===this._shape.type)t=this._shape.x,e=this._shape.y;else{const i=_o(this._shape);t=i.left,e=i.top,n=i.right-i.left,o=i.bottom-i.top}const i=this._keyboardActive&&null===this._keyboardMode?"rect":this._keyboardMode;H(St(po,{mode:i,tool:this._tool,x:t,y:e,width:n,height:o,keyboardActive:this._keyboardActive,pinnedCorner:this._pinnedCorner}),this._announcerContainer),H(St(go,{mode:i,keyboardActive:this._keyboardActive,pinnedCorner:this._pinnedCorner}),this._indicatorContainer),this._onKeyboardModeChange&&this._onKeyboardModeChange({keyboardActive:this._keyboardActive,keyboardMode:i})}cancel(t="canceled"){this._drawError&&this._drawError(new vo(t,"Drawing canceled")),this._abortDraw?.abort(),
|
|
99
|
+
this._waitingForSecondClick=!1,this._firstClickPoint=void 0,this._hasMoved=!1}_renderSurface(){this._surface&&H(St(wo,{shape:this._shape,waitingForSecondClick:this._waitingForSecondClick,firstClickPoint:this._firstClickPoint,keyboardMode:this._keyboardMode,keyboardActive:this._keyboardActive,pinnedCorner:this._pinnedCorner}),this._surface)}}class Co extends CustomEvent{constructor(t){super("hypothesis:layoutchange",{bubbles:!0,cancelable:!1,detail:t})}}const So=new Set;function Ao(...t){const e=t.join();So.has(e)||(console.warn(...t),So.add(e))}Ao.reset=()=>{So.clear()};const ko=["pdf_image_annotation","styled_highlight_clusters","vpat_keyboard"];class Mo extends Me{constructor(t=ko){super(),this._flags=new Map,this._knownFlags=t}update(t){this._flags.clear();for(const[e,n]of Object.entries(t))this._flags.set(e,n);this.emit("flagsChanged")}flagEnabled(t){return this._knownFlags.includes(t)?this._flags.get(t)??!1:(Ao("Looked up unknown feature",t),!1)}allFlags(){return Object.fromEntries(this._flags)}}
|
|
100
|
+
function Ro({cluster:t,label:e,onChange:n,currentStyles:o,highlightStyles:i}){const r=o[t],s="transparent"===r;return St("div",{className:"space-y-2",children:[St("div",{className:"flex items-center gap-x-2 text-annotator-base",children:St("div",{className:"grow text-color-text px-2 py-1 rounded",style:{backgroundColor:i[r].color},children:e})}),St("div",{className:"flex items-center gap-x-2",children:Object.keys(i).map((e=>St("div",{className:"relative",children:[St("input",{className:Tt("absolute w-6 h-6","opacity-[.00001]","cursor-pointer"),name:t,id:`hypothesis-${t}-${e}`,checked:r===e,onChange:n,type:"radio",value:e}),St("label",{className:"block",htmlFor:`${t}-${e}`,children:[St("div",{style:{backgroundColor:i[e].color},className:Tt("block w-6 h-6 rounded-full flex items-center justify-center",{"border-2 border-slate-0":r!==e,"border-2 border-slate-3":r===e}),children:"transparent"===e&&St($t,{className:Tt("w-3 h-3",{"text-slate-3":!s,"text-slate-7":s})})}),St("span",{className:"sr-only",children:e})]
|
|
101
|
+
})]},`${t}-${e}`)))})]})}function Eo({active:t,availableStyles:e,currentStyles:n,onStyleChange:o}){const i=st((t=>{const e=t.target,n=e.name,i=e.value;o(n,i)}),[o]),[r,s]=et(!1);return t?St(Nt,{classes:"overflow-hidden",children:St("div",{className:"flex flex-col text-annotator-base text-color-text",children:[St(ee,{classes:"rounded-none","data-testid":"control-toggle-button",onClick:()=>s(!r),title:r?"Hide highlight settings":"Show highlight settings",children:St(y,r?{children:[St(Bt,{}),St("span",{children:"Highlight Appearance"})]}:{children:[St(Ft,{}),St(qt,{})]})}),r&&St(Lt,{"data-testid":"cluster-style-controls",size:"sm",children:[St(Ro,{highlightStyles:e,label:"My annotations",cluster:"user-annotations",onChange:i,currentStyles:n}),St(Ro,{highlightStyles:e,label:"My highlights",cluster:"user-highlights",onChange:i,currentStyles:n}),St(Ro,{highlightStyles:e,label:"Everybody's content",cluster:"other-content",onChange:i,currentStyles:n})]})]})}):null}const Po={transparent:{color:"transparent",
|
|
102
|
+
secondColor:"transparent",thirdColor:"transparent"},pink:{color:"var(--hypothesis-color-pink)",secondColor:"var(--hypothesis-color-pink-1)",thirdColor:"var(--hypothesis-color-pink-2)"},orange:{color:"var(--hypothesis-color-orange)",secondColor:"var(--hypothesis-color-orange-1)",thirdColor:"var(--hypothesis-color-orange-2)"},yellow:{color:"var(--hypothesis-color-yellow)",secondColor:"var(--hypothesis-color-yellow-1)",thirdColor:"var(--hypothesis-color-yellow-2)"},green:{color:"var(--hypothesis-color-green)",secondColor:"var(--hypothesis-color-green-1)",thirdColor:"var(--hypothesis-color-green-2)"},purple:{color:"var(--hypothesis-color-purple)",secondColor:"var(--hypothesis-color-purple-1)",thirdColor:"var(--hypothesis-color-purple-2)"},grey:{color:"var(--hypothesis-color-grey)",secondColor:"var(--hypothesis-color-grey-1)",thirdColor:"var(--hypothesis-color-grey-2)"}},To={"other-content":"yellow","user-annotations":"orange","user-highlights":"purple"};class No{constructor(t,e){this._element=t,
|
|
103
|
+
this._features=e.features,this._container=new Pn("highlight-cluster-toolbar",(()=>this._render())),this._element.appendChild(this._container.element),Object.assign(this._container.element.style,{position:"fixed",top:`${this._element.offsetTop+4}px`,left:"4px"}),this.appliedStyles=To,this._init(),this._features.on("flagsChanged",(()=>{this._activate(this._isActive())})),this._container.render()}destroy(){clearTimeout(this._updateTimeout),this._activate(!1),this._container.destroy()}scheduleClusterUpdates(){clearTimeout(this._updateTimeout),this._updateTimeout=setTimeout((()=>this._updateClusters()),100)}_init(){for(const t of Object.keys(this.appliedStyles))this._setClusterStyles(t,this.appliedStyles[t]);this._activate(this._isActive())}_updateClusters(){this._isActive()&&io(this._element)}_isActive(){return this._features.flagEnabled("styled_highlight_clusters")}_activate(t){this._element.classList.toggle("hypothesis-highlights-clustered",t),this._container.render()}_setClusterStyle(t,e){
|
|
104
|
+
document.documentElement.style.setProperty(t,e)}_setClusterStyles(t,e){const n=Po[e];for(const e of Object.keys(n))this._setClusterStyle(`--hypothesis-${t}-${e}`,n[e])}_onChangeClusterStyle(t,e){this.appliedStyles[t]=e,this._setClusterStyles(t,e),this._container.render()}_render(){return St(Eo,{active:this._isActive(),availableStyles:Po,currentStyles:this.appliedStyles,onStyleChange:(t,e)=>this._onChangeClusterStyle(t,e)})}}function Lo(t){return t.split("").reverse().join("")}function Oo(t){return(t|-t)>>31&1}function Io(t,e,n,o){let i=t.P[n],r=t.M[n];const s=o>>>31,a=e[n]|s,l=a|r,c=(a&i)+i^i|a;let h=r|~(c|i),d=i&c;const u=Oo(h&t.lastRowMask[n])-Oo(d&t.lastRowMask[n]);return h<<=1,d<<=1,d|=s,h|=Oo(o)-s,i=d|~(l|h),r=h&l,t.P[n]=i,t.M[n]=r,u}function Bo(t,e,n){if(0===e.length)return[];n=Math.min(n,e.length);const o=[],i=32,r=Math.ceil(e.length/i)-1,s={P:new Uint32Array(r+1),M:new Uint32Array(r+1),lastRowMask:new Uint32Array(r+1)};s.lastRowMask.fill(1<<31),s.lastRowMask[r]=1<<(e.length-1)%i
|
|
105
|
+
;const a=new Uint32Array(r+1),l=new Map,c=[];for(let t=0;t<256;t++)c.push(a);for(let t=0;t<e.length;t+=1){const n=e.charCodeAt(t);if(l.has(n))continue;const o=new Uint32Array(r+1);l.set(n,o),n<c.length&&(c[n]=o);for(let t=0;t<=r;t+=1){o[t]=0;for(let r=0;r<i;r+=1){const s=t*i+r;if(s>=e.length)continue;e.charCodeAt(s)===n&&(o[t]|=1<<r)}}}let h=Math.max(0,Math.ceil(n/i)-1);const d=new Uint32Array(r+1);for(let t=0;t<=h;t+=1)d[t]=(t+1)*i;d[r]=e.length;for(let t=0;t<=h;t+=1)s.P[t]=-1,s.M[t]=0;for(let u=0;u<t.length;u+=1){const f=t.charCodeAt(u);let p;f<c.length?p=c[f]:(p=l.get(f),void 0===p&&(p=a));let g=0;for(let t=0;t<=h;t+=1)g=Io(s,p,t,g),d[t]+=g;if(d[h]-g<=n&&h<r&&(1&p[h+1]||g<0)){let t;if(h+=1,s.P[h]=-1,s.M[h]=0,h===r){const n=e.length%i;t=0===n?i:n}else t=i;d[h]=d[h-1]+t-g+Io(s,p,h,g)}else for(;h>0&&d[h]>=n+i;)h-=1;h===r&&d[h]<=n&&(d[h]<n&&o.splice(0,o.length),o.push({start:-1,end:u+1,errors:d[h]}),n=d[h])}return o}function Do(t,e,n){return function(t,e,n){const o=Lo(e);return n.map((n=>{
|
|
106
|
+
const i=Math.max(0,n.end-e.length-n.errors);return{start:Bo(Lo(t.slice(i,n.end)),o,n.errors).reduce(((t,e)=>n.end-e.end<t?n.end-e.end:t),n.end),end:n.end,errors:n.errors}}))}(t,e,Bo(t,e,n))}function Fo(t,e,n){let o=0;const i=[];for(;-1!==o;)o=t.indexOf(e,o),-1!==o&&(i.push({start:o,end:o+e.length,errors:0}),o+=1);return i.length>0?i:Do(t,e,n)}function Ho(t,e){if(0===e.length||0===t.length)return 0;return 1-Fo(t,e,e.length)[0].errors/e.length}function Vo(t,e,n={}){if(0===e.length)return null;const o=Math.min(256,e.length/2),i=Fo(t,e,o);if(0===i.length)return null;const r=o=>{const i=1-o.errors/e.length,r=n.prefix?Ho(t.slice(Math.max(0,o.start-n.prefix.length),o.start),n.prefix):1,s=n.suffix?Ho(t.slice(o.end,o.end+n.suffix.length),n.suffix):1;let a=1;if("number"==typeof n.hint){a=1-Math.abs(o.start-n.hint)/t.length}return(50*i+20*r+20*s+2*a)/92},s=i.map((t=>({start:t.start,end:t.end,score:r(t)})));return s.sort(((t,e)=>e.score-t.score)),s[0]}function zo(t){const e=document.createElement("div")
|
|
107
|
+
;return e.appendChild(t.cloneContents()),function(t){for(const e of Array.from(t.querySelectorAll("br")))e.replaceWith(document.createTextNode(" "));return t.textContent??""}(e)}function Uo(t,e){let n=0;for(const o of t){if(!(o<e))break;n+=1}return e-n}function $o(t){const e=function(t){const e=t.nodeName.toLowerCase();return"#text"===e?"text()":e}(t),n=function(t){let e=0,n=t;for(;n;)n.nodeName===t.nodeName&&(e+=1),n=n.previousSibling;return e}(t);return`${e}[${n}]`}function qo(t,e){let n="",o=t;for(;o!==e;){if(!o)throw new Error("Node is not a descendant of root");n=$o(o)+"/"+n,o=o.parentNode}return n="/"+n,n=n.replace(/\/$/,""),n}function Wo(t,e,n){e=e.toUpperCase();let o=-1;for(let i=0;i<t.children.length;i++){const r=t.children[i];if(r.nodeName.toUpperCase()===e&&(++o,o===n))return r}return null}function jo(t,e=document.body){try{return function(t,e){if(null===t.match(/^(\/[A-Za-z0-9-]+(\[[0-9]+\])?)+$/))throw new Error("Expression is not a simple XPath");const n=t.split("/");let o=e;n.shift()
|
|
108
|
+
;for(const t of n){let e,n;const i=t.indexOf("[");if(-1!==i){e=t.slice(0,i);const o=t.slice(i+1,t.indexOf("]"));if(n=parseInt(o)-1,n<0)return null}else e=t,n=0;const r=Wo(o,e,n);if(!r)return null;o=r}return o}(t,e)}catch{return document.evaluate("."+t,e,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}}class Ko{constructor(t,e){this.root=t,this.range=e}static fromRange(t,e){return new Ko(t,e)}static fromSelector(t,e){const n=jo(e.startContainer,t);if(!n)throw new Error("Failed to resolve startContainer XPath");const o=jo(e.endContainer,t);if(!o)throw new Error("Failed to resolve endContainer XPath");const i=zn.fromCharOffset(n,e.startOffset),r=zn.fromCharOffset(o,e.endOffset),s=new Un(i,r).toRange();return new Ko(t,s)}toRange(){return this.range}toSelector(){const t=Un.fromRange(this.range).toRange(),e=Un.fromRange(t),n=qo(e.start.element,this.root),o=qo(e.end.element,this.root);return{type:"RangeSelector",startContainer:n,startOffset:e.start.offset,endContainer:o,endOffset:e.end.offset}}}
|
|
109
|
+
class Xo{constructor(t,e,n){this.root=t,this.start=e,this.end=n}static fromRange(t,e){const n=Un.fromRange(e).relativeTo(t);return new Xo(t,n.start.offset,n.end.offset)}static fromSelector(t,e){return new Xo(t,e.start,e.end)}toSelector(){return{type:"TextPositionSelector",start:this.start,end:this.end}}toRange(){return Un.fromOffsets(this.root,this.start,this.end).toRange()}}class Yo{constructor(t,e,n={}){this.root=t,this.exact=e,this.context=n}static fromRange(t,e){const n=t.textContent??"",o=Un.fromRange(e).relativeTo(t),i=o.start.offset,r=o.end.offset,s=zo(e),a=zo(Un.fromOffsets(t,Math.max(0,i-32),i).toRange()),l=zo(Un.fromOffsets(t,r,Math.min(n.length,r+32)).toRange());return new Yo(t,s,{prefix:a,suffix:l})}static fromSelector(t,e){const{prefix:n,suffix:o}=e;return new Yo(t,e.exact,{prefix:n,suffix:o})}toSelector(){return{type:"TextQuoteSelector",exact:this.exact,prefix:this.context.prefix,suffix:this.context.suffix}}toRange(t={}){return this.toPositionAnchor(t).toRange()}toPositionAnchor(t={}){
|
|
110
|
+
const{text:e,brPositionsInText:n}=function(t){let e="";const n=[],o=t=>{if(t.nodeType!==Node.TEXT_NODE){if(t.nodeType===Node.ELEMENT_NODE){if("BR"===t.tagName)return n.push(e.length),void(e+=" ");for(const e of Array.from(t.childNodes))o(e)}}else e+=t.textContent??""};return o(t),{text:e,brPositionsInText:n}}(this.root),o=Vo(e,this.exact,{...this.context,hint:t.hint});if(!o)throw new Error("Quote not found");return new Xo(this.root,Uo(n,o.start),Uo(n,o.end))}}function Go(t){const e=parseFloat(t);return!Number.isFinite(e)||e<0?null:e}function Qo(t){return t instanceof Element?t:t.parentElement}function Jo(t,e=t){const n=Go(t?.getAttribute("data-time-start")??""),o=Go(e?.getAttribute("data-time-end")??"");return"number"!=typeof n||"number"!=typeof o||o<n?null:[n,o]}class Zo{constructor(t,e,n){this.root=t,this.start=e,this.end=n}static fromRange(t,e){const n=Qo(e.startContainer)?.closest("[data-time-start]"),o=Qo(e.endContainer)?.closest("[data-time-end]"),i=Jo(n,o);if(!i)return null;const[r,s]=i
|
|
111
|
+
;return new Zo(t,r,s)}toRange(){const t=[...this.root.querySelectorAll("[data-time-start]")].map((t=>{const e=Jo(t);if(!e)return null;const[n,o]=e;return{element:t,start:n,end:o}})).filter((t=>null!==t));t.sort(((t,e)=>t.start-e.start));const e=function(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}(t,(t=>t.start<=this.start&&t.end>=this.start));if(-1===e)throw new Error("Start segment not found");const n=e+t.slice(e).findIndex((t=>t.start<=this.end&&t.end>=this.end));if(-1===n)throw new Error("End segment not found");const o=new Range;o.setStart(t[e].element,0);const i=t[n].element;return o.setEnd(i,i.childNodes.length),o}static fromSelector(t,e){const{start:n,end:o}=e;return new Zo(t,n,o)}toSelector(){return{type:"MediaTimeSelector",start:this.start,end:this.end}}}async function ti(t,e){return t.toRange(e)}function ei(t,e,n){const o=t[e];if("function"!=typeof o)throw new Error("Can only intercept functions");return t[e]=(...e)=>{const i=o.call(t,...e);return n(...e),i},()=>{t[e]=o}}
|
|
112
|
+
function ni(t){return t.replace(/#.*/,"")}class oi{constructor(t,e=(()=>location.href)){this._listeners=new mt;let n=e();const o=(o=e())=>{ni(n)!==ni(o)&&(n=o,t(o))},i=function(){const t=window.navigation;return"function"==typeof Navigation&&t instanceof Navigation?t:null}();if(i)this._listeners.add(i,"navigatesuccess",(()=>o()));else{const t=[ei(window.history,"pushState",(()=>o())),ei(window.history,"replaceState",(()=>o()))];this._unpatchHistory=()=>t.forEach((t=>t())),this._listeners.add(window,"popstate",(()=>o()))}}disconnect(){this._unpatchHistory?.(),this._listeners.removeAll()}}var ii,ri;var si=function(){if(ri)return ii;ri=1;var t="complete",e="canceled";function n(t,e,n){t.self===t?t.scrollTo(e,n):(t.scrollLeft=e,t.scrollTop=n)}function o(e){var i=e._scrollSettings;if(i){var r=i.maxSynchronousAlignments,s=function(t,e){
|
|
113
|
+
var n,o,i,r,s,a,l,c=t.align,h=t.target.getBoundingClientRect(),d=c&&null!=c.left?c.left:.5,u=c&&null!=c.top?c.top:.5,f=c&&null!=c.leftOffset?c.leftOffset:0,p=c&&null!=c.topOffset?c.topOffset:0,g=d,_=u;if(t.isWindow(e))a=Math.min(h.width,e.innerWidth),l=Math.min(h.height,e.innerHeight),o=h.left+e.pageXOffset-e.innerWidth*g+a*g,i=h.top+e.pageYOffset-e.innerHeight*_+l*_,o-=f,i-=p,o=t.align.lockX?e.pageXOffset:o,i=t.align.lockY?e.pageYOffset:i,r=o-e.pageXOffset,s=i-e.pageYOffset;else{a=h.width,l=h.height,n=e.getBoundingClientRect();var m=h.left-(n.left-e.scrollLeft),b=h.top-(n.top-e.scrollTop);o=m+a*g-e.clientWidth*g,i=b+l*_-e.clientHeight*_,o-=f,i-=p,o=Math.max(Math.min(o,e.scrollWidth-e.clientWidth),0),i=Math.max(Math.min(i,e.scrollHeight-e.clientHeight),0),o=t.align.lockX?e.scrollLeft:o,i=t.align.lockY?e.scrollTop:i,r=o-e.scrollLeft,s=i-e.scrollTop}return{x:o,y:i,differenceX:r,differenceY:s}}(i,e),a=Date.now()-i.startTime,l=Math.min(1/i.time*a,1);if(i.endIterations>=r)return n(e,s.x,s.y),
|
|
114
|
+
e._scrollSettings=null,i.end(t);var c=1-i.ease(l);if(n(e,s.x-s.differenceX*c,s.y-s.differenceY*c),a>=i.time)return i.endIterations++,i.scrollAncestor&&o(i.scrollAncestor),void o(e);!function(t){if("requestAnimationFrame"in window)return window.requestAnimationFrame(t);setTimeout(t,16)}(o.bind(null,e))}}function i(t){return t.self===t}function r(t){return"pageXOffset"in t||(t.scrollHeight!==t.clientHeight||t.scrollWidth!==t.clientWidth)&&"hidden"!==getComputedStyle(t).overflow}function s(){return!0}function a(t){if(t.assignedSlot)return a(t.assignedSlot);if(t.parentElement)return"body"===t.parentElement.tagName.toLowerCase()?t.parentElement.ownerDocument.defaultView||t.parentElement.ownerDocument.ownerWindow:t.parentElement;if(t.getRootNode){var e=t.getRootNode();if(11===e.nodeType)return e.host}}return ii=function(n,l,c){if(n){"function"==typeof l&&(c=l,l=null),l||(l={}),l.time=isNaN(l.time)?1e3:l.time,l.ease=l.ease||function(t){return 1-Math.pow(1-t,t/2)},l.align=l.align||{}
|
|
115
|
+
;var h=a(n),d=1,u=l.validTarget||s,f=l.isScrollable;l.debug&&(console.log("About to scroll to",n),h||console.error("Target did not have a parent, is it mounted in the DOM?"));for(var p=[];h;)if(l.debug&&console.log("Scrolling parent node",h),u(h,d)&&(f?f(h,r):r(h))&&(d++,p.push(h)),!(h=a(h))){g(t);break}return p.reduce(((t,r,s)=>function(t,n,r,s,a){var l,c=!n._scrollSettings,h=n._scrollSettings,d=Date.now(),u={passive:!0};function f(t){n._scrollSettings=null,n.parentElement&&n.parentElement._scrollSettings&&n.parentElement._scrollSettings.end(t),r.debug&&console.log("Scrolling ended with type",t,"for",n),a(t),l&&(n.removeEventListener("touchstart",l,u),n.removeEventListener("wheel",l,u))}h&&h.end(e);var p=r.maxSynchronousAlignments;return null==p&&(p=3),n._scrollSettings={startTime:d,endIterations:0,target:t,time:r.time,ease:r.ease,align:r.align,isWindow:r.isWindow||i,maxSynchronousAlignments:p,end:f,scrollAncestor:s},"cancellable"in r&&!r.cancellable||(l=f.bind(null,e),n.addEventListener("touchstart",l,u),
|
|
116
|
+
n.addEventListener("wheel",l,u)),c&&o(n),l}(n,r,l,p[s+1],g)),null)}function g(t){--d||c&&c(t)}},ii}(),ai=kt(si);function li(t,e,n){return t+n*(e-t)}async function ci(t,e,{maxDuration:n=500}={}){const o=t.scrollTop,i=e,r=Date.now(),s=Math.min(Math.abs(i-o)/3,n);let a=0;for(;a<1;)await new Promise((t=>{requestAnimationFrame(t)})),a=Math.min(1,(Date.now()-r)/s),t.scrollTop=li(o,i,a)}function hi(t,e=document.baseURI){return new URL(t,e).href.toString().replace(/#.*/,"")}class di{constructor(t={}){this.document=t.document||document}uri(){let t=this._getDocumentHref();try{t=decodeURIComponent(t)}catch(t){console.error("Error decoding URI:",t)}const e=this._getLinks();for(const n of e)"canonical"===n.rel&&(t=n.href);return t}getDocumentMetadata(){const t={title:document.title,link:[],dc:this._getMetaTags("name","dc."),eprints:this._getMetaTags("name","eprints."),facebook:this._getMetaTags("property","og:"),highwire:this._getMetaTags("name","citation_"),prism:this._getMetaTags("name","prism."),
|
|
117
|
+
twitter:this._getMetaTags("name","twitter:")},e=this._getFavicon();e&&(t.favicon=e),t.title=this._getTitle(t),t.link=this._getLinks(t);const n=t.link.find((t=>t.href.startsWith("urn:x-dc")));n&&(t.documentFingerprint=n.href);const o=this._getVersion(t);return null!==o&&(t.version=o),t}_getVersion(t){const e=[t.highwire.id??[],t.highwire.public_url??[],[t.link.find((t=>"canonical"===t.rel))?.href]];let n=null;for(const t of e){const e=this._findVersion(t);if(!e)return null;if(null===n)n=e;else if(n!==e)return null}return n}_findVersion(t){for(const e of t){const t=this._extractVersionFromUri(e);if(null!==t)return t}return null}_extractVersionFromUri(t){if(void 0===t)return null;const e=t.trim().match(/(?<![a-zA-Z])v(\d+)$/i);if(!e)return null;const n=parseInt(e[1],10);return n>=1&&n<=25?n:null}_getMetaTags(t,e){const n={};for(const o of Array.from(this.document.querySelectorAll("meta"))){const i=o.getAttribute(t),{content:r}=o;if(i&&r){const t=i.match(RegExp(`^${e}(.+)$`,"i"));if(t){const e=t[1].toLowerCase()
|
|
118
|
+
;n[e]?n[e].push(r):n[e]=[r]}}}return n}_getTitle(t){return t.highwire.title?t.highwire.title[0]:t.eprints.title?t.eprints.title[0]:t.prism.title?t.prism.title[0]:t.facebook.title?t.facebook.title[0]:t.twitter.title?t.twitter.title[0]:t.dc.title?t.dc.title[0]:this.document.title}_getLinks(t={dc:{},highwire:{}}){const e=[{href:this._getDocumentHref()}],n=Array.from(this.document.querySelectorAll("link"));for(const t of n)if(["alternate","canonical","bookmark","shortlink"].includes(t.rel)){if("alternate"===t.rel){if(t.type&&t.type.match(/^application\/(rss|atom)\+xml/))continue;if(t.hreflang)continue}try{const n=this._absoluteUrl(t.href);e.push({href:n,rel:t.rel,type:t.type})}catch{}}for(const n of Object.keys(t.highwire)){const o=t.highwire[n];if("pdf_url"===n)for(const t of o)try{e.push({href:this._absoluteUrl(t),type:"application/pdf"})}catch{}if("doi"===n)for(let t of o)"doi:"!==t.slice(0,4)&&(t=`doi:${t}`),e.push({href:t})}for(const n of Object.keys(t.dc)){const o=t.dc[n]
|
|
119
|
+
;if("identifier"===n)for(const t of o)"doi:"===t.slice(0,4)&&e.push({href:t})}const o=t.dc["relation.ispartof"],i=t.dc.identifier;if(o&&i){const t=o[o.length-1],n=i[i.length-1],r="urn:x-dc:"+encodeURIComponent(t)+"/"+encodeURIComponent(n);e.push({href:r})}return e}_getFavicon(){let t=null;for(const e of Array.from(this.document.querySelectorAll("link")))if(["shortcut icon","icon"].includes(e.rel))try{t=this._absoluteUrl(e.href)}catch{}return t}_absoluteUrl(t){return hi(t,this.document.baseURI)}_getDocumentHref(){const{href:t}=this.document.location,e=["http:","https:","file:"],n=new URL(t).protocol;return e.includes(n)?t:this.document.baseURI&&e.includes(new URL(this.document.baseURI).protocol)?this.document.baseURI:t}}class ui extends Me{constructor({features:t,container:e=document.body,sideBySideOptions:n}){super(),this.featureFlags=t,this.container=e,this._htmlMeta=new di,this._prevURI=this._htmlMeta.uri(),this._sideBySideEnabled=!0,this._sideBySideOptions=n??{mode:"auto"},this._sideBySideActive=!1,
|
|
120
|
+
this._lastLayout=null,this._navObserver=new oi((()=>this._checkForURIChange())),this._metaObserver=new MutationObserver((()=>this._checkForURIChange())),this._metaObserver.observe(document.head,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["rel","href","name","content"]}),this._flagsChanged=()=>{},this.featureFlags.on("flagsChanged",this._flagsChanged)}anchor(t,e){return function(t,e,n={}){let o=null,i=null,r=null,s=null;for(const t of e)switch(t.type){case"TextPositionSelector":i=t,n.hint=i.start;break;case"TextQuoteSelector":r=t;break;case"RangeSelector":s=t;break;case"MediaTimeSelector":o=t}const a=t=>{if(r?.exact&&t.toString()!==r.exact)throw new Error("quote mismatch");return t};let l=Promise.reject("unable to anchor");if(s){const e=s;l=l.catch((()=>ti(Ko.fromSelector(t,e),n).then(a)))}if(i){const e=i;l=l.catch((()=>ti(Xo.fromSelector(t,e),n).then(a)))}if(r){const e=r;l=l.catch((()=>ti(Yo.fromSelector(t,e),n)))}if(o){const e=o;l=l.catch((()=>Zo.fromSelector(t,e).toRange()))}return l}(t,e)}
|
|
121
|
+
describe(t,e){if(e instanceof Range)return function(t,e){const n=[Zo,Ko,Xo,Yo],o=[];for(const i of n)try{const n=i.fromRange(t,e);n&&o.push(n.toSelector())}catch{}return o}(t,e);throw new Error("Unsupported region type")}_checkForURIChange(){const t=this._htmlMeta.uri();t!==this._prevURI&&(this._prevURI=t,this.emit("uriChanged",t))}getAnnotatableRange(t){try{return Un.trimmedRange(t)}catch(t){if(t instanceof RangeError)return null;throw t}}canStyleClusteredHighlights(){return!0}destroy(){this._deactivateSideBySide(),this._navObserver.disconnect(),this._metaObserver.disconnect(),this.featureFlags.off("flagsChanged",this._flagsChanged),super.destroy()}contentContainer(){return this.container}fitSideBySide(t){this._lastLayout=t;const e=window.innerWidth-t.width,n=this._sideBySideEnabled&&"auto"===this._sideBySideOptions.mode&&t.expanded&&e>=480;return n?this._activateSideBySide(t.width):this._sideBySideActive&&this._deactivateSideBySide(),this._sideBySideActive=n,
|
|
122
|
+
this.container.classList.toggle("hypothesis-sidebyside-active",this._sideBySideActive),n}sideBySideActive(){return this._sideBySideActive}supportedTools(){return["selection"]}_activateSideBySide(t){const e=t+12,n=t=>parseInt(window.getComputedStyle(t).marginLeft,10);on((()=>{document.body.style.marginLeft="",document.body.style.marginRight="";const t=n(document.body);document.body.style.marginRight=`${e}px`;const o=function(t){const e=new Map,n=new Map,o=Qe.join(","),i=Array.from(t.querySelectorAll(o)).map((t=>({rect:t.getBoundingClientRect(),textLength:t.textContent.length}))).filter((({rect:t})=>t.width>0&&t.height>0)).sort(((t,e)=>e.textLength-t.textLength)).slice(0,15);if(i.forEach((({rect:t})=>{let o=e.get(t.left)??0;o+=1,e.set(t.left,o);let i=n.get(t.right)??0;i+=1,n.set(t.right,i)})),0===e.size||0===n.size)return null;const r=[...e.entries()].sort(((t,e)=>e[1]-t[1])),s=[...n.entries()].sort(((t,e)=>e[1]-t[1])),[a]=r[0],[l]=s[0];return{left:a,right:l}}(document.body);if(o){
|
|
123
|
+
const i=Math.max(0,window.innerWidth-e-o.right);if(i>0){const t=Math.max(0,e-i);document.body.style.marginRight=`${t}px`}n(document.body)>t&&(document.body.style.marginLeft=`${t}px`),o.left<12&&(document.body.style.marginLeft="12px")}else document.body.style.marginLeft="",document.body.style.marginRight=""}))}_deactivateSideBySide(){on((()=>{document.body.style.marginLeft="",document.body.style.marginRight=""}))}async getMetadata(){return this._htmlMeta.getDocumentMetadata()}async uri(){return this._htmlMeta.uri()}async scrollToAnchor(t){const e=t.highlights?.[0];e&&await async function(t,{maxDuration:e=500}={}){const n=t.closest("body");n&&"BODY"!==n.tagName&&Object.defineProperty(n,"tagName",{value:"BODY",configurable:!0});const o=t.closest("details");o&&!o.hasAttribute("open")&&(o.open=!0),await new Promise((n=>ai(t,{time:e},n)))}(e)}}var fi,pi;var gi=function(){if(pi)return fi;pi=1
|
|
124
|
+
;var t=NaN,e="[object Symbol]",n=/^\s+|\s+$/g,o=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,r=/^0o[0-7]+$/i,s=parseInt,a="object"==typeof At&&At&&At.Object===Object&&At,l="object"==typeof self&&self&&self.Object===Object&&self,c=a||l||Function("return this")(),h=Object.prototype.toString,d=Math.max,u=Math.min,f=function(){return c.Date.now()};function p(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function g(a){if("number"==typeof a)return a;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&h.call(t)==e}(a))return t;if(p(a)){var l="function"==typeof a.valueOf?a.valueOf():a;a=p(l)?l+"":l}if("string"!=typeof a)return 0===a?a:+a;a=a.replace(n,"");var c=i.test(a);return c||r.test(a)?s(a.slice(2),c?2:8):o.test(a)?t:+a}return fi=function(t,e,n){var o,i,r,s,a,l,c=0,h=!1,_=!1,m=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function b(e){var n=o,r=i;return o=i=void 0,c=e,s=t.apply(r,n)}function y(t){var n=t-l;return void 0===l||n>=e||n<0||_&&t-c>=r}
|
|
125
|
+
function w(){var t=f();if(y(t))return v(t);a=setTimeout(w,function(t){var n=e-(t-l);return _?u(n,r-(t-c)):n}(t))}function v(t){return a=void 0,m&&o?b(t):(o=i=void 0,s)}function x(){var t=f(),n=y(t);if(o=arguments,i=this,l=t,n){if(void 0===a)return function(t){return c=t,a=setTimeout(w,e),h?b(t):s}(l);if(_)return a=setTimeout(w,e),b(l)}return void 0===a&&(a=setTimeout(w,e)),s}return e=g(e)||0,p(n)&&(h=!!n.leading,r=(_="maxWait"in n)?d(g(n.maxWait)||0,e):r,m="trailing"in n?!!n.trailing:m),x.cancel=function(){void 0!==a&&clearTimeout(a),c=0,o=l=i=a=void 0},x.flush=function(){return void 0===a?s:v(f())},x},fi}(),_i=kt(gi);function mi(t,e,n,o=0){let i=o;for(;i<t.length&&e>0;)n(t[i])&&--e,++i;return i}function bi(t,e,n,o){let i=0;for(let r=n;r<o;r++)e(t[r])&&++i;return i}const yi=new Map;function wi(t,e){const n=t.normalize("NFKD");if(n===t)return{input:t,output:n};const o=[],i=[];let r=0,s=0;for(const n of t){const t=n.codePointAt(0);let a=yi.get(t);if(void 0===a&&(a=n.normalize("NFKD").length,yi.set(t,a)),
|
|
126
|
+
e.offsets){for(let t=0;t<n.length;t++)i.push(s);s+=a}if(e.reverseOffsets){for(let t=0;t<a;t++)o.push(r);r+=n.length}}return e.offsets&&i.push(n.length),e.reverseOffsets&&o.push(r),{input:t,output:n,reverseOffsets:o,offsets:i}}function vi(t,e,n,o,i,r={}){n=Math.max(0,Math.min(n,t.length)),o=Math.max(n,Math.min(o,t.length));const s=r.normalize?wi(t,{offsets:!0}):{output:t},a=r.normalize?wi(e,{reverseOffsets:!0}):{output:e},l=s.offsets?.[n]??n,c=s.offsets?.[o]??o,h=bi(s.output,i,0,l),d=bi(s.output,i,l,c);let u=mi(a.output,h,i);for(;u<a.output.length&&!i(a.output[u]);)++u;const f=mi(a.output,d,i,u);return[a.reverseOffsets?.[u]??u,a.reverseOffsets?.[f]??f]}const xi={INITIAL:0,FINISHED:3},Ci=new Map,Si=new Map;function Ai(t,e){return`${t}:${e}`}function ki(t){const e="closest"in t?t:t.parentElement;return e?.closest(".textLayer")??null}function Mi(){return PDFViewerApplication.pdfViewer}async function Ri(t){const e=Mi();let n=e.getPageView(t);return n&&n.pdfPage||(n=await new Promise((n=>{const o=()=>{
|
|
127
|
+
e.eventBus?e.eventBus.off("pagesloaded",o):document.removeEventListener("pagesloaded",o),n(e.getPageView(t))};e.eventBus?e.eventBus.on("pagesloaded",o):document.addEventListener("pagesloaded",o)}))),n}function Ei(t,e){return document.elementsFromPoint(t,e).find((t=>t.classList.contains("textLayer")))}function Pi(t){const e=Ci.get(t);if(e)return e;const n=(async()=>{const e=await Ri(t);return(await e.pdfPage.getTextContent({normalizeWhitespace:!0})).items.map((t=>t.str)).join("")})();return Ci.set(t,n),n}async function Ti(t){const e=Mi();let n=0,o=0,i="";for(let r=0;r<e.pagesCount;r++)if(i=await Pi(r),n=o,o+=i.length,o>=t)return{index:r,offset:n,text:i};return{index:e.pagesCount-1,offset:n,text:i}}function Ni(t){switch(t){case" ":case"\f":case"\n":case"\r":case"\t":case"\v":case" ":return!0;default:return!1}}const Li=t=>!Ni(t);function Oi(t){return void 0!==t.renderingDone?t.renderingDone:!!t.div&&null!==t.div.querySelector(".endOfContent")}async function Ii(t,e,n){const[o,i]=await Promise.all([Ri(t),Pi(t)])
|
|
128
|
+
;if(o.renderingState===xi.FINISHED&&o.textLayer&&Oi(o.textLayer)){const t=o.textLayer.textLayerDiv??o.textLayer.div;if(!t)throw new Error("Unable to find PDF.js text layer root");const r=t.textContent,[s,a]=vi(i,r,e,n,Li,{normalize:!0}),l=Bi(r.slice(s,a)),c=Bi(i.slice(e,n));l.normalize("NFKD")!==c.normalize("NFKD")&&Ao("Text layer text does not match page text. Highlights will be mis-aligned.");const h=new zn(t,s),d=new zn(t,a);return new Un(h,d).toRange()}const r=function(t){let e=t.querySelector($n);return e||(e=document.createElement("span"),e.classList.add("annotator-placeholder"),e.textContent="Loading annotations...",t.appendChild(e),e)}(o.div),s=document.createRange();return s.setStartBefore(r),s.setEndAfter(r),s}function Bi(t){let e="";for(let n=0;n<t.length;n++){const o=t[n];Ni(o)||(e+=o)}return e}async function Di(t){const e=t.find((t=>"TextQuoteSelector"===t.type));if(!e)throw new Error("No quote selector found");const n=t.find((t=>"TextPositionSelector"===t.type));if(n){try{
|
|
129
|
+
const{index:t,offset:o,text:i}=await Ti(n.start),r=n.start-o,s=n.end-o,a=i.substring(r,s);if(e.exact!==a)throw new Error("quote mismatch");return await Ii(t,r,s)}catch{}try{const t=Ai(e.exact,n.start),o=Si.get(t);if(o){const{pageIndex:t,anchor:e}=o;return await Ii(t,e.start,e.end)}}catch{}}return async function(t,e){const n=Mi().pagesCount,o=Array(n).fill(0).map(((t,e)=>e));let i,r;if(e){const{index:t,offset:n}=await Ti(e);i=t,r=e-n,o.sort(((e,n)=>Math.abs(e-t)-Math.abs(n-t)))}const s=void 0!==t.prefix?Bi(t.prefix):void 0,a=void 0!==t.suffix?Bi(t.suffix):void 0,l=Bi(t.exact);let c;for(const t of o){const e=await Pi(t),n=Bi(e);let o;void 0!==i&&void 0!==r&&(t<i?o=n.length:t===i?[o]=vi(e,n,r,r,Li,{normalize:!1}):o=0);const h=Vo(n,l,{prefix:s,suffix:a,hint:o});if(h&&(!c||h.score>c.match.score)){const[o,i]=vi(n,e,h.start,h.end,Li);c={page:t,match:{start:o,end:i,score:h.score}}
|
|
130
|
+
;const r=n.slice(h.start,h.end)===l,d=void 0!==s&&n.slice(Math.max(0,h.start-s.length),h.start)===s,u=void 0!==a&&n.slice(h.end,a.length)===a;if(r&&(d||u||void 0===s&&void 0===a))break}}if(c){const{page:n,match:o}=c;if(e){const i=Ai(t.exact,e);Si.set(i,{pageIndex:n,anchor:o})}return Ii(n,o.start,o.end)}throw new Error("Quote not found")}(e,n?.start)}async function Fi(t){const e=t.find((t=>"PageSelector"===t.type)),n=t.find((t=>"ShapeSelector"===t.type));if(n){if(!e)throw new Error("Cannot anchor a shape selector without a page");return async function(t,e){const n=Mi();if("number"!=typeof t.index||t.index<0||t.index>=n.pagesCount)throw new Error("PDF page index is invalid");const o=await Ri(t.index),i=o.div,r=o.viewport,s=t=>function(t,e,n){return Math.max(Math.min(t,n),e)}(t,0,1);let a;switch(e.shape.type){case"rect":{const t=e.shape;let[n,o]=r.convertToViewportPoint(t.left,t.top),[i,l]=r.convertToViewportPoint(t.right,t.bottom);i<n&&([n,i]=[i,n]),l<o&&([o,l]=[l,o]),a={type:"rect",left:s(n/r.width),
|
|
131
|
+
top:s(o/r.height),right:s(i/r.width),bottom:s(l/r.height)}}break;case"point":{const t=e.shape,[n,i]=o.viewport.convertToViewportPoint(t.x,t.y);a={type:"point",x:s(n/r.width),y:s(i/r.height)}}break;default:throw new Error("Unsupported shape in shape selector")}return{anchor:i,shape:a,coordinates:"anchor"}}(e,n)}return Di(t)}function Hi(t){try{t=Un.fromRange(t).toRange()}catch{throw new Error("Selection does not contain text")}const e=ki(t.startContainer),n=ki(t.endContainer);if(!e||!n)throw new Error("Selection is outside page text");if(e!==n)throw new Error("Selecting across page breaks is not supported");return[t,e]}function Vi(t){const e=t.closest(".page"),n=parseInt(e?.getAttribute("data-page-number")??"");if(!Number.isInteger(n))throw new Error("Unable to get page number from element");return n-1}async function zi(t){const[e,n]=Hi(t),o=zn.fromPoint(e.startContainer,e.startOffset).relativeTo(n),i=zn.fromPoint(e.endContainer,e.endOffset).relativeTo(n),r=Vi(n),s=await async function(t){
|
|
132
|
+
if(t>=Mi().pagesCount)throw new Error("Invalid page index");let e=0;for(let n=0;n<t;n++)e+=(await Pi(n)).length;return e}(r),a=await Ri(r);return[{type:"TextPositionSelector",start:s+o.offset,end:s+i.offset},Yo.fromRange(a.div,e).toSelector(),$i(a,r)]}async function Ui(t,e){const n=document.elementsFromPoint(t,e);for(const o of n){if(!o.classList.contains("page"))continue;const n=Vi(o),i=getComputedStyle(o),r=parseFloat(i.borderLeftWidth),s=parseFloat(i.borderTopWidth),a=o.getBoundingClientRect(),l=t-a.left-r,c=e-a.top-s,h=await Ri(n),[d,u]=h.getPagePoint(l,c);return{pageIndex:n,x:d,y:u}}return null}function $i(t,e){return{type:"PageSelector",index:e,label:t.pageLabel??`${e+1}`}}async function qi(t){const e=t=>{const[e,n,o,i]=t.view;return{left:e,top:i,right:o,bottom:n}},n=(t,e)=>function(t,e){const n=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT),o=[];let i,r;for(;r=n.nextNode();){const t=r,n=t.data.split(/\b/);let s=0;for(const r of n){const n=new Range;n.setStart(t,s);const a=s+r.length
|
|
133
|
+
;n.setEnd(t,a);const l=n.getBoundingClientRect();$e(l,e)&&(i&&!qe(i,l)&&o.push(" "),o.push(r),i=l),s=a}}return o.join("")}(t,e).slice(0,256);switch(t.type){case"rect":{const[o,i]=await Promise.all([Ui(t.left,t.top),Ui(t.right,t.bottom)]);if(!o)throw new Error("Top-left point is not in a page");if(!i)throw new Error("Bottom-right point is not in a page");if(o.pageIndex!==i.pageIndex)throw new Error("Shape must start and end on same page");const r=await Ri(o.pageIndex),s={type:"rect",left:o.x,top:o.y,right:i.x,bottom:i.y},a=Ei(t.left,t.top);let l;if(a){l=n(a,new DOMRect(t.left,t.top,t.right-t.left,t.bottom-t.top))}return[$i(r,o.pageIndex),{type:"ShapeSelector",anchor:"page",shape:s,view:e(r.pdfPage),text:l}]}case"point":{const o=await Ui(t.x,t.y);if(!o)throw new Error("Point is not in a page");const i=Ei(t.x,t.y);let r;if(i){r=n(i,new DOMRect(t.x,t.y,1,1))}const s=await Ri(o.pageIndex);return[$i(s,o.pageIndex),{type:"ShapeSelector",anchor:"page",shape:{type:"point",x:o.x,y:o.y},text:r,view:e(s.pdfPage)}]}
|
|
134
|
+
default:throw new Error("Unsupported shape")}}function Wi({children:t}){return St("div",{className:"flex flex-col",children:t})}function ji({info:t}){let e=t.item.title;return t.item.subtitle&&(e+=`: ${t.item.subtitle}`),St("div",{className:Tt("h-10 bg-white px-4 text-slate-7 text-annotator-base border-b","grid items-center","grid-cols-[100px_minmax(0,auto)]","2xl:grid-cols-[100px_minmax(0,auto)_minmax(0,auto)] 2xl:gap-x-3"),children:[St("div",{"data-testid":"content-logo",children:t.logo&&St(we,{href:t.logo.link,target:"_blank","data-testid":"logo-link",underline:"none",children:St("img",{alt:t.logo.title,src:t.logo.logo,"data-testid":"logo-image"})})}),St("div",{className:Tt("hidden","2xl:block 2xl:whitespace-nowrap 2xl:overflow-hidden 2xl:text-ellipsis","font-semibold"),"data-testid":"content-container-info",title:t.container.title,children:t.container.title}),St("div",{className:Tt("flex justify-center items-center gap-x-2"),"data-testid":"content-item-info",children:[St("div",{
|
|
135
|
+
className:Tt("hidden","2xl:block 2xl:grow")}),t.links.previousItem&&St(y,{children:[St(we,{title:"Open previous item",href:t.links.previousItem,underline:"always",target:"_blank","data-testid":"content-previous-link",children:St("div",{className:"flex gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[St(Dt,{className:"w-em h-em"}),St("span",{children:"Previous"})]})}),St("div",{className:"text-annotator-sm",children:"|"})]}),St("div",{className:Tt("min-w-0 whitespace-nowrap overflow-hidden text-ellipsis shrink font-medium"),children:St(we,{title:e,href:t.links.currentItem,"data-testid":"content-item-link",target:"_blank",unstyled:!0,children:e})}),t.links.nextItem&&St(y,{children:[St("div",{className:"text-annotator-sm",children:"|"}),St(we,{title:"Open next item",href:t.links.nextItem,underline:"always",target:"_blank","data-testid":"content-next-link",children:St("div",{className:"flex gap gap-x-1 items-center text-annotator-sm whitespace-nowrap",children:[St("span",{children:"Next"
|
|
136
|
+
}),St(Ft,{className:"w-em h-em"})]})})]})]})]})}function Ki(){return St("div",{className:"bg-white",role:"alert",children:St("div",{className:Tt("flex items-center gap-x-2","border border-yellow-notice bg-yellow-notice/10 text-annotator-base"),children:[St("div",{className:"bg-yellow-notice text-white p-2",children:St(Ht,{className:"text-annotator-xl"})}),St("div",{children:[St("strong",{children:"Text annotation tools are unavailable because this PDF does not contain selectable text."})," ",St(we,{target:"_blank",href:"https://web.hypothes.is/help/how-to-ocr-optimize-pdfs/",underline:"always",children:"Learn more here"}),"."]})]})})}class Xi{constructor(t){this._loaded=function(t){return t.initializedPromise?t.initializedPromise:t.initialized?Promise.resolve():new Promise((e=>{const n=setInterval((()=>{t.initialized&&(clearTimeout(n),e())}),5)}))}(t).then((async()=>{const e=await async function(t){return void 0!==t.downloadComplete?t.downloadComplete:(await t.pdfDocument.getDownloadInfo(),!0)}(t)
|
|
137
|
+
;return e?t:new Promise((e=>{const n=()=>{t.eventBus?(t.eventBus.off("documentload",n),t.eventBus.off("documentloaded",n)):window.removeEventListener("documentload",n),e(t)};t.eventBus?(t.eventBus.on("documentloaded",n),t.eventBus.on("documentload",n)):window.addEventListener("documentload",n)}))}))}getUri(){return this._loaded.then((t=>{let e=Qi(t);return e||(e=Gi(Yi(t))),e}))}async getMetadata(){const t=await this._loaded,{info:e,contentDispositionFilename:n,metadata:o}=await t.pdfDocument.getMetadata(),i=Yi(t),r=Qi(t),s=o?.get("dc:title");let a;a=s&&"Untitled"!==s?s:e?.Title?e.Title:n||(r?function(t){const e=new URL(t),n=e.pathname.split("/");return n[n.length-1]}(r):"");const l=[{href:Gi(i)}];return r&&l.push({href:r}),{title:a,link:l,documentFingerprint:i}}}function Yi(t){return Array.isArray(t.pdfDocument.fingerprints)?t.pdfDocument.fingerprints[0]:t.pdfDocument.fingerprint}function Gi(t){return`urn:x-pdf:${t}`}function Qi(t){if(!t.url)return null;const e=hi(t.url);return 0!==e.indexOf("file://")?e:null
|
|
138
|
+
}function Ji(t){const e=t.highlights?.[0];return e&&qn(e)}function Zi(t){return new Promise((e=>setTimeout(e,t)))}class tr{constructor(){this._pdfjsContainer=document.querySelector("#outerContainer"),this._contentInfo=null,this._noTextWarning=!1,this._container=null}setContentInfo(t){this._contentInfo=t,this._update()}showNoTextWarning(t){this._noTextWarning=t,this._update()}destroy(){this._container?.destroy()}_update(){if(!(this._noTextWarning||this._contentInfo))return this._container?.destroy(),this._container=null,void(this._pdfjsContainer.style.height="");this._container||(this._container=new Pn("banner",(()=>this._render())),document.body.prepend(this._container.element)),this._container.render();const t=this._container.element.getBoundingClientRect().height;this._pdfjsContainer.style.height=`calc(100% - ${t}px)`}_render(){return St(Wi,{children:[this._contentInfo&&St(ji,{info:this._contentInfo}),this._noTextWarning&&St(Ki,{})]})}}class er extends Me{
|
|
139
|
+
constructor({annotator:t,features:e,reanchoringMaxWait:n}){super(),this._annotator=t;const o=window,i=o.PDFViewerApplication;this._pdfViewer=i.pdfViewer,this._pdfViewer.viewer.classList.add("has-transparent-text-layer"),this._pdfContainer=i.appConfig?.appContainer??document.body,this._pdfMetadata=new Xi(i),this._observer=new MutationObserver(_i((()=>this._update()),100)),this._observer.observe(this._pdfViewer.viewer,{attributes:!0,attributeFilter:["data-loaded"],childList:!0,subtree:!0}),this._reanchoringMaxWait=n??3e3,this._banner=new tr,this._checkForSelectableText(),this._sideBySideActive=!1,this._updateAnnotationLayerVisibility=()=>{const t=o.getSelection();this._pdfViewer.viewer.classList.toggle("is-selecting",!t.isCollapsed)},this._listeners=new mt,this._listeners.add(document,"selectionchange",this._updateAnnotationLayerVisibility),this._destroyed=!1,this._features=e,this._features.on("flagsChanged",(()=>{this.emit("supportedToolsChanged",this.supportedTools())})),
|
|
140
|
+
this._pdfViewer.viewer.addEventListener("click",(t=>{const e=t.target;e instanceof HTMLAnchorElement&&(e.target="blank");oo(t.clientX,t.clientY).length>0&&t.preventDefault()}))}destroy(){this.fitSideBySide({expanded:!1,width:0,toolbarWidth:0,height:window.innerHeight}),this._listeners.removeAll(),this._pdfViewer.viewer.classList.remove("has-transparent-text-layer"),this._observer.disconnect(),this._banner.destroy(),this._destroyed=!0,super.destroy()}uri(){return this._pdfMetadata.getUri()}getMetadata(){return this._pdfMetadata.getMetadata()}showContentInfo(t){this._banner.setContentInfo(t)}anchor(t,e){return Fi(e)}getAnnotatableRange(t){try{const e=Un.trimmedRange(t);if(function(t){try{return Hi(t),!0}catch{return!1}}(e))return e}catch(t){if(!(t instanceof RangeError))throw t}return null}canStyleClusteredHighlights(){return!0}describe(t,e){return e instanceof Range?zi(e):qi(e)}async _checkForSelectableText(){try{await this.uri()}catch{return}if(!this._destroyed)try{const t=await async function(){const t=Mi()
|
|
141
|
+
;let e=!1;for(let n=0;n<t.pagesCount;n++)if((await Pi(n)).trim().length>0){e=!0;break}return e}();this._banner.showNoTextWarning(!t)}catch(t){console.warn("Unable to check for text in PDF:",t)}}_update(){const t=[],e=this._pdfViewer.pagesCount;for(let t=0;t<e;t++){const e=this._pdfViewer.getPageView(t);if(e?.textLayer&&Oi(e.textLayer))switch(e.renderingState){case xi.INITIAL:e.textLayer=null;break;case xi.FINISHED:n=e.div,n.querySelector($n)?.remove()}}var n;for(const e of this._annotator.anchors)if(e.highlights){if(t.includes(e.annotation))continue;for(let n=0;n<e.highlights.length;n++){const o=e.highlights[n];if(!document.body.contains(o)){e.highlights.splice(n,1),delete e.region,t.push(e.annotation);break}}}t.map((t=>this._annotator.anchor(t)))}contentContainer(){return document.querySelector("#viewerContainer")}fitSideBySide(t){const e=window.innerWidth-t.width,n=t.expanded&&e>=680,o=n?t.width:t.toolbarWidth;this._pdfContainer.style.width=`calc(100% - ${o}px)`;const i=this._pdfViewer.currentScaleValue
|
|
142
|
+
;return"auto"!==i&&"page-fit"!==i&&"page-width"!==i||(this._pdfViewer.currentScaleValue=i),this._pdfViewer.update(),this._sideBySideActive=n,n}sideBySideActive(){return this._sideBySideActive}supportedTools(){const t=this._features?.flagEnabled("pdf_image_annotation");return t?["selection","rect","point"]:["selection"]}async scrollToAnchor(t){const e=t.annotation,n=Ji(t),o=this._anchorOffset(t);if(null!==o&&(await ci(this.contentContainer(),o),n)){const t=await this._waitForAnnotationToBeAnchored(e,this._reanchoringMaxWait);if(!t)return;const n=this._anchorOffset(t);if(null===n)return;await ci(this.contentContainer(),n)}}async _waitForAnnotationToBeAnchored(t,e){const n=Date.now();let o;do{o=this._annotator.anchors.find((e=>e.annotation===t)),o&&!Ji(o)||(o=null,await Zi(20))}while(!o&&Date.now()-n<e);return o??null}_anchorOffset(t){if(!t.highlights)return null;const e=t.highlights[0];return function(t,e,n={}){let o=0,i=e;for(;i!==t&&t.contains(i);)o+=i.offsetTop,i=i.offsetParent;if("center"===n.position){
|
|
143
|
+
const n=t.getBoundingClientRect(),i=e.getBoundingClientRect();o-=n.height/2-i.height/2}return o}(this.contentContainer(),e,{position:"center"})}async renderToBitmap(t,e){const n=t.target.selector?.find((t=>"ShapeSelector"===t.type)),o=t.target.selector?.find((t=>"PageSelector"===t.type));if(!o||!n)throw new Error("Can only render bitmaps for anchors with shapes");const i=this._pdfViewer.getPageView(o.index);if(!i)throw new Error("Failed to get page view");let r,s,a,l;switch(n.shape.type){case"rect":({left:r,right:s,top:a,bottom:l}=n.shape);break;case"point":{const{x:t,y:e}=n.shape,[o,,c]=i.pdfPage.view,h=.1*Math.abs(c-o);r=t-h,a=e+h,s=t+h,l=e-h}break;default:throw new Error("Unsupported shape type")}s<r&&([r,s]=[s,r]),s=Math.max(s,r+1),a<l&&([a,l]=[l,a]),a=Math.max(a,l+1);const c=i.pdfPage.rotate%360;if(c%90!=0)throw new Error("Page rotation is not a multiple of 90 degrees");let h,d;0===c||180===c?(h=Math.abs(s-r),d=Math.abs(l-a)):(h=Math.abs(l-a),d=Math.abs(s-r))
|
|
144
|
+
;const u=96/72,f=e.devicePixelRatio??1,p=h*u*f,g=h/d,_="number"==typeof e.maxWidth?Math.min(e.maxWidth,p):p,m=_/g,b=i.pdfPage.getViewport({scale:1}),y=_/p*u*f,w=new(0,b.constructor)({rotation:c,scale:y,userUnit:b.userUnit,viewBox:[r,l,s,a]}),v=Math.max(_,1),x=Math.max(m,1),C=new OffscreenCanvas(v,x),S=C.getContext("2d"),A=i.pdfPage.render({canvasContext:S,viewport:w});if(await A.promise,"point"===n.shape.type){S.save(),S.scale(y,y);const t=n.shape.x-r,e=n.shape.y-l,o=5;S.strokeStyle="black",S.fillStyle="yellow",S.beginPath(),S.arc(t,e,o,0,2*Math.PI),S.fill(),S.stroke(),S.restore()}return C.transferToImageBitmap()}}function nr(t){if(!t.includes("["))return t;let e="",n=!1,o=!1;for(const i of t)n||"^"!==i?(n||"["!==i?!n&&o&&"]"===i?o=!1:o||(e+=i):o=!0,n=!1):n=!0;return e}function or(t){const e=nr(t),n=e.indexOf("!");return-1===n?e:e.slice(0,n)}class ir{constructor(t,e,n){this._element=t,this._onFrameAdded=e,this._onFrameRemoved=n,this._annotatableFrames=new Set,this._isDisconnected=!1,
|
|
145
|
+
this._mutationObserver=new MutationObserver(_i((()=>{this._discoverFrames()}),40)),this._discoverFrames(),this._mutationObserver.observe(this._element,{childList:!0,subtree:!0,attributeFilter:["enable-annotation"]})}disconnect(){this._isDisconnected=!0,this._mutationObserver.disconnect()}async _addFrame(t){this._annotatableFrames.add(t);try{if(await rr(t),this._isDisconnected)return;t.contentWindow.addEventListener("unload",(()=>{this._removeFrame(t)})),this._onFrameAdded(t)}catch{console.warn(`Unable to inject the Hypothesis client (from '${document.location.href}' into a cross-origin frame '${t.src}')`)}}_removeFrame(t){this._annotatableFrames.delete(t),this._onFrameRemoved(t)}_discoverFrames(){const t=new Set(this._element.querySelectorAll("iframe[enable-annotation]"));for(const e of t)this._annotatableFrames.has(e)||this._addFrame(e);for(const e of this._annotatableFrames)t.has(e)||this._removeFrame(e)}}function rr(t){return new Promise(((e,n)=>{const o=sr(t,((t,i)=>{o(),i?e(i):n(t)}))}))}
|
|
146
|
+
function sr(t,e,{pollInterval:n=10}={}){let o,i;const r=new WeakSet,s=()=>{clearTimeout(o),o=void 0},a=()=>{const n=t.contentDocument;if(n){if(!r.has(n)){if(r.add(n),s(),!function(t){return"about:blank"===t.contentDocument?.location.href&&t.hasAttribute("src")&&"about:blank"!==t.src}(t)){"interactive"===n.readyState||"complete"===n.readyState?e(null,n):n.addEventListener("DOMContentLoaded",(()=>e(null,n)))}t.contentDocument&&t.contentWindow?.addEventListener("unload",i)}}else{s();const n=t.isConnected?"Frame is cross-origin":"Frame is disconnected";e(new Error(n))}};let l=!1;i=()=>{s(),l||(o=setInterval(a,n))},t.addEventListener("load",a);const c=setTimeout(a,0);return()=>{l=!0,clearTimeout(c),s(),t.removeEventListener("load",a)}}class ar{constructor(t,e){this._config=e,this._frameObserver=new ir(t,(t=>lr(t,e)),(()=>{}))}destroy(){this._frameObserver.disconnect()}}async function lr(t,e,n){if(null!==t.contentDocument.querySelector("script.js-hypothesis-config"))return;await rr(t)
|
|
147
|
+
;const{assetRoot:o,notebookAppUrl:i,profileAppUrl:r,sidebarAppUrl:s}=He(document),a={...e,assetRoot:o,notebookAppUrl:i,profileAppUrl:r,sidebarAppUrl:s,subFrameIdentifier:n??Ce(10)},l=document.createElement("script");l.className="js-hypothesis-config",l.setAttribute("data-remove-on-unload",""),l.type="application/json",l.innerText=JSON.stringify(a);const c=document.createElement("script");c.async=!0,c.src=e.clientUrl;const h=t.contentDocument;h.body.appendChild(l),h.body.appendChild(c)}class cr{constructor(t,e,n){if(e.length!==n.length)throw new Error("Char boxes length does not match text length");const o=t.parentNode,i=document.createElement("hypothesis-text-layer");o.insertBefore(i,t.nextSibling),o.style.position="relative",i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.color="transparent",i.style.textAlign="left",i.style.mixBlendMode="multiply";const r="sans-serif";i.style.fontSize="16px",i.style.fontFamily=r;const s=document.createElement("canvas").getContext("2d");s.font=`16px ${r}`
|
|
148
|
+
;const a=(t,e,n="px")=>`calc(var(--${t}-scale) * ${e}${n})`,l=function(t,e){const n=[];let o={text:"",rect:new DOMRect};const i=()=>{o.text.length>0&&(n.push(o),o={text:"",rect:new DOMRect})};for(const[n,r]of t.entries()){const t=e[n],s=/\s/.test(t);o.text.length>0&&!qe(o.rect,r)&&i(),o.rect=je(o.rect,r),o.text+=s?" ":t,s&&i()}i();const r=[];let s={words:[],rect:new DOMRect};const a=()=>{s.words.length>0&&(r.push(s),s={words:[],rect:new DOMRect})};for(const t of n){const e=s.words[s.words.length-1];if(e){const n=Ke(e.rect),o=Ke(t.rect).x-n.x;(!qe(e.rect,t.rect)||o<0)&&a()}s.words.push(t),s.rect=je(s.rect,t.rect)}a();const l=[];let c={lines:[],rect:new DOMRect};const h=()=>{c.lines.length>0&&(l.push(c),c={lines:[],rect:new DOMRect})};for(const t of r){const e=c.lines[c.lines.length-1];if(e){const n=Ke(e.rect),o=Ke(t.rect).y-n.y;(!We(e.rect,t.rect)||qe(e.rect,t.rect)||o<0||o>4*t.rect.height)&&h()}c.lines.push(t),c.rect=je(c.rect,t.rect)}return h(),l}(e,n);for(const t of l){
|
|
149
|
+
const e=document.createElement("hypothesis-text-column");e.style.display="block",e.style.position="absolute",e.style.left=a("x",t.rect.left),e.style.top=a("y",t.rect.top);let n=null;for(const o of t.lines){const i=document.createElement("hypothesis-text-line");i.style.display="block",i.style.marginLeft=a("x",o.rect.left-t.rect.left),i.style.height=a("y",o.rect.height),n&&(i.style.marginTop=a("y",o.rect.top-n.rect.bottom)),n=o,i.style.whiteSpace="nowrap";let r=null;for(const t of o.words){const e=document.createElement("hypothesis-text-word");e.style.display="inline-block",e.style.transformOrigin="top left",e.textContent=t.text,r&&(e.style.marginLeft=a("x",t.rect.left-r.rect.right)),r=t,e.style.width=a("x",t.rect.width),e.style.height=a("y",t.rect.height),e.style.whiteSpace="pre";const n=s.measureText(t.text),o=a("x",t.rect.width/n.width,""),l=a("y",t.rect.height/16,"");e.style.transform=`scale(${o}, ${l})`,i.append(e)}e.append(i)}i.append(e)}const c=()=>{const{width:e,height:n}=t.getBoundingClientRect()
|
|
150
|
+
;i.style.width=e+"px",i.style.height=n+"px",i.style.setProperty("--x-scale",`${e}`),i.style.setProperty("--y-scale",`${n}`)};c(),this.container=i,this._updateTextLayerSize=_i(c,{maxWait:50}),this._listeners=new mt,"undefined"!=typeof ResizeObserver&&(this._imageSizeObserver=new ResizeObserver((()=>{this._updateTextLayerSize()})),this._imageSizeObserver.observe(t)),this._listeners.add(window,"resize",this._updateTextLayerSize)}updateSync(){this._updateTextLayerSize(),this._updateTextLayerSize.flush()}destroy(){this.container.remove(),this._listeners.removeAll(),this._updateTextLayerSize.cancel(),this._imageSizeObserver?.disconnect()}}function hr(t=document){return t.querySelector("mosaic-book")}function dr(t=window){if(hr(t.document))return"container";const e=t.frameElement?.ownerDocument;return e&&hr(e)?"content":null}class ur{constructor(t){const e=hr();if(!e)throw new Error("Book container element not found");const n=new WeakSet,o=e.shadowRoot,i=()=>{const e=o.querySelector("iframe")
|
|
151
|
+
;e&&!n.has(e)&&(n.add(e),sr(e,((n,o)=>{if(n)return;const i=o.body;i&&!i.querySelector("#page-content")&&lr(e,t,"vitalsource-content")})))};i(),this._frameObserver=new MutationObserver(i),this._frameObserver.observe(o,{childList:!0,subtree:!0})}destroy(){this._frameObserver.disconnect()}}function fr(){return document.querySelector("img#pbk-page")}class pr extends Me{constructor(t=document.body,e={}){super();const n=e.bookElement??hr(window.parent.document);if(!n)throw new Error("Failed to find <mosaic-book> element in container frame");this._bookElement=n;const o=new Mo;this._htmlIntegration=new ui({container:t,features:o}),this._listeners=new mt;const i=["mouseup","mousedown","mouseout"];for(const t of i)this._listeners.add(document.documentElement,t,(t=>{t.stopPropagation()}));const r=window.frameElement;r&&function(t){if("no"!==t.getAttribute("scrolling"))return;const e=document.createElement("style");e.textContent="iframe { height: 100% !important; }",t.insertAdjacentElement("beforebegin",e)
|
|
152
|
+
;const n=()=>t.removeAttribute("scrolling");n(),new MutationObserver(n).observe(t,{attributes:!0})}(r);const s=fr(),a=window.innerPageData;if(s&&a){const t=a.glyphs.glyphs.map((t=>{const e=t.l/100,n=t.r/100,o=t.t/100,i=t.b/100;return new DOMRect(e,o,n-e,i-o)}));this._textLayer=new cr(s,t,a.words),this._textLayer.container.style.zIndex="100",this._sideBySideActive=!1}}getAnnotatableRange(t){return this._htmlIntegration.getAnnotatableRange(t)}destroy(){this._textLayer&&(this._textLayer.destroy(),this.fitSideBySide({expanded:!1,height:window.innerHeight,width:0,toolbarWidth:0})),this._listeners.removeAll(),this._htmlIntegration.destroy(),super.destroy()}anchor(t,e){return this._htmlIntegration.anchor(t,e)}async describe(t,e){const n=this._htmlIntegration.describe(t,e),{cfi:o,index:i,page:r,title:s,url:a}=await this._getPageInfo({includeTitle:!0,includePageIndex:!0}),l=[{type:"EPUBContentSelector",cfi:o,url:a,title:s}];if("number"==typeof i){const t={type:"PageSelector",index:i,label:r};l.push(t)}
|
|
153
|
+
return n.push(...l),n}contentContainer(){return this._htmlIntegration.contentContainer()}fitSideBySide(t){const e=fr();if(e&&this._textLayer){const n=e.parentElement,o=this._textLayer,i=window.innerWidth-t.width;return this._sideBySideActive=!1,on((()=>{t.expanded&&i>480?(n.style.textAlign="left",e.style.width=`${i}px`,this._sideBySideActive=!0):(n.style.textAlign="",e.style.width=""),o.updateSync()})),this._sideBySideActive}return this._htmlIntegration.fitSideBySide(t)}sideBySideActive(){return"boolean"==typeof this._sideBySideActive?this._sideBySideActive:this._htmlIntegration.sideBySideActive()}supportedTools(){return["selection"]}async getMetadata(){return{title:this._bookElement.getBookInfo().title,link:[]}}navigateToSegment(t){const e=t.target[0].selector?.find((t=>"EPUBContentSelector"===t.type));if(e?.cfi)this._bookElement.goToCfi(e.cfi);else{if(!e?.url)throw new Error("No segment information available");this._bookElement.goToURL(function(t){const e=new URL(t,document.baseURI)
|
|
154
|
+
;return e.pathname+e.search}(e.url))}}persistFrame(){return!0}async _getPageInfo({includeTitle:t=!1,includePageIndex:e=!1}={}){const[n,o,i]=await Promise.all([this._bookElement.getCurrentPage(),t?this._bookElement.getTOC():void 0,e?this._bookElement.getPages():void 0]),r=["absoluteURL","cfi"];for(const t of r)if(!(t in n))throw new Error(`Page metadata field "${t}" is missing`);let s;if(o){s=n.chapterTitle;const t=or(n.cfi),e=o.data?.find((e=>or(e.cfi)===t));e&&(s=e.title)}let a=n.index;if(void 0===a&&i){const t=i.data?.findIndex((t=>t.cfi===n.cfi));-1!==t&&(a=t)}return{cfi:n.cfi,index:a,page:n.page,title:s,url:new URL(n.absoluteURL,document.baseURI).toString()}}async _getPageRange(t){let e=[];try{const t=await this._bookElement.getPageBreaks();t.ok&&t.data&&(e=t.data)}catch(t){console.error("Failed to get page breaks",t)}const n=nr(t),o=e.filter((t=>t.cfiWithoutAssertions.split("!")[0]===n));let i;if(o.length>0){i={start:o[0].label,end:o[o.length-1].label}}return i}async segmentInfo(){
|
|
155
|
+
const{cfi:t,url:e}=await this._getPageInfo();return{cfi:t,pages:await this._getPageRange(t),url:e}}async uri(){const t=this._bookElement.getBookInfo().isbn;if(!t)throw new Error("Unable to get book ID from VitalSource");return`https://bookshelf.vitalsource.com/reader/books/${t}`}async scrollToAnchor(t){return this._htmlIntegration.scrollToAnchor(t)}}function gr(t){if(void 0!==window.PDFViewerApplication)return new er({annotator:t,features:t.features});return"content"===dr()?new pr(document.body):new ui({features:t.features,sideBySideOptions:t.sideBySide})}function _r(){return St(_e,{classes:"fixed left-[10px] top-[10px]","data-testid":"outside-assignment-notice",status:"notice",variant:"raised",children:"You are outside the page range for this assignment. Annotations made here may not be counted."})}class mr{constructor(t){this._visible=!1,this._container=new Pn("notice",(()=>this._render())),t.appendChild(this._container.element)}destroy(){this._container.destroy()}setVisible(t){this._visible=t,
|
|
156
|
+
this._container.render()}_render(){return this._visible?St(_r,{}):null}}class br{constructor(t,e=document){let n=!1;this._pendingCallback=null;const o=(n=10)=>{this._pendingCallback=setTimeout((()=>{t(jn(e.getSelection()))}),n)},i=t=>{if("mousedown"===t.type&&(n=!0),"mouseup"===t.type&&(n=!1),n)return;this._cancelPendingCallback();const e="mouseup"===t.type?10:100;o(e)};this._document=e,this._listeners=new mt,this._listeners.add(e,"selectionchange",i),this._listeners.add(e.body,"mousedown",i),this._listeners.add(e.body,"mouseup",i),o(1)}disconnect(){this._listeners.removeAll(),this._cancelPendingCallback()}_cancelPendingCallback(){this._pendingCallback&&(clearTimeout(this._pendingCallback),this._pendingCallback=null)}}function yr(t,e){if(t===e)return!0;if(t.parent!==e)return!1;if(!t.frameElement)return!1;return t.frameElement.getBoundingClientRect().width/t.parent.innerWidth>=.8}function wr(){return function(t,e){const n=new Set,o=new Set;return Yn(t,(t=>{for(;t&&!n.has(t);){n.add(t);const i=e(t)
|
|
157
|
+
;null!=i&&o.add(i),t=t.parentNode}})),[...o]}(jn()??new Range,(t=>t._annotation?.$tag))}function vr(t,e,n){return t.getHighlightsFromPoint(e,n).map((t=>t._annotation?.$tag)).filter((t=>void 0!==t))}function xr(t){if(!t.region)return null;if(!function(t){return void 0!==t&&"toRange"in t&&"function"==typeof t.toRange}(t.region))return t.region;try{return t.region.toRange()}catch{return null}}function Cr(){document.getSelection()?.removeAllRanges()}class Sr extends CustomEvent{constructor(t){super("scrolltorange",{bubbles:!0,cancelable:!0,detail:t}),this._ready=null}get ready(){return this._ready}waitUntil(t){this._ready=t}}class Ar extends Me{constructor(t,e={},n=window){super(),this.element=t,this._contentReady=e.contentReady,this._commentsMode=e.commentsMode??!1,this._hostFrame=n,this._highlightsVisible=!1,this._isAdderVisible=!1,this._informHostOnNextSelectionClear=!0,this.selectedRanges=[],this._outsideAssignmentNotice=null,this._highlighter=new Zn(this.element),this._adder=new Ln(this.element,{
|
|
158
|
+
onAnnotate:()=>this.createAnnotationFromSelection(),onHighlight:()=>this.createAnnotationFromSelection({highlight:!0}),onShowAnnotations:t=>this.selectAnnotations(t,{focusInSidebar:!0})}),this._drawTool=new xo(this.element),this._drawTool.setOnKeyboardModeChange((t=>{this._hostRPC.call("keyboardModeChanged",t)})),this._setupGlobalKeyboardListener(),this._selectionObserver=new br((t=>{t?this._onSelection(t):this._onClearSelection()})),this.anchors=[],this._annotations=new Set,this._frameIdentifier=e.subFrameIdentifier||null,this._portFinder=new ke({hostFrame:this._hostFrame,source:"guest",sourceId:this._frameIdentifier??void 0}),this.features=new Mo,this._featureFlagsReceived=new Promise((t=>{this.features.on("flagsChanged",t)})),this.sideBySide=e.sideBySide,this._integration=gr(this),this._integration.on("uriChanged",(()=>this._sendDocumentInfo())),e.contentInfoBanner&&this._integration.showContentInfo?.(e.contentInfoBanner),
|
|
159
|
+
this._integration.canStyleClusteredHighlights?.()&&(this._clusterToolbar=new No(this._integration.contentContainer(),{features:this.features})),this._integration.on("supportedToolsChanged",(()=>this._notifySupportedToolsChanged())),this._hostRPC=new De,this._connectHost(n),this._sidebarRPC=new De,this._sidebarLayout=null,this._connectSidebar(),this._bucketBarClient=new ho({contentContainer:this._integration.contentContainer(),hostRPC:this._hostRPC}),this._listeners=new mt,this._setupElementEvents(),this._hoveredAnnotations=new Set}_sideBySideActive(){return"manual"===this.sideBySide?.mode&&this.sideBySide.isActive?this.sideBySide.isActive():this._integration.sideBySideActive()}_setupElementEvents(){this._listeners.add(this.element,"mouseup",(t=>{if(!document.getSelection()?.isCollapsed)return;const{clientX:e,clientY:n,metaKey:o,ctrlKey:i}=t,r=vr(this._highlighter,e,n);if(r.length){const t=o||i;this.selectAnnotations(r,{toggle:t})}})),this._listeners.add(this.element,"pointerdown",(t=>{
|
|
160
|
+
this._sideBySideActive()||t.composedPath().some((t=>t instanceof Element&&t.localName.startsWith("hypothesis-")))||vr(this._highlighter,t.clientX,t.clientY).length||yr(window,this._hostFrame)&&this._sidebarLayout?.expanded&&window.innerWidth-t.clientX<this._sidebarLayout.width||this._sidebarRPC.call("closeSidebar")})),this._listeners.add(this.element,"mouseover",(({clientX:t,clientY:e})=>{const n=vr(this._highlighter,t,e);n.length&&this._sidebarRPC.call("hoverAnnotations",n)})),this._listeners.add(this.element,"mouseout",(()=>{this._highlightsVisible&&this._sidebarRPC.call("hoverAnnotations",[])})),this._listeners.add(this.element,"keydown",(t=>{this._handleShortcut(t)})),this._listeners.add(window,"resize",(()=>this._repositionAdder()))}async getDocumentInfo(){const[t,e,n]=await Promise.all([this._integration.uri(),this._integration.getMetadata(),this._integration.segmentInfo?.()]);return{uri:hi(t),metadata:e,segmentInfo:n,persistent:this._integration.persistFrame?.()??!1}}async _sendDocumentInfo(){
|
|
161
|
+
this._integration.waitForFeatureFlags?.()&&await this._featureFlagsReceived;const t=await this.getDocumentInfo();this._sidebarRPC.call("documentInfoChanged",t)}_repositionAdder(){if(!this._isAdderVisible)return;const t=jn();t&&this._onSelection(t)}async _connectHost(t){this._hostRPC.on("clearSelection",(()=>{jn()&&(this._informHostOnNextSelectionClear=!1,Cr())})),this._hostRPC.on("createAnnotation",(({tool:t})=>t?("rect"===t&&void 0===this._pendingKeyboardMode&&(this._pendingKeyboardMode="move"),this.createAnnotation(t)):(this._drawTool.cancel(),null))),this._hostRPC.on("hoverAnnotations",(t=>this._hoverAnnotations(t))),this._hostRPC.on("scrollToAnnotation",(t=>{this._scrollToAnnotation(t)})),this._hostRPC.on("selectAnnotations",((t,e)=>this.selectAnnotations(t,{toggle:e}))),this._hostRPC.on("setKeyboardMode",(({mode:t})=>{["move","resize","rect"].includes(t)&&this._drawTool.setKeyboardMode(t)})),this._hostRPC.on("activateMoveMode",(()=>{this._activateToolWithMoveMode("rect")})),
|
|
162
|
+
this._hostRPC.on("activatePointMoveMode",(()=>{this._activateToolWithMoveMode("point")})),this._hostRPC.on("sidebarLayoutChanged",(e=>{yr(window,t)&&this.fitSideBySide(e),this.element.dispatchEvent(new Co({sidebarLayout:e,sideBySideActive:this._sideBySideActive()}))})),this._hostRPC.on("close",(()=>this.emit("hostDisconnected"))),this._notifySupportedToolsChanged();const e=await this._portFinder.discover("host");this._hostRPC.connect(e)}_notifySupportedToolsChanged(){this._hostRPC.call("supportedToolsChanged",this._integration.supportedTools())}async _scrollToAnchor(t){const e=xr(t);if(!e)return;let n;e instanceof Range?n=e:(n=new Range,n.selectNodeContents(e.anchor));const o=new Sr(n);this.element.dispatchEvent(o)&&(await o.ready,await this._integration.scrollToAnchor(t))}async _scrollToAnnotation(t){const e=this.anchors.find((e=>e.annotation.$tag===t));e?.highlights&&await this._scrollToAnchor(e)}async _connectSidebar(){this._sidebarRPC.on("featureFlagsUpdated",(t=>this.features.update(t))),
|
|
163
|
+
this._sidebarRPC.on("shortcutsUpdated",(t=>{wn(t)})),this._sidebarRPC.on("hoverAnnotations",(t=>this._hoverAnnotations(t))),this._sidebarRPC.on("scrollToAnnotation",(t=>{this._scrollToAnnotation(t)})),this._sidebarRPC.on("setHighlightsVisible",(t=>{this.setHighlightsVisible(t,!1)})),this._sidebarRPC.on("deleteAnnotation",(t=>this.detach(t))),this._sidebarRPC.on("getDocumentInfo",(async t=>t(await this.getDocumentInfo()))),this._sidebarRPC.on("loadAnnotations",(async t=>{try{await Promise.all(t.map((t=>this.anchor(t))))}catch(t){console.warn("Failed to anchor annotations:",t)}})),this._sidebarRPC.on("showContentInfo",(t=>this._integration.showContentInfo?.(t))),this._sidebarRPC.on("setOutsideAssignmentNoticeVisible",(t=>{this._setOutsideAssignmentNoticeVisible(t)})),this._sidebarRPC.on("navigateToSegment",(t=>this._integration.navigateToSegment?.(t))),this._sidebarRPC.on("renderThumbnail",((t,e,n)=>{(async()=>{
|
|
164
|
+
if(!this._integration.renderToBitmap)throw new Error("Thumbnail rendering not supported for document type");const n=this.anchors.find((e=>e.annotation.$tag===t));if(!n)throw new Error("Annotation not anchored in guest");return this._integration.renderToBitmap(n,e)})().then((t=>n({ok:!0,value:t}))).catch((t=>n({ok:!1,error:t.message})))})),this._portFinder.discover("sidebar").then((t=>{this._sidebarRPC.connect(t)})),this._sendDocumentInfo()}destroy(){this._drawTool.destroy(),this._portFinder.destroy(),this._hostRPC.destroy(),this._sidebarRPC.destroy(),this._listeners.removeAll(),this._selectionObserver.disconnect(),this._adder.destroy(),this._bucketBarClient.destroy(),this._clusterToolbar?.destroy(),this._outsideAssignmentNotice?.destroy(),this._highlighter.removeAllHighlights(),this._integration.destroy(),this._globalKeyboardListenerCleanup?.(),super.destroy()}_isKeyboardAnnotationModeEnabled(){return this.features.flagEnabled("vpat_keyboard")}_setupGlobalKeyboardListener(){const t=t=>{if(Ge(t.target))return
|
|
165
|
+
;if(!this._isKeyboardAnnotationModeEnabled())return;const e=yn(),n=this._integration.supportedTools(),o=n.includes("rect"),i=n.includes("point"),r=e.activateRectMove;if(r&&un(t,r)&&o){t.preventDefault(),t.stopPropagation();return void(this._drawTool.getKeyboardModeState().keyboardActive?this._drawTool.setKeyboardMode("move"):(this._pendingKeyboardMode="move",this.createAnnotation("rect").catch((()=>{this._pendingKeyboardMode=void 0}))))}const s=e.activateRectResize;if(s&&un(t,s)&&o){t.preventDefault(),t.stopPropagation();return void(this._drawTool.getKeyboardModeState().keyboardActive?this._drawTool.setKeyboardMode("resize"):(this._pendingKeyboardMode="resize",this.createAnnotation("rect").catch((()=>{this._pendingKeyboardMode=void 0}))))}const a=e.activatePoint;if(a&&un(t,a)&&i){t.preventDefault(),t.stopPropagation();this._drawTool.getKeyboardModeState().keyboardActive||(this._pendingKeyboardMode="move",this.createAnnotation("point").catch((()=>{this._pendingKeyboardMode=void 0})))}else;}
|
|
166
|
+
;document.body.addEventListener("keydown",t),this._globalKeyboardListenerCleanup=()=>{document.body.removeEventListener("keydown",t)}}async anchor(t){this._contentReady&&(await this._contentReady,this._contentReady=void 0);const e=t=>{const e=xr(t);if(!e)return;let n;n=e instanceof Range?this._highlighter.highlightRange(e,t.annotation?.$cluster):this._highlighter.highlightShape(e),n.forEach((e=>{e._annotation=t.annotation})),t.highlights=n,this._hoveredAnnotations.has(t.annotation.$tag)&&this._highlighter.setHighlightsFocused(n,!0)};this.detach(t.$tag,!1),this._annotations.add(t.$tag),t.target||(t.target=[]);const n=await Promise.all(t.target.map((async e=>{if(!e.selector||!e.selector.some((t=>"TextQuoteSelector"===t.type||"ShapeSelector"===t.type)))return{annotation:t,target:e};let n;try{const o=await this._integration.anchor(this.element,e.selector);if(o instanceof Range){const i=Un.fromRange(o);n={annotation:t,target:e,region:i}}else n={annotation:t,target:e,region:o}}catch{n={annotation:t,target:e}}
|
|
167
|
+
return n})));if(!this._annotations.has(t.$tag))return[];for(const t of n)e(t);return t.$orphan=n.length>0&&n.every((t=>t.target.selector&&!t.region)),this._updateAnchors(this.anchors.concat(n),!0),this._sidebarRPC.call("syncAnchoringStatus",t),n}detach(t,e=!0){this._annotations.delete(t);const n=[];for(const e of this.anchors)e.annotation.$tag!==t?n.push(e):e.highlights&&this._highlighter.removeHighlights(e.highlights);this._updateAnchors(n,e)}_updateAnchors(t,e){this.anchors=t,this._clusterToolbar?.scheduleClusterUpdates(),e&&this._bucketBarClient.update(this.anchors)}async createAnnotation(t){if("selection"===t)return this.createAnnotationFromSelection();if(!["rect","point"].includes(t))throw new Error("Unsupported annotation tool");{let e=!1;try{this._hostRPC.call("activeToolChanged",t);const e=this._pendingKeyboardMode;this._pendingKeyboardMode=void 0;const n=await this._drawTool.draw(t,e),o=await this.getDocumentInfo(),i=[{source:o.uri,selector:await this._integration.describe(this.element,n)}],r={
|
|
168
|
+
uri:o.uri,document:o.metadata,target:i,$tag:"a:"+Ce(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),r}catch(t){if(t instanceof vo&&["canceled","restarted"].includes(t.kind))return e="restarted"===t.kind,null;throw t}finally{e||this._hostRPC.call("activeToolChanged",null)}}}_activateToolWithMoveMode(t){this._drawTool.getKeyboardModeState().keyboardActive?this._drawTool.setKeyboardMode("move"):(this._pendingKeyboardMode="move",this.createAnnotation(t).catch((()=>{this._pendingKeyboardMode=void 0})))}async createAnnotationFromSelection({highlight:t=!1}={}){const e=this.selectedRanges;this.selectedRanges=[];const n=await this.getDocumentInfo(),o=this.element,i=(await Promise.all(e.map((t=>this._integration.describe(o,t))))).map((t=>({source:n.uri,selector:t}))),r={uri:n.uri,document:n.metadata,target:i,$highlight:t,$cluster:t?"user-highlights":"user-annotations",$tag:"a:"+Ce(8)};return this._sidebarRPC.call("createAnnotation",r),this.anchor(r),Cr(),r}_hoverAnnotations(t){
|
|
169
|
+
this._hoveredAnnotations.clear(),t.forEach((t=>this._hoveredAnnotations.add(t)));for(const e of this.anchors)if(e.highlights){const n=t.includes(e.annotation.$tag);this._highlighter.setHighlightsFocused(e.highlights,n)}this._sidebarRPC.call("hoverAnnotations",t)}_onSelection(t){const e=this._integration.getAnnotatableRange(t);if(!e)return void this._onClearSelection();const n=document.getSelection(),o=Kn(n),i=Gn(n);i?(this.selectedRanges=[e],this._hostRPC.call("textSelected"),this._commentsMode||(this._adder.annotationsForSelection=wr(),this._isAdderVisible=!0,this._adder.show(i,o))):this._onClearSelection()}_onClearSelection(){this._isAdderVisible=!1,this._adder.hide(),this.selectedRanges=[],this._informHostOnNextSelectionClear&&this._hostRPC.call("textUnselected"),this._informHostOnNextSelectionClear=!0}selectAnnotations(t,{toggle:e=!1,focusInSidebar:n=!1}={}){e?this._sidebarRPC.call("toggleAnnotationSelection",t):this._sidebarRPC.call("showAnnotations",t,n),this._sidebarRPC.call("openSidebar")}
|
|
170
|
+
setHighlightsVisible(t,e=!0){this._highlighter.setHighlightsVisible(t),this._highlightsVisible=t,e&&this._hostRPC.call("highlightsVisibleChanged",t)}get highlightsVisible(){return this._highlightsVisible}fitSideBySide(t){this._sidebarLayout=t,this._integration.fitSideBySide(t)}get hoveredAnnotationTags(){return this._hoveredAnnotations}_handleShortcut(t){const e=yn().toggleHighlights;e&&un(t,e)&&this.setHighlightsVisible(!this._highlightsVisible&&!this._commentsMode)}_setOutsideAssignmentNoticeVisible(t){this._outsideAssignmentNotice||(this._outsideAssignmentNotice=new mr(this.element)),this._outsideAssignmentNotice.setVisible(t)}}function kr(t,e){const n=new URL(t),o=new URLSearchParams;return o.append("config",JSON.stringify(e)),n.hash=o.toString(),n.toString()}function Mr(t,e){const n={};for(const[t,o]of Object.entries(e))"notebookAppUrl"!==t&&"sidebarAppUrl"!==t&&null!=o&&(n[t]=o);n.origin=new URL(t).origin,n.version="1.1766.0";const o=new URL(window.location.href);if(o.hash="",n.hostURL=o.toString(),
|
|
171
|
+
Array.isArray(n.services)&&n.services?.length>0){const t=n.services[0];t.onLoginRequest&&(t.onLoginRequestProvided=!0),t.onLogoutRequest&&(t.onLogoutRequestProvided=!0),t.onSignupRequest&&(t.onSignupRequestProvided=!0),t.onProfileRequest&&(t.onProfileRequestProvided=!0),t.onHelpRequest&&(t.onHelpRequestProvided=!0)}return n}function Rr({closed:t,onClose:e,children:n,className:o,"data-testid":i,"aria-label":r}){const s=it(null);return nt((()=>{t?s.current?.close():s.current?.showModal()}),[t]),nt((()=>{const t=s.current;return t?.addEventListener("cancel",e),()=>{t?.removeEventListener("cancel",e)}}),[e]),St("dialog",{ref:s,className:Tt("relative m-5 w-full h-full backdrop:bg-black/50",o),"data-testid":i,"aria-label":r,children:n})}function Er({closed:t,children:e,className:n,...o}){return St("div",{...o,className:Tt("fixed z-max top-0 left-0 right-0 bottom-0 p-3 bg-black/50",{hidden:t}),children:St("div",{className:Tt("relative w-full h-full",n),children:e})})}function Pr({document_:t=document,...e}){
|
|
172
|
+
return St(rt((()=>function(t){return"function"==typeof t.createElement("dialog").showModal}(t)?Rr:Er),[t]),{...e})}function Tr({config:t,groupId:e}){return St("iframe",{title:"Hypothesis annotation notebook",className:"h-full w-full border-0",allow:"fullscreen; clipboard-write",src:kr(t.notebookAppUrl,{...Mr(t.notebookAppUrl,t),group:e})})}function Nr({eventBus:t,config:e}){const[n,o]=et(0),[i,r]=et(!0),[s,a]=et(null),l=it(""),c=it(null);nt((()=>(l.current=document.body.style.overflow,()=>{document.body.style.overflow=l.current})),[]),nt((()=>{document.body.style.overflow=i?l.current:"hidden"}),[i]),nt((()=>{const e=t.createEmitter();return e.subscribe("openNotebook",(t=>{r(!1),o((t=>t+1)),a(t)})),c.current=e,()=>{e.destroy()}}),[t]);const h=st((()=>{r(!0),c.current?.publish("closeNotebook")}),[]);return null===s?null:St(Pr,{closed:i,onClose:h,"data-testid":"notebook-outer","aria-label":"Hypothesis notebook",children:[St("div",{className:"absolute right-0 m-3",children:St(oe,{title:"Close notebook",onClick:h,
|
|
173
|
+
variant:"dark",classes:Tt("!bg-transparent enabled:hover:!bg-grey-3"),"data-testid":"close-button",children:St(It,{className:"w-4 h-4"})})}),St(Tr,{config:e,groupId:s},n)]})}class Lr{constructor(t,e,n){this._container=new Pn("notebook",(()=>St(Nr,{eventBus:e,config:n}))),t.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function Or({eventBus:t,config:e}){const[n,o]=et(!0),i=it(null);nt((()=>{const e=t.createEmitter();return e.subscribe("openProfile",(()=>{o(!1)})),i.current=e,()=>{e.destroy()}}),[t]);const r=()=>{o(!0),i.current?.publish("closeProfile")};return n?null:St(Pr,{closed:n,onClose:r,"data-testid":"profile-outer","aria-label":"Hypothesis profile",children:[St("div",{className:"absolute right-0 m-3",children:St(oe,{title:"Close profile dialog",onClick:r,variant:"dark",classes:Tt("!bg-transparent enabled:hover:!bg-grey-3"),children:St(It,{className:"w-4 h-4"})})}),St("iframe",{title:"Hypothesis profile",className:"h-full w-full border-0",
|
|
174
|
+
src:e.profileAppUrl})]})}class Ir{constructor(t,e,n){this._container=new Pn("profile",(()=>St(Or,{eventBus:e,config:n}))),t.append(this._container.element),this._container.render()}destroy(){this._container.destroy()}}function Br({above:t,below:e,buckets:n,onFocusAnnotations:o,onScrollToAnnotation:i,onSelectAnnotations:r}){const s=t.anchors.length>0,a=e.anchors.length>0,l=t=>t.anchors.map((t=>t.tag));return St("ul",{className:"relative",children:[s&&St("li",{className:"absolute right-0 pointer-events-auto mt-[-11px]",style:{top:t.position},children:St(ve,{"data-testid":"up-navigation-button",direction:"up",onClick:()=>{const e=[...t.anchors].sort(((t,e)=>t.bottom-e.bottom)),n=e[e.length-1];i(n.tag)},onBlur:()=>o([]),onFocus:()=>o(l(t)),onMouseEnter:()=>o(l(t)),onMouseOut:()=>o([]),title:`Go up to next annotations (${t.anchors.length})`,children:t.anchors.length})}),n.map(((t,e)=>St("li",{className:"absolute right-0 pointer-events-auto mt-[-8px]",style:{top:t.position},children:St(ve,{direction:"left",
|
|
175
|
+
onClick:e=>r(l(t),e.metaKey||e.ctrlKey),onBlur:()=>o([]),onFocus:()=>o(l(t)),onMouseEnter:()=>o(l(t)),onMouseOut:()=>o([]),title:`Select nearby annotations (${t.anchors.length})`,children:t.anchors.length})},e))),a&&St("li",{className:"absolute right-0 pointer-events-auto",style:{top:e.position},children:St(ve,{"data-testid":"down-navigation-button",direction:"down",onClick:()=>{const t=[...e.anchors].sort(((t,e)=>t.top-e.top)),n=t[0];i(n.tag)},onBlur:()=>o([]),onFocus:()=>o(l(e)),onMouseEnter:()=>o(l(e)),onMouseOut:()=>o([]),title:`Go up to next annotations (${e.anchors.length})`,children:e.anchors.length})})]})}class Dr{constructor(t,{onFocusAnnotations:e,onScrollToAnnotation:n,onSelectAnnotations:o}){this._positions=[],this._container=new Pn("bucket-bar",(()=>this._render())),Object.assign(this._container.element.style,{display:"block",flexGrow:"1",width:"100%"}),t.appendChild(this._container.element),this._onFocusAnnotations=e,this._onScrollToAnnotation=n,this._onSelectAnnotations=o,
|
|
176
|
+
this._container.render()}destroy(){this._container.destroy()}update(t){this._positions=t,this._container.render()}_render(){const t=function(t,e){const n=[],o=[],i=[];let r=null;function s(t){const{bottom:e,top:n}=t;return{bottom:e,position:n+(e-n)/2,anchors:[t],top:n}}const a=e.getBoundingClientRect(),l=t.map((t=>({tag:t.tag,top:t.top-a.top,bottom:t.bottom-a.top})));for(const t of l){const e=(t.top+t.bottom)/2;if(e<30){n.push(t);continue}if(e>a.height-30){o.push(t);continue}if(!r){r=s(t);continue}const l=t.top>r.top&&t.bottom<r.bottom;if(t.top-r.bottom>60&&!l)i.push(r),r=s(t);else{const e=t.bottom>r.bottom?t.bottom:r.bottom,n=e-r.top;r.anchors.push(t),r.bottom=e,r.position=r.top+n/2}}return r&&i.push(r),{above:{anchors:n,position:25},below:{anchors:o,position:a.height-30},buckets:i}}(this._positions,this._container.element);return St(Br,{above:t.above,below:t.below,buckets:t.buckets,onFocusAnnotations:t=>this._onFocusAnnotations(t),onScrollToAnnotation:t=>this._onScrollToAnnotation(t),
|
|
177
|
+
onSelectAnnotations:(t,e)=>this._onSelectAnnotations(t,e)})}}function Fr({emitter:t}){const[e,n]=et([]),o=st((t=>n((e=>[...e,t]))),[]),i=st((t=>n((e=>e.filter((e=>e.id!==t))))),[]);return nt((()=>(t.subscribe("toastMessageAdded",o),t.subscribe("toastMessageDismissed",i),()=>{t.unsubscribe("toastMessageAdded",o),t.unsubscribe("toastMessageDismissed",i)})),[t,i,o]),St(ye,{messages:e,onMessageDismiss:i})}function Hr(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",...t,children:[St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor","clip-rule":"evenodd",
|
|
178
|
+
d:"M2.5 0h-1A1.5 1.5 0 0 0 0 1.5v1 a1.5 1.5 0 0 0 1 1.415v8.17 A1.5 1.5 0 0 0 0 13.5v1 A1.5 1.5 0 0 0 1.5 16h1 a1.5 1.5 0 0 0 1.415-1h8.17 a1.5 1.5 0 0 0 1.415 1h1 a1.5 1.5 0 0 0 1.5-1.5v-1 a1.5 1.5 0 0 0-1-1.415v-8.17 A1.5 1.5 0 0 0 16 2.5v-1 A1.5 1.5 0 0 0 14.5 0h-1 a1.5 1.5 0 0 0-1.415 1h-8.17 A1.5 1.5 0 0 0 2.5 0 m9.585 13 c.151-.426.489-.764.915-.915v-8.17 A1.5 1.5 0 0 1 12.085 3h-8.17 c-.151.426-.489.764-.915.915v8.17 c.426.151.764.489.915.915z M1 1.5 a.5.5 0 0 1 .5-.5h1 a.5.5 0 0 1 .5.5v1 a.5.5 0 0 1-.5.5h-1 a.5.5 0 0 1-.5-.5z M1.5 13 a.5.5 0 0 0-.5.5v1 a.5.5 0 0 0 .5.5h1 a.5.5 0 0 0 .5-.5v-1 a.5.5 0 0 0-.5-.5z M13 1.5 a.5.5 0 0 1 .5-.5h1 a.5.5 0 0 1 .5.5v1 a.5.5 0 0 1-.5.5h-1 a.5.5 0 0 1-.5-.5z m.5 11.5 a.5.5 0 0 0-.5.5v1 a.5.5 0 0 0 .5.5h1 a.5.5 0 0 0 .5-.5v-1 a.5.5 0 0 0-.5-.5z"})]}),St("g",{transform:"translate(3 3) scale(0.0833)",stroke:"currentColor","stroke-width":"10","stroke-linecap":"round","stroke-linejoin":"round",fill:"none",children:[St("path",{d:"M60 15 L60 48"}),St("path",{
|
|
179
|
+
d:"M45 30 L60 15 L75 30"}),St("path",{d:"M60 72 L60 105"}),St("path",{d:"M45 90 L60 105 L75 90"}),St("path",{d:"M15 60 L48 60"}),St("path",{d:"M30 45 L15 60 L30 75"}),St("path",{d:"M72 60 L105 60"}),St("path",{d:"M90 45 L105 60 L90 75"})]})]})}function Vr(t){return St("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",...t,children:[St("g",{"fill-rule":"evenodd",children:[St("path",{fill:"none",d:"M0 0h16v16H0z"}),St("path",{fill:"currentColor","clip-rule":"evenodd",
|
|
180
|
+
d:"M2.5 0h-1A1.5 1.5 0 0 0 0 1.5v1 a1.5 1.5 0 0 0 1 1.415v8.17 A1.5 1.5 0 0 0 0 13.5v1 A1.5 1.5 0 0 0 1.5 16h1 a1.5 1.5 0 0 0 1.415-1h8.17 a1.5 1.5 0 0 0 1.415 1h1 a1.5 1.5 0 0 0 1.5-1.5v-1 a1.5 1.5 0 0 0-1-1.415v-8.17 A1.5 1.5 0 0 0 16 2.5v-1 A1.5 1.5 0 0 0 14.5 0h-1 a1.5 1.5 0 0 0-1.415 1h-8.17 A1.5 1.5 0 0 0 2.5 0 m9.585 13 c.151-.426.489-.764.915-.915v-8.17 A1.5 1.5 0 0 1 12.085 3h-8.17 c-.151.426-.489.764-.915.915v8.17 c.426.151.764.489.915.915z M1 1.5 a.5.5 0 0 1 .5-.5h1 a.5.5 0 0 1 .5.5v1 a.5.5 0 0 1-.5.5h-1 a.5.5 0 0 1-.5-.5z M1.5 13 a.5.5 0 0 0-.5.5v1 a.5.5 0 0 0 .5.5h1 a.5.5 0 0 0 .5-.5v-1 a.5.5 0 0 0-.5-.5z M13 1.5 a.5.5 0 0 1 .5-.5h1 a.5.5 0 0 1 .5.5v1 a.5.5 0 0 1-.5.5h-1 a.5.5 0 0 1-.5-.5z m.5 11.5 a.5.5 0 0 0-.5.5v1 a.5.5 0 0 0 .5.5h1 a.5.5 0 0 0 .5-.5v-1 a.5.5 0 0 0-.5-.5z"})]}),St("g",{transform:"translate(3 3) scale(0.0833)",stroke:"currentColor","stroke-width":"18","stroke-linecap":"round","stroke-linejoin":"round",fill:"none",children:[St("path",{d:"M30 30 L55 55"}),St("path",{
|
|
181
|
+
d:"M65 65 L90 90"}),St("path",{d:"M30 45 L30 30 L45 30"}),St("path",{d:"M75 90 L90 90 L90 75"})]})]})}function zr(t,e,n){return t&&"rect"===e?"move"===n?"Move mode (Ctrl+Shift+Y) - Click to switch to Resize mode":"resize"===n?"Resize mode (Ctrl+Shift+J) - Click to switch to Rectangle mode":"Rectangle mode - Click to switch to Move mode":"Rectangle annotation"}function Ur(t,e){return n=>{"Enter"===n.key&&t&&!e&&(n.preventDefault(),n.stopPropagation(),t())}}function $r({mode:t}){return St("move"===t?Hr:"resize"===t?Vr:Zt,{})}function qr({icon:t,pressedBackground:e=!0,...n}){return St(ee,{classes:Tt("justify-center rounded","w-[30px] h-[30px] touch:h-[40px]","shadow border bg-white text-grey-6 hover:text-grey-9",e&&"aria-pressed:bg-grey-3"),...n,size:"custom",variant:"custom",children:St(t,{})})}function Wr({highlightsVisible:t}){return St("div",{className:"sr-only",role:"status","data-testid":"toolbar-status",children:t?"Highlights visible":"Highlights hidden"})}
|
|
182
|
+
function jr({activeTool:t=null,closeSidebar:e,createAnnotation:n,isSidebarOpen:o,sidebarContainerId:i,newAnnotationType:r,showHighlights:s,supportedTools:a=["selection"],toggleHighlights:l,toggleSidebar:c,toggleSidebarRef:h,useMinimalControls:d=!1,keyboardMode:u=null,keyboardActive:f=!1,onModeClick:p,onActivateMoveMode:g,onActivatePointMoveMode:_}){return St("div",{className:Tt({"absolute right-full":d,"relative right-[11px]":!d},"w-[33px] z-2","text-px-base leading-none"),children:[d&&o&&St(ee,{classes:Tt("transition-colors focus-visible-ring ring-inset","w-[27px] h-[27px] mt-[140px] ml-[6px]","flex items-center justify-center bg-white border","text-grey-6 hover:text-grey-9 transition-colors","border-r-0","shadow-sidebar"),title:"Close annotation sidebar",onClick:e,unstyled:!0,children:St(It,{})}),!d&&St(y,{children:[St(ee,{classes:Tt("transition-colors focus-visible-ring ring-inset","h-[40px] w-[33px] pl-[6px] rounded-bl","bg-white text-grey-6 hover:text-grey-9","border-l border-b"),elementRef:h,
|
|
183
|
+
title:"Annotation sidebar",expanded:o,"aria-controls":i,onClick:c,unstyled:!0,children:St(o?Ft:Dt,{})}),St("div",{className:"space-y-[6px] mt-[8px]",children:[St(qr,{title:"Show highlights",icon:s?te:$t,pressed:s,pressedBackground:!1,onClick:l}),a.includes("selection")&&St(qr,{"data-testid":"text-annotation",title:"note"===r?"New page note":"New annotation",icon:"note"===r?Kt:Ot,onClick:()=>n("selection")}),a.includes("rect")&&St(qr,{"data-testid":"rect-annotation",pressed:"rect"===t,title:zr(f,t,u??null),icon:f&&"rect"===t?()=>St($r,{mode:u??"rect"}):Zt,onClick:()=>{f&&"rect"===t?p?.():n("rect"===t?null:"rect")},onKeyDown:Ur(g,f)}),a.includes("point")&&St(qr,{"data-testid":"point-annotation",pressed:"point"===t,title:"Pin annotation",icon:Xt,onClick:()=>n("point"===t?null:"point"),onKeyDown:Ur(_,f)})]}),St(Wr,{highlightsVisible:s})]})]})}class Kr{constructor(t,e){const{createAnnotation:n,setSidebarOpen:o,setHighlightsVisible:i}=e;this.container=t,this._activeTool=null,this._useMinimalControls=!1,
|
|
184
|
+
this._newAnnotationType="note",this._highlightsVisible=!1,this._sidebarOpen=!1,this._sidebarContainerId=e.sidebarContainerId,this._supportedAnnotationTools=["selection"],this._keyboardMode=null,this._keyboardActive=!1,this._closeSidebar=()=>o(!1),this._toggleSidebar=()=>o(!this._sidebarOpen),this._toggleHighlights=()=>i(!this._highlightsVisible),this._createAnnotation=t=>{n(t),"selection"===t&&o(!0)},this._sidebarToggleButton={current:null},this.render()}getWidth(){return this.container.firstChild.getBoundingClientRect().width}set activeTool(t){this._activeTool=t,this.render()}get activeTool(){return this._activeTool}set useMinimalControls(t){this._useMinimalControls=t,this.render()}get useMinimalControls(){return this._useMinimalControls}set sidebarOpen(t){this._sidebarOpen=t,this.render()}get sidebarOpen(){return this._sidebarOpen}set newAnnotationType(t){this._newAnnotationType=t,this.render()}get newAnnotationType(){return this._newAnnotationType}set highlightsVisible(t){this._highlightsVisible=t,
|
|
185
|
+
this.render()}get highlightsVisible(){return this._highlightsVisible}get sidebarToggleButton(){return this._sidebarToggleButton.current}set supportedAnnotationTools(t){this._supportedAnnotationTools=t,this.render()}get supportedAnnotationTools(){return this._supportedAnnotationTools}set keyboardModeState(t){this._keyboardActive=t.keyboardActive,this._keyboardMode=t.keyboardMode,this.render()}get keyboardModeState(){return{keyboardActive:this._keyboardActive,keyboardMode:this._keyboardMode}}set modeButtonCallbacks(t){this._onModeClick=t.onModeClick,this._onActivateMoveMode=t.onActivateMoveMode,this._onActivatePointMoveMode=t.onActivatePointMoveMode,this.render()}get modeButtonCallbacks(){return{onModeClick:this._onModeClick,onActivateMoveMode:this._onActivateMoveMode,onActivatePointMoveMode:this._onActivatePointMoveMode}}render(){H(St(jr,{activeTool:this._activeTool,closeSidebar:this._closeSidebar,createAnnotation:this._createAnnotation,newAnnotationType:this._newAnnotationType,isSidebarOpen:this._sidebarOpen,
|
|
186
|
+
sidebarContainerId:this._sidebarContainerId,showHighlights:this._highlightsVisible,supportedTools:this._supportedAnnotationTools,toggleHighlights:this._toggleHighlights,toggleSidebar:this._toggleSidebar,toggleSidebarRef:this._sidebarToggleButton,useMinimalControls:this.useMinimalControls,keyboardMode:this._keyboardMode,keyboardActive:this._keyboardActive,onModeClick:this._onModeClick,onActivateMoveMode:this._onActivateMoveMode,onActivatePointMoveMode:this._onActivatePointMoveMode}),this.container)}}class Xr{constructor({target:t,threshold:e=10,onDrag:n}){t.style.touchAction="none",this._listeners=new mt,this._startX=null,this._dragActive=!1,this._threshold=e,this._listeners.add(t,"pointerdown",(t=>{this._startX=t.clientX}));const o=t=>{if(null!==this._startX&&this._dragActive){const e=t.clientX-this._startX;n({type:"dragend",deltaX:e})}this._startX=null,this._dragActive=!1};this._listeners.add(window,"pointercancel",o),this._listeners.add(window,"pointerup",o),this._listeners.add(window,"pointermove",(t=>{
|
|
187
|
+
if(null===this._startX)return;const e=t.clientX-this._startX;!this._dragActive&&Math.abs(e)>=this._threshold&&(this._dragActive=!0,n({type:"dragstart",deltaX:e})),this._dragActive&&n({type:"dragmove",deltaX:e})}))}destroy(){this._listeners.removeAll()}}const Yr=280;class Gr{constructor(t,e,n){this._emitter=e.createEmitter(),this._guestWithSelection=null,this._guestRPC=[],this._sidebarRPC=new De,this.iframe=function(t){const e=t.sidebarAppUrl,n=kr(e,Mr(e,t)),o=document.createElement("iframe");return o.src=n,o.title="Hypothesis annotation viewer",o.className="sidebar-frame",o.allow="fullscreen; clipboard-write",o}(n),this._config=n,this.bucketBar=null,this.features=new Mo;const o="sidebar-container",i=document.createElement("div");if(i.setAttribute("data-testid","toolbar-container"),this.toolbar=new Kr(i,{sidebarContainerId:o,createAnnotation:t=>{if(0===this._guestRPC.length)return;(this._guestWithSelection??this._guestRPC[0]).call("createAnnotation",{tool:t})},setSidebarOpen:t=>t?this.open():this.close(),
|
|
188
|
+
setHighlightsVisible:t=>this.setHighlightsVisible(t)}),this.toolbar.modeButtonCallbacks={onModeClick:()=>{const t=this._getGuestRPC();if(!t)return;const e=this.toolbar.keyboardModeState?.keyboardMode||"rect";let n;n="rect"===e?"move":"move"===e?"resize":"rect",t.call("setKeyboardMode",{mode:n})},onActivateMoveMode:()=>{const t=this._getGuestRPC();t&&t.call("activateMoveMode")},onActivatePointMoveMode:()=>{const t=this._getGuestRPC();t&&t.call("activatePointMoveMode")}},n.externalContainerSelector)this.externalFrame=document.querySelector(n.externalContainerSelector)??t,this.externalFrame.appendChild(this.iframe);else{if(this.iframeContainer=document.createElement("div"),this.iframeContainer.style.display="none",this.iframeContainer.className="sidebar-container",this.iframeContainer.id=o,"clean"===n.theme)this.iframeContainer.classList.add("theme-clean"),this.iframeContainer.append(i),this.toolbar.useMinimalControls=!0;else{let t;n.bucketContainerSelector&&(t=document.querySelector(n.bucketContainerSelector),
|
|
189
|
+
t||console.warn(`Custom bucket container "${n.bucketContainerSelector}" not found`));const e=document.createElement("div");e.setAttribute("data-testid","sidebar-edge"),e.className=Tt("absolute top-0 bottom-0 w-[23px] left-[-22px]","flex flex-col pr-[5px]","bg-grey-2 sidebar-collapsed:bg-black/[.08]","pointer-events-none"),i.className="pointer-events-auto",e.append(i),this.iframeContainer.append(e),t||(t=e),this.bucketBar=new Dr(t,{onFocusAnnotations:t=>this._guestRPC.forEach((e=>e.call("hoverAnnotations",t))),onScrollToAnnotation:t=>this._guestRPC.forEach((e=>e.call("scrollToAnnotation",t))),onSelectAnnotations:(t,e)=>this._guestRPC.forEach((n=>n.call("selectAnnotations",t,e)))})}this.iframeContainer.appendChild(this.iframe),this._hypothesisSidebar=document.createElement("hypothesis-sidebar");const{shadowRoot:e,stylesLoaded:r}=En(this._hypothesisSidebar);e.appendChild(this.iframeContainer),r.then((()=>this._onResize())),t.appendChild(this._hypothesisSidebar),
|
|
190
|
+
this._messagesElement=document.createElement("div"),e.appendChild(this._messagesElement),H(St(Fr,{emitter:this._emitter}),this._messagesElement)}this.iframe.contentWindow&&Te(this.iframe.contentWindow),this._listeners=new mt,this.iframeContainer?this._toolbarWidth=this.toolbar.getWidth():this._toolbarWidth=0,this._listeners.add(window,"resize",(()=>this._onResize())),this._dragResizeState={initial:null,final:null};const r=this.toolbar.sidebarToggleButton;r&&(this._dragResizeHandler=new Xr({target:r,onDrag:t=>this._onDragSidebarToggleButton(t)})),this.close();const[s]=n.services||[];s&&(this.onLoginRequest=s.onLoginRequest,this.onLogoutRequest=s.onLogoutRequest,this.onSignupRequest=s.onSignupRequest,this.onProfileRequest=s.onProfileRequest,this.onHelpRequest=s.onHelpRequest),this.onLayoutChange=n.onLayoutChange,this._layoutState={expanded:!1,width:0,height:0,toolbarWidth:0},this._updateLayoutState(!1),this._setupSidebarEvents()}_getGuestRPC(){return this._guestRPC[0]??null}destroy(){
|
|
191
|
+
this._guestRPC.forEach((t=>t.destroy())),this._sidebarRPC.destroy(),this.bucketBar?.destroy(),this._listeners.removeAll(),this._dragResizeHandler?.destroy(),this._hypothesisSidebar?(H(null,this._messagesElement),this._hypothesisSidebar.remove()):this.iframe.remove(),this._emitter.destroy(),Te(null)}onFrameConnected(t,e){switch(t){case"guest":this._connectGuest(e);break;case"sidebar":this._sidebarRPC.connect(e)}}_connectGuest(t){const e=new De;e.on("textSelected",(()=>{this._guestWithSelection=e,this.toolbar.newAnnotationType="annotation",this._guestRPC.filter((t=>t!==e)).forEach((t=>t.call("clearSelection")))})),e.on("textUnselected",(()=>{this._guestWithSelection=null,this.toolbar.newAnnotationType="note",this._guestRPC.filter((t=>t!==e)).forEach((t=>t.call("clearSelection")))})),e.on("activeToolChanged",(t=>{this.toolbar.activeTool=t})),e.on("highlightsVisibleChanged",(t=>{this.setHighlightsVisible(t)}));const n=this.bucketBar;n&&e.on("anchorsChanged",(t=>{0===this._guestRPC.indexOf(e)&&n.update(t)})),
|
|
192
|
+
e.on("close",(()=>{e.destroy(),e===this._guestWithSelection&&(this._guestWithSelection=null),this._guestRPC=this._guestRPC.filter((t=>t!==e))})),e.on("supportedToolsChanged",(t=>{this.toolbar.supportedAnnotationTools=t})),e.on("keyboardModeChanged",(t=>{this.toolbar.keyboardModeState=t})),e.connect(t),this._guestRPC.push(e),e.call("sidebarLayoutChanged",this._layoutState)}_setupSidebarEvents(){var t;t=document.body,this._sidebarRPC.on("publicAnnotationCountChanged",(function(e){const n=t.querySelectorAll("[data-hypothesis-annotation-count]");Array.from(n).forEach((t=>{t.textContent=e.toString()}))})),function(t,e){const n=t.querySelectorAll("[data-hypothesis-trigger]");Array.from(n).forEach((t=>{t.addEventListener("click",(t=>{e(),t.stopPropagation()}))}))}(document.body,(()=>this.open())),this._sidebarRPC.on("featureFlagsUpdated",(t=>this.features.update(t))),this._sidebarRPC.on("connect",(()=>{this.iframeContainer&&(this.iframeContainer.style.display="");const t="always"===this._config.showHighlights
|
|
193
|
+
;this.setHighlightsVisible(t),(this._config.openSidebar||this._config.annotations||this._config.query||this._config.group)&&this.open()})),this._sidebarRPC.on("showHighlights",(()=>this.setHighlightsVisible(!0))),this._sidebarRPC.on("openSidebar",(()=>this.open())),this._sidebarRPC.on("closeSidebar",(()=>this.close())),this._sidebarRPC.on("openNotebook",(t=>{this.hide(),this._emitter.publish("openNotebook",t)})),this._sidebarRPC.on("openProfile",(()=>{this.hide(),this._emitter.publish("openProfile")})),this._emitter.subscribe("closeProfile",(()=>{this.show()})),this._emitter.subscribe("closeNotebook",(()=>{this.show()})),this._sidebarRPC.on("toastMessageAdded",(t=>{this._emitter.publish("toastMessageAdded",t)})),this._sidebarRPC.on("toastMessageDismissed",(t=>{this._emitter.publish("toastMessageDismissed",t)}))
|
|
194
|
+
;[["loginRequested",this.onLoginRequest],["logoutRequested",this.onLogoutRequest],["signupRequested",this.onSignupRequest],["profileRequested",this.onProfileRequest],["helpRequested",this.onHelpRequest]].forEach((([t,e])=>{e&&this._sidebarRPC.on(t,(()=>e()))}))}_resetDragResizeState(){this._dragResizeState={initial:null,final:null}}_updateLayout(){this._renderFrame||(this._renderFrame=requestAnimationFrame((()=>{if(this._renderFrame=void 0,"number"==typeof this._dragResizeState.final&&this._dragResizeState.final!==this._dragResizeState.initial&&this.iframeContainer){const t=this._dragResizeState.final,e=-t;this.iframeContainer.style.marginLeft=`${t}px`,e>=Yr&&(this.iframeContainer.style.width=`${e}px`),this._updateLayoutState()}})))}_updateLayoutState(t){const e=this.iframeContainer&&this.toolbar.getWidth()||0,n=this.iframeContainer??this.externalFrame,{height:o}=n.getBoundingClientRect(),i=window.getComputedStyle(n),r=parseInt(i.width),s=parseInt(i.marginLeft);let a=e
|
|
195
|
+
;"boolean"==typeof t?t&&(a+=r):(s<Yr?a-=s:a+=r,t=a>e);const l={expanded:t,width:t?a:e,height:o,toolbarWidth:e};this._layoutState=l,this.onLayoutChange?.(l),this._guestRPC.forEach((t=>t.call("sidebarLayoutChanged",l)))}_onResize(){this.toolbar.sidebarOpen&&(window.innerWidth<Yr?this.close():this.open())}isResizing(){return null!==this._dragResizeState.initial}_onDragSidebarToggleButton(t){const e=this.iframeContainer;if(e)switch(t.type){case"dragstart":this._resetDragResizeState(),e.classList.add("sidebar-no-transition"),this.toolbar.container.style.pointerEvents="none",this._dragResizeState.initial=parseInt(getComputedStyle(e).marginLeft);break;case"dragend":e.classList.remove("sidebar-no-transition"),this.toolbar.container.style.pointerEvents="",null===this._dragResizeState.final||this._dragResizeState.final<=-280?this.open():this.close(),this._resetDragResizeState();break;case"dragmove":{if("number"!=typeof this._dragResizeState.initial)return;const e=this._dragResizeState.initial,n=t.deltaX
|
|
196
|
+
;this._dragResizeState.final=Math.min(Math.round(e+n),0),this._updateLayout();break}}}open(){if(this._sidebarRPC.call("sidebarOpened"),this.iframeContainer){const t=this.iframeContainer.getBoundingClientRect().width;this.iframeContainer.style.marginLeft=-1*t+"px",this.iframeContainer.classList.remove("sidebar-collapsed")}this.toolbar.sidebarOpen=!0,"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!0),this._updateLayoutState(!0)}close(){this._sidebarRPC.call("sidebarClosed"),this.iframeContainer&&(this.iframeContainer.style.marginLeft="",this.iframeContainer.classList.add("sidebar-collapsed")),this.toolbar.sidebarOpen=!1,"whenSidebarOpen"===this._config.showHighlights&&this.setHighlightsVisible(!1),this._updateLayoutState(!1)}setHighlightsVisible(t){this.toolbar.highlightsVisible=t,this._sidebarRPC.call("setHighlightsVisible",t)}show(){this.iframeContainer?.classList.remove("is-hidden")}hide(){this.iframeContainer?.classList.add("is-hidden")}}class Qr{constructor(t){this._emitter=t,
|
|
197
|
+
this._subscriptions=[]}publish(t,...e){this._emitter.emit(t,...e)}subscribe(t,e){this._emitter.on(t,e),this._subscriptions.push([t,e])}unsubscribe(t,e){this._emitter.off(t,e),this._subscriptions=this._subscriptions.filter((([n,o])=>n!==t||o!==e))}destroy(){for(const[t,e]of this._subscriptions)this._emitter.off(t,e);this._subscriptions=[]}}class Jr{constructor(){this._emitter=new Me}createEmitter(){return new Qr(this._emitter)}}const Zr=document.querySelector('link[type="application/annotator+html"][rel="sidebar"]');new Promise((t=>{"loading"!==document.readyState&&t(),document.addEventListener("readystatechange",(()=>t()))})).then((function(){const t=hn("annotator");let e=()=>{};const n=new Promise((t=>{e=t}));Zr.addEventListener("destroy",e);const o=t.subFrameIdentifier?window.parent:window,i=[];if(o===window){if(function(){const t=document.querySelectorAll(["hypothesis-sidebar","hypothesis-notebook","hypothesis-profile"].join(","));return t.forEach((t=>t.remove())),t.length>0
|
|
198
|
+
}())return void console.warn("Hypothesis did not load because it found an existing instance on the page.");const t=hn("sidebar"),e=new URL(t.sidebarAppUrl).origin,n=new Ne(e),o=new Jr,r=new Gr(document.body,o,t),s=new Lr(document.body,o,hn("notebook")),a=new Ir(document.body,o,hn("profile"));n.on("frameConnected",((t,e)=>r.onFrameConnected(t,e))),i.push(n,r,s,a)}if("container"===dr()){const e=new ur(t);i.push(e)}else{const n=new ar(document.body,t),r=new Ar(document.body,t,o);r.on("hostDisconnected",e),i.push(n,r)}n.then((()=>{i.forEach((t=>t.destroy()));document.querySelectorAll("[data-hypothesis-asset]").forEach((t=>t.remove())),function(t=document){Array.from(t.querySelectorAll("script.js-hypothesis-config[data-remove-on-unload]")).forEach((t=>t.remove()))}()}))}))}();
|
|
199
|
+
//# sourceMappingURL=annotator.bundle.js.map
|