index.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /**
  2. * @license Angular v19.2.13
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { Location, LocationStrategy, CommonModule } from '../common_module.d-NEF7UaHr.js';
  7. import { PlatformLocation } from '../platform_location.d-Lbv6Ueec.js';
  8. import { UpgradeModule } from '@angular/upgrade/static';
  9. import * as i0 from '@angular/core';
  10. import { InjectionToken, ModuleWithProviders } from '@angular/core';
  11. import 'rxjs';
  12. /**
  13. * A codec for encoding and decoding URL parts.
  14. *
  15. * @publicApi
  16. **/
  17. declare abstract class UrlCodec {
  18. /**
  19. * Encodes the path from the provided string
  20. *
  21. * @param path The path string
  22. */
  23. abstract encodePath(path: string): string;
  24. /**
  25. * Decodes the path from the provided string
  26. *
  27. * @param path The path string
  28. */
  29. abstract decodePath(path: string): string;
  30. /**
  31. * Encodes the search string from the provided string or object
  32. *
  33. * @param path The path string or object
  34. */
  35. abstract encodeSearch(search: string | {
  36. [k: string]: unknown;
  37. }): string;
  38. /**
  39. * Decodes the search objects from the provided string
  40. *
  41. * @param path The path string
  42. */
  43. abstract decodeSearch(search: string): {
  44. [k: string]: unknown;
  45. };
  46. /**
  47. * Encodes the hash from the provided string
  48. *
  49. * @param path The hash string
  50. */
  51. abstract encodeHash(hash: string): string;
  52. /**
  53. * Decodes the hash from the provided string
  54. *
  55. * @param path The hash string
  56. */
  57. abstract decodeHash(hash: string): string;
  58. /**
  59. * Normalizes the URL from the provided string
  60. *
  61. * @param path The URL string
  62. */
  63. abstract normalize(href: string): string;
  64. /**
  65. * Normalizes the URL from the provided string, search, hash, and base URL parameters
  66. *
  67. * @param path The URL path
  68. * @param search The search object
  69. * @param hash The has string
  70. * @param baseUrl The base URL for the URL
  71. */
  72. abstract normalize(path: string, search: {
  73. [k: string]: unknown;
  74. }, hash: string, baseUrl?: string): string;
  75. /**
  76. * Checks whether the two strings are equal
  77. * @param valA First string for comparison
  78. * @param valB Second string for comparison
  79. */
  80. abstract areEqual(valA: string, valB: string): boolean;
  81. /**
  82. * Parses the URL string based on the base URL
  83. *
  84. * @param url The full URL string
  85. * @param base The base for the URL
  86. */
  87. abstract parse(url: string, base?: string): {
  88. href: string;
  89. protocol: string;
  90. host: string;
  91. search: string;
  92. hash: string;
  93. hostname: string;
  94. port: string;
  95. pathname: string;
  96. };
  97. }
  98. /**
  99. * A `UrlCodec` that uses logic from AngularJS to serialize and parse URLs
  100. * and URL parameters.
  101. *
  102. * @publicApi
  103. */
  104. declare class AngularJSUrlCodec implements UrlCodec {
  105. encodePath(path: string): string;
  106. encodeSearch(search: string | {
  107. [k: string]: unknown;
  108. }): string;
  109. encodeHash(hash: string): string;
  110. decodePath(path: string, html5Mode?: boolean): string;
  111. decodeSearch(search: string): {
  112. [k: string]: unknown;
  113. };
  114. decodeHash(hash: string): string;
  115. normalize(href: string): string;
  116. normalize(path: string, search: {
  117. [k: string]: unknown;
  118. }, hash: string, baseUrl?: string): string;
  119. areEqual(valA: string, valB: string): boolean;
  120. parse(url: string, base?: string): {
  121. href: string;
  122. protocol: string;
  123. host: string;
  124. search: string;
  125. hash: string;
  126. hostname: string;
  127. port: string;
  128. pathname: string;
  129. };
  130. }
  131. /**
  132. * Location service that provides a drop-in replacement for the $location service
  133. * provided in AngularJS.
  134. *
  135. * @see [Using the Angular Unified Location Service](guide/upgrade#using-the-unified-angular-location-service)
  136. *
  137. * @publicApi
  138. */
  139. declare class $locationShim {
  140. private location;
  141. private platformLocation;
  142. private urlCodec;
  143. private locationStrategy;
  144. private initializing;
  145. private updateBrowser;
  146. private $$absUrl;
  147. private $$url;
  148. private $$protocol;
  149. private $$host;
  150. private $$port;
  151. private $$replace;
  152. private $$path;
  153. private $$search;
  154. private $$hash;
  155. private $$state;
  156. private $$changeListeners;
  157. private cachedState;
  158. private urlChanges;
  159. private readonly removeOnUrlChangeFn;
  160. constructor($injector: any, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy);
  161. private initialize;
  162. private resetBrowserUpdate;
  163. private lastHistoryState;
  164. private lastBrowserUrl;
  165. private browserUrl;
  166. private lastCachedState;
  167. private cacheState;
  168. /**
  169. * This function emulates the $browser.state() function from AngularJS. It will cause
  170. * history.state to be cached unless changed with deep equality check.
  171. */
  172. private browserState;
  173. private stripBaseUrl;
  174. private getServerBase;
  175. private parseAppUrl;
  176. /**
  177. * Registers listeners for URL changes. This API is used to catch updates performed by the
  178. * AngularJS framework. These changes are a subset of the `$locationChangeStart` and
  179. * `$locationChangeSuccess` events which fire when AngularJS updates its internally-referenced
  180. * version of the browser URL.
  181. *
  182. * It's possible for `$locationChange` events to happen, but for the browser URL
  183. * (window.location) to remain unchanged. This `onChange` callback will fire only when AngularJS
  184. * actually updates the browser URL (window.location).
  185. *
  186. * @param fn The callback function that is triggered for the listener when the URL changes.
  187. * @param err The callback function that is triggered when an error occurs.
  188. */
  189. onChange(fn: (url: string, state: unknown, oldUrl: string, oldState: unknown) => void, err?: (e: Error) => void): void;
  190. /**
  191. * Parses the provided URL, and sets the current URL to the parsed result.
  192. *
  193. * @param url The URL string.
  194. */
  195. $$parse(url: string): void;
  196. /**
  197. * Parses the provided URL and its relative URL.
  198. *
  199. * @param url The full URL string.
  200. * @param relHref A URL string relative to the full URL string.
  201. */
  202. $$parseLinkUrl(url: string, relHref?: string | null): boolean;
  203. private setBrowserUrlWithFallback;
  204. private composeUrls;
  205. /**
  206. * Retrieves the full URL representation with all segments encoded according to
  207. * rules specified in
  208. * [RFC 3986](https://tools.ietf.org/html/rfc3986).
  209. *
  210. *
  211. * ```js
  212. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  213. * let absUrl = $location.absUrl();
  214. * // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
  215. * ```
  216. */
  217. absUrl(): string;
  218. /**
  219. * Retrieves the current URL, or sets a new URL. When setting a URL,
  220. * changes the path, search, and hash, and returns a reference to its own instance.
  221. *
  222. * ```js
  223. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  224. * let url = $location.url();
  225. * // => "/some/path?foo=bar&baz=xoxo"
  226. * ```
  227. */
  228. url(): string;
  229. url(url: string): this;
  230. /**
  231. * Retrieves the protocol of the current URL.
  232. *
  233. * ```js
  234. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  235. * let protocol = $location.protocol();
  236. * // => "http"
  237. * ```
  238. */
  239. protocol(): string;
  240. /**
  241. * Retrieves the protocol of the current URL.
  242. *
  243. * In contrast to the non-AngularJS version `location.host` which returns `hostname:port`, this
  244. * returns the `hostname` portion only.
  245. *
  246. *
  247. * ```js
  248. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  249. * let host = $location.host();
  250. * // => "example.com"
  251. *
  252. * // given URL http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxo
  253. * host = $location.host();
  254. * // => "example.com"
  255. * host = location.host;
  256. * // => "example.com:8080"
  257. * ```
  258. */
  259. host(): string;
  260. /**
  261. * Retrieves the port of the current URL.
  262. *
  263. * ```js
  264. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  265. * let port = $location.port();
  266. * // => 80
  267. * ```
  268. */
  269. port(): number | null;
  270. /**
  271. * Retrieves the path of the current URL, or changes the path and returns a reference to its own
  272. * instance.
  273. *
  274. * Paths should always begin with forward slash (/). This method adds the forward slash
  275. * if it is missing.
  276. *
  277. * ```js
  278. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  279. * let path = $location.path();
  280. * // => "/some/path"
  281. * ```
  282. */
  283. path(): string;
  284. path(path: string | number | null): this;
  285. /**
  286. * Retrieves a map of the search parameters of the current URL, or changes a search
  287. * part and returns a reference to its own instance.
  288. *
  289. *
  290. * ```js
  291. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  292. * let searchObject = $location.search();
  293. * // => {foo: 'bar', baz: 'xoxo'}
  294. *
  295. * // set foo to 'yipee'
  296. * $location.search('foo', 'yipee');
  297. * // $location.search() => {foo: 'yipee', baz: 'xoxo'}
  298. * ```
  299. *
  300. * @param {string|Object.<string>|Object.<Array.<string>>} search New search params - string or
  301. * hash object.
  302. *
  303. * When called with a single argument the method acts as a setter, setting the `search` component
  304. * of `$location` to the specified value.
  305. *
  306. * If the argument is a hash object containing an array of values, these values will be encoded
  307. * as duplicate search parameters in the URL.
  308. *
  309. * @param {(string|Number|Array<string>|boolean)=} paramValue If `search` is a string or number,
  310. * then `paramValue`
  311. * will override only a single search property.
  312. *
  313. * If `paramValue` is an array, it will override the property of the `search` component of
  314. * `$location` specified via the first argument.
  315. *
  316. * If `paramValue` is `null`, the property specified via the first argument will be deleted.
  317. *
  318. * If `paramValue` is `true`, the property specified via the first argument will be added with no
  319. * value nor trailing equal sign.
  320. *
  321. * @return {Object} The parsed `search` object of the current URL, or the changed `search` object.
  322. */
  323. search(): {
  324. [key: string]: unknown;
  325. };
  326. search(search: string | number | {
  327. [key: string]: unknown;
  328. }): this;
  329. search(search: string | number | {
  330. [key: string]: unknown;
  331. }, paramValue: null | undefined | string | number | boolean | string[]): this;
  332. /**
  333. * Retrieves the current hash fragment, or changes the hash fragment and returns a reference to
  334. * its own instance.
  335. *
  336. * ```js
  337. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
  338. * let hash = $location.hash();
  339. * // => "hashValue"
  340. * ```
  341. */
  342. hash(): string;
  343. hash(hash: string | number | null): this;
  344. /**
  345. * Changes to `$location` during the current `$digest` will replace the current
  346. * history record, instead of adding a new one.
  347. */
  348. replace(): this;
  349. /**
  350. * Retrieves the history state object when called without any parameter.
  351. *
  352. * Change the history state object when called with one parameter and return `$location`.
  353. * The state object is later passed to `pushState` or `replaceState`.
  354. *
  355. * This method is supported only in HTML5 mode and only in browsers supporting
  356. * the HTML5 History API methods such as `pushState` and `replaceState`. If you need to support
  357. * older browsers (like Android < 4.0), don't use this method.
  358. *
  359. */
  360. state(): unknown;
  361. state(state: unknown): this;
  362. }
  363. /**
  364. * The factory function used to create an instance of the `$locationShim` in Angular,
  365. * and provides an API-compatible `$locationProvider` for AngularJS.
  366. *
  367. * @publicApi
  368. */
  369. declare class $locationShimProvider {
  370. private ngUpgrade;
  371. private location;
  372. private platformLocation;
  373. private urlCodec;
  374. private locationStrategy;
  375. constructor(ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy);
  376. /**
  377. * Factory method that returns an instance of the $locationShim
  378. */
  379. $get(): $locationShim;
  380. /**
  381. * Stub method used to keep API compatible with AngularJS. This setting is configured through
  382. * the LocationUpgradeModule's `config` method in your Angular app.
  383. */
  384. hashPrefix(prefix?: string): void;
  385. /**
  386. * Stub method used to keep API compatible with AngularJS. This setting is configured through
  387. * the LocationUpgradeModule's `config` method in your Angular app.
  388. */
  389. html5Mode(mode?: any): void;
  390. }
  391. /**
  392. * Configuration options for LocationUpgrade.
  393. *
  394. * @publicApi
  395. */
  396. interface LocationUpgradeConfig {
  397. /**
  398. * Configures whether the location upgrade module should use the `HashLocationStrategy`
  399. * or the `PathLocationStrategy`
  400. */
  401. useHash?: boolean;
  402. /**
  403. * Configures the hash prefix used in the URL when using the `HashLocationStrategy`
  404. */
  405. hashPrefix?: string;
  406. /**
  407. * Configures the URL codec for encoding and decoding URLs. Default is the `AngularJSCodec`
  408. */
  409. urlCodec?: typeof UrlCodec;
  410. /**
  411. * Configures the base href when used in server-side rendered applications
  412. */
  413. serverBaseHref?: string;
  414. /**
  415. * Configures the base href when used in client-side rendered applications
  416. */
  417. appBaseHref?: string;
  418. }
  419. /**
  420. * A provider token used to configure the location upgrade module.
  421. *
  422. * @publicApi
  423. */
  424. declare const LOCATION_UPGRADE_CONFIGURATION: InjectionToken<LocationUpgradeConfig>;
  425. /**
  426. * `NgModule` used for providing and configuring Angular's Unified Location Service for upgrading.
  427. *
  428. * @see [Using the Unified Angular Location Service](https://angular.io/guide/upgrade#using-the-unified-angular-location-service)
  429. *
  430. * @publicApi
  431. */
  432. declare class LocationUpgradeModule {
  433. static config(config?: LocationUpgradeConfig): ModuleWithProviders<LocationUpgradeModule>;
  434. static ɵfac: i0.ɵɵFactoryDeclaration<LocationUpgradeModule, never>;
  435. static ɵmod: i0.ɵɵNgModuleDeclaration<LocationUpgradeModule, never, [typeof CommonModule], never>;
  436. static ɵinj: i0.ɵɵInjectorDeclaration<LocationUpgradeModule>;
  437. }
  438. export { $locationShim, $locationShimProvider, AngularJSUrlCodec, LOCATION_UPGRADE_CONFIGURATION, LocationUpgradeModule, UrlCodec };
  439. export type { LocationUpgradeConfig };