@internetarchive/bookreader 5.0.0-6-14 → 5.0.0-60
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.js +17 -15
- package/.github/workflows/node.js.yml +72 -10
- package/.github/workflows/npm-publish.yml +6 -20
- package/.testcaferc.js +10 -0
- package/BookReader/BookReader.css +241 -140
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.LICENSE.txt +24 -20
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +1519 -0
- package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +17 -0
- package/BookReader/ia-bookreader-bundle.js.map +1 -0
- package/BookReader/icons/close-circle-dark.svg +1 -0
- package/BookReader/icons/magnify-minus.svg +1 -1
- package/BookReader/icons/magnify-plus.svg +1 -1
- package/BookReader/icons/pause.svg +1 -1
- package/BookReader/icons/playback-speed.svg +1 -1
- package/BookReader/icons/read-aloud.svg +1 -1
- package/BookReader/icons/voice.svg +1 -0
- package/BookReader/images/BRicons.svg +2 -2
- package/BookReader/images/books_graphic.svg +1 -1
- package/BookReader/images/icon_book.svg +1 -1
- package/BookReader/images/icon_gear.svg +1 -1
- package/BookReader/images/icon_info.svg +1 -1
- package/BookReader/images/icon_playback-rate.svg +1 -1
- package/BookReader/images/icon_search_button.svg +1 -1
- package/BookReader/images/icon_share.svg +1 -1
- package/BookReader/images/icon_speaker.svg +1 -1
- package/BookReader/images/icon_speaker_open.svg +1 -1
- package/BookReader/images/marker_chap-off.svg +1 -1
- package/BookReader/images/marker_chap-on.svg +1 -1
- package/BookReader/images/marker_srch-on.svg +1 -1
- package/BookReader/jquery-3.js +2 -0
- package/BookReader/jquery-3.js.LICENSE.txt +24 -0
- package/BookReader/plugins/plugin.archive_analytics.js +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js +1 -1
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +1 -1
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.iframe.js +1 -1
- package/BookReader/plugins/plugin.iframe.js.map +1 -1
- package/BookReader/plugins/plugin.mobile_nav.js +1 -1
- package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js +1 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +1 -1
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +1 -1
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
- 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/BookReaderDemo/BookReaderDemo.css +14 -1
- package/BookReaderDemo/BookReaderJSAutoplay.js +4 -1
- package/BookReaderDemo/BookReaderJSSimple.js +1 -0
- package/BookReaderDemo/IADemoBr.js +147 -0
- package/BookReaderDemo/demo-advanced.html +2 -2
- package/BookReaderDemo/demo-autoplay.html +2 -1
- package/BookReaderDemo/demo-embed-iframe-src.html +2 -1
- package/BookReaderDemo/demo-fullscreen-mobile.html +2 -1
- package/BookReaderDemo/demo-fullscreen.html +2 -1
- package/BookReaderDemo/demo-iiif.html +2 -1
- package/BookReaderDemo/demo-internetarchive.html +84 -17
- package/BookReaderDemo/demo-multiple.html +2 -1
- package/BookReaderDemo/demo-preview-pages.html +2 -1
- package/BookReaderDemo/demo-simple.html +2 -1
- package/BookReaderDemo/demo-vendor-fullscreen.html +2 -1
- package/BookReaderDemo/ia-multiple-volumes-manifest.js +170 -0
- package/BookReaderDemo/immersion-1up.html +2 -1
- package/BookReaderDemo/immersion-mode.html +2 -1
- package/BookReaderDemo/toggle_controls.html +2 -1
- package/BookReaderDemo/view_mode.html +2 -1
- package/BookReaderDemo/viewmode-cycle.html +2 -3
- package/CHANGELOG.md +244 -0
- package/README.md +14 -1
- package/babel.config.js +19 -0
- package/codecov.yml +6 -0
- package/index.html +3 -0
- package/jsconfig.json +19 -0
- package/netlify.toml +5 -0
- package/package.json +70 -59
- package/renovate.json +52 -0
- package/scripts/preversion.js +4 -1
- package/src/BookNavigator/assets/bookmark-colors.js +1 -1
- package/src/BookNavigator/assets/button-base.js +9 -2
- package/src/BookNavigator/assets/ia-logo.js +17 -0
- package/src/BookNavigator/assets/icon_checkmark.js +1 -1
- package/src/BookNavigator/assets/icon_close.js +1 -1
- package/src/BookNavigator/assets/icon_sort_asc.js +5 -0
- package/src/BookNavigator/assets/icon_sort_desc.js +5 -0
- package/src/BookNavigator/assets/icon_sort_neutral.js +5 -0
- package/src/BookNavigator/assets/icon_volumes.js +11 -0
- package/src/BookNavigator/book-navigator.js +585 -0
- package/src/BookNavigator/bookmarks/bookmark-button.js +3 -2
- package/src/BookNavigator/bookmarks/bookmark-edit.js +3 -4
- package/src/BookNavigator/bookmarks/bookmarks-list.js +2 -3
- package/src/BookNavigator/bookmarks/bookmarks-loginCTA.js +3 -8
- package/src/BookNavigator/bookmarks/bookmarks-provider.js +27 -17
- package/src/BookNavigator/bookmarks/ia-bookmarks.js +116 -67
- package/src/BookNavigator/delete-modal-actions.js +1 -1
- package/src/BookNavigator/downloads/downloads-provider.js +36 -21
- package/src/BookNavigator/downloads/downloads.js +41 -25
- package/src/BookNavigator/search/search-provider.js +80 -28
- package/src/BookNavigator/search/search-results.js +34 -25
- package/src/BookNavigator/sharing.js +27 -0
- package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +11 -10
- package/src/BookNavigator/visual-adjustments/visual-adjustments.js +3 -3
- package/src/BookNavigator/volumes/volumes-provider.js +111 -0
- package/src/BookNavigator/volumes/volumes.js +188 -0
- package/src/BookReader/BookModel.js +59 -30
- package/src/BookReader/DebugConsole.js +3 -3
- package/src/BookReader/DragScrollable.js +233 -0
- package/src/BookReader/Mode1Up.js +56 -351
- package/src/BookReader/Mode1UpLit.js +391 -0
- package/src/BookReader/Mode2Up.js +73 -1318
- package/src/BookReader/Mode2UpLit.js +781 -0
- package/src/BookReader/ModeCoordinateSpace.js +29 -0
- package/src/BookReader/ModeSmoothZoom.js +211 -0
- package/src/BookReader/ModeThumb.js +17 -11
- package/src/BookReader/Navbar/Navbar.js +10 -36
- package/src/BookReader/PageContainer.js +69 -6
- package/src/BookReader/ReduceSet.js +1 -1
- package/src/BookReader/Toolbar/Toolbar.js +10 -37
- package/src/BookReader/events.js +2 -0
- package/src/BookReader/options.js +24 -2
- package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
- package/src/BookReader/utils/ScrollClassAdder.js +31 -0
- package/src/BookReader/utils.js +108 -13
- package/src/BookReader.js +481 -828
- package/src/assets/icons/close-circle-dark.svg +1 -0
- package/src/assets/icons/magnify-minus.svg +3 -7
- package/src/assets/icons/magnify-plus.svg +3 -7
- package/src/assets/icons/voice.svg +1 -0
- package/src/css/_BRBookmarks.scss +1 -1
- package/src/css/_BRComponent.scss +1 -1
- package/src/css/_BRmain.scss +33 -0
- package/src/css/_BRnav.scss +4 -26
- package/src/css/_BRpages.scss +147 -40
- package/src/css/_BRsearch.scss +25 -11
- package/src/css/_TextSelection.scss +16 -17
- package/src/css/_colorbox.scss +2 -2
- package/src/css/_controls.scss +17 -5
- package/src/css/_icons.scss +7 -1
- package/src/ia-bookreader/ia-bookreader.js +224 -0
- package/src/plugins/plugin.archive_analytics.js +3 -3
- package/src/plugins/plugin.autoplay.js +4 -9
- package/src/plugins/plugin.chapters.js +28 -35
- package/src/plugins/plugin.mobile_nav.js +11 -10
- package/src/plugins/plugin.resume.js +3 -3
- package/src/plugins/plugin.text_selection.js +32 -41
- package/src/plugins/plugin.vendor-fullscreen.js +4 -4
- package/src/plugins/search/plugin.search.js +179 -103
- package/src/plugins/search/view.js +59 -44
- package/src/plugins/tts/AbstractTTSEngine.js +46 -37
- package/src/plugins/tts/FestivalTTSEngine.js +13 -14
- package/src/plugins/tts/PageChunk.js +15 -21
- package/src/plugins/tts/PageChunkIterator.js +8 -12
- package/src/plugins/tts/WebTTSEngine.js +87 -71
- package/src/plugins/tts/plugin.tts.js +94 -125
- package/src/plugins/tts/utils.js +0 -25
- package/src/plugins/url/UrlPlugin.js +193 -0
- package/src/plugins/{plugin.url.js → url/plugin.url.js} +45 -16
- package/src/util/docCookies.js +21 -2
- package/tests/e2e/README.md +37 -0
- package/tests/e2e/autoplay.test.js +2 -2
- package/tests/e2e/base.test.js +7 -7
- package/tests/e2e/helpers/base.js +28 -23
- package/tests/e2e/helpers/debug.js +1 -1
- package/tests/e2e/helpers/desktopSearch.js +14 -13
- package/tests/e2e/helpers/mobileSearch.js +3 -3
- package/tests/e2e/helpers/params.js +17 -0
- package/tests/e2e/helpers/rightToLeft.js +4 -10
- package/tests/e2e/models/Navigation.js +13 -4
- package/tests/e2e/rightToLeft.test.js +4 -5
- package/tests/e2e/viewmode.test.js +40 -33
- package/tests/jest/BookNavigator/book-navigator.test.js +658 -0
- package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +43 -0
- package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-edit.test.js +25 -26
- package/tests/{karma → jest}/BookNavigator/bookmarks/bookmarks-list.test.js +41 -42
- package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +45 -0
- package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +67 -0
- package/tests/jest/BookNavigator/downloads/downloads.test.js +53 -0
- package/tests/jest/BookNavigator/search/search-provider.test.js +167 -0
- package/tests/{karma/BookNavigator → jest/BookNavigator/search}/search-results.test.js +104 -60
- package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +49 -0
- package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
- package/tests/jest/BookNavigator/volumes/volumes-provider.test.js +184 -0
- package/tests/jest/BookNavigator/volumes/volumes.test.js +97 -0
- package/tests/{BookReader → jest/BookReader}/BookModel.test.js +59 -14
- package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +193 -0
- package/tests/{BookReader → jest/BookReader}/DebugConsole.test.js +1 -1
- package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +4 -4
- package/tests/jest/BookReader/Mode1UpLit.test.js +73 -0
- package/tests/jest/BookReader/Mode2Up.test.js +98 -0
- package/tests/jest/BookReader/Mode2UpLit.test.js +190 -0
- package/tests/jest/BookReader/ModeCoordinateSpace.test.js +16 -0
- package/tests/jest/BookReader/ModeSmoothZoom.test.js +175 -0
- package/tests/jest/BookReader/ModeThumb.test.js +71 -0
- package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +10 -10
- package/tests/{BookReader → jest/BookReader}/PageContainer.test.js +88 -6
- package/tests/{BookReader → jest/BookReader}/ReduceSet.test.js +1 -1
- package/tests/{BookReader → jest/BookReader}/Toolbar/Toolbar.test.js +2 -2
- package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +59 -0
- package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
- package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +1 -1
- package/tests/jest/BookReader/utils.test.js +217 -0
- package/tests/jest/BookReader.keyboard.test.js +190 -0
- package/tests/{BookReader.options.test.js → jest/BookReader.options.test.js} +9 -1
- package/tests/{BookReader.test.js → jest/BookReader.test.js} +26 -37
- package/tests/{plugins → jest/plugins}/plugin.archive_analytics.test.js +2 -2
- package/tests/{plugins → jest/plugins}/plugin.autoplay.test.js +4 -4
- package/tests/{plugins → jest/plugins}/plugin.chapters.test.js +10 -11
- package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +2 -2
- package/tests/{plugins → jest/plugins}/plugin.mobile_nav.test.js +5 -5
- package/tests/{plugins → jest/plugins}/plugin.resume.test.js +3 -3
- package/tests/{plugins → jest/plugins}/plugin.text_selection.test.js +39 -47
- package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +2 -2
- package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +57 -47
- package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +35 -6
- package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +9 -9
- package/tests/{plugins → jest/plugins}/tts/FestivalTTSEngine.test.js +4 -4
- package/tests/{plugins → jest/plugins}/tts/PageChunk.test.js +1 -1
- package/tests/{plugins → jest/plugins}/tts/PageChunkIterator.test.js +3 -3
- package/tests/{plugins → jest/plugins}/tts/WebTTSEngine.test.js +47 -1
- package/tests/{plugins → jest/plugins}/tts/utils.test.js +1 -60
- package/tests/jest/plugins/url/UrlPlugin.test.js +190 -0
- package/tests/{plugins → jest/plugins/url}/plugin.url.test.js +53 -14
- package/tests/jest/setup.js +3 -0
- package/tests/{util → jest/util}/browserSniffing.test.js +1 -1
- package/tests/jest/util/docCookies.test.js +24 -0
- package/tests/{util → jest/util}/strings.test.js +1 -1
- package/tests/{utils.js → jest/utils.js} +38 -0
- package/webpack.config.js +11 -5
- package/.babelrc +0 -12
- package/.dependabot/config.yml +0 -6
- package/.testcaferc.json +0 -5
- package/BookReader/bookreader-component-bundle.js +0 -1450
- 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 -2
- package/BookReader/jquery-1.10.1.js.LICENSE.txt +0 -24
- package/BookReader/plugins/plugin.menu_toggle.js +0 -2
- package/BookReader/plugins/plugin.menu_toggle.js.map +0 -1
- package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
- package/BookReaderDemo/demo-plugin-menu-toggle.html +0 -34
- package/karma.conf.js +0 -23
- package/src/BookNavigator/BookModel.js +0 -14
- package/src/BookNavigator/BookNavigator.js +0 -438
- package/src/BookNavigator/assets/book-loader.js +0 -27
- package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
- package/src/BookNavigator/search/a-search-result.js +0 -55
- package/src/BookReaderComponent/BookReaderComponent.js +0 -112
- package/src/ItemNavigator/ItemNavigator.js +0 -372
- package/src/ItemNavigator/providers/sharing.js +0 -29
- package/src/dragscrollable-br.js +0 -261
- package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
- package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
- package/tests/BookReader/Mode1Up.test.js +0 -164
- package/tests/BookReader/Mode2Up.test.js +0 -247
- package/tests/BookReader/utils.test.js +0 -109
- package/tests/e2e/ia-production/ia-prod-base.js +0 -17
- package/tests/karma/BookNavigator/book-navigator.test.js +0 -132
- package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
- package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
- package/tests/util/docCookies.test.js +0 -15
@@ -0,0 +1,193 @@
|
|
1
|
+
import BookReader from '@/src/BookReader';
|
2
|
+
import { sleep } from '@/src/BookReader/utils.js';
|
3
|
+
import sinon from 'sinon';
|
4
|
+
|
5
|
+
beforeAll(() => {
|
6
|
+
global.alert = sinon.fake();
|
7
|
+
});
|
8
|
+
afterEach(() => {
|
9
|
+
sinon.restore();
|
10
|
+
});
|
11
|
+
|
12
|
+
describe('BookReader.prototype.toggleFullscreen', () => {
|
13
|
+
test('uses `isFullscreen` to check fullscreen state', () => {
|
14
|
+
const isFSmock = sinon.fake();
|
15
|
+
// isFSmock.mockReturnValueOnce(false);
|
16
|
+
const br = new BookReader();
|
17
|
+
br.mode = br.constMode1up;
|
18
|
+
br.enterFullscreen = sinon.fake();
|
19
|
+
br.isFullscreen = isFSmock;
|
20
|
+
|
21
|
+
br.toggleFullscreen();
|
22
|
+
expect(br.isFullscreen.callCount).toEqual(1);
|
23
|
+
});
|
24
|
+
|
25
|
+
test('will always emit an event', async () => {
|
26
|
+
const br = new BookReader();
|
27
|
+
br.mode = br.constMode2up;
|
28
|
+
br.trigger = sinon.fake();
|
29
|
+
br.switchMode = sinon.fake();
|
30
|
+
br.updateBrClasses = sinon.fake();
|
31
|
+
br.jumpToIndex = sinon.fake();
|
32
|
+
br.refs.$brContainer = {
|
33
|
+
css: sinon.fake(),
|
34
|
+
animate: (options, speed, style, callback) => callback()
|
35
|
+
};
|
36
|
+
br.refs.$br = {
|
37
|
+
updateBrClasses: sinon.fake(),
|
38
|
+
removeClass: sinon.fake(),
|
39
|
+
addClass: sinon.fake(),
|
40
|
+
css: sinon.fake(),
|
41
|
+
animate: (options, speed, style, callback) => callback()
|
42
|
+
};
|
43
|
+
|
44
|
+
await br.toggleFullscreen();
|
45
|
+
expect(br.trigger.callCount).toBeGreaterThan(0);
|
46
|
+
});
|
47
|
+
|
48
|
+
test('will start with opening fullscreen', () => {
|
49
|
+
const br = new BookReader();
|
50
|
+
br.mode = br.constMode2up;
|
51
|
+
br.enterFullscreen = sinon.fake();
|
52
|
+
|
53
|
+
br.toggleFullscreen();
|
54
|
+
expect(br.enterFullscreen.callCount).toEqual(1);
|
55
|
+
});
|
56
|
+
|
57
|
+
test('will close fullscreen if BookReader is in fullscreen', () => {
|
58
|
+
const br = new BookReader();
|
59
|
+
br.mode = br.constMode1up;
|
60
|
+
br.exitFullScreen = sinon.fake();
|
61
|
+
br.isFullscreenActive = true;
|
62
|
+
|
63
|
+
br.toggleFullscreen();
|
64
|
+
expect(br.exitFullScreen.callCount).toEqual(1);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
describe('BookReader.prototype.enterFullscreen', () => {
|
69
|
+
test('will bind `_fullscreenCloseHandler` by default', () => {
|
70
|
+
const br = new BookReader();
|
71
|
+
br.mode = br.constMode1up;
|
72
|
+
br.switchMode = sinon.fake();
|
73
|
+
br.updateBrClasses = sinon.fake();
|
74
|
+
br.refs.$br = {
|
75
|
+
css: sinon.fake(),
|
76
|
+
animate: sinon.fake(),
|
77
|
+
addClass: sinon.fake(),
|
78
|
+
};
|
79
|
+
expect(br._fullscreenCloseHandler).toBeUndefined();
|
80
|
+
|
81
|
+
br.enterFullscreen();
|
82
|
+
expect(br._fullscreenCloseHandler).toBeDefined();
|
83
|
+
});
|
84
|
+
|
85
|
+
test('fires certain events when called', async () => {
|
86
|
+
const br = new BookReader();
|
87
|
+
br.mode = br.constMode2up;
|
88
|
+
br.switchMode = sinon.fake();
|
89
|
+
br.updateBrClasses = sinon.fake();
|
90
|
+
br.trigger = sinon.fake();
|
91
|
+
br.resize = sinon.fake();
|
92
|
+
br.jumpToIndex = sinon.fake();
|
93
|
+
br.refs.$br = {
|
94
|
+
addClass: sinon.fake(),
|
95
|
+
removeClass: sinon.fake(),
|
96
|
+
};
|
97
|
+
br.refs.$brContainer = {
|
98
|
+
css: sinon.fake(),
|
99
|
+
animate: (options, speed, style, callback) => callback(),
|
100
|
+
};
|
101
|
+
|
102
|
+
await br.enterFullscreen();
|
103
|
+
expect(br.switchMode.callCount).toEqual(1);
|
104
|
+
expect(br.updateBrClasses.callCount).toEqual(1);
|
105
|
+
expect(br.trigger.callCount).toEqual(2); // fragmentChange, fullscreenToggled
|
106
|
+
expect(br.jumpToIndex.callCount).toEqual(1);
|
107
|
+
|
108
|
+
await sleep(0);
|
109
|
+
expect(br.resize.callCount).toEqual(1);
|
110
|
+
});
|
111
|
+
});
|
112
|
+
|
113
|
+
describe('BookReader.prototype.exitFullScreen', () => {
|
114
|
+
test('fires certain events when called', async () => {
|
115
|
+
const br = new BookReader();
|
116
|
+
br.mode = br.constMode2up;
|
117
|
+
br.switchMode = sinon.fake();
|
118
|
+
br.updateBrClasses = sinon.fake();
|
119
|
+
br.trigger = sinon.fake();
|
120
|
+
br.resize = sinon.fake();
|
121
|
+
br.refs.$br = {
|
122
|
+
addClass: sinon.fake(),
|
123
|
+
removeClass: sinon.fake(),
|
124
|
+
};
|
125
|
+
br.refs.$brContainer = {
|
126
|
+
css: sinon.fake(),
|
127
|
+
animate: (options, speed, style, callback) => callback()
|
128
|
+
};
|
129
|
+
await br.exitFullScreen();
|
130
|
+
expect(br.switchMode.callCount).toEqual(1);
|
131
|
+
expect(br.updateBrClasses.callCount).toEqual(1);
|
132
|
+
expect(br.trigger.callCount).toEqual(2); // fragmentChange, fullscreenToggled
|
133
|
+
expect(br.resize.callCount).toEqual(1);
|
134
|
+
});
|
135
|
+
});
|
136
|
+
|
137
|
+
describe('BookReader.prototype.trigger', () => {
|
138
|
+
test('fires custom event', () => {
|
139
|
+
const br = new BookReader();
|
140
|
+
global.br = br;
|
141
|
+
global.dispatchEvent = sinon.fake();
|
142
|
+
|
143
|
+
const props = {bar: 1};
|
144
|
+
br.trigger('foo', props);
|
145
|
+
expect(global.dispatchEvent.callCount).toBe(1);
|
146
|
+
});
|
147
|
+
});
|
148
|
+
|
149
|
+
describe('`BookReader.prototype.prev`', () => {
|
150
|
+
let br;
|
151
|
+
let flipAnimationStub;
|
152
|
+
beforeEach(() => {
|
153
|
+
br = new BookReader();
|
154
|
+
global.br = br;
|
155
|
+
br.trigger = sinon.fake();
|
156
|
+
br.jumpToIndex = sinon.fake();
|
157
|
+
flipAnimationStub = sinon.stub(br._modes.mode2Up.mode2UpLit, 'flipAnimation');
|
158
|
+
});
|
159
|
+
|
160
|
+
afterEach(() => {
|
161
|
+
sinon.restore();
|
162
|
+
});
|
163
|
+
|
164
|
+
test('does not take action if user is on front page', () => {
|
165
|
+
br.firstIndex = 0;
|
166
|
+
br.prev();
|
167
|
+
expect(br.trigger.callCount).toBe(0);
|
168
|
+
expect(flipAnimationStub.callCount).toBe(0);
|
169
|
+
expect(br.jumpToIndex.callCount).toBe(0);
|
170
|
+
});
|
171
|
+
|
172
|
+
describe('2up mode', () => {
|
173
|
+
test('fires event and turns the page', () => {
|
174
|
+
br.firstIndex = 10;
|
175
|
+
br.mode = br.constMode2up;
|
176
|
+
br.prev();
|
177
|
+
expect(br.jumpToIndex.callCount).toBe(0); // <-- does not get called
|
178
|
+
expect(br.trigger.callCount).toBe(1);
|
179
|
+
expect(flipAnimationStub.callCount).toBe(1);
|
180
|
+
});
|
181
|
+
});
|
182
|
+
|
183
|
+
describe('non 2up mode', () => {
|
184
|
+
test('jumps to provided index', () => {
|
185
|
+
br.firstIndex = 100;
|
186
|
+
br.mode = br.constMode1up;
|
187
|
+
br.prev();
|
188
|
+
expect(br.jumpToIndex.callCount).toBe(1); // <-- gets called
|
189
|
+
expect(flipAnimationStub.callCount).toBe(0); // <-- gets called by `jumpToIndex` internally
|
190
|
+
});
|
191
|
+
});
|
192
|
+
});
|
193
|
+
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import sinon from 'sinon';
|
2
|
-
import { BookModel } from '
|
3
|
-
import { ImageCache } from '
|
4
|
-
import { Pow2ReduceSet } from '
|
5
|
-
/** @typedef {import('
|
2
|
+
import { BookModel } from '@/src/BookReader/BookModel.js';
|
3
|
+
import { ImageCache } from '@/src/BookReader/ImageCache.js';
|
4
|
+
import { Pow2ReduceSet } from '@/src/BookReader/ReduceSet.js';
|
5
|
+
/** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
|
6
6
|
|
7
7
|
afterEach(() => {
|
8
8
|
jest.restoreAllMocks();
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { BookModel } from '@/src/BookReader/BookModel.js';
|
2
|
+
import { Mode1UpLit } from '@/src/BookReader/Mode1UpLit.js';
|
3
|
+
|
4
|
+
/** @type {import('@/src/BookReader/options.js').BookReaderOptions['data']} */
|
5
|
+
const SAMPLE_DATA = [
|
6
|
+
[
|
7
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image0.jpg', pageNum: '1' },
|
8
|
+
],
|
9
|
+
[
|
10
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image1.jpg', pageNum: '2' },
|
11
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '3' },
|
12
|
+
],
|
13
|
+
[
|
14
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image3.jpg', pageNum: '4' },
|
15
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image4.jpg', pageNum: '5' },
|
16
|
+
],
|
17
|
+
[
|
18
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image5.jpg', pageNum: '6' },
|
19
|
+
],
|
20
|
+
];
|
21
|
+
|
22
|
+
function make_dummy_br(overrides = {}) {
|
23
|
+
return Object.assign({
|
24
|
+
updateFirstIndex() {},
|
25
|
+
_components: {
|
26
|
+
navbar: {
|
27
|
+
updateNavIndexThrottled() {},
|
28
|
+
}
|
29
|
+
},
|
30
|
+
data: []
|
31
|
+
}, overrides);
|
32
|
+
}
|
33
|
+
|
34
|
+
describe('pageTops', () => {
|
35
|
+
afterEach(() => document.body.innerHTML = '');
|
36
|
+
|
37
|
+
test('Works with empty book', async () => {
|
38
|
+
const br = make_dummy_br({ data: [] });
|
39
|
+
const book = new BookModel(br);
|
40
|
+
const mode = new Mode1UpLit(book, br);
|
41
|
+
document.body.appendChild(mode);
|
42
|
+
mode.requestUpdate();
|
43
|
+
await mode.updateComplete;
|
44
|
+
expect(mode.pageTops).toEqual({});
|
45
|
+
});
|
46
|
+
|
47
|
+
test('Iterates all pages', async () => {
|
48
|
+
const br = make_dummy_br({ data: SAMPLE_DATA });
|
49
|
+
const book = new BookModel(br);
|
50
|
+
const mode = new Mode1UpLit(book, br);
|
51
|
+
document.body.appendChild(mode);
|
52
|
+
await mode.requestUpdate();
|
53
|
+
expect(Object.values(mode.pageTops)).toHaveLength(6);
|
54
|
+
});
|
55
|
+
|
56
|
+
test('Computes tops', async () => {
|
57
|
+
const br = make_dummy_br({ data: SAMPLE_DATA });
|
58
|
+
const book = new BookModel(br);
|
59
|
+
const mode = new Mode1UpLit(book, br);
|
60
|
+
document.body.appendChild(mode);
|
61
|
+
await mode.requestUpdate();
|
62
|
+
const tops = Object.entries(mode.pageTops);
|
63
|
+
expect(tops.map(([index, top]) => [index, top.toFixed(1)])).toEqual([
|
64
|
+
// Recall these are in inches
|
65
|
+
['0', '0.2'],
|
66
|
+
['1', '0.6'],
|
67
|
+
['2', '1.1'],
|
68
|
+
['3', '1.5'],
|
69
|
+
['4', '2.0'],
|
70
|
+
['5', '2.4'],
|
71
|
+
]);
|
72
|
+
});
|
73
|
+
});
|
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
import sinon from 'sinon';
|
3
|
+
import { Mode2Up } from '@/src/BookReader/Mode2Up.js';
|
4
|
+
import BookReader from '@/src/BookReader.js';
|
5
|
+
import { BookModel } from '@/src/BookReader/BookModel.js';
|
6
|
+
import { afterEventLoop } from '../utils';
|
7
|
+
/** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
|
8
|
+
|
9
|
+
beforeAll(() => {
|
10
|
+
global.alert = jest.fn();
|
11
|
+
});
|
12
|
+
afterEach(() => {
|
13
|
+
jest.restoreAllMocks();
|
14
|
+
sinon.restore();
|
15
|
+
});
|
16
|
+
|
17
|
+
/** @type {BookReaderOptions['data']} */
|
18
|
+
const SAMPLE_DATA = [
|
19
|
+
[
|
20
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image0.jpg', pageNum: '1' },
|
21
|
+
],
|
22
|
+
[
|
23
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image1.jpg', pageNum: '2' },
|
24
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '3' },
|
25
|
+
],
|
26
|
+
[
|
27
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image3.jpg', pageNum: '4' },
|
28
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image4.jpg', pageNum: '5' },
|
29
|
+
],
|
30
|
+
[
|
31
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image5.jpg', pageNum: '6' },
|
32
|
+
],
|
33
|
+
];
|
34
|
+
|
35
|
+
|
36
|
+
describe('Mode2Up', () => {
|
37
|
+
/** @type {BookReader} */
|
38
|
+
let br;
|
39
|
+
/** @type {BookModel} */
|
40
|
+
let bookModel;
|
41
|
+
/** @type {Mode2Up} */
|
42
|
+
let mode2Up;
|
43
|
+
|
44
|
+
beforeEach(() => {
|
45
|
+
br = new BookReader({
|
46
|
+
data: SAMPLE_DATA,
|
47
|
+
el: document.createElement('div'),
|
48
|
+
});
|
49
|
+
br.init();
|
50
|
+
bookModel = new BookModel(br);
|
51
|
+
mode2Up = new Mode2Up(br, bookModel);
|
52
|
+
});
|
53
|
+
|
54
|
+
describe('prepare', () => {
|
55
|
+
it('initializes DOM properly', async () => {
|
56
|
+
const spyAppend = sinon.spy(br.refs.$brContainer, 'append');
|
57
|
+
const spyRequestUpdate = sinon.spy(mode2Up.mode2UpLit, 'requestUpdate');
|
58
|
+
const initFirstRenderSpy = sinon.spy(mode2Up.mode2UpLit, 'initFirstRender');
|
59
|
+
const jumpToIndexSpy = sinon.spy(mode2Up.mode2UpLit, 'jumpToIndex');
|
60
|
+
sinon.stub(mode2Up.mode2UpLit, 'updateComplete').get(() => Promise.resolve());
|
61
|
+
mode2Up.prepare();
|
62
|
+
|
63
|
+
expect(br.refs.$brContainer[0].style.overflow).toEqual('hidden');
|
64
|
+
expect(spyAppend.calledWith(mode2Up.$el)).toBe(true);
|
65
|
+
expect(mode2Up.mode2UpLit.style.opacity).toEqual('0');
|
66
|
+
|
67
|
+
await afterEventLoop();
|
68
|
+
|
69
|
+
expect(initFirstRenderSpy.called).toBe(true);
|
70
|
+
expect(jumpToIndexSpy.called).toBe(false);
|
71
|
+
expect(mode2Up.everShown).toBe(true);
|
72
|
+
expect(spyRequestUpdate.called).toBe(true);
|
73
|
+
expect(mode2Up.mode2UpLit.style.opacity).toEqual('1');
|
74
|
+
});
|
75
|
+
});
|
76
|
+
|
77
|
+
describe('resizePageView', () => {
|
78
|
+
it('updates autoFit when possible', async () => {
|
79
|
+
const updateClientSizesSpy = sinon.stub(mode2Up.mode2UpLit.htmlDimensionsCacher, 'updateClientSizes');
|
80
|
+
const resizeViaAutofitSpy = sinon.spy(mode2Up.mode2UpLit, 'resizeViaAutofit');
|
81
|
+
const recenterStub = sinon.stub(mode2Up.mode2UpLit, 'recenter');
|
82
|
+
|
83
|
+
mode2Up.resizePageView();
|
84
|
+
expect(updateClientSizesSpy.called).toBe(true);
|
85
|
+
expect(resizeViaAutofitSpy.called).toBe(true);
|
86
|
+
expect(recenterStub.called).toBe(true);
|
87
|
+
|
88
|
+
// Test with scale and autoFit as 'none'
|
89
|
+
mode2Up.mode2UpLit.scale = 0.1;
|
90
|
+
mode2Up.mode2UpLit.autoFit = 'none';
|
91
|
+
mode2Up.resizePageView();
|
92
|
+
|
93
|
+
expect(mode2Up.mode2UpLit.autoFit).toEqual('auto');
|
94
|
+
expect(resizeViaAutofitSpy.callCount).toEqual(2);
|
95
|
+
expect(recenterStub.callCount).toEqual(2);
|
96
|
+
});
|
97
|
+
});
|
98
|
+
});
|
@@ -0,0 +1,190 @@
|
|
1
|
+
import sinon from "sinon";
|
2
|
+
import { BookModel } from "@/src/BookReader/BookModel.js";
|
3
|
+
import { Mode2UpLit } from "@/src/BookReader/Mode2UpLit.js";
|
4
|
+
|
5
|
+
/** @type {import('@/src/BookReader/options.js').BookReaderOptions['data']} */
|
6
|
+
const SAMPLE_DATA = [
|
7
|
+
[
|
8
|
+
{
|
9
|
+
width: 123,
|
10
|
+
height: 123,
|
11
|
+
uri: "https://archive.org/image0.jpg",
|
12
|
+
pageNum: "1",
|
13
|
+
},
|
14
|
+
],
|
15
|
+
[
|
16
|
+
{
|
17
|
+
width: 123,
|
18
|
+
height: 123,
|
19
|
+
uri: "https://archive.org/image1.jpg",
|
20
|
+
pageNum: "2",
|
21
|
+
},
|
22
|
+
{
|
23
|
+
width: 123,
|
24
|
+
height: 123,
|
25
|
+
uri: "https://archive.org/image2.jpg",
|
26
|
+
pageNum: "3",
|
27
|
+
},
|
28
|
+
],
|
29
|
+
[
|
30
|
+
{
|
31
|
+
width: 123,
|
32
|
+
height: 123,
|
33
|
+
uri: "https://archive.org/image3.jpg",
|
34
|
+
pageNum: "4",
|
35
|
+
},
|
36
|
+
{
|
37
|
+
width: 123,
|
38
|
+
height: 123,
|
39
|
+
uri: "https://archive.org/image4.jpg",
|
40
|
+
pageNum: "5",
|
41
|
+
},
|
42
|
+
],
|
43
|
+
[
|
44
|
+
{
|
45
|
+
width: 123,
|
46
|
+
height: 123,
|
47
|
+
uri: "https://archive.org/image5.jpg",
|
48
|
+
pageNum: "6",
|
49
|
+
},
|
50
|
+
],
|
51
|
+
];
|
52
|
+
|
53
|
+
function make_dummy_br(overrides = {}) {
|
54
|
+
return Object.assign({
|
55
|
+
updateFirstIndex() {},
|
56
|
+
_components: {
|
57
|
+
navbar: {
|
58
|
+
updateNavIndexThrottled() {},
|
59
|
+
},
|
60
|
+
},
|
61
|
+
data: [],
|
62
|
+
}, overrides);
|
63
|
+
}
|
64
|
+
|
65
|
+
afterEach(() => {
|
66
|
+
sinon.restore();
|
67
|
+
});
|
68
|
+
|
69
|
+
describe("computePageHeight", () => {
|
70
|
+
test("Always returns the median", () => {
|
71
|
+
const mode = new Mode2UpLit({
|
72
|
+
getMedianPageSizeInches: () => ({ width: 100, height: 200 }),
|
73
|
+
}, null);
|
74
|
+
expect(mode.computePageHeight(null)).toEqual(200);
|
75
|
+
expect(mode.computePageHeight({ widthInches: 300, heightInches: 400 }))
|
76
|
+
.toEqual(200);
|
77
|
+
});
|
78
|
+
});
|
79
|
+
|
80
|
+
describe("computePageWidth", () => {
|
81
|
+
test("returns relative to pageHeight", () => {
|
82
|
+
const mode = new Mode2UpLit(null, null);
|
83
|
+
sinon.stub(mode, "computePageHeight").returns(6);
|
84
|
+
|
85
|
+
expect(mode.computePageWidth({ widthInches: 2, heightInches: 6 })).toEqual(
|
86
|
+
2,
|
87
|
+
);
|
88
|
+
expect(mode.computePageWidth({ widthInches: 3, heightInches: 6 })).toEqual(
|
89
|
+
3,
|
90
|
+
);
|
91
|
+
expect(mode.computePageWidth({ widthInches: 2, heightInches: 4 })).toEqual(
|
92
|
+
2 * 6 / 4,
|
93
|
+
);
|
94
|
+
});
|
95
|
+
});
|
96
|
+
|
97
|
+
describe("computePositions", () => {
|
98
|
+
const LEFT_COVER_EXPECTED = {
|
99
|
+
leafEdgesLeftStart: -0.246,
|
100
|
+
leafEdgesLeftMainWidth: 0,
|
101
|
+
leafEdgesLeftMovingStart: -0.246,
|
102
|
+
leafEdgesLeftMovingWidth: 0,
|
103
|
+
leafEdgesLeftEnd: -0.246,
|
104
|
+
leafEdgesLeftFullWidth: 0,
|
105
|
+
pageLeftStart: -0.246,
|
106
|
+
pageLeftWidth: 0.246,
|
107
|
+
pageLeftEnd: 0,
|
108
|
+
gutter: 0,
|
109
|
+
pageRightStart: 0,
|
110
|
+
pageRightWidth: 0.246,
|
111
|
+
pageRightEnd: 0.246,
|
112
|
+
leafEdgesRightStart: 0.246,
|
113
|
+
leafEdgesRightMovingWidth: 0,
|
114
|
+
leafEdgesRightMainStart: 0.246,
|
115
|
+
leafEdgesRightMainWidth: 0.006,
|
116
|
+
leafEdgesRightEnd: 0.252,
|
117
|
+
leafEdgesRightFullWidth: 0.006,
|
118
|
+
spreadWidth: 0.492,
|
119
|
+
bookWidth: 0.498
|
120
|
+
};
|
121
|
+
const SPREAD_EXPECTED = {
|
122
|
+
leafEdgesLeftStart: -0.246,
|
123
|
+
leafEdgesLeftMainWidth: 0.002,
|
124
|
+
leafEdgesLeftMovingStart: -0.244,
|
125
|
+
leafEdgesLeftMovingWidth: 0,
|
126
|
+
leafEdgesLeftEnd: -0.244,
|
127
|
+
leafEdgesLeftFullWidth: 0.002,
|
128
|
+
pageLeftStart: -0.244,
|
129
|
+
pageLeftWidth: 0.246,
|
130
|
+
pageLeftEnd: 0.002,
|
131
|
+
gutter: 0.002,
|
132
|
+
pageRightStart: 0.002,
|
133
|
+
pageRightWidth: 0.246,
|
134
|
+
pageRightEnd: 0.248,
|
135
|
+
leafEdgesRightStart: 0.248,
|
136
|
+
leafEdgesRightMovingWidth: 0,
|
137
|
+
leafEdgesRightMainStart: 0.248,
|
138
|
+
leafEdgesRightMainWidth: 0.004,
|
139
|
+
leafEdgesRightEnd: 0.252,
|
140
|
+
leafEdgesRightFullWidth: 0.004,
|
141
|
+
spreadWidth: 0.492,
|
142
|
+
bookWidth: 0.498
|
143
|
+
};
|
144
|
+
const RIGHT_COVER_EXPECTED = {
|
145
|
+
leafEdgesLeftStart: -0.242,
|
146
|
+
leafEdgesLeftMainWidth: 0.006,
|
147
|
+
leafEdgesLeftMovingStart: -0.236,
|
148
|
+
leafEdgesLeftMovingWidth: 0,
|
149
|
+
leafEdgesLeftEnd: -0.236,
|
150
|
+
leafEdgesLeftFullWidth: 0.006,
|
151
|
+
pageLeftStart: -0.236,
|
152
|
+
pageLeftWidth: 0.246,
|
153
|
+
pageLeftEnd: 0.01,
|
154
|
+
gutter: 0.01,
|
155
|
+
pageRightStart: 0.01,
|
156
|
+
pageRightWidth: 0,
|
157
|
+
pageRightEnd: 0.01,
|
158
|
+
leafEdgesRightStart: 0.01,
|
159
|
+
leafEdgesRightMovingWidth: 0,
|
160
|
+
leafEdgesRightMainStart: 0.01,
|
161
|
+
leafEdgesRightMainWidth: 0,
|
162
|
+
leafEdgesRightEnd: 0.01,
|
163
|
+
leafEdgesRightFullWidth: 0,
|
164
|
+
spreadWidth: 0.246,
|
165
|
+
bookWidth: 0.252
|
166
|
+
};
|
167
|
+
|
168
|
+
test("left cover page", () => {
|
169
|
+
const br = make_dummy_br({ data: SAMPLE_DATA });
|
170
|
+
const book = new BookModel(br);
|
171
|
+
const mode = new Mode2UpLit(book, br);
|
172
|
+
expect(mode.computePositions(null, book.getPage(0))).toEqual(LEFT_COVER_EXPECTED);
|
173
|
+
});
|
174
|
+
|
175
|
+
test("spread", () => {
|
176
|
+
const br = make_dummy_br({ data: SAMPLE_DATA });
|
177
|
+
const book = new BookModel(br);
|
178
|
+
const mode = new Mode2UpLit(book, br);
|
179
|
+
|
180
|
+
expect(mode.computePositions(book.getPage(1), book.getPage(2))).toEqual(SPREAD_EXPECTED);
|
181
|
+
});
|
182
|
+
|
183
|
+
test("right cover page", () => {
|
184
|
+
const br = make_dummy_br({ data: SAMPLE_DATA });
|
185
|
+
const book = new BookModel(br);
|
186
|
+
const mode = new Mode2UpLit(book, br);
|
187
|
+
|
188
|
+
expect(mode.computePositions(book.getPage(-1), null)).toEqual(RIGHT_COVER_EXPECTED);
|
189
|
+
});
|
190
|
+
});
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { ModeCoordinateSpace } from "@/src/BookReader/ModeCoordinateSpace";
|
2
|
+
|
3
|
+
describe("worldUnitsToRenderedPixels", () => {
|
4
|
+
test("0 case", () => {
|
5
|
+
const mcs = new ModeCoordinateSpace({ scale: 1 });
|
6
|
+
expect(mcs.worldUnitsToRenderedPixels(0)).toBe(0);
|
7
|
+
});
|
8
|
+
|
9
|
+
test("Misc cases", () => {
|
10
|
+
const mcs = new ModeCoordinateSpace({ scale: 1 });
|
11
|
+
mcs.screenDPI = 100;
|
12
|
+
expect(mcs.worldUnitsToRenderedPixels(1)).toBe(100);
|
13
|
+
mcs.screenDPI = 78;
|
14
|
+
expect(mcs.worldUnitsToRenderedPixels(1)).toBe(78);
|
15
|
+
});
|
16
|
+
});
|