1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | 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; };
|
25 |
|
26 | var globalScope = require('./global_scope');
|
27 | if (!globalScope._pdfjsCompatibilityChecked) {
|
28 | globalScope._pdfjsCompatibilityChecked = true;
|
29 | var isNodeJS = require('./is_node');
|
30 | var hasDOM = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && (typeof document === 'undefined' ? 'undefined' : _typeof(document)) === 'object';
|
31 | (function checkNodeBtoa() {
|
32 | if (globalScope.btoa || !isNodeJS()) {
|
33 | return;
|
34 | }
|
35 | globalScope.btoa = function (chars) {
|
36 | return Buffer.from(chars, 'binary').toString('base64');
|
37 | };
|
38 | })();
|
39 | (function checkNodeAtob() {
|
40 | if (globalScope.atob || !isNodeJS()) {
|
41 | return;
|
42 | }
|
43 | globalScope.atob = function (input) {
|
44 | return Buffer.from(input, 'base64').toString('binary');
|
45 | };
|
46 | })();
|
47 | (function checkCurrentScript() {
|
48 | if (!hasDOM) {
|
49 | return;
|
50 | }
|
51 | if ('currentScript' in document) {
|
52 | return;
|
53 | }
|
54 | Object.defineProperty(document, 'currentScript', {
|
55 | get: function get() {
|
56 | var scripts = document.getElementsByTagName('script');
|
57 | return scripts[scripts.length - 1];
|
58 | },
|
59 |
|
60 | enumerable: true,
|
61 | configurable: true
|
62 | });
|
63 | })();
|
64 | (function checkChildNodeRemove() {
|
65 | if (!hasDOM) {
|
66 | return;
|
67 | }
|
68 | if (typeof Element.prototype.remove !== 'undefined') {
|
69 | return;
|
70 | }
|
71 | Element.prototype.remove = function () {
|
72 | if (this.parentNode) {
|
73 | this.parentNode.removeChild(this);
|
74 | }
|
75 | };
|
76 | })();
|
77 | (function checkStringIncludes() {
|
78 | if (String.prototype.includes) {
|
79 | return;
|
80 | }
|
81 | require('core-js/fn/string/includes');
|
82 | })();
|
83 | (function checkArrayIncludes() {
|
84 | if (Array.prototype.includes) {
|
85 | return;
|
86 | }
|
87 | require('core-js/fn/array/includes');
|
88 | })();
|
89 | (function checkMathLog2() {
|
90 | if (Math.log2) {
|
91 | return;
|
92 | }
|
93 | Math.log2 = require('core-js/fn/math/log2');
|
94 | })();
|
95 | (function checkNumberIsNaN() {
|
96 | if (Number.isNaN) {
|
97 | return;
|
98 | }
|
99 | Number.isNaN = require('core-js/fn/number/is-nan');
|
100 | })();
|
101 | (function checkNumberIsInteger() {
|
102 | if (Number.isInteger) {
|
103 | return;
|
104 | }
|
105 | Number.isInteger = require('core-js/fn/number/is-integer');
|
106 | })();
|
107 | (function checkPromise() {
|
108 | if (globalScope.Promise) {
|
109 | return;
|
110 | }
|
111 | globalScope.Promise = require('core-js/fn/promise');
|
112 | })();
|
113 | (function checkWeakMap() {
|
114 | if (globalScope.WeakMap) {
|
115 | return;
|
116 | }
|
117 | globalScope.WeakMap = require('core-js/fn/weak-map');
|
118 | })();
|
119 | (function checkURLConstructor() {
|
120 | var hasWorkingUrl = false;
|
121 | try {
|
122 | if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
|
123 | var u = new URL('b', 'http://a');
|
124 | u.pathname = 'c%20d';
|
125 | hasWorkingUrl = u.href === 'http://a/c%20d';
|
126 | }
|
127 | } catch (e) {}
|
128 | if (hasWorkingUrl) {
|
129 | return;
|
130 | }
|
131 | var relative = Object.create(null);
|
132 | relative['ftp'] = 21;
|
133 | relative['file'] = 0;
|
134 | relative['gopher'] = 70;
|
135 | relative['http'] = 80;
|
136 | relative['https'] = 443;
|
137 | relative['ws'] = 80;
|
138 | relative['wss'] = 443;
|
139 | var relativePathDotMapping = Object.create(null);
|
140 | relativePathDotMapping['%2e'] = '.';
|
141 | relativePathDotMapping['.%2e'] = '..';
|
142 | relativePathDotMapping['%2e.'] = '..';
|
143 | relativePathDotMapping['%2e%2e'] = '..';
|
144 | function isRelativeScheme(scheme) {
|
145 | return relative[scheme] !== undefined;
|
146 | }
|
147 | function invalid() {
|
148 | clear.call(this);
|
149 | this._isInvalid = true;
|
150 | }
|
151 | function IDNAToASCII(h) {
|
152 | if (h === '') {
|
153 | invalid.call(this);
|
154 | }
|
155 | return h.toLowerCase();
|
156 | }
|
157 | function percentEscape(c) {
|
158 | var unicode = c.charCodeAt(0);
|
159 | if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) {
|
160 | return c;
|
161 | }
|
162 | return encodeURIComponent(c);
|
163 | }
|
164 | function percentEscapeQuery(c) {
|
165 | var unicode = c.charCodeAt(0);
|
166 | if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) {
|
167 | return c;
|
168 | }
|
169 | return encodeURIComponent(c);
|
170 | }
|
171 | var EOF,
|
172 | ALPHA = /[a-zA-Z]/,
|
173 | ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
|
174 | function parse(input, stateOverride, base) {
|
175 | function err(message) {
|
176 | errors.push(message);
|
177 | }
|
178 | var state = stateOverride || 'scheme start',
|
179 | cursor = 0,
|
180 | buffer = '',
|
181 | seenAt = false,
|
182 | seenBracket = false,
|
183 | errors = [];
|
184 | loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
|
185 | var c = input[cursor];
|
186 | switch (state) {
|
187 | case 'scheme start':
|
188 | if (c && ALPHA.test(c)) {
|
189 | buffer += c.toLowerCase();
|
190 | state = 'scheme';
|
191 | } else if (!stateOverride) {
|
192 | buffer = '';
|
193 | state = 'no scheme';
|
194 | continue;
|
195 | } else {
|
196 | err('Invalid scheme.');
|
197 | break loop;
|
198 | }
|
199 | break;
|
200 | case 'scheme':
|
201 | if (c && ALPHANUMERIC.test(c)) {
|
202 | buffer += c.toLowerCase();
|
203 | } else if (c === ':') {
|
204 | this._scheme = buffer;
|
205 | buffer = '';
|
206 | if (stateOverride) {
|
207 | break loop;
|
208 | }
|
209 | if (isRelativeScheme(this._scheme)) {
|
210 | this._isRelative = true;
|
211 | }
|
212 | if (this._scheme === 'file') {
|
213 | state = 'relative';
|
214 | } else if (this._isRelative && base && base._scheme === this._scheme) {
|
215 | state = 'relative or authority';
|
216 | } else if (this._isRelative) {
|
217 | state = 'authority first slash';
|
218 | } else {
|
219 | state = 'scheme data';
|
220 | }
|
221 | } else if (!stateOverride) {
|
222 | buffer = '';
|
223 | cursor = 0;
|
224 | state = 'no scheme';
|
225 | continue;
|
226 | } else if (c === EOF) {
|
227 | break loop;
|
228 | } else {
|
229 | err('Code point not allowed in scheme: ' + c);
|
230 | break loop;
|
231 | }
|
232 | break;
|
233 | case 'scheme data':
|
234 | if (c === '?') {
|
235 | this._query = '?';
|
236 | state = 'query';
|
237 | } else if (c === '#') {
|
238 | this._fragment = '#';
|
239 | state = 'fragment';
|
240 | } else {
|
241 | if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
|
242 | this._schemeData += percentEscape(c);
|
243 | }
|
244 | }
|
245 | break;
|
246 | case 'no scheme':
|
247 | if (!base || !isRelativeScheme(base._scheme)) {
|
248 | err('Missing scheme.');
|
249 | invalid.call(this);
|
250 | } else {
|
251 | state = 'relative';
|
252 | continue;
|
253 | }
|
254 | break;
|
255 | case 'relative or authority':
|
256 | if (c === '/' && input[cursor + 1] === '/') {
|
257 | state = 'authority ignore slashes';
|
258 | } else {
|
259 | err('Expected /, got: ' + c);
|
260 | state = 'relative';
|
261 | continue;
|
262 | }
|
263 | break;
|
264 | case 'relative':
|
265 | this._isRelative = true;
|
266 | if (this._scheme !== 'file') {
|
267 | this._scheme = base._scheme;
|
268 | }
|
269 | if (c === EOF) {
|
270 | this._host = base._host;
|
271 | this._port = base._port;
|
272 | this._path = base._path.slice();
|
273 | this._query = base._query;
|
274 | this._username = base._username;
|
275 | this._password = base._password;
|
276 | break loop;
|
277 | } else if (c === '/' || c === '\\') {
|
278 | if (c === '\\') {
|
279 | err('\\ is an invalid code point.');
|
280 | }
|
281 | state = 'relative slash';
|
282 | } else if (c === '?') {
|
283 | this._host = base._host;
|
284 | this._port = base._port;
|
285 | this._path = base._path.slice();
|
286 | this._query = '?';
|
287 | this._username = base._username;
|
288 | this._password = base._password;
|
289 | state = 'query';
|
290 | } else if (c === '#') {
|
291 | this._host = base._host;
|
292 | this._port = base._port;
|
293 | this._path = base._path.slice();
|
294 | this._query = base._query;
|
295 | this._fragment = '#';
|
296 | this._username = base._username;
|
297 | this._password = base._password;
|
298 | state = 'fragment';
|
299 | } else {
|
300 | var nextC = input[cursor + 1];
|
301 | var nextNextC = input[cursor + 2];
|
302 | if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') {
|
303 | this._host = base._host;
|
304 | this._port = base._port;
|
305 | this._username = base._username;
|
306 | this._password = base._password;
|
307 | this._path = base._path.slice();
|
308 | this._path.pop();
|
309 | }
|
310 | state = 'relative path';
|
311 | continue;
|
312 | }
|
313 | break;
|
314 | case 'relative slash':
|
315 | if (c === '/' || c === '\\') {
|
316 | if (c === '\\') {
|
317 | err('\\ is an invalid code point.');
|
318 | }
|
319 | if (this._scheme === 'file') {
|
320 | state = 'file host';
|
321 | } else {
|
322 | state = 'authority ignore slashes';
|
323 | }
|
324 | } else {
|
325 | if (this._scheme !== 'file') {
|
326 | this._host = base._host;
|
327 | this._port = base._port;
|
328 | this._username = base._username;
|
329 | this._password = base._password;
|
330 | }
|
331 | state = 'relative path';
|
332 | continue;
|
333 | }
|
334 | break;
|
335 | case 'authority first slash':
|
336 | if (c === '/') {
|
337 | state = 'authority second slash';
|
338 | } else {
|
339 | err('Expected \'/\', got: ' + c);
|
340 | state = 'authority ignore slashes';
|
341 | continue;
|
342 | }
|
343 | break;
|
344 | case 'authority second slash':
|
345 | state = 'authority ignore slashes';
|
346 | if (c !== '/') {
|
347 | err('Expected \'/\', got: ' + c);
|
348 | continue;
|
349 | }
|
350 | break;
|
351 | case 'authority ignore slashes':
|
352 | if (c !== '/' && c !== '\\') {
|
353 | state = 'authority';
|
354 | continue;
|
355 | } else {
|
356 | err('Expected authority, got: ' + c);
|
357 | }
|
358 | break;
|
359 | case 'authority':
|
360 | if (c === '@') {
|
361 | if (seenAt) {
|
362 | err('@ already seen.');
|
363 | buffer += '%40';
|
364 | }
|
365 | seenAt = true;
|
366 | for (var i = 0; i < buffer.length; i++) {
|
367 | var cp = buffer[i];
|
368 | if (cp === '\t' || cp === '\n' || cp === '\r') {
|
369 | err('Invalid whitespace in authority.');
|
370 | continue;
|
371 | }
|
372 | if (cp === ':' && this._password === null) {
|
373 | this._password = '';
|
374 | continue;
|
375 | }
|
376 | var tempC = percentEscape(cp);
|
377 | if (this._password !== null) {
|
378 | this._password += tempC;
|
379 | } else {
|
380 | this._username += tempC;
|
381 | }
|
382 | }
|
383 | buffer = '';
|
384 | } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
|
385 | cursor -= buffer.length;
|
386 | buffer = '';
|
387 | state = 'host';
|
388 | continue;
|
389 | } else {
|
390 | buffer += c;
|
391 | }
|
392 | break;
|
393 | case 'file host':
|
394 | if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
|
395 | if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
|
396 | state = 'relative path';
|
397 | } else if (buffer.length === 0) {
|
398 | state = 'relative path start';
|
399 | } else {
|
400 | this._host = IDNAToASCII.call(this, buffer);
|
401 | buffer = '';
|
402 | state = 'relative path start';
|
403 | }
|
404 | continue;
|
405 | } else if (c === '\t' || c === '\n' || c === '\r') {
|
406 | err('Invalid whitespace in file host.');
|
407 | } else {
|
408 | buffer += c;
|
409 | }
|
410 | break;
|
411 | case 'host':
|
412 | case 'hostname':
|
413 | if (c === ':' && !seenBracket) {
|
414 | this._host = IDNAToASCII.call(this, buffer);
|
415 | buffer = '';
|
416 | state = 'port';
|
417 | if (stateOverride === 'hostname') {
|
418 | break loop;
|
419 | }
|
420 | } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') {
|
421 | this._host = IDNAToASCII.call(this, buffer);
|
422 | buffer = '';
|
423 | state = 'relative path start';
|
424 | if (stateOverride) {
|
425 | break loop;
|
426 | }
|
427 | continue;
|
428 | } else if (c !== '\t' && c !== '\n' && c !== '\r') {
|
429 | if (c === '[') {
|
430 | seenBracket = true;
|
431 | } else if (c === ']') {
|
432 | seenBracket = false;
|
433 | }
|
434 | buffer += c;
|
435 | } else {
|
436 | err('Invalid code point in host/hostname: ' + c);
|
437 | }
|
438 | break;
|
439 | case 'port':
|
440 | if (/[0-9]/.test(c)) {
|
441 | buffer += c;
|
442 | } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) {
|
443 | if (buffer !== '') {
|
444 | var temp = parseInt(buffer, 10);
|
445 | if (temp !== relative[this._scheme]) {
|
446 | this._port = temp + '';
|
447 | }
|
448 | buffer = '';
|
449 | }
|
450 | if (stateOverride) {
|
451 | break loop;
|
452 | }
|
453 | state = 'relative path start';
|
454 | continue;
|
455 | } else if (c === '\t' || c === '\n' || c === '\r') {
|
456 | err('Invalid code point in port: ' + c);
|
457 | } else {
|
458 | invalid.call(this);
|
459 | }
|
460 | break;
|
461 | case 'relative path start':
|
462 | if (c === '\\') {
|
463 | err('\'\\\' not allowed in path.');
|
464 | }
|
465 | state = 'relative path';
|
466 | if (c !== '/' && c !== '\\') {
|
467 | continue;
|
468 | }
|
469 | break;
|
470 | case 'relative path':
|
471 | if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) {
|
472 | if (c === '\\') {
|
473 | err('\\ not allowed in relative path.');
|
474 | }
|
475 | var tmp;
|
476 | if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
|
477 | buffer = tmp;
|
478 | }
|
479 | if (buffer === '..') {
|
480 | this._path.pop();
|
481 | if (c !== '/' && c !== '\\') {
|
482 | this._path.push('');
|
483 | }
|
484 | } else if (buffer === '.' && c !== '/' && c !== '\\') {
|
485 | this._path.push('');
|
486 | } else if (buffer !== '.') {
|
487 | if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
|
488 | buffer = buffer[0] + ':';
|
489 | }
|
490 | this._path.push(buffer);
|
491 | }
|
492 | buffer = '';
|
493 | if (c === '?') {
|
494 | this._query = '?';
|
495 | state = 'query';
|
496 | } else if (c === '#') {
|
497 | this._fragment = '#';
|
498 | state = 'fragment';
|
499 | }
|
500 | } else if (c !== '\t' && c !== '\n' && c !== '\r') {
|
501 | buffer += percentEscape(c);
|
502 | }
|
503 | break;
|
504 | case 'query':
|
505 | if (!stateOverride && c === '#') {
|
506 | this._fragment = '#';
|
507 | state = 'fragment';
|
508 | } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
|
509 | this._query += percentEscapeQuery(c);
|
510 | }
|
511 | break;
|
512 | case 'fragment':
|
513 | if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') {
|
514 | this._fragment += c;
|
515 | }
|
516 | break;
|
517 | }
|
518 | cursor++;
|
519 | }
|
520 | }
|
521 | function clear() {
|
522 | this._scheme = '';
|
523 | this._schemeData = '';
|
524 | this._username = '';
|
525 | this._password = null;
|
526 | this._host = '';
|
527 | this._port = '';
|
528 | this._path = [];
|
529 | this._query = '';
|
530 | this._fragment = '';
|
531 | this._isInvalid = false;
|
532 | this._isRelative = false;
|
533 | }
|
534 | function JURL(url, base) {
|
535 | if (base !== undefined && !(base instanceof JURL)) {
|
536 | base = new JURL(String(base));
|
537 | }
|
538 | this._url = url;
|
539 | clear.call(this);
|
540 | var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
|
541 | parse.call(this, input, null, base);
|
542 | }
|
543 | JURL.prototype = {
|
544 | toString: function toString() {
|
545 | return this.href;
|
546 | },
|
547 |
|
548 | get href() {
|
549 | if (this._isInvalid) {
|
550 | return this._url;
|
551 | }
|
552 | var authority = '';
|
553 | if (this._username !== '' || this._password !== null) {
|
554 | authority = this._username + (this._password !== null ? ':' + this._password : '') + '@';
|
555 | }
|
556 | return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
|
557 | },
|
558 | set href(value) {
|
559 | clear.call(this);
|
560 | parse.call(this, value);
|
561 | },
|
562 | get protocol() {
|
563 | return this._scheme + ':';
|
564 | },
|
565 | set protocol(value) {
|
566 | if (this._isInvalid) {
|
567 | return;
|
568 | }
|
569 | parse.call(this, value + ':', 'scheme start');
|
570 | },
|
571 | get host() {
|
572 | return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
|
573 | },
|
574 | set host(value) {
|
575 | if (this._isInvalid || !this._isRelative) {
|
576 | return;
|
577 | }
|
578 | parse.call(this, value, 'host');
|
579 | },
|
580 | get hostname() {
|
581 | return this._host;
|
582 | },
|
583 | set hostname(value) {
|
584 | if (this._isInvalid || !this._isRelative) {
|
585 | return;
|
586 | }
|
587 | parse.call(this, value, 'hostname');
|
588 | },
|
589 | get port() {
|
590 | return this._port;
|
591 | },
|
592 | set port(value) {
|
593 | if (this._isInvalid || !this._isRelative) {
|
594 | return;
|
595 | }
|
596 | parse.call(this, value, 'port');
|
597 | },
|
598 | get pathname() {
|
599 | return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
|
600 | },
|
601 | set pathname(value) {
|
602 | if (this._isInvalid || !this._isRelative) {
|
603 | return;
|
604 | }
|
605 | this._path = [];
|
606 | parse.call(this, value, 'relative path start');
|
607 | },
|
608 | get search() {
|
609 | return this._isInvalid || !this._query || this._query === '?' ? '' : this._query;
|
610 | },
|
611 | set search(value) {
|
612 | if (this._isInvalid || !this._isRelative) {
|
613 | return;
|
614 | }
|
615 | this._query = '?';
|
616 | if (value[0] === '?') {
|
617 | value = value.slice(1);
|
618 | }
|
619 | parse.call(this, value, 'query');
|
620 | },
|
621 | get hash() {
|
622 | return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment;
|
623 | },
|
624 | set hash(value) {
|
625 | if (this._isInvalid) {
|
626 | return;
|
627 | }
|
628 | this._fragment = '#';
|
629 | if (value[0] === '#') {
|
630 | value = value.slice(1);
|
631 | }
|
632 | parse.call(this, value, 'fragment');
|
633 | },
|
634 | get origin() {
|
635 | var host;
|
636 | if (this._isInvalid || !this._scheme) {
|
637 | return '';
|
638 | }
|
639 | switch (this._scheme) {
|
640 | case 'data':
|
641 | case 'file':
|
642 | case 'javascript':
|
643 | case 'mailto':
|
644 | return 'null';
|
645 | case 'blob':
|
646 | try {
|
647 | return new JURL(this._schemeData).origin || 'null';
|
648 | } catch (_) {}
|
649 | return 'null';
|
650 | }
|
651 | host = this.host;
|
652 | if (!host) {
|
653 | return '';
|
654 | }
|
655 | return this._scheme + '://' + host;
|
656 | }
|
657 | };
|
658 | var OriginalURL = globalScope.URL;
|
659 | if (OriginalURL) {
|
660 | JURL.createObjectURL = function (blob) {
|
661 | return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
|
662 | };
|
663 | JURL.revokeObjectURL = function (url) {
|
664 | OriginalURL.revokeObjectURL(url);
|
665 | };
|
666 | }
|
667 | globalScope.URL = JURL;
|
668 | })();
|
669 | (function checkObjectValues() {
|
670 | if (Object.values) {
|
671 | return;
|
672 | }
|
673 | Object.values = require('core-js/fn/object/values');
|
674 | })();
|
675 | } |
\ | No newline at end of file |