compatibility.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  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 installFakeAnimationFrameFunctions() {
  570. window.requestAnimationFrame = function (callback) {
  571. return window.setTimeout(callback, 20);
  572. };
  573. window.cancelAnimationFrame = function (timeoutID) {
  574. window.clearTimeout(timeoutID);
  575. };
  576. }
  577. if (!hasDOM) {
  578. return;
  579. }
  580. if (isIOS) {
  581. installFakeAnimationFrameFunctions();
  582. return;
  583. }
  584. if ('requestAnimationFrame' in window) {
  585. return;
  586. }
  587. window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;
  588. if (window.requestAnimationFrame) {
  589. return;
  590. }
  591. installFakeAnimationFrameFunctions();
  592. })();
  593. (function checkCanvasSizeLimitation() {
  594. if (isIOS || isAndroid) {
  595. PDFJS.maxCanvasPixels = 5242880;
  596. }
  597. })();
  598. (function checkFullscreenSupport() {
  599. if (!hasDOM) {
  600. return;
  601. }
  602. if (isIE && window.parent !== window) {
  603. PDFJS.disableFullscreen = true;
  604. }
  605. })();
  606. (function checkCurrentScript() {
  607. if (!hasDOM) {
  608. return;
  609. }
  610. if ('currentScript' in document) {
  611. return;
  612. }
  613. Object.defineProperty(document, 'currentScript', {
  614. get: function () {
  615. var scripts = document.getElementsByTagName('script');
  616. return scripts[scripts.length - 1];
  617. },
  618. enumerable: true,
  619. configurable: true
  620. });
  621. })();
  622. (function checkInputTypeNumberAssign() {
  623. if (!hasDOM) {
  624. return;
  625. }
  626. var el = document.createElement('input');
  627. try {
  628. el.type = 'number';
  629. } catch (ex) {
  630. var inputProto = el.constructor.prototype;
  631. var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
  632. Object.defineProperty(inputProto, 'type', {
  633. get: function () {
  634. return typeProperty.get.call(this);
  635. },
  636. set: function (value) {
  637. typeProperty.set.call(this, value === 'number' ? 'text' : value);
  638. },
  639. enumerable: true,
  640. configurable: true
  641. });
  642. }
  643. })();
  644. (function checkDocumentReadyState() {
  645. if (!hasDOM) {
  646. return;
  647. }
  648. if (!document.attachEvent) {
  649. return;
  650. }
  651. var documentProto = document.constructor.prototype;
  652. var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState');
  653. Object.defineProperty(documentProto, 'readyState', {
  654. get: function () {
  655. var value = readyStateProto.get.call(this);
  656. return value === 'interactive' ? 'loading' : value;
  657. },
  658. set: function (value) {
  659. readyStateProto.set.call(this, value);
  660. },
  661. enumerable: true,
  662. configurable: true
  663. });
  664. })();
  665. (function checkChildNodeRemove() {
  666. if (!hasDOM) {
  667. return;
  668. }
  669. if (typeof Element.prototype.remove !== 'undefined') {
  670. return;
  671. }
  672. Element.prototype.remove = function () {
  673. if (this.parentNode) {
  674. this.parentNode.removeChild(this);
  675. }
  676. };
  677. })();
  678. (function checkPromise() {
  679. if (globalScope.Promise) {
  680. if (typeof globalScope.Promise.all !== 'function') {
  681. globalScope.Promise.all = function (iterable) {
  682. var count = 0,
  683. results = [],
  684. resolve,
  685. reject;
  686. var promise = new globalScope.Promise(function (resolve_, reject_) {
  687. resolve = resolve_;
  688. reject = reject_;
  689. });
  690. iterable.forEach(function (p, i) {
  691. count++;
  692. p.then(function (result) {
  693. results[i] = result;
  694. count--;
  695. if (count === 0) {
  696. resolve(results);
  697. }
  698. }, reject);
  699. });
  700. if (count === 0) {
  701. resolve(results);
  702. }
  703. return promise;
  704. };
  705. }
  706. if (typeof globalScope.Promise.resolve !== 'function') {
  707. globalScope.Promise.resolve = function (value) {
  708. return new globalScope.Promise(function (resolve) {
  709. resolve(value);
  710. });
  711. };
  712. }
  713. if (typeof globalScope.Promise.reject !== 'function') {
  714. globalScope.Promise.reject = function (reason) {
  715. return new globalScope.Promise(function (resolve, reject) {
  716. reject(reason);
  717. });
  718. };
  719. }
  720. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  721. globalScope.Promise.prototype.catch = function (onReject) {
  722. return globalScope.Promise.prototype.then(undefined, onReject);
  723. };
  724. }
  725. return;
  726. }
  727. var STATUS_PENDING = 0;
  728. var STATUS_RESOLVED = 1;
  729. var STATUS_REJECTED = 2;
  730. var REJECTION_TIMEOUT = 500;
  731. var HandlerManager = {
  732. handlers: [],
  733. running: false,
  734. unhandledRejections: [],
  735. pendingRejectionCheck: false,
  736. scheduleHandlers: function scheduleHandlers(promise) {
  737. if (promise._status === STATUS_PENDING) {
  738. return;
  739. }
  740. this.handlers = this.handlers.concat(promise._handlers);
  741. promise._handlers = [];
  742. if (this.running) {
  743. return;
  744. }
  745. this.running = true;
  746. setTimeout(this.runHandlers.bind(this), 0);
  747. },
  748. runHandlers: function runHandlers() {
  749. var RUN_TIMEOUT = 1;
  750. var timeoutAt = Date.now() + RUN_TIMEOUT;
  751. while (this.handlers.length > 0) {
  752. var handler = this.handlers.shift();
  753. var nextStatus = handler.thisPromise._status;
  754. var nextValue = handler.thisPromise._value;
  755. try {
  756. if (nextStatus === STATUS_RESOLVED) {
  757. if (typeof handler.onResolve === 'function') {
  758. nextValue = handler.onResolve(nextValue);
  759. }
  760. } else if (typeof handler.onReject === 'function') {
  761. nextValue = handler.onReject(nextValue);
  762. nextStatus = STATUS_RESOLVED;
  763. if (handler.thisPromise._unhandledRejection) {
  764. this.removeUnhandeledRejection(handler.thisPromise);
  765. }
  766. }
  767. } catch (ex) {
  768. nextStatus = STATUS_REJECTED;
  769. nextValue = ex;
  770. }
  771. handler.nextPromise._updateStatus(nextStatus, nextValue);
  772. if (Date.now() >= timeoutAt) {
  773. break;
  774. }
  775. }
  776. if (this.handlers.length > 0) {
  777. setTimeout(this.runHandlers.bind(this), 0);
  778. return;
  779. }
  780. this.running = false;
  781. },
  782. addUnhandledRejection: function addUnhandledRejection(promise) {
  783. this.unhandledRejections.push({
  784. promise: promise,
  785. time: Date.now()
  786. });
  787. this.scheduleRejectionCheck();
  788. },
  789. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  790. promise._unhandledRejection = false;
  791. for (var i = 0; i < this.unhandledRejections.length; i++) {
  792. if (this.unhandledRejections[i].promise === promise) {
  793. this.unhandledRejections.splice(i);
  794. i--;
  795. }
  796. }
  797. },
  798. scheduleRejectionCheck: function scheduleRejectionCheck() {
  799. if (this.pendingRejectionCheck) {
  800. return;
  801. }
  802. this.pendingRejectionCheck = true;
  803. setTimeout(function rejectionCheck() {
  804. this.pendingRejectionCheck = false;
  805. var now = Date.now();
  806. for (var i = 0; i < this.unhandledRejections.length; i++) {
  807. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  808. var unhandled = this.unhandledRejections[i].promise._value;
  809. var msg = 'Unhandled rejection: ' + unhandled;
  810. if (unhandled.stack) {
  811. msg += '\n' + unhandled.stack;
  812. }
  813. try {
  814. throw new Error(msg);
  815. } catch (_) {
  816. console.warn(msg);
  817. }
  818. this.unhandledRejections.splice(i);
  819. i--;
  820. }
  821. }
  822. if (this.unhandledRejections.length) {
  823. this.scheduleRejectionCheck();
  824. }
  825. }.bind(this), REJECTION_TIMEOUT);
  826. }
  827. };
  828. var Promise = function Promise(resolver) {
  829. this._status = STATUS_PENDING;
  830. this._handlers = [];
  831. try {
  832. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  833. } catch (e) {
  834. this._reject(e);
  835. }
  836. };
  837. Promise.all = function Promise_all(promises) {
  838. var resolveAll, rejectAll;
  839. var deferred = new Promise(function (resolve, reject) {
  840. resolveAll = resolve;
  841. rejectAll = reject;
  842. });
  843. var unresolved = promises.length;
  844. var results = [];
  845. if (unresolved === 0) {
  846. resolveAll(results);
  847. return deferred;
  848. }
  849. function reject(reason) {
  850. if (deferred._status === STATUS_REJECTED) {
  851. return;
  852. }
  853. results = [];
  854. rejectAll(reason);
  855. }
  856. for (var i = 0, ii = promises.length; i < ii; ++i) {
  857. var promise = promises[i];
  858. var resolve = function (i) {
  859. return function (value) {
  860. if (deferred._status === STATUS_REJECTED) {
  861. return;
  862. }
  863. results[i] = value;
  864. unresolved--;
  865. if (unresolved === 0) {
  866. resolveAll(results);
  867. }
  868. };
  869. }(i);
  870. if (Promise.isPromise(promise)) {
  871. promise.then(resolve, reject);
  872. } else {
  873. resolve(promise);
  874. }
  875. }
  876. return deferred;
  877. };
  878. Promise.isPromise = function Promise_isPromise(value) {
  879. return value && typeof value.then === 'function';
  880. };
  881. Promise.resolve = function Promise_resolve(value) {
  882. return new Promise(function (resolve) {
  883. resolve(value);
  884. });
  885. };
  886. Promise.reject = function Promise_reject(reason) {
  887. return new Promise(function (resolve, reject) {
  888. reject(reason);
  889. });
  890. };
  891. Promise.prototype = {
  892. _status: null,
  893. _value: null,
  894. _handlers: null,
  895. _unhandledRejection: null,
  896. _updateStatus: function Promise__updateStatus(status, value) {
  897. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  898. return;
  899. }
  900. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  901. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  902. return;
  903. }
  904. this._status = status;
  905. this._value = value;
  906. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  907. this._unhandledRejection = true;
  908. HandlerManager.addUnhandledRejection(this);
  909. }
  910. HandlerManager.scheduleHandlers(this);
  911. },
  912. _resolve: function Promise_resolve(value) {
  913. this._updateStatus(STATUS_RESOLVED, value);
  914. },
  915. _reject: function Promise_reject(reason) {
  916. this._updateStatus(STATUS_REJECTED, reason);
  917. },
  918. then: function Promise_then(onResolve, onReject) {
  919. var nextPromise = new Promise(function (resolve, reject) {
  920. this.resolve = resolve;
  921. this.reject = reject;
  922. });
  923. this._handlers.push({
  924. thisPromise: this,
  925. onResolve: onResolve,
  926. onReject: onReject,
  927. nextPromise: nextPromise
  928. });
  929. HandlerManager.scheduleHandlers(this);
  930. return nextPromise;
  931. },
  932. catch: function Promise_catch(onReject) {
  933. return this.then(undefined, onReject);
  934. }
  935. };
  936. globalScope.Promise = Promise;
  937. })();
  938. (function checkWeakMap() {
  939. if (globalScope.WeakMap) {
  940. return;
  941. }
  942. var id = 0;
  943. function WeakMap() {
  944. this.id = '$weakmap' + id++;
  945. }
  946. WeakMap.prototype = {
  947. has: function (obj) {
  948. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  949. },
  950. get: function (obj, defaultValue) {
  951. return this.has(obj) ? obj[this.id] : defaultValue;
  952. },
  953. set: function (obj, value) {
  954. Object.defineProperty(obj, this.id, {
  955. value: value,
  956. enumerable: false,
  957. configurable: true
  958. });
  959. },
  960. delete: function (obj) {
  961. delete obj[this.id];
  962. }
  963. };
  964. globalScope.WeakMap = WeakMap;
  965. })();
  966. (function checkURLConstructor() {
  967. var hasWorkingUrl = false;
  968. try {
  969. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  970. var u = new URL('b', 'http://a');
  971. u.pathname = 'c%20d';
  972. hasWorkingUrl = u.href === 'http://a/c%20d';
  973. }
  974. } catch (e) {}
  975. if (hasWorkingUrl) {
  976. return;
  977. }
  978. var relative = Object.create(null);
  979. relative['ftp'] = 21;
  980. relative['file'] = 0;
  981. relative['gopher'] = 70;
  982. relative['http'] = 80;
  983. relative['https'] = 443;
  984. relative['ws'] = 80;
  985. relative['wss'] = 443;
  986. var relativePathDotMapping = Object.create(null);
  987. relativePathDotMapping['%2e'] = '.';
  988. relativePathDotMapping['.%2e'] = '..';
  989. relativePathDotMapping['%2e.'] = '..';
  990. relativePathDotMapping['%2e%2e'] = '..';
  991. function isRelativeScheme(scheme) {
  992. return relative[scheme] !== undefined;
  993. }
  994. function invalid() {
  995. clear.call(this);
  996. this._isInvalid = true;
  997. }
  998. function IDNAToASCII(h) {
  999. if (h === '') {
  1000. invalid.call(this);
  1001. }
  1002. return h.toLowerCase();
  1003. }
  1004. function percentEscape(c) {
  1005. var unicode = c.charCodeAt(0);
  1006. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  1007. return c;
  1008. }
  1009. return encodeURIComponent(c);
  1010. }
  1011. function percentEscapeQuery(c) {
  1012. var unicode = c.charCodeAt(0);
  1013. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  1014. return c;
  1015. }
  1016. return encodeURIComponent(c);
  1017. }
  1018. var EOF,
  1019. ALPHA = /[a-zA-Z]/,
  1020. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  1021. function parse(input, stateOverride, base) {
  1022. function err(message) {
  1023. errors.push(message);
  1024. }
  1025. var state = stateOverride || 'scheme start',
  1026. cursor = 0,
  1027. buffer = '',
  1028. seenAt = false,
  1029. seenBracket = false,
  1030. errors = [];
  1031. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  1032. var c = input[cursor];
  1033. switch (state) {
  1034. case 'scheme start':
  1035. if (c && ALPHA.test(c)) {
  1036. buffer += c.toLowerCase();
  1037. state = 'scheme';
  1038. } else if (!stateOverride) {
  1039. buffer = '';
  1040. state = 'no scheme';
  1041. continue;
  1042. } else {
  1043. err('Invalid scheme.');
  1044. break loop;
  1045. }
  1046. break;
  1047. case 'scheme':
  1048. if (c && ALPHANUMERIC.test(c)) {
  1049. buffer += c.toLowerCase();
  1050. } else if (c === ':') {
  1051. this._scheme = buffer;
  1052. buffer = '';
  1053. if (stateOverride) {
  1054. break loop;
  1055. }
  1056. if (isRelativeScheme(this._scheme)) {
  1057. this._isRelative = true;
  1058. }
  1059. if (this._scheme === 'file') {
  1060. state = 'relative';
  1061. } else if (this._isRelative && base && base._scheme === this._scheme) {
  1062. state = 'relative or authority';
  1063. } else if (this._isRelative) {
  1064. state = 'authority first slash';
  1065. } else {
  1066. state = 'scheme data';
  1067. }
  1068. } else if (!stateOverride) {
  1069. buffer = '';
  1070. cursor = 0;
  1071. state = 'no scheme';
  1072. continue;
  1073. } else if (c === EOF) {
  1074. break loop;
  1075. } else {
  1076. err('Code point not allowed in scheme: ' + c);
  1077. break loop;
  1078. }
  1079. break;
  1080. case 'scheme data':
  1081. if (c === '?') {
  1082. this._query = '?';
  1083. state = 'query';
  1084. } else if (c === '#') {
  1085. this._fragment = '#';
  1086. state = 'fragment';
  1087. } else {
  1088. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1089. this._schemeData += percentEscape(c);
  1090. }
  1091. }
  1092. break;
  1093. case 'no scheme':
  1094. if (!base || !isRelativeScheme(base._scheme)) {
  1095. err('Missing scheme.');
  1096. invalid.call(this);
  1097. } else {
  1098. state = 'relative';
  1099. continue;
  1100. }
  1101. break;
  1102. case 'relative or authority':
  1103. if (c === '/' && input[cursor + 1] === '/') {
  1104. state = 'authority ignore slashes';
  1105. } else {
  1106. err('Expected /, got: ' + c);
  1107. state = 'relative';
  1108. continue;
  1109. }
  1110. break;
  1111. case 'relative':
  1112. this._isRelative = true;
  1113. if (this._scheme !== 'file') {
  1114. this._scheme = base._scheme;
  1115. }
  1116. if (c === EOF) {
  1117. this._host = base._host;
  1118. this._port = base._port;
  1119. this._path = base._path.slice();
  1120. this._query = base._query;
  1121. this._username = base._username;
  1122. this._password = base._password;
  1123. break loop;
  1124. } else if (c === '/' || c === '\\') {
  1125. if (c === '\\') {
  1126. err('\\ is an invalid code point.');
  1127. }
  1128. state = 'relative slash';
  1129. } else if (c === '?') {
  1130. this._host = base._host;
  1131. this._port = base._port;
  1132. this._path = base._path.slice();
  1133. this._query = '?';
  1134. this._username = base._username;
  1135. this._password = base._password;
  1136. state = 'query';
  1137. } else if (c === '#') {
  1138. this._host = base._host;
  1139. this._port = base._port;
  1140. this._path = base._path.slice();
  1141. this._query = base._query;
  1142. this._fragment = '#';
  1143. this._username = base._username;
  1144. this._password = base._password;
  1145. state = 'fragment';
  1146. } else {
  1147. var nextC = input[cursor + 1];
  1148. var nextNextC = input[cursor + 2];
  1149. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  1150. this._host = base._host;
  1151. this._port = base._port;
  1152. this._username = base._username;
  1153. this._password = base._password;
  1154. this._path = base._path.slice();
  1155. this._path.pop();
  1156. }
  1157. state = 'relative path';
  1158. continue;
  1159. }
  1160. break;
  1161. case 'relative slash':
  1162. if (c === '/' || c === '\\') {
  1163. if (c === '\\') {
  1164. err('\\ is an invalid code point.');
  1165. }
  1166. if (this._scheme === 'file') {
  1167. state = 'file host';
  1168. } else {
  1169. state = 'authority ignore slashes';
  1170. }
  1171. } else {
  1172. if (this._scheme !== 'file') {
  1173. this._host = base._host;
  1174. this._port = base._port;
  1175. this._username = base._username;
  1176. this._password = base._password;
  1177. }
  1178. state = 'relative path';
  1179. continue;
  1180. }
  1181. break;
  1182. case 'authority first slash':
  1183. if (c === '/') {
  1184. state = 'authority second slash';
  1185. } else {
  1186. err('Expected \'/\', got: ' + c);
  1187. state = 'authority ignore slashes';
  1188. continue;
  1189. }
  1190. break;
  1191. case 'authority second slash':
  1192. state = 'authority ignore slashes';
  1193. if (c !== '/') {
  1194. err('Expected \'/\', got: ' + c);
  1195. continue;
  1196. }
  1197. break;
  1198. case 'authority ignore slashes':
  1199. if (c !== '/' && c !== '\\') {
  1200. state = 'authority';
  1201. continue;
  1202. } else {
  1203. err('Expected authority, got: ' + c);
  1204. }
  1205. break;
  1206. case 'authority':
  1207. if (c === '@') {
  1208. if (seenAt) {
  1209. err('@ already seen.');
  1210. buffer += '%40';
  1211. }
  1212. seenAt = true;
  1213. for (var i = 0; i < buffer.length; i++) {
  1214. var cp = buffer[i];
  1215. if (cp === '\t' || cp === '\n' || cp === '\r') {
  1216. err('Invalid whitespace in authority.');
  1217. continue;
  1218. }
  1219. if (cp === ':' && this._password === null) {
  1220. this._password = '';
  1221. continue;
  1222. }
  1223. var tempC = percentEscape(cp);
  1224. if (this._password !== null) {
  1225. this._password += tempC;
  1226. } else {
  1227. this._username += tempC;
  1228. }
  1229. }
  1230. buffer = '';
  1231. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1232. cursor -= buffer.length;
  1233. buffer = '';
  1234. state = 'host';
  1235. continue;
  1236. } else {
  1237. buffer += c;
  1238. }
  1239. break;
  1240. case 'file host':
  1241. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1242. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  1243. state = 'relative path';
  1244. } else if (buffer.length === 0) {
  1245. state = 'relative path start';
  1246. } else {
  1247. this._host = IDNAToASCII.call(this, buffer);
  1248. buffer = '';
  1249. state = 'relative path start';
  1250. }
  1251. continue;
  1252. } else if (c === '\t' || c === '\n' || c === '\r') {
  1253. err('Invalid whitespace in file host.');
  1254. } else {
  1255. buffer += c;
  1256. }
  1257. break;
  1258. case 'host':
  1259. case 'hostname':
  1260. if (c === ':' && !seenBracket) {
  1261. this._host = IDNAToASCII.call(this, buffer);
  1262. buffer = '';
  1263. state = 'port';
  1264. if (stateOverride === 'hostname') {
  1265. break loop;
  1266. }
  1267. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1268. this._host = IDNAToASCII.call(this, buffer);
  1269. buffer = '';
  1270. state = 'relative path start';
  1271. if (stateOverride) {
  1272. break loop;
  1273. }
  1274. continue;
  1275. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1276. if (c === '[') {
  1277. seenBracket = true;
  1278. } else if (c === ']') {
  1279. seenBracket = false;
  1280. }
  1281. buffer += c;
  1282. } else {
  1283. err('Invalid code point in host/hostname: ' + c);
  1284. }
  1285. break;
  1286. case 'port':
  1287. if (/[0-9]/.test(c)) {
  1288. buffer += c;
  1289. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1290. if (buffer !== '') {
  1291. var temp = parseInt(buffer, 10);
  1292. if (temp !== relative[this._scheme]) {
  1293. this._port = temp + '';
  1294. }
  1295. buffer = '';
  1296. }
  1297. if (stateOverride) {
  1298. break loop;
  1299. }
  1300. state = 'relative path start';
  1301. continue;
  1302. } else if (c === '\t' || c === '\n' || c === '\r') {
  1303. err('Invalid code point in port: ' + c);
  1304. } else {
  1305. invalid.call(this);
  1306. }
  1307. break;
  1308. case 'relative path start':
  1309. if (c === '\\') {
  1310. err('\'\\\' not allowed in path.');
  1311. }
  1312. state = 'relative path';
  1313. if (c !== '/' && c !== '\\') {
  1314. continue;
  1315. }
  1316. break;
  1317. case 'relative path':
  1318. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1319. if (c === '\\') {
  1320. err('\\ not allowed in relative path.');
  1321. }
  1322. var tmp;
  1323. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1324. buffer = tmp;
  1325. }
  1326. if (buffer === '..') {
  1327. this._path.pop();
  1328. if (c !== '/' && c !== '\\') {
  1329. this._path.push('');
  1330. }
  1331. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  1332. this._path.push('');
  1333. } else if (buffer !== '.') {
  1334. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1335. buffer = buffer[0] + ':';
  1336. }
  1337. this._path.push(buffer);
  1338. }
  1339. buffer = '';
  1340. if (c === '?') {
  1341. this._query = '?';
  1342. state = 'query';
  1343. } else if (c === '#') {
  1344. this._fragment = '#';
  1345. state = 'fragment';
  1346. }
  1347. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1348. buffer += percentEscape(c);
  1349. }
  1350. break;
  1351. case 'query':
  1352. if (!stateOverride && c === '#') {
  1353. this._fragment = '#';
  1354. state = 'fragment';
  1355. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1356. this._query += percentEscapeQuery(c);
  1357. }
  1358. break;
  1359. case 'fragment':
  1360. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1361. this._fragment += c;
  1362. }
  1363. break;
  1364. }
  1365. cursor++;
  1366. }
  1367. }
  1368. function clear() {
  1369. this._scheme = '';
  1370. this._schemeData = '';
  1371. this._username = '';
  1372. this._password = null;
  1373. this._host = '';
  1374. this._port = '';
  1375. this._path = [];
  1376. this._query = '';
  1377. this._fragment = '';
  1378. this._isInvalid = false;
  1379. this._isRelative = false;
  1380. }
  1381. function JURL(url, base) {
  1382. if (base !== undefined && !(base instanceof JURL)) {
  1383. base = new JURL(String(base));
  1384. }
  1385. this._url = url;
  1386. clear.call(this);
  1387. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1388. parse.call(this, input, null, base);
  1389. }
  1390. JURL.prototype = {
  1391. toString: function () {
  1392. return this.href;
  1393. },
  1394. get href() {
  1395. if (this._isInvalid) {
  1396. return this._url;
  1397. }
  1398. var authority = '';
  1399. if (this._username !== '' || this._password !== null) {
  1400. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  1401. }
  1402. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1403. },
  1404. set href(href) {
  1405. clear.call(this);
  1406. parse.call(this, href);
  1407. },
  1408. get protocol() {
  1409. return this._scheme + ':';
  1410. },
  1411. set protocol(protocol) {
  1412. if (this._isInvalid) {
  1413. return;
  1414. }
  1415. parse.call(this, protocol + ':', 'scheme start');
  1416. },
  1417. get host() {
  1418. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1419. },
  1420. set host(host) {
  1421. if (this._isInvalid || !this._isRelative) {
  1422. return;
  1423. }
  1424. parse.call(this, host, 'host');
  1425. },
  1426. get hostname() {
  1427. return this._host;
  1428. },
  1429. set hostname(hostname) {
  1430. if (this._isInvalid || !this._isRelative) {
  1431. return;
  1432. }
  1433. parse.call(this, hostname, 'hostname');
  1434. },
  1435. get port() {
  1436. return this._port;
  1437. },
  1438. set port(port) {
  1439. if (this._isInvalid || !this._isRelative) {
  1440. return;
  1441. }
  1442. parse.call(this, port, 'port');
  1443. },
  1444. get pathname() {
  1445. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1446. },
  1447. set pathname(pathname) {
  1448. if (this._isInvalid || !this._isRelative) {
  1449. return;
  1450. }
  1451. this._path = [];
  1452. parse.call(this, pathname, 'relative path start');
  1453. },
  1454. get search() {
  1455. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1456. },
  1457. set search(search) {
  1458. if (this._isInvalid || !this._isRelative) {
  1459. return;
  1460. }
  1461. this._query = '?';
  1462. if (search[0] === '?') {
  1463. search = search.slice(1);
  1464. }
  1465. parse.call(this, search, 'query');
  1466. },
  1467. get hash() {
  1468. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1469. },
  1470. set hash(hash) {
  1471. if (this._isInvalid) {
  1472. return;
  1473. }
  1474. this._fragment = '#';
  1475. if (hash[0] === '#') {
  1476. hash = hash.slice(1);
  1477. }
  1478. parse.call(this, hash, 'fragment');
  1479. },
  1480. get origin() {
  1481. var host;
  1482. if (this._isInvalid || !this._scheme) {
  1483. return '';
  1484. }
  1485. switch (this._scheme) {
  1486. case 'data':
  1487. case 'file':
  1488. case 'javascript':
  1489. case 'mailto':
  1490. return 'null';
  1491. }
  1492. host = this.host;
  1493. if (!host) {
  1494. return '';
  1495. }
  1496. return this._scheme + '://' + host;
  1497. }
  1498. };
  1499. var OriginalURL = globalScope.URL;
  1500. if (OriginalURL) {
  1501. JURL.createObjectURL = function (blob) {
  1502. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1503. };
  1504. JURL.revokeObjectURL = function (url) {
  1505. OriginalURL.revokeObjectURL(url);
  1506. };
  1507. }
  1508. globalScope.URL = JURL;
  1509. })();
  1510. }
  1511. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
  1512. /***/ }),
  1513. /* 1 */
  1514. /***/ (function(module, exports, __webpack_require__) {
  1515. "use strict";
  1516. var g;
  1517. g = function () {
  1518. return this;
  1519. }();
  1520. try {
  1521. g = g || Function("return this")() || (1, eval)("this");
  1522. } catch (e) {
  1523. if (typeof window === "object") g = window;
  1524. }
  1525. module.exports = g;
  1526. /***/ }),
  1527. /* 2 */
  1528. /***/ (function(module, exports, __webpack_require__) {
  1529. "use strict";
  1530. __webpack_require__(0);
  1531. /***/ })
  1532. /******/ ]);
  1533. });