diff --git a/dist/PDFPasswordForm.d.ts b/dist/PDFPasswordForm.d.ts deleted file mode 100644 index b9e6011..0000000 --- a/dist/PDFPasswordForm.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -type Props = { - isPasswordInvalid?: boolean; - onSubmit?: (password: string) => void; - onPasswordChange?: (password: string) => void; - onPasswordFieldFocus?: (isFocused: boolean) => void; -}; -declare function PDFPasswordForm({ isPasswordInvalid, onSubmit, onPasswordChange, onPasswordFieldFocus }: Props): React.JSX.Element; -declare namespace PDFPasswordForm { - var propTypes: { - /** If the submitted password is invalid (show an error message) */ - isPasswordInvalid: PropTypes.Requireable; - /** Notify parent that the password form has been submitted */ - onSubmit: PropTypes.Requireable<(...args: any[]) => any>; - /** Notify parent that the password has been updated/edited */ - onPasswordChange: PropTypes.Requireable<(...args: any[]) => any>; - /** Notify parent that a text field has been focused or blurred */ - onPasswordFieldFocus: PropTypes.Requireable<(...args: any[]) => any>; - }; - var defaultProps: { - isPasswordInvalid: boolean; - onSubmit: () => void; - onPasswordChange: () => void; - onPasswordFieldFocus: () => void; - }; - var displayName: string; -} -export type { Props as PDFPasswordFormProps }; -export default PDFPasswordForm; -//# sourceMappingURL=PDFPasswordForm.d.ts.map \ No newline at end of file diff --git a/dist/PDFPasswordForm.d.ts.map b/dist/PDFPasswordForm.d.ts.map deleted file mode 100644 index 66b0b3f..0000000 --- a/dist/PDFPasswordForm.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"PDFPasswordForm.d.ts","sourceRoot":"","sources":["../src/PDFPasswordForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2E,MAAM,OAAO,CAAC;AAChG,OAAO,SAAS,MAAM,YAAY,CAAC;AAKnC,KAAK,KAAK,GAAG;IACT,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,oBAAoB,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD,CAAC;AAuBF,iBAAS,eAAe,CAAC,EAAC,iBAAiB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,oBAAoB,EAAC,EAAE,KAAK,qBAqHpG;kBArHQ,eAAe;;QApBpB,mEAAmE;;QAGnE,8DAA8D;;QAG9D,8DAA8D;;QAG9D,kEAAkE;;;;;;;;;;;AAsItE,YAAY,EAAC,KAAK,IAAI,oBAAoB,EAAC,CAAC;AAC5C,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/PDFPasswordForm.js b/dist/PDFPasswordForm.js deleted file mode 100644 index e704a6e..0000000 --- a/dist/PDFPasswordForm.js +++ /dev/null @@ -1,117 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const react_1 = __importStar(require("react")); -const prop_types_1 = __importDefault(require("prop-types")); -const styles_1 = require("./styles"); -const helpers_1 = require("./helpers"); -const propTypes = { - /** If the submitted password is invalid (show an error message) */ - isPasswordInvalid: prop_types_1.default.bool, - /** Notify parent that the password form has been submitted */ - onSubmit: prop_types_1.default.func, - /** Notify parent that the password has been updated/edited */ - onPasswordChange: prop_types_1.default.func, - /** Notify parent that a text field has been focused or blurred */ - onPasswordFieldFocus: prop_types_1.default.func, -}; -const defaultProps = { - isPasswordInvalid: false, - onSubmit: () => { }, - onPasswordChange: () => { }, - onPasswordFieldFocus: () => { }, -}; -function PDFPasswordForm({ isPasswordInvalid, onSubmit, onPasswordChange, onPasswordFieldFocus }) { - const [password, setPassword] = (0, react_1.useState)(''); - const [validationErrorText, setValidationErrorText] = (0, react_1.useState)(''); - const [shouldShowForm, setShouldShowForm] = (0, react_1.useState)(false); - const textInputRef = (0, react_1.useRef)(null); - const errorText = (0, react_1.useMemo)(() => { - if (isPasswordInvalid) { - return 'Incorrect password. Please try again.'; - } - if (validationErrorText) { - return validationErrorText; - } - return ''; - }, [isPasswordInvalid, validationErrorText]); - const updatePassword = (event) => { - const newPassword = event.target.value; - setPassword(newPassword); - onPasswordChange === null || onPasswordChange === void 0 ? void 0 : onPasswordChange(newPassword); - setValidationErrorText(''); - }; - const validate = () => { - if (!isPasswordInvalid && password) { - return true; - } - if (!password) { - setValidationErrorText('Password required. Pleaser enter.'); - } - return false; - }; - const submitPassword = (e) => { - e.preventDefault(); - if (!validate()) { - return; - } - onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit(password); - }; - const validateAndNotifyPasswordBlur = () => { - validate(); - onPasswordFieldFocus === null || onPasswordFieldFocus === void 0 ? void 0 : onPasswordFieldFocus(false); - }; - if (!shouldShowForm) { - return (react_1.default.createElement("div", { style: styles_1.pdfPasswordFormStyles.container }, - react_1.default.createElement("p", { style: styles_1.pdfPasswordFormStyles.infoMessage }, - "This PDF is password protected.", - react_1.default.createElement("br", null), - "Please\u00A0", - react_1.default.createElement("span", { style: styles_1.pdfPasswordFormStyles.infoMessageButton, "aria-hidden": "true", onClick: () => setShouldShowForm(true) }, "enter the password"), - "\u00A0to view it."))); - } - return (react_1.default.createElement("div", { style: styles_1.pdfPasswordFormStyles.container }, - react_1.default.createElement("p", { style: styles_1.pdfPasswordFormStyles.infoMessage }, "View PDF"), - react_1.default.createElement("form", { style: styles_1.pdfPasswordFormStyles.form, onSubmit: submitPassword }, - react_1.default.createElement("label", { style: styles_1.pdfPasswordFormStyles.inputLabel, htmlFor: "password" }, - "Password:", - react_1.default.createElement("input", { style: styles_1.pdfPasswordFormStyles.input, ref: textInputRef, id: "password", value: password, - /** - * This is a workaround to bypass Safari's autofill odd behaviour. - * This tricks the browser not to fill the username somewhere else and still fill the password correctly. - */ - autoComplete: (0, helpers_1.isSafari)() ? 'username' : 'off', - // eslint-disable-next-line jsx-a11y/no-autofocus - autoFocus: true, type: "password", onFocus: () => onPasswordFieldFocus === null || onPasswordFieldFocus === void 0 ? void 0 : onPasswordFieldFocus(true), onBlur: validateAndNotifyPasswordBlur, onChange: updatePassword })), - !!errorText && react_1.default.createElement("p", { style: styles_1.pdfPasswordFormStyles.errorMessage }, errorText), - react_1.default.createElement("input", { style: styles_1.pdfPasswordFormStyles.confirmButton, type: "submit", value: "Confirm" })))); -} -PDFPasswordForm.propTypes = propTypes; -PDFPasswordForm.defaultProps = defaultProps; -PDFPasswordForm.displayName = 'PDFPasswordForm'; -exports.default = PDFPasswordForm; diff --git a/dist/PDFPreviewer.d.ts b/dist/PDFPreviewer.d.ts deleted file mode 100644 index ce411bd..0000000 --- a/dist/PDFPreviewer.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -import React from 'react'; -import type { CSSProperties, ReactNode } from 'react'; -import PropTypes from 'prop-types'; -import 'react-pdf/dist/Page/AnnotationLayer.css'; -import 'react-pdf/dist/Page/TextLayer.css'; -import { type PDFPasswordFormProps } from './PDFPasswordForm'; -type Props = { - file: string; - pageMaxWidth: number; - isSmallScreen: boolean; - maxCanvasWidth: number | null; - maxCanvasHeight: number | null; - maxCanvasArea: number | null; - renderPasswordForm?: ({ isPasswordInvalid, onSubmit, onPasswordChange }: Omit) => ReactNode | null; - LoadingComponent?: ReactNode; - ErrorComponent?: ReactNode; - containerStyle?: CSSProperties; - contentContainerStyle?: CSSProperties; -}; -declare function PDFPreviewer({ file, pageMaxWidth, isSmallScreen, maxCanvasWidth, maxCanvasHeight, maxCanvasArea, LoadingComponent, ErrorComponent, renderPasswordForm, containerStyle, contentContainerStyle, }: Props): React.JSX.Element; -declare namespace PDFPreviewer { - var propTypes: { - file: PropTypes.Validator; - pageMaxWidth: PropTypes.Validator; - isSmallScreen: PropTypes.Validator; - maxCanvasWidth: PropTypes.Requireable; - maxCanvasHeight: PropTypes.Requireable; - maxCanvasArea: PropTypes.Requireable; - renderPasswordForm: PropTypes.Requireable<(...args: any[]) => any>; - LoadingComponent: PropTypes.Requireable; - ErrorComponent: PropTypes.Requireable; - containerStyle: PropTypes.Requireable; - contentContainerStyle: PropTypes.Requireable; - }; - var defaultProps: { - maxCanvasWidth: null; - maxCanvasHeight: null; - maxCanvasArea: null; - renderPasswordForm: null; - LoadingComponent: React.JSX.Element; - ErrorComponent: React.JSX.Element; - containerStyle: {}; - contentContainerStyle: {}; - }; -} -declare const _default: React.MemoExoticComponent; -export default _default; -//# sourceMappingURL=PDFPreviewer.d.ts.map \ No newline at end of file diff --git a/dist/PDFPreviewer.d.ts.map b/dist/PDFPreviewer.d.ts.map deleted file mode 100644 index e2215d4..0000000 --- a/dist/PDFPreviewer.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"PDFPreviewer.d.ts","sourceRoot":"","sources":["../src/PDFPreviewer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6D,MAAM,OAAO,CAAC;AAClF,OAAO,KAAK,EAAC,aAAa,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAEpD,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,OAAO,yCAAyC,CAAC;AACjD,OAAO,mCAAmC,CAAC;AAI3C,OAAwB,EAAC,KAAK,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AAK7E,KAAK,KAAK,GAAG;IACT,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,kBAAkB,CAAC,EAAE,CAAC,EAAC,iBAAiB,EAAE,QAAQ,EAAE,gBAAgB,EAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,KAAK,SAAS,GAAG,IAAI,CAAC;IAC/I,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAC7B,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,qBAAqB,CAAC,EAAE,aAAa,CAAC;CACzC,CAAC;AAkCF,iBAAS,YAAY,CAAC,EAClB,IAAI,EACJ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,qBAAqB,GACxB,EAAE,KAAK,qBA4LP;kBAxMQ,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;AA8MrB,wBAAkC"} \ No newline at end of file diff --git a/dist/PDFPreviewer.js b/dist/PDFPreviewer.js deleted file mode 100644 index 8aabc9a..0000000 --- a/dist/PDFPreviewer.js +++ /dev/null @@ -1,197 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const react_1 = __importStar(require("react")); -const times_1 = __importDefault(require("lodash/times")); -const prop_types_1 = __importDefault(require("prop-types")); -const react_window_1 = require("react-window"); -const react_pdf_1 = require("react-pdf"); -require("react-pdf/dist/Page/AnnotationLayer.css"); -require("react-pdf/dist/Page/TextLayer.css"); -const styles_1 = require("./styles"); -const PDFPasswordForm_1 = __importDefault(require("./PDFPasswordForm")); -const PageRenderer_1 = __importDefault(require("./PageRenderer")); -const constants_1 = require("./constants"); -const helpers_1 = require("./helpers"); -const propTypes = { - file: prop_types_1.default.string.isRequired, - pageMaxWidth: prop_types_1.default.number.isRequired, - isSmallScreen: prop_types_1.default.bool.isRequired, - maxCanvasWidth: prop_types_1.default.number, - maxCanvasHeight: prop_types_1.default.number, - maxCanvasArea: prop_types_1.default.number, - renderPasswordForm: prop_types_1.default.func, - LoadingComponent: prop_types_1.default.node, - ErrorComponent: prop_types_1.default.node, - // eslint-disable-next-line react/forbid-prop-types - containerStyle: prop_types_1.default.object, - // eslint-disable-next-line react/forbid-prop-types - contentContainerStyle: prop_types_1.default.object, -}; -const defaultProps = { - maxCanvasWidth: null, - maxCanvasHeight: null, - maxCanvasArea: null, - renderPasswordForm: null, - LoadingComponent: react_1.default.createElement("p", null, "Loading..."), - ErrorComponent: react_1.default.createElement("p", null, "Failed to load the PDF file :("), - containerStyle: {}, - contentContainerStyle: {}, -}; -// @ts-expect-error - It is a recommended step for import worker - https://github.com/wojtekmaj/react-pdf/blob/main/packages/react-pdf/README.md#import-worker-recommended -react_pdf_1.pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.js', import.meta.url).toString(); -function PDFPreviewer({ file, pageMaxWidth, isSmallScreen, maxCanvasWidth, maxCanvasHeight, maxCanvasArea, LoadingComponent, ErrorComponent, renderPasswordForm, containerStyle, contentContainerStyle, }) { - const [pageViewports, setPageViewports] = (0, react_1.useState)([]); - const [numPages, setNumPages] = (0, react_1.useState)(0); - const [containerWidth, setContainerWidth] = (0, react_1.useState)(0); - const [containerHeight, setContainerHeight] = (0, react_1.useState)(0); - const [shouldRequestPassword, setShouldRequestPassword] = (0, react_1.useState)(false); - const [isPasswordInvalid, setIsPasswordInvalid] = (0, react_1.useState)(false); - const containerRef = (0, react_1.useRef)(null); - const onPasswordCallbackRef = (0, react_1.useRef)(null); - /** - * Calculate the devicePixelRatio the page should be rendered with - * Each platform has a different default devicePixelRatio and different canvas limits, we need to verify that - * with the default devicePixelRatio it will be able to diplay the pdf correctly, if not we must change the devicePixelRatio. - * @param {Number} width of the page - * @param {Number} height of the page - * @returns {Number} devicePixelRatio for this page on this platform - */ - const getDevicePixelRatio = (width, height) => { - if (!maxCanvasWidth || !maxCanvasHeight || !maxCanvasArea) { - return undefined; - } - const nbPixels = width * height; - const ratioHeight = maxCanvasHeight / height; - const ratioWidth = maxCanvasWidth / width; - const ratioArea = Math.sqrt(maxCanvasArea / nbPixels); - const ratio = Math.min(ratioHeight, ratioArea, ratioWidth); - if (ratio > window.devicePixelRatio) { - return undefined; - } - return ratio; - }; - /** - * Calculates a proper page width. - * It depends on a screen size. Also, the app should take into account the page borders. - */ - const calculatePageWidth = (0, react_1.useCallback)(() => { - const pageWidthOnLargeScreen = Math.min(containerWidth - constants_1.LARGE_SCREEN_SIDE_SPACING * 2, pageMaxWidth); - const pageWidth = isSmallScreen ? containerWidth : pageWidthOnLargeScreen; - return pageWidth + constants_1.PAGE_BORDER * 2; - }, [containerWidth, pageMaxWidth, isSmallScreen]); - /** - * Calculates a proper page height. The method should be called only when there are page viewports. - * It is based on a ratio between the specific page viewport width and provided page width. - * Also, the app should take into account the page borders. - */ - const calculatePageHeight = (0, react_1.useCallback)((pageIndex) => { - if (pageViewports.length === 0) { - return 0; - } - const pageWidth = calculatePageWidth(); - const { width: pageViewportWidth, height: pageViewportHeight } = pageViewports[pageIndex]; - const scale = pageWidth / pageViewportWidth; - return pageViewportHeight * scale + constants_1.PAGE_BORDER * 2; - }, [pageViewports, calculatePageWidth]); - const estimatedPageHeight = calculatePageHeight(0); - const pageWidth = calculatePageWidth(); - /** - * Upon successful document load, combine an array of page viewports, - * set the number of pages on PDF, - * hide/reset PDF password form, and notify parent component that - * user input is no longer required. - */ - const onDocumentLoadSuccess = (pdf) => { - Promise.all((0, times_1.default)(pdf.numPages, (index) => { - const pageNumber = index + 1; - return pdf.getPage(pageNumber).then((page) => page.getViewport({ scale: 1 })); - })).then((viewports) => { - setPageViewports(viewports); - setNumPages(pdf.numPages); - setShouldRequestPassword(false); - setIsPasswordInvalid(false); - }, () => { }); - }; - /** - * Initiate password challenge process. The react-pdf/Document - * component calls this handler to indicate that a PDF requires a - * password, or to indicate that a previously provided password was - * invalid. - * - * The PasswordResponses constants used below were copied from react-pdf - * because they're not exported in entry.webpack. - */ - const initiatePasswordChallenge = (callback, reason) => { - onPasswordCallbackRef.current = callback; - if (reason === constants_1.PDF_PASSWORD_FORM_RESPONSES.NEED_PASSWORD) { - setShouldRequestPassword(true); - } - else if (reason === constants_1.PDF_PASSWORD_FORM_RESPONSES.INCORRECT_PASSWORD) { - setShouldRequestPassword(true); - setIsPasswordInvalid(true); - } - }; - /** - * Send password to react-pdf via its callback so that it can attempt to load - * the PDF. - */ - const attemptPDFLoad = (password) => { - var _a; - (_a = onPasswordCallbackRef.current) === null || _a === void 0 ? void 0 : _a.call(onPasswordCallbackRef, password); - }; - /** - * Render a form to handle password typing. - * The method renders the passed or default component. - */ - const internalRenderPasswordForm = (0, react_1.useCallback)(() => { - const onSubmit = attemptPDFLoad; - const onPasswordChange = () => setIsPasswordInvalid(false); - if (typeof renderPasswordForm === 'function') { - return renderPasswordForm({ - isPasswordInvalid, - onSubmit, - onPasswordChange, - }); - } - return (react_1.default.createElement(PDFPasswordForm_1.default, { isPasswordInvalid: isPasswordInvalid, onSubmit: onSubmit, onPasswordChange: onPasswordChange })); - }, [isPasswordInvalid, attemptPDFLoad, setIsPasswordInvalid, renderPasswordForm]); - (0, react_1.useLayoutEffect)(() => { - var _a, _b, _c, _d; - setContainerWidth((_b = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) !== null && _b !== void 0 ? _b : 0); - setContainerHeight((_d = (_c = containerRef.current) === null || _c === void 0 ? void 0 : _c.clientHeight) !== null && _d !== void 0 ? _d : 0); - }, []); - return (react_1.default.createElement("div", { ref: containerRef, style: Object.assign(Object.assign({}, styles_1.pdfPreviewerStyles.container), containerStyle) }, - react_1.default.createElement("div", { style: Object.assign(Object.assign({}, styles_1.pdfPreviewerStyles.innerContainer), (shouldRequestPassword ? styles_1.pdfPreviewerStyles.invisibleContainer : {})) }, - react_1.default.createElement(react_pdf_1.Document, { file: file, options: constants_1.DEFAULT_DOCUMENT_OPTIONS, externalLinkTarget: constants_1.DEFAULT_EXTERNAL_LINK_TARGET, error: ErrorComponent, loading: LoadingComponent, onLoadSuccess: onDocumentLoadSuccess, onPassword: initiatePasswordChallenge }, pageViewports.length > 0 && (react_1.default.createElement(react_window_1.VariableSizeList, { style: Object.assign(Object.assign({}, styles_1.pdfPreviewerStyles.list), contentContainerStyle), outerRef: helpers_1.setListAttributes, width: isSmallScreen ? pageWidth : containerWidth, height: containerHeight, itemCount: numPages, itemSize: calculatePageHeight, estimatedItemSize: calculatePageHeight(0), itemData: { pageWidth, estimatedPageHeight, calculatePageHeight, getDevicePixelRatio } }, PageRenderer_1.default)))), - shouldRequestPassword && internalRenderPasswordForm())); -} -PDFPasswordForm_1.default.displayName = 'PDFPreviewer'; -PDFPreviewer.propTypes = propTypes; -PDFPreviewer.defaultProps = defaultProps; -exports.default = (0, react_1.memo)(PDFPreviewer); diff --git a/dist/PageRenderer.d.ts b/dist/PageRenderer.d.ts deleted file mode 100644 index 7eabbec..0000000 --- a/dist/PageRenderer.d.ts +++ /dev/null @@ -1,36 +0,0 @@ -import React, { type CSSProperties } from 'react'; -import PropTypes from 'prop-types'; -type Props = { - index: number; - style: CSSProperties; - data: { - pageWidth: number; - estimatedPageHeight: number; - calculatePageHeight: (pageIndex: number) => number; - getDevicePixelRatio: (width: number, height: number) => number | undefined; - }; -}; -declare function PageRenderer({ index, style, data }: Props): React.JSX.Element; -declare namespace PageRenderer { - var displayName: string; - var propTypes: { - /** Index of the PDF page to be displayed passed by VariableSizeList */ - index: PropTypes.Validator; - /** Page extra data passed by VariableSizeList's data prop */ - data: PropTypes.Validator; - /** The estimated height of a single page in the document */ - estimatedPageHeight: PropTypes.Validator; - /** Function that calculates the height of a page given its index */ - calculatePageHeight: PropTypes.Validator<(...args: any[]) => any>; - /** Function that calculates the pixel ratio for a page given its calculated width and height */ - getDevicePixelRatio: PropTypes.Validator<(...args: any[]) => any>; - }>>>; - /** Additional style props passed by VariableSizeList */ - style: PropTypes.Validator; - }; -} -declare const _default: React.MemoExoticComponent; -export default _default; -//# sourceMappingURL=PageRenderer.d.ts.map \ No newline at end of file diff --git a/dist/PageRenderer.d.ts.map b/dist/PageRenderer.d.ts.map deleted file mode 100644 index 4422ef4..0000000 --- a/dist/PageRenderer.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"PageRenderer.d.ts","sourceRoot":"","sources":["../src/PageRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAO,KAAK,aAAa,EAAC,MAAM,OAAO,CAAC;AACtD,OAAO,SAAS,MAAM,YAAY,CAAC;AAKnC,KAAK,KAAK,GAAG;IACT,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE;QACF,SAAS,EAAE,MAAM,CAAC;QAClB,mBAAmB,EAAE,MAAM,CAAC;QAC5B,mBAAmB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;QACnD,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;KAC9E,CAAC;CACL,CAAC;AAuBF,iBAAS,YAAY,CAAC,EAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAC,EAAE,KAAK,qBAuBhD;kBAvBQ,YAAY;;;QApBjB,uEAAuE;;QAGvE,6DAA6D;;YAEzD,6CAA6C;;YAE7C,4DAA4D;;YAE5D,oEAAoE;;YAEpE,gGAAgG;;;QAIpG,wDAAwD;;;;;AAiC5D,wBAAkC"} \ No newline at end of file diff --git a/dist/PageRenderer.js b/dist/PageRenderer.js deleted file mode 100644 index c05d8cd..0000000 --- a/dist/PageRenderer.js +++ /dev/null @@ -1,68 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const react_1 = __importStar(require("react")); -const prop_types_1 = __importDefault(require("prop-types")); -const react_pdf_1 = require("react-pdf"); -const styles_1 = require("./styles"); -const constants_1 = require("./constants"); -const propTypes = { - /** Index of the PDF page to be displayed passed by VariableSizeList */ - index: prop_types_1.default.number.isRequired, - /** Page extra data passed by VariableSizeList's data prop */ - data: prop_types_1.default.shape({ - /** Width of a single page in the document */ - pageWidth: prop_types_1.default.number.isRequired, - /** The estimated height of a single page in the document */ - estimatedPageHeight: prop_types_1.default.number.isRequired, - /** Function that calculates the height of a page given its index */ - calculatePageHeight: prop_types_1.default.func.isRequired, - /** Function that calculates the pixel ratio for a page given its calculated width and height */ - getDevicePixelRatio: prop_types_1.default.func.isRequired, - }).isRequired, - /** Additional style props passed by VariableSizeList */ - // eslint-disable-next-line react/forbid-prop-types - style: prop_types_1.default.object.isRequired, -}; -function PageRenderer({ index, style, data }) { - const { pageWidth, estimatedPageHeight, calculatePageHeight, getDevicePixelRatio } = data; - /** - * Render a specific page based on its index. - * The method includes a wrapper to apply virtualized styles. - */ - const pageHeight = calculatePageHeight(index); - const devicePixelRatio = getDevicePixelRatio(pageWidth, pageHeight); - return (react_1.default.createElement("div", { style: Object.assign(Object.assign(Object.assign({}, styles_1.pdfPreviewerStyles.pageWrapper), style), { top: `${parseFloat(style.top) + constants_1.PAGE_BORDER}px` }) }, - react_1.default.createElement(react_pdf_1.Page, { key: `page_${index}`, width: pageWidth, height: pageHeight || estimatedPageHeight, pageIndex: index, - // This needs to be empty to avoid multiple loading texts which show per page and look ugly - // See https://github.com/Expensify/App/issues/14358 for more details - loading: "", devicePixelRatio: devicePixelRatio }))); -} -PageRenderer.displayName = 'PageRenderer'; -PageRenderer.propTypes = propTypes; -exports.default = (0, react_1.memo)(PageRenderer); diff --git a/dist/constants.d.ts b/dist/constants.d.ts deleted file mode 100644 index 59c3652..0000000 --- a/dist/constants.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Each page has a default border. The app should take this size into account - * when calculates the page width and height. - */ -declare const PAGE_BORDER = 9; -/** - * Pages should be more narrow than the container on large screens. The app should take this size into account - * when calculates the page width. - */ -declare const LARGE_SCREEN_SIDE_SPACING = 40; -/** - * An object in which additional parameters to be passed to PDF.js can be defined. - * 1. cMapUrl - The URL where the predefined Adobe CMaps are located. Include the trailing slash. - * 2. cMapPacked - specifies if the Adobe CMaps are binary packed or not. The default value is `true`. - */ -declare const DEFAULT_DOCUMENT_OPTIONS: { - cMapUrl: string; - cMapPacked: boolean; -}; -/** - * Link target for external links rendered in annotations. - */ -declare const DEFAULT_EXTERNAL_LINK_TARGET = "_blank"; -/** - * Constants for password-related error responses received from react-pdf. - */ -declare const PDF_PASSWORD_FORM_RESPONSES: { - NEED_PASSWORD: number; - INCORRECT_PASSWORD: number; -}; -export { PAGE_BORDER, LARGE_SCREEN_SIDE_SPACING, DEFAULT_DOCUMENT_OPTIONS, DEFAULT_EXTERNAL_LINK_TARGET, PDF_PASSWORD_FORM_RESPONSES }; -//# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/dist/constants.d.ts.map b/dist/constants.d.ts.map deleted file mode 100644 index a30e6a5..0000000 --- a/dist/constants.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,QAAA,MAAM,WAAW,IAAI,CAAC;AAEtB;;;GAGG;AACH,QAAA,MAAM,yBAAyB,KAAK,CAAC;AAErC;;;;GAIG;AACH,QAAA,MAAM,wBAAwB;;;CAG7B,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,4BAA4B,WAAW,CAAC;AAE9C;;GAEG;AACH,QAAA,MAAM,2BAA2B;;;CAGhC,CAAC;AAEF,OAAO,EAAC,WAAW,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,2BAA2B,EAAC,CAAC"} \ No newline at end of file diff --git a/dist/constants.js b/dist/constants.js deleted file mode 100644 index 3353883..0000000 --- a/dist/constants.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.PDF_PASSWORD_FORM_RESPONSES = exports.DEFAULT_EXTERNAL_LINK_TARGET = exports.DEFAULT_DOCUMENT_OPTIONS = exports.LARGE_SCREEN_SIDE_SPACING = exports.PAGE_BORDER = void 0; -/** - * Each page has a default border. The app should take this size into account - * when calculates the page width and height. - */ -const PAGE_BORDER = 9; -exports.PAGE_BORDER = PAGE_BORDER; -/** - * Pages should be more narrow than the container on large screens. The app should take this size into account - * when calculates the page width. - */ -const LARGE_SCREEN_SIDE_SPACING = 40; -exports.LARGE_SCREEN_SIDE_SPACING = LARGE_SCREEN_SIDE_SPACING; -/** - * An object in which additional parameters to be passed to PDF.js can be defined. - * 1. cMapUrl - The URL where the predefined Adobe CMaps are located. Include the trailing slash. - * 2. cMapPacked - specifies if the Adobe CMaps are binary packed or not. The default value is `true`. - */ -const DEFAULT_DOCUMENT_OPTIONS = { - cMapUrl: 'cmaps/', - cMapPacked: true, -}; -exports.DEFAULT_DOCUMENT_OPTIONS = DEFAULT_DOCUMENT_OPTIONS; -/** - * Link target for external links rendered in annotations. - */ -const DEFAULT_EXTERNAL_LINK_TARGET = '_blank'; -exports.DEFAULT_EXTERNAL_LINK_TARGET = DEFAULT_EXTERNAL_LINK_TARGET; -/** - * Constants for password-related error responses received from react-pdf. - */ -const PDF_PASSWORD_FORM_RESPONSES = { - NEED_PASSWORD: 1, - INCORRECT_PASSWORD: 2, -}; -exports.PDF_PASSWORD_FORM_RESPONSES = PDF_PASSWORD_FORM_RESPONSES; diff --git a/dist/helpers.d.ts b/dist/helpers.d.ts deleted file mode 100644 index 9760ab0..0000000 --- a/dist/helpers.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Fetch browser name from UA string - */ -declare const getBrowser: () => string; -/** - * Checks if requesting user agent is Safari browser on a mobile device - */ -declare const isMobileSafari: () => boolean; -declare const isSafari: () => boolean; -type ListRef = { - tabIndex: number; -}; -/** - * Sets attributes to list container. - * It unblocks a default scroll by keyboard of browsers. - */ -declare const setListAttributes: (ref: ListRef | undefined) => void; -export { getBrowser, isMobileSafari, isSafari, setListAttributes }; -//# sourceMappingURL=helpers.d.ts.map \ No newline at end of file diff --git a/dist/helpers.d.ts.map b/dist/helpers.d.ts.map deleted file mode 100644 index ff44a38..0000000 --- a/dist/helpers.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,QAAA,MAAM,UAAU,QAAO,MAyBtB,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,cAAc,QAAO,OAI1B,CAAC;AAEF,QAAA,MAAM,QAAQ,eAAsD,CAAC;AAErE,KAAK,OAAO,GAAG;IACX,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,iBAAiB,QAAS,OAAO,GAAG,SAAS,SAWlD,CAAC;AAEF,OAAO,EAAC,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,iBAAiB,EAAC,CAAC"} \ No newline at end of file diff --git a/dist/helpers.js b/dist/helpers.js deleted file mode 100644 index 81e37f7..0000000 --- a/dist/helpers.js +++ /dev/null @@ -1,55 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.setListAttributes = exports.isSafari = exports.isMobileSafari = exports.getBrowser = void 0; -/** - * Fetch browser name from UA string - */ -const getBrowser = () => { - var _a, _b; - const { userAgent } = window.navigator; - const match = (_a = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))/i)) !== null && _a !== void 0 ? _a : []; - let temp; - let browserName = ''; - if (/trident/i.test(match[1])) { - return 'IE'; - } - if (match[1] && match[1].toLowerCase() === 'chrome') { - temp = userAgent.match(/\b(OPR)/); - if (temp !== null) { - return 'Opera'; - } - temp = userAgent.match(/\b(Edg)/); - if (temp !== null) { - return 'Edge'; - } - } - browserName = (_b = match[1]) !== null && _b !== void 0 ? _b : navigator.appName; - return browserName ? browserName.toLowerCase() : 'other'; -}; -exports.getBrowser = getBrowser; -/** - * Checks if requesting user agent is Safari browser on a mobile device - */ -const isMobileSafari = () => { - const { userAgent } = window.navigator; - return /iP(ad|od|hone)/i.test(userAgent) && /WebKit/i.test(userAgent) && !/(CriOS|FxiOS|OPiOS|mercury)/i.test(userAgent); -}; -exports.isMobileSafari = isMobileSafari; -const isSafari = () => getBrowser() === 'safari' || isMobileSafari(); -exports.isSafari = isSafari; -/** - * Sets attributes to list container. - * It unblocks a default scroll by keyboard of browsers. - */ -const setListAttributes = (ref) => { - if (!ref) { - return; - } - /** - * Useful for elements that should not be navigated to directly using the "Tab" key, - * but need to have keyboard focus set to them. - */ - // eslint-disable-next-line no-param-reassign - ref.tabIndex = -1; -}; -exports.setListAttributes = setListAttributes; diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 493e18e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import PDFPreviewer from './PDFPreviewer'; -export { PDFPreviewer }; -declare const _default: { - PackageName: string; -}; -export default _default; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map deleted file mode 100644 index 360f58c..0000000 --- a/dist/index.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,EAAC,YAAY,EAAC,CAAC;;;;AAEtB,wBAEE"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f534807..0000000 --- a/dist/index.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.PDFPreviewer = void 0; -const PDFPreviewer_1 = __importDefault(require("./PDFPreviewer")); -exports.PDFPreviewer = PDFPreviewer_1.default; -const PACKAGE_NAME = 'react-fast-pdf'; -exports.default = { - PackageName: PACKAGE_NAME, -}; diff --git a/dist/styles.d.ts b/dist/styles.d.ts deleted file mode 100644 index 307081c..0000000 --- a/dist/styles.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { ComponentStyles } from './types'; -declare const pdfPreviewerStyles: ComponentStyles; -declare const pdfPasswordFormStyles: ComponentStyles; -export { pdfPreviewerStyles, pdfPasswordFormStyles }; -//# sourceMappingURL=styles.d.ts.map \ No newline at end of file diff --git a/dist/styles.d.ts.map b/dist/styles.d.ts.map deleted file mode 100644 index e968e59..0000000 --- a/dist/styles.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,SAAS,CAAC;AAE7C,QAAA,MAAM,kBAAkB,EAAE,eAkCzB,CAAC;AAEF,QAAA,MAAM,qBAAqB,EAAE,eAiD5B,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,qBAAqB,EAAC,CAAC"} \ No newline at end of file diff --git a/dist/styles.js b/dist/styles.js deleted file mode 100644 index 377ae66..0000000 --- a/dist/styles.js +++ /dev/null @@ -1,90 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.pdfPasswordFormStyles = exports.pdfPreviewerStyles = void 0; -const pdfPreviewerStyles = { - container: { - width: '100%', - height: '100%', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - }, - innerContainer: { - width: '100%', - height: '100%', - /** - * It's being used on Web/Desktop only to vertically center short PDFs, - * while preventing the overflow of the top of long PDF files. - */ - display: 'grid', - alignItems: 'center', - justifyContent: 'center', - overflow: 'hidden', - }, - invisibleContainer: { - position: 'absolute', - opacity: 0, - zIndex: -1, - }, - list: { - overflowX: 'hidden', - // There properties disable "focus" effect on list - boxShadow: 'none', - outline: 'none', - }, - pageWrapper: { - display: 'flex', - }, -}; -exports.pdfPreviewerStyles = pdfPreviewerStyles; -const pdfPasswordFormStyles = { - container: { - display: 'flex', - flexDirection: 'column', - alignItems: 'center', - justifyContent: 'center', - backgroundColor: '#07271f', - }, - infoMessage: { - fontSize: 18, - textAlign: 'center', - }, - infoMessageButton: { - textDecoration: 'underline', - cursor: 'pointer', - }, - form: { - marginTop: 16, - display: 'flex', - flexDirection: 'column', - justifyContent: 'center', - }, - inputLabel: { - fontSize: 16, - }, - input: { - marginLeft: 16, - padding: '8px 16px', - fontSize: 16, - border: 0, - borderRadius: 16, - backgroundColor: '#184e3d', - outline: 'none', - }, - errorMessage: { - marginTop: 8, - color: '#f25730', - fontSize: 16, - textAlign: 'center', - }, - confirmButton: { - marginTop: 16, - padding: '8px 16px', - fontSize: 18, - border: 0, - borderRadius: 16, - backgroundColor: '#03d47c', - cursor: 'pointer', - }, -}; -exports.pdfPasswordFormStyles = pdfPasswordFormStyles; diff --git a/dist/types.d.ts b/dist/types.d.ts deleted file mode 100644 index 9a93e74..0000000 --- a/dist/types.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { CSSProperties } from 'react'; -type Page = { - getViewport: ({ scale }: { - scale: number; - }) => PageViewport; -}; -type PDFDocument = { - numPages: number; - getPage: (pageNumber: number) => Promise; -}; -type PageViewport = { - height: number; - width: number; -}; -type ComponentStyles = { - [key: string]: CSSProperties; -}; -export type { PDFDocument, PageViewport, ComponentStyles }; -//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/types.d.ts.map b/dist/types.d.ts.map deleted file mode 100644 index 633c94d..0000000 --- a/dist/types.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAEpC,KAAK,IAAI,GAAG;IACR,WAAW,EAAE,CAAC,EAAC,KAAK,EAAC,EAAE;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,KAAK,YAAY,CAAC;CAC3D,CAAC;AAEF,KAAK,WAAW,GAAG;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,eAAe,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC;CAChC,CAAC;AAEF,YAAY,EAAC,WAAW,EAAE,YAAY,EAAE,eAAe,EAAC,CAAC"} \ No newline at end of file diff --git a/dist/types.js b/dist/types.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/types.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true });