[Pkg-javascript-commits] [pdf.js] 01/414: Adds UMD headers to core, display and shared files.

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:11:59 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 6b60c8f4dbd87233ccf5ad7e0fca617fd02dca9c
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Sat Nov 21 10:32:47 2015 -0600

    Adds UMD headers to core, display and shared files.
---
 .jshintrc                                     |   6 +
 examples/acroforms/index.html                 |  14 +-
 examples/helloworld/index.html                |  13 +-
 examples/svgviewer/index.html                 |   9 +-
 make.js                                       |  15 +-
 src/core/annotation.js                        |  48 +++-
 src/core/arithmetic_decoder.js                |  13 +
 src/core/bidi.js                              |  16 +-
 src/core/charsets.js                          |  15 +
 src/core/chunked_stream.js                    |  24 +-
 src/core/cmap.js                              |  35 ++-
 src/core/colorspace.js                        |  44 ++-
 src/core/crypto.js                            |  40 ++-
 src/core/{core.js => document.js}             |  69 ++++-
 src/core/evaluator.js                         |  90 +++++-
 src/core/font_renderer.js                     |  36 ++-
 src/core/fonts.js                             |  86 +++++-
 src/core/function.js                          |  30 +-
 src/core/glyphlist.js                         |  14 +
 src/core/image.js                             |  39 ++-
 src/core/jbig2.js                             |  26 +-
 src/core/jpg.js                               |  17 +-
 src/core/jpx.js                               |  25 +-
 src/core/metrics.js                           |  13 +
 src/core/murmurhash3.js                       |  16 +-
 src/core/obj.js                               | 369 ++++---------------------
 src/core/parser.js                            |  57 +++-
 src/core/pattern.js                           |  33 ++-
 src/core/pdf_manager.js                       |  30 +-
 src/core/primitives.js                        | 378 ++++++++++++++++++++++++++
 src/core/ps_parser.js                         |  21 +-
 src/core/stream.js                            |  70 ++++-
 src/core/worker.js                            |  50 +++-
 src/display/annotation_layer.js               |  27 +-
 src/display/api.js                            |  53 +++-
 src/display/canvas.js                         |  50 +++-
 src/display/dom_utils.js                      |  17 +-
 src/display/font_loader.js                    |  30 +-
 src/display/metadata.js                       |  17 +-
 src/display/pattern_helper.js                 |  34 ++-
 src/display/svg.js                            |  25 +-
 src/display/text_layer.js                     |  18 +-
 src/display/webgl.js                          |  17 +-
 src/expose_to_global.js                       |  35 +++
 src/shared/global.js                          |  47 ++++
 src/shared/util.js                            | 108 +++++---
 src/worker_loader.js                          |  44 +--
 test/driver.js                                |   7 +-
 test/font/font_test.html                      |  53 ++--
 test/test_slave.html                          |  13 +-
 test/unit/font_spec.js                        |   8 +-
 test/unit/{obj_spec.js => primitives_spec.js} |   2 +-
 test/unit/unit_test.html                      |  57 ++--
 web/viewer.html                               |  13 +-
 54 files changed, 1870 insertions(+), 566 deletions(-)

diff --git a/.jshintrc b/.jshintrc
index b777537..19c53a4 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -3,6 +3,12 @@
   "browser": true,
   "devel": true,
   "worker": true,
+  "predef": [
+    "Promise",
+    "require",
+    "define",
+    "exports"
+  ],
 
   // Enforcing
   "maxlen": 80,
diff --git a/examples/acroforms/index.html b/examples/acroforms/index.html
index a54ba70..15b9fde 100644
--- a/examples/acroforms/index.html
+++ b/examples/acroforms/index.html
@@ -4,17 +4,17 @@
 <head>
   <!-- In production, only one script (pdf.js) is necessary -->
   <!-- In production, change the content of PDFJS.workerSrc below -->
+  <script src="../../src/shared/global.js"></script>
+  <script src="../../src/display/dom_utils.js"></script>
   <script src="../../src/shared/util.js"></script>
-  <script src="../../src/display/api.js"></script>
+  <script src="../../src/display/annotation_layer.js"></script>
+  <script src="../../src/display/font_loader.js"></script>
   <script src="../../src/display/metadata.js"></script>
-  <script src="../../src/display/canvas.js"></script>
+  <script src="../../src/display/text_layer.js"></script>
   <script src="../../src/display/webgl.js"></script>
   <script src="../../src/display/pattern_helper.js"></script>
-  <script src="../../src/display/font_loader.js"></script>
-  <script src="../../src/display/dom_utils.js"></script>
-  <script src="../../src/display/annotation_layer.js"></script>
-  <script src="../../src/display/text_layer.js"></script>
-
+  <script src="../../src/display/canvas.js"></script>
+  <script src="../../src/display/api.js"></script>
   <script>
     // Specify the main script used to create a new PDF.JS web worker.
     // In production, change this to point to the combined `pdf.js` file.
diff --git a/examples/helloworld/index.html b/examples/helloworld/index.html
index 02947cf..8172122 100644
--- a/examples/helloworld/index.html
+++ b/examples/helloworld/index.html
@@ -4,16 +4,17 @@
 <head>
   <!-- In production, only one script (pdf.js) is necessary -->
   <!-- In production, change the content of PDFJS.workerSrc below -->
+  <script src="../../src/shared/global.js"></script>
+  <script src="../../src/display/dom_utils.js"></script>
   <script src="../../src/shared/util.js"></script>
-  <script src="../../src/display/api.js"></script>
+  <script src="../../src/display/annotation_layer.js"></script>
+  <script src="../../src/display/font_loader.js"></script>
   <script src="../../src/display/metadata.js"></script>
-  <script src="../../src/display/canvas.js"></script>
+  <script src="../../src/display/text_layer.js"></script>
   <script src="../../src/display/webgl.js"></script>
   <script src="../../src/display/pattern_helper.js"></script>
-  <script src="../../src/display/font_loader.js"></script>
-  <script src="../../src/display/dom_utils.js"></script>
-  <script src="../../src/display/annotation_layer.js"></script>
-  <script src="../../src/display/text_layer.js"></script>
+  <script src="../../src/display/canvas.js"></script>
+  <script src="../../src/display/api.js"></script>
 
   <script>
     // Specify the main script used to create a new PDF.JS web worker.
diff --git a/examples/svgviewer/index.html b/examples/svgviewer/index.html
index 2fb5ce8..b519375 100644
--- a/examples/svgviewer/index.html
+++ b/examples/svgviewer/index.html
@@ -4,12 +4,15 @@
 <head>
   <!-- In production, only one script (pdf.js) is necessary -->
   <!-- In production, change the content of PDFJS.workerSrc below -->
+  <script src="../../src/shared/global.js"></script>
   <script src="../../src/shared/util.js"></script>
-  <script src="../../src/display/api.js"></script>
-  <script src="../../src/display/metadata.js"></script>
-  <script src="../../src/display/pattern_helper.js"></script>
   <script src="../../src/display/font_loader.js"></script>
+  <script src="../../src/display/metadata.js"></script>
   <script src="../../src/display/svg.js"></script>
+  <script src="../../src/display/webgl.js"></script>
+  <script src="../../src/display/pattern_helper.js"></script>
+  <script src="../../src/display/canvas.js"></script>
+  <script src="../../src/display/api.js"></script>
 
   <script>
     // Specify the main script used to create a new PDF.JS web worker.
diff --git a/make.js b/make.js
index 4e3448c..60c360e 100644
--- a/make.js
+++ b/make.js
@@ -520,19 +520,20 @@ target.bundle = function(args) {
   }
 
   var SHARED_SRC_FILES = [
-    'shared/util.js',
+    'shared/global.js',
+    'shared/util.js'
   ];
 
   var MAIN_SRC_FILES = SHARED_SRC_FILES.concat([
-    'display/api.js',
-    'display/metadata.js',
-    'display/canvas.js',
-    'display/webgl.js',
-    'display/pattern_helper.js',
-    'display/font_loader.js',
     'display/dom_utils.js',
     'display/annotation_layer.js',
+    'display/font_loader.js',
+    'display/metadata.js',
     'display/text_layer.js',
+    'display/webgl.js',
+    'display/pattern_helper.js',
+    'display/canvas.js',
+    'display/api.js',
     'display/svg.js'
   ]);
 
diff --git a/src/core/annotation.js b/src/core/annotation.js
index 80881db..8da90de 100644
--- a/src/core/annotation.js
+++ b/src/core/annotation.js
@@ -12,13 +12,48 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, Util, isDict, isName, stringToPDFString, warn, Dict, Stream,
-           stringToBytes, Promise, isArray, ObjectLoader, OperatorList,
-           isValidUrl, OPS, AnnotationType, stringToUTF8String,
-           AnnotationBorderStyleType, ColorSpace, AnnotationFlag, isInt */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/annotation', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/colorspace',
+      'pdfjs/core/obj', 'pdfjs/core/evaluator'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./stream.js'), require('./colorspace.js'), require('./obj.js'),
+      require('./evaluator.js'));
+  } else {
+    factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
+      root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreStream,
+                  coreColorSpace, coreObj, coreEvaluator) {
+
+var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
+var AnnotationFlag = sharedUtil.AnnotationFlag;
+var AnnotationType = sharedUtil.AnnotationType;
+var OPS = sharedUtil.OPS;
+var Util = sharedUtil.Util;
+var isArray = sharedUtil.isArray;
+var isInt = sharedUtil.isInt;
+var isValidUrl = sharedUtil.isValidUrl;
+var stringToBytes = sharedUtil.stringToBytes;
+var stringToPDFString = sharedUtil.stringToPDFString;
+var stringToUTF8String = sharedUtil.stringToUTF8String;
+var warn = sharedUtil.warn;
+var Dict = corePrimitives.Dict;
+var Name = corePrimitives.Name;
+var isDict = corePrimitives.isDict;
+var isName = corePrimitives.isName;
+var Stream = coreStream.Stream;
+var ColorSpace = coreColorSpace.ColorSpace;
+var ObjectLoader = coreObj.ObjectLoader;
+var OperatorList = coreEvaluator.OperatorList;
+
 var DEFAULT_ICON_SIZE = 22; // px
 
 /**
@@ -712,3 +747,8 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
 
   return LinkAnnotation;
 })();
+
+exports.Annotation = Annotation;
+exports.AnnotationBorderStyle = AnnotationBorderStyle;
+exports.AnnotationFactory = AnnotationFactory;
+}));
diff --git a/src/core/arithmetic_decoder.js b/src/core/arithmetic_decoder.js
index 57faa57..553bf73 100644
--- a/src/core/arithmetic_decoder.js
+++ b/src/core/arithmetic_decoder.js
@@ -15,6 +15,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/arithmetic_decoder', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsCoreArithmeticDecoder = {}));
+  }
+}(this, function (exports) {
+
 /* This class implements the QM Coder decoding as defined in
  *   JPEG 2000 Part I Final Committee Draft Version 1.0
  *   Annex C.3 Arithmetic decoding procedure
@@ -181,3 +191,6 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
 
   return ArithmeticDecoder;
 })();
+
+exports.ArithmeticDecoder = ArithmeticDecoder;
+}));
diff --git a/src/core/bidi.js b/src/core/bidi.js
index 6bd64b2..1648e36 100644
--- a/src/core/bidi.js
+++ b/src/core/bidi.js
@@ -12,10 +12,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/bidi', ['exports', 'pdfjs/shared/global'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/global.js'));
+  } else {
+    factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
+  }
+}(this, function (exports, sharedGlobal) {
+
+var PDFJS = sharedGlobal.PDFJS;
+
 var bidi = PDFJS.bidi = (function bidiClosure() {
   // Character types for symbols from 0000 to 00FF.
   var baseTypes = [
@@ -421,3 +432,6 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
 
   return bidi;
 })();
+
+exports.bidi = bidi;
+}));
diff --git a/src/core/charsets.js b/src/core/charsets.js
index 3c0ee7b..7463711 100644
--- a/src/core/charsets.js
+++ b/src/core/charsets.js
@@ -15,6 +15,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/charsets', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsCoreCharsets = {}));
+  }
+}(this, function (exports) {
+
 var ISOAdobeCharset = [
   '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
   'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
@@ -114,3 +124,8 @@ var ExpertSubsetCharset = [
   'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
   'periodinferior', 'commainferior'
 ];
+
+exports.ISOAdobeCharset = ISOAdobeCharset;
+exports.ExpertCharset = ExpertCharset;
+exports.ExpertSubsetCharset = ExpertSubsetCharset;
+}));
diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js
index a1fcfac..be09700 100644
--- a/src/core/chunked_stream.js
+++ b/src/core/chunked_stream.js
@@ -12,11 +12,27 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals assert, MissingDataException, isInt, NetworkManager, Promise,
-           isEmptyObj, createPromiseCapability */
+/* globals NetworkManager */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/chunked_stream', ['exports', 'pdfjs/shared/util'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'));
+  } else {
+    factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
+  }
+}(this, function (exports, sharedUtil) {
+
+var MissingDataException = sharedUtil.MissingDataException;
+var assert = sharedUtil.assert;
+var createPromiseCapability = sharedUtil.createPromiseCapability;
+var isInt = sharedUtil.isInt;
+var isEmptyObj = sharedUtil.isEmptyObj;
+
 var ChunkedStream = (function ChunkedStreamClosure() {
   function ChunkedStream(length, chunkSize, manager) {
     this.bytes = new Uint8Array(length);
@@ -545,3 +561,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
 
   return ChunkedStreamManager;
 })();
+
+exports.ChunkedStream = ChunkedStream;
+exports.ChunkedStreamManager = ChunkedStreamManager;
+}));
diff --git a/src/core/cmap.js b/src/core/cmap.js
index fb8ba1a..f68fa0a 100644
--- a/src/core/cmap.js
+++ b/src/core/cmap.js
@@ -12,11 +12,37 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals Util, isString, isInt, warn, error, isCmd, isEOF, isName, Lexer,
-           isStream, StringStream, PDFJS, assert */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/cmap', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/parser'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./stream.js'), require('./parser.js'));
+  } else {
+    factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
+
+var Util = sharedUtil.Util;
+var assert = sharedUtil.assert;
+var error = sharedUtil.error;
+var isInt = sharedUtil.isInt;
+var isString = sharedUtil.isString;
+var warn = sharedUtil.warn;
+var isName = corePrimitives.isName;
+var isCmd = corePrimitives.isCmd;
+var isStream = corePrimitives.isStream;
+var StringStream = coreStream.StringStream;
+var Lexer = coreParser.Lexer;
+var isEOF = coreParser.isEOF;
+
 var BUILT_IN_CMAPS = [
 // << Start unicode maps.
 'Adobe-GB1-UCS2',
@@ -992,3 +1018,8 @@ var CMapFactory = (function CMapFactoryClosure() {
     }
   };
 })();
+
+exports.CMap = CMap;
+exports.CMapFactory = CMapFactory;
+exports.IdentityCMap = IdentityCMap;
+}));
diff --git a/src/core/colorspace.js b/src/core/colorspace.js
index eead7be..f94a2dd 100644
--- a/src/core/colorspace.js
+++ b/src/core/colorspace.js
@@ -12,11 +12,38 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals error, info, isArray, isDict, isName, isStream, isString,
-           PDFFunction, PDFImage, shadow, warn */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/colorspace', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/function', 'pdfjs/core/stream'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./function.js'), require('./stream.js'));
+  } else {
+    factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreFunction,
+                  coreStream) {
+
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var isString = sharedUtil.isString;
+var shadow = sharedUtil.shadow;
+var warn = sharedUtil.warn;
+var isDict = corePrimitives.isDict;
+var isName = corePrimitives.isName;
+var isStream = corePrimitives.isStream;
+var PDFFunction = coreFunction.PDFFunction;
+
+var coreImage; // see _setCoreImage below
+var PDFImage; // = coreImage.PDFImage;
+
 var ColorSpace = (function ColorSpaceClosure() {
   // Constructor should define this.numComps, this.defaultColor, this.name
   function ColorSpace() {
@@ -1253,3 +1280,16 @@ var LabCS = (function LabCSClosure() {
   };
   return LabCS;
 })();
+
+// TODO refactor to remove dependency on image.js
+function _setCoreImage(coreImage_) {
+  coreImage = coreImage_;
+  PDFImage = coreImage_.PDFImage;
+}
+exports._setCoreImage = _setCoreImage;
+
+exports.ColorSpace = ColorSpace;
+
+// TODO refactor to remove dependency on colorspace.js
+coreStream._setCoreColorSpace(exports);
+}));
diff --git a/src/core/crypto.js b/src/core/crypto.js
index dc4ce30..7a9efb7 100644
--- a/src/core/crypto.js
+++ b/src/core/crypto.js
@@ -12,12 +12,34 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals bytesToString, DecryptStream, error, isInt, isName, Name,
-           PasswordException, PasswordResponses, stringToBytes, warn,
-           utf8StringToString */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/crypto', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/stream'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./stream.js'));
+  } else {
+    factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreStream);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreStream) {
+
+var PasswordException = sharedUtil.PasswordException;
+var PasswordResponses = sharedUtil.PasswordResponses;
+var bytesToString = sharedUtil.bytesToString;
+var error = sharedUtil.error;
+var isInt = sharedUtil.isInt;
+var stringToBytes = sharedUtil.stringToBytes;
+var utf8StringToString = sharedUtil.utf8StringToString;
+var warn = sharedUtil.warn;
+var Name = corePrimitives.Name;
+var isName = corePrimitives.isName;
+var DecryptStream = coreStream.DecryptStream;
+
 var ARCFourCipher = (function ARCFourCipherClosure() {
   function ARCFourCipher(key) {
     this.a = 0;
@@ -2049,3 +2071,15 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
 
   return CipherTransformFactory;
 })();
+
+exports.AES128Cipher = AES128Cipher;
+exports.AES256Cipher = AES256Cipher;
+exports.ARCFourCipher = ARCFourCipher;
+exports.CipherTransformFactory = CipherTransformFactory;
+exports.PDF17 = PDF17;
+exports.PDF20 = PDF20;
+exports.calculateMD5 = calculateMD5;
+exports.calculateSHA256 = calculateSHA256;
+exports.calculateSHA384 = calculateSHA384;
+exports.calculateSHA512 = calculateSHA512;
+}));
diff --git a/src/core/core.js b/src/core/document.js
similarity index 87%
rename from src/core/core.js
rename to src/core/document.js
index 2ab2af7..a22019c 100644
--- a/src/core/core.js
+++ b/src/core/document.js
@@ -12,15 +12,59 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals warn, Dict, isDict, shadow, isArray, Util, StreamsSequenceStream,
-           isStream, NullStream, ObjectLoader, PartialEvaluator, Promise,
-           OperatorList, Annotation, error, assert, XRef, isArrayBuffer, Stream,
-           isString, isName, info, Linearization, MissingDataException, Lexer,
-           Catalog, stringToPDFString, stringToBytes, calculateMD5,
-           AnnotationFactory */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/document', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/obj',
+      'pdfjs/core/parser', 'pdfjs/core/crypto', 'pdfjs/core/evaluator',
+      'pdfjs/core/annotation'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./stream.js'), require('./obj.js'), require('./parser.js'),
+      require('./crypto.js'), require('./evaluator.js'),
+      require('./annotation.js'));
+  } else {
+    factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreStream,
+      root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
+      root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
+                  coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
+
+var MissingDataException = sharedUtil.MissingDataException;
+var Util = sharedUtil.Util;
+var assert = sharedUtil.assert;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var isArrayBuffer = sharedUtil.isArrayBuffer;
+var isString = sharedUtil.isString;
+var shadow = sharedUtil.shadow;
+var stringToBytes = sharedUtil.stringToBytes;
+var stringToPDFString = sharedUtil.stringToPDFString;
+var warn = sharedUtil.warn;
+var Dict = corePrimitives.Dict;
+var isDict = corePrimitives.isDict;
+var isName = corePrimitives.isName;
+var isStream = corePrimitives.isStream;
+var NullStream = coreStream.NullStream;
+var Stream = coreStream.Stream;
+var StreamsSequenceStream = coreStream.StreamsSequenceStream;
+var Catalog = coreObj.Catalog;
+var ObjectLoader = coreObj.ObjectLoader;
+var XRef = coreObj.XRef;
+var Lexer = coreParser.Lexer;
+var Linearization = coreParser.Linearization;
+var calculateMD5 = coreCrypto.calculateMD5;
+var OperatorList = coreEvaluator.OperatorList;
+var PartialEvaluator = coreEvaluator.PartialEvaluator;
+var Annotation = coreAnnotation.Annotation;
+var AnnotationFactory = coreAnnotation.AnnotationFactory;
+
 var Page = (function PageClosure() {
 
   var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
@@ -478,7 +522,14 @@ var PDFDocument = (function PDFDocumentClosure() {
     },
     setup: function PDFDocument_setup(recoveryMode) {
       this.xref.parse(recoveryMode);
-      this.catalog = new Catalog(this.pdfManager, this.xref);
+      var self = this;
+      var pageFactory = {
+        createPage: function (pageIndex, dict, ref, fontCache) {
+          return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
+                          fontCache);
+        }
+      };
+      this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
     },
     get numPages() {
       var linearization = this.linearization;
@@ -551,3 +602,7 @@ var PDFDocument = (function PDFDocumentClosure() {
 
   return PDFDocument;
 })();
+
+exports.Page = Page;
+exports.PDFDocument = PDFDocument;
+}));
diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index 05bf061..9f08417 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -12,19 +12,85 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals assert, CMapFactory, ColorSpace, DecodeStream, Dict, Encodings,
-           error, ErrorFont, Font, FONT_IDENTITY_MATRIX, fontCharsToUnicode,
-           FontFlags, ImageKind, info, isArray, isCmd, isDict, isEOF, isName,
-           isNum, isStream, isString, JpegStream, Lexer, Metrics, IdentityCMap,
-           MurmurHash3_64, Name, Parser, Pattern, PDFImage, PDFJS, serifFonts,
-           stdFontMap, symbolsFonts, getTilingPatternIR, warn, Util, Promise,
-           RefSetCache, isRef, TextRenderingMode, IdentityToUnicodeMap,
-           OPS, UNSUPPORTED_FEATURES, NormalizedUnicodes, IDENTITY_MATRIX,
-           reverseIfRtl, createPromiseCapability, ToUnicodeMap, getFontType,
-           isPDFFunction, PDFFunction */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/evaluator', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/parser',
+      'pdfjs/core/image', 'pdfjs/core/colorspace', 'pdfjs/core/murmurhash3',
+      'pdfjs/core/fonts', 'pdfjs/core/function', 'pdfjs/core/pattern',
+      'pdfjs/core/cmap', 'pdfjs/core/metrics', 'pdfjs/core/bidi'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./stream.js'), require('./parser.js'), require('./image.js'),
+      require('./colorspace.js'), require('./murmurhash3.js'),
+      require('./fonts.js'), require('./function.js'), require('./pattern.js'),
+      require('./cmap.js'), require('./metrics.js'), require('./bidi.js'));
+  } else {
+    factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
+      root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
+      root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
+      root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
+                  coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
+                  coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
+
+var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
+var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
+var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
+var ImageKind = sharedUtil.ImageKind;
+var OPS = sharedUtil.OPS;
+var TextRenderingMode = sharedUtil.TextRenderingMode;
+var Util = sharedUtil.Util;
+var assert = sharedUtil.assert;
+var createPromiseCapability = sharedUtil.createPromiseCapability;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var isNum = sharedUtil.isNum;
+var isString = sharedUtil.isString;
+var warn = sharedUtil.warn;
+var Dict = corePrimitives.Dict;
+var Name = corePrimitives.Name;
+var isCmd = corePrimitives.isCmd;
+var isDict = corePrimitives.isDict;
+var isName = corePrimitives.isName;
+var isRef = corePrimitives.isRef;
+var isStream = corePrimitives.isStream;
+var DecodeStream = coreStream.DecodeStream;
+var JpegStream = coreStream.JpegStream;
+var Lexer = coreParser.Lexer;
+var Parser = coreParser.Parser;
+var isEOF = coreParser.isEOF;
+var PDFImage = coreImage.PDFImage;
+var ColorSpace = coreColorSpace.ColorSpace;
+var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
+var Encodings = coreFonts.Encodings;
+var ErrorFont = coreFonts.ErrorFont;
+var FontFlags = coreFonts.FontFlags;
+var Font = coreFonts.Font;
+var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
+var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
+var ToUnicodeMap = coreFonts.ToUnicodeMap;
+var getFontType = coreFonts.getFontType;
+var reverseIfRtl = coreFonts.reverseIfRtl;
+var serifFonts = coreFonts.serifFonts;
+var symbolsFonts = coreFonts.symbolsFonts;
+var stdFontMap = coreFonts.stdFontMap;
+var isPDFFunction = coreFunction.isPDFFunction;
+var PDFFunction = coreFunction.PDFFunction;
+var Pattern = corePattern.Pattern;
+var getTilingPatternIR = corePattern.getTilingPatternIR;
+var CMapFactory = coreCMap.CMapFactory;
+var IdentityCMap = coreCMap.IdentityCMap;
+var Metrics = coreMetrics.Metrics;
+var bidi = coreBidi.bidi;
+
 var PartialEvaluator = (function PartialEvaluatorClosure() {
   function PartialEvaluator(pdfManager, xref, handler, pageIndex,
                             uniquePrefix, idCounters, fontCache) {
@@ -2889,3 +2955,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
   };
   return QueueOptimizer;
 })();
+
+exports.OperatorList = OperatorList;
+exports.PartialEvaluator = PartialEvaluator;
+}));
diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js
index a7267c8..3f45524 100644
--- a/src/core/font_renderer.js
+++ b/src/core/font_renderer.js
@@ -12,10 +12,30 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals error, bytesToString, Stream, GlyphsUnicode, CFFParser, Encodings,
-           Util */
 
 'use strict';
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/font_renderer', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/stream', 'pdfjs/core/glyphlist'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./stream.js'),
+      require('./glyphlist.js'));
+  } else {
+    factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
+      root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
+  }
+}(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
+
+var Util = sharedUtil.Util;
+var bytesToString = sharedUtil.bytesToString;
+var error = sharedUtil.error;
+var Stream = coreStream.Stream;
+var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
+
+var coreFonts; // see _setCoreFonts below
+var CFFParser; // = coreFonts.CFFParser;
+var Encodings; // = coreFonts.Encodings;
 
 var FontRendererFactory = (function FontRendererFactoryClosure() {
   function getLong(data, offset) {
@@ -706,3 +726,15 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
     }
   };
 })();
+
+
+// TODO refactor to remove cyclic dependency on fonts.js
+function _setCoreFonts(coreFonts_) {
+  coreFonts = coreFonts_;
+  Encodings = coreFonts_.Encodings;
+  CFFParser = coreFonts_.CFFParser;
+}
+exports._setCoreFonts = _setCoreFonts;
+
+exports.FontRendererFactory = FontRendererFactory;
+}));
diff --git a/src/core/fonts.js b/src/core/fonts.js
index cfb1f1c..b67a0c6 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -12,14 +12,57 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals FONT_IDENTITY_MATRIX, FontType, warn, GlyphsUnicode, error, string32,
-           readUint32, Stream, FontRendererFactory, shadow, stringToBytes,
-           bytesToString, info, assert, IdentityCMap, Name, CMapFactory, PDFJS,
-           isNum, Lexer, isArray, ISOAdobeCharset, ExpertCharset, isInt,
-           ExpertSubsetCharset, Util, DingbatsGlyphsUnicode */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/fonts', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/parser',
+      'pdfjs/core/cmap', 'pdfjs/core/glyphlist', 'pdfjs/core/charsets',
+      'pdfjs/core/font_renderer'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./stream.js'), require('./parser.js'), require('./cmap.js'),
+      require('./glyphlist.js'), require('./charsets.js'),
+      require('./font_renderer.js'));
+  } else {
+    factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
+      root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
+      root.pdfjsCoreFontRenderer);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
+                  coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
+
+var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
+var FontType = sharedUtil.FontType;
+var Util = sharedUtil.Util;
+var assert = sharedUtil.assert;
+var bytesToString = sharedUtil.bytesToString;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var isInt = sharedUtil.isInt;
+var isNum = sharedUtil.isNum;
+var readUint32 = sharedUtil.readUint32;
+var shadow = sharedUtil.shadow;
+var stringToBytes = sharedUtil.stringToBytes;
+var string32 = sharedUtil.string32;
+var warn = sharedUtil.warn;
+var Name = corePrimitives.Name;
+var Stream = coreStream.Stream;
+var Lexer = coreParser.Lexer;
+var CMapFactory = coreCMap.CMapFactory;
+var IdentityCMap = coreCMap.IdentityCMap;
+var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
+var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
+var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
+var ExpertCharset = coreCharsets.ExpertCharset;
+var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
+var FontRendererFactory = coreFontRenderer.FontRendererFactory;
+
 // Unicode Private Use Area
 var PRIVATE_USE_OFFSET_START = 0xE000;
 var PRIVATE_USE_OFFSET_END = 0xF8FF;
@@ -7354,9 +7397,13 @@ var CFFCompiler = (function CFFCompilerClosure() {
   return CFFCompiler;
 })();
 
+function _enableSeacAnalysis(enabled) {
+  exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
+}
+
 // Workaround for seac on Windows.
 (function checkSeacSupport() {
-  if (/Windows/.test(navigator.userAgent)) {
+  if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
     SEAC_ANALYSIS_ENABLED = true;
   }
 })();
@@ -7365,7 +7412,32 @@ var CFFCompiler = (function CFFCompilerClosure() {
 // http://code.google.com/p/chromium/issues/detail?id=122465
 // https://github.com/mozilla/pdf.js/issues/1689
 (function checkChromeWindows() {
-  if (/Windows.*Chrome/.test(navigator.userAgent)) {
+  if (typeof navigator !== 'undefined' &&
+      /Windows.*Chrome/.test(navigator.userAgent)) {
     SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
   }
 })();
+
+exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
+exports.CFFCompiler = CFFCompiler;
+exports.CFFIndex = CFFIndex;
+exports.CFFParser = CFFParser;
+exports.CFFStrings = CFFStrings;
+exports.Encodings = Encodings;
+exports.ErrorFont = ErrorFont;
+exports.FontFlags = FontFlags;
+exports.Font = Font;
+exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
+exports.NormalizedUnicodes = NormalizedUnicodes;
+exports.ToUnicodeMap = ToUnicodeMap;
+exports.Type1Parser = Type1Parser;
+exports.getFontType = getFontType;
+exports.reverseIfRtl = reverseIfRtl;
+exports.serifFonts = serifFonts;
+exports.symbolsFonts = symbolsFonts;
+exports.stdFontMap = stdFontMap;
+exports._enableSeacAnalysis = _enableSeacAnalysis;
+
+// TODO refactor to remove cyclic dependency on font_renderer.js
+coreFontRenderer._setCoreFonts(exports);
+}));
diff --git a/src/core/function.js b/src/core/function.js
index b85e7ee..d7b7cfd 100644
--- a/src/core/function.js
+++ b/src/core/function.js
@@ -12,11 +12,31 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PostScriptLexer, PostScriptParser, error, info, isArray, isBool,
-           isDict, isStream */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/function', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/ps_parser'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./ps_parser.js'));
+  } else {
+    factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
+
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var isBool = sharedUtil.isBool;
+var isDict = corePrimitives.isDict;
+var isStream = corePrimitives.isStream;
+var PostScriptLexer = corePsParser.PostScriptLexer;
+var PostScriptParser = corePsParser.PostScriptParser;
+
 var PDFFunction = (function PDFFunctionClosure() {
   var CONSTRUCT_SAMPLED = 0;
   var CONSTRUCT_INTERPOLATED = 2;
@@ -1131,3 +1151,9 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() {
 
   return PostScriptCompiler;
 })();
+
+exports.isPDFFunction = isPDFFunction;
+exports.PDFFunction = PDFFunction;
+exports.PostScriptEvaluator = PostScriptEvaluator;
+exports.PostScriptCompiler = PostScriptCompiler;
+}));
diff --git a/src/core/glyphlist.js b/src/core/glyphlist.js
index 1ddef6a..1714f7e 100644
--- a/src/core/glyphlist.js
+++ b/src/core/glyphlist.js
@@ -15,6 +15,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/glyphlist', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsCoreGlyphList = {}));
+  }
+}(this, function (exports) {
+
 var GlyphsUnicode = {
   A: 0x0041,
   AE: 0x00C6,
@@ -4427,3 +4437,7 @@ var DingbatsGlyphsUnicode = {
   a96: 0x2775, // 0xF8E4
   '.notdef': 0x0000
 };
+
+exports.GlyphsUnicode = GlyphsUnicode;
+exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
+}));
diff --git a/src/core/image.js b/src/core/image.js
index fdbd89b..7688ed5 100644
--- a/src/core/image.js
+++ b/src/core/image.js
@@ -12,11 +12,40 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals assert, ColorSpace, DecodeStream, error, info, isArray, ImageKind,
-           isStream, JpegStream, JpxImage, Name, Promise, Stream, warn */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/image', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/colorspace', 'pdfjs/core/stream',
+      'pdfjs/core/jpx'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./colorspace.js'), require('./stream.js'),
+      require('./jpx.js'));
+  } else {
+    factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
+      root.pdfjsCoreJpx);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
+                  coreStream, coreJpx) {
+
+var ImageKind = sharedUtil.ImageKind;
+var assert = sharedUtil.assert;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var warn = sharedUtil.warn;
+var Name = corePrimitives.Name;
+var isStream = corePrimitives.isStream;
+var ColorSpace = coreColorSpace.ColorSpace;
+var DecodeStream = coreStream.DecodeStream;
+var Stream = coreStream.Stream;
+var JpegStream = coreStream.JpegStream;
+var JpxImage = coreJpx.JpxImage;
+
 var PDFImage = (function PDFImageClosure() {
   /**
    * Decode the image in the main thread if it supported. Resovles the promise
@@ -672,3 +701,9 @@ var PDFImage = (function PDFImageClosure() {
   };
   return PDFImage;
 })();
+
+exports.PDFImage = PDFImage;
+
+// TODO refactor to remove dependency on colorspace.js
+coreColorSpace._setCoreImage(exports);
+}));
diff --git a/src/core/jbig2.js b/src/core/jbig2.js
index 1fc7c97..de12341 100644
--- a/src/core/jbig2.js
+++ b/src/core/jbig2.js
@@ -12,11 +12,30 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals ArithmeticDecoder, error, log2, readInt8, readUint16, readUint32,
-           shadow */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/jbig2', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/arithmetic_decoder'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'),
+      require('./arithmetic_decoder.js'));
+  } else {
+    factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
+      root.pdfjsCoreArithmeticDecoder);
+  }
+}(this, function (exports, sharedUtil, coreArithmeticDecoder) {
+
+var error = sharedUtil.error;
+var log2 = sharedUtil.log2;
+var readInt8 = sharedUtil.readInt8;
+var readUint16 = sharedUtil.readUint16;
+var readUint32 = sharedUtil.readUint32;
+var shadow = sharedUtil.shadow;
+var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
+
 var Jbig2Image = (function Jbig2ImageClosure() {
   // Utility data structures
   function ContextCache() {}
@@ -1084,3 +1103,6 @@ var Jbig2Image = (function Jbig2ImageClosure() {
 
   return Jbig2Image;
 })();
+
+exports.Jbig2Image = Jbig2Image;
+}));
diff --git a/src/core/jpg.js b/src/core/jpg.js
index 2f31813..1d8b25f 100644
--- a/src/core/jpg.js
+++ b/src/core/jpg.js
@@ -14,6 +14,18 @@
  * limitations under the License.
  */
 
+'use strict';
+
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/jpg', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsCoreJpg = {}));
+  }
+}(this, function (exports) {
+
 /*
 This code was forked from https://github.com/notmasteryet/jpgjs. The original
 version was created by github user notmasteryet
@@ -27,8 +39,6 @@ version was created by github user notmasteryet
  (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
 */
 
-'use strict';
-
 var JpegImage = (function jpegImage() {
   var dctZigZag = new Uint8Array([
      0,
@@ -1033,3 +1043,6 @@ var JpegImage = (function jpegImage() {
 
   return constructor;
 })();
+
+exports.JpegImage = JpegImage;
+}));
diff --git a/src/core/jpx.js b/src/core/jpx.js
index 97cd11f..2f2fde8 100644
--- a/src/core/jpx.js
+++ b/src/core/jpx.js
@@ -12,11 +12,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals ArithmeticDecoder, globalScope, log2, readUint16, readUint32,
-           info, warn */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/jpx', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/arithmetic_decoder'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'),
+      require('./arithmetic_decoder.js'));
+  } else {
+    factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
+      root.pdfjsCoreArithmeticDecoder);
+  }
+}(this, function (exports, sharedUtil, coreArithmeticDecoder) {
+
+var info = sharedUtil.info;
+var log2 = sharedUtil.log2;
+var readUint16 = sharedUtil.readUint16;
+var readUint32 = sharedUtil.readUint32;
+var warn = sharedUtil.warn;
+var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
+
 var JpxImage = (function JpxImageClosure() {
   // Table E.1
   var SubbandsGainLog2 = {
@@ -2211,3 +2229,6 @@ var JpxImage = (function JpxImageClosure() {
 
   return JpxImage;
 })();
+
+exports.JpxImage = JpxImage;
+}));
diff --git a/src/core/metrics.js b/src/core/metrics.js
index 61740c1..3d2ff7e 100644
--- a/src/core/metrics.js
+++ b/src/core/metrics.js
@@ -15,6 +15,16 @@
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/metrics', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsCoreMetrics = {}));
+  }
+}(this, function (exports) {
+
 // The Metrics object contains glyph widths (in glyph space units).
 // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
 // space unit corresponds to 1/1000th of text space unit.
@@ -2956,3 +2966,6 @@ var Metrics = {
     'a191': 918
   }
 };
+
+exports.Metrics = Metrics;
+}));
diff --git a/src/core/murmurhash3.js b/src/core/murmurhash3.js
index 813358d..292c59f 100644
--- a/src/core/murmurhash3.js
+++ b/src/core/murmurhash3.js
@@ -17,10 +17,21 @@
  * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  */
-/* globals Uint32ArrayView */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/murmurhash3', ['exports', 'pdfjs/shared/util'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'));
+  } else {
+    factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
+  }
+}(this, function (exports, sharedUtil) {
+
+var Uint32ArrayView = sharedUtil.Uint32ArrayView;
+
 var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
   // Workaround for missing math precison in JS.
   var MASK_HIGH = 0xffff0000;
@@ -162,3 +173,6 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
 
   return MurmurHash3_64;
 })();
+
+exports.MurmurHash3_64 = MurmurHash3_64;
+}));
diff --git a/src/core/obj.js b/src/core/obj.js
index 82ea426..c465979 100644
--- a/src/core/obj.js
+++ b/src/core/obj.js
@@ -12,326 +12,56 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals assert, bytesToString, CipherTransformFactory, error, info,
-           InvalidPDFException, isArray, isCmd, isDict, isInt, isName, isRef,
-           isStream, Lexer, Page, Parser, Promise, shadow,
-           stringToPDFString, stringToUTF8String, warn, isString,
-           Promise, MissingDataException, XRefParseException, Stream,
-           ChunkedStream, createPromiseCapability */
 
 'use strict';
 
-var Name = (function NameClosure() {
-  function Name(name) {
-    this.name = name;
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/obj', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/crypto', 'pdfjs/core/parser',
+      'pdfjs/core/chunked_stream'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./crypto.js'), require('./parser.js'),
+      require('./chunked_stream.js'));
+  } else {
+    factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
+      root.pdfjsCoreChunkedStream);
   }
-
-  Name.prototype = {};
-
-  var nameCache = {};
-
-  Name.get = function Name_get(name) {
-    var nameValue = nameCache[name];
-    return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
-  };
-
-  return Name;
-})();
-
-var Cmd = (function CmdClosure() {
-  function Cmd(cmd) {
-    this.cmd = cmd;
-  }
-
-  Cmd.prototype = {};
-
-  var cmdCache = {};
-
-  Cmd.get = function Cmd_get(cmd) {
-    var cmdValue = cmdCache[cmd];
-    return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
-  };
-
-  return Cmd;
-})();
-
-var Dict = (function DictClosure() {
-  var nonSerializable = function nonSerializableClosure() {
-    return nonSerializable; // creating closure on some variable
-  };
-
-  var GETALL_DICTIONARY_TYPES_WHITELIST = {
-    'Background': true,
-    'ExtGState': true,
-    'Halftone': true,
-    'Layout': true,
-    'Mask': true,
-    'Pagination': true,
-    'Printing': true
-  };
-
-  function isRecursionAllowedFor(dict) {
-    if (!isName(dict.Type)) {
-      return true;
-    }
-    var dictType = dict.Type.name;
-    return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
-  }
-
-  // xref is optional
-  function Dict(xref) {
-    // Map should only be used internally, use functions below to access.
-    this.map = Object.create(null);
-    this.xref = xref;
-    this.objId = null;
-    this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
-  }
-
-  Dict.prototype = {
-    assignXref: function Dict_assignXref(newXref) {
-      this.xref = newXref;
-    },
-
-    // automatically dereferences Ref objects
-    get: function Dict_get(key1, key2, key3) {
-      var value;
-      var xref = this.xref;
-      if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
-          typeof key2 === 'undefined') {
-        return xref ? xref.fetchIfRef(value) : value;
-      }
-      if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
-          typeof key3 === 'undefined') {
-        return xref ? xref.fetchIfRef(value) : value;
-      }
-      value = this.map[key3] || null;
-      return xref ? xref.fetchIfRef(value) : value;
-    },
-
-    // Same as get(), but returns a promise and uses fetchIfRefAsync().
-    getAsync: function Dict_getAsync(key1, key2, key3) {
-      var value;
-      var xref = this.xref;
-      if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
-          typeof key2 === 'undefined') {
-        if (xref) {
-          return xref.fetchIfRefAsync(value);
-        }
-        return Promise.resolve(value);
-      }
-      if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
-          typeof key3 === 'undefined') {
-        if (xref) {
-          return xref.fetchIfRefAsync(value);
-        }
-        return Promise.resolve(value);
-      }
-      value = this.map[key3] || null;
-      if (xref) {
-        return xref.fetchIfRefAsync(value);
-      }
-      return Promise.resolve(value);
-    },
-
-    // Same as get(), but dereferences all elements if the result is an Array.
-    getArray: function Dict_getArray(key1, key2, key3) {
-      var value = this.get(key1, key2, key3);
-      var xref = this.xref;
-      if (!isArray(value) || !xref) {
-        return value;
-      }
-      value = value.slice(); // Ensure that we don't modify the Dict data.
-      for (var i = 0, ii = value.length; i < ii; i++) {
-        if (!isRef(value[i])) {
-          continue;
-        }
-        value[i] = xref.fetch(value[i]);
-      }
-      return value;
-    },
-
-    // no dereferencing
-    getRaw: function Dict_getRaw(key) {
-      return this.map[key];
-    },
-
-    // creates new map and dereferences all Refs
-    getAll: function Dict_getAll() {
-      var all = Object.create(null);
-      var queue = null;
-      var key, obj;
-      for (key in this.map) {
-        obj = this.get(key);
-        if (obj instanceof Dict) {
-          if (isRecursionAllowedFor(obj)) {
-            (queue || (queue = [])).push({target: all, key: key, obj: obj});
-          } else {
-            all[key] = this.getRaw(key);
-          }
-        } else {
-          all[key] = obj;
-        }
-      }
-      if (!queue) {
-        return all;
-      }
-
-      // trying to take cyclic references into the account
-      var processed = Object.create(null);
-      while (queue.length > 0) {
-        var item = queue.shift();
-        var itemObj = item.obj;
-        var objId = itemObj.objId;
-        if (objId && objId in processed) {
-          item.target[item.key] = processed[objId];
-          continue;
-        }
-        var dereferenced = Object.create(null);
-        for (key in itemObj.map) {
-          obj = itemObj.get(key);
-          if (obj instanceof Dict) {
-            if (isRecursionAllowedFor(obj)) {
-              queue.push({target: dereferenced, key: key, obj: obj});
-            } else {
-              dereferenced[key] = itemObj.getRaw(key);
-            }
-          } else {
-            dereferenced[key] = obj;
-          }
-        }
-        if (objId) {
-          processed[objId] = dereferenced;
-        }
-        item.target[item.key] = dereferenced;
-      }
-      return all;
-    },
-
-    getKeys: function Dict_getKeys() {
-      return Object.keys(this.map);
-    },
-
-    set: function Dict_set(key, value) {
-      this.map[key] = value;
-    },
-
-    has: function Dict_has(key) {
-      return key in this.map;
-    },
-
-    forEach: function Dict_forEach(callback) {
-      for (var key in this.map) {
-        callback(key, this.get(key));
-      }
-    }
-  };
-
-  Dict.empty = new Dict(null);
-
-  Dict.merge = function Dict_merge(xref, dictArray) {
-    var mergedDict = new Dict(xref);
-
-    for (var i = 0, ii = dictArray.length; i < ii; i++) {
-      var dict = dictArray[i];
-      if (!isDict(dict)) {
-        continue;
-      }
-      for (var keyName in dict.map) {
-        if (mergedDict.map[keyName]) {
-          continue;
-        }
-        mergedDict.map[keyName] = dict.map[keyName];
-      }
-    }
-    return mergedDict;
-  };
-
-  return Dict;
-})();
-
-var Ref = (function RefClosure() {
-  function Ref(num, gen) {
-    this.num = num;
-    this.gen = gen;
-  }
-
-  Ref.prototype = {
-    toString: function Ref_toString() {
-      // This function is hot, so we make the string as compact as possible.
-      // |this.gen| is almost always zero, so we treat that case specially.
-      var str = this.num + 'R';
-      if (this.gen !== 0) {
-        str += this.gen;
-      }
-      return str;
-    }
-  };
-
-  return Ref;
-})();
-
-// The reference is identified by number and generation.
-// This structure stores only one instance of the reference.
-var RefSet = (function RefSetClosure() {
-  function RefSet() {
-    this.dict = {};
-  }
-
-  RefSet.prototype = {
-    has: function RefSet_has(ref) {
-      return ref.toString() in this.dict;
-    },
-
-    put: function RefSet_put(ref) {
-      this.dict[ref.toString()] = true;
-    },
-
-    remove: function RefSet_remove(ref) {
-      delete this.dict[ref.toString()];
-    }
-  };
-
-  return RefSet;
-})();
-
-var RefSetCache = (function RefSetCacheClosure() {
-  function RefSetCache() {
-    this.dict = Object.create(null);
-  }
-
-  RefSetCache.prototype = {
-    get: function RefSetCache_get(ref) {
-      return this.dict[ref.toString()];
-    },
-
-    has: function RefSetCache_has(ref) {
-      return ref.toString() in this.dict;
-    },
-
-    put: function RefSetCache_put(ref, obj) {
-      this.dict[ref.toString()] = obj;
-    },
-
-    putAlias: function RefSetCache_putAlias(ref, aliasRef) {
-      this.dict[ref.toString()] = this.get(aliasRef);
-    },
-
-    forEach: function RefSetCache_forEach(fn, thisArg) {
-      for (var i in this.dict) {
-        fn.call(thisArg, this.dict[i]);
-      }
-    },
-
-    clear: function RefSetCache_clear() {
-      this.dict = Object.create(null);
-    }
-  };
-
-  return RefSetCache;
-})();
+}(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
+                  coreChunkedStream) {
+
+var InvalidPDFException = sharedUtil.InvalidPDFException;
+var MissingDataException = sharedUtil.MissingDataException;
+var XRefParseException = sharedUtil.XRefParseException;
+var assert = sharedUtil.assert;
+var bytesToString = sharedUtil.bytesToString;
+var createPromiseCapability = sharedUtil.createPromiseCapability;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var isInt = sharedUtil.isInt;
+var isString = sharedUtil.isString;
+var shadow = sharedUtil.shadow;
+var stringToPDFString = sharedUtil.stringToPDFString;
+var stringToUTF8String = sharedUtil.stringToUTF8String;
+var warn = sharedUtil.warn;
+var Ref = corePrimitives.Ref;
+var RefSet = corePrimitives.RefSet;
+var RefSetCache = corePrimitives.RefSetCache;
+var isName = corePrimitives.isName;
+var isCmd = corePrimitives.isCmd;
+var isDict = corePrimitives.isDict;
+var isRef = corePrimitives.isRef;
+var isStream = corePrimitives.isStream;
+var CipherTransformFactory = coreCrypto.CipherTransformFactory;
+var Lexer = coreParser.Lexer;
+var Parser = coreParser.Parser;
+var ChunkedStream = coreChunkedStream.ChunkedStream;
 
 var Catalog = (function CatalogClosure() {
-  function Catalog(pdfManager, xref) {
+  function Catalog(pdfManager, xref, pageFactory) {
     this.pdfManager = pdfManager;
     this.xref = xref;
     this.catDict = xref.getCatalogObj();
@@ -339,6 +69,8 @@ var Catalog = (function CatalogClosure() {
     assert(isDict(this.catDict),
       'catalog object is not a dictionary');
 
+    // TODO refactor to move getPage() to the PDFDocument.
+    this.pageFactory = pageFactory;
     this.pagePromises = [];
   }
 
@@ -617,8 +349,8 @@ var Catalog = (function CatalogClosure() {
           function (a) {
             var dict = a[0];
             var ref = a[1];
-            return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
-                            this.fontCache);
+            return this.pageFactory.createPage(pageIndex, dict, ref,
+                                               this.fontCache);
           }.bind(this)
         );
       }
@@ -1749,3 +1481,8 @@ var ObjectLoader = (function() {
 
   return ObjectLoader;
 })();
+
+exports.Catalog = Catalog;
+exports.ObjectLoader = ObjectLoader;
+exports.XRef = XRef;
+}));
diff --git a/src/core/parser.js b/src/core/parser.js
index e43fe09..71ec89e 100644
--- a/src/core/parser.js
+++ b/src/core/parser.js
@@ -12,14 +12,51 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals Ascii85Stream, AsciiHexStream, CCITTFaxStream, Cmd, Dict, error,
-           FlateStream, isArray, isCmd, isDict, isInt, isName, isNum, isRef,
-           isString, Jbig2Stream, JpegStream, JpxStream, LZWStream, Name,
-           NullStream, PredictorStream, Ref, RunLengthStream, warn, info,
-           StreamType, MissingDataException, assert */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/parser', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/stream'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./stream.js'));
+  } else {
+    factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreStream);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreStream) {
+
+var MissingDataException = sharedUtil.MissingDataException;
+var StreamType = sharedUtil.StreamType;
+var assert = sharedUtil.assert;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var isInt = sharedUtil.isInt;
+var isNum = sharedUtil.isNum;
+var isString = sharedUtil.isString;
+var warn = sharedUtil.warn;
+var Cmd = corePrimitives.Cmd;
+var Dict = corePrimitives.Dict;
+var Name = corePrimitives.Name;
+var Ref = corePrimitives.Ref;
+var isCmd = corePrimitives.isCmd;
+var isDict = corePrimitives.isDict;
+var isName = corePrimitives.isName;
+var Ascii85Stream = coreStream.Ascii85Stream;
+var AsciiHexStream = coreStream.AsciiHexStream;
+var CCITTFaxStream = coreStream.CCITTFaxStream;
+var FlateStream = coreStream.FlateStream;
+var Jbig2Stream = coreStream.Jbig2Stream;
+var JpegStream = coreStream.JpegStream;
+var JpxStream = coreStream.JpxStream;
+var LZWStream = coreStream.LZWStream;
+var NullStream = coreStream.NullStream;
+var PredictorStream = coreStream.PredictorStream;
+var RunLengthStream = coreStream.RunLengthStream;
+
 var EOF = {};
 
 function isEOF(v) {
@@ -1074,3 +1111,13 @@ var Linearization = {
     };
   }
 };
+
+exports.EOF = EOF;
+exports.Lexer = Lexer;
+exports.Linearization = Linearization;
+exports.Parser = Parser;
+exports.isEOF = isEOF;
+
+// TODO refactor to remove dependency on stream.js
+coreStream._setCoreParser(exports);
+}));
diff --git a/src/core/pattern.js b/src/core/pattern.js
index a83770b..589443e 100644
--- a/src/core/pattern.js
+++ b/src/core/pattern.js
@@ -12,11 +12,36 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals ColorSpace, PDFFunction, Util, error, warn, info, isArray, isStream,
-           assert, isPDFFunction, UNSUPPORTED_FEATURES, MissingDataException */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/pattern', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/function',
+      'pdfjs/core/colorspace'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./function.js'), require('./colorspace.js'));
+  } else {
+    factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
+      root.pdfjsCoreColorSpace);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreFunction,
+                  coreColorSpace) {
+
+var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
+var MissingDataException = sharedUtil.MissingDataException;
+var Util = sharedUtil.Util;
+var assert = sharedUtil.assert;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var warn = sharedUtil.warn;
+var isStream = corePrimitives.isStream;
+var PDFFunction = coreFunction.PDFFunction;
+var ColorSpace = coreColorSpace.ColorSpace;
+
 var ShadingType = {
   FUNCTION_BASED: 1,
   AXIAL: 2,
@@ -805,3 +830,7 @@ function getTilingPatternIR(operatorList, dict, args) {
     paintType, tilingType
   ];
 }
+
+exports.Pattern = Pattern;
+exports.getTilingPatternIR = getTilingPatternIR;
+}));
diff --git a/src/core/pdf_manager.js b/src/core/pdf_manager.js
index 3abaecd..564e7d2 100644
--- a/src/core/pdf_manager.js
+++ b/src/core/pdf_manager.js
@@ -12,11 +12,33 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals NotImplementedException, MissingDataException, Promise, Stream,
-           PDFDocument, ChunkedStreamManager, createPromiseCapability, Util */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/pdf_manager', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/stream', 'pdfjs/core/chunked_stream', 'pdfjs/core/document'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./stream.js'),
+      require('./chunked_stream.js'), require('./document.js'));
+  } else {
+    factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
+      root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
+      root.pdfjsCoreDocument);
+  }
+}(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
+                  coreDocument) {
+
+var NotImplementedException = sharedUtil.NotImplementedException;
+var MissingDataException = sharedUtil.MissingDataException;
+var createPromiseCapability = sharedUtil.createPromiseCapability;
+var Util = sharedUtil.Util;
+var Stream = coreStream.Stream;
+var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
+var PDFDocument = coreDocument.PDFDocument;
+
 var BasePdfManager = (function BasePdfManagerClosure() {
   function BasePdfManager() {
     throw new Error('Cannot initialize BaseManagerManager');
@@ -207,3 +229,7 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
 
   return NetworkPdfManager;
 })();
+
+exports.LocalPdfManager = LocalPdfManager;
+exports.NetworkPdfManager = NetworkPdfManager;
+}));
diff --git a/src/core/primitives.js b/src/core/primitives.js
new file mode 100644
index 0000000..efe4a43
--- /dev/null
+++ b/src/core/primitives.js
@@ -0,0 +1,378 @@
+/* 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.
+ */
+/* uses XRef */
+
+'use strict';
+
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/primitives', ['exports', 'pdfjs/shared/util'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'));
+  } else {
+    factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
+  }
+}(this, function (exports, sharedUtil) {
+
+var isArray = sharedUtil.isArray;
+
+var Name = (function NameClosure() {
+  function Name(name) {
+    this.name = name;
+  }
+
+  Name.prototype = {};
+
+  var nameCache = {};
+
+  Name.get = function Name_get(name) {
+    var nameValue = nameCache[name];
+    return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
+  };
+
+  return Name;
+})();
+
+var Cmd = (function CmdClosure() {
+  function Cmd(cmd) {
+    this.cmd = cmd;
+  }
+
+  Cmd.prototype = {};
+
+  var cmdCache = {};
+
+  Cmd.get = function Cmd_get(cmd) {
+    var cmdValue = cmdCache[cmd];
+    return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
+  };
+
+  return Cmd;
+})();
+
+var Dict = (function DictClosure() {
+  var nonSerializable = function nonSerializableClosure() {
+    return nonSerializable; // creating closure on some variable
+  };
+
+  var GETALL_DICTIONARY_TYPES_WHITELIST = {
+    'Background': true,
+    'ExtGState': true,
+    'Halftone': true,
+    'Layout': true,
+    'Mask': true,
+    'Pagination': true,
+    'Printing': true
+  };
+
+  function isRecursionAllowedFor(dict) {
+    if (!isName(dict.Type)) {
+      return true;
+    }
+    var dictType = dict.Type.name;
+    return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
+  }
+
+  // xref is optional
+  function Dict(xref) {
+    // Map should only be used internally, use functions below to access.
+    this.map = Object.create(null);
+    this.xref = xref;
+    this.objId = null;
+    this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
+  }
+
+  Dict.prototype = {
+    assignXref: function Dict_assignXref(newXref) {
+      this.xref = newXref;
+    },
+
+    // automatically dereferences Ref objects
+    get: function Dict_get(key1, key2, key3) {
+      var value;
+      var xref = this.xref;
+      if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
+          typeof key2 === 'undefined') {
+        return xref ? xref.fetchIfRef(value) : value;
+      }
+      if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
+          typeof key3 === 'undefined') {
+        return xref ? xref.fetchIfRef(value) : value;
+      }
+      value = this.map[key3] || null;
+      return xref ? xref.fetchIfRef(value) : value;
+    },
+
+    // Same as get(), but returns a promise and uses fetchIfRefAsync().
+    getAsync: function Dict_getAsync(key1, key2, key3) {
+      var value;
+      var xref = this.xref;
+      if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
+          typeof key2 === 'undefined') {
+        if (xref) {
+          return xref.fetchIfRefAsync(value);
+        }
+        return Promise.resolve(value);
+      }
+      if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
+          typeof key3 === 'undefined') {
+        if (xref) {
+          return xref.fetchIfRefAsync(value);
+        }
+        return Promise.resolve(value);
+      }
+      value = this.map[key3] || null;
+      if (xref) {
+        return xref.fetchIfRefAsync(value);
+      }
+      return Promise.resolve(value);
+    },
+
+    // Same as get(), but dereferences all elements if the result is an Array.
+    getArray: function Dict_getArray(key1, key2, key3) {
+      var value = this.get(key1, key2, key3);
+      var xref = this.xref;
+      if (!isArray(value) || !xref) {
+        return value;
+      }
+      value = value.slice(); // Ensure that we don't modify the Dict data.
+      for (var i = 0, ii = value.length; i < ii; i++) {
+        if (!isRef(value[i])) {
+          continue;
+        }
+        value[i] = xref.fetch(value[i]);
+      }
+      return value;
+    },
+
+    // no dereferencing
+    getRaw: function Dict_getRaw(key) {
+      return this.map[key];
+    },
+
+    // creates new map and dereferences all Refs
+    getAll: function Dict_getAll() {
+      var all = Object.create(null);
+      var queue = null;
+      var key, obj;
+      for (key in this.map) {
+        obj = this.get(key);
+        if (obj instanceof Dict) {
+          if (isRecursionAllowedFor(obj)) {
+            (queue || (queue = [])).push({target: all, key: key, obj: obj});
+          } else {
+            all[key] = this.getRaw(key);
+          }
+        } else {
+          all[key] = obj;
+        }
+      }
+      if (!queue) {
+        return all;
+      }
+
+      // trying to take cyclic references into the account
+      var processed = Object.create(null);
+      while (queue.length > 0) {
+        var item = queue.shift();
+        var itemObj = item.obj;
+        var objId = itemObj.objId;
+        if (objId && objId in processed) {
+          item.target[item.key] = processed[objId];
+          continue;
+        }
+        var dereferenced = Object.create(null);
+        for (key in itemObj.map) {
+          obj = itemObj.get(key);
+          if (obj instanceof Dict) {
+            if (isRecursionAllowedFor(obj)) {
+              queue.push({target: dereferenced, key: key, obj: obj});
+            } else {
+              dereferenced[key] = itemObj.getRaw(key);
+            }
+          } else {
+            dereferenced[key] = obj;
+          }
+        }
+        if (objId) {
+          processed[objId] = dereferenced;
+        }
+        item.target[item.key] = dereferenced;
+      }
+      return all;
+    },
+
+    getKeys: function Dict_getKeys() {
+      return Object.keys(this.map);
+    },
+
+    set: function Dict_set(key, value) {
+      this.map[key] = value;
+    },
+
+    has: function Dict_has(key) {
+      return key in this.map;
+    },
+
+    forEach: function Dict_forEach(callback) {
+      for (var key in this.map) {
+        callback(key, this.get(key));
+      }
+    }
+  };
+
+  Dict.empty = new Dict(null);
+
+  Dict.merge = function Dict_merge(xref, dictArray) {
+    var mergedDict = new Dict(xref);
+
+    for (var i = 0, ii = dictArray.length; i < ii; i++) {
+      var dict = dictArray[i];
+      if (!isDict(dict)) {
+        continue;
+      }
+      for (var keyName in dict.map) {
+        if (mergedDict.map[keyName]) {
+          continue;
+        }
+        mergedDict.map[keyName] = dict.map[keyName];
+      }
+    }
+    return mergedDict;
+  };
+
+  return Dict;
+})();
+
+var Ref = (function RefClosure() {
+  function Ref(num, gen) {
+    this.num = num;
+    this.gen = gen;
+  }
+
+  Ref.prototype = {
+    toString: function Ref_toString() {
+      // This function is hot, so we make the string as compact as possible.
+      // |this.gen| is almost always zero, so we treat that case specially.
+      var str = this.num + 'R';
+      if (this.gen !== 0) {
+        str += this.gen;
+      }
+      return str;
+    }
+  };
+
+  return Ref;
+})();
+
+// The reference is identified by number and generation.
+// This structure stores only one instance of the reference.
+var RefSet = (function RefSetClosure() {
+  function RefSet() {
+    this.dict = {};
+  }
+
+  RefSet.prototype = {
+    has: function RefSet_has(ref) {
+      return ref.toString() in this.dict;
+    },
+
+    put: function RefSet_put(ref) {
+      this.dict[ref.toString()] = true;
+    },
+
+    remove: function RefSet_remove(ref) {
+      delete this.dict[ref.toString()];
+    }
+  };
+
+  return RefSet;
+})();
+
+var RefSetCache = (function RefSetCacheClosure() {
+  function RefSetCache() {
+    this.dict = Object.create(null);
+  }
+
+  RefSetCache.prototype = {
+    get: function RefSetCache_get(ref) {
+      return this.dict[ref.toString()];
+    },
+
+    has: function RefSetCache_has(ref) {
+      return ref.toString() in this.dict;
+    },
+
+    put: function RefSetCache_put(ref, obj) {
+      this.dict[ref.toString()] = obj;
+    },
+
+    putAlias: function RefSetCache_putAlias(ref, aliasRef) {
+      this.dict[ref.toString()] = this.get(aliasRef);
+    },
+
+    forEach: function RefSetCache_forEach(fn, thisArg) {
+      for (var i in this.dict) {
+        fn.call(thisArg, this.dict[i]);
+      }
+    },
+
+    clear: function RefSetCache_clear() {
+      this.dict = Object.create(null);
+    }
+  };
+
+  return RefSetCache;
+})();
+
+function isName(v) {
+  return v instanceof Name;
+}
+
+function isCmd(v, cmd) {
+  return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
+}
+
+function isDict(v, type) {
+  if (!(v instanceof Dict)) {
+    return false;
+  }
+  if (!type) {
+    return true;
+  }
+  var dictType = v.get('Type');
+  return isName(dictType) && dictType.name === type;
+}
+
+function isRef(v) {
+  return v instanceof Ref;
+}
+
+function isStream(v) {
+  return typeof v === 'object' && v !== null && v.getBytes !== undefined;
+}
+
+exports.Cmd = Cmd;
+exports.Dict = Dict;
+exports.Name = Name;
+exports.Ref = Ref;
+exports.RefSet = RefSet;
+exports.RefSetCache = RefSetCache;
+exports.isCmd = isCmd;
+exports.isDict = isDict;
+exports.isName = isName;
+exports.isRef = isRef;
+exports.isStream = isStream;
+}));
diff --git a/src/core/ps_parser.js b/src/core/ps_parser.js
index 9727a0d..f91e4af 100644
--- a/src/core/ps_parser.js
+++ b/src/core/ps_parser.js
@@ -12,10 +12,25 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals EOF, error, Lexer */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/ps_parser', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/parser'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./parser.js'));
+  } else {
+    factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
+      root.pdfjsCoreParser);
+  }
+}(this, function (exports, sharedUtil, coreParser) {
+
+var error = sharedUtil.error;
+var EOF = coreParser.EOF;
+var Lexer = coreParser.Lexer;
+
 var PostScriptParser = (function PostScriptParserClosure() {
   function PostScriptParser(lexer) {
     this.lexer = lexer;
@@ -218,3 +233,7 @@ var PostScriptLexer = (function PostScriptLexerClosure() {
   };
   return PostScriptLexer;
 })();
+
+exports.PostScriptLexer = PostScriptLexer;
+exports.PostScriptParser = PostScriptParser;
+}));
diff --git a/src/core/stream.js b/src/core/stream.js
index 3fb3748..fceff08 100644
--- a/src/core/stream.js
+++ b/src/core/stream.js
@@ -12,11 +12,44 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals bytesToString, ColorSpace, Dict, EOF, error, info, isArray,
-           Jbig2Image, JpegImage, JpxImage, Lexer, PDFJS, shadow, Util, warn */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/stream', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/jbig2', 'pdfjs/core/jpg',
+      'pdfjs/core/jpx'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./jbig2.js'), require('./jpg.js'), require('./jpx.js'));
+  } else {
+    factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
+      root.pdfjsCoreJpx);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
+                  coreJpx) {
+
+var Util = sharedUtil.Util;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var shadow = sharedUtil.shadow;
+var warn = sharedUtil.warn;
+var Dict = corePrimitives.Dict;
+var Jbig2Image = coreJbig2.Jbig2Image;
+var JpegImage = coreJpg.JpegImage;
+var JpxImage = coreJpx.JpxImage;
+
+var coreParser; // see _setCoreParser below
+var EOF; // = coreParser.EOF;
+var Lexer; // = coreParser.Lexer;
+
+var coreColorSpace; // see _setCoreColorSpace below
+var ColorSpace; // = coreColorSpace.ColorSpace;
+
 var Stream = (function StreamClosure() {
   function Stream(arrayBuffer, start, length, dict) {
     this.bytes = (arrayBuffer instanceof Uint8Array ?
@@ -2464,3 +2497,36 @@ var NullStream = (function NullStreamClosure() {
 
   return NullStream;
 })();
+
+// TODO refactor to remove dependency on parser.js
+function _setCoreParser(coreParser_) {
+  coreParser = coreParser_;
+  EOF = coreParser_.EOF;
+  Lexer = coreParser_.Lexer;
+}
+exports._setCoreParser = _setCoreParser;
+
+// TODO refactor to remove dependency on colorspace.js
+function _setCoreColorSpace(coreColorSpace_) {
+  coreColorSpace = coreColorSpace_;
+  ColorSpace = coreColorSpace_.ColorSpace;
+}
+exports._setCoreColorSpace = _setCoreColorSpace;
+
+exports.Ascii85Stream = Ascii85Stream;
+exports.AsciiHexStream = AsciiHexStream;
+exports.CCITTFaxStream = CCITTFaxStream;
+exports.DecryptStream = DecryptStream;
+exports.DecodeStream = DecodeStream;
+exports.FlateStream = FlateStream;
+exports.Jbig2Stream = Jbig2Stream;
+exports.JpegStream = JpegStream;
+exports.JpxStream = JpxStream;
+exports.NullStream = NullStream;
+exports.PredictorStream = PredictorStream;
+exports.RunLengthStream = RunLengthStream;
+exports.Stream = Stream;
+exports.StreamsSequenceStream = StreamsSequenceStream;
+exports.StringStream = StringStream;
+exports.LZWStream = LZWStream;
+}));
diff --git a/src/core/worker.js b/src/core/worker.js
index ae90138..4245710 100644
--- a/src/core/worker.js
+++ b/src/core/worker.js
@@ -12,14 +12,46 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, createPromiseCapability, LocalPdfManager, NetworkPdfManager,
-           NetworkManager, isInt, MissingPDFException, UNSUPPORTED_FEATURES,
-           UnexpectedResponseException, PasswordException, Promise, warn,
-           PasswordResponses, InvalidPDFException, UnknownErrorException,
-           XRefParseException, Ref, info, globalScope, error, MessageHandler */
+/* globals NetworkManager */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/core/worker', ['exports', 'pdfjs/shared/util',
+      'pdfjs/core/primitives', 'pdfjs/core/pdf_manager', 'pdfjs/shared/global'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./primitives.js'),
+      require('./pdf_manager.js'), require('../shared/global.js'));
+  } else {
+    factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
+      root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
+      root.pdfjsSharedGlobal);
+  }
+}(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
+                  sharedGlobal) {
+
+var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
+var InvalidPDFException = sharedUtil.InvalidPDFException;
+var MessageHandler = sharedUtil.MessageHandler;
+var MissingPDFException = sharedUtil.MissingPDFException;
+var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
+var PasswordException = sharedUtil.PasswordException;
+var PasswordResponses = sharedUtil.PasswordResponses;
+var UnknownErrorException = sharedUtil.UnknownErrorException;
+var XRefParseException = sharedUtil.XRefParseException;
+var createPromiseCapability = sharedUtil.createPromiseCapability;
+var error = sharedUtil.error;
+var info = sharedUtil.info;
+var isInt = sharedUtil.isInt;
+var warn = sharedUtil.warn;
+var Ref = corePrimitives.Ref;
+var LocalPdfManager = corePdfManager.LocalPdfManager;
+var NetworkPdfManager = corePdfManager.NetworkPdfManager;
+var globalScope = sharedGlobal.globalScope;
+var PDFJS = sharedGlobal.PDFJS;
+
 var WorkerTask = (function WorkerTaskClosure() {
   function WorkerTask(name) {
     this.name = name;
@@ -621,6 +653,10 @@ if (typeof window === 'undefined') {
     globalScope.console = workerConsole;
   }
 
-  var handler = new MessageHandler('worker', 'main', this);
-  WorkerMessageHandler.setup(handler, this);
+  var handler = new MessageHandler('worker', 'main', self);
+  WorkerMessageHandler.setup(handler, self);
 }
+
+exports.WorkerTask = WorkerTask;
+exports.WorkerMessageHandler = WorkerMessageHandler;
+}));
diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js
index f24db67..a65f905 100644
--- a/src/display/annotation_layer.js
+++ b/src/display/annotation_layer.js
@@ -12,11 +12,30 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, Util, AnnotationType, AnnotationBorderStyleType, warn,
-           CustomStyle, isExternalLinkTargetSet, LinkTargetStringMap */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/annotation_layer', ['exports', 'pdfjs/shared/util',
+      'pdfjs/display/dom_utils'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./dom_utils.js'));
+  } else {
+    factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
+      root.pdfjsDisplayDOMUtils);
+  }
+}(this, function (exports, sharedUtil, displayDOMUtils) {
+
+var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
+var AnnotationType = sharedUtil.AnnotationType;
+var Util = sharedUtil.Util;
+var isExternalLinkTargetSet = sharedUtil.Util;
+var LinkTargetStringMap = sharedUtil.LinkTargetStringMap;
+var warn = sharedUtil.warn;
+var CustomStyle = displayDOMUtils.CustomStyle;
+
 var ANNOT_MIN_SIZE = 10; // px
 
 var AnnotationLayer = (function AnnotationLayerClosure() {
@@ -354,5 +373,7 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
     update: update
   };
 })();
-
 PDFJS.AnnotationLayer = AnnotationLayer;
+
+exports.AnnotationLayer = AnnotationLayer;
+}));
diff --git a/src/display/api.js b/src/display/api.js
index 646f09e..e95409f 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -12,15 +12,50 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, isArrayBuffer, error, combineUrl, createPromiseCapability,
-           StatTimer, globalScope, MessageHandler, info, FontLoader, Util, warn,
-           Promise, PasswordResponses, PasswordException, InvalidPDFException,
-           MissingPDFException, UnknownErrorException, FontFaceObject,
-           loadJpegStream, createScratchCanvas, CanvasGraphics, stringToBytes,
-           UnexpectedResponseException, deprecated */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/api', ['exports', 'pdfjs/shared/util',
+      'pdfjs/display/font_loader', 'pdfjs/display/canvas',
+      'pdfjs/shared/global'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./font_loader.js'),
+      require('./canvas.js'), require('../shared/global.js'));
+  } else {
+    factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
+      root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
+      root.pdfjsSharedGlobal);
+  }
+}(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
+                  sharedGlobal) {
+
+var InvalidPDFException = sharedUtil.InvalidPDFException;
+var MessageHandler = sharedUtil.MessageHandler;
+var MissingPDFException = sharedUtil.MissingPDFException;
+var PasswordResponses = sharedUtil.PasswordResponses;
+var PasswordException = sharedUtil.PasswordException;
+var StatTimer = sharedUtil.StatTimer;
+var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
+var UnknownErrorException = sharedUtil.UnknownErrorException;
+var Util = sharedUtil.Util;
+var createPromiseCapability = sharedUtil.createPromiseCapability;
+var combineUrl = sharedUtil.combineUrl;
+var error = sharedUtil.error;
+var deprecated = sharedUtil.deprecated;
+var info = sharedUtil.info;
+var isArrayBuffer = sharedUtil.isArrayBuffer;
+var loadJpegStream = sharedUtil.loadJpegStream;
+var stringToBytes = sharedUtil.stringToBytes;
+var warn = sharedUtil.warn;
+var FontFaceObject = displayFontLoader.FontFaceObject;
+var FontLoader = displayFontLoader.FontLoader;
+var CanvasGraphics = displayCanvas.CanvasGraphics;
+var createScratchCanvas = displayCanvas.createScratchCanvas;
+var PDFJS = sharedGlobal.PDFJS;
+var globalScope = sharedGlobal.globalScope;
+
 var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
 
 /**
@@ -2036,3 +2071,9 @@ PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
     }
   };
 })();
+
+exports.getDocument = PDFJS.getDocument;
+exports.PDFDataRangeTransport = PDFDataRangeTransport;
+exports.PDFDocumentProxy = PDFDocumentProxy;
+exports.PDFPageProxy = PDFPageProxy;
+}));
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 9cf911a..f55ad4b 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -12,13 +12,41 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals IDENTITY_MATRIX, FONT_IDENTITY_MATRIX, TextRenderingMode, ImageData,
-           ImageKind, PDFJS, Uint32ArrayView, error, WebGLUtils, OPS, warn,
-           shadow, isNum, Util, TilingPattern, getShadingPatternFromIR, isArray,
-           info, assert */
+/* globals PDFJS, ImageData */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/canvas', ['exports', 'pdfjs/shared/util',
+      'pdfjs/display/pattern_helper', 'pdfjs/display/webgl'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'),
+      require('./pattern_helper.js'), require('./webgl.js'));
+  } else {
+    factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
+      root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
+  }
+}(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
+
+var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
+var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
+var ImageKind = sharedUtil.ImageKind;
+var OPS = sharedUtil.OPS;
+var TextRenderingMode = sharedUtil.TextRenderingMode;
+var Uint32ArrayView = sharedUtil.Uint32ArrayView;
+var Util = sharedUtil.Util;
+var assert = sharedUtil.assert;
+var info = sharedUtil.info;
+var isNum = sharedUtil.isNum;
+var isArray = sharedUtil.isArray;
+var error = sharedUtil.error;
+var shadow = sharedUtil.shadow;
+var warn = sharedUtil.warn;
+var TilingPattern = displayPatternHelper.TilingPattern;
+var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
+var WebGLUtils = displayWebGL.WebGLUtils;
+
 // <canvas> contexts store most of the state we need natively.
 // However, PDF needs a bit more state, which we store here.
 
@@ -1580,8 +1608,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
         var color = IR[1];
         var baseTransform = this.baseTransform ||
                             this.ctx.mozCurrentTransform.slice();
-        pattern = new TilingPattern(IR, color, this.ctx, this.objs,
-                                    this.commonObjs, baseTransform);
+        var self = this;
+        var canvasGraphicsFactory = {
+          createCanvasGraphics: function (ctx) {
+            return new CanvasGraphics(ctx, self.commonObjs, self.objs);
+          }
+        };
+        pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
+                                    baseTransform);
       } else {
         pattern = getShadingPatternFromIR(IR);
       }
@@ -2181,3 +2215,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
 
   return CanvasGraphics;
 })();
+
+exports.CanvasGraphics = CanvasGraphics;
+exports.createScratchCanvas = createScratchCanvas;
+}));
diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js
index 5b76bc4..6b8a4f4 100644
--- a/src/display/dom_utils.js
+++ b/src/display/dom_utils.js
@@ -12,10 +12,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/dom_utils', ['exports', 'pdfjs/shared/global'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/global.js'));
+  } else {
+    factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
+  }
+}(this, function (exports, sharedGlobal) {
+
+var PDFJS = sharedGlobal.PDFJS;
+
 /**
  * Optimised CSS custom property getter/setter.
  * @class
@@ -71,3 +83,6 @@ var CustomStyle = (function CustomStyleClosure() {
 })();
 
 PDFJS.CustomStyle = CustomStyle;
+
+exports.CustomStyle = CustomStyle;
+}));
diff --git a/src/display/font_loader.js b/src/display/font_loader.js
index e78fdd2..4648af2 100644
--- a/src/display/font_loader.js
+++ b/src/display/font_loader.js
@@ -12,11 +12,33 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, shadow, isWorker, assert, warn, bytesToString, string32,
-           globalScope, FontFace, Promise */
+/* globals FontFace */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/font_loader', ['exports', 'pdfjs/shared/util',
+      'pdfjs/shared/global'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'),
+      require('../shared/global.js'));
+  } else {
+    factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
+      root.pdfjsSharedGlobal);
+  }
+}(this, function (exports, sharedUtil, sharedGlobal) {
+
+var assert = sharedUtil.assert;
+var bytesToString = sharedUtil.bytesToString;
+var string32 = sharedUtil.string32;
+var shadow = sharedUtil.shadow;
+var warn = sharedUtil.warn;
+
+var PDFJS = sharedGlobal.PDFJS;
+var globalScope = sharedGlobal.globalScope;
+var isWorker = sharedGlobal.isWorker;
+
 function FontLoader(docId) {
   this.docId = docId;
   this.styleElement = null;
@@ -430,3 +452,7 @@ var FontFaceObject = (function FontFaceObjectClosure() {
   };
   return FontFaceObject;
 })();
+
+exports.FontFaceObject = FontFaceObject;
+exports.FontLoader = FontLoader;
+}));
diff --git a/src/display/metadata.js b/src/display/metadata.js
index 1adf72f..ad5f579 100644
--- a/src/display/metadata.js
+++ b/src/display/metadata.js
@@ -12,10 +12,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals Document, error, PDFJS */
+/* globals PDFJS, Document */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/metadata', ['exports', 'pdfjs/shared/util'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'));
+  } else {
+    factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
+  }
+}(this, function (exports, sharedUtil) {
+
+var error = sharedUtil.error;
+
 var Metadata = PDFJS.Metadata = (function MetadataClosure() {
   function fixMetadata(meta) {
     return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
@@ -95,3 +107,6 @@ var Metadata = PDFJS.Metadata = (function MetadataClosure() {
 
   return Metadata;
 })();
+
+exports.Metadata = Metadata;
+}));
diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js
index bff9bda..c5b6a3b 100644
--- a/src/display/pattern_helper.js
+++ b/src/display/pattern_helper.js
@@ -12,11 +12,27 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals CanvasGraphics, CachedCanvases, ColorSpace, Util, error, info,
-           isArray, makeCssRgb, WebGLUtils */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/pattern_helper', ['exports', 'pdfjs/shared/util',
+      'pdfjs/display/webgl'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'), require('./webgl.js'));
+  } else {
+    factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
+      root.pdfjsDisplayWebGL);
+  }
+}(this, function (exports, sharedUtil, displayWebGL) {
+
+var Util = sharedUtil.Util;
+var info = sharedUtil.info;
+var isArray = sharedUtil.isArray;
+var error = sharedUtil.error;
+var WebGLUtils = displayWebGL.WebGLUtils;
+
 var ShadingIRs = {};
 
 ShadingIRs.RadialAxial = {
@@ -289,7 +305,7 @@ var TilingPattern = (function TilingPatternClosure() {
 
   var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
 
-  function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
+  function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
     this.operatorList = IR[2];
     this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
     this.bbox = IR[4];
@@ -298,8 +314,7 @@ var TilingPattern = (function TilingPatternClosure() {
     this.paintType = IR[7];
     this.tilingType = IR[8];
     this.color = color;
-    this.objs = objs;
-    this.commonObjs = commonObjs;
+    this.canvasGraphicsFactory = canvasGraphicsFactory;
     this.baseTransform = baseTransform;
     this.type = 'Pattern';
     this.ctx = ctx;
@@ -314,8 +329,7 @@ var TilingPattern = (function TilingPatternClosure() {
       var paintType = this.paintType;
       var tilingType = this.tilingType;
       var color = this.color;
-      var objs = this.objs;
-      var commonObjs = this.commonObjs;
+      var canvasGraphicsFactory = this.canvasGraphicsFactory;
 
       info('TilingType: ' + tilingType);
 
@@ -348,7 +362,7 @@ var TilingPattern = (function TilingPatternClosure() {
       var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
         width, height, true);
       var tmpCtx = tmpCanvas.context;
-      var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
+      var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
       graphics.groupLevel = owner.groupLevel;
 
       this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
@@ -423,3 +437,7 @@ var TilingPattern = (function TilingPatternClosure() {
 
   return TilingPattern;
 })();
+
+exports.getShadingPatternFromIR = getShadingPatternFromIR;
+exports.TilingPattern = TilingPattern;
+}));
diff --git a/src/display/svg.js b/src/display/svg.js
index 6facd3f..472287e 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -12,12 +12,30 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, FONT_IDENTITY_MATRIX, IDENTITY_MATRIX, isArray,
-           isNum, OPS, Promise, Util, warn, ImageKind, PDFJS */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/svg', ['exports', 'pdfjs/shared/util'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'));
+  } else {
+    factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
+  }
+}(this, function (exports, sharedUtil) {
 //#if (GENERIC || SINGLE_FILE)
+
+var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
+var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
+var ImageKind = sharedUtil.ImageKind;
+var OPS = sharedUtil.OPS;
+var Util = sharedUtil.Util;
+var isNum = sharedUtil.isNum;
+var isArray = sharedUtil.isArray;
+var warn = sharedUtil.warn;
+
 var SVG_DEFAULTS = {
   fontStyle: 'normal',
   fontWeight: 'normal',
@@ -1189,4 +1207,7 @@ var SVGGraphics = (function SVGGraphicsClosure() {
 })();
 
 PDFJS.SVGGraphics = SVGGraphics;
+
+exports.SVGGraphics = SVGGraphics;
 //#endif
+}));
diff --git a/src/display/text_layer.js b/src/display/text_layer.js
index 576853e..7b00f07 100644
--- a/src/display/text_layer.js
+++ b/src/display/text_layer.js
@@ -12,10 +12,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, createPromiseCapability */
+/* globals PDFJS */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/text_layer', ['exports', 'pdfjs/shared/util'],
+      factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'));
+  } else {
+    factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil);
+  }
+}(this, function (exports, sharedUtil) {
+
+var createPromiseCapability = sharedUtil.createPromiseCapability;
+
 /**
  * Text layer render parameters.
  *
@@ -235,3 +248,6 @@ var renderTextLayer = (function renderTextLayerClosure() {
 })();
 
 PDFJS.renderTextLayer = renderTextLayer;
+
+exports.renderTextLayer = renderTextLayer;
+}));
diff --git a/src/display/webgl.js b/src/display/webgl.js
index b5d9c8b..2a3fb09 100644
--- a/src/display/webgl.js
+++ b/src/display/webgl.js
@@ -12,11 +12,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, shadow */
+/* globals PDFJS */
 /* jshint -W043 */
 
 'use strict';
 
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/display/webgl', ['exports', 'pdfjs/shared/util'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('../shared/util.js'));
+  } else {
+    factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
+  }
+}(this, function (exports, sharedUtil) {
+
+var shadow = sharedUtil.shadow;
+
 var WebGLUtils = (function WebGLUtilsClosure() {
   function loadShader(gl, code, shaderType) {
     var shader = gl.createShader(shaderType);
@@ -433,3 +445,6 @@ var WebGLUtils = (function WebGLUtilsClosure() {
     clear: cleanup
   };
 })();
+
+exports.WebGLUtils = WebGLUtils;
+}));
diff --git a/src/expose_to_global.js b/src/expose_to_global.js
new file mode 100644
index 0000000..36b4d50
--- /dev/null
+++ b/src/expose_to_global.js
@@ -0,0 +1,35 @@
+/* Copyright 2015 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.
+ */
+
+/*
+ NOTE: This file is created as a helper to expose all loaded internal exported
+ members to global scope.
+ */
+
+'use strict';
+
+(function (root) {
+  for (var i in root) {
+    if (/^pdfjs(Shared|Core|Display)/.test(i)) {
+      var obj = root[i];
+      for (var j in obj) {
+        if (Object.getOwnPropertyDescriptor(root, j)) {
+          continue; // ignoring if already set
+        }
+        root[j] =  obj[j];
+      }
+    }
+  }
+})(window);
diff --git a/src/shared/global.js b/src/shared/global.js
new file mode 100644
index 0000000..2492b07
--- /dev/null
+++ b/src/shared/global.js
@@ -0,0 +1,47 @@
+/* Copyright 2015 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.
+ */
+/* globals PDFJS, global */
+
+'use strict';
+
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/shared/global', ['exports'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports);
+  } else {
+    factory((root.pdfjsSharedGlobal = {}));
+  }
+}(this, function (exports) {
+
+  var globalScope = (typeof window !== 'undefined') ? window :
+                    (typeof global !== 'undefined') ? global :
+                    (typeof self !== 'undefined') ? self : this;
+
+  var isWorker = (typeof window === 'undefined');
+
+  // The global PDFJS object exposes the API
+  // In production, it will be declared outside a global wrapper
+  // In development, it will be declared here
+  if (!globalScope.PDFJS) {
+    globalScope.PDFJS = {};
+  }
+
+  globalScope.PDFJS.pdfBug = false;
+
+  exports.globalScope = globalScope;
+  exports.isWorker = isWorker;
+  exports.PDFJS = globalScope.PDFJS;
+}));
diff --git a/src/shared/util.js b/src/shared/util.js
index ebdd6e6..9b203ca 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -12,14 +12,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
-           Promise */
+/* globals MozBlobBuilder, URL */
 
 'use strict';
 
-var globalScope = (typeof window === 'undefined') ? this : window;
+(function (root, factory) {
+  if (typeof define === 'function' && define.amd) {
+    define('pdfjs/shared/util', ['exports', 'pdfjs/shared/global'], factory);
+  } else if (typeof exports !== 'undefined') {
+    factory(exports, require('./global.js'));
+  } else {
+    factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
+  }
+}(this, function (exports, sharedGlobal) {
 
-var isWorker = (typeof window === 'undefined');
+var PDFJS = sharedGlobal.PDFJS;
+var globalScope = sharedGlobal.globalScope;
 
 var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
 
@@ -119,15 +127,6 @@ var FontType = {
   MMTYPE1: 10
 };
 
-// The global PDFJS object exposes the API
-// In production, it will be declared outside a global wrapper
-// In development, it will be declared here
-if (!globalScope.PDFJS) {
-  globalScope.PDFJS = {};
-}
-
-globalScope.PDFJS.pdfBug = false;
-
 PDFJS.VERBOSITY_LEVELS = {
   errors: 0,
   warnings: 1,
@@ -1046,41 +1045,14 @@ function isString(v) {
   return typeof v === 'string';
 }
 
-function isName(v) {
-  return v instanceof Name;
-}
-
-function isCmd(v, cmd) {
-  return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
-}
-
-function isDict(v, type) {
-  if (!(v instanceof Dict)) {
-    return false;
-  }
-  if (!type) {
-    return true;
-  }
-  var dictType = v.get('Type');
-  return isName(dictType) && dictType.name === type;
-}
-
 function isArray(v) {
   return v instanceof Array;
 }
 
-function isStream(v) {
-  return typeof v === 'object' && v !== null && v.getBytes !== undefined;
-}
-
 function isArrayBuffer(v) {
   return typeof v === 'object' && v !== null && v.byteLength !== undefined;
 }
 
-function isRef(v) {
-  return v instanceof Ref;
-}
-
 /**
  * Promise Capability object.
  *
@@ -1669,3 +1641,59 @@ function loadJpegStream(id, imageUrl, objs) {
   });
   img.src = imageUrl;
 }
+
+exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
+exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
+exports.OPS = OPS;
+exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
+exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
+exports.AnnotationFlag = AnnotationFlag;
+exports.AnnotationType = AnnotationType;
+exports.FontType = FontType;
+exports.ImageKind = ImageKind;
+exports.InvalidPDFException = InvalidPDFException;
+exports.LinkTarget = LinkTarget;
+exports.LinkTargetStringMap = LinkTargetStringMap;
+exports.MessageHandler = MessageHandler;
+exports.MissingDataException = MissingDataException;
+exports.MissingPDFException = MissingPDFException;
+exports.NotImplementedException = NotImplementedException;
+exports.PasswordException = PasswordException;
+exports.PasswordResponses = PasswordResponses;
+exports.StatTimer = StatTimer;
+exports.StreamType = StreamType;
+exports.TextRenderingMode = TextRenderingMode;
+exports.Uint32ArrayView = Uint32ArrayView;
+exports.UnexpectedResponseException = UnexpectedResponseException;
+exports.UnknownErrorException = UnknownErrorException;
+exports.Util = Util;
+exports.XRefParseException = XRefParseException;
+exports.assert = assert;
+exports.bytesToString = bytesToString;
+exports.combineUrl = combineUrl;
+exports.createPromiseCapability = createPromiseCapability;
+exports.deprecated = deprecated;
+exports.error = error;
+exports.info = info;
+exports.isArray = isArray;
+exports.isArrayBuffer = isArrayBuffer;
+exports.isBool = isBool;
+exports.isEmptyObj = isEmptyObj;
+exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
+exports.isInt = isInt;
+exports.isNum = isNum;
+exports.isString = isString;
+exports.isValidUrl = isValidUrl;
+exports.loadJpegStream = loadJpegStream;
+exports.log2 = log2;
+exports.readInt8 = readInt8;
+exports.readUint16 = readUint16;
+exports.readUint32 = readUint32;
+exports.shadow = shadow;
+exports.string32 = string32;
+exports.stringToBytes = stringToBytes;
+exports.stringToPDFString = stringToPDFString;
+exports.stringToUTF8String = stringToUTF8String;
+exports.utf8StringToString = utf8StringToString;
+exports.warn = warn;
+}));
diff --git a/src/worker_loader.js b/src/worker_loader.js
index 2500f99..dc11706 100644
--- a/src/worker_loader.js
+++ b/src/worker_loader.js
@@ -18,39 +18,41 @@
 
 // List of shared files to include;
 var sharedFiles = [
+  'shared/global.js',
   'shared/util.js'
 ];
 
 // List of other files to include;
 var otherFiles = [
   'core/network.js',
+  'core/arithmetic_decoder.js',
+  'core/charsets.js',
+  'core/glyphlist.js',
+  'core/jpg.js',
+  'core/metrics.js',
+  'core/bidi.js',
   'core/chunked_stream.js',
-  'core/pdf_manager.js',
-  'core/core.js',
+  'core/jbig2.js',
+  'core/jpx.js',
+  'core/murmurhash3.js',
+  'core/primitives.js',
+  'core/stream.js',
+  'core/crypto.js',
+  'core/font_renderer.js',
+  'core/parser.js',
+  'core/cmap.js',
   'core/obj.js',
-  'core/charsets.js',
-  'core/annotation.js',
+  'core/ps_parser.js',
+  'core/fonts.js',
   'core/function.js',
   'core/colorspace.js',
-  'core/crypto.js',
+  'core/image.js',
   'core/pattern.js',
   'core/evaluator.js',
-  'core/cmap.js',
-  'core/fonts.js',
-  'core/font_renderer.js',
-  'core/glyphlist.js',
-  'core/image.js',
-  'core/metrics.js',
-  'core/parser.js',
-  'core/ps_parser.js',
-  'core/stream.js',
-  'core/worker.js',
-  'core/arithmetic_decoder.js',
-  'core/jpg.js',
-  'core/jpx.js',
-  'core/jbig2.js',
-  'core/bidi.js',
-  'core/murmurhash3.js'
+  'core/annotation.js',
+  'core/document.js',
+  'core/pdf_manager.js',
+  'core/worker.js'
 ];
 
 function loadInOrder(index, path, files) {
diff --git a/test/driver.js b/test/driver.js
index a61084e..fa9c77a 100644
--- a/test/driver.js
+++ b/test/driver.js
@@ -12,7 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals PDFJS, combineUrl, StatTimer, Promise */
+/* globals PDFJS, pdfjsSharedUtil */
 
 'use strict';
 
@@ -196,7 +196,8 @@ var Driver = (function DriverClosure() {
 
       this._log('Loading file "' + task.file + '"\n');
 
-      var absoluteUrl = combineUrl(window.location.href, task.file);
+      var absoluteUrl = pdfjsSharedUtil.combineUrl(window.location.href,
+                                                   task.file);
 
       PDFJS.disableRange = task.disableRange;
       PDFJS.disableAutoFetch = !task.enableAutoFetch;
@@ -360,7 +361,7 @@ var Driver = (function DriverClosure() {
               }
               page.cleanup();
               task.stats = page.stats;
-              page.stats = new StatTimer();
+              page.stats = new pdfjsSharedUtil.StatTimer();
               self._snapshot(task, error);
             });
             initPromise.then(function () {
diff --git a/test/font/font_test.html b/test/font/font_test.html
index 77c581a..44a3fbc 100644
--- a/test/font/font_test.html
+++ b/test/font/font_test.html
@@ -13,35 +13,46 @@
 
   <!-- include source files here... -->
   <script src="../../src/core/network.js"></script>
-  <script src="../../src/core/chunked_stream.js"></script>
-  <script src="../../src/core/pdf_manager.js"></script>
-  <script src="../../src/core/core.js"></script>
+  <script src="../../src/core/arithmetic_decoder.js"></script>
+  <script src="../../src/core/charsets.js"></script>
+  <script src="../../src/core/glyphlist.js"></script>
+  <script src="../../src/core/jpg.js"></script>
+  <script src="../../src/core/metrics.js"></script>
+  <script src="../../src/shared/global.js"></script>
+  <script src="../../src/core/bidi.js"></script>
+  <script src="../../src/display/dom_utils.js"></script>
   <script src="../../src/shared/util.js"></script>
-  <script src="../../src/display/api.js"></script>
-  <script src="../../src/display/canvas.js"></script>
+  <script src="../../src/core/chunked_stream.js"></script>
+  <script src="../../src/core/jbig2.js"></script>
+  <script src="../../src/core/jpx.js"></script>
+  <script src="../../src/core/murmurhash3.js"></script>
+  <script src="../../src/core/primitives.js"></script>
+  <script src="../../src/display/annotation_layer.js"></script>
+  <script src="../../src/display/font_loader.js"></script>
+  <script src="../../src/display/metadata.js"></script>
+  <script src="../../src/display/text_layer.js"></script>
   <script src="../../src/display/webgl.js"></script>
+  <script src="../../src/core/stream.js"></script>
+  <script src="../../src/display/pattern_helper.js"></script>
+  <script src="../../src/core/crypto.js"></script>
+  <script src="../../src/core/font_renderer.js"></script>
+  <script src="../../src/core/parser.js"></script>
+  <script src="../../src/display/canvas.js"></script>
+  <script src="../../src/core/cmap.js"></script>
   <script src="../../src/core/obj.js"></script>
-  <script src="../../src/core/annotation.js"></script>
+  <script src="../../src/core/ps_parser.js"></script>
+  <script src="../../src/display/api.js"></script>
+  <script src="../../src/core/fonts.js"></script>
   <script src="../../src/core/function.js"></script>
-  <script src="../../src/core/charsets.js"></script>
   <script src="../../src/core/colorspace.js"></script>
-  <script src="../../src/core/crypto.js"></script>
+  <script src="../../src/core/image.js"></script>
   <script src="../../src/core/pattern.js"></script>
   <script src="../../src/core/evaluator.js"></script>
-  <script src="../../src/core/cmap.js"></script>
-  <script src="../../src/core/fonts.js"></script>
-  <script src="../../src/core/glyphlist.js"></script>
-  <script src="../../src/core/image.js"></script>
-  <script src="../../src/core/metrics.js"></script>
-  <script src="../../src/core/parser.js"></script>
-  <script src="../../src/core/ps_parser.js"></script>
-  <script src="../../src/display/pattern_helper.js"></script>
-  <script src="../../src/display/annotation_layer.js"></script>
-  <script src="../../src/display/text_layer.js"></script>
-  <script src="../../src/core/stream.js"></script>
+  <script src="../../src/core/annotation.js"></script>
+  <script src="../../src/core/document.js"></script>
+  <script src="../../src/core/pdf_manager.js"></script>
   <script src="../../src/core/worker.js"></script>
-  <script src="../../src/display/metadata.js"></script>
-  <script src="../../src/core/jpg.js"></script>
+  <script src="../../src/expose_to_global.js"></script>
   <script>PDFJS.workerSrc = '../../src/worker_loader.js';</script>
 
   <!-- include spec files here... -->
diff --git a/test/test_slave.html b/test/test_slave.html
index ad33b59..50f0ce1 100644
--- a/test/test_slave.html
+++ b/test/test_slave.html
@@ -18,16 +18,17 @@ limitations under the License.
   <head>
     <title>PDF.js test slave</title>
     <meta charset="utf-8">
+    <script src="../src/shared/global.js"></script>
+    <script src="../src/display/dom_utils.js"></script>
     <script src="../src/shared/util.js"></script>
-    <script src="../src/display/api.js"></script>
+    <script src="../src/display/annotation_layer.js"></script>
+    <script src="../src/display/font_loader.js"></script>
     <script src="../src/display/metadata.js"></script>
-    <script src="../src/display/canvas.js"></script>
+    <script src="../src/display/text_layer.js"></script>
     <script src="../src/display/webgl.js"></script>
     <script src="../src/display/pattern_helper.js"></script>
-    <script src="../src/display/font_loader.js"></script>
-    <script src="../src/display/dom_utils.js"></script>
-    <script src="../src/display/annotation_layer.js"></script>
-    <script src="../src/display/text_layer.js"></script>
+    <script src="../src/display/canvas.js"></script>
+    <script src="../src/display/api.js"></script>
     <script src="driver.js"></script>
   </head>
   <body>
diff --git a/test/unit/font_spec.js b/test/unit/font_spec.js
index 7f25ac0..1eff8a2 100644
--- a/test/unit/font_spec.js
+++ b/test/unit/font_spec.js
@@ -109,7 +109,7 @@ describe('font', function() {
     it('parses a CharString endchar with 4 args w/seac enabled', function() {
       var seacAnalysisState = SEAC_ANALYSIS_ENABLED;
       try {
-        SEAC_ANALYSIS_ENABLED = true;
+        window.pdfjsCoreFonts._enableSeacAnalysis(true);
         var bytes = new Uint8Array([0, 1, // count
                                     1,  // offsetSize
                                     0,  // offset[0]
@@ -125,14 +125,14 @@ describe('font', function() {
         expect(result.seacs[0][2]).toEqual(65);
         expect(result.seacs[0][3]).toEqual(194);
       } finally {
-        SEAC_ANALYSIS_ENABLED = seacAnalysisState;
+        window.pdfjsCoreFonts._enableSeacAnalysis(seacAnalysisState);
       }
     });
 
     it('parses a CharString endchar with 4 args w/seac disabled', function() {
       var seacAnalysisState = SEAC_ANALYSIS_ENABLED;
       try {
-        SEAC_ANALYSIS_ENABLED = false;
+        window.pdfjsCoreFonts._enableSeacAnalysis(false);
         var bytes = new Uint8Array([0, 1, // count
                                     1,  // offsetSize
                                     0,  // offset[0]
@@ -143,7 +143,7 @@ describe('font', function() {
         expect(result.charStrings.get(0).length).toEqual(9);
         expect(result.seacs.length).toEqual(0);
       } finally {
-        SEAC_ANALYSIS_ENABLED = seacAnalysisState;
+        window.pdfjsCoreFonts._enableSeacAnalysis(seacAnalysisState);
       }
     });
 
diff --git a/test/unit/obj_spec.js b/test/unit/primitives_spec.js
similarity index 99%
rename from test/unit/obj_spec.js
rename to test/unit/primitives_spec.js
index 7b91899..20482ea 100644
--- a/test/unit/obj_spec.js
+++ b/test/unit/primitives_spec.js
@@ -3,7 +3,7 @@
 
 'use strict';
 
-describe('obj', function() {
+describe('primitives', function() {
 
   describe('Name', function() {
     it('should retain the given name', function() {
diff --git a/test/unit/unit_test.html b/test/unit/unit_test.html
index 2fbfa8d..6b6bff8 100644
--- a/test/unit/unit_test.html
+++ b/test/unit/unit_test.html
@@ -12,42 +12,51 @@
 
   <!-- include source files here... -->
   <script src="../../src/core/network.js"></script>
-  <script src="../../src/core/chunked_stream.js"></script>
-  <script src="../../src/core/pdf_manager.js"></script>
-  <script src="../../src/core/core.js"></script>
-  <script src="../../src/shared/util.js"></script>
-  <script src="../../src/display/api.js"></script>
-  <script src="../../src/display/canvas.js"></script>
-  <script src="../../src/display/webgl.js"></script>
-  <script src="../../src/core/obj.js"></script>
-  <script src="../../src/core/annotation.js"></script>
-  <script src="../../src/core/function.js"></script>
+  <script src="../../src/core/arithmetic_decoder.js"></script>
   <script src="../../src/core/charsets.js"></script>
-  <script src="../../src/core/colorspace.js"></script>
-  <script src="../../src/core/crypto.js"></script>
-  <script src="../../src/core/pattern.js"></script>
-  <script src="../../src/core/evaluator.js"></script>
-  <script src="../../src/core/cmap.js"></script>
-  <script src="../../src/core/fonts.js"></script>
   <script src="../../src/core/glyphlist.js"></script>
-  <script src="../../src/core/image.js"></script>
+  <script src="../../src/core/jpg.js"></script>
   <script src="../../src/core/metrics.js"></script>
-  <script src="../../src/core/parser.js"></script>
-  <script src="../../src/core/ps_parser.js"></script>
-  <script src="../../src/display/pattern_helper.js"></script>
-  <script src="../../src/display/font_loader.js"></script>
+  <script src="../../src/shared/global.js"></script>
+  <script src="../../src/core/bidi.js"></script>
   <script src="../../src/display/dom_utils.js"></script>
+  <script src="../../src/shared/util.js"></script>
+  <script src="../../src/core/chunked_stream.js"></script>
+  <script src="../../src/core/jbig2.js"></script>
+  <script src="../../src/core/jpx.js"></script>
+  <script src="../../src/core/murmurhash3.js"></script>
+  <script src="../../src/core/primitives.js"></script>
   <script src="../../src/display/annotation_layer.js"></script>
+  <script src="../../src/display/font_loader.js"></script>
+  <script src="../../src/display/metadata.js"></script>
   <script src="../../src/display/text_layer.js"></script>
+  <script src="../../src/display/webgl.js"></script>
   <script src="../../src/core/stream.js"></script>
+  <script src="../../src/display/pattern_helper.js"></script>
+  <script src="../../src/core/crypto.js"></script>
+  <script src="../../src/core/font_renderer.js"></script>
+  <script src="../../src/core/parser.js"></script>
+  <script src="../../src/display/canvas.js"></script>
+  <script src="../../src/core/cmap.js"></script>
+  <script src="../../src/core/obj.js"></script>
+  <script src="../../src/core/ps_parser.js"></script>
+  <script src="../../src/display/api.js"></script>
+  <script src="../../src/core/fonts.js"></script>
+  <script src="../../src/core/function.js"></script>
+  <script src="../../src/core/colorspace.js"></script>
+  <script src="../../src/core/image.js"></script>
+  <script src="../../src/core/pattern.js"></script>
+  <script src="../../src/core/evaluator.js"></script>
+  <script src="../../src/core/annotation.js"></script>
+  <script src="../../src/core/document.js"></script>
+  <script src="../../src/core/pdf_manager.js"></script>
   <script src="../../src/core/worker.js"></script>
-  <script src="../../src/display/metadata.js"></script>
-  <script src="../../src/core/jpg.js"></script>
+  <script src="../../src/expose_to_global.js"></script>
   <script src="../../web/ui_utils.js"></script>
   <script>PDFJS.workerSrc = '../../src/worker_loader.js';</script>
 
   <!-- include spec files here... -->
-  <script src="obj_spec.js"></script>
+  <script src="primitives_spec.js"></script>
   <script src="font_spec.js"></script>
   <script src="function_spec.js"></script>
   <script src="crypto_spec.js"></script>
diff --git a/web/viewer.html b/web/viewer.html
index 8cc4ea9..2423e9b 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -53,16 +53,17 @@ See https://github.com/adobe-type-tools/cmap-resources
 <!--#endif-->
 
 <!--#if !PRODUCTION-->
+    <script src="../src/shared/global.js"></script>
+    <script src="../src/display/dom_utils.js"></script>
     <script src="../src/shared/util.js"></script>
-    <script src="../src/display/api.js"></script>
+    <script src="../src/display/annotation_layer.js"></script>
+    <script src="../src/display/font_loader.js"></script>
     <script src="../src/display/metadata.js"></script>
-    <script src="../src/display/canvas.js"></script>
+    <script src="../src/display/text_layer.js"></script>
     <script src="../src/display/webgl.js"></script>
     <script src="../src/display/pattern_helper.js"></script>
-    <script src="../src/display/font_loader.js"></script>
-    <script src="../src/display/dom_utils.js"></script>
-    <script src="../src/display/annotation_layer.js"></script>
-    <script src="../src/display/text_layer.js"></script>
+    <script src="../src/display/canvas.js"></script>
+    <script src="../src/display/api.js"></script>
     <script>PDFJS.workerSrc = '../src/worker_loader.js';</script>
 <!--#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