@angular/platform-browser 21.0.0-next.1 → 21.0.0-next.10

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.
@@ -1,837 +0,0 @@
1
- /**
2
- * @license Angular v21.0.0-next.1
3
- * (c) 2010-2025 Google LLC. https://angular.io/
4
- * License: MIT
5
- */
6
-
7
- import { DOCUMENT, ɵgetDOM as _getDOM } from '@angular/common';
8
- import * as i0 from '@angular/core';
9
- import { InjectionToken, ɵRuntimeError as _RuntimeError, Injectable, Inject, APP_ID, CSP_NONCE, PLATFORM_ID, Optional, ɵgetAnimationElementRemovalRegistry as _getAnimationElementRemovalRegistry, ViewEncapsulation, ɵANIMATIONS_DISABLED as _ANIMATIONS_DISABLED, MAX_ANIMATION_TIMEOUT, ɵ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: "20.2.0-next.2", 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: "20.2.0-next.2", ngImport: i0, type: EventManager });
74
- }
75
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", 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
- constructor(doc, appId, nonce,
179
- // Cannot remove it due to backward compatibility
180
- // (it seems some TGP targets might be calling this constructor directly).
181
- platformId = {}) {
182
- this.doc = doc;
183
- this.appId = appId;
184
- this.nonce = nonce;
185
- addServerStyles(doc, appId, this.inline, this.external);
186
- this.hosts.add(doc.head);
187
- }
188
- /**
189
- * Adds embedded styles to the DOM via HTML `style` elements.
190
- * @param styles An array of style content strings.
191
- */
192
- addStyles(styles, urls) {
193
- for (const value of styles) {
194
- this.addUsage(value, this.inline, createStyleElement);
195
- }
196
- urls?.forEach((value) => this.addUsage(value, this.external, createLinkElement));
197
- }
198
- /**
199
- * Removes embedded styles from the DOM that were added as HTML `style` elements.
200
- * @param styles An array of style content strings.
201
- */
202
- removeStyles(styles, urls) {
203
- for (const value of styles) {
204
- this.removeUsage(value, this.inline);
205
- }
206
- urls?.forEach((value) => this.removeUsage(value, this.external));
207
- }
208
- addUsage(value, usages, creator) {
209
- // Attempt to get any current usage of the value
210
- const record = usages.get(value);
211
- // If existing, just increment the usage count
212
- if (record) {
213
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && record.usage === 0) {
214
- // A usage count of zero indicates a preexisting server generated style.
215
- // This attribute is solely used for debugging purposes of SSR style reuse.
216
- record.elements.forEach((element) => element.setAttribute('ng-style-reused', ''));
217
- }
218
- record.usage++;
219
- }
220
- else {
221
- // Otherwise, create an entry to track the elements and add element for each host
222
- usages.set(value, {
223
- usage: 1,
224
- elements: [...this.hosts].map((host) => this.addElement(host, creator(value, this.doc))),
225
- });
226
- }
227
- }
228
- removeUsage(value, usages) {
229
- // Attempt to get any current usage of the value
230
- const record = usages.get(value);
231
- // If there is a record, reduce the usage count and if no longer used,
232
- // remove from DOM and delete usage record.
233
- if (record) {
234
- record.usage--;
235
- if (record.usage <= 0) {
236
- removeElements(record.elements);
237
- usages.delete(value);
238
- }
239
- }
240
- }
241
- ngOnDestroy() {
242
- for (const [, { elements }] of [...this.inline, ...this.external]) {
243
- removeElements(elements);
244
- }
245
- this.hosts.clear();
246
- }
247
- /**
248
- * Adds a host node to the set of style hosts and adds all existing style usage to
249
- * the newly added host node.
250
- *
251
- * This is currently only used for Shadow DOM encapsulation mode.
252
- */
253
- addHost(hostNode) {
254
- this.hosts.add(hostNode);
255
- // Add existing styles to new host
256
- for (const [style, { elements }] of this.inline) {
257
- elements.push(this.addElement(hostNode, createStyleElement(style, this.doc)));
258
- }
259
- for (const [url, { elements }] of this.external) {
260
- elements.push(this.addElement(hostNode, createLinkElement(url, this.doc)));
261
- }
262
- }
263
- removeHost(hostNode) {
264
- this.hosts.delete(hostNode);
265
- }
266
- addElement(host, element) {
267
- // Add a nonce if present
268
- if (this.nonce) {
269
- element.setAttribute('nonce', this.nonce);
270
- }
271
- // Add application identifier when on the server to support client-side reuse
272
- if (typeof ngServerMode !== 'undefined' && ngServerMode) {
273
- element.setAttribute(APP_ID_ATTRIBUTE_NAME, this.appId);
274
- }
275
- // Insert the element into the DOM with the host node as parent
276
- return host.appendChild(element);
277
- }
278
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: SharedStylesHost, deps: [{ token: DOCUMENT }, { token: APP_ID }, { token: CSP_NONCE, optional: true }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
279
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: SharedStylesHost });
280
- }
281
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: SharedStylesHost, decorators: [{
282
- type: Injectable
283
- }], ctorParameters: () => [{ type: Document, decorators: [{
284
- type: Inject,
285
- args: [DOCUMENT]
286
- }] }, { type: undefined, decorators: [{
287
- type: Inject,
288
- args: [APP_ID]
289
- }] }, { type: undefined, decorators: [{
290
- type: Inject,
291
- args: [CSP_NONCE]
292
- }, {
293
- type: Optional
294
- }] }, { type: undefined, decorators: [{
295
- type: Inject,
296
- args: [PLATFORM_ID]
297
- }] }] });
298
-
299
- const NAMESPACE_URIS = {
300
- 'svg': 'http://www.w3.org/2000/svg',
301
- 'xhtml': 'http://www.w3.org/1999/xhtml',
302
- 'xlink': 'http://www.w3.org/1999/xlink',
303
- 'xml': 'http://www.w3.org/XML/1998/namespace',
304
- 'xmlns': 'http://www.w3.org/2000/xmlns/',
305
- 'math': 'http://www.w3.org/1998/Math/MathML',
306
- };
307
- const COMPONENT_REGEX = /%COMP%/g;
308
- const SOURCEMAP_URL_REGEXP = /\/\*#\s*sourceMappingURL=(.+?)\s*\*\//;
309
- const PROTOCOL_REGEXP = /^https?:/;
310
- const COMPONENT_VARIABLE = '%COMP%';
311
- const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
312
- const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
313
- /**
314
- * The default value for the `REMOVE_STYLES_ON_COMPONENT_DESTROY` DI token.
315
- */
316
- const REMOVE_STYLES_ON_COMPONENT_DESTROY_DEFAULT = true;
317
- /**
318
- * A DI token that indicates whether styles
319
- * of destroyed components should be removed from DOM.
320
- *
321
- * By default, the value is set to `true`.
322
- * @publicApi
323
- */
324
- const REMOVE_STYLES_ON_COMPONENT_DESTROY = new InjectionToken(ngDevMode ? 'RemoveStylesOnCompDestroy' : '', {
325
- providedIn: 'root',
326
- factory: () => REMOVE_STYLES_ON_COMPONENT_DESTROY_DEFAULT,
327
- });
328
- function shimContentAttribute(componentShortId) {
329
- return CONTENT_ATTR.replace(COMPONENT_REGEX, componentShortId);
330
- }
331
- function shimHostAttribute(componentShortId) {
332
- return HOST_ATTR.replace(COMPONENT_REGEX, componentShortId);
333
- }
334
- function shimStylesContent(compId, styles) {
335
- return styles.map((s) => s.replace(COMPONENT_REGEX, compId));
336
- }
337
- /**
338
- * Prepends a baseHref to the `sourceMappingURL` within the provided CSS content.
339
- * If the `sourceMappingURL` contains an inline (encoded) map, the function skips processing.
340
- *
341
- * @note For inline stylesheets, the `sourceMappingURL` is relative to the page's origin
342
- * and not the provided baseHref. This function is needed as when accessing the page with a URL
343
- * containing two or more segments.
344
- * For example, if the baseHref is set to `/`, and you visit a URL like `http://localhost/foo/bar`,
345
- * the map would be requested from `http://localhost/foo/bar/comp.css.map` instead of what you'd expect,
346
- * which is `http://localhost/comp.css.map`. This behavior is corrected by modifying the `sourceMappingURL`
347
- * to ensure external source maps are loaded relative to the baseHref.
348
- *
349
-
350
- * @param baseHref - The base URL to prepend to the `sourceMappingURL`.
351
- * @param styles - An array of CSS content strings, each potentially containing a `sourceMappingURL`.
352
- * @returns The updated array of CSS content strings with modified `sourceMappingURL` values,
353
- * or the original content if no modification is needed.
354
- */
355
- function addBaseHrefToCssSourceMap(baseHref, styles) {
356
- if (!baseHref) {
357
- return styles;
358
- }
359
- const absoluteBaseHrefUrl = new URL(baseHref, 'http://localhost');
360
- return styles.map((cssContent) => {
361
- if (!cssContent.includes('sourceMappingURL=')) {
362
- return cssContent;
363
- }
364
- return cssContent.replace(SOURCEMAP_URL_REGEXP, (_, sourceMapUrl) => {
365
- if (sourceMapUrl[0] === '/' ||
366
- sourceMapUrl.startsWith('data:') ||
367
- PROTOCOL_REGEXP.test(sourceMapUrl)) {
368
- return `/*# sourceMappingURL=${sourceMapUrl} */`;
369
- }
370
- const { pathname: resolvedSourceMapUrl } = new URL(sourceMapUrl, absoluteBaseHrefUrl);
371
- return `/*# sourceMappingURL=${resolvedSourceMapUrl} */`;
372
- });
373
- });
374
- }
375
- class DomRendererFactory2 {
376
- eventManager;
377
- sharedStylesHost;
378
- appId;
379
- removeStylesOnCompDestroy;
380
- doc;
381
- platformId;
382
- ngZone;
383
- nonce;
384
- animationDisabled;
385
- maxAnimationTimeout;
386
- tracingService;
387
- rendererByCompId = new Map();
388
- defaultRenderer;
389
- platformIsServer;
390
- registry;
391
- constructor(eventManager, sharedStylesHost, appId, removeStylesOnCompDestroy, doc, platformId, ngZone, nonce = null, animationDisabled, maxAnimationTimeout, tracingService = null) {
392
- this.eventManager = eventManager;
393
- this.sharedStylesHost = sharedStylesHost;
394
- this.appId = appId;
395
- this.removeStylesOnCompDestroy = removeStylesOnCompDestroy;
396
- this.doc = doc;
397
- this.platformId = platformId;
398
- this.ngZone = ngZone;
399
- this.nonce = nonce;
400
- this.animationDisabled = animationDisabled;
401
- this.maxAnimationTimeout = maxAnimationTimeout;
402
- this.tracingService = tracingService;
403
- this.platformIsServer = typeof ngServerMode !== 'undefined' && ngServerMode;
404
- this.defaultRenderer = new DefaultDomRenderer2(eventManager, doc, ngZone, this.platformIsServer, this.tracingService, (this.registry = _getAnimationElementRemovalRegistry()), this.maxAnimationTimeout);
405
- }
406
- createRenderer(element, type) {
407
- if (!element || !type) {
408
- return this.defaultRenderer;
409
- }
410
- if (typeof ngServerMode !== 'undefined' &&
411
- ngServerMode &&
412
- (type.encapsulation === ViewEncapsulation.ShadowDom ||
413
- type.encapsulation === ViewEncapsulation.IsolatedShadowDom)) {
414
- // Domino does not support shadow DOM.
415
- type = { ...type, encapsulation: ViewEncapsulation.Emulated };
416
- }
417
- const renderer = this.getOrCreateRenderer(element, type);
418
- // Renderers have different logic due to different encapsulation behaviours.
419
- // Ex: for emulated, an attribute is added to the element.
420
- if (renderer instanceof EmulatedEncapsulationDomRenderer2) {
421
- renderer.applyToHost(element);
422
- }
423
- else if (renderer instanceof NoneEncapsulationDomRenderer) {
424
- renderer.applyStyles();
425
- }
426
- return renderer;
427
- }
428
- getOrCreateRenderer(element, type) {
429
- const rendererByCompId = this.rendererByCompId;
430
- let renderer = rendererByCompId.get(type.id);
431
- if (!renderer) {
432
- const doc = this.doc;
433
- const ngZone = this.ngZone;
434
- const eventManager = this.eventManager;
435
- const sharedStylesHost = this.sharedStylesHost;
436
- const removeStylesOnCompDestroy = this.removeStylesOnCompDestroy;
437
- const platformIsServer = this.platformIsServer;
438
- const tracingService = this.tracingService;
439
- switch (type.encapsulation) {
440
- case ViewEncapsulation.Emulated:
441
- renderer = new EmulatedEncapsulationDomRenderer2(eventManager, sharedStylesHost, type, this.appId, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, this.registry, this.animationDisabled, this.maxAnimationTimeout);
442
- break;
443
- case ViewEncapsulation.ShadowDom:
444
- return new ShadowDomRenderer(eventManager, element, type, doc, ngZone, this.nonce, platformIsServer, tracingService, this.registry, this.maxAnimationTimeout, sharedStylesHost);
445
- case ViewEncapsulation.IsolatedShadowDom:
446
- return new ShadowDomRenderer(eventManager, element, type, doc, ngZone, this.nonce, platformIsServer, tracingService, this.registry, this.maxAnimationTimeout);
447
- default:
448
- renderer = new NoneEncapsulationDomRenderer(eventManager, sharedStylesHost, type, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, this.registry, this.animationDisabled, this.maxAnimationTimeout);
449
- break;
450
- }
451
- rendererByCompId.set(type.id, renderer);
452
- }
453
- return renderer;
454
- }
455
- ngOnDestroy() {
456
- this.rendererByCompId.clear();
457
- }
458
- /**
459
- * Used during HMR to clear any cached data about a component.
460
- * @param componentId ID of the component that is being replaced.
461
- */
462
- componentReplaced(componentId) {
463
- this.rendererByCompId.delete(componentId);
464
- }
465
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0-next.2", 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: _ANIMATIONS_DISABLED }, { token: MAX_ANIMATION_TIMEOUT }, { token: _TracingService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
466
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: DomRendererFactory2 });
467
- }
468
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0-next.2", ngImport: i0, type: DomRendererFactory2, decorators: [{
469
- type: Injectable
470
- }], ctorParameters: () => [{ type: EventManager }, { type: SharedStylesHost }, { type: undefined, decorators: [{
471
- type: Inject,
472
- args: [APP_ID]
473
- }] }, { type: undefined, decorators: [{
474
- type: Inject,
475
- args: [REMOVE_STYLES_ON_COMPONENT_DESTROY]
476
- }] }, { type: Document, decorators: [{
477
- type: Inject,
478
- args: [DOCUMENT]
479
- }] }, { type: Object, decorators: [{
480
- type: Inject,
481
- args: [PLATFORM_ID]
482
- }] }, { type: i0.NgZone }, { type: undefined, decorators: [{
483
- type: Inject,
484
- args: [CSP_NONCE]
485
- }] }, { type: undefined, decorators: [{
486
- type: Inject,
487
- args: [_ANIMATIONS_DISABLED]
488
- }] }, { type: undefined, decorators: [{
489
- type: Inject,
490
- args: [MAX_ANIMATION_TIMEOUT]
491
- }] }, { type: i0.ɵTracingService, decorators: [{
492
- type: Inject,
493
- args: [_TracingService]
494
- }, {
495
- type: Optional
496
- }] }] });
497
- class DefaultDomRenderer2 {
498
- eventManager;
499
- doc;
500
- ngZone;
501
- platformIsServer;
502
- tracingService;
503
- registry;
504
- maxAnimationTimeout;
505
- data = Object.create(null);
506
- /**
507
- * By default this renderer throws when encountering synthetic properties
508
- * This can be disabled for example by the AsyncAnimationRendererFactory
509
- */
510
- throwOnSyntheticProps = true;
511
- constructor(eventManager, doc, ngZone, platformIsServer, tracingService, registry, maxAnimationTimeout) {
512
- this.eventManager = eventManager;
513
- this.doc = doc;
514
- this.ngZone = ngZone;
515
- this.platformIsServer = platformIsServer;
516
- this.tracingService = tracingService;
517
- this.registry = registry;
518
- this.maxAnimationTimeout = maxAnimationTimeout;
519
- }
520
- destroy() { }
521
- destroyNode = null;
522
- createElement(name, namespace) {
523
- if (namespace) {
524
- // TODO: `|| namespace` was added in
525
- // https://github.com/angular/angular/commit/2b9cc8503d48173492c29f5a271b61126104fbdb to
526
- // support how Ivy passed around the namespace URI rather than short name at the time. It did
527
- // not, however extend the support to other parts of the system (setAttribute, setAttribute,
528
- // and the ServerRenderer). We should decide what exactly the semantics for dealing with
529
- // namespaces should be and make it consistent.
530
- // Related issues:
531
- // https://github.com/angular/angular/issues/44028
532
- // https://github.com/angular/angular/issues/44883
533
- return this.doc.createElementNS(NAMESPACE_URIS[namespace] || namespace, name);
534
- }
535
- return this.doc.createElement(name);
536
- }
537
- createComment(value) {
538
- return this.doc.createComment(value);
539
- }
540
- createText(value) {
541
- return this.doc.createTextNode(value);
542
- }
543
- appendChild(parent, newChild) {
544
- const targetParent = isTemplateNode(parent) ? parent.content : parent;
545
- targetParent.appendChild(newChild);
546
- }
547
- insertBefore(parent, newChild, refChild) {
548
- if (parent) {
549
- const targetParent = isTemplateNode(parent) ? parent.content : parent;
550
- targetParent.insertBefore(newChild, refChild);
551
- }
552
- }
553
- removeChild(_parent, oldChild) {
554
- const { elements } = this.registry;
555
- if (elements) {
556
- elements.animate(oldChild, () => oldChild.remove(), this.maxAnimationTimeout);
557
- return;
558
- }
559
- // child was removed
560
- oldChild.remove();
561
- }
562
- selectRootElement(selectorOrNode, preserveContent) {
563
- let el = typeof selectorOrNode === 'string' ? this.doc.querySelector(selectorOrNode) : selectorOrNode;
564
- if (!el) {
565
- throw new _RuntimeError(-5104 /* RuntimeErrorCode.ROOT_NODE_NOT_FOUND */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
566
- `The selector "${selectorOrNode}" did not match any elements`);
567
- }
568
- if (!preserveContent) {
569
- el.textContent = '';
570
- }
571
- return el;
572
- }
573
- parentNode(node) {
574
- return node.parentNode;
575
- }
576
- nextSibling(node) {
577
- return node.nextSibling;
578
- }
579
- setAttribute(el, name, value, namespace) {
580
- if (namespace) {
581
- name = namespace + ':' + name;
582
- const namespaceUri = NAMESPACE_URIS[namespace];
583
- if (namespaceUri) {
584
- el.setAttributeNS(namespaceUri, name, value);
585
- }
586
- else {
587
- el.setAttribute(name, value);
588
- }
589
- }
590
- else {
591
- el.setAttribute(name, value);
592
- }
593
- }
594
- removeAttribute(el, name, namespace) {
595
- if (namespace) {
596
- const namespaceUri = NAMESPACE_URIS[namespace];
597
- if (namespaceUri) {
598
- el.removeAttributeNS(namespaceUri, name);
599
- }
600
- else {
601
- el.removeAttribute(`${namespace}:${name}`);
602
- }
603
- }
604
- else {
605
- el.removeAttribute(name);
606
- }
607
- }
608
- addClass(el, name) {
609
- el.classList.add(name);
610
- }
611
- removeClass(el, name) {
612
- el.classList.remove(name);
613
- }
614
- setStyle(el, style, value, flags) {
615
- if (flags & (RendererStyleFlags2.DashCase | RendererStyleFlags2.Important)) {
616
- el.style.setProperty(style, value, flags & RendererStyleFlags2.Important ? 'important' : '');
617
- }
618
- else {
619
- el.style[style] = value;
620
- }
621
- }
622
- removeStyle(el, style, flags) {
623
- if (flags & RendererStyleFlags2.DashCase) {
624
- // removeProperty has no effect when used on camelCased properties.
625
- el.style.removeProperty(style);
626
- }
627
- else {
628
- el.style[style] = '';
629
- }
630
- }
631
- setProperty(el, name, value) {
632
- if (el == null) {
633
- return;
634
- }
635
- (typeof ngDevMode === 'undefined' || ngDevMode) &&
636
- this.throwOnSyntheticProps &&
637
- checkNoSyntheticProp(name, 'property');
638
- el[name] = value;
639
- }
640
- setValue(node, value) {
641
- node.nodeValue = value;
642
- }
643
- listen(target, event, callback, options) {
644
- (typeof ngDevMode === 'undefined' || ngDevMode) &&
645
- this.throwOnSyntheticProps &&
646
- checkNoSyntheticProp(event, 'listener');
647
- if (typeof target === 'string') {
648
- target = _getDOM().getGlobalEventTarget(this.doc, target);
649
- if (!target) {
650
- throw new _RuntimeError(5102 /* RuntimeErrorCode.UNSUPPORTED_EVENT_TARGET */, (typeof ngDevMode === 'undefined' || ngDevMode) &&
651
- `Unsupported event target ${target} for event ${event}`);
652
- }
653
- }
654
- let wrappedCallback = this.decoratePreventDefault(callback);
655
- if (this.tracingService?.wrapEventListener) {
656
- wrappedCallback = this.tracingService.wrapEventListener(target, event, wrappedCallback);
657
- }
658
- return this.eventManager.addEventListener(target, event, wrappedCallback, options);
659
- }
660
- decoratePreventDefault(eventHandler) {
661
- // `DebugNode.triggerEventHandler` needs to know if the listener was created with
662
- // decoratePreventDefault or is a listener added outside the Angular context so it can handle
663
- // the two differently. In the first case, the special '__ngUnwrap__' token is passed to the
664
- // unwrap the listener (see below).
665
- return (event) => {
666
- // Ivy uses '__ngUnwrap__' as a special token that allows us to unwrap the function
667
- // so that it can be invoked programmatically by `DebugNode.triggerEventHandler`. The
668
- // debug_node can inspect the listener toString contents for the existence of this special
669
- // token. Because the token is a string literal, it is ensured to not be modified by compiled
670
- // code.
671
- if (event === '__ngUnwrap__') {
672
- return eventHandler;
673
- }
674
- // Run the event handler inside the ngZone because event handlers are not patched
675
- // by Zone on the server. This is required only for tests.
676
- const allowDefaultBehavior = typeof ngServerMode !== 'undefined' && ngServerMode
677
- ? this.ngZone.runGuarded(() => eventHandler(event))
678
- : eventHandler(event);
679
- if (allowDefaultBehavior === false) {
680
- event.preventDefault();
681
- }
682
- return undefined;
683
- };
684
- }
685
- }
686
- const AT_CHARCODE = (() => '@'.charCodeAt(0))();
687
- function checkNoSyntheticProp(name, nameKind) {
688
- if (name.charCodeAt(0) === AT_CHARCODE) {
689
- throw new _RuntimeError(5105 /* RuntimeErrorCode.UNEXPECTED_SYNTHETIC_PROPERTY */, `Unexpected synthetic ${nameKind} ${name} found. Please make sure that:
690
- - Make sure \`provideAnimationsAsync()\`, \`provideAnimations()\` or \`provideNoopAnimations()\` call was added to a list of providers used to bootstrap an application.
691
- - 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).`);
692
- }
693
- }
694
- function isTemplateNode(node) {
695
- return node.tagName === 'TEMPLATE' && node.content !== undefined;
696
- }
697
- class ShadowDomRenderer extends DefaultDomRenderer2 {
698
- hostEl;
699
- sharedStylesHost;
700
- shadowRoot;
701
- constructor(eventManager, hostEl, component, doc, ngZone, nonce, platformIsServer, tracingService, registry, maxAnimationTimeout, sharedStylesHost) {
702
- super(eventManager, doc, ngZone, platformIsServer, tracingService, registry, maxAnimationTimeout);
703
- this.hostEl = hostEl;
704
- this.sharedStylesHost = sharedStylesHost;
705
- this.shadowRoot = hostEl.attachShadow({ mode: 'open' });
706
- // SharedStylesHost is used to add styles to the shadow root by ShadowDom.
707
- // This is optional as it is not used by IsolatedShadowDom.
708
- if (this.sharedStylesHost) {
709
- this.sharedStylesHost.addHost(this.shadowRoot);
710
- }
711
- let styles = component.styles;
712
- if (ngDevMode) {
713
- // We only do this in development, as for production users should not add CSS sourcemaps to components.
714
- const baseHref = _getDOM().getBaseHref(doc) ?? '';
715
- styles = addBaseHrefToCssSourceMap(baseHref, styles);
716
- }
717
- styles = shimStylesContent(component.id, styles);
718
- for (const style of styles) {
719
- const styleEl = document.createElement('style');
720
- if (nonce) {
721
- styleEl.setAttribute('nonce', nonce);
722
- }
723
- styleEl.textContent = style;
724
- this.shadowRoot.appendChild(styleEl);
725
- }
726
- // Apply any external component styles to the shadow root for the component's element.
727
- // The ShadowDOM renderer uses an alternative execution path for component styles that
728
- // does not use the SharedStylesHost that other encapsulation modes leverage. Much like
729
- // the manual addition of embedded styles directly above, any external stylesheets
730
- // must be manually added here to ensure ShadowDOM components are correctly styled.
731
- // TODO: Consider reworking the DOM Renderers to consolidate style handling.
732
- const styleUrls = component.getExternalStyles?.();
733
- if (styleUrls) {
734
- for (const styleUrl of styleUrls) {
735
- const linkEl = createLinkElement(styleUrl, doc);
736
- if (nonce) {
737
- linkEl.setAttribute('nonce', nonce);
738
- }
739
- this.shadowRoot.appendChild(linkEl);
740
- }
741
- }
742
- }
743
- nodeOrShadowRoot(node) {
744
- return node === this.hostEl ? this.shadowRoot : node;
745
- }
746
- appendChild(parent, newChild) {
747
- return super.appendChild(this.nodeOrShadowRoot(parent), newChild);
748
- }
749
- insertBefore(parent, newChild, refChild) {
750
- return super.insertBefore(this.nodeOrShadowRoot(parent), newChild, refChild);
751
- }
752
- removeChild(_parent, oldChild) {
753
- return super.removeChild(null, oldChild);
754
- }
755
- parentNode(node) {
756
- return this.nodeOrShadowRoot(super.parentNode(this.nodeOrShadowRoot(node)));
757
- }
758
- destroy() {
759
- if (this.sharedStylesHost) {
760
- this.sharedStylesHost.removeHost(this.shadowRoot);
761
- }
762
- }
763
- }
764
- class NoneEncapsulationDomRenderer extends DefaultDomRenderer2 {
765
- sharedStylesHost;
766
- removeStylesOnCompDestroy;
767
- styles;
768
- styleUrls;
769
- _animationDisabled;
770
- constructor(eventManager, sharedStylesHost, component, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, registry, animationDisabled, maxAnimationTimeout, compId) {
771
- super(eventManager, doc, ngZone, platformIsServer, tracingService, registry, maxAnimationTimeout);
772
- this.sharedStylesHost = sharedStylesHost;
773
- this.removeStylesOnCompDestroy = removeStylesOnCompDestroy;
774
- this._animationDisabled = animationDisabled;
775
- let styles = component.styles;
776
- if (ngDevMode) {
777
- // We only do this in development, as for production users should not add CSS sourcemaps to components.
778
- const baseHref = _getDOM().getBaseHref(doc) ?? '';
779
- styles = addBaseHrefToCssSourceMap(baseHref, styles);
780
- }
781
- this.styles = compId ? shimStylesContent(compId, styles) : styles;
782
- this.styleUrls = component.getExternalStyles?.(compId);
783
- }
784
- applyStyles() {
785
- this.sharedStylesHost.addStyles(this.styles, this.styleUrls);
786
- }
787
- destroy() {
788
- if (!this.removeStylesOnCompDestroy) {
789
- return;
790
- }
791
- // In the case that animate.leave animations are used, depending on
792
- // app structure, a race condition happens with the destroy call and
793
- // the animation being added to the element. Either the DOM node is
794
- // immediately removed or the animate instruction is called right
795
- // as the styles are pruned, causing the animated element to sit
796
- // until the timeout removes it. This delays the pruning of style
797
- // sheets for a few seconds to avoid this problem.
798
- //
799
- // TODO(thePunderWoman): replace this with a more targeted delay on only
800
- // cases where we know there's a leave animation, that the leave animation
801
- // is actually running, and to instead use the longest animation value
802
- // for the timeout duration.
803
- if ((typeof ngServerMode === 'undefined' || !ngServerMode) &&
804
- !this._animationDisabled &&
805
- this.registry.elements) {
806
- this.ngZone.runOutsideAngular(() => {
807
- setTimeout(() => {
808
- this.sharedStylesHost.removeStyles(this.styles, this.styleUrls);
809
- }, this.maxAnimationTimeout);
810
- });
811
- return;
812
- }
813
- this.sharedStylesHost.removeStyles(this.styles, this.styleUrls);
814
- }
815
- }
816
- class EmulatedEncapsulationDomRenderer2 extends NoneEncapsulationDomRenderer {
817
- contentAttr;
818
- hostAttr;
819
- constructor(eventManager, sharedStylesHost, component, appId, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, registry, animationDisabled, maxAnimationTimeout) {
820
- const compId = appId + '-' + component.id;
821
- super(eventManager, sharedStylesHost, component, removeStylesOnCompDestroy, doc, ngZone, platformIsServer, tracingService, registry, animationDisabled, maxAnimationTimeout, compId);
822
- this.contentAttr = shimContentAttribute(compId);
823
- this.hostAttr = shimHostAttribute(compId);
824
- }
825
- applyToHost(element) {
826
- this.applyStyles();
827
- this.setAttribute(element, this.hostAttr, '');
828
- }
829
- createElement(parent, name) {
830
- const el = super.createElement(parent, name);
831
- super.setAttribute(el, this.contentAttr, '');
832
- return el;
833
- }
834
- }
835
-
836
- export { DomRendererFactory2, EVENT_MANAGER_PLUGINS, EventManager, EventManagerPlugin, REMOVE_STYLES_ON_COMPONENT_DESTROY, SharedStylesHost };
837
- //# sourceMappingURL=dom_renderer.mjs.map