2
0

compatibility.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2019 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  24. var globalScope = require('./global_scope');
  25. if (!globalScope._pdfjsCompatibilityChecked) {
  26. globalScope._pdfjsCompatibilityChecked = true;
  27. var isNodeJS = require('./is_node');
  28. var hasDOM = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && (typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object';
  29. (function checkNodeBtoa() {
  30. if (globalScope.btoa || !isNodeJS()) {
  31. return;
  32. }
  33. globalScope.btoa = function (chars) {
  34. return Buffer.from(chars, 'binary').toString('base64');
  35. };
  36. })();
  37. (function checkNodeAtob() {
  38. if (globalScope.atob || !isNodeJS()) {
  39. return;
  40. }
  41. globalScope.atob = function (input) {
  42. return Buffer.from(input, 'base64').toString('binary');
  43. };
  44. })();
  45. (function checkChildNodeRemove() {
  46. if (!hasDOM) {
  47. return;
  48. }
  49. if (typeof Element.prototype.remove !== 'undefined') {
  50. return;
  51. }
  52. Element.prototype.remove = function () {
  53. if (this.parentNode) {
  54. this.parentNode.removeChild(this);
  55. }
  56. };
  57. })();
  58. (function checkDOMTokenListAddRemove() {
  59. if (!hasDOM || isNodeJS()) {
  60. return;
  61. }
  62. var div = document.createElement('div');
  63. div.classList.add('testOne', 'testTwo');
  64. if (div.classList.contains('testOne') === true && div.classList.contains('testTwo') === true) {
  65. return;
  66. }
  67. var OriginalDOMTokenListAdd = DOMTokenList.prototype.add;
  68. var OriginalDOMTokenListRemove = DOMTokenList.prototype.remove;
  69. DOMTokenList.prototype.add = function () {
  70. for (var _len = arguments.length, tokens = new Array(_len), _key = 0; _key < _len; _key++) {
  71. tokens[_key] = arguments[_key];
  72. }
  73. for (var _i = 0, _tokens = tokens; _i < _tokens.length; _i++) {
  74. var token = _tokens[_i];
  75. OriginalDOMTokenListAdd.call(this, token);
  76. }
  77. };
  78. DOMTokenList.prototype.remove = function () {
  79. for (var _len2 = arguments.length, tokens = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  80. tokens[_key2] = arguments[_key2];
  81. }
  82. for (var _i2 = 0, _tokens2 = tokens; _i2 < _tokens2.length; _i2++) {
  83. var token = _tokens2[_i2];
  84. OriginalDOMTokenListRemove.call(this, token);
  85. }
  86. };
  87. })();
  88. (function checkDOMTokenListToggle() {
  89. if (!hasDOM || isNodeJS()) {
  90. return;
  91. }
  92. var div = document.createElement('div');
  93. if (div.classList.toggle('test', 0) === false) {
  94. return;
  95. }
  96. DOMTokenList.prototype.toggle = function (token) {
  97. var force = arguments.length > 1 ? !!arguments[1] : !this.contains(token);
  98. return this[force ? 'add' : 'remove'](token), force;
  99. };
  100. })();
  101. (function checkStringStartsWith() {
  102. if (String.prototype.startsWith) {
  103. return;
  104. }
  105. require('core-js/fn/string/starts-with');
  106. })();
  107. (function checkStringEndsWith() {
  108. if (String.prototype.endsWith) {
  109. return;
  110. }
  111. require('core-js/fn/string/ends-with');
  112. })();
  113. (function checkStringIncludes() {
  114. if (String.prototype.includes) {
  115. return;
  116. }
  117. require('core-js/fn/string/includes');
  118. })();
  119. (function checkArrayIncludes() {
  120. if (Array.prototype.includes) {
  121. return;
  122. }
  123. require('core-js/fn/array/includes');
  124. })();
  125. (function checkArrayFrom() {
  126. if (Array.from) {
  127. return;
  128. }
  129. require('core-js/fn/array/from');
  130. })();
  131. (function checkObjectAssign() {
  132. if (Object.assign) {
  133. return;
  134. }
  135. require('core-js/fn/object/assign');
  136. })();
  137. (function checkMathLog2() {
  138. if (Math.log2) {
  139. return;
  140. }
  141. Math.log2 = require('core-js/fn/math/log2');
  142. })();
  143. (function checkNumberIsNaN() {
  144. if (Number.isNaN) {
  145. return;
  146. }
  147. Number.isNaN = require('core-js/fn/number/is-nan');
  148. })();
  149. (function checkNumberIsInteger() {
  150. if (Number.isInteger) {
  151. return;
  152. }
  153. Number.isInteger = require('core-js/fn/number/is-integer');
  154. })();
  155. (function checkPromise() {
  156. if (globalScope.Promise && globalScope.Promise.prototype && globalScope.Promise.prototype["finally"]) {
  157. return;
  158. }
  159. globalScope.Promise = require('core-js/fn/promise');
  160. })();
  161. (function checkWeakMap() {
  162. if (globalScope.WeakMap) {
  163. return;
  164. }
  165. globalScope.WeakMap = require('core-js/fn/weak-map');
  166. })();
  167. (function checkWeakSet() {
  168. if (globalScope.WeakSet) {
  169. return;
  170. }
  171. globalScope.WeakSet = require('core-js/fn/weak-set');
  172. })();
  173. (function checkStringCodePointAt() {
  174. if (String.codePointAt) {
  175. return;
  176. }
  177. String.codePointAt = require('core-js/fn/string/code-point-at');
  178. })();
  179. (function checkStringFromCodePoint() {
  180. if (String.fromCodePoint) {
  181. return;
  182. }
  183. String.fromCodePoint = require('core-js/fn/string/from-code-point');
  184. })();
  185. (function checkSymbol() {
  186. if (globalScope.Symbol) {
  187. return;
  188. }
  189. require('core-js/es6/symbol');
  190. })();
  191. (function checkStringPadStart() {
  192. if (String.prototype.padStart) {
  193. return;
  194. }
  195. require('core-js/fn/string/pad-start');
  196. })();
  197. (function checkStringPadEnd() {
  198. if (String.prototype.padEnd) {
  199. return;
  200. }
  201. require('core-js/fn/string/pad-end');
  202. })();
  203. (function checkObjectValues() {
  204. if (Object.values) {
  205. return;
  206. }
  207. Object.values = require('core-js/fn/object/values');
  208. })();
  209. }