@internetarchive/bookreader 5.0.0-95 → 5.0.0-96
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/BookReader.css +2251 -0
- package/BookReader/BookReader.js +3 -0
- package/BookReader/BookReader.js.LICENSE.txt +72 -0
- package/BookReader/BookReader.js.map +1 -0
- package/BookReader/hypothesis/LICENSE +50 -0
- package/BookReader/hypothesis/README.md +55 -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 +184 -0
- package/BookReader/hypothesis/build/scripts/annotator.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/scripts/sidebar.bundle.js +798 -0
- package/BookReader/hypothesis/build/scripts/sidebar.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js +711 -0
- package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/styles/annotator.css +2235 -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 +2 -0
- package/BookReader/hypothesis/build/styles/katex.min.css.map +1 -0
- package/BookReader/hypothesis/build/styles/pdfjs-overrides.css +2 -0
- package/BookReader/hypothesis/build/styles/pdfjs-overrides.css.map +1 -0
- package/BookReader/hypothesis/build/styles/sidebar.css +2731 -0
- package/BookReader/hypothesis/build/styles/sidebar.css.map +1 -0
- package/BookReader/hypothesis/build/styles/ui-playground.css +2659 -0
- package/BookReader/hypothesis/build/styles/ui-playground.css.map +1 -0
- package/BookReader/hypothesis/package.json +126 -0
- package/BookReader/ia-bookreader-bundle.js +1782 -0
- package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +7 -0
- package/BookReader/ia-bookreader-bundle.js.map +1 -0
- package/BookReader/icons/1up.svg +1 -0
- package/BookReader/icons/2up.svg +1 -0
- package/BookReader/icons/advance.svg +3 -0
- package/BookReader/icons/chevron-right.svg +1 -0
- package/BookReader/icons/close-circle-dark.svg +1 -0
- package/BookReader/icons/close-circle.svg +1 -0
- package/BookReader/icons/fullscreen.svg +1 -0
- package/BookReader/icons/fullscreen_exit.svg +1 -0
- package/BookReader/icons/hamburger.svg +1 -0
- package/BookReader/icons/left-arrow.svg +1 -0
- package/BookReader/icons/magnify-minus.svg +1 -0
- package/BookReader/icons/magnify-plus.svg +1 -0
- package/BookReader/icons/magnify.svg +1 -0
- package/BookReader/icons/pause.svg +1 -0
- package/BookReader/icons/play.svg +1 -0
- package/BookReader/icons/playback-speed.svg +1 -0
- package/BookReader/icons/read-aloud.svg +1 -0
- package/BookReader/icons/review.svg +3 -0
- package/BookReader/icons/thumbnails.svg +1 -0
- package/BookReader/icons/voice.svg +1 -0
- package/BookReader/icons/volume-full.svg +1 -0
- package/BookReader/images/BRicons.png +0 -0
- package/BookReader/images/BRicons.svg +5 -0
- package/BookReader/images/BRicons_ia.png +0 -0
- package/BookReader/images/back_pages.png +0 -0
- package/BookReader/images/book_bottom_icon.png +0 -0
- package/BookReader/images/book_down_icon.png +0 -0
- package/BookReader/images/book_left_icon.png +0 -0
- package/BookReader/images/book_leftmost_icon.png +0 -0
- package/BookReader/images/book_right_icon.png +0 -0
- package/BookReader/images/book_rightmost_icon.png +0 -0
- package/BookReader/images/book_top_icon.png +0 -0
- package/BookReader/images/book_up_icon.png +0 -0
- package/BookReader/images/books_graphic.svg +1 -0
- package/BookReader/images/booksplit.png +0 -0
- package/BookReader/images/control_pause_icon.png +0 -0
- package/BookReader/images/control_play_icon.png +0 -0
- package/BookReader/images/embed_icon.png +0 -0
- package/BookReader/images/hypothesis.ico +0 -0
- package/BookReader/images/icon-home-ia.png +0 -0
- package/BookReader/images/icon_OL-logo-xs.png +0 -0
- package/BookReader/images/icon_alert-xs.png +0 -0
- package/BookReader/images/icon_book.svg +1 -0
- package/BookReader/images/icon_bookmark.svg +1 -0
- package/BookReader/images/icon_close-pop.png +0 -0
- package/BookReader/images/icon_download.png +0 -0
- package/BookReader/images/icon_gear.svg +1 -0
- package/BookReader/images/icon_hamburger.svg +1 -0
- package/BookReader/images/icon_home.png +0 -0
- package/BookReader/images/icon_home.svg +1 -0
- package/BookReader/images/icon_home_ia.png +0 -0
- package/BookReader/images/icon_indicator.png +0 -0
- package/BookReader/images/icon_info.svg +1 -0
- package/BookReader/images/icon_one_page.svg +1 -0
- package/BookReader/images/icon_pause.svg +1 -0
- package/BookReader/images/icon_play.svg +1 -0
- package/BookReader/images/icon_playback-rate.svg +1 -0
- package/BookReader/images/icon_return.png +0 -0
- package/BookReader/images/icon_search_button.svg +1 -0
- package/BookReader/images/icon_share.svg +1 -0
- package/BookReader/images/icon_skip-ahead.svg +1 -0
- package/BookReader/images/icon_skip-back.svg +2 -0
- package/BookReader/images/icon_speaker.svg +1 -0
- package/BookReader/images/icon_speaker_open.svg +1 -0
- package/BookReader/images/icon_thumbnails.svg +1 -0
- package/BookReader/images/icon_toc.svg +1 -0
- package/BookReader/images/icon_two_pages.svg +1 -0
- package/BookReader/images/icon_zoomer.png +0 -0
- package/BookReader/images/loading.gif +0 -0
- package/BookReader/images/logo_icon.png +0 -0
- package/BookReader/images/marker_chap-off.png +0 -0
- package/BookReader/images/marker_chap-off.svg +1 -0
- package/BookReader/images/marker_chap-off_ia.png +0 -0
- package/BookReader/images/marker_chap-on.png +0 -0
- package/BookReader/images/marker_chap-on.svg +1 -0
- package/BookReader/images/marker_srch-on.svg +1 -0
- package/BookReader/images/marker_srchchap-off.png +0 -0
- package/BookReader/images/marker_srchchap-on.png +0 -0
- package/BookReader/images/nav_control-dn.png +0 -0
- package/BookReader/images/nav_control-dn_ia.png +0 -0
- package/BookReader/images/nav_control-up.png +0 -0
- package/BookReader/images/nav_control-up_ia.png +0 -0
- package/BookReader/images/nav_control.png +0 -0
- package/BookReader/images/one_page_mode_icon.png +0 -0
- package/BookReader/images/paper-badge.png +0 -0
- package/BookReader/images/print_icon.png +0 -0
- package/BookReader/images/progressbar.gif +0 -0
- package/BookReader/images/right_edges.png +0 -0
- package/BookReader/images/slider.png +0 -0
- package/BookReader/images/slider_ia.png +0 -0
- package/BookReader/images/thumbnail_mode_icon.png +0 -0
- package/BookReader/images/transparent.png +0 -0
- package/BookReader/images/two_page_mode_icon.png +0 -0
- package/BookReader/images/unviewable_page.png +0 -0
- package/BookReader/images/zoom_in_icon.png +0 -0
- package/BookReader/images/zoom_out_icon.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 +2 -0
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -0
- package/BookReader/plugins/plugin.autoplay.js +2 -0
- package/BookReader/plugins/plugin.autoplay.js.map +1 -0
- package/BookReader/plugins/plugin.chapters.js +26 -0
- package/BookReader/plugins/plugin.chapters.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.chapters.js.map +1 -0
- 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 +2 -0
- package/BookReader/plugins/plugin.iframe.js.map +1 -0
- package/BookReader/plugins/plugin.iiif.js +2 -0
- package/BookReader/plugins/plugin.iiif.js.map +1 -0
- package/BookReader/plugins/plugin.resume.js +2 -0
- package/BookReader/plugins/plugin.resume.js.map +1 -0
- package/BookReader/plugins/plugin.search.js +3 -0
- package/BookReader/plugins/plugin.search.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.search.js.map +1 -0
- package/BookReader/plugins/plugin.text_selection.js +3 -0
- package/BookReader/plugins/plugin.text_selection.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.text_selection.js.map +1 -0
- package/BookReader/plugins/plugin.tts.js +3 -0
- package/BookReader/plugins/plugin.tts.js.LICENSE.txt +29 -0
- package/BookReader/plugins/plugin.tts.js.map +1 -0
- package/BookReader/plugins/plugin.url.js +2 -0
- package/BookReader/plugins/plugin.url.js.map +1 -0
- package/BookReader/plugins/plugin.vendor-fullscreen.js +2 -0
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -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/package.json +6 -1
- package/src/BookReader/BookModel.js +564 -0
- package/src/BookReader/DragScrollable.js +233 -0
- package/src/BookReader/ImageCache.js +149 -0
- package/src/BookReader/Mode1Up.js +110 -0
- package/src/BookReader/Mode1UpLit.js +388 -0
- package/src/BookReader/Mode2Up.js +107 -0
- package/src/BookReader/Mode2UpLit.js +777 -0
- package/src/BookReader/ModeCoordinateSpace.js +29 -0
- package/src/BookReader/ModeSmoothZoom.js +312 -0
- package/src/BookReader/ModeThumb.js +344 -0
- package/src/BookReader/Navbar/Navbar.js +355 -0
- package/src/BookReader/PageContainer.js +172 -0
- package/src/BookReader/ReduceSet.js +26 -0
- package/src/BookReader/Toolbar/Toolbar.js +362 -0
- package/src/BookReader/events.js +19 -0
- package/src/BookReader/options.js +387 -0
- package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
- package/src/BookReader/utils/ScrollClassAdder.js +31 -0
- package/src/BookReader/utils/SelectionObserver.js +45 -0
- package/src/BookReader/utils/classes.js +36 -0
- package/src/BookReader/utils.js +313 -0
- package/.eslintrc.cjs +0 -51
- 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 -102
- package/.github/workflows/npm-publish.yml +0 -23
- package/.testcaferc.cjs +0 -10
- package/BookReaderDemo/BookReaderDemo.css +0 -40
- package/BookReaderDemo/BookReaderJSAdvanced.js +0 -112
- package/BookReaderDemo/BookReaderJSSimple.js +0 -56
- package/BookReaderDemo/IADemoBr.js +0 -149
- 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/demo-advanced.html +0 -33
- package/BookReaderDemo/demo-embed-iframe-src.html +0 -85
- package/BookReaderDemo/demo-embed.html +0 -26
- package/BookReaderDemo/demo-fullscreen-mobile.html +0 -34
- package/BookReaderDemo/demo-fullscreen.html +0 -31
- package/BookReaderDemo/demo-iiif.html +0 -121
- package/BookReaderDemo/demo-internetarchive.html +0 -271
- package/BookReaderDemo/demo-multiple.html +0 -44
- package/BookReaderDemo/demo-preview-pages.html +0 -1093
- package/BookReaderDemo/demo-simple.html +0 -35
- package/BookReaderDemo/demo-vendor-fullscreen.html +0 -34
- package/BookReaderDemo/ia-multiple-volumes-manifest.js +0 -169
- package/BookReaderDemo/immersion-1up.html +0 -64
- package/BookReaderDemo/immersion-mode.html +0 -33
- package/BookReaderDemo/toggle_controls.html +0 -54
- package/BookReaderDemo/view_mode.html +0 -40
- package/BookReaderDemo/viewmode-cycle.html +0 -40
- package/CHANGELOG.md +0 -1087
- package/CONTRIBUTING.md +0 -7
- package/babel.config.cjs +0 -20
- package/codecov.yml +0 -23
- package/index.html +0 -34
- package/netlify.toml +0 -9
- package/renovate.json +0 -52
- package/screenshot.png +0 -0
- package/scripts/postversion.js +0 -11
- package/scripts/preversion.js +0 -15
- package/scripts/version.js +0 -24
- package/tests/e2e/README.md +0 -112
- package/tests/e2e/autoplay.test.js +0 -16
- package/tests/e2e/base.test.js +0 -27
- package/tests/e2e/helpers/base.js +0 -263
- package/tests/e2e/helpers/debug.js +0 -13
- package/tests/e2e/helpers/mockSearch.js +0 -90
- package/tests/e2e/helpers/params.js +0 -17
- package/tests/e2e/helpers/rightToLeft.js +0 -23
- package/tests/e2e/helpers/search.js +0 -73
- package/tests/e2e/models/BookReader.js +0 -11
- package/tests/e2e/models/Navigation.js +0 -39
- package/tests/e2e/rightToLeft.test.js +0 -19
- package/tests/e2e/viewmode.test.js +0 -44
- package/tests/jest/BookNavigator/book-navigator.test.js +0 -653
- package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +0 -43
- package/tests/jest/BookNavigator/bookmarks/bookmark-edit.test.js +0 -132
- package/tests/jest/BookNavigator/bookmarks/bookmarks-list.test.js +0 -221
- package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +0 -45
- package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +0 -67
- package/tests/jest/BookNavigator/downloads/downloads.test.js +0 -53
- package/tests/jest/BookNavigator/search/search-provider.test.js +0 -179
- package/tests/jest/BookNavigator/search/search-results.test.js +0 -289
- package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +0 -49
- package/tests/jest/BookNavigator/viewable-files/viewable-files-provider.test.js +0 -80
- package/tests/jest/BookNavigator/visual-adjustments.test.js +0 -200
- package/tests/jest/BookReader.keyboard.test.js +0 -190
- package/tests/jest/BookReader.options.test.js +0 -47
- package/tests/jest/BookReader.test.js +0 -316
- package/tests/jest/plugins/plugin.archive_analytics.test.js +0 -20
- package/tests/jest/plugins/plugin.autoplay.test.js +0 -35
- package/tests/jest/plugins/plugin.chapters.test.js +0 -193
- package/tests/jest/plugins/plugin.iframe.test.js +0 -42
- package/tests/jest/plugins/plugin.resume.test.js +0 -85
- package/tests/jest/plugins/plugin.text_selection.test.js +0 -447
- package/tests/jest/plugins/plugin.vendor-fullscreen.test.js +0 -65
- package/tests/jest/plugins/search/plugin.search.test.js +0 -120
- package/tests/jest/plugins/search/plugin.search.view.test.js +0 -131
- package/tests/jest/plugins/search/utils.js +0 -25
- package/tests/jest/plugins/search/utils.test.js +0 -29
- package/tests/jest/plugins/tts/AbstractTTSEngine.test.js +0 -173
- package/tests/jest/plugins/tts/FestivalTTSEngine.test.js +0 -59
- package/tests/jest/plugins/tts/PageChunk.test.js +0 -57
- package/tests/jest/plugins/tts/PageChunkIterator.test.js +0 -179
- package/tests/jest/plugins/tts/WebTTSEngine.test.js +0 -178
- package/tests/jest/plugins/tts/utils.test.js +0 -74
- package/tests/jest/plugins/url/UrlPlugin.test.js +0 -198
- package/tests/jest/plugins/url/plugin.url.test.js +0 -168
- package/tests/jest/setup.js +0 -3
- package/tests/jest/util/browserSniffing.test.js +0 -62
- package/tests/jest/util/docCookies.test.js +0 -24
- package/tests/jest/util/strings.test.js +0 -63
- package/tests/jest/utils.js +0 -83
- package/webpack.config.js +0 -97
@@ -1,447 +0,0 @@
|
|
1
|
-
import sinon from 'sinon';
|
2
|
-
|
3
|
-
import BookReader from '@/src/BookReader.js';
|
4
|
-
import {
|
5
|
-
Cache,
|
6
|
-
genAt,
|
7
|
-
genFilter,
|
8
|
-
genMap,
|
9
|
-
lookAroundWindow,
|
10
|
-
walkBetweenNodes,
|
11
|
-
zip,
|
12
|
-
} from '@/src/plugins/plugin.text_selection.js';
|
13
|
-
|
14
|
-
// djvu.xml book infos copied from https://ia803103.us.archive.org/14/items/goodytwoshoes00newyiala/goodytwoshoes00newyiala_djvu.xml
|
15
|
-
const FAKE_XML_1WORD = `
|
16
|
-
<OBJECT data="file://localhost//tmp/derive/goodytwoshoes00newyiala//goodytwoshoes00newyiala.djvu" height="3192" type="image/x.djvu" usemap="goodytwoshoes00newyiala_0001.djvu" width="2454">
|
17
|
-
<PARAGRAPH>
|
18
|
-
<LINE>
|
19
|
-
<WORD coords="1216,2768,1256,2640">test</WORD>
|
20
|
-
</LINE>
|
21
|
-
</PARAGRAPH>
|
22
|
-
</OBJECT>`;
|
23
|
-
const FAKE_XML_MULT_WORDS = `
|
24
|
-
<OBJECT data="file://localhost//tmp/derive/goodytwoshoes00newyiala//goodytwoshoes00newyiala.djvu" height="3192" type="image/x.djvu" usemap="goodytwoshoes00newyiala_0001.djvu" width="2454">
|
25
|
-
<PARAGRAPH>
|
26
|
-
<LINE>
|
27
|
-
<WORD coords="1216,2768,1256,2640">test1</WORD>
|
28
|
-
<WORD coords="1400,2768,1500,2640">test2</WORD>
|
29
|
-
<WORD coords="1600,2768,1700,2640">test3</WORD>
|
30
|
-
</LINE>
|
31
|
-
</PARAGRAPH>
|
32
|
-
</OBJECT>`;
|
33
|
-
const FAKE_XML_MULT_LINES = `
|
34
|
-
<OBJECT data="file://localhost//tmp/derive/goodytwoshoes00newyiala//goodytwoshoes00newyiala.djvu" height="3192" type="image/x.djvu" usemap="goodytwoshoes00newyiala_0001.djvu" width="2454">
|
35
|
-
<PARAGRAPH>
|
36
|
-
<LINE>
|
37
|
-
<WORD coords="119,2050,230,2014" x-confidence="29">way </WORD>
|
38
|
-
<WORD coords="230,2038,320,2002" x-confidence="30">can </WORD>
|
39
|
-
<WORD coords="320,2039,433,2002" x-confidence="28">false </WORD>
|
40
|
-
<WORD coords="433,2051,658,2003" x-confidence="29">judgment </WORD>
|
41
|
-
<WORD coords="658,2039,728,2002" x-confidence="30">be </WORD>
|
42
|
-
<WORD coords="658,2039,728,2002" x-confidence="30">-</WORD>
|
43
|
-
<WORD coords="728,2039,939,2001" x-confidence="29">formed. </WORD>
|
44
|
-
<WORD coords="939,2039,1087,2001" x-confidence="29">There </WORD>
|
45
|
-
<WORD coords="1087,2039,1187,2002" x-confidence="29">still </WORD>
|
46
|
-
<WORD coords="1187,2038,1370,2003" x-confidence="29">remains </WORD>
|
47
|
-
<WORD coords="1370,2037,1433,2014" x-confidence="28">an-</WORD>
|
48
|
-
</LINE>
|
49
|
-
<LINE>
|
50
|
-
<WORD coords="244,2099,370,2063" x-confidence="29">other mode </WORD>
|
51
|
-
<WORD coords="370,2100,427,2064" x-confidence="29">in </WORD>
|
52
|
-
<WORD coords="427,2100,566,2063" x-confidence="29">which </WORD>
|
53
|
-
<WORD coords="566,2100,670,2063" x-confidence="29">false </WORD>
|
54
|
-
<WORD coords="670,2112,907,2063" x-confidence="29">judgments </WORD>
|
55
|
-
<WORD coords="907,2112,1006,2064" x-confidence="29">may </WORD>
|
56
|
-
<WORD coords="1006,2100,1071,2063" x-confidence="29">be </WORD>
|
57
|
-
<WORD coords="1071,2100,1266,2062" x-confidence="29">formed. </WORD>
|
58
|
-
<WORD coords="1266,2110,1435,2062" x-confidence="29">Suppose</WORD>
|
59
|
-
</LINE>
|
60
|
-
<LINE>
|
61
|
-
<WORD coords="118,2160,217,2123" x-confidence="29">that </WORD>
|
62
|
-
<WORD coords="217,2160,289,2124" x-confidence="29">we </WORD>
|
63
|
-
<WORD coords="289,2160,400,2124" x-confidence="29">have </WORD>
|
64
|
-
<WORD coords="400,2160,456,2124" x-confidence="30">in </WORD>
|
65
|
-
<WORD coords="456,2161,542,2136" x-confidence="29">our </WORD>
|
66
|
-
<WORD coords="542,2161,660,2124" x-confidence="29">souls </WORD>
|
67
|
-
<WORD coords="660,2160,700,2136" x-confidence="29">a </WORD>
|
68
|
-
<WORD coords="700,2160,847,2129" x-confidence="28">waxen </WORD>
|
69
|
-
<WORD coords="847,2160,983,2123" x-confidence="29">tablet </WORD>
|
70
|
-
<WORD coords="983,2160,1045,2124" x-confidence="29">of </WORD>
|
71
|
-
<WORD coords="1045,2160,1211,2124" x-confidence="29">various </WORD>
|
72
|
-
<WORD coords="1211,2171,1398,2122" x-confidence="29">qualities </WORD>
|
73
|
-
<WORD coords="1398,2157,1434,2122" x-confidence="29">lastWord</WORD>
|
74
|
-
</LINE>
|
75
|
-
</PARAGRAPH>
|
76
|
-
</OBJECT>`;
|
77
|
-
const FAKE_XML_5COORDS = `
|
78
|
-
<OBJECT data="file://localhost//tmp/derive/goodytwoshoes00newyiala//goodytwoshoes00newyiala.djvu" height="3192" type="image/x.djvu" usemap="goodytwoshoes00newyiala_0001.djvu" width="2454">
|
79
|
-
<PARAGRAPH>
|
80
|
-
<LINE>
|
81
|
-
<WORD coords="1216,2768,1256,2640,2690">test</WORD>
|
82
|
-
</LINE>
|
83
|
-
</PARAGRAPH>
|
84
|
-
</OBJECT>`;
|
85
|
-
const FAKE_XML_EMPTY = '';
|
86
|
-
|
87
|
-
describe("Generic tests", () => {
|
88
|
-
document.body.innerHTML = '<div id="BookReader">';
|
89
|
-
const br = window.br = new BookReader({
|
90
|
-
data: [
|
91
|
-
[
|
92
|
-
{ width: 800, height: 1200,
|
93
|
-
uri: '//archive.org/download/BookReader/img/page001.jpg' },
|
94
|
-
],
|
95
|
-
[
|
96
|
-
{ width: 800, height: 1200,
|
97
|
-
uri: '//archive.org/download/BookReader/img/page002.jpg' },
|
98
|
-
{ width: 800, height: 1200,
|
99
|
-
uri: '//archive.org/download/BookReader/img/page003.jpg' },
|
100
|
-
],
|
101
|
-
[
|
102
|
-
{ width: 800, height: 1200,
|
103
|
-
uri: '//archive.org/download/BookReader/img/page004.jpg' },
|
104
|
-
{ width: 800, height: 1200,
|
105
|
-
uri: '//archive.org/download/BookReader/img/page005.jpg' },
|
106
|
-
],
|
107
|
-
],
|
108
|
-
});
|
109
|
-
br.init();
|
110
|
-
|
111
|
-
afterEach(() => {
|
112
|
-
sinon.restore();
|
113
|
-
$('.BRtextLayer').remove();
|
114
|
-
});
|
115
|
-
|
116
|
-
test("_limitSelection handles short selection", async () => {
|
117
|
-
const $container = br.refs.$brContainer;
|
118
|
-
br.options.plugins.textSelection.maxProtectedWords = 5;
|
119
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
120
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_MULT_LINES, "text/xml")));
|
121
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
|
122
|
-
|
123
|
-
const rangeBefore = document.createRange();
|
124
|
-
rangeBefore.setStart($container.find(".BRwordElement")[0].firstChild, 0);
|
125
|
-
rangeBefore.setEnd($container.find(".BRwordElement")[4].firstChild, 1);
|
126
|
-
const selection = window.getSelection();
|
127
|
-
selection.removeAllRanges();
|
128
|
-
selection.addRange(rangeBefore);
|
129
|
-
|
130
|
-
br.plugins.textSelection._limitSelection();
|
131
|
-
|
132
|
-
const rangeAfter = window.getSelection().getRangeAt(0);
|
133
|
-
expect(rangeAfter.startContainer).toBe(rangeBefore.startContainer);
|
134
|
-
expect(rangeAfter.startOffset).toBe(0);
|
135
|
-
expect(rangeAfter.endContainer).toBe(rangeBefore.endContainer);
|
136
|
-
expect(rangeAfter.endOffset).toBe(1);
|
137
|
-
|
138
|
-
window.getSelection().removeAllRanges();
|
139
|
-
});
|
140
|
-
|
141
|
-
test("_limitSelection shrinks selection", async () => {
|
142
|
-
const $container = br.refs.$brContainer;
|
143
|
-
br.options.plugins.textSelection.maxProtectedWords = 5;
|
144
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
145
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_MULT_LINES, "text/xml")));
|
146
|
-
|
147
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
|
148
|
-
|
149
|
-
const rangeBefore = document.createRange();
|
150
|
-
rangeBefore.setStart($container.find(".BRwordElement")[0].firstChild, 0);
|
151
|
-
rangeBefore.setEnd($container.find(".BRwordElement")[12].firstChild, 1);
|
152
|
-
const selection = window.getSelection();
|
153
|
-
selection.removeAllRanges();
|
154
|
-
selection.addRange(rangeBefore);
|
155
|
-
|
156
|
-
br.plugins.textSelection._limitSelection();
|
157
|
-
|
158
|
-
const rangeAfter = window.getSelection().getRangeAt(0);
|
159
|
-
expect(rangeAfter.startContainer).toBe(rangeBefore.startContainer);
|
160
|
-
expect(rangeAfter.endContainer).toBe($container.find(".BRwordElement")[4].firstChild);
|
161
|
-
});
|
162
|
-
|
163
|
-
test("_createPageContainer overridden function still creates a BRpagecontainer element", () => {
|
164
|
-
const spy = sinon.spy(br.plugins.textSelection, 'createTextLayer');
|
165
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
166
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
|
167
|
-
const container = br._createPageContainer(1, {});
|
168
|
-
expect(container).toBeTruthy();
|
169
|
-
expect(spy.callCount).toBe(1);
|
170
|
-
});
|
171
|
-
|
172
|
-
// test loading first object from sample data
|
173
|
-
test("_createPageContainer handles index 0", () => {
|
174
|
-
const spy = sinon.spy(br.plugins.textSelection, 'createTextLayer');
|
175
|
-
br._createPageContainer(0, {});
|
176
|
-
expect(spy.callCount).toBe(1);
|
177
|
-
});
|
178
|
-
|
179
|
-
// test loading last object from sample data
|
180
|
-
test("_createPageContainer handles index -1", () => {
|
181
|
-
const spy = sinon.spy(br.plugins.textSelection, 'createTextLayer');
|
182
|
-
br._createPageContainer(-1, {});
|
183
|
-
expect(spy.callCount).toBe(0);
|
184
|
-
});
|
185
|
-
|
186
|
-
test("createTextLayer will render the last page and create text layer properly", async () => {
|
187
|
-
const $container = br.refs.$brContainer;
|
188
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
189
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
|
190
|
-
const pageIndex = br.data.length - 1;
|
191
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: pageIndex, width: 100, height: 100 }});
|
192
|
-
expect($container.find(".BRtextLayer").length).toBe(1);
|
193
|
-
expect($container.find("p").length).toBe(1);
|
194
|
-
});
|
195
|
-
|
196
|
-
test("createTextLayer will not create text layer if there are too many words", async () => {
|
197
|
-
const $container = br.refs.$brContainer;
|
198
|
-
const xml = FAKE_XML_1WORD.replace(/<WORD.*<\/WORD>/, FAKE_XML_1WORD.match(/<WORD.*<\/WORD>/)[0].repeat(3000));
|
199
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
200
|
-
.returns($(new DOMParser().parseFromString(xml, "text/xml")));
|
201
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 0, width: 100, height: 100 }});
|
202
|
-
expect($container.find(".BRtextLayer").length).toBe(0);
|
203
|
-
expect($container.find("p").length).toBe(0);
|
204
|
-
expect($container.find(".BRwordElement").length).toBe(0);
|
205
|
-
});
|
206
|
-
|
207
|
-
test("createTextLayer creates text layer with paragraph with 1 word element", async () => {
|
208
|
-
const $container = br.refs.$brContainer;
|
209
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
210
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
|
211
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 1, width: 100, height: 100 }});
|
212
|
-
expect($container.find(".BRtextLayer").length).toBe(1);
|
213
|
-
expect($container.find("p").length).toBe(1);
|
214
|
-
expect($container.find(".BRwordElement").length).toBe(1);
|
215
|
-
expect($container.find(".BRwordElement").text()).toBe("test");
|
216
|
-
});
|
217
|
-
|
218
|
-
test("createTextLayer creates text layer with paragraph with multiple word elements", async () => {
|
219
|
-
const $container = br.refs.$brContainer;
|
220
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
221
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_MULT_WORDS, "text/xml")));
|
222
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 2, width: 100, height: 100 }});
|
223
|
-
expect($container.find(".BRtextLayer").length).toBe(1);
|
224
|
-
expect($container.find("p").length).toBe(1);
|
225
|
-
expect($container.find(".BRwordElement").length).toBe(3);
|
226
|
-
expect($container.find(".BRspace").length).toBe(2);
|
227
|
-
});
|
228
|
-
|
229
|
-
test("createTextLayer creates text layer with paragraph with word with 5 params coordinates", async () => {
|
230
|
-
const $container = br.refs.$brContainer;
|
231
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
232
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_5COORDS, "text/xml")));
|
233
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
|
234
|
-
expect($container.find(".BRtextLayer").length).toBe(1);
|
235
|
-
expect($container.find("p").length).toBe(1);
|
236
|
-
expect($container.find(".BRwordElement").length).toBe(1);
|
237
|
-
});
|
238
|
-
|
239
|
-
test("createTextLayer handles multiple lines", async () => {
|
240
|
-
const $container = br.refs.$brContainer;
|
241
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
242
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_MULT_LINES, "text/xml")));
|
243
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
|
244
|
-
expect($container.find(".BRtextLayer").length).toBe(1);
|
245
|
-
expect($container.find("p").length).toBe(1);
|
246
|
-
expect($container.find(".BRlineElement").length).toBe(3);
|
247
|
-
// Adds space at end of line; except last line/hyphens
|
248
|
-
expect($container.find("p").text()).toMatch(/another/);
|
249
|
-
expect($container.find("p").text()).toMatch(/Suppose /);
|
250
|
-
expect($container.find("p").text()).toMatch(/lastWord$/);
|
251
|
-
expect($container.find("p > br").length).toBe(1);
|
252
|
-
});
|
253
|
-
|
254
|
-
test("createTextLayer repairs trailing hyphens", async () => {
|
255
|
-
const $container = br.refs.$brContainer;
|
256
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
257
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_MULT_LINES, "text/xml")));
|
258
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
|
259
|
-
|
260
|
-
expect($container.find(".BRwordElement--hyphen").length).toBe(1);
|
261
|
-
expect($container.find(".BRwordElement--hyphen").closest(".BRlineElement").text().endsWith(' ')).toBe(false);
|
262
|
-
expect($container.find(".BRwordElement--hyphen").closest(".BRlineElement").text().endsWith('-')).toBe(false);
|
263
|
-
});
|
264
|
-
|
265
|
-
test("createTextLayer can handle empty xml", async () => {
|
266
|
-
const $container = br.refs.$brContainer;
|
267
|
-
sinon.stub(br.plugins.textSelection, "getPageText")
|
268
|
-
.returns($(new DOMParser().parseFromString(FAKE_XML_EMPTY, "text/xml")));
|
269
|
-
await br.plugins.textSelection.createTextLayer({ $container, page: { index: 4, width: 100, height: 100 }});
|
270
|
-
expect($container.find(".BRtextLayer").length).toBe(1);
|
271
|
-
expect($container.find("p").length).toBe(0);
|
272
|
-
expect($container.find(".BRwordElement").length).toBe(0);
|
273
|
-
});
|
274
|
-
|
275
|
-
const LONG_PRESS_DURATION = 500;
|
276
|
-
test("calling stopPageFlip does not allow long click to flip the page", () => {
|
277
|
-
const $container = br.refs.$brContainer;
|
278
|
-
br.plugins.textSelection.stopPageFlip($container);
|
279
|
-
const currIndex = br.currentIndex();
|
280
|
-
$container.find("BRwordElement").trigger("mousedown");
|
281
|
-
// Waits for long press
|
282
|
-
setTimeout(() => {
|
283
|
-
$container.find("BRwordElement").trigger("mousedown");
|
284
|
-
// Waits for flipping animation
|
285
|
-
setTimeout(() => {
|
286
|
-
expect(br.currentIndex()).toBe(currIndex);
|
287
|
-
}, 2000);
|
288
|
-
}, LONG_PRESS_DURATION);
|
289
|
-
});
|
290
|
-
});
|
291
|
-
|
292
|
-
describe("Cache", () => {
|
293
|
-
test('Adding works', () => {
|
294
|
-
const c = new Cache(10);
|
295
|
-
c.add(35);
|
296
|
-
expect(c.entries).toEqual([35]);
|
297
|
-
});
|
298
|
-
|
299
|
-
test('Size does not grow beyond limit', () => {
|
300
|
-
const c = new Cache(2);
|
301
|
-
c.add(35);
|
302
|
-
c.add(32);
|
303
|
-
c.add(12);
|
304
|
-
c.add(11);
|
305
|
-
c.add(112);
|
306
|
-
expect(c.entries).toHaveLength(2);
|
307
|
-
});
|
308
|
-
|
309
|
-
test('Oldest evicted first', () => {
|
310
|
-
const c = new Cache(2);
|
311
|
-
c.add(35);
|
312
|
-
c.add(32);
|
313
|
-
c.add(12);
|
314
|
-
c.add(12);
|
315
|
-
c.add(10);
|
316
|
-
expect(c.entries).toEqual([12, 10]);
|
317
|
-
});
|
318
|
-
});
|
319
|
-
|
320
|
-
describe('genAt', () => {
|
321
|
-
test('handles empty', () => {
|
322
|
-
expect(genAt(genRange(-1), 0)).toBeUndefined();
|
323
|
-
});
|
324
|
-
|
325
|
-
test('handles non-empty', () => {
|
326
|
-
expect(genAt(genRange(3), 0)).toBe(0);
|
327
|
-
expect(genAt(genRange(3), 1)).toBe(1);
|
328
|
-
expect(genAt(genRange(3), 2)).toBe(2);
|
329
|
-
});
|
330
|
-
|
331
|
-
test('handles out of bounds', () => {
|
332
|
-
expect(genAt(genRange(3), 4)).toBeUndefined();
|
333
|
-
expect(genAt(genRange(3), -1)).toBeUndefined();
|
334
|
-
});
|
335
|
-
});
|
336
|
-
|
337
|
-
describe('genFilter', () => {
|
338
|
-
test('handles empty', () => {
|
339
|
-
expect(Array.from(genFilter(genRange(0), x => x > 0))).toEqual([]);
|
340
|
-
});
|
341
|
-
|
342
|
-
test('handles non-empty', () => {
|
343
|
-
expect(Array.from(genFilter(genRange(3), x => x > 1))).toEqual([2, 3]);
|
344
|
-
expect(Array.from(genFilter(genRange(3), x => x < 1))).toEqual([0]);
|
345
|
-
});
|
346
|
-
|
347
|
-
test('handles all false', () => {
|
348
|
-
expect(Array.from(genFilter(genRange(3), x => x > 3))).toEqual([]);
|
349
|
-
});
|
350
|
-
});
|
351
|
-
|
352
|
-
describe('genMap', () => {
|
353
|
-
test('handles empty', () => {
|
354
|
-
expect(Array.from(genMap([], x => x ** 2))).toEqual([]);
|
355
|
-
});
|
356
|
-
|
357
|
-
test('handles non-empty', () => {
|
358
|
-
expect(Array.from(genMap([1,2,3], x => x ** 2))).toEqual([1,4,9]);
|
359
|
-
});
|
360
|
-
});
|
361
|
-
|
362
|
-
describe('lookAroundWindow', () => {
|
363
|
-
test('handles empty', () => {
|
364
|
-
expect(Array.from(lookAroundWindow([]))).toEqual([]);
|
365
|
-
});
|
366
|
-
|
367
|
-
test('handles smaller than window', () => {
|
368
|
-
expect(Array.from(lookAroundWindow([1]))).toEqual([[undefined, 1, undefined]]);
|
369
|
-
expect(Array.from(lookAroundWindow([1, 2]))).toEqual([[undefined, 1, 2], [1, 2, undefined]]);
|
370
|
-
expect(Array.from(lookAroundWindow([1, 2, 3]))).toEqual([[undefined, 1, 2], [1, 2, 3], [2, 3, undefined]]);
|
371
|
-
});
|
372
|
-
|
373
|
-
test('handles larger than window', () => {
|
374
|
-
expect(Array.from(lookAroundWindow([1, 2, 3, 4]))).toEqual([
|
375
|
-
[undefined, 1, 2],
|
376
|
-
[1, 2, 3],
|
377
|
-
[2, 3, 4],
|
378
|
-
[3, 4, undefined],
|
379
|
-
]);
|
380
|
-
});
|
381
|
-
});
|
382
|
-
|
383
|
-
describe('zip', () => {
|
384
|
-
test('handles empty', () => {
|
385
|
-
expect(Array.from(zip([], []))).toEqual([]);
|
386
|
-
});
|
387
|
-
|
388
|
-
test('uneven throws error', () => {
|
389
|
-
expect(() => Array.from(zip([1], [2, 3]))).toThrow();
|
390
|
-
});
|
391
|
-
|
392
|
-
test('handles even', () => {
|
393
|
-
expect(Array.from(zip([1, 2], [3, 4]))).toEqual([[1, 3], [2, 4]]);
|
394
|
-
});
|
395
|
-
});
|
396
|
-
|
397
|
-
describe('walkBetweenNodes', () => {
|
398
|
-
const tree = $(FAKE_XML_MULT_LINES);
|
399
|
-
|
400
|
-
test('handles empty', () => {
|
401
|
-
const result = Array.from(walkBetweenNodes(tree[0], tree[0]));
|
402
|
-
expect(result).toHaveLength(1);
|
403
|
-
expect(result[0]).toBe(tree[0]);
|
404
|
-
});
|
405
|
-
|
406
|
-
test('Words on same line', () => {
|
407
|
-
const start = tree.find('WORD')[2];
|
408
|
-
const end = start.nextElementSibling;
|
409
|
-
// Use first child so we hit the text nodes
|
410
|
-
const result = Array.from(walkBetweenNodes(start.firstChild, end.firstChild));
|
411
|
-
expect(result).toHaveLength(5);
|
412
|
-
expect(result[0].nodeType).toBe(Node.TEXT_NODE);
|
413
|
-
expect(result[0].textContent).toBe('false ');
|
414
|
-
expect(result[1]).toBe(start);
|
415
|
-
// Whitespace
|
416
|
-
expect(result[2].nodeType).toBe(Node.TEXT_NODE);
|
417
|
-
expect(result[2].textContent).toMatch(/^\s*$/);
|
418
|
-
expect(result[3]).toBe(end);
|
419
|
-
expect(result[4].nodeType).toBe(Node.TEXT_NODE);
|
420
|
-
expect(result[4].textContent).toBe('judgment ');
|
421
|
-
});
|
422
|
-
|
423
|
-
test('Words on different lines', () => {
|
424
|
-
const start = tree.find('WORD')[2];
|
425
|
-
const end = tree.find('WORD')[19];
|
426
|
-
const result = Array.from(walkBetweenNodes(start.firstChild, end.firstChild));
|
427
|
-
// Expect two LINES in result
|
428
|
-
expect(result.filter(x => x.nodeName == 'LINE')).toHaveLength(2);
|
429
|
-
// Expect 18 WORDs in result
|
430
|
-
expect(result.filter(x => x.nodeName == 'WORD')).toHaveLength(18);
|
431
|
-
// First word should be the start word
|
432
|
-
expect(result[0].parentElement).toBe(start);
|
433
|
-
expect(result[0].textContent).toBe('false ');
|
434
|
-
// Last word should be the end word
|
435
|
-
expect(result[result.length - 1].parentElement).toBe(end);
|
436
|
-
expect(result[result.length - 1].textContent).toBe('Suppose');
|
437
|
-
});
|
438
|
-
});
|
439
|
-
|
440
|
-
/**
|
441
|
-
* @param {number} n
|
442
|
-
*/
|
443
|
-
function* genRange(n) {
|
444
|
-
for (let i = 0; i <= n; i++) {
|
445
|
-
yield i;
|
446
|
-
}
|
447
|
-
}
|
@@ -1,65 +0,0 @@
|
|
1
|
-
|
2
|
-
import BookReader from '@/src/BookReader.js';
|
3
|
-
import * as util from '@/src/plugins/plugin.vendor-fullscreen.js';
|
4
|
-
|
5
|
-
let br;
|
6
|
-
beforeEach(() => {
|
7
|
-
document.body.innerHTML = '<div id="BookReader">';
|
8
|
-
br = new BookReader();
|
9
|
-
br.init();
|
10
|
-
});
|
11
|
-
|
12
|
-
afterEach(() => {
|
13
|
-
jest.clearAllMocks();
|
14
|
-
});
|
15
|
-
|
16
|
-
describe('Plugin: Vendor-fullscreen', () => {
|
17
|
-
test('has option flag', () => {
|
18
|
-
expect(BookReader.defaultOptions.enableVendorFullscreenPlugin).toEqual(true);
|
19
|
-
});
|
20
|
-
|
21
|
-
test('enterFullWindow will run when enter in Fullscreen mode', () => {
|
22
|
-
const enterFullWindow = br.enterFullWindow;
|
23
|
-
br.updateBrClasses = jest.fn();
|
24
|
-
br.resize = jest.fn();
|
25
|
-
br.init();
|
26
|
-
br.enterFullWindow();
|
27
|
-
|
28
|
-
expect(enterFullWindow).toBeTruthy();
|
29
|
-
|
30
|
-
// br.isVendorFullscreenActive set to `true` when enterFullWindow Called
|
31
|
-
expect(br.isVendorFullscreenActive).toEqual(true);
|
32
|
-
|
33
|
-
// br.updateBrClasses trigger when enterFullWindow called
|
34
|
-
expect(br.updateBrClasses).toHaveBeenCalledTimes(2);
|
35
|
-
|
36
|
-
// br.resize trigger when enterFullWindow called
|
37
|
-
expect(br.resize).toHaveBeenCalledTimes(1);
|
38
|
-
});
|
39
|
-
|
40
|
-
test('exitFullWindow will run when exit Fullscreen mode', () => {
|
41
|
-
const exitFullWindow = br.exitFullWindow;
|
42
|
-
br.updateBrClasses = jest.fn();
|
43
|
-
br.init();
|
44
|
-
br.exitFullWindow();
|
45
|
-
|
46
|
-
expect(exitFullWindow).toBeTruthy();
|
47
|
-
|
48
|
-
// br.isFullscreenActive set to `false` when exitFullWindow Called
|
49
|
-
expect(br.isFullscreenActive).toEqual(false);
|
50
|
-
|
51
|
-
// br.updateBrClasses trigger when exitFullWindow called
|
52
|
-
expect(br.updateBrClasses).toHaveBeenCalledTimes(2);
|
53
|
-
});
|
54
|
-
|
55
|
-
test('isFullscreen returns true when fullscreen activated', () => {
|
56
|
-
br.init();
|
57
|
-
br.isVendorFullscreenActive = true;
|
58
|
-
expect(br.isFullscreen).toBeTruthy();
|
59
|
-
});
|
60
|
-
|
61
|
-
test('util: isFullscreenActive', () => {
|
62
|
-
document.fullscreenElement = true;
|
63
|
-
expect(util.isFullscreenActive).toBeTruthy();
|
64
|
-
});
|
65
|
-
});
|
@@ -1,120 +0,0 @@
|
|
1
|
-
import BookReader from '@/src/BookReader.js';
|
2
|
-
import '@/src/plugins/search/plugin.search.js';
|
3
|
-
import { deepCopy } from '../../utils.js';
|
4
|
-
import { DUMMY_RESULTS } from './utils.js';
|
5
|
-
|
6
|
-
jest.mock('@/src/plugins/search/view.js');
|
7
|
-
|
8
|
-
/** @type {BookReader} */
|
9
|
-
let br;
|
10
|
-
const namespace = 'BookReader:';
|
11
|
-
const triggeredEvents = () => {
|
12
|
-
return $.fn.trigger.mock.calls.map((params) => {
|
13
|
-
if (typeof params[0] === 'string') { return params[0]; }
|
14
|
-
return params[0].type;
|
15
|
-
});
|
16
|
-
};
|
17
|
-
|
18
|
-
beforeEach(() => {
|
19
|
-
$.ajax = jest.fn().mockImplementation(() => {
|
20
|
-
// return from:
|
21
|
-
// `https://ia800304.us.archive.org/fulltext/inside.php?item_id=adventuresofoli00dick&doc=adventuresofoli00dick&path=/30/items/adventuresofoli00dick&q=child&callback=<serialized jQ CB>`
|
22
|
-
return Promise.resolve(deepCopy(DUMMY_RESULTS));
|
23
|
-
});
|
24
|
-
|
25
|
-
$.fn.trigger = jest.fn();
|
26
|
-
document.body.innerHTML = '<div id="BookReader">';
|
27
|
-
br = new BookReader({
|
28
|
-
server: 'foo.bar.com',
|
29
|
-
bookPath: '/13/items/foo/foobar',
|
30
|
-
subPrefix: '/foobar',
|
31
|
-
});
|
32
|
-
br.initToolbar = jest.fn();
|
33
|
-
br.showProgressPopup = jest.fn();
|
34
|
-
br.plugins.search.searchXHR = jest.fn();
|
35
|
-
});
|
36
|
-
|
37
|
-
afterEach(() => {
|
38
|
-
jest.clearAllMocks();
|
39
|
-
});
|
40
|
-
|
41
|
-
describe('Plugin: Search', () => {
|
42
|
-
test('On init, it loads the toolbar', () => {
|
43
|
-
br.init();
|
44
|
-
expect(br.initToolbar).toHaveBeenCalled();
|
45
|
-
});
|
46
|
-
|
47
|
-
test('Constructs SearchView', () => {
|
48
|
-
expect(br.plugins.search.searchView).toBeDefined();
|
49
|
-
});
|
50
|
-
|
51
|
-
test('On init, it will run a search if given `options.initialSearchTerm`', () => {
|
52
|
-
br.plugins.search.search = jest.fn();
|
53
|
-
br.options.plugins.search.initialSearchTerm = 'foo';
|
54
|
-
br.init();
|
55
|
-
|
56
|
-
expect(br.plugins.search.search).toHaveBeenCalled();
|
57
|
-
expect(br.plugins.search.search.mock.calls[0][1])
|
58
|
-
.toHaveProperty('goToFirstResult', true);
|
59
|
-
expect(br.plugins.search.search.mock.calls[0][1])
|
60
|
-
.toHaveProperty('suppressFragmentChange', false);
|
61
|
-
});
|
62
|
-
|
63
|
-
test('calling `search` fires ajax call`', () => {
|
64
|
-
br.init();
|
65
|
-
br.search('foo');
|
66
|
-
expect($.ajax).toHaveBeenCalled();
|
67
|
-
});
|
68
|
-
|
69
|
-
test('SearchStarted event fires when search method called', () => {
|
70
|
-
br.init();
|
71
|
-
br.search('foo');
|
72
|
-
expect(triggeredEvents()).toContain(`${namespace}SearchStarted`);
|
73
|
-
});
|
74
|
-
|
75
|
-
test('SearchStarted event fires and should go to first result', () => {
|
76
|
-
br.init();
|
77
|
-
br.search('foo', { goToFirstResult: true});
|
78
|
-
expect(br.plugins.search.options.goToFirstResult).toBeTruthy();
|
79
|
-
});
|
80
|
-
|
81
|
-
test('SearchCallback event fires when AJAX search returns results', async () => {
|
82
|
-
br.init();
|
83
|
-
await br.search('foo');
|
84
|
-
expect(triggeredEvents()).toContain(`${namespace}SearchCallback`);
|
85
|
-
});
|
86
|
-
|
87
|
-
test('SearchCallbackError event fires when AJAX search returns error', async () => {
|
88
|
-
$.ajax = jest.fn().mockImplementation(() => {
|
89
|
-
return Promise.resolve({
|
90
|
-
error: true,
|
91
|
-
});
|
92
|
-
});
|
93
|
-
br.init();
|
94
|
-
await br.search('foo');
|
95
|
-
expect(triggeredEvents()).toContain(`${namespace}SearchCallbackError`);
|
96
|
-
});
|
97
|
-
|
98
|
-
test('SearchCallbackNotIndexed event fires when AJAX search returns false indexed value', async () => {
|
99
|
-
$.ajax = jest.fn().mockImplementation(() => {
|
100
|
-
return Promise.resolve({
|
101
|
-
matches: [],
|
102
|
-
indexed: false,
|
103
|
-
});
|
104
|
-
});
|
105
|
-
br.init();
|
106
|
-
await br.search('foo');
|
107
|
-
expect(triggeredEvents()).toContain(`${namespace}SearchCallbackBookNotIndexed`);
|
108
|
-
});
|
109
|
-
|
110
|
-
test('SearchCallbackEmpty event fires when AJAX search returns no matches', async () => {
|
111
|
-
$.ajax = jest.fn().mockImplementation(() => {
|
112
|
-
return Promise.resolve({
|
113
|
-
matches: [],
|
114
|
-
});
|
115
|
-
});
|
116
|
-
br.init();
|
117
|
-
await br.search('foo');
|
118
|
-
expect(triggeredEvents()).toContain(`${namespace}SearchCallbackEmpty`);
|
119
|
-
});
|
120
|
-
});
|