[Pkg-javascript-commits] [pdf.js] 368/414: Introduces UMD headers to the web/ folder.

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:40 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 006e8fb59d9ee9abad2439fec795a71e0b2360d4
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Fri Apr 8 12:34:27 2016 -0500

    Introduces UMD headers to the web/ folder.
---
 external/builder/builder.js      |   9 +-
 external/umdutils/verifier.js    |   7 +-
 make.js                          | 182 ++++++++++++++++++++++++++-------------
 src/display/api.js               |   2 +-
 test/unit/jasmine-boot.js        |   9 +-
 test/unit/unit_test.html         |   2 -
 web/annotation_layer_builder.js  |  21 ++++-
 web/app.js                       | 119 ++++++++++++++++++-------
 web/chromecom.js                 |  28 ++++--
 web/download_manager.js          |  19 ++--
 web/firefoxcom.js                |  23 ++++-
 web/grab_to_pan.js               |  14 ++-
 web/hand_tool.js                 |  25 +++++-
 web/mozPrintCallback_polyfill.js |  16 +++-
 web/overlay_manager.js           |  13 +++
 web/password_prompt.js           |  20 ++++-
 web/pdf_attachment_viewer.js     |  13 +++
 web/pdf_document_properties.js   |  20 ++++-
 web/pdf_find_bar.js              |  20 ++++-
 web/pdf_find_controller.js       |  20 ++++-
 web/pdf_history.js               |  15 +++-
 web/pdf_link_service.js          |  67 +++++++++++++-
 web/pdf_outline_viewer.js        |  13 +++
 web/pdf_page_view.js             |  26 +++++-
 web/pdf_presentation_mode.js     |  13 +++
 web/pdf_rendering_queue.js       |  14 +++
 web/pdf_sidebar.js               |  18 +++-
 web/pdf_thumbnail_view.js        |  21 ++++-
 web/pdf_thumbnail_viewer.js      |  25 +++++-
 web/pdf_viewer.component.js      |  38 ++++----
 web/pdf_viewer.js                |  99 +++++++++------------
 web/platform_integration.js      |  30 -------
 web/preferences.js               |  17 +++-
 web/secondary_toolbar.js         |  26 +++++-
 web/text_layer_builder.js        |  14 +++
 web/ui_utils.js                  |  33 ++++++-
 web/view_history.js              |  13 +++
 web/viewer.html                  |  27 ------
 web/viewer.js                    |  26 ++++--
 39 files changed, 836 insertions(+), 281 deletions(-)

diff --git a/external/builder/builder.js b/external/builder/builder.js
index e1d2cf0..6c05bbc 100644
--- a/external/builder/builder.js
+++ b/external/builder/builder.js
@@ -66,7 +66,14 @@ function preprocess(inFilename, outFilename, defines) {
     var realPath = fs.realpathSync(inFilename);
     var dir = path.dirname(realPath);
     try {
-      preprocess(path.join(dir, file), writeLine, defines);
+      var fullpath;
+      if (file.indexOf('$ROOT/') === 0) {
+        fullpath = path.join(__dirname, '../..',
+          file.substring('$ROOT/'.length));
+      } else {
+        fullpath = path.join(dir, file);
+      }
+      preprocess(fullpath, writeLine, defines);
     } catch (e) {
       if (e.code === 'ENOENT') {
         throw new Error('Failed to include "' + file + '" at ' + loc());
diff --git a/external/umdutils/verifier.js b/external/umdutils/verifier.js
index 97ed7f8..000872a 100644
--- a/external/umdutils/verifier.js
+++ b/external/umdutils/verifier.js
@@ -245,7 +245,8 @@ function validateFile(path, name, context) {
     if (name !== umd.amdId) {
       error('AMD name does not match module name');
     }
-    if (name.replace(/[_\/]/g, '') !== umd.jsRootName.toLowerCase()) {
+    if (name.replace(/[_\-\/]/g, '').toLowerCase() !==
+        umd.jsRootName.toLowerCase()) {
       error('root name does not look like module name');
     }
 
@@ -272,7 +273,7 @@ function validateFile(path, name, context) {
         return;
       }
       i = i.substring('root.'.length);
-      var j = umd.imports[index];
+      var j = umd.imports[index].replace(/(_|Lib)$/, '');
       var offset = i.toLowerCase().lastIndexOf(j.toLowerCase());
       if (offset + j.length !== i.length) {
         error('JS import name does not look like corresponding body import ' +
@@ -281,7 +282,7 @@ function validateFile(path, name, context) {
 
       j = umd.amdImports[index];
       if (j) {
-        if (j.replace(/[_\/]/g, '') !== i.toLowerCase()) {
+        if (j.replace(/[_\-\/]/g, '').toLowerCase() !== i.toLowerCase()) {
           error('JS import name does not look like corresponding AMD import ' +
             'name: ' + i + ' vs ' + j);
         }
diff --git a/make.js b/make.js
index 5bd5c39..6fb54fe 100644
--- a/make.js
+++ b/make.js
@@ -36,6 +36,7 @@ var config = JSON.parse(fs.readFileSync(CONFIG_FILE));
 
 // Defined by buildnumber target.
 var BUILD_NUMBER,
+    BUILD_COMMIT,
     VERSION;
 
 var ROOT_DIR = __dirname + '/', // absolute path to project's root
@@ -100,8 +101,7 @@ var COMMON_WEB_FILES =
       ['web/images',
        'web/debugger.js'],
     COMMON_WEB_FILES_PREPROCESS =
-      ['web/viewer.js',
-       'web/viewer.html'],
+      ['web/viewer.html'],
     COMMON_FIREFOX_FILES_PREPROCESS =
       [FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm',
        FIREFOX_CONTENT_DIR + 'PdfjsContentUtils.jsm',
@@ -127,6 +127,13 @@ target.generic = function() {
 
   var defines = builder.merge(DEFINES, {GENERIC: true});
 
+  var TMP_VIEWER = GENERIC_DIR + '/web/viewer.js.tmp';
+  cd('web/');
+  var viewerBundleFiles = ['app.js'];
+  bundle('viewer.js', ROOT_DIR + TMP_VIEWER,  viewerBundleFiles,
+    'pdfjs-dist/web/viewer', defines, true);
+  cd(ROOT_DIR);
+
   var setup = {
     defines: defines,
     copy: [
@@ -140,6 +147,7 @@ target.generic = function() {
     ],
     preprocess: [
       [BUILD_TARGETS, GENERIC_DIR + BUILD_DIR],
+      [TMP_VIEWER, GENERIC_DIR + '/web/viewer.js'],
       [COMMON_WEB_FILES_PREPROCESS, GENERIC_DIR + '/web']
     ],
     preprocessCSS: [
@@ -152,6 +160,7 @@ target.generic = function() {
   cleanupJSSource(GENERIC_DIR + '/build/pdf.js');
   cleanupJSSource(GENERIC_DIR + '/web/viewer.js');
   cleanupCSSSource(GENERIC_DIR + '/web/viewer.css');
+  rm(TMP_VIEWER);
 };
 
 target.components = function() {
@@ -163,7 +172,18 @@ target.components = function() {
   mkdir('-p', COMPONENTS_DIR);
   mkdir('-p', COMPONENTS_DIR + 'images');
 
-  var defines = builder.merge(DEFINES, {COMPONENTS: true});
+  var defines = builder.merge(DEFINES, {COMPONENTS: true, GENERIC: true});
+
+  var TMP_PDF_VIEWER = COMPONENTS_DIR + 'pdf_viewer.js.tmp';
+  cd('web/');
+  var bundleFiles = [
+    'pdf_viewer.js',
+    'pdf_history.js',
+    'download_manager.js'
+  ];
+  bundle('pdf_viewer.component.js', ROOT_DIR + TMP_PDF_VIEWER, bundleFiles,
+    'pdfjs-dist/web/pdf_viewer', defines, true);
+  cd(ROOT_DIR);
 
   var COMPONENTS_IMAGES = [
     'web/images/annotation-*.svg',
@@ -179,7 +199,7 @@ target.components = function() {
       ['web/compatibility.js', COMPONENTS_DIR],
     ],
     preprocess: [
-      ['web/pdf_viewer.component.js', COMPONENTS_DIR + 'pdf_viewer.js'],
+      [TMP_PDF_VIEWER, COMPONENTS_DIR + 'pdf_viewer.js'],
     ],
     preprocessCSS: [
       ['components', 'web/pdf_viewer.css', COMPONENTS_DIR + 'pdf_viewer.css'],
@@ -189,6 +209,7 @@ target.components = function() {
 
   cleanupJSSource(COMPONENTS_DIR + 'pdf_viewer.js');
   cleanupCSSSource(COMPONENTS_DIR + 'pdf_viewer.css');
+  rm(TMP_PDF_VIEWER);
 };
 
 target.jsdoc = function() {
@@ -477,6 +498,46 @@ target.cmaps = function () {
   compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true);
 };
 
+function bundle(filename, outfilename, initFiles, amdName, defines,
+                isMainFile) {
+  // 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');
+  var files = umd.readDependencies(initFiles).loadOrder.map(
+    function (name) { return name.replace(/^[\w\-]+\//, '') + '.js'; });
+
+  crlfchecker.checkIfCrlfIsPresent(files);
+
+  var bundleContent = cat(files),
+      bundleVersion = VERSION,
+      bundleBuild = BUILD_COMMIT;
+
+  // 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.
+  bundleContent = stripCommentHeaders('\n' + bundleContent);
+
+  // Removes AMD and CommonJS branches from UMD headers.
+  bundleContent = stripUMDHeaders(bundleContent);
+
+  var jsName = amdName.replace(/[\-_\.\/]\w/g, function (all) {
+    return all[1].toUpperCase();
+  });
+
+  // This just preprocesses the empty pdf.js file, we don't actually want to
+  // preprocess everything yet since other build targets use this file.
+  builder.preprocess(filename, outfilename,
+    builder.merge(defines, {
+      BUNDLE: bundleContent,
+      BUNDLE_VERSION: bundleVersion,
+      BUNDLE_BUILD: bundleBuild,
+      BUNDLE_AMD_NAME: amdName,
+      BUNDLE_JS_NAME: jsName,
+      MAIN_FILE: isMainFile
+    }));
+}
+
 //
 // make bundle
 // Bundles all source files into one wrapper 'pdf.js' file, in the given order.
@@ -491,86 +552,45 @@ target.bundle = function(args) {
   echo();
   echo('### Bundling files into ' + BUILD_TARGET);
 
-  function bundle(filename, outfilename, files, distname, isMainFile) {
-    var bundleContent = cat(files),
-        bundleVersion = VERSION,
-        bundleBuild = exec('git log --format="%h" -n 1',
-          {silent: true}).output.replace('\n', '');
-
-    crlfchecker.checkIfCrlfIsPresent(files);
-
-    // 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.
-    bundleContent = stripCommentHeaders('\n' + bundleContent);
-
-    // Removes AMD and CommonJS branches from UMD headers.
-    bundleContent = stripUMDHeaders(bundleContent);
-
-    var amdName = 'pdfjs-dist/build/' + distname.replace(/\.js$/, '');
-    var jsName = amdName.replace(/[\-_\.\/]\w/g, function (all) {
-      return all[1].toUpperCase();
-    });
-    // This just preprocesses the empty pdf.js file, we don't actually want to
-    // preprocess everything yet since other build targets use this file.
-    builder.preprocess(filename, outfilename, builder.merge(defines,
-                           {BUNDLE: bundleContent,
-                            BUNDLE_VERSION: bundleVersion,
-                            BUNDLE_BUILD: bundleBuild,
-                            BUNDLE_AMD_NAME: amdName,
-                            BUNDLE_JS_NAME: jsName,
-                            MAIN_FILE: isMainFile}));
-  }
-
   if (!test('-d', BUILD_DIR)) {
     mkdir(BUILD_DIR);
   }
 
-  var umd = require('./external/umdutils/verifier.js');
-  var MAIN_SRC_FILES = [
-    SRC_DIR + 'display/global.js'
+  var mainFiles = [
+    'display/global.js'
   ];
 
-  var WORKER_SRC_FILES = [
-    SRC_DIR + 'core/worker.js'
+  var workerFiles = [
+    'core/worker.js'
   ];
 
-  var mainFileName = 'pdf.js';
-  var workerFileName = 'pdf.worker.js';
+  var mainAMDName = 'pdfjs-dist/build/pdf';
+  var workerAMDName = 'pdfjs-dist/build/pdf.worker';
 
   // Extension does not need network.js file.
   if (!defines.FIREFOX && !defines.MOZCENTRAL) {
-    WORKER_SRC_FILES.push(SRC_DIR + 'core/network.js');
+    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.
-    MAIN_SRC_FILES = MAIN_SRC_FILES.concat(WORKER_SRC_FILES);
-    WORKER_SRC_FILES = null; // no need for worker file
-    mainFileName = 'pdf.combined.js';
-    workerFileName = null;
+    mainFiles = mainFiles.concat(workerFiles);
+    workerFiles = null; // no need for worker file
+    mainAMDName = 'pdfjs-dist/build/pdf.combined';
+    workerAMDName = null;
   }
 
-  // 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 mainFiles = umd.readDependencies(MAIN_SRC_FILES).loadOrder.map(
-    function (name) { return name.replace('pdfjs/', '') + '.js'; });
-
-  var workerFiles = WORKER_SRC_FILES &&
-                    umd.readDependencies(WORKER_SRC_FILES).loadOrder.map(
-    function (name) { return name.replace('pdfjs/', '') + '.js'; });
-
   cd(SRC_DIR);
 
-  bundle('pdf.js', ROOT_DIR + BUILD_TARGET, mainFiles, mainFileName, true);
+  bundle('pdf.js', ROOT_DIR + BUILD_TARGET, mainFiles, mainAMDName, defines,
+         true);
 
   if (workerFiles) {
     var srcCopy = ROOT_DIR + BUILD_DIR + 'pdf.worker.js.temp';
     cp('pdf.js', srcCopy);
-    bundle(srcCopy, ROOT_DIR + BUILD_WORKER_TARGET, workerFiles,
-           workerFileName, false);
+    bundle(srcCopy, ROOT_DIR + BUILD_WORKER_TARGET, workerFiles, workerAMDName,
+           defines, false);
     rm(srcCopy);
   }
 };
@@ -674,6 +694,13 @@ target.minified = function() {
 
   var defines = builder.merge(DEFINES, {GENERIC: true, MINIFIED: true});
 
+  var TMP_VIEWER = MINIFIED_DIR + '/web/viewer.js.tmp';
+  cd('web/');
+  var viewerBundleFiles = ['app.js'];
+  bundle('viewer.js', ROOT_DIR + TMP_VIEWER, viewerBundleFiles,
+    'pdfjs-dist/web/viewer', defines, true);
+  cd(ROOT_DIR);
+
   var setup = {
     defines: defines,
     copy: [
@@ -684,6 +711,7 @@ target.minified = function() {
     ],
     preprocess: [
       [BUILD_TARGETS, MINIFIED_DIR + BUILD_DIR],
+      [TMP_VIEWER, MINIFIED_DIR + '/web/viewer.js'],
       [COMMON_WEB_FILES_PREPROCESS, MINIFIED_DIR + '/web']
     ],
     preprocessCSS: [
@@ -694,6 +722,7 @@ target.minified = function() {
   builder.build(setup);
 
   cleanupCSSSource(MINIFIED_DIR + '/web/viewer.css');
+  rm(TMP_VIEWER);
 
   var viewerFiles = [
     'web/compatibility.js',
@@ -760,6 +789,9 @@ target.buildnumber = function() {
   echo('Extension build number: ' + BUILD_NUMBER);
 
   VERSION = config.versionPrefix + BUILD_NUMBER;
+
+  BUILD_COMMIT = exec('git log --format="%h" -n 1',  {silent: true}).
+    output.replace('\n', '');
 };
 
 //
@@ -817,6 +849,14 @@ target.firefox = function() {
   cp('-R', FIREFOX_EXTENSION_FILES_TO_COPY, ROOT_DIR + FIREFOX_BUILD_DIR);
   cd(ROOT_DIR);
 
+  var TMP_VIEWER = FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.js.tmp';
+  cd('web/');
+  var viewerBundleFiles = ['app.js', 'firefoxcom.js'];
+  bundle('viewer.js', ROOT_DIR + TMP_VIEWER, viewerBundleFiles,
+    'pdfjs-dist/web/viewer', defines, true);
+  cd(ROOT_DIR);
+
+
   var setup = {
     defines: defines,
     copy: [
@@ -827,6 +867,7 @@ target.firefox = function() {
        FIREFOX_BUILD_CONTENT_DIR + '/web']
     ],
     preprocess: [
+      [TMP_VIEWER, FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.js'],
       [COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'],
       [BUILD_TARGETS, FIREFOX_BUILD_CONTENT_DIR + BUILD_DIR],
       [COMMON_FIREFOX_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR],
@@ -844,6 +885,7 @@ target.firefox = function() {
   cleanupJSSource(FIREFOX_BUILD_DIR + 'bootstrap.js');
   cleanupJSSource(FIREFOX_BUILD_CONTENT_DIR + 'PdfjsChromeUtils.jsm');
   cleanupCSSSource(FIREFOX_BUILD_CONTENT_DIR + '/web/viewer.css');
+  rm(TMP_VIEWER);
 
   // Remove '.DS_Store' and other hidden files
   find(FIREFOX_BUILD_DIR).forEach(function(file) {
@@ -944,6 +986,13 @@ target.mozcentral = function() {
            ROOT_DIR + MOZCENTRAL_EXTENSION_DIR + '/chrome.manifest');
   cd(ROOT_DIR);
 
+  var TMP_VIEWER = MOZCENTRAL_CONTENT_DIR + '/web/viewer.js.tmp';
+  cd('web/');
+  var viewerBundleFiles = ['app.js', 'firefoxcom.js'];
+  bundle('viewer.js', ROOT_DIR + TMP_VIEWER, viewerBundleFiles,
+    'pdfjs-dist/web/viewer', defines, true);
+  cd(ROOT_DIR);
+
   var setup = {
     defines: defines,
     copy: [
@@ -952,6 +1001,7 @@ target.mozcentral = function() {
       ['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web']
     ],
     preprocess: [
+      [TMP_VIEWER, MOZCENTRAL_CONTENT_DIR + '/web/viewer.js'],
       [COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'],
       [FIREFOX_CONTENT_DIR + 'pdfjschildbootstrap.js', MOZCENTRAL_CONTENT_DIR],
       [BUILD_TARGETS, MOZCENTRAL_CONTENT_DIR + BUILD_DIR],
@@ -971,6 +1021,7 @@ target.mozcentral = function() {
   cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/PdfJs.jsm');
   cleanupJSSource(MOZCENTRAL_CONTENT_DIR + '/PdfjsChromeUtils.jsm');
   cleanupCSSSource(MOZCENTRAL_CONTENT_DIR + '/web/viewer.css');
+  rm(TMP_VIEWER);
 
   // Remove '.DS_Store' and other hidden files
   find(MOZCENTRAL_DIR).forEach(function(file) {
@@ -1076,6 +1127,13 @@ target.chromium = function() {
   mkdir('-p', CHROME_BUILD_CONTENT_DIR + BUILD_DIR);
   mkdir('-p', CHROME_BUILD_CONTENT_DIR + '/web');
 
+  var TMP_VIEWER = CHROME_BUILD_CONTENT_DIR + '/web/viewer.js.tmp';
+  cd('web/');
+  var viewerBundleFiles = ['app.js', 'chromecom.js'];
+  bundle('viewer.js', ROOT_DIR + TMP_VIEWER, viewerBundleFiles,
+    'pdfjs-dist/web/viewer', defines, true);
+  cd(ROOT_DIR);
+
   var setup = {
     defines: defines,
     copy: [
@@ -1094,6 +1152,7 @@ target.chromium = function() {
     ],
     preprocess: [
       [BUILD_TARGETS, CHROME_BUILD_CONTENT_DIR + BUILD_DIR],
+      [TMP_VIEWER, CHROME_BUILD_CONTENT_DIR + '/web/viewer.js'],
       [COMMON_WEB_FILES_PREPROCESS, CHROME_BUILD_CONTENT_DIR + '/web']
     ],
     preprocessCSS: [
@@ -1105,6 +1164,7 @@ target.chromium = function() {
 
   cleanupJSSource(CHROME_BUILD_CONTENT_DIR + '/web/viewer.js');
   cleanupCSSSource(CHROME_BUILD_CONTENT_DIR + '/web/viewer.css');
+  rm(TMP_VIEWER);
 
   // Update the build version number
   sed('-i', /PDFJSSCRIPT_VERSION/, VERSION,
@@ -1506,7 +1566,7 @@ target.lint = function() {
   echo();
   echo('### Checking UMD dependencies');
   var umd = require('./external/umdutils/verifier.js');
-  if (!umd.validateFiles({'pdfjs': './src'})) {
+  if (!umd.validateFiles({'pdfjs': './src', 'pdfjs-web': './web'})) {
     exit(1);
   }
 
diff --git a/src/display/api.js b/src/display/api.js
index 3dfb939..c882bca 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -71,7 +71,7 @@ var isPostMessageTransfersDisabled = false;
 
 //#if PRODUCTION && !SINGLE_FILE
 //#if GENERIC
-//#include ../src/frameworks.js
+//#include $ROOT/src/frameworks.js
 //#else
 //var fakeWorkerFilesLoader = null;
 //#endif
diff --git a/test/unit/jasmine-boot.js b/test/unit/jasmine-boot.js
index 8ae3bda..60d7f73 100644
--- a/test/unit/jasmine-boot.js
+++ b/test/unit/jasmine-boot.js
@@ -43,19 +43,19 @@
 var pdfjsLibs;
 
 function initializePDFJS(callback) {
-  require.config({paths: {'pdfjs': '../../src'}});
+  require.config({paths: {'pdfjs': '../../src', 'pdfjs-web': '../../web'}});
   require(['pdfjs/shared/util', 'pdfjs/display/global', 'pdfjs/core/primitives',
       'pdfjs/core/annotation', 'pdfjs/core/crypto', 'pdfjs/core/stream',
       'pdfjs/core/fonts', 'pdfjs/core/ps_parser', 'pdfjs/core/function',
       'pdfjs/core/parser', 'pdfjs/core/evaluator', 'pdfjs/core/cmap',
       'pdfjs/core/worker', 'pdfjs/core/network', 'pdfjs/core/type1_parser',
       'pdfjs/core/cff_parser', 'pdfjs/display/api', 'pdfjs/display/metadata',
-      'pdfjs/display/dom_utils'],
+      'pdfjs/display/dom_utils', 'pdfjs-web/ui_utils'],
     function (sharedUtil, displayGlobal, corePrimitives, coreAnnotation,
               coreCrypto, coreStream, coreFonts, corePsParser, coreFunction,
               coreParser, coreEvaluator, coreCMap, coreWorker, coreNetwork,
               coreType1Parser, coreCFFParser, displayAPI, displayMetadata,
-              displayDOMUtils) {
+              displayDOMUtils, webUIUtils) {
 
       pdfjsLibs = {
         sharedUtil: sharedUtil,
@@ -76,7 +76,8 @@ function initializePDFJS(callback) {
         coreCFFParser: coreCFFParser,
         displayAPI: displayAPI,
         displayMetadata: displayMetadata,
-        displayDOMUtils: displayDOMUtils
+        displayDOMUtils: displayDOMUtils,
+        webUIUtils: webUIUtils
       };
 
       // Expose all loaded internal exported members to global scope.
diff --git a/test/unit/unit_test.html b/test/unit/unit_test.html
index dcef372..720f636 100644
--- a/test/unit/unit_test.html
+++ b/test/unit/unit_test.html
@@ -11,8 +11,6 @@
   <script src="testreporter.js"></script>
   <script src="jasmine-boot.js"></script>
 
-  <script src="../../web/ui_utils.js"></script>
-
   <!-- include spec files here... -->
   <script src="primitives_spec.js"></script>
   <script src="font_spec.js"></script>
diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js
index d2bf28b..37da4e8 100644
--- a/web/annotation_layer_builder.js
+++ b/web/annotation_layer_builder.js
@@ -12,10 +12,26 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*globals pdfjsLib, mozL10n, SimpleLinkService */
+/*globals pdfjsLib */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/annotation_layer_builder', ['exports',
+      'pdfjs-web/ui_utils', 'pdfjs-web/pdf_link_service'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'),
+      require('./pdf_link_service.js'));
+  } else {
+    factory((root.pdfjsWebAnnotationLayerBuilder = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebPDFLinkService);
+  }
+}(this, function (exports, uiUtils, pdfLinkService) {
+
+var mozL10n = uiUtils.mozL10n;
+var SimpleLinkService = pdfLinkService.SimpleLinkService;
+
 /**
  * @typedef {Object} AnnotationLayerBuilderOptions
  * @property {HTMLDivElement} pageDiv
@@ -119,3 +135,6 @@ DefaultAnnotationLayerFactory.prototype = {
     });
   }
 };
+
+exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
+}));
diff --git a/web/app.js b/web/app.js
index 532286e..9dbee31 100644
--- a/web/app.js
+++ b/web/app.js
@@ -12,18 +12,92 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals pdfjsLib, PDFBug, FirefoxCom, Stats, ProgressBar, DownloadManager,
-           getPDFFileNameFromURL, PDFHistory, Preferences, SidebarView,
-           ViewHistory, Stats, PDFThumbnailViewer, URL, noContextMenuHandler,
-           SecondaryToolbar, PasswordPrompt, PDFPresentationMode, PDFSidebar,
-           PDFDocumentProperties, HandTool, Promise, PDFLinkService,
-           PDFOutlineViewer, PDFAttachmentViewer, OverlayManager,
-           PDFFindController, PDFFindBar, PDFViewer, PDFRenderingQueue,
-           PresentationModeState, parseQueryString, RenderingStates,
-           UNKNOWN_SCALE, DEFAULT_SCALE_VALUE, DEFAULT_URL, mozL10n */
+/* globals DEFAULT_URL, pdfjsLib, PDFBug, Stats */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/app', ['exports', 'pdfjs-web/ui_utils',
+      'pdfjs-web/firefoxcom', 'pdfjs-web/download_manager',
+      'pdfjs-web/pdf_history', 'pdfjs-web/preferences', 'pdfjs-web/pdf_sidebar',
+      'pdfjs-web/view_history', 'pdfjs-web/pdf_thumbnail_viewer',
+      'pdfjs-web/secondary_toolbar', 'pdfjs-web/password_prompt',
+      'pdfjs-web/pdf_presentation_mode', 'pdfjs-web/pdf_document_properties',
+      'pdfjs-web/hand_tool', 'pdfjs-web/pdf_viewer',
+      'pdfjs-web/pdf_rendering_queue', 'pdfjs-web/pdf_link_service',
+      'pdfjs-web/pdf_outline_viewer', 'pdfjs-web/overlay_manager',
+      'pdfjs-web/pdf_attachment_viewer', 'pdfjs-web/pdf_find_controller',
+      'pdfjs-web/pdf_find_bar', 'pdfjs-web/mozPrintCallback_polyfill'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'), require('./firefoxcom.js'),
+      require('./download_manager.js'), require('./pdf_history.js'),
+      require('./preferences.js'), require('./pdf_sidebar.js'),
+      require('./view_history.js'), require('./pdf_thumbnail_viewer.js'),
+      require('./secondary_toolbar.js'), require('./password_prompt.js'),
+      require('./pdf_presentation_mode.js'),
+      require('./pdf_document_properties.js'), require('./hand_tool.js'),
+      require('./pdf_viewer.js'), require('./pdf_rendering_queue.js'),
+      require('./pdf_link_service.js'), require('./pdf_outline_viewer.js'),
+      require('./overlay_manager.js'), require('./pdf_attachment_viewer.js'),
+      require('./pdf_find_controller.js'), require('./pdf_find_bar.js'),
+      require('./mozPrintCallback_polyfill.js'));
+  } else {
+    factory((root.pdfjsWebApp = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebFirefoxCom, root.pdfjsWebDownloadManager,
+      root.pdfjsWebPDFHistory, root.pdfjsWebPreferences,
+      root.pdfjsWebPDFSidebar, root.pdfjsWebViewHistory,
+      root.pdfjsWebPDFThumbnailViewer, root.pdfjsWebSecondaryToolbar,
+      root.pdfjsWebPasswordPrompt, root.pdfjsWebPDFPresentationMode,
+      root.pdfjsWebPDFDocumentProperties, root.pdfjsWebHandTool,
+      root.pdfjsWebPDFViewer, root.pdfjsWebPDFRenderingQueue,
+      root.pdfjsWebPDFLinkService, root.pdfjsWebPDFOutlineViewer,
+      root.pdfjsWebOverlayManager, root.pdfjsWebPDFAttachmentViewer,
+      root.pdfjsWebPDFFindController, root.pdfjsWebPDFFindBar,
+      root.pdfjsWebMozPrintCallbackPolyfill);
+  }
+}(this, function (exports, uiUtilsLib, firefoxComLib, downloadManagerLib,
+                  pdfHistoryLib, preferencesLib, pdfSidebarLib, viewHistoryLib,
+                  pdfThumbnailViewerLib, secondaryToolbarLib, passwordPromptLib,
+                  pdfPresentationModeLib, pdfDocumentPropertiesLib, handToolLib,
+                  pdfViewerLib, pdfRenderingQueueLib, pdfLinkServiceLib,
+                  pdfOutlineViewerLib, overlayManagerLib,
+                  pdfAttachmentViewerLib, pdfFindControllerLib, pdfFindBarLib,
+                  mozPrintCallbackPolyfillLib) {
+
+var FirefoxCom = firefoxComLib.FirefoxCom;
+var UNKNOWN_SCALE = uiUtilsLib.UNKNOWN_SCALE;
+var DEFAULT_SCALE_VALUE = uiUtilsLib.DEFAULT_SCALE_VALUE;
+var ProgressBar = uiUtilsLib.ProgressBar;
+var getPDFFileNameFromURL = uiUtilsLib.getPDFFileNameFromURL;
+var noContextMenuHandler = uiUtilsLib.noContextMenuHandler;
+var mozL10n = uiUtilsLib.mozL10n;
+var parseQueryString = uiUtilsLib.parseQueryString;
+var DownloadManager = downloadManagerLib.DownloadManager ||
+                      firefoxComLib.DownloadManager;
+var PDFHistory = pdfHistoryLib.PDFHistory;
+var Preferences = preferencesLib.Preferences;
+var SidebarView = pdfSidebarLib.SidebarView;
+var PDFSidebar = pdfSidebarLib.PDFSidebar;
+var ViewHistory = viewHistoryLib.ViewHistory;
+var PDFThumbnailViewer = pdfThumbnailViewerLib.PDFThumbnailViewer;
+var SecondaryToolbar = secondaryToolbarLib.SecondaryToolbar;
+var PasswordPrompt = passwordPromptLib.PasswordPrompt;
+var PDFPresentationMode = pdfPresentationModeLib.PDFPresentationMode;
+var PDFDocumentProperties = pdfDocumentPropertiesLib.PDFDocumentProperties;
+var HandTool = handToolLib.HandTool;
+var PresentationModeState = pdfViewerLib.PresentationModeState;
+var PDFViewer = pdfViewerLib.PDFViewer;
+var RenderingStates = pdfRenderingQueueLib.RenderingStates;
+var PDFRenderingQueue = pdfRenderingQueueLib.PDFRenderingQueue;
+var PDFLinkService = pdfLinkServiceLib.PDFLinkService;
+var PDFOutlineViewer = pdfOutlineViewerLib.PDFOutlineViewer;
+var OverlayManager = overlayManagerLib.OverlayManager;
+var PDFAttachmentViewer = pdfAttachmentViewerLib.PDFAttachmentViewer;
+var PDFFindController = pdfFindControllerLib.PDFFindController;
+var PDFFindBar = pdfFindBarLib.PDFFindBar;
+
 var DEFAULT_SCALE_DELTA = 1.1;
 var MIN_SCALE = 0.25;
 var MAX_SCALE = 10.0;
@@ -47,26 +121,6 @@ function configure(PDFJS) {
 //#endif
 }
 
-//#include ui_utils.js
-//#include preferences.js
-//#include platform_integration.js
-//#include view_history.js
-//#include pdf_find_bar.js
-//#include pdf_find_controller.js
-//#include pdf_link_service.js
-//#include pdf_history.js
-//#include secondary_toolbar.js
-//#include pdf_presentation_mode.js
-//#include hand_tool.js
-//#include overlay_manager.js
-//#include password_prompt.js
-//#include pdf_document_properties.js
-//#include pdf_viewer.js
-//#include pdf_thumbnail_viewer.js
-//#include pdf_sidebar.js
-//#include pdf_outline_viewer.js
-//#include pdf_attachment_viewer.js
-
 var PDFViewerApplication = {
   initialBookmark: document.location.hash.substring(1),
   initialDestination: null,
@@ -2144,3 +2198,10 @@ window.addEventListener('afterprint', function afterPrint(evt) {
     window.requestAnimationFrame(resolve);
   });
 })();
+
+exports.PDFViewerApplication = PDFViewerApplication;
+
+// TODO remove circular reference of pdfjs-web/secondary_toolbar on app.
+secondaryToolbarLib._setApp(exports);
+
+}));
diff --git a/web/chromecom.js b/web/chromecom.js
index f9848f0..5464ce7 100644
--- a/web/chromecom.js
+++ b/web/chromecom.js
@@ -13,10 +13,27 @@
  * limitations under the License.
  */
 
-/* globals chrome, pdfjsLib, PDFViewerApplication, OverlayManager */
+/* globals chrome, pdfjsLib */
 'use strict';
 
-var ChromeCom = (function ChromeComClosure() {
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/chromecom', ['exports', 'pdfjs-web/app',
+      'pdfjs-web/overlay_manager'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./app.js'), require('./overlay_manager.js'));
+  } else {
+    factory((root.pdfjsWebChromeCom = {}), root.pdfjsWebApp,
+      root.pdfjsWebOverlayManager);
+  }
+}(this, function (exports, app, overlayManager) {
+//#if CHROME
+//#if !CHROME
+  if (true) { return; } // TODO ensure nothing depends on this module.
+//#endif
+  var PDFViewerApplication = app.PDFViewerApplication;
+  var OverlayManager = overlayManager.OverlayManager;
+
   var ChromeCom = {};
   /**
    * Creates an event that the extension is listening for and will
@@ -205,7 +222,7 @@ var ChromeCom = (function ChromeComClosure() {
       // because the shown string should match the UI at chrome://extensions.
       // These strings are from chrome/app/resources/generated_resources_*.xtb.
       var i18nFileAccessLabel =
-//#include chrome-i18n-allow-access-to-file-urls.json
+//#include $ROOT/web/chrome-i18n-allow-access-to-file-urls.json
         [chrome.i18n.getUILanguage && chrome.i18n.getUILanguage()];
 
       if (i18nFileAccessLabel) {
@@ -304,5 +321,6 @@ var ChromeCom = (function ChromeComClosure() {
     }
   }
 
-  return ChromeCom;
-})();
+  exports.ChromeCom = ChromeCom;
+//#endif
+}));
diff --git a/web/download_manager.js b/web/download_manager.js
index dc899e7..d7cc544 100644
--- a/web/download_manager.js
+++ b/web/download_manager.js
@@ -12,12 +12,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals URL, pdfjsLib */
+/* globals pdfjsLib */
 
 'use strict';
 
-var DownloadManager = (function DownloadManagerClosure() {
-
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/download_manager', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebDownloadManager = {}));
+  }
+}(this, function (exports) {
+//#if GENERIC || CHROME
   function download(blobUrl, filename) {
     var a = document.createElement('a');
     if (a.click) {
@@ -97,5 +105,6 @@ var DownloadManager = (function DownloadManagerClosure() {
     }
   };
 
-  return DownloadManager;
-})();
+  exports.DownloadManager = DownloadManager;
+//#endif
+}));
diff --git a/web/firefoxcom.js b/web/firefoxcom.js
index 1931f1f..0d6a3e2 100644
--- a/web/firefoxcom.js
+++ b/web/firefoxcom.js
@@ -12,10 +12,26 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals Preferences, pdfjsLib, Promise */
+/* globals pdfjsLib */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/firefoxcom', ['exports', 'pdfjs-web/preferences'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./preferences.js'));
+  } else {
+    factory((root.pdfjsWebFirefoxCom = {}), root.pdfjsWebPreferences);
+  }
+}(this, function (exports, preferences) {
+//#if FIREFOX || MOZCENTRAL
+//#if !(FIREFOX || MOZCENTRAL)
+  if (true) { return; }  // TODO ensure nothing depends on this module.
+//#endif
+var Preferences = preferences.Preferences;
+
 var FirefoxCom = (function FirefoxComClosure() {
   return {
     /**
@@ -132,3 +148,8 @@ Preferences._readFromStorage = function (prefObj) {
     });
   });
 };
+
+exports.DownloadManager = DownloadManager;
+exports.FirefoxCom = FirefoxCom;
+//#endif
+}));
diff --git a/web/grab_to_pan.js b/web/grab_to_pan.js
index e50a6bc..f27f74f 100644
--- a/web/grab_to_pan.js
+++ b/web/grab_to_pan.js
@@ -16,7 +16,15 @@
 
 'use strict';
 
-var GrabToPan = (function GrabToPanClosure() {
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/grab_to_pan', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebGrabToPan = {}));
+  }
+}(this, function (exports) {
   /**
    * Construct a GrabToPan instance for a given HTML element.
    * @param options.element {Element}
@@ -217,5 +225,5 @@ var GrabToPan = (function GrabToPanClosure() {
     }
   }
 
-  return GrabToPan;
-})();
+  exports.GrabToPan = GrabToPan;
+}));
diff --git a/web/hand_tool.js b/web/hand_tool.js
index a16e019..85addc5 100644
--- a/web/hand_tool.js
+++ b/web/hand_tool.js
@@ -12,11 +12,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals mozL10n, GrabToPan, Preferences, SecondaryToolbar */
 
 'use strict';
 
-//#include grab_to_pan.js
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/hand_tool', ['exports', 'pdfjs-web/ui_utils',
+      'pdfjs-web/grab_to_pan', 'pdfjs-web/preferences',
+      'pdfjs-web/secondary_toolbar'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'), require('./grab_to_pan.js'),
+      require('./preferences.js'), require('./secondary_toolbar.js'));
+  } else {
+    factory((root.pdfjsWebHandTool = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebGrabToPan, root.pdfjsWebPreferences,
+      root.pdfjsWebSecondaryToolbar);
+  }
+}(this, function (exports, uiUtils, grabToPan, preferences, secondaryToolbar) {
+
+var mozL10n = uiUtils.mozL10n;
+var GrabToPan = grabToPan.GrabToPan;
+var Preferences = preferences.Preferences;
+var SecondaryToolbar = secondaryToolbar.SecondaryToolbar;
+
 var HandTool = {
   initialize: function handToolInitialize(options) {
     var toggleHandTool = options.toggleHandTool;
@@ -82,3 +100,6 @@ var HandTool = {
     }
   }
 };
+
+exports.HandTool = HandTool;
+}));
diff --git a/web/mozPrintCallback_polyfill.js b/web/mozPrintCallback_polyfill.js
index d1a2f8e..afc4407 100644
--- a/web/mozPrintCallback_polyfill.js
+++ b/web/mozPrintCallback_polyfill.js
@@ -15,10 +15,21 @@
 /* globals HTMLCanvasElement */
 
 'use strict';
-(function mozPrintCallbackPolyfillClosure() {
+
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/mozPrintCallback_polyfill', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebMozPrintCallbackPolyfill = {}));
+  }
+}(this, function (exports) {
+//#if !(FIREFOX || MOZCENTRAL)
   if ('mozPrintCallback' in document.createElement('canvas')) {
     return;
   }
+
   // Cause positive result on feature-detection:
   HTMLCanvasElement.prototype.mozPrintCallback = undefined;
 
@@ -139,4 +150,5 @@
     window.addEventListener('beforeprint', stopPropagationIfNeeded, false);
     window.addEventListener('afterprint', stopPropagationIfNeeded, false);
   }
-})();
+//#endif
+}));
diff --git a/web/overlay_manager.js b/web/overlay_manager.js
index 56b23ab..1807d27 100644
--- a/web/overlay_manager.js
+++ b/web/overlay_manager.js
@@ -15,6 +15,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/overlay_manager', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebOverlayManager = {}));
+  }
+}(this, function (exports) {
+
 var OverlayManager = {
   overlays: {},
   active: null,
@@ -141,3 +151,6 @@ var OverlayManager = {
     }
   }
 };
+
+exports.OverlayManager = OverlayManager;
+}));
diff --git a/web/password_prompt.js b/web/password_prompt.js
index 4ca9474..38fe8a3 100644
--- a/web/password_prompt.js
+++ b/web/password_prompt.js
@@ -12,10 +12,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals pdfjsLib, mozL10n, OverlayManager */
+/* globals pdfjsLib */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/password_prompt', ['exports',
+      'pdfjs-web/ui_utils', 'pdfjs-web/overlay_manager'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'), require('./overlay_manager.js'));
+  } else {
+    factory((root.pdfjsWebPasswordPrompt = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebOverlayManager);
+  }
+}(this, function (exports, uiUtils, overlayManager) {
+
+var mozL10n = uiUtils.mozL10n;
+var OverlayManager = overlayManager.OverlayManager;
+
 var PasswordPrompt = {
   overlayName: null,
   updatePassword: null,
@@ -79,3 +94,6 @@ var PasswordPrompt = {
     }
   }
 };
+
+exports.PasswordPrompt = PasswordPrompt;
+}));
diff --git a/web/pdf_attachment_viewer.js b/web/pdf_attachment_viewer.js
index 68c90d8..8dc9b0e 100644
--- a/web/pdf_attachment_viewer.js
+++ b/web/pdf_attachment_viewer.js
@@ -16,6 +16,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_attachment_viewer', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebPDFAttachmentViewer = {}));
+  }
+}(this, function (exports) {
+
 /**
  * @typedef {Object} PDFAttachmentViewerOptions
  * @property {HTMLDivElement} container - The viewer element.
@@ -114,3 +124,6 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
 
   return PDFAttachmentViewer;
 })();
+
+exports.PDFAttachmentViewer = PDFAttachmentViewer;
+}));
diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js
index 73444b3..4fa9bc8 100644
--- a/web/pdf_document_properties.js
+++ b/web/pdf_document_properties.js
@@ -12,10 +12,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals mozL10n, getPDFFileNameFromURL, OverlayManager */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_document_properties', ['exports',
+      'pdfjs-web/ui_utils', 'pdfjs-web/overlay_manager'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'), require('./overlay_manager.js'));
+  } else {
+    factory((root.pdfjsWebPDFDocumentProperties = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebOverlayManager);
+  }
+}(this, function (exports, uiUtils, overlayManager) {
+
+var getPDFFileNameFromURL = uiUtils.getPDFFileNameFromURL;
+var mozL10n = uiUtils.mozL10n;
+var OverlayManager = overlayManager.OverlayManager;
+
 /**
  * @typedef {Object} PDFDocumentPropertiesOptions
  * @property {string} overlayName - Name/identifier for the overlay.
@@ -222,3 +237,6 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
 
   return PDFDocumentProperties;
 })();
+
+exports.PDFDocumentProperties = PDFDocumentProperties;
+}));
diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js
index ffcbef7..02d2e75 100644
--- a/web/pdf_find_bar.js
+++ b/web/pdf_find_bar.js
@@ -12,10 +12,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals FindStates, mozL10n */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_find_bar', ['exports',
+      'pdfjs-web/ui_utils', 'pdfjs-web/pdf_find_controller'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'),
+      require('./pdf_find_controller.js'));
+  } else {
+    factory((root.pdfjsWebPDFFindBar = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebPDFFindController);
+  }
+}(this, function (exports, uiUtils, pdfFindController) {
+
+var mozL10n = uiUtils.mozL10n;
+var FindStates = pdfFindController.FindStates;
+
 /**
  * Creates a "search bar" given a set of DOM elements that act as controls
  * for searching or for setting search preferences in the UI. This object
@@ -188,3 +203,6 @@ var PDFFindBar = (function PDFFindBarClosure() {
   };
   return PDFFindBar;
 })();
+
+exports.PDFFindBar = PDFFindBar;
+}));
diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js
index 89fae75..ac813f7 100644
--- a/web/pdf_find_controller.js
+++ b/web/pdf_find_controller.js
@@ -12,10 +12,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals FirefoxCom, Promise, scrollIntoView */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_find_controller', ['exports',
+      'pdfjs-web/ui_utils', 'pdfjs-web/firefoxcom'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'), require('./firefoxcom.js'));
+  } else {
+    factory((root.pdfjsWebPDFFindController = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebFirefoxCom);
+  }
+}(this, function (exports, uiUtils, firefoxCom) {
+
+var scrollIntoView = uiUtils.scrollIntoView;
+var FirefoxCom = firefoxCom.FirefoxCom;
+
 var FindStates = {
   FIND_FOUND: 0,
   FIND_NOTFOUND: 1,
@@ -416,3 +430,7 @@ var PDFFindController = (function PDFFindControllerClosure() {
   };
   return PDFFindController;
 })();
+
+exports.FindStates = FindStates;
+exports.PDFFindController = PDFFindController;
+}));
diff --git a/web/pdf_history.js b/web/pdf_history.js
index fdca1e5..403caef 100644
--- a/web/pdf_history.js
+++ b/web/pdf_history.js
@@ -15,7 +15,16 @@
 
 'use strict';
 
-var PDFHistory = (function () {
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_history', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebPDFHistory = {}));
+  }
+}(this, function (exports) {
+
   function PDFHistory(options) {
     this.linkService = options.linkService;
 
@@ -423,5 +432,5 @@ var PDFHistory = (function () {
     }
   };
 
-  return PDFHistory;
-})();
+  exports.PDFHistory = PDFHistory;
+}));
diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js
index 4340118..eac27dd 100644
--- a/web/pdf_link_service.js
+++ b/web/pdf_link_service.js
@@ -12,10 +12,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFViewer, PDFHistory, Promise, parseQueryString */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_link_service', ['exports', 'pdfjs-web/ui_utils'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'));
+  } else {
+    factory((root.pdfjsWebPDFLinkService = {}), root.pdfjsWebUIUtils);
+  }
+}(this, function (exports, uiUtils) {
+
+var parseQueryString = uiUtils.parseQueryString;
+
 /**
  * Performs navigation functions inside PDF, such as opening specified page,
  * or destination.
@@ -299,3 +311,56 @@ var PDFLinkService = (function () {
 
   return PDFLinkService;
 })();
+
+var SimpleLinkService = (function SimpleLinkServiceClosure() {
+  function SimpleLinkService() {}
+
+  SimpleLinkService.prototype = {
+    /**
+     * @returns {number}
+     */
+    get page() {
+      return 0;
+    },
+    /**
+     * @param {number} value
+     */
+    set page(value) {},
+    /**
+     * @param dest - The PDF destination object.
+     */
+    navigateTo: function (dest) {},
+    /**
+     * @param dest - The PDF destination object.
+     * @returns {string} The hyperlink to the PDF object.
+     */
+    getDestinationHash: function (dest) {
+      return '#';
+    },
+    /**
+     * @param hash - The PDF parameters/hash.
+     * @returns {string} The hyperlink to the PDF object.
+     */
+    getAnchorUrl: function (hash) {
+      return '#';
+    },
+    /**
+     * @param {string} hash
+     */
+    setHash: function (hash) {},
+    /**
+     * @param {string} action
+     */
+    executeNamedAction: function (action) {},
+    /**
+     * @param {number} pageNum - page number.
+     * @param {Object} pageRef - reference to the page.
+     */
+    cachePageRef: function (pageNum, pageRef) {}
+  };
+  return SimpleLinkService;
+})();
+
+exports.PDFLinkService = PDFLinkService;
+exports.SimpleLinkService = SimpleLinkService;
+}));
diff --git a/web/pdf_outline_viewer.js b/web/pdf_outline_viewer.js
index 235380c..6fd1425 100644
--- a/web/pdf_outline_viewer.js
+++ b/web/pdf_outline_viewer.js
@@ -16,6 +16,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_outline_viewer', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebPDFOutlineViewer = {}));
+  }
+}(this, function (exports) {
+
 var DEFAULT_TITLE = '\u2013';
 
 /**
@@ -210,3 +220,6 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
 
   return PDFOutlineViewer;
 })();
+
+exports.PDFOutlineViewer = PDFOutlineViewer;
+}));
diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js
index 81e1c1b..4f3227b 100644
--- a/web/pdf_page_view.js
+++ b/web/pdf_page_view.js
@@ -12,11 +12,30 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals RenderingStates, pdfjsLib, DEFAULT_SCALE, CSS_UNITS, getOutputScale,
-           TextLayerBuilder, Promise, approximateFraction, roundToDivide */
+/* globals pdfjsLib */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_page_view', ['exports',
+      'pdfjs-web/ui_utils', 'pdfjs-web/pdf_rendering_queue'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'),
+      require('./pdf_rendering_queue.js'));
+  } else {
+    factory((root.pdfjsWebPDFPageView = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebPDFRenderingQueue);
+  }
+}(this, function (exports, uiUtils, pdfRenderingQueue) {
+
+var CSS_UNITS = uiUtils.CSS_UNITS;
+var DEFAULT_SCALE = uiUtils.DEFAULT_SCALE;
+var getOutputScale = uiUtils.getOutputScale;
+var approximateFraction = uiUtils.approximateFraction;
+var roundToDivide = uiUtils.roundToDivide;
+var RenderingStates = pdfRenderingQueue.RenderingStates;
+
 var TEXT_LAYER_RENDER_DELAY = 200; // ms
 
 /**
@@ -582,3 +601,6 @@ var PDFPageView = (function PDFPageViewClosure() {
 
   return PDFPageView;
 })();
+
+exports.PDFPageView = PDFPageView;
+}));
diff --git a/web/pdf_presentation_mode.js b/web/pdf_presentation_mode.js
index 4da6f34..537ee3d 100644
--- a/web/pdf_presentation_mode.js
+++ b/web/pdf_presentation_mode.js
@@ -15,6 +15,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_presentation_mode', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebPDFPresentationMode = {}));
+  }
+}(this, function (exports) {
+
 var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500; // in ms
 var DELAY_BEFORE_HIDING_CONTROLS = 3000; // in ms
 var ACTIVE_SELECTOR = 'pdfPresentationMode';
@@ -389,3 +399,6 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
 
   return PDFPresentationMode;
 })();
+
+exports.PDFPresentationMode = PDFPresentationMode;
+}));
diff --git a/web/pdf_rendering_queue.js b/web/pdf_rendering_queue.js
index 89f77cd..63f0ba4 100644
--- a/web/pdf_rendering_queue.js
+++ b/web/pdf_rendering_queue.js
@@ -15,6 +15,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_rendering_queue', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebPDFRenderingQueue = {}));
+  }
+}(this, function (exports) {
+
 var CLEANUP_TIMEOUT = 30000;
 
 var RenderingStates = {
@@ -175,3 +185,7 @@ var PDFRenderingQueue = (function PDFRenderingQueueClosure() {
 
   return PDFRenderingQueue;
 })();
+
+exports.RenderingStates = RenderingStates;
+exports.PDFRenderingQueue = PDFRenderingQueue;
+}));
diff --git a/web/pdf_sidebar.js b/web/pdf_sidebar.js
index aa78803..c28b4db 100644
--- a/web/pdf_sidebar.js
+++ b/web/pdf_sidebar.js
@@ -12,10 +12,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- /* globals RenderingStates */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_sidebar', ['exports',
+      'pdfjs-web/pdf_rendering_queue'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./pdf_rendering_queue.js'));
+  } else {
+    factory((root.pdfjsWebPDFSidebar = {}), root.pdfjsWebPDFRenderingQueue);
+  }
+}(this, function (exports, pdfRenderingQueue) {
+
+var RenderingStates = pdfRenderingQueue.RenderingStates;
+
 var SidebarView = {
   NONE: 0,
   THUMBS: 1,
@@ -330,3 +342,7 @@ var PDFSidebar = (function PDFSidebarClosure() {
 
   return PDFSidebar;
 })();
+
+exports.SidebarView = SidebarView;
+exports.PDFSidebar = PDFSidebar;
+}));
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 5908904..1d96af7 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -12,10 +12,26 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals mozL10n, RenderingStates, Promise, getOutputScale */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_thumbnail_view', ['exports',
+      'pdfjs-web/ui_utils', 'pdfjs-web/pdf_rendering_queue'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'),
+      require('./pdf_rendering_queue.js'));
+  } else {
+    factory((root.pdfjsWebPDFThumbnailView = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebPDFRenderingQueue);
+  }
+}(this, function (exports, uiUtils, pdfRenderingQueue) {
+
+var mozL10n = uiUtils.mozL10n;
+var getOutputScale = uiUtils.getOutputScale;
+var RenderingStates = pdfRenderingQueue.RenderingStates;
+
 var THUMBNAIL_WIDTH = 98; // px
 var THUMBNAIL_CANVAS_BORDER_WIDTH = 1; // px
 
@@ -377,3 +393,6 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
 })();
 
 PDFThumbnailView.tempImageCache = null;
+
+exports.PDFThumbnailView = PDFThumbnailView;
+}));
diff --git a/web/pdf_thumbnail_viewer.js b/web/pdf_thumbnail_viewer.js
index 2b1397b..2a67414 100644
--- a/web/pdf_thumbnail_viewer.js
+++ b/web/pdf_thumbnail_viewer.js
@@ -12,14 +12,28 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals watchScroll, getVisibleElements, scrollIntoView, PDFThumbnailView,
-           Promise */
 
 'use strict';
 
-var THUMBNAIL_SCROLL_MARGIN = -19;
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_thumbnail_viewer', ['exports',
+      'pdfjs-web/ui_utils', 'pdfjs-web/pdf_thumbnail_view'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'),
+      require('./pdf_thumbnail_view.js'));
+  } else {
+    factory((root.pdfjsWebPDFThumbnailViewer = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebPDFThumbnailView);
+  }
+}(this, function (exports, uiUtils, pdfThumbnailView) {
 
-//#include pdf_thumbnail_view.js
+var watchScroll = uiUtils.watchScroll;
+var getVisibleElements = uiUtils.getVisibleElements;
+var scrollIntoView = uiUtils.scrollIntoView;
+var PDFThumbnailView = pdfThumbnailView.PDFThumbnailView;
+
+var THUMBNAIL_SCROLL_MARGIN = -19;
 
 /**
  * @typedef {Object} PDFThumbnailViewerOptions
@@ -196,3 +210,6 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() {
 
   return PDFThumbnailViewer;
 })();
+
+exports.PDFThumbnailViewer = PDFThumbnailViewer;
+}));
diff --git a/web/pdf_viewer.component.js b/web/pdf_viewer.component.js
index 596362c..f1c33bd 100644
--- a/web/pdf_viewer.component.js
+++ b/web/pdf_viewer.component.js
@@ -13,9 +13,6 @@
  * limitations under the License.
  */
 /*jshint globalstrict: false */
-/* globals PDFJS, PDFViewer, PDFPageView, TextLayerBuilder, PDFLinkService,
-           DefaultTextLayerFactory, AnnotationLayerBuilder, PDFHistory,
-           DefaultAnnotationLayerFactory, DownloadManager, ProgressBar */
 
 (function pdfViewerWrapper() {
   'use strict';
@@ -32,21 +29,26 @@
     });
   }
 
-//#include ui_utils.js
-//#include pdf_link_service.js
-//#include pdf_viewer.js
-//#include pdf_history.js
-//#include download_manager.js
+  var pdfViewerLibs = {};
+  (function () {
+//#expand __BUNDLE__
+  }).call(pdfViewerLibs);
 
-  PDFJS.PDFViewer = PDFViewer;
-  PDFJS.PDFPageView = PDFPageView;
-  PDFJS.PDFLinkService = PDFLinkService;
-  PDFJS.TextLayerBuilder = TextLayerBuilder;
-  PDFJS.DefaultTextLayerFactory = DefaultTextLayerFactory;
-  PDFJS.AnnotationLayerBuilder = AnnotationLayerBuilder;
-  PDFJS.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
-  PDFJS.PDFHistory = PDFHistory;
+  var PDFJS = window.PDFJS || (window.PDFJS = {});
 
-  PDFJS.DownloadManager = DownloadManager;
-  PDFJS.ProgressBar = ProgressBar;
+  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.DownloadManager = pdfViewerLibs.pdfjsWebDownloadManager.DownloadManager;
+  PDFJS.ProgressBar = pdfViewerLibs.pdfjsWebUIUtils.ProgressBar;
 }).call((typeof window === 'undefined') ? this : window);
diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js
index 766d88c..8ff3a52 100644
--- a/web/pdf_viewer.js
+++ b/web/pdf_viewer.js
@@ -12,14 +12,47 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- /*globals watchScroll, PDFPageView, UNKNOWN_SCALE,
-           SCROLLBAR_PADDING, VERTICAL_PADDING, MAX_AUTO_SCALE, CSS_UNITS,
-           DEFAULT_SCALE, scrollIntoView, getVisibleElements, RenderingStates,
-           pdfjsLib, Promise, TextLayerBuilder, PDFRenderingQueue,
-           AnnotationLayerBuilder, DEFAULT_SCALE_VALUE */
+/* globals pdfjsLib */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/pdf_viewer', ['exports', 'pdfjs-web/ui_utils',
+      'pdfjs-web/pdf_page_view', 'pdfjs-web/pdf_rendering_queue',
+      'pdfjs-web/text_layer_builder', 'pdfjs-web/annotation_layer_builder',
+      'pdfjs-web/pdf_link_service'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'), require('./pdf_page_view.js'),
+      require('./pdf_rendering_queue.js'), require('./text_layer_builder.js'),
+      require('./annotation_layer_builder.js'),
+      require('./pdf_link_service.js'));
+  } else {
+    factory((root.pdfjsWebPDFViewer = {}), root.pdfjsWebUIUtils,
+      root.pdfjsWebPDFPageView, root.pdfjsWebPDFRenderingQueue,
+      root.pdfjsWebTextLayerBuilder, root.pdfjsWebAnnotationLayerBuilder,
+      root.pdfjsWebPDFLinkService);
+  }
+}(this, function (exports, uiUtils, pdfPageView, pdfRenderingQueue,
+                  textLayerBuilder, annotationLayerBuilder, pdfLinkService) {
+
+var UNKNOWN_SCALE = uiUtils.UNKNOWN_SCALE;
+var SCROLLBAR_PADDING = uiUtils.SCROLLBAR_PADDING;
+var VERTICAL_PADDING = uiUtils.VERTICAL_PADDING;
+var MAX_AUTO_SCALE = uiUtils.MAX_AUTO_SCALE;
+var CSS_UNITS = uiUtils.CSS_UNITS;
+var DEFAULT_SCALE = uiUtils.DEFAULT_SCALE;
+var DEFAULT_SCALE_VALUE = uiUtils.DEFAULT_SCALE_VALUE;
+var scrollIntoView = uiUtils.scrollIntoView;
+var watchScroll = uiUtils.watchScroll;
+var getVisibleElements = uiUtils.getVisibleElements;
+var PDFPageView = pdfPageView.PDFPageView;
+var RenderingStates = pdfRenderingQueue.RenderingStates;
+var PDFRenderingQueue = pdfRenderingQueue.PDFRenderingQueue;
+var TextLayerBuilder = textLayerBuilder.TextLayerBuilder;
+var AnnotationLayerBuilder = annotationLayerBuilder.AnnotationLayerBuilder;
+var SimpleLinkService = pdfLinkService.SimpleLinkService;
+
 var PresentationModeState = {
   UNKNOWN: 0,
   NORMAL: 1,
@@ -29,11 +62,6 @@ var PresentationModeState = {
 
 var DEFAULT_CACHE_SIZE = 10;
 
-//#include pdf_rendering_queue.js
-//#include pdf_page_view.js
-//#include text_layer_builder.js
-//#include annotation_layer_builder.js
-
 /**
  * @typedef {Object} PDFViewerOptions
  * @property {HTMLDivElement} container - The container for the viewer element.
@@ -772,51 +800,6 @@ var PDFViewer = (function pdfViewer() {
   return PDFViewer;
 })();
 
-var SimpleLinkService = (function SimpleLinkServiceClosure() {
-  function SimpleLinkService() {}
-
-  SimpleLinkService.prototype = {
-    /**
-     * @returns {number}
-     */
-    get page() {
-      return 0;
-    },
-    /**
-     * @param {number} value
-     */
-    set page(value) {},
-    /**
-     * @param dest - The PDF destination object.
-     */
-    navigateTo: function (dest) {},
-    /**
-     * @param dest - The PDF destination object.
-     * @returns {string} The hyperlink to the PDF object.
-     */
-    getDestinationHash: function (dest) {
-      return '#';
-    },
-    /**
-     * @param hash - The PDF parameters/hash.
-     * @returns {string} The hyperlink to the PDF object.
-     */
-    getAnchorUrl: function (hash) {
-      return '#';
-    },
-    /**
-     * @param {string} hash
-     */
-    setHash: function (hash) {},
-    /**
-     * @param {string} action
-     */
-    executeNamedAction: function (action) {},
-    /**
-     * @param {number} pageNum - page number.
-     * @param {Object} pageRef - reference to the page.
-     */
-    cachePageRef: function (pageNum, pageRef) {}
-  };
-  return SimpleLinkService;
-})();
+exports.PresentationModeState = PresentationModeState;
+exports.PDFViewer = PDFViewer;
+}));
diff --git a/web/platform_integration.js b/web/platform_integration.js
deleted file mode 100644
index bd7f80d..0000000
--- a/web/platform_integration.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Copyright 2016 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.
- */
-
-//#if !(FIREFOX || MOZCENTRAL)
-//#include mozPrintCallback_polyfill.js
-//#endif
-
-//#if GENERIC || CHROME
-//#include download_manager.js
-//#endif
-
-//#if FIREFOX || MOZCENTRAL
-//#include firefoxcom.js
-//#endif
-
-//#if CHROME
-//#include chromecom.js
-//#endif
diff --git a/web/preferences.js b/web/preferences.js
index f0cd46f..e3c28f3 100644
--- a/web/preferences.js
+++ b/web/preferences.js
@@ -12,11 +12,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals DEFAULT_PREFERENCES, Promise */
+/* globals DEFAULT_PREFERENCES, chrome */
 
 'use strict';
 
-//#include default_preferences.js
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/preferences', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebPreferences = {}));
+  }
+}(this, function (exports) {
+
+//#include $ROOT/web/default_preferences.js
 
 /**
  * Preferences - Utility for storing persistent settings.
@@ -209,3 +219,6 @@ Preferences._readFromStorage = function (prefObj) {
   });
 };
 //#endif
+
+exports.Preferences = Preferences;
+}));
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index a672783..83adaf7 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -12,10 +12,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFViewerApplication, SCROLLBAR_PADDING */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/secondary_toolbar', ['exports', 'pdfjs-web/ui_utils'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./ui_utils.js'));
+  } else {
+    factory((root.pdfjsWebSecondaryToolbar = {}), root.pdfjsWebUIUtils);
+  }
+}(this, function (exports, uiUtils) {
+
+var SCROLLBAR_PADDING = uiUtils.SCROLLBAR_PADDING;
+
+var app; // Avoiding circular reference, see _setApp function below.
+var PDFViewerApplication = null; // = app.PDFViewerApplication;
+
 var SecondaryToolbar = {
   opened: false,
   previousContainerHeight: null,
@@ -158,3 +173,12 @@ var SecondaryToolbar = {
     }
   }
 };
+
+function _setApp(app_) {
+  app = app_;
+  PDFViewerApplication = app.PDFViewerApplication;
+}
+
+exports.SecondaryToolbar = SecondaryToolbar;
+exports._setApp = _setApp;
+}));
diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js
index e246fa9..d64729d 100644
--- a/web/text_layer_builder.js
+++ b/web/text_layer_builder.js
@@ -16,6 +16,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/text_layer_builder', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebTextLayerBuilder = {}));
+  }
+}(this, function (exports) {
+
 /**
  * @typedef {Object} TextLayerBuilderOptions
  * @property {HTMLDivElement} textLayerDiv - The text layer container.
@@ -346,3 +356,7 @@ DefaultTextLayerFactory.prototype = {
     });
   }
 };
+
+exports.TextLayerBuilder = TextLayerBuilder;
+exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
+}));
diff --git a/web/ui_utils.js b/web/ui_utils.js
index 0f54adc..08b99b0 100644
--- a/web/ui_utils.js
+++ b/web/ui_utils.js
@@ -12,10 +12,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- /* global PDFJS */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/ui_utils', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebUIUtils = {}));
+  }
+}(this, function (exports) {
+
 var CSS_UNITS = 96.0 / 72.0;
 var DEFAULT_SCALE_VALUE = 'auto';
 var DEFAULT_SCALE = 1.0;
@@ -458,3 +468,24 @@ var ProgressBar = (function ProgressBarClosure() {
 
   return ProgressBar;
 })();
+
+exports.CSS_UNITS = CSS_UNITS;
+exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
+exports.DEFAULT_SCALE = DEFAULT_SCALE;
+exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
+exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
+exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
+exports.VERTICAL_PADDING = VERTICAL_PADDING;
+exports.mozL10n = mozL10n;
+exports.ProgressBar = ProgressBar;
+exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
+exports.noContextMenuHandler = noContextMenuHandler;
+exports.parseQueryString = parseQueryString;
+exports.getVisibleElements = getVisibleElements;
+exports.roundToDivide = roundToDivide;
+exports.approximateFraction = approximateFraction;
+exports.getOutputScale = getOutputScale;
+exports.scrollIntoView = scrollIntoView;
+exports.watchScroll = watchScroll;
+exports.binarySearchFirstItem = binarySearchFirstItem;
+}));
diff --git a/web/view_history.js b/web/view_history.js
index b8404e6..8f18520 100644
--- a/web/view_history.js
+++ b/web/view_history.js
@@ -15,6 +15,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs-web/view_history', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsWebViewHistory = {}));
+  }
+}(this, function (exports) {
+
 var DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
 
 /**
@@ -115,3 +125,6 @@ var ViewHistory = (function ViewHistoryClosure() {
 
   return ViewHistory;
 })();
+
+exports.ViewHistory = ViewHistory;
+}));
diff --git a/web/viewer.html b/web/viewer.html
index 0018bba..8c11041 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -61,34 +61,7 @@ See https://github.com/adobe-type-tools/cmap-resources
 <!--#endif-->
 
 <!--#if !PRODUCTION-->
-    <script src="ui_utils.js"></script>
     <script src="default_preferences.js"></script>
-    <script src="preferences.js"></script>
-    <script src="download_manager.js"></script>
-    <script src="platform_integration.js"></script>
-    <script src="view_history.js"></script>
-    <script src="pdf_link_service.js"></script>
-    <script src="pdf_rendering_queue.js"></script>
-    <script src="pdf_page_view.js"></script>
-    <script src="text_layer_builder.js"></script>
-    <script src="annotation_layer_builder.js"></script>
-    <script src="pdf_viewer.js"></script>
-    <script src="pdf_thumbnail_view.js"></script>
-    <script src="pdf_thumbnail_viewer.js"></script>
-    <script src="pdf_sidebar.js"></script>
-    <script src="pdf_outline_viewer.js"></script>
-    <script src="pdf_attachment_viewer.js"></script>
-    <script src="pdf_find_bar.js"></script>
-    <script src="pdf_find_controller.js"></script>
-    <script src="pdf_history.js"></script>
-    <script src="secondary_toolbar.js"></script>
-    <script src="pdf_presentation_mode.js"></script>
-    <script src="grab_to_pan.js"></script>
-    <script src="hand_tool.js"></script>
-    <script src="overlay_manager.js"></script>
-    <script src="password_prompt.js"></script>
-    <script src="pdf_document_properties.js"></script>
-    <script src="app.js"></script>
 <!--#endif-->
 
 <!--#if !MINIFIED -->
diff --git a/web/viewer.js b/web/viewer.js
index 20b6371..2b98498 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -12,21 +12,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*globals require, parseQueryString, chrome, PDFViewerApplication */
+/*globals require, chrome */
 
 'use strict';
 
 var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';
 
-//#include app.js
+var pdfjsWebLibs = {};
+(function () {
+//#expand __BUNDLE__
+}).call(pdfjsWebLibs);
+
+//#if FIREFOX || MOZCENTRAL
+//// FIXME the l10n.js file in the Firefox extension needs global FirefoxCom.
+//window.FirefoxCom = pdfjsWebLibs.pdfjsWebFirefoxCom.FirefoxCom;
+//#endif
 
 //#if CHROME
 //(function rewriteUrlClosure() {
 //  // Run this code outside DOMContentLoaded to make sure that the URL
 //  // is rewritten as soon as possible.
 //  var queryString = document.location.search.slice(1);
-//  var params = parseQueryString(queryString);
-//  DEFAULT_URL = params.file || '';
+//  var m = /(^|&)file=([^&]*)/.exec(queryString);
+//  DEFAULT_URL = m ? decodeURIComponent(m[2]) : '';
 //
 //  // Example: chrome-extension://.../http://example.com/file.pdf
 //  var humanReadableUrl = '/' + DEFAULT_URL + location.hash;
@@ -39,14 +47,16 @@ var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';
 
 function webViewerLoad() {
 //#if !PRODUCTION
-  require.config({paths: {'pdfjs': '../src'}});
-  require(['pdfjs/main_loader'], function (loader) {
+  require.config({paths: {'pdfjs': '../src', 'pdfjs-web': '.'}});
+  require(['pdfjs/main_loader', 'pdfjs-web/app'], function (loader, web) {
     window.pdfjsLib = loader;
-    PDFViewerApplication.run();
+    window.PDFViewerApplication = web.PDFViewerApplication;
+    web.PDFViewerApplication.run();
   });
 //#else
 //window.pdfjsLib = window.pdfjsDistBuildPdf;
-//PDFViewerApplication.run();
+//window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication;
+//pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication.run();
 //#endif
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list