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