/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { DOCUMENT } from '@angular/common'; import { ANIMATION_MODULE_TYPE, ElementRef, Injectable, NgZone, inject, } from '@angular/core'; import { MAT_RIPPLE_GLOBAL_OPTIONS, MatRipple } from '../ripple'; import { Platform } from '@angular/cdk/platform'; import * as i0 from "@angular/core"; /** The options for the MatRippleLoader's event listeners. */ const eventListenerOptions = { capture: true }; /** The events that should trigger the initialization of the ripple. */ const rippleInteractionEvents = ['focus', 'click', 'mouseenter', 'touchstart']; /** The attribute attached to a component whose ripple has not yet been initialized. */ const matRippleUninitialized = 'mat-ripple-loader-uninitialized'; /** Additional classes that should be added to the ripple when it is rendered. */ const matRippleClassName = 'mat-ripple-loader-class-name'; /** Whether the ripple should be centered. */ const matRippleCentered = 'mat-ripple-loader-centered'; /** Whether the ripple should be disabled. */ const matRippleDisabled = 'mat-ripple-loader-disabled'; /** * Handles attaching ripples on demand. * * This service allows us to avoid eagerly creating & attaching MatRipples. * It works by creating & attaching a ripple only when a component is first interacted with. * * @docs-private */ export class MatRippleLoader { constructor() { this._document = inject(DOCUMENT, { optional: true }); this._animationMode = inject(ANIMATION_MODULE_TYPE, { optional: true }); this._globalRippleOptions = inject(MAT_RIPPLE_GLOBAL_OPTIONS, { optional: true }); this._platform = inject(Platform); this._ngZone = inject(NgZone); this._hosts = new Map(); /** Handles creating and attaching component internals when a component it is initially interacted with. */ this._onInteraction = (event) => { if (!(event.target instanceof HTMLElement)) { return; } const eventTarget = event.target; // TODO(wagnermaciel): Consider batching these events to improve runtime performance. const element = eventTarget.closest(`[${matRippleUninitialized}]`); if (element) { this._createRipple(element); } }; this._ngZone.runOutsideAngular(() => { for (const event of rippleInteractionEvents) { this._document?.addEventListener(event, this._onInteraction, eventListenerOptions); } }); } ngOnDestroy() { const hosts = this._hosts.keys(); for (const host of hosts) { this.destroyRipple(host); } for (const event of rippleInteractionEvents) { this._document?.removeEventListener(event, this._onInteraction, eventListenerOptions); } } /** * Configures the ripple that will be rendered by the ripple loader. * * Stores the given information about how the ripple should be configured on the host * element so that it can later be retrived & used when the ripple is actually created. */ configureRipple(host, config) { // Indicates that the ripple has not yet been rendered for this component. host.setAttribute(matRippleUninitialized, ''); // Store the additional class name(s) that should be added to the ripple element. if (config.className || !host.hasAttribute(matRippleClassName)) { host.setAttribute(matRippleClassName, config.className || ''); } // Store whether the ripple should be centered. if (config.centered) { host.setAttribute(matRippleCentered, ''); } if (config.disabled) { host.setAttribute(matRippleDisabled, ''); } } /** Returns the ripple instance for the given host element. */ getRipple(host) { const ripple = this._hosts.get(host); return ripple || this._createRipple(host); } /** Sets the disabled state on the ripple instance corresponding to the given host element. */ setDisabled(host, disabled) { const ripple = this._hosts.get(host); // If the ripple has already been instantiated, just disable it. if (ripple) { ripple.disabled = disabled; return; } // Otherwise, set an attribute so we know what the // disabled state should be when the ripple is initialized. if (disabled) { host.setAttribute(matRippleDisabled, ''); } else { host.removeAttribute(matRippleDisabled); } } /** Creates a MatRipple and appends it to the given element. */ _createRipple(host) { if (!this._document) { return; } const existingRipple = this._hosts.get(host); if (existingRipple) { return existingRipple; } // Create the ripple element. host.querySelector('.mat-ripple')?.remove(); const rippleEl = this._document.createElement('span'); rippleEl.classList.add('mat-ripple', host.getAttribute(matRippleClassName)); host.append(rippleEl); // Create the MatRipple. const ripple = new MatRipple(new ElementRef(rippleEl), this._ngZone, this._platform, this._globalRippleOptions ? this._globalRippleOptions : undefined, this._animationMode ? this._animationMode : undefined); ripple._isInitialized = true; ripple.trigger = host; ripple.centered = host.hasAttribute(matRippleCentered); ripple.disabled = host.hasAttribute(matRippleDisabled); this.attachRipple(host, ripple); return ripple; } attachRipple(host, ripple) { host.removeAttribute(matRippleUninitialized); this._hosts.set(host, ripple); } destroyRipple(host) { const ripple = this._hosts.get(host); if (ripple) { // Since this directive is created manually, it needs to be destroyed manually too. // tslint:disable-next-line:no-lifecycle-invocation ripple.ngOnDestroy(); this._hosts.delete(host); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatRippleLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatRippleLoader, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatRippleLoader, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return []; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmlwcGxlLWxvYWRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9jb3JlL3ByaXZhdGUvcmlwcGxlLWxvYWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsUUFBUSxFQUFDLE1BQU0saUJBQWlCLENBQUM7QUFDekMsT0FBTyxFQUNMLHFCQUFxQixFQUNyQixVQUFVLEVBQ1YsVUFBVSxFQUNWLE1BQU0sRUFFTixNQUFNLEdBQ1AsTUFBTSxlQUFlLENBQUM7QUFDdkIsT0FBTyxFQUFDLHlCQUF5QixFQUFFLFNBQVMsRUFBQyxNQUFNLFdBQVcsQ0FBQztBQUMvRCxPQUFPLEVBQUMsUUFBUSxFQUFDLE1BQU0sdUJBQXVCLENBQUM7O0FBRS9DLDZEQUE2RDtBQUM3RCxNQUFNLG9CQUFvQixHQUFHLEVBQUMsT0FBTyxFQUFFLElBQUksRUFBQyxDQUFDO0FBRTdDLHVFQUF1RTtBQUN2RSxNQUFNLHVCQUF1QixHQUFHLENBQUMsT0FBTyxFQUFFLE9BQU8sRUFBRSxZQUFZLEVBQUUsWUFBWSx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