compatibility.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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 checkNumberIsNaN() {
  663. if (Number.isNaN) {
  664. return;
  665. }
  666. Number.isNaN = require('core-js/fn/number/is-nan');
  667. })();
  668. (function checkNumberIsInteger() {
  669. if (Number.isInteger) {
  670. return;
  671. }
  672. Number.isInteger = require('core-js/fn/number/is-integer');
  673. })();
  674. (function checkPromise() {
  675. if (globalScope.Promise) {
  676. return;
  677. }
  678. globalScope.Promise = require('core-js/fn/promise');
  679. })();
  680. (function checkWeakMap() {
  681. if (globalScope.WeakMap) {
  682. return;
  683. }
  684. globalScope.WeakMap = require('core-js/fn/weak-map');
  685. })();
  686. (function checkURLConstructor() {
  687. var hasWorkingUrl = false;
  688. try {
  689. if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
  690. var u = new URL('b', 'http://a');
  691. u.pathname = 'c%20d';
  692. hasWorkingUrl = u.href === 'http://a/c%20d';
  693. }
  694. } catch (e) {}
  695. if (hasWorkingUrl) {
  696. return;
  697. }
  698. var relative = Object.create(null);
  699. relative['ftp'] = 21;
  700. relative['file'] = 0;
  701. relative['gopher'] = 70;
  702. relative['http'] = 80;
  703. relative['https'] = 443;
  704. relative['ws'] = 80;
  705. relative['wss'] = 443;
  706. var relativePathDotMapping = Object.create(null);
  707. relativePathDotMapping['%2e'] = '.';
  708. relativePathDotMapping['.%2e'] = '..';
  709. relativePathDotMapping['%2e.'] = '..';
  710. relativePathDotMapping['%2e%2e'] = '..';
  711. function isRelativeScheme(scheme) {
  712. return relative[scheme] !== undefined;
  713. }
  714. function invalid() {
  715. clear.call(this);
  716. this._isInvalid = true;
  717. }
  718. function IDNAToASCII(h) {
  719. if (h === '') {
  720. invalid.call(this);
  721. }
  722. return h.toLowerCase();
  723. }
  724. function percentEscape(c) {
  725. var unicode = c.charCodeAt(0);
  726. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  727. return c;
  728. }
  729. return encodeURIComponent(c);
  730. }
  731. function percentEscapeQuery(c) {
  732. var unicode = c.charCodeAt(0);
  733. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  734. return c;
  735. }
  736. return encodeURIComponent(c);
  737. }
  738. var EOF,
  739. ALPHA = /[a-zA-Z]/,
  740. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  741. function parse(input, stateOverride, base) {
  742. function err(message) {
  743. errors.push(message);
  744. }
  745. var state = stateOverride || 'scheme start',
  746. cursor = 0,
  747. buffer = '',
  748. seenAt = false,
  749. seenBracket = false,
  750. errors = [];
  751. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  752. var c = input[cursor];
  753. switch (state) {
  754. case 'scheme start':
  755. if (c && ALPHA.test(c)) {
  756. buffer += c.toLowerCase();
  757. state = 'scheme';
  758. } else if (!stateOverride) {
  759. buffer = '';
  760. state = 'no scheme';
  761. continue;
  762. } else {
  763. err('Invalid scheme.');
  764. break loop;
  765. }
  766. break;
  767. case 'scheme':
  768. if (c && ALPHANUMERIC.test(c)) {
  769. buffer += c.toLowerCase();
  770. } else if (c === ':') {
  771. this._scheme = buffer;
  772. buffer = '';
  773. if (stateOverride) {
  774. break loop;
  775. }
  776. if (isRelativeScheme(this._scheme)) {
  777. this._isRelative = true;
  778. }
  779. if (this._scheme === 'file') {
  780. state = 'relative';
  781. } else if (this._isRelative && base && base._scheme === this._scheme) {
  782. state = 'relative or authority';
  783. } else if (this._isRelative) {
  784. state = 'authority first slash';
  785. } else {
  786. state = 'scheme data';
  787. }
  788. } else if (!stateOverride) {
  789. buffer = '';
  790. cursor = 0;
  791. state = 'no scheme';
  792. continue;
  793. } else if (c === EOF) {
  794. break loop;
  795. } else {
  796. err('Code point not allowed in scheme: ' + c);
  797. break loop;
  798. }
  799. break;
  800. case 'scheme data':
  801. if (c === '?') {
  802. this._query = '?';
  803. state = 'query';
  804. } else if (c === '#') {
  805. this._fragment = '#';
  806. state = 'fragment';
  807. } else {
  808. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  809. this._schemeData += percentEscape(c);
  810. }
  811. }
  812. break;
  813. case 'no scheme':
  814. if (!base || !isRelativeScheme(base._scheme)) {
  815. err('Missing scheme.');
  816. invalid.call(this);
  817. } else {
  818. state = 'relative';
  819. continue;
  820. }
  821. break;
  822. case 'relative or authority':
  823. if (c === '/' && input[cursor + 1] === '/') {
  824. state = 'authority ignore slashes';
  825. } else {
  826. err('Expected /, got: ' + c);
  827. state = 'relative';
  828. continue;
  829. }
  830. break;
  831. case 'relative':
  832. this._isRelative = true;
  833. if (this._scheme !== 'file') {
  834. this._scheme = base._scheme;
  835. }
  836. if (c === EOF) {
  837. this._host = base._host;
  838. this._port = base._port;
  839. this._path = base._path.slice();
  840. this._query = base._query;
  841. this._username = base._username;
  842. this._password = base._password;
  843. break loop;
  844. } else if (c === '/' || c === '\\') {
  845. if (c === '\\') {
  846. err('\\ is an invalid code point.');
  847. }
  848. state = 'relative slash';
  849. } else if (c === '?') {
  850. this._host = base._host;
  851. this._port = base._port;
  852. this._path = base._path.slice();
  853. this._query = '?';
  854. this._username = base._username;
  855. this._password = base._password;
  856. state = 'query';
  857. } else if (c === '#') {
  858. this._host = base._host;
  859. this._port = base._port;
  860. this._path = base._path.slice();
  861. this._query = base._query;
  862. this._fragment = '#';
  863. this._username = base._username;
  864. this._password = base._password;
  865. state = 'fragment';
  866. } else {
  867. var nextC = input[cursor + 1];
  868. var nextNextC = input[cursor + 2];
  869. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  870. this._host = base._host;
  871. this._port = base._port;
  872. this._username = base._username;
  873. this._password = base._password;
  874. this._path = base._path.slice();
  875. this._path.pop();
  876. }
  877. state = 'relative path';
  878. continue;
  879. }
  880. break;
  881. case 'relative slash':
  882. if (c === '/' || c === '\\') {
  883. if (c === '\\') {
  884. err('\\ is an invalid code point.');
  885. }
  886. if (this._scheme === 'file') {
  887. state = 'file host';
  888. } else {
  889. state = 'authority ignore slashes';
  890. }
  891. } else {
  892. if (this._scheme !== 'file') {
  893. this._host = base._host;
  894. this._port = base._port;
  895. this._username = base._username;
  896. this._password = base._password;
  897. }
  898. state = 'relative path';
  899. continue;
  900. }
  901. break;
  902. case 'authority first slash':
  903. if (c === '/') {
  904. state = 'authority second slash';
  905. } else {
  906. err('Expected \'/\', got: ' + c);
  907. state = 'authority ignore slashes';
  908. continue;
  909. }
  910. break;
  911. case 'authority second slash':
  912. state = 'authority ignore slashes';
  913. if (c !== '/') {
  914. err('Expected \'/\', got: ' + c);
  915. continue;
  916. }
  917. break;
  918. case 'authority ignore slashes':
  919. if (c !== '/' && c !== '\\') {
  920. state = 'authority';
  921. continue;
  922. } else {
  923. err('Expected authority, got: ' + c);
  924. }
  925. break;
  926. case 'authority':
  927. if (c === '@') {
  928. if (seenAt) {
  929. err('@ already seen.');
  930. buffer += '%40';
  931. }
  932. seenAt = true;
  933. for (var i = 0; i < buffer.length; i++) {
  934. var cp = buffer[i];
  935. if (cp === '\t' || cp === '\n' || cp === '\r') {
  936. err('Invalid whitespace in authority.');
  937. continue;
  938. }
  939. if (cp === ':' && this._password === null) {
  940. this._password = '';
  941. continue;
  942. }
  943. var tempC = percentEscape(cp);
  944. if (this._password !== null) {
  945. this._password += tempC;
  946. } else {
  947. this._username += tempC;
  948. }
  949. }
  950. buffer = '';
  951. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  952. cursor -= buffer.length;
  953. buffer = '';
  954. state = 'host';
  955. continue;
  956. } else {
  957. buffer += c;
  958. }
  959. break;
  960. case 'file host':
  961. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  962. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  963. state = 'relative path';
  964. } else if (buffer.length === 0) {
  965. state = 'relative path start';
  966. } else {
  967. this._host = IDNAToASCII.call(this, buffer);
  968. buffer = '';
  969. state = 'relative path start';
  970. }
  971. continue;
  972. } else if (c === '\t' || c === '\n' || c === '\r') {
  973. err('Invalid whitespace in file host.');
  974. } else {
  975. buffer += c;
  976. }
  977. break;
  978. case 'host':
  979. case 'hostname':
  980. if (c === ':' && !seenBracket) {
  981. this._host = IDNAToASCII.call(this, buffer);
  982. buffer = '';
  983. state = 'port';
  984. if (stateOverride === 'hostname') {
  985. break loop;
  986. }
  987. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  988. this._host = IDNAToASCII.call(this, buffer);
  989. buffer = '';
  990. state = 'relative path start';
  991. if (stateOverride) {
  992. break loop;
  993. }
  994. continue;
  995. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  996. if (c === '[') {
  997. seenBracket = true;
  998. } else if (c === ']') {
  999. seenBracket = false;
  1000. }
  1001. buffer += c;
  1002. } else {
  1003. err('Invalid code point in host/hostname: ' + c);
  1004. }
  1005. break;
  1006. case 'port':
  1007. if (/[0-9]/.test(c)) {
  1008. buffer += c;
  1009. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1010. if (buffer !== '') {
  1011. var temp = parseInt(buffer, 10);
  1012. if (temp !== relative[this._scheme]) {
  1013. this._port = temp + '';
  1014. }
  1015. buffer = '';
  1016. }
  1017. if (stateOverride) {
  1018. break loop;
  1019. }
  1020. state = 'relative path start';
  1021. continue;
  1022. } else if (c === '\t' || c === '\n' || c === '\r') {
  1023. err('Invalid code point in port: ' + c);
  1024. } else {
  1025. invalid.call(this);
  1026. }
  1027. break;
  1028. case 'relative path start':
  1029. if (c === '\\') {
  1030. err('\'\\\' not allowed in path.');
  1031. }
  1032. state = 'relative path';
  1033. if (c !== '/' && c !== '\\') {
  1034. continue;
  1035. }
  1036. break;
  1037. case 'relative path':
  1038. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1039. if (c === '\\') {
  1040. err('\\ not allowed in relative path.');
  1041. }
  1042. var tmp;
  1043. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1044. buffer = tmp;
  1045. }
  1046. if (buffer === '..') {
  1047. this._path.pop();
  1048. if (c !== '/' && c !== '\\') {
  1049. this._path.push('');
  1050. }
  1051. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  1052. this._path.push('');
  1053. } else if (buffer !== '.') {
  1054. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1055. buffer = buffer[0] + ':';
  1056. }
  1057. this._path.push(buffer);
  1058. }
  1059. buffer = '';
  1060. if (c === '?') {
  1061. this._query = '?';
  1062. state = 'query';
  1063. } else if (c === '#') {
  1064. this._fragment = '#';
  1065. state = 'fragment';
  1066. }
  1067. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1068. buffer += percentEscape(c);
  1069. }
  1070. break;
  1071. case 'query':
  1072. if (!stateOverride && c === '#') {
  1073. this._fragment = '#';
  1074. state = 'fragment';
  1075. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1076. this._query += percentEscapeQuery(c);
  1077. }
  1078. break;
  1079. case 'fragment':
  1080. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1081. this._fragment += c;
  1082. }
  1083. break;
  1084. }
  1085. cursor++;
  1086. }
  1087. }
  1088. function clear() {
  1089. this._scheme = '';
  1090. this._schemeData = '';
  1091. this._username = '';
  1092. this._password = null;
  1093. this._host = '';
  1094. this._port = '';
  1095. this._path = [];
  1096. this._query = '';
  1097. this._fragment = '';
  1098. this._isInvalid = false;
  1099. this._isRelative = false;
  1100. }
  1101. function JURL(url, base) {
  1102. if (base !== undefined && !(base instanceof JURL)) {
  1103. base = new JURL(String(base));
  1104. }
  1105. this._url = url;
  1106. clear.call(this);
  1107. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1108. parse.call(this, input, null, base);
  1109. }
  1110. JURL.prototype = {
  1111. toString: function toString() {
  1112. return this.href;
  1113. },
  1114. get href() {
  1115. if (this._isInvalid) {
  1116. return this._url;
  1117. }
  1118. var authority = '';
  1119. if (this._username !== '' || this._password !== null) {
  1120. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  1121. }
  1122. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1123. },
  1124. set href(value) {
  1125. clear.call(this);
  1126. parse.call(this, value);
  1127. },
  1128. get protocol() {
  1129. return this._scheme + ':';
  1130. },
  1131. set protocol(value) {
  1132. if (this._isInvalid) {
  1133. return;
  1134. }
  1135. parse.call(this, value + ':', 'scheme start');
  1136. },
  1137. get host() {
  1138. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1139. },
  1140. set host(value) {
  1141. if (this._isInvalid || !this._isRelative) {
  1142. return;
  1143. }
  1144. parse.call(this, value, 'host');
  1145. },
  1146. get hostname() {
  1147. return this._host;
  1148. },
  1149. set hostname(value) {
  1150. if (this._isInvalid || !this._isRelative) {
  1151. return;
  1152. }
  1153. parse.call(this, value, 'hostname');
  1154. },
  1155. get port() {
  1156. return this._port;
  1157. },
  1158. set port(value) {
  1159. if (this._isInvalid || !this._isRelative) {
  1160. return;
  1161. }
  1162. parse.call(this, value, 'port');
  1163. },
  1164. get pathname() {
  1165. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1166. },
  1167. set pathname(value) {
  1168. if (this._isInvalid || !this._isRelative) {
  1169. return;
  1170. }
  1171. this._path = [];
  1172. parse.call(this, value, 'relative path start');
  1173. },
  1174. get search() {
  1175. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1176. },
  1177. set search(value) {
  1178. if (this._isInvalid || !this._isRelative) {
  1179. return;
  1180. }
  1181. this._query = '?';
  1182. if (value[0] === '?') {
  1183. value = value.slice(1);
  1184. }
  1185. parse.call(this, value, 'query');
  1186. },
  1187. get hash() {
  1188. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1189. },
  1190. set hash(value) {
  1191. if (this._isInvalid) {
  1192. return;
  1193. }
  1194. this._fragment = '#';
  1195. if (value[0] === '#') {
  1196. value = value.slice(1);
  1197. }
  1198. parse.call(this, value, 'fragment');
  1199. },
  1200. get origin() {
  1201. var host;
  1202. if (this._isInvalid || !this._scheme) {
  1203. return '';
  1204. }
  1205. switch (this._scheme) {
  1206. case 'data':
  1207. case 'file':
  1208. case 'javascript':
  1209. case 'mailto':
  1210. return 'null';
  1211. case 'blob':
  1212. try {
  1213. return new JURL(this._schemeData).origin || 'null';
  1214. } catch (_) {}
  1215. return 'null';
  1216. }
  1217. host = this.host;
  1218. if (!host) {
  1219. return '';
  1220. }
  1221. return this._scheme + '://' + host;
  1222. }
  1223. };
  1224. var OriginalURL = globalScope.URL;
  1225. if (OriginalURL) {
  1226. JURL.createObjectURL = function (blob) {
  1227. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1228. };
  1229. JURL.revokeObjectURL = function (url) {
  1230. OriginalURL.revokeObjectURL(url);
  1231. };
  1232. }
  1233. globalScope.URL = JURL;
  1234. })();
  1235. }