Skip to content

Commit

Permalink
Merge branch 'main' into feat/1494/add-accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj authored Jun 5, 2023
2 parents 19a52b7 + 72f4da8 commit a2d7164
Show file tree
Hide file tree
Showing 33 changed files with 1,035 additions and 222 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{
"files": ["sample/**", "test/**"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"import/no-unresolved": "off"
}
}
Expand Down
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ React-PDF is under constant development. This documentation is written for React

React-PDF supports all modern browsers. It is tested with the latest versions of Chrome, Edge, Safari, Firefox, and Opera.

The following browsers are supported in React-PDF v7:
The following browsers are supported out of the box in React-PDF v7:

- Chrome ≥88
- Edge ≥88
- Safari ≥14.1
- Firefox ESR
- Chrome ≥92
- Edge ≥92
- Safari ≥15.4
- Firefox ≥90

You may extend the list of supported browsers by providing additional polyfills (e.g. for `Promise.allSettled`) and configuring your bundler to transpile `pdfjs-dist`.
You may extend the list of supported browsers by providing additional polyfills (e.g. for `Array.prototype.at` or `Promise.allSettled`) and either configuring your bundler to transpile `pdfjs-dist` or using [legacy PDF.js worker](#legacy-pdfjs-worker).

If you need to support older browsers, you will need to use React-PDF v6 or v5.

Expand Down Expand Up @@ -121,6 +121,9 @@ pdfjs.GlobalWorkerOptions.workerSrc = new URL(
).toString();
```

> **Note**
> pnpm requires an `.npmrc` file with `public-hoist-pattern[]=pdfjs-dist` for this to work.
<details>
<summary>See more examples</summary>

Expand Down Expand Up @@ -174,6 +177,25 @@ import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js`;
```

#### Legacy PDF.js worker

If you need to support older browsers, you may use legacy PDF.js worker. To do so, follow the instructions above, but replace `/build/` with `legacy/build/` in PDF.js worker import path, for example:

```diff
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
- 'pdfjs-dist/build/pdf.worker.min.js',
+ 'pdfjs-dist/legacy/build/pdf.worker.min.js',
import.meta.url,
).toString();
```

or:

```diff
-pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js`;
+pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.js`;
```

### Support for annotations

If you want to use annotations (e.g. links) in PDFs rendered by React-PDF, then you would need to include stylesheet necessary for annotations to be correctly displayed like so:
Expand Down
1 change: 0 additions & 1 deletion __mocks__/styleMock.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-pdf",
"version": "7.0.0-beta.4",
"version": "7.0.3",
"description": "Display PDFs in your React app as easily as if they were images.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -49,7 +49,7 @@
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.0",
"eslint": "^8.26.0",
"eslint-config-wojtekmaj": "^0.8.3",
"eslint-config-wojtekmaj": "^0.8.4",
"husky": "^8.0.0",
"jsdom": "^21.1.0",
"prettier": "^2.7.0",
Expand Down
4 changes: 4 additions & 0 deletions sample/webpack4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
"@babel/preset-env": "^7.21.0",
"@babel/preset-react": "^7.18.0",
"@babel/preset-typescript": "^7.21.0",
"@types/copy-webpack-plugin": "^6.4.0",
"@types/node": "*",
"babel-loader": "^8.0.0",
"copy-webpack-plugin": "^6.4.0",
"css-loader": "^5.2.0",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^4.5.0",
"style-loader": "^2.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.0",
"webpack": "^4.46.0",
"webpack-cli": "^4.7.0",
"webpack-dev-server": "^4.13.1"
Expand Down
2 changes: 1 addition & 1 deletion sample/webpack4/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react",
"module": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"noUncheckedIndexedAccess": true,
"outDir": "dist",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const webpack = require('webpack');
const path = require('node:path');
import webpack from 'webpack';
import path from 'node:path';

const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
import CopyWebpackPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import type { Configuration } from 'webpack';
import 'webpack-dev-server';

const isProduction = process.env.NODE_ENV === 'production';

Expand All @@ -12,7 +15,7 @@ const standardFontsDir = path.join(
'standard_fonts',
);

module.exports = {
const config = {
mode: isProduction ? 'production' : 'development',
bail: isProduction,
context: path.join(__dirname),
Expand Down Expand Up @@ -61,4 +64,6 @@ module.exports = {
hot: true, // enable HMR on the server
port: 3000,
},
};
} satisfies Configuration;

export default config;
Loading

0 comments on commit a2d7164

Please sign in to comment.