compatibility.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  17. if (typeof PDFJS === 'undefined' || !PDFJS.compatibilityChecked) {
  18. var globalScope = require('./global_scope');
  19. var userAgent = typeof navigator !== 'undefined' && navigator.userAgent || '';
  20. var isAndroid = /Android/.test(userAgent);
  21. var isAndroidPre3 = /Android\s[0-2][^\d]/.test(userAgent);
  22. var isAndroidPre5 = /Android\s[0-4][^\d]/.test(userAgent);
  23. var isChrome = userAgent.indexOf('Chrom') >= 0;
  24. var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(userAgent);
  25. var isIOSChrome = userAgent.indexOf('CriOS') >= 0;
  26. var isIE = userAgent.indexOf('Trident') >= 0;
  27. var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent);
  28. var isOpera = userAgent.indexOf('Opera') >= 0;
  29. var isSafari = /Safari\//.test(userAgent) && !/(Chrome\/|Android\s)/.test(userAgent);
  30. var hasDOM = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && (typeof document === 'undefined' ? 'undefined' : _typeof(document)) === 'object';
  31. if (typeof PDFJS === 'undefined') {
  32. globalScope.PDFJS = {};
  33. }
  34. PDFJS.compatibilityChecked = true;
  35. (function checkTypedArrayCompatibility() {
  36. if (typeof Uint8ClampedArray === 'undefined') {
  37. globalScope.Uint8ClampedArray = require('core-js/fn/typed/uint8-clamped-array');
  38. }
  39. if (typeof Uint8Array !== 'undefined') {
  40. if (typeof Uint8Array.prototype.subarray === 'undefined') {
  41. Uint8Array.prototype.subarray = function subarray(start, end) {
  42. return new Uint8Array(this.slice(start, end));
  43. };
  44. Float32Array.prototype.subarray = function subarray(start, end) {
  45. return new Float32Array(this.slice(start, end));
  46. };
  47. }
  48. if (typeof Float64Array === 'undefined') {
  49. globalScope.Float64Array = Float32Array;
  50. }
  51. return;
  52. }
  53. function subarray(start, end) {
  54. return new TypedArray(this.slice(start, end));
  55. }
  56. function setArrayOffset(array, offset) {
  57. if (arguments.length < 2) {
  58. offset = 0;
  59. }
  60. for (var i = 0, n = array.length; i < n; ++i, ++offset) {
  61. this[offset] = array[i] & 0xFF;
  62. }
  63. }
  64. function Uint32ArrayView(buffer, length) {
  65. this.buffer = buffer;
  66. this.byteLength = buffer.length;
  67. this.length = length;
  68. ensureUint32ArrayViewProps(this.length);
  69. }
  70. Uint32ArrayView.prototype = Object.create(null);
  71. var uint32ArrayViewSetters = 0;
  72. function createUint32ArrayProp(index) {
  73. return {
  74. get: function get() {
  75. var buffer = this.buffer,
  76. offset = index << 2;
  77. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  78. },
  79. set: function set(value) {
  80. var buffer = this.buffer,
  81. offset = index << 2;
  82. buffer[offset] = value & 255;
  83. buffer[offset + 1] = value >> 8 & 255;
  84. buffer[offset + 2] = value >> 16 & 255;
  85. buffer[offset + 3] = value >>> 24 & 255;
  86. }
  87. };
  88. }
  89. function ensureUint32ArrayViewProps(length) {
  90. while (uint32ArrayViewSetters < length) {
  91. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  92. uint32ArrayViewSetters++;
  93. }
  94. }
  95. function TypedArray(arg1) {
  96. var result, i, n;
  97. if (typeof arg1 === 'number') {
  98. result = [];
  99. for (i = 0; i < arg1; ++i) {
  100. result[i] = 0;
  101. }
  102. } else if ('slice' in arg1) {
  103. result = arg1.slice(0);
  104. } else {
  105. result = [];
  106. for (i = 0, n = arg1.length; i < n; ++i) {
  107. result[i] = arg1[i];
  108. }
  109. }
  110. result.subarray = subarray;
  111. result.buffer = result;
  112. result.byteLength = result.length;
  113. result.set = setArrayOffset;
  114. if ((typeof arg1 === 'undefined' ? 'undefined' : _typeof(arg1)) === 'object' && arg1.buffer) {
  115. result.buffer = arg1.buffer;
  116. }
  117. return result;
  118. }
  119. globalScope.Uint8Array = TypedArray;
  120. globalScope.Int8Array = TypedArray;
  121. globalScope.Int32Array = TypedArray;
  122. globalScope.Uint16Array = TypedArray;
  123. globalScope.Float32Array = TypedArray;
  124. globalScope.Float64Array = TypedArray;
  125. globalScope.Uint32Array = function () {
  126. if (arguments.length === 3) {
  127. if (arguments[1] !== 0) {
  128. throw new Error('offset !== 0 is not supported');
  129. }
  130. return new Uint32ArrayView(arguments[0], arguments[2]);
  131. }
  132. return TypedArray.apply(this, arguments);
  133. };
  134. })();
  135. (function canvasPixelArrayBuffer() {
  136. if (!hasDOM || !window.CanvasPixelArray) {
  137. return;
  138. }
  139. var cpaProto = window.CanvasPixelArray.prototype;
  140. if ('buffer' in cpaProto) {
  141. return;
  142. }
  143. Object.defineProperty(cpaProto, 'buffer', {
  144. get: function get() {
  145. return this;
  146. },
  147. enumerable: false,
  148. configurable: true
  149. });
  150. Object.defineProperty(cpaProto, 'byteLength', {
  151. get: function get() {
  152. return this.length;
  153. },
  154. enumerable: false,
  155. configurable: true
  156. });
  157. })();
  158. (function normalizeURLObject() {
  159. if (!globalScope.URL) {
  160. globalScope.URL = globalScope.webkitURL;
  161. }
  162. })();
  163. (function checkObjectDefinePropertyCompatibility() {
  164. if (typeof Object.defineProperty !== 'undefined') {
  165. var definePropertyPossible = true;
  166. try {
  167. if (hasDOM) {
  168. Object.defineProperty(new Image(), 'id', { value: 'test' });
  169. }
  170. var Test = function Test() {};
  171. Test.prototype = {
  172. get id() {}
  173. };
  174. Object.defineProperty(new Test(), 'id', {
  175. value: '',
  176. configurable: true,
  177. enumerable: true,
  178. writable: false
  179. });
  180. } catch (e) {
  181. definePropertyPossible = false;
  182. }
  183. if (definePropertyPossible) {
  184. return;
  185. }
  186. }
  187. Object.defineProperty = function objectDefineProperty(obj, name, def) {
  188. delete obj[name];
  189. if ('get' in def) {
  190. obj.__defineGetter__(name, def['get']);
  191. }
  192. if ('set' in def) {
  193. obj.__defineSetter__(name, def['set']);
  194. }
  195. if ('value' in def) {
  196. obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
  197. this.__defineGetter__(name, function objectDefinePropertyGetter() {
  198. return value;
  199. });
  200. return value;
  201. });
  202. obj[name] = def.value;
  203. }
  204. };
  205. })();
  206. (function checkXMLHttpRequestResponseCompatibility() {
  207. if (typeof XMLHttpRequest === 'undefined') {
  208. return;
  209. }
  210. var xhrPrototype = XMLHttpRequest.prototype;
  211. var xhr = new XMLHttpRequest();
  212. if (!('overrideMimeType' in xhr)) {
  213. Object.defineProperty(xhrPrototype, 'overrideMimeType', {
  214. value: function xmlHttpRequestOverrideMimeType(mimeType) {}
  215. });
  216. }
  217. if ('responseType' in xhr) {
  218. return;
  219. }
  220. Object.defineProperty(xhrPrototype, 'responseType', {
  221. get: function xmlHttpRequestGetResponseType() {
  222. return this._responseType || 'text';
  223. },
  224. set: function xmlHttpRequestSetResponseType(value) {
  225. if (value === 'text' || value === 'arraybuffer') {
  226. this._responseType = value;
  227. if (value === 'arraybuffer' && typeof this.overrideMimeType === 'function') {
  228. this.overrideMimeType('text/plain; charset=x-user-defined');
  229. }
  230. }
  231. }
  232. });
  233. if (typeof VBArray !== 'undefined') {
  234. Object.defineProperty(xhrPrototype, 'response', {
  235. get: function xmlHttpRequestResponseGet() {
  236. if (this.responseType === 'arraybuffer') {
  237. return new Uint8Array(new VBArray(this.responseBody).toArray());
  238. }
  239. return this.responseText;
  240. }
  241. });
  242. return;
  243. }
  244. Object.defineProperty(xhrPrototype, 'response', {
  245. get: function xmlHttpRequestResponseGet() {
  246. if (this.responseType !== 'arraybuffer') {
  247. return this.responseText;
  248. }
  249. var text = this.responseText;
  250. var i,
  251. n = text.length;
  252. var result = new Uint8Array(n);
  253. for (i = 0; i < n; ++i) {
  254. result[i] = text.charCodeAt(i) & 0xFF;
  255. }
  256. return result.buffer;
  257. }
  258. });
  259. })();
  260. (function checkWindowBtoaCompatibility() {
  261. if ('btoa' in globalScope) {
  262. return;
  263. }
  264. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  265. globalScope.btoa = function (chars) {
  266. var buffer = '';
  267. var i, n;
  268. for (i = 0, n = chars.length; i < n; i += 3) {
  269. var b1 = chars.charCodeAt(i) & 0xFF;
  270. var b2 = chars.charCodeAt(i + 1) & 0xFF;
  271. var b3 = chars.charCodeAt(i + 2) & 0xFF;
  272. var d1 = b1 >> 2,
  273. d2 = (b1 & 3) << 4 | b2 >> 4;
  274. var d3 = i + 1 < n ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  275. var d4 = i + 2 < n ? b3 & 0x3F : 64;
  276. buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
  277. }
  278. return buffer;
  279. };
  280. })();
  281. (function checkWindowAtobCompatibility() {
  282. if ('atob' in globalScope) {
  283. return;
  284. }
  285. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  286. globalScope.atob = function (input) {
  287. input = input.replace(/=+$/, '');
  288. if (input.length % 4 === 1) {
  289. throw new Error('bad atob input');
  290. }
  291. for (var bc = 0, bs, buffer, idx = 0, output = ''; buffer = input.charAt(idx++); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) {
  292. buffer = digits.indexOf(buffer);
  293. }
  294. return output;
  295. };
  296. })();
  297. (function checkFunctionPrototypeBindCompatibility() {
  298. if (typeof Function.prototype.bind !== 'undefined') {
  299. return;
  300. }
  301. Function.prototype.bind = function functionPrototypeBind(obj) {
  302. var fn = this,
  303. headArgs = Array.prototype.slice.call(arguments, 1);
  304. var bound = function functionPrototypeBindBound() {
  305. var args = headArgs.concat(Array.prototype.slice.call(arguments));
  306. return fn.apply(obj, args);
  307. };
  308. return bound;
  309. };
  310. })();
  311. (function checkDatasetProperty() {
  312. if (!hasDOM) {
  313. return;
  314. }
  315. var div = document.createElement('div');
  316. if ('dataset' in div) {
  317. return;
  318. }
  319. Object.defineProperty(HTMLElement.prototype, 'dataset', {
  320. get: function get() {
  321. if (this._dataset) {
  322. return this._dataset;
  323. }
  324. var dataset = {};
  325. for (var j = 0, jj = this.attributes.length; j < jj; j++) {
  326. var attribute = this.attributes[j];
  327. if (attribute.name.substring(0, 5) !== 'data-') {
  328. continue;
  329. }
  330. var key = attribute.name.substring(5).replace(/\-([a-z])/g, function (all, ch) {
  331. return ch.toUpperCase();
  332. });
  333. dataset[key] = attribute.value;
  334. }
  335. Object.defineProperty(this, '_dataset', {
  336. value: dataset,
  337. writable: false,
  338. enumerable: false
  339. });
  340. return dataset;
  341. },
  342. enumerable: true
  343. });
  344. })();
  345. (function checkClassListProperty() {
  346. function changeList(element, itemName, add, remove) {
  347. var s = element.className || '';
  348. var list = s.split(/\s+/g);
  349. if (list[0] === '') {
  350. list.shift();
  351. }
  352. var index = list.indexOf(itemName);
  353. if (index < 0 && add) {
  354. list.push(itemName);
  355. }
  356. if (index >= 0 && remove) {
  357. list.splice(index, 1);
  358. }
  359. element.className = list.join(' ');
  360. return index >= 0;
  361. }
  362. if (!hasDOM) {
  363. return;
  364. }
  365. var div = document.createElement('div');
  366. if ('classList' in div) {
  367. return;
  368. }
  369. var classListPrototype = {
  370. add: function add(name) {
  371. changeList(this.element, name, true, false);
  372. },
  373. contains: function contains(name) {
  374. return changeList(this.element, name, false, false);
  375. },
  376. remove: function remove(name) {
  377. changeList(this.element, name, false, true);
  378. },
  379. toggle: function toggle(name) {
  380. changeList(this.element, name, true, true);
  381. }
  382. };
  383. Object.defineProperty(HTMLElement.prototype, 'classList', {
  384. get: function get() {
  385. if (this._classList) {
  386. return this._classList;
  387. }
  388. var classList = Object.create(classListPrototype, {
  389. element: {
  390. value: this,
  391. writable: false,
  392. enumerable: true
  393. }
  394. });
  395. Object.defineProperty(this, '_classList', {
  396. value: classList,
  397. writable: false,
  398. enumerable: false
  399. });
  400. return classList;
  401. },
  402. enumerable: true
  403. });
  404. })();
  405. (function checkWorkerConsoleCompatibility() {
  406. if (typeof importScripts === 'undefined' || 'console' in globalScope) {
  407. return;
  408. }
  409. var consoleTimer = {};
  410. var workerConsole = {
  411. log: function log() {
  412. var args = Array.prototype.slice.call(arguments);
  413. globalScope.postMessage({
  414. targetName: 'main',
  415. action: 'console_log',
  416. data: args
  417. });
  418. },
  419. error: function error() {
  420. var args = Array.prototype.slice.call(arguments);
  421. globalScope.postMessage({
  422. targetName: 'main',
  423. action: 'console_error',
  424. data: args
  425. });
  426. },
  427. time: function time(name) {
  428. consoleTimer[name] = Date.now();
  429. },
  430. timeEnd: function timeEnd(name) {
  431. var time = consoleTimer[name];
  432. if (!time) {
  433. throw new Error('Unknown timer name ' + name);
  434. }
  435. this.log('Timer:', name, Date.now() - time);
  436. }
  437. };
  438. globalScope.console = workerConsole;
  439. })();
  440. (function checkConsoleCompatibility() {
  441. if (!hasDOM) {
  442. return;
  443. }
  444. if (!('console' in window)) {
  445. window.console = {
  446. log: function log() {},
  447. error: function error() {},
  448. warn: function warn() {}
  449. };
  450. return;
  451. }
  452. if (!('bind' in console.log)) {
  453. console.log = function (fn) {
  454. return function (msg) {
  455. return fn(msg);
  456. };
  457. }(console.log);
  458. console.error = function (fn) {
  459. return function (msg) {
  460. return fn(msg);
  461. };
  462. }(console.error);
  463. console.warn = function (fn) {
  464. return function (msg) {
  465. return fn(msg);
  466. };
  467. }(console.warn);
  468. return;
  469. }
  470. })();
  471. (function checkOnClickCompatibility() {
  472. function ignoreIfTargetDisabled(event) {
  473. if (isDisabled(event.target)) {
  474. event.stopPropagation();
  475. }
  476. }
  477. function isDisabled(node) {
  478. return node.disabled || node.parentNode && isDisabled(node.parentNode);
  479. }
  480. if (isOpera) {
  481. document.addEventListener('click', ignoreIfTargetDisabled, true);
  482. }
  483. })();
  484. (function checkOnBlobSupport() {
  485. if (isIE || isIOSChrome) {
  486. PDFJS.disableCreateObjectURL = true;
  487. }
  488. })();
  489. (function checkNavigatorLanguage() {
  490. if (typeof navigator === 'undefined') {
  491. return;
  492. }
  493. if ('language' in navigator) {
  494. return;
  495. }
  496. PDFJS.locale = navigator.userLanguage || 'en-US';
  497. })();
  498. (function checkRangeRequests() {
  499. if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
  500. PDFJS.disableRange = true;
  501. PDFJS.disableStream = true;
  502. }
  503. })();
  504. (function checkHistoryManipulation() {
  505. if (!hasDOM) {
  506. return;
  507. }
  508. if (!history.pushState || isAndroidPre3) {
  509. PDFJS.disableHistory = true;
  510. }
  511. })();
  512. (function checkSetPresenceInImageData() {
  513. if (!hasDOM) {
  514. return;
  515. }
  516. if (window.CanvasPixelArray) {
  517. if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
  518. window.CanvasPixelArray.prototype.set = function (arr) {
  519. for (var i = 0, ii = this.length; i < ii; i++) {
  520. this[i] = arr[i];
  521. }
  522. };
  523. }
  524. } else {
  525. var polyfill = false,
  526. versionMatch;
  527. if (isChrome) {
  528. versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  529. polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
  530. } else if (isAndroid) {
  531. polyfill = isAndroidPre5;
  532. } else if (isSafari) {
  533. versionMatch = userAgent.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
  534. polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
  535. }
  536. if (polyfill) {
  537. var contextPrototype = window.CanvasRenderingContext2D.prototype;
  538. var createImageData = contextPrototype.createImageData;
  539. contextPrototype.createImageData = function (w, h) {
  540. var imageData = createImageData.call(this, w, h);
  541. imageData.data.set = function (arr) {
  542. for (var i = 0, ii = this.length; i < ii; i++) {
  543. this[i] = arr[i];
  544. }
  545. };
  546. return imageData;
  547. };
  548. contextPrototype = null;
  549. }
  550. }
  551. })();
  552. (function checkRequestAnimationFrame() {
  553. function installFakeAnimationFrameFunctions() {
  554. window.requestAnimationFrame = function (callback) {
  555. return window.setTimeout(callback, 20);
  556. };
  557. window.cancelAnimationFrame = function (timeoutID) {
  558. window.clearTimeout(timeoutID);
  559. };
  560. }
  561. if (!hasDOM) {
  562. return;
  563. }
  564. if (isIOS) {
  565. installFakeAnimationFrameFunctions();
  566. return;
  567. }
  568. if ('requestAnimationFrame' in window) {
  569. return;
  570. }
  571. window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;
  572. if (window.requestAnimationFrame) {
  573. return;
  574. }
  575. installFakeAnimationFrameFunctions();
  576. })();
  577. (function checkCanvasSizeLimitation() {
  578. if (isIOS || isAndroid) {
  579. PDFJS.maxCanvasPixels = 5242880;
  580. }
  581. })();
  582. (function checkFullscreenSupport() {
  583. if (!hasDOM) {
  584. return;
  585. }
  586. if (isIE && window.parent !== window) {
  587. PDFJS.disableFullscreen = true;
  588. }
  589. })();
  590. (function checkCurrentScript() {
  591. if (!hasDOM) {
  592. return;
  593. }
  594. if ('currentScript' in document) {
  595. return;
  596. }
  597. Object.defineProperty(document, 'currentScript', {
  598. get: function get() {
  599. var scripts = document.getElementsByTagName('script');
  600. return scripts[scripts.length - 1];
  601. },
  602. enumerable: true,
  603. configurable: true
  604. });
  605. })();
  606. (function checkInputTypeNumberAssign() {
  607. if (!hasDOM) {
  608. return;
  609. }
  610. var el = document.createElement('input');
  611. try {
  612. el.type = 'number';
  613. } catch (ex) {
  614. var inputProto = el.constructor.prototype;
  615. var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
  616. Object.defineProperty(inputProto, 'type', {
  617. get: function get() {
  618. return typeProperty.get.call(this);
  619. },
  620. set: function set(value) {
  621. typeProperty.set.call(this, value === 'number' ? 'text' : value);
  622. },
  623. enumerable: true,
  624. configurable: true
  625. });
  626. }
  627. })();
  628. (function checkDocumentReadyState() {
  629. if (!hasDOM) {
  630. return;
  631. }
  632. if (!document.attachEvent) {
  633. return;
  634. }
  635. var documentProto = document.constructor.prototype;
  636. var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState');
  637. Object.defineProperty(documentProto, 'readyState', {
  638. get: function get() {
  639. var value = readyStateProto.get.call(this);
  640. return value === 'interactive' ? 'loading' : value;
  641. },
  642. set: function set(value) {
  643. readyStateProto.set.call(this, value);
  644. },
  645. enumerable: true,
  646. configurable: true
  647. });
  648. })();
  649. (function checkChildNodeRemove() {
  650. if (!hasDOM) {
  651. return;
  652. }
  653. if (typeof Element.prototype.remove !== 'undefined') {
  654. return;
  655. }
  656. Element.prototype.remove = function () {
  657. if (this.parentNode) {
  658. this.parentNode.removeChild(this);
  659. }
  660. };
  661. })();
  662. (function checkObjectValues() {
  663. if (Object.values) {
  664. return;
  665. }
  666. Object.values = require('core-js/fn/object/values');
  667. })();
  668. (function checkArrayIncludes() {
  669. if (Array.prototype.includes) {
  670. return;
  671. }
  672. Array.prototype.includes = require('core-js/fn/array/includes');
  673. })();
  674. (function checkNumberIsNaN() {
  675. if (Number.isNaN) {
  676. return;
  677. }
  678. Number.isNaN = require('core-js/fn/number/is-nan');
  679. })();
  680. (function checkNumberIsInteger() {
  681. if (Number.isInteger) {
  682. return;
  683. }
  684. Number.isInteger = require('core-js/fn/number/is-integer');
  685. })();
  686. (function checkPromise() {
  687. if (globalScope.Promise) {
  688. return;
  689. }
  690. globalScope.Promise = require('core-js/fn/promise');
  691. })();
  692. (function checkWeakMap() {
  693. if (globalScope.WeakMap) {
  694. return;
  695. }
  696. globalScope.WeakMap = require('core-js/fn/weak-map');
  697. })();
  698. (function checkURLConstructor() {
  699. var hasWorkingUrl = false;
  700. try {
  701. if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
  702. var u = new URL('b', 'http://a');
  703. u.pathname = 'c%20d';
  704. hasWorkingUrl = u.href === 'http://a/c%20d';
  705. }
  706. } catch (e) {}
  707. if (hasWorkingUrl) {
  708. return;
  709. }
  710. var relative = Object.create(null);
  711. relative['ftp'] = 21;
  712. relative['file'] = 0;
  713. relative['gopher'] = 70;
  714. relative['http'] = 80;
  715. relative['https'] = 443;
  716. relative['ws'] = 80;
  717. relative['wss'] = 443;
  718. var relativePathDotMapping = Object.create(null);
  719. relativePathDotMapping['%2e'] = '.';
  720. relativePathDotMapping['.%2e'] = '..';
  721. relativePathDotMapping['%2e.'] = '..';
  722. relativePathDotMapping['%2e%2e'] = '..';
  723. function isRelativeScheme(scheme) {
  724. return relative[scheme] !== undefined;
  725. }
  726. function invalid() {
  727. clear.call(this);
  728. this._isInvalid = true;
  729. }
  730. function IDNAToASCII(h) {
  731. if (h === '') {
  732. invalid.call(this);
  733. }
  734. return h.toLowerCase();
  735. }
  736. function percentEscape(c) {
  737. var unicode = c.charCodeAt(0);
  738. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  739. return c;
  740. }
  741. return encodeURIComponent(c);
  742. }
  743. function percentEscapeQuery(c) {
  744. var unicode = c.charCodeAt(0);
  745. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  746. return c;
  747. }
  748. return encodeURIComponent(c);
  749. }
  750. var EOF,
  751. ALPHA = /[a-zA-Z]/,
  752. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  753. function parse(input, stateOverride, base) {
  754. function err(message) {
  755. errors.push(message);
  756. }
  757. var state = stateOverride || 'scheme start',
  758. cursor = 0,
  759. buffer = '',
  760. seenAt = false,
  761. seenBracket = false,
  762. errors = [];
  763. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  764. var c = input[cursor];
  765. switch (state) {
  766. case 'scheme start':
  767. if (c && ALPHA.test(c)) {
  768. buffer += c.toLowerCase();
  769. state = 'scheme';
  770. } else if (!stateOverride) {
  771. buffer = '';
  772. state = 'no scheme';
  773. continue;
  774. } else {
  775. err('Invalid scheme.');
  776. break loop;
  777. }
  778. break;
  779. case 'scheme':
  780. if (c && ALPHANUMERIC.test(c)) {
  781. buffer += c.toLowerCase();
  782. } else if (c === ':') {
  783. this._scheme = buffer;
  784. buffer = '';
  785. if (stateOverride) {
  786. break loop;
  787. }
  788. if (isRelativeScheme(this._scheme)) {
  789. this._isRelative = true;
  790. }
  791. if (this._scheme === 'file') {
  792. state = 'relative';
  793. } else if (this._isRelative && base && base._scheme === this._scheme) {
  794. state = 'relative or authority';
  795. } else if (this._isRelative) {
  796. state = 'authority first slash';
  797. } else {
  798. state = 'scheme data';
  799. }
  800. } else if (!stateOverride) {
  801. buffer = '';
  802. cursor = 0;
  803. state = 'no scheme';
  804. continue;
  805. } else if (c === EOF) {
  806. break loop;
  807. } else {
  808. err('Code point not allowed in scheme: ' + c);
  809. break loop;
  810. }
  811. break;
  812. case 'scheme data':
  813. if (c === '?') {
  814. this._query = '?';
  815. state = 'query';
  816. } else if (c === '#') {
  817. this._fragment = '#';
  818. state = 'fragment';
  819. } else {
  820. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  821. this._schemeData += percentEscape(c);
  822. }
  823. }
  824. break;
  825. case 'no scheme':
  826. if (!base || !isRelativeScheme(base._scheme)) {
  827. err('Missing scheme.');
  828. invalid.call(this);
  829. } else {
  830. state = 'relative';
  831. continue;
  832. }
  833. break;
  834. case 'relative or authority':
  835. if (c === '/' && input[cursor + 1] === '/') {
  836. state = 'authority ignore slashes';
  837. } else {
  838. err('Expected /, got: ' + c);
  839. state = 'relative';
  840. continue;
  841. }
  842. break;
  843. case 'relative':
  844. this._isRelative = true;
  845. if (this._scheme !== 'file') {
  846. this._scheme = base._scheme;
  847. }
  848. if (c === EOF) {
  849. this._host = base._host;
  850. this._port = base._port;
  851. this._path = base._path.slice();
  852. this._query = base._query;
  853. this._username = base._username;
  854. this._password = base._password;
  855. break loop;
  856. } else if (c === '/' || c === '\\') {
  857. if (c === '\\') {
  858. err('\\ is an invalid code point.');
  859. }
  860. state = 'relative slash';
  861. } else if (c === '?') {
  862. this._host = base._host;
  863. this._port = base._port;
  864. this._path = base._path.slice();
  865. this._query = '?';
  866. this._username = base._username;
  867. this._password = base._password;
  868. state = 'query';
  869. } else if (c === '#') {
  870. this._host = base._host;
  871. this._port = base._port;
  872. this._path = base._path.slice();
  873. this._query = base._query;
  874. this._fragment = '#';
  875. this._username = base._username;
  876. this._password = base._password;
  877. state = 'fragment';
  878. } else {
  879. var nextC = input[cursor + 1];
  880. var nextNextC = input[cursor + 2];
  881. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  882. this._host = base._host;
  883. this._port = base._port;
  884. this._username = base._username;
  885. this._password = base._password;
  886. this._path = base._path.slice();
  887. this._path.pop();
  888. }
  889. state = 'relative path';
  890. continue;
  891. }
  892. break;
  893. case 'relative slash':
  894. if (c === '/' || c === '\\') {
  895. if (c === '\\') {
  896. err('\\ is an invalid code point.');
  897. }
  898. if (this._scheme === 'file') {
  899. state = 'file host';
  900. } else {
  901. state = 'authority ignore slashes';
  902. }
  903. } else {
  904. if (this._scheme !== 'file') {
  905. this._host = base._host;
  906. this._port = base._port;
  907. this._username = base._username;
  908. this._password = base._password;
  909. }
  910. state = 'relative path';
  911. continue;
  912. }
  913. break;
  914. case 'authority first slash':
  915. if (c === '/') {
  916. state = 'authority second slash';
  917. } else {
  918. err('Expected \'/\', got: ' + c);
  919. state = 'authority ignore slashes';
  920. continue;
  921. }
  922. break;
  923. case 'authority second slash':
  924. state = 'authority ignore slashes';
  925. if (c !== '/') {
  926. err('Expected \'/\', got: ' + c);
  927. continue;
  928. }
  929. break;
  930. case 'authority ignore slashes':
  931. if (c !== '/' && c !== '\\') {
  932. state = 'authority';
  933. continue;
  934. } else {
  935. err('Expected authority, got: ' + c);
  936. }
  937. break;
  938. case 'authority':
  939. if (c === '@') {
  940. if (seenAt) {
  941. err('@ already seen.');
  942. buffer += '%40';
  943. }
  944. seenAt = true;
  945. for (var i = 0; i < buffer.length; i++) {
  946. var cp = buffer[i];
  947. if (cp === '\t' || cp === '\n' || cp === '\r') {
  948. err('Invalid whitespace in authority.');
  949. continue;
  950. }
  951. if (cp === ':' && this._password === null) {
  952. this._password = '';
  953. continue;
  954. }
  955. var tempC = percentEscape(cp);
  956. if (this._password !== null) {
  957. this._password += tempC;
  958. } else {
  959. this._username += tempC;
  960. }
  961. }
  962. buffer = '';
  963. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  964. cursor -= buffer.length;
  965. buffer = '';
  966. state = 'host';
  967. continue;
  968. } else {
  969. buffer += c;
  970. }
  971. break;
  972. case 'file host':
  973. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  974. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  975. state = 'relative path';
  976. } else if (buffer.length === 0) {
  977. state = 'relative path start';
  978. } else {
  979. this._host = IDNAToASCII.call(this, buffer);
  980. buffer = '';
  981. state = 'relative path start';
  982. }
  983. continue;
  984. } else if (c === '\t' || c === '\n' || c === '\r') {
  985. err('Invalid whitespace in file host.');
  986. } else {
  987. buffer += c;
  988. }
  989. break;
  990. case 'host':
  991. case 'hostname':
  992. if (c === ':' && !seenBracket) {
  993. this._host = IDNAToASCII.call(this, buffer);
  994. buffer = '';
  995. state = 'port';
  996. if (stateOverride === 'hostname') {
  997. break loop;
  998. }
  999. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1000. this._host = IDNAToASCII.call(this, buffer);
  1001. buffer = '';
  1002. state = 'relative path start';
  1003. if (stateOverride) {
  1004. break loop;
  1005. }
  1006. continue;
  1007. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1008. if (c === '[') {
  1009. seenBracket = true;
  1010. } else if (c === ']') {
  1011. seenBracket = false;
  1012. }
  1013. buffer += c;
  1014. } else {
  1015. err('Invalid code point in host/hostname: ' + c);
  1016. }
  1017. break;
  1018. case 'port':
  1019. if (/[0-9]/.test(c)) {
  1020. buffer += c;
  1021. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1022. if (buffer !== '') {
  1023. var temp = parseInt(buffer, 10);
  1024. if (temp !== relative[this._scheme]) {
  1025. this._port = temp + '';
  1026. }
  1027. buffer = '';
  1028. }
  1029. if (stateOverride) {
  1030. break loop;
  1031. }
  1032. state = 'relative path start';
  1033. continue;
  1034. } else if (c === '\t' || c === '\n' || c === '\r') {
  1035. err('Invalid code point in port: ' + c);
  1036. } else {
  1037. invalid.call(this);
  1038. }
  1039. break;
  1040. case 'relative path start':
  1041. if (c === '\\') {
  1042. err('\'\\\' not allowed in path.');
  1043. }
  1044. state = 'relative path';
  1045. if (c !== '/' && c !== '\\') {
  1046. continue;
  1047. }
  1048. break;
  1049. case 'relative path':
  1050. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1051. if (c === '\\') {
  1052. err('\\ not allowed in relative path.');
  1053. }
  1054. var tmp;
  1055. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1056. buffer = tmp;
  1057. }
  1058. if (buffer === '..') {
  1059. this._path.pop();
  1060. if (c !== '/' && c !== '\\') {
  1061. this._path.push('');
  1062. }
  1063. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  1064. this._path.push('');
  1065. } else if (buffer !== '.') {
  1066. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1067. buffer = buffer[0] + ':';
  1068. }
  1069. this._path.push(buffer);
  1070. }
  1071. buffer = '';
  1072. if (c === '?') {
  1073. this._query = '?';
  1074. state = 'query';
  1075. } else if (c === '#') {
  1076. this._fragment = '#';
  1077. state = 'fragment';
  1078. }
  1079. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1080. buffer += percentEscape(c);
  1081. }
  1082. break;
  1083. case 'query':
  1084. if (!stateOverride && c === '#') {
  1085. this._fragment = '#';
  1086. state = 'fragment';
  1087. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1088. this._query += percentEscapeQuery(c);
  1089. }
  1090. break;
  1091. case 'fragment':
  1092. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1093. this._fragment += c;
  1094. }
  1095. break;
  1096. }
  1097. cursor++;
  1098. }
  1099. }
  1100. function clear() {
  1101. this._scheme = '';
  1102. this._schemeData = '';
  1103. this._username = '';
  1104. this._password = null;
  1105. this._host = '';
  1106. this._port = '';
  1107. this._path = [];
  1108. this._query = '';
  1109. this._fragment = '';
  1110. this._isInvalid = false;
  1111. this._isRelative = false;
  1112. }
  1113. function JURL(url, base) {
  1114. if (base !== undefined && !(base instanceof JURL)) {
  1115. base = new JURL(String(base));
  1116. }
  1117. this._url = url;
  1118. clear.call(this);
  1119. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1120. parse.call(this, input, null, base);
  1121. }
  1122. JURL.prototype = {
  1123. toString: function toString() {
  1124. return this.href;
  1125. },
  1126. get href() {
  1127. if (this._isInvalid) {
  1128. return this._url;
  1129. }
  1130. var authority = '';
  1131. if (this._username !== '' || this._password !== null) {
  1132. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  1133. }
  1134. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1135. },
  1136. set href(value) {
  1137. clear.call(this);
  1138. parse.call(this, value);
  1139. },
  1140. get protocol() {
  1141. return this._scheme + ':';
  1142. },
  1143. set protocol(value) {
  1144. if (this._isInvalid) {
  1145. return;
  1146. }
  1147. parse.call(this, value + ':', 'scheme start');
  1148. },
  1149. get host() {
  1150. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1151. },
  1152. set host(value) {
  1153. if (this._isInvalid || !this._isRelative) {
  1154. return;
  1155. }
  1156. parse.call(this, value, 'host');
  1157. },
  1158. get hostname() {
  1159. return this._host;
  1160. },
  1161. set hostname(value) {
  1162. if (this._isInvalid || !this._isRelative) {
  1163. return;
  1164. }
  1165. parse.call(this, value, 'hostname');
  1166. },
  1167. get port() {
  1168. return this._port;
  1169. },
  1170. set port(value) {
  1171. if (this._isInvalid || !this._isRelative) {
  1172. return;
  1173. }
  1174. parse.call(this, value, 'port');
  1175. },
  1176. get pathname() {
  1177. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1178. },
  1179. set pathname(value) {
  1180. if (this._isInvalid || !this._isRelative) {
  1181. return;
  1182. }
  1183. this._path = [];
  1184. parse.call(this, value, 'relative path start');
  1185. },
  1186. get search() {
  1187. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1188. },
  1189. set search(value) {
  1190. if (this._isInvalid || !this._isRelative) {
  1191. return;
  1192. }
  1193. this._query = '?';
  1194. if (value[0] === '?') {
  1195. value = value.slice(1);
  1196. }
  1197. parse.call(this, value, 'query');
  1198. },
  1199. get hash() {
  1200. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1201. },
  1202. set hash(value) {
  1203. if (this._isInvalid) {
  1204. return;
  1205. }
  1206. this._fragment = '#';
  1207. if (value[0] === '#') {
  1208. value = value.slice(1);
  1209. }
  1210. parse.call(this, value, 'fragment');
  1211. },
  1212. get origin() {
  1213. var host;
  1214. if (this._isInvalid || !this._scheme) {
  1215. return '';
  1216. }
  1217. switch (this._scheme) {
  1218. case 'data':
  1219. case 'file':
  1220. case 'javascript':
  1221. case 'mailto':
  1222. return 'null';
  1223. case 'blob':
  1224. try {
  1225. return new JURL(this._schemeData).origin || 'null';
  1226. } catch (_) {}
  1227. return 'null';
  1228. }
  1229. host = this.host;
  1230. if (!host) {
  1231. return '';
  1232. }
  1233. return this._scheme + '://' + host;
  1234. }
  1235. };
  1236. var OriginalURL = globalScope.URL;
  1237. if (OriginalURL) {
  1238. JURL.createObjectURL = function (blob) {
  1239. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1240. };
  1241. JURL.revokeObjectURL = function (url) {
  1242. OriginalURL.revokeObjectURL(url);
  1243. };
  1244. }
  1245. globalScope.URL = JURL;
  1246. })();
  1247. }