Replacing custom bundling with webpack2.

This commit is contained in:
Yury Delendik 2017-02-08 16:32:15 -06:00
parent d7cb46dafc
commit eb4c88cd44
12 changed files with 330 additions and 321 deletions

50
external/webpack/block-require.js vendored Normal file
View File

@ -0,0 +1,50 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-env node */
'use strict';
function isPDFJSDevCheck(test) {
// Is it something like `typeof __pdfjsdev_webpack__ === 'undefined'`?
return test.type === 'BinaryExpression' &&
(test.operator === '===' || test.operator === '!==' ||
test.operator === '==' || test.operator === '!=') &&
test.left.type === 'UnaryExpression' &&
test.left.operator === 'typeof' &&
test.left.argument.type === 'Identifier' &&
test.left.argument.name === '__pdfjsdev_webpack__' &&
test.right.type === 'Literal' && test.right.value === 'undefined';
}
function isPDFJSDevEnabled(test) {
return test.operator[0] === '!';
}
function BlockRequirePlugin() {}
BlockRequirePlugin.prototype.apply = function(compiler) {
compiler.plugin('compilation', function(compilation, data) {
data.normalModuleFactory.plugin('parser', function (parser, options) {
parser.plugin('statement if', function (ifNode) {
if (isPDFJSDevCheck(ifNode.test)) {
return isPDFJSDevEnabled(ifNode.test);
}
return undefined;
});
});
});
};
module.exports = BlockRequirePlugin;

30
external/webpack/pdfjsdev-loader.js vendored Normal file
View File

@ -0,0 +1,30 @@
/* Copyright 2017 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-env node */
'use strict';
var preprocessor2 = require('../builder/preprocessor2.js');
module.exports = function (source) {
// Options must be specified, ignoring request if not.
if (!this.query || typeof this.query !== 'object') {
return source;
}
this.cacheable();
var ctx = this.query;
source = preprocessor2.preprocessPDFJSCode(ctx, source);
return source;
};

View File

@ -31,6 +31,8 @@ var spawn = require('child_process').spawn;
var streamqueue = require('streamqueue'); var streamqueue = require('streamqueue');
var merge = require('merge-stream'); var merge = require('merge-stream');
var zip = require('gulp-zip'); var zip = require('gulp-zip');
var webpack2 = require('webpack');
var webpackStream = require('webpack-stream');
var BUILD_DIR = 'build/'; var BUILD_DIR = 'build/';
var JSDOC_DIR = 'jsdoc/'; var JSDOC_DIR = 'jsdoc/';
@ -79,12 +81,45 @@ function createStringSource(filename, content) {
return source; return source;
} }
function stripUMDHeaders(content) { function createWebpackConfig(defines, output) {
var reg = new RegExp( var path = require('path');
'if \\(typeof define === \'function\' && define.amd\\) \\{[^}]*' + var BlockRequirePlugin = require('./external/webpack/block-require.js');
'\\} else if \\(typeof exports !== \'undefined\'\\) \\{[^}]*' +
'\\} else ', 'g'); var versionInfo = getVersionJSON();
return content.replace(reg, ''); var bundleDefines = builder.merge(defines, {
BUNDLE_VERSION: versionInfo.version,
BUNDLE_BUILD: versionInfo.commit
});
return {
output: output,
plugins: [
new BlockRequirePlugin()
],
resolve: {
alias: {
'pdfjs': path.join(__dirname, 'src'),
'pdfjs-web': path.join(__dirname, 'web'),
}
},
module: {
loaders: [
{
loader: path.join(__dirname, 'external/webpack/pdfjsdev-loader.js'),
options: {
rootPath: __dirname,
saveComments: 'copyright',
defines: bundleDefines
}
}
]
}
};
}
function webpack2Stream(config) {
// Replacing webpack1 to webpack2 in the webpack-stream.
return webpackStream(config, webpack2);
} }
function stripCommentHeaders(content) { function stripCommentHeaders(content) {
@ -124,185 +159,74 @@ function checkChromePreferencesFile(chromePrefsPath, webPrefsPath) {
}); });
} }
function bundle(filename, outfilename, pathPrefix, initFiles, amdName, defines, function replaceWebpackRequire() {
isMainFile, versionInfo) { // Produced bundles can be rebundled again, avoid collisions (e.g. in api.js)
// Reading UMD headers and building loading orders of modules. The // by renaming __webpack_require__ to something else.
// readDependencies returns AMD module names: removing 'pdfjs' prefix and return replace('__webpack_require__', '__w_pdfjs_require__');
// adding '.js' extensions to the name.
var umd = require('./external/umdutils/verifier.js');
initFiles = initFiles.map(function (p) {
return pathPrefix + p;
});
var files = umd.readDependencies(initFiles).loadOrder.map(function (name) {
return pathPrefix + name.replace(/^[\w\-]+\//, '') + '.js';
});
var crlfchecker = require('./external/crlfchecker/crlfchecker.js');
crlfchecker.checkIfCrlfIsPresent(files);
var bundleContent = files.map(function (file) {
var content = fs.readFileSync(file);
// Prepend a newline because stripCommentHeaders only strips comments that
// follow a line feed. The file where bundleContent is inserted already
// contains a license header, so the header of bundleContent can be removed.
content = stripCommentHeaders('\n' + content);
// Removes AMD and CommonJS branches from UMD headers.
content = stripUMDHeaders(content);
return content;
}).join('');
var jsName = amdName.replace(/[\-_\.\/]\w/g, function (all) {
return all[1].toUpperCase();
});
var p2 = require('./external/builder/preprocessor2.js');
var ctx = {
rootPath: __dirname,
saveComments: 'copyright',
defines: builder.merge(defines, {
BUNDLE_VERSION: versionInfo.version,
BUNDLE_BUILD: versionInfo.commit,
BUNDLE_AMD_NAME: amdName,
BUNDLE_JS_NAME: jsName,
MAIN_FILE: isMainFile
})
};
var templateContent = fs.readFileSync(filename).toString();
templateContent = templateContent.replace(
/\/\/#expand\s+__BUNDLE__\s*\n/, function (all) {
return bundleContent;
});
bundleContent = null;
templateContent = p2.preprocessPDFJSCode(ctx, templateContent);
fs.writeFileSync(outfilename, templateContent);
templateContent = null;
} }
function createBundle(defines) { function createBundle(defines) {
var versionJSON = getVersionJSON();
console.log(); console.log();
console.log('### Bundling files into pdf.js'); console.log('### Bundling files into pdf.js');
var mainFiles = [
'display/global.js'
];
var workerFiles = [
'core/worker.js'
];
var mainAMDName = 'pdfjs-dist/build/pdf'; var mainAMDName = 'pdfjs-dist/build/pdf';
var workerAMDName = 'pdfjs-dist/build/pdf.worker';
var mainOutputName = 'pdf.js'; var mainOutputName = 'pdf.js';
if (defines.SINGLE_FILE) {
mainAMDName = 'pdfjs-dist/build/pdf.combined';
mainOutputName = 'pdf.combined.js';
}
var mainFileConfig = createWebpackConfig(defines, {
filename: mainOutputName,
library: mainAMDName,
libraryTarget: 'umd',
umdNamedDefine: true
});
var mainOutput = gulp.src('./src/pdf.js')
.pipe(webpack2Stream(mainFileConfig))
.pipe(replaceWebpackRequire());
if (defines.SINGLE_FILE) {
return mainOutput; // don't need a worker file.
}
var workerAMDName = 'pdfjs-dist/build/pdf.worker';
var workerOutputName = 'pdf.worker.js'; var workerOutputName = 'pdf.worker.js';
// Extension does not need network.js file. var workerFileConfig = createWebpackConfig(defines, {
if (!defines.FIREFOX && !defines.MOZCENTRAL) { filename: workerOutputName,
workerFiles.push('core/network.js'); library: workerAMDName,
} libraryTarget: 'umd',
umdNamedDefine: true
if (defines.SINGLE_FILE) { });
// In singlefile mode, all of the src files will be bundled into var workerOutput = gulp.src('./src/pdf.worker.js')
// the main pdf.js output. .pipe(webpack2Stream(workerFileConfig))
mainFiles = mainFiles.concat(workerFiles); .pipe(replaceWebpackRequire());
workerFiles = null; // no need for worker file return merge([mainOutput, workerOutput]);
mainAMDName = 'pdfjs-dist/build/pdf.combined';
workerAMDName = null;
mainOutputName = 'pdf.combined.js';
workerOutputName = null;
}
var state = 'mainfile';
var source = stream.Readable({ objectMode: true });
source._read = function () {
var tmpFile;
switch (state) {
case 'mainfile':
// 'buildnumber' shall create BUILD_DIR for us
tmpFile = BUILD_DIR + '~' + mainOutputName + '.tmp';
bundle('src/pdf.js', tmpFile, 'src/', mainFiles, mainAMDName,
defines, true, versionJSON);
this.push(new gutil.File({
cwd: '',
base: '',
path: mainOutputName,
contents: fs.readFileSync(tmpFile)
}));
fs.unlinkSync(tmpFile);
state = workerFiles ? 'workerfile' : 'stop';
break;
case 'workerfile':
// 'buildnumber' shall create BUILD_DIR for us
tmpFile = BUILD_DIR + '~' + workerOutputName + '.tmp';
bundle('src/pdf.js', tmpFile, 'src/', workerFiles, workerAMDName,
defines, false, versionJSON);
this.push(new gutil.File({
cwd: '',
base: '',
path: workerOutputName,
contents: fs.readFileSync(tmpFile)
}));
fs.unlinkSync(tmpFile);
state = 'stop';
break;
case 'stop':
this.push(null);
break;
}
};
return source;
} }
function createWebBundle(defines) { function createWebBundle(defines) {
var versionJSON = getVersionJSON(); var viewerOutputName = 'viewer.js';
var template, files, outputName, amdName; var viewerFileConfig = createWebpackConfig(defines, {
if (defines.COMPONENTS) { filename: viewerOutputName
amdName = 'pdfjs-dist/web/pdf_viewer'; });
template = 'web/pdf_viewer.component.js'; return gulp.src('./web/viewer.js')
files = [ .pipe(webpack2Stream(viewerFileConfig));
'pdf_viewer.js', }
'pdf_history.js',
'pdf_find_controller.js',
'download_manager.js'
];
outputName = 'pdf_viewer.js';
} else {
amdName = 'pdfjs-dist/web/viewer';
outputName = 'viewer.js';
template = 'web/viewer.js';
files = ['app.js'];
if (defines.FIREFOX || defines.MOZCENTRAL) {
files.push('firefoxcom.js', 'firefox_print_service.js');
} else if (defines.CHROME) {
files.push('chromecom.js', 'pdf_print_service.js');
} else if (defines.GENERIC) {
files.push('pdf_print_service.js');
}
}
var source = stream.Readable({ objectMode: true }); function createComponentsBundle(defines) {
source._read = function () { var componentsAMDName = 'pdfjs-dist/web/pdf_viewer';
// 'buildnumber' shall create BUILD_DIR for us var componentsOutputName = 'pdf_viewer.js';
var tmpFile = BUILD_DIR + '~' + outputName + '.tmp';
bundle(template, tmpFile, 'web/', files, amdName, defines, false, var componentsFileConfig = createWebpackConfig(defines, {
versionJSON); filename: componentsOutputName,
this.push(new gutil.File({ library: componentsAMDName,
cwd: '', libraryTarget: 'umd',
base: '', umdNamedDefine: true
path: outputName, });
contents: fs.readFileSync(tmpFile) return gulp.src('./web/pdf_viewer.component.js')
})); .pipe(webpack2Stream(componentsFileConfig))
fs.unlinkSync(tmpFile); .pipe(replaceWebpackRequire());
this.push(null);
};
return source;
} }
function checkFile(path) { function checkFile(path) {
@ -631,7 +555,7 @@ gulp.task('components', ['buildnumber'], function () {
]; ];
return merge([ return merge([
createWebBundle(defines).pipe(gulp.dest(COMPONENTS_DIR)), createComponentsBundle(defines).pipe(gulp.dest(COMPONENTS_DIR)),
gulp.src(COMPONENTS_IMAGES).pipe(gulp.dest(COMPONENTS_DIR + 'images')), gulp.src(COMPONENTS_IMAGES).pipe(gulp.dest(COMPONENTS_DIR + 'images')),
gulp.src('web/compatibility.js').pipe(gulp.dest(COMPONENTS_DIR)), gulp.src('web/compatibility.js').pipe(gulp.dest(COMPONENTS_DIR)),
preprocessCSS('web/pdf_viewer.css', 'components', defines, true) preprocessCSS('web/pdf_viewer.css', 'components', defines, true)

View File

@ -23,6 +23,8 @@
"streamqueue": "^1.1.1", "streamqueue": "^1.1.1",
"typogr": "~0.6.5", "typogr": "~0.6.5",
"uglify-js": "^2.6.1", "uglify-js": "^2.6.1",
"webpack": "^2.2.1",
"webpack-stream": "^3.2.0",
"wintersmith": "^2.0.0", "wintersmith": "^2.0.0",
"yargs": "^3.14.0" "yargs": "^3.14.0"
}, },

View File

@ -12,8 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals pdfjsFilePath, pdfjsVersion, pdfjsBuild, requirejs, pdfjsLibs, /* globals requirejs, pdfjsLibs, __webpack_require__, __pdfjsdev_webpack__ */
__webpack_require__ */
'use strict'; 'use strict';
@ -70,10 +69,18 @@ var isWorkerDisabled = false;
var workerSrc; var workerSrc;
var isPostMessageTransfersDisabled = false; var isPostMessageTransfersDisabled = false;
var pdfjsFilePath =
typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('PRODUCTION && !(MOZCENTRAL || FIREFOX)') &&
typeof document !== 'undefined' && document.currentScript ?
document.currentScript.src : null;
var fakeWorkerFilesLoader = null; var fakeWorkerFilesLoader = null;
var useRequireEnsure = false; var useRequireEnsure = false;
// The if below protected by __pdfjsdev_webpack__ check from webpack parsing.
if (typeof PDFJSDev !== 'undefined' && if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('GENERIC && !SINGLE_FILE')) { PDFJSDev.test('GENERIC && !SINGLE_FILE') &&
typeof __pdfjsdev_webpack__ === 'undefined') {
// For GENERIC build we need add support of different fake file loaders // For GENERIC build we need add support of different fake file loaders
// for different frameworks. // for different frameworks.
if (typeof window === 'undefined') { if (typeof window === 'undefined') {
@ -83,8 +90,8 @@ if (typeof PDFJSDev !== 'undefined' &&
require.ensure = require('node-ensure'); require.ensure = require('node-ensure');
} }
useRequireEnsure = true; useRequireEnsure = true;
} } else if (typeof require !== 'undefined' &&
if (typeof __webpack_require__ !== 'undefined') { typeof require.ensure === 'function') {
useRequireEnsure = true; useRequireEnsure = true;
} }
if (typeof requirejs !== 'undefined' && requirejs.toUrl) { if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
@ -2184,11 +2191,9 @@ var _UnsupportedManager = (function UnsupportedManagerClosure() {
}; };
})(); })();
if (typeof pdfjsVersion !== 'undefined') { if (typeof PDFJSDev !== 'undefined') {
exports.version = pdfjsVersion; exports.version = PDFJSDev.eval('BUNDLE_VERSION');
} exports.build = PDFJSDev.eval('BUNDLE_BUILD');
if (typeof pdfjsBuild !== 'undefined') {
exports.build = pdfjsBuild;
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals pdfjsVersion, pdfjsBuild */
'use strict'; 'use strict';
@ -54,11 +53,9 @@
} }
var PDFJS = globalScope.PDFJS; var PDFJS = globalScope.PDFJS;
if (typeof pdfjsVersion !== 'undefined') { if (typeof PDFJSDev !== 'undefined') {
PDFJS.version = pdfjsVersion; PDFJS.version = PDFJSDev.eval('BUNDLE_VERSION');
} PDFJS.build = PDFJSDev.eval('BUNDLE_BUILD');
if (typeof pdfjsBuild !== 'undefined') {
PDFJS.build = pdfjsBuild;
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;

View File

@ -12,75 +12,50 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint strict: ["error", "function"] */
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
/* umdutils ignore */ /* umdutils ignore */
(function (root, factory) { 'use strict';
'use strict';
if (typeof define === 'function' && define.amd) {
define(PDFJSDev.eval('BUNDLE_AMD_NAME'), ['exports'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports);
} else {
factory((root[PDFJSDev.eval('BUNDLE_JS_NAME')] = {}));
}
}(this, function (exports) {
// Use strict in our context only - users might not want it
'use strict';
var pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION'); var pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION');
var pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD'); var pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD');
var pdfjsFilePath = var pdfjsSharedUtil = require('./shared/util.js');
typeof document !== 'undefined' && document.currentScript ? var pdfjsDisplayGlobal = require('./display/global.js');
document.currentScript.src : null; var pdfjsDisplayAPI = require('./display/api.js');
var pdfjsDisplayTextLayer = require('./display/text_layer.js');
var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
var pdfjsDisplayDOMUtils = require('./display/dom_utils.js');
var pdfjsDisplaySVG = require('./display/svg.js');
var pdfjsLibs = {}; if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('SINGLE_FILE')) {
require('./core/worker.js');
require('./core/network.js');
}
(function pdfjsWrapper() { exports.PDFJS = pdfjsDisplayGlobal.PDFJS;
exports.build = pdfjsDisplayAPI.build;
//#expand __BUNDLE__ exports.version = pdfjsDisplayAPI.version;
exports.getDocument = pdfjsDisplayAPI.getDocument;
}).call(pdfjsLibs); exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport;
exports.PDFWorker = pdfjsDisplayAPI.PDFWorker;
if (PDFJSDev.test('MAIN_FILE')) { exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer;
exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS; exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer;
exports.build = pdfjsLibs.pdfjsDisplayAPI.build; exports.CustomStyle = pdfjsDisplayDOMUtils.CustomStyle;
exports.version = pdfjsLibs.pdfjsDisplayAPI.version; exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability;
exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument; exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses;
exports.PDFDataRangeTransport = exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException;
pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport; exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException;
exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker; exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics;
exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer; exports.UnexpectedResponseException =
exports.AnnotationLayer = pdfjsSharedUtil.UnexpectedResponseException;
pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer; exports.OPS = pdfjsSharedUtil.OPS;
exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle; exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
exports.createPromiseCapability = exports.isValidUrl = pdfjsDisplayDOMUtils.isValidUrl;
pdfjsLibs.pdfjsSharedUtil.createPromiseCapability; exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses; exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException; exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters;
exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException; exports.shadow = pdfjsSharedUtil.shadow;
exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics; exports.createBlob = pdfjsSharedUtil.createBlob;
exports.UnexpectedResponseException = exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException; exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
exports.UNSUPPORTED_FEATURES =
pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
exports.isValidUrl = pdfjsLibs.pdfjsDisplayDOMUtils.isValidUrl;
exports.createValidAbsoluteUrl =
pdfjsLibs.pdfjsSharedUtil.createValidAbsoluteUrl;
exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
exports.removeNullCharacters =
pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
exports.getFilenameFromUrl =
pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
exports.addLinkAttributes =
pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
} else {
exports.WorkerMessageHandler =
pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
}
}));

30
src/pdf.worker.js vendored Normal file
View File

@ -0,0 +1,30 @@
/* Copyright 2012 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-unused-vars */
/* umdutils ignore */
'use strict';
var pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION');
var pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD');
var pdfjsCoreWorker = require('./core/worker.js');
if (typeof PDFJSDev === 'undefined' ||
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
require('./core/network.js');
}
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals DEFAULT_URL, PDFBug, Stats */ /* globals PDFBug, Stats */
'use strict'; 'use strict';
@ -1391,20 +1391,20 @@ function loadAndEnablePDFBug(enabledTabs) {
} }
function webViewerInitialized() { function webViewerInitialized() {
var appConfig = PDFViewerApplication.appConfig;
var file; var file;
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
var queryString = document.location.search.substring(1); var queryString = document.location.search.substring(1);
var params = parseQueryString(queryString); var params = parseQueryString(queryString);
file = 'file' in params ? params.file : DEFAULT_URL; file = 'file' in params ? params.file : appConfig.defaultUrl;
validateFileURL(file); validateFileURL(file);
} else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) { } else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
file = window.location.href.split('#')[0]; file = window.location.href.split('#')[0];
} else if (PDFJSDev.test('CHROME')) { } else if (PDFJSDev.test('CHROME')) {
file = DEFAULT_URL; file = appConfig.defaultUrl;
} }
var waitForBeforeOpening = []; var waitForBeforeOpening = [];
var appConfig = PDFViewerApplication.appConfig;
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
var fileInput = document.createElement('input'); var fileInput = document.createElement('input');
fileInput.id = appConfig.openFileInputName; fileInput.id = appConfig.openFileInputName;

View File

@ -12,50 +12,38 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint strict: ["error", "function"] */
/* umdutils ignore */ /* umdutils ignore */
(function (root, factory) { 'use strict';
'use strict';
if (typeof define === 'function' && define.amd) {
define('pdfjs-dist/web/pdf_viewer', ['exports', 'pdfjs-dist/build/pdf'],
factory);
} else if (typeof exports !== 'undefined') {
factory(exports, require('../build/pdf.js'));
} else {
factory((root.pdfjsDistWebPDFViewer = {}), root.pdfjsDistBuildPdf);
}
}(this, function (exports, pdfjsLib) {
'use strict';
var pdfViewerLibs = { var pdfjsLib = require('./pdfjs.js');
pdfjsWebPDFJS: pdfjsLib var pdfjsWebPDFViewer = require('./pdf_viewer.js');
}; var pdfjsWebPDFPageView = require('./pdf_page_view.js');
var pdfjsWebPDFLinkService = require('./pdf_link_service.js');
var pdfjsWebTextLayerBuilder = require('./text_layer_builder.js');
var pdfjsWebAnnotationLayerBuilder = require('./annotation_layer_builder.js');
var pdfjsWebPDFHistory = require('./pdf_history.js');
var pdfjsWebPDFFindController = require('./pdf_find_controller.js');
var pdfjsWebUIUtils = require('./ui_utils.js');
var pdfjsWebDownloadManager = require('./download_manager.js');
(function () { var PDFJS = pdfjsLib.PDFJS;
//#expand __BUNDLE__
}).call(pdfViewerLibs);
var PDFJS = pdfjsLib.PDFJS; PDFJS.PDFViewer = pdfjsWebPDFViewer.PDFViewer;
PDFJS.PDFPageView = pdfjsWebPDFPageView.PDFPageView;
PDFJS.PDFLinkService = pdfjsWebPDFLinkService.PDFLinkService;
PDFJS.TextLayerBuilder = pdfjsWebTextLayerBuilder.TextLayerBuilder;
PDFJS.DefaultTextLayerFactory =
pdfjsWebTextLayerBuilder.DefaultTextLayerFactory;
PDFJS.AnnotationLayerBuilder =
pdfjsWebAnnotationLayerBuilder.AnnotationLayerBuilder;
PDFJS.DefaultAnnotationLayerFactory =
pdfjsWebAnnotationLayerBuilder.DefaultAnnotationLayerFactory;
PDFJS.PDFHistory = pdfjsWebPDFHistory.PDFHistory;
PDFJS.PDFFindController = pdfjsWebPDFFindController.PDFFindController;
PDFJS.EventBus = pdfjsWebUIUtils.EventBus;
PDFJS.PDFViewer = pdfViewerLibs.pdfjsWebPDFViewer.PDFViewer; PDFJS.DownloadManager = pdfjsWebDownloadManager.DownloadManager;
PDFJS.PDFPageView = pdfViewerLibs.pdfjsWebPDFPageView.PDFPageView; PDFJS.ProgressBar = pdfjsWebUIUtils.ProgressBar;
PDFJS.PDFLinkService = pdfViewerLibs.pdfjsWebPDFLinkService.PDFLinkService;
PDFJS.TextLayerBuilder =
pdfViewerLibs.pdfjsWebTextLayerBuilder.TextLayerBuilder;
PDFJS.DefaultTextLayerFactory =
pdfViewerLibs.pdfjsWebTextLayerBuilder.DefaultTextLayerFactory;
PDFJS.AnnotationLayerBuilder =
pdfViewerLibs.pdfjsWebAnnotationLayerBuilder.AnnotationLayerBuilder;
PDFJS.DefaultAnnotationLayerFactory =
pdfViewerLibs.pdfjsWebAnnotationLayerBuilder.DefaultAnnotationLayerFactory;
PDFJS.PDFHistory = pdfViewerLibs.pdfjsWebPDFHistory.PDFHistory;
PDFJS.PDFFindController =
pdfViewerLibs.pdfjsWebPDFFindController.PDFFindController;
PDFJS.EventBus = pdfViewerLibs.pdfjsWebUIUtils.EventBus;
PDFJS.DownloadManager = pdfViewerLibs.pdfjsWebDownloadManager.DownloadManager; exports.PDFJS = PDFJS;
PDFJS.ProgressBar = pdfViewerLibs.pdfjsWebUIUtils.ProgressBar;
exports.PDFJS = PDFJS;
}));

View File

@ -12,23 +12,28 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals module */
/* umdutils ignore */ /* umdutils ignore */
'use strict'; 'use strict';
(function (root, factory) { if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
if (typeof define === 'function' && define.amd) { module.exports = window['pdfjs-dist/build/pdf']; // loaded via html script tag
define('pdfjs-web/pdfjs', ['exports', 'pdfjs/main_loader'], factory); } else {
} else if (typeof exports !== 'undefined') { (function (root, factory) {
factory(exports, require('../src/main_loader.js')); if (typeof define === 'function' && define.amd) {
} else { define('pdfjs-web/pdfjs', ['exports', 'pdfjs/main_loader'], factory);
factory((root.pdfjsWebPDFJS = {}), root.pdfjsMainLoader); } else if (typeof exports !== 'undefined') {
} factory(exports, require('../src/main_loader.js'));
}(this, function (exports, mainLoader) { } else {
// Re-export all mainLoader members. factory((root.pdfjsWebPDFJS = {}), root.pdfjsMainLoader);
for (var i in mainLoader) {
if (Object.prototype.hasOwnProperty.call(mainLoader, i)) {
exports[i] = mainLoader[i];
} }
} }(this, function (exports, mainLoader) {
})); // Re-export all mainLoader members.
for (var i in mainLoader) {
if (Object.prototype.hasOwnProperty.call(mainLoader, i)) {
exports[i] = mainLoader[i];
}
}
}));
}

View File

@ -35,19 +35,21 @@ if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
})(); })();
} }
var pdfjsWebLibs; var pdfjsWebApp;
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) { if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
pdfjsWebLibs = { pdfjsWebApp = require('./app.js');
pdfjsWebPDFJS: window.pdfjsDistBuildPdf
};
(function () {
//#expand __BUNDLE__
}).call(pdfjsWebLibs);
} }
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL')) { if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
// FIXME the l10n.js file in the Firefox extension needs global FirefoxCom. // FIXME the l10n.js file in the Firefox extension needs global FirefoxCom.
window.FirefoxCom = pdfjsWebLibs.pdfjsWebFirefoxCom.FirefoxCom; window.FirefoxCom = require('./firefoxcom.js').FirefoxCom;
require('./firefox_print_service.js');
}
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
require('./chromecom.js');
}
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME || GENERIC')) {
require('./pdf_print_service.js');
} }
function getViewerConfiguration() { function getViewerConfiguration() {
@ -162,6 +164,7 @@ function getViewerConfiguration() {
printContainer: document.getElementById('printContainer'), printContainer: document.getElementById('printContainer'),
openFileInputName: 'fileInput', openFileInputName: 'fileInput',
debuggerScriptPath: './debugger.js', debuggerScriptPath: './debugger.js',
defaultUrl: DEFAULT_URL
}; };
} }
@ -174,8 +177,8 @@ function webViewerLoad() {
web.PDFViewerApplication.run(config); web.PDFViewerApplication.run(config);
}); });
} else { } else {
window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication; window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication.run(config); pdfjsWebApp.PDFViewerApplication.run(config);
} }
} }