legacy-slider.mjs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. import * as i3 from '@angular/common';
  2. import { DOCUMENT, CommonModule } from '@angular/common';
  3. import * as i0 from '@angular/core';
  4. import { forwardRef, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Optional, Attribute, Inject, Input, Output, ViewChild, NgModule } from '@angular/core';
  5. import { mixinTabIndex, mixinColor, mixinDisabled, MatCommonModule } from '@angular/material/core';
  6. import * as i1 from '@angular/cdk/a11y';
  7. import * as i2 from '@angular/cdk/bidi';
  8. import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
  9. import { hasModifierKey, DOWN_ARROW, RIGHT_ARROW, UP_ARROW, LEFT_ARROW, HOME, END, PAGE_DOWN, PAGE_UP } from '@angular/cdk/keycodes';
  10. import { NG_VALUE_ACCESSOR } from '@angular/forms';
  11. import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
  12. import { normalizePassiveListenerOptions } from '@angular/cdk/platform';
  13. import { Subscription } from 'rxjs';
  14. const activeEventOptions = normalizePassiveListenerOptions({ passive: false });
  15. /**
  16. * Visually, a 30px separation between tick marks looks best. This is very subjective but it is
  17. * the default separation we chose.
  18. */
  19. const MIN_AUTO_TICK_SEPARATION = 30;
  20. /** The thumb gap size for a disabled slider. */
  21. const DISABLED_THUMB_GAP = 7;
  22. /** The thumb gap size for a non-active slider at its minimum value. */
  23. const MIN_VALUE_NONACTIVE_THUMB_GAP = 7;
  24. /** The thumb gap size for an active slider at its minimum value. */
  25. const MIN_VALUE_ACTIVE_THUMB_GAP = 10;
  26. /**
  27. * Provider Expression that allows mat-slider to register as a ControlValueAccessor.
  28. * This allows it to support [(ngModel)] and [formControl].
  29. * @docs-private
  30. * @deprecated Use `MAT_SLIDER_VALUE_ACCESSOR` from `@angular/material/slider` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  31. * @breaking-change 17.0.0
  32. */
  33. const MAT_LEGACY_SLIDER_VALUE_ACCESSOR = {
  34. provide: NG_VALUE_ACCESSOR,
  35. useExisting: forwardRef(() => MatLegacySlider),
  36. multi: true,
  37. };
  38. /**
  39. * A simple change event emitted by the MatSlider component.
  40. * @deprecated Use `MatSliderChange` from `@angular/material/slider` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  41. * @breaking-change 17.0.0
  42. */
  43. class MatLegacySliderChange {
  44. }
  45. // Boilerplate for applying mixins to MatSlider.
  46. /** @docs-private */
  47. const _MatSliderBase = mixinTabIndex(mixinColor(mixinDisabled(class {
  48. constructor(_elementRef) {
  49. this._elementRef = _elementRef;
  50. }
  51. }), 'accent'));
  52. /**
  53. * Allows users to select from a range of values by moving the slider thumb. It is similar in
  54. * behavior to the native `<input type="range">` element.
  55. * @deprecated Use `MatSlider` from `@angular/material/slider` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  56. * @breaking-change 17.0.0
  57. */
  58. class MatLegacySlider extends _MatSliderBase {
  59. /** Whether the slider is inverted. */
  60. get invert() {
  61. return this._invert;
  62. }
  63. set invert(value) {
  64. this._invert = coerceBooleanProperty(value);
  65. }
  66. /** The maximum value that the slider can have. */
  67. get max() {
  68. return this._max;
  69. }
  70. set max(v) {
  71. this._max = coerceNumberProperty(v, this._max);
  72. this._percent = this._calculatePercentage(this._value);
  73. // Since this also modifies the percentage, we need to let the change detection know.
  74. this._changeDetectorRef.markForCheck();
  75. }
  76. /** The minimum value that the slider can have. */
  77. get min() {
  78. return this._min;
  79. }
  80. set min(v) {
  81. this._min = coerceNumberProperty(v, this._min);
  82. this._percent = this._calculatePercentage(this._value);
  83. // Since this also modifies the percentage, we need to let the change detection know.
  84. this._changeDetectorRef.markForCheck();
  85. }
  86. /** The values at which the thumb will snap. */
  87. get step() {
  88. return this._step;
  89. }
  90. set step(v) {
  91. this._step = coerceNumberProperty(v, this._step);
  92. if (this._step % 1 !== 0) {
  93. this._roundToDecimal = this._step.toString().split('.').pop().length;
  94. }
  95. // Since this could modify the label, we need to notify the change detection.
  96. this._changeDetectorRef.markForCheck();
  97. }
  98. /** Whether or not to show the thumb label. */
  99. get thumbLabel() {
  100. return this._thumbLabel;
  101. }
  102. set thumbLabel(value) {
  103. this._thumbLabel = coerceBooleanProperty(value);
  104. }
  105. /**
  106. * How often to show ticks. Relative to the step so that a tick always appears on a step.
  107. * Ex: Tick interval of 4 with a step of 3 will draw a tick every 4 steps (every 12 values).
  108. */
  109. get tickInterval() {
  110. return this._tickInterval;
  111. }
  112. set tickInterval(value) {
  113. if (value === 'auto') {
  114. this._tickInterval = 'auto';
  115. }
  116. else if (typeof value === 'number' || typeof value === 'string') {
  117. this._tickInterval = coerceNumberProperty(value, this._tickInterval);
  118. }
  119. else {
  120. this._tickInterval = 0;
  121. }
  122. }
  123. /** Value of the slider. */
  124. get value() {
  125. // If the value needs to be read and it is still uninitialized, initialize it to the min.
  126. if (this._value === null) {
  127. this.value = this._min;
  128. }
  129. return this._value;
  130. }
  131. set value(v) {
  132. if (v !== this._value) {
  133. let value = coerceNumberProperty(v, 0);
  134. // While incrementing by a decimal we can end up with values like 33.300000000000004.
  135. // Truncate it to ensure that it matches the label and to make it easier to work with.
  136. if (this._roundToDecimal && value !== this.min && value !== this.max) {
  137. value = parseFloat(value.toFixed(this._roundToDecimal));
  138. }
  139. this._value = value;
  140. this._percent = this._calculatePercentage(this._value);
  141. // Since this also modifies the percentage, we need to let the change detection know.
  142. this._changeDetectorRef.markForCheck();
  143. }
  144. }
  145. /** Whether the slider is vertical. */
  146. get vertical() {
  147. return this._vertical;
  148. }
  149. set vertical(value) {
  150. this._vertical = coerceBooleanProperty(value);
  151. }
  152. /** The value to be used for display purposes. */
  153. get displayValue() {
  154. if (this.displayWith) {
  155. // Value is never null but since setters and getters cannot have
  156. // different types, the value getter is also typed to return null.
  157. return this.displayWith(this.value);
  158. }
  159. // Note that this could be improved further by rounding something like 0.999 to 1 or
  160. // 0.899 to 0.9, however it is very performance sensitive, because it gets called on
  161. // every change detection cycle.
  162. if (this._roundToDecimal && this.value && this.value % 1 !== 0) {
  163. return this.value.toFixed(this._roundToDecimal);
  164. }
  165. return this.value || 0;
  166. }
  167. /** set focus to the host element */
  168. focus(options) {
  169. this._focusHostElement(options);
  170. }
  171. /** blur the host element */
  172. blur() {
  173. this._blurHostElement();
  174. }
  175. /** The percentage of the slider that coincides with the value. */
  176. get percent() {
  177. return this._clamp(this._percent);
  178. }
  179. /**
  180. * Whether the axis of the slider is inverted.
  181. * (i.e. whether moving the thumb in the positive x or y direction decreases the slider's value).
  182. */
  183. _shouldInvertAxis() {
  184. // Standard non-inverted mode for a vertical slider should be dragging the thumb from bottom to
  185. // top. However from a y-axis standpoint this is inverted.
  186. return this.vertical ? !this.invert : this.invert;
  187. }
  188. /** Whether the slider is at its minimum value. */
  189. _isMinValue() {
  190. return this.percent === 0;
  191. }
  192. /**
  193. * The amount of space to leave between the slider thumb and the track fill & track background
  194. * elements.
  195. */
  196. _getThumbGap() {
  197. if (this.disabled) {
  198. return DISABLED_THUMB_GAP;
  199. }
  200. if (this._isMinValue() && !this.thumbLabel) {
  201. return this._isActive ? MIN_VALUE_ACTIVE_THUMB_GAP : MIN_VALUE_NONACTIVE_THUMB_GAP;
  202. }
  203. return 0;
  204. }
  205. /** CSS styles for the track background element. */
  206. _getTrackBackgroundStyles() {
  207. const axis = this.vertical ? 'Y' : 'X';
  208. const scale = this.vertical ? `1, ${1 - this.percent}, 1` : `${1 - this.percent}, 1, 1`;
  209. const sign = this._shouldInvertMouseCoords() ? '-' : '';
  210. return {
  211. // scale3d avoids some rendering issues in Chrome. See #12071.
  212. transform: `translate${axis}(${sign}${this._getThumbGap()}px) scale3d(${scale})`,
  213. };
  214. }
  215. /** CSS styles for the track fill element. */
  216. _getTrackFillStyles() {
  217. const percent = this.percent;
  218. const axis = this.vertical ? 'Y' : 'X';
  219. const scale = this.vertical ? `1, ${percent}, 1` : `${percent}, 1, 1`;
  220. const sign = this._shouldInvertMouseCoords() ? '' : '-';
  221. return {
  222. // scale3d avoids some rendering issues in Chrome. See #12071.
  223. transform: `translate${axis}(${sign}${this._getThumbGap()}px) scale3d(${scale})`,
  224. // iOS Safari has a bug where it won't re-render elements which start of as `scale(0)` until
  225. // something forces a style recalculation on it. Since we'll end up with `scale(0)` when
  226. // the value of the slider is 0, we can easily get into this situation. We force a
  227. // recalculation by changing the element's `display` when it goes from 0 to any other value.
  228. display: percent === 0 ? 'none' : '',
  229. };
  230. }
  231. /** CSS styles for the ticks container element. */
  232. _getTicksContainerStyles() {
  233. let axis = this.vertical ? 'Y' : 'X';
  234. // For a horizontal slider in RTL languages we push the ticks container off the left edge
  235. // instead of the right edge to avoid causing a horizontal scrollbar to appear.
  236. let sign = !this.vertical && this._getDirection() == 'rtl' ? '' : '-';
  237. let offset = (this._tickIntervalPercent / 2) * 100;
  238. return {
  239. 'transform': `translate${axis}(${sign}${offset}%)`,
  240. };
  241. }
  242. /** CSS styles for the ticks element. */
  243. _getTicksStyles() {
  244. let tickSize = this._tickIntervalPercent * 100;
  245. let backgroundSize = this.vertical ? `2px ${tickSize}%` : `${tickSize}% 2px`;
  246. let axis = this.vertical ? 'Y' : 'X';
  247. // Depending on the direction we pushed the ticks container, push the ticks the opposite
  248. // direction to re-center them but clip off the end edge. In RTL languages we need to flip the
  249. // ticks 180 degrees so we're really cutting off the end edge abd not the start.
  250. let sign = !this.vertical && this._getDirection() == 'rtl' ? '-' : '';
  251. let rotate = !this.vertical && this._getDirection() == 'rtl' ? ' rotate(180deg)' : '';
  252. let styles = {
  253. 'backgroundSize': backgroundSize,
  254. // Without translateZ ticks sometimes jitter as the slider moves on Chrome & Firefox.
  255. 'transform': `translateZ(0) translate${axis}(${sign}${tickSize / 2}%)${rotate}`,
  256. };
  257. if (this._isMinValue() && this._getThumbGap()) {
  258. const shouldInvertAxis = this._shouldInvertAxis();
  259. let side;
  260. if (this.vertical) {
  261. side = shouldInvertAxis ? 'Bottom' : 'Top';
  262. }
  263. else {
  264. side = shouldInvertAxis ? 'Right' : 'Left';
  265. }
  266. styles[`padding${side}`] = `${this._getThumbGap()}px`;
  267. }
  268. return styles;
  269. }
  270. _getThumbContainerStyles() {
  271. const shouldInvertAxis = this._shouldInvertAxis();
  272. let axis = this.vertical ? 'Y' : 'X';
  273. // For a horizontal slider in RTL languages we push the thumb container off the left edge
  274. // instead of the right edge to avoid causing a horizontal scrollbar to appear.
  275. let invertOffset = this._getDirection() == 'rtl' && !this.vertical ? !shouldInvertAxis : shouldInvertAxis;
  276. let offset = (invertOffset ? this.percent : 1 - this.percent) * 100;
  277. return {
  278. 'transform': `translate${axis}(-${offset}%)`,
  279. };
  280. }
  281. /**
  282. * Whether mouse events should be converted to a slider position by calculating their distance
  283. * from the right or bottom edge of the slider as opposed to the top or left.
  284. */
  285. _shouldInvertMouseCoords() {
  286. const shouldInvertAxis = this._shouldInvertAxis();
  287. return this._getDirection() == 'rtl' && !this.vertical ? !shouldInvertAxis : shouldInvertAxis;
  288. }
  289. /** The language direction for this slider element. */
  290. _getDirection() {
  291. return this._dir && this._dir.value == 'rtl' ? 'rtl' : 'ltr';
  292. }
  293. constructor(elementRef, _focusMonitor, _changeDetectorRef, _dir, tabIndex, _ngZone, _document, _animationMode) {
  294. super(elementRef);
  295. this._focusMonitor = _focusMonitor;
  296. this._changeDetectorRef = _changeDetectorRef;
  297. this._dir = _dir;
  298. this._ngZone = _ngZone;
  299. this._animationMode = _animationMode;
  300. this._invert = false;
  301. this._max = 100;
  302. this._min = 0;
  303. this._step = 1;
  304. this._thumbLabel = false;
  305. this._tickInterval = 0;
  306. this._value = null;
  307. this._vertical = false;
  308. /** Event emitted when the slider value has changed. */
  309. this.change = new EventEmitter();
  310. /** Event emitted when the slider thumb moves. */
  311. this.input = new EventEmitter();
  312. /**
  313. * Emits when the raw value of the slider changes. This is here primarily
  314. * to facilitate the two-way binding for the `value` input.
  315. * @docs-private
  316. */
  317. this.valueChange = new EventEmitter();
  318. /** onTouch function registered via registerOnTouch (ControlValueAccessor). */
  319. this.onTouched = () => { };
  320. this._percent = 0;
  321. /**
  322. * Whether or not the thumb is sliding and what the user is using to slide it with.
  323. * Used to determine if there should be a transition for the thumb and fill track.
  324. */
  325. this._isSliding = null;
  326. /**
  327. * Whether or not the slider is active (clicked or sliding).
  328. * Used to shrink and grow the thumb as according to the Material Design spec.
  329. */
  330. this._isActive = false;
  331. /** The size of a tick interval as a percentage of the size of the track. */
  332. this._tickIntervalPercent = 0;
  333. /** The dimensions of the slider. */
  334. this._sliderDimensions = null;
  335. this._controlValueAccessorChangeFn = () => { };
  336. /** Subscription to the Directionality change EventEmitter. */
  337. this._dirChangeSubscription = Subscription.EMPTY;
  338. /** Called when the user has put their pointer down on the slider. */
  339. this._pointerDown = (event) => {
  340. // Don't do anything if the slider is disabled or the
  341. // user is using anything other than the main mouse button.
  342. if (this.disabled || this._isSliding || (!isTouchEvent(event) && event.button !== 0)) {
  343. return;
  344. }
  345. this._ngZone.run(() => {
  346. this._touchId = isTouchEvent(event)
  347. ? getTouchIdForSlider(event, this._elementRef.nativeElement)
  348. : undefined;
  349. const pointerPosition = getPointerPositionOnPage(event, this._touchId);
  350. if (pointerPosition) {
  351. const oldValue = this.value;
  352. this._isSliding = 'pointer';
  353. this._lastPointerEvent = event;
  354. this._focusHostElement();
  355. this._onMouseenter(); // Simulate mouseenter in case this is a mobile device.
  356. this._bindGlobalEvents(event);
  357. this._focusHostElement();
  358. this._updateValueFromPosition(pointerPosition);
  359. this._valueOnSlideStart = oldValue;
  360. // Despite the fact that we explicitly bind active events, in some cases the browser
  361. // still dispatches non-cancelable events which cause this call to throw an error.
  362. // There doesn't appear to be a good way of avoiding them. See #23820.
  363. if (event.cancelable) {
  364. event.preventDefault();
  365. }
  366. // Emit a change and input event if the value changed.
  367. if (oldValue != this.value) {
  368. this._emitInputEvent();
  369. }
  370. }
  371. });
  372. };
  373. /**
  374. * Called when the user has moved their pointer after
  375. * starting to drag. Bound on the document level.
  376. */
  377. this._pointerMove = (event) => {
  378. if (this._isSliding === 'pointer') {
  379. const pointerPosition = getPointerPositionOnPage(event, this._touchId);
  380. if (pointerPosition) {
  381. // Prevent the slide from selecting anything else.
  382. if (event.cancelable) {
  383. event.preventDefault();
  384. }
  385. const oldValue = this.value;
  386. this._lastPointerEvent = event;
  387. this._updateValueFromPosition(pointerPosition);
  388. // Native range elements always emit `input` events when the value changed while sliding.
  389. if (oldValue != this.value) {
  390. this._emitInputEvent();
  391. }
  392. }
  393. }
  394. };
  395. /** Called when the user has lifted their pointer. Bound on the document level. */
  396. this._pointerUp = (event) => {
  397. if (this._isSliding === 'pointer') {
  398. if (!isTouchEvent(event) ||
  399. typeof this._touchId !== 'number' ||
  400. // Note that we use `changedTouches`, rather than `touches` because it
  401. // seems like in most cases `touches` is empty for `touchend` events.
  402. findMatchingTouch(event.changedTouches, this._touchId)) {
  403. if (event.cancelable) {
  404. event.preventDefault();
  405. }
  406. this._removeGlobalEvents();
  407. this._isSliding = null;
  408. this._touchId = undefined;
  409. if (this._valueOnSlideStart != this.value && !this.disabled) {
  410. this._emitChangeEvent();
  411. }
  412. this._valueOnSlideStart = this._lastPointerEvent = null;
  413. }
  414. }
  415. };
  416. /** Called when the window has lost focus. */
  417. this._windowBlur = () => {
  418. // If the window is blurred while dragging we need to stop dragging because the
  419. // browser won't dispatch the `mouseup` and `touchend` events anymore.
  420. if (this._lastPointerEvent) {
  421. this._pointerUp(this._lastPointerEvent);
  422. }
  423. };
  424. this._document = _document;
  425. this.tabIndex = parseInt(tabIndex) || 0;
  426. _ngZone.runOutsideAngular(() => {
  427. const element = elementRef.nativeElement;
  428. element.addEventListener('mousedown', this._pointerDown, activeEventOptions);
  429. element.addEventListener('touchstart', this._pointerDown, activeEventOptions);
  430. });
  431. }
  432. ngAfterViewInit() {
  433. this._focusMonitor.monitor(this._elementRef, true).subscribe((origin) => {
  434. this._isActive = !!origin && origin !== 'keyboard';
  435. this._changeDetectorRef.detectChanges();
  436. });
  437. if (this._dir) {
  438. this._dirChangeSubscription = this._dir.change.subscribe(() => {
  439. this._changeDetectorRef.markForCheck();
  440. });
  441. }
  442. }
  443. ngOnDestroy() {
  444. const element = this._elementRef.nativeElement;
  445. element.removeEventListener('mousedown', this._pointerDown, activeEventOptions);
  446. element.removeEventListener('touchstart', this._pointerDown, activeEventOptions);
  447. this._lastPointerEvent = null;
  448. this._removeGlobalEvents();
  449. this._focusMonitor.stopMonitoring(this._elementRef);
  450. this._dirChangeSubscription.unsubscribe();
  451. }
  452. _onMouseenter() {
  453. if (this.disabled) {
  454. return;
  455. }
  456. // We save the dimensions of the slider here so we can use them to update the spacing of the
  457. // ticks and determine where on the slider click and slide events happen.
  458. this._sliderDimensions = this._getSliderDimensions();
  459. this._updateTickIntervalPercent();
  460. }
  461. _onFocus() {
  462. // We save the dimensions of the slider here so we can use them to update the spacing of the
  463. // ticks and determine where on the slider click and slide events happen.
  464. this._sliderDimensions = this._getSliderDimensions();
  465. this._updateTickIntervalPercent();
  466. }
  467. _onBlur() {
  468. this.onTouched();
  469. }
  470. _onKeydown(event) {
  471. if (this.disabled ||
  472. hasModifierKey(event) ||
  473. (this._isSliding && this._isSliding !== 'keyboard')) {
  474. return;
  475. }
  476. const oldValue = this.value;
  477. switch (event.keyCode) {
  478. case PAGE_UP:
  479. this._increment(10);
  480. break;
  481. case PAGE_DOWN:
  482. this._increment(-10);
  483. break;
  484. case END:
  485. this.value = this.max;
  486. break;
  487. case HOME:
  488. this.value = this.min;
  489. break;
  490. case LEFT_ARROW:
  491. // NOTE: For a sighted user it would make more sense that when they press an arrow key on an
  492. // inverted slider the thumb moves in that direction. However for a blind user, nothing
  493. // about the slider indicates that it is inverted. They will expect left to be decrement,
  494. // regardless of how it appears on the screen. For speakers ofRTL languages, they probably
  495. // expect left to mean increment. Therefore we flip the meaning of the side arrow keys for
  496. // RTL. For inverted sliders we prefer a good a11y experience to having it "look right" for
  497. // sighted users, therefore we do not swap the meaning.
  498. this._increment(this._getDirection() == 'rtl' ? 1 : -1);
  499. break;
  500. case UP_ARROW:
  501. this._increment(1);
  502. break;
  503. case RIGHT_ARROW:
  504. // See comment on LEFT_ARROW about the conditions under which we flip the meaning.
  505. this._increment(this._getDirection() == 'rtl' ? -1 : 1);
  506. break;
  507. case DOWN_ARROW:
  508. this._increment(-1);
  509. break;
  510. default:
  511. // Return if the key is not one that we explicitly handle to avoid calling preventDefault on
  512. // it.
  513. return;
  514. }
  515. if (oldValue != this.value) {
  516. this._emitInputEvent();
  517. this._emitChangeEvent();
  518. }
  519. this._isSliding = 'keyboard';
  520. event.preventDefault();
  521. }
  522. _onKeyup() {
  523. if (this._isSliding === 'keyboard') {
  524. this._isSliding = null;
  525. }
  526. }
  527. /** Use defaultView of injected document if available or fallback to global window reference */
  528. _getWindow() {
  529. return this._document.defaultView || window;
  530. }
  531. /**
  532. * Binds our global move and end events. They're bound at the document level and only while
  533. * dragging so that the user doesn't have to keep their pointer exactly over the slider
  534. * as they're swiping across the screen.
  535. */
  536. _bindGlobalEvents(triggerEvent) {
  537. // Note that we bind the events to the `document`, because it allows us to capture
  538. // drag cancel events where the user's pointer is outside the browser window.
  539. const document = this._document;
  540. const isTouch = isTouchEvent(triggerEvent);
  541. const moveEventName = isTouch ? 'touchmove' : 'mousemove';
  542. const endEventName = isTouch ? 'touchend' : 'mouseup';
  543. document.addEventListener(moveEventName, this._pointerMove, activeEventOptions);
  544. document.addEventListener(endEventName, this._pointerUp, activeEventOptions);
  545. if (isTouch) {
  546. document.addEventListener('touchcancel', this._pointerUp, activeEventOptions);
  547. }
  548. const window = this._getWindow();
  549. if (typeof window !== 'undefined' && window) {
  550. window.addEventListener('blur', this._windowBlur);
  551. }
  552. }
  553. /** Removes any global event listeners that we may have added. */
  554. _removeGlobalEvents() {
  555. const document = this._document;
  556. document.removeEventListener('mousemove', this._pointerMove, activeEventOptions);
  557. document.removeEventListener('mouseup', this._pointerUp, activeEventOptions);
  558. document.removeEventListener('touchmove', this._pointerMove, activeEventOptions);
  559. document.removeEventListener('touchend', this._pointerUp, activeEventOptions);
  560. document.removeEventListener('touchcancel', this._pointerUp, activeEventOptions);
  561. const window = this._getWindow();
  562. if (typeof window !== 'undefined' && window) {
  563. window.removeEventListener('blur', this._windowBlur);
  564. }
  565. }
  566. /** Increments the slider by the given number of steps (negative number decrements). */
  567. _increment(numSteps) {
  568. // Pre-clamp the current value since it's allowed to be
  569. // out of bounds when assigned programmatically.
  570. const clampedValue = this._clamp(this.value || 0, this.min, this.max);
  571. this.value = this._clamp(clampedValue + this.step * numSteps, this.min, this.max);
  572. }
  573. /** Calculate the new value from the new physical location. The value will always be snapped. */
  574. _updateValueFromPosition(pos) {
  575. if (!this._sliderDimensions) {
  576. return;
  577. }
  578. let offset = this.vertical ? this._sliderDimensions.top : this._sliderDimensions.left;
  579. let size = this.vertical ? this._sliderDimensions.height : this._sliderDimensions.width;
  580. let posComponent = this.vertical ? pos.y : pos.x;
  581. // The exact value is calculated from the event and used to find the closest snap value.
  582. let percent = this._clamp((posComponent - offset) / size);
  583. if (this._shouldInvertMouseCoords()) {
  584. percent = 1 - percent;
  585. }
  586. // Since the steps may not divide cleanly into the max value, if the user
  587. // slid to 0 or 100 percent, we jump to the min/max value. This approach
  588. // is slightly more intuitive than using `Math.ceil` below, because it
  589. // follows the user's pointer closer.
  590. if (percent === 0) {
  591. this.value = this.min;
  592. }
  593. else if (percent === 1) {
  594. this.value = this.max;
  595. }
  596. else {
  597. const exactValue = this._calculateValue(percent);
  598. // This calculation finds the closest step by finding the closest
  599. // whole number divisible by the step relative to the min.
  600. const closestValue = Math.round((exactValue - this.min) / this.step) * this.step + this.min;
  601. // The value needs to snap to the min and max.
  602. this.value = this._clamp(closestValue, this.min, this.max);
  603. }
  604. }
  605. /** Emits a change event if the current value is different from the last emitted value. */
  606. _emitChangeEvent() {
  607. this._controlValueAccessorChangeFn(this.value);
  608. this.valueChange.emit(this.value);
  609. this.change.emit(this._createChangeEvent());
  610. }
  611. /** Emits an input event when the current value is different from the last emitted value. */
  612. _emitInputEvent() {
  613. this.input.emit(this._createChangeEvent());
  614. }
  615. /** Updates the amount of space between ticks as a percentage of the width of the slider. */
  616. _updateTickIntervalPercent() {
  617. if (!this.tickInterval || !this._sliderDimensions) {
  618. return;
  619. }
  620. let tickIntervalPercent;
  621. if (this.tickInterval == 'auto') {
  622. let trackSize = this.vertical ? this._sliderDimensions.height : this._sliderDimensions.width;
  623. let pixelsPerStep = (trackSize * this.step) / (this.max - this.min);
  624. let stepsPerTick = Math.ceil(MIN_AUTO_TICK_SEPARATION / pixelsPerStep);
  625. let pixelsPerTick = stepsPerTick * this.step;
  626. tickIntervalPercent = pixelsPerTick / trackSize;
  627. }
  628. else {
  629. tickIntervalPercent = (this.tickInterval * this.step) / (this.max - this.min);
  630. }
  631. this._tickIntervalPercent = isSafeNumber(tickIntervalPercent) ? tickIntervalPercent : 0;
  632. }
  633. /** Creates a slider change object from the specified value. */
  634. _createChangeEvent(value = this.value) {
  635. let event = new MatLegacySliderChange();
  636. event.source = this;
  637. event.value = value;
  638. return event;
  639. }
  640. /** Calculates the percentage of the slider that a value is. */
  641. _calculatePercentage(value) {
  642. const percentage = ((value || 0) - this.min) / (this.max - this.min);
  643. return isSafeNumber(percentage) ? percentage : 0;
  644. }
  645. /** Calculates the value a percentage of the slider corresponds to. */
  646. _calculateValue(percentage) {
  647. return this.min + percentage * (this.max - this.min);
  648. }
  649. /** Return a number between two numbers. */
  650. _clamp(value, min = 0, max = 1) {
  651. return Math.max(min, Math.min(value, max));
  652. }
  653. /**
  654. * Get the bounding client rect of the slider track element.
  655. * The track is used rather than the native element to ignore the extra space that the thumb can
  656. * take up.
  657. */
  658. _getSliderDimensions() {
  659. return this._sliderWrapper ? this._sliderWrapper.nativeElement.getBoundingClientRect() : null;
  660. }
  661. /**
  662. * Focuses the native element.
  663. * Currently only used to allow a blur event to fire but will be used with keyboard input later.
  664. */
  665. _focusHostElement(options) {
  666. this._elementRef.nativeElement.focus(options);
  667. }
  668. /** Blurs the native element. */
  669. _blurHostElement() {
  670. this._elementRef.nativeElement.blur();
  671. }
  672. /**
  673. * Sets the model value. Implemented as part of ControlValueAccessor.
  674. * @param value
  675. */
  676. writeValue(value) {
  677. this.value = value;
  678. }
  679. /**
  680. * Registers a callback to be triggered when the value has changed.
  681. * Implemented as part of ControlValueAccessor.
  682. * @param fn Callback to be registered.
  683. */
  684. registerOnChange(fn) {
  685. this._controlValueAccessorChangeFn = fn;
  686. }
  687. /**
  688. * Registers a callback to be triggered when the component is touched.
  689. * Implemented as part of ControlValueAccessor.
  690. * @param fn Callback to be registered.
  691. */
  692. registerOnTouched(fn) {
  693. this.onTouched = fn;
  694. }
  695. /**
  696. * Sets whether the component should be disabled.
  697. * Implemented as part of ControlValueAccessor.
  698. * @param isDisabled
  699. */
  700. setDisabledState(isDisabled) {
  701. this.disabled = isDisabled;
  702. }
  703. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySlider, deps: [{ token: i0.ElementRef }, { token: i1.FocusMonitor }, { token: i0.ChangeDetectorRef }, { token: i2.Directionality, optional: true }, { token: 'tabindex', attribute: true }, { token: i0.NgZone }, { token: DOCUMENT }, { token: ANIMATION_MODULE_TYPE, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
  704. static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.0", type: MatLegacySlider, selector: "mat-slider", inputs: { disabled: "disabled", color: "color", tabIndex: "tabIndex", invert: "invert", max: "max", min: "min", step: "step", thumbLabel: "thumbLabel", tickInterval: "tickInterval", value: "value", displayWith: "displayWith", valueText: "valueText", vertical: "vertical" }, outputs: { change: "change", input: "input", valueChange: "valueChange" }, host: { attributes: { "role": "slider" }, listeners: { "focus": "_onFocus()", "blur": "_onBlur()", "keydown": "_onKeydown($event)", "keyup": "_onKeyup()", "mouseenter": "_onMouseenter()", "selectstart": "$event.preventDefault()" }, properties: { "tabIndex": "tabIndex", "attr.aria-disabled": "disabled", "attr.aria-valuemax": "max", "attr.aria-valuemin": "min", "attr.aria-valuenow": "value", "attr.aria-valuetext": "valueText == null ? displayValue : valueText", "attr.aria-orientation": "vertical ? \"vertical\" : \"horizontal\"", "class.mat-slider-disabled": "disabled", "class.mat-slider-has-ticks": "tickInterval", "class.mat-slider-horizontal": "!vertical", "class.mat-slider-axis-inverted": "_shouldInvertAxis()", "class.mat-slider-invert-mouse-coords": "_shouldInvertMouseCoords()", "class.mat-slider-sliding": "_isSliding", "class.mat-slider-thumb-label-showing": "thumbLabel", "class.mat-slider-vertical": "vertical", "class.mat-slider-min-value": "_isMinValue()", "class.mat-slider-hide-last-tick": "disabled || _isMinValue() && _getThumbGap() && _shouldInvertAxis()", "class._mat-animation-noopable": "_animationMode === \"NoopAnimations\"" }, classAttribute: "mat-slider mat-focus-indicator" }, providers: [MAT_LEGACY_SLIDER_VALUE_ACCESSOR], viewQueries: [{ propertyName: "_sliderWrapper", first: true, predicate: ["sliderWrapper"], descendants: true }], exportAs: ["matSlider"], usesInheritance: true, ngImport: i0, template: "<div class=\"mat-slider-wrapper\" #sliderWrapper>\n <div class=\"mat-slider-track-wrapper\">\n <div class=\"mat-slider-track-background\" [ngStyle]=\"_getTrackBackgroundStyles()\"></div>\n <div class=\"mat-slider-track-fill\" [ngStyle]=\"_getTrackFillStyles()\"></div>\n </div>\n <div class=\"mat-slider-ticks-container\" [ngStyle]=\"_getTicksContainerStyles()\">\n <div class=\"mat-slider-ticks\" [ngStyle]=\"_getTicksStyles()\"></div>\n </div>\n <div class=\"mat-slider-thumb-container\" [ngStyle]=\"_getThumbContainerStyles()\">\n <div class=\"mat-slider-focus-ring\"></div>\n <div class=\"mat-slider-thumb\"></div>\n <div class=\"mat-slider-thumb-label\">\n <span class=\"mat-slider-thumb-label-text\">{{displayValue}}</span>\n </div>\n </div>\n</div>\n", styles: [".mat-slider{display:inline-block;position:relative;box-sizing:border-box;padding:8px;outline:none;vertical-align:middle}.mat-slider:not(.mat-slider-disabled):active,.mat-slider.mat-slider-sliding:not(.mat-slider-disabled){cursor:grabbing}.mat-slider-wrapper{-webkit-print-color-adjust:exact;color-adjust:exact;position:absolute}.mat-slider-track-wrapper{position:absolute;top:0;left:0;overflow:hidden}.mat-slider-track-fill{position:absolute;transform-origin:0 0;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-track-background{position:absolute;transform-origin:100% 100%;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-ticks-container{position:absolute;left:0;top:0;overflow:hidden}.mat-slider-ticks{-webkit-background-clip:content-box;background-clip:content-box;background-repeat:repeat;box-sizing:border-box;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-thumb-container{position:absolute;z-index:1;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-focus-ring{position:absolute;width:30px;height:30px;border-radius:50%;transform:scale(0);opacity:0;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1),opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider.cdk-keyboard-focused .mat-slider-focus-ring,.mat-slider.cdk-program-focused .mat-slider-focus-ring{transform:scale(1);opacity:1}.mat-slider:not(.mat-slider-disabled):not(.mat-slider-sliding) .mat-slider-thumb-label,.mat-slider:not(.mat-slider-disabled):not(.mat-slider-sliding) .mat-slider-thumb{cursor:grab}.mat-slider-thumb{position:absolute;right:-10px;bottom:-10px;box-sizing:border-box;width:20px;height:20px;border:3px solid rgba(0,0,0,0);border-radius:50%;transform:scale(0.7);transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1),border-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-thumb-label{display:none;align-items:center;justify-content:center;position:absolute;width:28px;height:28px;border-radius:50%;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),border-radius 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.cdk-high-contrast-active .mat-slider-thumb-label{outline:solid 1px}.mat-slider-thumb-label-text{z-index:1;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-sliding .mat-slider-track-fill,.mat-slider-sliding .mat-slider-track-background,.mat-slider-sliding .mat-slider-thumb-container{transition-duration:0ms}.mat-slider-has-ticks .mat-slider-wrapper::after{content:\"\";position:absolute;border-width:0;border-style:solid;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-has-ticks.cdk-focused:not(.mat-slider-hide-last-tick) .mat-slider-wrapper::after,.mat-slider-has-ticks:hover:not(.mat-slider-hide-last-tick) .mat-slider-wrapper::after{opacity:1}.mat-slider-has-ticks.cdk-focused:not(.mat-slider-disabled) .mat-slider-ticks,.mat-slider-has-ticks:hover:not(.mat-slider-disabled) .mat-slider-ticks{opacity:1}.mat-slider-thumb-label-showing .mat-slider-focus-ring{display:none}.mat-slider-thumb-label-showing .mat-slider-thumb-label{display:flex}.mat-slider-axis-inverted .mat-slider-track-fill{transform-origin:100% 100%}.mat-slider-axis-inverted .mat-slider-track-background{transform-origin:0 0}.mat-slider:not(.mat-slider-disabled).cdk-focused.mat-slider-thumb-label-showing .mat-slider-thumb{transform:scale(0)}.mat-slider:not(.mat-slider-disabled).cdk-focused .mat-slider-thumb-label{border-radius:50% 50% 0}.mat-slider:not(.mat-slider-disabled).cdk-focused .mat-slider-thumb-label-text{opacity:1}.mat-slider:not(.mat-slider-disabled).cdk-mouse-focused .mat-slider-thumb,.mat-slider:not(.mat-slider-disabled).cdk-touch-focused .mat-slider-thumb,.mat-slider:not(.mat-slider-disabled).cdk-program-focused .mat-slider-thumb{border-width:2px;transform:scale(1)}.mat-slider-disabled .mat-slider-focus-ring{transform:scale(0);opacity:0}.mat-slider-disabled .mat-slider-thumb{border-width:4px;transform:scale(0.5)}.mat-slider-disabled .mat-slider-thumb-label{display:none}.mat-slider-horizontal{height:48px;min-width:128px}.mat-slider-horizontal .mat-slider-wrapper{height:2px;top:23px;left:8px;right:8px}.mat-slider-horizontal .mat-slider-wrapper::after{height:2px;border-left-width:2px;right:0;top:0}.mat-slider-horizontal .mat-slider-track-wrapper{height:2px;width:100%}.mat-slider-horizontal .mat-slider-track-fill{height:2px;width:100%;transform:scaleX(0)}.mat-slider-horizontal .mat-slider-track-background{height:2px;width:100%;transform:scaleX(1)}.mat-slider-horizontal .mat-slider-ticks-container{height:2px;width:100%}.cdk-high-contrast-active .mat-slider-horizontal .mat-slider-ticks-container{height:0;outline:solid 2px;top:1px}.mat-slider-horizontal .mat-slider-ticks{height:2px;width:100%}.mat-slider-horizontal .mat-slider-thumb-container{width:100%;height:0;top:50%}.mat-slider-horizontal .mat-slider-focus-ring{top:-15px;right:-15px}.mat-slider-horizontal .mat-slider-thumb-label{right:-14px;top:-40px;transform:translateY(26px) scale(0.01) rotate(45deg)}.mat-slider-horizontal .mat-slider-thumb-label-text{transform:rotate(-45deg)}.mat-slider-horizontal.cdk-focused .mat-slider-thumb-label{transform:rotate(45deg)}.cdk-high-contrast-active .mat-slider-horizontal.cdk-focused .mat-slider-thumb-label,.cdk-high-contrast-active .mat-slider-horizontal.cdk-focused .mat-slider-thumb-label-text{transform:none}.mat-slider-vertical{width:48px;min-height:128px}.mat-slider-vertical .mat-slider-wrapper{width:2px;top:8px;bottom:8px;left:23px}.mat-slider-vertical .mat-slider-wrapper::after{width:2px;border-top-width:2px;bottom:0;left:0}.mat-slider-vertical .mat-slider-track-wrapper{height:100%;width:2px}.mat-slider-vertical .mat-slider-track-fill{height:100%;width:2px;transform:scaleY(0)}.mat-slider-vertical .mat-slider-track-background{height:100%;width:2px;transform:scaleY(1)}.mat-slider-vertical .mat-slider-ticks-container{width:2px;height:100%}.cdk-high-contrast-active .mat-slider-vertical .mat-slider-ticks-container{width:0;outline:solid 2px;left:1px}.mat-slider-vertical .mat-slider-focus-ring{bottom:-15px;left:-15px}.mat-slider-vertical .mat-slider-ticks{width:2px;height:100%}.mat-slider-vertical .mat-slider-thumb-container{height:100%;width:0;left:50%}.mat-slider-vertical .mat-slider-thumb{-webkit-backface-visibility:hidden;backface-visibility:hidden}.mat-slider-vertical .mat-slider-thumb-label{bottom:-14px;left:-40px;transform:translateX(26px) scale(0.01) rotate(-45deg)}.mat-slider-vertical .mat-slider-thumb-label-text{transform:rotate(45deg)}.mat-slider-vertical.cdk-focused .mat-slider-thumb-label{transform:rotate(-45deg)}[dir=rtl] .mat-slider-wrapper::after{left:0;right:auto}[dir=rtl] .mat-slider-horizontal .mat-slider-track-fill{transform-origin:100% 100%}[dir=rtl] .mat-slider-horizontal .mat-slider-track-background{transform-origin:0 0}[dir=rtl] .mat-slider-horizontal.mat-slider-axis-inverted .mat-slider-track-fill{transform-origin:0 0}[dir=rtl] .mat-slider-horizontal.mat-slider-axis-inverted .mat-slider-track-background{transform-origin:100% 100%}.mat-slider._mat-animation-noopable .mat-slider-track-fill,.mat-slider._mat-animation-noopable .mat-slider-track-background,.mat-slider._mat-animation-noopable .mat-slider-ticks,.mat-slider._mat-animation-noopable .mat-slider-thumb-container,.mat-slider._mat-animation-noopable .mat-slider-focus-ring,.mat-slider._mat-animation-noopable .mat-slider-thumb,.mat-slider._mat-animation-noopable .mat-slider-thumb-label,.mat-slider._mat-animation-noopable .mat-slider-thumb-label-text,.mat-slider._mat-animation-noopable .mat-slider-has-ticks .mat-slider-wrapper::after{transition:none}"], dependencies: [{ kind: "directive", type: i3.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
  705. }
  706. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySlider, decorators: [{
  707. type: Component,
  708. args: [{ selector: 'mat-slider', exportAs: 'matSlider', providers: [MAT_LEGACY_SLIDER_VALUE_ACCESSOR], host: {
  709. '(focus)': '_onFocus()',
  710. '(blur)': '_onBlur()',
  711. '(keydown)': '_onKeydown($event)',
  712. '(keyup)': '_onKeyup()',
  713. '(mouseenter)': '_onMouseenter()',
  714. // On Safari starting to slide temporarily triggers text selection mode which
  715. // show the wrong cursor. We prevent it by stopping the `selectstart` event.
  716. '(selectstart)': '$event.preventDefault()',
  717. 'class': 'mat-slider mat-focus-indicator',
  718. 'role': 'slider',
  719. '[tabIndex]': 'tabIndex',
  720. '[attr.aria-disabled]': 'disabled',
  721. '[attr.aria-valuemax]': 'max',
  722. '[attr.aria-valuemin]': 'min',
  723. '[attr.aria-valuenow]': 'value',
  724. // NVDA and Jaws appear to announce the `aria-valuenow` by calculating its percentage based
  725. // on its value between `aria-valuemin` and `aria-valuemax`. Due to how decimals are handled,
  726. // it can cause the slider to read out a very long value like 0.20000068 if the current value
  727. // is 0.2 with a min of 0 and max of 1. We work around the issue by setting `aria-valuetext`
  728. // to the same value that we set on the slider's thumb which will be truncated.
  729. '[attr.aria-valuetext]': 'valueText == null ? displayValue : valueText',
  730. '[attr.aria-orientation]': 'vertical ? "vertical" : "horizontal"',
  731. '[class.mat-slider-disabled]': 'disabled',
  732. '[class.mat-slider-has-ticks]': 'tickInterval',
  733. '[class.mat-slider-horizontal]': '!vertical',
  734. '[class.mat-slider-axis-inverted]': '_shouldInvertAxis()',
  735. // Class binding which is only used by the test harness as there is no other
  736. // way for the harness to detect if mouse coordinates need to be inverted.
  737. '[class.mat-slider-invert-mouse-coords]': '_shouldInvertMouseCoords()',
  738. '[class.mat-slider-sliding]': '_isSliding',
  739. '[class.mat-slider-thumb-label-showing]': 'thumbLabel',
  740. '[class.mat-slider-vertical]': 'vertical',
  741. '[class.mat-slider-min-value]': '_isMinValue()',
  742. '[class.mat-slider-hide-last-tick]': 'disabled || _isMinValue() && _getThumbGap() && _shouldInvertAxis()',
  743. '[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
  744. }, inputs: ['disabled', 'color', 'tabIndex'], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"mat-slider-wrapper\" #sliderWrapper>\n <div class=\"mat-slider-track-wrapper\">\n <div class=\"mat-slider-track-background\" [ngStyle]=\"_getTrackBackgroundStyles()\"></div>\n <div class=\"mat-slider-track-fill\" [ngStyle]=\"_getTrackFillStyles()\"></div>\n </div>\n <div class=\"mat-slider-ticks-container\" [ngStyle]=\"_getTicksContainerStyles()\">\n <div class=\"mat-slider-ticks\" [ngStyle]=\"_getTicksStyles()\"></div>\n </div>\n <div class=\"mat-slider-thumb-container\" [ngStyle]=\"_getThumbContainerStyles()\">\n <div class=\"mat-slider-focus-ring\"></div>\n <div class=\"mat-slider-thumb\"></div>\n <div class=\"mat-slider-thumb-label\">\n <span class=\"mat-slider-thumb-label-text\">{{displayValue}}</span>\n </div>\n </div>\n</div>\n", styles: [".mat-slider{display:inline-block;position:relative;box-sizing:border-box;padding:8px;outline:none;vertical-align:middle}.mat-slider:not(.mat-slider-disabled):active,.mat-slider.mat-slider-sliding:not(.mat-slider-disabled){cursor:grabbing}.mat-slider-wrapper{-webkit-print-color-adjust:exact;color-adjust:exact;position:absolute}.mat-slider-track-wrapper{position:absolute;top:0;left:0;overflow:hidden}.mat-slider-track-fill{position:absolute;transform-origin:0 0;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-track-background{position:absolute;transform-origin:100% 100%;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-ticks-container{position:absolute;left:0;top:0;overflow:hidden}.mat-slider-ticks{-webkit-background-clip:content-box;background-clip:content-box;background-repeat:repeat;box-sizing:border-box;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-thumb-container{position:absolute;z-index:1;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-focus-ring{position:absolute;width:30px;height:30px;border-radius:50%;transform:scale(0);opacity:0;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1),opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider.cdk-keyboard-focused .mat-slider-focus-ring,.mat-slider.cdk-program-focused .mat-slider-focus-ring{transform:scale(1);opacity:1}.mat-slider:not(.mat-slider-disabled):not(.mat-slider-sliding) .mat-slider-thumb-label,.mat-slider:not(.mat-slider-disabled):not(.mat-slider-sliding) .mat-slider-thumb{cursor:grab}.mat-slider-thumb{position:absolute;right:-10px;bottom:-10px;box-sizing:border-box;width:20px;height:20px;border:3px solid rgba(0,0,0,0);border-radius:50%;transform:scale(0.7);transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1),border-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-thumb-label{display:none;align-items:center;justify-content:center;position:absolute;width:28px;height:28px;border-radius:50%;transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1),border-radius 400ms cubic-bezier(0.25, 0.8, 0.25, 1),background-color 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.cdk-high-contrast-active .mat-slider-thumb-label{outline:solid 1px}.mat-slider-thumb-label-text{z-index:1;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-sliding .mat-slider-track-fill,.mat-slider-sliding .mat-slider-track-background,.mat-slider-sliding .mat-slider-thumb-container{transition-duration:0ms}.mat-slider-has-ticks .mat-slider-wrapper::after{content:\"\";position:absolute;border-width:0;border-style:solid;opacity:0;transition:opacity 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}.mat-slider-has-ticks.cdk-focused:not(.mat-slider-hide-last-tick) .mat-slider-wrapper::after,.mat-slider-has-ticks:hover:not(.mat-slider-hide-last-tick) .mat-slider-wrapper::after{opacity:1}.mat-slider-has-ticks.cdk-focused:not(.mat-slider-disabled) .mat-slider-ticks,.mat-slider-has-ticks:hover:not(.mat-slider-disabled) .mat-slider-ticks{opacity:1}.mat-slider-thumb-label-showing .mat-slider-focus-ring{display:none}.mat-slider-thumb-label-showing .mat-slider-thumb-label{display:flex}.mat-slider-axis-inverted .mat-slider-track-fill{transform-origin:100% 100%}.mat-slider-axis-inverted .mat-slider-track-background{transform-origin:0 0}.mat-slider:not(.mat-slider-disabled).cdk-focused.mat-slider-thumb-label-showing .mat-slider-thumb{transform:scale(0)}.mat-slider:not(.mat-slider-disabled).cdk-focused .mat-slider-thumb-label{border-radius:50% 50% 0}.mat-slider:not(.mat-slider-disabled).cdk-focused .mat-slider-thumb-label-text{opacity:1}.mat-slider:not(.mat-slider-disabled).cdk-mouse-focused .mat-slider-thumb,.mat-slider:not(.mat-slider-disabled).cdk-touch-focused .mat-slider-thumb,.mat-slider:not(.mat-slider-disabled).cdk-program-focused .mat-slider-thumb{border-width:2px;transform:scale(1)}.mat-slider-disabled .mat-slider-focus-ring{transform:scale(0);opacity:0}.mat-slider-disabled .mat-slider-thumb{border-width:4px;transform:scale(0.5)}.mat-slider-disabled .mat-slider-thumb-label{display:none}.mat-slider-horizontal{height:48px;min-width:128px}.mat-slider-horizontal .mat-slider-wrapper{height:2px;top:23px;left:8px;right:8px}.mat-slider-horizontal .mat-slider-wrapper::after{height:2px;border-left-width:2px;right:0;top:0}.mat-slider-horizontal .mat-slider-track-wrapper{height:2px;width:100%}.mat-slider-horizontal .mat-slider-track-fill{height:2px;width:100%;transform:scaleX(0)}.mat-slider-horizontal .mat-slider-track-background{height:2px;width:100%;transform:scaleX(1)}.mat-slider-horizontal .mat-slider-ticks-container{height:2px;width:100%}.cdk-high-contrast-active .mat-slider-horizontal .mat-slider-ticks-container{height:0;outline:solid 2px;top:1px}.mat-slider-horizontal .mat-slider-ticks{height:2px;width:100%}.mat-slider-horizontal .mat-slider-thumb-container{width:100%;height:0;top:50%}.mat-slider-horizontal .mat-slider-focus-ring{top:-15px;right:-15px}.mat-slider-horizontal .mat-slider-thumb-label{right:-14px;top:-40px;transform:translateY(26px) scale(0.01) rotate(45deg)}.mat-slider-horizontal .mat-slider-thumb-label-text{transform:rotate(-45deg)}.mat-slider-horizontal.cdk-focused .mat-slider-thumb-label{transform:rotate(45deg)}.cdk-high-contrast-active .mat-slider-horizontal.cdk-focused .mat-slider-thumb-label,.cdk-high-contrast-active .mat-slider-horizontal.cdk-focused .mat-slider-thumb-label-text{transform:none}.mat-slider-vertical{width:48px;min-height:128px}.mat-slider-vertical .mat-slider-wrapper{width:2px;top:8px;bottom:8px;left:23px}.mat-slider-vertical .mat-slider-wrapper::after{width:2px;border-top-width:2px;bottom:0;left:0}.mat-slider-vertical .mat-slider-track-wrapper{height:100%;width:2px}.mat-slider-vertical .mat-slider-track-fill{height:100%;width:2px;transform:scaleY(0)}.mat-slider-vertical .mat-slider-track-background{height:100%;width:2px;transform:scaleY(1)}.mat-slider-vertical .mat-slider-ticks-container{width:2px;height:100%}.cdk-high-contrast-active .mat-slider-vertical .mat-slider-ticks-container{width:0;outline:solid 2px;left:1px}.mat-slider-vertical .mat-slider-focus-ring{bottom:-15px;left:-15px}.mat-slider-vertical .mat-slider-ticks{width:2px;height:100%}.mat-slider-vertical .mat-slider-thumb-container{height:100%;width:0;left:50%}.mat-slider-vertical .mat-slider-thumb{-webkit-backface-visibility:hidden;backface-visibility:hidden}.mat-slider-vertical .mat-slider-thumb-label{bottom:-14px;left:-40px;transform:translateX(26px) scale(0.01) rotate(-45deg)}.mat-slider-vertical .mat-slider-thumb-label-text{transform:rotate(45deg)}.mat-slider-vertical.cdk-focused .mat-slider-thumb-label{transform:rotate(-45deg)}[dir=rtl] .mat-slider-wrapper::after{left:0;right:auto}[dir=rtl] .mat-slider-horizontal .mat-slider-track-fill{transform-origin:100% 100%}[dir=rtl] .mat-slider-horizontal .mat-slider-track-background{transform-origin:0 0}[dir=rtl] .mat-slider-horizontal.mat-slider-axis-inverted .mat-slider-track-fill{transform-origin:0 0}[dir=rtl] .mat-slider-horizontal.mat-slider-axis-inverted .mat-slider-track-background{transform-origin:100% 100%}.mat-slider._mat-animation-noopable .mat-slider-track-fill,.mat-slider._mat-animation-noopable .mat-slider-track-background,.mat-slider._mat-animation-noopable .mat-slider-ticks,.mat-slider._mat-animation-noopable .mat-slider-thumb-container,.mat-slider._mat-animation-noopable .mat-slider-focus-ring,.mat-slider._mat-animation-noopable .mat-slider-thumb,.mat-slider._mat-animation-noopable .mat-slider-thumb-label,.mat-slider._mat-animation-noopable .mat-slider-thumb-label-text,.mat-slider._mat-animation-noopable .mat-slider-has-ticks .mat-slider-wrapper::after{transition:none}"] }]
  745. }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.FocusMonitor }, { type: i0.ChangeDetectorRef }, { type: i2.Directionality, decorators: [{
  746. type: Optional
  747. }] }, { type: undefined, decorators: [{
  748. type: Attribute,
  749. args: ['tabindex']
  750. }] }, { type: i0.NgZone }, { type: undefined, decorators: [{
  751. type: Inject,
  752. args: [DOCUMENT]
  753. }] }, { type: undefined, decorators: [{
  754. type: Optional
  755. }, {
  756. type: Inject,
  757. args: [ANIMATION_MODULE_TYPE]
  758. }] }]; }, propDecorators: { invert: [{
  759. type: Input
  760. }], max: [{
  761. type: Input
  762. }], min: [{
  763. type: Input
  764. }], step: [{
  765. type: Input
  766. }], thumbLabel: [{
  767. type: Input
  768. }], tickInterval: [{
  769. type: Input
  770. }], value: [{
  771. type: Input
  772. }], displayWith: [{
  773. type: Input
  774. }], valueText: [{
  775. type: Input
  776. }], vertical: [{
  777. type: Input
  778. }], change: [{
  779. type: Output
  780. }], input: [{
  781. type: Output
  782. }], valueChange: [{
  783. type: Output
  784. }], _sliderWrapper: [{
  785. type: ViewChild,
  786. args: ['sliderWrapper']
  787. }] } });
  788. /** Checks if number is safe for calculation */
  789. function isSafeNumber(value) {
  790. return !isNaN(value) && isFinite(value);
  791. }
  792. /** Returns whether an event is a touch event. */
  793. function isTouchEvent(event) {
  794. // This function is called for every pixel that the user has dragged so we need it to be
  795. // as fast as possible. Since we only bind mouse events and touch events, we can assume
  796. // that if the event's name starts with `t`, it's a touch event.
  797. return event.type[0] === 't';
  798. }
  799. /** Gets the coordinates of a touch or mouse event relative to the viewport. */
  800. function getPointerPositionOnPage(event, id) {
  801. let point;
  802. if (isTouchEvent(event)) {
  803. // The `identifier` could be undefined if the browser doesn't support `TouchEvent.identifier`.
  804. // If that's the case, attribute the first touch to all active sliders. This should still cover
  805. // the most common case while only breaking multi-touch.
  806. if (typeof id === 'number') {
  807. point = findMatchingTouch(event.touches, id) || findMatchingTouch(event.changedTouches, id);
  808. }
  809. else {
  810. // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
  811. point = event.touches[0] || event.changedTouches[0];
  812. }
  813. }
  814. else {
  815. point = event;
  816. }
  817. return point ? { x: point.clientX, y: point.clientY } : undefined;
  818. }
  819. /** Finds a `Touch` with a specific ID in a `TouchList`. */
  820. function findMatchingTouch(touches, id) {
  821. for (let i = 0; i < touches.length; i++) {
  822. if (touches[i].identifier === id) {
  823. return touches[i];
  824. }
  825. }
  826. return undefined;
  827. }
  828. /** Gets the unique ID of a touch that matches a specific slider. */
  829. function getTouchIdForSlider(event, sliderHost) {
  830. for (let i = 0; i < event.touches.length; i++) {
  831. const target = event.touches[i].target;
  832. if (sliderHost === target || sliderHost.contains(target)) {
  833. return event.touches[i].identifier;
  834. }
  835. }
  836. return undefined;
  837. }
  838. /**
  839. * @deprecated Use `MatSliderModule` from `@angular/material/slider` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  840. * @breaking-change 17.0.0
  841. */
  842. class MatLegacySliderModule {
  843. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySliderModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
  844. static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySliderModule, declarations: [MatLegacySlider], imports: [CommonModule, MatCommonModule], exports: [MatLegacySlider, MatCommonModule] }); }
  845. static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySliderModule, imports: [CommonModule, MatCommonModule, MatCommonModule] }); }
  846. }
  847. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySliderModule, decorators: [{
  848. type: NgModule,
  849. args: [{
  850. imports: [CommonModule, MatCommonModule],
  851. exports: [MatLegacySlider, MatCommonModule],
  852. declarations: [MatLegacySlider],
  853. }]
  854. }] });
  855. /**
  856. * Generated bundle index. Do not edit.
  857. */
  858. export { MAT_LEGACY_SLIDER_VALUE_ACCESSOR, MatLegacySlider, MatLegacySliderChange, MatLegacySliderModule };
  859. //# sourceMappingURL=legacy-slider.mjs.map