1 | {"version":3,"file":"badge.js","sources":["../../../../../../src/material/badge/badge.ts","../../../../../../src/material/badge/badge-module.ts","../../../../../../src/material/badge/public-api.ts","../../../../../../src/material/badge/index.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.io/license\n */\n\nimport {AriaDescriber} from '@angular/cdk/a11y';\nimport {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {\n Directive,\n ElementRef,\n Inject,\n Input,\n NgZone,\n OnDestroy,\n OnInit,\n Optional,\n Renderer2,\n} from '@angular/core';\nimport {CanDisable, mixinDisabled, ThemePalette} from '@angular/material/core';\nimport {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';\n\n\nlet nextId = 0;\n\n// Boilerplate for applying mixins to MatBadge.\n/** @docs-private */\nconst _MatBadgeBase = mixinDisabled(class {});\n\n/** Allowed position options for matBadgePosition */\nexport type MatBadgePosition =\n 'above after' | 'above before' | 'below before' | 'below after' |\n 'before' | 'after' | 'above' | 'below';\n\n/** Allowed size options for matBadgeSize */\nexport type MatBadgeSize = 'small' | 'medium' | 'large';\n\nconst BADGE_CONTENT_CLASS = 'mat-badge-content';\n\n/** Directive to display a text badge. */\n@Directive({\n selector: '[matBadge]',\n inputs: ['disabled: matBadgeDisabled'],\n host: {\n 'class': 'mat-badge',\n '[class.mat-badge-overlap]': 'overlap',\n '[class.mat-badge-above]': 'isAbove()',\n '[class.mat-badge-below]': '!isAbove()',\n '[class.mat-badge-before]': '!isAfter()',\n '[class.mat-badge-after]': 'isAfter()',\n '[class.mat-badge-small]': 'size === \"small\"',\n '[class.mat-badge-medium]': 'size === \"medium\"',\n '[class.mat-badge-large]': 'size === \"large\"',\n '[class.mat-badge-hidden]': 'hidden || !content',\n '[class.mat-badge-disabled]': 'disabled',\n },\n})\nexport class MatBadge extends _MatBadgeBase implements OnInit, OnDestroy, CanDisable {\n /** The color of the badge. Can be `primary`, `accent`, or `warn`. */\n @Input('matBadgeColor')\n get color(): ThemePalette { return this._color; }\n set color(value: ThemePalette) {\n this._setColor(value);\n this._color = value;\n }\n private _color: ThemePalette = 'primary';\n\n /** Whether the badge should overlap its contents or not */\n @Input('matBadgeOverlap')\n get overlap(): boolean { return this._overlap; }\n set overlap(val: boolean) {\n this._overlap = coerceBooleanProperty(val);\n }\n private _overlap: boolean = true;\n\n /**\n * Position the badge should reside.\n * Accepts any combination of 'above'|'below' and 'before'|'after'\n */\n @Input('matBadgePosition') position: MatBadgePosition = 'above after';\n\n /** The content for the badge */\n @Input('matBadge')\n get content(): string | number | undefined | null {\n return this._content;\n }\n set content(newContent: string | number | undefined | null) {\n this._updateRenderedContent(newContent);\n }\n private _content: string | number | undefined | null;\n\n /** Message used to describe the decorated element via aria-describedby */\n @Input('matBadgeDescription')\n get description(): string { return this._description; }\n set description(newDescription: string) {\n this._updateHostAriaDescription(newDescription);\n }\n private _description: string;\n\n /** Size of the badge. Can be 'small', 'medium', or 'large'. */\n @Input('matBadgeSize') size: MatBadgeSize = 'medium';\n\n /** Whether the badge is hidden. */\n @Input('matBadgeHidden')\n get hidden(): boolean { return this._hidden; }\n set hidden(val: boolean) {\n this._hidden = coerceBooleanProperty(val);\n }\n private _hidden: boolean;\n\n /** Unique id for the badge */\n _id: number = nextId++;\n\n /** Visible badge element. */\n private _badgeElement: HTMLElement | undefined;\n\n /** Whether the OnInit lifecycle hook has run yet */\n private _isInitialized = false;\n\n constructor(\n private _ngZone: NgZone,\n private _elementRef: ElementRef<HTMLElement>,\n private _ariaDescriber: AriaDescriber,\n private _renderer: Renderer2,\n @Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) {\n super();\n\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n const nativeElement = _elementRef.nativeElement;\n if (nativeElement.nodeType !== nativeElement.ELEMENT_NODE) {\n throw Error('matBadge must be attached to an element node.');\n }\n }\n }\n\n /** Whether the badge is above the host or not */\n isAbove(): boolean {\n return this.position.indexOf('below') === -1;\n }\n\n /** Whether the badge is after the host or not */\n isAfter(): boolean {\n return this.position.indexOf('before') === -1;\n }\n\n /**\n * Gets the element into which the badge's content is being rendered. Undefined if the element\n * hasn't been created (e.g. if the badge doesn't have content).\n */\n getBadgeElement(): HTMLElement | undefined {\n return this._badgeElement;\n }\n\n ngOnInit() {\n // We may have server-side rendered badge that we need to clear.\n // We need to do this in ngOnInit because the full content of the component\n // on which the badge is attached won't necessarily be in the DOM until this point.\n this._clearExistingBadges();\n\n if (this.content && !this._badgeElement) {\n this._badgeElement = this._createBadgeElement();\n this._updateRenderedContent(this.content);\n }\n\n this._isInitialized = true;\n }\n\n ngOnDestroy() {\n // ViewEngine only: when creating a badge through the Renderer, Angular remembers its index.\n // We have to destroy it ourselves, otherwise it'll be retained in memory.\n if (this._renderer.destroyNode) {\n this._renderer.destroyNode(this._badgeElement);\n }\n\n this._ariaDescriber.removeDescription(this._elementRef.nativeElement, this.description);\n }\n\n /** Creates the badge element */\n private _createBadgeElement(): HTMLElement {\n const badgeElement = this._renderer.createElement('span');\n const activeClass = 'mat-badge-active';\n\n badgeElement.setAttribute('id', `mat-badge-content-${this._id}`);\n\n // The badge is aria-hidden because we don't want it to appear in the page's navigation\n // flow. Instead, we use the badge to describe the decorated element with aria-describedby.\n badgeElement.setAttribute('aria-hidden', 'true');\n badgeElement.classList.add(BADGE_CONTENT_CLASS);\n\n if (this._animationMode === 'NoopAnimations') {\n badgeElement.classList.add('_mat-animation-noopable');\n }\n\n this._elementRef.nativeElement.appendChild(badgeElement);\n\n // animate in after insertion\n if (typeof requestAnimationFrame === 'function' && this._animationMode !== 'NoopAnimations') {\n this._ngZone.runOutsideAngular(() => {\n requestAnimationFrame(() => {\n badgeElement.classList.add(activeClass);\n });\n });\n } else {\n badgeElement.classList.add(activeClass);\n }\n\n return badgeElement;\n }\n\n /** Update the text content of the badge element in the DOM, creating the element if necessary. */\n private _updateRenderedContent(newContent: string | number | undefined | null): void {\n const newContentNormalized: string = `${newContent ?? ''}`.trim();\n\n // Don't create the badge element if the directive isn't initialized because we want to\n // append the badge element to the *end* of the host element's content for backwards\n // compatibility.\n if (this._isInitialized && newContentNormalized && !this._badgeElement) {\n this._badgeElement = this._createBadgeElement();\n }\n\n if (this._badgeElement) {\n this._badgeElement.textContent = newContentNormalized;\n }\n\n this._content = newContentNormalized;\n }\n\n /** Updates the host element's aria description via AriaDescriber. */\n private _updateHostAriaDescription(newDescription: string): void {\n this._ariaDescriber.removeDescription(this._elementRef.nativeElement, this.description);\n if (newDescription) {\n this._ariaDescriber.describe(this._elementRef.nativeElement, newDescription);\n }\n this._description = newDescription;\n }\n\n /** Adds css theme class given the color to the component host */\n private _setColor(colorPalette: ThemePalette) {\n const classList = this._elementRef.nativeElement.classList;\n classList.remove(`mat-badge-${this._color}`);\n if (colorPalette) {\n classList.add(`mat-badge-${colorPalette}`);\n }\n }\n\n /** Clears any existing badges that might be left over from server-side rendering. */\n private _clearExistingBadges() {\n // Only check direct children of this host element in order to avoid deleting\n // any badges that might exist in descendant elements.\n const badges =\n this._elementRef.nativeElement.querySelectorAll(`:scope > .${BADGE_CONTENT_CLASS}`);\n for (const badgeElement of Array.from(badges)) {\n if (badgeElement !== this._badgeElement) {\n badgeElement.remove();\n }\n }\n }\n\n static ngAcceptInputType_disabled: BooleanInput;\n static ngAcceptInputType_hidden: BooleanInput;\n static ngAcceptInputType_overlap: BooleanInput;\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.io/license\n */\n\nimport {NgModule} from '@angular/core';\nimport {MatCommonModule} from '@angular/material/core';\nimport {A11yModule} from '@angular/cdk/a11y';\nimport {MatBadge} from './badge';\n\n\n@NgModule({\n imports: [\n A11yModule,\n MatCommonModule\n ],\n exports: [MatBadge, MatCommonModule],\n declarations: [MatBadge],\n})\nexport class MatBadgeModule {}\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.io/license\n */\n\nexport * from './badge-module';\nexport * from './badge';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAAA;;;;;;;AAyBA,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf;AACA;AACA,MAAM,aAAa,GAAG,aAAa,CAAC;CAAQ,CAAC,CAAC;AAU9C,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEhD;MAkBa,QAAS,SAAQ,aAAa;IA8DzC,YACY,OAAe,EACf,WAAoC,EACpC,cAA6B,EAC7B,SAAoB,EACuB,cAAuB;QAC1E,KAAK,EAAE,CAAC;QALA,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAyB;QACpC,mBAAc,GAAd,cAAc,CAAe;QAC7B,cAAS,GAAT,SAAS,CAAW;QACuB,mBAAc,GAAd,cAAc,CAAS;QA3DtE,WAAM,GAAiB,SAAS,CAAC;QAQjC,aAAQ,GAAY,IAAI,CAAC;;;;;QAMN,aAAQ,GAAqB,aAAa,CAAC;;QAqB/C,SAAI,GAAiB,QAAQ,CAAC;;QAWrD,QAAG,GAAW,MAAM,EAAE,CAAC;;QAMf,mBAAc,GAAG,KAAK,CAAC;QAU3B,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,EAAE;YACjD,MAAM,aAAa,GAAG,WAAW,CAAC,aAAa,CAAC;YAChD,IAAI,aAAa,CAAC,QAAQ,KAAK,aAAa,CAAC,YAAY,EAAE;gBACzD,MAAM,KAAK,CAAC,+CAA+C,CAAC,CAAC;aAC9D;SACF;KACF;;IA1EH,IACI,KAAK,KAAmB,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE;IACjD,IAAI,KAAK,CAAC,KAAmB;QAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAA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