Adds UMD header to pdf.js and pdf.worker.js files.
This commit is contained in:
parent
e8db825512
commit
cbbb9bb82d
3
external/umdutils/verifier.js
vendored
3
external/umdutils/verifier.js
vendored
@ -55,6 +55,9 @@ var path = require('path');
|
||||
*/
|
||||
function parseUmd(filePath) {
|
||||
var jscode = fs.readFileSync(filePath).toString();
|
||||
if (/\/\*\s*umdutils\s+ignore\s*\*\//.test(jscode)) {
|
||||
throw new Error('UMD processing ignored');
|
||||
}
|
||||
// Extracts header and body.
|
||||
var umdStart = '\\(function\\s\\(root,\\sfactory\\)\\s\\{';
|
||||
var umdImports = '\\}\\(this,\\sfunction\\s\\(exports\\b';
|
||||
|
20
make.js
20
make.js
@ -484,7 +484,7 @@ target.bundle = function(args) {
|
||||
echo();
|
||||
echo('### Bundling files into ' + BUILD_TARGET);
|
||||
|
||||
function bundle(filename, outfilename, files) {
|
||||
function bundle(filename, outfilename, files, distname) {
|
||||
var bundleContent = cat(files),
|
||||
bundleVersion = VERSION,
|
||||
bundleBuild = exec('git log --format="%h" -n 1',
|
||||
@ -500,12 +500,18 @@ target.bundle = function(args) {
|
||||
// Removes AMD and CommonJS branches from UMD headers.
|
||||
bundleContent = stripUMDHeaders(bundleContent);
|
||||
|
||||
var amdName = 'pdfjs-dist/build/' + distname.replace(/\.js$/, '');
|
||||
var jsName = amdName.replace(/[\-_\.\/]\w/g, function (all) {
|
||||
return all[1].toUpperCase();
|
||||
});
|
||||
// This just preprocesses the empty pdf.js file, we don't actually want to
|
||||
// preprocess everything yet since other build targets use this file.
|
||||
builder.preprocess(filename, outfilename, builder.merge(defines,
|
||||
{BUNDLE: bundleContent,
|
||||
BUNDLE_VERSION: bundleVersion,
|
||||
BUNDLE_BUILD: bundleBuild}));
|
||||
BUNDLE_BUILD: bundleBuild,
|
||||
BUNDLE_AMD_NAME: amdName,
|
||||
BUNDLE_JS_NAME: jsName}));
|
||||
}
|
||||
|
||||
if (!test('-d', BUILD_DIR)) {
|
||||
@ -524,6 +530,9 @@ target.bundle = function(args) {
|
||||
SRC_DIR + 'core/worker.js'
|
||||
];
|
||||
|
||||
var mainFileName = 'pdf.js';
|
||||
var workerFileName = 'pdf.worker.js';
|
||||
|
||||
// Extension does not need svg.js and network.js files.
|
||||
if (!defines.FIREFOX && !defines.MOZCENTRAL) {
|
||||
MAIN_SRC_FILES.push(SRC_DIR + 'display/svg.js');
|
||||
@ -535,6 +544,8 @@ target.bundle = function(args) {
|
||||
// the main pdf.js output.
|
||||
MAIN_SRC_FILES = MAIN_SRC_FILES.concat(WORKER_SRC_FILES);
|
||||
WORKER_SRC_FILES = null; // no need for worker file
|
||||
mainFileName = 'pdf.combined.js';
|
||||
workerFileName = null;
|
||||
}
|
||||
|
||||
// Reading UMD headers and building loading orders of modules. The
|
||||
@ -549,12 +560,13 @@ target.bundle = function(args) {
|
||||
|
||||
cd(SRC_DIR);
|
||||
|
||||
bundle('pdf.js', ROOT_DIR + BUILD_TARGET, mainFiles);
|
||||
bundle('pdf.js', ROOT_DIR + BUILD_TARGET, mainFiles, mainFileName);
|
||||
|
||||
if (workerFiles) {
|
||||
var srcCopy = ROOT_DIR + BUILD_DIR + 'pdf.worker.js.temp';
|
||||
cp('pdf.js', srcCopy);
|
||||
bundle(srcCopy, ROOT_DIR + BUILD_WORKER_TARGET, workerFiles);
|
||||
bundle(srcCopy, ROOT_DIR + BUILD_WORKER_TARGET, workerFiles,
|
||||
workerFileName);
|
||||
rm(srcCopy);
|
||||
}
|
||||
};
|
||||
|
@ -12,6 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals pdfjsFilePath */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -1177,6 +1178,18 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
||||
var PDFWorker = (function PDFWorkerClosure() {
|
||||
var nextFakeWorkerId = 0;
|
||||
|
||||
function getWorkerSrc() {
|
||||
if (PDFJS.workerSrc) {
|
||||
return PDFJS.workerSrc;
|
||||
}
|
||||
//#if PRODUCTION && !(MOZCENTRAL || FIREFOX)
|
||||
// if (pdfjsFilePath) {
|
||||
// return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
|
||||
// }
|
||||
//#endif
|
||||
error('No PDFJS.workerSrc specified');
|
||||
}
|
||||
|
||||
// Loads worker code into main thread.
|
||||
function setupFakeWorkerGlobal() {
|
||||
if (!PDFJS.fakeWorkerFilesLoadedCapability) {
|
||||
@ -1201,7 +1214,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
||||
//#endif
|
||||
//#if PRODUCTION && !SINGLE_FILE
|
||||
// var loader = fakeWorkerFilesLoader || function (callback) {
|
||||
// Util.loadScript(PDFJS.workerSrc, callback);
|
||||
// Util.loadScript(getWorkerSrc(), callback);
|
||||
// };
|
||||
// loader(function () {
|
||||
// PDFJS.fakeWorkerFilesLoadedCapability.resolve();
|
||||
@ -1243,10 +1256,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
||||
// Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
|
||||
//#if !SINGLE_FILE
|
||||
if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {
|
||||
var workerSrc = PDFJS.workerSrc;
|
||||
if (!workerSrc) {
|
||||
error('No PDFJS.workerSrc specified');
|
||||
}
|
||||
var workerSrc = getWorkerSrc();
|
||||
|
||||
try {
|
||||
// Some versions of FF can't create a worker on localhost, see:
|
||||
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals PDFJS, require, module */
|
||||
/* globals PDFJS, require, module, requirejs */
|
||||
|
||||
// included from api.js for GENERIC build
|
||||
|
||||
@ -32,9 +32,16 @@ if (typeof __webpack_require__ !== 'undefined') {
|
||||
PDFJS.workerSrc = require('entry?name=[hash]-worker.js!./pdf.worker.js');
|
||||
useRequireEnsure = true;
|
||||
}
|
||||
var fakeWorkerFilesLoader = useRequireEnsure && function (callback) {
|
||||
if (typeof requirejs !== 'undefined' && requirejs.toUrl) {
|
||||
PDFJS.workerSrc = requirejs.toUrl('pdfjs-dist/build/pdf.worker.js');
|
||||
}
|
||||
var fakeWorkerFilesLoader = useRequireEnsure ? (function (callback) {
|
||||
require.ensure([], function () {
|
||||
require('./pdf.worker.js');
|
||||
callback();
|
||||
});
|
||||
};
|
||||
}) : (typeof requirejs !== 'undefined') ? (function (callback) {
|
||||
requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) {
|
||||
callback();
|
||||
});
|
||||
}) : null;
|
||||
|
51
src/pdf.js
51
src/pdf.js
@ -13,36 +13,35 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* jshint globalstrict: false */
|
||||
/* globals PDFJS, global */
|
||||
/* umdutils ignore */
|
||||
|
||||
// Initializing PDFJS global object (if still undefined)
|
||||
if (typeof PDFJS === 'undefined') {
|
||||
(typeof window !== 'undefined' ? window :
|
||||
typeof global !== 'undefined' ? global : this).PDFJS = {};
|
||||
}
|
||||
|
||||
//#if BUNDLE_VERSION
|
||||
//#expand PDFJS.version = '__BUNDLE_VERSION__';
|
||||
//#endif
|
||||
//#if BUNDLE_BUILD
|
||||
//#expand PDFJS.build = '__BUNDLE_BUILD__';
|
||||
//#endif
|
||||
|
||||
(function pdfjsWrapper() {
|
||||
(function (root, factory) {
|
||||
'use strict';
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
//#expand define('__BUNDLE_AMD_NAME__', ['exports'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
factory(exports);
|
||||
} else {
|
||||
//#expand factory((root.__BUNDLE_JS_NAME__ = {}));
|
||||
}
|
||||
}(this, function (exports) {
|
||||
// Use strict in our context only - users might not want it
|
||||
'use strict';
|
||||
|
||||
//#expand var pdfjsVersion = '__BUNDLE_VERSION__';
|
||||
//#expand var pdfjsBuild = '__BUNDLE_BUILD__';
|
||||
|
||||
var pdfjsFilePath =
|
||||
typeof document !== 'undefined' && document.currentScript ?
|
||||
document.currentScript.src : null;
|
||||
|
||||
var pdfjsLibs = {};
|
||||
|
||||
(function pdfjsWrapper() {
|
||||
|
||||
//#expand __BUNDLE__
|
||||
|
||||
}).call((typeof window === 'undefined') ? this : window);
|
||||
}).call(pdfjsLibs);
|
||||
|
||||
//#if !(MOZCENTRAL || FIREFOX)
|
||||
if (!PDFJS.workerSrc && typeof document !== 'undefined') {
|
||||
// workerSrc is not set -- using last script url to define default location
|
||||
PDFJS.workerSrc = (function () {
|
||||
'use strict';
|
||||
var pdfJsSrc = document.currentScript.src;
|
||||
return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
|
||||
})();
|
||||
}
|
||||
//#endif
|
||||
exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
|
||||
}));
|
||||
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals global */
|
||||
/* globals global, pdfjsVersion, pdfjsBuild */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -39,6 +39,13 @@
|
||||
globalScope.PDFJS = {};
|
||||
}
|
||||
|
||||
if (typeof pdfjsVersion !== 'undefined') {
|
||||
globalScope.PDFJS.version = pdfjsVersion;
|
||||
}
|
||||
if (typeof pdfjsVersion !== 'undefined') {
|
||||
globalScope.PDFJS.build = pdfjsBuild;
|
||||
}
|
||||
|
||||
globalScope.PDFJS.pdfBug = false;
|
||||
|
||||
exports.globalScope = globalScope;
|
||||
|
Loading…
Reference in New Issue
Block a user