2
0

compatibility.js 51 KB

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