Skip to content

Commit bb73ce2

Browse files
refactor: remove dead code from pdf-viewer page logic (#13391)
Co-authored-by: web-padawan <iamkulykov@gmail.com>
1 parent 8dd8a2a commit bb73ce2

3 files changed

Lines changed: 21 additions & 24 deletions

File tree

‎packages/pdf-viewer/src/pdf-viewer-layout.d.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
export type PdfViewerVisiblePage = {
1313
/** The index of the page. */
1414
index: number;
15-
/** The height of the page that is inside the view. */
16-
height: number;
1715
/**
1816
* The visible height divided by the page height, or by the view height for
1917
* a page taller than the view, from 0 to 1.
@@ -41,7 +39,7 @@ export declare function getFitScale(availableWidth: number, pageWidth: number):
4139
/**
4240
* Returns the pages that intersect the view, in document order. When no page
4341
* intersects it, returns the first page below the top of the view with a
44-
* visible height and ratio of 0.
42+
* ratio of 0.
4543
*/
4644
export declare function getVisiblePages(
4745
count: number,

‎packages/pdf-viewer/src/pdf-viewer-layout.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/**
1313
* @typedef {Object} PdfViewerVisiblePage
1414
* @property {number} index The index of the page.
15-
* @property {number} height The height of the page that is inside the view.
1615
* @property {number} ratio The visible height divided by the page height, or by
1716
* the view height for a page taller than the view, from 0 to 1.
1817
*/
@@ -40,7 +39,7 @@ export function getFitScale(availableWidth, pageWidth) {
4039
/**
4140
* Returns the pages that intersect the view, in document order. When no page
4241
* intersects it, returns the first page below the top of the view with a
43-
* visible height and ratio of 0.
42+
* ratio of 0.
4443
*
4544
* @param {number} count the number of pages
4645
* @param {(index: number) => { top: number, height: number }} getBounds
@@ -72,10 +71,10 @@ export function getVisiblePages(count, getBounds, viewTop, viewBottom) {
7271
const visibleHeight = Math.min(viewBottom, top + height) - Math.max(viewTop, top);
7372
// A page taller than the view can at most fill the view.
7473
const maxHeight = Math.min(height, viewBottom - viewTop);
75-
visible.push({ index, height: visibleHeight, ratio: maxHeight > 0 ? visibleHeight / maxHeight : 0 });
74+
visible.push({ index, ratio: maxHeight > 0 ? visibleHeight / maxHeight : 0 });
7675
}
7776
if (!visible.length) {
78-
visible.push({ index: low, height: 0, ratio: 0 });
77+
visible.push({ index: low, ratio: 0 });
7978
}
8079
return visible;
8180
}

‎packages/pdf-viewer/test/layout.test.ts‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ describe('layout', () => {
2424
// Pages of 100px with a gap of 10px
2525
const getBounds = (index: number) => ({ top: index * 110, height: 100 });
2626

27-
it('should return the pages that intersect the view with their visible height and ratio', () => {
27+
it('should return the pages that intersect the view with their visible ratio', () => {
2828
expect(getVisiblePages(10, getBounds, 150, 350)).to.deep.equal([
29-
{ index: 1, height: 60, ratio: 0.6 },
30-
{ index: 2, height: 100, ratio: 1 },
31-
{ index: 3, height: 20, ratio: 0.2 },
29+
{ index: 1, ratio: 0.6 },
30+
{ index: 2, ratio: 1 },
31+
{ index: 3, ratio: 0.2 },
3232
]);
3333
});
3434

@@ -38,8 +38,8 @@ describe('layout', () => {
3838
{ top: 60, height: 200 },
3939
];
4040
expect(getVisiblePages(2, (index) => bounds[index], 0, 210)).to.deep.equal([
41-
{ index: 0, height: 50, ratio: 1 },
42-
{ index: 1, height: 150, ratio: 0.75 },
41+
{ index: 0, ratio: 1 },
42+
{ index: 1, ratio: 0.75 },
4343
]);
4444
});
4545

@@ -49,8 +49,8 @@ describe('layout', () => {
4949
{ top: 1610, height: 200 },
5050
];
5151
expect(getVisiblePages(2, (index) => bounds[index], 900, 1700)).to.deep.equal([
52-
{ index: 0, height: 700, ratio: 0.875 },
53-
{ index: 1, height: 90, ratio: 0.45 },
52+
{ index: 0, ratio: 0.875 },
53+
{ index: 1, ratio: 0.45 },
5454
]);
5555
});
5656

@@ -60,13 +60,13 @@ describe('layout', () => {
6060
{ top: 60, height: 0 },
6161
];
6262
expect(getVisiblePages(2, (index) => bounds[index], 0, 160)).to.deep.equal([
63-
{ index: 0, height: 50, ratio: 1 },
64-
{ index: 1, height: 0, ratio: 0 },
63+
{ index: 0, ratio: 1 },
64+
{ index: 1, ratio: 0 },
6565
]);
6666
});
6767

68-
it('should return the next page with height 0 when the view only shows a gap', () => {
69-
expect(getVisiblePages(10, getBounds, 212, 218)).to.deep.equal([{ index: 2, height: 0, ratio: 0 }]);
68+
it('should return the next page with a ratio of 0 when the view only shows a gap', () => {
69+
expect(getVisiblePages(10, getBounds, 212, 218)).to.deep.equal([{ index: 2, ratio: 0 }]);
7070
});
7171

7272
it('should only measure a few pages of a long document', () => {
@@ -80,18 +80,18 @@ describe('layout', () => {
8080
it('should return the page with the largest visible part of its height', () => {
8181
expect(
8282
getMostVisibleIndex([
83-
{ index: 3, height: 50, ratio: 0.1 },
84-
{ index: 4, height: 60, ratio: 1 },
85-
{ index: 5, height: 300, ratio: 0.6 },
83+
{ index: 3, ratio: 0.1 },
84+
{ index: 4, ratio: 1 },
85+
{ index: 5, ratio: 0.6 },
8686
]),
8787
).to.equal(4);
8888
});
8989

9090
it('should return the first page on a tie', () => {
9191
expect(
9292
getMostVisibleIndex([
93-
{ index: 3, height: 100, ratio: 1 },
94-
{ index: 4, height: 200, ratio: 1 },
93+
{ index: 3, ratio: 1 },
94+
{ index: 4, ratio: 1 },
9595
]),
9696
).to.equal(3);
9797
});

0 commit comments

Comments
 (0)