compatibility.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. (function webpackUniversalModuleDefinition(root, factory) {
  16. if(typeof exports === 'object' && typeof module === 'object')
  17. module.exports = factory();
  18. else if(typeof define === 'function' && define.amd)
  19. define("pdfjs-dist/web/compatibility", [], factory);
  20. else if(typeof exports === 'object')
  21. exports["pdfjs-dist/web/compatibility"] = factory();
  22. else
  23. root["pdfjs-dist/web/compatibility"] = factory();
  24. })(this, function() {
  25. return /******/ (function(modules) { // webpackBootstrap
  26. /******/ // The module cache
  27. /******/ var installedModules = {};
  28. /******/
  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 : this;
  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. };
  188. Test.prototype = {
  189. get id() {
  190. }
  191. };
  192. Object.defineProperty(new Test(), 'id', {
  193. value: '',
  194. configurable: true,
  195. enumerable: true,
  196. writable: false
  197. });
  198. } catch (e) {
  199. definePropertyPossible = false;
  200. }
  201. if (definePropertyPossible) {
  202. return;
  203. }
  204. }
  205. Object.defineProperty = function objectDefineProperty(obj, name, def) {
  206. delete obj[name];
  207. if ('get' in def) {
  208. obj.__defineGetter__(name, def['get']);
  209. }
  210. if ('set' in def) {
  211. obj.__defineSetter__(name, def['set']);
  212. }
  213. if ('value' in def) {
  214. obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
  215. this.__defineGetter__(name, function objectDefinePropertyGetter() {
  216. return value;
  217. });
  218. return value;
  219. });
  220. obj[name] = def.value;
  221. }
  222. };
  223. }());
  224. (function checkXMLHttpRequestResponseCompatibility() {
  225. if (typeof XMLHttpRequest === 'undefined') {
  226. return;
  227. }
  228. var xhrPrototype = XMLHttpRequest.prototype;
  229. var xhr = new XMLHttpRequest();
  230. if (!('overrideMimeType' in xhr)) {
  231. Object.defineProperty(xhrPrototype, 'overrideMimeType', {
  232. value: function xmlHttpRequestOverrideMimeType(mimeType) {
  233. }
  234. });
  235. }
  236. if ('responseType' in xhr) {
  237. return;
  238. }
  239. Object.defineProperty(xhrPrototype, 'responseType', {
  240. get: function xmlHttpRequestGetResponseType() {
  241. return this._responseType || 'text';
  242. },
  243. set: function xmlHttpRequestSetResponseType(value) {
  244. if (value === 'text' || value === 'arraybuffer') {
  245. this._responseType = value;
  246. if (value === 'arraybuffer' && typeof this.overrideMimeType === 'function') {
  247. this.overrideMimeType('text/plain; charset=x-user-defined');
  248. }
  249. }
  250. }
  251. });
  252. if (typeof VBArray !== 'undefined') {
  253. Object.defineProperty(xhrPrototype, 'response', {
  254. get: function xmlHttpRequestResponseGet() {
  255. if (this.responseType === 'arraybuffer') {
  256. return new Uint8Array(new VBArray(this.responseBody).toArray());
  257. }
  258. return this.responseText;
  259. }
  260. });
  261. return;
  262. }
  263. Object.defineProperty(xhrPrototype, 'response', {
  264. get: function xmlHttpRequestResponseGet() {
  265. if (this.responseType !== 'arraybuffer') {
  266. return this.responseText;
  267. }
  268. var text = this.responseText;
  269. var i, n = text.length;
  270. var result = new Uint8Array(n);
  271. for (i = 0; i < n; ++i) {
  272. result[i] = text.charCodeAt(i) & 0xFF;
  273. }
  274. return result.buffer;
  275. }
  276. });
  277. }());
  278. (function checkWindowBtoaCompatibility() {
  279. if ('btoa' in globalScope) {
  280. return;
  281. }
  282. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  283. globalScope.btoa = function (chars) {
  284. var buffer = '';
  285. var i, n;
  286. for (i = 0, n = chars.length; i < n; i += 3) {
  287. var b1 = chars.charCodeAt(i) & 0xFF;
  288. var b2 = chars.charCodeAt(i + 1) & 0xFF;
  289. var b3 = chars.charCodeAt(i + 2) & 0xFF;
  290. var d1 = b1 >> 2, d2 = (b1 & 3) << 4 | b2 >> 4;
  291. var d3 = i + 1 < n ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  292. var d4 = i + 2 < n ? b3 & 0x3F : 64;
  293. buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4);
  294. }
  295. return buffer;
  296. };
  297. }());
  298. (function checkWindowAtobCompatibility() {
  299. if ('atob' in globalScope) {
  300. return;
  301. }
  302. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  303. globalScope.atob = function (input) {
  304. input = input.replace(/=+$/, '');
  305. if (input.length % 4 === 1) {
  306. throw new Error('bad atob input');
  307. }
  308. 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) {
  309. buffer = digits.indexOf(buffer);
  310. }
  311. return output;
  312. };
  313. }());
  314. (function checkFunctionPrototypeBindCompatibility() {
  315. if (typeof Function.prototype.bind !== 'undefined') {
  316. return;
  317. }
  318. Function.prototype.bind = function functionPrototypeBind(obj) {
  319. var fn = this, 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. },
  464. error: function () {
  465. },
  466. warn: function () {
  467. }
  468. };
  469. return;
  470. }
  471. if (!('bind' in console.log)) {
  472. console.log = function (fn) {
  473. return function (msg) {
  474. return fn(msg);
  475. };
  476. }(console.log);
  477. console.error = function (fn) {
  478. return function (msg) {
  479. return fn(msg);
  480. };
  481. }(console.error);
  482. console.warn = function (fn) {
  483. return function (msg) {
  484. return fn(msg);
  485. };
  486. }(console.warn);
  487. return;
  488. }
  489. }());
  490. (function checkOnClickCompatibility() {
  491. function ignoreIfTargetDisabled(event) {
  492. if (isDisabled(event.target)) {
  493. event.stopPropagation();
  494. }
  495. }
  496. function isDisabled(node) {
  497. return node.disabled || node.parentNode && isDisabled(node.parentNode);
  498. }
  499. if (isOpera) {
  500. document.addEventListener('click', ignoreIfTargetDisabled, true);
  501. }
  502. }());
  503. (function checkOnBlobSupport() {
  504. if (isIE || isIOSChrome) {
  505. PDFJS.disableCreateObjectURL = true;
  506. }
  507. }());
  508. (function checkNavigatorLanguage() {
  509. if (typeof navigator === 'undefined') {
  510. return;
  511. }
  512. if ('language' in navigator) {
  513. return;
  514. }
  515. PDFJS.locale = navigator.userLanguage || 'en-US';
  516. }());
  517. (function checkRangeRequests() {
  518. if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
  519. PDFJS.disableRange = true;
  520. PDFJS.disableStream = true;
  521. }
  522. }());
  523. (function checkHistoryManipulation() {
  524. if (!hasDOM) {
  525. return;
  526. }
  527. if (!history.pushState || isAndroidPre3) {
  528. PDFJS.disableHistory = true;
  529. }
  530. }());
  531. (function checkSetPresenceInImageData() {
  532. if (!hasDOM) {
  533. return;
  534. }
  535. if (window.CanvasPixelArray) {
  536. if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
  537. window.CanvasPixelArray.prototype.set = function (arr) {
  538. for (var i = 0, ii = this.length; i < ii; i++) {
  539. this[i] = arr[i];
  540. }
  541. };
  542. }
  543. } else {
  544. var polyfill = false, versionMatch;
  545. if (isChrome) {
  546. versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  547. polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
  548. } else if (isAndroid) {
  549. polyfill = isAndroidPre5;
  550. } else if (isSafari) {
  551. versionMatch = userAgent.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
  552. polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
  553. }
  554. if (polyfill) {
  555. var contextPrototype = window.CanvasRenderingContext2D.prototype;
  556. var createImageData = contextPrototype.createImageData;
  557. contextPrototype.createImageData = function (w, h) {
  558. var imageData = createImageData.call(this, w, h);
  559. imageData.data.set = function (arr) {
  560. for (var i = 0, ii = this.length; i < ii; i++) {
  561. this[i] = arr[i];
  562. }
  563. };
  564. return imageData;
  565. };
  566. contextPrototype = null;
  567. }
  568. }
  569. }());
  570. (function checkRequestAnimationFrame() {
  571. function fakeRequestAnimationFrame(callback) {
  572. window.setTimeout(callback, 20);
  573. }
  574. if (!hasDOM) {
  575. return;
  576. }
  577. if (isIOS) {
  578. window.requestAnimationFrame = fakeRequestAnimationFrame;
  579. return;
  580. }
  581. if ('requestAnimationFrame' in window) {
  582. return;
  583. }
  584. window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || fakeRequestAnimationFrame;
  585. }());
  586. (function checkCanvasSizeLimitation() {
  587. if (isIOS || isAndroid) {
  588. PDFJS.maxCanvasPixels = 5242880;
  589. }
  590. }());
  591. (function checkFullscreenSupport() {
  592. if (!hasDOM) {
  593. return;
  594. }
  595. if (isIE && window.parent !== window) {
  596. PDFJS.disableFullscreen = true;
  597. }
  598. }());
  599. (function checkCurrentScript() {
  600. if (!hasDOM) {
  601. return;
  602. }
  603. if ('currentScript' in document) {
  604. return;
  605. }
  606. Object.defineProperty(document, 'currentScript', {
  607. get: function () {
  608. var scripts = document.getElementsByTagName('script');
  609. return scripts[scripts.length - 1];
  610. },
  611. enumerable: true,
  612. configurable: true
  613. });
  614. }());
  615. (function checkInputTypeNumberAssign() {
  616. if (!hasDOM) {
  617. return;
  618. }
  619. var el = document.createElement('input');
  620. try {
  621. el.type = 'number';
  622. } catch (ex) {
  623. var inputProto = el.constructor.prototype;
  624. var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
  625. Object.defineProperty(inputProto, 'type', {
  626. get: function () {
  627. return typeProperty.get.call(this);
  628. },
  629. set: function (value) {
  630. typeProperty.set.call(this, value === 'number' ? 'text' : value);
  631. },
  632. enumerable: true,
  633. configurable: true
  634. });
  635. }
  636. }());
  637. (function checkDocumentReadyState() {
  638. if (!hasDOM) {
  639. return;
  640. }
  641. if (!document.attachEvent) {
  642. return;
  643. }
  644. var documentProto = document.constructor.prototype;
  645. var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState');
  646. Object.defineProperty(documentProto, 'readyState', {
  647. get: function () {
  648. var value = readyStateProto.get.call(this);
  649. return value === 'interactive' ? 'loading' : value;
  650. },
  651. set: function (value) {
  652. readyStateProto.set.call(this, value);
  653. },
  654. enumerable: true,
  655. configurable: true
  656. });
  657. }());
  658. (function checkChildNodeRemove() {
  659. if (!hasDOM) {
  660. return;
  661. }
  662. if (typeof Element.prototype.remove !== 'undefined') {
  663. return;
  664. }
  665. Element.prototype.remove = function () {
  666. if (this.parentNode) {
  667. this.parentNode.removeChild(this);
  668. }
  669. };
  670. }());
  671. (function checkPromise() {
  672. if (globalScope.Promise) {
  673. if (typeof globalScope.Promise.all !== 'function') {
  674. globalScope.Promise.all = function (iterable) {
  675. var count = 0, results = [], resolve, reject;
  676. var promise = new globalScope.Promise(function (resolve_, reject_) {
  677. resolve = resolve_;
  678. reject = reject_;
  679. });
  680. iterable.forEach(function (p, i) {
  681. count++;
  682. p.then(function (result) {
  683. results[i] = result;
  684. count--;
  685. if (count === 0) {
  686. resolve(results);
  687. }
  688. }, reject);
  689. });
  690. if (count === 0) {
  691. resolve(results);
  692. }
  693. return promise;
  694. };
  695. }
  696. if (typeof globalScope.Promise.resolve !== 'function') {
  697. globalScope.Promise.resolve = function (value) {
  698. return new globalScope.Promise(function (resolve) {
  699. resolve(value);
  700. });
  701. };
  702. }
  703. if (typeof globalScope.Promise.reject !== 'function') {
  704. globalScope.Promise.reject = function (reason) {
  705. return new globalScope.Promise(function (resolve, reject) {
  706. reject(reason);
  707. });
  708. };
  709. }
  710. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  711. globalScope.Promise.prototype.catch = function (onReject) {
  712. return globalScope.Promise.prototype.then(undefined, onReject);
  713. };
  714. }
  715. return;
  716. }
  717. var STATUS_PENDING = 0;
  718. var STATUS_RESOLVED = 1;
  719. var STATUS_REJECTED = 2;
  720. var REJECTION_TIMEOUT = 500;
  721. var HandlerManager = {
  722. handlers: [],
  723. running: false,
  724. unhandledRejections: [],
  725. pendingRejectionCheck: false,
  726. scheduleHandlers: function scheduleHandlers(promise) {
  727. if (promise._status === STATUS_PENDING) {
  728. return;
  729. }
  730. this.handlers = this.handlers.concat(promise._handlers);
  731. promise._handlers = [];
  732. if (this.running) {
  733. return;
  734. }
  735. this.running = true;
  736. setTimeout(this.runHandlers.bind(this), 0);
  737. },
  738. runHandlers: function runHandlers() {
  739. var RUN_TIMEOUT = 1;
  740. var timeoutAt = Date.now() + RUN_TIMEOUT;
  741. while (this.handlers.length > 0) {
  742. var handler = this.handlers.shift();
  743. var nextStatus = handler.thisPromise._status;
  744. var nextValue = handler.thisPromise._value;
  745. try {
  746. if (nextStatus === STATUS_RESOLVED) {
  747. if (typeof handler.onResolve === 'function') {
  748. nextValue = handler.onResolve(nextValue);
  749. }
  750. } else if (typeof handler.onReject === 'function') {
  751. nextValue = handler.onReject(nextValue);
  752. nextStatus = STATUS_RESOLVED;
  753. if (handler.thisPromise._unhandledRejection) {
  754. this.removeUnhandeledRejection(handler.thisPromise);
  755. }
  756. }
  757. } catch (ex) {
  758. nextStatus = STATUS_REJECTED;
  759. nextValue = ex;
  760. }
  761. handler.nextPromise._updateStatus(nextStatus, nextValue);
  762. if (Date.now() >= timeoutAt) {
  763. break;
  764. }
  765. }
  766. if (this.handlers.length > 0) {
  767. setTimeout(this.runHandlers.bind(this), 0);
  768. return;
  769. }
  770. this.running = false;
  771. },
  772. addUnhandledRejection: function addUnhandledRejection(promise) {
  773. this.unhandledRejections.push({
  774. promise: promise,
  775. time: Date.now()
  776. });
  777. this.scheduleRejectionCheck();
  778. },
  779. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  780. promise._unhandledRejection = false;
  781. for (var i = 0; i < this.unhandledRejections.length; i++) {
  782. if (this.unhandledRejections[i].promise === promise) {
  783. this.unhandledRejections.splice(i);
  784. i--;
  785. }
  786. }
  787. },
  788. scheduleRejectionCheck: function scheduleRejectionCheck() {
  789. if (this.pendingRejectionCheck) {
  790. return;
  791. }
  792. this.pendingRejectionCheck = true;
  793. setTimeout(function rejectionCheck() {
  794. this.pendingRejectionCheck = false;
  795. var now = Date.now();
  796. for (var i = 0; i < this.unhandledRejections.length; i++) {
  797. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  798. var unhandled = this.unhandledRejections[i].promise._value;
  799. var msg = 'Unhandled rejection: ' + unhandled;
  800. if (unhandled.stack) {
  801. msg += '\n' + unhandled.stack;
  802. }
  803. try {
  804. throw new Error(msg);
  805. } catch (_) {
  806. console.warn(msg);
  807. }
  808. this.unhandledRejections.splice(i);
  809. i--;
  810. }
  811. }
  812. if (this.unhandledRejections.length) {
  813. this.scheduleRejectionCheck();
  814. }
  815. }.bind(this), REJECTION_TIMEOUT);
  816. }
  817. };
  818. var Promise = function Promise(resolver) {
  819. this._status = STATUS_PENDING;
  820. this._handlers = [];
  821. try {
  822. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  823. } catch (e) {
  824. this._reject(e);
  825. }
  826. };
  827. Promise.all = function Promise_all(promises) {
  828. var resolveAll, rejectAll;
  829. var deferred = new Promise(function (resolve, reject) {
  830. resolveAll = resolve;
  831. rejectAll = reject;
  832. });
  833. var unresolved = promises.length;
  834. var results = [];
  835. if (unresolved === 0) {
  836. resolveAll(results);
  837. return deferred;
  838. }
  839. function reject(reason) {
  840. if (deferred._status === STATUS_REJECTED) {
  841. return;
  842. }
  843. results = [];
  844. rejectAll(reason);
  845. }
  846. for (var i = 0, ii = promises.length; i < ii; ++i) {
  847. var promise = promises[i];
  848. var resolve = function (i) {
  849. return function (value) {
  850. if (deferred._status === STATUS_REJECTED) {
  851. return;
  852. }
  853. results[i] = value;
  854. unresolved--;
  855. if (unresolved === 0) {
  856. resolveAll(results);
  857. }
  858. };
  859. }(i);
  860. if (Promise.isPromise(promise)) {
  861. promise.then(resolve, reject);
  862. } else {
  863. resolve(promise);
  864. }
  865. }
  866. return deferred;
  867. };
  868. Promise.isPromise = function Promise_isPromise(value) {
  869. return value && typeof value.then === 'function';
  870. };
  871. Promise.resolve = function Promise_resolve(value) {
  872. return new Promise(function (resolve) {
  873. resolve(value);
  874. });
  875. };
  876. Promise.reject = function Promise_reject(reason) {
  877. return new Promise(function (resolve, reject) {
  878. reject(reason);
  879. });
  880. };
  881. Promise.prototype = {
  882. _status: null,
  883. _value: null,
  884. _handlers: null,
  885. _unhandledRejection: null,
  886. _updateStatus: function Promise__updateStatus(status, value) {
  887. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  888. return;
  889. }
  890. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  891. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  892. return;
  893. }
  894. this._status = status;
  895. this._value = value;
  896. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  897. this._unhandledRejection = true;
  898. HandlerManager.addUnhandledRejection(this);
  899. }
  900. HandlerManager.scheduleHandlers(this);
  901. },
  902. _resolve: function Promise_resolve(value) {
  903. this._updateStatus(STATUS_RESOLVED, value);
  904. },
  905. _reject: function Promise_reject(reason) {
  906. this._updateStatus(STATUS_REJECTED, reason);
  907. },
  908. then: function Promise_then(onResolve, onReject) {
  909. var nextPromise = new Promise(function (resolve, reject) {
  910. this.resolve = resolve;
  911. this.reject = reject;
  912. });
  913. this._handlers.push({
  914. thisPromise: this,
  915. onResolve: onResolve,
  916. onReject: onReject,
  917. nextPromise: nextPromise
  918. });
  919. HandlerManager.scheduleHandlers(this);
  920. return nextPromise;
  921. },
  922. catch: function Promise_catch(onReject) {
  923. return this.then(undefined, onReject);
  924. }
  925. };
  926. globalScope.Promise = Promise;
  927. }());
  928. (function checkWeakMap() {
  929. if (globalScope.WeakMap) {
  930. return;
  931. }
  932. var id = 0;
  933. function WeakMap() {
  934. this.id = '$weakmap' + id++;
  935. }
  936. WeakMap.prototype = {
  937. has: function (obj) {
  938. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  939. },
  940. get: function (obj, defaultValue) {
  941. return this.has(obj) ? obj[this.id] : defaultValue;
  942. },
  943. set: function (obj, value) {
  944. Object.defineProperty(obj, this.id, {
  945. value: value,
  946. enumerable: false,
  947. configurable: true
  948. });
  949. },
  950. delete: function (obj) {
  951. delete obj[this.id];
  952. }
  953. };
  954. globalScope.WeakMap = WeakMap;
  955. }());
  956. (function checkURLConstructor() {
  957. var hasWorkingUrl = false;
  958. try {
  959. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  960. var u = new URL('b', 'http://a');
  961. u.pathname = 'c%20d';
  962. hasWorkingUrl = u.href === 'http://a/c%20d';
  963. }
  964. } catch (e) {
  965. }
  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 && [
  998. 0x22,
  999. 0x23,
  1000. 0x3C,
  1001. 0x3E,
  1002. 0x3F,
  1003. 0x60
  1004. ].indexOf(unicode) === -1) {
  1005. return c;
  1006. }
  1007. return encodeURIComponent(c);
  1008. }
  1009. function percentEscapeQuery(c) {
  1010. var unicode = c.charCodeAt(0);
  1011. if (unicode > 0x20 && unicode < 0x7F && [
  1012. 0x22,
  1013. 0x23,
  1014. 0x3C,
  1015. 0x3E,
  1016. 0x60
  1017. ].indexOf(unicode) === -1) {
  1018. return c;
  1019. }
  1020. return encodeURIComponent(c);
  1021. }
  1022. var EOF, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  1023. function parse(input, stateOverride, base) {
  1024. function err(message) {
  1025. errors.push(message);
  1026. }
  1027. var state = stateOverride || 'scheme start', cursor = 0, buffer = '', seenAt = false, seenBracket = false, errors = [];
  1028. loop:
  1029. while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  1030. var c = input[cursor];
  1031. switch (state) {
  1032. case 'scheme start':
  1033. if (c && ALPHA.test(c)) {
  1034. buffer += c.toLowerCase();
  1035. state = 'scheme';
  1036. } else if (!stateOverride) {
  1037. buffer = '';
  1038. state = 'no scheme';
  1039. continue;
  1040. } else {
  1041. err('Invalid scheme.');
  1042. break loop;
  1043. }
  1044. break;
  1045. case 'scheme':
  1046. if (c && ALPHANUMERIC.test(c)) {
  1047. buffer += c.toLowerCase();
  1048. } else if (c === ':') {
  1049. this._scheme = buffer;
  1050. buffer = '';
  1051. if (stateOverride) {
  1052. break loop;
  1053. }
  1054. if (isRelativeScheme(this._scheme)) {
  1055. this._isRelative = true;
  1056. }
  1057. if (this._scheme === 'file') {
  1058. state = 'relative';
  1059. } else if (this._isRelative && base && base._scheme === this._scheme) {
  1060. state = 'relative or authority';
  1061. } else if (this._isRelative) {
  1062. state = 'authority first slash';
  1063. } else {
  1064. state = 'scheme data';
  1065. }
  1066. } else if (!stateOverride) {
  1067. buffer = '';
  1068. cursor = 0;
  1069. state = 'no scheme';
  1070. continue;
  1071. } else if (EOF === c) {
  1072. break loop;
  1073. } else {
  1074. err('Code point not allowed in scheme: ' + c);
  1075. break loop;
  1076. }
  1077. break;
  1078. case 'scheme data':
  1079. if (c === '?') {
  1080. this._query = '?';
  1081. state = 'query';
  1082. } else if (c === '#') {
  1083. this._fragment = '#';
  1084. state = 'fragment';
  1085. } else {
  1086. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  1087. this._schemeData += percentEscape(c);
  1088. }
  1089. }
  1090. break;
  1091. case 'no scheme':
  1092. if (!base || !isRelativeScheme(base._scheme)) {
  1093. err('Missing scheme.');
  1094. invalid.call(this);
  1095. } else {
  1096. state = 'relative';
  1097. continue;
  1098. }
  1099. break;
  1100. case 'relative or authority':
  1101. if (c === '/' && input[cursor + 1] === '/') {
  1102. state = 'authority ignore slashes';
  1103. } else {
  1104. err('Expected /, got: ' + c);
  1105. state = 'relative';
  1106. continue;
  1107. }
  1108. break;
  1109. case 'relative':
  1110. this._isRelative = true;
  1111. if ('file' !== this._scheme) {
  1112. this._scheme = base._scheme;
  1113. }
  1114. if (EOF === c) {
  1115. this._host = base._host;
  1116. this._port = base._port;
  1117. this._path = base._path.slice();
  1118. this._query = base._query;
  1119. this._username = base._username;
  1120. this._password = base._password;
  1121. break loop;
  1122. } else if (c === '/' || c === '\\') {
  1123. if (c === '\\') {
  1124. err('\\ is an invalid code point.');
  1125. }
  1126. state = 'relative slash';
  1127. } else if (c === '?') {
  1128. this._host = base._host;
  1129. this._port = base._port;
  1130. this._path = base._path.slice();
  1131. this._query = '?';
  1132. this._username = base._username;
  1133. this._password = base._password;
  1134. state = 'query';
  1135. } else if (c === '#') {
  1136. this._host = base._host;
  1137. this._port = base._port;
  1138. this._path = base._path.slice();
  1139. this._query = base._query;
  1140. this._fragment = '#';
  1141. this._username = base._username;
  1142. this._password = base._password;
  1143. state = 'fragment';
  1144. } else {
  1145. var nextC = input[cursor + 1];
  1146. var nextNextC = input[cursor + 2];
  1147. if ('file' !== this._scheme || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC && '?' !== nextNextC && '#' !== nextNextC) {
  1148. this._host = base._host;
  1149. this._port = base._port;
  1150. this._username = base._username;
  1151. this._password = base._password;
  1152. this._path = base._path.slice();
  1153. this._path.pop();
  1154. }
  1155. state = 'relative path';
  1156. continue;
  1157. }
  1158. break;
  1159. case 'relative slash':
  1160. if (c === '/' || c === '\\') {
  1161. if (c === '\\') {
  1162. err('\\ is an invalid code point.');
  1163. }
  1164. if (this._scheme === 'file') {
  1165. state = 'file host';
  1166. } else {
  1167. state = 'authority ignore slashes';
  1168. }
  1169. } else {
  1170. if ('file' !== this._scheme) {
  1171. this._host = base._host;
  1172. this._port = base._port;
  1173. this._username = base._username;
  1174. this._password = base._password;
  1175. }
  1176. state = 'relative path';
  1177. continue;
  1178. }
  1179. break;
  1180. case 'authority first slash':
  1181. if (c === '/') {
  1182. state = 'authority second slash';
  1183. } else {
  1184. err('Expected \'/\', got: ' + c);
  1185. state = 'authority ignore slashes';
  1186. continue;
  1187. }
  1188. break;
  1189. case 'authority second slash':
  1190. state = 'authority ignore slashes';
  1191. if ('/' !== c) {
  1192. err('Expected \'/\', got: ' + c);
  1193. continue;
  1194. }
  1195. break;
  1196. case 'authority ignore slashes':
  1197. if ('/' !== c && '\\' !== c) {
  1198. state = 'authority';
  1199. continue;
  1200. } else {
  1201. err('Expected authority, got: ' + c);
  1202. }
  1203. break;
  1204. case 'authority':
  1205. if (c === '@') {
  1206. if (seenAt) {
  1207. err('@ already seen.');
  1208. buffer += '%40';
  1209. }
  1210. seenAt = true;
  1211. for (var i = 0; i < buffer.length; i++) {
  1212. var cp = buffer[i];
  1213. if (cp === '\t' || cp === '\n' || cp === '\r') {
  1214. err('Invalid whitespace in authority.');
  1215. continue;
  1216. }
  1217. if (cp === ':' && this._password === null) {
  1218. this._password = '';
  1219. continue;
  1220. }
  1221. var tempC = percentEscape(cp);
  1222. if (null !== this._password) {
  1223. this._password += tempC;
  1224. } else {
  1225. this._username += tempC;
  1226. }
  1227. }
  1228. buffer = '';
  1229. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1230. cursor -= buffer.length;
  1231. buffer = '';
  1232. state = 'host';
  1233. continue;
  1234. } else {
  1235. buffer += c;
  1236. }
  1237. break;
  1238. case 'file host':
  1239. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1240. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  1241. state = 'relative path';
  1242. } else if (buffer.length === 0) {
  1243. state = 'relative path start';
  1244. } else {
  1245. this._host = IDNAToASCII.call(this, buffer);
  1246. buffer = '';
  1247. state = 'relative path start';
  1248. }
  1249. continue;
  1250. } else if (c === '\t' || c === '\n' || c === '\r') {
  1251. err('Invalid whitespace in file host.');
  1252. } else {
  1253. buffer += c;
  1254. }
  1255. break;
  1256. case 'host':
  1257. case 'hostname':
  1258. if (c === ':' && !seenBracket) {
  1259. this._host = IDNAToASCII.call(this, buffer);
  1260. buffer = '';
  1261. state = 'port';
  1262. if (stateOverride === 'hostname') {
  1263. break loop;
  1264. }
  1265. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1266. this._host = IDNAToASCII.call(this, buffer);
  1267. buffer = '';
  1268. state = 'relative path start';
  1269. if (stateOverride) {
  1270. break loop;
  1271. }
  1272. continue;
  1273. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  1274. if (c === '[') {
  1275. seenBracket = true;
  1276. } else if (c === ']') {
  1277. seenBracket = false;
  1278. }
  1279. buffer += c;
  1280. } else {
  1281. err('Invalid code point in host/hostname: ' + c);
  1282. }
  1283. break;
  1284. case 'port':
  1285. if (/[0-9]/.test(c)) {
  1286. buffer += c;
  1287. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1288. if ('' !== buffer) {
  1289. var temp = parseInt(buffer, 10);
  1290. if (temp !== relative[this._scheme]) {
  1291. this._port = temp + '';
  1292. }
  1293. buffer = '';
  1294. }
  1295. if (stateOverride) {
  1296. break loop;
  1297. }
  1298. state = 'relative path start';
  1299. continue;
  1300. } else if (c === '\t' || c === '\n' || c === '\r') {
  1301. err('Invalid code point in port: ' + c);
  1302. } else {
  1303. invalid.call(this);
  1304. }
  1305. break;
  1306. case 'relative path start':
  1307. if (c === '\\') {
  1308. err('\'\\\' not allowed in path.');
  1309. }
  1310. state = 'relative path';
  1311. if ('/' !== c && '\\' !== c) {
  1312. continue;
  1313. }
  1314. break;
  1315. case 'relative path':
  1316. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1317. if (c === '\\') {
  1318. err('\\ not allowed in relative path.');
  1319. }
  1320. var tmp;
  1321. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1322. buffer = tmp;
  1323. }
  1324. if (buffer === '..') {
  1325. this._path.pop();
  1326. if ('/' !== c && '\\' !== c) {
  1327. this._path.push('');
  1328. }
  1329. } else if (buffer === '.' && '/' !== c && '\\' !== c) {
  1330. this._path.push('');
  1331. } else if ('.' !== buffer) {
  1332. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1333. buffer = buffer[0] + ':';
  1334. }
  1335. this._path.push(buffer);
  1336. }
  1337. buffer = '';
  1338. if (c === '?') {
  1339. this._query = '?';
  1340. state = 'query';
  1341. } else if (c === '#') {
  1342. this._fragment = '#';
  1343. state = 'fragment';
  1344. }
  1345. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  1346. buffer += percentEscape(c);
  1347. }
  1348. break;
  1349. case 'query':
  1350. if (!stateOverride && c === '#') {
  1351. this._fragment = '#';
  1352. state = 'fragment';
  1353. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  1354. this._query += percentEscapeQuery(c);
  1355. }
  1356. break;
  1357. case 'fragment':
  1358. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  1359. this._fragment += c;
  1360. }
  1361. break;
  1362. }
  1363. cursor++;
  1364. }
  1365. }
  1366. function clear() {
  1367. this._scheme = '';
  1368. this._schemeData = '';
  1369. this._username = '';
  1370. this._password = null;
  1371. this._host = '';
  1372. this._port = '';
  1373. this._path = [];
  1374. this._query = '';
  1375. this._fragment = '';
  1376. this._isInvalid = false;
  1377. this._isRelative = false;
  1378. }
  1379. function JURL(url, base) {
  1380. if (base !== undefined && !(base instanceof JURL)) {
  1381. base = new JURL(String(base));
  1382. }
  1383. this._url = url;
  1384. clear.call(this);
  1385. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1386. parse.call(this, input, null, base);
  1387. }
  1388. JURL.prototype = {
  1389. toString: function () {
  1390. return this.href;
  1391. },
  1392. get href() {
  1393. if (this._isInvalid) {
  1394. return this._url;
  1395. }
  1396. var authority = '';
  1397. if ('' !== this._username || null !== this._password) {
  1398. authority = this._username + (null !== this._password ? ':' + this._password : '') + '@';
  1399. }
  1400. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1401. },
  1402. set href(href) {
  1403. clear.call(this);
  1404. parse.call(this, href);
  1405. },
  1406. get protocol() {
  1407. return this._scheme + ':';
  1408. },
  1409. set protocol(protocol) {
  1410. if (this._isInvalid) {
  1411. return;
  1412. }
  1413. parse.call(this, protocol + ':', 'scheme start');
  1414. },
  1415. get host() {
  1416. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1417. },
  1418. set host(host) {
  1419. if (this._isInvalid || !this._isRelative) {
  1420. return;
  1421. }
  1422. parse.call(this, host, 'host');
  1423. },
  1424. get hostname() {
  1425. return this._host;
  1426. },
  1427. set hostname(hostname) {
  1428. if (this._isInvalid || !this._isRelative) {
  1429. return;
  1430. }
  1431. parse.call(this, hostname, 'hostname');
  1432. },
  1433. get port() {
  1434. return this._port;
  1435. },
  1436. set port(port) {
  1437. if (this._isInvalid || !this._isRelative) {
  1438. return;
  1439. }
  1440. parse.call(this, port, 'port');
  1441. },
  1442. get pathname() {
  1443. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1444. },
  1445. set pathname(pathname) {
  1446. if (this._isInvalid || !this._isRelative) {
  1447. return;
  1448. }
  1449. this._path = [];
  1450. parse.call(this, pathname, 'relative path start');
  1451. },
  1452. get search() {
  1453. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1454. },
  1455. set search(search) {
  1456. if (this._isInvalid || !this._isRelative) {
  1457. return;
  1458. }
  1459. this._query = '?';
  1460. if (search[0] === '?') {
  1461. search = search.slice(1);
  1462. }
  1463. parse.call(this, search, 'query');
  1464. },
  1465. get hash() {
  1466. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1467. },
  1468. set hash(hash) {
  1469. if (this._isInvalid) {
  1470. return;
  1471. }
  1472. this._fragment = '#';
  1473. if (hash[0] === '#') {
  1474. hash = hash.slice(1);
  1475. }
  1476. parse.call(this, hash, 'fragment');
  1477. },
  1478. get origin() {
  1479. var host;
  1480. if (this._isInvalid || !this._scheme) {
  1481. return '';
  1482. }
  1483. switch (this._scheme) {
  1484. case 'data':
  1485. case 'file':
  1486. case 'javascript':
  1487. case 'mailto':
  1488. return 'null';
  1489. }
  1490. host = this.host;
  1491. if (!host) {
  1492. return '';
  1493. }
  1494. return this._scheme + '://' + host;
  1495. }
  1496. };
  1497. var OriginalURL = globalScope.URL;
  1498. if (OriginalURL) {
  1499. JURL.createObjectURL = function (blob) {
  1500. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1501. };
  1502. JURL.revokeObjectURL = function (url) {
  1503. OriginalURL.revokeObjectURL(url);
  1504. };
  1505. }
  1506. globalScope.URL = JURL;
  1507. }());
  1508. }
  1509. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
  1510. /***/ }),
  1511. /* 1 */
  1512. /***/ (function(module, exports) {
  1513. var g;
  1514. g = function () {
  1515. return this;
  1516. }();
  1517. try {
  1518. g = g || Function("return this")() || (1, eval)("this");
  1519. } catch (e) {
  1520. if (typeof window === "object")
  1521. g = window;
  1522. }
  1523. module.exports = g;
  1524. /***/ }),
  1525. /* 2 */
  1526. /***/ (function(module, exports, __webpack_require__) {
  1527. "use strict";
  1528. __webpack_require__(0);
  1529. /***/ })
  1530. /******/ ]);
  1531. });