Primeiro commit do projeto Angular
This commit is contained in:
+3331
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+379
@@ -0,0 +1,379 @@
|
||||
/**
|
||||
* @license Angular v21.2.1
|
||||
* (c) 2010-2026 Google LLC. https://angular.dev/
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
import * as i0 from '@angular/core';
|
||||
import { inject, Injectable, InjectionToken, DOCUMENT, Optional, Inject, ɵɵinject as __inject } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { PlatformLocation } from './_platform_location-chunk.mjs';
|
||||
|
||||
function joinWithSlash(start, end) {
|
||||
if (!start) return end;
|
||||
if (!end) return start;
|
||||
if (start.endsWith('/')) {
|
||||
return end.startsWith('/') ? start + end.slice(1) : start + end;
|
||||
}
|
||||
return end.startsWith('/') ? start + end : `${start}/${end}`;
|
||||
}
|
||||
function stripTrailingSlash(url) {
|
||||
const pathEndIdx = url.search(/#|\?|$/);
|
||||
return url[pathEndIdx - 1] === '/' ? url.slice(0, pathEndIdx - 1) + url.slice(pathEndIdx) : url;
|
||||
}
|
||||
function normalizeQueryParams(params) {
|
||||
return params && params[0] !== '?' ? `?${params}` : params;
|
||||
}
|
||||
|
||||
class LocationStrategy {
|
||||
historyGo(relativePosition) {
|
||||
throw new Error(ngDevMode ? 'Not implemented' : '');
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: LocationStrategy,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: LocationStrategy,
|
||||
providedIn: 'root',
|
||||
useFactory: () => inject(PathLocationStrategy)
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: LocationStrategy,
|
||||
decorators: [{
|
||||
type: Injectable,
|
||||
args: [{
|
||||
providedIn: 'root',
|
||||
useFactory: () => inject(PathLocationStrategy)
|
||||
}]
|
||||
}]
|
||||
});
|
||||
const APP_BASE_HREF = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'appBaseHref' : '');
|
||||
class PathLocationStrategy extends LocationStrategy {
|
||||
_platformLocation;
|
||||
_baseHref;
|
||||
_removeListenerFns = [];
|
||||
constructor(_platformLocation, href) {
|
||||
super();
|
||||
this._platformLocation = _platformLocation;
|
||||
this._baseHref = href ?? this._platformLocation.getBaseHrefFromDOM() ?? inject(DOCUMENT).location?.origin ?? '';
|
||||
}
|
||||
ngOnDestroy() {
|
||||
while (this._removeListenerFns.length) {
|
||||
this._removeListenerFns.pop()();
|
||||
}
|
||||
}
|
||||
onPopState(fn) {
|
||||
this._removeListenerFns.push(this._platformLocation.onPopState(fn), this._platformLocation.onHashChange(fn));
|
||||
}
|
||||
getBaseHref() {
|
||||
return this._baseHref;
|
||||
}
|
||||
prepareExternalUrl(internal) {
|
||||
return joinWithSlash(this._baseHref, internal);
|
||||
}
|
||||
path(includeHash = false) {
|
||||
const pathname = this._platformLocation.pathname + normalizeQueryParams(this._platformLocation.search);
|
||||
const hash = this._platformLocation.hash;
|
||||
return hash && includeHash ? `${pathname}${hash}` : pathname;
|
||||
}
|
||||
pushState(state, title, url, queryParams) {
|
||||
const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
|
||||
this._platformLocation.pushState(state, title, externalUrl);
|
||||
}
|
||||
replaceState(state, title, url, queryParams) {
|
||||
const externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
|
||||
this._platformLocation.replaceState(state, title, externalUrl);
|
||||
}
|
||||
forward() {
|
||||
this._platformLocation.forward();
|
||||
}
|
||||
back() {
|
||||
this._platformLocation.back();
|
||||
}
|
||||
getState() {
|
||||
return this._platformLocation.getState();
|
||||
}
|
||||
historyGo(relativePosition = 0) {
|
||||
this._platformLocation.historyGo?.(relativePosition);
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PathLocationStrategy,
|
||||
deps: [{
|
||||
token: PlatformLocation
|
||||
}, {
|
||||
token: APP_BASE_HREF,
|
||||
optional: true
|
||||
}],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PathLocationStrategy,
|
||||
providedIn: 'root'
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PathLocationStrategy,
|
||||
decorators: [{
|
||||
type: Injectable,
|
||||
args: [{
|
||||
providedIn: 'root'
|
||||
}]
|
||||
}],
|
||||
ctorParameters: () => [{
|
||||
type: PlatformLocation
|
||||
}, {
|
||||
type: undefined,
|
||||
decorators: [{
|
||||
type: Optional
|
||||
}, {
|
||||
type: Inject,
|
||||
args: [APP_BASE_HREF]
|
||||
}]
|
||||
}]
|
||||
});
|
||||
class NoTrailingSlashPathLocationStrategy extends PathLocationStrategy {
|
||||
prepareExternalUrl(internal) {
|
||||
const path = extractUrlPath(internal);
|
||||
if (path.endsWith('/') && path.length > 1) {
|
||||
internal = path.slice(0, -1) + internal.slice(path.length);
|
||||
}
|
||||
return super.prepareExternalUrl(internal);
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: NoTrailingSlashPathLocationStrategy,
|
||||
deps: null,
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: NoTrailingSlashPathLocationStrategy,
|
||||
providedIn: 'root'
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: NoTrailingSlashPathLocationStrategy,
|
||||
decorators: [{
|
||||
type: Injectable,
|
||||
args: [{
|
||||
providedIn: 'root'
|
||||
}]
|
||||
}]
|
||||
});
|
||||
class TrailingSlashPathLocationStrategy extends PathLocationStrategy {
|
||||
prepareExternalUrl(internal) {
|
||||
const path = extractUrlPath(internal);
|
||||
if (!path.endsWith('/')) {
|
||||
internal = path + '/' + internal.slice(path.length);
|
||||
}
|
||||
return super.prepareExternalUrl(internal);
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: TrailingSlashPathLocationStrategy,
|
||||
deps: null,
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: TrailingSlashPathLocationStrategy,
|
||||
providedIn: 'root'
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: TrailingSlashPathLocationStrategy,
|
||||
decorators: [{
|
||||
type: Injectable,
|
||||
args: [{
|
||||
providedIn: 'root'
|
||||
}]
|
||||
}]
|
||||
});
|
||||
function extractUrlPath(url) {
|
||||
const questionMarkOrHashIndex = url.search(/[?#]/);
|
||||
const pathEnd = questionMarkOrHashIndex > -1 ? questionMarkOrHashIndex : url.length;
|
||||
return url.slice(0, pathEnd);
|
||||
}
|
||||
|
||||
class Location {
|
||||
_subject = new Subject();
|
||||
_basePath;
|
||||
_locationStrategy;
|
||||
_urlChangeListeners = [];
|
||||
_urlChangeSubscription = null;
|
||||
constructor(locationStrategy) {
|
||||
this._locationStrategy = locationStrategy;
|
||||
const baseHref = this._locationStrategy.getBaseHref();
|
||||
this._basePath = _stripOrigin(stripTrailingSlash(_stripIndexHtml(baseHref)));
|
||||
this._locationStrategy.onPopState(ev => {
|
||||
this._subject.next({
|
||||
'url': this.path(true),
|
||||
'pop': true,
|
||||
'state': ev.state,
|
||||
'type': ev.type
|
||||
});
|
||||
});
|
||||
}
|
||||
ngOnDestroy() {
|
||||
this._urlChangeSubscription?.unsubscribe();
|
||||
this._urlChangeListeners = [];
|
||||
}
|
||||
path(includeHash = false) {
|
||||
return this.normalize(this._locationStrategy.path(includeHash));
|
||||
}
|
||||
getState() {
|
||||
return this._locationStrategy.getState();
|
||||
}
|
||||
isCurrentPathEqualTo(path, query = '') {
|
||||
return this.path() == this.normalize(path + normalizeQueryParams(query));
|
||||
}
|
||||
normalize(url) {
|
||||
return Location.stripTrailingSlash(_stripBasePath(this._basePath, _stripIndexHtml(url)));
|
||||
}
|
||||
prepareExternalUrl(url) {
|
||||
if (url && url[0] !== '/') {
|
||||
url = '/' + url;
|
||||
}
|
||||
return this._locationStrategy.prepareExternalUrl(url);
|
||||
}
|
||||
go(path, query = '', state = null) {
|
||||
this._locationStrategy.pushState(state, '', path, query);
|
||||
this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
|
||||
}
|
||||
replaceState(path, query = '', state = null) {
|
||||
this._locationStrategy.replaceState(state, '', path, query);
|
||||
this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
|
||||
}
|
||||
forward() {
|
||||
this._locationStrategy.forward();
|
||||
}
|
||||
back() {
|
||||
this._locationStrategy.back();
|
||||
}
|
||||
historyGo(relativePosition = 0) {
|
||||
this._locationStrategy.historyGo?.(relativePosition);
|
||||
}
|
||||
onUrlChange(fn) {
|
||||
this._urlChangeListeners.push(fn);
|
||||
this._urlChangeSubscription ??= this.subscribe(v => {
|
||||
this._notifyUrlChangeListeners(v.url, v.state);
|
||||
});
|
||||
return () => {
|
||||
const fnIndex = this._urlChangeListeners.indexOf(fn);
|
||||
this._urlChangeListeners.splice(fnIndex, 1);
|
||||
if (this._urlChangeListeners.length === 0) {
|
||||
this._urlChangeSubscription?.unsubscribe();
|
||||
this._urlChangeSubscription = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
_notifyUrlChangeListeners(url = '', state) {
|
||||
this._urlChangeListeners.forEach(fn => fn(url, state));
|
||||
}
|
||||
subscribe(onNext, onThrow, onReturn) {
|
||||
return this._subject.subscribe({
|
||||
next: onNext,
|
||||
error: onThrow ?? undefined,
|
||||
complete: onReturn ?? undefined
|
||||
});
|
||||
}
|
||||
static normalizeQueryParams = normalizeQueryParams;
|
||||
static joinWithSlash = joinWithSlash;
|
||||
static stripTrailingSlash = stripTrailingSlash;
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: Location,
|
||||
deps: [{
|
||||
token: LocationStrategy
|
||||
}],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: Location,
|
||||
providedIn: 'root',
|
||||
useFactory: createLocation
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: Location,
|
||||
decorators: [{
|
||||
type: Injectable,
|
||||
args: [{
|
||||
providedIn: 'root',
|
||||
useFactory: createLocation
|
||||
}]
|
||||
}],
|
||||
ctorParameters: () => [{
|
||||
type: LocationStrategy
|
||||
}]
|
||||
});
|
||||
function createLocation() {
|
||||
return new Location(__inject(LocationStrategy));
|
||||
}
|
||||
function _stripBasePath(basePath, url) {
|
||||
if (!basePath || !url.startsWith(basePath)) {
|
||||
return url;
|
||||
}
|
||||
const strippedUrl = url.substring(basePath.length);
|
||||
if (strippedUrl === '' || ['/', ';', '?', '#'].includes(strippedUrl[0])) {
|
||||
return strippedUrl;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
function _stripIndexHtml(url) {
|
||||
return url.replace(/\/index.html$/, '');
|
||||
}
|
||||
function _stripOrigin(baseHref) {
|
||||
const isAbsoluteUrl = new RegExp('^(https?:)?//').test(baseHref);
|
||||
if (isAbsoluteUrl) {
|
||||
const [, pathname] = baseHref.split(/\/\/[^\/]+/);
|
||||
return pathname;
|
||||
}
|
||||
return baseHref;
|
||||
}
|
||||
|
||||
export { APP_BASE_HREF, Location, LocationStrategy, NoTrailingSlashPathLocationStrategy, PathLocationStrategy, TrailingSlashPathLocationStrategy, joinWithSlash, normalizeQueryParams };
|
||||
//# sourceMappingURL=_location-chunk.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+2212
File diff suppressed because it is too large
Load Diff
+1
File diff suppressed because one or more lines are too long
+151
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* @license Angular v21.2.1
|
||||
* (c) 2010-2026 Google LLC. https://angular.dev/
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
import * as i0 from '@angular/core';
|
||||
import { inject, Injectable, InjectionToken, DOCUMENT } from '@angular/core';
|
||||
|
||||
let _DOM = null;
|
||||
function getDOM() {
|
||||
return _DOM;
|
||||
}
|
||||
function setRootDomAdapter(adapter) {
|
||||
_DOM ??= adapter;
|
||||
}
|
||||
class DomAdapter {}
|
||||
|
||||
class PlatformLocation {
|
||||
historyGo(relativePosition) {
|
||||
throw new Error(ngDevMode ? 'Not implemented' : '');
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PlatformLocation,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PlatformLocation,
|
||||
providedIn: 'platform',
|
||||
useFactory: () => inject(BrowserPlatformLocation)
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PlatformLocation,
|
||||
decorators: [{
|
||||
type: Injectable,
|
||||
args: [{
|
||||
providedIn: 'platform',
|
||||
useFactory: () => inject(BrowserPlatformLocation)
|
||||
}]
|
||||
}]
|
||||
});
|
||||
const LOCATION_INITIALIZED = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'Location Initialized' : '');
|
||||
class BrowserPlatformLocation extends PlatformLocation {
|
||||
_location;
|
||||
_history;
|
||||
_doc = inject(DOCUMENT);
|
||||
constructor() {
|
||||
super();
|
||||
this._location = window.location;
|
||||
this._history = window.history;
|
||||
}
|
||||
getBaseHrefFromDOM() {
|
||||
return getDOM().getBaseHref(this._doc);
|
||||
}
|
||||
onPopState(fn) {
|
||||
const window = getDOM().getGlobalEventTarget(this._doc, 'window');
|
||||
window.addEventListener('popstate', fn, false);
|
||||
return () => window.removeEventListener('popstate', fn);
|
||||
}
|
||||
onHashChange(fn) {
|
||||
const window = getDOM().getGlobalEventTarget(this._doc, 'window');
|
||||
window.addEventListener('hashchange', fn, false);
|
||||
return () => window.removeEventListener('hashchange', fn);
|
||||
}
|
||||
get href() {
|
||||
return this._location.href;
|
||||
}
|
||||
get protocol() {
|
||||
return this._location.protocol;
|
||||
}
|
||||
get hostname() {
|
||||
return this._location.hostname;
|
||||
}
|
||||
get port() {
|
||||
return this._location.port;
|
||||
}
|
||||
get pathname() {
|
||||
return this._location.pathname;
|
||||
}
|
||||
get search() {
|
||||
return this._location.search;
|
||||
}
|
||||
get hash() {
|
||||
return this._location.hash;
|
||||
}
|
||||
set pathname(newPath) {
|
||||
this._location.pathname = newPath;
|
||||
}
|
||||
pushState(state, title, url) {
|
||||
this._history.pushState(state, title, url);
|
||||
}
|
||||
replaceState(state, title, url) {
|
||||
this._history.replaceState(state, title, url);
|
||||
}
|
||||
forward() {
|
||||
this._history.forward();
|
||||
}
|
||||
back() {
|
||||
this._history.back();
|
||||
}
|
||||
historyGo(relativePosition = 0) {
|
||||
this._history.go(relativePosition);
|
||||
}
|
||||
getState() {
|
||||
return this._history.state;
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: BrowserPlatformLocation,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: BrowserPlatformLocation,
|
||||
providedIn: 'platform',
|
||||
useFactory: () => new BrowserPlatformLocation()
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: BrowserPlatformLocation,
|
||||
decorators: [{
|
||||
type: Injectable,
|
||||
args: [{
|
||||
providedIn: 'platform',
|
||||
useFactory: () => new BrowserPlatformLocation()
|
||||
}]
|
||||
}],
|
||||
ctorParameters: () => []
|
||||
});
|
||||
|
||||
export { BrowserPlatformLocation, DomAdapter, LOCATION_INITIALIZED, PlatformLocation, getDOM, setRootDomAdapter };
|
||||
//# sourceMappingURL=_platform_location-chunk.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @license Angular v21.2.1
|
||||
* (c) 2010-2026 Google LLC. https://angular.dev/
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
import * as i0 from '@angular/core';
|
||||
import { InjectionToken, Injectable } from '@angular/core';
|
||||
|
||||
const PRECOMMIT_HANDLER_SUPPORTED = new InjectionToken('', {
|
||||
factory: () => {
|
||||
return typeof window !== 'undefined' && typeof window.NavigationPrecommitController !== 'undefined';
|
||||
}
|
||||
});
|
||||
class PlatformNavigation {
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PlatformNavigation,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PlatformNavigation,
|
||||
providedIn: 'platform',
|
||||
useFactory: () => window.navigation
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: PlatformNavigation,
|
||||
decorators: [{
|
||||
type: Injectable,
|
||||
args: [{
|
||||
providedIn: 'platform',
|
||||
useFactory: () => window.navigation
|
||||
}]
|
||||
}]
|
||||
});
|
||||
|
||||
export { PRECOMMIT_HANDLER_SUPPORTED, PlatformNavigation };
|
||||
//# sourceMappingURL=_platform_navigation-chunk.mjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"_platform_navigation-chunk.mjs","sources":["../../../../../k8-fastbuild-ST-fdfa778d11ba/bin/packages/common/src/navigation/platform_navigation.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {\n Injectable,\n InjectionToken,\n ɵNavigateEvent as NavigateEvent,\n ɵNavigation as Navigation,\n ɵNavigationCurrentEntryChangeEvent as NavigationCurrentEntryChangeEvent,\n ɵNavigationHistoryEntry as NavigationHistoryEntry,\n ɵNavigationNavigateOptions as NavigationNavigateOptions,\n ɵNavigationOptions as NavigationOptions,\n ɵNavigationReloadOptions as NavigationReloadOptions,\n ɵNavigationResult as NavigationResult,\n ɵNavigationTransition as NavigationTransition,\n ɵNavigationUpdateCurrentEntryOptions as NavigationUpdateCurrentEntryOptions,\n} from '@angular/core';\n\n/**\n * @see https://developer.mozilla.org/en-US/docs/Web/API/NavigationPrecommitController\n * @see https://developer.mozilla.org/en-US/docs/Web/API/NavigateEvent/intercept#precommithandler\n */\nexport const PRECOMMIT_HANDLER_SUPPORTED = new InjectionToken<boolean>('', {\n factory: () => {\n return (\n typeof window !== 'undefined' &&\n typeof (window as any).NavigationPrecommitController !== 'undefined'\n );\n },\n});\n\n/**\n * This class wraps the platform Navigation API which allows server-specific and test\n * implementations.\n *\n * Browser support is limited, so this API may not be available in all environments,\n * may contain bugs, and is experimental.\n *\n * @experimental 21.0.0\n */\n@Injectable({providedIn: 'platform', useFactory: () => (window as any).navigation})\nexport abstract class PlatformNavigation implements Navigation {\n abstract entries(): NavigationHistoryEntry[];\n abstract currentEntry: NavigationHistoryEntry | null;\n abstract updateCurrentEntry(options: NavigationUpdateCurrentEntryOptions): void;\n abstract transition: NavigationTransition | null;\n abstract canGoBack: boolean;\n abstract canGoForward: boolean;\n abstract navigate(url: string, options?: NavigationNavigateOptions | undefined): NavigationResult;\n abstract reload(options?: NavigationReloadOptions | undefined): NavigationResult;\n abstract traverseTo(key: string, options?: NavigationOptions | undefined): NavigationResult;\n abstract back(options?: NavigationOptions | undefined): NavigationResult;\n abstract forward(options?: NavigationOptions | undefined): NavigationResult;\n abstract onnavigate: ((this: Navigation, ev: NavigateEvent) => any) | null;\n abstract onnavigatesuccess: ((this: Navigation, ev: Event) => any) | null;\n abstract onnavigateerror: ((this: Navigation, ev: ErrorEvent) => any) | null;\n abstract oncurrententrychange:\n | ((this: Navigation, ev: NavigationCurrentEntryChangeEvent) => any)\n | null;\n abstract addEventListener(type: unknown, listener: unknown, options?: unknown): void;\n abstract removeEventListener(type: unknown, listener: unknown, options?: unknown): void;\n abstract dispatchEvent(event: Event): boolean;\n}\n"],"names":["PRECOMMIT_HANDLER_SUPPORTED","InjectionToken","factory","window","NavigationPrecommitController","PlatformNavigation","deps","target","i0","ɵɵFactoryTarget","Injectable","providedIn","useFactory","navigation","decorators","args"],"mappings":";;;;;;;;;MA2BaA,2BAA2B,GAAG,IAAIC,cAAc,CAAU,EAAE,EAAE;EACzEC,OAAO,EAAEA,MAAK;IACZ,OACE,OAAOC,MAAM,KAAK,WAAW,IAC7B,OAAQA,MAAc,CAACC,6BAA6B,KAAK,WAAW;AAExE;AACD,CAAA;MAYqBC,kBAAkB,CAAA;;;;;UAAlBA,kBAAkB;AAAAC,IAAAA,IAAA,EAAA,EAAA;AAAAC,IAAAA,MAAA,EAAAC,EAAA,CAAAC,eAAA,CAAAC;AAAA,GAAA,CAAA;;;;;UAAlBL,kBAAkB;AAAAM,IAAAA,UAAA,EADf,UAAU;AAAcC,IAAAA,UAAA,EAAAA,MAAOT,MAAc,CAACU;AAAU,GAAA,CAAA;;;;;;QAC3DR,kBAAkB;AAAAS,EAAAA,UAAA,EAAA,CAAA;UADvCJ,UAAU;AAACK,IAAAA,IAAA,EAAA,CAAA;AAACJ,MAAAA,UAAU,EAAE,UAAU;AAAEC,MAAAA,UAAU,EAAEA,MAAOT,MAAc,CAACU;KAAW;;;;;;"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* @license Angular v21.2.1
|
||||
* (c) 2010-2026 Google LLC. https://angular.dev/
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
function parseCookieValue(cookieStr, name) {
|
||||
name = encodeURIComponent(name);
|
||||
for (const cookie of cookieStr.split(';')) {
|
||||
const eqIndex = cookie.indexOf('=');
|
||||
const [cookieName, cookieValue] = eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)];
|
||||
if (cookieName.trim() === name) {
|
||||
return decodeURIComponent(cookieValue);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class XhrFactory {}
|
||||
|
||||
export { XhrFactory, parseCookieValue };
|
||||
//# sourceMappingURL=_xhr-chunk.mjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"_xhr-chunk.mjs","sources":["../../../../../k8-fastbuild-ST-fdfa778d11ba/bin/packages/common/src/cookie.ts","../../../../../k8-fastbuild-ST-fdfa778d11ba/bin/packages/common/src/xhr.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nexport function parseCookieValue(cookieStr: string, name: string): string | null {\n name = encodeURIComponent(name);\n for (const cookie of cookieStr.split(';')) {\n const eqIndex = cookie.indexOf('=');\n const [cookieName, cookieValue]: string[] =\n eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)];\n if (cookieName.trim() === name) {\n return decodeURIComponent(cookieValue);\n }\n }\n return null;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\n/**\n * A wrapper around the `XMLHttpRequest` constructor.\n *\n * @publicApi\n */\nexport abstract class XhrFactory {\n abstract build(): XMLHttpRequest;\n}\n"],"names":["parseCookieValue","cookieStr","name","encodeURIComponent","cookie","split","eqIndex","indexOf","cookieName","cookieValue","slice","trim","decodeURIComponent","XhrFactory"],"mappings":";;;;;;AAQgB,SAAAA,gBAAgBA,CAACC,SAAiB,EAAEC,IAAY,EAAA;AAC9DA,EAAAA,IAAI,GAAGC,kBAAkB,CAACD,IAAI,CAAC;EAC/B,KAAK,MAAME,MAAM,IAAIH,SAAS,CAACI,KAAK,CAAC,GAAG,CAAC,EAAE;AACzC,IAAA,MAAMC,OAAO,GAAGF,MAAM,CAACG,OAAO,CAAC,GAAG,CAAC;AACnC,IAAA,MAAM,CAACC,UAAU,EAAEC,WAAW,CAAC,GAC7BH,OAAO,IAAI,CAAC,CAAC,GAAG,CAACF,MAAM,EAAE,EAAE,CAAC,GAAG,CAACA,MAAM,CAACM,KAAK,CAAC,CAAC,EAAEJ,OAAO,CAAC,EAAEF,MAAM,CAACM,KAAK,CAACJ,OAAO,GAAG,CAAC,CAAC,CAAC;AACtF,IAAA,IAAIE,UAAU,CAACG,IAAI,EAAE,KAAKT,IAAI,EAAE;MAC9B,OAAOU,kBAAkB,CAACH,WAAW,CAAC;AACxC;AACF;AACA,EAAA,OAAO,IAAI;AACb;;MCNsBI,UAAU,CAAA;;;;"}
|
||||
+1441
File diff suppressed because it is too large
Load Diff
+1
File diff suppressed because one or more lines are too long
+311
@@ -0,0 +1,311 @@
|
||||
/**
|
||||
* @license Angular v21.2.1
|
||||
* (c) 2010-2026 Google LLC. https://angular.dev/
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
import * as i0 from '@angular/core';
|
||||
import { Injectable, NgModule } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { HttpHeaders, HttpResponse, HttpErrorResponse, HttpStatusCode, HttpEventType, HttpBackend, REQUESTS_CONTRIBUTE_TO_STABILITY, HttpClientModule } from './_module-chunk.mjs';
|
||||
import 'rxjs/operators';
|
||||
import './_xhr-chunk.mjs';
|
||||
import './_platform_location-chunk.mjs';
|
||||
|
||||
class HttpTestingController {}
|
||||
|
||||
class TestRequest {
|
||||
request;
|
||||
observer;
|
||||
get cancelled() {
|
||||
return this._cancelled;
|
||||
}
|
||||
_cancelled = false;
|
||||
constructor(request, observer) {
|
||||
this.request = request;
|
||||
this.observer = observer;
|
||||
}
|
||||
flush(body, opts = {}) {
|
||||
if (this.cancelled) {
|
||||
throw new Error(`Cannot flush a cancelled request.`);
|
||||
}
|
||||
const url = this.request.urlWithParams;
|
||||
const headers = opts.headers instanceof HttpHeaders ? opts.headers : new HttpHeaders(opts.headers);
|
||||
body = _maybeConvertBody(this.request.responseType, body);
|
||||
let statusText = opts.statusText;
|
||||
let status = opts.status !== undefined ? opts.status : HttpStatusCode.Ok;
|
||||
if (opts.status === undefined) {
|
||||
if (body === null) {
|
||||
status = HttpStatusCode.NoContent;
|
||||
statusText ||= 'No Content';
|
||||
} else {
|
||||
statusText ||= 'OK';
|
||||
}
|
||||
}
|
||||
if (statusText === undefined) {
|
||||
throw new Error('statusText is required when setting a custom status.');
|
||||
}
|
||||
if (status >= 200 && status < 300) {
|
||||
this.observer.next(new HttpResponse({
|
||||
body,
|
||||
headers,
|
||||
status,
|
||||
statusText,
|
||||
url
|
||||
}));
|
||||
this.observer.complete();
|
||||
} else {
|
||||
this.observer.error(new HttpErrorResponse({
|
||||
error: body,
|
||||
headers,
|
||||
status,
|
||||
statusText,
|
||||
url
|
||||
}));
|
||||
}
|
||||
}
|
||||
error(error, opts = {}) {
|
||||
if (this.cancelled) {
|
||||
throw new Error(`Cannot return an error for a cancelled request.`);
|
||||
}
|
||||
const headers = opts.headers instanceof HttpHeaders ? opts.headers : new HttpHeaders(opts.headers);
|
||||
this.observer.error(new HttpErrorResponse({
|
||||
error,
|
||||
headers,
|
||||
status: opts.status || 0,
|
||||
statusText: opts.statusText || '',
|
||||
url: this.request.urlWithParams
|
||||
}));
|
||||
}
|
||||
event(event) {
|
||||
if (this.cancelled) {
|
||||
throw new Error(`Cannot send events to a cancelled request.`);
|
||||
}
|
||||
this.observer.next(event);
|
||||
}
|
||||
}
|
||||
function _toArrayBufferBody(body) {
|
||||
if (typeof ArrayBuffer === 'undefined') {
|
||||
throw new Error('ArrayBuffer responses are not supported on this platform.');
|
||||
}
|
||||
if (body instanceof ArrayBuffer) {
|
||||
return body;
|
||||
}
|
||||
throw new Error('Automatic conversion to ArrayBuffer is not supported for response type.');
|
||||
}
|
||||
function _toBlob(body) {
|
||||
if (typeof Blob === 'undefined') {
|
||||
throw new Error('Blob responses are not supported on this platform.');
|
||||
}
|
||||
if (body instanceof Blob) {
|
||||
return body;
|
||||
}
|
||||
if (ArrayBuffer && body instanceof ArrayBuffer) {
|
||||
return new Blob([body]);
|
||||
}
|
||||
throw new Error('Automatic conversion to Blob is not supported for response type.');
|
||||
}
|
||||
function _toJsonBody(body, format = 'JSON') {
|
||||
if (typeof ArrayBuffer !== 'undefined' && body instanceof ArrayBuffer) {
|
||||
throw new Error(`Automatic conversion to ${format} is not supported for ArrayBuffers.`);
|
||||
}
|
||||
if (typeof Blob !== 'undefined' && body instanceof Blob) {
|
||||
throw new Error(`Automatic conversion to ${format} is not supported for Blobs.`);
|
||||
}
|
||||
if (typeof body === 'string' || typeof body === 'number' || typeof body === 'object' || typeof body === 'boolean' || Array.isArray(body)) {
|
||||
return body;
|
||||
}
|
||||
throw new Error(`Automatic conversion to ${format} is not supported for response type.`);
|
||||
}
|
||||
function _toTextBody(body) {
|
||||
if (typeof body === 'string') {
|
||||
return body;
|
||||
}
|
||||
if (typeof ArrayBuffer !== 'undefined' && body instanceof ArrayBuffer) {
|
||||
throw new Error('Automatic conversion to text is not supported for ArrayBuffers.');
|
||||
}
|
||||
if (typeof Blob !== 'undefined' && body instanceof Blob) {
|
||||
throw new Error('Automatic conversion to text is not supported for Blobs.');
|
||||
}
|
||||
return JSON.stringify(_toJsonBody(body, 'text'));
|
||||
}
|
||||
function _maybeConvertBody(responseType, body) {
|
||||
if (body === null) {
|
||||
return null;
|
||||
}
|
||||
switch (responseType) {
|
||||
case 'arraybuffer':
|
||||
return _toArrayBufferBody(body);
|
||||
case 'blob':
|
||||
return _toBlob(body);
|
||||
case 'json':
|
||||
return _toJsonBody(body);
|
||||
case 'text':
|
||||
return _toTextBody(body);
|
||||
default:
|
||||
throw new Error(`Unsupported responseType: ${responseType}`);
|
||||
}
|
||||
}
|
||||
|
||||
class HttpClientTestingBackend {
|
||||
open = [];
|
||||
isTestingBackend = true;
|
||||
handle(req) {
|
||||
return new Observable(observer => {
|
||||
const testReq = new TestRequest(req, observer);
|
||||
this.open.push(testReq);
|
||||
observer.next({
|
||||
type: HttpEventType.Sent
|
||||
});
|
||||
return () => {
|
||||
testReq._cancelled = true;
|
||||
};
|
||||
});
|
||||
}
|
||||
_match(match) {
|
||||
if (typeof match === 'string') {
|
||||
return this.open.filter(testReq => testReq.request.urlWithParams === match);
|
||||
} else if (typeof match === 'function') {
|
||||
return this.open.filter(testReq => match(testReq.request));
|
||||
} else {
|
||||
return this.open.filter(testReq => (!match.method || testReq.request.method === match.method.toUpperCase()) && (!match.url || testReq.request.urlWithParams === match.url));
|
||||
}
|
||||
}
|
||||
match(match) {
|
||||
const results = this._match(match);
|
||||
results.forEach(result => {
|
||||
const index = this.open.indexOf(result);
|
||||
if (index !== -1) {
|
||||
this.open.splice(index, 1);
|
||||
}
|
||||
});
|
||||
return results;
|
||||
}
|
||||
expectOne(match, description) {
|
||||
description ||= this.descriptionFromMatcher(match);
|
||||
const matches = this.match(match);
|
||||
if (matches.length > 1) {
|
||||
throw new Error(`Expected one matching request for criteria "${description}", found ${matches.length} requests.`);
|
||||
}
|
||||
if (matches.length === 0) {
|
||||
let message = `Expected one matching request for criteria "${description}", found none.`;
|
||||
if (this.open.length > 0) {
|
||||
const requests = this.open.map(describeRequest).join(', ');
|
||||
message += ` Requests received are: ${requests}.`;
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
return matches[0];
|
||||
}
|
||||
expectNone(match, description) {
|
||||
description ||= this.descriptionFromMatcher(match);
|
||||
const matches = this.match(match);
|
||||
if (matches.length > 0) {
|
||||
throw new Error(`Expected zero matching requests for criteria "${description}", found ${matches.length}.`);
|
||||
}
|
||||
}
|
||||
verify(opts = {}) {
|
||||
let open = this.open;
|
||||
if (opts.ignoreCancelled) {
|
||||
open = open.filter(testReq => !testReq.cancelled);
|
||||
}
|
||||
if (open.length > 0) {
|
||||
const requests = open.map(describeRequest).join(', ');
|
||||
throw new Error(`Expected no open requests, found ${open.length}: ${requests}`);
|
||||
}
|
||||
}
|
||||
descriptionFromMatcher(matcher) {
|
||||
if (typeof matcher === 'string') {
|
||||
return `Match URL: ${matcher}`;
|
||||
} else if (typeof matcher === 'object') {
|
||||
const method = matcher.method || '(any)';
|
||||
const url = matcher.url || '(any)';
|
||||
return `Match method: ${method}, URL: ${url}`;
|
||||
} else {
|
||||
return `Match by function: ${matcher.name}`;
|
||||
}
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: HttpClientTestingBackend,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: HttpClientTestingBackend
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: HttpClientTestingBackend,
|
||||
decorators: [{
|
||||
type: Injectable
|
||||
}]
|
||||
});
|
||||
function describeRequest(testRequest) {
|
||||
const url = testRequest.request.urlWithParams;
|
||||
const method = testRequest.request.method;
|
||||
return `${method} ${url}`;
|
||||
}
|
||||
|
||||
function provideHttpClientTesting() {
|
||||
return [HttpClientTestingBackend, {
|
||||
provide: HttpBackend,
|
||||
useExisting: HttpClientTestingBackend
|
||||
}, {
|
||||
provide: HttpTestingController,
|
||||
useExisting: HttpClientTestingBackend
|
||||
}, {
|
||||
provide: REQUESTS_CONTRIBUTE_TO_STABILITY,
|
||||
useValue: false
|
||||
}];
|
||||
}
|
||||
|
||||
class HttpClientTestingModule {
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: HttpClientTestingModule,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.NgModule
|
||||
});
|
||||
static ɵmod = i0.ɵɵngDeclareNgModule({
|
||||
minVersion: "14.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: HttpClientTestingModule,
|
||||
imports: [HttpClientModule]
|
||||
});
|
||||
static ɵinj = i0.ɵɵngDeclareInjector({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: HttpClientTestingModule,
|
||||
providers: [provideHttpClientTesting()],
|
||||
imports: [HttpClientModule]
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: HttpClientTestingModule,
|
||||
decorators: [{
|
||||
type: NgModule,
|
||||
args: [{
|
||||
imports: [HttpClientModule],
|
||||
providers: [provideHttpClientTesting()]
|
||||
}]
|
||||
}]
|
||||
});
|
||||
|
||||
export { HttpClientTestingModule, HttpTestingController, TestRequest, provideHttpClientTesting };
|
||||
//# sourceMappingURL=http-testing.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+433
@@ -0,0 +1,433 @@
|
||||
/**
|
||||
* @license Angular v21.2.1
|
||||
* (c) 2010-2026 Google LLC. https://angular.dev/
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
import { HTTP_ROOT_INTERCEPTOR_FNS, HttpResponse, HttpHeaders, HttpParams, HttpRequest, HttpEventType, HttpErrorResponse, HttpClient } from './_module-chunk.mjs';
|
||||
export { FetchBackend, HTTP_INTERCEPTORS, HttpBackend, HttpClientJsonpModule, HttpClientModule, HttpClientXsrfModule, HttpContext, HttpContextToken, HttpFeatureKind, HttpHandler, HttpHeaderResponse, HttpResponseBase, HttpStatusCode, HttpUrlEncodingCodec, HttpXhrBackend, HttpXsrfTokenExtractor, JsonpClientBackend, JsonpInterceptor, provideHttpClient, withFetch, withInterceptors, withInterceptorsFromDi, withJsonpSupport, withNoXsrfProtection, withRequestsMadeViaParent, withXsrfConfiguration, HttpInterceptorHandler as ɵHttpInterceptingHandler, REQUESTS_CONTRIBUTE_TO_STABILITY as ɵREQUESTS_CONTRIBUTE_TO_STABILITY } from './_module-chunk.mjs';
|
||||
import { InjectionToken, ɵperformanceMarkFeature as _performanceMarkFeature, APP_BOOTSTRAP_LISTENER, inject, ApplicationRef, TransferState, makeStateKey, ɵRuntimeError as _RuntimeError, ɵtruncateMiddle as _truncateMiddle, ɵformatRuntimeError as _formatRuntimeError, assertInInjectionContext, Injector, ɵResourceImpl as _ResourceImpl, linkedSignal, computed, signal, ɵencapsulateResourceError as _encapsulateResourceError } from '@angular/core';
|
||||
import { of } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import './_xhr-chunk.mjs';
|
||||
import './_platform_location-chunk.mjs';
|
||||
|
||||
const HTTP_TRANSFER_CACHE_ORIGIN_MAP = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'HTTP_TRANSFER_CACHE_ORIGIN_MAP' : '');
|
||||
const BODY = 'b';
|
||||
const HEADERS = 'h';
|
||||
const STATUS = 's';
|
||||
const STATUS_TEXT = 'st';
|
||||
const REQ_URL = 'u';
|
||||
const RESPONSE_TYPE = 'rt';
|
||||
const CACHE_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'HTTP_TRANSFER_STATE_CACHE_OPTIONS' : '');
|
||||
const ALLOWED_METHODS = ['GET', 'HEAD'];
|
||||
function shouldCacheRequest(req, options) {
|
||||
const {
|
||||
isCacheActive,
|
||||
...globalOptions
|
||||
} = options;
|
||||
const {
|
||||
transferCache: requestOptions,
|
||||
method: requestMethod
|
||||
} = req;
|
||||
if (!isCacheActive || requestOptions === false || requestMethod === 'POST' && !globalOptions.includePostRequests && !requestOptions || requestMethod !== 'POST' && !ALLOWED_METHODS.includes(requestMethod) || !globalOptions.includeRequestsWithAuthHeaders && hasAuthHeaders(req) || globalOptions.filter?.(req) === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function getHeadersToInclude(options, requestOptions) {
|
||||
const {
|
||||
includeHeaders: globalHeaders
|
||||
} = options;
|
||||
let headersToInclude = globalHeaders;
|
||||
if (typeof requestOptions === 'object' && requestOptions.includeHeaders) {
|
||||
headersToInclude = requestOptions.includeHeaders;
|
||||
}
|
||||
return headersToInclude;
|
||||
}
|
||||
function retrieveStateFromCache(req, options, transferState, originMap) {
|
||||
const {
|
||||
transferCache: requestOptions
|
||||
} = req;
|
||||
if (!shouldCacheRequest(req, options)) {
|
||||
return null;
|
||||
}
|
||||
if (typeof ngServerMode !== 'undefined' && !ngServerMode && originMap) {
|
||||
throw new _RuntimeError(2803, ngDevMode && 'Angular detected that the `HTTP_TRANSFER_CACHE_ORIGIN_MAP` token is configured and ' + 'present in the client side code. Please ensure that this token is only provided in the ' + 'server code of the application.');
|
||||
}
|
||||
const requestUrl = typeof ngServerMode !== 'undefined' && ngServerMode && originMap ? mapRequestOriginUrl(req.url, originMap) : req.url;
|
||||
const storeKey = makeCacheKey(req, requestUrl);
|
||||
const response = transferState.get(storeKey, null);
|
||||
const headersToInclude = getHeadersToInclude(options, requestOptions);
|
||||
if (response) {
|
||||
const {
|
||||
[BODY]: undecodedBody,
|
||||
[RESPONSE_TYPE]: responseType,
|
||||
[HEADERS]: httpHeaders,
|
||||
[STATUS]: status,
|
||||
[STATUS_TEXT]: statusText,
|
||||
[REQ_URL]: url
|
||||
} = response;
|
||||
let body = undecodedBody;
|
||||
switch (responseType) {
|
||||
case 'arraybuffer':
|
||||
body = fromBase64(undecodedBody);
|
||||
break;
|
||||
case 'blob':
|
||||
body = new Blob([fromBase64(undecodedBody)]);
|
||||
break;
|
||||
}
|
||||
let headers = new HttpHeaders(httpHeaders);
|
||||
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
||||
headers = appendMissingHeadersDetection(req.url, headers, headersToInclude ?? []);
|
||||
}
|
||||
return new HttpResponse({
|
||||
body,
|
||||
headers,
|
||||
status,
|
||||
statusText,
|
||||
url
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function transferCacheInterceptorFn(req, next) {
|
||||
const options = inject(CACHE_OPTIONS);
|
||||
const transferState = inject(TransferState);
|
||||
const originMap = inject(HTTP_TRANSFER_CACHE_ORIGIN_MAP, {
|
||||
optional: true
|
||||
});
|
||||
const cachedResponse = retrieveStateFromCache(req, options, transferState, originMap);
|
||||
if (cachedResponse) {
|
||||
return of(cachedResponse);
|
||||
}
|
||||
const {
|
||||
transferCache: requestOptions
|
||||
} = req;
|
||||
const headersToInclude = getHeadersToInclude(options, requestOptions);
|
||||
const requestUrl = typeof ngServerMode !== 'undefined' && ngServerMode && originMap ? mapRequestOriginUrl(req.url, originMap) : req.url;
|
||||
const storeKey = makeCacheKey(req, requestUrl);
|
||||
if (!shouldCacheRequest(req, options)) {
|
||||
return next(req);
|
||||
}
|
||||
const event$ = next(req);
|
||||
if (typeof ngServerMode !== 'undefined' && ngServerMode) {
|
||||
return event$.pipe(tap(event => {
|
||||
if (event instanceof HttpResponse) {
|
||||
transferState.set(storeKey, {
|
||||
[BODY]: req.responseType === 'arraybuffer' || req.responseType === 'blob' ? toBase64(event.body) : event.body,
|
||||
[HEADERS]: getFilteredHeaders(event.headers, headersToInclude),
|
||||
[STATUS]: event.status,
|
||||
[STATUS_TEXT]: event.statusText,
|
||||
[REQ_URL]: requestUrl,
|
||||
[RESPONSE_TYPE]: req.responseType
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
return event$;
|
||||
}
|
||||
function hasAuthHeaders(req) {
|
||||
return req.headers.has('authorization') || req.headers.has('proxy-authorization');
|
||||
}
|
||||
function getFilteredHeaders(headers, includeHeaders) {
|
||||
if (!includeHeaders) {
|
||||
return {};
|
||||
}
|
||||
const headersMap = {};
|
||||
for (const key of includeHeaders) {
|
||||
const values = headers.getAll(key);
|
||||
if (values !== null) {
|
||||
headersMap[key] = values;
|
||||
}
|
||||
}
|
||||
return headersMap;
|
||||
}
|
||||
function sortAndConcatParams(params) {
|
||||
return [...params.keys()].sort().map(k => `${k}=${params.getAll(k)}`).join('&');
|
||||
}
|
||||
function makeCacheKey(request, mappedRequestUrl) {
|
||||
const {
|
||||
params,
|
||||
method,
|
||||
responseType
|
||||
} = request;
|
||||
const encodedParams = sortAndConcatParams(params);
|
||||
let serializedBody = request.serializeBody();
|
||||
if (serializedBody instanceof URLSearchParams) {
|
||||
serializedBody = sortAndConcatParams(serializedBody);
|
||||
} else if (typeof serializedBody !== 'string') {
|
||||
serializedBody = '';
|
||||
}
|
||||
const key = [method, responseType, mappedRequestUrl, serializedBody, encodedParams].join('|');
|
||||
const hash = generateHash(key);
|
||||
return makeStateKey(hash);
|
||||
}
|
||||
function generateHash(value) {
|
||||
let hash = 0;
|
||||
for (const char of value) {
|
||||
hash = Math.imul(31, hash) + char.charCodeAt(0) << 0;
|
||||
}
|
||||
hash += 2147483647 + 1;
|
||||
return hash.toString();
|
||||
}
|
||||
function toBase64(buffer) {
|
||||
const bytes = new Uint8Array(buffer);
|
||||
const CHUNK_SIZE = 0x8000;
|
||||
let binaryString = '';
|
||||
for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {
|
||||
const chunk = bytes.subarray(i, i + CHUNK_SIZE);
|
||||
binaryString += String.fromCharCode.apply(null, chunk);
|
||||
}
|
||||
return btoa(binaryString);
|
||||
}
|
||||
function fromBase64(base64) {
|
||||
const binary = atob(base64);
|
||||
const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
|
||||
return bytes.buffer;
|
||||
}
|
||||
function withHttpTransferCache(cacheOptions) {
|
||||
return [{
|
||||
provide: CACHE_OPTIONS,
|
||||
useFactory: () => {
|
||||
_performanceMarkFeature('NgHttpTransferCache');
|
||||
return {
|
||||
isCacheActive: true,
|
||||
...cacheOptions
|
||||
};
|
||||
}
|
||||
}, {
|
||||
provide: HTTP_ROOT_INTERCEPTOR_FNS,
|
||||
useValue: transferCacheInterceptorFn,
|
||||
multi: true
|
||||
}, {
|
||||
provide: APP_BOOTSTRAP_LISTENER,
|
||||
multi: true,
|
||||
useFactory: () => {
|
||||
const appRef = inject(ApplicationRef);
|
||||
const cacheState = inject(CACHE_OPTIONS);
|
||||
return () => {
|
||||
appRef.whenStable().then(() => {
|
||||
cacheState.isCacheActive = false;
|
||||
});
|
||||
};
|
||||
}
|
||||
}];
|
||||
}
|
||||
function appendMissingHeadersDetection(url, headers, headersToInclude) {
|
||||
const warningProduced = new Set();
|
||||
return new Proxy(headers, {
|
||||
get(target, prop) {
|
||||
const value = Reflect.get(target, prop);
|
||||
const methods = new Set(['get', 'has', 'getAll']);
|
||||
if (typeof value !== 'function' || !methods.has(prop)) {
|
||||
return value;
|
||||
}
|
||||
return headerName => {
|
||||
const key = (prop + ':' + headerName).toLowerCase();
|
||||
if (!headersToInclude.includes(headerName) && !warningProduced.has(key)) {
|
||||
warningProduced.add(key);
|
||||
const truncatedUrl = _truncateMiddle(url);
|
||||
console.warn(_formatRuntimeError(-2802, `Angular detected that the \`${headerName}\` header is accessed, but the value of the header ` + `was not transferred from the server to the client by the HttpTransferCache. ` + `To include the value of the \`${headerName}\` header for the \`${truncatedUrl}\` request, ` + `use the \`includeHeaders\` list. The \`includeHeaders\` can be defined either ` + `on a request level by adding the \`transferCache\` parameter, or on an application ` + `level by adding the \`httpCacheTransfer.includeHeaders\` argument to the ` + `\`provideClientHydration()\` call. `));
|
||||
}
|
||||
return value.apply(target, [headerName]);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
function mapRequestOriginUrl(url, originMap) {
|
||||
const origin = new URL(url, 'resolve://').origin;
|
||||
const mappedOrigin = originMap[origin];
|
||||
if (!mappedOrigin) {
|
||||
return url;
|
||||
}
|
||||
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
||||
verifyMappedOrigin(mappedOrigin);
|
||||
}
|
||||
return url.replace(origin, mappedOrigin);
|
||||
}
|
||||
function verifyMappedOrigin(url) {
|
||||
if (new URL(url, 'resolve://').pathname !== '/') {
|
||||
throw new _RuntimeError(2804, 'Angular detected a URL with a path segment in the value provided for the ' + `\`HTTP_TRANSFER_CACHE_ORIGIN_MAP\` token: ${url}. The map should only contain origins ` + 'without any other segments.');
|
||||
}
|
||||
}
|
||||
|
||||
const httpResource = (() => {
|
||||
const jsonFn = makeHttpResourceFn('json');
|
||||
jsonFn.arrayBuffer = makeHttpResourceFn('arraybuffer');
|
||||
jsonFn.blob = makeHttpResourceFn('blob');
|
||||
jsonFn.text = makeHttpResourceFn('text');
|
||||
return jsonFn;
|
||||
})();
|
||||
function makeHttpResourceFn(responseType) {
|
||||
return function httpResource(request, options) {
|
||||
if (ngDevMode && !options?.injector) {
|
||||
assertInInjectionContext(httpResource);
|
||||
}
|
||||
const injector = options?.injector ?? inject(Injector);
|
||||
const cacheOptions = injector.get(CACHE_OPTIONS, null, {
|
||||
optional: true
|
||||
});
|
||||
const transferState = injector.get(TransferState, null, {
|
||||
optional: true
|
||||
});
|
||||
const originMap = injector.get(HTTP_TRANSFER_CACHE_ORIGIN_MAP, null, {
|
||||
optional: true
|
||||
});
|
||||
const getInitialStream = req => {
|
||||
if (cacheOptions && transferState && req) {
|
||||
const cachedResponse = retrieveStateFromCache(req, cacheOptions, transferState, originMap);
|
||||
if (cachedResponse) {
|
||||
try {
|
||||
const body = cachedResponse.body;
|
||||
const parsed = options?.parse ? options.parse(body) : body;
|
||||
return signal({
|
||||
value: parsed
|
||||
});
|
||||
} catch (e) {
|
||||
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
||||
console.warn(`Angular detected an error while parsing the cached response for the httpResource at \`${req.url}\`. ` + `The resource will fall back to its default value and try again asynchronously.`, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
return new HttpResourceImpl(injector, () => normalizeRequest(request, responseType), options?.defaultValue, options?.debugName, options?.parse, options?.equal, getInitialStream);
|
||||
};
|
||||
}
|
||||
function normalizeRequest(request, responseType) {
|
||||
let unwrappedRequest = typeof request === 'function' ? request() : request;
|
||||
if (unwrappedRequest === undefined) {
|
||||
return undefined;
|
||||
} else if (typeof unwrappedRequest === 'string') {
|
||||
unwrappedRequest = {
|
||||
url: unwrappedRequest
|
||||
};
|
||||
}
|
||||
const headers = unwrappedRequest.headers instanceof HttpHeaders ? unwrappedRequest.headers : new HttpHeaders(unwrappedRequest.headers);
|
||||
const params = unwrappedRequest.params instanceof HttpParams ? unwrappedRequest.params : new HttpParams({
|
||||
fromObject: unwrappedRequest.params
|
||||
});
|
||||
return new HttpRequest(unwrappedRequest.method ?? 'GET', unwrappedRequest.url, unwrappedRequest.body ?? null, {
|
||||
headers,
|
||||
params,
|
||||
reportProgress: unwrappedRequest.reportProgress,
|
||||
withCredentials: unwrappedRequest.withCredentials,
|
||||
keepalive: unwrappedRequest.keepalive,
|
||||
cache: unwrappedRequest.cache,
|
||||
priority: unwrappedRequest.priority,
|
||||
mode: unwrappedRequest.mode,
|
||||
redirect: unwrappedRequest.redirect,
|
||||
responseType,
|
||||
context: unwrappedRequest.context,
|
||||
transferCache: unwrappedRequest.transferCache,
|
||||
credentials: unwrappedRequest.credentials,
|
||||
referrer: unwrappedRequest.referrer,
|
||||
referrerPolicy: unwrappedRequest.referrerPolicy,
|
||||
integrity: unwrappedRequest.integrity,
|
||||
timeout: unwrappedRequest.timeout
|
||||
});
|
||||
}
|
||||
class HttpResourceImpl extends _ResourceImpl {
|
||||
client;
|
||||
_headers = linkedSignal({
|
||||
...(ngDevMode ? {
|
||||
debugName: "_headers"
|
||||
} : {}),
|
||||
source: this.extRequest,
|
||||
computation: () => undefined
|
||||
});
|
||||
_progress = linkedSignal({
|
||||
...(ngDevMode ? {
|
||||
debugName: "_progress"
|
||||
} : {}),
|
||||
source: this.extRequest,
|
||||
computation: () => undefined
|
||||
});
|
||||
_statusCode = linkedSignal({
|
||||
...(ngDevMode ? {
|
||||
debugName: "_statusCode"
|
||||
} : {}),
|
||||
source: this.extRequest,
|
||||
computation: () => undefined
|
||||
});
|
||||
headers = computed(() => this.status() === 'resolved' || this.status() === 'error' ? this._headers() : undefined, ...(ngDevMode ? [{
|
||||
debugName: "headers"
|
||||
}] : []));
|
||||
progress = this._progress.asReadonly();
|
||||
statusCode = this._statusCode.asReadonly();
|
||||
constructor(injector, request, defaultValue, debugName, parse, equal, getInitialStream) {
|
||||
super(request, ({
|
||||
params: request,
|
||||
abortSignal
|
||||
}) => {
|
||||
let sub;
|
||||
const onAbort = () => sub.unsubscribe();
|
||||
abortSignal.addEventListener('abort', onAbort);
|
||||
const stream = signal({
|
||||
value: undefined
|
||||
}, ...(ngDevMode ? [{
|
||||
debugName: "stream"
|
||||
}] : []));
|
||||
let resolve;
|
||||
const promise = new Promise(r => resolve = r);
|
||||
const send = value => {
|
||||
stream.set(value);
|
||||
resolve?.(stream);
|
||||
resolve = undefined;
|
||||
};
|
||||
sub = this.client.request(request).subscribe({
|
||||
next: event => {
|
||||
switch (event.type) {
|
||||
case HttpEventType.Response:
|
||||
this._headers.set(event.headers);
|
||||
this._statusCode.set(event.status);
|
||||
try {
|
||||
send({
|
||||
value: parse ? parse(event.body) : event.body
|
||||
});
|
||||
} catch (error) {
|
||||
send({
|
||||
error: _encapsulateResourceError(error)
|
||||
});
|
||||
}
|
||||
break;
|
||||
case HttpEventType.DownloadProgress:
|
||||
this._progress.set(event);
|
||||
break;
|
||||
}
|
||||
},
|
||||
error: error => {
|
||||
if (error instanceof HttpErrorResponse) {
|
||||
this._headers.set(error.headers);
|
||||
this._statusCode.set(error.status);
|
||||
}
|
||||
send({
|
||||
error
|
||||
});
|
||||
abortSignal.removeEventListener('abort', onAbort);
|
||||
},
|
||||
complete: () => {
|
||||
if (resolve) {
|
||||
send({
|
||||
error: new _RuntimeError(991, ngDevMode && 'Resource completed before producing a value')
|
||||
});
|
||||
}
|
||||
abortSignal.removeEventListener('abort', onAbort);
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
}, defaultValue, equal, debugName, injector, getInitialStream);
|
||||
this.client = injector.get(HttpClient);
|
||||
}
|
||||
set(value) {
|
||||
super.set(value);
|
||||
this._headers.set(undefined);
|
||||
this._progress.set(undefined);
|
||||
this._statusCode.set(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
export { HTTP_TRANSFER_CACHE_ORIGIN_MAP, HttpClient, HttpErrorResponse, HttpEventType, HttpHeaders, HttpParams, HttpRequest, HttpResponse, httpResource, HTTP_ROOT_INTERCEPTOR_FNS as ɵHTTP_ROOT_INTERCEPTOR_FNS, withHttpTransferCache as ɵwithHttpTransferCache };
|
||||
//# sourceMappingURL=http.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+643
@@ -0,0 +1,643 @@
|
||||
/**
|
||||
* @license Angular v21.2.1
|
||||
* (c) 2010-2026 Google LLC. https://angular.dev/
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
import { ɵnormalizeQueryParams as _normalizeQueryParams, LocationStrategy } from '@angular/common';
|
||||
import * as i0 from '@angular/core';
|
||||
import { InjectionToken, Injectable, Inject, Optional, inject, DOCUMENT } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { PlatformNavigation, PRECOMMIT_HANDLER_SUPPORTED } from './_platform_navigation-chunk.mjs';
|
||||
import { ɵFakeNavigation as _FakeNavigation } from '@angular/core/testing';
|
||||
export { ɵFakeNavigation } from '@angular/core/testing';
|
||||
import { Location, LocationStrategy as LocationStrategy$1 } from './_location-chunk.mjs';
|
||||
import { PlatformLocation } from './_platform_location-chunk.mjs';
|
||||
|
||||
const urlParse = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
||||
function parseUrl(urlStr, baseHref) {
|
||||
const verifyProtocol = /^((http[s]?|ftp):\/\/)/;
|
||||
let serverBase;
|
||||
if (!verifyProtocol.test(urlStr)) {
|
||||
serverBase = 'http://empty.com/';
|
||||
}
|
||||
let parsedUrl;
|
||||
try {
|
||||
parsedUrl = new URL(urlStr, serverBase);
|
||||
} catch (e) {
|
||||
const result = urlParse.exec(serverBase || '' + urlStr);
|
||||
if (!result) {
|
||||
throw new Error(`Invalid URL: ${urlStr} with base: ${baseHref}`);
|
||||
}
|
||||
const hostSplit = result[4].split(':');
|
||||
parsedUrl = {
|
||||
protocol: result[1],
|
||||
hostname: hostSplit[0],
|
||||
port: hostSplit[1] || '',
|
||||
pathname: result[5],
|
||||
search: result[6],
|
||||
hash: result[8]
|
||||
};
|
||||
}
|
||||
if (parsedUrl.pathname && parsedUrl.pathname.indexOf(baseHref) === 0) {
|
||||
parsedUrl.pathname = parsedUrl.pathname.substring(baseHref.length);
|
||||
}
|
||||
return {
|
||||
hostname: !serverBase && parsedUrl.hostname || '',
|
||||
protocol: !serverBase && parsedUrl.protocol || '',
|
||||
port: !serverBase && parsedUrl.port || '',
|
||||
pathname: parsedUrl.pathname || '/',
|
||||
search: parsedUrl.search || '',
|
||||
hash: parsedUrl.hash || ''
|
||||
};
|
||||
}
|
||||
const MOCK_PLATFORM_LOCATION_CONFIG = new InjectionToken('MOCK_PLATFORM_LOCATION_CONFIG');
|
||||
class MockPlatformLocation {
|
||||
baseHref = '';
|
||||
hashUpdate = new Subject();
|
||||
popStateSubject = new Subject();
|
||||
urlChangeIndex = 0;
|
||||
urlChanges = [{
|
||||
hostname: '',
|
||||
protocol: '',
|
||||
port: '',
|
||||
pathname: '/',
|
||||
search: '',
|
||||
hash: '',
|
||||
state: null
|
||||
}];
|
||||
constructor(config) {
|
||||
if (config) {
|
||||
this.baseHref = config.appBaseHref || '';
|
||||
const parsedChanges = this.parseChanges(null, config.startUrl || 'http://_empty_/', this.baseHref);
|
||||
this.urlChanges[0] = {
|
||||
...parsedChanges
|
||||
};
|
||||
}
|
||||
}
|
||||
get hostname() {
|
||||
return this.urlChanges[this.urlChangeIndex].hostname;
|
||||
}
|
||||
get protocol() {
|
||||
return this.urlChanges[this.urlChangeIndex].protocol;
|
||||
}
|
||||
get port() {
|
||||
return this.urlChanges[this.urlChangeIndex].port;
|
||||
}
|
||||
get pathname() {
|
||||
return this.urlChanges[this.urlChangeIndex].pathname;
|
||||
}
|
||||
get search() {
|
||||
return this.urlChanges[this.urlChangeIndex].search;
|
||||
}
|
||||
get hash() {
|
||||
return this.urlChanges[this.urlChangeIndex].hash;
|
||||
}
|
||||
get state() {
|
||||
return this.urlChanges[this.urlChangeIndex].state;
|
||||
}
|
||||
getBaseHrefFromDOM() {
|
||||
return this.baseHref;
|
||||
}
|
||||
onPopState(fn) {
|
||||
const subscription = this.popStateSubject.subscribe(fn);
|
||||
return () => subscription.unsubscribe();
|
||||
}
|
||||
onHashChange(fn) {
|
||||
const subscription = this.hashUpdate.subscribe(fn);
|
||||
return () => subscription.unsubscribe();
|
||||
}
|
||||
get href() {
|
||||
let url = `${this.protocol}//${this.hostname}${this.port ? ':' + this.port : ''}`;
|
||||
url += `${this.pathname === '/' ? '' : this.pathname}${this.search}${this.hash}`;
|
||||
return url;
|
||||
}
|
||||
get url() {
|
||||
return `${this.pathname}${this.search}${this.hash}`;
|
||||
}
|
||||
parseChanges(state, url, baseHref = '') {
|
||||
state = JSON.parse(JSON.stringify(state));
|
||||
return {
|
||||
...parseUrl(url, baseHref),
|
||||
state
|
||||
};
|
||||
}
|
||||
replaceState(state, title, newUrl) {
|
||||
const {
|
||||
pathname,
|
||||
search,
|
||||
state: parsedState,
|
||||
hash
|
||||
} = this.parseChanges(state, newUrl);
|
||||
this.urlChanges[this.urlChangeIndex] = {
|
||||
...this.urlChanges[this.urlChangeIndex],
|
||||
pathname,
|
||||
search,
|
||||
hash,
|
||||
state: parsedState
|
||||
};
|
||||
}
|
||||
pushState(state, title, newUrl) {
|
||||
const {
|
||||
pathname,
|
||||
search,
|
||||
state: parsedState,
|
||||
hash
|
||||
} = this.parseChanges(state, newUrl);
|
||||
if (this.urlChangeIndex > 0) {
|
||||
this.urlChanges.splice(this.urlChangeIndex + 1);
|
||||
}
|
||||
this.urlChanges.push({
|
||||
...this.urlChanges[this.urlChangeIndex],
|
||||
pathname,
|
||||
search,
|
||||
hash,
|
||||
state: parsedState
|
||||
});
|
||||
this.urlChangeIndex = this.urlChanges.length - 1;
|
||||
}
|
||||
forward() {
|
||||
const oldUrl = this.url;
|
||||
const oldHash = this.hash;
|
||||
if (this.urlChangeIndex < this.urlChanges.length) {
|
||||
this.urlChangeIndex++;
|
||||
}
|
||||
this.emitEvents(oldHash, oldUrl);
|
||||
}
|
||||
back() {
|
||||
const oldUrl = this.url;
|
||||
const oldHash = this.hash;
|
||||
if (this.urlChangeIndex > 0) {
|
||||
this.urlChangeIndex--;
|
||||
}
|
||||
this.emitEvents(oldHash, oldUrl);
|
||||
}
|
||||
historyGo(relativePosition = 0) {
|
||||
const oldUrl = this.url;
|
||||
const oldHash = this.hash;
|
||||
const nextPageIndex = this.urlChangeIndex + relativePosition;
|
||||
if (nextPageIndex >= 0 && nextPageIndex < this.urlChanges.length) {
|
||||
this.urlChangeIndex = nextPageIndex;
|
||||
}
|
||||
this.emitEvents(oldHash, oldUrl);
|
||||
}
|
||||
getState() {
|
||||
return this.state;
|
||||
}
|
||||
emitEvents(oldHash, oldUrl) {
|
||||
this.popStateSubject.next({
|
||||
type: 'popstate',
|
||||
state: this.getState(),
|
||||
oldUrl,
|
||||
newUrl: this.url
|
||||
});
|
||||
if (oldHash !== this.hash) {
|
||||
this.hashUpdate.next({
|
||||
type: 'hashchange',
|
||||
state: null,
|
||||
oldUrl,
|
||||
newUrl: this.url
|
||||
});
|
||||
}
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: MockPlatformLocation,
|
||||
deps: [{
|
||||
token: MOCK_PLATFORM_LOCATION_CONFIG,
|
||||
optional: true
|
||||
}],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: MockPlatformLocation
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: MockPlatformLocation,
|
||||
decorators: [{
|
||||
type: Injectable
|
||||
}],
|
||||
ctorParameters: () => [{
|
||||
type: undefined,
|
||||
decorators: [{
|
||||
type: Inject,
|
||||
args: [MOCK_PLATFORM_LOCATION_CONFIG]
|
||||
}, {
|
||||
type: Optional
|
||||
}]
|
||||
}]
|
||||
});
|
||||
class FakeNavigationPlatformLocation {
|
||||
_platformNavigation;
|
||||
constructor() {
|
||||
const platformNavigation = inject(PlatformNavigation);
|
||||
if (!(platformNavigation instanceof _FakeNavigation)) {
|
||||
throw new Error('FakePlatformNavigation cannot be used without FakeNavigation. Use ' + '`provideFakeNavigation` to have all these services provided together.');
|
||||
}
|
||||
this._platformNavigation = platformNavigation;
|
||||
}
|
||||
config = inject(MOCK_PLATFORM_LOCATION_CONFIG, {
|
||||
optional: true
|
||||
});
|
||||
getBaseHrefFromDOM() {
|
||||
return this.config?.appBaseHref ?? '';
|
||||
}
|
||||
onPopState(fn) {
|
||||
this._platformNavigation.window?.addEventListener?.('popstate', fn);
|
||||
return () => this._platformNavigation.window?.removeEventListener?.('popstate', fn);
|
||||
}
|
||||
onHashChange(fn) {
|
||||
this._platformNavigation.window?.addEventListener?.('hashchange', fn);
|
||||
return () => this._platformNavigation.window?.removeEventListener?.('hashchange', fn);
|
||||
}
|
||||
get href() {
|
||||
return this._platformNavigation.currentEntry.url;
|
||||
}
|
||||
get protocol() {
|
||||
return new URL(this._platformNavigation.currentEntry.url).protocol;
|
||||
}
|
||||
get hostname() {
|
||||
return new URL(this._platformNavigation.currentEntry.url).hostname;
|
||||
}
|
||||
get port() {
|
||||
return new URL(this._platformNavigation.currentEntry.url).port;
|
||||
}
|
||||
get pathname() {
|
||||
return new URL(this._platformNavigation.currentEntry.url).pathname;
|
||||
}
|
||||
get search() {
|
||||
return new URL(this._platformNavigation.currentEntry.url).search;
|
||||
}
|
||||
get hash() {
|
||||
return new URL(this._platformNavigation.currentEntry.url).hash;
|
||||
}
|
||||
pushState(state, title, url) {
|
||||
this._platformNavigation.pushState(state, title, url);
|
||||
}
|
||||
replaceState(state, title, url) {
|
||||
this._platformNavigation.replaceState(state, title, url);
|
||||
}
|
||||
forward() {
|
||||
this._platformNavigation.forward();
|
||||
}
|
||||
back() {
|
||||
this._platformNavigation.back();
|
||||
}
|
||||
historyGo(relativePosition = 0) {
|
||||
this._platformNavigation.go(relativePosition);
|
||||
}
|
||||
getState() {
|
||||
return this._platformNavigation.currentEntry.getHistoryState();
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: FakeNavigationPlatformLocation,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: FakeNavigationPlatformLocation
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: FakeNavigationPlatformLocation,
|
||||
decorators: [{
|
||||
type: Injectable
|
||||
}],
|
||||
ctorParameters: () => []
|
||||
});
|
||||
|
||||
const FAKE_NAVIGATION = new InjectionToken('fakeNavigation', {
|
||||
factory: () => {
|
||||
const config = inject(MOCK_PLATFORM_LOCATION_CONFIG, {
|
||||
optional: true
|
||||
});
|
||||
const baseFallback = 'http://_empty_/';
|
||||
const startUrl = new URL(config?.startUrl || baseFallback, baseFallback);
|
||||
const fakeNavigation = new _FakeNavigation(inject(DOCUMENT), startUrl.href);
|
||||
fakeNavigation.setSynchronousTraversalsForTesting(true);
|
||||
return fakeNavigation;
|
||||
}
|
||||
});
|
||||
function provideFakePlatformNavigation() {
|
||||
return [{
|
||||
provide: PlatformNavigation,
|
||||
useFactory: () => inject(FAKE_NAVIGATION)
|
||||
}, {
|
||||
provide: PlatformLocation,
|
||||
useClass: FakeNavigationPlatformLocation
|
||||
}, {
|
||||
provide: PRECOMMIT_HANDLER_SUPPORTED,
|
||||
useValue: true
|
||||
}];
|
||||
}
|
||||
|
||||
class SpyLocation {
|
||||
urlChanges = [];
|
||||
_history = [new LocationState('', '', null)];
|
||||
_historyIndex = 0;
|
||||
_subject = new Subject();
|
||||
_basePath = '';
|
||||
_locationStrategy = null;
|
||||
_urlChangeListeners = [];
|
||||
_urlChangeSubscription = null;
|
||||
ngOnDestroy() {
|
||||
this._urlChangeSubscription?.unsubscribe();
|
||||
this._urlChangeListeners = [];
|
||||
}
|
||||
setInitialPath(url) {
|
||||
this._history[this._historyIndex].path = url;
|
||||
}
|
||||
setBaseHref(url) {
|
||||
this._basePath = url;
|
||||
}
|
||||
path() {
|
||||
return this._history[this._historyIndex].path;
|
||||
}
|
||||
getState() {
|
||||
return this._history[this._historyIndex].state;
|
||||
}
|
||||
isCurrentPathEqualTo(path, query = '') {
|
||||
const givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
|
||||
const currPath = this.path().endsWith('/') ? this.path().substring(0, this.path().length - 1) : this.path();
|
||||
return currPath == givenPath + (query.length > 0 ? '?' + query : '');
|
||||
}
|
||||
simulateUrlPop(pathname) {
|
||||
this._subject.next({
|
||||
'url': pathname,
|
||||
'pop': true,
|
||||
'type': 'popstate'
|
||||
});
|
||||
}
|
||||
simulateHashChange(pathname) {
|
||||
const path = this.prepareExternalUrl(pathname);
|
||||
this.pushHistory(path, '', null);
|
||||
this.urlChanges.push('hash: ' + pathname);
|
||||
this._subject.next({
|
||||
'url': pathname,
|
||||
'pop': true,
|
||||
'type': 'popstate'
|
||||
});
|
||||
this._subject.next({
|
||||
'url': pathname,
|
||||
'pop': true,
|
||||
'type': 'hashchange'
|
||||
});
|
||||
}
|
||||
prepareExternalUrl(url) {
|
||||
if (url.length > 0 && !url.startsWith('/')) {
|
||||
url = '/' + url;
|
||||
}
|
||||
return this._basePath + url;
|
||||
}
|
||||
go(path, query = '', state = null) {
|
||||
path = this.prepareExternalUrl(path);
|
||||
this.pushHistory(path, query, state);
|
||||
const locationState = this._history[this._historyIndex - 1];
|
||||
if (locationState.path == path && locationState.query == query) {
|
||||
return;
|
||||
}
|
||||
const url = path + (query.length > 0 ? '?' + query : '');
|
||||
this.urlChanges.push(url);
|
||||
this._notifyUrlChangeListeners(path + _normalizeQueryParams(query), state);
|
||||
}
|
||||
replaceState(path, query = '', state = null) {
|
||||
path = this.prepareExternalUrl(path);
|
||||
const history = this._history[this._historyIndex];
|
||||
history.state = state;
|
||||
if (history.path == path && history.query == query) {
|
||||
return;
|
||||
}
|
||||
history.path = path;
|
||||
history.query = query;
|
||||
const url = path + (query.length > 0 ? '?' + query : '');
|
||||
this.urlChanges.push('replace: ' + url);
|
||||
this._notifyUrlChangeListeners(path + _normalizeQueryParams(query), state);
|
||||
}
|
||||
forward() {
|
||||
if (this._historyIndex < this._history.length - 1) {
|
||||
this._historyIndex++;
|
||||
this._subject.next({
|
||||
'url': this.path(),
|
||||
'state': this.getState(),
|
||||
'pop': true,
|
||||
'type': 'popstate'
|
||||
});
|
||||
}
|
||||
}
|
||||
back() {
|
||||
if (this._historyIndex > 0) {
|
||||
this._historyIndex--;
|
||||
this._subject.next({
|
||||
'url': this.path(),
|
||||
'state': this.getState(),
|
||||
'pop': true,
|
||||
'type': 'popstate'
|
||||
});
|
||||
}
|
||||
}
|
||||
historyGo(relativePosition = 0) {
|
||||
const nextPageIndex = this._historyIndex + relativePosition;
|
||||
if (nextPageIndex >= 0 && nextPageIndex < this._history.length) {
|
||||
this._historyIndex = nextPageIndex;
|
||||
this._subject.next({
|
||||
'url': this.path(),
|
||||
'state': this.getState(),
|
||||
'pop': true,
|
||||
'type': 'popstate'
|
||||
});
|
||||
}
|
||||
}
|
||||
onUrlChange(fn) {
|
||||
this._urlChangeListeners.push(fn);
|
||||
this._urlChangeSubscription ??= this.subscribe(v => {
|
||||
this._notifyUrlChangeListeners(v.url, v.state);
|
||||
});
|
||||
return () => {
|
||||
const fnIndex = this._urlChangeListeners.indexOf(fn);
|
||||
this._urlChangeListeners.splice(fnIndex, 1);
|
||||
if (this._urlChangeListeners.length === 0) {
|
||||
this._urlChangeSubscription?.unsubscribe();
|
||||
this._urlChangeSubscription = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
_notifyUrlChangeListeners(url = '', state) {
|
||||
this._urlChangeListeners.forEach(fn => fn(url, state));
|
||||
}
|
||||
subscribe(onNext, onThrow, onReturn) {
|
||||
return this._subject.subscribe({
|
||||
next: onNext,
|
||||
error: onThrow ?? undefined,
|
||||
complete: onReturn ?? undefined
|
||||
});
|
||||
}
|
||||
normalize(url) {
|
||||
return null;
|
||||
}
|
||||
pushHistory(path, query, state) {
|
||||
if (this._historyIndex > 0) {
|
||||
this._history.splice(this._historyIndex + 1);
|
||||
}
|
||||
this._history.push(new LocationState(path, query, state));
|
||||
this._historyIndex = this._history.length - 1;
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: SpyLocation,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: SpyLocation
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: SpyLocation,
|
||||
decorators: [{
|
||||
type: Injectable
|
||||
}]
|
||||
});
|
||||
class LocationState {
|
||||
path;
|
||||
query;
|
||||
state;
|
||||
constructor(path, query, state) {
|
||||
this.path = path;
|
||||
this.query = query;
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
|
||||
class MockLocationStrategy extends LocationStrategy {
|
||||
internalBaseHref = '/';
|
||||
internalPath = '/';
|
||||
internalTitle = '';
|
||||
urlChanges = [];
|
||||
_subject = new Subject();
|
||||
stateChanges = [];
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
simulatePopState(url) {
|
||||
this.internalPath = url;
|
||||
this._subject.next(new _MockPopStateEvent(this.path()));
|
||||
}
|
||||
path(includeHash = false) {
|
||||
return this.internalPath;
|
||||
}
|
||||
prepareExternalUrl(internal) {
|
||||
if (internal.startsWith('/') && this.internalBaseHref.endsWith('/')) {
|
||||
return this.internalBaseHref + internal.substring(1);
|
||||
}
|
||||
return this.internalBaseHref + internal;
|
||||
}
|
||||
pushState(ctx, title, path, query) {
|
||||
this.stateChanges.push(ctx);
|
||||
this.internalTitle = title;
|
||||
const url = path + (query.length > 0 ? '?' + query : '');
|
||||
this.internalPath = url;
|
||||
const externalUrl = this.prepareExternalUrl(url);
|
||||
this.urlChanges.push(externalUrl);
|
||||
}
|
||||
replaceState(ctx, title, path, query) {
|
||||
this.stateChanges[(this.stateChanges.length || 1) - 1] = ctx;
|
||||
this.internalTitle = title;
|
||||
const url = path + (query.length > 0 ? '?' + query : '');
|
||||
this.internalPath = url;
|
||||
const externalUrl = this.prepareExternalUrl(url);
|
||||
this.urlChanges.push('replace: ' + externalUrl);
|
||||
}
|
||||
onPopState(fn) {
|
||||
this._subject.subscribe({
|
||||
next: fn
|
||||
});
|
||||
}
|
||||
getBaseHref() {
|
||||
return this.internalBaseHref;
|
||||
}
|
||||
back() {
|
||||
if (this.urlChanges.length > 0) {
|
||||
this.urlChanges.pop();
|
||||
this.stateChanges.pop();
|
||||
const nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : '';
|
||||
this.simulatePopState(nextUrl);
|
||||
}
|
||||
}
|
||||
forward() {
|
||||
throw 'not implemented';
|
||||
}
|
||||
getState() {
|
||||
return this.stateChanges[(this.stateChanges.length || 1) - 1];
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: MockLocationStrategy,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.Injectable
|
||||
});
|
||||
static ɵprov = i0.ɵɵngDeclareInjectable({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: MockLocationStrategy
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: MockLocationStrategy,
|
||||
decorators: [{
|
||||
type: Injectable
|
||||
}],
|
||||
ctorParameters: () => []
|
||||
});
|
||||
class _MockPopStateEvent {
|
||||
newUrl;
|
||||
pop = true;
|
||||
type = 'popstate';
|
||||
constructor(newUrl) {
|
||||
this.newUrl = newUrl;
|
||||
}
|
||||
}
|
||||
|
||||
function provideLocationMocks() {
|
||||
return [{
|
||||
provide: Location,
|
||||
useClass: SpyLocation
|
||||
}, {
|
||||
provide: LocationStrategy$1,
|
||||
useClass: MockLocationStrategy
|
||||
}];
|
||||
}
|
||||
|
||||
export { MOCK_PLATFORM_LOCATION_CONFIG, MockLocationStrategy, MockPlatformLocation, SpyLocation, provideLocationMocks, FakeNavigationPlatformLocation as ɵFakeNavigationPlatformLocation, provideFakePlatformNavigation as ɵprovideFakePlatformNavigation };
|
||||
//# sourceMappingURL=testing.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+666
@@ -0,0 +1,666 @@
|
||||
/**
|
||||
* @license Angular v21.2.1
|
||||
* (c) 2010-2026 Google LLC. https://angular.dev/
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
import * as i0 from '@angular/core';
|
||||
import { ɵisPromise as _isPromise, InjectionToken, NgModule, inject } from '@angular/core';
|
||||
import { ReplaySubject } from 'rxjs';
|
||||
import { UpgradeModule } from '@angular/upgrade/static';
|
||||
import { CommonModule, HashLocationStrategy } from './_common_module-chunk.mjs';
|
||||
import { Location, LocationStrategy, APP_BASE_HREF, PathLocationStrategy } from './_location-chunk.mjs';
|
||||
import { PlatformLocation } from './_platform_location-chunk.mjs';
|
||||
|
||||
function deepEqual(a, b) {
|
||||
if (a === b) {
|
||||
return true;
|
||||
} else if (!a || !b) {
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
if (a.prototype !== b.prototype || Array.isArray(a) && Array.isArray(b)) {
|
||||
return false;
|
||||
}
|
||||
return JSON.stringify(a) === JSON.stringify(b);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
function isAnchor(el) {
|
||||
return el.href !== undefined;
|
||||
}
|
||||
|
||||
const PATH_MATCH = /^([^?#]*)(\?([^#]*))?(#(.*))?$/;
|
||||
const DOUBLE_SLASH_REGEX = /^\s*[\\/]{2,}/;
|
||||
const IGNORE_URI_REGEXP = /^\s*(javascript|mailto):/i;
|
||||
const DEFAULT_PORTS = {
|
||||
'http:': 80,
|
||||
'https:': 443,
|
||||
'ftp:': 21
|
||||
};
|
||||
class $locationShim {
|
||||
location;
|
||||
platformLocation;
|
||||
urlCodec;
|
||||
locationStrategy;
|
||||
initializing = true;
|
||||
updateBrowser = false;
|
||||
$$absUrl = '';
|
||||
$$url = '';
|
||||
$$protocol;
|
||||
$$host = '';
|
||||
$$port;
|
||||
$$replace = false;
|
||||
$$path = '';
|
||||
$$search = '';
|
||||
$$hash = '';
|
||||
$$state;
|
||||
$$changeListeners = [];
|
||||
cachedState = null;
|
||||
urlChanges = new ReplaySubject(1);
|
||||
removeOnUrlChangeFn;
|
||||
constructor($injector, location, platformLocation, urlCodec, locationStrategy) {
|
||||
this.location = location;
|
||||
this.platformLocation = platformLocation;
|
||||
this.urlCodec = urlCodec;
|
||||
this.locationStrategy = locationStrategy;
|
||||
const initialUrl = this.browserUrl();
|
||||
let parsedUrl = this.urlCodec.parse(initialUrl);
|
||||
if (typeof parsedUrl === 'string') {
|
||||
throw 'Invalid URL';
|
||||
}
|
||||
this.$$protocol = parsedUrl.protocol;
|
||||
this.$$host = parsedUrl.hostname;
|
||||
this.$$port = parseInt(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null;
|
||||
this.$$parseLinkUrl(initialUrl, initialUrl);
|
||||
this.cacheState();
|
||||
this.$$state = this.browserState();
|
||||
this.removeOnUrlChangeFn = this.location.onUrlChange((newUrl, newState) => {
|
||||
this.urlChanges.next({
|
||||
newUrl,
|
||||
newState
|
||||
});
|
||||
});
|
||||
if (_isPromise($injector)) {
|
||||
$injector.then($i => this.initialize($i));
|
||||
} else {
|
||||
this.initialize($injector);
|
||||
}
|
||||
}
|
||||
initialize($injector) {
|
||||
const $rootScope = $injector.get('$rootScope');
|
||||
const $rootElement = $injector.get('$rootElement');
|
||||
$rootElement.on('click', event => {
|
||||
if (event.ctrlKey || event.metaKey || event.shiftKey || event.which === 2 || event.button === 2) {
|
||||
return;
|
||||
}
|
||||
let elm = event.target;
|
||||
while (elm && elm.nodeName.toLowerCase() !== 'a') {
|
||||
if (elm === $rootElement[0] || !(elm = elm.parentNode)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!isAnchor(elm)) {
|
||||
return;
|
||||
}
|
||||
const absHref = elm.href;
|
||||
const relHref = elm.getAttribute('href');
|
||||
if (IGNORE_URI_REGEXP.test(absHref)) {
|
||||
return;
|
||||
}
|
||||
if (absHref && !elm.getAttribute('target') && !event.isDefaultPrevented()) {
|
||||
if (this.$$parseLinkUrl(absHref, relHref)) {
|
||||
event.preventDefault();
|
||||
if (this.absUrl() !== this.browserUrl()) {
|
||||
$rootScope.$apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.urlChanges.subscribe(({
|
||||
newUrl,
|
||||
newState
|
||||
}) => {
|
||||
const oldUrl = this.absUrl();
|
||||
const oldState = this.$$state;
|
||||
this.$$parse(newUrl);
|
||||
newUrl = this.absUrl();
|
||||
this.$$state = newState;
|
||||
const defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl, newState, oldState).defaultPrevented;
|
||||
if (this.absUrl() !== newUrl) return;
|
||||
if (defaultPrevented) {
|
||||
this.$$parse(oldUrl);
|
||||
this.state(oldState);
|
||||
this.setBrowserUrlWithFallback(oldUrl, false, oldState);
|
||||
this.$$notifyChangeListeners(this.url(), this.$$state, oldUrl, oldState);
|
||||
} else {
|
||||
this.initializing = false;
|
||||
$rootScope.$broadcast('$locationChangeSuccess', newUrl, oldUrl, newState, oldState);
|
||||
this.resetBrowserUpdate();
|
||||
}
|
||||
if (!$rootScope.$$phase) {
|
||||
$rootScope.$digest();
|
||||
}
|
||||
});
|
||||
$rootScope.$watch(() => {
|
||||
if (this.initializing || this.updateBrowser) {
|
||||
this.updateBrowser = false;
|
||||
const oldUrl = this.browserUrl();
|
||||
const newUrl = this.absUrl();
|
||||
const oldState = this.browserState();
|
||||
let currentReplace = this.$$replace;
|
||||
const urlOrStateChanged = !this.urlCodec.areEqual(oldUrl, newUrl) || oldState !== this.$$state;
|
||||
if (this.initializing || urlOrStateChanged) {
|
||||
this.initializing = false;
|
||||
$rootScope.$evalAsync(() => {
|
||||
const newUrl = this.absUrl();
|
||||
const defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl, this.$$state, oldState).defaultPrevented;
|
||||
if (this.absUrl() !== newUrl) return;
|
||||
if (defaultPrevented) {
|
||||
this.$$parse(oldUrl);
|
||||
this.$$state = oldState;
|
||||
} else {
|
||||
if (urlOrStateChanged) {
|
||||
this.setBrowserUrlWithFallback(newUrl, currentReplace, oldState === this.$$state ? null : this.$$state);
|
||||
this.$$replace = false;
|
||||
}
|
||||
$rootScope.$broadcast('$locationChangeSuccess', newUrl, oldUrl, this.$$state, oldState);
|
||||
if (urlOrStateChanged) {
|
||||
this.$$notifyChangeListeners(this.url(), this.$$state, oldUrl, oldState);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
this.$$replace = false;
|
||||
});
|
||||
$rootScope.$on('$destroy', () => {
|
||||
this.removeOnUrlChangeFn();
|
||||
this.urlChanges.complete();
|
||||
});
|
||||
}
|
||||
resetBrowserUpdate() {
|
||||
this.$$replace = false;
|
||||
this.$$state = this.browserState();
|
||||
this.updateBrowser = false;
|
||||
this.lastBrowserUrl = this.browserUrl();
|
||||
}
|
||||
lastHistoryState;
|
||||
lastBrowserUrl = '';
|
||||
browserUrl(url, replace, state) {
|
||||
if (typeof state === 'undefined') {
|
||||
state = null;
|
||||
}
|
||||
if (url) {
|
||||
let sameState = this.lastHistoryState === state;
|
||||
url = this.urlCodec.parse(url).href;
|
||||
if (this.lastBrowserUrl === url && sameState) {
|
||||
return this;
|
||||
}
|
||||
this.lastBrowserUrl = url;
|
||||
this.lastHistoryState = state;
|
||||
url = this.stripBaseUrl(this.getServerBase(), url) || url;
|
||||
if (replace) {
|
||||
this.locationStrategy.replaceState(state, '', url, '');
|
||||
} else {
|
||||
this.locationStrategy.pushState(state, '', url, '');
|
||||
}
|
||||
this.cacheState();
|
||||
return this;
|
||||
} else {
|
||||
return this.platformLocation.href;
|
||||
}
|
||||
}
|
||||
lastCachedState = null;
|
||||
cacheState() {
|
||||
this.cachedState = this.platformLocation.getState();
|
||||
if (typeof this.cachedState === 'undefined') {
|
||||
this.cachedState = null;
|
||||
}
|
||||
if (deepEqual(this.cachedState, this.lastCachedState)) {
|
||||
this.cachedState = this.lastCachedState;
|
||||
}
|
||||
this.lastCachedState = this.cachedState;
|
||||
this.lastHistoryState = this.cachedState;
|
||||
}
|
||||
browserState() {
|
||||
return this.cachedState;
|
||||
}
|
||||
stripBaseUrl(base, url) {
|
||||
if (url.startsWith(base)) {
|
||||
return url.slice(base.length);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
getServerBase() {
|
||||
const {
|
||||
protocol,
|
||||
hostname,
|
||||
port
|
||||
} = this.platformLocation;
|
||||
const baseHref = this.locationStrategy.getBaseHref();
|
||||
let url = `${protocol}//${hostname}${port ? ':' + port : ''}${baseHref || '/'}`;
|
||||
return url.endsWith('/') ? url : url + '/';
|
||||
}
|
||||
parseAppUrl(url) {
|
||||
if (DOUBLE_SLASH_REGEX.test(url)) {
|
||||
throw new Error(`Bad Path - URL cannot start with double slashes: ${url}`);
|
||||
}
|
||||
let prefixed = url.charAt(0) !== '/';
|
||||
if (prefixed) {
|
||||
url = '/' + url;
|
||||
}
|
||||
let match = this.urlCodec.parse(url, this.getServerBase());
|
||||
if (typeof match === 'string') {
|
||||
throw new Error(`Bad URL - Cannot parse URL: ${url}`);
|
||||
}
|
||||
let path = prefixed && match.pathname.charAt(0) === '/' ? match.pathname.substring(1) : match.pathname;
|
||||
this.$$path = this.urlCodec.decodePath(path);
|
||||
this.$$search = this.urlCodec.decodeSearch(match.search);
|
||||
this.$$hash = this.urlCodec.decodeHash(match.hash);
|
||||
if (this.$$path && this.$$path.charAt(0) !== '/') {
|
||||
this.$$path = '/' + this.$$path;
|
||||
}
|
||||
}
|
||||
onChange(fn, err = e => {}) {
|
||||
this.$$changeListeners.push([fn, err]);
|
||||
}
|
||||
$$notifyChangeListeners(url = '', state, oldUrl = '', oldState) {
|
||||
this.$$changeListeners.forEach(([fn, err]) => {
|
||||
try {
|
||||
fn(url, state, oldUrl, oldState);
|
||||
} catch (e) {
|
||||
err(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
$$parse(url) {
|
||||
let pathUrl;
|
||||
if (url.startsWith('/')) {
|
||||
pathUrl = url;
|
||||
} else {
|
||||
pathUrl = this.stripBaseUrl(this.getServerBase(), url);
|
||||
}
|
||||
if (typeof pathUrl === 'undefined') {
|
||||
throw new Error(`Invalid url "${url}", missing path prefix "${this.getServerBase()}".`);
|
||||
}
|
||||
this.parseAppUrl(pathUrl);
|
||||
this.$$path ||= '/';
|
||||
this.composeUrls();
|
||||
}
|
||||
$$parseLinkUrl(url, relHref) {
|
||||
if (relHref && relHref[0] === '#') {
|
||||
this.hash(relHref.slice(1));
|
||||
return true;
|
||||
}
|
||||
let rewrittenUrl;
|
||||
let appUrl = this.stripBaseUrl(this.getServerBase(), url);
|
||||
if (typeof appUrl !== 'undefined') {
|
||||
rewrittenUrl = this.getServerBase() + appUrl;
|
||||
} else if (this.getServerBase() === url + '/') {
|
||||
rewrittenUrl = this.getServerBase();
|
||||
}
|
||||
if (rewrittenUrl) {
|
||||
this.$$parse(rewrittenUrl);
|
||||
}
|
||||
return !!rewrittenUrl;
|
||||
}
|
||||
setBrowserUrlWithFallback(url, replace, state) {
|
||||
const oldUrl = this.url();
|
||||
const oldState = this.$$state;
|
||||
try {
|
||||
this.browserUrl(url, replace, state);
|
||||
this.$$state = this.browserState();
|
||||
} catch (e) {
|
||||
this.url(oldUrl);
|
||||
this.$$state = oldState;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
composeUrls() {
|
||||
this.$$url = this.urlCodec.normalize(this.$$path, this.$$search, this.$$hash);
|
||||
this.$$absUrl = this.getServerBase() + this.$$url.slice(1);
|
||||
this.updateBrowser = true;
|
||||
}
|
||||
absUrl() {
|
||||
return this.$$absUrl;
|
||||
}
|
||||
url(url) {
|
||||
if (typeof url === 'string') {
|
||||
if (!url.length) {
|
||||
url = '/';
|
||||
}
|
||||
const match = PATH_MATCH.exec(url);
|
||||
if (!match) return this;
|
||||
if (match[1] || url === '') this.path(this.urlCodec.decodePath(match[1]));
|
||||
if (match[2] || match[1] || url === '') this.search(match[3] || '');
|
||||
this.hash(match[5] || '');
|
||||
return this;
|
||||
}
|
||||
return this.$$url;
|
||||
}
|
||||
protocol() {
|
||||
return this.$$protocol;
|
||||
}
|
||||
host() {
|
||||
return this.$$host;
|
||||
}
|
||||
port() {
|
||||
return this.$$port;
|
||||
}
|
||||
path(path) {
|
||||
if (typeof path === 'undefined') {
|
||||
return this.$$path;
|
||||
}
|
||||
path = path !== null ? path.toString() : '';
|
||||
path = path.charAt(0) === '/' ? path : '/' + path;
|
||||
this.$$path = path;
|
||||
this.composeUrls();
|
||||
return this;
|
||||
}
|
||||
search(search, paramValue) {
|
||||
switch (arguments.length) {
|
||||
case 0:
|
||||
return this.$$search;
|
||||
case 1:
|
||||
if (typeof search === 'string' || typeof search === 'number') {
|
||||
this.$$search = this.urlCodec.decodeSearch(search.toString());
|
||||
} else if (typeof search === 'object' && search !== null) {
|
||||
search = {
|
||||
...search
|
||||
};
|
||||
for (const key in search) {
|
||||
if (search[key] == null) delete search[key];
|
||||
}
|
||||
this.$$search = search;
|
||||
} else {
|
||||
throw new Error('LocationProvider.search(): First argument must be a string or an object.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (typeof search === 'string') {
|
||||
const currentSearch = this.search();
|
||||
if (typeof paramValue === 'undefined' || paramValue === null) {
|
||||
delete currentSearch[search];
|
||||
return this.search(currentSearch);
|
||||
} else {
|
||||
currentSearch[search] = paramValue;
|
||||
return this.search(currentSearch);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.composeUrls();
|
||||
return this;
|
||||
}
|
||||
hash(hash) {
|
||||
if (typeof hash === 'undefined') {
|
||||
return this.$$hash;
|
||||
}
|
||||
this.$$hash = hash !== null ? hash.toString() : '';
|
||||
this.composeUrls();
|
||||
return this;
|
||||
}
|
||||
replace() {
|
||||
this.$$replace = true;
|
||||
return this;
|
||||
}
|
||||
state(state) {
|
||||
if (typeof state === 'undefined') {
|
||||
return this.$$state;
|
||||
}
|
||||
this.$$state = state;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class $locationShimProvider {
|
||||
ngUpgrade;
|
||||
location;
|
||||
platformLocation;
|
||||
urlCodec;
|
||||
locationStrategy;
|
||||
constructor(ngUpgrade, location, platformLocation, urlCodec, locationStrategy) {
|
||||
this.ngUpgrade = ngUpgrade;
|
||||
this.location = location;
|
||||
this.platformLocation = platformLocation;
|
||||
this.urlCodec = urlCodec;
|
||||
this.locationStrategy = locationStrategy;
|
||||
}
|
||||
$get() {
|
||||
return new $locationShim(this.ngUpgrade.$injector, this.location, this.platformLocation, this.urlCodec, this.locationStrategy);
|
||||
}
|
||||
hashPrefix(prefix) {
|
||||
throw new Error('Configure LocationUpgrade through LocationUpgradeModule.config method.');
|
||||
}
|
||||
html5Mode(mode) {
|
||||
throw new Error('Configure LocationUpgrade through LocationUpgradeModule.config method.');
|
||||
}
|
||||
}
|
||||
|
||||
class UrlCodec {}
|
||||
class AngularJSUrlCodec {
|
||||
encodePath(path) {
|
||||
const segments = path.split('/');
|
||||
let i = segments.length;
|
||||
while (i--) {
|
||||
segments[i] = encodeUriSegment(segments[i].replace(/%2F/g, '/'));
|
||||
}
|
||||
path = segments.join('/');
|
||||
return _stripIndexHtml((path && path[0] !== '/' && '/' || '') + path);
|
||||
}
|
||||
encodeSearch(search) {
|
||||
if (typeof search === 'string') {
|
||||
search = parseKeyValue(search);
|
||||
}
|
||||
search = toKeyValue(search);
|
||||
return search ? '?' + search : '';
|
||||
}
|
||||
encodeHash(hash) {
|
||||
hash = encodeUriSegment(hash);
|
||||
return hash ? '#' + hash : '';
|
||||
}
|
||||
decodePath(path, html5Mode = true) {
|
||||
const segments = path.split('/');
|
||||
let i = segments.length;
|
||||
while (i--) {
|
||||
segments[i] = decodeURIComponent(segments[i]);
|
||||
if (html5Mode) {
|
||||
segments[i] = segments[i].replace(/\//g, '%2F');
|
||||
}
|
||||
}
|
||||
return segments.join('/');
|
||||
}
|
||||
decodeSearch(search) {
|
||||
return parseKeyValue(search);
|
||||
}
|
||||
decodeHash(hash) {
|
||||
hash = decodeURIComponent(hash);
|
||||
return hash[0] === '#' ? hash.substring(1) : hash;
|
||||
}
|
||||
normalize(pathOrHref, search, hash, baseUrl) {
|
||||
if (arguments.length === 1) {
|
||||
const parsed = this.parse(pathOrHref, baseUrl);
|
||||
if (typeof parsed === 'string') {
|
||||
return parsed;
|
||||
}
|
||||
const serverUrl = `${parsed.protocol}://${parsed.hostname}${parsed.port ? ':' + parsed.port : ''}`;
|
||||
return this.normalize(this.decodePath(parsed.pathname), this.decodeSearch(parsed.search), this.decodeHash(parsed.hash), serverUrl);
|
||||
} else {
|
||||
const encPath = this.encodePath(pathOrHref);
|
||||
const encSearch = search && this.encodeSearch(search) || '';
|
||||
const encHash = hash && this.encodeHash(hash) || '';
|
||||
let joinedPath = (baseUrl || '') + encPath;
|
||||
if (!joinedPath.length || joinedPath[0] !== '/') {
|
||||
joinedPath = '/' + joinedPath;
|
||||
}
|
||||
return joinedPath + encSearch + encHash;
|
||||
}
|
||||
}
|
||||
areEqual(valA, valB) {
|
||||
return this.normalize(valA) === this.normalize(valB);
|
||||
}
|
||||
parse(url, base) {
|
||||
try {
|
||||
const parsed = !base ? new URL(url) : new URL(url, base);
|
||||
return {
|
||||
href: parsed.href,
|
||||
protocol: parsed.protocol ? parsed.protocol.replace(/:$/, '') : '',
|
||||
host: parsed.host,
|
||||
search: parsed.search ? parsed.search.replace(/^\?/, '') : '',
|
||||
hash: parsed.hash ? parsed.hash.replace(/^#/, '') : '',
|
||||
hostname: parsed.hostname,
|
||||
port: parsed.port,
|
||||
pathname: parsed.pathname.charAt(0) === '/' ? parsed.pathname : '/' + parsed.pathname
|
||||
};
|
||||
} catch (e) {
|
||||
throw new Error(`Invalid URL (${url}) with base (${base})`);
|
||||
}
|
||||
}
|
||||
}
|
||||
function _stripIndexHtml(url) {
|
||||
return url.replace(/\/index.html$/, '');
|
||||
}
|
||||
function tryDecodeURIComponent(value) {
|
||||
try {
|
||||
return decodeURIComponent(value);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
function parseKeyValue(keyValue) {
|
||||
const obj = {};
|
||||
(keyValue || '').split('&').forEach(keyValue => {
|
||||
let splitPoint, key, val;
|
||||
if (keyValue) {
|
||||
key = keyValue = keyValue.replace(/\+/g, '%20');
|
||||
splitPoint = keyValue.indexOf('=');
|
||||
if (splitPoint !== -1) {
|
||||
key = keyValue.substring(0, splitPoint);
|
||||
val = keyValue.substring(splitPoint + 1);
|
||||
}
|
||||
key = tryDecodeURIComponent(key);
|
||||
if (typeof key !== 'undefined') {
|
||||
val = typeof val !== 'undefined' ? tryDecodeURIComponent(val) : true;
|
||||
if (!obj.hasOwnProperty(key)) {
|
||||
obj[key] = val;
|
||||
} else if (Array.isArray(obj[key])) {
|
||||
obj[key].push(val);
|
||||
} else {
|
||||
obj[key] = [obj[key], val];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
function toKeyValue(obj) {
|
||||
const parts = [];
|
||||
for (const key in obj) {
|
||||
let value = obj[key];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(arrayValue => {
|
||||
parts.push(encodeUriQuery(key, true) + (arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
|
||||
});
|
||||
} else {
|
||||
parts.push(encodeUriQuery(key, true) + (value === true ? '' : '=' + encodeUriQuery(value, true)));
|
||||
}
|
||||
}
|
||||
return parts.length ? parts.join('&') : '';
|
||||
}
|
||||
function encodeUriSegment(val) {
|
||||
return encodeUriQuery(val, true).replace(/%26/g, '&').replace(/%3D/gi, '=').replace(/%2B/gi, '+');
|
||||
}
|
||||
function encodeUriQuery(val, pctEncodeSpaces = false) {
|
||||
return encodeURIComponent(val).replace(/%40/g, '@').replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%3B/gi, ';').replace(/%20/g, pctEncodeSpaces ? '%20' : '+');
|
||||
}
|
||||
|
||||
const LOCATION_UPGRADE_CONFIGURATION = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'LOCATION_UPGRADE_CONFIGURATION' : '');
|
||||
const APP_BASE_HREF_RESOLVED = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'APP_BASE_HREF_RESOLVED' : '');
|
||||
class LocationUpgradeModule {
|
||||
static config(config) {
|
||||
return {
|
||||
ngModule: LocationUpgradeModule,
|
||||
providers: [Location, {
|
||||
provide: $locationShim,
|
||||
useFactory: provide$location
|
||||
}, {
|
||||
provide: LOCATION_UPGRADE_CONFIGURATION,
|
||||
useValue: config ? config : {}
|
||||
}, {
|
||||
provide: UrlCodec,
|
||||
useFactory: provideUrlCodec
|
||||
}, {
|
||||
provide: APP_BASE_HREF_RESOLVED,
|
||||
useFactory: provideAppBaseHref
|
||||
}, {
|
||||
provide: LocationStrategy,
|
||||
useFactory: provideLocationStrategy
|
||||
}]
|
||||
};
|
||||
}
|
||||
static ɵfac = i0.ɵɵngDeclareFactory({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: LocationUpgradeModule,
|
||||
deps: [],
|
||||
target: i0.ɵɵFactoryTarget.NgModule
|
||||
});
|
||||
static ɵmod = i0.ɵɵngDeclareNgModule({
|
||||
minVersion: "14.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: LocationUpgradeModule,
|
||||
imports: [CommonModule]
|
||||
});
|
||||
static ɵinj = i0.ɵɵngDeclareInjector({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: LocationUpgradeModule,
|
||||
imports: [CommonModule]
|
||||
});
|
||||
}
|
||||
i0.ɵɵngDeclareClassMetadata({
|
||||
minVersion: "12.0.0",
|
||||
version: "21.2.1",
|
||||
ngImport: i0,
|
||||
type: LocationUpgradeModule,
|
||||
decorators: [{
|
||||
type: NgModule,
|
||||
args: [{
|
||||
imports: [CommonModule]
|
||||
}]
|
||||
}]
|
||||
});
|
||||
function provideAppBaseHref() {
|
||||
const config = inject(LOCATION_UPGRADE_CONFIGURATION);
|
||||
const appBaseHref = inject(APP_BASE_HREF, {
|
||||
optional: true
|
||||
});
|
||||
if (config && config.appBaseHref != null) {
|
||||
return config.appBaseHref;
|
||||
} else if (appBaseHref != null) {
|
||||
return appBaseHref;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function provideUrlCodec() {
|
||||
const config = inject(LOCATION_UPGRADE_CONFIGURATION);
|
||||
const codec = config && config.urlCodec || AngularJSUrlCodec;
|
||||
return new codec();
|
||||
}
|
||||
function provideLocationStrategy() {
|
||||
const platformLocation = inject(PlatformLocation);
|
||||
const baseHref = inject(APP_BASE_HREF_RESOLVED);
|
||||
const options = inject(LOCATION_UPGRADE_CONFIGURATION);
|
||||
return options.useHash ? new HashLocationStrategy(platformLocation, baseHref) : new PathLocationStrategy(platformLocation, baseHref);
|
||||
}
|
||||
function provide$location() {
|
||||
const $locationProvider = new $locationShimProvider(inject(UpgradeModule), inject(Location), inject(PlatformLocation), inject(UrlCodec), inject(LocationStrategy));
|
||||
return $locationProvider.$get();
|
||||
}
|
||||
|
||||
export { $locationShim, $locationShimProvider, AngularJSUrlCodec, LOCATION_UPGRADE_CONFIGURATION, LocationUpgradeModule, UrlCodec };
|
||||
//# sourceMappingURL=upgrade.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user