Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wojtekmaj/react-pdf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.1.1
Choose a base ref
...
head repository: wojtekmaj/react-pdf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.1.2
Choose a head ref
  • 4 commits
  • 10 files changed
  • 2 contributors

Commits on Jun 8, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    9cb0a18 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    b370645 View commit details

Commits on Jun 12, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    11027c1 View commit details
  2. v7.1.2

    wojtekmaj committed Jun 12, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    7740ef6 View commit details
Binary file added __mocks__/_untagged.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-pdf",
"version": "7.1.1",
"version": "7.1.2",
"description": "Display PDFs in your React app as easily as if they were images.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
2 changes: 1 addition & 1 deletion sample/parcel/package.json
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@
"description": "A sample page for React-PDF.",
"private": true,
"scripts": {
"build": "parcel build index.html --public-url ./",
"copy-cmaps": "node --loader ts-node/esm ./scripts/copy-cmaps.ts",
"copy-standard-fonts": "node --loader ts-node/esm ./scripts/copy-standard-fonts.ts",
"build": "parcel build index.html --public-url ./",
"dev": "parcel index.html"
},
"author": {
2 changes: 1 addition & 1 deletion sample/parcel2/package.json
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@
"description": "A sample page for React-PDF.",
"private": true,
"scripts": {
"build": "parcel build index.html --public-url ./",
"copy-cmaps": "node --loader ts-node/esm ./scripts/copy-cmaps.ts",
"copy-standard-fonts": "node --loader ts-node/esm ./scripts/copy-standard-fonts.ts",
"build": "parcel build index.html --public-url ./",
"dev": "parcel index.html"
},
"author": {
23 changes: 23 additions & 0 deletions src/Page/TextLayer.spec.tsx
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import type { TextContent } from 'pdfjs-dist/types/src/display/api';
import type { PageContextType } from '../shared/types';

const pdfFile = loadPDF('./__mocks__/_pdf.pdf');
const untaggedPdfFile = loadPDF('./__mocks__/_untagged.pdf');

function renderWithContext(children: React.ReactNode, context: Partial<PageContextType>) {
const { rerender, ...otherResult } = render(
@@ -248,5 +249,27 @@ describe('TextLayer', () => {

expect(container).toHaveTextContent('Test value');
});

it('renders text content properly given customTextRenderer and untagged document', async () => {
const { func: onRenderTextLayerSuccess, promise: onRenderTextLayerSuccessPromise } =
makeAsyncCallback();

const customTextRenderer = () => 'Test value';

const untaggedDoc = await pdfjs.getDocument({ data: untaggedPdfFile.arrayBuffer }).promise;
const untaggedPage = await untaggedDoc.getPage(1);

const { container } = renderWithContext(<TextLayer />, {
customTextRenderer,
onRenderTextLayerSuccess,
page: untaggedPage,
});

expect.assertions(1);

await onRenderTextLayerSuccessPromise;

expect(container).toHaveTextContent('Test value');
});
});
});
8 changes: 6 additions & 2 deletions src/Page/TextLayer.tsx
Original file line number Diff line number Diff line change
@@ -202,7 +202,11 @@ export default function TextLayer() {
layer.append(end);
endElement.current = end;

const layerChildrenDeep = layer.querySelectorAll('.markedContent > *:not(.markedContent');
const hasMarkedContent = Boolean(layer.querySelector('.markedContent'));

const layerChildren = hasMarkedContent
? layer.querySelectorAll('.markedContent > *:not(.markedContent')
: layer.children;

if (customTextRenderer) {
let index = 0;
@@ -211,7 +215,7 @@ export default function TextLayer() {
return;
}

const child = layerChildrenDeep[index];
const child = layerChildren[index];

if (!child) {
return;
5 changes: 4 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
"type": "module",
"scripts": {
"build": "vite build",
"copy-cmaps": "node --experimental-import-meta-resolve --loader ts-node/esm ./scripts/copy-cmaps.ts",
"copy-standard-fonts": "node --experimental-import-meta-resolve --loader ts-node/esm ./scripts/copy-standard-fonts.ts",
"dev": "vite",
"preview": "vite preview"
},
@@ -18,7 +20,8 @@
"prop-types": "^15.6.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-pdf": "portal:../"
"react-pdf": "portal:../",
"ts-node": "^10.9.1"
},
"devDependencies": {
"@types/babel__core": "^7.20.0",
19 changes: 19 additions & 0 deletions test/scripts/copy-cmaps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from 'node:fs';
import path from 'node:path';
import { createRequire } from 'node:module';

function copyDir(from: string, to: string) {
// Ensure target directory exists
fs.mkdirSync(to, { recursive: true });

const files = fs.readdirSync(from);
files.forEach((file) => {
fs.copyFileSync(path.join(from, file), path.join(to, file));
});
}

const require = createRequire(import.meta.url);
const cMapsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps');
const targetDir = path.join('dist', 'assets', 'cmaps');

copyDir(cMapsDir, targetDir);
22 changes: 22 additions & 0 deletions test/scripts/copy-standard-fonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from 'node:fs';
import path from 'node:path';
import { createRequire } from 'node:module';

function copyDir(from: string, to: string) {
// Ensure target directory exists
fs.mkdirSync(to, { recursive: true });

const files = fs.readdirSync(from);
files.forEach((file) => {
fs.copyFileSync(path.join(from, file), path.join(to, file));
});
}

const require = createRequire(import.meta.url);
const standardFontsDir = path.join(
path.dirname(require.resolve('pdfjs-dist/package.json')),
'standard_fonts',
);
const targetDir = path.join('dist', 'assets', 'standard_fonts');

copyDir(standardFontsDir, targetDir);
151 changes: 151 additions & 0 deletions test/yarn.lock
Original file line number Diff line number Diff line change
@@ -271,6 +271,15 @@ __metadata:
languageName: node
linkType: hard

"@cspotcode/source-map-support@npm:^0.8.0":
version: 0.8.1
resolution: "@cspotcode/source-map-support@npm:0.8.1"
dependencies:
"@jridgewell/trace-mapping": 0.3.9
checksum: 5718f267085ed8edb3e7ef210137241775e607ee18b77d95aa5bd7514f47f5019aa2d82d96b3bf342ef7aa890a346fa1044532ff7cc3009e7d24fce3ce6200fa
languageName: node
linkType: hard

"@esbuild/android-arm64@npm:0.17.14":
version: 0.17.14
resolution: "@esbuild/android-arm64@npm:0.17.14"
@@ -460,6 +469,13 @@ __metadata:
languageName: node
linkType: hard

"@jridgewell/resolve-uri@npm:^3.0.3":
version: 3.1.1
resolution: "@jridgewell/resolve-uri@npm:3.1.1"
checksum: f5b441fe7900eab4f9155b3b93f9800a916257f4e8563afbcd3b5a5337b55e52bd8ae6735453b1b745457d9f6cdb16d74cd6220bbdd98cf153239e13f6cbb653
languageName: node
linkType: hard

"@jridgewell/set-array@npm:^1.0.0, @jridgewell/set-array@npm:^1.0.1":
version: 1.1.2
resolution: "@jridgewell/set-array@npm:1.1.2"
@@ -474,6 +490,16 @@ __metadata:
languageName: node
linkType: hard

"@jridgewell/trace-mapping@npm:0.3.9":
version: 0.3.9
resolution: "@jridgewell/trace-mapping@npm:0.3.9"
dependencies:
"@jridgewell/resolve-uri": ^3.0.3
"@jridgewell/sourcemap-codec": ^1.4.10
checksum: d89597752fd88d3f3480845691a05a44bd21faac18e2185b6f436c3b0fd0c5a859fbbd9aaa92050c4052caf325ad3e10e2e1d1b64327517471b7d51babc0ddef
languageName: node
linkType: hard

"@jridgewell/trace-mapping@npm:^0.3.17, @jridgewell/trace-mapping@npm:^0.3.9":
version: 0.3.17
resolution: "@jridgewell/trace-mapping@npm:0.3.17"
@@ -530,6 +556,34 @@ __metadata:
languageName: node
linkType: hard

"@tsconfig/node10@npm:^1.0.7":
version: 1.0.9
resolution: "@tsconfig/node10@npm:1.0.9"
checksum: a33ae4dc2a621c0678ac8ac4bceb8e512ae75dac65417a2ad9b022d9b5411e863c4c198b6ba9ef659e14b9fb609bbec680841a2e84c1172df7a5ffcf076539df
languageName: node
linkType: hard

"@tsconfig/node12@npm:^1.0.7":
version: 1.0.11
resolution: "@tsconfig/node12@npm:1.0.11"
checksum: 5ce29a41b13e7897a58b8e2df11269c5395999e588b9a467386f99d1d26f6c77d1af2719e407621412520ea30517d718d5192a32403b8dfcc163bf33e40a338a
languageName: node
linkType: hard

"@tsconfig/node14@npm:^1.0.0":
version: 1.0.3
resolution: "@tsconfig/node14@npm:1.0.3"
checksum: 19275fe80c4c8d0ad0abed6a96dbf00642e88b220b090418609c4376e1cef81bf16237bf170ad1b341452feddb8115d8dd2e5acdfdea1b27422071163dc9ba9d
languageName: node
linkType: hard

"@tsconfig/node16@npm:^1.0.2":
version: 1.0.4
resolution: "@tsconfig/node16@npm:1.0.4"
checksum: 202319785901f942a6e1e476b872d421baec20cf09f4b266a1854060efbf78cde16a4d256e8bc949d31e6cd9a90f1e8ef8fb06af96a65e98338a2b6b0de0a0ff
languageName: node
linkType: hard

"@types/babel__core@npm:^7.20.0":
version: 7.20.0
resolution: "@types/babel__core@npm:7.20.0"
@@ -618,6 +672,22 @@ __metadata:
languageName: node
linkType: hard

"acorn-walk@npm:^8.1.1":
version: 8.2.0
resolution: "acorn-walk@npm:8.2.0"
checksum: 1715e76c01dd7b2d4ca472f9c58968516a4899378a63ad5b6c2d668bba8da21a71976c14ec5f5b75f887b6317c4ae0b897ab141c831d741dc76024d8745f1ad1
languageName: node
linkType: hard

"acorn@npm:^8.4.1":
version: 8.8.2
resolution: "acorn@npm:8.8.2"
bin:
acorn: bin/acorn
checksum: f790b99a1bf63ef160c967e23c46feea7787e531292bb827126334612c234ed489a0dc2c7ba33156416f0ffa8d25bf2b0fdb7f35c2ba60eb3e960572bece4001
languageName: node
linkType: hard

"agent-base@npm:6, agent-base@npm:^6.0.2":
version: 6.0.2
resolution: "agent-base@npm:6.0.2"
@@ -691,6 +761,13 @@ __metadata:
languageName: node
linkType: hard

"arg@npm:^4.1.0":
version: 4.1.3
resolution: "arg@npm:4.1.3"
checksum: 544af8dd3f60546d3e4aff084d451b96961d2267d668670199692f8d054f0415d86fc5497d0e641e91546f0aa920e7c29e5250e99fc89f5552a34b5d93b77f43
languageName: node
linkType: hard

"balanced-match@npm:^1.0.0":
version: 1.0.2
resolution: "balanced-match@npm:1.0.2"
@@ -854,6 +931,13 @@ __metadata:
languageName: node
linkType: hard

"create-require@npm:^1.1.0":
version: 1.1.1
resolution: "create-require@npm:1.1.1"
checksum: a9a1503d4390d8b59ad86f4607de7870b39cad43d929813599a23714831e81c520bddf61bcdd1f8e30f05fd3a2b71ae8538e946eb2786dc65c2bbc520f692eff
languageName: node
linkType: hard

"csstype@npm:^3.0.2":
version: 3.1.1
resolution: "csstype@npm:3.1.1"
@@ -903,6 +987,13 @@ __metadata:
languageName: node
linkType: hard

"diff@npm:^4.0.1":
version: 4.0.2
resolution: "diff@npm:4.0.2"
checksum: f2c09b0ce4e6b301c221addd83bf3f454c0bc00caa3dd837cf6c127d6edf7223aa2bbe3b688feea110b7f262adbfc845b757c44c8a9f8c0c5b15d8fa9ce9d20d
languageName: node
linkType: hard

"electron-to-chromium@npm:^1.4.284":
version: 1.4.345
resolution: "electron-to-chromium@npm:1.4.345"
@@ -1359,6 +1450,13 @@ __metadata:
languageName: node
linkType: hard

"make-error@npm:^1.1.1":
version: 1.3.6
resolution: "make-error@npm:1.3.6"
checksum: b86e5e0e25f7f777b77fabd8e2cbf15737972869d852a22b7e73c17623928fccb826d8e46b9951501d3f20e51ad74ba8c59ed584f610526a48f8ccf88aaec402
languageName: node
linkType: hard

"make-event-props@npm:^1.5.0":
version: 1.5.0
resolution: "make-event-props@npm:1.5.0"
@@ -1764,6 +1862,7 @@ __metadata:
react: ^18.2.0
react-dom: ^18.2.0
react-pdf: "portal:../"
ts-node: ^10.9.1
typescript: ^5.0.0
vite: ^4.0.0
languageName: unknown
@@ -2045,6 +2144,44 @@ __metadata:
languageName: node
linkType: hard

"ts-node@npm:^10.9.1":
version: 10.9.1
resolution: "ts-node@npm:10.9.1"
dependencies:
"@cspotcode/source-map-support": ^0.8.0
"@tsconfig/node10": ^1.0.7
"@tsconfig/node12": ^1.0.7
"@tsconfig/node14": ^1.0.0
"@tsconfig/node16": ^1.0.2
acorn: ^8.4.1
acorn-walk: ^8.1.1
arg: ^4.1.0
create-require: ^1.1.0
diff: ^4.0.1
make-error: ^1.1.1
v8-compile-cache-lib: ^3.0.1
yn: 3.1.1
peerDependencies:
"@swc/core": ">=1.2.50"
"@swc/wasm": ">=1.2.50"
"@types/node": "*"
typescript: ">=2.7"
peerDependenciesMeta:
"@swc/core":
optional: true
"@swc/wasm":
optional: true
bin:
ts-node: dist/bin.js
ts-node-cwd: dist/bin-cwd.js
ts-node-esm: dist/bin-esm.js
ts-node-script: dist/bin-script.js
ts-node-transpile-only: dist/bin-transpile.js
ts-script: dist/bin-script-deprecated.js
checksum: 090adff1302ab20bd3486e6b4799e90f97726ed39e02b39e566f8ab674fd5bd5f727f43615debbfc580d33c6d9d1c6b1b3ce7d8e3cca3e20530a145ffa232c35
languageName: node
linkType: hard

"typescript@npm:^5.0.0":
version: 5.0.4
resolution: "typescript@npm:5.0.4"
@@ -2104,6 +2241,13 @@ __metadata:
languageName: node
linkType: hard

"v8-compile-cache-lib@npm:^3.0.1":
version: 3.0.1
resolution: "v8-compile-cache-lib@npm:3.0.1"
checksum: 78089ad549e21bcdbfca10c08850022b22024cdcc2da9b168bcf5a73a6ed7bf01a9cebb9eac28e03cd23a684d81e0502797e88f3ccd27a32aeab1cfc44c39da0
languageName: node
linkType: hard

"vite@npm:^4.0.0":
version: 4.3.9
resolution: "vite@npm:4.3.9"
@@ -2205,3 +2349,10 @@ __metadata:
checksum: 343617202af32df2a15a3be36a5a8c0c8545208f3d3dfbc6bb7c3e3b7e8c6f8e7485432e4f3b88da3031a6e20afa7c711eded32ddfb122896ac5d914e75848d5
languageName: node
linkType: hard

"yn@npm:3.1.1":
version: 3.1.1
resolution: "yn@npm:3.1.1"
checksum: 2c487b0e149e746ef48cda9f8bad10fc83693cd69d7f9dcd8be4214e985de33a29c9e24f3c0d6bcf2288427040a8947406ab27f7af67ee9456e6b84854f02dd6
languageName: node
linkType: hard