rtl-default-scroller.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license
  3. * Copyright 2018 Google Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. import { __extends } from "tslib";
  24. import { MDCTabScrollerRTL } from './rtl-scroller';
  25. /** MDC Tab Scroller RTL Default */
  26. var MDCTabScrollerRTLDefault = /** @class */ (function (_super) {
  27. __extends(MDCTabScrollerRTLDefault, _super);
  28. function MDCTabScrollerRTLDefault() {
  29. return _super !== null && _super.apply(this, arguments) || this;
  30. }
  31. MDCTabScrollerRTLDefault.prototype.getScrollPositionRTL = function () {
  32. var currentScrollLeft = this.adapter.getScrollAreaScrollLeft();
  33. var right = this.calculateScrollEdges().right;
  34. // Scroll values on most browsers are ints instead of floats so we round
  35. return Math.round(right - currentScrollLeft);
  36. };
  37. MDCTabScrollerRTLDefault.prototype.scrollToRTL = function (scrollX) {
  38. var edges = this.calculateScrollEdges();
  39. var currentScrollLeft = this.adapter.getScrollAreaScrollLeft();
  40. var clampedScrollLeft = this.clampScrollValue(edges.right - scrollX);
  41. return {
  42. finalScrollPosition: clampedScrollLeft,
  43. scrollDelta: clampedScrollLeft - currentScrollLeft,
  44. };
  45. };
  46. MDCTabScrollerRTLDefault.prototype.incrementScrollRTL = function (scrollX) {
  47. var currentScrollLeft = this.adapter.getScrollAreaScrollLeft();
  48. var clampedScrollLeft = this.clampScrollValue(currentScrollLeft - scrollX);
  49. return {
  50. finalScrollPosition: clampedScrollLeft,
  51. scrollDelta: clampedScrollLeft - currentScrollLeft,
  52. };
  53. };
  54. MDCTabScrollerRTLDefault.prototype.getAnimatingScrollPosition = function (scrollX) {
  55. return scrollX;
  56. };
  57. MDCTabScrollerRTLDefault.prototype.calculateScrollEdges = function () {
  58. var contentWidth = this.adapter.getScrollContentOffsetWidth();
  59. var rootWidth = this.adapter.getScrollAreaOffsetWidth();
  60. return {
  61. left: 0,
  62. right: contentWidth - rootWidth,
  63. };
  64. };
  65. MDCTabScrollerRTLDefault.prototype.clampScrollValue = function (scrollX) {
  66. var edges = this.calculateScrollEdges();
  67. return Math.min(Math.max(edges.left, scrollX), edges.right);
  68. };
  69. return MDCTabScrollerRTLDefault;
  70. }(MDCTabScrollerRTL));
  71. export { MDCTabScrollerRTLDefault };
  72. // tslint:disable-next-line:no-default-export Needed for backward compatibility with MDC Web v0.44.0 and earlier.
  73. export default MDCTabScrollerRTLDefault;
  74. //# sourceMappingURL=rtl-default-scroller.js.map