2017-02-24 07:35:35 +09:00
|
|
|
/* Copyright 2017 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2018-02-18 07:51:24 +09:00
|
|
|
|
|
|
|
const globalScope = require('./global_scope');
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2017-04-02 20:14:36 +09:00
|
|
|
// Skip compatibility checks for the extensions and if we already ran
|
2017-02-24 07:35:35 +09:00
|
|
|
// this module.
|
|
|
|
if ((typeof PDFJSDev === 'undefined' ||
|
2018-01-26 20:18:57 +09:00
|
|
|
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) &&
|
2018-02-18 07:51:24 +09:00
|
|
|
!globalScope._pdfjsCompatibilityChecked) {
|
|
|
|
|
|
|
|
globalScope._pdfjsCompatibilityChecked = true;
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2018-01-26 20:18:57 +09:00
|
|
|
// In the Chrome extension, most of the polyfills are unnecessary.
|
|
|
|
// We support down to Chrome 49, because it's still commonly used by Windows XP
|
|
|
|
// users - https://github.com/mozilla/pdf.js/issues/9397
|
|
|
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) {
|
|
|
|
|
2018-01-06 21:10:58 +09:00
|
|
|
const isNodeJS = require('./is_node');
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2018-02-17 20:57:15 +09:00
|
|
|
const hasDOM = typeof window === 'object' && typeof document === 'object';
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2018-01-06 21:10:58 +09:00
|
|
|
// Support: Node.js
|
|
|
|
(function checkNodeBtoa() {
|
|
|
|
if (globalScope.btoa || !isNodeJS()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
globalScope.btoa = function(chars) {
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
return Buffer.from(chars, 'binary').toString('base64');
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Support: Node.js
|
|
|
|
(function checkNodeAtob() {
|
|
|
|
if (globalScope.atob || !isNodeJS()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
globalScope.atob = function(input) {
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
return Buffer.from(input, 'base64').toString('binary');
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2017-02-24 07:35:35 +09:00
|
|
|
// Provides support for ChildNode.remove in legacy browsers.
|
|
|
|
// Support: IE.
|
|
|
|
(function checkChildNodeRemove() {
|
|
|
|
if (!hasDOM) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (typeof Element.prototype.remove !== 'undefined') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Element.prototype.remove = function () {
|
|
|
|
if (this.parentNode) {
|
2018-02-11 00:19:45 +09:00
|
|
|
// eslint-disable-next-line mozilla/avoid-removeChild
|
2017-02-24 07:35:35 +09:00
|
|
|
this.parentNode.removeChild(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
2018-02-04 22:31:59 +09:00
|
|
|
|
2019-02-08 21:31:14 +09:00
|
|
|
// Provides support for DOMTokenList.prototype.{add, remove}, with more than
|
|
|
|
// one parameter, in legacy browsers.
|
|
|
|
// Support: IE
|
|
|
|
(function checkDOMTokenListAddRemove() {
|
|
|
|
if (!hasDOM || isNodeJS()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.classList.add('testOne', 'testTwo');
|
|
|
|
|
|
|
|
if (div.classList.contains('testOne') === true &&
|
|
|
|
div.classList.contains('testTwo') === true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const OriginalDOMTokenListAdd = DOMTokenList.prototype.add;
|
|
|
|
const OriginalDOMTokenListRemove = DOMTokenList.prototype.remove;
|
|
|
|
|
|
|
|
DOMTokenList.prototype.add = function(...tokens) {
|
|
|
|
for (let token of tokens) {
|
|
|
|
OriginalDOMTokenListAdd.call(this, token);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DOMTokenList.prototype.remove = function(...tokens) {
|
|
|
|
for (let token of tokens) {
|
|
|
|
OriginalDOMTokenListRemove.call(this, token);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2018-10-12 22:25:38 +09:00
|
|
|
// Provides support for DOMTokenList.prototype.toggle, with the optional
|
|
|
|
// "force" parameter, in legacy browsers.
|
|
|
|
// Support: IE
|
|
|
|
(function checkDOMTokenListToggle() {
|
|
|
|
if (!hasDOM || isNodeJS()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const div = document.createElement('div');
|
|
|
|
if (div.classList.toggle('test', 0) === false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMTokenList.prototype.toggle = function(token) {
|
2019-02-08 21:31:14 +09:00
|
|
|
let force = (arguments.length > 1 ? !!arguments[1] : !this.contains(token));
|
|
|
|
return (this[force ? 'add' : 'remove'](token), force);
|
2018-10-12 22:25:38 +09:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2019-01-06 01:09:44 +09:00
|
|
|
// Provides support for String.prototype.startsWith in legacy browsers.
|
|
|
|
// Support: IE, Chrome<41
|
|
|
|
(function checkStringStartsWith() {
|
|
|
|
if (String.prototype.startsWith) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require('core-js/fn/string/starts-with');
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Provides support for String.prototype.endsWith in legacy browsers.
|
|
|
|
// Support: IE, Chrome<41
|
|
|
|
(function checkStringEndsWith() {
|
|
|
|
if (String.prototype.endsWith) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require('core-js/fn/string/ends-with');
|
|
|
|
})();
|
|
|
|
|
2018-02-04 22:31:59 +09:00
|
|
|
// Provides support for String.prototype.includes in legacy browsers.
|
|
|
|
// Support: IE, Chrome<41
|
|
|
|
(function checkStringIncludes() {
|
|
|
|
if (String.prototype.includes) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-28 20:04:32 +09:00
|
|
|
require('core-js/fn/string/includes');
|
2018-02-04 22:31:59 +09:00
|
|
|
})();
|
2017-02-24 07:35:35 +09:00
|
|
|
|
2017-10-16 16:09:08 +09:00
|
|
|
// Provides support for Array.prototype.includes in legacy browsers.
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE, Chrome<47
|
2017-10-16 16:09:08 +09:00
|
|
|
(function checkArrayIncludes() {
|
|
|
|
if (Array.prototype.includes) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-28 20:04:32 +09:00
|
|
|
require('core-js/fn/array/includes');
|
2017-10-16 16:09:08 +09:00
|
|
|
})();
|
|
|
|
|
2019-01-20 16:49:20 +09:00
|
|
|
// Provides support for Array.from in legacy browsers.
|
|
|
|
// Support: IE
|
|
|
|
(function checkArrayFrom() {
|
|
|
|
if (Array.from) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require('core-js/fn/array/from');
|
|
|
|
})();
|
|
|
|
|
2018-06-11 02:59:03 +09:00
|
|
|
// Provides support for Object.assign in legacy browsers.
|
|
|
|
// Support: IE
|
|
|
|
(function checkObjectAssign() {
|
|
|
|
if (Object.assign) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require('core-js/fn/object/assign');
|
|
|
|
})();
|
|
|
|
|
2017-12-10 01:24:31 +09:00
|
|
|
// Provides support for Math.log2 in legacy browsers.
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE, Chrome<38
|
2017-12-10 01:24:31 +09:00
|
|
|
(function checkMathLog2() {
|
|
|
|
if (Math.log2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Math.log2 = require('core-js/fn/math/log2');
|
|
|
|
})();
|
2017-10-16 16:09:08 +09:00
|
|
|
|
2017-07-13 18:48:17 +09:00
|
|
|
// Provides support for Number.isNaN in legacy browsers.
|
|
|
|
// Support: IE.
|
|
|
|
(function checkNumberIsNaN() {
|
|
|
|
if (Number.isNaN) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-21 19:58:53 +09:00
|
|
|
Number.isNaN = require('core-js/fn/number/is-nan');
|
2017-07-13 18:48:17 +09:00
|
|
|
})();
|
|
|
|
|
|
|
|
// Provides support for Number.isInteger in legacy browsers.
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE, Chrome<34
|
2017-07-13 18:48:17 +09:00
|
|
|
(function checkNumberIsInteger() {
|
|
|
|
if (Number.isInteger) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-21 19:58:53 +09:00
|
|
|
Number.isInteger = require('core-js/fn/number/is-integer');
|
2017-07-13 18:48:17 +09:00
|
|
|
})();
|
|
|
|
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE, Safari<8, Chrome<32
|
2017-02-24 07:35:35 +09:00
|
|
|
(function checkPromise() {
|
Add a `gulp image_decoders` command to allow packaging/distributing the image decoders (i.e. jpg.js, jpx.js, jbig2.js) separately from the main PDF.js library
Please note that the standalone `pdf.image_decoders.js` file will be including the complete `src/shared/util.js` file, despite only using parts of it.[1] This was done *purposely*, to not negatively impact the readability/maintainability of the core PDF.js code.
Furthermore, to ensure that the compatibility is the same in the regular PDF.js library *and* in the the standalone image decoders, `src/shared/compatibility.js` was included as well.
To (hopefully) prevent future complaints about the size of the built `pdf.image_decoders.js` file, a few existing async-related polyfills are being skipped (since all of the image decoders are completely synchronous).
Obviously this required adding a couple of pre-processor statements, but given that these are all limited to "compatibility" code, I think this might be OK!?
---
[1] However, please note that previous commits moved `PageViewport` and `MessageHandler` out of `src/shared/util.js` which reduced its size.
2018-05-16 20:49:26 +09:00
|
|
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('IMAGE_DECODERS')) {
|
|
|
|
// The current image decoders are synchronous, hence `Promise` shouldn't
|
|
|
|
// need to be polyfilled for the IMAGE_DECODERS build target.
|
|
|
|
return;
|
|
|
|
}
|
2017-02-24 07:35:35 +09:00
|
|
|
if (globalScope.Promise) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-21 19:49:15 +09:00
|
|
|
globalScope.Promise = require('core-js/fn/promise');
|
2017-02-24 07:35:35 +09:00
|
|
|
})();
|
|
|
|
|
2018-01-24 04:12:03 +09:00
|
|
|
// Support: IE<11, Safari<8, Chrome<36
|
2017-02-24 07:35:35 +09:00
|
|
|
(function checkWeakMap() {
|
|
|
|
if (globalScope.WeakMap) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-15 17:22:06 +09:00
|
|
|
globalScope.WeakMap = require('core-js/fn/weak-map');
|
2017-02-24 07:35:35 +09:00
|
|
|
})();
|
|
|
|
|
2018-11-01 02:15:23 +09:00
|
|
|
// Support: IE11
|
|
|
|
(function checkWeakSet() {
|
|
|
|
if (globalScope.WeakSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
globalScope.WeakSet = require('core-js/fn/weak-set');
|
|
|
|
})();
|
|
|
|
|
2018-01-05 07:43:07 +09:00
|
|
|
// Provides support for String.codePointAt in legacy browsers.
|
|
|
|
// Support: IE11.
|
|
|
|
(function checkStringCodePointAt() {
|
|
|
|
if (String.codePointAt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String.codePointAt = require('core-js/fn/string/code-point-at');
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Provides support for String.fromCodePoint in legacy browsers.
|
|
|
|
// Support: IE11.
|
|
|
|
(function checkStringFromCodePoint() {
|
|
|
|
if (String.fromCodePoint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String.fromCodePoint = require('core-js/fn/string/from-code-point');
|
|
|
|
})();
|
|
|
|
|
2018-08-20 19:14:37 +09:00
|
|
|
// Support: IE
|
|
|
|
(function checkSymbol() {
|
|
|
|
if (globalScope.Symbol) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require('core-js/es6/symbol');
|
|
|
|
})();
|
|
|
|
|
2018-01-26 20:18:57 +09:00
|
|
|
} // End of !PDFJSDev.test('CHROME')
|
|
|
|
|
2019-01-06 01:09:44 +09:00
|
|
|
// Provides support for String.prototype.padStart in legacy browsers.
|
|
|
|
// Support: IE, Chrome<57
|
|
|
|
(function checkStringPadStart() {
|
|
|
|
if (String.prototype.padStart) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require('core-js/fn/string/pad-start');
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Provides support for String.prototype.padEnd in legacy browsers.
|
|
|
|
// Support: IE, Chrome<57
|
|
|
|
(function checkStringPadEnd() {
|
|
|
|
if (String.prototype.padEnd) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
require('core-js/fn/string/pad-end');
|
|
|
|
})();
|
|
|
|
|
2018-01-26 20:18:57 +09:00
|
|
|
// Provides support for Object.values in legacy browsers.
|
|
|
|
// Support: IE, Chrome<54
|
|
|
|
(function checkObjectValues() {
|
|
|
|
if (Object.values) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Object.values = require('core-js/fn/object/values');
|
|
|
|
})();
|
|
|
|
|
2017-02-24 07:35:35 +09:00
|
|
|
}
|