compatibility.js 48 KB

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