{"version":3,"file":"dom_renderer-DGKzginR.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-2d99d9656325/bin/packages/platform-browser/src/dom/events/event_manager.ts","../../../../../darwin_arm64-fastbuild-ST-2d99d9656325/bin/packages/platform-browser/src/dom/shared_styles_host.ts","../../../../../darwin_arm64-fastbuild-ST-2d99d9656325/bin/packages/platform-browser/src/dom/dom_renderer.js"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {\n Inject,\n Injectable,\n InjectionToken,\n NgZone,\n ɵRuntimeError as RuntimeError,\n type ListenerOptions,\n} from '@angular/core';\n\nimport {RuntimeErrorCode} from '../../errors';\n\n/**\n * The injection token for plugins of the `EventManager` service.\n *\n * @publicApi\n */\nexport const EVENT_MANAGER_PLUGINS = new InjectionToken(\n ngDevMode ? 'EventManagerPlugins' : '',\n);\n\n/**\n * An injectable service that provides event management for Angular\n * through a browser plug-in.\n *\n * @publicApi\n */\n@Injectable()\nexport class EventManager {\n private _plugins: EventManagerPlugin[];\n private _eventNameToPlugin = new Map();\n\n /**\n * Initializes an instance of the event-manager service.\n */\n constructor(\n @Inject(EVENT_MANAGER_PLUGINS) plugins: EventManagerPlugin[],\n private _zone: NgZone,\n ) {\n plugins.forEach((plugin) => {\n plugin.manager = this;\n });\n this._plugins = plugins.slice().reverse();\n }\n\n /**\n * Registers a handler for a specific element and event.\n *\n * @param element The HTML element to receive event notifications.\n * @param eventName The name of the event to listen for.\n * @param handler A function to call when the notification occurs. Receives the\n * event object as an argument.\n * @param options Options that configure how the event listener is bound.\n * @returns A callback function that can be used to remove the handler.\n */\n addEventListener(\n element: HTMLElement,\n eventName: string,\n handler: Function,\n options?: ListenerOptions,\n ): Function {\n const plugin = this._findPluginFor(eventName);\n return plugin.addEventListener(element, eventName, handler, options);\n }\n\n /**\n * Retrieves the compilation zone in which event listeners are registered.\n */\n getZone(): NgZone {\n return this._zone;\n }\n\n /** @internal */\n _findPluginFor(eventName: string): EventManagerPlugin {\n let plugin = this._eventNameToPlugin.get(eventName);\n if (plugin) {\n return plugin;\n }\n\n const plugins = this._plugins;\n plugin = plugins.find((plugin) => plugin.supports(eventName));\n if (!plugin) {\n throw new RuntimeError(\n RuntimeErrorCode.NO_PLUGIN_FOR_EVENT,\n (typeof ngDevMode === 'undefined' || ngDevMode) &&\n `No event manager plugin found for event ${eventName}`,\n );\n }\n\n this._eventNameToPlugin.set(eventName, plugin);\n return plugin;\n }\n}\n\n/**\n * The plugin definition for the `EventManager` class\n *\n * It can be used as a base class to create custom manager plugins, i.e. you can create your own\n * class that extends the `EventManagerPlugin` one.\n *\n * @publicApi\n */\nexport abstract class EventManagerPlugin {\n // TODO: remove (has some usage in G3)\n constructor(private _doc: any) {}\n\n // Using non-null assertion because it's set by EventManager's constructor\n manager!: EventManager;\n\n /**\n * Should return `true` for every event name that should be supported by this plugin\n */\n abstract supports(eventName: string): boolean;\n\n /**\n * Implement the behaviour for the supported events\n */\n abstract addEventListener(\n element: HTMLElement,\n eventName: string,\n handler: Function,\n options?: ListenerOptions,\n ): Function;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {DOCUMENT, isPlatformServer} from '@angular/common';\nimport {\n APP_ID,\n CSP_NONCE,\n Inject,\n Injectable,\n OnDestroy,\n Optional,\n PLATFORM_ID,\n} from '@angular/core';\n\n/** The style elements attribute name used to set value of `APP_ID` token. */\nconst APP_ID_ATTRIBUTE_NAME = 'ng-app-id';\n\n/**\n * A record of usage for a specific style including all elements added to the DOM\n * that contain a given style.\n */\ninterface UsageRecord {\n elements: T[];\n usage: number;\n}\n\n/**\n * Removes all provided elements from the document.\n * @param elements An array of HTML Elements.\n */\nfunction removeElements(elements: Iterable): void {\n for (const element of elements) {\n element.remove();\n }\n}\n\n/**\n * Creates a `style` element with the provided inline style content.\n * @param style A string of the inline style content.\n * @param doc A DOM Document to use to create the element.\n * @returns An HTMLStyleElement instance.\n */\nfunction createStyleElement(style: string, doc: Document): HTMLStyleElement {\n const styleElement = doc.createElement('style');\n styleElement.textContent = style;\n\n return styleElement;\n}\n\n/**\n * Searches a DOM document's head element for style elements with a matching application\n * identifier attribute (`ng-app-id`) to the provide identifier and adds usage records for each.\n * @param doc An HTML DOM document instance.\n * @param appId A string containing an Angular application identifer.\n * @param inline A Map object for tracking inline (defined via `styles` in component decorator) style usage.\n * @param external A Map object for tracking external (defined via `styleUrls` in component decorator) style usage.\n */\nfunction addServerStyles(\n doc: Document,\n appId: string,\n inline: Map>,\n external: Map>,\n): void {\n const elements = doc.head?.querySelectorAll(\n `style[${APP_ID_ATTRIBUTE_NAME}=\"${appId}\"],link[${APP_ID_ATTRIBUTE_NAME}=\"${appId}\"]`,\n );\n\n if (elements) {\n for (const styleElement of elements) {\n styleElement.removeAttribute(APP_ID_ATTRIBUTE_NAME);\n if (styleElement instanceof HTMLLinkElement) {\n // Only use filename from href\n // The href is build time generated with a unique value to prevent duplicates.\n external.set(styleElement.href.slice(styleElement.href.lastIndexOf('/') + 1), {\n usage: 0,\n elements: [styleElement],\n });\n } else if (styleElement.textContent) {\n inline.set(styleElement.textContent, {usage: 0, elements: [styleElement]});\n }\n }\n }\n}\n\n/**\n * Creates a `link` element for the provided external style URL.\n * @param url A string of the URL for the stylesheet.\n * @param doc A DOM Document to use to create the element.\n * @returns An HTMLLinkElement instance.\n */\nexport function createLinkElement(url: string, doc: Document): HTMLLinkElement {\n const linkElement = doc.createElement('link');\n linkElement.setAttribute('rel', 'stylesheet');\n linkElement.setAttribute('href', url);\n\n return linkElement;\n}\n\n@Injectable()\nexport class SharedStylesHost implements OnDestroy {\n /**\n * Provides usage information for active inline style content and associated HTML