2
0

compatibility.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  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 = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : typeof undefined !== 'undefined' && undefined.Math === Math ? undefined : {};
  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. var id = 0;
  944. function WeakMap() {
  945. this.id = '$weakmap' + id++;
  946. }
  947. WeakMap.prototype = {
  948. has: function has(obj) {
  949. if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' && typeof obj !== 'function' || obj === null) {
  950. return false;
  951. }
  952. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  953. },
  954. get: function get(obj) {
  955. return this.has(obj) ? obj[this.id] : undefined;
  956. },
  957. set: function set(obj, value) {
  958. Object.defineProperty(obj, this.id, {
  959. value: value,
  960. enumerable: false,
  961. configurable: true
  962. });
  963. },
  964. delete: function _delete(obj) {
  965. delete obj[this.id];
  966. }
  967. };
  968. globalScope.WeakMap = WeakMap;
  969. })();
  970. (function checkURLConstructor() {
  971. var hasWorkingUrl = false;
  972. try {
  973. if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
  974. var u = new URL('b', 'http://a');
  975. u.pathname = 'c%20d';
  976. hasWorkingUrl = u.href === 'http://a/c%20d';
  977. }
  978. } catch (e) {}
  979. if (hasWorkingUrl) {
  980. return;
  981. }
  982. var relative = Object.create(null);
  983. relative['ftp'] = 21;
  984. relative['file'] = 0;
  985. relative['gopher'] = 70;
  986. relative['http'] = 80;
  987. relative['https'] = 443;
  988. relative['ws'] = 80;
  989. relative['wss'] = 443;
  990. var relativePathDotMapping = Object.create(null);
  991. relativePathDotMapping['%2e'] = '.';
  992. relativePathDotMapping['.%2e'] = '..';
  993. relativePathDotMapping['%2e.'] = '..';
  994. relativePathDotMapping['%2e%2e'] = '..';
  995. function isRelativeScheme(scheme) {
  996. return relative[scheme] !== undefined;
  997. }
  998. function invalid() {
  999. clear.call(this);
  1000. this._isInvalid = true;
  1001. }
  1002. function IDNAToASCII(h) {
  1003. if (h === '') {
  1004. invalid.call(this);
  1005. }
  1006. return h.toLowerCase();
  1007. }
  1008. function percentEscape(c) {
  1009. var unicode = c.charCodeAt(0);
  1010. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
  1011. return c;
  1012. }
  1013. return encodeURIComponent(c);
  1014. }
  1015. function percentEscapeQuery(c) {
  1016. var unicode = c.charCodeAt(0);
  1017. if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
  1018. return c;
  1019. }
  1020. return encodeURIComponent(c);
  1021. }
  1022. var EOF,
  1023. ALPHA = /[a-zA-Z]/,
  1024. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  1025. function parse(input, stateOverride, base) {
  1026. function err(message) {
  1027. errors.push(message);
  1028. }
  1029. var state = stateOverride || 'scheme start',
  1030. cursor = 0,
  1031. buffer = '',
  1032. seenAt = false,
  1033. seenBracket = false,
  1034. errors = [];
  1035. loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  1036. var c = input[cursor];
  1037. switch (state) {
  1038. case 'scheme start':
  1039. if (c && ALPHA.test(c)) {
  1040. buffer += c.toLowerCase();
  1041. state = 'scheme';
  1042. } else if (!stateOverride) {
  1043. buffer = '';
  1044. state = 'no scheme';
  1045. continue;
  1046. } else {
  1047. err('Invalid scheme.');
  1048. break loop;
  1049. }
  1050. break;
  1051. case 'scheme':
  1052. if (c && ALPHANUMERIC.test(c)) {
  1053. buffer += c.toLowerCase();
  1054. } else if (c === ':') {
  1055. this._scheme = buffer;
  1056. buffer = '';
  1057. if (stateOverride) {
  1058. break loop;
  1059. }
  1060. if (isRelativeScheme(this._scheme)) {
  1061. this._isRelative = true;
  1062. }
  1063. if (this._scheme === 'file') {
  1064. state = 'relative';
  1065. } else if (this._isRelative && base && base._scheme === this._scheme) {
  1066. state = 'relative or authority';
  1067. } else if (this._isRelative) {
  1068. state = 'authority first slash';
  1069. } else {
  1070. state = 'scheme data';
  1071. }
  1072. } else if (!stateOverride) {
  1073. buffer = '';
  1074. cursor = 0;
  1075. state = 'no scheme';
  1076. continue;
  1077. } else if (c === EOF) {
  1078. break loop;
  1079. } else {
  1080. err('Code point not allowed in scheme: ' + c);
  1081. break loop;
  1082. }
  1083. break;
  1084. case 'scheme data':
  1085. if (c === '?') {
  1086. this._query = '?';
  1087. state = 'query';
  1088. } else if (c === '#') {
  1089. this._fragment = '#';
  1090. state = 'fragment';
  1091. } else {
  1092. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1093. this._schemeData += percentEscape(c);
  1094. }
  1095. }
  1096. break;
  1097. case 'no scheme':
  1098. if (!base || !isRelativeScheme(base._scheme)) {
  1099. err('Missing scheme.');
  1100. invalid.call(this);
  1101. } else {
  1102. state = 'relative';
  1103. continue;
  1104. }
  1105. break;
  1106. case 'relative or authority':
  1107. if (c === '/' && input[cursor + 1] === '/') {
  1108. state = 'authority ignore slashes';
  1109. } else {
  1110. err('Expected /, got: ' + c);
  1111. state = 'relative';
  1112. continue;
  1113. }
  1114. break;
  1115. case 'relative':
  1116. this._isRelative = true;
  1117. if (this._scheme !== 'file') {
  1118. this._scheme = base._scheme;
  1119. }
  1120. if (c === EOF) {
  1121. this._host = base._host;
  1122. this._port = base._port;
  1123. this._path = base._path.slice();
  1124. this._query = base._query;
  1125. this._username = base._username;
  1126. this._password = base._password;
  1127. break loop;
  1128. } else if (c === '/' || c === '\\') {
  1129. if (c === '\\') {
  1130. err('\\ is an invalid code point.');
  1131. }
  1132. state = 'relative slash';
  1133. } else if (c === '?') {
  1134. this._host = base._host;
  1135. this._port = base._port;
  1136. this._path = base._path.slice();
  1137. this._query = '?';
  1138. this._username = base._username;
  1139. this._password = base._password;
  1140. state = 'query';
  1141. } else if (c === '#') {
  1142. this._host = base._host;
  1143. this._port = base._port;
  1144. this._path = base._path.slice();
  1145. this._query = base._query;
  1146. this._fragment = '#';
  1147. this._username = base._username;
  1148. this._password = base._password;
  1149. state = 'fragment';
  1150. } else {
  1151. var nextC = input[cursor + 1];
  1152. var nextNextC = input[cursor + 2];
  1153. if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
  1154. this._host = base._host;
  1155. this._port = base._port;
  1156. this._username = base._username;
  1157. this._password = base._password;
  1158. this._path = base._path.slice();
  1159. this._path.pop();
  1160. }
  1161. state = 'relative path';
  1162. continue;
  1163. }
  1164. break;
  1165. case 'relative slash':
  1166. if (c === '/' || c === '\\') {
  1167. if (c === '\\') {
  1168. err('\\ is an invalid code point.');
  1169. }
  1170. if (this._scheme === 'file') {
  1171. state = 'file host';
  1172. } else {
  1173. state = 'authority ignore slashes';
  1174. }
  1175. } else {
  1176. if (this._scheme !== 'file') {
  1177. this._host = base._host;
  1178. this._port = base._port;
  1179. this._username = base._username;
  1180. this._password = base._password;
  1181. }
  1182. state = 'relative path';
  1183. continue;
  1184. }
  1185. break;
  1186. case 'authority first slash':
  1187. if (c === '/') {
  1188. state = 'authority second slash';
  1189. } else {
  1190. err('Expected \'/\', got: ' + c);
  1191. state = 'authority ignore slashes';
  1192. continue;
  1193. }
  1194. break;
  1195. case 'authority second slash':
  1196. state = 'authority ignore slashes';
  1197. if (c !== '/') {
  1198. err('Expected \'/\', got: ' + c);
  1199. continue;
  1200. }
  1201. break;
  1202. case 'authority ignore slashes':
  1203. if (c !== '/' && c !== '\\') {
  1204. state = 'authority';
  1205. continue;
  1206. } else {
  1207. err('Expected authority, got: ' + c);
  1208. }
  1209. break;
  1210. case 'authority':
  1211. if (c === '@') {
  1212. if (seenAt) {
  1213. err('@ already seen.');
  1214. buffer += '%40';
  1215. }
  1216. seenAt = true;
  1217. for (var i = 0; i < buffer.length; i++) {
  1218. var cp = buffer[i];
  1219. if (cp === '\t' || cp === '\n' || cp === '\r') {
  1220. err('Invalid whitespace in authority.');
  1221. continue;
  1222. }
  1223. if (cp === ':' && this._password === null) {
  1224. this._password = '';
  1225. continue;
  1226. }
  1227. var tempC = percentEscape(cp);
  1228. if (this._password !== null) {
  1229. this._password += tempC;
  1230. } else {
  1231. this._username += tempC;
  1232. }
  1233. }
  1234. buffer = '';
  1235. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1236. cursor -= buffer.length;
  1237. buffer = '';
  1238. state = 'host';
  1239. continue;
  1240. } else {
  1241. buffer += c;
  1242. }
  1243. break;
  1244. case 'file host':
  1245. if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1246. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  1247. state = 'relative path';
  1248. } else if (buffer.length === 0) {
  1249. state = 'relative path start';
  1250. } else {
  1251. this._host = IDNAToASCII.call(this, buffer);
  1252. buffer = '';
  1253. state = 'relative path start';
  1254. }
  1255. continue;
  1256. } else if (c === '\t' || c === '\n' || c === '\r') {
  1257. err('Invalid whitespace in file host.');
  1258. } else {
  1259. buffer += c;
  1260. }
  1261. break;
  1262. case 'host':
  1263. case 'hostname':
  1264. if (c === ':' && !seenBracket) {
  1265. this._host = IDNAToASCII.call(this, buffer);
  1266. buffer = '';
  1267. state = 'port';
  1268. if (stateOverride === 'hostname') {
  1269. break loop;
  1270. }
  1271. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
  1272. this._host = IDNAToASCII.call(this, buffer);
  1273. buffer = '';
  1274. state = 'relative path start';
  1275. if (stateOverride) {
  1276. break loop;
  1277. }
  1278. continue;
  1279. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1280. if (c === '[') {
  1281. seenBracket = true;
  1282. } else if (c === ']') {
  1283. seenBracket = false;
  1284. }
  1285. buffer += c;
  1286. } else {
  1287. err('Invalid code point in host/hostname: ' + c);
  1288. }
  1289. break;
  1290. case 'port':
  1291. if (/[0-9]/.test(c)) {
  1292. buffer += c;
  1293. } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
  1294. if (buffer !== '') {
  1295. var temp = parseInt(buffer, 10);
  1296. if (temp !== relative[this._scheme]) {
  1297. this._port = temp + '';
  1298. }
  1299. buffer = '';
  1300. }
  1301. if (stateOverride) {
  1302. break loop;
  1303. }
  1304. state = 'relative path start';
  1305. continue;
  1306. } else if (c === '\t' || c === '\n' || c === '\r') {
  1307. err('Invalid code point in port: ' + c);
  1308. } else {
  1309. invalid.call(this);
  1310. }
  1311. break;
  1312. case 'relative path start':
  1313. if (c === '\\') {
  1314. err('\'\\\' not allowed in path.');
  1315. }
  1316. state = 'relative path';
  1317. if (c !== '/' && c !== '\\') {
  1318. continue;
  1319. }
  1320. break;
  1321. case 'relative path':
  1322. if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
  1323. if (c === '\\') {
  1324. err('\\ not allowed in relative path.');
  1325. }
  1326. var tmp;
  1327. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1328. buffer = tmp;
  1329. }
  1330. if (buffer === '..') {
  1331. this._path.pop();
  1332. if (c !== '/' && c !== '\\') {
  1333. this._path.push('');
  1334. }
  1335. } else if (buffer === '.' && c !== '/' && c !== '\\') {
  1336. this._path.push('');
  1337. } else if (buffer !== '.') {
  1338. if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  1339. buffer = buffer[0] + ':';
  1340. }
  1341. this._path.push(buffer);
  1342. }
  1343. buffer = '';
  1344. if (c === '?') {
  1345. this._query = '?';
  1346. state = 'query';
  1347. } else if (c === '#') {
  1348. this._fragment = '#';
  1349. state = 'fragment';
  1350. }
  1351. } else if (c !== '\t' && c !== '\n' && c !== '\r') {
  1352. buffer += percentEscape(c);
  1353. }
  1354. break;
  1355. case 'query':
  1356. if (!stateOverride && c === '#') {
  1357. this._fragment = '#';
  1358. state = 'fragment';
  1359. } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1360. this._query += percentEscapeQuery(c);
  1361. }
  1362. break;
  1363. case 'fragment':
  1364. if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
  1365. this._fragment += c;
  1366. }
  1367. break;
  1368. }
  1369. cursor++;
  1370. }
  1371. }
  1372. function clear() {
  1373. this._scheme = '';
  1374. this._schemeData = '';
  1375. this._username = '';
  1376. this._password = null;
  1377. this._host = '';
  1378. this._port = '';
  1379. this._path = [];
  1380. this._query = '';
  1381. this._fragment = '';
  1382. this._isInvalid = false;
  1383. this._isRelative = false;
  1384. }
  1385. function JURL(url, base) {
  1386. if (base !== undefined && !(base instanceof JURL)) {
  1387. base = new JURL(String(base));
  1388. }
  1389. this._url = url;
  1390. clear.call(this);
  1391. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1392. parse.call(this, input, null, base);
  1393. }
  1394. JURL.prototype = {
  1395. toString: function toString() {
  1396. return this.href;
  1397. },
  1398. get href() {
  1399. if (this._isInvalid) {
  1400. return this._url;
  1401. }
  1402. var authority = '';
  1403. if (this._username !== '' || this._password !== null) {
  1404. authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
  1405. }
  1406. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  1407. },
  1408. set href(value) {
  1409. clear.call(this);
  1410. parse.call(this, value);
  1411. },
  1412. get protocol() {
  1413. return this._scheme + ':';
  1414. },
  1415. set protocol(value) {
  1416. if (this._isInvalid) {
  1417. return;
  1418. }
  1419. parse.call(this, value + ':', 'scheme start');
  1420. },
  1421. get host() {
  1422. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  1423. },
  1424. set host(value) {
  1425. if (this._isInvalid || !this._isRelative) {
  1426. return;
  1427. }
  1428. parse.call(this, value, 'host');
  1429. },
  1430. get hostname() {
  1431. return this._host;
  1432. },
  1433. set hostname(value) {
  1434. if (this._isInvalid || !this._isRelative) {
  1435. return;
  1436. }
  1437. parse.call(this, value, 'hostname');
  1438. },
  1439. get port() {
  1440. return this._port;
  1441. },
  1442. set port(value) {
  1443. if (this._isInvalid || !this._isRelative) {
  1444. return;
  1445. }
  1446. parse.call(this, value, 'port');
  1447. },
  1448. get pathname() {
  1449. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  1450. },
  1451. set pathname(value) {
  1452. if (this._isInvalid || !this._isRelative) {
  1453. return;
  1454. }
  1455. this._path = [];
  1456. parse.call(this, value, 'relative path start');
  1457. },
  1458. get search() {
  1459. return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
  1460. },
  1461. set search(value) {
  1462. if (this._isInvalid || !this._isRelative) {
  1463. return;
  1464. }
  1465. this._query = '?';
  1466. if (value[0] === '?') {
  1467. value = value.slice(1);
  1468. }
  1469. parse.call(this, value, 'query');
  1470. },
  1471. get hash() {
  1472. return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
  1473. },
  1474. set hash(value) {
  1475. if (this._isInvalid) {
  1476. return;
  1477. }
  1478. this._fragment = '#';
  1479. if (value[0] === '#') {
  1480. value = value.slice(1);
  1481. }
  1482. parse.call(this, value, 'fragment');
  1483. },
  1484. get origin() {
  1485. var host;
  1486. if (this._isInvalid || !this._scheme) {
  1487. return '';
  1488. }
  1489. switch (this._scheme) {
  1490. case 'data':
  1491. case 'file':
  1492. case 'javascript':
  1493. case 'mailto':
  1494. return 'null';
  1495. case 'blob':
  1496. try {
  1497. return new JURL(this._schemeData).origin || 'null';
  1498. } catch (_) {}
  1499. return 'null';
  1500. }
  1501. host = this.host;
  1502. if (!host) {
  1503. return '';
  1504. }
  1505. return this._scheme + '://' + host;
  1506. }
  1507. };
  1508. var OriginalURL = globalScope.URL;
  1509. if (OriginalURL) {
  1510. JURL.createObjectURL = function (blob) {
  1511. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  1512. };
  1513. JURL.revokeObjectURL = function (url) {
  1514. OriginalURL.revokeObjectURL(url);
  1515. };
  1516. }
  1517. globalScope.URL = JURL;
  1518. })();
  1519. }