@internetarchive/bookreader 5.0.0-23 → 5.0.0-24
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.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/bookreader-component-bundle.js +1 -1
- package/BookReader/bookreader-component-bundle.js.map +1 -1
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +1 -1
- package/src/BookReader/Mode1Up.js +10 -2
- package/src/BookReader/ModeThumb.js +13 -6
- package/src/BookReader/options.js +4 -0
- package/src/BookReader.js +4 -22
- package/tests/jest/BookReader/ModeThumb.test.js +71 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
@@ -79,8 +79,16 @@ export class Mode1Up {
|
|
79
79
|
* @param {'in' | 'out'} direction
|
80
80
|
*/
|
81
81
|
zoom(direction) {
|
82
|
-
|
83
|
-
|
82
|
+
switch (direction) {
|
83
|
+
case 'in':
|
84
|
+
this.mode1UpLit.zoomIn();
|
85
|
+
break;
|
86
|
+
case 'out':
|
87
|
+
this.mode1UpLit.zoomOut();
|
88
|
+
break;
|
89
|
+
default:
|
90
|
+
console.error(`Unsupported direction: ${direction}`);
|
91
|
+
}
|
84
92
|
}
|
85
93
|
|
86
94
|
/**
|
@@ -235,20 +235,27 @@ export class ModeThumb {
|
|
235
235
|
}
|
236
236
|
|
237
237
|
/**
|
238
|
-
* @param {
|
238
|
+
* @param {'in' | 'out'} direction
|
239
239
|
*/
|
240
240
|
zoom(direction) {
|
241
241
|
const oldColumns = this.br.thumbColumns;
|
242
242
|
switch (direction) {
|
243
|
-
case
|
244
|
-
this.br.thumbColumns += 1;
|
245
|
-
break;
|
246
|
-
case 1:
|
243
|
+
case 'in':
|
247
244
|
this.br.thumbColumns -= 1;
|
248
245
|
break;
|
246
|
+
case 'out':
|
247
|
+
this.br.thumbColumns += 1;
|
248
|
+
break;
|
249
|
+
default:
|
250
|
+
console.error(`Unsupported direction: ${direction}`);
|
249
251
|
}
|
250
252
|
|
251
|
-
|
253
|
+
// Limit zoom in/out columns
|
254
|
+
this.br.thumbColumns = clamp(
|
255
|
+
this.br.thumbColumns,
|
256
|
+
this.br.options.thumbMinZoomColumns,
|
257
|
+
this.br.options.thumbMaxZoomColumns
|
258
|
+
);
|
252
259
|
|
253
260
|
if (this.br.thumbColumns != oldColumns) {
|
254
261
|
this.br.displayedRows = []; /* force a gallery redraw */
|
@@ -25,6 +25,10 @@ export const DEFAULT_OPTIONS = {
|
|
25
25
|
thumbMaxLoading: 4,
|
26
26
|
/** spacing between thumbnails */
|
27
27
|
thumbPadding: 10,
|
28
|
+
/** min zoom in columns */
|
29
|
+
thumbMinZoomColumns: 2,
|
30
|
+
/** max zoom out columns */
|
31
|
+
thumbMaxZoomColumns: 8,
|
28
32
|
|
29
33
|
/** @type {number | 'fast' | 'slow'} speed for flip animation */
|
30
34
|
flipSpeed: 'fast',
|
package/src/BookReader.js
CHANGED
@@ -829,29 +829,11 @@ BookReader.prototype.drawLeafsThrottled = utils.throttle(
|
|
829
829
|
* @param {number} direction Pass 1 to zoom in, anything else to zoom out
|
830
830
|
*/
|
831
831
|
BookReader.prototype.zoom = function(direction) {
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
this.zoom1up('in');
|
837
|
-
} else {
|
838
|
-
this.zoom1up('out');
|
839
|
-
}
|
840
|
-
break;
|
841
|
-
case this.constMode2up:
|
842
|
-
if (direction == 1) {
|
843
|
-
// XXX other cases
|
844
|
-
this.zoom2up('in');
|
845
|
-
} else {
|
846
|
-
this.zoom2up('out');
|
847
|
-
}
|
848
|
-
break;
|
849
|
-
case this.constModeThumb:
|
850
|
-
// XXX update zoomThumb for named directions
|
851
|
-
this.zoomThumb(direction);
|
852
|
-
break;
|
832
|
+
if (direction == 1) {
|
833
|
+
this.activeMode.zoom('in');
|
834
|
+
} else {
|
835
|
+
this.activeMode.zoom('out');
|
853
836
|
}
|
854
|
-
|
855
837
|
this.textSelectionPlugin?.stopPageFlip(this.refs.$brContainer);
|
856
838
|
return;
|
857
839
|
};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
import sinon from 'sinon';
|
3
|
+
import BookReader from '@/src/BookReader.js';
|
4
|
+
/** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
|
5
|
+
|
6
|
+
beforeAll(() => {
|
7
|
+
global.alert = jest.fn();
|
8
|
+
});
|
9
|
+
afterEach(() => {
|
10
|
+
jest.restoreAllMocks();
|
11
|
+
sinon.restore();
|
12
|
+
});
|
13
|
+
|
14
|
+
/** @type {BookReaderOptions['data']} */
|
15
|
+
const SAMPLE_DATA = [
|
16
|
+
[
|
17
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image0.jpg', pageNum: '1' },
|
18
|
+
],
|
19
|
+
[
|
20
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image1.jpg', pageNum: '2' },
|
21
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '3' },
|
22
|
+
],
|
23
|
+
[
|
24
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image3.jpg', pageNum: '4' },
|
25
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image4.jpg', pageNum: '5' },
|
26
|
+
],
|
27
|
+
[
|
28
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image5.jpg', pageNum: '6' },
|
29
|
+
],
|
30
|
+
];
|
31
|
+
|
32
|
+
describe('zoom', () => {
|
33
|
+
const br = new BookReader({ data: SAMPLE_DATA });
|
34
|
+
br.init();
|
35
|
+
|
36
|
+
test('initializes with default columns', () => {
|
37
|
+
expect(br.thumbColumns).toBe(br.options.thumbColumns);
|
38
|
+
});
|
39
|
+
|
40
|
+
test('removes column and redraws zooming in', () => {
|
41
|
+
const prepare = sinon.spy(br._modes.modeThumb, 'prepare');
|
42
|
+
const startColumns = br.thumbColumns;
|
43
|
+
br._modes.modeThumb.zoom('in');
|
44
|
+
expect(br.thumbColumns).toBe(startColumns - 1);
|
45
|
+
expect(prepare.callCount).toBe(1);
|
46
|
+
});
|
47
|
+
|
48
|
+
test('adds column and redraws zooming out', () => {
|
49
|
+
const prepare = sinon.spy(br._modes.modeThumb, 'prepare');
|
50
|
+
const startColumns = br.thumbColumns;
|
51
|
+
br._modes.modeThumb.zoom('out');
|
52
|
+
expect(br.thumbColumns).toBe(startColumns + 1);
|
53
|
+
expect(prepare.callCount).toBe(1);
|
54
|
+
});
|
55
|
+
|
56
|
+
test('keeps columns and no redraw at zooming in limit', () => {
|
57
|
+
const prepare = sinon.spy(br._modes.modeThumb, 'prepare');
|
58
|
+
br.thumbColumns = br.options.thumbMinZoomColumns;
|
59
|
+
br._modes.modeThumb.zoom('in');
|
60
|
+
expect(br.thumbColumns).toBe(br.options.thumbMinZoomColumns);
|
61
|
+
expect(prepare.callCount).toBe(0);
|
62
|
+
});
|
63
|
+
|
64
|
+
test('keeps columns and no redraw at zooming out limit', () => {
|
65
|
+
const prepare = sinon.spy(br._modes.modeThumb, 'prepare');
|
66
|
+
br.thumbColumns = br.options.thumbMaxZoomColumns;
|
67
|
+
br._modes.modeThumb.zoom('out');
|
68
|
+
expect(br.thumbColumns).toBe(br.options.thumbMaxZoomColumns);
|
69
|
+
expect(prepare.callCount).toBe(0);
|
70
|
+
});
|
71
|
+
});
|