platform-browser.mjs 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275
  1. /**
  2. * @license Angular v19.2.4
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { ɵDomAdapter as _DomAdapter, ɵsetRootDomAdapter as _setRootDomAdapter, ɵparseCookieValue as _parseCookieValue, ɵgetDOM as _getDOM, isPlatformServer, DOCUMENT, CommonModule, XhrFactory, ɵPLATFORM_BROWSER_ID as _PLATFORM_BROWSER_ID } from '@angular/common';
  7. export { ɵgetDOM } from '@angular/common';
  8. import * as i0 from '@angular/core';
  9. import { ɵglobal as _global, ɵRuntimeError as _RuntimeError, Injectable, InjectionToken, Inject, APP_ID, CSP_NONCE, PLATFORM_ID, Optional, ViewEncapsulation, ɵTracingService as _TracingService, RendererStyleFlags2, createPlatformFactory, ɵinternalCreateApplication as _internalCreateApplication, inject, ApplicationModule, ɵINJECTOR_SCOPE as _INJECTOR_SCOPE, ErrorHandler, RendererFactory2, ɵTESTABILITY_GETTER as _TESTABILITY_GETTER, NgZone, TestabilityRegistry, Testability, ɵTESTABILITY as _TESTABILITY, platformCore, PLATFORM_INITIALIZER, ɵsetDocument as _setDocument, NgModule, ApplicationRef, Injector, ɵConsole as _Console, ɵXSS_SECURITY_URL as _XSS_SECURITY_URL, SecurityContext, ɵallowSanitizationBypassAndThrow as _allowSanitizationBypassAndThrow, ɵunwrapSafeValue as _unwrapSafeValue, ɵ_sanitizeUrl as __sanitizeUrl, ɵ_sanitizeHtml as __sanitizeHtml, ɵbypassSanitizationTrustHtml as _bypassSanitizationTrustHtml, ɵbypassSanitizationTrustStyle as _bypassSanitizationTrustStyle, ɵbypassSanitizationTrustScript as _bypassSanitizationTrustScript, ɵbypassSanitizationTrustUrl as _bypassSanitizationTrustUrl, ɵbypassSanitizationTrustResourceUrl as _bypassSanitizationTrustResourceUrl, forwardRef, makeEnvironmentProviders, ɵwithDomHydration as _withDomHydration, ɵwithEventReplay as _withEventReplay, ɵwithI18nSupport as _withI18nSupport, ɵwithIncrementalHydration as _withIncrementalHydration, ENVIRONMENT_INITIALIZER, ɵZONELESS_ENABLED as _ZONELESS_ENABLED, ɵformatRuntimeError as _formatRuntimeError, Version } from '@angular/core';
  10. import { ɵwithHttpTransferCache as _withHttpTransferCache } from '@angular/common/http';
  11. /**
  12. * Provides DOM operations in any browser environment.
  13. *
  14. * @security Tread carefully! Interacting with the DOM directly is dangerous and
  15. * can introduce XSS risks.
  16. */
  17. class GenericBrowserDomAdapter extends _DomAdapter {
  18. supportsDOMEvents = true;
  19. }
  20. /**
  21. * A `DomAdapter` powered by full browser DOM APIs.
  22. *
  23. * @security Tread carefully! Interacting with the DOM directly is dangerous and
  24. * can introduce XSS risks.
  25. */
  26. class BrowserDomAdapter extends GenericBrowserDomAdapter {
  27. static makeCurrent() {
  28. _setRootDomAdapter(new BrowserDomAdapter());
  29. }
  30. onAndCancel(el, evt, listener, options) {
  31. el.addEventListener(evt, listener, options);
  32. return () => {
  33. el.removeEventListener(evt, listener, options);
  34. };
  35. }
  36. dispatchEvent(el, evt) {
  37. el.dispatchEvent(evt);
  38. }
  39. remove(node) {
  40. node.remove();
  41. }
  42. createElement(tagName, doc) {
  43. doc = doc || this.getDefaultDocument();
  44. return doc.createElement(tagName);
  45. }
  46. createHtmlDocument() {
  47. return document.implementation.createHTMLDocument('fakeTitle');
  48. }
  49. getDefaultDocument() {
  50. return document;
  51. }
  52. isElementNode(node) {
  53. return node.nodeType === Node.ELEMENT_NODE;
  54. }
  55. isShadowRoot(node) {
  56. return node instanceof DocumentFragment;
  57. }
  58. /** @deprecated No longer being used in Ivy code. To be removed in version 14. */
  59. getGlobalEventTarget(doc, target) {
  60. if (target === 'window') {
  61. return window;
  62. }
  63. if (target === 'document') {
  64. return doc;
  65. }
  66. if (target === 'body') {
  67. return doc.body;
  68. }
  69. return null;
  70. }
  71. getBaseHref(doc) {
  72. const href = getBaseElementHref();
  73. return href == null ? null : relativePath(href);
  74. }
  75. resetBaseElement() {
  76. baseElement = null;
  77. }
  78. getUserAgent() {
  79. return window.navigator.userAgent;
  80. }
  81. getCookie(name) {
  82. return _parseCookieValue(document.cookie, name);
  83. }
  84. }
  85. let baseElement = null;
  86. function getBaseElementHref() {
  87. baseElement = baseElement || document.querySelector('base');
  88. return baseElement ? baseElement.getAttribute('href') : null;
  89. }
  90. function relativePath(url) {
  91. // The base URL doesn't really matter, we just need it so relative paths have something
  92. // to resolve against. In the browser `HTMLBaseElement.href` is always absolute.
  93. return new URL(url, document.baseURI).pathname;
  94. }
  95. class BrowserGetTestability {
  96. addToWindow(registry) {
  97. _global['getAngularTestability'] = (elem, findInAncestors = true) => {
  98. const testability = registry.findTestabilityInTree(elem, findInAncestors);
  99. if (testability == null) {
  100. throw new _RuntimeError(5103 /* RuntimeErrorCode.TESTABILITY_NOT_FOUND */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  101. 'Could not find testability for element.');
  102. }
  103. return testability;
  104. };
  105. _global['getAllAngularTestabilities'] = () => registry.getAllTestabilities();
  106. _global['getAllAngularRootElements'] = () => registry.getAllRootElements();
  107. const whenAllStable = (callback) => {
  108. const testabilities = _global['getAllAngularTestabilities']();
  109. let count = testabilities.length;
  110. const decrement = function () {
  111. count--;
  112. if (count == 0) {
  113. callback();
  114. }
  115. };
  116. testabilities.forEach((testability) => {
  117. testability.whenStable(decrement);
  118. });
  119. };
  120. if (!_global['frameworkStabilizers']) {
  121. _global['frameworkStabilizers'] = [];
  122. }
  123. _global['frameworkStabilizers'].push(whenAllStable);
  124. }
  125. findTestabilityInTree(registry, elem, findInAncestors) {
  126. if (elem == null) {
  127. return null;
  128. }
  129. const t = registry.getTestability(elem);
  130. if (t != null) {
  131. return t;
  132. }
  133. else if (!findInAncestors) {
  134. return null;
  135. }
  136. if (_getDOM().isShadowRoot(elem)) {
  137. return this.findTestabilityInTree(registry, elem.host, true);
  138. }
  139. return this.findTestabilityInTree(registry, elem.parentElement, true);
  140. }
  141. }
  142. /**
  143. * A factory for `HttpXhrBackend` that uses the `XMLHttpRequest` browser API.
  144. */
  145. class BrowserXhr {
  146. build() {
  147. return new XMLHttpRequest();
  148. }
  149. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: BrowserXhr, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  150. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: BrowserXhr });
  151. }
  152. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: BrowserXhr, decorators: [{
  153. type: Injectable
  154. }] });
  155. /**
  156. * The injection token for plugins of the `EventManager` service.
  157. *
  158. * @publicApi
  159. */
  160. const EVENT_MANAGER_PLUGINS = new InjectionToken(ngDevMode ? 'EventManagerPlugins' : '');
  161. /**
  162. * An injectable service that provides event management for Angular
  163. * through a browser plug-in.
  164. *
  165. * @publicApi
  166. */
  167. class EventManager {
  168. _zone;
  169. _plugins;
  170. _eventNameToPlugin = new Map();
  171. /**
  172. * Initializes an instance of the event-manager service.
  173. */
  174. constructor(plugins, _zone) {
  175. this._zone = _zone;
  176. plugins.forEach((plugin) => {
  177. plugin.manager = this;
  178. });
  179. this._plugins = plugins.slice().reverse();
  180. }
  181. /**
  182. * Registers a handler for a specific element and event.
  183. *
  184. * @param element The HTML element to receive event notifications.
  185. * @param eventName The name of the event to listen for.
  186. * @param handler A function to call when the notification occurs. Receives the
  187. * event object as an argument.
  188. * @param options Options that configure how the event listener is bound.
  189. * @returns A callback function that can be used to remove the handler.
  190. */
  191. addEventListener(element, eventName, handler, options) {
  192. const plugin = this._findPluginFor(eventName);
  193. return plugin.addEventListener(element, eventName, handler, options);
  194. }
  195. /**
  196. * Retrieves the compilation zone in which event listeners are registered.
  197. */
  198. getZone() {
  199. return this._zone;
  200. }
  201. /** @internal */
  202. _findPluginFor(eventName) {
  203. let plugin = this._eventNameToPlugin.get(eventName);
  204. if (plugin) {
  205. return plugin;
  206. }
  207. const plugins = this._plugins;
  208. plugin = plugins.find((plugin) => plugin.supports(eventName));
  209. if (!plugin) {
  210. throw new _RuntimeError(5101 /* RuntimeErrorCode.NO_PLUGIN_FOR_EVENT */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  211. `No event manager plugin found for event ${eventName}`);
  212. }
  213. this._eventNameToPlugin.set(eventName, plugin);
  214. return plugin;
  215. }
  216. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: EventManager, deps: [{ token: EVENT_MANAGER_PLUGINS }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
  217. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: EventManager });
  218. }
  219. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: EventManager, decorators: [{
  220. type: Injectable
  221. }], ctorParameters: () => [{ type: undefined, decorators: [{
  222. type: Inject,
  223. args: [EVENT_MANAGER_PLUGINS]
  224. }] }, { type: i0.NgZone }] });
  225. /**
  226. * The plugin definition for the `EventManager` class
  227. *
  228. * It can be used as a base class to create custom manager plugins, i.e. you can create your own
  229. * class that extends the `EventManagerPlugin` one.
  230. *
  231. * @publicApi
  232. */
  233. class EventManagerPlugin {
  234. _doc;
  235. // TODO: remove (has some usage in G3)
  236. constructor(_doc) {
  237. this._doc = _doc;
  238. }
  239. // Using non-null assertion because it's set by EventManager's constructor
  240. manager;
  241. }
  242. /** The style elements attribute name used to set value of `APP_ID` token. */
  243. const APP_ID_ATTRIBUTE_NAME = 'ng-app-id';
  244. /**
  245. * Removes all provided elements from the document.
  246. * @param elements An array of HTML Elements.
  247. */
  248. function removeElements(elements) {
  249. for (const element of elements) {
  250. element.remove();
  251. }
  252. }
  253. /**
  254. * Creates a `style` element with the provided inline style content.
  255. * @param style A string of the inline style content.
  256. * @param doc A DOM Document to use to create the element.
  257. * @returns An HTMLStyleElement instance.
  258. */
  259. function createStyleElement(style, doc) {
  260. const styleElement = doc.createElement('style');
  261. styleElement.textContent = style;
  262. return styleElement;
  263. }
  264. /**
  265. * Searches a DOM document's head element for style elements with a matching application
  266. * identifier attribute (`ng-app-id`) to the provide identifier and adds usage records for each.
  267. * @param doc An HTML DOM document instance.
  268. * @param appId A string containing an Angular application identifer.
  269. * @param inline A Map object for tracking inline (defined via `styles` in component decorator) style usage.
  270. * @param external A Map object for tracking external (defined via `styleUrls` in component decorator) style usage.
  271. */
  272. function addServerStyles(doc, appId, inline, external) {
  273. const elements = doc.head?.querySelectorAll(`style[${APP_ID_ATTRIBUTE_NAME}="${appId}"],link[${APP_ID_ATTRIBUTE_NAME}="${appId}"]`);
  274. if (elements) {
  275. for (const styleElement of elements) {
  276. styleElement.removeAttribute(APP_ID_ATTRIBUTE_NAME);
  277. if (styleElement instanceof HTMLLinkElement) {
  278. // Only use filename from href
  279. // The href is build time generated with a unique value to prevent duplicates.
  280. external.set(styleElement.href.slice(styleElement.href.lastIndexOf('/') + 1), {
  281. usage: 0,
  282. elements: [styleElement],
  283. });
  284. }
  285. else if (styleElement.textContent) {
  286. inline.set(styleElement.textContent, { usage: 0, elements: [styleElement] });
  287. }
  288. }
  289. }
  290. }
  291. /**
  292. * Creates a `link` element for the provided external style URL.
  293. * @param url A string of the URL for the stylesheet.
  294. * @param doc A DOM Document to use to create the element.
  295. * @returns An HTMLLinkElement instance.
  296. */
  297. function createLinkElement(url, doc) {
  298. const linkElement = doc.createElement('link');
  299. linkElement.setAttribute('rel', 'stylesheet');
  300. linkElement.setAttribute('href', url);
  301. return linkElement;
  302. }
  303. class SharedStylesHost {
  304. doc;
  305. appId;
  306. nonce;
  307. /**
  308. * Provides usage information for active inline style content and associated HTML <style> elements.
  309. * Embedded styles typically originate from the `styles` metadata of a rendered component.
  310. */
  311. inline = new Map();
  312. /**
  313. * Provides usage information for active external style URLs and the associated HTML <link> elements.
  314. * External styles typically originate from the `ɵɵExternalStylesFeature` of a rendered component.
  315. */
  316. external = new Map();
  317. /**
  318. * Set of host DOM nodes that will have styles attached.
  319. */
  320. hosts = new Set();
  321. /**
  322. * Whether the application code is currently executing on a server.
  323. */
  324. isServer;
  325. constructor(doc, appId, nonce, platformId = {}) {
  326. this.doc = doc;
  327. this.appId = appId;
  328. this.nonce = nonce;
  329. this.isServer = isPlatformServer(platformId);
  330. addServerStyles(doc, appId, this.inline, this.external);
  331. this.hosts.add(doc.head);
  332. }
  333. /**
  334. * Adds embedded styles to the DOM via HTML `style` elements.
  335. * @param styles An array of style content strings.
  336. */
  337. addStyles(styles, urls) {
  338. for (const value of styles) {
  339. this.addUsage(value, this.inline, createStyleElement);
  340. }
  341. urls?.forEach((value) => this.addUsage(value, this.external, createLinkElement));
  342. }
  343. /**
  344. * Removes embedded styles from the DOM that were added as HTML `style` elements.
  345. * @param styles An array of style content strings.
  346. */
  347. removeStyles(styles, urls) {
  348. for (const value of styles) {
  349. this.removeUsage(value, this.inline);
  350. }
  351. urls?.forEach((value) => this.removeUsage(value, this.external));
  352. }
  353. addUsage(value, usages, creator) {
  354. // Attempt to get any current usage of the value
  355. const record = usages.get(value);
  356. // If existing, just increment the usage count
  357. if (record) {
  358. if ((typeof ngDevMode === 'undefined' || ngDevMode) && record.usage === 0) {
  359. // A usage count of zero indicates a preexisting server generated style.
  360. // This attribute is solely used for debugging purposes of SSR style reuse.
  361. record.elements.forEach((element) => element.setAttribute('ng-style-reused', ''));
  362. }
  363. record.usage++;
  364. }
  365. else {
  366. // Otherwise, create an entry to track the elements and add element for each host
  367. usages.set(value, {
  368. usage: 1,
  369. elements: [...this.hosts].map((host) => this.addElement(host, creator(value, this.doc))),
  370. });
  371. }
  372. }
  373. removeUsage(value, usages) {
  374. // Attempt to get any current usage of the value
  375. const record = usages.get(value);
  376. // If there is a record, reduce the usage count and if no longer used,
  377. // remove from DOM and delete usage record.
  378. if (record) {
  379. record.usage--;
  380. if (record.usage <= 0) {
  381. removeElements(record.elements);
  382. usages.delete(value);
  383. }
  384. }
  385. }
  386. ngOnDestroy() {
  387. for (const [, { elements }] of [...this.inline, ...this.external]) {
  388. removeElements(elements);
  389. }
  390. this.hosts.clear();
  391. }
  392. /**
  393. * Adds a host node to the set of style hosts and adds all existing style usage to
  394. * the newly added host node.
  395. *
  396. * This is currently only used for Shadow DOM encapsulation mode.
  397. */
  398. addHost(hostNode) {
  399. this.hosts.add(hostNode);
  400. // Add existing styles to new host
  401. for (const [style, { elements }] of this.inline) {
  402. elements.push(this.addElement(hostNode, createStyleElement(style, this.doc)));
  403. }
  404. for (const [url, { elements }] of this.external) {
  405. elements.push(this.addElement(hostNode, createLinkElement(url, this.doc)));
  406. }
  407. }
  408. removeHost(hostNode) {
  409. this.hosts.delete(hostNode);
  410. }
  411. addElement(host, element) {
  412. // Add a nonce if present
  413. if (this.nonce) {
  414. element.setAttribute('nonce', this.nonce);
  415. }
  416. // Add application identifier when on the server to support client-side reuse
  417. if (this.isServer) {
  418. element.setAttribute(APP_ID_ATTRIBUTE_NAME, this.appId);
  419. }
  420. // Insert the element into the DOM with the host node as parent
  421. return host.appendChild(element);
  422. }
  423. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SharedStylesHost, deps: [{ token: DOCUMENT }, { token: APP_ID }, { token: CSP_NONCE, optional: true }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
  424. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SharedStylesHost });
  425. }
  426. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SharedStylesHost, decorators: [{
  427. type: Injectable
  428. }], ctorParameters: () => [{ type: Document, decorators: [{
  429. type: Inject,
  430. args: [DOCUMENT]
  431. }] }, { type: undefined, decorators: [{
  432. type: Inject,
  433. args: [APP_ID]
  434. }] }, { type: undefined, decorators: [{
  435. type: Inject,
  436. args: [CSP_NONCE]
  437. }, {
  438. type: Optional
  439. }] }, { type: undefined, decorators: [{
  440. type: Inject,
  441. args: [PLATFORM_ID]
  442. }] }] });
  443. const NAMESPACE_URIS = {
  444. 'svg': 'http://www.w3.org/2000/svg',
  445. 'xhtml': 'http://www.w3.org/1999/xhtml',
  446. 'xlink': 'http://www.w3.org/1999/xlink',
  447. 'xml': 'http://www.w3.org/XML/1998/namespace',
  448. 'xmlns': 'http://www.w3.org/2000/xmlns/',
  449. 'math': 'http://www.w3.org/1998/Math/MathML',
  450. };
  451. const COMPONENT_REGEX = /%COMP%/g;
  452. const SOURCEMAP_URL_REGEXP = /\/\*#\s*sourceMappingURL=(.+?)\s*\*\//;
  453. const PROTOCOL_REGEXP = /^https?:/;
  454. const COMPONENT_VARIABLE = '%COMP%';
  455. const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
  456. const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
  457. /**
  458. * The default value for the `REMOVE_STYLES_ON_COMPONENT_DESTROY` DI token.
  459. */
  460. const REMOVE_STYLES_ON_COMPONENT_DESTROY_DEFAULT = true;
  461. /**
  462. * A DI token that indicates whether styles
  463. * of destroyed components should be removed from DOM.
  464. *
  465. * By default, the value is set to `true`.
  466. * @publicApi
  467. */
  468. const REMOVE_STYLES_ON_COMPONENT_DESTROY = new InjectionToken(ngDevMode ? 'RemoveStylesOnCompDestroy' : '', {
  469. providedIn: 'root',
  470. factory: () => REMOVE_STYLES_ON_COMPONENT_DESTROY_DEFAULT,
  471. });
  472. function shimContentAttribute(componentShortId) {
  473. return CONTENT_ATTR.replace(COMPONENT_REGEX, componentShortId);
  474. }
  475. function shimHostAttribute(componentShortId) {
  476. return HOST_ATTR.replace(COMPONENT_REGEX, componentShortId);
  477. }
  478. function shimStylesContent(compId, styles) {
  479. return styles.map((s) => s.replace(COMPONENT_REGEX, compId));
  480. }
  481. /**
  482. * Prepends a baseHref to the `sourceMappingURL` within the provided CSS content.
  483. * If the `sourceMappingURL` contains an inline (encoded) map, the function skips processing.
  484. *
  485. * @note For inline stylesheets, the `sourceMappingURL` is relative to the page's origin
  486. * and not the provided baseHref. This function is needed as when accessing the page with a URL
  487. * containing two or more segments.
  488. * For example, if the baseHref is set to `/`, and you visit a URL like `http://localhost/foo/bar`,
  489. * the map would be requested from `http://localhost/foo/bar/comp.css.map` instead of what you'd expect,
  490. * which is `http://localhost/comp.css.map`. This behavior is corrected by modifying the `sourceMappingURL`
  491. * to ensure external source maps are loaded relative to the baseHref.
  492. *
  493. * @param baseHref - The base URL to prepend to the `sourceMappingURL`.
  494. * @param styles - An array of CSS content strings, each potentially containing a `sourceMappingURL`.
  495. * @returns The updated array of CSS content strings with modified `sourceMappingURL` values,
  496. * or the original content if no modification is needed.
  497. */
  498. function addBaseHrefToCssSourceMap(baseHref, styles) {
  499. if (!baseHref) {
  500. return styles;
  501. }
  502. const absoluteBaseHrefUrl = new URL(baseHref, 'http://localhost');
  503. return styles.map((cssContent) => {
  504. if (!cssContent.includes('sourceMappingURL=')) {
  505. return cssContent;
  506. }
  507. return cssContent.replace(SOURCEMAP_URL_REGEXP, (_, sourceMapUrl) => {
  508. if (sourceMapUrl[0] === '/' ||
  509. sourceMapUrl.startsWith('data:') ||
  510. PROTOCOL_REGEXP.test(sourceMapUrl)) {
  511. return `/*# sourceMappingURL=${sourceMapUrl} */`;
  512. }
  513. const { pathname: resolvedSourceMapUrl } = new URL(sourceMapUrl, absoluteBaseHrefUrl);
  514. return `/*# sourceMappingURL=${resolvedSourceMapUrl} */`;
  515. });
  516. });
  517. }
  518. class DomRendererFactory2 {
  519. eventManager;
  520. sharedStylesHost;
  521. appId;
  522. removeStylesOnCompDestroy;
  523. doc;
  524. platformId;
  525. ngZone;
  526. nonce;
  527. tracingService;
  528. rendererByCompId = new Map();
  529. defaultRenderer;
  530. platformIsServer;
  531. constructor(eventManager, sharedStylesHost, appId, removeStylesOnCompDestroy, doc, platformId, ngZone, nonce = null, tracingService = null) {
  532. this.eventManager = eventManager;
  533. this.sharedStylesHost = sharedStylesHost;
  534. this.appId = appId;
  535. this.removeStylesOnCompDestroy = removeStylesOnCompDestroy;
  536. this.doc = doc;
  537. this.platformId = platformId;
  538. this.ngZone = ngZone;
  539. this.nonce = nonce;
  540. this.tracingService = tracingService;
  541. this.platformIsServer = isPlatformServer(platformId);
  542. this.defaultRenderer = new DefaultDomRenderer2(eventManager, doc, ngZone, this.platformIsServer, this.tracingService);
  543. }
  544. createRenderer(element, type) {
  545. if (!element || !type) {
  546. return this.defaultRenderer;
  547. }
  548. if (this.platformIsServer && type.encapsulation === ViewEncapsulation.ShadowDom) {
  549. // Domino does not support shadow DOM.
  550. type = { ...type, encapsulation: ViewEncapsulation.Emulated };
  551. }
  552. const renderer = this.getOrCreateRenderer(element, type);
  553. // Renderers have different logic due to different encapsulation behaviours.
  554. // Ex: for emulated, an attribute is added to the element.
  555. if (renderer instanceof EmulatedEncapsulationDomRenderer2) {
  556. renderer.applyToHost(element);
  557. }
  558. else if (renderer instanceof NoneEncapsulationDomRenderer) {
  559. renderer.applyStyles();
  560. }
  561. return renderer;
  562. }
  563. getOrCreateRenderer(element, type) {
  564. const rendererByCompId = this.rendererByCompId;
  565. let renderer = rendererByCompId.get(type.id);
  566. if (!renderer) {
  567. const doc = this.doc;
  568. const ngZone = this.ngZone;
  569. const eventManager = this.eventManager;
  570. const sharedStylesHost = this.sharedStylesHost;
  571. const removeStylesOnCompDestroy = this.removeStylesOnCompDestroy;
  572. const platformIsServer = this.platformIsServer;
  573. const tracingService = this.tracingService;
  574. switch (type.encapsulation) {
  575. case ViewEncapsulation.Emulated:
  576. renderer = new EmulatedEncapsulationDomRenderer2(eventManager, sharedStylesHost, type, this.appId, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService);
  577. break;
  578. case ViewEncapsulation.ShadowDom:
  579. return new ShadowDomRenderer(eventManager, sharedStylesHost, element, type, doc, ngZone, this.nonce, platformIsServer, tracingService);
  580. default:
  581. renderer = new NoneEncapsulationDomRenderer(eventManager, sharedStylesHost, type, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService);
  582. break;
  583. }
  584. rendererByCompId.set(type.id, renderer);
  585. }
  586. return renderer;
  587. }
  588. ngOnDestroy() {
  589. this.rendererByCompId.clear();
  590. }
  591. /**
  592. * Used during HMR to clear any cached data about a component.
  593. * @param componentId ID of the component that is being replaced.
  594. */
  595. componentReplaced(componentId) {
  596. this.rendererByCompId.delete(componentId);
  597. }
  598. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomRendererFactory2, deps: [{ token: EventManager }, { token: SharedStylesHost }, { token: APP_ID }, { token: REMOVE_STYLES_ON_COMPONENT_DESTROY }, { token: DOCUMENT }, { token: PLATFORM_ID }, { token: i0.NgZone }, { token: CSP_NONCE }, { token: _TracingService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
  599. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomRendererFactory2 });
  600. }
  601. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomRendererFactory2, decorators: [{
  602. type: Injectable
  603. }], ctorParameters: () => [{ type: EventManager }, { type: SharedStylesHost }, { type: undefined, decorators: [{
  604. type: Inject,
  605. args: [APP_ID]
  606. }] }, { type: undefined, decorators: [{
  607. type: Inject,
  608. args: [REMOVE_STYLES_ON_COMPONENT_DESTROY]
  609. }] }, { type: Document, decorators: [{
  610. type: Inject,
  611. args: [DOCUMENT]
  612. }] }, { type: Object, decorators: [{
  613. type: Inject,
  614. args: [PLATFORM_ID]
  615. }] }, { type: i0.NgZone }, { type: undefined, decorators: [{
  616. type: Inject,
  617. args: [CSP_NONCE]
  618. }] }, { type: i0.ɵTracingService, decorators: [{
  619. type: Inject,
  620. args: [_TracingService]
  621. }, {
  622. type: Optional
  623. }] }] });
  624. class DefaultDomRenderer2 {
  625. eventManager;
  626. doc;
  627. ngZone;
  628. platformIsServer;
  629. tracingService;
  630. data = Object.create(null);
  631. /**
  632. * By default this renderer throws when encountering synthetic properties
  633. * This can be disabled for example by the AsyncAnimationRendererFactory
  634. */
  635. throwOnSyntheticProps = true;
  636. constructor(eventManager, doc, ngZone, platformIsServer, tracingService) {
  637. this.eventManager = eventManager;
  638. this.doc = doc;
  639. this.ngZone = ngZone;
  640. this.platformIsServer = platformIsServer;
  641. this.tracingService = tracingService;
  642. }
  643. destroy() { }
  644. destroyNode = null;
  645. createElement(name, namespace) {
  646. if (namespace) {
  647. // TODO: `|| namespace` was added in
  648. // https://github.com/angular/angular/commit/2b9cc8503d48173492c29f5a271b61126104fbdb to
  649. // support how Ivy passed around the namespace URI rather than short name at the time. It did
  650. // not, however extend the support to other parts of the system (setAttribute, setAttribute,
  651. // and the ServerRenderer). We should decide what exactly the semantics for dealing with
  652. // namespaces should be and make it consistent.
  653. // Related issues:
  654. // https://github.com/angular/angular/issues/44028
  655. // https://github.com/angular/angular/issues/44883
  656. return this.doc.createElementNS(NAMESPACE_URIS[namespace] || namespace, name);
  657. }
  658. return this.doc.createElement(name);
  659. }
  660. createComment(value) {
  661. return this.doc.createComment(value);
  662. }
  663. createText(value) {
  664. return this.doc.createTextNode(value);
  665. }
  666. appendChild(parent, newChild) {
  667. const targetParent = isTemplateNode(parent) ? parent.content : parent;
  668. targetParent.appendChild(newChild);
  669. }
  670. insertBefore(parent, newChild, refChild) {
  671. if (parent) {
  672. const targetParent = isTemplateNode(parent) ? parent.content : parent;
  673. targetParent.insertBefore(newChild, refChild);
  674. }
  675. }
  676. removeChild(_parent, oldChild) {
  677. oldChild.remove();
  678. }
  679. selectRootElement(selectorOrNode, preserveContent) {
  680. let el = typeof selectorOrNode === 'string' ? this.doc.querySelector(selectorOrNode) : selectorOrNode;
  681. if (!el) {
  682. throw new _RuntimeError(-5104 /* RuntimeErrorCode.ROOT_NODE_NOT_FOUND */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  683. `The selector "${selectorOrNode}" did not match any elements`);
  684. }
  685. if (!preserveContent) {
  686. el.textContent = '';
  687. }
  688. return el;
  689. }
  690. parentNode(node) {
  691. return node.parentNode;
  692. }
  693. nextSibling(node) {
  694. return node.nextSibling;
  695. }
  696. setAttribute(el, name, value, namespace) {
  697. if (namespace) {
  698. name = namespace + ':' + name;
  699. const namespaceUri = NAMESPACE_URIS[namespace];
  700. if (namespaceUri) {
  701. el.setAttributeNS(namespaceUri, name, value);
  702. }
  703. else {
  704. el.setAttribute(name, value);
  705. }
  706. }
  707. else {
  708. el.setAttribute(name, value);
  709. }
  710. }
  711. removeAttribute(el, name, namespace) {
  712. if (namespace) {
  713. const namespaceUri = NAMESPACE_URIS[namespace];
  714. if (namespaceUri) {
  715. el.removeAttributeNS(namespaceUri, name);
  716. }
  717. else {
  718. el.removeAttribute(`${namespace}:${name}`);
  719. }
  720. }
  721. else {
  722. el.removeAttribute(name);
  723. }
  724. }
  725. addClass(el, name) {
  726. el.classList.add(name);
  727. }
  728. removeClass(el, name) {
  729. el.classList.remove(name);
  730. }
  731. setStyle(el, style, value, flags) {
  732. if (flags & (RendererStyleFlags2.DashCase | RendererStyleFlags2.Important)) {
  733. el.style.setProperty(style, value, flags & RendererStyleFlags2.Important ? 'important' : '');
  734. }
  735. else {
  736. el.style[style] = value;
  737. }
  738. }
  739. removeStyle(el, style, flags) {
  740. if (flags & RendererStyleFlags2.DashCase) {
  741. // removeProperty has no effect when used on camelCased properties.
  742. el.style.removeProperty(style);
  743. }
  744. else {
  745. el.style[style] = '';
  746. }
  747. }
  748. setProperty(el, name, value) {
  749. if (el == null) {
  750. return;
  751. }
  752. (typeof ngDevMode === 'undefined' || ngDevMode) &&
  753. this.throwOnSyntheticProps &&
  754. checkNoSyntheticProp(name, 'property');
  755. el[name] = value;
  756. }
  757. setValue(node, value) {
  758. node.nodeValue = value;
  759. }
  760. listen(target, event, callback, options) {
  761. (typeof ngDevMode === 'undefined' || ngDevMode) &&
  762. this.throwOnSyntheticProps &&
  763. checkNoSyntheticProp(event, 'listener');
  764. if (typeof target === 'string') {
  765. target = _getDOM().getGlobalEventTarget(this.doc, target);
  766. if (!target) {
  767. throw new _RuntimeError(5102 /* RuntimeErrorCode.UNSUPPORTED_EVENT_TARGET */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  768. `Unsupported event target ${target} for event ${event}`);
  769. }
  770. }
  771. let wrappedCallback = this.decoratePreventDefault(callback);
  772. if (this.tracingService?.wrapEventListener) {
  773. wrappedCallback = this.tracingService.wrapEventListener(target, event, wrappedCallback);
  774. }
  775. return this.eventManager.addEventListener(target, event, wrappedCallback, options);
  776. }
  777. decoratePreventDefault(eventHandler) {
  778. // `DebugNode.triggerEventHandler` needs to know if the listener was created with
  779. // decoratePreventDefault or is a listener added outside the Angular context so it can handle
  780. // the two differently. In the first case, the special '__ngUnwrap__' token is passed to the
  781. // unwrap the listener (see below).
  782. return (event) => {
  783. // Ivy uses '__ngUnwrap__' as a special token that allows us to unwrap the function
  784. // so that it can be invoked programmatically by `DebugNode.triggerEventHandler`. The
  785. // debug_node can inspect the listener toString contents for the existence of this special
  786. // token. Because the token is a string literal, it is ensured to not be modified by compiled
  787. // code.
  788. if (event === '__ngUnwrap__') {
  789. return eventHandler;
  790. }
  791. // Run the event handler inside the ngZone because event handlers are not patched
  792. // by Zone on the server. This is required only for tests.
  793. const allowDefaultBehavior = this.platformIsServer
  794. ? this.ngZone.runGuarded(() => eventHandler(event))
  795. : eventHandler(event);
  796. if (allowDefaultBehavior === false) {
  797. event.preventDefault();
  798. }
  799. return undefined;
  800. };
  801. }
  802. }
  803. const AT_CHARCODE = (() => '@'.charCodeAt(0))();
  804. function checkNoSyntheticProp(name, nameKind) {
  805. if (name.charCodeAt(0) === AT_CHARCODE) {
  806. throw new _RuntimeError(5105 /* RuntimeErrorCode.UNEXPECTED_SYNTHETIC_PROPERTY */, `Unexpected synthetic ${nameKind} ${name} found. Please make sure that:
  807. - Make sure \`provideAnimationsAsync()\`, \`provideAnimations()\` or \`provideNoopAnimations()\` call was added to a list of providers used to bootstrap an application.
  808. - There is a corresponding animation configuration named \`${name}\` defined in the \`animations\` field of the \`@Component\` decorator (see https://angular.dev/api/core/Component#animations).`);
  809. }
  810. }
  811. function isTemplateNode(node) {
  812. return node.tagName === 'TEMPLATE' && node.content !== undefined;
  813. }
  814. class ShadowDomRenderer extends DefaultDomRenderer2 {
  815. sharedStylesHost;
  816. hostEl;
  817. shadowRoot;
  818. constructor(eventManager, sharedStylesHost, hostEl, component, doc, ngZone, nonce, platformIsServer, tracingService) {
  819. super(eventManager, doc, ngZone, platformIsServer, tracingService);
  820. this.sharedStylesHost = sharedStylesHost;
  821. this.hostEl = hostEl;
  822. this.shadowRoot = hostEl.attachShadow({ mode: 'open' });
  823. this.sharedStylesHost.addHost(this.shadowRoot);
  824. let styles = component.styles;
  825. if (ngDevMode) {
  826. // We only do this in development, as for production users should not add CSS sourcemaps to components.
  827. const baseHref = _getDOM().getBaseHref(doc) ?? '';
  828. styles = addBaseHrefToCssSourceMap(baseHref, styles);
  829. }
  830. styles = shimStylesContent(component.id, styles);
  831. for (const style of styles) {
  832. const styleEl = document.createElement('style');
  833. if (nonce) {
  834. styleEl.setAttribute('nonce', nonce);
  835. }
  836. styleEl.textContent = style;
  837. this.shadowRoot.appendChild(styleEl);
  838. }
  839. // Apply any external component styles to the shadow root for the component's element.
  840. // The ShadowDOM renderer uses an alternative execution path for component styles that
  841. // does not use the SharedStylesHost that other encapsulation modes leverage. Much like
  842. // the manual addition of embedded styles directly above, any external stylesheets
  843. // must be manually added here to ensure ShadowDOM components are correctly styled.
  844. // TODO: Consider reworking the DOM Renderers to consolidate style handling.
  845. const styleUrls = component.getExternalStyles?.();
  846. if (styleUrls) {
  847. for (const styleUrl of styleUrls) {
  848. const linkEl = createLinkElement(styleUrl, doc);
  849. if (nonce) {
  850. linkEl.setAttribute('nonce', nonce);
  851. }
  852. this.shadowRoot.appendChild(linkEl);
  853. }
  854. }
  855. }
  856. nodeOrShadowRoot(node) {
  857. return node === this.hostEl ? this.shadowRoot : node;
  858. }
  859. appendChild(parent, newChild) {
  860. return super.appendChild(this.nodeOrShadowRoot(parent), newChild);
  861. }
  862. insertBefore(parent, newChild, refChild) {
  863. return super.insertBefore(this.nodeOrShadowRoot(parent), newChild, refChild);
  864. }
  865. removeChild(_parent, oldChild) {
  866. return super.removeChild(null, oldChild);
  867. }
  868. parentNode(node) {
  869. return this.nodeOrShadowRoot(super.parentNode(this.nodeOrShadowRoot(node)));
  870. }
  871. destroy() {
  872. this.sharedStylesHost.removeHost(this.shadowRoot);
  873. }
  874. }
  875. class NoneEncapsulationDomRenderer extends DefaultDomRenderer2 {
  876. sharedStylesHost;
  877. removeStylesOnCompDestroy;
  878. styles;
  879. styleUrls;
  880. constructor(eventManager, sharedStylesHost, component, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, compId) {
  881. super(eventManager, doc, ngZone, platformIsServer, tracingService);
  882. this.sharedStylesHost = sharedStylesHost;
  883. this.removeStylesOnCompDestroy = removeStylesOnCompDestroy;
  884. let styles = component.styles;
  885. if (ngDevMode) {
  886. // We only do this in development, as for production users should not add CSS sourcemaps to components.
  887. const baseHref = _getDOM().getBaseHref(doc) ?? '';
  888. styles = addBaseHrefToCssSourceMap(baseHref, styles);
  889. }
  890. this.styles = compId ? shimStylesContent(compId, styles) : styles;
  891. this.styleUrls = component.getExternalStyles?.(compId);
  892. }
  893. applyStyles() {
  894. this.sharedStylesHost.addStyles(this.styles, this.styleUrls);
  895. }
  896. destroy() {
  897. if (!this.removeStylesOnCompDestroy) {
  898. return;
  899. }
  900. this.sharedStylesHost.removeStyles(this.styles, this.styleUrls);
  901. }
  902. }
  903. class EmulatedEncapsulationDomRenderer2 extends NoneEncapsulationDomRenderer {
  904. contentAttr;
  905. hostAttr;
  906. constructor(eventManager, sharedStylesHost, component, appId, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService) {
  907. const compId = appId + '-' + component.id;
  908. super(eventManager, sharedStylesHost, component, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, compId);
  909. this.contentAttr = shimContentAttribute(compId);
  910. this.hostAttr = shimHostAttribute(compId);
  911. }
  912. applyToHost(element) {
  913. this.applyStyles();
  914. this.setAttribute(element, this.hostAttr, '');
  915. }
  916. createElement(parent, name) {
  917. const el = super.createElement(parent, name);
  918. super.setAttribute(el, this.contentAttr, '');
  919. return el;
  920. }
  921. }
  922. class DomEventsPlugin extends EventManagerPlugin {
  923. constructor(doc) {
  924. super(doc);
  925. }
  926. // This plugin should come last in the list of plugins, because it accepts all
  927. // events.
  928. supports(eventName) {
  929. return true;
  930. }
  931. addEventListener(element, eventName, handler, options) {
  932. element.addEventListener(eventName, handler, options);
  933. return () => this.removeEventListener(element, eventName, handler, options);
  934. }
  935. removeEventListener(target, eventName, callback, options) {
  936. return target.removeEventListener(eventName, callback, options);
  937. }
  938. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomEventsPlugin, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  939. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomEventsPlugin });
  940. }
  941. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomEventsPlugin, decorators: [{
  942. type: Injectable
  943. }], ctorParameters: () => [{ type: undefined, decorators: [{
  944. type: Inject,
  945. args: [DOCUMENT]
  946. }] }] });
  947. /**
  948. * Defines supported modifiers for key events.
  949. */
  950. const MODIFIER_KEYS = ['alt', 'control', 'meta', 'shift'];
  951. // The following values are here for cross-browser compatibility and to match the W3C standard
  952. // cf https://www.w3.org/TR/DOM-Level-3-Events-key/
  953. const _keyMap = {
  954. '\b': 'Backspace',
  955. '\t': 'Tab',
  956. '\x7F': 'Delete',
  957. '\x1B': 'Escape',
  958. 'Del': 'Delete',
  959. 'Esc': 'Escape',
  960. 'Left': 'ArrowLeft',
  961. 'Right': 'ArrowRight',
  962. 'Up': 'ArrowUp',
  963. 'Down': 'ArrowDown',
  964. 'Menu': 'ContextMenu',
  965. 'Scroll': 'ScrollLock',
  966. 'Win': 'OS',
  967. };
  968. /**
  969. * Retrieves modifiers from key-event objects.
  970. */
  971. const MODIFIER_KEY_GETTERS = {
  972. 'alt': (event) => event.altKey,
  973. 'control': (event) => event.ctrlKey,
  974. 'meta': (event) => event.metaKey,
  975. 'shift': (event) => event.shiftKey,
  976. };
  977. /**
  978. * A browser plug-in that provides support for handling of key events in Angular.
  979. */
  980. class KeyEventsPlugin extends EventManagerPlugin {
  981. /**
  982. * Initializes an instance of the browser plug-in.
  983. * @param doc The document in which key events will be detected.
  984. */
  985. constructor(doc) {
  986. super(doc);
  987. }
  988. /**
  989. * Reports whether a named key event is supported.
  990. * @param eventName The event name to query.
  991. * @return True if the named key event is supported.
  992. */
  993. supports(eventName) {
  994. return KeyEventsPlugin.parseEventName(eventName) != null;
  995. }
  996. /**
  997. * Registers a handler for a specific element and key event.
  998. * @param element The HTML element to receive event notifications.
  999. * @param eventName The name of the key event to listen for.
  1000. * @param handler A function to call when the notification occurs. Receives the
  1001. * event object as an argument.
  1002. * @returns The key event that was registered.
  1003. */
  1004. addEventListener(element, eventName, handler, options) {
  1005. const parsedEvent = KeyEventsPlugin.parseEventName(eventName);
  1006. const outsideHandler = KeyEventsPlugin.eventCallback(parsedEvent['fullKey'], handler, this.manager.getZone());
  1007. return this.manager.getZone().runOutsideAngular(() => {
  1008. return _getDOM().onAndCancel(element, parsedEvent['domEventName'], outsideHandler, options);
  1009. });
  1010. }
  1011. /**
  1012. * Parses the user provided full keyboard event definition and normalizes it for
  1013. * later internal use. It ensures the string is all lowercase, converts special
  1014. * characters to a standard spelling, and orders all the values consistently.
  1015. *
  1016. * @param eventName The name of the key event to listen for.
  1017. * @returns an object with the full, normalized string, and the dom event name
  1018. * or null in the case when the event doesn't match a keyboard event.
  1019. */
  1020. static parseEventName(eventName) {
  1021. const parts = eventName.toLowerCase().split('.');
  1022. const domEventName = parts.shift();
  1023. if (parts.length === 0 || !(domEventName === 'keydown' || domEventName === 'keyup')) {
  1024. return null;
  1025. }
  1026. const key = KeyEventsPlugin._normalizeKey(parts.pop());
  1027. let fullKey = '';
  1028. let codeIX = parts.indexOf('code');
  1029. if (codeIX > -1) {
  1030. parts.splice(codeIX, 1);
  1031. fullKey = 'code.';
  1032. }
  1033. MODIFIER_KEYS.forEach((modifierName) => {
  1034. const index = parts.indexOf(modifierName);
  1035. if (index > -1) {
  1036. parts.splice(index, 1);
  1037. fullKey += modifierName + '.';
  1038. }
  1039. });
  1040. fullKey += key;
  1041. if (parts.length != 0 || key.length === 0) {
  1042. // returning null instead of throwing to let another plugin process the event
  1043. return null;
  1044. }
  1045. // NOTE: Please don't rewrite this as so, as it will break JSCompiler property renaming.
  1046. // The code must remain in the `result['domEventName']` form.
  1047. // return {domEventName, fullKey};
  1048. const result = {};
  1049. result['domEventName'] = domEventName;
  1050. result['fullKey'] = fullKey;
  1051. return result;
  1052. }
  1053. /**
  1054. * Determines whether the actual keys pressed match the configured key code string.
  1055. * The `fullKeyCode` event is normalized in the `parseEventName` method when the
  1056. * event is attached to the DOM during the `addEventListener` call. This is unseen
  1057. * by the end user and is normalized for internal consistency and parsing.
  1058. *
  1059. * @param event The keyboard event.
  1060. * @param fullKeyCode The normalized user defined expected key event string
  1061. * @returns boolean.
  1062. */
  1063. static matchEventFullKeyCode(event, fullKeyCode) {
  1064. let keycode = _keyMap[event.key] || event.key;
  1065. let key = '';
  1066. if (fullKeyCode.indexOf('code.') > -1) {
  1067. keycode = event.code;
  1068. key = 'code.';
  1069. }
  1070. // the keycode could be unidentified so we have to check here
  1071. if (keycode == null || !keycode)
  1072. return false;
  1073. keycode = keycode.toLowerCase();
  1074. if (keycode === ' ') {
  1075. keycode = 'space'; // for readability
  1076. }
  1077. else if (keycode === '.') {
  1078. keycode = 'dot'; // because '.' is used as a separator in event names
  1079. }
  1080. MODIFIER_KEYS.forEach((modifierName) => {
  1081. if (modifierName !== keycode) {
  1082. const modifierGetter = MODIFIER_KEY_GETTERS[modifierName];
  1083. if (modifierGetter(event)) {
  1084. key += modifierName + '.';
  1085. }
  1086. }
  1087. });
  1088. key += keycode;
  1089. return key === fullKeyCode;
  1090. }
  1091. /**
  1092. * Configures a handler callback for a key event.
  1093. * @param fullKey The event name that combines all simultaneous keystrokes.
  1094. * @param handler The function that responds to the key event.
  1095. * @param zone The zone in which the event occurred.
  1096. * @returns A callback function.
  1097. */
  1098. static eventCallback(fullKey, handler, zone) {
  1099. return (event) => {
  1100. if (KeyEventsPlugin.matchEventFullKeyCode(event, fullKey)) {
  1101. zone.runGuarded(() => handler(event));
  1102. }
  1103. };
  1104. }
  1105. /** @internal */
  1106. static _normalizeKey(keyName) {
  1107. return keyName === 'esc' ? 'escape' : keyName;
  1108. }
  1109. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: KeyEventsPlugin, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  1110. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: KeyEventsPlugin });
  1111. }
  1112. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: KeyEventsPlugin, decorators: [{
  1113. type: Injectable
  1114. }], ctorParameters: () => [{ type: undefined, decorators: [{
  1115. type: Inject,
  1116. args: [DOCUMENT]
  1117. }] }] });
  1118. /**
  1119. * Bootstraps an instance of an Angular application and renders a standalone component as the
  1120. * application's root component. More information about standalone components can be found in [this
  1121. * guide](guide/components/importing).
  1122. *
  1123. * @usageNotes
  1124. * The root component passed into this function *must* be a standalone one (should have the
  1125. * `standalone: true` flag in the `@Component` decorator config).
  1126. *
  1127. * ```angular-ts
  1128. * @Component({
  1129. * standalone: true,
  1130. * template: 'Hello world!'
  1131. * })
  1132. * class RootComponent {}
  1133. *
  1134. * const appRef: ApplicationRef = await bootstrapApplication(RootComponent);
  1135. * ```
  1136. *
  1137. * You can add the list of providers that should be available in the application injector by
  1138. * specifying the `providers` field in an object passed as the second argument:
  1139. *
  1140. * ```ts
  1141. * await bootstrapApplication(RootComponent, {
  1142. * providers: [
  1143. * {provide: BACKEND_URL, useValue: 'https://yourdomain.com/api'}
  1144. * ]
  1145. * });
  1146. * ```
  1147. *
  1148. * The `importProvidersFrom` helper method can be used to collect all providers from any
  1149. * existing NgModule (and transitively from all NgModules that it imports):
  1150. *
  1151. * ```ts
  1152. * await bootstrapApplication(RootComponent, {
  1153. * providers: [
  1154. * importProvidersFrom(SomeNgModule)
  1155. * ]
  1156. * });
  1157. * ```
  1158. *
  1159. * Note: the `bootstrapApplication` method doesn't include [Testability](api/core/Testability) by
  1160. * default. You can add [Testability](api/core/Testability) by getting the list of necessary
  1161. * providers using `provideProtractorTestingSupport()` function and adding them into the `providers`
  1162. * array, for example:
  1163. *
  1164. * ```ts
  1165. * import {provideProtractorTestingSupport} from '@angular/platform-browser';
  1166. *
  1167. * await bootstrapApplication(RootComponent, {providers: [provideProtractorTestingSupport()]});
  1168. * ```
  1169. *
  1170. * @param rootComponent A reference to a standalone component that should be rendered.
  1171. * @param options Extra configuration for the bootstrap operation, see `ApplicationConfig` for
  1172. * additional info.
  1173. * @returns A promise that returns an `ApplicationRef` instance once resolved.
  1174. *
  1175. * @publicApi
  1176. */
  1177. function bootstrapApplication(rootComponent, options) {
  1178. return _internalCreateApplication({ rootComponent, ...createProvidersConfig(options) });
  1179. }
  1180. /**
  1181. * Create an instance of an Angular application without bootstrapping any components. This is useful
  1182. * for the situation where one wants to decouple application environment creation (a platform and
  1183. * associated injectors) from rendering components on a screen. Components can be subsequently
  1184. * bootstrapped on the returned `ApplicationRef`.
  1185. *
  1186. * @param options Extra configuration for the application environment, see `ApplicationConfig` for
  1187. * additional info.
  1188. * @returns A promise that returns an `ApplicationRef` instance once resolved.
  1189. *
  1190. * @publicApi
  1191. */
  1192. function createApplication(options) {
  1193. return _internalCreateApplication(createProvidersConfig(options));
  1194. }
  1195. function createProvidersConfig(options) {
  1196. return {
  1197. appProviders: [...BROWSER_MODULE_PROVIDERS, ...(options?.providers ?? [])],
  1198. platformProviders: INTERNAL_BROWSER_PLATFORM_PROVIDERS,
  1199. };
  1200. }
  1201. /**
  1202. * Returns a set of providers required to setup [Testability](api/core/Testability) for an
  1203. * application bootstrapped using the `bootstrapApplication` function. The set of providers is
  1204. * needed to support testing an application with Protractor (which relies on the Testability APIs
  1205. * to be present).
  1206. *
  1207. * @returns An array of providers required to setup Testability for an application and make it
  1208. * available for testing using Protractor.
  1209. *
  1210. * @publicApi
  1211. */
  1212. function provideProtractorTestingSupport() {
  1213. // Return a copy to prevent changes to the original array in case any in-place
  1214. // alterations are performed to the `provideProtractorTestingSupport` call results in app
  1215. // code.
  1216. return [...TESTABILITY_PROVIDERS];
  1217. }
  1218. function initDomAdapter() {
  1219. BrowserDomAdapter.makeCurrent();
  1220. }
  1221. function errorHandler() {
  1222. return new ErrorHandler();
  1223. }
  1224. function _document() {
  1225. // Tell ivy about the global document
  1226. _setDocument(document);
  1227. return document;
  1228. }
  1229. const INTERNAL_BROWSER_PLATFORM_PROVIDERS = [
  1230. { provide: PLATFORM_ID, useValue: _PLATFORM_BROWSER_ID },
  1231. { provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true },
  1232. { provide: DOCUMENT, useFactory: _document, deps: [] },
  1233. ];
  1234. /**
  1235. * A factory function that returns a `PlatformRef` instance associated with browser service
  1236. * providers.
  1237. *
  1238. * @publicApi
  1239. */
  1240. const platformBrowser = createPlatformFactory(platformCore, 'browser', INTERNAL_BROWSER_PLATFORM_PROVIDERS);
  1241. /**
  1242. * Internal marker to signal whether providers from the `BrowserModule` are already present in DI.
  1243. * This is needed to avoid loading `BrowserModule` providers twice. We can't rely on the
  1244. * `BrowserModule` presence itself, since the standalone-based bootstrap just imports
  1245. * `BrowserModule` providers without referencing the module itself.
  1246. */
  1247. const BROWSER_MODULE_PROVIDERS_MARKER = new InjectionToken(typeof ngDevMode === 'undefined' || ngDevMode ? 'BrowserModule Providers Marker' : '');
  1248. const TESTABILITY_PROVIDERS = [
  1249. {
  1250. provide: _TESTABILITY_GETTER,
  1251. useClass: BrowserGetTestability,
  1252. deps: [],
  1253. },
  1254. {
  1255. provide: _TESTABILITY,
  1256. useClass: Testability,
  1257. deps: [NgZone, TestabilityRegistry, _TESTABILITY_GETTER],
  1258. },
  1259. {
  1260. provide: Testability, // Also provide as `Testability` for backwards-compatibility.
  1261. useClass: Testability,
  1262. deps: [NgZone, TestabilityRegistry, _TESTABILITY_GETTER],
  1263. },
  1264. ];
  1265. const BROWSER_MODULE_PROVIDERS = [
  1266. { provide: _INJECTOR_SCOPE, useValue: 'root' },
  1267. { provide: ErrorHandler, useFactory: errorHandler, deps: [] },
  1268. {
  1269. provide: EVENT_MANAGER_PLUGINS,
  1270. useClass: DomEventsPlugin,
  1271. multi: true,
  1272. deps: [DOCUMENT],
  1273. },
  1274. { provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true, deps: [DOCUMENT] },
  1275. DomRendererFactory2,
  1276. SharedStylesHost,
  1277. EventManager,
  1278. { provide: RendererFactory2, useExisting: DomRendererFactory2 },
  1279. { provide: XhrFactory, useClass: BrowserXhr, deps: [] },
  1280. typeof ngDevMode === 'undefined' || ngDevMode
  1281. ? { provide: BROWSER_MODULE_PROVIDERS_MARKER, useValue: true }
  1282. : [],
  1283. ];
  1284. /**
  1285. * Exports required infrastructure for all Angular apps.
  1286. * Included by default in all Angular apps created with the CLI
  1287. * `new` command.
  1288. * Re-exports `CommonModule` and `ApplicationModule`, making their
  1289. * exports and providers available to all apps.
  1290. *
  1291. * @publicApi
  1292. */
  1293. class BrowserModule {
  1294. constructor() {
  1295. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  1296. const providersAlreadyPresent = inject(BROWSER_MODULE_PROVIDERS_MARKER, {
  1297. optional: true,
  1298. skipSelf: true,
  1299. });
  1300. if (providersAlreadyPresent) {
  1301. throw new _RuntimeError(5100 /* RuntimeErrorCode.BROWSER_MODULE_ALREADY_LOADED */, `Providers from the \`BrowserModule\` have already been loaded. If you need access ` +
  1302. `to common directives such as NgIf and NgFor, import the \`CommonModule\` instead.`);
  1303. }
  1304. }
  1305. }
  1306. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: BrowserModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  1307. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.4", ngImport: i0, type: BrowserModule, exports: [CommonModule, ApplicationModule] });
  1308. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: BrowserModule, providers: [...BROWSER_MODULE_PROVIDERS, ...TESTABILITY_PROVIDERS], imports: [CommonModule, ApplicationModule] });
  1309. }
  1310. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: BrowserModule, decorators: [{
  1311. type: NgModule,
  1312. args: [{
  1313. providers: [...BROWSER_MODULE_PROVIDERS, ...TESTABILITY_PROVIDERS],
  1314. exports: [CommonModule, ApplicationModule],
  1315. }]
  1316. }], ctorParameters: () => [] });
  1317. /**
  1318. * A service for managing HTML `<meta>` tags.
  1319. *
  1320. * Properties of the `MetaDefinition` object match the attributes of the
  1321. * HTML `<meta>` tag. These tags define document metadata that is important for
  1322. * things like configuring a Content Security Policy, defining browser compatibility
  1323. * and security settings, setting HTTP Headers, defining rich content for social sharing,
  1324. * and Search Engine Optimization (SEO).
  1325. *
  1326. * To identify specific `<meta>` tags in a document, use an attribute selection
  1327. * string in the format `"tag_attribute='value string'"`.
  1328. * For example, an `attrSelector` value of `"name='description'"` matches a tag
  1329. * whose `name` attribute has the value `"description"`.
  1330. * Selectors are used with the `querySelector()` Document method,
  1331. * in the format `meta[{attrSelector}]`.
  1332. *
  1333. * @see [HTML meta tag](https://developer.mozilla.org/docs/Web/HTML/Element/meta)
  1334. * @see [Document.querySelector()](https://developer.mozilla.org/docs/Web/API/Document/querySelector)
  1335. *
  1336. *
  1337. * @publicApi
  1338. */
  1339. class Meta {
  1340. _doc;
  1341. _dom;
  1342. constructor(_doc) {
  1343. this._doc = _doc;
  1344. this._dom = _getDOM();
  1345. }
  1346. /**
  1347. * Retrieves or creates a specific `<meta>` tag element in the current HTML document.
  1348. * In searching for an existing tag, Angular attempts to match the `name` or `property` attribute
  1349. * values in the provided tag definition, and verifies that all other attribute values are equal.
  1350. * If an existing element is found, it is returned and is not modified in any way.
  1351. * @param tag The definition of a `<meta>` element to match or create.
  1352. * @param forceCreation True to create a new element without checking whether one already exists.
  1353. * @returns The existing element with the same attributes and values if found,
  1354. * the new element if no match is found, or `null` if the tag parameter is not defined.
  1355. */
  1356. addTag(tag, forceCreation = false) {
  1357. if (!tag)
  1358. return null;
  1359. return this._getOrCreateElement(tag, forceCreation);
  1360. }
  1361. /**
  1362. * Retrieves or creates a set of `<meta>` tag elements in the current HTML document.
  1363. * In searching for an existing tag, Angular attempts to match the `name` or `property` attribute
  1364. * values in the provided tag definition, and verifies that all other attribute values are equal.
  1365. * @param tags An array of tag definitions to match or create.
  1366. * @param forceCreation True to create new elements without checking whether they already exist.
  1367. * @returns The matching elements if found, or the new elements.
  1368. */
  1369. addTags(tags, forceCreation = false) {
  1370. if (!tags)
  1371. return [];
  1372. return tags.reduce((result, tag) => {
  1373. if (tag) {
  1374. result.push(this._getOrCreateElement(tag, forceCreation));
  1375. }
  1376. return result;
  1377. }, []);
  1378. }
  1379. /**
  1380. * Retrieves a `<meta>` tag element in the current HTML document.
  1381. * @param attrSelector The tag attribute and value to match against, in the format
  1382. * `"tag_attribute='value string'"`.
  1383. * @returns The matching element, if any.
  1384. */
  1385. getTag(attrSelector) {
  1386. if (!attrSelector)
  1387. return null;
  1388. return this._doc.querySelector(`meta[${attrSelector}]`) || null;
  1389. }
  1390. /**
  1391. * Retrieves a set of `<meta>` tag elements in the current HTML document.
  1392. * @param attrSelector The tag attribute and value to match against, in the format
  1393. * `"tag_attribute='value string'"`.
  1394. * @returns The matching elements, if any.
  1395. */
  1396. getTags(attrSelector) {
  1397. if (!attrSelector)
  1398. return [];
  1399. const list /*NodeList*/ = this._doc.querySelectorAll(`meta[${attrSelector}]`);
  1400. return list ? [].slice.call(list) : [];
  1401. }
  1402. /**
  1403. * Modifies an existing `<meta>` tag element in the current HTML document.
  1404. * @param tag The tag description with which to replace the existing tag content.
  1405. * @param selector A tag attribute and value to match against, to identify
  1406. * an existing tag. A string in the format `"tag_attribute=`value string`"`.
  1407. * If not supplied, matches a tag with the same `name` or `property` attribute value as the
  1408. * replacement tag.
  1409. * @return The modified element.
  1410. */
  1411. updateTag(tag, selector) {
  1412. if (!tag)
  1413. return null;
  1414. selector = selector || this._parseSelector(tag);
  1415. const meta = this.getTag(selector);
  1416. if (meta) {
  1417. return this._setMetaElementAttributes(tag, meta);
  1418. }
  1419. return this._getOrCreateElement(tag, true);
  1420. }
  1421. /**
  1422. * Removes an existing `<meta>` tag element from the current HTML document.
  1423. * @param attrSelector A tag attribute and value to match against, to identify
  1424. * an existing tag. A string in the format `"tag_attribute=`value string`"`.
  1425. */
  1426. removeTag(attrSelector) {
  1427. this.removeTagElement(this.getTag(attrSelector));
  1428. }
  1429. /**
  1430. * Removes an existing `<meta>` tag element from the current HTML document.
  1431. * @param meta The tag definition to match against to identify an existing tag.
  1432. */
  1433. removeTagElement(meta) {
  1434. if (meta) {
  1435. this._dom.remove(meta);
  1436. }
  1437. }
  1438. _getOrCreateElement(meta, forceCreation = false) {
  1439. if (!forceCreation) {
  1440. const selector = this._parseSelector(meta);
  1441. // It's allowed to have multiple elements with the same name so it's not enough to
  1442. // just check that element with the same name already present on the page. We also need to
  1443. // check if element has tag attributes
  1444. const elem = this.getTags(selector).filter((elem) => this._containsAttributes(meta, elem))[0];
  1445. if (elem !== undefined)
  1446. return elem;
  1447. }
  1448. const element = this._dom.createElement('meta');
  1449. this._setMetaElementAttributes(meta, element);
  1450. const head = this._doc.getElementsByTagName('head')[0];
  1451. head.appendChild(element);
  1452. return element;
  1453. }
  1454. _setMetaElementAttributes(tag, el) {
  1455. Object.keys(tag).forEach((prop) => el.setAttribute(this._getMetaKeyMap(prop), tag[prop]));
  1456. return el;
  1457. }
  1458. _parseSelector(tag) {
  1459. const attr = tag.name ? 'name' : 'property';
  1460. return `${attr}="${tag[attr]}"`;
  1461. }
  1462. _containsAttributes(tag, elem) {
  1463. return Object.keys(tag).every((key) => elem.getAttribute(this._getMetaKeyMap(key)) === tag[key]);
  1464. }
  1465. _getMetaKeyMap(prop) {
  1466. return META_KEYS_MAP[prop] || prop;
  1467. }
  1468. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: Meta, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  1469. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: Meta, providedIn: 'root' });
  1470. }
  1471. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: Meta, decorators: [{
  1472. type: Injectable,
  1473. args: [{ providedIn: 'root' }]
  1474. }], ctorParameters: () => [{ type: undefined, decorators: [{
  1475. type: Inject,
  1476. args: [DOCUMENT]
  1477. }] }] });
  1478. /**
  1479. * Mapping for MetaDefinition properties with their correct meta attribute names
  1480. */
  1481. const META_KEYS_MAP = {
  1482. httpEquiv: 'http-equiv',
  1483. };
  1484. /**
  1485. * A service that can be used to get and set the title of a current HTML document.
  1486. *
  1487. * Since an Angular application can't be bootstrapped on the entire HTML document (`<html>` tag)
  1488. * it is not possible to bind to the `text` property of the `HTMLTitleElement` elements
  1489. * (representing the `<title>` tag). Instead, this service can be used to set and get the current
  1490. * title value.
  1491. *
  1492. * @publicApi
  1493. */
  1494. class Title {
  1495. _doc;
  1496. constructor(_doc) {
  1497. this._doc = _doc;
  1498. }
  1499. /**
  1500. * Get the title of the current HTML document.
  1501. */
  1502. getTitle() {
  1503. return this._doc.title;
  1504. }
  1505. /**
  1506. * Set the title of the current HTML document.
  1507. * @param newTitle
  1508. */
  1509. setTitle(newTitle) {
  1510. this._doc.title = newTitle || '';
  1511. }
  1512. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: Title, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  1513. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: Title, providedIn: 'root' });
  1514. }
  1515. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: Title, decorators: [{
  1516. type: Injectable,
  1517. args: [{ providedIn: 'root' }]
  1518. }], ctorParameters: () => [{ type: undefined, decorators: [{
  1519. type: Inject,
  1520. args: [DOCUMENT]
  1521. }] }] });
  1522. /**
  1523. * Exports the value under a given `name` in the global property `ng`. For example `ng.probe` if
  1524. * `name` is `'probe'`.
  1525. * @param name Name under which it will be exported. Keep in mind this will be a property of the
  1526. * global `ng` object.
  1527. * @param value The value to export.
  1528. */
  1529. function exportNgVar(name, value) {
  1530. if (typeof COMPILED === 'undefined' || !COMPILED) {
  1531. // Note: we can't export `ng` when using closure enhanced optimization as:
  1532. // - closure declares globals itself for minified names, which sometimes clobber our `ng` global
  1533. // - we can't declare a closure extern as the namespace `ng` is already used within Google
  1534. // for typings for angularJS (via `goog.provide('ng....')`).
  1535. const ng = (_global['ng'] = _global['ng'] || {});
  1536. ng[name] = value;
  1537. }
  1538. }
  1539. class ChangeDetectionPerfRecord {
  1540. msPerTick;
  1541. numTicks;
  1542. constructor(msPerTick, numTicks) {
  1543. this.msPerTick = msPerTick;
  1544. this.numTicks = numTicks;
  1545. }
  1546. }
  1547. /**
  1548. * Entry point for all Angular profiling-related debug tools. This object
  1549. * corresponds to the `ng.profiler` in the dev console.
  1550. */
  1551. class AngularProfiler {
  1552. appRef;
  1553. constructor(ref) {
  1554. this.appRef = ref.injector.get(ApplicationRef);
  1555. }
  1556. // tslint:disable:no-console
  1557. /**
  1558. * Exercises change detection in a loop and then prints the average amount of
  1559. * time in milliseconds how long a single round of change detection takes for
  1560. * the current state of the UI. It runs a minimum of 5 rounds for a minimum
  1561. * of 500 milliseconds.
  1562. *
  1563. * Optionally, a user may pass a `config` parameter containing a map of
  1564. * options. Supported options are:
  1565. *
  1566. * `record` (boolean) - causes the profiler to record a CPU profile while
  1567. * it exercises the change detector. Example:
  1568. *
  1569. * ```ts
  1570. * ng.profiler.timeChangeDetection({record: true})
  1571. * ```
  1572. */
  1573. timeChangeDetection(config) {
  1574. const record = config && config['record'];
  1575. const profileName = 'Change Detection';
  1576. // Profiler is not available in Android browsers without dev tools opened
  1577. if (record && 'profile' in console && typeof console.profile === 'function') {
  1578. console.profile(profileName);
  1579. }
  1580. const start = performance.now();
  1581. let numTicks = 0;
  1582. while (numTicks < 5 || performance.now() - start < 500) {
  1583. this.appRef.tick();
  1584. numTicks++;
  1585. }
  1586. const end = performance.now();
  1587. if (record && 'profileEnd' in console && typeof console.profileEnd === 'function') {
  1588. console.profileEnd(profileName);
  1589. }
  1590. const msPerTick = (end - start) / numTicks;
  1591. console.log(`ran ${numTicks} change detection cycles`);
  1592. console.log(`${msPerTick.toFixed(2)} ms per check`);
  1593. return new ChangeDetectionPerfRecord(msPerTick, numTicks);
  1594. }
  1595. }
  1596. const PROFILER_GLOBAL_NAME = 'profiler';
  1597. /**
  1598. * Enabled Angular debug tools that are accessible via your browser's
  1599. * developer console.
  1600. *
  1601. * Usage:
  1602. *
  1603. * 1. Open developer console (e.g. in Chrome Ctrl + Shift + j)
  1604. * 1. Type `ng.` (usually the console will show auto-complete suggestion)
  1605. * 1. Try the change detection profiler `ng.profiler.timeChangeDetection()`
  1606. * then hit Enter.
  1607. *
  1608. * @publicApi
  1609. */
  1610. function enableDebugTools(ref) {
  1611. exportNgVar(PROFILER_GLOBAL_NAME, new AngularProfiler(ref));
  1612. return ref;
  1613. }
  1614. /**
  1615. * Disables Angular tools.
  1616. *
  1617. * @publicApi
  1618. */
  1619. function disableDebugTools() {
  1620. exportNgVar(PROFILER_GLOBAL_NAME, null);
  1621. }
  1622. /**
  1623. * Predicates for use with {@link DebugElement}'s query functions.
  1624. *
  1625. * @publicApi
  1626. */
  1627. class By {
  1628. /**
  1629. * Match all nodes.
  1630. *
  1631. * @usageNotes
  1632. * ### Example
  1633. *
  1634. * {@example platform-browser/dom/debug/ts/by/by.ts region='by_all'}
  1635. */
  1636. static all() {
  1637. return () => true;
  1638. }
  1639. /**
  1640. * Match elements by the given CSS selector.
  1641. *
  1642. * @usageNotes
  1643. * ### Example
  1644. *
  1645. * {@example platform-browser/dom/debug/ts/by/by.ts region='by_css'}
  1646. */
  1647. static css(selector) {
  1648. return (debugElement) => {
  1649. return debugElement.nativeElement != null
  1650. ? elementMatches(debugElement.nativeElement, selector)
  1651. : false;
  1652. };
  1653. }
  1654. /**
  1655. * Match nodes that have the given directive present.
  1656. *
  1657. * @usageNotes
  1658. * ### Example
  1659. *
  1660. * {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'}
  1661. */
  1662. static directive(type) {
  1663. return (debugNode) => debugNode.providerTokens.indexOf(type) !== -1;
  1664. }
  1665. }
  1666. function elementMatches(n, selector) {
  1667. if (_getDOM().isElementNode(n)) {
  1668. return ((n.matches && n.matches(selector)) ||
  1669. (n.msMatchesSelector && n.msMatchesSelector(selector)) ||
  1670. (n.webkitMatchesSelector && n.webkitMatchesSelector(selector)));
  1671. }
  1672. return false;
  1673. }
  1674. /**
  1675. * Supported HammerJS recognizer event names.
  1676. */
  1677. const EVENT_NAMES = {
  1678. // pan
  1679. 'pan': true,
  1680. 'panstart': true,
  1681. 'panmove': true,
  1682. 'panend': true,
  1683. 'pancancel': true,
  1684. 'panleft': true,
  1685. 'panright': true,
  1686. 'panup': true,
  1687. 'pandown': true,
  1688. // pinch
  1689. 'pinch': true,
  1690. 'pinchstart': true,
  1691. 'pinchmove': true,
  1692. 'pinchend': true,
  1693. 'pinchcancel': true,
  1694. 'pinchin': true,
  1695. 'pinchout': true,
  1696. // press
  1697. 'press': true,
  1698. 'pressup': true,
  1699. // rotate
  1700. 'rotate': true,
  1701. 'rotatestart': true,
  1702. 'rotatemove': true,
  1703. 'rotateend': true,
  1704. 'rotatecancel': true,
  1705. // swipe
  1706. 'swipe': true,
  1707. 'swipeleft': true,
  1708. 'swiperight': true,
  1709. 'swipeup': true,
  1710. 'swipedown': true,
  1711. // tap
  1712. 'tap': true,
  1713. 'doubletap': true,
  1714. };
  1715. /**
  1716. * DI token for providing [HammerJS](https://hammerjs.github.io/) support to Angular.
  1717. * @see {@link HammerGestureConfig}
  1718. *
  1719. * @ngModule HammerModule
  1720. * @publicApi
  1721. */
  1722. const HAMMER_GESTURE_CONFIG = new InjectionToken(typeof ngDevMode === 'undefined' || ngDevMode ? 'HammerGestureConfig' : '');
  1723. /**
  1724. * Injection token used to provide a HammerLoader to Angular.
  1725. *
  1726. * @see {@link HammerLoader}
  1727. *
  1728. * @publicApi
  1729. */
  1730. const HAMMER_LOADER = new InjectionToken(typeof ngDevMode === 'undefined' || ngDevMode ? 'HammerLoader' : '');
  1731. /**
  1732. * An injectable [HammerJS Manager](https://hammerjs.github.io/api/#hammermanager)
  1733. * for gesture recognition. Configures specific event recognition.
  1734. * @publicApi
  1735. */
  1736. class HammerGestureConfig {
  1737. /**
  1738. * A set of supported event names for gestures to be used in Angular.
  1739. * Angular supports all built-in recognizers, as listed in
  1740. * [HammerJS documentation](https://hammerjs.github.io/).
  1741. */
  1742. events = [];
  1743. /**
  1744. * Maps gesture event names to a set of configuration options
  1745. * that specify overrides to the default values for specific properties.
  1746. *
  1747. * The key is a supported event name to be configured,
  1748. * and the options object contains a set of properties, with override values
  1749. * to be applied to the named recognizer event.
  1750. * For example, to disable recognition of the rotate event, specify
  1751. * `{"rotate": {"enable": false}}`.
  1752. *
  1753. * Properties that are not present take the HammerJS default values.
  1754. * For information about which properties are supported for which events,
  1755. * and their allowed and default values, see
  1756. * [HammerJS documentation](https://hammerjs.github.io/).
  1757. *
  1758. */
  1759. overrides = {};
  1760. /**
  1761. * Properties whose default values can be overridden for a given event.
  1762. * Different sets of properties apply to different events.
  1763. * For information about which properties are supported for which events,
  1764. * and their allowed and default values, see
  1765. * [HammerJS documentation](https://hammerjs.github.io/).
  1766. */
  1767. options;
  1768. /**
  1769. * Creates a [HammerJS Manager](https://hammerjs.github.io/api/#hammermanager)
  1770. * and attaches it to a given HTML element.
  1771. * @param element The element that will recognize gestures.
  1772. * @returns A HammerJS event-manager object.
  1773. */
  1774. buildHammer(element) {
  1775. const mc = new Hammer(element, this.options);
  1776. mc.get('pinch').set({ enable: true });
  1777. mc.get('rotate').set({ enable: true });
  1778. for (const eventName in this.overrides) {
  1779. mc.get(eventName).set(this.overrides[eventName]);
  1780. }
  1781. return mc;
  1782. }
  1783. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerGestureConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  1784. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerGestureConfig });
  1785. }
  1786. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerGestureConfig, decorators: [{
  1787. type: Injectable
  1788. }] });
  1789. /**
  1790. * Event plugin that adds Hammer support to an application.
  1791. *
  1792. * @ngModule HammerModule
  1793. */
  1794. class HammerGesturesPlugin extends EventManagerPlugin {
  1795. _config;
  1796. _injector;
  1797. loader;
  1798. _loaderPromise = null;
  1799. constructor(doc, _config, _injector, loader) {
  1800. super(doc);
  1801. this._config = _config;
  1802. this._injector = _injector;
  1803. this.loader = loader;
  1804. }
  1805. supports(eventName) {
  1806. if (!EVENT_NAMES.hasOwnProperty(eventName.toLowerCase()) && !this.isCustomEvent(eventName)) {
  1807. return false;
  1808. }
  1809. if (!window.Hammer && !this.loader) {
  1810. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  1811. // Get a `Console` through an injector to tree-shake the
  1812. // class when it is unused in production.
  1813. const _console = this._injector.get(_Console);
  1814. _console.warn(`The "${eventName}" event cannot be bound because Hammer.JS is not ` +
  1815. `loaded and no custom loader has been specified.`);
  1816. }
  1817. return false;
  1818. }
  1819. return true;
  1820. }
  1821. addEventListener(element, eventName, handler) {
  1822. const zone = this.manager.getZone();
  1823. eventName = eventName.toLowerCase();
  1824. // If Hammer is not present but a loader is specified, we defer adding the event listener
  1825. // until Hammer is loaded.
  1826. if (!window.Hammer && this.loader) {
  1827. this._loaderPromise = this._loaderPromise || zone.runOutsideAngular(() => this.loader());
  1828. // This `addEventListener` method returns a function to remove the added listener.
  1829. // Until Hammer is loaded, the returned function needs to *cancel* the registration rather
  1830. // than remove anything.
  1831. let cancelRegistration = false;
  1832. let deregister = () => {
  1833. cancelRegistration = true;
  1834. };
  1835. zone.runOutsideAngular(() => this._loaderPromise.then(() => {
  1836. // If Hammer isn't actually loaded when the custom loader resolves, give up.
  1837. if (!window.Hammer) {
  1838. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  1839. const _console = this._injector.get(_Console);
  1840. _console.warn(`The custom HAMMER_LOADER completed, but Hammer.JS is not present.`);
  1841. }
  1842. deregister = () => { };
  1843. return;
  1844. }
  1845. if (!cancelRegistration) {
  1846. // Now that Hammer is loaded and the listener is being loaded for real,
  1847. // the deregistration function changes from canceling registration to
  1848. // removal.
  1849. deregister = this.addEventListener(element, eventName, handler);
  1850. }
  1851. }).catch(() => {
  1852. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  1853. const _console = this._injector.get(_Console);
  1854. _console.warn(`The "${eventName}" event cannot be bound because the custom ` +
  1855. `Hammer.JS loader failed.`);
  1856. }
  1857. deregister = () => { };
  1858. }));
  1859. // Return a function that *executes* `deregister` (and not `deregister` itself) so that we
  1860. // can change the behavior of `deregister` once the listener is added. Using a closure in
  1861. // this way allows us to avoid any additional data structures to track listener removal.
  1862. return () => {
  1863. deregister();
  1864. };
  1865. }
  1866. return zone.runOutsideAngular(() => {
  1867. // Creating the manager bind events, must be done outside of angular
  1868. const mc = this._config.buildHammer(element);
  1869. const callback = function (eventObj) {
  1870. zone.runGuarded(function () {
  1871. handler(eventObj);
  1872. });
  1873. };
  1874. mc.on(eventName, callback);
  1875. return () => {
  1876. mc.off(eventName, callback);
  1877. // destroy mc to prevent memory leak
  1878. if (typeof mc.destroy === 'function') {
  1879. mc.destroy();
  1880. }
  1881. };
  1882. });
  1883. }
  1884. isCustomEvent(eventName) {
  1885. return this._config.events.indexOf(eventName) > -1;
  1886. }
  1887. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerGesturesPlugin, deps: [{ token: DOCUMENT }, { token: HAMMER_GESTURE_CONFIG }, { token: i0.Injector }, { token: HAMMER_LOADER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
  1888. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerGesturesPlugin });
  1889. }
  1890. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerGesturesPlugin, decorators: [{
  1891. type: Injectable
  1892. }], ctorParameters: () => [{ type: undefined, decorators: [{
  1893. type: Inject,
  1894. args: [DOCUMENT]
  1895. }] }, { type: HammerGestureConfig, decorators: [{
  1896. type: Inject,
  1897. args: [HAMMER_GESTURE_CONFIG]
  1898. }] }, { type: i0.Injector }, { type: undefined, decorators: [{
  1899. type: Optional
  1900. }, {
  1901. type: Inject,
  1902. args: [HAMMER_LOADER]
  1903. }] }] });
  1904. /**
  1905. * Adds support for HammerJS.
  1906. *
  1907. * Import this module at the root of your application so that Angular can work with
  1908. * HammerJS to detect gesture events.
  1909. *
  1910. * Note that applications still need to include the HammerJS script itself. This module
  1911. * simply sets up the coordination layer between HammerJS and Angular's `EventManager`.
  1912. *
  1913. * @publicApi
  1914. */
  1915. class HammerModule {
  1916. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  1917. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.4", ngImport: i0, type: HammerModule });
  1918. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerModule, providers: [
  1919. {
  1920. provide: EVENT_MANAGER_PLUGINS,
  1921. useClass: HammerGesturesPlugin,
  1922. multi: true,
  1923. deps: [DOCUMENT, HAMMER_GESTURE_CONFIG, Injector, [new Optional(), HAMMER_LOADER]],
  1924. },
  1925. { provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig, deps: [] },
  1926. ] });
  1927. }
  1928. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: HammerModule, decorators: [{
  1929. type: NgModule,
  1930. args: [{
  1931. providers: [
  1932. {
  1933. provide: EVENT_MANAGER_PLUGINS,
  1934. useClass: HammerGesturesPlugin,
  1935. multi: true,
  1936. deps: [DOCUMENT, HAMMER_GESTURE_CONFIG, Injector, [new Optional(), HAMMER_LOADER]],
  1937. },
  1938. { provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig, deps: [] },
  1939. ],
  1940. }]
  1941. }] });
  1942. /**
  1943. * DomSanitizer helps preventing Cross Site Scripting Security bugs (XSS) by sanitizing
  1944. * values to be safe to use in the different DOM contexts.
  1945. *
  1946. * For example, when binding a URL in an `<a [href]="someValue">` hyperlink, `someValue` will be
  1947. * sanitized so that an attacker cannot inject e.g. a `javascript:` URL that would execute code on
  1948. * the website.
  1949. *
  1950. * In specific situations, it might be necessary to disable sanitization, for example if the
  1951. * application genuinely needs to produce a `javascript:` style link with a dynamic value in it.
  1952. * Users can bypass security by constructing a value with one of the `bypassSecurityTrust...`
  1953. * methods, and then binding to that value from the template.
  1954. *
  1955. * These situations should be very rare, and extraordinary care must be taken to avoid creating a
  1956. * Cross Site Scripting (XSS) security bug!
  1957. *
  1958. * When using `bypassSecurityTrust...`, make sure to call the method as early as possible and as
  1959. * close as possible to the source of the value, to make it easy to verify no security bug is
  1960. * created by its use.
  1961. *
  1962. * It is not required (and not recommended) to bypass security if the value is safe, e.g. a URL that
  1963. * does not start with a suspicious protocol, or an HTML snippet that does not contain dangerous
  1964. * code. The sanitizer leaves safe values intact.
  1965. *
  1966. * @security Calling any of the `bypassSecurityTrust...` APIs disables Angular's built-in
  1967. * sanitization for the value passed in. Carefully check and audit all values and code paths going
  1968. * into this call. Make sure any user data is appropriately escaped for this security context.
  1969. * For more detail, see the [Security Guide](https://g.co/ng/security).
  1970. *
  1971. * @publicApi
  1972. */
  1973. class DomSanitizer {
  1974. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomSanitizer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  1975. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomSanitizer, providedIn: 'root', useExisting: i0.forwardRef(() => DomSanitizerImpl) });
  1976. }
  1977. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomSanitizer, decorators: [{
  1978. type: Injectable,
  1979. args: [{ providedIn: 'root', useExisting: forwardRef(() => DomSanitizerImpl) }]
  1980. }] });
  1981. class DomSanitizerImpl extends DomSanitizer {
  1982. _doc;
  1983. constructor(_doc) {
  1984. super();
  1985. this._doc = _doc;
  1986. }
  1987. sanitize(ctx, value) {
  1988. if (value == null)
  1989. return null;
  1990. switch (ctx) {
  1991. case SecurityContext.NONE:
  1992. return value;
  1993. case SecurityContext.HTML:
  1994. if (_allowSanitizationBypassAndThrow(value, "HTML" /* BypassType.Html */)) {
  1995. return _unwrapSafeValue(value);
  1996. }
  1997. return __sanitizeHtml(this._doc, String(value)).toString();
  1998. case SecurityContext.STYLE:
  1999. if (_allowSanitizationBypassAndThrow(value, "Style" /* BypassType.Style */)) {
  2000. return _unwrapSafeValue(value);
  2001. }
  2002. return value;
  2003. case SecurityContext.SCRIPT:
  2004. if (_allowSanitizationBypassAndThrow(value, "Script" /* BypassType.Script */)) {
  2005. return _unwrapSafeValue(value);
  2006. }
  2007. throw new _RuntimeError(5200 /* RuntimeErrorCode.SANITIZATION_UNSAFE_SCRIPT */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  2008. 'unsafe value used in a script context');
  2009. case SecurityContext.URL:
  2010. if (_allowSanitizationBypassAndThrow(value, "URL" /* BypassType.Url */)) {
  2011. return _unwrapSafeValue(value);
  2012. }
  2013. return __sanitizeUrl(String(value));
  2014. case SecurityContext.RESOURCE_URL:
  2015. if (_allowSanitizationBypassAndThrow(value, "ResourceURL" /* BypassType.ResourceUrl */)) {
  2016. return _unwrapSafeValue(value);
  2017. }
  2018. throw new _RuntimeError(5201 /* RuntimeErrorCode.SANITIZATION_UNSAFE_RESOURCE_URL */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  2019. `unsafe value used in a resource URL context (see ${_XSS_SECURITY_URL})`);
  2020. default:
  2021. throw new _RuntimeError(5202 /* RuntimeErrorCode.SANITIZATION_UNEXPECTED_CTX */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  2022. `Unexpected SecurityContext ${ctx} (see ${_XSS_SECURITY_URL})`);
  2023. }
  2024. }
  2025. bypassSecurityTrustHtml(value) {
  2026. return _bypassSanitizationTrustHtml(value);
  2027. }
  2028. bypassSecurityTrustStyle(value) {
  2029. return _bypassSanitizationTrustStyle(value);
  2030. }
  2031. bypassSecurityTrustScript(value) {
  2032. return _bypassSanitizationTrustScript(value);
  2033. }
  2034. bypassSecurityTrustUrl(value) {
  2035. return _bypassSanitizationTrustUrl(value);
  2036. }
  2037. bypassSecurityTrustResourceUrl(value) {
  2038. return _bypassSanitizationTrustResourceUrl(value);
  2039. }
  2040. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomSanitizerImpl, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  2041. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomSanitizerImpl, providedIn: 'root' });
  2042. }
  2043. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: DomSanitizerImpl, decorators: [{
  2044. type: Injectable,
  2045. args: [{ providedIn: 'root' }]
  2046. }], ctorParameters: () => [{ type: undefined, decorators: [{
  2047. type: Inject,
  2048. args: [DOCUMENT]
  2049. }] }] });
  2050. /**
  2051. * The list of features as an enum to uniquely type each `HydrationFeature`.
  2052. * @see {@link HydrationFeature}
  2053. *
  2054. * @publicApi
  2055. */
  2056. var HydrationFeatureKind;
  2057. (function (HydrationFeatureKind) {
  2058. HydrationFeatureKind[HydrationFeatureKind["NoHttpTransferCache"] = 0] = "NoHttpTransferCache";
  2059. HydrationFeatureKind[HydrationFeatureKind["HttpTransferCacheOptions"] = 1] = "HttpTransferCacheOptions";
  2060. HydrationFeatureKind[HydrationFeatureKind["I18nSupport"] = 2] = "I18nSupport";
  2061. HydrationFeatureKind[HydrationFeatureKind["EventReplay"] = 3] = "EventReplay";
  2062. HydrationFeatureKind[HydrationFeatureKind["IncrementalHydration"] = 4] = "IncrementalHydration";
  2063. })(HydrationFeatureKind || (HydrationFeatureKind = {}));
  2064. /**
  2065. * Helper function to create an object that represents a Hydration feature.
  2066. */
  2067. function hydrationFeature(ɵkind, ɵproviders = [], ɵoptions = {}) {
  2068. return { ɵkind, ɵproviders };
  2069. }
  2070. /**
  2071. * Disables HTTP transfer cache. Effectively causes HTTP requests to be performed twice: once on the
  2072. * server and other one on the browser.
  2073. *
  2074. * @publicApi
  2075. */
  2076. function withNoHttpTransferCache() {
  2077. // This feature has no providers and acts as a flag that turns off
  2078. // HTTP transfer cache (which otherwise is turned on by default).
  2079. return hydrationFeature(HydrationFeatureKind.NoHttpTransferCache);
  2080. }
  2081. /**
  2082. * The function accepts an object, which allows to configure cache parameters,
  2083. * such as which headers should be included (no headers are included by default),
  2084. * whether POST requests should be cached or a callback function to determine if a
  2085. * particular request should be cached.
  2086. *
  2087. * @publicApi
  2088. */
  2089. function withHttpTransferCacheOptions(options) {
  2090. // This feature has no providers and acts as a flag to pass options to the HTTP transfer cache.
  2091. return hydrationFeature(HydrationFeatureKind.HttpTransferCacheOptions, _withHttpTransferCache(options));
  2092. }
  2093. /**
  2094. * Enables support for hydrating i18n blocks.
  2095. *
  2096. * @developerPreview
  2097. * @publicApi
  2098. */
  2099. function withI18nSupport() {
  2100. return hydrationFeature(HydrationFeatureKind.I18nSupport, _withI18nSupport());
  2101. }
  2102. /**
  2103. * Enables support for replaying user events (e.g. `click`s) that happened on a page
  2104. * before hydration logic has completed. Once an application is hydrated, all captured
  2105. * events are replayed and relevant event listeners are executed.
  2106. *
  2107. * @usageNotes
  2108. *
  2109. * Basic example of how you can enable event replay in your application when
  2110. * `bootstrapApplication` function is used:
  2111. * ```ts
  2112. * bootstrapApplication(AppComponent, {
  2113. * providers: [provideClientHydration(withEventReplay())]
  2114. * });
  2115. * ```
  2116. * @publicApi
  2117. * @see {@link provideClientHydration}
  2118. */
  2119. function withEventReplay() {
  2120. return hydrationFeature(HydrationFeatureKind.EventReplay, _withEventReplay());
  2121. }
  2122. /**
  2123. * Enables support for incremental hydration using the `hydrate` trigger syntax.
  2124. *
  2125. * @usageNotes
  2126. *
  2127. * Basic example of how you can enable incremental hydration in your application when
  2128. * the `bootstrapApplication` function is used:
  2129. * ```ts
  2130. * bootstrapApplication(AppComponent, {
  2131. * providers: [provideClientHydration(withIncrementalHydration())]
  2132. * });
  2133. * ```
  2134. * @experimental
  2135. * @publicApi
  2136. * @see {@link provideClientHydration}
  2137. */
  2138. function withIncrementalHydration() {
  2139. return hydrationFeature(HydrationFeatureKind.IncrementalHydration, _withIncrementalHydration());
  2140. }
  2141. /**
  2142. * Returns an `ENVIRONMENT_INITIALIZER` token setup with a function
  2143. * that verifies whether compatible ZoneJS was used in an application
  2144. * and logs a warning in a console if it's not the case.
  2145. */
  2146. function provideZoneJsCompatibilityDetector() {
  2147. return [
  2148. {
  2149. provide: ENVIRONMENT_INITIALIZER,
  2150. useValue: () => {
  2151. const ngZone = inject(NgZone);
  2152. const isZoneless = inject(_ZONELESS_ENABLED);
  2153. // Checking `ngZone instanceof NgZone` would be insufficient here,
  2154. // because custom implementations might use NgZone as a base class.
  2155. if (!isZoneless && ngZone.constructor !== NgZone) {
  2156. const console = inject(_Console);
  2157. const message = _formatRuntimeError(-5e3 /* RuntimeErrorCode.UNSUPPORTED_ZONEJS_INSTANCE */, 'Angular detected that hydration was enabled for an application ' +
  2158. 'that uses a custom or a noop Zone.js implementation. ' +
  2159. 'This is not yet a fully supported configuration.');
  2160. console.warn(message);
  2161. }
  2162. },
  2163. multi: true,
  2164. },
  2165. ];
  2166. }
  2167. /**
  2168. * Sets up providers necessary to enable hydration functionality for the application.
  2169. *
  2170. * By default, the function enables the recommended set of features for the optimal
  2171. * performance for most of the applications. It includes the following features:
  2172. *
  2173. * * Reconciling DOM hydration. Learn more about it [here](guide/hydration).
  2174. * * [`HttpClient`](api/common/http/HttpClient) response caching while running on the server and
  2175. * transferring this cache to the client to avoid extra HTTP requests. Learn more about data caching
  2176. * [here](guide/ssr#caching-data-when-using-httpclient).
  2177. *
  2178. * These functions allow you to disable some of the default features or enable new ones:
  2179. *
  2180. * * {@link withNoHttpTransferCache} to disable HTTP transfer cache
  2181. * * {@link withHttpTransferCacheOptions} to configure some HTTP transfer cache options
  2182. * * {@link withI18nSupport} to enable hydration support for i18n blocks
  2183. * * {@link withEventReplay} to enable support for replaying user events
  2184. *
  2185. * @usageNotes
  2186. *
  2187. * Basic example of how you can enable hydration in your application when
  2188. * `bootstrapApplication` function is used:
  2189. * ```ts
  2190. * bootstrapApplication(AppComponent, {
  2191. * providers: [provideClientHydration()]
  2192. * });
  2193. * ```
  2194. *
  2195. * Alternatively if you are using NgModules, you would add `provideClientHydration`
  2196. * to your root app module's provider list.
  2197. * ```ts
  2198. * @NgModule({
  2199. * declarations: [RootCmp],
  2200. * bootstrap: [RootCmp],
  2201. * providers: [provideClientHydration()],
  2202. * })
  2203. * export class AppModule {}
  2204. * ```
  2205. *
  2206. * @see {@link withNoHttpTransferCache}
  2207. * @see {@link withHttpTransferCacheOptions}
  2208. * @see {@link withI18nSupport}
  2209. * @see {@link withEventReplay}
  2210. *
  2211. * @param features Optional features to configure additional hydration behaviors.
  2212. * @returns A set of providers to enable hydration.
  2213. *
  2214. * @publicApi
  2215. */
  2216. function provideClientHydration(...features) {
  2217. const providers = [];
  2218. const featuresKind = new Set();
  2219. const hasHttpTransferCacheOptions = featuresKind.has(HydrationFeatureKind.HttpTransferCacheOptions);
  2220. for (const { ɵproviders, ɵkind } of features) {
  2221. featuresKind.add(ɵkind);
  2222. if (ɵproviders.length) {
  2223. providers.push(ɵproviders);
  2224. }
  2225. }
  2226. if (typeof ngDevMode !== 'undefined' &&
  2227. ngDevMode &&
  2228. featuresKind.has(HydrationFeatureKind.NoHttpTransferCache) &&
  2229. hasHttpTransferCacheOptions) {
  2230. // TODO: Make this a runtime error
  2231. throw new Error('Configuration error: found both withHttpTransferCacheOptions() and withNoHttpTransferCache() in the same call to provideClientHydration(), which is a contradiction.');
  2232. }
  2233. return makeEnvironmentProviders([
  2234. typeof ngDevMode !== 'undefined' && ngDevMode ? provideZoneJsCompatibilityDetector() : [],
  2235. _withDomHydration(),
  2236. featuresKind.has(HydrationFeatureKind.NoHttpTransferCache) || hasHttpTransferCacheOptions
  2237. ? []
  2238. : _withHttpTransferCache({}),
  2239. providers,
  2240. ]);
  2241. }
  2242. /**
  2243. * @module
  2244. * @description
  2245. * Entry point for all public APIs of the platform-browser package.
  2246. */
  2247. /**
  2248. * @publicApi
  2249. */
  2250. const VERSION = new Version('19.2.4');
  2251. export { BrowserModule, By, DomSanitizer, EVENT_MANAGER_PLUGINS, EventManager, EventManagerPlugin, HAMMER_GESTURE_CONFIG, HAMMER_LOADER, HammerGestureConfig, HammerModule, HydrationFeatureKind, Meta, REMOVE_STYLES_ON_COMPONENT_DESTROY, Title, VERSION, bootstrapApplication, createApplication, disableDebugTools, enableDebugTools, platformBrowser, provideClientHydration, provideProtractorTestingSupport, withEventReplay, withHttpTransferCacheOptions, withI18nSupport, withIncrementalHydration, withNoHttpTransferCache, BrowserDomAdapter as ɵBrowserDomAdapter, BrowserGetTestability as ɵBrowserGetTestability, DomEventsPlugin as ɵDomEventsPlugin, DomRendererFactory2 as ɵDomRendererFactory2, DomSanitizerImpl as ɵDomSanitizerImpl, HammerGesturesPlugin as ɵHammerGesturesPlugin, KeyEventsPlugin as ɵKeyEventsPlugin, SharedStylesHost as ɵSharedStylesHost };
  2252. //# sourceMappingURL=platform-browser.mjs.map