compatibility.js 48 KB

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