compatibility.js 39 KB

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