platform-browser.mjs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. /**
  2. * @license Angular v19.2.13
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. export { BrowserModule, bootstrapApplication, createApplication, platformBrowser, provideProtractorTestingSupport, BrowserDomAdapter as ɵBrowserDomAdapter, BrowserGetTestability as ɵBrowserGetTestability, DomEventsPlugin as ɵDomEventsPlugin, KeyEventsPlugin as ɵKeyEventsPlugin } from './browser-D-u-fknz.mjs';
  7. import { ɵgetDOM as _getDOM, DOCUMENT } from '@angular/common';
  8. export { ɵgetDOM } from '@angular/common';
  9. import * as i0 from '@angular/core';
  10. import { Inject, Injectable, ɵglobal as _global, ApplicationRef, InjectionToken, Injector, Optional, ɵConsole as _Console, NgModule, ɵRuntimeError as _RuntimeError, ɵ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, inject, NgZone, ɵZONELESS_ENABLED as _ZONELESS_ENABLED, ɵformatRuntimeError as _formatRuntimeError, Version } from '@angular/core';
  11. import { EVENT_MANAGER_PLUGINS, EventManagerPlugin } from './dom_renderer-DGKzginR.mjs';
  12. export { EventManager, REMOVE_STYLES_ON_COMPONENT_DESTROY, DomRendererFactory2 as ɵDomRendererFactory2, SharedStylesHost as ɵSharedStylesHost } from './dom_renderer-DGKzginR.mjs';
  13. import { ɵwithHttpTransferCache as _withHttpTransferCache } from '@angular/common/http';
  14. /**
  15. * A service for managing HTML `<meta>` tags.
  16. *
  17. * Properties of the `MetaDefinition` object match the attributes of the
  18. * HTML `<meta>` tag. These tags define document metadata that is important for
  19. * things like configuring a Content Security Policy, defining browser compatibility
  20. * and security settings, setting HTTP Headers, defining rich content for social sharing,
  21. * and Search Engine Optimization (SEO).
  22. *
  23. * To identify specific `<meta>` tags in a document, use an attribute selection
  24. * string in the format `"tag_attribute='value string'"`.
  25. * For example, an `attrSelector` value of `"name='description'"` matches a tag
  26. * whose `name` attribute has the value `"description"`.
  27. * Selectors are used with the `querySelector()` Document method,
  28. * in the format `meta[{attrSelector}]`.
  29. *
  30. * @see [HTML meta tag](https://developer.mozilla.org/docs/Web/HTML/Element/meta)
  31. * @see [Document.querySelector()](https://developer.mozilla.org/docs/Web/API/Document/querySelector)
  32. *
  33. *
  34. * @publicApi
  35. */
  36. class Meta {
  37. _doc;
  38. _dom;
  39. constructor(_doc) {
  40. this._doc = _doc;
  41. this._dom = _getDOM();
  42. }
  43. /**
  44. * Retrieves or creates a specific `<meta>` tag element in the current HTML document.
  45. * In searching for an existing tag, Angular attempts to match the `name` or `property` attribute
  46. * values in the provided tag definition, and verifies that all other attribute values are equal.
  47. * If an existing element is found, it is returned and is not modified in any way.
  48. * @param tag The definition of a `<meta>` element to match or create.
  49. * @param forceCreation True to create a new element without checking whether one already exists.
  50. * @returns The existing element with the same attributes and values if found,
  51. * the new element if no match is found, or `null` if the tag parameter is not defined.
  52. */
  53. addTag(tag, forceCreation = false) {
  54. if (!tag)
  55. return null;
  56. return this._getOrCreateElement(tag, forceCreation);
  57. }
  58. /**
  59. * Retrieves or creates a set of `<meta>` tag elements in the current HTML document.
  60. * In searching for an existing tag, Angular attempts to match the `name` or `property` attribute
  61. * values in the provided tag definition, and verifies that all other attribute values are equal.
  62. * @param tags An array of tag definitions to match or create.
  63. * @param forceCreation True to create new elements without checking whether they already exist.
  64. * @returns The matching elements if found, or the new elements.
  65. */
  66. addTags(tags, forceCreation = false) {
  67. if (!tags)
  68. return [];
  69. return tags.reduce((result, tag) => {
  70. if (tag) {
  71. result.push(this._getOrCreateElement(tag, forceCreation));
  72. }
  73. return result;
  74. }, []);
  75. }
  76. /**
  77. * Retrieves a `<meta>` tag element in the current HTML document.
  78. * @param attrSelector The tag attribute and value to match against, in the format
  79. * `"tag_attribute='value string'"`.
  80. * @returns The matching element, if any.
  81. */
  82. getTag(attrSelector) {
  83. if (!attrSelector)
  84. return null;
  85. return this._doc.querySelector(`meta[${attrSelector}]`) || null;
  86. }
  87. /**
  88. * Retrieves a set of `<meta>` tag elements in the current HTML document.
  89. * @param attrSelector The tag attribute and value to match against, in the format
  90. * `"tag_attribute='value string'"`.
  91. * @returns The matching elements, if any.
  92. */
  93. getTags(attrSelector) {
  94. if (!attrSelector)
  95. return [];
  96. const list /*NodeList*/ = this._doc.querySelectorAll(`meta[${attrSelector}]`);
  97. return list ? [].slice.call(list) : [];
  98. }
  99. /**
  100. * Modifies an existing `<meta>` tag element in the current HTML document.
  101. * @param tag The tag description with which to replace the existing tag content.
  102. * @param selector A tag attribute and value to match against, to identify
  103. * an existing tag. A string in the format `"tag_attribute=`value string`"`.
  104. * If not supplied, matches a tag with the same `name` or `property` attribute value as the
  105. * replacement tag.
  106. * @return The modified element.
  107. */
  108. updateTag(tag, selector) {
  109. if (!tag)
  110. return null;
  111. selector = selector || this._parseSelector(tag);
  112. const meta = this.getTag(selector);
  113. if (meta) {
  114. return this._setMetaElementAttributes(tag, meta);
  115. }
  116. return this._getOrCreateElement(tag, true);
  117. }
  118. /**
  119. * Removes an existing `<meta>` tag element from the current HTML document.
  120. * @param attrSelector A tag attribute and value to match against, to identify
  121. * an existing tag. A string in the format `"tag_attribute=`value string`"`.
  122. */
  123. removeTag(attrSelector) {
  124. this.removeTagElement(this.getTag(attrSelector));
  125. }
  126. /**
  127. * Removes an existing `<meta>` tag element from the current HTML document.
  128. * @param meta The tag definition to match against to identify an existing tag.
  129. */
  130. removeTagElement(meta) {
  131. if (meta) {
  132. this._dom.remove(meta);
  133. }
  134. }
  135. _getOrCreateElement(meta, forceCreation = false) {
  136. if (!forceCreation) {
  137. const selector = this._parseSelector(meta);
  138. // It's allowed to have multiple elements with the same name so it's not enough to
  139. // just check that element with the same name already present on the page. We also need to
  140. // check if element has tag attributes
  141. const elem = this.getTags(selector).filter((elem) => this._containsAttributes(meta, elem))[0];
  142. if (elem !== undefined)
  143. return elem;
  144. }
  145. const element = this._dom.createElement('meta');
  146. this._setMetaElementAttributes(meta, element);
  147. const head = this._doc.getElementsByTagName('head')[0];
  148. head.appendChild(element);
  149. return element;
  150. }
  151. _setMetaElementAttributes(tag, el) {
  152. Object.keys(tag).forEach((prop) => el.setAttribute(this._getMetaKeyMap(prop), tag[prop]));
  153. return el;
  154. }
  155. _parseSelector(tag) {
  156. const attr = tag.name ? 'name' : 'property';
  157. return `${attr}="${tag[attr]}"`;
  158. }
  159. _containsAttributes(tag, elem) {
  160. return Object.keys(tag).every((key) => elem.getAttribute(this._getMetaKeyMap(key)) === tag[key]);
  161. }
  162. _getMetaKeyMap(prop) {
  163. return META_KEYS_MAP[prop] || prop;
  164. }
  165. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: Meta, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  166. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: Meta, providedIn: 'root' });
  167. }
  168. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: Meta, decorators: [{
  169. type: Injectable,
  170. args: [{ providedIn: 'root' }]
  171. }], ctorParameters: () => [{ type: undefined, decorators: [{
  172. type: Inject,
  173. args: [DOCUMENT]
  174. }] }] });
  175. /**
  176. * Mapping for MetaDefinition properties with their correct meta attribute names
  177. */
  178. const META_KEYS_MAP = {
  179. httpEquiv: 'http-equiv',
  180. };
  181. /**
  182. * A service that can be used to get and set the title of a current HTML document.
  183. *
  184. * Since an Angular application can't be bootstrapped on the entire HTML document (`<html>` tag)
  185. * it is not possible to bind to the `text` property of the `HTMLTitleElement` elements
  186. * (representing the `<title>` tag). Instead, this service can be used to set and get the current
  187. * title value.
  188. *
  189. * @publicApi
  190. */
  191. class Title {
  192. _doc;
  193. constructor(_doc) {
  194. this._doc = _doc;
  195. }
  196. /**
  197. * Get the title of the current HTML document.
  198. */
  199. getTitle() {
  200. return this._doc.title;
  201. }
  202. /**
  203. * Set the title of the current HTML document.
  204. * @param newTitle
  205. */
  206. setTitle(newTitle) {
  207. this._doc.title = newTitle || '';
  208. }
  209. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: Title, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  210. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: Title, providedIn: 'root' });
  211. }
  212. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: Title, decorators: [{
  213. type: Injectable,
  214. args: [{ providedIn: 'root' }]
  215. }], ctorParameters: () => [{ type: undefined, decorators: [{
  216. type: Inject,
  217. args: [DOCUMENT]
  218. }] }] });
  219. /// <reference path="../../../goog.d.ts" />
  220. /**
  221. * Exports the value under a given `name` in the global property `ng`. For example `ng.probe` if
  222. * `name` is `'probe'`.
  223. * @param name Name under which it will be exported. Keep in mind this will be a property of the
  224. * global `ng` object.
  225. * @param value The value to export.
  226. */
  227. function exportNgVar(name, value) {
  228. if (typeof COMPILED === 'undefined' || !COMPILED) {
  229. // Note: we can't export `ng` when using closure enhanced optimization as:
  230. // - closure declares globals itself for minified names, which sometimes clobber our `ng` global
  231. // - we can't declare a closure extern as the namespace `ng` is already used within Google
  232. // for typings for angularJS (via `goog.provide('ng....')`).
  233. const ng = (_global['ng'] = _global['ng'] || {});
  234. ng[name] = value;
  235. }
  236. }
  237. class ChangeDetectionPerfRecord {
  238. msPerTick;
  239. numTicks;
  240. constructor(msPerTick, numTicks) {
  241. this.msPerTick = msPerTick;
  242. this.numTicks = numTicks;
  243. }
  244. }
  245. /**
  246. * Entry point for all Angular profiling-related debug tools. This object
  247. * corresponds to the `ng.profiler` in the dev console.
  248. */
  249. class AngularProfiler {
  250. appRef;
  251. constructor(ref) {
  252. this.appRef = ref.injector.get(ApplicationRef);
  253. }
  254. // tslint:disable:no-console
  255. /**
  256. * Exercises change detection in a loop and then prints the average amount of
  257. * time in milliseconds how long a single round of change detection takes for
  258. * the current state of the UI. It runs a minimum of 5 rounds for a minimum
  259. * of 500 milliseconds.
  260. *
  261. * Optionally, a user may pass a `config` parameter containing a map of
  262. * options. Supported options are:
  263. *
  264. * `record` (boolean) - causes the profiler to record a CPU profile while
  265. * it exercises the change detector. Example:
  266. *
  267. * ```ts
  268. * ng.profiler.timeChangeDetection({record: true})
  269. * ```
  270. */
  271. timeChangeDetection(config) {
  272. const record = config && config['record'];
  273. const profileName = 'Change Detection';
  274. // Profiler is not available in Android browsers without dev tools opened
  275. if (record && 'profile' in console && typeof console.profile === 'function') {
  276. console.profile(profileName);
  277. }
  278. const start = performance.now();
  279. let numTicks = 0;
  280. while (numTicks < 5 || performance.now() - start < 500) {
  281. this.appRef.tick();
  282. numTicks++;
  283. }
  284. const end = performance.now();
  285. if (record && 'profileEnd' in console && typeof console.profileEnd === 'function') {
  286. console.profileEnd(profileName);
  287. }
  288. const msPerTick = (end - start) / numTicks;
  289. console.log(`ran ${numTicks} change detection cycles`);
  290. console.log(`${msPerTick.toFixed(2)} ms per check`);
  291. return new ChangeDetectionPerfRecord(msPerTick, numTicks);
  292. }
  293. }
  294. const PROFILER_GLOBAL_NAME = 'profiler';
  295. /**
  296. * Enabled Angular debug tools that are accessible via your browser's
  297. * developer console.
  298. *
  299. * Usage:
  300. *
  301. * 1. Open developer console (e.g. in Chrome Ctrl + Shift + j)
  302. * 1. Type `ng.` (usually the console will show auto-complete suggestion)
  303. * 1. Try the change detection profiler `ng.profiler.timeChangeDetection()`
  304. * then hit Enter.
  305. *
  306. * @publicApi
  307. */
  308. function enableDebugTools(ref) {
  309. exportNgVar(PROFILER_GLOBAL_NAME, new AngularProfiler(ref));
  310. return ref;
  311. }
  312. /**
  313. * Disables Angular tools.
  314. *
  315. * @publicApi
  316. */
  317. function disableDebugTools() {
  318. exportNgVar(PROFILER_GLOBAL_NAME, null);
  319. }
  320. /**
  321. * Predicates for use with {@link DebugElement}'s query functions.
  322. *
  323. * @publicApi
  324. */
  325. class By {
  326. /**
  327. * Match all nodes.
  328. *
  329. * @usageNotes
  330. * ### Example
  331. *
  332. * {@example platform-browser/dom/debug/ts/by/by.ts region='by_all'}
  333. */
  334. static all() {
  335. return () => true;
  336. }
  337. /**
  338. * Match elements by the given CSS selector.
  339. *
  340. * @usageNotes
  341. * ### Example
  342. *
  343. * {@example platform-browser/dom/debug/ts/by/by.ts region='by_css'}
  344. */
  345. static css(selector) {
  346. return (debugElement) => {
  347. return debugElement.nativeElement != null
  348. ? elementMatches(debugElement.nativeElement, selector)
  349. : false;
  350. };
  351. }
  352. /**
  353. * Match nodes that have the given directive present.
  354. *
  355. * @usageNotes
  356. * ### Example
  357. *
  358. * {@example platform-browser/dom/debug/ts/by/by.ts region='by_directive'}
  359. */
  360. static directive(type) {
  361. return (debugNode) => debugNode.providerTokens.indexOf(type) !== -1;
  362. }
  363. }
  364. function elementMatches(n, selector) {
  365. if (_getDOM().isElementNode(n)) {
  366. return ((n.matches && n.matches(selector)) ||
  367. (n.msMatchesSelector && n.msMatchesSelector(selector)) ||
  368. (n.webkitMatchesSelector && n.webkitMatchesSelector(selector)));
  369. }
  370. return false;
  371. }
  372. /// <reference types="hammerjs" />
  373. /**
  374. * Supported HammerJS recognizer event names.
  375. */
  376. const EVENT_NAMES = {
  377. // pan
  378. 'pan': true,
  379. 'panstart': true,
  380. 'panmove': true,
  381. 'panend': true,
  382. 'pancancel': true,
  383. 'panleft': true,
  384. 'panright': true,
  385. 'panup': true,
  386. 'pandown': true,
  387. // pinch
  388. 'pinch': true,
  389. 'pinchstart': true,
  390. 'pinchmove': true,
  391. 'pinchend': true,
  392. 'pinchcancel': true,
  393. 'pinchin': true,
  394. 'pinchout': true,
  395. // press
  396. 'press': true,
  397. 'pressup': true,
  398. // rotate
  399. 'rotate': true,
  400. 'rotatestart': true,
  401. 'rotatemove': true,
  402. 'rotateend': true,
  403. 'rotatecancel': true,
  404. // swipe
  405. 'swipe': true,
  406. 'swipeleft': true,
  407. 'swiperight': true,
  408. 'swipeup': true,
  409. 'swipedown': true,
  410. // tap
  411. 'tap': true,
  412. 'doubletap': true,
  413. };
  414. /**
  415. * DI token for providing [HammerJS](https://hammerjs.github.io/) support to Angular.
  416. * @see {@link HammerGestureConfig}
  417. *
  418. * @ngModule HammerModule
  419. * @publicApi
  420. */
  421. const HAMMER_GESTURE_CONFIG = new InjectionToken(typeof ngDevMode === 'undefined' || ngDevMode ? 'HammerGestureConfig' : '');
  422. /**
  423. * Injection token used to provide a HammerLoader to Angular.
  424. *
  425. * @see {@link HammerLoader}
  426. *
  427. * @publicApi
  428. */
  429. const HAMMER_LOADER = new InjectionToken(typeof ngDevMode === 'undefined' || ngDevMode ? 'HammerLoader' : '');
  430. /**
  431. * An injectable [HammerJS Manager](https://hammerjs.github.io/api/#hammermanager)
  432. * for gesture recognition. Configures specific event recognition.
  433. * @publicApi
  434. */
  435. class HammerGestureConfig {
  436. /**
  437. * A set of supported event names for gestures to be used in Angular.
  438. * Angular supports all built-in recognizers, as listed in
  439. * [HammerJS documentation](https://hammerjs.github.io/).
  440. */
  441. events = [];
  442. /**
  443. * Maps gesture event names to a set of configuration options
  444. * that specify overrides to the default values for specific properties.
  445. *
  446. * The key is a supported event name to be configured,
  447. * and the options object contains a set of properties, with override values
  448. * to be applied to the named recognizer event.
  449. * For example, to disable recognition of the rotate event, specify
  450. * `{"rotate": {"enable": false}}`.
  451. *
  452. * Properties that are not present take the HammerJS default values.
  453. * For information about which properties are supported for which events,
  454. * and their allowed and default values, see
  455. * [HammerJS documentation](https://hammerjs.github.io/).
  456. *
  457. */
  458. overrides = {};
  459. /**
  460. * Properties whose default values can be overridden for a given event.
  461. * Different sets of properties apply to different events.
  462. * For information about which properties are supported for which events,
  463. * and their allowed and default values, see
  464. * [HammerJS documentation](https://hammerjs.github.io/).
  465. */
  466. options;
  467. /**
  468. * Creates a [HammerJS Manager](https://hammerjs.github.io/api/#hammermanager)
  469. * and attaches it to a given HTML element.
  470. * @param element The element that will recognize gestures.
  471. * @returns A HammerJS event-manager object.
  472. */
  473. buildHammer(element) {
  474. const mc = new Hammer(element, this.options);
  475. mc.get('pinch').set({ enable: true });
  476. mc.get('rotate').set({ enable: true });
  477. for (const eventName in this.overrides) {
  478. mc.get(eventName).set(this.overrides[eventName]);
  479. }
  480. return mc;
  481. }
  482. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerGestureConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  483. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerGestureConfig });
  484. }
  485. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerGestureConfig, decorators: [{
  486. type: Injectable
  487. }] });
  488. /**
  489. * Event plugin that adds Hammer support to an application.
  490. *
  491. * @ngModule HammerModule
  492. */
  493. class HammerGesturesPlugin extends EventManagerPlugin {
  494. _config;
  495. _injector;
  496. loader;
  497. _loaderPromise = null;
  498. constructor(doc, _config, _injector, loader) {
  499. super(doc);
  500. this._config = _config;
  501. this._injector = _injector;
  502. this.loader = loader;
  503. }
  504. supports(eventName) {
  505. if (!EVENT_NAMES.hasOwnProperty(eventName.toLowerCase()) && !this.isCustomEvent(eventName)) {
  506. return false;
  507. }
  508. if (!window.Hammer && !this.loader) {
  509. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  510. // Get a `Console` through an injector to tree-shake the
  511. // class when it is unused in production.
  512. const _console = this._injector.get(_Console);
  513. _console.warn(`The "${eventName}" event cannot be bound because Hammer.JS is not ` +
  514. `loaded and no custom loader has been specified.`);
  515. }
  516. return false;
  517. }
  518. return true;
  519. }
  520. addEventListener(element, eventName, handler) {
  521. const zone = this.manager.getZone();
  522. eventName = eventName.toLowerCase();
  523. // If Hammer is not present but a loader is specified, we defer adding the event listener
  524. // until Hammer is loaded.
  525. if (!window.Hammer && this.loader) {
  526. this._loaderPromise = this._loaderPromise || zone.runOutsideAngular(() => this.loader());
  527. // This `addEventListener` method returns a function to remove the added listener.
  528. // Until Hammer is loaded, the returned function needs to *cancel* the registration rather
  529. // than remove anything.
  530. let cancelRegistration = false;
  531. let deregister = () => {
  532. cancelRegistration = true;
  533. };
  534. zone.runOutsideAngular(() => this._loaderPromise.then(() => {
  535. // If Hammer isn't actually loaded when the custom loader resolves, give up.
  536. if (!window.Hammer) {
  537. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  538. const _console = this._injector.get(_Console);
  539. _console.warn(`The custom HAMMER_LOADER completed, but Hammer.JS is not present.`);
  540. }
  541. deregister = () => { };
  542. return;
  543. }
  544. if (!cancelRegistration) {
  545. // Now that Hammer is loaded and the listener is being loaded for real,
  546. // the deregistration function changes from canceling registration to
  547. // removal.
  548. deregister = this.addEventListener(element, eventName, handler);
  549. }
  550. }).catch(() => {
  551. if (typeof ngDevMode === 'undefined' || ngDevMode) {
  552. const _console = this._injector.get(_Console);
  553. _console.warn(`The "${eventName}" event cannot be bound because the custom ` +
  554. `Hammer.JS loader failed.`);
  555. }
  556. deregister = () => { };
  557. }));
  558. // Return a function that *executes* `deregister` (and not `deregister` itself) so that we
  559. // can change the behavior of `deregister` once the listener is added. Using a closure in
  560. // this way allows us to avoid any additional data structures to track listener removal.
  561. return () => {
  562. deregister();
  563. };
  564. }
  565. return zone.runOutsideAngular(() => {
  566. // Creating the manager bind events, must be done outside of angular
  567. const mc = this._config.buildHammer(element);
  568. const callback = function (eventObj) {
  569. zone.runGuarded(function () {
  570. handler(eventObj);
  571. });
  572. };
  573. mc.on(eventName, callback);
  574. return () => {
  575. mc.off(eventName, callback);
  576. // destroy mc to prevent memory leak
  577. if (typeof mc.destroy === 'function') {
  578. mc.destroy();
  579. }
  580. };
  581. });
  582. }
  583. isCustomEvent(eventName) {
  584. return this._config.events.indexOf(eventName) > -1;
  585. }
  586. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerGesturesPlugin, deps: [{ token: DOCUMENT }, { token: HAMMER_GESTURE_CONFIG }, { token: i0.Injector }, { token: HAMMER_LOADER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
  587. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerGesturesPlugin });
  588. }
  589. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerGesturesPlugin, decorators: [{
  590. type: Injectable
  591. }], ctorParameters: () => [{ type: undefined, decorators: [{
  592. type: Inject,
  593. args: [DOCUMENT]
  594. }] }, { type: HammerGestureConfig, decorators: [{
  595. type: Inject,
  596. args: [HAMMER_GESTURE_CONFIG]
  597. }] }, { type: i0.Injector }, { type: undefined, decorators: [{
  598. type: Optional
  599. }, {
  600. type: Inject,
  601. args: [HAMMER_LOADER]
  602. }] }] });
  603. /**
  604. * Adds support for HammerJS.
  605. *
  606. * Import this module at the root of your application so that Angular can work with
  607. * HammerJS to detect gesture events.
  608. *
  609. * Note that applications still need to include the HammerJS script itself. This module
  610. * simply sets up the coordination layer between HammerJS and Angular's `EventManager`.
  611. *
  612. * @publicApi
  613. */
  614. class HammerModule {
  615. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  616. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.13", ngImport: i0, type: HammerModule });
  617. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerModule, providers: [
  618. {
  619. provide: EVENT_MANAGER_PLUGINS,
  620. useClass: HammerGesturesPlugin,
  621. multi: true,
  622. deps: [DOCUMENT, HAMMER_GESTURE_CONFIG, Injector, [new Optional(), HAMMER_LOADER]],
  623. },
  624. { provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig },
  625. ] });
  626. }
  627. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: HammerModule, decorators: [{
  628. type: NgModule,
  629. args: [{
  630. providers: [
  631. {
  632. provide: EVENT_MANAGER_PLUGINS,
  633. useClass: HammerGesturesPlugin,
  634. multi: true,
  635. deps: [DOCUMENT, HAMMER_GESTURE_CONFIG, Injector, [new Optional(), HAMMER_LOADER]],
  636. },
  637. { provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig },
  638. ],
  639. }]
  640. }] });
  641. /**
  642. * DomSanitizer helps preventing Cross Site Scripting Security bugs (XSS) by sanitizing
  643. * values to be safe to use in the different DOM contexts.
  644. *
  645. * For example, when binding a URL in an `<a [href]="someValue">` hyperlink, `someValue` will be
  646. * sanitized so that an attacker cannot inject e.g. a `javascript:` URL that would execute code on
  647. * the website.
  648. *
  649. * In specific situations, it might be necessary to disable sanitization, for example if the
  650. * application genuinely needs to produce a `javascript:` style link with a dynamic value in it.
  651. * Users can bypass security by constructing a value with one of the `bypassSecurityTrust...`
  652. * methods, and then binding to that value from the template.
  653. *
  654. * These situations should be very rare, and extraordinary care must be taken to avoid creating a
  655. * Cross Site Scripting (XSS) security bug!
  656. *
  657. * When using `bypassSecurityTrust...`, make sure to call the method as early as possible and as
  658. * close as possible to the source of the value, to make it easy to verify no security bug is
  659. * created by its use.
  660. *
  661. * It is not required (and not recommended) to bypass security if the value is safe, e.g. a URL that
  662. * does not start with a suspicious protocol, or an HTML snippet that does not contain dangerous
  663. * code. The sanitizer leaves safe values intact.
  664. *
  665. * @security Calling any of the `bypassSecurityTrust...` APIs disables Angular's built-in
  666. * sanitization for the value passed in. Carefully check and audit all values and code paths going
  667. * into this call. Make sure any user data is appropriately escaped for this security context.
  668. * For more detail, see the [Security Guide](https://g.co/ng/security).
  669. *
  670. * @publicApi
  671. */
  672. class DomSanitizer {
  673. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DomSanitizer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  674. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DomSanitizer, providedIn: 'root', useExisting: i0.forwardRef(() => DomSanitizerImpl) });
  675. }
  676. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DomSanitizer, decorators: [{
  677. type: Injectable,
  678. args: [{ providedIn: 'root', useExisting: forwardRef(() => DomSanitizerImpl) }]
  679. }] });
  680. class DomSanitizerImpl extends DomSanitizer {
  681. _doc;
  682. constructor(_doc) {
  683. super();
  684. this._doc = _doc;
  685. }
  686. sanitize(ctx, value) {
  687. if (value == null)
  688. return null;
  689. switch (ctx) {
  690. case SecurityContext.NONE:
  691. return value;
  692. case SecurityContext.HTML:
  693. if (_allowSanitizationBypassAndThrow(value, "HTML" /* BypassType.Html */)) {
  694. return _unwrapSafeValue(value);
  695. }
  696. return __sanitizeHtml(this._doc, String(value)).toString();
  697. case SecurityContext.STYLE:
  698. if (_allowSanitizationBypassAndThrow(value, "Style" /* BypassType.Style */)) {
  699. return _unwrapSafeValue(value);
  700. }
  701. return value;
  702. case SecurityContext.SCRIPT:
  703. if (_allowSanitizationBypassAndThrow(value, "Script" /* BypassType.Script */)) {
  704. return _unwrapSafeValue(value);
  705. }
  706. throw new _RuntimeError(5200 /* RuntimeErrorCode.SANITIZATION_UNSAFE_SCRIPT */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  707. 'unsafe value used in a script context');
  708. case SecurityContext.URL:
  709. if (_allowSanitizationBypassAndThrow(value, "URL" /* BypassType.Url */)) {
  710. return _unwrapSafeValue(value);
  711. }
  712. return __sanitizeUrl(String(value));
  713. case SecurityContext.RESOURCE_URL:
  714. if (_allowSanitizationBypassAndThrow(value, "ResourceURL" /* BypassType.ResourceUrl */)) {
  715. return _unwrapSafeValue(value);
  716. }
  717. throw new _RuntimeError(5201 /* RuntimeErrorCode.SANITIZATION_UNSAFE_RESOURCE_URL */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  718. `unsafe value used in a resource URL context (see ${_XSS_SECURITY_URL})`);
  719. default:
  720. throw new _RuntimeError(5202 /* RuntimeErrorCode.SANITIZATION_UNEXPECTED_CTX */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
  721. `Unexpected SecurityContext ${ctx} (see ${_XSS_SECURITY_URL})`);
  722. }
  723. }
  724. bypassSecurityTrustHtml(value) {
  725. return _bypassSanitizationTrustHtml(value);
  726. }
  727. bypassSecurityTrustStyle(value) {
  728. return _bypassSanitizationTrustStyle(value);
  729. }
  730. bypassSecurityTrustScript(value) {
  731. return _bypassSanitizationTrustScript(value);
  732. }
  733. bypassSecurityTrustUrl(value) {
  734. return _bypassSanitizationTrustUrl(value);
  735. }
  736. bypassSecurityTrustResourceUrl(value) {
  737. return _bypassSanitizationTrustResourceUrl(value);
  738. }
  739. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DomSanitizerImpl, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
  740. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DomSanitizerImpl, providedIn: 'root' });
  741. }
  742. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: DomSanitizerImpl, decorators: [{
  743. type: Injectable,
  744. args: [{ providedIn: 'root' }]
  745. }], ctorParameters: () => [{ type: undefined, decorators: [{
  746. type: Inject,
  747. args: [DOCUMENT]
  748. }] }] });
  749. /**
  750. * The list of features as an enum to uniquely type each `HydrationFeature`.
  751. * @see {@link HydrationFeature}
  752. *
  753. * @publicApi
  754. */
  755. var HydrationFeatureKind;
  756. (function (HydrationFeatureKind) {
  757. HydrationFeatureKind[HydrationFeatureKind["NoHttpTransferCache"] = 0] = "NoHttpTransferCache";
  758. HydrationFeatureKind[HydrationFeatureKind["HttpTransferCacheOptions"] = 1] = "HttpTransferCacheOptions";
  759. HydrationFeatureKind[HydrationFeatureKind["I18nSupport"] = 2] = "I18nSupport";
  760. HydrationFeatureKind[HydrationFeatureKind["EventReplay"] = 3] = "EventReplay";
  761. HydrationFeatureKind[HydrationFeatureKind["IncrementalHydration"] = 4] = "IncrementalHydration";
  762. })(HydrationFeatureKind || (HydrationFeatureKind = {}));
  763. /**
  764. * Helper function to create an object that represents a Hydration feature.
  765. */
  766. function hydrationFeature(ɵkind, ɵproviders = [], ɵoptions = {}) {
  767. return { ɵkind, ɵproviders };
  768. }
  769. /**
  770. * Disables HTTP transfer cache. Effectively causes HTTP requests to be performed twice: once on the
  771. * server and other one on the browser.
  772. *
  773. * @publicApi
  774. */
  775. function withNoHttpTransferCache() {
  776. // This feature has no providers and acts as a flag that turns off
  777. // HTTP transfer cache (which otherwise is turned on by default).
  778. return hydrationFeature(HydrationFeatureKind.NoHttpTransferCache);
  779. }
  780. /**
  781. * The function accepts an object, which allows to configure cache parameters,
  782. * such as which headers should be included (no headers are included by default),
  783. * whether POST requests should be cached or a callback function to determine if a
  784. * particular request should be cached.
  785. *
  786. * @publicApi
  787. */
  788. function withHttpTransferCacheOptions(options) {
  789. // This feature has no providers and acts as a flag to pass options to the HTTP transfer cache.
  790. return hydrationFeature(HydrationFeatureKind.HttpTransferCacheOptions, _withHttpTransferCache(options));
  791. }
  792. /**
  793. * Enables support for hydrating i18n blocks.
  794. *
  795. * @developerPreview
  796. * @publicApi
  797. */
  798. function withI18nSupport() {
  799. return hydrationFeature(HydrationFeatureKind.I18nSupport, _withI18nSupport());
  800. }
  801. /**
  802. * Enables support for replaying user events (e.g. `click`s) that happened on a page
  803. * before hydration logic has completed. Once an application is hydrated, all captured
  804. * events are replayed and relevant event listeners are executed.
  805. *
  806. * @usageNotes
  807. *
  808. * Basic example of how you can enable event replay in your application when
  809. * `bootstrapApplication` function is used:
  810. * ```ts
  811. * bootstrapApplication(AppComponent, {
  812. * providers: [provideClientHydration(withEventReplay())]
  813. * });
  814. * ```
  815. * @publicApi
  816. * @see {@link provideClientHydration}
  817. */
  818. function withEventReplay() {
  819. return hydrationFeature(HydrationFeatureKind.EventReplay, _withEventReplay());
  820. }
  821. /**
  822. * Enables support for incremental hydration using the `hydrate` trigger syntax.
  823. *
  824. * @usageNotes
  825. *
  826. * Basic example of how you can enable incremental hydration in your application when
  827. * the `bootstrapApplication` function is used:
  828. * ```ts
  829. * bootstrapApplication(AppComponent, {
  830. * providers: [provideClientHydration(withIncrementalHydration())]
  831. * });
  832. * ```
  833. * @experimental
  834. * @publicApi
  835. * @see {@link provideClientHydration}
  836. */
  837. function withIncrementalHydration() {
  838. return hydrationFeature(HydrationFeatureKind.IncrementalHydration, _withIncrementalHydration());
  839. }
  840. /**
  841. * Returns an `ENVIRONMENT_INITIALIZER` token setup with a function
  842. * that verifies whether compatible ZoneJS was used in an application
  843. * and logs a warning in a console if it's not the case.
  844. */
  845. function provideZoneJsCompatibilityDetector() {
  846. return [
  847. {
  848. provide: ENVIRONMENT_INITIALIZER,
  849. useValue: () => {
  850. const ngZone = inject(NgZone);
  851. const isZoneless = inject(_ZONELESS_ENABLED);
  852. // Checking `ngZone instanceof NgZone` would be insufficient here,
  853. // because custom implementations might use NgZone as a base class.
  854. if (!isZoneless && ngZone.constructor !== NgZone) {
  855. const console = inject(_Console);
  856. const message = _formatRuntimeError(-5e3 /* RuntimeErrorCode.UNSUPPORTED_ZONEJS_INSTANCE */, 'Angular detected that hydration was enabled for an application ' +
  857. 'that uses a custom or a noop Zone.js implementation. ' +
  858. 'This is not yet a fully supported configuration.');
  859. console.warn(message);
  860. }
  861. },
  862. multi: true,
  863. },
  864. ];
  865. }
  866. /**
  867. * Sets up providers necessary to enable hydration functionality for the application.
  868. *
  869. * By default, the function enables the recommended set of features for the optimal
  870. * performance for most of the applications. It includes the following features:
  871. *
  872. * * Reconciling DOM hydration. Learn more about it [here](guide/hydration).
  873. * * [`HttpClient`](api/common/http/HttpClient) response caching while running on the server and
  874. * transferring this cache to the client to avoid extra HTTP requests. Learn more about data caching
  875. * [here](guide/ssr#caching-data-when-using-httpclient).
  876. *
  877. * These functions allow you to disable some of the default features or enable new ones:
  878. *
  879. * * {@link withNoHttpTransferCache} to disable HTTP transfer cache
  880. * * {@link withHttpTransferCacheOptions} to configure some HTTP transfer cache options
  881. * * {@link withI18nSupport} to enable hydration support for i18n blocks
  882. * * {@link withEventReplay} to enable support for replaying user events
  883. *
  884. * @usageNotes
  885. *
  886. * Basic example of how you can enable hydration in your application when
  887. * `bootstrapApplication` function is used:
  888. * ```ts
  889. * bootstrapApplication(AppComponent, {
  890. * providers: [provideClientHydration()]
  891. * });
  892. * ```
  893. *
  894. * Alternatively if you are using NgModules, you would add `provideClientHydration`
  895. * to your root app module's provider list.
  896. * ```ts
  897. * @NgModule({
  898. * declarations: [RootCmp],
  899. * bootstrap: [RootCmp],
  900. * providers: [provideClientHydration()],
  901. * })
  902. * export class AppModule {}
  903. * ```
  904. *
  905. * @see {@link withNoHttpTransferCache}
  906. * @see {@link withHttpTransferCacheOptions}
  907. * @see {@link withI18nSupport}
  908. * @see {@link withEventReplay}
  909. *
  910. * @param features Optional features to configure additional hydration behaviors.
  911. * @returns A set of providers to enable hydration.
  912. *
  913. * @publicApi
  914. */
  915. function provideClientHydration(...features) {
  916. const providers = [];
  917. const featuresKind = new Set();
  918. for (const { ɵproviders, ɵkind } of features) {
  919. featuresKind.add(ɵkind);
  920. if (ɵproviders.length) {
  921. providers.push(ɵproviders);
  922. }
  923. }
  924. const hasHttpTransferCacheOptions = featuresKind.has(HydrationFeatureKind.HttpTransferCacheOptions);
  925. if (typeof ngDevMode !== 'undefined' &&
  926. ngDevMode &&
  927. featuresKind.has(HydrationFeatureKind.NoHttpTransferCache) &&
  928. hasHttpTransferCacheOptions) {
  929. // TODO: Make this a runtime error
  930. throw new Error('Configuration error: found both withHttpTransferCacheOptions() and withNoHttpTransferCache() in the same call to provideClientHydration(), which is a contradiction.');
  931. }
  932. return makeEnvironmentProviders([
  933. typeof ngDevMode !== 'undefined' && ngDevMode ? provideZoneJsCompatibilityDetector() : [],
  934. _withDomHydration(),
  935. featuresKind.has(HydrationFeatureKind.NoHttpTransferCache) || hasHttpTransferCacheOptions
  936. ? []
  937. : _withHttpTransferCache({}),
  938. providers,
  939. ]);
  940. }
  941. /**
  942. * @module
  943. * @description
  944. * Entry point for all public APIs of the platform-browser package.
  945. */
  946. /**
  947. * @publicApi
  948. */
  949. const VERSION = new Version('19.2.13');
  950. export { By, DomSanitizer, EVENT_MANAGER_PLUGINS, EventManagerPlugin, HAMMER_GESTURE_CONFIG, HAMMER_LOADER, HammerGestureConfig, HammerModule, HydrationFeatureKind, Meta, Title, VERSION, disableDebugTools, enableDebugTools, provideClientHydration, withEventReplay, withHttpTransferCacheOptions, withI18nSupport, withIncrementalHydration, withNoHttpTransferCache, DomSanitizerImpl as ɵDomSanitizerImpl, HammerGesturesPlugin as ɵHammerGesturesPlugin };
  951. //# sourceMappingURL=platform-browser.mjs.map