compatibility.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  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. (function webpackUniversalModuleDefinition(root, factory) {
  16. if(typeof exports === 'object' && typeof module === 'object')
  17. module.exports = factory();
  18. else if(typeof define === 'function' && define.amd)
  19. define("pdfjs-dist/web/compatibility", [], factory);
  20. else if(typeof exports === 'object')
  21. exports["pdfjs-dist/web/compatibility"] = factory();
  22. else
  23. root["pdfjs-dist/web/compatibility"] = factory();
  24. })(this, function() {
  25. return /******/ (function(modules) { // webpackBootstrap
  26. /******/ // The module cache
  27. /******/ var installedModules = {};
  28. /******/
  29. /******/ // The require function
  30. /******/ function __webpack_require__(moduleId) {
  31. /******/
  32. /******/ // Check if module is in cache
  33. /******/ if(installedModules[moduleId]) {
  34. /******/ return installedModules[moduleId].exports;
  35. /******/ }
  36. /******/ // Create a new module (and put it into the cache)
  37. /******/ var module = installedModules[moduleId] = {
  38. /******/ i: moduleId,
  39. /******/ l: false,
  40. /******/ exports: {}
  41. /******/ };
  42. /******/
  43. /******/ // Execute the module function
  44. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  45. /******/
  46. /******/ // Flag the module as loaded
  47. /******/ module.l = true;
  48. /******/
  49. /******/ // Return the exports of the module
  50. /******/ return module.exports;
  51. /******/ }
  52. /******/
  53. /******/
  54. /******/ // expose the modules object (__webpack_modules__)
  55. /******/ __webpack_require__.m = modules;
  56. /******/
  57. /******/ // expose the module cache
  58. /******/ __webpack_require__.c = installedModules;
  59. /******/
  60. /******/ // identity function for calling harmony imports with the correct context
  61. /******/ __webpack_require__.i = function(value) { return value; };
  62. /******/
  63. /******/ // define getter function for harmony exports
  64. /******/ __webpack_require__.d = function(exports, name, getter) {
  65. /******/ if(!__webpack_require__.o(exports, name)) {
  66. /******/ Object.defineProperty(exports, name, {
  67. /******/ configurable: false,
  68. /******/ enumerable: true,
  69. /******/ get: getter
  70. /******/ });
  71. /******/ }
  72. /******/ };
  73. /******/
  74. /******/ // getDefaultExport function for compatibility with non-harmony modules
  75. /******/ __webpack_require__.n = function(module) {
  76. /******/ var getter = module && module.__esModule ?
  77. /******/ function getDefault() { return module['default']; } :
  78. /******/ function getModuleExports() { return module; };
  79. /******/ __webpack_require__.d(getter, 'a', getter);
  80. /******/ return getter;
  81. /******/ };
  82. /******/
  83. /******/ // Object.prototype.hasOwnProperty.call
  84. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  85. /******/
  86. /******/ // __webpack_public_path__
  87. /******/ __webpack_require__.p = "";
  88. /******/
  89. /******/ // Load entry module and return exports
  90. /******/ return __webpack_require__(__webpack_require__.s = 2);
  91. /******/ })
  92. /************************************************************************/
  93. /******/ ([
  94. /* 0 */
  95. /***/ (function(module, exports, __webpack_require__) {
  96. "use strict";
  97. /* WEBPACK VAR INJECTION */(function(global) {
  98. 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; };
  99. if (typeof PDFJS === 'undefined' || !PDFJS.compatibilityChecked) {
  100. var globalScope = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : undefined;
  101. var userAgent = typeof navigator !== 'undefined' && navigator.userAgent || '';
  102. var isAndroid = /Android/.test(userAgent);
  103. var isAndroidPre3 = /Android\s[0-2][^\d]/.test(userAgent);
  104. var isAndroidPre5 = /Android\s[0-4][^\d]/.test(userAgent);
  105. var isChrome = userAgent.indexOf('Chrom') >= 0;
  106. var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(userAgent);
  107. var isIOSChrome = userAgent.indexOf('CriOS') >= 0;
  108. var isIE = userAgent.indexOf('Trident') >= 0;
  109. var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent);
  110. var isOpera = userAgent.indexOf('Opera') >= 0;
  111. var isSafari = /Safari\//.test(userAgent) && !/(Chrome\/|Android\s)/.test(userAgent);
  112. var hasDOM = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && (typeof document === 'undefined' ? 'undefined' : _typeof(document)) === 'object';
  113. if (typeof PDFJS === 'undefined') {
  114. globalScope.PDFJS = {};
  115. }
  116. PDFJS.compatibilityChecked = true;
  117. (function checkTypedArrayCompatibility() {
  118. if (typeof Uint8Array !== 'undefined') {
  119. if (typeof Uint8Array.prototype.subarray === 'undefined') {
  120. Uint8Array.prototype.subarray = function subarray(start, end) {
  121. return new Uint8Array(this.slice(start, end));
  122. };
  123. Float32Array.prototype.subarray = function subarray(start, end) {
  124. return new Float32Array(this.slice(start, end));
  125. };
  126. }
  127. if (typeof Float64Array === 'undefined') {
  128. globalScope.Float64Array = Float32Array;
  129. }
  130. return;
  131. }
  132. function subarray(start, end) {
  133. return new TypedArray(this.slice(start, end));
  134. }
  135. function setArrayOffset(array, offset) {
  136. if (arguments.length < 2) {
  137. offset = 0;
  138. }
  139. for (var i = 0, n = array.length; i < n; ++i, ++offset) {
  140. this[offset] = array[i] & 0xFF;
  141. }
  142. }
  143. function Uint32ArrayView(buffer, length) {
  144. this.buffer = buffer;
  145. this.byteLength = buffer.length;
  146. this.length = length;
  147. ensureUint32ArrayViewProps(this.length);
  148. }
  149. Uint32ArrayView.prototype = Object.create(null);
  150. var uint32ArrayViewSetters = 0;
  151. function createUint32ArrayProp(index) {
  152. return {
  153. get: function get() {
  154. var buffer = this.buffer,
  155. offset = index << 2;
  156. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  157. },
  158. set: function set(value) {
  159. var buffer = this.buffer,
  160. offset = index << 2;
  161. buffer[offset] = value & 255;
  162. buffer[offset + 1] = value >> 8 & 255;
  163. buffer[offset + 2] = value >> 16 & 255;
  164. buffer[offset + 3] = value >>> 24 & 255;
  165. }
  166. };
  167. }
  168. function ensureUint32ArrayViewProps(length) {
  169. while (uint32ArrayViewSetters < length) {
  170. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  171. uint32ArrayViewSetters++;
  172. }
  173. }
  174. function TypedArray(arg1) {
  175. var result, i, n;
  176. if (typeof arg1 === 'number') {
  177. result = [];
  178. for (i = 0; i < arg1; ++i) {
  179. result[i] = 0;
  180. }
  181. } else if ('slice' in arg1) {
  182. result = arg1.slice(0);
  183. } else {
  184. result = [];
  185. for (i = 0, n = arg1.length; i < n; ++i) {
  186. result[i] = arg1[i];
  187. }
  188. }
  189. result.subarray = subarray;
  190. result.buffer = result;
  191. result.byteLength = result.length;
  192. result.set = setArrayOffset;
  193. if ((typeof arg1 === 'undefined' ? 'undefined' : _typeof(arg1)) === 'object' && arg1.buffer) {
  194. result.buffer = arg1.buffer;
  195. }
  196. return result;
  197. }
  198. globalScope.Uint8Array = TypedArray;
  199. globalScope.Int8Array = TypedArray;
  200. globalScope.Int32Array = TypedArray;
  201. globalScope.Uint16Array = TypedArray;
  202. globalScope.Float32Array = TypedArray;
  203. globalScope.Float64Array = TypedArray;
  204. globalScope.Uint32Array = function () {
  205. if (arguments.length === 3) {
  206. if (arguments[1] !== 0) {
  207. throw new Error('offset !== 0 is not supported');
  208. }
  209. return new Uint32ArrayView(arguments[0], arguments[2]);
  210. }
  211. return TypedArray.apply(this, arguments);
  212. };
  213. })();
  214. (function canvasPixelArrayBuffer() {
  215. if (!hasDOM || !window.CanvasPixelArray) {
  216. return;
  217. }
  218. var cpaProto = window.CanvasPixelArray.prototype;
  219. if ('buffer' in cpaProto) {
  220. return;
  221. }
  222. Object.defineProperty(cpaProto, 'buffer', {
  223. get: function get() {
  224. return this;
  225. },
  226. enumerable: false,
  227. configurable: true
  228. });
  229. Object.defineProperty(cpaProto, 'byteLength', {
  230. get: function get() {
  231. return this.length;
  232. },
  233. enumerable: false,
  234. configurable: true
  235. });
  236. })();
  237. (function normalizeURLObject() {
  238. if (!globalScope.URL) {
  239. globalScope.URL = globalScope.webkitURL;
  240. }
  241. })();
  242. (function checkObjectDefinePropertyCompatibility() {
  243. if (typeof Object.defineProperty !== 'undefined') {
  244. var definePropertyPossible = true;
  245. try {
  246. if (hasDOM) {
  247. Object.defineProperty(new Image(), 'id', { value: 'test' });
  248. }
  249. var Test = function Test() {};
  250. Test.prototype = {
  251. get id() {}
  252. };
  253. Object.defineProperty(new Test(), 'id', {
  254. value: '',
  255. configurable: true,
  256. enumerable: true,
  257. writable: false
  258. });
  259. } catch (e) {
  260. definePropertyPossible = false;
  261. }
  262. if (definePropertyPossible) {
  263. return;
  264. }
  265. }
  266. Object.defineProperty = function objectDefineProperty(obj, name, def) {
  267. delete obj[name];
  268. if ('get' in def) {
  269. obj.__defineGetter__(name, def['get']);
  270. }
  271. if ('set' in def) {
  272. obj.__defineSetter__(name, def['set']);
  273. }
  274. if ('value' in def) {
  275. obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
  276. this.__defineGetter__(name, function objectDefinePropertyGetter() {
  277. return value;
  278. });
  279. return value;
  280. });
  281. obj[name] = def.value;
  282. }
  283. };
  284. })();
  285. (function checkXMLHttpRequestResponseCompatibility() {
  286. if (typeof XMLHttpRequest === 'undefined') {
  287. return;
  288. }
  289. var xhrPrototype = XMLHttpRequest.prototype;
  290. var xhr = new XMLHttpRequest();
  291. if (!('overrideMimeType' in xhr)) {
  292. Object.defineProperty(xhrPrototype, 'overrideMimeType', {
  293. value: function xmlHttpRequestOverrideMimeType(mimeType) {}
  294. });
  295. }
  296. if ('responseType' in xhr) {
  297. return;
  298. }
  299. Object.defineProperty(xhrPrototype, 'responseType', {
  300. get: function xmlHttpRequestGetResponseType() {
  301. return this._responseType || 'text';
  302. },
  303. set: function xmlHttpRequestSetResponseType(value) {
  304. if (value === 'text' || value === 'arraybuffer') {
  305. this._responseType = value;
  306. if (value === 'arraybuffer' && typeof this.overrideMimeType === 'function') {
  307. this.overrideMimeType('text/plain; charset=x-user-defined');
  308. }
  309. }
  310. }
  311. });
  312. if (typeof VBArray !== 'undefined') {
  313. Object.defineProperty(xhrPrototype, 'response', {
  314. get: function xmlHttpRequestResponseGet() {
  315. if (this.responseType === 'arraybuffer') {
  316. return new Uint8Array(new VBArray(this.responseBody).toArray());
  317. }
  318. return this.responseText;
  319. }
  320. });
  321. return;
  322. }
  323. Object.defineProperty(xhrPrototype, 'response', {
  324. get: function xmlHttpRequestResponseGet() {
  325. if (this.responseType !== 'arraybuffer') {
  326. return this.responseText;
  327. }
  328. var text = this.responseText;
  329. var i,
  330. n = text.length;
  331. var result = new Uint8Array(n);
  332. for (i = 0; i < n; ++i) {
  333. result[i] = text.charCodeAt(i) & 0xFF;
  334. }
  335. return result.buffer;
  336. }
  337. });
  338. })();
  339. (function checkWindowBtoaCompatibility() {
  340. if ('btoa' in globalScope) {
  341. return;
  342. }
  343. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  344. globalScope.btoa = function (chars) {
  345. var buffer = '';
  346. var i, n;
  347. for (i = 0, n = chars.length; i < n; i += 3) {
  348. var b1 = chars.charCodeAt(i) & 0xFF;
  349. var b2 = chars.charCodeAt(i + 1) & 0xFF;
  350. var b3 = chars.charCodeAt(i + 2) & 0xFF;
  351. var d1 = b1 >> 2,
  352. d2 = (b1 & 3) << 4 | b2 >> 4;
  353. var d3 = i + 1 < n ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  354. var d4 = i + 2 < n ? b3 & 0x3F : 64;
  355. buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
  356. }
  357. return buffer;
  358. };
  359. })();
  360. (function checkWindowAtobCompatibility() {
  361. if ('atob' in globalScope) {
  362. return;
  363. }
  364. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  365. globalScope.atob = function (input) {
  366. input = input.replace(/=+$/, '');
  367. if (input.length % 4 === 1) {
  368. throw new Error('bad atob input');
  369. }
  370. 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) {
  371. buffer = digits.indexOf(buffer);
  372. }
  373. return output;
  374. };
  375. })();
  376. (function checkFunctionPrototypeBindCompatibility() {
  377. if (typeof Function.prototype.bind !== 'undefined') {
  378. return;
  379. }
  380. Function.prototype.bind = function functionPrototypeBind(obj) {
  381. var fn = this,
  382. headArgs = Array.prototype.slice.call(arguments, 1);
  383. var bound = function functionPrototypeBindBound() {
  384. var args = headArgs.concat(Array.prototype.slice.call(arguments));
  385. return fn.apply(obj, args);
  386. };
  387. return bound;
  388. };
  389. })();
  390. (function checkDatasetProperty() {
  391. if (!hasDOM) {
  392. return;
  393. }
  394. var div = document.createElement('div');
  395. if ('dataset' in div) {
  396. return;
  397. }
  398. Object.defineProperty(HTMLElement.prototype, 'dataset', {
  399. get: function get() {
  400. if (this._dataset) {
  401. return this._dataset;
  402. }
  403. var dataset = {};
  404. for (var j = 0, jj = this.attributes.length; j < jj; j++) {
  405. var attribute = this.attributes[j];
  406. if (attribute.name.substring(0, 5) !== 'data-') {
  407. continue;
  408. }
  409. var key = attribute.name.substring(5).replace(/\-([a-z])/g, function (all, ch) {
  410. return ch.toUpperCase();
  411. });
  412. dataset[key] = attribute.value;
  413. }
  414. Object.defineProperty(this, '_dataset', {
  415. value: dataset,
  416. writable: false,
  417. enumerable: false
  418. });
  419. return dataset;
  420. },
  421. enumerable: true
  422. });
  423. })();
  424. (function checkClassListProperty() {
  425. function changeList(element, itemName, add, remove) {
  426. var s = element.className || '';
  427. var list = s.split(/\s+/g);
  428. if (list[0] === '') {
  429. list.shift();
  430. }
  431. var index = list.indexOf(itemName);
  432. if (index < 0 && add) {
  433. list.push(itemName);
  434. }
  435. if (index >= 0 && remove) {
  436. list.splice(index, 1);
  437. }
  438. element.className = list.join(' ');
  439. return index >= 0;
  440. }
  441. if (!hasDOM) {
  442. return;
  443. }
  444. var div = document.createElement('div');
  445. if ('classList' in div) {
  446. return;
  447. }
  448. var classListPrototype = {
  449. add: function add(name) {
  450. changeList(this.element, name, true, false);
  451. },
  452. contains: function contains(name) {
  453. return changeList(this.element, name, false, false);
  454. },
  455. remove: function remove(name) {
  456. changeList(this.element, name, false, true);
  457. },
  458. toggle: function toggle(name) {
  459. changeList(this.element, name, true, true);
  460. }
  461. };
  462. Object.defineProperty(HTMLElement.prototype, 'classList', {
  463. get: function get() {
  464. if (this._classList) {
  465. return this._classList;
  466. }
  467. var classList = Object.create(classListPrototype, {
  468. element: {
  469. value: this,
  470. writable: false,
  471. enumerable: true
  472. }
  473. });
  474. Object.defineProperty(this, '_classList', {
  475. value: classList,
  476. writable: false,
  477. enumerable: false
  478. });
  479. return classList;
  480. },
  481. enumerable: true
  482. });
  483. })();
  484. (function checkWorkerConsoleCompatibility() {
  485. if (typeof importScripts === 'undefined' || 'console' in globalScope) {
  486. return;
  487. }
  488. var consoleTimer = {};
  489. var workerConsole = {
  490. log: function log() {
  491. var args = Array.prototype.slice.call(arguments);
  492. globalScope.postMessage({
  493. targetName: 'main',
  494. action: 'console_log',
  495. data: args
  496. });
  497. },
  498. error: function error() {
  499. var args = Array.prototype.slice.call(arguments);
  500. globalScope.postMessage({
  501. targetName: 'main',
  502. action: 'console_error',
  503. data: args
  504. });
  505. },
  506. time: function time(name) {
  507. consoleTimer[name] = Date.now();
  508. },
  509. timeEnd: function timeEnd(name) {
  510. var time = consoleTimer[name];
  511. if (!time) {
  512. throw new Error('Unknown timer name ' + name);
  513. }
  514. this.log('Timer:', name, Date.now() - time);
  515. }
  516. };
  517. globalScope.console = workerConsole;
  518. })();
  519. (function checkConsoleCompatibility() {
  520. if (!hasDOM) {
  521. return;
  522. }
  523. if (!('console' in window)) {
  524. window.console = {
  525. log: function log() {},
  526. error: function error() {},
  527. warn: function warn() {}
  528. };
  529. return;
  530. }
  531. if (!('bind' in console.log)) {
  532. console.log = function (fn) {
  533. return function (msg) {
  534. return fn(msg);
  535. };
  536. }(console.log);
  537. console.error = function (fn) {
  538. return function (msg) {
  539. return fn(msg);
  540. };
  541. }(console.error);
  542. console.warn = function (fn) {
  543. return function (msg) {
  544. return fn(msg);
  545. };
  546. }(console.warn);
  547. return;
  548. }
  549. })();
  550. (function checkOnClickCompatibility() {
  551. function ignoreIfTargetDisabled(event) {
  552. if (isDisabled(event.target)) {
  553. event.stopPropagation();
  554. }
  555. }
  556. function isDisabled(node) {
  557. return node.disabled || node.parentNode && isDisabled(node.parentNode);
  558. }
  559. if (isOpera) {
  560. document.addEventListener('click', ignoreIfTargetDisabled, true);
  561. }
  562. })();
  563. (function checkOnBlobSupport() {
  564. if (isIE || isIOSChrome) {
  565. PDFJS.disableCreateObjectURL = true;
  566. }
  567. })();
  568. (function checkNavigatorLanguage() {
  569. if (typeof navigator === 'undefined') {
  570. return;
  571. }
  572. if ('language' in navigator) {
  573. return;
  574. }
  575. PDFJS.locale = navigator.userLanguage || 'en-US';
  576. })();
  577. (function checkRangeRequests() {
  578. if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
  579. PDFJS.disableRange = true;
  580. PDFJS.disableStream = true;
  581. }
  582. })();
  583. (function checkHistoryManipulation() {
  584. if (!hasDOM) {
  585. return;
  586. }
  587. if (!history.pushState || isAndroidPre3) {
  588. PDFJS.disableHistory = true;
  589. }
  590. })();
  591. (function checkSetPresenceInImageData() {
  592. if (!hasDOM) {
  593. return;
  594. }
  595. if (window.CanvasPixelArray) {
  596. if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
  597. window.CanvasPixelArray.prototype.set = function (arr) {
  598. for (var i = 0, ii = this.length; i < ii; i++) {
  599. this[i] = arr[i];
  600. }
  601. };
  602. }
  603. } else {
  604. var polyfill = false,
  605. versionMatch;
  606. if (isChrome) {
  607. versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  608. polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
  609. } else if (isAndroid) {
  610. polyfill = isAndroidPre5;
  611. } else if (isSafari) {
  612. versionMatch = userAgent.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
  613. polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
  614. }
  615. if (polyfill) {
  616. var contextPrototype = window.CanvasRenderingContext2D.prototype;
  617. var createImageData = contextPrototype.createImageData;
  618. contextPrototype.createImageData = function (w, h) {
  619. var imageData = createImageData.call(this, w, h);
  620. imageData.data.set = function (arr) {
  621. for (var i = 0, ii = this.length; i < ii; i++) {
  622. this[i] = arr[i];
  623. }
  624. };
  625. return imageData;
  626. };
  627. contextPrototype = null;
  628. }
  629. }
  630. })();
  631. (function checkRequestAnimationFrame() {
  632. function installFakeAnimationFrameFunctions() {
  633. window.requestAnimationFrame = function (callback) {
  634. return window.setTimeout(callback, 20);
  635. };
  636. window.cancelAnimationFrame = function (timeoutID) {
  637. window.clearTimeout(timeoutID);
  638. };
  639. }
  640. if (!hasDOM) {
  641. return;
  642. }
  643. if (isIOS) {
  644. installFakeAnimationFrameFunctions();
  645. return;
  646. }
  647. if ('requestAnimationFrame' in window) {
  648. return;
  649. }
  650. window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;
  651. if (window.requestAnimationFrame) {
  652. return;
  653. }
  654. installFakeAnimationFrameFunctions();
  655. })();
  656. (function checkCanvasSizeLimitation() {
  657. if (isIOS || isAndroid) {
  658. PDFJS.maxCanvasPixels = 5242880;
  659. }
  660. })();
  661. (function checkFullscreenSupport() {
  662. if (!hasDOM) {
  663. return;
  664. }
  665. if (isIE && window.parent !== window) {
  666. PDFJS.disableFullscreen = true;
  667. }
  668. })();
  669. (function checkCurrentScript() {
  670. if (!hasDOM) {
  671. return;
  672. }
  673. if ('currentScript' in document) {
  674. return;
  675. }
  676. Object.defineProperty(document, 'currentScript', {
  677. get: function get() {
  678. var scripts = document.getElementsByTagName('script');
  679. return scripts[scripts.length - 1];
  680. },
  681. enumerable: true,
  682. configurable: true
  683. });
  684. })();
  685. (function checkInputTypeNumberAssign() {
  686. if (!hasDOM) {
  687. return;
  688. }
  689. var el = document.createElement('input');
  690. try {
  691. el.type = 'number';
  692. } catch (ex) {
  693. var inputProto = el.constructor.prototype;
  694. var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
  695. Object.defineProperty(inputProto, 'type', {
  696. get: function get() {
  697. return typeProperty.get.call(this);
  698. },
  699. set: function set(value) {
  700. typeProperty.set.call(this, value === 'number' ? 'text' : value);
  701. },
  702. enumerable: true,
  703. configurable: true
  704. });
  705. }
  706. })();
  707. (function checkDocumentReadyState() {
  708. if (!hasDOM) {
  709. return;
  710. }
  711. if (!document.attachEvent) {
  712. return;
  713. }
  714. var documentProto = document.constructor.prototype;
  715. var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState');
  716. Object.defineProperty(documentProto, 'readyState', {
  717. get: function get() {
  718. var value = readyStateProto.get.call(this);
  719. return value === 'interactive' ? 'loading' : value;
  720. },
  721. set: function set(value) {
  722. readyStateProto.set.call(this, value);
  723. },
  724. enumerable: true,
  725. configurable: true
  726. });
  727. })();
  728. (function checkChildNodeRemove() {
  729. if (!hasDOM) {
  730. return;
  731. }
  732. if (typeof Element.prototype.remove !== 'undefined') {
  733. return;
  734. }
  735. Element.prototype.remove = function () {
  736. if (this.parentNode) {
  737. this.parentNode.removeChild(this);
  738. }
  739. };
  740. })();
  741. (function checkPromise() {
  742. if (globalScope.Promise) {
  743. if (typeof globalScope.Promise.all !== 'function') {
  744. globalScope.Promise.all = function (iterable) {
  745. var count = 0,
  746. results = [],
  747. resolve,
  748. reject;
  749. var promise = new globalScope.Promise(function (resolve_, reject_) {
  750. resolve = resolve_;
  751. reject = reject_;
  752. });
  753. iterable.forEach(function (p, i) {
  754. count++;
  755. p.then(function (result) {
  756. results[i] = result;
  757. count--;
  758. if (count === 0) {
  759. resolve(results);
  760. }
  761. }, reject);
  762. });
  763. if (count === 0) {
  764. resolve(results);
  765. }
  766. return promise;
  767. };
  768. }
  769. if (typeof globalScope.Promise.resolve !== 'function') {
  770. globalScope.Promise.resolve = function (value) {
  771. return new globalScope.Promise(function (resolve) {
  772. resolve(value);
  773. });
  774. };
  775. }
  776. if (typeof globalScope.Promise.reject !== 'function') {
  777. globalScope.Promise.reject = function (reason) {
  778. return new globalScope.Promise(function (resolve, reject) {
  779. reject(reason);
  780. });
  781. };
  782. }
  783. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  784. globalScope.Promise.prototype.catch = function (onReject) {
  785. return globalScope.Promise.prototype.then(undefined, onReject);
  786. };
  787. }
  788. return;
  789. }
  790. var STATUS_PENDING = 0;
  791. var STATUS_RESOLVED = 1;
  792. var STATUS_REJECTED = 2;
  793. var REJECTION_TIMEOUT = 500;
  794. var HandlerManager = {
  795. handlers: [],
  796. running: false,
  797. unhandledRejections: [],
  798. pendingRejectionCheck: false,
  799. scheduleHandlers: function scheduleHandlers(promise) {
  800. if (promise._status === STATUS_PENDING) {
  801. return;
  802. }
  803. this.handlers = this.handlers.concat(promise._handlers);
  804. promise._handlers = [];
  805. if (this.running) {
  806. return;
  807. }
  808. this.running = true;
  809. setTimeout(this.runHandlers.bind(this), 0);
  810. },
  811. runHandlers: function runHandlers() {
  812. var RUN_TIMEOUT = 1;
  813. var timeoutAt = Date.now() + RUN_TIMEOUT;
  814. while (this.handlers.length > 0) {
  815. var handler = this.handlers.shift();
  816. var nextStatus = handler.thisPromise._status;
  817. var nextValue = handler.thisPromise._value;
  818. try {
  819. if (nextStatus === STATUS_RESOLVED) {
  820. if (typeof handler.onResolve === 'function') {
  821. nextValue = handler.onResolve(nextValue);
  822. }
  823. } else if (typeof handler.onReject === 'function') {
  824. nextValue = handler.onReject(nextValue);
  825. nextStatus = STATUS_RESOLVED;
  826. if (handler.thisPromise._unhandledRejection) {
  827. this.removeUnhandeledRejection(handler.thisPromise);
  828. }
  829. }
  830. } catch (ex) {
  831. nextStatus = STATUS_REJECTED;
  832. nextValue = ex;
  833. }
  834. handler.nextPromise._updateStatus(nextStatus, nextValue);
  835. if (Date.now() >= timeoutAt) {
  836. break;
  837. }
  838. }
  839. if (this.handlers.length > 0) {
  840. setTimeout(this.runHandlers.bind(this), 0);
  841. return;
  842. }
  843. this.running = false;
  844. },
  845. addUnhandledRejection: function addUnhandledRejection(promise) {
  846. this.unhandledRejections.push({
  847. promise: promise,
  848. time: Date.now()
  849. });
  850. this.scheduleRejectionCheck();
  851. },
  852. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  853. promise._unhandledRejection = false;
  854. for (var i = 0; i < this.unhandledRejections.length; i++) {
  855. if (this.unhandledRejections[i].promise === promise) {
  856. this.unhandledRejections.splice(i);
  857. i--;
  858. }
  859. }
  860. },
  861. scheduleRejectionCheck: function scheduleRejectionCheck() {
  862. var _this = this;
  863. if (this.pendingRejectionCheck) {
  864. return;
  865. }
  866. this.pendingRejectionCheck = true;
  867. setTimeout(function () {
  868. _this.pendingRejectionCheck = false;
  869. var now = Date.now();
  870. for (var i = 0; i < _this.unhandledRejections.length; i++) {
  871. if (now - _this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  872. var unhandled = _this.unhandledRejections[i].promise._value;
  873. var msg = 'Unhandled rejection: ' + unhandled;
  874. if (unhandled.stack) {
  875. msg += '\n' + unhandled.stack;
  876. }
  877. try {
  878. throw new Error(msg);
  879. } catch (_) {
  880. console.warn(msg);
  881. }
  882. _this.unhandledRejections.splice(i);
  883. i--;
  884. }
  885. }
  886. if (_this.unhandledRejections.length) {
  887. _this.scheduleRejectionCheck();
  888. }
  889. }, REJECTION_TIMEOUT);
  890. }
  891. };
  892. var Promise = function Promise(resolver) {
  893. this._status = STATUS_PENDING;
  894. this._handlers = [];
  895. try {
  896. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  897. } catch (e) {
  898. this._reject(e);
  899. }
  900. };
  901. Promise.all = function Promise_all(promises) {
  902. var resolveAll, rejectAll;
  903. var deferred = new Promise(function (resolve, reject) {
  904. resolveAll = resolve;
  905. rejectAll = reject;
  906. });
  907. var unresolved = promises.length;
  908. var results = [];
  909. if (unresolved === 0) {
  910. resolveAll(results);
  911. return deferred;
  912. }
  913. function reject(reason) {
  914. if (deferred._status === STATUS_REJECTED) {
  915. return;
  916. }
  917. results = [];
  918. rejectAll(reason);
  919. }
  920. for (var i = 0, ii = promises.length; i < ii; ++i) {
  921. var promise = promises[i];
  922. var resolve = function (i) {
  923. return function (value) {
  924. if (deferred._status === STATUS_REJECTED) {
  925. return;
  926. }
  927. results[i] = value;
  928. unresolved--;
  929. if (unresolved === 0) {
  930. resolveAll(results);
  931. }
  932. };
  933. }(i);
  934. if (Promise.isPromise(promise)) {
  935. promise.then(resolve, reject);
  936. } else {
  937. resolve(promise);
  938. }
  939. }
  940. return deferred;
  941. };
  942. Promise.isPromise = function Promise_isPromise(value) {
  943. return value && typeof value.then === 'function';
  944. };
  945. Promise.resolve = function Promise_resolve(value) {
  946. return new Promise(function (resolve) {
  947. resolve(value);
  948. });
  949. };
  950. Promise.reject = function Promise_reject(reason) {
  951. return new Promise(function (resolve, reject) {
  952. reject(reason);
  953. });
  954. };
  955. Promise.prototype = {
  956. _status: null,
  957. _value: null,
  958. _handlers: null,
  959. _unhandledRejection: null,
  960. _updateStatus: function Promise__updateStatus(status, value) {
  961. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  962. return;
  963. }
  964. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  965. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  966. return;
  967. }
  968. this._status = status;
  969. this._value = value;
  970. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  971. this._unhandledRejection = true;
  972. HandlerManager.addUnhandledRejection(this);
  973. }
  974. HandlerManager.scheduleHandlers(this);
  975. },
  976. _resolve: function Promise_resolve(value) {
  977. this._updateStatus(STATUS_RESOLVED, value);
  978. },
  979. _reject: function Promise_reject(reason) {
  980. this._updateStatus(STATUS_REJECTED, reason);
  981. },
  982. then: function Promise_then(onResolve, onReject) {
  983. var nextPromise = new Promise(function (resolve, reject) {
  984. this.resolve = resolve;
  985. this.reject = reject;
  986. });
  987. this._handlers.push({
  988. thisPromise: this,
  989. onResolve: onResolve,
  990. onReject: onReject,
  991. nextPromise: nextPromise
  992. });
  993. HandlerManager.scheduleHandlers(this);
  994. return nextPromise;
  995. },
  996. catch: function Promise_catch(onReject) {
  997. return this.then(undefined, onReject);
  998. }
  999. };
  1000. globalScope.Promise = Promise;
  1001. })();
  1002. (function checkWeakMap() {
  1003. if (globalScope.WeakMap) {
  1004. return;
  1005. }
  1006. var id = 0;
  1007. function WeakMap() {
  1008. this.id = '$weakmap' + id++;
  1009. }
  1010. WeakMap.prototype = {
  1011. has: function has(obj) {
  1012. if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' && typeof obj !== 'function' || obj === null) {
  1013. return false;
  1014. }
  1015. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  1016. },
  1017. get: function get(obj) {
  1018. return this.has(obj) ? obj[this.id] : undefined;
  1019. },
  1020. set: function set(obj, value) {
  1021. Object.defineProperty(obj, this.id, {
  1022. value: value,
  1023. enumerable: false,
  1024. configurable: true
  1025. });
  1026. },
  1027. delete: function _delete(obj) {
  1028. delete obj[this.id];
  1029. }
  1030. };
  1031. globalScope.WeakMap = WeakMap;
  1032. })();
  1033. (function checkURLConstructor() {
  1034. var hasWorkingUrl = false;
  1035. try {
  1036. if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
  1037. var u = new URL('b', 'http://a');
  1038. u.pathname = 'c%20d';
  1039. hasWorkingUrl = u.href === 'http://a/c%20d';
  1040. }
  1041. } catch (e) {}
  1042. if (hasWorkingUrl) {
  1043. return;
  1044. }
  1045. var relative = Object.create(null);
  1046. relative['ftp'] = 21;
  1047. relative['file'] = 0;
  1048. relative['gopher'] = 70;
  1049. relative['http'] = 80;
  1050. relative['https'] = 443;
  1051. relative['ws'] = 80;
  1052. relative['wss'] = 443;
  1053. var relativePathDotMapping = Object.create(null);
  1054. relativePathDotMapping['%2e'] = '.';
  1055. relativePathDotMapping['.%2e'] = '..';
  1056. relativePathDotMapping['%2e.'] = '..';
  1057. relativePathDotMapping['%2e%2e'] = '..';
  1058. function isRelativeScheme(scheme) {
  1059. return relative[scheme] !== undefined;
  1060. }
  1061. function invalid() {
  1062. clear.call(this);
  1063. this._isInvalid = true;
  1064. }
  1065. function IDNAToASCII(h) {
  1066. if (h === '') {
  1067. invalid.call(this);
  1068. }
  1069. return h.toLowerCase();
  1070. }
  1071. function percentEscape(c) {
  1072. var unicode = c.charCodeAt(0);
  1073. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  1074. return c;
  1075. }
  1076. return encodeURIComponent(c);
  1077. }
  1078. function percentEscapeQuery(c) {
  1079. var unicode = c.charCodeAt(0);
  1080. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  1081. return c;
  1082. }
  1083. return encodeURIComponent(c);
  1084. }
  1085. var EOF,
  1086. ALPHA = /[a-zA-Z]/,
  1087. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  1088. function parse(input, stateOverride, base) {
  1089. function err(message) {
  1090. errors.push(message);
  1091. }
  1092. var state = stateOverride || 'scheme start',
  1093. cursor = 0,
  1094. buffer = '',
  1095. seenAt = false,
  1096. seenBracket = false,
  1097. errors = [];
  1098. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  1099. var c = input[cursor];
  1100. switch (state) {
  1101. case 'scheme start':
  1102. if (c && ALPHA.test(c)) {
  1103. buffer += c.toLowerCase();
  1104. state = 'scheme';
  1105. } else if (!stateOverride) {
  1106. buffer = '';
  1107. state = 'no scheme';
  1108. continue;
  1109. } else {
  1110. err('Invalid scheme.');
  1111. break loop;
  1112. }
  1113. break;
  1114. case 'scheme':
  1115. if (c && ALPHANUMERIC.test(c)) {
  1116. buffer += c.toLowerCase();
  1117. } else if (c === ':') {
  1118. this._scheme = buffer;
  1119. buffer = '';
  1120. if (stateOverride) {
  1121. break loop;
  1122. }
  1123. if (isRelativeScheme(this._scheme)) {
  1124. this._isRelative = true;
  1125. }
  1126. if (this._scheme === 'file') {
  1127. state = 'relative';
  1128. } else if (this._isRelative && base && base._scheme === this._scheme) {
  1129. state = 'relative or authority';
  1130. } else if (this._isRelative) {
  1131. state = 'authority first slash';
  1132. } else {
  1133. state = 'scheme data';
  1134. }
  1135. } else if (!stateOverride) {
  1136. buffer = '';
  1137. cursor = 0;
  1138. state = 'no scheme';
  1139. continue;
  1140. } else if (c === EOF) {
  1141. break loop;
  1142. } else {
  1143. err('Code point not allowed in scheme: ' + c);
  1144. break loop;
  1145. }
  1146. break;
  1147. case 'scheme data':
  1148. if (c === '?') {
  1149. this._query = '?';
  1150. state = 'query';
  1151. } else if (c === '#') {
  1152. this._fragment = '#';
  1153. state = 'fragment';
  1154. } else {
  1155. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1156. this._schemeData += percentEscape(c);
  1157. }
  1158. }
  1159. break;
  1160. case 'no scheme':
  1161. if (!base || !isRelativeScheme(base._scheme)) {
  1162. err('Missing scheme.');
  1163. invalid.call(this);
  1164. } else {
  1165. state = 'relative';
  1166. continue;
  1167. }
  1168. break;
  1169. case 'relative or authority':
  1170. if (c === '/' && input[cursor + 1] === '/') {
  1171. state = 'authority ignore slashes';
  1172. } else {
  1173. err('Expected /, got: ' + c);
  1174. state = 'relative';
  1175. continue;
  1176. }
  1177. break;
  1178. case 'relative':
  1179. this._isRelative = true;
  1180. if (this._scheme !== 'file') {
  1181. this._scheme = base._scheme;
  1182. }
  1183. if (c === EOF) {
  1184. this._host = base._host;
  1185. this._port = base._port;
  1186. this._path = base._path.slice();
  1187. this._query = base._query;
  1188. this._username = base._username;
  1189. this._password = base._password;
  1190. break loop;
  1191. } else if (c === '/' || c === '\\') {
  1192. if (c === '\\') {
  1193. err('\\ is an invalid code point.');
  1194. }
  1195. state = 'relative slash';
  1196. } else if (c === '?') {
  1197. this._host = base._host;
  1198. this._port = base._port;
  1199. this._path = base._path.slice();
  1200. this._query = '?';
  1201. this._username = base._username;
  1202. this._password = base._password;
  1203. state = 'query';
  1204. } else if (c === '#') {
  1205. this._host = base._host;
  1206. this._port = base._port;
  1207. this._path = base._path.slice();
  1208. this._query = base._query;
  1209. this._fragment = '#';
  1210. this._username = base._username;
  1211. this._password = base._password;
  1212. state = 'fragment';
  1213. } else {
  1214. var nextC = input[cursor + 1];
  1215. var nextNextC = input[cursor + 2];
  1216. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  1217. this._host = base._host;
  1218. this._port = base._port;
  1219. this._username = base._username;
  1220. this._password = base._password;
  1221. this._path = base._path.slice();
  1222. this._path.pop();
  1223. }
  1224. state = 'relative path';
  1225. continue;
  1226. }
  1227. break;
  1228. case 'relative slash':
  1229. if (c === '/' || c === '\\') {
  1230. if (c === '\\') {
  1231. err('\\ is an invalid code point.');
  1232. }
  1233. if (this._scheme === 'file') {
  1234. state = 'file host';
  1235. } else {
  1236. state = 'authority ignore slashes';
  1237. }
  1238. } else {
  1239. if (this._scheme !== 'file') {
  1240. this._host = base._host;
  1241. this._port = base._port;
  1242. this._username = base._username;
  1243. this._password = base._password;
  1244. }
  1245. state = 'relative path';
  1246. continue;
  1247. }
  1248. break;
  1249. case 'authority first slash':
  1250. if (c === '/') {
  1251. state = 'authority second slash';
  1252. } else {
  1253. err('Expected \'/\', got: ' + c);
  1254. state = 'authority ignore slashes';
  1255. continue;
  1256. }
  1257. break;
  1258. case 'authority second slash':
  1259. state = 'authority ignore slashes';
  1260. if (c !== '/') {
  1261. err('Expected \'/\', got: ' + c);
  1262. continue;
  1263. }
  1264. break;
  1265. case 'authority ignore slashes':
  1266. if (c !== '/' && c !== '\\') {
  1267. state = 'authority';
  1268. continue;
  1269. } else {
  1270. err('Expected authority, got: ' + c);
  1271. }
  1272. break;
  1273. case 'authority':
  1274. if (c === '@') {
  1275. if (seenAt) {
  1276. err('@ already seen.');
  1277. buffer += '%40';
  1278. }
  1279. seenAt = true;
  1280. for (var i = 0; i < buffer.length; i++) {
  1281. var cp = buffer[i];
  1282. if (cp === '\t' || cp === '\n' || cp === '\r') {
  1283. err('Invalid whitespace in authority.');
  1284. continue;
  1285. }
  1286. if (cp === ':' && this._password === null) {
  1287. this._password = '';
  1288. continue;
  1289. }
  1290. var tempC = percentEscape(cp);
  1291. if (this._password !== null) {
  1292. this._password += tempC;
  1293. } else {
  1294. this._username += tempC;
  1295. }
  1296. }
  1297. buffer = '';
  1298. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1299. cursor -= buffer.length;
  1300. buffer = '';
  1301. state = 'host';
  1302. continue;
  1303. } else {
  1304. buffer += c;
  1305. }
  1306. break;
  1307. case 'file host':
  1308. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1309. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  1310. state = 'relative path';
  1311. } else if (buffer.length === 0) {
  1312. state = 'relative path start';
  1313. } else {
  1314. this._host = IDNAToASCII.call(this, buffer);
  1315. buffer = '';
  1316. state = 'relative path start';
  1317. }
  1318. continue;
  1319. } else if (c === '\t' || c === '\n' || c === '\r') {
  1320. err('Invalid whitespace in file host.');
  1321. } else {
  1322. buffer += c;
  1323. }
  1324. break;
  1325. case 'host':
  1326. case 'hostname':
  1327. if (c === ':' && !seenBracket) {
  1328. this._host = IDNAToASCII.call(this, buffer);
  1329. buffer = '';
  1330. state = 'port';
  1331. if (stateOverride === 'hostname') {
  1332. break loop;
  1333. }
  1334. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1335. this._host = IDNAToASCII.call(this, buffer);
  1336. buffer = '';
  1337. state = 'relative path start';
  1338. if (stateOverride) {
  1339. break loop;
  1340. }
  1341. continue;
  1342. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1343. if (c === '[') {
  1344. seenBracket = true;
  1345. } else if (c === ']') {
  1346. seenBracket = false;
  1347. }
  1348. buffer += c;
  1349. } else {
  1350. err('Invalid code point in host/hostname: ' + c);
  1351. }
  1352. break;
  1353. case 'port':
  1354. if (/[0-9]/.test(c)) {
  1355. buffer += c;
  1356. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1357. if (buffer !== '') {
  1358. var temp = parseInt(buffer, 10);
  1359. if (temp !== relative[this._scheme]) {
  1360. this._port = temp + '';
  1361. }
  1362. buffer = '';
  1363. }
  1364. if (stateOverride) {
  1365. break loop;
  1366. }
  1367. state = 'relative path start';
  1368. continue;
  1369. } else if (c === '\t' || c === '\n' || c === '\r') {
  1370. err('Invalid code point in port: ' + c);
  1371. } else {
  1372. invalid.call(this);
  1373. }
  1374. break;
  1375. case 'relative path start':
  1376. if (c === '\\') {
  1377. err('\'\\\' not allowed in path.');
  1378. }
  1379. state = 'relative path';
  1380. if (c !== '/' && c !== '\\') {
  1381. continue;
  1382. }
  1383. break;
  1384. case 'relative path':
  1385. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1386. if (c === '\\') {
  1387. err('\\ not allowed in relative path.');
  1388. }
  1389. var tmp;
  1390. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1391. buffer = tmp;
  1392. }
  1393. if (buffer === '..') {
  1394. this._path.pop();
  1395. if (c !== '/' && c !== '\\') {
  1396. this._path.push('');
  1397. }
  1398. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  1399. this._path.push('');
  1400. } else if (buffer !== '.') {
  1401. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1402. buffer = buffer[0] + ':';
  1403. }
  1404. this._path.push(buffer);
  1405. }
  1406. buffer = '';
  1407. if (c === '?') {
  1408. this._query = '?';
  1409. state = 'query';
  1410. } else if (c === '#') {
  1411. this._fragment = '#';
  1412. state = 'fragment';
  1413. }
  1414. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1415. buffer += percentEscape(c);
  1416. }
  1417. break;
  1418. case 'query':
  1419. if (!stateOverride && c === '#') {
  1420. this._fragment = '#';
  1421. state = 'fragment';
  1422. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1423. this._query += percentEscapeQuery(c);
  1424. }
  1425. break;
  1426. case 'fragment':
  1427. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1428. this._fragment += c;
  1429. }
  1430. break;
  1431. }
  1432. cursor++;
  1433. }
  1434. }
  1435. function clear() {
  1436. this._scheme = '';
  1437. this._schemeData = '';
  1438. this._username = '';
  1439. this._password = null;
  1440. this._host = '';
  1441. this._port = '';
  1442. this._path = [];
  1443. this._query = '';
  1444. this._fragment = '';
  1445. this._isInvalid = false;
  1446. this._isRelative = false;
  1447. }
  1448. function JURL(url, base) {
  1449. if (base !== undefined && !(base instanceof JURL)) {
  1450. base = new JURL(String(base));
  1451. }
  1452. this._url = url;
  1453. clear.call(this);
  1454. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1455. parse.call(this, input, null, base);
  1456. }
  1457. JURL.prototype = {
  1458. toString: function toString() {
  1459. return this.href;
  1460. },
  1461. get href() {
  1462. if (this._isInvalid) {
  1463. return this._url;
  1464. }
  1465. var authority = '';
  1466. if (this._username !== '' || this._password !== null) {
  1467. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  1468. }
  1469. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1470. },
  1471. set href(value) {
  1472. clear.call(this);
  1473. parse.call(this, value);
  1474. },
  1475. get protocol() {
  1476. return this._scheme + ':';
  1477. },
  1478. set protocol(value) {
  1479. if (this._isInvalid) {
  1480. return;
  1481. }
  1482. parse.call(this, value + ':', 'scheme start');
  1483. },
  1484. get host() {
  1485. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1486. },
  1487. set host(value) {
  1488. if (this._isInvalid || !this._isRelative) {
  1489. return;
  1490. }
  1491. parse.call(this, value, 'host');
  1492. },
  1493. get hostname() {
  1494. return this._host;
  1495. },
  1496. set hostname(value) {
  1497. if (this._isInvalid || !this._isRelative) {
  1498. return;
  1499. }
  1500. parse.call(this, value, 'hostname');
  1501. },
  1502. get port() {
  1503. return this._port;
  1504. },
  1505. set port(value) {
  1506. if (this._isInvalid || !this._isRelative) {
  1507. return;
  1508. }
  1509. parse.call(this, value, 'port');
  1510. },
  1511. get pathname() {
  1512. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1513. },
  1514. set pathname(value) {
  1515. if (this._isInvalid || !this._isRelative) {
  1516. return;
  1517. }
  1518. this._path = [];
  1519. parse.call(this, value, 'relative path start');
  1520. },
  1521. get search() {
  1522. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1523. },
  1524. set search(value) {
  1525. if (this._isInvalid || !this._isRelative) {
  1526. return;
  1527. }
  1528. this._query = '?';
  1529. if (value[0] === '?') {
  1530. value = value.slice(1);
  1531. }
  1532. parse.call(this, value, 'query');
  1533. },
  1534. get hash() {
  1535. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1536. },
  1537. set hash(value) {
  1538. if (this._isInvalid) {
  1539. return;
  1540. }
  1541. this._fragment = '#';
  1542. if (value[0] === '#') {
  1543. value = value.slice(1);
  1544. }
  1545. parse.call(this, value, 'fragment');
  1546. },
  1547. get origin() {
  1548. var host;
  1549. if (this._isInvalid || !this._scheme) {
  1550. return '';
  1551. }
  1552. switch (this._scheme) {
  1553. case 'data':
  1554. case 'file':
  1555. case 'javascript':
  1556. case 'mailto':
  1557. return 'null';
  1558. case 'blob':
  1559. try {
  1560. return new JURL(this._schemeData).origin || 'null';
  1561. } catch (_) {}
  1562. return 'null';
  1563. }
  1564. host = this.host;
  1565. if (!host) {
  1566. return '';
  1567. }
  1568. return this._scheme + '://' + host;
  1569. }
  1570. };
  1571. var OriginalURL = globalScope.URL;
  1572. if (OriginalURL) {
  1573. JURL.createObjectURL = function (blob) {
  1574. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1575. };
  1576. JURL.revokeObjectURL = function (url) {
  1577. OriginalURL.revokeObjectURL(url);
  1578. };
  1579. }
  1580. globalScope.URL = JURL;
  1581. })();
  1582. }
  1583. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
  1584. /***/ }),
  1585. /* 1 */
  1586. /***/ (function(module, exports, __webpack_require__) {
  1587. "use strict";
  1588. 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; };
  1589. var g;
  1590. g = function () {
  1591. return this;
  1592. }();
  1593. try {
  1594. g = g || Function("return this")() || (1, eval)("this");
  1595. } catch (e) {
  1596. if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "object") g = window;
  1597. }
  1598. module.exports = g;
  1599. /***/ }),
  1600. /* 2 */
  1601. /***/ (function(module, exports, __webpack_require__) {
  1602. "use strict";
  1603. __webpack_require__(0);
  1604. /***/ })
  1605. /******/ ]);
  1606. });
  1607. //# sourceMappingURL=compatibility.js.map