FitAddon.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.FitAddon = void 0;
  4. var MINIMUM_COLS = 2;
  5. var MINIMUM_ROWS = 1;
  6. var FitAddon = (function () {
  7. function FitAddon() {
  8. }
  9. FitAddon.prototype.activate = function (terminal) {
  10. this._terminal = terminal;
  11. };
  12. FitAddon.prototype.dispose = function () { };
  13. FitAddon.prototype.fit = function () {
  14. var dims = this.proposeDimensions();
  15. if (!dims || !this._terminal) {
  16. return;
  17. }
  18. var core = this._terminal._core;
  19. if (this._terminal.rows !== dims.rows || this._terminal.cols !== dims.cols) {
  20. core._renderService.clear();
  21. this._terminal.resize(dims.cols, dims.rows);
  22. }
  23. };
  24. FitAddon.prototype.proposeDimensions = function () {
  25. if (!this._terminal) {
  26. return undefined;
  27. }
  28. if (!this._terminal.element || !this._terminal.element.parentElement) {
  29. return undefined;
  30. }
  31. var core = this._terminal._core;
  32. if (core._renderService.dimensions.actualCellWidth === 0 || core._renderService.dimensions.actualCellHeight === 0) {
  33. return undefined;
  34. }
  35. var parentElementStyle = window.getComputedStyle(this._terminal.element.parentElement);
  36. var parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));
  37. var parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));
  38. var elementStyle = window.getComputedStyle(this._terminal.element);
  39. var elementPadding = {
  40. top: parseInt(elementStyle.getPropertyValue('padding-top')),
  41. bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')),
  42. right: parseInt(elementStyle.getPropertyValue('padding-right')),
  43. left: parseInt(elementStyle.getPropertyValue('padding-left'))
  44. };
  45. var elementPaddingVer = elementPadding.top + elementPadding.bottom;
  46. var elementPaddingHor = elementPadding.right + elementPadding.left;
  47. var availableHeight = parentElementHeight - elementPaddingVer;
  48. var availableWidth = parentElementWidth - elementPaddingHor - core.viewport.scrollBarWidth;
  49. var geometry = {
  50. cols: Math.max(MINIMUM_COLS, Math.floor(availableWidth / core._renderService.dimensions.actualCellWidth)),
  51. rows: Math.max(MINIMUM_ROWS, Math.floor(availableHeight / core._renderService.dimensions.actualCellHeight))
  52. };
  53. return geometry;
  54. };
  55. return FitAddon;
  56. }());
  57. exports.FitAddon = FitAddon;
  58. //# sourceMappingURL=FitAddon.js.map