Replacing custom bundling with webpack2.
This commit is contained in:
		
							parent
							
								
									d7cb46dafc
								
							
						
					
					
						commit
						eb4c88cd44
					
				
							
								
								
									
										50
									
								
								external/webpack/block-require.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								external/webpack/block-require.js
									
									
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										30
									
								
								external/webpack/pdfjsdev-loader.js
									
									
									
									
										vendored
									
									
										Normal 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; | ||||
| }; | ||||
							
								
								
									
										266
									
								
								gulpfile.js
									
									
									
									
									
								
							
							
						
						
									
										266
									
								
								gulpfile.js
									
									
									
									
									
								
							| @ -31,6 +31,8 @@ var spawn = require('child_process').spawn; | ||||
| var streamqueue = require('streamqueue'); | ||||
| var merge = require('merge-stream'); | ||||
| var zip = require('gulp-zip'); | ||||
| var webpack2 = require('webpack'); | ||||
| var webpackStream = require('webpack-stream'); | ||||
| 
 | ||||
| var BUILD_DIR = 'build/'; | ||||
| var JSDOC_DIR = 'jsdoc/'; | ||||
| @ -79,12 +81,45 @@ function createStringSource(filename, content) { | ||||
|   return source; | ||||
| } | ||||
| 
 | ||||
| function stripUMDHeaders(content) { | ||||
|   var reg = new RegExp( | ||||
|     'if \\(typeof define === \'function\' && define.amd\\) \\{[^}]*' + | ||||
|     '\\} else if \\(typeof exports !== \'undefined\'\\) \\{[^}]*' + | ||||
|     '\\} else ', 'g'); | ||||
|   return content.replace(reg, ''); | ||||
| function createWebpackConfig(defines, output) { | ||||
|   var path = require('path'); | ||||
|   var BlockRequirePlugin = require('./external/webpack/block-require.js'); | ||||
| 
 | ||||
|   var versionInfo = getVersionJSON(); | ||||
|   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) { | ||||
| @ -124,185 +159,74 @@ function checkChromePreferencesFile(chromePrefsPath, webPrefsPath) { | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
| function bundle(filename, outfilename, pathPrefix, initFiles, amdName, defines, | ||||
|                 isMainFile, versionInfo) { | ||||
|   // Reading UMD headers and building loading orders of modules. The
 | ||||
|   // readDependencies returns AMD module names: removing 'pdfjs' prefix and
 | ||||
|   // 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 replaceWebpackRequire() { | ||||
|   // Produced bundles can be rebundled again, avoid collisions (e.g. in api.js)
 | ||||
|   // by renaming  __webpack_require__ to something else.
 | ||||
|   return replace('__webpack_require__', '__w_pdfjs_require__'); | ||||
| } | ||||
| 
 | ||||
| function createBundle(defines) { | ||||
|   var versionJSON = getVersionJSON(); | ||||
| 
 | ||||
|   console.log(); | ||||
|   console.log('### Bundling files into pdf.js'); | ||||
| 
 | ||||
|   var mainFiles = [ | ||||
|     'display/global.js' | ||||
|   ]; | ||||
| 
 | ||||
|   var workerFiles = [ | ||||
|     'core/worker.js' | ||||
|   ]; | ||||
| 
 | ||||
|   var mainAMDName = 'pdfjs-dist/build/pdf'; | ||||
|   var workerAMDName = 'pdfjs-dist/build/pdf.worker'; | ||||
|   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'; | ||||
| 
 | ||||
|   // Extension does not need network.js file.
 | ||||
|   if (!defines.FIREFOX && !defines.MOZCENTRAL) { | ||||
|     workerFiles.push('core/network.js'); | ||||
|   } | ||||
| 
 | ||||
|   if (defines.SINGLE_FILE) { | ||||
|     // In singlefile mode, all of the src files will be bundled into
 | ||||
|     // the main pdf.js output.
 | ||||
|     mainFiles = mainFiles.concat(workerFiles); | ||||
|     workerFiles = null; // no need for worker file
 | ||||
|     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; | ||||
|   var workerFileConfig = createWebpackConfig(defines, { | ||||
|     filename: workerOutputName, | ||||
|     library: workerAMDName, | ||||
|     libraryTarget: 'umd', | ||||
|     umdNamedDefine: true | ||||
|   }); | ||||
|   var workerOutput = gulp.src('./src/pdf.worker.js') | ||||
|     .pipe(webpack2Stream(workerFileConfig)) | ||||
|     .pipe(replaceWebpackRequire()); | ||||
|   return merge([mainOutput, workerOutput]); | ||||
| } | ||||
| 
 | ||||
| function createWebBundle(defines) { | ||||
|   var versionJSON = getVersionJSON(); | ||||
|   var viewerOutputName = 'viewer.js'; | ||||
| 
 | ||||
|   var template, files, outputName, amdName; | ||||
|   if (defines.COMPONENTS) { | ||||
|     amdName = 'pdfjs-dist/web/pdf_viewer'; | ||||
|     template = 'web/pdf_viewer.component.js'; | ||||
|     files = [ | ||||
|       '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 viewerFileConfig = createWebpackConfig(defines, { | ||||
|     filename: viewerOutputName | ||||
|   }); | ||||
|   return gulp.src('./web/viewer.js') | ||||
|              .pipe(webpack2Stream(viewerFileConfig)); | ||||
| } | ||||
| 
 | ||||
|   var source = stream.Readable({ objectMode: true }); | ||||
|   source._read = function () { | ||||
|     // 'buildnumber' shall create BUILD_DIR for us
 | ||||
|     var tmpFile = BUILD_DIR + '~' + outputName + '.tmp'; | ||||
|     bundle(template, tmpFile, 'web/', files, amdName, defines, false, | ||||
|       versionJSON); | ||||
|     this.push(new gutil.File({ | ||||
|       cwd: '', | ||||
|       base: '', | ||||
|       path: outputName, | ||||
|       contents: fs.readFileSync(tmpFile) | ||||
|     })); | ||||
|     fs.unlinkSync(tmpFile); | ||||
|     this.push(null); | ||||
|   }; | ||||
|   return source; | ||||
| function createComponentsBundle(defines) { | ||||
|   var componentsAMDName = 'pdfjs-dist/web/pdf_viewer'; | ||||
|   var componentsOutputName = 'pdf_viewer.js'; | ||||
| 
 | ||||
|   var componentsFileConfig = createWebpackConfig(defines, { | ||||
|     filename: componentsOutputName, | ||||
|     library: componentsAMDName, | ||||
|     libraryTarget: 'umd', | ||||
|     umdNamedDefine: true | ||||
|   }); | ||||
|   return gulp.src('./web/pdf_viewer.component.js') | ||||
|     .pipe(webpack2Stream(componentsFileConfig)) | ||||
|     .pipe(replaceWebpackRequire()); | ||||
| } | ||||
| 
 | ||||
| function checkFile(path) { | ||||
| @ -631,7 +555,7 @@ gulp.task('components', ['buildnumber'], function () { | ||||
|   ]; | ||||
| 
 | ||||
|   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('web/compatibility.js').pipe(gulp.dest(COMPONENTS_DIR)), | ||||
|     preprocessCSS('web/pdf_viewer.css', 'components', defines, true) | ||||
|  | ||||
| @ -23,6 +23,8 @@ | ||||
|     "streamqueue": "^1.1.1", | ||||
|     "typogr": "~0.6.5", | ||||
|     "uglify-js": "^2.6.1", | ||||
|     "webpack": "^2.2.1", | ||||
|     "webpack-stream": "^3.2.0", | ||||
|     "wintersmith": "^2.0.0", | ||||
|     "yargs": "^3.14.0" | ||||
|   }, | ||||
|  | ||||
| @ -12,8 +12,7 @@ | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| /* globals pdfjsFilePath, pdfjsVersion, pdfjsBuild, requirejs, pdfjsLibs, | ||||
|            __webpack_require__ */ | ||||
| /* globals requirejs, pdfjsLibs, __webpack_require__, __pdfjsdev_webpack__ */ | ||||
| 
 | ||||
| 'use strict'; | ||||
| 
 | ||||
| @ -70,10 +69,18 @@ var isWorkerDisabled = false; | ||||
| var workerSrc; | ||||
| 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 useRequireEnsure = false; | ||||
| // The if below protected by __pdfjsdev_webpack__ check from webpack parsing.
 | ||||
| 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 different  frameworks.
 | ||||
|   if (typeof window === 'undefined') { | ||||
| @ -83,8 +90,8 @@ if (typeof PDFJSDev !== 'undefined' && | ||||
|       require.ensure = require('node-ensure'); | ||||
|     } | ||||
|     useRequireEnsure = true; | ||||
|   } | ||||
|   if (typeof __webpack_require__ !== 'undefined') { | ||||
|   } else if (typeof require !== 'undefined' && | ||||
|              typeof require.ensure === 'function') { | ||||
|     useRequireEnsure = true; | ||||
|   } | ||||
|   if (typeof requirejs !== 'undefined' && requirejs.toUrl) { | ||||
| @ -2184,11 +2191,9 @@ var _UnsupportedManager = (function UnsupportedManagerClosure() { | ||||
|   }; | ||||
| })(); | ||||
| 
 | ||||
| if (typeof pdfjsVersion !== 'undefined') { | ||||
|   exports.version = pdfjsVersion; | ||||
| } | ||||
| if (typeof pdfjsBuild !== 'undefined') { | ||||
|   exports.build = pdfjsBuild; | ||||
| if (typeof PDFJSDev !== 'undefined') { | ||||
|   exports.version = PDFJSDev.eval('BUNDLE_VERSION'); | ||||
|   exports.build = PDFJSDev.eval('BUNDLE_BUILD'); | ||||
| } | ||||
| 
 | ||||
| exports.getDocument = getDocument; | ||||
|  | ||||
| @ -12,7 +12,6 @@ | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| /* globals pdfjsVersion, pdfjsBuild */ | ||||
| 
 | ||||
| 'use strict'; | ||||
| 
 | ||||
| @ -54,11 +53,9 @@ | ||||
|   } | ||||
|   var PDFJS = globalScope.PDFJS; | ||||
| 
 | ||||
|   if (typeof pdfjsVersion !== 'undefined') { | ||||
|     PDFJS.version = pdfjsVersion; | ||||
|   } | ||||
|   if (typeof pdfjsBuild !== 'undefined') { | ||||
|     PDFJS.build = pdfjsBuild; | ||||
|   if (typeof PDFJSDev !== 'undefined') { | ||||
|     PDFJS.version = PDFJSDev.eval('BUNDLE_VERSION'); | ||||
|     PDFJS.build = PDFJSDev.eval('BUNDLE_BUILD'); | ||||
|   } | ||||
| 
 | ||||
|   PDFJS.pdfBug = false; | ||||
|  | ||||
							
								
								
									
										105
									
								
								src/pdf.js
									
									
									
									
									
								
							
							
						
						
									
										105
									
								
								src/pdf.js
									
									
									
									
									
								
							| @ -12,75 +12,50 @@ | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| /* eslint strict: ["error", "function"] */ | ||||
| /* eslint-disable no-unused-vars */ | ||||
| /* umdutils ignore */ | ||||
| 
 | ||||
| (function (root, factory) { | ||||
|   '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'; | ||||
| 'use strict'; | ||||
| 
 | ||||
|   var pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION'); | ||||
|   var pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD'); | ||||
| var pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION'); | ||||
| var pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD'); | ||||
| 
 | ||||
|   var pdfjsFilePath = | ||||
|     typeof document !== 'undefined' && document.currentScript ? | ||||
|       document.currentScript.src : null; | ||||
| var pdfjsSharedUtil = require('./shared/util.js'); | ||||
| var pdfjsDisplayGlobal = require('./display/global.js'); | ||||
| 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() { | ||||
| 
 | ||||
| //#expand __BUNDLE__
 | ||||
| 
 | ||||
|   }).call(pdfjsLibs); | ||||
| 
 | ||||
|   if (PDFJSDev.test('MAIN_FILE')) { | ||||
|     exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS; | ||||
|     exports.build = pdfjsLibs.pdfjsDisplayAPI.build; | ||||
|     exports.version = pdfjsLibs.pdfjsDisplayAPI.version; | ||||
|     exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument; | ||||
|     exports.PDFDataRangeTransport = | ||||
|       pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport; | ||||
|     exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker; | ||||
|     exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer; | ||||
|     exports.AnnotationLayer = | ||||
|       pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer; | ||||
|     exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle; | ||||
|     exports.createPromiseCapability = | ||||
|       pdfjsLibs.pdfjsSharedUtil.createPromiseCapability; | ||||
|     exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses; | ||||
|     exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException; | ||||
|     exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException; | ||||
|     exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics; | ||||
|     exports.UnexpectedResponseException = | ||||
|       pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException; | ||||
|     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; | ||||
|   } | ||||
| })); | ||||
| exports.PDFJS = pdfjsDisplayGlobal.PDFJS; | ||||
| exports.build = pdfjsDisplayAPI.build; | ||||
| exports.version = pdfjsDisplayAPI.version; | ||||
| exports.getDocument = pdfjsDisplayAPI.getDocument; | ||||
| exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport; | ||||
| exports.PDFWorker = pdfjsDisplayAPI.PDFWorker; | ||||
| exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer; | ||||
| exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer; | ||||
| exports.CustomStyle = pdfjsDisplayDOMUtils.CustomStyle; | ||||
| exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability; | ||||
| exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses; | ||||
| exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException; | ||||
| exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException; | ||||
| exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics; | ||||
| exports.UnexpectedResponseException = | ||||
|   pdfjsSharedUtil.UnexpectedResponseException; | ||||
| exports.OPS = pdfjsSharedUtil.OPS; | ||||
| exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES; | ||||
| exports.isValidUrl = pdfjsDisplayDOMUtils.isValidUrl; | ||||
| exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl; | ||||
| exports.createObjectURL = pdfjsSharedUtil.createObjectURL; | ||||
| exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters; | ||||
| exports.shadow = pdfjsSharedUtil.shadow; | ||||
| exports.createBlob = pdfjsSharedUtil.createBlob; | ||||
| exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl; | ||||
| exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes; | ||||
|  | ||||
							
								
								
									
										30
									
								
								src/pdf.worker.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/pdf.worker.js
									
									
									
									
										vendored
									
									
										Normal 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; | ||||
| @ -12,7 +12,7 @@ | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| /* globals DEFAULT_URL, PDFBug, Stats */ | ||||
| /* globals PDFBug, Stats */ | ||||
| 
 | ||||
| 'use strict'; | ||||
| 
 | ||||
| @ -1391,20 +1391,20 @@ function loadAndEnablePDFBug(enabledTabs) { | ||||
| } | ||||
| 
 | ||||
| function webViewerInitialized() { | ||||
|   var appConfig = PDFViewerApplication.appConfig; | ||||
|   var file; | ||||
|   if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { | ||||
|     var queryString = document.location.search.substring(1); | ||||
|     var params = parseQueryString(queryString); | ||||
|     file = 'file' in params ? params.file : DEFAULT_URL; | ||||
|     file = 'file' in params ? params.file : appConfig.defaultUrl; | ||||
|     validateFileURL(file); | ||||
|   } else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) { | ||||
|     file = window.location.href.split('#')[0]; | ||||
|   } else if (PDFJSDev.test('CHROME')) { | ||||
|     file = DEFAULT_URL; | ||||
|     file = appConfig.defaultUrl; | ||||
|   } | ||||
| 
 | ||||
|   var waitForBeforeOpening = []; | ||||
|   var appConfig = PDFViewerApplication.appConfig; | ||||
|   if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { | ||||
|     var fileInput = document.createElement('input'); | ||||
|     fileInput.id = appConfig.openFileInputName; | ||||
|  | ||||
| @ -12,50 +12,38 @@ | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| /* eslint strict: ["error", "function"] */ | ||||
| /* umdutils ignore */ | ||||
| 
 | ||||
| (function (root, factory) { | ||||
|   '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'; | ||||
| 'use strict'; | ||||
| 
 | ||||
|   var pdfViewerLibs = { | ||||
|     pdfjsWebPDFJS: pdfjsLib | ||||
|   }; | ||||
| var pdfjsLib = require('./pdfjs.js'); | ||||
| 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 () { | ||||
| //#expand __BUNDLE__
 | ||||
|   }).call(pdfViewerLibs); | ||||
| var PDFJS = pdfjsLib.PDFJS; | ||||
| 
 | ||||
|   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.PDFPageView = pdfViewerLibs.pdfjsWebPDFPageView.PDFPageView; | ||||
|   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 = pdfjsWebDownloadManager.DownloadManager; | ||||
| PDFJS.ProgressBar = pdfjsWebUIUtils.ProgressBar; | ||||
| 
 | ||||
|   PDFJS.DownloadManager = pdfViewerLibs.pdfjsWebDownloadManager.DownloadManager; | ||||
|   PDFJS.ProgressBar = pdfViewerLibs.pdfjsWebUIUtils.ProgressBar; | ||||
| 
 | ||||
|   exports.PDFJS = PDFJS; | ||||
| })); | ||||
| exports.PDFJS = PDFJS; | ||||
|  | ||||
							
								
								
									
										35
									
								
								web/pdfjs.js
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								web/pdfjs.js
									
									
									
									
									
								
							| @ -12,23 +12,28 @@ | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| /* globals module */ | ||||
| /* umdutils ignore */ | ||||
| 
 | ||||
| 'use strict'; | ||||
| 
 | ||||
| (function (root, factory) { | ||||
|   if (typeof define === 'function' && define.amd) { | ||||
|     define('pdfjs-web/pdfjs', ['exports', 'pdfjs/main_loader'], factory); | ||||
|   } else if (typeof exports !== 'undefined') { | ||||
|     factory(exports, require('../src/main_loader.js')); | ||||
|   } else { | ||||
|     factory((root.pdfjsWebPDFJS = {}), root.pdfjsMainLoader); | ||||
|   } | ||||
| }(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]; | ||||
| if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) { | ||||
|   module.exports = window['pdfjs-dist/build/pdf']; // loaded via html script tag
 | ||||
| } else { | ||||
|   (function (root, factory) { | ||||
|     if (typeof define === 'function' && define.amd) { | ||||
|       define('pdfjs-web/pdfjs', ['exports', 'pdfjs/main_loader'], factory); | ||||
|     } else if (typeof exports !== 'undefined') { | ||||
|       factory(exports, require('../src/main_loader.js')); | ||||
|     } else { | ||||
|       factory((root.pdfjsWebPDFJS = {}), root.pdfjsMainLoader); | ||||
|     } | ||||
|   } | ||||
| })); | ||||
|   }(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]; | ||||
|       } | ||||
|     } | ||||
|   })); | ||||
| } | ||||
|  | ||||
| @ -35,19 +35,21 @@ if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) { | ||||
|   })(); | ||||
| } | ||||
| 
 | ||||
| var pdfjsWebLibs; | ||||
| var pdfjsWebApp; | ||||
| if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) { | ||||
|   pdfjsWebLibs = { | ||||
|     pdfjsWebPDFJS: window.pdfjsDistBuildPdf | ||||
|   }; | ||||
|   (function () { | ||||
| //#expand __BUNDLE__
 | ||||
|   }).call(pdfjsWebLibs); | ||||
|   pdfjsWebApp = require('./app.js'); | ||||
| } | ||||
| 
 | ||||
| if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL')) { | ||||
|   // 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() { | ||||
| @ -162,6 +164,7 @@ function getViewerConfiguration() { | ||||
|     printContainer: document.getElementById('printContainer'), | ||||
|     openFileInputName: 'fileInput', | ||||
|     debuggerScriptPath: './debugger.js', | ||||
|     defaultUrl: DEFAULT_URL | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| @ -174,8 +177,8 @@ function webViewerLoad() { | ||||
|       web.PDFViewerApplication.run(config); | ||||
|     }); | ||||
|   } else { | ||||
|     window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication; | ||||
|     pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication.run(config); | ||||
|     window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication; | ||||
|     pdfjsWebApp.PDFViewerApplication.run(config); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user