{"version":3,"file":"_ripple-loader-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/core/private/ripple-loader.ts"],"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  Service,\n  Injector,\n  NgZone,\n  OnDestroy,\n  RendererFactory2,\n  inject,\n  DOCUMENT,\n} from '@angular/core';\nimport {\n  MAT_RIPPLE_GLOBAL_OPTIONS,\n  RippleRenderer,\n  RippleTarget,\n  defaultRippleAnimationConfig,\n} from '../ripple';\nimport {Platform, _getEventTarget} from '@angular/cdk/platform';\nimport {_CdkPrivateStyleLoader} from '@angular/cdk/private';\nimport {_animationsDisabled} from '../animation/animation';\n\n/** The options for the MatRippleLoader's event listeners. */\nconst eventListenerOptions = {capture: true};\n\n/**\n * The events that should trigger the initialization of the ripple.\n * Note that we use `mousedown`, rather than `click`, for mouse devices because\n * we can't rely on `mouseenter` in the shadow DOM and `click` happens too late.\n */\nconst rippleInteractionEvents = ['focus', 'mousedown', 'mouseenter', 'touchstart'];\n\n/** The attribute attached to a component whose ripple has not yet been initialized. */\nconst matRippleUninitialized = 'mat-ripple-loader-uninitialized';\n\n/** Additional classes that should be added to the ripple when it is rendered. */\nconst matRippleClassName = 'mat-ripple-loader-class-name';\n\n/** Whether the ripple should be centered. */\nconst matRippleCentered = 'mat-ripple-loader-centered';\n\n/** Whether the ripple should be disabled. */\nconst matRippleDisabled = 'mat-ripple-loader-disabled';\n\n/**\n * Handles attaching ripples on demand.\n *\n * This service allows us to avoid eagerly creating & attaching MatRipples.\n * It works by creating & attaching a ripple only when a component is first interacted with.\n *\n * @docs-private\n */\n@Service()\nexport class MatRippleLoader implements OnDestroy {\n  private _document = inject(DOCUMENT);\n  private _animationsDisabled = _animationsDisabled();\n  private _globalRippleOptions = inject(MAT_RIPPLE_GLOBAL_OPTIONS, {optional: true});\n  private _platform = inject(Platform);\n  private _ngZone = inject(NgZone);\n  private _injector = inject(Injector);\n  private _eventCleanups: (() => void)[];\n  private _hosts = new Map<\n    HTMLElement,\n    {renderer: RippleRenderer; target: RippleTarget; hasSetUpEvents: boolean}\n  >();\n\n  constructor() {\n    const renderer = inject(RendererFactory2).createRenderer(null, null);\n\n    this._eventCleanups = this._ngZone.runOutsideAngular(() =>\n      rippleInteractionEvents.map(name =>\n        renderer.listen(this._document, name, this._onInteraction, eventListenerOptions),\n      ),\n    );\n  }\n\n  ngOnDestroy(): void {\n    const hosts = this._hosts.keys();\n\n    for (const host of hosts) {\n      this.destroyRipple(host);\n    }\n\n    this._eventCleanups.forEach(cleanup => cleanup());\n  }\n\n  /**\n   * Configures the ripple that will be rendered by the ripple loader.\n   *\n   * Stores the given information about how the ripple should be configured on the host\n   * element so that it can later be retrived & used when the ripple is actually created.\n   */\n  configureRipple(\n    host: HTMLElement,\n    config: {\n      className?: string;\n      centered?: boolean;\n      disabled?: boolean;\n    },\n  ): void {\n    // Indicates that the ripple has not yet been rendered for this component.\n    host.setAttribute(matRippleUninitialized, this._globalRippleOptions?.namespace ?? '');\n\n    // Store the additional class name(s) that should be added to the ripple element.\n    if (config.className || !host.hasAttribute(matRippleClassName)) {\n      host.setAttribute(matRippleClassName, config.className || '');\n    }\n\n    // Store whether the ripple should be centered.\n    if (config.centered) {\n      host.setAttribute(matRippleCentered, '');\n    }\n\n    if (config.disabled) {\n      host.setAttribute(matRippleDisabled, '');\n    }\n  }\n\n  /** Sets the disabled state on the ripple instance corresponding to the given host element. */\n  setDisabled(host: HTMLElement, disabled: boolean): void {\n    const ripple = this._hosts.get(host);\n\n    // If the ripple has already been instantiated, just disable it.\n    if (ripple) {\n      ripple.target.rippleDisabled = disabled;\n\n      if (!disabled && !ripple.hasSetUpEvents) {\n        ripple.hasSetUpEvents = true;\n        ripple.renderer.setupTriggerEvents(host);\n      }\n    } else if (disabled) {\n      // Otherwise, set an attribute so we know what the\n      // disabled state should be when the ripple is initialized.\n      host.setAttribute(matRippleDisabled, '');\n    } else {\n      host.removeAttribute(matRippleDisabled);\n    }\n  }\n\n  /**\n   * Handles creating and attaching component internals\n   * when a component is initially interacted with.\n   */\n  private _onInteraction = (event: Event) => {\n    const eventTarget = _getEventTarget(event);\n\n    if (eventTarget instanceof HTMLElement) {\n      // TODO(wagnermaciel): Consider batching these events to improve runtime performance.\n      const element = eventTarget.closest(\n        `[${matRippleUninitialized}=\"${this._globalRippleOptions?.namespace ?? ''}\"]`,\n      );\n\n      if (element) {\n        this._createRipple(element as HTMLElement);\n      }\n    }\n  };\n\n  /** Creates a MatRipple and appends it to the given element. */\n  private _createRipple(host: HTMLElement): void {\n    if (!this._document || this._hosts.has(host)) {\n      return;\n    }\n\n    // Create the ripple element.\n    host.querySelector('.mat-ripple')?.remove();\n    const rippleEl = this._document.createElement('span');\n    rippleEl.classList.add('mat-ripple', host.getAttribute(matRippleClassName)!);\n    host.append(rippleEl);\n\n    const globalOptions = this._globalRippleOptions;\n    const enterDuration = this._animationsDisabled\n      ? 0\n      : (globalOptions?.animation?.enterDuration ?? defaultRippleAnimationConfig.enterDuration);\n    const exitDuration = this._animationsDisabled\n      ? 0\n      : (globalOptions?.animation?.exitDuration ?? defaultRippleAnimationConfig.exitDuration);\n    const target: RippleTarget = {\n      rippleDisabled:\n        this._animationsDisabled || globalOptions?.disabled || host.hasAttribute(matRippleDisabled),\n      rippleConfig: {\n        centered: host.hasAttribute(matRippleCentered),\n        terminateOnPointerUp: globalOptions?.terminateOnPointerUp,\n        animation: {\n          enterDuration,\n          exitDuration,\n        },\n      },\n    };\n\n    const renderer = new RippleRenderer(\n      target,\n      this._ngZone,\n      rippleEl,\n      this._platform,\n      this._injector,\n    );\n    const hasSetUpEvents = !target.rippleDisabled;\n\n    if (hasSetUpEvents) {\n      renderer.setupTriggerEvents(host);\n    }\n\n    this._hosts.set(host, {\n      target,\n      renderer,\n      hasSetUpEvents,\n    });\n\n    host.removeAttribute(matRippleUninitialized);\n  }\n\n  destroyRipple(host: HTMLElement): void {\n    const ripple = this._hosts.get(host);\n\n    if (ripple) {\n      ripple.renderer._removeTriggerEvents();\n      this._hosts.delete(host);\n    }\n  }\n}\n"],"names":[],"mappings":";;;;;;AA4BA,MAAM,oBAAoB,GAAG;AAAC,EAAA,OAAO,EAAE;CAAK;AAO5C,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC;AAGlF,MAAM,sBAAsB,GAAG,iCAAiC;AAGhE,MAAM,kBAAkB,GAAG,8BAA8B;AAGzD,MAAM,iBAAiB,GAAG,4BAA4B;AAGtD,MAAM,iBAAiB,GAAG,4BAA4B;MAWzC,eAAe,CAAA;AAClB,EAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;EAC5B,mBAAmB,GAAG,mBAAmB,EAAE;AAC3C,EAAA,oBAAoB,GAAG,MAAM,CAAC,yBAAyB,EAAE;AAAC,IAAA,QAAQ,EAAE;AAAI,GAAC,CAAC;AAC1E,EAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC5B,EAAA,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;AACxB,EAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;EAC5B,cAAc;AACd,EAAA,MAAM,GAAG,IAAI,GAAG,EAGrB;AAEH,EAAA,WAAA,GAAA;AACE,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC;AAEpE,IAAA,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,MACnD,uBAAuB,CAAC,GAAG,CAAC,IAAI,IAC9B,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,oBAAoB,CAAC,CACjF,CACF;AACH,EAAA;AAEA,EAAA,WAAW,GAAA;IACT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