diff --git a/.eslintrc b/.eslintrc index 35a761559..d007e47e6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -23,10 +23,11 @@ "assert": false, "fixture": false, "__": false, - "PDFJS": false, "Box": false, + "ActiveXObject": false, "DocumentTouch": false, - "ActiveXObject": false + "pdfjsLib": false, + "pdfjsViewer": false }, "rules": { "quotes": [ diff --git a/build/closure-compiler-v20161201.jar b/build/closure-compiler-v20190121.jar similarity index 51% rename from build/closure-compiler-v20161201.jar rename to build/closure-compiler-v20190121.jar index 34211c774..ade0a4754 100644 Binary files a/build/closure-compiler-v20161201.jar and b/build/closure-compiler-v20190121.jar differ diff --git a/build/karma.conf.js b/build/karma.conf.js index e3efc0f7a..39bc8ae93 100644 --- a/build/karma.conf.js +++ b/build/karma.conf.js @@ -3,7 +3,7 @@ const webpackConfig = require('./webpack.karma.config'); // These should be updated to match the Preview version in package.json whenever a file in that third party directory // is updated. Also, update the matching configuration in constants.js, which is needed for main preview functionality -const DOC_STATIC_ASSETS_VERSION = '1.60.0'; +const DOC_STATIC_ASSETS_VERSION = '1.63.0'; const MEDIA_STATIC_ASSETS_VERSION = '1.33.0'; const MODEL3D_STATIC_ASSETS_VERSION = '1.12.0'; const SWF_STATIC_ASSETS_VERSION = '0.112.0'; diff --git a/build/minify_pdfjs.sh b/build/minify_pdfjs.sh index 44be11880..735177b64 100755 --- a/build/minify_pdfjs.sh +++ b/build/minify_pdfjs.sh @@ -1,4 +1,7 @@ -DOC_STATIC_ASSETS_VERSION=$1 || $(./build/current_version.sh) +#!/bin/bash + +DOC_COMPILER_BINARY="build/closure-compiler-v20190121.jar" +DOC_STATIC_ASSETS_VERSION=$(./build/current_version.sh) # Minify using Google Closure Compiler, options: # Output to ECMASCRIPT5 / ES5 (Box supports Chrome, IE11, Firefox, Safari, and newer versions of iOS, Android) @@ -6,15 +9,17 @@ DOC_STATIC_ASSETS_VERSION=$1 || $(./build/current_version.sh) echo "-----------------------------------------------------------------------------------" echo "Minifying pdf.js files with Google Closure... Warnings are okay!" echo "-----------------------------------------------------------------------------------" -java -jar build/closure-compiler-v20161201.jar --rewrite_polyfills false --language_out ECMASCRIPT5 --js src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf.js --js_output_file src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf.min.js +java -jar ${DOC_COMPILER_BINARY} --rewrite_polyfills false --language_out ECMASCRIPT5 --js src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf.js --js_output_file src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf.min.js + +java -jar ${DOC_COMPILER_BINARY} --rewrite_polyfills false --language_out ECMASCRIPT5 --js src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf.worker.js --js_output_file src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf.worker.min.js -java -jar build/closure-compiler-v20161201.jar --rewrite_polyfills false --language_out ECMASCRIPT5 --js src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf.worker.js --js_output_file src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf.worker.min.js +java -jar ${DOC_COMPILER_BINARY} --rewrite_polyfills false --language_out ECMASCRIPT5 --js src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf_viewer.js --js_output_file src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf_viewer.min.js -java -jar build/closure-compiler-v20161201.jar --rewrite_polyfills false --language_out ECMASCRIPT5 --js src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf_viewer.js --js_output_file src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf_viewer.min.js echo "-----------------------------------------------------------------------------------" echo "Minifying pdf.js CSS with cssnano" echo "-----------------------------------------------------------------------------------" -./node_modules/.bin/cssnano src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf_viewer.css src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf_viewer.min.css +./node_modules/.bin/cssnano src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf_viewer.css src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf_viewer.min.css + echo "-----------------------------------------------------------------------------------" echo "Successfully updated and minified pdf.js files!" echo "-----------------------------------------------------------------------------------" diff --git a/build/upgrade_pdfjs.sh b/build/upgrade_pdfjs.sh index 34adb9723..cb2d1ed08 100755 --- a/build/upgrade_pdfjs.sh +++ b/build/upgrade_pdfjs.sh @@ -1,45 +1,55 @@ +#!/bin/bash +# Run with specific branch/tag (e.g. ./upgrade_pdfjs.sh tags/v2.0.943) or with no arguments to use master + +DOC_STATIC_ASSETS_BRANCH=${1:-master} DOC_STATIC_ASSETS_VERSION=$(./build/current_version.sh) -DOC_STATIC_ASSETS_PATH="src/third-party/doc/$DOC_STATIC_ASSETS_VERSION" +DOC_STATIC_ASSETS_PATH="src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}" -if [ ! -d $DOC_STATIC_ASSETS_PATH ]; then - DOC_LATEST_STATIC_ASSETS=`ls src/third-party/doc | sort -t "." -k1,1n -k2,2n -k3,3n | tail -1` - echo "Latest version is $DOC_LATEST_STATIC_ASSETS" - `cp -R src/third-party/doc/$DOC_LATEST_STATIC_ASSETS $DOC_STATIC_ASSETS_PATH` - echo "Created build directory for $DOC_STATIC_ASSETS_PATH" -fi +echo "Upgrading pdf.js to $DOC_STATIC_ASSETS_BRANCH"; echo "-----------------------------------------------------------------------------------" -echo "Fetching latest pdf.js files from pdfjs-dist repo..." +echo "Creating target directory at $DOC_STATIC_ASSETS_PATH..." +echo "-----------------------------------------------------------------------------------" + +rm -rf ${DOC_STATIC_ASSETS_PATH} + +DOC_LATEST_STATIC_ASSETS=`ls src/third-party/doc | sort -t "." -k1,1n -k2,2n -k3,3n | tail -1` +echo "Usig base version from $DOC_LATEST_STATIC_ASSETS" +`cp -R src/third-party/doc/${DOC_LATEST_STATIC_ASSETS} ${DOC_STATIC_ASSETS_PATH}` + +echo "-----------------------------------------------------------------------------------" +echo "Cloining pdfjs-dist repo at branch: $DOC_STATIC_ASSETS_BRANCH..." echo "-----------------------------------------------------------------------------------" rm -rf ./pdfjs-dist/ -git clone https://github.com/mozilla/pdfjs-dist.git +git clone https://github.com/mozilla/pdfjs-dist.git --depth 1 --single-branch --branch ${DOC_STATIC_ASSETS_BRANCH} echo "-----------------------------------------------------------------------------------" echo "Copying relevant files to Preview third-party dir..." echo "-----------------------------------------------------------------------------------" -cp pdfjs-dist/build/pdf.js src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/ -cp pdfjs-dist/build/pdf.worker.js src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/ -cp pdfjs-dist/web/pdf_viewer.js src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/ -cp pdfjs-dist/web/pdf_viewer.css src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/ -cp pdfjs-dist/cmaps/* src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/cmaps/ +\cp -rf pdfjs-dist/build/pdf.js src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/ +\cp -rf pdfjs-dist/build/pdf.worker.js src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/ +\cp -rf pdfjs-dist/web/pdf_viewer.js src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/ +\cp -rf pdfjs-dist/web/pdf_viewer.css src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/ +\cp -rf pdfjs-dist/cmaps/* src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/cmaps/ rm -rf ./pdfjs-dist/ # Fix Chrome console warning issue by not testing for moz-chunked-arraybuffer support in Chrome echo "-----------------------------------------------------------------------------------" echo "Tweaking pdf.js for Chrome..." echo "-----------------------------------------------------------------------------------" -sed -e 's/function supportsMozChunkedClosure/!\(\/Chrome\/\.test\(navigator\.userAgent\)\) \&\& function supportsMozChunkedClosure/' -i '' src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf.js +sed -e 's/function supportsMozChunkedClosure/!\(\/Chrome\/\.test\(navigator\.userAgent\)\) \&\& function supportsMozChunkedClosure/' -i '' src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf.js # Decreased default cached pages size to 5 on mobile web to lower memory usage echo "-----------------------------------------------------------------------------------" -echo "Decreasing # of cached pages on mobile web" +echo "Decreasing # of cached pages on mobile web..." echo "-----------------------------------------------------------------------------------" -sed -e 's@var DEFAULT_CACHE_SIZE = 10;@var DEFAULT_CACHE_SIZE = /iphone|ipad|ipod|android|blackberry|bb10|mini|windows\sce|palm/i.test(navigator.userAgent) ? 5 : 10;@' -i '' src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf_viewer.js +sed -e 's@var DEFAULT_CACHE_SIZE = 10;@var DEFAULT_CACHE_SIZE = /iphone|ipad|ipod|android|blackberry|bb10|mini|windows\sce|palm/i.test(navigator.userAgent) ? 5 : 10;@' -i '' src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf_viewer.js -# Deletes code hiding PDF signatures. -# For preview purposes, it is acceptable to show signatures without verifying them. +# Render e-signatures without validation echo "-----------------------------------------------------------------------------------" -echo "Enabling PDF signatures" +echo "Enabling e-signature rendering without validation..." echo "-----------------------------------------------------------------------------------" -# Deletes a block of code that starts with `if (data.fieldType === 'Sig') {``, and ends with `}` -sed -e "/if (data.fieldType === 'Sig') {/,/}/d" -i '' src/third-party/doc/$DOC_STATIC_ASSETS_VERSION/pdf.worker.js +sed -e 's@_this2.setFlags(_util.AnnotationFlag.HIDDEN);@\/\/_this2.setFlags(_util.AnnotationFlag.HIDDEN);@' -i '' src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/pdf.worker.js + +# Miniy the libraries +./build/minify_pdfjs.sh diff --git a/package.json b/package.json index 87b468d05..ec4f825c7 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "start": "yarn install && BABEL_ENV=dev NODE_ENV=dev ./node_modules/.bin/webpack --watch --progress --colors --config build/webpack.config.js", "start:dev": "yarn run build-rb && LANGUAGE=en-US BABEL_ENV=dev NODE_ENV=dev ./node_modules/.bin/webpack-dev-server --config build/webpack.config.js", "test": "yarn install && NODE_ENV=test node --max_old_space_size=4096 ./node_modules/.bin/karma start build/karma.conf.js", - "upgrade-pdfjs": "./build/upgrade_pdfjs.sh && ./build/minify_pdfjs.sh", + "upgrade-pdfjs": "./build/upgrade_pdfjs.sh", "upgrade-annotations": "./build/upgrade_annotations.sh", "major": "./build/release.sh -m", "minor": "./build/release.sh -n", diff --git a/src/lib/constants.js b/src/lib/constants.js index 8248a0280..6f14dfd69 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -97,7 +97,7 @@ export const PDFJS_HEIGHT_PADDING_PX = 5; // Should match VERTICAL_PADDING in pd // These should be updated to match the Preview version in package.json whenever a file in that third party directory // is updated. Also, update the matching configuration in karma.conf.js, which is needed for tests -export const DOC_STATIC_ASSETS_VERSION = '1.60.0'; +export const DOC_STATIC_ASSETS_VERSION = '1.63.0'; export const MEDIA_STATIC_ASSETS_VERSION = '1.33.0'; export const MODEL3D_STATIC_ASSETS_VERSION = '1.12.0'; export const SWF_STATIC_ASSETS_VERSION = '0.112.0'; diff --git a/src/lib/util.js b/src/lib/util.js index 7f0001b15..e3321de1a 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -13,6 +13,8 @@ const CLIENT_NAME = __NAME__; export const CLIENT_VERSION = __VERSION__; /* eslint-enable no-undef */ +const promiseMap = {}; + /** * Retrieves JSON from response. * @@ -481,6 +483,17 @@ export function loadStylesheets(urls) { }); } +/** + * Delete all promises from the promise map + * + * @return {void} + */ +export function clearPromises() { + Object.keys(promiseMap).forEach((promiseKey) => { + delete promiseMap[promiseKey]; + }); +} + /** * Loads external scripts by appending a