blob: 9a171d08fd07f064057134a467d4822e87ea184c [file] [log] [blame]
{"version":3,"file":"progress-bar.js","sources":["../../../src/material/progress-bar/progress-bar-module.ts","../../../src/material/progress-bar/progress-bar.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 {NgModule} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {MatCommonModule} from '@angular/material/core';\nimport {MatProgressBar} from './progress-bar';\n\n\n@NgModule({\n imports: [CommonModule, MatCommonModule],\n exports: [MatProgressBar, MatCommonModule],\n declarations: [MatProgressBar],\n})\nexport class MatProgressBarModule {}\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 */\nimport {\n Component,\n ChangeDetectionStrategy,\n ElementRef,\n Inject,\n Input,\n Output,\n EventEmitter,\n Optional,\n NgZone,\n ViewEncapsulation,\n AfterViewInit,\n ViewChild,\n OnDestroy,\n InjectionToken,\n inject,\n} from '@angular/core';\nimport {fromEvent, Subscription, Observable} from 'rxjs';\nimport {filter} from 'rxjs/operators';\nimport {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';\nimport {CanColor, CanColorCtor, mixinColor} from '@angular/material/core';\nimport {DOCUMENT} from '@angular/common';\n\n// TODO(josephperrott): Benchpress tests.\n// TODO(josephperrott): Add ARIA attributes for progress bar \"for\".\n\n/** Last animation end data. */\nexport interface ProgressAnimationEnd {\n value: number;\n}\n\n// Boilerplate for applying mixins to MatProgressBar.\n/** @docs-private */\nclass MatProgressBarBase {\n constructor(public _elementRef: ElementRef) { }\n}\n\nconst _MatProgressBarMixinBase: CanColorCtor & typeof MatProgressBarBase =\n mixinColor(MatProgressBarBase, 'primary');\n\n/**\n * Injection token used to provide the current location to `MatProgressBar`.\n * Used to handle server-side rendering and to stub out during unit tests.\n * @docs-private\n */\nexport const MAT_PROGRESS_BAR_LOCATION = new InjectionToken<MatProgressBarLocation>(\n 'mat-progress-bar-location',\n {providedIn: 'root', factory: MAT_PROGRESS_BAR_LOCATION_FACTORY}\n);\n\n/**\n * Stubbed out location for `MatProgressBar`.\n * @docs-private\n */\nexport interface MatProgressBarLocation {\n getPathname: () => string;\n}\n\n/** @docs-private */\nexport function MAT_PROGRESS_BAR_LOCATION_FACTORY(): MatProgressBarLocation {\n const _document = inject(DOCUMENT);\n const _location = _document ? _document.location : null;\n\n return {\n // Note that this needs to be a function, rather than a property, because Angular\n // will only resolve it once, but we want the current path on each call.\n getPathname: () => _location ? (_location.pathname + _location.search) : ''\n };\n}\n\n\n/** Counter used to generate unique IDs for progress bars. */\nlet progressbarId = 0;\n\n/**\n * `<mat-progress-bar>` component.\n */\n@Component({\n moduleId: module.id,\n selector: 'mat-progress-bar',\n exportAs: 'matProgressBar',\n host: {\n 'role': 'progressbar',\n 'aria-valuemin': '0',\n 'aria-valuemax': '100',\n '[attr.aria-valuenow]': '(mode === \"indeterminate\" || mode === \"query\") ? null : value',\n '[attr.mode]': 'mode',\n 'class': 'mat-progress-bar',\n '[class._mat-animation-noopable]': '_isNoopAnimation',\n },\n inputs: ['color'],\n templateUrl: 'progress-bar.html',\n styleUrls: ['progress-bar.css'],\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n})\nexport class MatProgressBar extends _MatProgressBarMixinBase implements CanColor,\n AfterViewInit, OnDestroy {\n constructor(public _elementRef: ElementRef, private _ngZone: NgZone,\n @Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string,\n /**\n * @deprecated `location` parameter to be made required.\n * @breaking-change 8.0.0\n */\n @Optional() @Inject(MAT_PROGRESS_BAR_LOCATION) location?: MatProgressBarLocation) {\n super(_elementRef);\n\n // We need to prefix the SVG reference with the current path, otherwise they won't work\n // in Safari if the page has a `<base>` tag. Note that we need quotes inside the `url()`,\n\n // because named route URLs can contain parentheses (see #12338). Also we don't use since\n // we can't tell the difference between whether\n // the consumer is using the hash location strategy or not, because `Location` normalizes\n // both `/#/foo/bar` and `/foo/bar` to the same thing.\n const path = location ? location.getPathname().split('#')[0] : '';\n this._rectangleFillValue = `url('${path}#${this.progressbarId}')`;\n this._isNoopAnimation = _animationMode === 'NoopAnimations';\n }\n\n /** Flag that indicates whether NoopAnimations mode is set to true. */\n _isNoopAnimation = false;\n\n /** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */\n @Input()\n get value(): number { return this._value; }\n set value(v: number) {\n this._value = clamp(v || 0);\n\n // When noop animation is set to true, trigger animationEnd directly.\n if (this._isNoopAnimation) {\n this._emitAnimationEnd();\n }\n }\n private _value: number = 0;\n\n /** Buffer value of the progress bar. Defaults to zero. */\n @Input()\n get bufferValue(): number { return this._bufferValue; }\n set bufferValue(v: number) { this._bufferValue = clamp(v || 0); }\n private _bufferValue: number = 0;\n\n @ViewChild('primaryValueBar', {static: false}) _primaryValueBar: ElementRef;\n\n /**\n * Event emitted when animation of the primary progress bar completes. This event will not\n * be emitted when animations are disabled, nor will it be emitted for modes with continuous\n * animations (indeterminate and query).\n */\n @Output() animationEnd = new EventEmitter<ProgressAnimationEnd>();\n\n /** Reference to animation end subscription to be unsubscribed on destroy. */\n private _animationEndSubscription: Subscription = Subscription.EMPTY;\n\n /**\n * Mode of the progress bar.\n *\n * Input must be one of these values: determinate, indeterminate, buffer, query, defaults to\n * 'determinate'.\n * Mirrored to mode attribute.\n */\n @Input() mode: 'determinate' | 'indeterminate' | 'buffer' | 'query' = 'determinate';\n\n /** ID of the progress bar. */\n progressbarId = `mat-progress-bar-${progressbarId++}`;\n\n /** Attribute to be used for the `fill` attribute on the internal `rect` element. */\n _rectangleFillValue: string;\n\n /** Gets the current transform value for the progress bar's primary indicator. */\n _primaryTransform() {\n const scale = this.value / 100;\n return {transform: `scaleX(${scale})`};\n }\n\n /**\n * Gets the current transform value for the progress bar's buffer indicator. Only used if the\n * progress mode is set to buffer, otherwise returns an undefined, causing no transformation.\n */\n _bufferTransform() {\n if (this.mode === 'buffer') {\n const scale = this.bufferValue / 100;\n return {transform: `scaleX(${scale})`};\n }\n }\n\n ngAfterViewInit() {\n if (!this._isNoopAnimation) {\n // Run outside angular so change detection didn't get triggered on every transition end\n // instead only on the animation that we care about (primary value bar's transitionend)\n this._ngZone.runOutsideAngular((() => {\n const element = this._primaryValueBar.nativeElement;\n\n this._animationEndSubscription =\n (fromEvent(element, 'transitionend') as Observable<TransitionEvent>)\n .pipe(filter(((e: TransitionEvent) => e.target === element)))\n .subscribe(() => this._ngZone.run(() => this._emitAnimationEnd()));\n }));\n }\n }\n\n ngOnDestroy() {\n this._animationEndSubscription.unsubscribe();\n }\n\n /** Emit an animationEnd event if in determinate or buffer mode. */\n private _emitAnimationEnd(): void {\n if (this.mode === 'determinate' || this.mode === 'buffer') {\n this.animationEnd.next({value: this.value});\n }\n }\n}\n\n/** Clamps a value to be between two numbers, by default 0 and 100. */\nfunction clamp(v: number, min = 0, max = 100) {\n return Math.max(min, Math.min(max, v));\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;ACwCA,MAAM,kBAAkB,CAAxB;;;;IACE,WAAF,CAAqB,WAAuB,EAA5C;QAAqB,IAArB,CAAA,WAAgC,GAAX,WAAW,CAAY;KAAK;CAChD;;AAED,MAAM,wBAAwB,GAC1B,UAAU,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAD7C;;;;;;;AAQA,AAAA,MAAa,yBAAyB,GAAG,IAAI,cAAc,CACzD,2BAA2B,EAC3B,EAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,iCAAiC,EAAC,CACjE,CAHD;;;;;AAcA,AAAA,SAAgB,iCAAiC,GAAjD;;IACA,MAAQ,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAApC;;IACA,MAAQ,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAzD;IAEE,OAAO;;;QAGL,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