2
0

compatibility.js 42 KB

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