1 | /**
|
---|
2 | * @license Angular v12.2.13
|
---|
3 | * (c) 2010-2021 Google LLC. https://angular.io/
|
---|
4 | * License: MIT
|
---|
5 | */
|
---|
6 |
|
---|
7 | (function (global, factory) {
|
---|
8 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('@angular/common'), require('@angular/core'), require('@angular/upgrade/static')) :
|
---|
9 | typeof define === 'function' && define.amd ? define('@angular/common/upgrade', ['exports', 'rxjs', '@angular/common', '@angular/core', '@angular/upgrade/static'], factory) :
|
---|
10 | (global = global || self, factory((global.ng = global.ng || {}, global.ng.common = global.ng.common || {}, global.ng.common.upgrade = {}), global.rxjs, global.ng.common, global.ng.core, global.ng.upgrade.static));
|
---|
11 | }(this, (function (exports, rxjs, common, core, _static) { 'use strict';
|
---|
12 |
|
---|
13 | /*! *****************************************************************************
|
---|
14 | Copyright (c) Microsoft Corporation.
|
---|
15 |
|
---|
16 | Permission to use, copy, modify, and/or distribute this software for any
|
---|
17 | purpose with or without fee is hereby granted.
|
---|
18 |
|
---|
19 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
---|
20 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
---|
21 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
---|
22 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
---|
23 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
---|
24 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
---|
25 | PERFORMANCE OF THIS SOFTWARE.
|
---|
26 | ***************************************************************************** */
|
---|
27 | /* global Reflect, Promise */
|
---|
28 | var extendStatics = function (d, b) {
|
---|
29 | extendStatics = Object.setPrototypeOf ||
|
---|
30 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
---|
31 | function (d, b) { for (var p in b)
|
---|
32 | if (Object.prototype.hasOwnProperty.call(b, p))
|
---|
33 | d[p] = b[p]; };
|
---|
34 | return extendStatics(d, b);
|
---|
35 | };
|
---|
36 | function __extends(d, b) {
|
---|
37 | if (typeof b !== "function" && b !== null)
|
---|
38 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
---|
39 | extendStatics(d, b);
|
---|
40 | function __() { this.constructor = d; }
|
---|
41 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
---|
42 | }
|
---|
43 | var __assign = function () {
|
---|
44 | __assign = Object.assign || function __assign(t) {
|
---|
45 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
---|
46 | s = arguments[i];
|
---|
47 | for (var p in s)
|
---|
48 | if (Object.prototype.hasOwnProperty.call(s, p))
|
---|
49 | t[p] = s[p];
|
---|
50 | }
|
---|
51 | return t;
|
---|
52 | };
|
---|
53 | return __assign.apply(this, arguments);
|
---|
54 | };
|
---|
55 | function __rest(s, e) {
|
---|
56 | var t = {};
|
---|
57 | for (var p in s)
|
---|
58 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
---|
59 | t[p] = s[p];
|
---|
60 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
---|
61 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
---|
62 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
---|
63 | t[p[i]] = s[p[i]];
|
---|
64 | }
|
---|
65 | return t;
|
---|
66 | }
|
---|
67 | function __decorate(decorators, target, key, desc) {
|
---|
68 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
---|
69 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
---|
70 | r = Reflect.decorate(decorators, target, key, desc);
|
---|
71 | else
|
---|
72 | for (var i = decorators.length - 1; i >= 0; i--)
|
---|
73 | if (d = decorators[i])
|
---|
74 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
---|
75 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
---|
76 | }
|
---|
77 | function __param(paramIndex, decorator) {
|
---|
78 | return function (target, key) { decorator(target, key, paramIndex); };
|
---|
79 | }
|
---|
80 | function __metadata(metadataKey, metadataValue) {
|
---|
81 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
---|
82 | return Reflect.metadata(metadataKey, metadataValue);
|
---|
83 | }
|
---|
84 | function __awaiter(thisArg, _arguments, P, generator) {
|
---|
85 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
---|
86 | return new (P || (P = Promise))(function (resolve, reject) {
|
---|
87 | function fulfilled(value) { try {
|
---|
88 | step(generator.next(value));
|
---|
89 | }
|
---|
90 | catch (e) {
|
---|
91 | reject(e);
|
---|
92 | } }
|
---|
93 | function rejected(value) { try {
|
---|
94 | step(generator["throw"](value));
|
---|
95 | }
|
---|
96 | catch (e) {
|
---|
97 | reject(e);
|
---|
98 | } }
|
---|
99 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
---|
100 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
---|
101 | });
|
---|
102 | }
|
---|
103 | function __generator(thisArg, body) {
|
---|
104 | var _ = { label: 0, sent: function () { if (t[0] & 1)
|
---|
105 | throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
---|
106 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
---|
107 | function verb(n) { return function (v) { return step([n, v]); }; }
|
---|
108 | function step(op) {
|
---|
109 | if (f)
|
---|
110 | throw new TypeError("Generator is already executing.");
|
---|
111 | while (_)
|
---|
112 | try {
|
---|
113 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
---|
114 | return t;
|
---|
115 | if (y = 0, t)
|
---|
116 | op = [op[0] & 2, t.value];
|
---|
117 | switch (op[0]) {
|
---|
118 | case 0:
|
---|
119 | case 1:
|
---|
120 | t = op;
|
---|
121 | break;
|
---|
122 | case 4:
|
---|
123 | _.label++;
|
---|
124 | return { value: op[1], done: false };
|
---|
125 | case 5:
|
---|
126 | _.label++;
|
---|
127 | y = op[1];
|
---|
128 | op = [0];
|
---|
129 | continue;
|
---|
130 | case 7:
|
---|
131 | op = _.ops.pop();
|
---|
132 | _.trys.pop();
|
---|
133 | continue;
|
---|
134 | default:
|
---|
135 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
---|
136 | _ = 0;
|
---|
137 | continue;
|
---|
138 | }
|
---|
139 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
---|
140 | _.label = op[1];
|
---|
141 | break;
|
---|
142 | }
|
---|
143 | if (op[0] === 6 && _.label < t[1]) {
|
---|
144 | _.label = t[1];
|
---|
145 | t = op;
|
---|
146 | break;
|
---|
147 | }
|
---|
148 | if (t && _.label < t[2]) {
|
---|
149 | _.label = t[2];
|
---|
150 | _.ops.push(op);
|
---|
151 | break;
|
---|
152 | }
|
---|
153 | if (t[2])
|
---|
154 | _.ops.pop();
|
---|
155 | _.trys.pop();
|
---|
156 | continue;
|
---|
157 | }
|
---|
158 | op = body.call(thisArg, _);
|
---|
159 | }
|
---|
160 | catch (e) {
|
---|
161 | op = [6, e];
|
---|
162 | y = 0;
|
---|
163 | }
|
---|
164 | finally {
|
---|
165 | f = t = 0;
|
---|
166 | }
|
---|
167 | if (op[0] & 5)
|
---|
168 | throw op[1];
|
---|
169 | return { value: op[0] ? op[1] : void 0, done: true };
|
---|
170 | }
|
---|
171 | }
|
---|
172 | var __createBinding = Object.create ? (function (o, m, k, k2) {
|
---|
173 | if (k2 === undefined)
|
---|
174 | k2 = k;
|
---|
175 | Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
---|
176 | }) : (function (o, m, k, k2) {
|
---|
177 | if (k2 === undefined)
|
---|
178 | k2 = k;
|
---|
179 | o[k2] = m[k];
|
---|
180 | });
|
---|
181 | function __exportStar(m, o) {
|
---|
182 | for (var p in m)
|
---|
183 | if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
---|
184 | __createBinding(o, m, p);
|
---|
185 | }
|
---|
186 | function __values(o) {
|
---|
187 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
---|
188 | if (m)
|
---|
189 | return m.call(o);
|
---|
190 | if (o && typeof o.length === "number")
|
---|
191 | return {
|
---|
192 | next: function () {
|
---|
193 | if (o && i >= o.length)
|
---|
194 | o = void 0;
|
---|
195 | return { value: o && o[i++], done: !o };
|
---|
196 | }
|
---|
197 | };
|
---|
198 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
---|
199 | }
|
---|
200 | function __read(o, n) {
|
---|
201 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
---|
202 | if (!m)
|
---|
203 | return o;
|
---|
204 | var i = m.call(o), r, ar = [], e;
|
---|
205 | try {
|
---|
206 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
---|
207 | ar.push(r.value);
|
---|
208 | }
|
---|
209 | catch (error) {
|
---|
210 | e = { error: error };
|
---|
211 | }
|
---|
212 | finally {
|
---|
213 | try {
|
---|
214 | if (r && !r.done && (m = i["return"]))
|
---|
215 | m.call(i);
|
---|
216 | }
|
---|
217 | finally {
|
---|
218 | if (e)
|
---|
219 | throw e.error;
|
---|
220 | }
|
---|
221 | }
|
---|
222 | return ar;
|
---|
223 | }
|
---|
224 | /** @deprecated */
|
---|
225 | function __spread() {
|
---|
226 | for (var ar = [], i = 0; i < arguments.length; i++)
|
---|
227 | ar = ar.concat(__read(arguments[i]));
|
---|
228 | return ar;
|
---|
229 | }
|
---|
230 | /** @deprecated */
|
---|
231 | function __spreadArrays() {
|
---|
232 | for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
---|
233 | s += arguments[i].length;
|
---|
234 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
---|
235 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
---|
236 | r[k] = a[j];
|
---|
237 | return r;
|
---|
238 | }
|
---|
239 | function __spreadArray(to, from, pack) {
|
---|
240 | if (pack || arguments.length === 2)
|
---|
241 | for (var i = 0, l = from.length, ar; i < l; i++) {
|
---|
242 | if (ar || !(i in from)) {
|
---|
243 | if (!ar)
|
---|
244 | ar = Array.prototype.slice.call(from, 0, i);
|
---|
245 | ar[i] = from[i];
|
---|
246 | }
|
---|
247 | }
|
---|
248 | return to.concat(ar || Array.prototype.slice.call(from));
|
---|
249 | }
|
---|
250 | function __await(v) {
|
---|
251 | return this instanceof __await ? (this.v = v, this) : new __await(v);
|
---|
252 | }
|
---|
253 | function __asyncGenerator(thisArg, _arguments, generator) {
|
---|
254 | if (!Symbol.asyncIterator)
|
---|
255 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
---|
256 | var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
---|
257 | return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
---|
258 | function verb(n) { if (g[n])
|
---|
259 | i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
---|
260 | function resume(n, v) { try {
|
---|
261 | step(g[n](v));
|
---|
262 | }
|
---|
263 | catch (e) {
|
---|
264 | settle(q[0][3], e);
|
---|
265 | } }
|
---|
266 | function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
---|
267 | function fulfill(value) { resume("next", value); }
|
---|
268 | function reject(value) { resume("throw", value); }
|
---|
269 | function settle(f, v) { if (f(v), q.shift(), q.length)
|
---|
270 | resume(q[0][0], q[0][1]); }
|
---|
271 | }
|
---|
272 | function __asyncDelegator(o) {
|
---|
273 | var i, p;
|
---|
274 | return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
---|
275 | function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
---|
276 | }
|
---|
277 | function __asyncValues(o) {
|
---|
278 | if (!Symbol.asyncIterator)
|
---|
279 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
---|
280 | var m = o[Symbol.asyncIterator], i;
|
---|
281 | return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
---|
282 | function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
---|
283 | function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
---|
284 | }
|
---|
285 | function __makeTemplateObject(cooked, raw) {
|
---|
286 | if (Object.defineProperty) {
|
---|
287 | Object.defineProperty(cooked, "raw", { value: raw });
|
---|
288 | }
|
---|
289 | else {
|
---|
290 | cooked.raw = raw;
|
---|
291 | }
|
---|
292 | return cooked;
|
---|
293 | }
|
---|
294 | ;
|
---|
295 | var __setModuleDefault = Object.create ? (function (o, v) {
|
---|
296 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
297 | }) : function (o, v) {
|
---|
298 | o["default"] = v;
|
---|
299 | };
|
---|
300 | function __importStar(mod) {
|
---|
301 | if (mod && mod.__esModule)
|
---|
302 | return mod;
|
---|
303 | var result = {};
|
---|
304 | if (mod != null)
|
---|
305 | for (var k in mod)
|
---|
306 | if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
---|
307 | __createBinding(result, mod, k);
|
---|
308 | __setModuleDefault(result, mod);
|
---|
309 | return result;
|
---|
310 | }
|
---|
311 | function __importDefault(mod) {
|
---|
312 | return (mod && mod.__esModule) ? mod : { default: mod };
|
---|
313 | }
|
---|
314 | function __classPrivateFieldGet(receiver, state, kind, f) {
|
---|
315 | if (kind === "a" && !f)
|
---|
316 | throw new TypeError("Private accessor was defined without a getter");
|
---|
317 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
---|
318 | throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
---|
319 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
---|
320 | }
|
---|
321 | function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
---|
322 | if (kind === "m")
|
---|
323 | throw new TypeError("Private method is not writable");
|
---|
324 | if (kind === "a" && !f)
|
---|
325 | throw new TypeError("Private accessor was defined without a setter");
|
---|
326 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
---|
327 | throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
---|
328 | return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
---|
329 | }
|
---|
330 |
|
---|
331 | /**
|
---|
332 | * @license
|
---|
333 | * Copyright Google LLC All Rights Reserved.
|
---|
334 | *
|
---|
335 | * Use of this source code is governed by an MIT-style license that can be
|
---|
336 | * found in the LICENSE file at https://angular.io/license
|
---|
337 | */
|
---|
338 | function stripPrefix(val, prefix) {
|
---|
339 | return val.startsWith(prefix) ? val.substring(prefix.length) : val;
|
---|
340 | }
|
---|
341 | function deepEqual(a, b) {
|
---|
342 | if (a === b) {
|
---|
343 | return true;
|
---|
344 | }
|
---|
345 | else if (!a || !b) {
|
---|
346 | return false;
|
---|
347 | }
|
---|
348 | else {
|
---|
349 | try {
|
---|
350 | if ((a.prototype !== b.prototype) || (Array.isArray(a) && Array.isArray(b))) {
|
---|
351 | return false;
|
---|
352 | }
|
---|
353 | return JSON.stringify(a) === JSON.stringify(b);
|
---|
354 | }
|
---|
355 | catch (e) {
|
---|
356 | return false;
|
---|
357 | }
|
---|
358 | }
|
---|
359 | }
|
---|
360 | function isAnchor(el) {
|
---|
361 | return el.href !== undefined;
|
---|
362 | }
|
---|
363 | function isPromise(obj) {
|
---|
364 | // allow any Promise/A+ compliant thenable.
|
---|
365 | // It's up to the caller to ensure that obj.then conforms to the spec
|
---|
366 | return !!obj && typeof obj.then === 'function';
|
---|
367 | }
|
---|
368 |
|
---|
369 | var PATH_MATCH = /^([^?#]*)(\?([^#]*))?(#(.*))?$/;
|
---|
370 | var DOUBLE_SLASH_REGEX = /^\s*[\\/]{2,}/;
|
---|
371 | var IGNORE_URI_REGEXP = /^\s*(javascript|mailto):/i;
|
---|
372 | var DEFAULT_PORTS = {
|
---|
373 | 'http:': 80,
|
---|
374 | 'https:': 443,
|
---|
375 | 'ftp:': 21
|
---|
376 | };
|
---|
377 | /**
|
---|
378 | * Location service that provides a drop-in replacement for the $location service
|
---|
379 | * provided in AngularJS.
|
---|
380 | *
|
---|
381 | * @see [Using the Angular Unified Location Service](guide/upgrade#using-the-unified-angular-location-service)
|
---|
382 | *
|
---|
383 | * @publicApi
|
---|
384 | */
|
---|
385 | var $locationShim = /** @class */ (function () {
|
---|
386 | function $locationShim($injector, location, platformLocation, urlCodec, locationStrategy) {
|
---|
387 | var _this = this;
|
---|
388 | this.location = location;
|
---|
389 | this.platformLocation = platformLocation;
|
---|
390 | this.urlCodec = urlCodec;
|
---|
391 | this.locationStrategy = locationStrategy;
|
---|
392 | this.initalizing = true;
|
---|
393 | this.updateBrowser = false;
|
---|
394 | this.$$absUrl = '';
|
---|
395 | this.$$url = '';
|
---|
396 | this.$$host = '';
|
---|
397 | this.$$replace = false;
|
---|
398 | this.$$path = '';
|
---|
399 | this.$$search = '';
|
---|
400 | this.$$hash = '';
|
---|
401 | this.$$changeListeners = [];
|
---|
402 | this.cachedState = null;
|
---|
403 | this.urlChanges = new rxjs.ReplaySubject(1);
|
---|
404 | this.lastBrowserUrl = '';
|
---|
405 | // This variable should be used *only* inside the cacheState function.
|
---|
406 | this.lastCachedState = null;
|
---|
407 | var initialUrl = this.browserUrl();
|
---|
408 | var parsedUrl = this.urlCodec.parse(initialUrl);
|
---|
409 | if (typeof parsedUrl === 'string') {
|
---|
410 | throw 'Invalid URL';
|
---|
411 | }
|
---|
412 | this.$$protocol = parsedUrl.protocol;
|
---|
413 | this.$$host = parsedUrl.hostname;
|
---|
414 | this.$$port = parseInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
|
---|
415 | this.$$parseLinkUrl(initialUrl, initialUrl);
|
---|
416 | this.cacheState();
|
---|
417 | this.$$state = this.browserState();
|
---|
418 | this.location.onUrlChange(function (newUrl, newState) {
|
---|
419 | _this.urlChanges.next({ newUrl: newUrl, newState: newState });
|
---|
420 | });
|
---|
421 | if (isPromise($injector)) {
|
---|
422 | $injector.then(function ($i) { return _this.initialize($i); });
|
---|
423 | }
|
---|
424 | else {
|
---|
425 | this.initialize($injector);
|
---|
426 | }
|
---|
427 | }
|
---|
428 | $locationShim.prototype.initialize = function ($injector) {
|
---|
429 | var _this = this;
|
---|
430 | var $rootScope = $injector.get('$rootScope');
|
---|
431 | var $rootElement = $injector.get('$rootElement');
|
---|
432 | $rootElement.on('click', function (event) {
|
---|
433 | if (event.ctrlKey || event.metaKey || event.shiftKey || event.which === 2 ||
|
---|
434 | event.button === 2) {
|
---|
435 | return;
|
---|
436 | }
|
---|
437 | var elm = event.target;
|
---|
438 | // traverse the DOM up to find first A tag
|
---|
439 | while (elm && elm.nodeName.toLowerCase() !== 'a') {
|
---|
440 | // ignore rewriting if no A tag (reached root element, or no parent - removed from document)
|
---|
441 | if (elm === $rootElement[0] || !(elm = elm.parentNode)) {
|
---|
442 | return;
|
---|
443 | }
|
---|
444 | }
|
---|
445 | if (!isAnchor(elm)) {
|
---|
446 | return;
|
---|
447 | }
|
---|
448 | var absHref = elm.href;
|
---|
449 | var relHref = elm.getAttribute('href');
|
---|
450 | // Ignore when url is started with javascript: or mailto:
|
---|
451 | if (IGNORE_URI_REGEXP.test(absHref)) {
|
---|
452 | return;
|
---|
453 | }
|
---|
454 | if (absHref && !elm.getAttribute('target') && !event.isDefaultPrevented()) {
|
---|
455 | if (_this.$$parseLinkUrl(absHref, relHref)) {
|
---|
456 | // We do a preventDefault for all urls that are part of the AngularJS application,
|
---|
457 | // in html5mode and also without, so that we are able to abort navigation without
|
---|
458 | // getting double entries in the location history.
|
---|
459 | event.preventDefault();
|
---|
460 | // update location manually
|
---|
461 | if (_this.absUrl() !== _this.browserUrl()) {
|
---|
462 | $rootScope.$apply();
|
---|
463 | }
|
---|
464 | }
|
---|
465 | }
|
---|
466 | });
|
---|
467 | this.urlChanges.subscribe(function (_a) {
|
---|
468 | var newUrl = _a.newUrl, newState = _a.newState;
|
---|
469 | var oldUrl = _this.absUrl();
|
---|
470 | var oldState = _this.$$state;
|
---|
471 | _this.$$parse(newUrl);
|
---|
472 | newUrl = _this.absUrl();
|
---|
473 | _this.$$state = newState;
|
---|
474 | var defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl, newState, oldState)
|
---|
475 | .defaultPrevented;
|
---|
476 | // if the location was changed by a `$locationChangeStart` handler then stop
|
---|
477 | // processing this location change
|
---|
478 | if (_this.absUrl() !== newUrl)
|
---|
479 | return;
|
---|
480 | // If default was prevented, set back to old state. This is the state that was locally
|
---|
481 | // cached in the $location service.
|
---|
482 | if (defaultPrevented) {
|
---|
483 | _this.$$parse(oldUrl);
|
---|
484 | _this.state(oldState);
|
---|
485 | _this.setBrowserUrlWithFallback(oldUrl, false, oldState);
|
---|
486 | _this.$$notifyChangeListeners(_this.url(), _this.$$state, oldUrl, oldState);
|
---|
487 | }
|
---|
488 | else {
|
---|
489 | _this.initalizing = false;
|
---|
490 | $rootScope.$broadcast('$locationChangeSuccess', newUrl, oldUrl, newState, oldState);
|
---|
491 | _this.resetBrowserUpdate();
|
---|
492 | }
|
---|
493 | if (!$rootScope.$$phase) {
|
---|
494 | $rootScope.$digest();
|
---|
495 | }
|
---|
496 | });
|
---|
497 | // update browser
|
---|
498 | $rootScope.$watch(function () {
|
---|
499 | if (_this.initalizing || _this.updateBrowser) {
|
---|
500 | _this.updateBrowser = false;
|
---|
501 | var oldUrl_1 = _this.browserUrl();
|
---|
502 | var newUrl = _this.absUrl();
|
---|
503 | var oldState_1 = _this.browserState();
|
---|
504 | var currentReplace_1 = _this.$$replace;
|
---|
505 | var urlOrStateChanged_1 = !_this.urlCodec.areEqual(oldUrl_1, newUrl) || oldState_1 !== _this.$$state;
|
---|
506 | // Fire location changes one time to on initialization. This must be done on the
|
---|
507 | // next tick (thus inside $evalAsync()) in order for listeners to be registered
|
---|
508 | // before the event fires. Mimicing behavior from $locationWatch:
|
---|
509 | // https://github.com/angular/angular.js/blob/master/src/ng/location.js#L983
|
---|
510 | if (_this.initalizing || urlOrStateChanged_1) {
|
---|
511 | _this.initalizing = false;
|
---|
512 | $rootScope.$evalAsync(function () {
|
---|
513 | // Get the new URL again since it could have changed due to async update
|
---|
514 | var newUrl = _this.absUrl();
|
---|
515 | var defaultPrevented = $rootScope
|
---|
516 | .$broadcast('$locationChangeStart', newUrl, oldUrl_1, _this.$$state, oldState_1)
|
---|
517 | .defaultPrevented;
|
---|
518 | // if the location was changed by a `$locationChangeStart` handler then stop
|
---|
519 | // processing this location change
|
---|
520 | if (_this.absUrl() !== newUrl)
|
---|
521 | return;
|
---|
522 | if (defaultPrevented) {
|
---|
523 | _this.$$parse(oldUrl_1);
|
---|
524 | _this.$$state = oldState_1;
|
---|
525 | }
|
---|
526 | else {
|
---|
527 | // This block doesn't run when initalizing because it's going to perform the update to
|
---|
528 | // the URL which shouldn't be needed when initalizing.
|
---|
529 | if (urlOrStateChanged_1) {
|
---|
530 | _this.setBrowserUrlWithFallback(newUrl, currentReplace_1, oldState_1 === _this.$$state ? null : _this.$$state);
|
---|
531 | _this.$$replace = false;
|
---|
532 | }
|
---|
533 | $rootScope.$broadcast('$locationChangeSuccess', newUrl, oldUrl_1, _this.$$state, oldState_1);
|
---|
534 | if (urlOrStateChanged_1) {
|
---|
535 | _this.$$notifyChangeListeners(_this.url(), _this.$$state, oldUrl_1, oldState_1);
|
---|
536 | }
|
---|
537 | }
|
---|
538 | });
|
---|
539 | }
|
---|
540 | }
|
---|
541 | _this.$$replace = false;
|
---|
542 | });
|
---|
543 | };
|
---|
544 | $locationShim.prototype.resetBrowserUpdate = function () {
|
---|
545 | this.$$replace = false;
|
---|
546 | this.$$state = this.browserState();
|
---|
547 | this.updateBrowser = false;
|
---|
548 | this.lastBrowserUrl = this.browserUrl();
|
---|
549 | };
|
---|
550 | $locationShim.prototype.browserUrl = function (url, replace, state) {
|
---|
551 | // In modern browsers `history.state` is `null` by default; treating it separately
|
---|
552 | // from `undefined` would cause `$browser.url('/foo')` to change `history.state`
|
---|
553 | // to undefined via `pushState`. Instead, let's change `undefined` to `null` here.
|
---|
554 | if (typeof state === 'undefined') {
|
---|
555 | state = null;
|
---|
556 | }
|
---|
557 | // setter
|
---|
558 | if (url) {
|
---|
559 | var sameState = this.lastHistoryState === state;
|
---|
560 | // Normalize the inputted URL
|
---|
561 | url = this.urlCodec.parse(url).href;
|
---|
562 | // Don't change anything if previous and current URLs and states match.
|
---|
563 | if (this.lastBrowserUrl === url && sameState) {
|
---|
564 | return this;
|
---|
565 | }
|
---|
566 | this.lastBrowserUrl = url;
|
---|
567 | this.lastHistoryState = state;
|
---|
568 | // Remove server base from URL as the Angular APIs for updating URL require
|
---|
569 | // it to be the path+.
|
---|
570 | url = this.stripBaseUrl(this.getServerBase(), url) || url;
|
---|
571 | // Set the URL
|
---|
572 | if (replace) {
|
---|
573 | this.locationStrategy.replaceState(state, '', url, '');
|
---|
574 | }
|
---|
575 | else {
|
---|
576 | this.locationStrategy.pushState(state, '', url, '');
|
---|
577 | }
|
---|
578 | this.cacheState();
|
---|
579 | return this;
|
---|
580 | // getter
|
---|
581 | }
|
---|
582 | else {
|
---|
583 | return this.platformLocation.href;
|
---|
584 | }
|
---|
585 | };
|
---|
586 | $locationShim.prototype.cacheState = function () {
|
---|
587 | // This should be the only place in $browser where `history.state` is read.
|
---|
588 | this.cachedState = this.platformLocation.getState();
|
---|
589 | if (typeof this.cachedState === 'undefined') {
|
---|
590 | this.cachedState = null;
|
---|
591 | }
|
---|
592 | // Prevent callbacks fo fire twice if both hashchange & popstate were fired.
|
---|
593 | if (deepEqual(this.cachedState, this.lastCachedState)) {
|
---|
594 | this.cachedState = this.lastCachedState;
|
---|
595 | }
|
---|
596 | this.lastCachedState = this.cachedState;
|
---|
597 | this.lastHistoryState = this.cachedState;
|
---|
598 | };
|
---|
599 | /**
|
---|
600 | * This function emulates the $browser.state() function from AngularJS. It will cause
|
---|
601 | * history.state to be cached unless changed with deep equality check.
|
---|
602 | */
|
---|
603 | $locationShim.prototype.browserState = function () {
|
---|
604 | return this.cachedState;
|
---|
605 | };
|
---|
606 | $locationShim.prototype.stripBaseUrl = function (base, url) {
|
---|
607 | if (url.startsWith(base)) {
|
---|
608 | return url.substr(base.length);
|
---|
609 | }
|
---|
610 | return undefined;
|
---|
611 | };
|
---|
612 | $locationShim.prototype.getServerBase = function () {
|
---|
613 | var _a = this.platformLocation, protocol = _a.protocol, hostname = _a.hostname, port = _a.port;
|
---|
614 | var baseHref = this.locationStrategy.getBaseHref();
|
---|
615 | var url = protocol + "//" + hostname + (port ? ':' + port : '') + (baseHref || '/');
|
---|
616 | return url.endsWith('/') ? url : url + '/';
|
---|
617 | };
|
---|
618 | $locationShim.prototype.parseAppUrl = function (url) {
|
---|
619 | if (DOUBLE_SLASH_REGEX.test(url)) {
|
---|
620 | throw new Error("Bad Path - URL cannot start with double slashes: " + url);
|
---|
621 | }
|
---|
622 | var prefixed = (url.charAt(0) !== '/');
|
---|
623 | if (prefixed) {
|
---|
624 | url = '/' + url;
|
---|
625 | }
|
---|
626 | var match = this.urlCodec.parse(url, this.getServerBase());
|
---|
627 | if (typeof match === 'string') {
|
---|
628 | throw new Error("Bad URL - Cannot parse URL: " + url);
|
---|
629 | }
|
---|
630 | var path = prefixed && match.pathname.charAt(0) === '/' ? match.pathname.substring(1) : match.pathname;
|
---|
631 | this.$$path = this.urlCodec.decodePath(path);
|
---|
632 | this.$$search = this.urlCodec.decodeSearch(match.search);
|
---|
633 | this.$$hash = this.urlCodec.decodeHash(match.hash);
|
---|
634 | // make sure path starts with '/';
|
---|
635 | if (this.$$path && this.$$path.charAt(0) !== '/') {
|
---|
636 | this.$$path = '/' + this.$$path;
|
---|
637 | }
|
---|
638 | };
|
---|
639 | /**
|
---|
640 | * Registers listeners for URL changes. This API is used to catch updates performed by the
|
---|
641 | * AngularJS framework. These changes are a subset of the `$locationChangeStart` and
|
---|
642 | * `$locationChangeSuccess` events which fire when AngularJS updates its internally-referenced
|
---|
643 | * version of the browser URL.
|
---|
644 | *
|
---|
645 | * It's possible for `$locationChange` events to happen, but for the browser URL
|
---|
646 | * (window.location) to remain unchanged. This `onChange` callback will fire only when AngularJS
|
---|
647 | * actually updates the browser URL (window.location).
|
---|
648 | *
|
---|
649 | * @param fn The callback function that is triggered for the listener when the URL changes.
|
---|
650 | * @param err The callback function that is triggered when an error occurs.
|
---|
651 | */
|
---|
652 | $locationShim.prototype.onChange = function (fn, err) {
|
---|
653 | if (err === void 0) { err = function (e) { }; }
|
---|
654 | this.$$changeListeners.push([fn, err]);
|
---|
655 | };
|
---|
656 | /** @internal */
|
---|
657 | $locationShim.prototype.$$notifyChangeListeners = function (url, state, oldUrl, oldState) {
|
---|
658 | if (url === void 0) { url = ''; }
|
---|
659 | if (oldUrl === void 0) { oldUrl = ''; }
|
---|
660 | this.$$changeListeners.forEach(function (_a) {
|
---|
661 | var _b = __read(_a, 2), fn = _b[0], err = _b[1];
|
---|
662 | try {
|
---|
663 | fn(url, state, oldUrl, oldState);
|
---|
664 | }
|
---|
665 | catch (e) {
|
---|
666 | err(e);
|
---|
667 | }
|
---|
668 | });
|
---|
669 | };
|
---|
670 | /**
|
---|
671 | * Parses the provided URL, and sets the current URL to the parsed result.
|
---|
672 | *
|
---|
673 | * @param url The URL string.
|
---|
674 | */
|
---|
675 | $locationShim.prototype.$$parse = function (url) {
|
---|
676 | var pathUrl;
|
---|
677 | if (url.startsWith('/')) {
|
---|
678 | pathUrl = url;
|
---|
679 | }
|
---|
680 | else {
|
---|
681 | // Remove protocol & hostname if URL starts with it
|
---|
682 | pathUrl = this.stripBaseUrl(this.getServerBase(), url);
|
---|
683 | }
|
---|
684 | if (typeof pathUrl === 'undefined') {
|
---|
685 | throw new Error("Invalid url \"" + url + "\", missing path prefix \"" + this.getServerBase() + "\".");
|
---|
686 | }
|
---|
687 | this.parseAppUrl(pathUrl);
|
---|
688 | if (!this.$$path) {
|
---|
689 | this.$$path = '/';
|
---|
690 | }
|
---|
691 | this.composeUrls();
|
---|
692 | };
|
---|
693 | /**
|
---|
694 | * Parses the provided URL and its relative URL.
|
---|
695 | *
|
---|
696 | * @param url The full URL string.
|
---|
697 | * @param relHref A URL string relative to the full URL string.
|
---|
698 | */
|
---|
699 | $locationShim.prototype.$$parseLinkUrl = function (url, relHref) {
|
---|
700 | // When relHref is passed, it should be a hash and is handled separately
|
---|
701 | if (relHref && relHref[0] === '#') {
|
---|
702 | this.hash(relHref.slice(1));
|
---|
703 | return true;
|
---|
704 | }
|
---|
705 | var rewrittenUrl;
|
---|
706 | var appUrl = this.stripBaseUrl(this.getServerBase(), url);
|
---|
707 | if (typeof appUrl !== 'undefined') {
|
---|
708 | rewrittenUrl = this.getServerBase() + appUrl;
|
---|
709 | }
|
---|
710 | else if (this.getServerBase() === url + '/') {
|
---|
711 | rewrittenUrl = this.getServerBase();
|
---|
712 | }
|
---|
713 | // Set the URL
|
---|
714 | if (rewrittenUrl) {
|
---|
715 | this.$$parse(rewrittenUrl);
|
---|
716 | }
|
---|
717 | return !!rewrittenUrl;
|
---|
718 | };
|
---|
719 | $locationShim.prototype.setBrowserUrlWithFallback = function (url, replace, state) {
|
---|
720 | var oldUrl = this.url();
|
---|
721 | var oldState = this.$$state;
|
---|
722 | try {
|
---|
723 | this.browserUrl(url, replace, state);
|
---|
724 | // Make sure $location.state() returns referentially identical (not just deeply equal)
|
---|
725 | // state object; this makes possible quick checking if the state changed in the digest
|
---|
726 | // loop. Checking deep equality would be too expensive.
|
---|
727 | this.$$state = this.browserState();
|
---|
728 | }
|
---|
729 | catch (e) {
|
---|
730 | // Restore old values if pushState fails
|
---|
731 | this.url(oldUrl);
|
---|
732 | this.$$state = oldState;
|
---|
733 | throw e;
|
---|
734 | }
|
---|
735 | };
|
---|
736 | $locationShim.prototype.composeUrls = function () {
|
---|
737 | this.$$url = this.urlCodec.normalize(this.$$path, this.$$search, this.$$hash);
|
---|
738 | this.$$absUrl = this.getServerBase() + this.$$url.substr(1); // remove '/' from front of URL
|
---|
739 | this.updateBrowser = true;
|
---|
740 | };
|
---|
741 | /**
|
---|
742 | * Retrieves the full URL representation with all segments encoded according to
|
---|
743 | * rules specified in
|
---|
744 | * [RFC 3986](https://tools.ietf.org/html/rfc3986).
|
---|
745 | *
|
---|
746 | *
|
---|
747 | * ```js
|
---|
748 | * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
|
---|
749 | * let absUrl = $location.absUrl();
|
---|
750 | * // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
|
---|
751 | * ```
|
---|
752 | */
|
---|
753 | $locationShim.prototype.absUrl = function () {
|
---|
754 | return this.$$absUrl;
|
---|
755 | };
|
---|
756 | $locationShim.prototype.url = function (url) {
|
---|
757 | if (typeof url === 'string') {
|
---|
758 | if (!url.length) {
|
---|
759 | url = '/';
|
---|
760 | }
|
---|
761 | var match = PATH_MATCH.exec(url);
|
---|
762 | if (!match)
|
---|
763 | return this;
|
---|
764 | if (match[1] || url === '')
|
---|
765 | this.path(this.urlCodec.decodePath(match[1]));
|
---|
766 | if (match[2] || match[1] || url === '')
|
---|
767 | this.search(match[3] || '');
|
---|
768 | this.hash(match[5] || '');
|
---|
769 | // Chainable method
|
---|
770 | return this;
|
---|
771 | }
|
---|
772 | return this.$$url;
|
---|
773 | };
|
---|
774 | /**
|
---|
775 | * Retrieves the protocol of the current URL.
|
---|
776 | *
|
---|
777 | * ```js
|
---|
778 | * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
|
---|
779 | * let protocol = $location.protocol();
|
---|
780 | * // => "http"
|
---|
781 | * ```
|
---|
782 | */
|
---|
783 | $locationShim.prototype.protocol = function () {
|
---|
784 | return this.$$protocol;
|
---|
785 | };
|
---|
786 | /**
|
---|
787 | * Retrieves the protocol of the current URL.
|
---|
788 | *
|
---|
789 | * In contrast to the non-AngularJS version `location.host` which returns `hostname:port`, this
|
---|
790 | * returns the `hostname` portion only.
|
---|
791 | *
|
---|
792 | *
|
---|
793 | * ```js
|
---|
794 | * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
|
---|
795 | * let host = $location.host();
|
---|
796 | * // => "example.com"
|
---|
797 | *
|
---|
798 | * // given URL http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxo
|
---|
799 | * host = $location.host();
|
---|
800 | * // => "example.com"
|
---|
801 | * host = location.host;
|
---|
802 | * // => "example.com:8080"
|
---|
803 | * ```
|
---|
804 | */
|
---|
805 | $locationShim.prototype.host = function () {
|
---|
806 | return this.$$host;
|
---|
807 | };
|
---|
808 | /**
|
---|
809 | * Retrieves the port of the current URL.
|
---|
810 | *
|
---|
811 | * ```js
|
---|
812 | * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
|
---|
813 | * let port = $location.port();
|
---|
814 | * // => 80
|
---|
815 | * ```
|
---|
816 | */
|
---|
817 | $locationShim.prototype.port = function () {
|
---|
818 | return this.$$port;
|
---|
819 | };
|
---|
820 | $locationShim.prototype.path = function (path) {
|
---|
821 | if (typeof path === 'undefined') {
|
---|
822 | return this.$$path;
|
---|
823 | }
|
---|
824 | // null path converts to empty string. Prepend with "/" if needed.
|
---|
825 | path = path !== null ? path.toString() : '';
|
---|
826 | path = path.charAt(0) === '/' ? path : '/' + path;
|
---|
827 | this.$$path = path;
|
---|
828 | this.composeUrls();
|
---|
829 | return this;
|
---|
830 | };
|
---|
831 | $locationShim.prototype.search = function (search, paramValue) {
|
---|
832 | switch (arguments.length) {
|
---|
833 | case 0:
|
---|
834 | return this.$$search;
|
---|
835 | case 1:
|
---|
836 | if (typeof search === 'string' || typeof search === 'number') {
|
---|
837 | this.$$search = this.urlCodec.decodeSearch(search.toString());
|
---|
838 | }
|
---|
839 | else if (typeof search === 'object' && search !== null) {
|
---|
840 | // Copy the object so it's never mutated
|
---|
841 | search = Object.assign({}, search);
|
---|
842 | // remove object undefined or null properties
|
---|
843 | for (var key in search) {
|
---|
844 | if (search[key] == null)
|
---|
845 | delete search[key];
|
---|
846 | }
|
---|
847 | this.$$search = search;
|
---|
848 | }
|
---|
849 | else {
|
---|
850 | throw new Error('LocationProvider.search(): First argument must be a string or an object.');
|
---|
851 | }
|
---|
852 | break;
|
---|
853 | default:
|
---|
854 | if (typeof search === 'string') {
|
---|
855 | var currentSearch = this.search();
|
---|
856 | if (typeof paramValue === 'undefined' || paramValue === null) {
|
---|
857 | delete currentSearch[search];
|
---|
858 | return this.search(currentSearch);
|
---|
859 | }
|
---|
860 | else {
|
---|
861 | currentSearch[search] = paramValue;
|
---|
862 | return this.search(currentSearch);
|
---|
863 | }
|
---|
864 | }
|
---|
865 | }
|
---|
866 | this.composeUrls();
|
---|
867 | return this;
|
---|
868 | };
|
---|
869 | $locationShim.prototype.hash = function (hash) {
|
---|
870 | if (typeof hash === 'undefined') {
|
---|
871 | return this.$$hash;
|
---|
872 | }
|
---|
873 | this.$$hash = hash !== null ? hash.toString() : '';
|
---|
874 | this.composeUrls();
|
---|
875 | return this;
|
---|
876 | };
|
---|
877 | /**
|
---|
878 | * Changes to `$location` during the current `$digest` will replace the current
|
---|
879 | * history record, instead of adding a new one.
|
---|
880 | */
|
---|
881 | $locationShim.prototype.replace = function () {
|
---|
882 | this.$$replace = true;
|
---|
883 | return this;
|
---|
884 | };
|
---|
885 | $locationShim.prototype.state = function (state) {
|
---|
886 | if (typeof state === 'undefined') {
|
---|
887 | return this.$$state;
|
---|
888 | }
|
---|
889 | this.$$state = state;
|
---|
890 | return this;
|
---|
891 | };
|
---|
892 | return $locationShim;
|
---|
893 | }());
|
---|
894 | /**
|
---|
895 | * The factory function used to create an instance of the `$locationShim` in Angular,
|
---|
896 | * and provides an API-compatiable `$locationProvider` for AngularJS.
|
---|
897 | *
|
---|
898 | * @publicApi
|
---|
899 | */
|
---|
900 | var $locationShimProvider = /** @class */ (function () {
|
---|
901 | function $locationShimProvider(ngUpgrade, location, platformLocation, urlCodec, locationStrategy) {
|
---|
902 | this.ngUpgrade = ngUpgrade;
|
---|
903 | this.location = location;
|
---|
904 | this.platformLocation = platformLocation;
|
---|
905 | this.urlCodec = urlCodec;
|
---|
906 | this.locationStrategy = locationStrategy;
|
---|
907 | }
|
---|
908 | /**
|
---|
909 | * Factory method that returns an instance of the $locationShim
|
---|
910 | */
|
---|
911 | $locationShimProvider.prototype.$get = function () {
|
---|
912 | return new $locationShim(this.ngUpgrade.$injector, this.location, this.platformLocation, this.urlCodec, this.locationStrategy);
|
---|
913 | };
|
---|
914 | /**
|
---|
915 | * Stub method used to keep API compatible with AngularJS. This setting is configured through
|
---|
916 | * the LocationUpgradeModule's `config` method in your Angular app.
|
---|
917 | */
|
---|
918 | $locationShimProvider.prototype.hashPrefix = function (prefix) {
|
---|
919 | throw new Error('Configure LocationUpgrade through LocationUpgradeModule.config method.');
|
---|
920 | };
|
---|
921 | /**
|
---|
922 | * Stub method used to keep API compatible with AngularJS. This setting is configured through
|
---|
923 | * the LocationUpgradeModule's `config` method in your Angular app.
|
---|
924 | */
|
---|
925 | $locationShimProvider.prototype.html5Mode = function (mode) {
|
---|
926 | throw new Error('Configure LocationUpgrade through LocationUpgradeModule.config method.');
|
---|
927 | };
|
---|
928 | return $locationShimProvider;
|
---|
929 | }());
|
---|
930 |
|
---|
931 | /**
|
---|
932 | * @license
|
---|
933 | * Copyright Google LLC All Rights Reserved.
|
---|
934 | *
|
---|
935 | * Use of this source code is governed by an MIT-style license that can be
|
---|
936 | * found in the LICENSE file at https://angular.io/license
|
---|
937 | */
|
---|
938 | /**
|
---|
939 | * A codec for encoding and decoding URL parts.
|
---|
940 | *
|
---|
941 | * @publicApi
|
---|
942 | **/
|
---|
943 | var UrlCodec = /** @class */ (function () {
|
---|
944 | function UrlCodec() {
|
---|
945 | }
|
---|
946 | return UrlCodec;
|
---|
947 | }());
|
---|
948 | /**
|
---|
949 | * A `UrlCodec` that uses logic from AngularJS to serialize and parse URLs
|
---|
950 | * and URL parameters.
|
---|
951 | *
|
---|
952 | * @publicApi
|
---|
953 | */
|
---|
954 | var AngularJSUrlCodec = /** @class */ (function () {
|
---|
955 | function AngularJSUrlCodec() {
|
---|
956 | }
|
---|
957 | // https://github.com/angular/angular.js/blob/864c7f0/src/ng/location.js#L15
|
---|
958 | AngularJSUrlCodec.prototype.encodePath = function (path) {
|
---|
959 | var segments = path.split('/');
|
---|
960 | var i = segments.length;
|
---|
961 | while (i--) {
|
---|
962 | // decode forward slashes to prevent them from being double encoded
|
---|
963 | segments[i] = encodeUriSegment(segments[i].replace(/%2F/g, '/'));
|
---|
964 | }
|
---|
965 | path = segments.join('/');
|
---|
966 | return _stripIndexHtml((path && path[0] !== '/' && '/' || '') + path);
|
---|
967 | };
|
---|
968 | // https://github.com/angular/angular.js/blob/864c7f0/src/ng/location.js#L42
|
---|
969 | AngularJSUrlCodec.prototype.encodeSearch = function (search) {
|
---|
970 | if (typeof search === 'string') {
|
---|
971 | search = parseKeyValue(search);
|
---|
972 | }
|
---|
973 | search = toKeyValue(search);
|
---|
974 | return search ? '?' + search : '';
|
---|
975 | };
|
---|
976 | // https://github.com/angular/angular.js/blob/864c7f0/src/ng/location.js#L44
|
---|
977 | AngularJSUrlCodec.prototype.encodeHash = function (hash) {
|
---|
978 | hash = encodeUriSegment(hash);
|
---|
979 | return hash ? '#' + hash : '';
|
---|
980 | };
|
---|
981 | // https://github.com/angular/angular.js/blob/864c7f0/src/ng/location.js#L27
|
---|
982 | AngularJSUrlCodec.prototype.decodePath = function (path, html5Mode) {
|
---|
983 | if (html5Mode === void 0) { html5Mode = true; }
|
---|
984 | var segments = path.split('/');
|
---|
985 | var i = segments.length;
|
---|
986 | while (i--) {
|
---|
987 | segments[i] = decodeURIComponent(segments[i]);
|
---|
988 | if (html5Mode) {
|
---|
989 | // encode forward slashes to prevent them from being mistaken for path separators
|
---|
990 | segments[i] = segments[i].replace(/\//g, '%2F');
|
---|
991 | }
|
---|
992 | }
|
---|
993 | return segments.join('/');
|
---|
994 | };
|
---|
995 | // https://github.com/angular/angular.js/blob/864c7f0/src/ng/location.js#L72
|
---|
996 | AngularJSUrlCodec.prototype.decodeSearch = function (search) {
|
---|
997 | return parseKeyValue(search);
|
---|
998 | };
|
---|
999 | // https://github.com/angular/angular.js/blob/864c7f0/src/ng/location.js#L73
|
---|
1000 | AngularJSUrlCodec.prototype.decodeHash = function (hash) {
|
---|
1001 | hash = decodeURIComponent(hash);
|
---|
1002 | return hash[0] === '#' ? hash.substring(1) : hash;
|
---|
1003 | };
|
---|
1004 | AngularJSUrlCodec.prototype.normalize = function (pathOrHref, search, hash, baseUrl) {
|
---|
1005 | if (arguments.length === 1) {
|
---|
1006 | var parsed = this.parse(pathOrHref, baseUrl);
|
---|
1007 | if (typeof parsed === 'string') {
|
---|
1008 | return parsed;
|
---|
1009 | }
|
---|
1010 | var serverUrl = parsed.protocol + "://" + parsed.hostname + (parsed.port ? ':' + parsed.port : '');
|
---|
1011 | return this.normalize(this.decodePath(parsed.pathname), this.decodeSearch(parsed.search), this.decodeHash(parsed.hash), serverUrl);
|
---|
1012 | }
|
---|
1013 | else {
|
---|
1014 | var encPath = this.encodePath(pathOrHref);
|
---|
1015 | var encSearch = search && this.encodeSearch(search) || '';
|
---|
1016 | var encHash = hash && this.encodeHash(hash) || '';
|
---|
1017 | var joinedPath = (baseUrl || '') + encPath;
|
---|
1018 | if (!joinedPath.length || joinedPath[0] !== '/') {
|
---|
1019 | joinedPath = '/' + joinedPath;
|
---|
1020 | }
|
---|
1021 | return joinedPath + encSearch + encHash;
|
---|
1022 | }
|
---|
1023 | };
|
---|
1024 | AngularJSUrlCodec.prototype.areEqual = function (valA, valB) {
|
---|
1025 | return this.normalize(valA) === this.normalize(valB);
|
---|
1026 | };
|
---|
1027 | // https://github.com/angular/angular.js/blob/864c7f0/src/ng/urlUtils.js#L60
|
---|
1028 | AngularJSUrlCodec.prototype.parse = function (url, base) {
|
---|
1029 | try {
|
---|
1030 | // Safari 12 throws an error when the URL constructor is called with an undefined base.
|
---|
1031 | var parsed = !base ? new URL(url) : new URL(url, base);
|
---|
1032 | return {
|
---|
1033 | href: parsed.href,
|
---|
1034 | protocol: parsed.protocol ? parsed.protocol.replace(/:$/, '') : '',
|
---|
1035 | host: parsed.host,
|
---|
1036 | search: parsed.search ? parsed.search.replace(/^\?/, '') : '',
|
---|
1037 | hash: parsed.hash ? parsed.hash.replace(/^#/, '') : '',
|
---|
1038 | hostname: parsed.hostname,
|
---|
1039 | port: parsed.port,
|
---|
1040 | pathname: (parsed.pathname.charAt(0) === '/') ? parsed.pathname : '/' + parsed.pathname
|
---|
1041 | };
|
---|
1042 | }
|
---|
1043 | catch (e) {
|
---|
1044 | throw new Error("Invalid URL (" + url + ") with base (" + base + ")");
|
---|
1045 | }
|
---|
1046 | };
|
---|
1047 | return AngularJSUrlCodec;
|
---|
1048 | }());
|
---|
1049 | function _stripIndexHtml(url) {
|
---|
1050 | return url.replace(/\/index.html$/, '');
|
---|
1051 | }
|
---|
1052 | /**
|
---|
1053 | * Tries to decode the URI component without throwing an exception.
|
---|
1054 | *
|
---|
1055 | * @param str value potential URI component to check.
|
---|
1056 | * @returns the decoded URI if it can be decoded or else `undefined`.
|
---|
1057 | */
|
---|
1058 | function tryDecodeURIComponent(value) {
|
---|
1059 | try {
|
---|
1060 | return decodeURIComponent(value);
|
---|
1061 | }
|
---|
1062 | catch (e) {
|
---|
1063 | // Ignore any invalid uri component.
|
---|
1064 | return undefined;
|
---|
1065 | }
|
---|
1066 | }
|
---|
1067 | /**
|
---|
1068 | * Parses an escaped url query string into key-value pairs. Logic taken from
|
---|
1069 | * https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1382
|
---|
1070 | */
|
---|
1071 | function parseKeyValue(keyValue) {
|
---|
1072 | var obj = {};
|
---|
1073 | (keyValue || '').split('&').forEach(function (keyValue) {
|
---|
1074 | var splitPoint, key, val;
|
---|
1075 | if (keyValue) {
|
---|
1076 | key = keyValue = keyValue.replace(/\+/g, '%20');
|
---|
1077 | splitPoint = keyValue.indexOf('=');
|
---|
1078 | if (splitPoint !== -1) {
|
---|
1079 | key = keyValue.substring(0, splitPoint);
|
---|
1080 | val = keyValue.substring(splitPoint + 1);
|
---|
1081 | }
|
---|
1082 | key = tryDecodeURIComponent(key);
|
---|
1083 | if (typeof key !== 'undefined') {
|
---|
1084 | val = typeof val !== 'undefined' ? tryDecodeURIComponent(val) : true;
|
---|
1085 | if (!obj.hasOwnProperty(key)) {
|
---|
1086 | obj[key] = val;
|
---|
1087 | }
|
---|
1088 | else if (Array.isArray(obj[key])) {
|
---|
1089 | obj[key].push(val);
|
---|
1090 | }
|
---|
1091 | else {
|
---|
1092 | obj[key] = [obj[key], val];
|
---|
1093 | }
|
---|
1094 | }
|
---|
1095 | }
|
---|
1096 | });
|
---|
1097 | return obj;
|
---|
1098 | }
|
---|
1099 | /**
|
---|
1100 | * Serializes into key-value pairs. Logic taken from
|
---|
1101 | * https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1409
|
---|
1102 | */
|
---|
1103 | function toKeyValue(obj) {
|
---|
1104 | var parts = [];
|
---|
1105 | var _loop_1 = function (key) {
|
---|
1106 | var value = obj[key];
|
---|
1107 | if (Array.isArray(value)) {
|
---|
1108 | value.forEach(function (arrayValue) {
|
---|
1109 | parts.push(encodeUriQuery(key, true) +
|
---|
1110 | (arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
|
---|
1111 | });
|
---|
1112 | }
|
---|
1113 | else {
|
---|
1114 | parts.push(encodeUriQuery(key, true) +
|
---|
1115 | (value === true ? '' : '=' + encodeUriQuery(value, true)));
|
---|
1116 | }
|
---|
1117 | };
|
---|
1118 | for (var key in obj) {
|
---|
1119 | _loop_1(key);
|
---|
1120 | }
|
---|
1121 | return parts.length ? parts.join('&') : '';
|
---|
1122 | }
|
---|
1123 | /**
|
---|
1124 | * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
|
---|
1125 | * https://tools.ietf.org/html/rfc3986 with regards to the character set (pchar) allowed in path
|
---|
1126 | * segments:
|
---|
1127 | * segment = *pchar
|
---|
1128 | * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
---|
1129 | * pct-encoded = "%" HEXDIG HEXDIG
|
---|
1130 | * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
---|
1131 | * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
---|
1132 | * / "*" / "+" / "," / ";" / "="
|
---|
1133 | *
|
---|
1134 | * Logic from https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1437
|
---|
1135 | */
|
---|
1136 | function encodeUriSegment(val) {
|
---|
1137 | return encodeUriQuery(val, true).replace(/%26/g, '&').replace(/%3D/gi, '=').replace(/%2B/gi, '+');
|
---|
1138 | }
|
---|
1139 | /**
|
---|
1140 | * This method is intended for encoding *key* or *value* parts of query component. We need a custom
|
---|
1141 | * method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
|
---|
1142 | * encoded per https://tools.ietf.org/html/rfc3986:
|
---|
1143 | * query = *( pchar / "/" / "?" )
|
---|
1144 | * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
---|
1145 | * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
---|
1146 | * pct-encoded = "%" HEXDIG HEXDIG
|
---|
1147 | * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
---|
1148 | * / "*" / "+" / "," / ";" / "="
|
---|
1149 | *
|
---|
1150 | * Logic from https://github.com/angular/angular.js/blob/864c7f0/src/Angular.js#L1456
|
---|
1151 | */
|
---|
1152 | function encodeUriQuery(val, pctEncodeSpaces) {
|
---|
1153 | if (pctEncodeSpaces === void 0) { pctEncodeSpaces = false; }
|
---|
1154 | return encodeURIComponent(val)
|
---|
1155 | .replace(/%40/g, '@')
|
---|
1156 | .replace(/%3A/gi, ':')
|
---|
1157 | .replace(/%24/g, '$')
|
---|
1158 | .replace(/%2C/gi, ',')
|
---|
1159 | .replace(/%3B/gi, ';')
|
---|
1160 | .replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | /**
|
---|
1164 | * @license
|
---|
1165 | * Copyright Google LLC All Rights Reserved.
|
---|
1166 | *
|
---|
1167 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1168 | * found in the LICENSE file at https://angular.io/license
|
---|
1169 | */
|
---|
1170 | /**
|
---|
1171 | * A provider token used to configure the location upgrade module.
|
---|
1172 | *
|
---|
1173 | * @publicApi
|
---|
1174 | */
|
---|
1175 | var LOCATION_UPGRADE_CONFIGURATION = new core.InjectionToken('LOCATION_UPGRADE_CONFIGURATION');
|
---|
1176 | var APP_BASE_HREF_RESOLVED = new core.InjectionToken('APP_BASE_HREF_RESOLVED');
|
---|
1177 | /**
|
---|
1178 | * `NgModule` used for providing and configuring Angular's Unified Location Service for upgrading.
|
---|
1179 | *
|
---|
1180 | * @see [Using the Unified Angular Location Service](guide/upgrade#using-the-unified-angular-location-service)
|
---|
1181 | *
|
---|
1182 | * @publicApi
|
---|
1183 | */
|
---|
1184 | var LocationUpgradeModule = /** @class */ (function () {
|
---|
1185 | function LocationUpgradeModule() {
|
---|
1186 | }
|
---|
1187 | LocationUpgradeModule.config = function (config) {
|
---|
1188 | return {
|
---|
1189 | ngModule: LocationUpgradeModule,
|
---|
1190 | providers: [
|
---|
1191 | common.Location,
|
---|
1192 | {
|
---|
1193 | provide: $locationShim,
|
---|
1194 | useFactory: provide$location,
|
---|
1195 | deps: [_static.UpgradeModule, common.Location, common.PlatformLocation, UrlCodec, common.LocationStrategy]
|
---|
1196 | },
|
---|
1197 | { provide: LOCATION_UPGRADE_CONFIGURATION, useValue: config ? config : {} },
|
---|
1198 | { provide: UrlCodec, useFactory: provideUrlCodec, deps: [LOCATION_UPGRADE_CONFIGURATION] },
|
---|
1199 | {
|
---|
1200 | provide: APP_BASE_HREF_RESOLVED,
|
---|
1201 | useFactory: provideAppBaseHref,
|
---|
1202 | deps: [LOCATION_UPGRADE_CONFIGURATION, [new core.Inject(common.APP_BASE_HREF), new core.Optional()]]
|
---|
1203 | },
|
---|
1204 | {
|
---|
1205 | provide: common.LocationStrategy,
|
---|
1206 | useFactory: provideLocationStrategy,
|
---|
1207 | deps: [
|
---|
1208 | common.PlatformLocation,
|
---|
1209 | APP_BASE_HREF_RESOLVED,
|
---|
1210 | LOCATION_UPGRADE_CONFIGURATION,
|
---|
1211 | ]
|
---|
1212 | },
|
---|
1213 | ],
|
---|
1214 | };
|
---|
1215 | };
|
---|
1216 | return LocationUpgradeModule;
|
---|
1217 | }());
|
---|
1218 | LocationUpgradeModule.decorators = [
|
---|
1219 | { type: core.NgModule, args: [{ imports: [common.CommonModule] },] }
|
---|
1220 | ];
|
---|
1221 | function provideAppBaseHref(config, appBaseHref) {
|
---|
1222 | if (config && config.appBaseHref != null) {
|
---|
1223 | return config.appBaseHref;
|
---|
1224 | }
|
---|
1225 | else if (appBaseHref != null) {
|
---|
1226 | return appBaseHref;
|
---|
1227 | }
|
---|
1228 | return '';
|
---|
1229 | }
|
---|
1230 | function provideUrlCodec(config) {
|
---|
1231 | var codec = config && config.urlCodec || AngularJSUrlCodec;
|
---|
1232 | return new codec();
|
---|
1233 | }
|
---|
1234 | function provideLocationStrategy(platformLocation, baseHref, options) {
|
---|
1235 | if (options === void 0) { options = {}; }
|
---|
1236 | return options.useHash ? new common.HashLocationStrategy(platformLocation, baseHref) :
|
---|
1237 | new common.PathLocationStrategy(platformLocation, baseHref);
|
---|
1238 | }
|
---|
1239 | function provide$location(ngUpgrade, location, platformLocation, urlCodec, locationStrategy) {
|
---|
1240 | var $locationProvider = new $locationShimProvider(ngUpgrade, location, platformLocation, urlCodec, locationStrategy);
|
---|
1241 | return $locationProvider.$get();
|
---|
1242 | }
|
---|
1243 |
|
---|
1244 | /**
|
---|
1245 | * @license
|
---|
1246 | * Copyright Google LLC All Rights Reserved.
|
---|
1247 | *
|
---|
1248 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1249 | * found in the LICENSE file at https://angular.io/license
|
---|
1250 | */
|
---|
1251 |
|
---|
1252 | /**
|
---|
1253 | * @license
|
---|
1254 | * Copyright Google LLC All Rights Reserved.
|
---|
1255 | *
|
---|
1256 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1257 | * found in the LICENSE file at https://angular.io/license
|
---|
1258 | */
|
---|
1259 | // This file only reexports content of the `src` folder. Keep it that way.
|
---|
1260 |
|
---|
1261 | /**
|
---|
1262 | * @license
|
---|
1263 | * Copyright Google LLC All Rights Reserved.
|
---|
1264 | *
|
---|
1265 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1266 | * found in the LICENSE file at https://angular.io/license
|
---|
1267 | */
|
---|
1268 |
|
---|
1269 | /**
|
---|
1270 | * Generated bundle index. Do not edit.
|
---|
1271 | */
|
---|
1272 |
|
---|
1273 | exports.$locationShim = $locationShim;
|
---|
1274 | exports.$locationShimProvider = $locationShimProvider;
|
---|
1275 | exports.AngularJSUrlCodec = AngularJSUrlCodec;
|
---|
1276 | exports.LOCATION_UPGRADE_CONFIGURATION = LOCATION_UPGRADE_CONFIGURATION;
|
---|
1277 | exports.LocationUpgradeModule = LocationUpgradeModule;
|
---|
1278 | exports.UrlCodec = UrlCodec;
|
---|
1279 | exports.ɵangular_packages_common_upgrade_upgrade_a = provideAppBaseHref;
|
---|
1280 | exports.ɵangular_packages_common_upgrade_upgrade_b = provideUrlCodec;
|
---|
1281 | exports.ɵangular_packages_common_upgrade_upgrade_c = provideLocationStrategy;
|
---|
1282 | exports.ɵangular_packages_common_upgrade_upgrade_d = provide$location;
|
---|
1283 |
|
---|
1284 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
1285 |
|
---|
1286 | })));
|
---|
1287 | //# sourceMappingURL=common-upgrade.umd.js.map
|
---|