document-viewer-ts
Advanced tools
Comparing version 0.5.0-legacy to 0.5.1-legacy
export declare const renderPDF: (containerDiv: Element, documentUrl: string) => Promise<unknown>; | ||
export declare const renderDocument: (containerDiv: Element) => void; | ||
export declare const renderDocument: (workerSrc: string) => (containerDiv: Element) => void; | ||
export declare const init: (workerSrc: string) => void; |
@@ -125,3 +125,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const ctx = canvas.getContext('2d'); | ||
ctx === null || ctx === void 0 ? void 0 : ctx.fillRect(0, 0, canvas.width, canvas.height); | ||
yield pdfPage.render({ | ||
@@ -210,3 +209,3 @@ canvasContext: ctx || {}, | ||
}; | ||
export const renderDocument = (containerDiv) => { | ||
export const renderDocument = (workerSrc) => (containerDiv) => { | ||
var _a; | ||
@@ -225,2 +224,3 @@ try { | ||
new File([], 'test.txt'); | ||
GlobalWorkerOptions.workerSrc = workerSrc; | ||
renderPDF(containerDiv, documentUrl); | ||
@@ -259,11 +259,10 @@ } | ||
}; | ||
const loadDocuments = () => { | ||
const loadDocuments = (workerSrc) => () => { | ||
const containerDivs = document.getElementsByClassName('viewer-container'); | ||
Array.from(containerDivs).forEach(renderDocument); | ||
Array.from(containerDivs).forEach(renderDocument(workerSrc)); | ||
}; | ||
export const init = (workerSrc) => { | ||
GlobalWorkerOptions.workerSrc = workerSrc; | ||
loadDocuments(); | ||
window.addEventListener('load', loadDocuments); | ||
loadDocuments(workerSrc)(); | ||
window.addEventListener('load', loadDocuments(workerSrc)); | ||
}; | ||
//# sourceMappingURL=base.js.map |
import React, { useEffect, useRef } from 'react'; | ||
import { GlobalWorkerOptions } from 'pdfjs-dist'; | ||
import { renderDocument } from './base'; | ||
export const Viewer = (props) => { | ||
GlobalWorkerOptions.workerSrc = props.workerSrc; | ||
const viewerContainer = useRef(null); | ||
useEffect(() => { | ||
viewerContainer.current && renderDocument(viewerContainer.current); | ||
viewerContainer.current && renderDocument(props.workerSrc)(viewerContainer.current); | ||
return () => { | ||
@@ -10,0 +8,0 @@ viewerContainer.current && viewerContainer.current.firstElementChild && viewerContainer.current.removeChild(viewerContainer.current.firstElementChild); |
export declare const renderPDF: (containerDiv: Element, documentUrl: string) => Promise<unknown>; | ||
export declare const renderDocument: (containerDiv: Element) => void; | ||
export declare const renderDocument: (workerSrc: string) => (containerDiv: Element) => void; | ||
export declare const init: (workerSrc: string) => void; |
@@ -128,3 +128,2 @@ "use strict"; | ||
const ctx = canvas.getContext('2d'); | ||
ctx === null || ctx === void 0 ? void 0 : ctx.fillRect(0, 0, canvas.width, canvas.height); | ||
yield pdfPage.render({ | ||
@@ -214,3 +213,3 @@ canvasContext: ctx || {}, | ||
}; | ||
const renderDocument = (containerDiv) => { | ||
const renderDocument = (workerSrc) => (containerDiv) => { | ||
var _a; | ||
@@ -229,2 +228,3 @@ try { | ||
new File([], 'test.txt'); | ||
pdf_1.GlobalWorkerOptions.workerSrc = workerSrc; | ||
(0, exports.renderPDF)(containerDiv, documentUrl); | ||
@@ -264,12 +264,11 @@ } | ||
exports.renderDocument = renderDocument; | ||
const loadDocuments = () => { | ||
const loadDocuments = (workerSrc) => () => { | ||
const containerDivs = document.getElementsByClassName('viewer-container'); | ||
Array.from(containerDivs).forEach(exports.renderDocument); | ||
Array.from(containerDivs).forEach((0, exports.renderDocument)(workerSrc)); | ||
}; | ||
const init = (workerSrc) => { | ||
pdf_1.GlobalWorkerOptions.workerSrc = workerSrc; | ||
loadDocuments(); | ||
window.addEventListener('load', loadDocuments); | ||
loadDocuments(workerSrc)(); | ||
window.addEventListener('load', loadDocuments(workerSrc)); | ||
}; | ||
exports.init = init; | ||
//# sourceMappingURL=base.js.map |
@@ -5,9 +5,7 @@ "use strict"; | ||
const react_1 = require("react"); | ||
const pdfjs_dist_1 = require("pdfjs-dist"); | ||
const base_1 = require("./base"); | ||
const Viewer = (props) => { | ||
pdfjs_dist_1.GlobalWorkerOptions.workerSrc = props.workerSrc; | ||
const viewerContainer = (0, react_1.useRef)(null); | ||
(0, react_1.useEffect)(() => { | ||
viewerContainer.current && (0, base_1.renderDocument)(viewerContainer.current); | ||
viewerContainer.current && (0, base_1.renderDocument)(props.workerSrc)(viewerContainer.current); | ||
return () => { | ||
@@ -14,0 +12,0 @@ viewerContainer.current && viewerContainer.current.firstElementChild && viewerContainer.current.removeChild(viewerContainer.current.firstElementChild); |
{ | ||
"name": "document-viewer-ts", | ||
"version": "0.5.0-legacy", | ||
"version": "0.5.1-legacy", | ||
"description": "PDF and MS Doc viewer written in TypeScript for React and vanilla JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
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
Sorry, the diff of this file is not supported yet
58988
761