@angular/platform-browser 21.0.0-next.9 → 21.0.0-rc.1

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