Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mikecousins/react-pdf

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mikecousins/react-pdf - npm Package Compare versions

Comparing version 5.3.1 to 5.4.0

7

dist/index.d.ts

@@ -5,2 +5,3 @@ import React from 'react';

onDocumentComplete: (numPages: number) => void;
onPageLoaded: () => void;
page?: number;

@@ -15,5 +16,6 @@ scale?: number;

declare const Pdf: {
({ file, onDocumentComplete, page, scale, rotate, cMapUrl, cMapPacked, workerSrc, withCredentials, }: ComponentProps): JSX.Element;
({ file, onDocumentComplete, onPageLoaded, page, scale, rotate, cMapUrl, cMapPacked, workerSrc, withCredentials, }: ComponentProps): JSX.Element;
defaultProps: {
onDocumentComplete: () => void;
onPageLoaded: () => void;
};

@@ -24,2 +26,3 @@ };

file: string;
onPageLoaded: () => void;
scale?: number;

@@ -33,3 +36,3 @@ rotate?: number;

};
export declare const usePdf: ({ canvasEl, file, scale, rotate, page, cMapUrl, cMapPacked, workerSrc, withCredentials, }: HookProps) => any[];
export declare const usePdf: ({ canvasEl, file, onPageLoaded, scale, rotate, page, cMapUrl, cMapPacked, workerSrc, withCredentials, }: HookProps) => any[];
export default Pdf;
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var pdfjs = _interopDefault(require('@bundled-es-modules/pdfjs-dist'));
var pdfjs = _interopDefault(require('pdfjs-dist'));
var React = require('react');

@@ -12,2 +14,3 @@ var React__default = _interopDefault(React);

onDocumentComplete = _ref.onDocumentComplete,
onPageLoaded = _ref.onPageLoaded,
page = _ref.page,

@@ -31,3 +34,4 @@ scale = _ref.scale,

workerSrc: workerSrc,
withCredentials: withCredentials
withCredentials: withCredentials,
onPageLoaded: onPageLoaded
}),

@@ -38,3 +42,3 @@ numPages = _usePdf[1];

onDocumentComplete(numPages);
}, [numPages]);
}, [numPages, onDocumentComplete]);
return React__default.createElement("canvas", {

@@ -46,3 +50,4 @@ ref: canvasEl

Pdf.defaultProps = {
onDocumentComplete: function onDocumentComplete() {}
onDocumentComplete: function onDocumentComplete() {},
onPageLoaded: function onPageLoaded() {}
};

@@ -52,2 +57,3 @@ var usePdf = function usePdf(_ref2) {

file = _ref2.file,
onPageLoaded = _ref2.onPageLoaded,
_ref2$scale = _ref2.scale,

@@ -62,3 +68,3 @@ scale = _ref2$scale === void 0 ? 1 : _ref2$scale,

_ref2$workerSrc = _ref2.workerSrc,
workerSrc = _ref2$workerSrc === void 0 ? '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.228/pdf.worker.js' : _ref2$workerSrc,
workerSrc = _ref2$workerSrc === void 0 ? "//cdnjs.cloudflare.com/ajax/libs/pdf.js/" + pdfjs.version + "/pdf.worker.js" : _ref2$workerSrc,
_ref2$withCredentials = _ref2.withCredentials,

@@ -86,3 +92,3 @@ withCredentials = _ref2$withCredentials === void 0 ? false : _ref2$withCredentials;

pdfjs.getDocument(config).promise.then(setPdf);
}, [file, withCredentials]); // handle changes
}, [file, withCredentials, cMapUrl, cMapPacked]); // handle changes

@@ -123,3 +129,3 @@ React.useEffect(function () {

};
page.render(renderContext);
page.render(renderContext).promise.then(onPageLoaded);
};

@@ -126,0 +132,0 @@

@@ -1,2 +0,2 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("@bundled-es-modules/pdfjs-dist")),r=require("react"),a=e(r),n=function(e){var t=e.file,n=e.onDocumentComplete,c=e.page,i=e.scale,u=e.rotate,l=e.cMapUrl,s=e.cMapPacked,f=e.workerSrc,d=e.withCredentials,p=r.useRef(null),v=o({canvasEl:p,file:t,page:c,scale:i,rotate:u,cMapUrl:l,cMapPacked:s,workerSrc:f,withCredentials:d})[1];return r.useEffect(function(){n(v)},[v]),a.createElement("canvas",{ref:p})};n.defaultProps={onDocumentComplete:function(){}};var o=function(e){var a=e.canvasEl,n=e.file,o=e.scale,c=void 0===o?1:o,i=e.rotate,u=void 0===i?0:i,l=e.page,s=void 0===l?1:l,f=e.cMapUrl,d=e.cMapPacked,p=e.workerSrc,v=void 0===p?"//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.228/pdf.worker.js":p,h=e.withCredentials,w=void 0!==h&&h,g=r.useState(),m=g[0],k=g[1];r.useEffect(function(){t.GlobalWorkerOptions.workerSrc=v},[]),r.useEffect(function(){var e={url:n,withCredentials:w};f&&(e.cMapUrl=f,e.cMapPacked=d),t.getDocument(e).promise.then(k)},[n,w]),r.useEffect(function(){m&&m.getPage(s).then(function(e){return M(e)})},[m,s,c,u,a]);var M=function(e){var t;t=window.devicePixelRatio;var r=e.getViewport({scale:c*t,rotation:0===u?e.rotate:e.rotate+u}),n=a.current;if(n){var o=n.getContext("2d");n.style.width=r.width/t+"px",n.style.height=r.height/t+"px",n.height=r.height,n.width=r.width,e.render({canvasContext:o,viewport:r})}};return[r.useMemo(function(){return!m},[m]),r.useMemo(function(){return m?m._pdfInfo.numPages:null},[m])]};exports.default=n,exports.usePdf=o;
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("pdfjs-dist")),r=require("react"),o=e(r),a=function(e){var t=e.file,a=e.onDocumentComplete,i=e.onPageLoaded,c=e.page,u=e.scale,d=e.rotate,s=e.cMapUrl,f=e.cMapPacked,l=e.workerSrc,p=e.withCredentials,v=r.useRef(null),h=n({canvasEl:v,file:t,page:c,scale:u,rotate:d,cMapUrl:s,cMapPacked:f,workerSrc:l,withCredentials:p,onPageLoaded:i})[1];return r.useEffect((function(){a(h)}),[h,a]),o.createElement("canvas",{ref:v})};a.defaultProps={onDocumentComplete:function(){},onPageLoaded:function(){}};var n=function(e){var o=e.canvasEl,a=e.file,n=e.onPageLoaded,i=e.scale,c=void 0===i?1:i,u=e.rotate,d=void 0===u?0:u,s=e.page,f=void 0===s?1:s,l=e.cMapUrl,p=e.cMapPacked,v=e.workerSrc,h=void 0===v?"//cdnjs.cloudflare.com/ajax/libs/pdf.js/"+t.version+"/pdf.worker.js":v,g=e.withCredentials,w=void 0!==g&&g,P=r.useState(),m=P[0],M=P[1];r.useEffect((function(){t.GlobalWorkerOptions.workerSrc=h}),[]),r.useEffect((function(){var e={url:a,withCredentials:w};l&&(e.cMapUrl=l,e.cMapPacked=p),t.getDocument(e).promise.then(M)}),[a,w,l,p]),r.useEffect((function(){m&&m.getPage(f).then((function(e){return k(e)}))}),[m,f,c,d,o]);var k=function(e){var t;t=window.devicePixelRatio;var r=e.getViewport({scale:c*t,rotation:0===d?e.rotate:e.rotate+d}),a=o.current;if(a){var i=a.getContext("2d");a.style.width=r.width/t+"px",a.style.height=r.height/t+"px",a.height=r.height,a.width=r.width,e.render({canvasContext:i,viewport:r}).promise.then(n)}};return[r.useMemo((function(){return!m}),[m]),r.useMemo((function(){return m?m._pdfInfo.numPages:null}),[m])]};exports.default=a,exports.usePdf=n;
//# sourceMappingURL=react-pdf.cjs.production.min.js.map

@@ -1,2 +0,2 @@

import pdfjs from '@bundled-es-modules/pdfjs-dist';
import pdfjs from 'pdfjs-dist';
import React, { useRef, useEffect, useState, useMemo } from 'react';

@@ -7,2 +7,3 @@

onDocumentComplete = _ref.onDocumentComplete,
onPageLoaded = _ref.onPageLoaded,
page = _ref.page,

@@ -26,3 +27,4 @@ scale = _ref.scale,

workerSrc: workerSrc,
withCredentials: withCredentials
withCredentials: withCredentials,
onPageLoaded: onPageLoaded
}),

@@ -33,3 +35,3 @@ numPages = _usePdf[1];

onDocumentComplete(numPages);
}, [numPages]);
}, [numPages, onDocumentComplete]);
return React.createElement("canvas", {

@@ -41,3 +43,4 @@ ref: canvasEl

Pdf.defaultProps = {
onDocumentComplete: function onDocumentComplete() {}
onDocumentComplete: function onDocumentComplete() {},
onPageLoaded: function onPageLoaded() {}
};

@@ -47,2 +50,3 @@ var usePdf = function usePdf(_ref2) {

file = _ref2.file,
onPageLoaded = _ref2.onPageLoaded,
_ref2$scale = _ref2.scale,

@@ -57,3 +61,3 @@ scale = _ref2$scale === void 0 ? 1 : _ref2$scale,

_ref2$workerSrc = _ref2.workerSrc,
workerSrc = _ref2$workerSrc === void 0 ? '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.2.228/pdf.worker.js' : _ref2$workerSrc,
workerSrc = _ref2$workerSrc === void 0 ? "//cdnjs.cloudflare.com/ajax/libs/pdf.js/" + pdfjs.version + "/pdf.worker.js" : _ref2$workerSrc,
_ref2$withCredentials = _ref2.withCredentials,

@@ -81,3 +85,3 @@ withCredentials = _ref2$withCredentials === void 0 ? false : _ref2$withCredentials;

pdfjs.getDocument(config).promise.then(setPdf);
}, [file, withCredentials]); // handle changes
}, [file, withCredentials, cMapUrl, cMapPacked]); // handle changes

@@ -118,3 +122,3 @@ useEffect(function () {

};
page.render(renderContext);
page.render(renderContext).promise.then(onPageLoaded);
};

@@ -121,0 +125,0 @@

{
"name": "@mikecousins/react-pdf",
"version": "5.3.1",
"version": "5.4.0",
"description": "Simple React component to wrap up PDF.js. The easiest way to render PDFs in your React app.",

@@ -18,2 +18,3 @@ "author": "mikecousins",

"test": "tsdx test --env=jsdom",
"test:coverage": "CI=true tsdx test --color --coverage",
"lint": "tsdx lint src",

@@ -37,16 +38,17 @@ "netlify": "yarn && yarn build && cd example && yarn && yarn build"

"devDependencies": {
"@testing-library/react": "9.1.0",
"@types/jest": "24.0.18",
"@types/react": "16.9.2",
"@types/react-dom": "16.9.0",
"husky": "3.0.5",
"react": "16.9.0",
"react-dom": "16.9.0",
"tsdx": "0.9.2",
"@testing-library/react": "9.4.0",
"@types/jest": "24.0.25",
"@types/pdfjs-dist": "2.1.3",
"@types/react": "16.9.17",
"@types/react-dom": "16.9.4",
"husky": "3.1.0",
"react": "16.12.0",
"react-dom": "16.12.0",
"tsdx": "0.12.0",
"tslib": "1.10.0",
"typescript": "3.6.3"
"typescript": "3.7.4"
},
"dependencies": {
"@bundled-es-modules/pdfjs-dist": "2.2.228-alpha1"
"pdfjs-dist": "2.2.228"
}
}

@@ -125,2 +125,6 @@ # react-pdf-js

## onPageLoaded
Allows you to specify a callback that is called when the PDF page will be fully loaded into the DOM.
## page

@@ -127,0 +131,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc