compatibility.js 47 KB

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