1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import { __read, __assign, __decorate } from 'tslib';
|
8 | import { Location, PlatformLocation, LocationStrategy, APP_BASE_HREF, CommonModule, HashLocationStrategy, PathLocationStrategy } from '@angular/common';
|
9 | import { InjectionToken, Inject, Optional, NgModule } from '@angular/core';
|
10 | import { UpgradeModule } from '@angular/upgrade/static';
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function stripPrefix(val, prefix) {
|
20 | return val.startsWith(prefix) ? val.substring(prefix.length) : val;
|
21 | }
|
22 | function deepEqual(a, b) {
|
23 | if (a === b) {
|
24 | return true;
|
25 | }
|
26 | else if (!a || !b) {
|
27 | return false;
|
28 | }
|
29 | else {
|
30 | try {
|
31 | if ((a.prototype !== b.prototype) || (Array.isArray(a) && Array.isArray(b))) {
|
32 | return false;
|
33 | }
|
34 | return JSON.stringify(a) === JSON.stringify(b);
|
35 | }
|
36 | catch (e) {
|
37 | return false;
|
38 | }
|
39 | }
|
40 | }
|
41 | function isAnchor(el) {
|
42 | return el.href !== undefined;
|
43 | }
|
44 | function isPromise(obj) {
|
45 |
|
46 |
|
47 | return !!obj && typeof obj.then === 'function';
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | var PATH_MATCH = /^([^?#]*)(\?([^#]*))?(#(.*))?$/;
|
58 | var DOUBLE_SLASH_REGEX = /^\s*[\\/]{2,}/;
|
59 | var IGNORE_URI_REGEXP = /^\s*(javascript|mailto):/i;
|
60 | var DEFAULT_PORTS = {
|
61 | 'http:': 80,
|
62 | 'https:': 443,
|
63 | 'ftp:': 21
|
64 | };
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | var $locationShim = (function () {
|
74 | function $locationShim($injector, location, platformLocation, urlCodec, locationStrategy) {
|
75 | var _this = this;
|
76 | this.location = location;
|
77 | this.platformLocation = platformLocation;
|
78 | this.urlCodec = urlCodec;
|
79 | this.locationStrategy = locationStrategy;
|
80 | this.initalizing = true;
|
81 | this.updateBrowser = false;
|
82 | this.$$absUrl = '';
|
83 | this.$$url = '';
|
84 | this.$$host = '';
|
85 | this.$$replace = false;
|
86 | this.$$path = '';
|
87 | this.$$search = '';
|
88 | this.$$hash = '';
|
89 | this.$$changeListeners = [];
|
90 | this.cachedState = null;
|
91 | this.lastBrowserUrl = '';
|
92 |
|
93 | this.lastCachedState = null;
|
94 | var initialUrl = this.browserUrl();
|
95 | var parsedUrl = this.urlCodec.parse(initialUrl);
|
96 | if (typeof parsedUrl === 'string') {
|
97 | throw 'Invalid URL';
|
98 | }
|
99 | this.$$protocol = parsedUrl.protocol;
|
100 | this.$$host = parsedUrl.hostname;
|
101 | this.$$port = parseInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
|
102 | this.$$parseLinkUrl(initialUrl, initialUrl);
|
103 | this.cacheState();
|
104 | this.$$state = this.browserState();
|
105 | if (isPromise($injector)) {
|
106 | $injector.then(function ($i) { return _this.initialize($i); });
|
107 | }
|
108 | else {
|
109 | this.initialize($injector);
|
110 | }
|
111 | }
|
112 | $locationShim.prototype.initialize = function ($injector) {
|
113 | var _this = this;
|
114 | var $rootScope = $injector.get('$rootScope');
|
115 | var $rootElement = $injector.get('$rootElement');
|
116 | $rootElement.on('click', function (event) {
|
117 | if (event.ctrlKey || event.metaKey || event.shiftKey || event.which === 2 ||
|
118 | event.button === 2) {
|
119 | return;
|
120 | }
|
121 | var elm = event.target;
|
122 |
|
123 | while (elm && elm.nodeName.toLowerCase() !== 'a') {
|
124 |
|
125 | if (elm === $rootElement[0] || !(elm = elm.parentNode)) {
|
126 | return;
|
127 | }
|
128 | }
|
129 | if (!isAnchor(elm)) {
|
130 | return;
|
131 | }
|
132 | var absHref = elm.href;
|
133 | var relHref = elm.getAttribute('href');
|
134 |
|
135 | if (IGNORE_URI_REGEXP.test(absHref)) {
|
136 | return;
|
137 | }
|
138 | if (absHref && !elm.getAttribute('target') && !event.isDefaultPrevented()) {
|
139 | if (_this.$$parseLinkUrl(absHref, relHref)) {
|
140 |
|
141 |
|
142 |
|
143 | event.preventDefault();
|
144 |
|
145 | if (_this.absUrl() !== _this.browserUrl()) {
|
146 | $rootScope.$apply();
|
147 | }
|
148 | }
|
149 | }
|
150 | });
|
151 | this.location.onUrlChange(function (newUrl, newState) {
|
152 | var oldUrl = _this.absUrl();
|
153 | var oldState = _this.$$state;
|
154 | _this.$$parse(newUrl);
|
155 | newUrl = _this.absUrl();
|
156 | _this.$$state = newState;
|
157 | var defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl, newState, oldState)
|
158 | .defaultPrevented;
|
159 |
|
160 |
|
161 | if (_this.absUrl() !== newUrl)
|
162 | return;
|
163 |
|
164 |
|
165 | if (defaultPrevented) {
|
166 | _this.$$parse(oldUrl);
|
167 | _this.state(oldState);
|
168 | _this.setBrowserUrlWithFallback(oldUrl, false, oldState);
|
169 | _this.$$notifyChangeListeners(_this.url(), _this.$$state, oldUrl, oldState);
|
170 | }
|
171 | else {
|
172 | _this.initalizing = false;
|
173 | $rootScope.$broadcast('$locationChangeSuccess', newUrl, oldUrl, newState, oldState);
|
174 | _this.resetBrowserUpdate();
|
175 | }
|
176 | if (!$rootScope.$$phase) {
|
177 | $rootScope.$digest();
|
178 | }
|
179 | });
|
180 |
|
181 | $rootScope.$watch(function () {
|
182 | if (_this.initalizing || _this.updateBrowser) {
|
183 | _this.updateBrowser = false;
|
184 | var oldUrl_1 = _this.browserUrl();
|
185 | var newUrl = _this.absUrl();
|
186 | var oldState_1 = _this.browserState();
|
187 | var currentReplace_1 = _this.$$replace;
|
188 | var urlOrStateChanged_1 = !_this.urlCodec.areEqual(oldUrl_1, newUrl) || oldState_1 !== _this.$$state;
|
189 |
|
190 |
|
191 |
|
192 |
|
193 | if (_this.initalizing || urlOrStateChanged_1) {
|
194 | _this.initalizing = false;
|
195 | $rootScope.$evalAsync(function () {
|
196 |
|
197 | var newUrl = _this.absUrl();
|
198 | var defaultPrevented = $rootScope
|
199 | .$broadcast('$locationChangeStart', newUrl, oldUrl_1, _this.$$state, oldState_1)
|
200 | .defaultPrevented;
|
201 |
|
202 |
|
203 | if (_this.absUrl() !== newUrl)
|
204 | return;
|
205 | if (defaultPrevented) {
|
206 | _this.$$parse(oldUrl_1);
|
207 | _this.$$state = oldState_1;
|
208 | }
|
209 | else {
|
210 |
|
211 |
|
212 | if (urlOrStateChanged_1) {
|
213 | _this.setBrowserUrlWithFallback(newUrl, currentReplace_1, oldState_1 === _this.$$state ? null : _this.$$state);
|
214 | _this.$$replace = false;
|
215 | }
|
216 | $rootScope.$broadcast('$locationChangeSuccess', newUrl, oldUrl_1, _this.$$state, oldState_1);
|
217 | if (urlOrStateChanged_1) {
|
218 | _this.$$notifyChangeListeners(_this.url(), _this.$$state, oldUrl_1, oldState_1);
|
219 | }
|
220 | }
|
221 | });
|
222 | }
|
223 | }
|
224 | _this.$$replace = false;
|
225 | });
|
226 | };
|
227 | $locationShim.prototype.resetBrowserUpdate = function () {
|
228 | this.$$replace = false;
|
229 | this.$$state = this.browserState();
|
230 | this.updateBrowser = false;
|
231 | this.lastBrowserUrl = this.browserUrl();
|
232 | };
|
233 | $locationShim.prototype.browserUrl = function (url, replace, state) {
|
234 |
|
235 |
|
236 |
|
237 | if (typeof state === 'undefined') {
|
238 | state = null;
|
239 | }
|
240 |
|
241 | if (url) {
|
242 | var sameState = this.lastHistoryState === state;
|
243 |
|
244 | url = this.urlCodec.parse(url).href;
|
245 |
|
246 | if (this.lastBrowserUrl === url && sameState) {
|
247 | return this;
|
248 | }
|
249 | this.lastBrowserUrl = url;
|
250 | this.lastHistoryState = state;
|
251 |
|
252 |
|
253 | url = this.stripBaseUrl(this.getServerBase(), url) || url;
|
254 |
|
255 | if (replace) {
|
256 | this.locationStrategy.replaceState(state, '', url, '');
|
257 | }
|
258 | else {
|
259 | this.locationStrategy.pushState(state, '', url, '');
|
260 | }
|
261 | this.cacheState();
|
262 | return this;
|
263 |
|
264 | }
|
265 | else {
|
266 | return this.platformLocation.href;
|
267 | }
|
268 | };
|
269 | $locationShim.prototype.cacheState = function () {
|
270 |
|
271 | this.cachedState = this.platformLocation.getState();
|
272 | if (typeof this.cachedState === 'undefined') {
|
273 | this.cachedState = null;
|
274 | }
|
275 |
|
276 | if (deepEqual(this.cachedState, this.lastCachedState)) {
|
277 | this.cachedState = this.lastCachedState;
|
278 | }
|
279 | this.lastCachedState = this.cachedState;
|
280 | this.lastHistoryState = this.cachedState;
|
281 | };
|
282 | |
283 |
|
284 |
|
285 |
|
286 | $locationShim.prototype.browserState = function () { return this.cachedState; };
|
287 | $locationShim.prototype.stripBaseUrl = function (base, url) {
|
288 | if (url.startsWith(base)) {
|
289 | return url.substr(base.length);
|
290 | }
|
291 | return undefined;
|
292 | };
|
293 | $locationShim.prototype.getServerBase = function () {
|
294 | var _a = this.platformLocation, protocol = _a.protocol, hostname = _a.hostname, port = _a.port;
|
295 | var baseHref = this.locationStrategy.getBaseHref();
|
296 | var url = protocol + "//" + hostname + (port ? ':' + port : '') + (baseHref || '/');
|
297 | return url.endsWith('/') ? url : url + '/';
|
298 | };
|
299 | $locationShim.prototype.parseAppUrl = function (url) {
|
300 | if (DOUBLE_SLASH_REGEX.test(url)) {
|
301 | throw new Error("Bad Path - URL cannot start with double slashes: " + url);
|
302 | }
|
303 | var prefixed = (url.charAt(0) !== '/');
|
304 | if (prefixed) {
|
305 | url = '/' + url;
|
306 | }
|
307 | var match = this.urlCodec.parse(url, this.getServerBase());
|
308 | if (typeof match === 'string') {
|
309 | throw new Error("Bad URL - Cannot parse URL: " + url);
|
310 | }
|
311 | var path = prefixed && match.pathname.charAt(0) === '/' ? match.pathname.substring(1) : match.pathname;
|
312 | this.$$path = this.urlCodec.decodePath(path);
|
313 | this.$$search = this.urlCodec.decodeSearch(match.search);
|
314 | this.$$hash = this.urlCodec.decodeHash(match.hash);
|
315 |
|
316 | if (this.$$path && this.$$path.charAt(0) !== '/') {
|
317 | this.$$path = '/' + this.$$path;
|
318 | }
|
319 | };
|
320 | |
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 | $locationShim.prototype.onChange = function (fn, err) {
|
334 | if (err === void 0) { err = function (e) { }; }
|
335 | this.$$changeListeners.push([fn, err]);
|
336 | };
|
337 |
|
338 | $locationShim.prototype.$$notifyChangeListeners = function (url, state, oldUrl, oldState) {
|
339 | if (url === void 0) { url = ''; }
|
340 | if (oldUrl === void 0) { oldUrl = ''; }
|
341 | this.$$changeListeners.forEach(function (_a) {
|
342 | var _b = __read(_a, 2), fn = _b[0], err = _b[1];
|
343 | try {
|
344 | fn(url, state, oldUrl, oldState);
|
345 | }
|
346 | catch (e) {
|
347 | err(e);
|
348 | }
|
349 | });
|
350 | };
|
351 | |
352 |
|
353 |
|
354 |
|
355 |
|
356 | $locationShim.prototype.$$parse = function (url) {
|
357 | var pathUrl;
|
358 | if (url.startsWith('/')) {
|
359 | pathUrl = url;
|
360 | }
|
361 | else {
|
362 |
|
363 | pathUrl = this.stripBaseUrl(this.getServerBase(), url);
|
364 | }
|
365 | if (typeof pathUrl === 'undefined') {
|
366 | throw new Error("Invalid url \"" + url + "\", missing path prefix \"" + this.getServerBase() + "\".");
|
367 | }
|
368 | this.parseAppUrl(pathUrl);
|
369 | if (!this.$$path) {
|
370 | this.$$path = '/';
|
371 | }
|
372 | this.composeUrls();
|
373 | };
|
374 | |
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 | $locationShim.prototype.$$parseLinkUrl = function (url, relHref) {
|
381 |
|
382 | if (relHref && relHref[0] === '#') {
|
383 | this.hash(relHref.slice(1));
|
384 | return true;
|
385 | }
|
386 | var rewrittenUrl;
|
387 | var appUrl = this.stripBaseUrl(this.getServerBase(), url);
|
388 | if (typeof appUrl !== 'undefined') {
|
389 | rewrittenUrl = this.getServerBase() + appUrl;
|
390 | }
|
391 | else if (this.getServerBase() === url + '/') {
|
392 | rewrittenUrl = this.getServerBase();
|
393 | }
|
394 |
|
395 | if (rewrittenUrl) {
|
396 | this.$$parse(rewrittenUrl);
|
397 | }
|
398 | return !!rewrittenUrl;
|
399 | };
|
400 | $locationShim.prototype.setBrowserUrlWithFallback = function (url, replace, state) {
|
401 | var oldUrl = this.url();
|
402 | var oldState = this.$$state;
|
403 | try {
|
404 | this.browserUrl(url, replace, state);
|
405 |
|
406 |
|
407 |
|
408 | this.$$state = this.browserState();
|
409 | }
|
410 | catch (e) {
|
411 |
|
412 | this.url(oldUrl);
|
413 | this.$$state = oldState;
|
414 | throw e;
|
415 | }
|
416 | };
|
417 | $locationShim.prototype.composeUrls = function () {
|
418 | this.$$url = this.urlCodec.normalize(this.$$path, this.$$search, this.$$hash);
|
419 | this.$$absUrl = this.getServerBase() + this.$$url.substr(1);
|
420 | this.updateBrowser = true;
|
421 | };
|
422 | |
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 | $locationShim.prototype.absUrl = function () { return this.$$absUrl; };
|
435 | $locationShim.prototype.url = function (url) {
|
436 | if (typeof url === 'string') {
|
437 | if (!url.length) {
|
438 | url = '/';
|
439 | }
|
440 | var match = PATH_MATCH.exec(url);
|
441 | if (!match)
|
442 | return this;
|
443 | if (match[1] || url === '')
|
444 | this.path(this.urlCodec.decodePath(match[1]));
|
445 | if (match[2] || match[1] || url === '')
|
446 | this.search(match[3] || '');
|
447 | this.hash(match[5] || '');
|
448 |
|
449 | return this;
|
450 | }
|
451 | return this.$$url;
|
452 | };
|
453 | |
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 | $locationShim.prototype.protocol = function () { return this.$$protocol; };
|
463 | |
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | $locationShim.prototype.host = function () { return this.$$host; };
|
483 | |
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 | $locationShim.prototype.port = function () { return this.$$port; };
|
493 | $locationShim.prototype.path = function (path) {
|
494 | if (typeof path === 'undefined') {
|
495 | return this.$$path;
|
496 | }
|
497 |
|
498 | path = path !== null ? path.toString() : '';
|
499 | path = path.charAt(0) === '/' ? path : '/' + path;
|
500 | this.$$path = path;
|
501 | this.composeUrls();
|
502 | return this;
|
503 | };
|
504 | $locationShim.prototype.search = function (search, paramValue) {
|
505 | switch (arguments.length) {
|
506 | case 0:
|
507 | return this.$$search;
|
508 | case 1:
|
509 | if (typeof search === 'string' || typeof search === 'number') {
|
510 | this.$$search = this.urlCodec.decodeSearch(search.toString());
|
511 | }
|
512 | else if (typeof search === 'object' && search !== null) {
|
513 |
|
514 | search = __assign({}, search);
|
515 |
|
516 | for (var key in search) {
|
517 | if (search[key] == null)
|
518 | delete search[key];
|
519 | }
|
520 | this.$$search = search;
|
521 | }
|
522 | else {
|
523 | throw new Error('LocationProvider.search(): First argument must be a string or an object.');
|
524 | }
|
525 | break;
|
526 | default:
|
527 | if (typeof search === 'string') {
|
528 | var currentSearch = this.search();
|
529 | if (typeof paramValue === 'undefined' || paramValue === null) {
|
530 | delete currentSearch[search];
|
531 | return this.search(currentSearch);
|
532 | }
|
533 | else {
|
534 | currentSearch[search] = paramValue;
|
535 | return this.search(currentSearch);
|
536 | }
|
537 | }
|
538 | }
|
539 | this.composeUrls();
|
540 | return this;
|
541 | };
|
542 | $locationShim.prototype.hash = function (hash) {
|
543 | if (typeof hash === 'undefined') {
|
544 | return this.$$hash;
|
545 | }
|
546 | this.$$hash = hash !== null ? hash.toString() : '';
|
547 | this.composeUrls();
|
548 | return this;
|
549 | };
|
550 | |
551 |
|
552 |
|
553 |
|
554 | $locationShim.prototype.replace = function () {
|
555 | this.$$replace = true;
|
556 | return this;
|
557 | };
|
558 | $locationShim.prototype.state = function (state) {
|
559 | if (typeof state === 'undefined') {
|
560 | return this.$$state;
|
561 | }
|
562 | this.$$state = state;
|
563 | return this;
|
564 | };
|
565 | return $locationShim;
|
566 | }());
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | var $locationShimProvider = (function () {
|
574 | function $locationShimProvider(ngUpgrade, location, platformLocation, urlCodec, locationStrategy) {
|
575 | this.ngUpgrade = ngUpgrade;
|
576 | this.location = location;
|
577 | this.platformLocation = platformLocation;
|
578 | this.urlCodec = urlCodec;
|
579 | this.locationStrategy = locationStrategy;
|
580 | }
|
581 | |
582 |
|
583 |
|
584 | $locationShimProvider.prototype.$get = function () {
|
585 | return new $locationShim(this.ngUpgrade.$injector, this.location, this.platformLocation, this.urlCodec, this.locationStrategy);
|
586 | };
|
587 | |
588 |
|
589 |
|
590 |
|
591 | $locationShimProvider.prototype.hashPrefix = function (prefix) {
|
592 | throw new Error('Configure LocationUpgrade through LocationUpgradeModule.config method.');
|
593 | };
|
594 | |
595 |
|
596 |
|
597 |
|
598 | $locationShimProvider.prototype.html5Mode = function (mode) {
|
599 | throw new Error('Configure LocationUpgrade through LocationUpgradeModule.config method.');
|
600 | };
|
601 | return $locationShimProvider;
|
602 | }());
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 | var UrlCodec = (function () {
|
617 | function UrlCodec() {
|
618 | }
|
619 | return UrlCodec;
|
620 | }());
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 | var AngularJSUrlCodec = (function () {
|
628 | function AngularJSUrlCodec() {
|
629 | }
|
630 |
|
631 | AngularJSUrlCodec.prototype.encodePath = function (path) {
|
632 | var segments = path.split('/');
|
633 | var i = segments.length;
|
634 | while (i--) {
|
635 |
|
636 | segments[i] = encodeUriSegment(segments[i].replace(/%2F/g, '/'));
|
637 | }
|
638 | path = segments.join('/');
|
639 | return _stripIndexHtml((path && path[0] !== '/' && '/' || '') + path);
|
640 | };
|
641 |
|
642 | AngularJSUrlCodec.prototype.encodeSearch = function (search) {
|
643 | if (typeof search === 'string') {
|
644 | search = parseKeyValue(search);
|
645 | }
|
646 | search = toKeyValue(search);
|
647 | return search ? '?' + search : '';
|
648 | };
|
649 |
|
650 | AngularJSUrlCodec.prototype.encodeHash = function (hash) {
|
651 | hash = encodeUriSegment(hash);
|
652 | return hash ? '#' + hash : '';
|
653 | };
|
654 |
|
655 | AngularJSUrlCodec.prototype.decodePath = function (path, html5Mode) {
|
656 | if (html5Mode === void 0) { html5Mode = true; }
|
657 | var segments = path.split('/');
|
658 | var i = segments.length;
|
659 | while (i--) {
|
660 | segments[i] = decodeURIComponent(segments[i]);
|
661 | if (html5Mode) {
|
662 |
|
663 | segments[i] = segments[i].replace(/\//g, '%2F');
|
664 | }
|
665 | }
|
666 | return segments.join('/');
|
667 | };
|
668 |
|
669 | AngularJSUrlCodec.prototype.decodeSearch = function (search) { return parseKeyValue(search); };
|
670 |
|
671 | AngularJSUrlCodec.prototype.decodeHash = function (hash) {
|
672 | hash = decodeURIComponent(hash);
|
673 | return hash[0] === '#' ? hash.substring(1) : hash;
|
674 | };
|
675 | AngularJSUrlCodec.prototype.normalize = function (pathOrHref, search, hash, baseUrl) {
|
676 | if (arguments.length === 1) {
|
677 | var parsed = this.parse(pathOrHref, baseUrl);
|
678 | if (typeof parsed === 'string') {
|
679 | return parsed;
|
680 | }
|
681 | var serverUrl = parsed.protocol + "://" + parsed.hostname + (parsed.port ? ':' + parsed.port : '');
|
682 | return this.normalize(this.decodePath(parsed.pathname), this.decodeSearch(parsed.search), this.decodeHash(parsed.hash), serverUrl);
|
683 | }
|
684 | else {
|
685 | var encPath = this.encodePath(pathOrHref);
|
686 | var encSearch = search && this.encodeSearch(search) || '';
|
687 | var encHash = hash && this.encodeHash(hash) || '';
|
688 | var joinedPath = (baseUrl || '') + encPath;
|
689 | if (!joinedPath.length || joinedPath[0] !== '/') {
|
690 | joinedPath = '/' + joinedPath;
|
691 | }
|
692 | return joinedPath + encSearch + encHash;
|
693 | }
|
694 | };
|
695 | AngularJSUrlCodec.prototype.areEqual = function (valA, valB) { return this.normalize(valA) === this.normalize(valB); };
|
696 |
|
697 | AngularJSUrlCodec.prototype.parse = function (url, base) {
|
698 | try {
|
699 |
|
700 | var parsed = !base ? new URL(url) : new URL(url, base);
|
701 | return {
|
702 | href: parsed.href,
|
703 | protocol: parsed.protocol ? parsed.protocol.replace(/:$/, '') : '',
|
704 | host: parsed.host,
|
705 | search: parsed.search ? parsed.search.replace(/^\?/, '') : '',
|
706 | hash: parsed.hash ? parsed.hash.replace(/^#/, '') : '',
|
707 | hostname: parsed.hostname,
|
708 | port: parsed.port,
|
709 | pathname: (parsed.pathname.charAt(0) === '/') ? parsed.pathname : '/' + parsed.pathname
|
710 | };
|
711 | }
|
712 | catch (e) {
|
713 | throw new Error("Invalid URL (" + url + ") with base (" + base + ")");
|
714 | }
|
715 | };
|
716 | return AngularJSUrlCodec;
|
717 | }());
|
718 | function _stripIndexHtml(url) {
|
719 | return url.replace(/\/index.html$/, '');
|
720 | }
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 | function tryDecodeURIComponent(value) {
|
728 | try {
|
729 | return decodeURIComponent(value);
|
730 | }
|
731 | catch (e) {
|
732 |
|
733 | return undefined;
|
734 | }
|
735 | }
|
736 |
|
737 |
|
738 |
|
739 |
|
740 | function parseKeyValue(keyValue) {
|
741 | var obj = {};
|
742 | (keyValue || '').split('&').forEach(function (keyValue) {
|
743 | var splitPoint, key, val;
|
744 | if (keyValue) {
|
745 | key = keyValue = keyValue.replace(/\+/g, '%20');
|
746 | splitPoint = keyValue.indexOf('=');
|
747 | if (splitPoint !== -1) {
|
748 | key = keyValue.substring(0, splitPoint);
|
749 | val = keyValue.substring(splitPoint + 1);
|
750 | }
|
751 | key = tryDecodeURIComponent(key);
|
752 | if (typeof key !== 'undefined') {
|
753 | val = typeof val !== 'undefined' ? tryDecodeURIComponent(val) : true;
|
754 | if (!obj.hasOwnProperty(key)) {
|
755 | obj[key] = val;
|
756 | }
|
757 | else if (Array.isArray(obj[key])) {
|
758 | obj[key].push(val);
|
759 | }
|
760 | else {
|
761 | obj[key] = [obj[key], val];
|
762 | }
|
763 | }
|
764 | }
|
765 | });
|
766 | return obj;
|
767 | }
|
768 |
|
769 |
|
770 |
|
771 |
|
772 | function toKeyValue(obj) {
|
773 | var parts = [];
|
774 | var _loop_1 = function (key) {
|
775 | var value = obj[key];
|
776 | if (Array.isArray(value)) {
|
777 | value.forEach(function (arrayValue) {
|
778 | parts.push(encodeUriQuery(key, true) +
|
779 | (arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
|
780 | });
|
781 | }
|
782 | else {
|
783 | parts.push(encodeUriQuery(key, true) +
|
784 | (value === true ? '' : '=' + encodeUriQuery(value, true)));
|
785 | }
|
786 | };
|
787 | for (var key in obj) {
|
788 | _loop_1(key);
|
789 | }
|
790 | return parts.length ? parts.join('&') : '';
|
791 | }
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 | function encodeUriSegment(val) {
|
806 | return encodeUriQuery(val, true)
|
807 | .replace(/%26/gi, '&')
|
808 | .replace(/%3D/gi, '=')
|
809 | .replace(/%2B/gi, '+');
|
810 | }
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 | function encodeUriQuery(val, pctEncodeSpaces) {
|
825 | if (pctEncodeSpaces === void 0) { pctEncodeSpaces = false; }
|
826 | return encodeURIComponent(val)
|
827 | .replace(/%40/gi, '@')
|
828 | .replace(/%3A/gi, ':')
|
829 | .replace(/%24/g, '$')
|
830 | .replace(/%2C/gi, ',')
|
831 | .replace(/%3B/gi, ';')
|
832 | .replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
|
833 | }
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 | var LOCATION_UPGRADE_CONFIGURATION = new InjectionToken('LOCATION_UPGRADE_CONFIGURATION');
|
848 | var APP_BASE_HREF_RESOLVED = new InjectionToken('APP_BASE_HREF_RESOLVED');
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 | var LocationUpgradeModule = (function () {
|
857 | function LocationUpgradeModule() {
|
858 | }
|
859 | LocationUpgradeModule_1 = LocationUpgradeModule;
|
860 | LocationUpgradeModule.config = function (config) {
|
861 | return {
|
862 | ngModule: LocationUpgradeModule_1,
|
863 | providers: [
|
864 | Location,
|
865 | {
|
866 | provide: $locationShim,
|
867 | useFactory: provide$location,
|
868 | deps: [UpgradeModule, Location, PlatformLocation, UrlCodec, LocationStrategy]
|
869 | },
|
870 | { provide: LOCATION_UPGRADE_CONFIGURATION, useValue: config ? config : {} },
|
871 | { provide: UrlCodec, useFactory: provideUrlCodec, deps: [LOCATION_UPGRADE_CONFIGURATION] },
|
872 | {
|
873 | provide: APP_BASE_HREF_RESOLVED,
|
874 | useFactory: provideAppBaseHref,
|
875 | deps: [LOCATION_UPGRADE_CONFIGURATION, [new Inject(APP_BASE_HREF), new Optional()]]
|
876 | },
|
877 | {
|
878 | provide: LocationStrategy,
|
879 | useFactory: provideLocationStrategy,
|
880 | deps: [
|
881 | PlatformLocation,
|
882 | APP_BASE_HREF_RESOLVED,
|
883 | LOCATION_UPGRADE_CONFIGURATION,
|
884 | ]
|
885 | },
|
886 | ],
|
887 | };
|
888 | };
|
889 | var LocationUpgradeModule_1;
|
890 | LocationUpgradeModule = LocationUpgradeModule_1 = __decorate([
|
891 | NgModule({ imports: [CommonModule] })
|
892 | ], LocationUpgradeModule);
|
893 | return LocationUpgradeModule;
|
894 | }());
|
895 | function provideAppBaseHref(config, appBaseHref) {
|
896 | if (config && config.appBaseHref != null) {
|
897 | return config.appBaseHref;
|
898 | }
|
899 | else if (appBaseHref != null) {
|
900 | return appBaseHref;
|
901 | }
|
902 | return '';
|
903 | }
|
904 | function provideUrlCodec(config) {
|
905 | var codec = config && config.urlCodec || AngularJSUrlCodec;
|
906 | return new codec();
|
907 | }
|
908 | function provideLocationStrategy(platformLocation, baseHref, options) {
|
909 | if (options === void 0) { options = {}; }
|
910 | return options.useHash ? new HashLocationStrategy(platformLocation, baseHref) :
|
911 | new PathLocationStrategy(platformLocation, baseHref);
|
912 | }
|
913 | function provide$location(ngUpgrade, location, platformLocation, urlCodec, locationStrategy) {
|
914 | var $locationProvider = new $locationShimProvider(ngUpgrade, location, platformLocation, urlCodec, locationStrategy);
|
915 | return $locationProvider.$get();
|
916 | }
|
917 |
|
918 | /**
|
919 | * @license
|
920 | * Copyright Google Inc. All Rights Reserved.
|
921 | *
|
922 | * Use of this source code is governed by an MIT-style license that can be
|
923 | * found in the LICENSE file at https://angular.io/license
|
924 | */
|
925 |
|
926 | /**
|
927 | * @license
|
928 | * Copyright Google Inc. All Rights Reserved.
|
929 | *
|
930 | * Use of this source code is governed by an MIT-style license that can be
|
931 | * found in the LICENSE file at https://angular.io/license
|
932 | */
|
933 | // This file only reexports content of the `src` folder. Keep it that way.
|
934 |
|
935 | /**
|
936 | * @license
|
937 | * Copyright Google Inc. All Rights Reserved.
|
938 | *
|
939 | * Use of this source code is governed by an MIT-style license that can be
|
940 | * found in the LICENSE file at https://angular.io/license
|
941 | */
|
942 |
|
943 | /**
|
944 | * Generated bundle index. Do not edit.
|
945 | */
|
946 |
|
947 | export { $locationShim, $locationShimProvider, AngularJSUrlCodec, LOCATION_UPGRADE_CONFIGURATION, LocationUpgradeModule, UrlCodec, provideAppBaseHref as ɵangular_packages_common_upgrade_upgrade_a, provideUrlCodec as ɵangular_packages_common_upgrade_upgrade_b, provideLocationStrategy as ɵangular_packages_common_upgrade_upgrade_c, provide$location as ɵangular_packages_common_upgrade_upgrade_d };
|
948 |
|