UNPKG

@angular/material

Version:
1 lines 15.1 kB
{"version":3,"file":"progress-bar.mjs","sources":["../../../../../../src/material/progress-bar/progress-bar.ts","../../../../../../src/material/progress-bar/progress-bar.html","../../../../../../src/material/progress-bar/progress-bar-module.ts","../../../../../../src/material/progress-bar/public-api.ts","../../../../../../src/material/progress-bar/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 */\nimport {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';\nimport {DOCUMENT} from '@angular/common';\nimport {\n AfterViewInit,\n ChangeDetectionStrategy,\n Component,\n ElementRef,\n EventEmitter,\n Inject,\n inject,\n InjectionToken,\n Input,\n NgZone,\n OnDestroy,\n Optional,\n Output,\n ViewChild,\n ViewEncapsulation,\n} from '@angular/core';\nimport {CanColor, mixinColor, ThemePalette} from '@angular/material/core';\nimport {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';\nimport {fromEvent, Observable, Subscription} from 'rxjs';\nimport {filter} from 'rxjs/operators';\n\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 */\nconst _MatProgressBarBase = mixinColor(class {\n constructor(public _elementRef: ElementRef) {}\n}, '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\nexport type ProgressBarMode = 'determinate' | 'indeterminate' | 'buffer' | 'query';\n\n/** Default `mat-progress-bar` options that can be overridden. */\nexport interface MatProgressBarDefaultOptions {\n /** Default color of the progress bar. */\n color?: ThemePalette;\n\n /** Default mode of the progress bar. */\n mode?: ProgressBarMode;\n}\n\n/** Injection token to be used to override the default options for `mat-progress-bar`. */\nexport const MAT_PROGRESS_BAR_DEFAULT_OPTIONS =\n new InjectionToken<MatProgressBarDefaultOptions>('MAT_PROGRESS_BAR_DEFAULT_OPTIONS');\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 selector: 'mat-progress-bar',\n exportAs: 'matProgressBar',\n host: {\n 'role': 'progressbar',\n 'aria-valuemin': '0',\n 'aria-valuemax': '100',\n // set tab index to -1 so screen readers will read the aria-label\n // Note: there is a known issue with JAWS that does not read progressbar aria labels on FireFox\n 'tabindex': '-1',\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 _MatProgressBarBase implements CanColor,\n AfterViewInit, OnDestroy {\n constructor(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 @Optional() @Inject(MAT_PROGRESS_BAR_DEFAULT_OPTIONS)\n defaults?: MatProgressBarDefaultOptions) {\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 if (defaults) {\n if (defaults.color) {\n this.color = this.defaultColor = defaults.color;\n }\n\n this.mode = defaults.mode || this.mode;\n }\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(coerceNumberProperty(v) || 0);\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') _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() readonly 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: ProgressBarMode = '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 // We use a 3d transform to work around some rendering issues in iOS Safari. See #19328.\n const scale = this.value / 100;\n return {transform: `scale3d(${scale}, 1, 1)`};\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 // We use a 3d transform to work around some rendering issues in iOS Safari. See #19328.\n const scale = this.bufferValue / 100;\n return {transform: `scale3d(${scale}, 1, 1)`};\n }\n return null;\n }\n\n ngAfterViewInit() {\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(() => {\n if (this.mode === 'determinate' || this.mode === 'buffer') {\n this._ngZone.run(() => this.animationEnd.next({value: this.value}));\n }\n });\n }));\n }\n\n ngOnDestroy() {\n this._animationEndSubscription.unsubscribe();\n }\n\n static ngAcceptInputType_value: NumberInput;\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","<!--\n All children need to be hidden for screen readers in order to support ChromeVox.\n More context in the issue: https://github.com/angular/components/issues/22165.\n-->\n<div aria-hidden=\"true\">\n <svg width=\"100%\" height=\"4\" focusable=\"false\" class=\"mat-progress-bar-background mat-progress-bar-element\">\n <defs>\n <pattern [id]=\"progressbarId\" x=\"4\" y=\"0\" width=\"8\" height=\"4\" patternUnits=\"userSpaceOnUse\">\n <circle cx=\"2\" cy=\"2\" r=\"2\"/>\n </pattern>\n </defs>\n <rect [attr.fill]=\"_rectangleFillValue\" width=\"100%\" height=\"100%\"/>\n </svg>\n <!--\n The background div is named as such because it appears below the other divs and is not sized based\n on values.\n -->\n <div class=\"mat-progress-bar-buffer mat-progress-bar-element\" [ngStyle]=\"_bufferTransform()\"></div>\n <div class=\"mat-progress-bar-primary mat-progress-bar-fill mat-progress-bar-element\" [ngStyle]=\"_primaryTransform()\" #primaryValueBar></div>\n <div class=\"mat-progress-bar-secondary mat-progress-bar-fill mat-progress-bar-element\"></div>\n</div>\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 {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 */\n\nexport * from './progress-bar-module';\nexport * from './progress-bar';\n\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;AAAA;;;;;;;AAwCA;AACA;AACA,MAAM,mBAAmB,GAAG,UAAU,CAAC;IACrC,YAAmB,WAAuB;QAAvB,gBAAW,GAAX,WAAW,CAAY;KAAI;CAC/C,EAAE,SAAS,CAAC,CAAC;AAEd;;;;;MAKa,yBAAyB,GAAG,IAAI,cAAc,CACzD,2BAA2B,EAC3B,EAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,iCAAiC,EAAC,EAChE;AAUF;SACgB,iCAAiC;IAC/C,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC,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