compatibility.js 50 KB

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