compatibility.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  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 : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? 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. if (this.pendingRejectionCheck) {
  863. return;
  864. }
  865. this.pendingRejectionCheck = true;
  866. setTimeout(function rejectionCheck() {
  867. this.pendingRejectionCheck = false;
  868. var now = Date.now();
  869. for (var i = 0; i < this.unhandledRejections.length; i++) {
  870. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  871. var unhandled = this.unhandledRejections[i].promise._value;
  872. var msg = 'Unhandled rejection: ' + unhandled;
  873. if (unhandled.stack) {
  874. msg += '\n' + unhandled.stack;
  875. }
  876. try {
  877. throw new Error(msg);
  878. } catch (_) {
  879. console.warn(msg);
  880. }
  881. this.unhandledRejections.splice(i);
  882. i--;
  883. }
  884. }
  885. if (this.unhandledRejections.length) {
  886. this.scheduleRejectionCheck();
  887. }
  888. }.bind(this), REJECTION_TIMEOUT);
  889. }
  890. };
  891. var Promise = function Promise(resolver) {
  892. this._status = STATUS_PENDING;
  893. this._handlers = [];
  894. try {
  895. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  896. } catch (e) {
  897. this._reject(e);
  898. }
  899. };
  900. Promise.all = function Promise_all(promises) {
  901. var resolveAll, rejectAll;
  902. var deferred = new Promise(function (resolve, reject) {
  903. resolveAll = resolve;
  904. rejectAll = reject;
  905. });
  906. var unresolved = promises.length;
  907. var results = [];
  908. if (unresolved === 0) {
  909. resolveAll(results);
  910. return deferred;
  911. }
  912. function reject(reason) {
  913. if (deferred._status === STATUS_REJECTED) {
  914. return;
  915. }
  916. results = [];
  917. rejectAll(reason);
  918. }
  919. for (var i = 0, ii = promises.length; i < ii; ++i) {
  920. var promise = promises[i];
  921. var resolve = function (i) {
  922. return function (value) {
  923. if (deferred._status === STATUS_REJECTED) {
  924. return;
  925. }
  926. results[i] = value;
  927. unresolved--;
  928. if (unresolved === 0) {
  929. resolveAll(results);
  930. }
  931. };
  932. }(i);
  933. if (Promise.isPromise(promise)) {
  934. promise.then(resolve, reject);
  935. } else {
  936. resolve(promise);
  937. }
  938. }
  939. return deferred;
  940. };
  941. Promise.isPromise = function Promise_isPromise(value) {
  942. return value && typeof value.then === 'function';
  943. };
  944. Promise.resolve = function Promise_resolve(value) {
  945. return new Promise(function (resolve) {
  946. resolve(value);
  947. });
  948. };
  949. Promise.reject = function Promise_reject(reason) {
  950. return new Promise(function (resolve, reject) {
  951. reject(reason);
  952. });
  953. };
  954. Promise.prototype = {
  955. _status: null,
  956. _value: null,
  957. _handlers: null,
  958. _unhandledRejection: null,
  959. _updateStatus: function Promise__updateStatus(status, value) {
  960. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  961. return;
  962. }
  963. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  964. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  965. return;
  966. }
  967. this._status = status;
  968. this._value = value;
  969. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  970. this._unhandledRejection = true;
  971. HandlerManager.addUnhandledRejection(this);
  972. }
  973. HandlerManager.scheduleHandlers(this);
  974. },
  975. _resolve: function Promise_resolve(value) {
  976. this._updateStatus(STATUS_RESOLVED, value);
  977. },
  978. _reject: function Promise_reject(reason) {
  979. this._updateStatus(STATUS_REJECTED, reason);
  980. },
  981. then: function Promise_then(onResolve, onReject) {
  982. var nextPromise = new Promise(function (resolve, reject) {
  983. this.resolve = resolve;
  984. this.reject = reject;
  985. });
  986. this._handlers.push({
  987. thisPromise: this,
  988. onResolve: onResolve,
  989. onReject: onReject,
  990. nextPromise: nextPromise
  991. });
  992. HandlerManager.scheduleHandlers(this);
  993. return nextPromise;
  994. },
  995. catch: function Promise_catch(onReject) {
  996. return this.then(undefined, onReject);
  997. }
  998. };
  999. globalScope.Promise = Promise;
  1000. })();
  1001. (function checkWeakMap() {
  1002. if (globalScope.WeakMap) {
  1003. return;
  1004. }
  1005. var id = 0;
  1006. function WeakMap() {
  1007. this.id = '$weakmap' + id++;
  1008. }
  1009. WeakMap.prototype = {
  1010. has: function has(obj) {
  1011. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  1012. },
  1013. get: function get(obj, defaultValue) {
  1014. return this.has(obj) ? obj[this.id] : defaultValue;
  1015. },
  1016. set: function set(obj, value) {
  1017. Object.defineProperty(obj, this.id, {
  1018. value: value,
  1019. enumerable: false,
  1020. configurable: true
  1021. });
  1022. },
  1023. delete: function _delete(obj) {
  1024. delete obj[this.id];
  1025. }
  1026. };
  1027. globalScope.WeakMap = WeakMap;
  1028. })();
  1029. (function checkURLConstructor() {
  1030. var hasWorkingUrl = false;
  1031. try {
  1032. if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
  1033. var u = new URL('b', 'http://a');
  1034. u.pathname = 'c%20d';
  1035. hasWorkingUrl = u.href === 'http://a/c%20d';
  1036. }
  1037. } catch (e) {}
  1038. if (hasWorkingUrl) {
  1039. return;
  1040. }
  1041. var relative = Object.create(null);
  1042. relative['ftp'] = 21;
  1043. relative['file'] = 0;
  1044. relative['gopher'] = 70;
  1045. relative['http'] = 80;
  1046. relative['https'] = 443;
  1047. relative['ws'] = 80;
  1048. relative['wss'] = 443;
  1049. var relativePathDotMapping = Object.create(null);
  1050. relativePathDotMapping['%2e'] = '.';
  1051. relativePathDotMapping['.%2e'] = '..';
  1052. relativePathDotMapping['%2e.'] = '..';
  1053. relativePathDotMapping['%2e%2e'] = '..';
  1054. function isRelativeScheme(scheme) {
  1055. return relative[scheme] !== undefined;
  1056. }
  1057. function invalid() {
  1058. clear.call(this);
  1059. this._isInvalid = true;
  1060. }
  1061. function IDNAToASCII(h) {
  1062. if (h === '') {
  1063. invalid.call(this);
  1064. }
  1065. return h.toLowerCase();
  1066. }
  1067. function percentEscape(c) {
  1068. var unicode = c.charCodeAt(0);
  1069. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  1070. return c;
  1071. }
  1072. return encodeURIComponent(c);
  1073. }
  1074. function percentEscapeQuery(c) {
  1075. var unicode = c.charCodeAt(0);
  1076. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  1077. return c;
  1078. }
  1079. return encodeURIComponent(c);
  1080. }
  1081. var EOF,
  1082. ALPHA = /[a-zA-Z]/,
  1083. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  1084. function parse(input, stateOverride, base) {
  1085. function err(message) {
  1086. errors.push(message);
  1087. }
  1088. var state = stateOverride || 'scheme start',
  1089. cursor = 0,
  1090. buffer = '',
  1091. seenAt = false,
  1092. seenBracket = false,
  1093. errors = [];
  1094. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  1095. var c = input[cursor];
  1096. switch (state) {
  1097. case 'scheme start':
  1098. if (c && ALPHA.test(c)) {
  1099. buffer += c.toLowerCase();
  1100. state = 'scheme';
  1101. } else if (!stateOverride) {
  1102. buffer = '';
  1103. state = 'no scheme';
  1104. continue;
  1105. } else {
  1106. err('Invalid scheme.');
  1107. break loop;
  1108. }
  1109. break;
  1110. case 'scheme':
  1111. if (c && ALPHANUMERIC.test(c)) {
  1112. buffer += c.toLowerCase();
  1113. } else if (c === ':') {
  1114. this._scheme = buffer;
  1115. buffer = '';
  1116. if (stateOverride) {
  1117. break loop;
  1118. }
  1119. if (isRelativeScheme(this._scheme)) {
  1120. this._isRelative = true;
  1121. }
  1122. if (this._scheme === 'file') {
  1123. state = 'relative';
  1124. } else if (this._isRelative && base && base._scheme === this._scheme) {
  1125. state = 'relative or authority';
  1126. } else if (this._isRelative) {
  1127. state = 'authority first slash';
  1128. } else {
  1129. state = 'scheme data';
  1130. }
  1131. } else if (!stateOverride) {
  1132. buffer = '';
  1133. cursor = 0;
  1134. state = 'no scheme';
  1135. continue;
  1136. } else if (c === EOF) {
  1137. break loop;
  1138. } else {
  1139. err('Code point not allowed in scheme: ' + c);
  1140. break loop;
  1141. }
  1142. break;
  1143. case 'scheme data':
  1144. if (c === '?') {
  1145. this._query = '?';
  1146. state = 'query';
  1147. } else if (c === '#') {
  1148. this._fragment = '#';
  1149. state = 'fragment';
  1150. } else {
  1151. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1152. this._schemeData += percentEscape(c);
  1153. }
  1154. }
  1155. break;
  1156. case 'no scheme':
  1157. if (!base || !isRelativeScheme(base._scheme)) {
  1158. err('Missing scheme.');
  1159. invalid.call(this);
  1160. } else {
  1161. state = 'relative';
  1162. continue;
  1163. }
  1164. break;
  1165. case 'relative or authority':
  1166. if (c === '/' && input[cursor + 1] === '/') {
  1167. state = 'authority ignore slashes';
  1168. } else {
  1169. err('Expected /, got: ' + c);
  1170. state = 'relative';
  1171. continue;
  1172. }
  1173. break;
  1174. case 'relative':
  1175. this._isRelative = true;
  1176. if (this._scheme !== 'file') {
  1177. this._scheme = base._scheme;
  1178. }
  1179. if (c === EOF) {
  1180. this._host = base._host;
  1181. this._port = base._port;
  1182. this._path = base._path.slice();
  1183. this._query = base._query;
  1184. this._username = base._username;
  1185. this._password = base._password;
  1186. break loop;
  1187. } else if (c === '/' || c === '\\') {
  1188. if (c === '\\') {
  1189. err('\\ is an invalid code point.');
  1190. }
  1191. state = 'relative slash';
  1192. } else if (c === '?') {
  1193. this._host = base._host;
  1194. this._port = base._port;
  1195. this._path = base._path.slice();
  1196. this._query = '?';
  1197. this._username = base._username;
  1198. this._password = base._password;
  1199. state = 'query';
  1200. } else if (c === '#') {
  1201. this._host = base._host;
  1202. this._port = base._port;
  1203. this._path = base._path.slice();
  1204. this._query = base._query;
  1205. this._fragment = '#';
  1206. this._username = base._username;
  1207. this._password = base._password;
  1208. state = 'fragment';
  1209. } else {
  1210. var nextC = input[cursor + 1];
  1211. var nextNextC = input[cursor + 2];
  1212. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  1213. this._host = base._host;
  1214. this._port = base._port;
  1215. this._username = base._username;
  1216. this._password = base._password;
  1217. this._path = base._path.slice();
  1218. this._path.pop();
  1219. }
  1220. state = 'relative path';
  1221. continue;
  1222. }
  1223. break;
  1224. case 'relative slash':
  1225. if (c === '/' || c === '\\') {
  1226. if (c === '\\') {
  1227. err('\\ is an invalid code point.');
  1228. }
  1229. if (this._scheme === 'file') {
  1230. state = 'file host';
  1231. } else {
  1232. state = 'authority ignore slashes';
  1233. }
  1234. } else {
  1235. if (this._scheme !== 'file') {
  1236. this._host = base._host;
  1237. this._port = base._port;
  1238. this._username = base._username;
  1239. this._password = base._password;
  1240. }
  1241. state = 'relative path';
  1242. continue;
  1243. }
  1244. break;
  1245. case 'authority first slash':
  1246. if (c === '/') {
  1247. state = 'authority second slash';
  1248. } else {
  1249. err('Expected \'/\', got: ' + c);
  1250. state = 'authority ignore slashes';
  1251. continue;
  1252. }
  1253. break;
  1254. case 'authority second slash':
  1255. state = 'authority ignore slashes';
  1256. if (c !== '/') {
  1257. err('Expected \'/\', got: ' + c);
  1258. continue;
  1259. }
  1260. break;
  1261. case 'authority ignore slashes':
  1262. if (c !== '/' && c !== '\\') {
  1263. state = 'authority';
  1264. continue;
  1265. } else {
  1266. err('Expected authority, got: ' + c);
  1267. }
  1268. break;
  1269. case 'authority':
  1270. if (c === '@') {
  1271. if (seenAt) {
  1272. err('@ already seen.');
  1273. buffer += '%40';
  1274. }
  1275. seenAt = true;
  1276. for (var i = 0; i < buffer.length; i++) {
  1277. var cp = buffer[i];
  1278. if (cp === '\t' || cp === '\n' || cp === '\r') {
  1279. err('Invalid whitespace in authority.');
  1280. continue;
  1281. }
  1282. if (cp === ':' && this._password === null) {
  1283. this._password = '';
  1284. continue;
  1285. }
  1286. var tempC = percentEscape(cp);
  1287. if (this._password !== null) {
  1288. this._password += tempC;
  1289. } else {
  1290. this._username += tempC;
  1291. }
  1292. }
  1293. buffer = '';
  1294. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1295. cursor -= buffer.length;
  1296. buffer = '';
  1297. state = 'host';
  1298. continue;
  1299. } else {
  1300. buffer += c;
  1301. }
  1302. break;
  1303. case 'file host':
  1304. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1305. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  1306. state = 'relative path';
  1307. } else if (buffer.length === 0) {
  1308. state = 'relative path start';
  1309. } else {
  1310. this._host = IDNAToASCII.call(this, buffer);
  1311. buffer = '';
  1312. state = 'relative path start';
  1313. }
  1314. continue;
  1315. } else if (c === '\t' || c === '\n' || c === '\r') {
  1316. err('Invalid whitespace in file host.');
  1317. } else {
  1318. buffer += c;
  1319. }
  1320. break;
  1321. case 'host':
  1322. case 'hostname':
  1323. if (c === ':' && !seenBracket) {
  1324. this._host = IDNAToASCII.call(this, buffer);
  1325. buffer = '';
  1326. state = 'port';
  1327. if (stateOverride === 'hostname') {
  1328. break loop;
  1329. }
  1330. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1331. this._host = IDNAToASCII.call(this, buffer);
  1332. buffer = '';
  1333. state = 'relative path start';
  1334. if (stateOverride) {
  1335. break loop;
  1336. }
  1337. continue;
  1338. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1339. if (c === '[') {
  1340. seenBracket = true;
  1341. } else if (c === ']') {
  1342. seenBracket = false;
  1343. }
  1344. buffer += c;
  1345. } else {
  1346. err('Invalid code point in host/hostname: ' + c);
  1347. }
  1348. break;
  1349. case 'port':
  1350. if (/[0-9]/.test(c)) {
  1351. buffer += c;
  1352. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1353. if (buffer !== '') {
  1354. var temp = parseInt(buffer, 10);
  1355. if (temp !== relative[this._scheme]) {
  1356. this._port = temp + '';
  1357. }
  1358. buffer = '';
  1359. }
  1360. if (stateOverride) {
  1361. break loop;
  1362. }
  1363. state = 'relative path start';
  1364. continue;
  1365. } else if (c === '\t' || c === '\n' || c === '\r') {
  1366. err('Invalid code point in port: ' + c);
  1367. } else {
  1368. invalid.call(this);
  1369. }
  1370. break;
  1371. case 'relative path start':
  1372. if (c === '\\') {
  1373. err('\'\\\' not allowed in path.');
  1374. }
  1375. state = 'relative path';
  1376. if (c !== '/' && c !== '\\') {
  1377. continue;
  1378. }
  1379. break;
  1380. case 'relative path':
  1381. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1382. if (c === '\\') {
  1383. err('\\ not allowed in relative path.');
  1384. }
  1385. var tmp;
  1386. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1387. buffer = tmp;
  1388. }
  1389. if (buffer === '..') {
  1390. this._path.pop();
  1391. if (c !== '/' && c !== '\\') {
  1392. this._path.push('');
  1393. }
  1394. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  1395. this._path.push('');
  1396. } else if (buffer !== '.') {
  1397. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1398. buffer = buffer[0] + ':';
  1399. }
  1400. this._path.push(buffer);
  1401. }
  1402. buffer = '';
  1403. if (c === '?') {
  1404. this._query = '?';
  1405. state = 'query';
  1406. } else if (c === '#') {
  1407. this._fragment = '#';
  1408. state = 'fragment';
  1409. }
  1410. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1411. buffer += percentEscape(c);
  1412. }
  1413. break;
  1414. case 'query':
  1415. if (!stateOverride && c === '#') {
  1416. this._fragment = '#';
  1417. state = 'fragment';
  1418. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1419. this._query += percentEscapeQuery(c);
  1420. }
  1421. break;
  1422. case 'fragment':
  1423. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1424. this._fragment += c;
  1425. }
  1426. break;
  1427. }
  1428. cursor++;
  1429. }
  1430. }
  1431. function clear() {
  1432. this._scheme = '';
  1433. this._schemeData = '';
  1434. this._username = '';
  1435. this._password = null;
  1436. this._host = '';
  1437. this._port = '';
  1438. this._path = [];
  1439. this._query = '';
  1440. this._fragment = '';
  1441. this._isInvalid = false;
  1442. this._isRelative = false;
  1443. }
  1444. function JURL(url, base) {
  1445. if (base !== undefined && !(base instanceof JURL)) {
  1446. base = new JURL(String(base));
  1447. }
  1448. this._url = url;
  1449. clear.call(this);
  1450. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1451. parse.call(this, input, null, base);
  1452. }
  1453. JURL.prototype = {
  1454. toString: function toString() {
  1455. return this.href;
  1456. },
  1457. get href() {
  1458. if (this._isInvalid) {
  1459. return this._url;
  1460. }
  1461. var authority = '';
  1462. if (this._username !== '' || this._password !== null) {
  1463. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  1464. }
  1465. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1466. },
  1467. set href(href) {
  1468. clear.call(this);
  1469. parse.call(this, href);
  1470. },
  1471. get protocol() {
  1472. return this._scheme + ':';
  1473. },
  1474. set protocol(protocol) {
  1475. if (this._isInvalid) {
  1476. return;
  1477. }
  1478. parse.call(this, protocol + ':', 'scheme start');
  1479. },
  1480. get host() {
  1481. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1482. },
  1483. set host(host) {
  1484. if (this._isInvalid || !this._isRelative) {
  1485. return;
  1486. }
  1487. parse.call(this, host, 'host');
  1488. },
  1489. get hostname() {
  1490. return this._host;
  1491. },
  1492. set hostname(hostname) {
  1493. if (this._isInvalid || !this._isRelative) {
  1494. return;
  1495. }
  1496. parse.call(this, hostname, 'hostname');
  1497. },
  1498. get port() {
  1499. return this._port;
  1500. },
  1501. set port(port) {
  1502. if (this._isInvalid || !this._isRelative) {
  1503. return;
  1504. }
  1505. parse.call(this, port, 'port');
  1506. },
  1507. get pathname() {
  1508. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1509. },
  1510. set pathname(pathname) {
  1511. if (this._isInvalid || !this._isRelative) {
  1512. return;
  1513. }
  1514. this._path = [];
  1515. parse.call(this, pathname, 'relative path start');
  1516. },
  1517. get search() {
  1518. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1519. },
  1520. set search(search) {
  1521. if (this._isInvalid || !this._isRelative) {
  1522. return;
  1523. }
  1524. this._query = '?';
  1525. if (search[0] === '?') {
  1526. search = search.slice(1);
  1527. }
  1528. parse.call(this, search, 'query');
  1529. },
  1530. get hash() {
  1531. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1532. },
  1533. set hash(hash) {
  1534. if (this._isInvalid) {
  1535. return;
  1536. }
  1537. this._fragment = '#';
  1538. if (hash[0] === '#') {
  1539. hash = hash.slice(1);
  1540. }
  1541. parse.call(this, hash, 'fragment');
  1542. },
  1543. get origin() {
  1544. var host;
  1545. if (this._isInvalid || !this._scheme) {
  1546. return '';
  1547. }
  1548. switch (this._scheme) {
  1549. case 'data':
  1550. case 'file':
  1551. case 'javascript':
  1552. case 'mailto':
  1553. return 'null';
  1554. }
  1555. host = this.host;
  1556. if (!host) {
  1557. return '';
  1558. }
  1559. return this._scheme + '://' + host;
  1560. }
  1561. };
  1562. var OriginalURL = globalScope.URL;
  1563. if (OriginalURL) {
  1564. JURL.createObjectURL = function (blob) {
  1565. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1566. };
  1567. JURL.revokeObjectURL = function (url) {
  1568. OriginalURL.revokeObjectURL(url);
  1569. };
  1570. }
  1571. globalScope.URL = JURL;
  1572. })();
  1573. }
  1574. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
  1575. /***/ }),
  1576. /* 1 */
  1577. /***/ (function(module, exports, __webpack_require__) {
  1578. "use strict";
  1579. 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; };
  1580. var g;
  1581. g = function () {
  1582. return this;
  1583. }();
  1584. try {
  1585. g = g || Function("return this")() || (1, eval)("this");
  1586. } catch (e) {
  1587. if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "object") g = window;
  1588. }
  1589. module.exports = g;
  1590. /***/ }),
  1591. /* 2 */
  1592. /***/ (function(module, exports, __webpack_require__) {
  1593. "use strict";
  1594. __webpack_require__(0);
  1595. /***/ })
  1596. /******/ ]);
  1597. });