index.d.ts 14 KB

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