progress-bar.es5.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { __extends } from 'tslib';
  9. import { Component, ChangeDetectionStrategy, ElementRef, Inject, Input, Output, EventEmitter, Optional, NgZone, ViewEncapsulation, ViewChild, InjectionToken, inject, NgModule } from '@angular/core';
  10. import { fromEvent, Subscription } from 'rxjs';
  11. import { filter } from 'rxjs/operators';
  12. import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
  13. import { mixinColor, MatCommonModule } from '@angular/material/core';
  14. import { DOCUMENT, CommonModule } from '@angular/common';
  15. /**
  16. * @fileoverview added by tsickle
  17. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  18. */
  19. // Boilerplate for applying mixins to MatProgressBar.
  20. /**
  21. * \@docs-private
  22. */
  23. var
  24. // Boilerplate for applying mixins to MatProgressBar.
  25. /**
  26. * \@docs-private
  27. */
  28. MatProgressBarBase = /** @class */ (function () {
  29. function MatProgressBarBase(_elementRef) {
  30. this._elementRef = _elementRef;
  31. }
  32. return MatProgressBarBase;
  33. }());
  34. /** @type {?} */
  35. var _MatProgressBarMixinBase = mixinColor(MatProgressBarBase, 'primary');
  36. /**
  37. * Injection token used to provide the current location to `MatProgressBar`.
  38. * Used to handle server-side rendering and to stub out during unit tests.
  39. * \@docs-private
  40. * @type {?}
  41. */
  42. var MAT_PROGRESS_BAR_LOCATION = new InjectionToken('mat-progress-bar-location', { providedIn: 'root', factory: MAT_PROGRESS_BAR_LOCATION_FACTORY });
  43. /**
  44. * \@docs-private
  45. * @return {?}
  46. */
  47. function MAT_PROGRESS_BAR_LOCATION_FACTORY() {
  48. /** @type {?} */
  49. var _document = inject(DOCUMENT);
  50. /** @type {?} */
  51. var _location = _document ? _document.location : null;
  52. return {
  53. // Note that this needs to be a function, rather than a property, because Angular
  54. // will only resolve it once, but we want the current path on each call.
  55. getPathname: (/**
  56. * @return {?}
  57. */
  58. function () { return _location ? (_location.pathname + _location.search) : ''; })
  59. };
  60. }
  61. /**
  62. * Counter used to generate unique IDs for progress bars.
  63. * @type {?}
  64. */
  65. var progressbarId = 0;
  66. /**
  67. * `<mat-progress-bar>` component.
  68. */
  69. var MatProgressBar = /** @class */ (function (_super) {
  70. __extends(MatProgressBar, _super);
  71. function MatProgressBar(_elementRef, _ngZone, _animationMode,
  72. /**
  73. * @deprecated `location` parameter to be made required.
  74. * @breaking-change 8.0.0
  75. */
  76. location) {
  77. var _this = _super.call(this, _elementRef) || this;
  78. _this._elementRef = _elementRef;
  79. _this._ngZone = _ngZone;
  80. _this._animationMode = _animationMode;
  81. /**
  82. * Flag that indicates whether NoopAnimations mode is set to true.
  83. */
  84. _this._isNoopAnimation = false;
  85. _this._value = 0;
  86. _this._bufferValue = 0;
  87. /**
  88. * Event emitted when animation of the primary progress bar completes. This event will not
  89. * be emitted when animations are disabled, nor will it be emitted for modes with continuous
  90. * animations (indeterminate and query).
  91. */
  92. _this.animationEnd = new EventEmitter();
  93. /**
  94. * Reference to animation end subscription to be unsubscribed on destroy.
  95. */
  96. _this._animationEndSubscription = Subscription.EMPTY;
  97. /**
  98. * Mode of the progress bar.
  99. *
  100. * Input must be one of these values: determinate, indeterminate, buffer, query, defaults to
  101. * 'determinate'.
  102. * Mirrored to mode attribute.
  103. */
  104. _this.mode = 'determinate';
  105. /**
  106. * ID of the progress bar.
  107. */
  108. _this.progressbarId = "mat-progress-bar-" + progressbarId++;
  109. // We need to prefix the SVG reference with the current path, otherwise they won't work
  110. // in Safari if the page has a `<base>` tag. Note that we need quotes inside the `url()`,
  111. // because named route URLs can contain parentheses (see #12338). Also we don't use since
  112. // we can't tell the difference between whether
  113. // the consumer is using the hash location strategy or not, because `Location` normalizes
  114. // both `/#/foo/bar` and `/foo/bar` to the same thing.
  115. /** @type {?} */
  116. var path = location ? location.getPathname().split('#')[0] : '';
  117. _this._rectangleFillValue = "url('" + path + "#" + _this.progressbarId + "')";
  118. _this._isNoopAnimation = _animationMode === 'NoopAnimations';
  119. return _this;
  120. }
  121. Object.defineProperty(MatProgressBar.prototype, "value", {
  122. /** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */
  123. get: /**
  124. * Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow.
  125. * @return {?}
  126. */
  127. function () { return this._value; },
  128. set: /**
  129. * @param {?} v
  130. * @return {?}
  131. */
  132. function (v) {
  133. this._value = clamp(v || 0);
  134. // When noop animation is set to true, trigger animationEnd directly.
  135. if (this._isNoopAnimation) {
  136. this._emitAnimationEnd();
  137. }
  138. },
  139. enumerable: true,
  140. configurable: true
  141. });
  142. Object.defineProperty(MatProgressBar.prototype, "bufferValue", {
  143. /** Buffer value of the progress bar. Defaults to zero. */
  144. get: /**
  145. * Buffer value of the progress bar. Defaults to zero.
  146. * @return {?}
  147. */
  148. function () { return this._bufferValue; },
  149. set: /**
  150. * @param {?} v
  151. * @return {?}
  152. */
  153. function (v) { this._bufferValue = clamp(v || 0); },
  154. enumerable: true,
  155. configurable: true
  156. });
  157. /** Gets the current transform value for the progress bar's primary indicator. */
  158. /**
  159. * Gets the current transform value for the progress bar's primary indicator.
  160. * @return {?}
  161. */
  162. MatProgressBar.prototype._primaryTransform = /**
  163. * Gets the current transform value for the progress bar's primary indicator.
  164. * @return {?}
  165. */
  166. function () {
  167. /** @type {?} */
  168. var scale = this.value / 100;
  169. return { transform: "scaleX(" + scale + ")" };
  170. };
  171. /**
  172. * Gets the current transform value for the progress bar's buffer indicator. Only used if the
  173. * progress mode is set to buffer, otherwise returns an undefined, causing no transformation.
  174. */
  175. /**
  176. * Gets the current transform value for the progress bar's buffer indicator. Only used if the
  177. * progress mode is set to buffer, otherwise returns an undefined, causing no transformation.
  178. * @return {?}
  179. */
  180. MatProgressBar.prototype._bufferTransform = /**
  181. * Gets the current transform value for the progress bar's buffer indicator. Only used if the
  182. * progress mode is set to buffer, otherwise returns an undefined, causing no transformation.
  183. * @return {?}
  184. */
  185. function () {
  186. if (this.mode === 'buffer') {
  187. /** @type {?} */
  188. var scale = this.bufferValue / 100;
  189. return { transform: "scaleX(" + scale + ")" };
  190. }
  191. return undefined;
  192. };
  193. /**
  194. * @return {?}
  195. */
  196. MatProgressBar.prototype.ngAfterViewInit = /**
  197. * @return {?}
  198. */
  199. function () {
  200. var _this = this;
  201. if (!this._isNoopAnimation) {
  202. // Run outside angular so change detection didn't get triggered on every transition end
  203. // instead only on the animation that we care about (primary value bar's transitionend)
  204. this._ngZone.runOutsideAngular(((/**
  205. * @return {?}
  206. */
  207. function () {
  208. /** @type {?} */
  209. var element = _this._primaryValueBar.nativeElement;
  210. _this._animationEndSubscription =
  211. ((/** @type {?} */ (fromEvent(element, 'transitionend'))))
  212. .pipe(filter(((/**
  213. * @param {?} e
  214. * @return {?}
  215. */
  216. function (e) { return e.target === element; }))))
  217. .subscribe((/**
  218. * @return {?}
  219. */
  220. function () { return _this._ngZone.run((/**
  221. * @return {?}
  222. */
  223. function () { return _this._emitAnimationEnd(); })); }));
  224. })));
  225. }
  226. };
  227. /**
  228. * @return {?}
  229. */
  230. MatProgressBar.prototype.ngOnDestroy = /**
  231. * @return {?}
  232. */
  233. function () {
  234. this._animationEndSubscription.unsubscribe();
  235. };
  236. /** Emit an animationEnd event if in determinate or buffer mode. */
  237. /**
  238. * Emit an animationEnd event if in determinate or buffer mode.
  239. * @private
  240. * @return {?}
  241. */
  242. MatProgressBar.prototype._emitAnimationEnd = /**
  243. * Emit an animationEnd event if in determinate or buffer mode.
  244. * @private
  245. * @return {?}
  246. */
  247. function () {
  248. if (this.mode === 'determinate' || this.mode === 'buffer') {
  249. this.animationEnd.next({ value: this.value });
  250. }
  251. };
  252. MatProgressBar.decorators = [
  253. { type: Component, args: [{selector: 'mat-progress-bar',
  254. exportAs: 'matProgressBar',
  255. host: {
  256. 'role': 'progressbar',
  257. 'aria-valuemin': '0',
  258. 'aria-valuemax': '100',
  259. '[attr.aria-valuenow]': '(mode === "indeterminate" || mode === "query") ? null : value',
  260. '[attr.mode]': 'mode',
  261. 'class': 'mat-progress-bar',
  262. '[class._mat-animation-noopable]': '_isNoopAnimation',
  263. },
  264. inputs: ['color'],
  265. template: "<svg width=\"100%\" height=\"4\" focusable=\"false\" class=\"mat-progress-bar-background mat-progress-bar-element\"><defs><pattern [id]=\"progressbarId\" x=\"4\" y=\"0\" width=\"8\" height=\"4\" patternUnits=\"userSpaceOnUse\"><circle cx=\"2\" cy=\"2\" r=\"2\"/></pattern></defs><rect [attr.fill]=\"_rectangleFillValue\" width=\"100%\" height=\"100%\"/></svg><div class=\"mat-progress-bar-buffer mat-progress-bar-element\" [ngStyle]=\"_bufferTransform()\"></div><div class=\"mat-progress-bar-primary mat-progress-bar-fill mat-progress-bar-element\" [ngStyle]=\"_primaryTransform()\" #primaryValueBar></div><div class=\"mat-progress-bar-secondary mat-progress-bar-fill mat-progress-bar-element\"></div>",
  266. styles: [".mat-progress-bar{display:block;height:4px;overflow:hidden;position:relative;transition:opacity 250ms linear;width:100%}._mat-animation-noopable.mat-progress-bar{transition:none;animation:none}.mat-progress-bar .mat-progress-bar-element,.mat-progress-bar .mat-progress-bar-fill::after{height:100%;position:absolute;width:100%}.mat-progress-bar .mat-progress-bar-background{width:calc(100% + 10px)}@media (-ms-high-contrast:active){.mat-progress-bar .mat-progress-bar-background{display:none}}.mat-progress-bar .mat-progress-bar-buffer{transform-origin:top left;transition:transform 250ms ease}@media (-ms-high-contrast:active){.mat-progress-bar .mat-progress-bar-buffer{border-top:solid 5px;opacity:.5}}.mat-progress-bar .mat-progress-bar-secondary{display:none}.mat-progress-bar .mat-progress-bar-fill{animation:none;transform-origin:top left;transition:transform 250ms ease}@media (-ms-high-contrast:active){.mat-progress-bar .mat-progress-bar-fill{border-top:solid 4px}}.mat-progress-bar .mat-progress-bar-fill::after{animation:none;content:'';display:inline-block;left:0}.mat-progress-bar[dir=rtl],[dir=rtl] .mat-progress-bar{transform:rotateY(180deg)}.mat-progress-bar[mode=query]{transform:rotateZ(180deg)}.mat-progress-bar[mode=query][dir=rtl],[dir=rtl] .mat-progress-bar[mode=query]{transform:rotateZ(180deg) rotateY(180deg)}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-fill,.mat-progress-bar[mode=query] .mat-progress-bar-fill{transition:none}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-primary,.mat-progress-bar[mode=query] .mat-progress-bar-primary{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-primary-indeterminate-translate 2s infinite linear;left:-145.166611%}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-primary.mat-progress-bar-fill::after,.mat-progress-bar[mode=query] .mat-progress-bar-primary.mat-progress-bar-fill::after{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-primary-indeterminate-scale 2s infinite linear}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-secondary,.mat-progress-bar[mode=query] .mat-progress-bar-secondary{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-secondary-indeterminate-translate 2s infinite linear;left:-54.888891%;display:block}.mat-progress-bar[mode=indeterminate] .mat-progress-bar-secondary.mat-progress-bar-fill::after,.mat-progress-bar[mode=query] .mat-progress-bar-secondary.mat-progress-bar-fill::after{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-secondary-indeterminate-scale 2s infinite linear}.mat-progress-bar[mode=buffer] .mat-progress-bar-background{-webkit-backface-visibility:hidden;backface-visibility:hidden;animation:mat-progress-bar-background-scroll 250ms infinite linear;display:block}.mat-progress-bar._mat-animation-noopable .mat-progress-bar-background,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-buffer,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-fill,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-fill::after,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-primary,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-primary.mat-progress-bar-fill::after,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-secondary,.mat-progress-bar._mat-animation-noopable .mat-progress-bar-secondary.mat-progress-bar-fill::after{animation:none;transition:none}@keyframes mat-progress-bar-primary-indeterminate-translate{0%{transform:translateX(0)}20%{animation-timing-function:cubic-bezier(.5,0,.70173,.49582);transform:translateX(0)}59.15%{animation-timing-function:cubic-bezier(.30244,.38135,.55,.95635);transform:translateX(83.67142%)}100%{transform:translateX(200.61106%)}}@keyframes mat-progress-bar-primary-indeterminate-scale{0%{transform:scaleX(.08)}36.65%{animation-timing-function:cubic-bezier(.33473,.12482,.78584,1);transform:scaleX(.08)}69.15%{animation-timing-function:cubic-bezier(.06,.11,.6,1);transform:scaleX(.66148)}100%{transform:scaleX(.08)}}@keyframes mat-progress-bar-secondary-indeterminate-translate{0%{animation-timing-function:cubic-bezier(.15,0,.51506,.40969);transform:translateX(0)}25%{animation-timing-function:cubic-bezier(.31033,.28406,.8,.73371);transform:translateX(37.65191%)}48.35%{animation-timing-function:cubic-bezier(.4,.62704,.6,.90203);transform:translateX(84.38617%)}100%{transform:translateX(160.27778%)}}@keyframes mat-progress-bar-secondary-indeterminate-scale{0%{animation-timing-function:cubic-bezier(.15,0,.51506,.40969);transform:scaleX(.08)}19.15%{animation-timing-function:cubic-bezier(.31033,.28406,.8,.73371);transform:scaleX(.4571)}44.15%{animation-timing-function:cubic-bezier(.4,.62704,.6,.90203);transform:scaleX(.72796)}100%{transform:scaleX(.08)}}@keyframes mat-progress-bar-background-scroll{to{transform:translateX(-8px)}}"],
  267. changeDetection: ChangeDetectionStrategy.OnPush,
  268. encapsulation: ViewEncapsulation.None,
  269. },] },
  270. ];
  271. /** @nocollapse */
  272. MatProgressBar.ctorParameters = function () { return [
  273. { type: ElementRef },
  274. { type: NgZone },
  275. { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] },
  276. { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_PROGRESS_BAR_LOCATION,] }] }
  277. ]; };
  278. MatProgressBar.propDecorators = {
  279. value: [{ type: Input }],
  280. bufferValue: [{ type: Input }],
  281. _primaryValueBar: [{ type: ViewChild, args: ['primaryValueBar', { static: false },] }],
  282. animationEnd: [{ type: Output }],
  283. mode: [{ type: Input }]
  284. };
  285. return MatProgressBar;
  286. }(_MatProgressBarMixinBase));
  287. /**
  288. * Clamps a value to be between two numbers, by default 0 and 100.
  289. * @param {?} v
  290. * @param {?=} min
  291. * @param {?=} max
  292. * @return {?}
  293. */
  294. function clamp(v, min, max) {
  295. if (min === void 0) { min = 0; }
  296. if (max === void 0) { max = 100; }
  297. return Math.max(min, Math.min(max, v));
  298. }
  299. /**
  300. * @fileoverview added by tsickle
  301. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  302. */
  303. var MatProgressBarModule = /** @class */ (function () {
  304. function MatProgressBarModule() {
  305. }
  306. MatProgressBarModule.decorators = [
  307. { type: NgModule, args: [{
  308. imports: [CommonModule, MatCommonModule],
  309. exports: [MatProgressBar, MatCommonModule],
  310. declarations: [MatProgressBar],
  311. },] },
  312. ];
  313. return MatProgressBarModule;
  314. }());
  315. /**
  316. * @fileoverview added by tsickle
  317. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  318. */
  319. /**
  320. * @fileoverview added by tsickle
  321. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  322. */
  323. export { MatProgressBarModule, MAT_PROGRESS_BAR_LOCATION_FACTORY, MAT_PROGRESS_BAR_LOCATION, MatProgressBar };
  324. //# sourceMappingURL=progress-bar.es5.js.map