Skip to content

Commit c31e769

Browse files
committed
[breaking] Update pdfjs-dist to 4.0.379
1 parent 81c98f6 commit c31e769

32 files changed

+80
-398
lines changed

packages/react-pdf/README.md

Lines changed: 15 additions & 15 deletions
Large diffs are not rendered by default.

packages/react-pdf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"make-cancellable-promise": "^1.3.1",
6161
"make-event-props": "^1.6.0",
6262
"merge-refs": "^1.3.0",
63-
"pdfjs-dist": "3.11.174",
63+
"pdfjs-dist": "4.0.379",
6464
"tiny-invariant": "^1.0.0",
6565
"warning": "^4.0.0"
6666
},

packages/react-pdf/src/Document.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import clsx from 'clsx';
77
import invariant from 'tiny-invariant';
88
import warning from 'warning';
99
import { dequal } from 'dequal';
10-
import pdfjs from './pdfjs.js';
10+
import * as pdfjs from 'pdfjs-dist';
1111

1212
import DocumentContext from './DocumentContext.js';
1313

@@ -193,9 +193,7 @@ export type DocumentProps = {
193193
*/
194194
options?: Options;
195195
/**
196-
* Rendering mode of the document. Can be `"canvas"`, `"custom"`, `"none"` or `"svg"`. If set to `"custom"`, `customRenderer` must also be provided.
197-
*
198-
* **Warning**: SVG render mode is deprecated and will be removed in the future.
196+
* Rendering mode of the document. Can be `"canvas"`, `"custom"` or `"none"``. If set to `"custom"`, `customRenderer` must also be provided.
199197
*
200198
* @default 'canvas'
201199
* @example 'custom'

packages/react-pdf/src/Page.spec.tsx

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('Page', () => {
303303
expect(inputRef.current).toBeInstanceOf(HTMLDivElement);
304304
});
305305

306-
it('passes canvas element to PageCanvas properly', async () => {
306+
it('passes canvas element to Canvas properly', async () => {
307307
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();
308308

309309
const canvasRef = createRef<HTMLCanvasElement>();
@@ -506,15 +506,13 @@ describe('Page', () => {
506506
},
507507
);
508508

509-
expect.assertions(2);
509+
expect.assertions(1);
510510

511511
await onLoadSuccessPromise;
512512

513513
const pageCanvas = container.querySelector('.react-pdf__Page__canvas');
514-
const pageSVG = container.querySelector('.react-pdf__Page__svg');
515514

516515
expect(pageCanvas).not.toBeInTheDocument();
517-
expect(pageSVG).not.toBeInTheDocument();
518516
});
519517

520518
it('requests page to be rendered in canvas mode when given renderMode = "canvas"', async () => {
@@ -566,26 +564,6 @@ describe('Page', () => {
566564
expect(customRenderer).toBeInTheDocument();
567565
});
568566

569-
it('requests page to be rendered in SVG mode when given renderMode = "svg"', async () => {
570-
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();
571-
572-
const { container } = renderWithContext(
573-
<Page onLoadSuccess={onLoadSuccess} pageIndex={0} renderMode="svg" />,
574-
{
575-
linkService,
576-
pdf,
577-
},
578-
);
579-
580-
expect.assertions(1);
581-
582-
await onLoadSuccessPromise;
583-
584-
const pageSVG = container.querySelector('.react-pdf__Page__svg');
585-
586-
expect(pageSVG).toBeInTheDocument();
587-
});
588-
589567
it('requests text content to be rendered by default', async () => {
590568
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();
591569

@@ -696,26 +674,6 @@ describe('Page', () => {
696674
expect(textLayer).toBeInTheDocument();
697675
});
698676

699-
it('renders TextLayer when given renderMode = "svg"', async () => {
700-
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();
701-
702-
const { container } = renderWithContext(
703-
<Page onLoadSuccess={onLoadSuccess} pageIndex={0} renderMode="svg" renderTextLayer />,
704-
{
705-
linkService,
706-
pdf,
707-
},
708-
);
709-
710-
expect.assertions(1);
711-
712-
await onLoadSuccessPromise;
713-
714-
const textLayer = container.querySelector('.react-pdf__Page__textContent');
715-
716-
expect(textLayer).toBeInTheDocument();
717-
});
718-
719677
it('requests annotations to be rendered by default', async () => {
720678
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();
721679

packages/react-pdf/src/Page.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import warning from 'warning';
1111
import PageContext from './PageContext.js';
1212

1313
import Message from './Message.js';
14-
import PageCanvas from './Page/PageCanvas.js';
15-
import PageSVG from './Page/PageSVG.js';
14+
import Canvas from './Page/Canvas.js';
1615
import TextLayer from './Page/TextLayer.js';
1716
import AnnotationLayer from './Page/AnnotationLayer.js';
1817

@@ -52,13 +51,13 @@ export type PageProps = {
5251
_className?: string;
5352
_enableRegisterUnregisterPage?: boolean;
5453
/**
55-
* Canvas background color. Any valid `canvas.fillStyle` can be used. If you set `renderMode` to `"svg"` this prop will be ignored.
54+
* Canvas background color. Any valid `canvas.fillStyle` can be used.
5655
*
5756
* @example 'transparent'
5857
*/
5958
canvasBackground?: string;
6059
/**
61-
* A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to `<canvas>` rendered by `<PageCanvas>` component. If you set `renderMode` to `"svg"` this prop will be ignored.
60+
* A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to `<canvas>` rendered by `<PageCanvas>` component.
6261
*
6362
* @example (ref) => { this.myCanvas = ref; }
6463
* @example this.ref
@@ -260,9 +259,7 @@ export type PageProps = {
260259
*/
261260
renderForms?: boolean;
262261
/**
263-
* Rendering mode of the document. Can be `"canvas"`, `"custom"`, `"none"` or `"svg"`. If set to `"custom"`, `customRenderer` must also be provided.
264-
*
265-
* **Warning**: SVG render mode is deprecated and will be removed in the future.
262+
* Rendering mode of the document. Can be `"canvas"`, `"custom"` or `"none"`. If set to `"custom"`, `customRenderer` must also be provided.
266263
*
267264
* @default 'canvas'
268265
* @example 'custom'
@@ -556,8 +553,6 @@ export default function Page(props: PageProps) {
556553

557554
const pageKey = `${pageIndex}@${scale}/${rotate}`;
558555

559-
const pageKeyNoScale = `${pageIndex}/${rotate}`;
560-
561556
function renderMainLayer() {
562557
switch (renderMode) {
563558
case 'custom': {
@@ -570,11 +565,9 @@ export default function Page(props: PageProps) {
570565
}
571566
case 'none':
572567
return null;
573-
case 'svg':
574-
return <PageSVG key={`${pageKeyNoScale}_svg`} />;
575568
case 'canvas':
576569
default:
577-
return <PageCanvas key={`${pageKey}_canvas`} canvasRef={canvasRef} />;
570+
return <Canvas key={`${pageKey}_canvas`} canvasRef={canvasRef} />;
578571
}
579572
}
580573

packages/react-pdf/src/Page/AnnotationLayer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import makeCancellable from 'make-cancellable-promise';
55
import clsx from 'clsx';
66
import invariant from 'tiny-invariant';
77
import warning from 'warning';
8-
import pdfjs from '../pdfjs.js';
8+
import * as pdfjs from 'pdfjs-dist';
99

1010
import useDocumentContext from '../shared/hooks/useDocumentContext.js';
1111
import usePageContext from '../shared/hooks/usePageContext.js';

packages/react-pdf/src/Page/PageCanvas.spec.tsx renamed to packages/react-pdf/src/Page/Canvas.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render } from '@testing-library/react';
33

44
import { pdfjs } from '../index.test.js';
55

6-
import PageCanvas from './PageCanvas.js';
6+
import Canvas from './Canvas.js';
77

88
import failingPage from '../../../../__mocks__/_failing_page.js';
99

@@ -32,7 +32,7 @@ function renderWithContext(children: React.ReactNode, context: Partial<PageConte
3232
};
3333
}
3434

35-
describe('PageCanvas', () => {
35+
describe('Canvas', () => {
3636
// Loaded page
3737
let page: PDFPageProxy;
3838
let pageWithRendererMocked: PDFPageProxy;
@@ -58,7 +58,7 @@ describe('PageCanvas', () => {
5858

5959
muteConsole();
6060

61-
renderWithContext(<PageCanvas />, {
61+
renderWithContext(<Canvas />, {
6262
onRenderSuccess,
6363
page: pageWithRendererMocked,
6464
scale: 1,
@@ -76,7 +76,7 @@ describe('PageCanvas', () => {
7676

7777
muteConsole();
7878

79-
renderWithContext(<PageCanvas />, {
79+
renderWithContext(<Canvas />, {
8080
onRenderError,
8181
page: failingPage,
8282
scale: 1,
@@ -94,7 +94,7 @@ describe('PageCanvas', () => {
9494
it('passes canvas element to canvasRef properly', () => {
9595
const canvasRef = vi.fn();
9696

97-
renderWithContext(<PageCanvas canvasRef={canvasRef} />, {
97+
renderWithContext(<Canvas canvasRef={canvasRef} />, {
9898
page: pageWithRendererMocked,
9999
scale: 1,
100100
});
@@ -106,7 +106,7 @@ describe('PageCanvas', () => {
106106
it('does not request structure tree to be rendered when renderTextLayer = false', async () => {
107107
const { func: onRenderSuccess, promise: onRenderSuccessPromise } = makeAsyncCallback();
108108

109-
const { container } = renderWithContext(<PageCanvas />, {
109+
const { container } = renderWithContext(<Canvas />, {
110110
onRenderSuccess,
111111
page: pageWithRendererMocked,
112112
renderTextLayer: false,
@@ -123,7 +123,7 @@ describe('PageCanvas', () => {
123123
const { func: onGetStructTreeSuccess, promise: onGetStructTreeSuccessPromise } =
124124
makeAsyncCallback();
125125

126-
const { container } = renderWithContext(<PageCanvas />, {
126+
const { container } = renderWithContext(<Canvas />, {
127127
onGetStructTreeSuccess,
128128
page: pageWithRendererMocked,
129129
renderTextLayer: true,

packages/react-pdf/src/Page/PageCanvas.tsx renamed to packages/react-pdf/src/Page/Canvas.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useMemo, useRef } from 'react';
44
import mergeRefs from 'merge-refs';
55
import invariant from 'tiny-invariant';
66
import warning from 'warning';
7-
import pdfjs from '../pdfjs.js';
7+
import * as pdfjs from 'pdfjs-dist';
88

99
import StructTree from '../StructTree.js';
1010

@@ -20,11 +20,11 @@ import type { RenderParameters } from 'pdfjs-dist/types/src/display/api.js';
2020

2121
const ANNOTATION_MODE = pdfjs.AnnotationMode;
2222

23-
type PageCanvasProps = {
23+
type CanvasProps = {
2424
canvasRef?: React.Ref<HTMLCanvasElement>;
2525
};
2626

27-
export default function PageCanvas(props: PageCanvasProps) {
27+
export default function Canvas(props: CanvasProps) {
2828
const pageContext = usePageContext();
2929

3030
invariant(pageContext, 'Unable to find Page context.');

packages/react-pdf/src/Page/PageSVG.spec.tsx

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)