/** * @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.dev/license */ import { ModuleWithProviders, NgModule, Provider, ɵperformanceMarkFeature as performanceMarkFeature, } from '@angular/core'; import {BrowserModule} from '../../index'; import {BROWSER_ANIMATIONS_PROVIDERS, BROWSER_NOOP_ANIMATIONS_PROVIDERS} from './providers'; /** * Object used to configure the behavior of {@link BrowserAnimationsModule} * @publicApi * * @deprecated 20.2 Use `animate.enter` or `animate.leave` instead. Intent to remove in v23 */ export interface BrowserAnimationsModuleConfig { /** * Whether animations should be disabled. Passing this is identical to providing the * `NoopAnimationsModule`, but it can be controlled based on a runtime value. */ disableAnimations?: boolean; } /** * Exports `BrowserModule` with additional dependency-injection providers * for use with animations. See [Animations](guide/animations). * @publicApi * * @deprecated 20.2 Use `animate.enter` or `animate.leave` instead. Intent to remove in v23 */ @NgModule({ exports: [BrowserModule], providers: BROWSER_ANIMATIONS_PROVIDERS, }) export class BrowserAnimationsModule { /** * Configures the module based on the specified object. * * @param config Object used to configure the behavior of the `BrowserAnimationsModule`. * @see {@link BrowserAnimationsModuleConfig} * * @usageNotes * When registering the `BrowserAnimationsModule`, you can use the `withConfig` * function as follows: * ```ts * @NgModule({ * imports: [BrowserAnimationsModule.withConfig(config)] * }) * class MyNgModule {} * ``` */ static withConfig( config: BrowserAnimationsModuleConfig, ): ModuleWithProviders { return { ngModule: BrowserAnimationsModule, providers: config.disableAnimations ? BROWSER_NOOP_ANIMATIONS_PROVIDERS : BROWSER_ANIMATIONS_PROVIDERS, }; } } /** * Returns the set of dependency-injection providers * to enable animations in an application. See [animations guide](guide/animations) * to learn more about animations in Angular. * * @usageNotes * * The function is useful when you want to enable animations in an application * bootstrapped using the `bootstrapApplication` function. In this scenario there * is no need to import the `BrowserAnimationsModule` NgModule at all, just add * providers returned by this function to the `providers` list as show below. * * ```ts * bootstrapApplication(RootComponent, { * providers: [ * provideAnimations() * ] * }); * ``` * * @publicApi * * @deprecated 20.2 Use `animate.enter` or `animate.leave` instead. Intent to remove in v23 * */ export function provideAnimations(): Provider[] { performanceMarkFeature('NgEagerAnimations'); // Return a copy to prevent changes to the original array in case any in-place // alterations are performed to the `provideAnimations` call results in app code. return [...BROWSER_ANIMATIONS_PROVIDERS]; } /** * A null player that must be imported to allow disabling of animations. * @publicApi * * @deprecated 20.2 Use `animate.enter` or `animate.leave` instead. Intent to remove in v23 */ @NgModule({ exports: [BrowserModule], providers: BROWSER_NOOP_ANIMATIONS_PROVIDERS, }) export class NoopAnimationsModule {} /** * Returns the set of dependency-injection providers * to disable animations in an application. See [animations guide](guide/animations) * to learn more about animations in Angular. * * @usageNotes * * The function is useful when you want to bootstrap an application using * the `bootstrapApplication` function, but you need to disable animations * (for example, when running tests). * * ```ts * bootstrapApplication(RootComponent, { * providers: [ * provideNoopAnimations() * ] * }); * ``` * * @publicApi * * @deprecated 20.2 Use `animate.enter` or `animate.leave` instead. Intent to remove in v23 */ export function provideNoopAnimations(): Provider[] { // Return a copy to prevent changes to the original array in case any in-place // alterations are performed to the `provideNoopAnimations` call results in app code. return [...BROWSER_NOOP_ANIMATIONS_PROVIDERS]; }