Skip to content

Commit

Permalink
[breaking] Update pdfjs-dist to 4.0.379
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 17, 2024
1 parent 0cbb75a commit 06afe59
Show file tree
Hide file tree
Showing 32 changed files with 81 additions and 398 deletions.
30 changes: 15 additions & 15 deletions packages/react-pdf/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/react-pdf/package.json
Expand Up @@ -59,7 +59,7 @@
"make-cancellable-promise": "^1.3.1",
"make-event-props": "^1.6.0",
"merge-refs": "^1.2.1",
"pdfjs-dist": "3.11.174",
"pdfjs-dist": "4.0.379",
"prop-types": "^15.6.2",
"tiny-invariant": "^1.0.0",
"warning": "^4.0.0"
Expand Down
6 changes: 2 additions & 4 deletions packages/react-pdf/src/Document.tsx
Expand Up @@ -14,7 +14,7 @@ import makeCancellable from 'make-cancellable-promise';
import clsx from 'clsx';
import invariant from 'tiny-invariant';
import warning from 'warning';
import pdfjs from './pdfjs.js';
import * as pdfjs from 'pdfjs-dist';

import DocumentContext from './DocumentContext.js';

Expand Down Expand Up @@ -199,9 +199,7 @@ export type DocumentProps = {
*/
options?: Options;
/**
* Rendering mode of the document. Can be `"canvas"`, `"custom"`, `"none"` or `"svg"`. If set to `"custom"`, `customRenderer` must also be provided.
*
* **Warning**: SVG render mode is deprecated and will be removed in the future.
* Rendering mode of the document. Can be `"canvas"`, `"custom"` or `"none"``. If set to `"custom"`, `customRenderer` must also be provided.
*
* @default 'canvas'
* @example 'custom'
Expand Down
46 changes: 2 additions & 44 deletions packages/react-pdf/src/Page.spec.tsx
Expand Up @@ -274,7 +274,7 @@ describe('Page', () => {
expect(inputRef.current).toBeInstanceOf(HTMLDivElement);
});

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

const canvasRef = createRef<HTMLCanvasElement>();
Expand Down Expand Up @@ -475,15 +475,13 @@ describe('Page', () => {
},
);

expect.assertions(2);
expect.assertions(1);

await onLoadSuccessPromise;

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

expect(pageCanvas).not.toBeInTheDocument();
expect(pageSVG).not.toBeInTheDocument();
});

it('requests page to be rendered in canvas mode when given renderMode = "canvas"', async () => {
Expand Down Expand Up @@ -535,26 +533,6 @@ describe('Page', () => {
expect(customRenderer).toBeInTheDocument();
});

it('requests page to be rendered in SVG mode when given renderMode = "svg"', async () => {
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();

const { container } = renderWithContext(
<Page onLoadSuccess={onLoadSuccess} pageIndex={0} renderMode="svg" />,
{
linkService,
pdf,
},
);

expect.assertions(1);

await onLoadSuccessPromise;

const pageSVG = container.querySelector('.react-pdf__Page__svg');

expect(pageSVG).toBeInTheDocument();
});

it('requests text content to be rendered by default', async () => {
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();

Expand Down Expand Up @@ -665,26 +643,6 @@ describe('Page', () => {
expect(textLayer).toBeInTheDocument();
});

it('renders TextLayer when given renderMode = "svg"', async () => {
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();

const { container } = renderWithContext(
<Page onLoadSuccess={onLoadSuccess} pageIndex={0} renderMode="svg" renderTextLayer />,
{
linkService,
pdf,
},
);

expect.assertions(1);

await onLoadSuccessPromise;

const textLayer = container.querySelector('.react-pdf__Page__textContent');

expect(textLayer).toBeInTheDocument();
});

it('requests annotations to be rendered by default', async () => {
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();

Expand Down
17 changes: 5 additions & 12 deletions packages/react-pdf/src/Page.tsx
Expand Up @@ -12,8 +12,7 @@ import warning from 'warning';
import PageContext from './PageContext.js';

import Message from './Message.js';
import PageCanvas from './Page/PageCanvas.js';
import PageSVG from './Page/PageSVG.js';
import Canvas from './Page/Canvas.js';
import TextLayer from './Page/TextLayer.js';
import AnnotationLayer from './Page/AnnotationLayer.js';

Expand Down Expand Up @@ -63,13 +62,13 @@ export type PageProps = {
_className?: string;
_enableRegisterUnregisterPage?: boolean;
/**
* Canvas background color. Any valid `canvas.fillStyle` can be used. If you set `renderMode` to `"svg"` this prop will be ignored.
* Canvas background color. Any valid `canvas.fillStyle` can be used.
*
* @example 'transparent'
*/
canvasBackground?: string;
/**
* 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.
* 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.
*
* @example (ref) => { this.myCanvas = ref; }
* @example this.ref
Expand Down Expand Up @@ -271,9 +270,7 @@ export type PageProps = {
*/
renderForms?: boolean;
/**
* Rendering mode of the document. Can be `"canvas"`, `"custom"`, `"none"` or `"svg"`. If set to `"custom"`, `customRenderer` must also be provided.
*
* **Warning**: SVG render mode is deprecated and will be removed in the future.
* Rendering mode of the document. Can be `"canvas"`, `"custom"` or `"none"`. If set to `"custom"`, `customRenderer` must also be provided.
*
* @default 'canvas'
* @example 'custom'
Expand Down Expand Up @@ -569,8 +566,6 @@ const Page: React.FC<PageProps> = function Page(props) {

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

const pageKeyNoScale = `${pageIndex}/${rotate}`;

function renderMainLayer() {
switch (renderMode) {
case 'custom': {
Expand All @@ -583,11 +578,9 @@ const Page: React.FC<PageProps> = function Page(props) {
}
case 'none':
return null;
case 'svg':
return <PageSVG key={`${pageKeyNoScale}_svg`} />;
case 'canvas':
default:
return <PageCanvas key={`${pageKey}_canvas`} canvasRef={canvasRef} />;
return <Canvas key={`${pageKey}_canvas`} canvasRef={canvasRef} />;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-pdf/src/Page/AnnotationLayer.tsx
Expand Up @@ -5,7 +5,7 @@ import makeCancellable from 'make-cancellable-promise';
import clsx from 'clsx';
import invariant from 'tiny-invariant';
import warning from 'warning';
import pdfjs from '../pdfjs.js';
import * as pdfjs from 'pdfjs-dist';

import useDocumentContext from '../shared/hooks/useDocumentContext.js';
import usePageContext from '../shared/hooks/usePageContext.js';
Expand Down
Expand Up @@ -4,7 +4,7 @@ import { render } from '@testing-library/react';

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

import PageCanvas from './PageCanvas.js';
import Canvas from './Canvas.js';

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

Expand Down Expand Up @@ -33,7 +33,7 @@ function renderWithContext(children: React.ReactNode, context: Partial<PageConte
};
}

describe('PageCanvas', () => {
describe('Canvas', () => {
// Loaded page
let page: PDFPageProxy;
let pageWithRendererMocked: PDFPageProxy;
Expand All @@ -59,7 +59,7 @@ describe('PageCanvas', () => {

muteConsole();

renderWithContext(<PageCanvas />, {
renderWithContext(<Canvas />, {
onRenderSuccess,
page: pageWithRendererMocked,
scale: 1,
Expand All @@ -77,7 +77,7 @@ describe('PageCanvas', () => {

muteConsole();

renderWithContext(<PageCanvas />, {
renderWithContext(<Canvas />, {
onRenderError,
page: failingPage,
scale: 1,
Expand All @@ -95,7 +95,7 @@ describe('PageCanvas', () => {
it('passes canvas element to canvasRef properly', () => {
const canvasRef = vi.fn();

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

const { container } = renderWithContext(<PageCanvas />, {
const { container } = renderWithContext(<Canvas />, {
onRenderSuccess,
page: pageWithRendererMocked,
renderTextLayer: false,
Expand All @@ -124,7 +124,7 @@ describe('PageCanvas', () => {
const { func: onGetStructTreeSuccess, promise: onGetStructTreeSuccessPromise } =
makeAsyncCallback();

const { container } = renderWithContext(<PageCanvas />, {
const { container } = renderWithContext(<Canvas />, {
onGetStructTreeSuccess,
page: pageWithRendererMocked,
renderTextLayer: true,
Expand Down
Expand Up @@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import mergeRefs from 'merge-refs';
import invariant from 'tiny-invariant';
import warning from 'warning';
import pdfjs from '../pdfjs.js';
import * as pdfjs from 'pdfjs-dist';

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

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

const ANNOTATION_MODE = pdfjs.AnnotationMode;

type PageCanvasProps = {
type CanvasProps = {
canvasRef?: React.Ref<HTMLCanvasElement>;
};

export default function PageCanvas(props: PageCanvasProps) {
export default function Canvas(props: CanvasProps) {
const pageContext = usePageContext();

invariant(pageContext, 'Unable to find Page context.');
Expand Down
89 changes: 0 additions & 89 deletions packages/react-pdf/src/Page/PageSVG.spec.tsx

This file was deleted.

0 comments on commit 06afe59

Please sign in to comment.