@angular/platform-browser 19.2.4 → 19.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,783 @@
1
+ /**
2
+ * @license Angular v19.2.6
3
+ * (c) 2010-2025 Google LLC. https://angular.io/
4
+ * License: MIT
5
+ */
6
+
7
+ import { isPlatformServer, DOCUMENT, ɵgetDOM as _getDOM } from '@angular/common';
8
+ import * as i0 from '@angular/core';
9
+ import { InjectionToken, ɵRuntimeError as _RuntimeError, Inject, Injectable, APP_ID, CSP_NONCE, PLATFORM_ID, Optional, ViewEncapsulation, ɵTracingService as _TracingService, RendererStyleFlags2 } from '@angular/core';
10
+
11
+ /**
12
+ * The injection token for plugins of the `EventManager` service.
13
+ *
14
+ * @publicApi
15
+ */
16
+ const EVENT_MANAGER_PLUGINS = new InjectionToken(ngDevMode ? 'EventManagerPlugins' : '');
17
+ /**
18
+ * An injectable service that provides event management for Angular
19
+ * through a browser plug-in.
20
+ *
21
+ * @publicApi
22
+ */
23
+ class EventManager {
24
+ _zone;
25
+ _plugins;
26
+ _eventNameToPlugin = new Map();
27
+ /**
28
+ * Initializes an instance of the event-manager service.
29
+ */
30
+ constructor(plugins, _zone) {
31
+ this._zone = _zone;
32
+ plugins.forEach((plugin) => {
33
+ plugin.manager = this;
34
+ });
35
+ this._plugins = plugins.slice().reverse();
36
+ }
37
+ /**
38
+ * Registers a handler for a specific element and event.
39
+ *
40
+ * @param element The HTML element to receive event notifications.
41
+ * @param eventName The name of the event to listen for.
42
+ * @param handler A function to call when the notification occurs. Receives the
43
+ * event object as an argument.
44
+ * @param options Options that configure how the event listener is bound.
45
+ * @returns A callback function that can be used to remove the handler.
46
+ */
47
+ addEventListener(element, eventName, handler, options) {
48
+ const plugin = this._findPluginFor(eventName);
49
+ return plugin.addEventListener(element, eventName, handler, options);
50
+ }
51
+ /**
52
+ * Retrieves the compilation zone in which event listeners are registered.
53
+ */
54
+ getZone() {
55
+ return this._zone;
56
+ }
57
+ /** @internal */
58
+ _findPluginFor(eventName) {
59
+ let plugin = this._eventNameToPlugin.get(eventName);
60
+ if (plugin) {
61
+ return plugin;
62
+ }
63
+ const plugins = this._plugins;
64
+ plugin = plugins.find((plugin) => plugin.supports(eventName));
65
+ if (!plugin) {
66
+ throw new _RuntimeError(5101 /* RuntimeErrorCode.NO_PLUGIN_FOR_EVENT */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
67
+ `No event manager plugin found for event ${eventName}`);
68
+ }
69
+ this._eventNameToPlugin.set(eventName, plugin);
70
+ return plugin;
71
+ }
72
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: EventManager, deps: [{ token: EVENT_MANAGER_PLUGINS }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
73
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: EventManager });
74
+ }
75
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: EventManager, decorators: [{
76
+ type: Injectable
77
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
78
+ type: Inject,
79
+ args: [EVENT_MANAGER_PLUGINS]
80
+ }] }, { type: i0.NgZone }] });
81
+ /**
82
+ * The plugin definition for the `EventManager` class
83
+ *
84
+ * It can be used as a base class to create custom manager plugins, i.e. you can create your own
85
+ * class that extends the `EventManagerPlugin` one.
86
+ *
87
+ * @publicApi
88
+ */
89
+ class EventManagerPlugin {
90
+ _doc;
91
+ // TODO: remove (has some usage in G3)
92
+ constructor(_doc) {
93
+ this._doc = _doc;
94
+ }
95
+ // Using non-null assertion because it's set by EventManager's constructor
96
+ manager;
97
+ }
98
+
99
+ /** The style elements attribute name used to set value of `APP_ID` token. */
100
+ const APP_ID_ATTRIBUTE_NAME = 'ng-app-id';
101
+ /**
102
+ * Removes all provided elements from the document.
103
+ * @param elements An array of HTML Elements.
104
+ */
105
+ function removeElements(elements) {
106
+ for (const element of elements) {
107
+ element.remove();
108
+ }
109
+ }
110
+ /**
111
+ * Creates a `style` element with the provided inline style content.
112
+ * @param style A string of the inline style content.
113
+ * @param doc A DOM Document to use to create the element.
114
+ * @returns An HTMLStyleElement instance.
115
+ */
116
+ function createStyleElement(style, doc) {
117
+ const styleElement = doc.createElement('style');
118
+ styleElement.textContent = style;
119
+ return styleElement;
120
+ }
121
+ /**
122
+ * Searches a DOM document's head element for style elements with a matching application
123
+ * identifier attribute (`ng-app-id`) to the provide identifier and adds usage records for each.
124
+ * @param doc An HTML DOM document instance.
125
+ * @param appId A string containing an Angular application identifer.
126
+ * @param inline A Map object for tracking inline (defined via `styles` in component decorator) style usage.
127
+ * @param external A Map object for tracking external (defined via `styleUrls` in component decorator) style usage.
128
+ */
129
+ function addServerStyles(doc, appId, inline, external) {
130
+ const elements = doc.head?.querySelectorAll(`style[${APP_ID_ATTRIBUTE_NAME}="${appId}"],link[${APP_ID_ATTRIBUTE_NAME}="${appId}"]`);
131
+ if (elements) {
132
+ for (const styleElement of elements) {
133
+ styleElement.removeAttribute(APP_ID_ATTRIBUTE_NAME);
134
+ if (styleElement instanceof HTMLLinkElement) {
135
+ // Only use filename from href
136
+ // The href is build time generated with a unique value to prevent duplicates.
137
+ external.set(styleElement.href.slice(styleElement.href.lastIndexOf('/') + 1), {
138
+ usage: 0,
139
+ elements: [styleElement],
140
+ });
141
+ }
142
+ else if (styleElement.textContent) {
143
+ inline.set(styleElement.textContent, { usage: 0, elements: [styleElement] });
144
+ }
145
+ }
146
+ }
147
+ }
148
+ /**
149
+ * Creates a `link` element for the provided external style URL.
150
+ * @param url A string of the URL for the stylesheet.
151
+ * @param doc A DOM Document to use to create the element.
152
+ * @returns An HTMLLinkElement instance.
153
+ */
154
+ function createLinkElement(url, doc) {
155
+ const linkElement = doc.createElement('link');
156
+ linkElement.setAttribute('rel', 'stylesheet');
157
+ linkElement.setAttribute('href', url);
158
+ return linkElement;
159
+ }
160
+ class SharedStylesHost {
161
+ doc;
162
+ appId;
163
+ nonce;
164
+ /**
165
+ * Provides usage information for active inline style content and associated HTML <style> elements.
166
+ * Embedded styles typically originate from the `styles` metadata of a rendered component.
167
+ */
168
+ inline = new Map();
169
+ /**
170
+ * Provides usage information for active external style URLs and the associated HTML <link> elements.
171
+ * External styles typically originate from the `ɵɵExternalStylesFeature` of a rendered component.
172
+ */
173
+ external = new Map();
174
+ /**
175
+ * Set of host DOM nodes that will have styles attached.
176
+ */
177
+ hosts = new Set();
178
+ /**
179
+ * Whether the application code is currently executing on a server.
180
+ */
181
+ isServer;
182
+ constructor(doc, appId, nonce, platformId = {}) {
183
+ this.doc = doc;
184
+ this.appId = appId;
185
+ this.nonce = nonce;
186
+ this.isServer = isPlatformServer(platformId);
187
+ addServerStyles(doc, appId, this.inline, this.external);
188
+ this.hosts.add(doc.head);
189
+ }
190
+ /**
191
+ * Adds embedded styles to the DOM via HTML `style` elements.
192
+ * @param styles An array of style content strings.
193
+ */
194
+ addStyles(styles, urls) {
195
+ for (const value of styles) {
196
+ this.addUsage(value, this.inline, createStyleElement);
197
+ }
198
+ urls?.forEach((value) => this.addUsage(value, this.external, createLinkElement));
199
+ }
200
+ /**
201
+ * Removes embedded styles from the DOM that were added as HTML `style` elements.
202
+ * @param styles An array of style content strings.
203
+ */
204
+ removeStyles(styles, urls) {
205
+ for (const value of styles) {
206
+ this.removeUsage(value, this.inline);
207
+ }
208
+ urls?.forEach((value) => this.removeUsage(value, this.external));
209
+ }
210
+ addUsage(value, usages, creator) {
211
+ // Attempt to get any current usage of the value
212
+ const record = usages.get(value);
213
+ // If existing, just increment the usage count
214
+ if (record) {
215
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && record.usage === 0) {
216
+ // A usage count of zero indicates a preexisting server generated style.
217
+ // This attribute is solely used for debugging purposes of SSR style reuse.
218
+ record.elements.forEach((element) => element.setAttribute('ng-style-reused', ''));
219
+ }
220
+ record.usage++;
221
+ }
222
+ else {
223
+ // Otherwise, create an entry to track the elements and add element for each host
224
+ usages.set(value, {
225
+ usage: 1,
226
+ elements: [...this.hosts].map((host) => this.addElement(host, creator(value, this.doc))),
227
+ });
228
+ }
229
+ }
230
+ removeUsage(value, usages) {
231
+ // Attempt to get any current usage of the value
232
+ const record = usages.get(value);
233
+ // If there is a record, reduce the usage count and if no longer used,
234
+ // remove from DOM and delete usage record.
235
+ if (record) {
236
+ record.usage--;
237
+ if (record.usage <= 0) {
238
+ removeElements(record.elements);
239
+ usages.delete(value);
240
+ }
241
+ }
242
+ }
243
+ ngOnDestroy() {
244
+ for (const [, { elements }] of [...this.inline, ...this.external]) {
245
+ removeElements(elements);
246
+ }
247
+ this.hosts.clear();
248
+ }
249
+ /**
250
+ * Adds a host node to the set of style hosts and adds all existing style usage to
251
+ * the newly added host node.
252
+ *
253
+ * This is currently only used for Shadow DOM encapsulation mode.
254
+ */
255
+ addHost(hostNode) {
256
+ this.hosts.add(hostNode);
257
+ // Add existing styles to new host
258
+ for (const [style, { elements }] of this.inline) {
259
+ elements.push(this.addElement(hostNode, createStyleElement(style, this.doc)));
260
+ }
261
+ for (const [url, { elements }] of this.external) {
262
+ elements.push(this.addElement(hostNode, createLinkElement(url, this.doc)));
263
+ }
264
+ }
265
+ removeHost(hostNode) {
266
+ this.hosts.delete(hostNode);
267
+ }
268
+ addElement(host, element) {
269
+ // Add a nonce if present
270
+ if (this.nonce) {
271
+ element.setAttribute('nonce', this.nonce);
272
+ }
273
+ // Add application identifier when on the server to support client-side reuse
274
+ if (this.isServer) {
275
+ element.setAttribute(APP_ID_ATTRIBUTE_NAME, this.appId);
276
+ }
277
+ // Insert the element into the DOM with the host node as parent
278
+ return host.appendChild(element);
279
+ }
280
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: SharedStylesHost, deps: [{ token: DOCUMENT }, { token: APP_ID }, { token: CSP_NONCE, optional: true }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
281
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: SharedStylesHost });
282
+ }
283
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: SharedStylesHost, decorators: [{
284
+ type: Injectable
285
+ }], ctorParameters: () => [{ type: Document, decorators: [{
286
+ type: Inject,
287
+ args: [DOCUMENT]
288
+ }] }, { type: undefined, decorators: [{
289
+ type: Inject,
290
+ args: [APP_ID]
291
+ }] }, { type: undefined, decorators: [{
292
+ type: Inject,
293
+ args: [CSP_NONCE]
294
+ }, {
295
+ type: Optional
296
+ }] }, { type: undefined, decorators: [{
297
+ type: Inject,
298
+ args: [PLATFORM_ID]
299
+ }] }] });
300
+
301
+ const NAMESPACE_URIS = {
302
+ 'svg': 'http://www.w3.org/2000/svg',
303
+ 'xhtml': 'http://www.w3.org/1999/xhtml',
304
+ 'xlink': 'http://www.w3.org/1999/xlink',
305
+ 'xml': 'http://www.w3.org/XML/1998/namespace',
306
+ 'xmlns': 'http://www.w3.org/2000/xmlns/',
307
+ 'math': 'http://www.w3.org/1998/Math/MathML',
308
+ };
309
+ const COMPONENT_REGEX = /%COMP%/g;
310
+ const SOURCEMAP_URL_REGEXP = /\/\*#\s*sourceMappingURL=(.+?)\s*\*\//;
311
+ const PROTOCOL_REGEXP = /^https?:/;
312
+ const COMPONENT_VARIABLE = '%COMP%';
313
+ const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
314
+ const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
315
+ /**
316
+ * The default value for the `REMOVE_STYLES_ON_COMPONENT_DESTROY` DI token.
317
+ */
318
+ const REMOVE_STYLES_ON_COMPONENT_DESTROY_DEFAULT = true;
319
+ /**
320
+ * A DI token that indicates whether styles
321
+ * of destroyed components should be removed from DOM.
322
+ *
323
+ * By default, the value is set to `true`.
324
+ * @publicApi
325
+ */
326
+ const REMOVE_STYLES_ON_COMPONENT_DESTROY = new InjectionToken(ngDevMode ? 'RemoveStylesOnCompDestroy' : '', {
327
+ providedIn: 'root',
328
+ factory: () => REMOVE_STYLES_ON_COMPONENT_DESTROY_DEFAULT,
329
+ });
330
+ function shimContentAttribute(componentShortId) {
331
+ return CONTENT_ATTR.replace(COMPONENT_REGEX, componentShortId);
332
+ }
333
+ function shimHostAttribute(componentShortId) {
334
+ return HOST_ATTR.replace(COMPONENT_REGEX, componentShortId);
335
+ }
336
+ function shimStylesContent(compId, styles) {
337
+ return styles.map((s) => s.replace(COMPONENT_REGEX, compId));
338
+ }
339
+ /**
340
+ * Prepends a baseHref to the `sourceMappingURL` within the provided CSS content.
341
+ * If the `sourceMappingURL` contains an inline (encoded) map, the function skips processing.
342
+ *
343
+ * @note For inline stylesheets, the `sourceMappingURL` is relative to the page's origin
344
+ * and not the provided baseHref. This function is needed as when accessing the page with a URL
345
+ * containing two or more segments.
346
+ * For example, if the baseHref is set to `/`, and you visit a URL like `http://localhost/foo/bar`,
347
+ * the map would be requested from `http://localhost/foo/bar/comp.css.map` instead of what you'd expect,
348
+ * which is `http://localhost/comp.css.map`. This behavior is corrected by modifying the `sourceMappingURL`
349
+ * to ensure external source maps are loaded relative to the baseHref.
350
+ *
351
+
352
+ * @param baseHref - The base URL to prepend to the `sourceMappingURL`.
353
+ * @param styles - An array of CSS content strings, each potentially containing a `sourceMappingURL`.
354
+ * @returns The updated array of CSS content strings with modified `sourceMappingURL` values,
355
+ * or the original content if no modification is needed.
356
+ */
357
+ function addBaseHrefToCssSourceMap(baseHref, styles) {
358
+ if (!baseHref) {
359
+ return styles;
360
+ }
361
+ const absoluteBaseHrefUrl = new URL(baseHref, 'http://localhost');
362
+ return styles.map((cssContent) => {
363
+ if (!cssContent.includes('sourceMappingURL=')) {
364
+ return cssContent;
365
+ }
366
+ return cssContent.replace(SOURCEMAP_URL_REGEXP, (_, sourceMapUrl) => {
367
+ if (sourceMapUrl[0] === '/' ||
368
+ sourceMapUrl.startsWith('data:') ||
369
+ PROTOCOL_REGEXP.test(sourceMapUrl)) {
370
+ return `/*# sourceMappingURL=${sourceMapUrl} */`;
371
+ }
372
+ const { pathname: resolvedSourceMapUrl } = new URL(sourceMapUrl, absoluteBaseHrefUrl);
373
+ return `/*# sourceMappingURL=${resolvedSourceMapUrl} */`;
374
+ });
375
+ });
376
+ }
377
+ class DomRendererFactory2 {
378
+ eventManager;
379
+ sharedStylesHost;
380
+ appId;
381
+ removeStylesOnCompDestroy;
382
+ doc;
383
+ platformId;
384
+ ngZone;
385
+ nonce;
386
+ tracingService;
387
+ rendererByCompId = new Map();
388
+ defaultRenderer;
389
+ platformIsServer;
390
+ constructor(eventManager, sharedStylesHost, appId, removeStylesOnCompDestroy, doc, platformId, ngZone, nonce = null, tracingService = null) {
391
+ this.eventManager = eventManager;
392
+ this.sharedStylesHost = sharedStylesHost;
393
+ this.appId = appId;
394
+ this.removeStylesOnCompDestroy = removeStylesOnCompDestroy;
395
+ this.doc = doc;
396
+ this.platformId = platformId;
397
+ this.ngZone = ngZone;
398
+ this.nonce = nonce;
399
+ this.tracingService = tracingService;
400
+ this.platformIsServer = isPlatformServer(platformId);
401
+ this.defaultRenderer = new DefaultDomRenderer2(eventManager, doc, ngZone, this.platformIsServer, this.tracingService);
402
+ }
403
+ createRenderer(element, type) {
404
+ if (!element || !type) {
405
+ return this.defaultRenderer;
406
+ }
407
+ if (this.platformIsServer && type.encapsulation === ViewEncapsulation.ShadowDom) {
408
+ // Domino does not support shadow DOM.
409
+ type = { ...type, encapsulation: ViewEncapsulation.Emulated };
410
+ }
411
+ const renderer = this.getOrCreateRenderer(element, type);
412
+ // Renderers have different logic due to different encapsulation behaviours.
413
+ // Ex: for emulated, an attribute is added to the element.
414
+ if (renderer instanceof EmulatedEncapsulationDomRenderer2) {
415
+ renderer.applyToHost(element);
416
+ }
417
+ else if (renderer instanceof NoneEncapsulationDomRenderer) {
418
+ renderer.applyStyles();
419
+ }
420
+ return renderer;
421
+ }
422
+ getOrCreateRenderer(element, type) {
423
+ const rendererByCompId = this.rendererByCompId;
424
+ let renderer = rendererByCompId.get(type.id);
425
+ if (!renderer) {
426
+ const doc = this.doc;
427
+ const ngZone = this.ngZone;
428
+ const eventManager = this.eventManager;
429
+ const sharedStylesHost = this.sharedStylesHost;
430
+ const removeStylesOnCompDestroy = this.removeStylesOnCompDestroy;
431
+ const platformIsServer = this.platformIsServer;
432
+ const tracingService = this.tracingService;
433
+ switch (type.encapsulation) {
434
+ case ViewEncapsulation.Emulated:
435
+ renderer = new EmulatedEncapsulationDomRenderer2(eventManager, sharedStylesHost, type, this.appId, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService);
436
+ break;
437
+ case ViewEncapsulation.ShadowDom:
438
+ return new ShadowDomRenderer(eventManager, sharedStylesHost, element, type, doc, ngZone, this.nonce, platformIsServer, tracingService);
439
+ default:
440
+ renderer = new NoneEncapsulationDomRenderer(eventManager, sharedStylesHost, type, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService);
441
+ break;
442
+ }
443
+ rendererByCompId.set(type.id, renderer);
444
+ }
445
+ return renderer;
446
+ }
447
+ ngOnDestroy() {
448
+ this.rendererByCompId.clear();
449
+ }
450
+ /**
451
+ * Used during HMR to clear any cached data about a component.
452
+ * @param componentId ID of the component that is being replaced.
453
+ */
454
+ componentReplaced(componentId) {
455
+ this.rendererByCompId.delete(componentId);
456
+ }
457
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", 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 });
458
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: DomRendererFactory2 });
459
+ }
460
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: DomRendererFactory2, decorators: [{
461
+ type: Injectable
462
+ }], ctorParameters: () => [{ type: EventManager }, { type: SharedStylesHost }, { type: undefined, decorators: [{
463
+ type: Inject,
464
+ args: [APP_ID]
465
+ }] }, { type: undefined, decorators: [{
466
+ type: Inject,
467
+ args: [REMOVE_STYLES_ON_COMPONENT_DESTROY]
468
+ }] }, { type: Document, decorators: [{
469
+ type: Inject,
470
+ args: [DOCUMENT]
471
+ }] }, { type: Object, decorators: [{
472
+ type: Inject,
473
+ args: [PLATFORM_ID]
474
+ }] }, { type: i0.NgZone }, { type: undefined, decorators: [{
475
+ type: Inject,
476
+ args: [CSP_NONCE]
477
+ }] }, { type: i0.ɵTracingService, decorators: [{
478
+ type: Inject,
479
+ args: [_TracingService]
480
+ }, {
481
+ type: Optional
482
+ }] }] });
483
+ class DefaultDomRenderer2 {
484
+ eventManager;
485
+ doc;
486
+ ngZone;
487
+ platformIsServer;
488
+ tracingService;
489
+ data = Object.create(null);
490
+ /**
491
+ * By default this renderer throws when encountering synthetic properties
492
+ * This can be disabled for example by the AsyncAnimationRendererFactory
493
+ */
494
+ throwOnSyntheticProps = true;
495
+ constructor(eventManager, doc, ngZone, platformIsServer, tracingService) {
496
+ this.eventManager = eventManager;
497
+ this.doc = doc;
498
+ this.ngZone = ngZone;
499
+ this.platformIsServer = platformIsServer;
500
+ this.tracingService = tracingService;
501
+ }
502
+ destroy() { }
503
+ destroyNode = null;
504
+ createElement(name, namespace) {
505
+ if (namespace) {
506
+ // TODO: `|| namespace` was added in
507
+ // https://github.com/angular/angular/commit/2b9cc8503d48173492c29f5a271b61126104fbdb to
508
+ // support how Ivy passed around the namespace URI rather than short name at the time. It did
509
+ // not, however extend the support to other parts of the system (setAttribute, setAttribute,
510
+ // and the ServerRenderer). We should decide what exactly the semantics for dealing with
511
+ // namespaces should be and make it consistent.
512
+ // Related issues:
513
+ // https://github.com/angular/angular/issues/44028
514
+ // https://github.com/angular/angular/issues/44883
515
+ return this.doc.createElementNS(NAMESPACE_URIS[namespace] || namespace, name);
516
+ }
517
+ return this.doc.createElement(name);
518
+ }
519
+ createComment(value) {
520
+ return this.doc.createComment(value);
521
+ }
522
+ createText(value) {
523
+ return this.doc.createTextNode(value);
524
+ }
525
+ appendChild(parent, newChild) {
526
+ const targetParent = isTemplateNode(parent) ? parent.content : parent;
527
+ targetParent.appendChild(newChild);
528
+ }
529
+ insertBefore(parent, newChild, refChild) {
530
+ if (parent) {
531
+ const targetParent = isTemplateNode(parent) ? parent.content : parent;
532
+ targetParent.insertBefore(newChild, refChild);
533
+ }
534
+ }
535
+ removeChild(_parent, oldChild) {
536
+ oldChild.remove();
537
+ }
538
+ selectRootElement(selectorOrNode, preserveContent) {
539
+ let el = typeof selectorOrNode === 'string' ? this.doc.querySelector(selectorOrNode) : selectorOrNode;
540
+ if (!el) {
541
+ throw new _RuntimeError(-5104 /* RuntimeErrorCode.ROOT_NODE_NOT_FOUND */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
542
+ `The selector "${selectorOrNode}" did not match any elements`);
543
+ }
544
+ if (!preserveContent) {
545
+ el.textContent = '';
546
+ }
547
+ return el;
548
+ }
549
+ parentNode(node) {
550
+ return node.parentNode;
551
+ }
552
+ nextSibling(node) {
553
+ return node.nextSibling;
554
+ }
555
+ setAttribute(el, name, value, namespace) {
556
+ if (namespace) {
557
+ name = namespace + ':' + name;
558
+ const namespaceUri = NAMESPACE_URIS[namespace];
559
+ if (namespaceUri) {
560
+ el.setAttributeNS(namespaceUri, name, value);
561
+ }
562
+ else {
563
+ el.setAttribute(name, value);
564
+ }
565
+ }
566
+ else {
567
+ el.setAttribute(name, value);
568
+ }
569
+ }
570
+ removeAttribute(el, name, namespace) {
571
+ if (namespace) {
572
+ const namespaceUri = NAMESPACE_URIS[namespace];
573
+ if (namespaceUri) {
574
+ el.removeAttributeNS(namespaceUri, name);
575
+ }
576
+ else {
577
+ el.removeAttribute(`${namespace}:${name}`);
578
+ }
579
+ }
580
+ else {
581
+ el.removeAttribute(name);
582
+ }
583
+ }
584
+ addClass(el, name) {
585
+ el.classList.add(name);
586
+ }
587
+ removeClass(el, name) {
588
+ el.classList.remove(name);
589
+ }
590
+ setStyle(el, style, value, flags) {
591
+ if (flags & (RendererStyleFlags2.DashCase | RendererStyleFlags2.Important)) {
592
+ el.style.setProperty(style, value, flags & RendererStyleFlags2.Important ? 'important' : '');
593
+ }
594
+ else {
595
+ el.style[style] = value;
596
+ }
597
+ }
598
+ removeStyle(el, style, flags) {
599
+ if (flags & RendererStyleFlags2.DashCase) {
600
+ // removeProperty has no effect when used on camelCased properties.
601
+ el.style.removeProperty(style);
602
+ }
603
+ else {
604
+ el.style[style] = '';
605
+ }
606
+ }
607
+ setProperty(el, name, value) {
608
+ if (el == null) {
609
+ return;
610
+ }
611
+ (typeof ngDevMode === 'undefined' || ngDevMode) &&
612
+ this.throwOnSyntheticProps &&
613
+ checkNoSyntheticProp(name, 'property');
614
+ el[name] = value;
615
+ }
616
+ setValue(node, value) {
617
+ node.nodeValue = value;
618
+ }
619
+ listen(target, event, callback, options) {
620
+ (typeof ngDevMode === 'undefined' || ngDevMode) &&
621
+ this.throwOnSyntheticProps &&
622
+ checkNoSyntheticProp(event, 'listener');
623
+ if (typeof target === 'string') {
624
+ target = _getDOM().getGlobalEventTarget(this.doc, target);
625
+ if (!target) {
626
+ throw new _RuntimeError(5102 /* RuntimeErrorCode.UNSUPPORTED_EVENT_TARGET */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
627
+ `Unsupported event target ${target} for event ${event}`);
628
+ }
629
+ }
630
+ let wrappedCallback = this.decoratePreventDefault(callback);
631
+ if (this.tracingService?.wrapEventListener) {
632
+ wrappedCallback = this.tracingService.wrapEventListener(target, event, wrappedCallback);
633
+ }
634
+ return this.eventManager.addEventListener(target, event, wrappedCallback, options);
635
+ }
636
+ decoratePreventDefault(eventHandler) {
637
+ // `DebugNode.triggerEventHandler` needs to know if the listener was created with
638
+ // decoratePreventDefault or is a listener added outside the Angular context so it can handle
639
+ // the two differently. In the first case, the special '__ngUnwrap__' token is passed to the
640
+ // unwrap the listener (see below).
641
+ return (event) => {
642
+ // Ivy uses '__ngUnwrap__' as a special token that allows us to unwrap the function
643
+ // so that it can be invoked programmatically by `DebugNode.triggerEventHandler`. The
644
+ // debug_node can inspect the listener toString contents for the existence of this special
645
+ // token. Because the token is a string literal, it is ensured to not be modified by compiled
646
+ // code.
647
+ if (event === '__ngUnwrap__') {
648
+ return eventHandler;
649
+ }
650
+ // Run the event handler inside the ngZone because event handlers are not patched
651
+ // by Zone on the server. This is required only for tests.
652
+ const allowDefaultBehavior = this.platformIsServer
653
+ ? this.ngZone.runGuarded(() => eventHandler(event))
654
+ : eventHandler(event);
655
+ if (allowDefaultBehavior === false) {
656
+ event.preventDefault();
657
+ }
658
+ return undefined;
659
+ };
660
+ }
661
+ }
662
+ const AT_CHARCODE = (() => '@'.charCodeAt(0))();
663
+ function checkNoSyntheticProp(name, nameKind) {
664
+ if (name.charCodeAt(0) === AT_CHARCODE) {
665
+ throw new _RuntimeError(5105 /* RuntimeErrorCode.UNEXPECTED_SYNTHETIC_PROPERTY */, `Unexpected synthetic ${nameKind} ${name} found. Please make sure that:
666
+ - Make sure \`provideAnimationsAsync()\`, \`provideAnimations()\` or \`provideNoopAnimations()\` call was added to a list of providers used to bootstrap an application.
667
+ - 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).`);
668
+ }
669
+ }
670
+ function isTemplateNode(node) {
671
+ return node.tagName === 'TEMPLATE' && node.content !== undefined;
672
+ }
673
+ class ShadowDomRenderer extends DefaultDomRenderer2 {
674
+ sharedStylesHost;
675
+ hostEl;
676
+ shadowRoot;
677
+ constructor(eventManager, sharedStylesHost, hostEl, component, doc, ngZone, nonce, platformIsServer, tracingService) {
678
+ super(eventManager, doc, ngZone, platformIsServer, tracingService);
679
+ this.sharedStylesHost = sharedStylesHost;
680
+ this.hostEl = hostEl;
681
+ this.shadowRoot = hostEl.attachShadow({ mode: 'open' });
682
+ this.sharedStylesHost.addHost(this.shadowRoot);
683
+ let styles = component.styles;
684
+ if (ngDevMode) {
685
+ // We only do this in development, as for production users should not add CSS sourcemaps to components.
686
+ const baseHref = _getDOM().getBaseHref(doc) ?? '';
687
+ styles = addBaseHrefToCssSourceMap(baseHref, styles);
688
+ }
689
+ styles = shimStylesContent(component.id, styles);
690
+ for (const style of styles) {
691
+ const styleEl = document.createElement('style');
692
+ if (nonce) {
693
+ styleEl.setAttribute('nonce', nonce);
694
+ }
695
+ styleEl.textContent = style;
696
+ this.shadowRoot.appendChild(styleEl);
697
+ }
698
+ // Apply any external component styles to the shadow root for the component's element.
699
+ // The ShadowDOM renderer uses an alternative execution path for component styles that
700
+ // does not use the SharedStylesHost that other encapsulation modes leverage. Much like
701
+ // the manual addition of embedded styles directly above, any external stylesheets
702
+ // must be manually added here to ensure ShadowDOM components are correctly styled.
703
+ // TODO: Consider reworking the DOM Renderers to consolidate style handling.
704
+ const styleUrls = component.getExternalStyles?.();
705
+ if (styleUrls) {
706
+ for (const styleUrl of styleUrls) {
707
+ const linkEl = createLinkElement(styleUrl, doc);
708
+ if (nonce) {
709
+ linkEl.setAttribute('nonce', nonce);
710
+ }
711
+ this.shadowRoot.appendChild(linkEl);
712
+ }
713
+ }
714
+ }
715
+ nodeOrShadowRoot(node) {
716
+ return node === this.hostEl ? this.shadowRoot : node;
717
+ }
718
+ appendChild(parent, newChild) {
719
+ return super.appendChild(this.nodeOrShadowRoot(parent), newChild);
720
+ }
721
+ insertBefore(parent, newChild, refChild) {
722
+ return super.insertBefore(this.nodeOrShadowRoot(parent), newChild, refChild);
723
+ }
724
+ removeChild(_parent, oldChild) {
725
+ return super.removeChild(null, oldChild);
726
+ }
727
+ parentNode(node) {
728
+ return this.nodeOrShadowRoot(super.parentNode(this.nodeOrShadowRoot(node)));
729
+ }
730
+ destroy() {
731
+ this.sharedStylesHost.removeHost(this.shadowRoot);
732
+ }
733
+ }
734
+ class NoneEncapsulationDomRenderer extends DefaultDomRenderer2 {
735
+ sharedStylesHost;
736
+ removeStylesOnCompDestroy;
737
+ styles;
738
+ styleUrls;
739
+ constructor(eventManager, sharedStylesHost, component, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, compId) {
740
+ super(eventManager, doc, ngZone, platformIsServer, tracingService);
741
+ this.sharedStylesHost = sharedStylesHost;
742
+ this.removeStylesOnCompDestroy = removeStylesOnCompDestroy;
743
+ let styles = component.styles;
744
+ if (ngDevMode) {
745
+ // We only do this in development, as for production users should not add CSS sourcemaps to components.
746
+ const baseHref = _getDOM().getBaseHref(doc) ?? '';
747
+ styles = addBaseHrefToCssSourceMap(baseHref, styles);
748
+ }
749
+ this.styles = compId ? shimStylesContent(compId, styles) : styles;
750
+ this.styleUrls = component.getExternalStyles?.(compId);
751
+ }
752
+ applyStyles() {
753
+ this.sharedStylesHost.addStyles(this.styles, this.styleUrls);
754
+ }
755
+ destroy() {
756
+ if (!this.removeStylesOnCompDestroy) {
757
+ return;
758
+ }
759
+ this.sharedStylesHost.removeStyles(this.styles, this.styleUrls);
760
+ }
761
+ }
762
+ class EmulatedEncapsulationDomRenderer2 extends NoneEncapsulationDomRenderer {
763
+ contentAttr;
764
+ hostAttr;
765
+ constructor(eventManager, sharedStylesHost, component, appId, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService) {
766
+ const compId = appId + '-' + component.id;
767
+ super(eventManager, sharedStylesHost, component, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, compId);
768
+ this.contentAttr = shimContentAttribute(compId);
769
+ this.hostAttr = shimHostAttribute(compId);
770
+ }
771
+ applyToHost(element) {
772
+ this.applyStyles();
773
+ this.setAttribute(element, this.hostAttr, '');
774
+ }
775
+ createElement(parent, name) {
776
+ const el = super.createElement(parent, name);
777
+ super.setAttribute(el, this.contentAttr, '');
778
+ return el;
779
+ }
780
+ }
781
+
782
+ export { DomRendererFactory2, EVENT_MANAGER_PLUGINS, EventManager, EventManagerPlugin, REMOVE_STYLES_ON_COMPONENT_DESTROY, SharedStylesHost };
783
+ //# sourceMappingURL=dom_renderer-DGKzginR.mjs.map