2
0

compatibility.js 47 KB

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