@sailfish-ai/addon-fit 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2019, The xterm.js authors (https://github.com/xtermjs/xterm.js)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ ## @sailfish-ai/addon-fit
2
+
3
+ An addon for [xterm.js](https://github.com/xtermjs/xterm.js) that enables fitting the terminal's dimensions to a containing element. This addon requires xterm.js v4+.
4
+
5
+ ### Install
6
+
7
+ ```bash
8
+ npm install --save @sailfish-ai/addon-fit
9
+ ```
10
+
11
+ ### Usage
12
+
13
+ ```ts
14
+ import { Terminal } from '@sailfish-ai/xterm';
15
+ import { FitAddon } from '@sailfish-ai/addon-fit';
16
+
17
+ const terminal = new Terminal();
18
+ const fitAddon = new FitAddon();
19
+ terminal.loadAddon(fitAddon);
20
+ terminal.open(containerElement);
21
+ fitAddon.fit();
22
+ ```
23
+
24
+ See the full [API](https://github.com/xtermjs/xterm.js/blob/master/addons/addon-fit/typings/addon-fit.d.ts) for more advanced usage.
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FitAddon=t():e.FitAddon=t()}(globalThis,()=>(()=>{"use strict";var e={};return(()=>{var t=e;function i(e){return(t=e,t?.ownerDocument?.defaultView?t.ownerDocument.defaultView:window).getComputedStyle(e,null);var t}Object.defineProperty(t,"__esModule",{value:!0}),t.FitAddon=void 0,t.FitAddon=class{activate(e){this._terminal=e}dispose(){}fit(){const e=this.proposeDimensions();e&&this._terminal&&!isNaN(e.cols)&&!isNaN(e.rows)&&(this._terminal.rows===e.rows&&this._terminal.cols===e.cols||this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal)return;if(!this._terminal.element||!this._terminal.element.parentElement)return;const e=this._terminal.dimensions;if(!e||0===e.css.cell.width||0===e.css.cell.height)return;const t=0===this._terminal.options.scrollback?0:this._terminal.options.overviewRuler?.width||14,r=i(this._terminal.element.parentElement),o=parseInt(r.getPropertyValue("height")),n=Math.max(0,parseInt(r.getPropertyValue("width"))),s=i(this._terminal.element),l=o-(parseInt(s.getPropertyValue("padding-top"))+parseInt(s.getPropertyValue("padding-bottom"))),a=n-(parseInt(s.getPropertyValue("padding-right"))+parseInt(s.getPropertyValue("padding-left")))-t;return{cols:Math.max(2,Math.floor(a/e.css.cell.width)),rows:Math.max(1,Math.floor(l/e.css.cell.height))}}}})(),e})());
2
+ //# sourceMappingURL=addon-fit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addon-fit.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAkB,SAAID,IAEtBD,EAAe,SAAIC,GACpB,CATD,CASGK,WAAY,I,gDCsBf,SAASC,EAAkBC,GACzB,OARiBC,EAQAD,EAPbC,GAAGC,eAAeC,YACbF,EAAEC,cAAcC,YAGlBC,QAGcC,iBAAiBL,EAAI,MAR5C,IAAmBC,CASnB,C,mEAEA,iBAGS,QAAAK,CAASC,GACdC,KAAKC,UAAYF,CACnB,CAEO,OAAAG,GAAiB,CAEjB,GAAAC,GACL,MAAMC,EAAOJ,KAAKK,oBACbD,GAASJ,KAAKC,YAAaK,MAAMF,EAAKG,QAASD,MAAMF,EAAKI,QAK3DR,KAAKC,UAAUO,OAASJ,EAAKI,MAAQR,KAAKC,UAAUM,OAASH,EAAKG,MACpEP,KAAKC,UAAUQ,OAAOL,EAAKG,KAAMH,EAAKI,MAE1C,CAEO,iBAAAH,GACL,IAAKL,KAAKC,UACR,OAGF,IAAKD,KAAKC,UAAUS,UAAYV,KAAKC,UAAUS,QAAQC,cACrD,OAGF,MAAMP,EAAsCJ,KAAKC,UAAUW,WAE3D,IAAKR,GAAgC,IAAxBA,EAAKS,IAAIC,KAAKC,OAAwC,IAAzBX,EAAKS,IAAIC,KAAKE,OACtD,OAGF,MAAMC,EAAwD,IAAtCjB,KAAKC,UAAUiB,QAAQC,WAC3C,EACCnB,KAAKC,UAAUiB,QAAQE,eAAeL,OAAS,GAE9CM,EAAqB9B,EAAkBS,KAAKC,UAAUS,QAAQC,eAC9DW,EAAsBC,SAASF,EAAmBG,iBAAiB,WACnEC,EAAqBC,KAAKC,IAAI,EAAGJ,SAASF,EAAmBG,iBAAiB,WAC9EI,EAAerC,EAAkBS,KAAKC,UAAUS,SAShDmB,EAAkBP,GAPjBC,SAASK,EAAaJ,iBAAiB,gBACpCD,SAASK,EAAaJ,iBAAiB,oBAO3CM,EAAiBL,GANdF,SAASK,EAAaJ,iBAAiB,kBACxCD,SAASK,EAAaJ,iBAAiB,kBAKiBP,EAKhE,MAJiB,CACfV,KAAMmB,KAAKC,IArEI,EAqEcD,KAAKK,MAAMD,EAAiB1B,EAAKS,IAAIC,KAAKC,QACvEP,KAAMkB,KAAKC,IArEI,EAqEcD,KAAKK,MAAMF,EAAkBzB,EAAKS,IAAIC,KAAKE,SAG5E,E","sources":["webpack://FitAddon/webpack/universalModuleDefinition","webpack://FitAddon/./src/FitAddon.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"FitAddon\"] = factory();\n\telse\n\t\troot[\"FitAddon\"] = factory();\n})(globalThis, () => {\nreturn ","/**\n * Copyright (c) 2017 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { Terminal, ITerminalAddon, IRenderDimensions } from '@sailfish-ai/xterm';\nimport type { FitAddon as IFitApi } from '@sailfish-ai/addon-fit';\nimport { ViewportConstants } from 'browser/shared/Constants';\n\ninterface ITerminalDimensions {\n /**\n * The number of rows in the terminal.\n */\n rows: number;\n\n /**\n * The number of columns in the terminal.\n */\n cols: number;\n}\n\nconst MINIMUM_COLS = 2;\nconst MINIMUM_ROWS = 1;\n\nfunction getWindow(e: Node): Window {\n if (e?.ownerDocument?.defaultView) {\n return e.ownerDocument.defaultView;\n }\n\n return window;\n}\nfunction _getComputedStyle(el: HTMLElement): CSSStyleDeclaration {\n return getWindow(el).getComputedStyle(el, null);\n}\n\nexport class FitAddon implements ITerminalAddon , IFitApi {\n private _terminal: Terminal | undefined;\n\n public activate(terminal: Terminal): void {\n this._terminal = terminal;\n }\n\n public dispose(): void {}\n\n public fit(): void {\n const dims = this.proposeDimensions();\n if (!dims || !this._terminal || isNaN(dims.cols) || isNaN(dims.rows)) {\n return;\n }\n\n // Force a full render\n if (this._terminal.rows !== dims.rows || this._terminal.cols !== dims.cols) {\n this._terminal.resize(dims.cols, dims.rows);\n }\n }\n\n public proposeDimensions(): ITerminalDimensions | undefined {\n if (!this._terminal) {\n return undefined;\n }\n\n if (!this._terminal.element || !this._terminal.element.parentElement) {\n return undefined;\n }\n\n const dims: IRenderDimensions | undefined = this._terminal.dimensions;\n\n if (!dims || dims.css.cell.width === 0 || dims.css.cell.height === 0) {\n return undefined;\n }\n\n const scrollbarWidth = (this._terminal.options.scrollback === 0\n ? 0\n : (this._terminal.options.overviewRuler?.width || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH));\n\n const parentElementStyle = _getComputedStyle(this._terminal.element.parentElement);\n const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));\n const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));\n const elementStyle = _getComputedStyle(this._terminal.element);\n const elementPadding = {\n top: parseInt(elementStyle.getPropertyValue('padding-top')),\n bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')),\n right: parseInt(elementStyle.getPropertyValue('padding-right')),\n left: parseInt(elementStyle.getPropertyValue('padding-left'))\n };\n const elementPaddingVer = elementPadding.top + elementPadding.bottom;\n const elementPaddingHor = elementPadding.right + elementPadding.left;\n const availableHeight = parentElementHeight - elementPaddingVer;\n const availableWidth = parentElementWidth - elementPaddingHor - scrollbarWidth;\n const geometry = {\n cols: Math.max(MINIMUM_COLS, Math.floor(availableWidth / dims.css.cell.width)),\n rows: Math.max(MINIMUM_ROWS, Math.floor(availableHeight / dims.css.cell.height))\n };\n return geometry;\n }\n}\n"],"names":["root","factory","exports","module","define","amd","globalThis","_getComputedStyle","el","e","ownerDocument","defaultView","window","getComputedStyle","activate","terminal","this","_terminal","dispose","fit","dims","proposeDimensions","isNaN","cols","rows","resize","element","parentElement","dimensions","css","cell","width","height","scrollbarWidth","options","scrollback","overviewRuler","parentElementStyle","parentElementHeight","parseInt","getPropertyValue","parentElementWidth","Math","max","elementStyle","availableHeight","availableWidth","floor"],"sourceRoot":""}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ *
5
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
6
+ * @license MIT
7
+ *
8
+ * Originally forked from (with the author's permission):
9
+ * Fabrice Bellard's javascript vt100 for jslinux:
10
+ * http://bellard.org/jslinux/
11
+ * Copyright (c) 2011 Fabrice Bellard
12
+ */
13
+ /*---------------------------------------------------------------------------------------------
14
+ * Copyright (c) Microsoft Corporation. All rights reserved.
15
+ * Licensed under the MIT License. See License.txt in the project root for license information.
16
+ *--------------------------------------------------------------------------------------------*/
17
+ var u=2,f=1;function g(t){return t?.ownerDocument?.defaultView?t.ownerDocument.defaultView:window}function o(t){return g(t).getComputedStyle(t,null)}var s=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows)||(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&this._terminal.resize(e.cols,e.rows)}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal.dimensions;if(!e||e.css.cell.width===0||e.css.cell.height===0)return;let l=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,r=o(this._terminal.element.parentElement),a=parseInt(r.getPropertyValue("height")),m=Math.max(0,parseInt(r.getPropertyValue("width"))),i=o(this._terminal.element),n={top:parseInt(i.getPropertyValue("padding-top")),bottom:parseInt(i.getPropertyValue("padding-bottom")),right:parseInt(i.getPropertyValue("padding-right")),left:parseInt(i.getPropertyValue("padding-left"))},d=n.top+n.bottom,p=n.right+n.left,c=a-d,h=m-p-l;return{cols:Math.max(u,Math.floor(h/e.css.cell.width)),rows:Math.max(f,Math.floor(c/e.css.cell.height))}}};export{s as FitAddon};
18
+ //# sourceMappingURL=addon-fit.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/FitAddon.ts"],
4
+ "sourcesContent": ["/**\n * Copyright (c) 2017 The xterm.js authors. All rights reserved.\n * @license MIT\n */\n\nimport type { Terminal, ITerminalAddon, IRenderDimensions } from '@sailfish-ai/xterm';\nimport type { FitAddon as IFitApi } from '@sailfish-ai/addon-fit';\nimport { ViewportConstants } from 'browser/shared/Constants';\n\ninterface ITerminalDimensions {\n /**\n * The number of rows in the terminal.\n */\n rows: number;\n\n /**\n * The number of columns in the terminal.\n */\n cols: number;\n}\n\nconst MINIMUM_COLS = 2;\nconst MINIMUM_ROWS = 1;\n\nfunction getWindow(e: Node): Window {\n if (e?.ownerDocument?.defaultView) {\n return e.ownerDocument.defaultView;\n }\n\n return window;\n}\nfunction _getComputedStyle(el: HTMLElement): CSSStyleDeclaration {\n return getWindow(el).getComputedStyle(el, null);\n}\n\nexport class FitAddon implements ITerminalAddon , IFitApi {\n private _terminal: Terminal | undefined;\n\n public activate(terminal: Terminal): void {\n this._terminal = terminal;\n }\n\n public dispose(): void {}\n\n public fit(): void {\n const dims = this.proposeDimensions();\n if (!dims || !this._terminal || isNaN(dims.cols) || isNaN(dims.rows)) {\n return;\n }\n\n // Force a full render\n if (this._terminal.rows !== dims.rows || this._terminal.cols !== dims.cols) {\n this._terminal.resize(dims.cols, dims.rows);\n }\n }\n\n public proposeDimensions(): ITerminalDimensions | undefined {\n if (!this._terminal) {\n return undefined;\n }\n\n if (!this._terminal.element || !this._terminal.element.parentElement) {\n return undefined;\n }\n\n const dims: IRenderDimensions | undefined = this._terminal.dimensions;\n\n if (!dims || dims.css.cell.width === 0 || dims.css.cell.height === 0) {\n return undefined;\n }\n\n const scrollbarWidth = (this._terminal.options.scrollback === 0\n ? 0\n : (this._terminal.options.overviewRuler?.width || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH));\n\n const parentElementStyle = _getComputedStyle(this._terminal.element.parentElement);\n const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));\n const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));\n const elementStyle = _getComputedStyle(this._terminal.element);\n const elementPadding = {\n top: parseInt(elementStyle.getPropertyValue('padding-top')),\n bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')),\n right: parseInt(elementStyle.getPropertyValue('padding-right')),\n left: parseInt(elementStyle.getPropertyValue('padding-left'))\n };\n const elementPaddingVer = elementPadding.top + elementPadding.bottom;\n const elementPaddingHor = elementPadding.right + elementPadding.left;\n const availableHeight = parentElementHeight - elementPaddingVer;\n const availableWidth = parentElementWidth - elementPaddingHor - scrollbarWidth;\n const geometry = {\n cols: Math.max(MINIMUM_COLS, Math.floor(availableWidth / dims.css.cell.width)),\n rows: Math.max(MINIMUM_ROWS, Math.floor(availableHeight / dims.css.cell.height))\n };\n return geometry;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;AAqBA,IAAMA,EAAe,EACfC,EAAe,EAErB,SAASC,EAAUC,EAAiB,CAClC,OAAIA,GAAG,eAAe,YACbA,EAAE,cAAc,YAGlB,MACT,CACA,SAASC,EAAkBC,EAAsC,CAC/D,OAAOH,EAAUG,CAAE,EAAE,iBAAiBA,EAAI,IAAI,CAChD,CAEO,IAAMC,EAAN,KAAmD,CAGjD,SAASC,EAA0B,CACxC,KAAK,UAAYA,CACnB,CAEO,SAAgB,CAAC,CAEjB,KAAY,CACjB,IAAMC,EAAO,KAAK,kBAAkB,EAChC,CAACA,GAAQ,CAAC,KAAK,WAAa,MAAMA,EAAK,IAAI,GAAK,MAAMA,EAAK,IAAI,IAK/D,KAAK,UAAU,OAASA,EAAK,MAAQ,KAAK,UAAU,OAASA,EAAK,OACpE,KAAK,UAAU,OAAOA,EAAK,KAAMA,EAAK,IAAI,CAE9C,CAEO,mBAAqD,CAK1D,GAJI,CAAC,KAAK,WAIN,CAAC,KAAK,UAAU,SAAW,CAAC,KAAK,UAAU,QAAQ,cACrD,OAGF,IAAMA,EAAsC,KAAK,UAAU,WAE3D,GAAI,CAACA,GAAQA,EAAK,IAAI,KAAK,QAAU,GAAKA,EAAK,IAAI,KAAK,SAAW,EACjE,OAGF,IAAMC,EAAkB,KAAK,UAAU,QAAQ,aAAe,EAC1D,EACC,KAAK,UAAU,QAAQ,eAAe,OAAS,GAE9CC,EAAqBN,EAAkB,KAAK,UAAU,QAAQ,aAAa,EAC3EO,EAAsB,SAASD,EAAmB,iBAAiB,QAAQ,CAAC,EAC5EE,EAAqB,KAAK,IAAI,EAAG,SAASF,EAAmB,iBAAiB,OAAO,CAAC,CAAC,EACvFG,EAAeT,EAAkB,KAAK,UAAU,OAAO,EACvDU,EAAiB,CACrB,IAAK,SAASD,EAAa,iBAAiB,aAAa,CAAC,EAC1D,OAAQ,SAASA,EAAa,iBAAiB,gBAAgB,CAAC,EAChE,MAAO,SAASA,EAAa,iBAAiB,eAAe,CAAC,EAC9D,KAAM,SAASA,EAAa,iBAAiB,cAAc,CAAC,CAC9D,EACME,EAAoBD,EAAe,IAAMA,EAAe,OACxDE,EAAoBF,EAAe,MAAQA,EAAe,KAC1DG,EAAkBN,EAAsBI,EACxCG,EAAiBN,EAAqBI,EAAoBP,EAKhE,MAJiB,CACf,KAAM,KAAK,IAAIT,EAAc,KAAK,MAAMkB,EAAiBV,EAAK,IAAI,KAAK,KAAK,CAAC,EAC7E,KAAM,KAAK,IAAIP,EAAc,KAAK,MAAMgB,EAAkBT,EAAK,IAAI,KAAK,MAAM,CAAC,CACjF,CAEF,CACF",
6
+ "names": ["MINIMUM_COLS", "MINIMUM_ROWS", "getWindow", "e", "_getComputedStyle", "el", "FitAddon", "terminal", "dims", "scrollbarWidth", "parentElementStyle", "parentElementHeight", "parentElementWidth", "elementStyle", "elementPadding", "elementPaddingVer", "elementPaddingHor", "availableHeight", "availableWidth"]
7
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@sailfish-ai/addon-fit",
3
+ "version": "0.11.0",
4
+ "author": {
5
+ "name": "The xterm.js authors",
6
+ "url": "https://xtermjs.org/"
7
+ },
8
+ "main": "lib/addon-fit.js",
9
+ "module": "lib/addon-fit.mjs",
10
+ "types": "typings/addon-fit.d.ts",
11
+ "repository": "https://github.com/xtermjs/xterm.js/tree/master/addons/addon-fit",
12
+ "license": "MIT",
13
+ "keywords": [
14
+ "terminal",
15
+ "xterm",
16
+ "xterm.js"
17
+ ],
18
+ "scripts": {
19
+ "build": "../../node_modules/.bin/tsc -p .",
20
+ "prepackage": "npm run build",
21
+ "package": "../../node_modules/.bin/webpack",
22
+ "prepublishOnly": "npm run package",
23
+ "start": "node ../../demo/start"
24
+ },
25
+ "commit": "92b8a5db459ea3c341c9c2a5c09ffbd1fe062caa",
26
+ "peerDependencies": {
27
+ "@sailfish-ai/xterm": "^6.1.0-beta.1"
28
+ }
29
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import type { Terminal, ITerminalAddon, IRenderDimensions } from '@sailfish-ai/xterm';
7
+ import type { FitAddon as IFitApi } from '@sailfish-ai/addon-fit';
8
+ import { ViewportConstants } from 'browser/shared/Constants';
9
+
10
+ interface ITerminalDimensions {
11
+ /**
12
+ * The number of rows in the terminal.
13
+ */
14
+ rows: number;
15
+
16
+ /**
17
+ * The number of columns in the terminal.
18
+ */
19
+ cols: number;
20
+ }
21
+
22
+ const MINIMUM_COLS = 2;
23
+ const MINIMUM_ROWS = 1;
24
+
25
+ function getWindow(e: Node): Window {
26
+ if (e?.ownerDocument?.defaultView) {
27
+ return e.ownerDocument.defaultView;
28
+ }
29
+
30
+ return window;
31
+ }
32
+ function _getComputedStyle(el: HTMLElement): CSSStyleDeclaration {
33
+ return getWindow(el).getComputedStyle(el, null);
34
+ }
35
+
36
+ export class FitAddon implements ITerminalAddon , IFitApi {
37
+ private _terminal: Terminal | undefined;
38
+
39
+ public activate(terminal: Terminal): void {
40
+ this._terminal = terminal;
41
+ }
42
+
43
+ public dispose(): void {}
44
+
45
+ public fit(): void {
46
+ const dims = this.proposeDimensions();
47
+ if (!dims || !this._terminal || isNaN(dims.cols) || isNaN(dims.rows)) {
48
+ return;
49
+ }
50
+
51
+ // Force a full render
52
+ if (this._terminal.rows !== dims.rows || this._terminal.cols !== dims.cols) {
53
+ this._terminal.resize(dims.cols, dims.rows);
54
+ }
55
+ }
56
+
57
+ public proposeDimensions(): ITerminalDimensions | undefined {
58
+ if (!this._terminal) {
59
+ return undefined;
60
+ }
61
+
62
+ if (!this._terminal.element || !this._terminal.element.parentElement) {
63
+ return undefined;
64
+ }
65
+
66
+ const dims: IRenderDimensions | undefined = this._terminal.dimensions;
67
+
68
+ if (!dims || dims.css.cell.width === 0 || dims.css.cell.height === 0) {
69
+ return undefined;
70
+ }
71
+
72
+ const scrollbarWidth = (this._terminal.options.scrollback === 0
73
+ ? 0
74
+ : (this._terminal.options.overviewRuler?.width || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH));
75
+
76
+ const parentElementStyle = _getComputedStyle(this._terminal.element.parentElement);
77
+ const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));
78
+ const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));
79
+ const elementStyle = _getComputedStyle(this._terminal.element);
80
+ const elementPadding = {
81
+ top: parseInt(elementStyle.getPropertyValue('padding-top')),
82
+ bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')),
83
+ right: parseInt(elementStyle.getPropertyValue('padding-right')),
84
+ left: parseInt(elementStyle.getPropertyValue('padding-left'))
85
+ };
86
+ const elementPaddingVer = elementPadding.top + elementPadding.bottom;
87
+ const elementPaddingHor = elementPadding.right + elementPadding.left;
88
+ const availableHeight = parentElementHeight - elementPaddingVer;
89
+ const availableWidth = parentElementWidth - elementPaddingHor - scrollbarWidth;
90
+ const geometry = {
91
+ cols: Math.max(MINIMUM_COLS, Math.floor(availableWidth / dims.css.cell.width)),
92
+ rows: Math.max(MINIMUM_ROWS, Math.floor(availableHeight / dims.css.cell.height))
93
+ };
94
+ return geometry;
95
+ }
96
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3
+ * @license MIT
4
+ */
5
+
6
+ import { Terminal, ITerminalAddon } from '@sailfish-ai/xterm';
7
+
8
+ declare module '@sailfish-ai/addon-fit' {
9
+ /**
10
+ * An xterm.js addon that enables resizing the terminal to the dimensions of
11
+ * its containing element.
12
+ */
13
+ export class FitAddon implements ITerminalAddon {
14
+ /**
15
+ * Creates a new fit addon.
16
+ */
17
+ constructor();
18
+
19
+ /**
20
+ * Activates the addon
21
+ * @param terminal The terminal the addon is being loaded in.
22
+ */
23
+ public activate(terminal: Terminal): void;
24
+
25
+ /**
26
+ * Disposes the addon.
27
+ */
28
+ public dispose(): void;
29
+
30
+ /**
31
+ * Resizes the terminal to the dimensions of its containing element.
32
+ */
33
+ public fit(): void;
34
+
35
+ /**
36
+ * Gets the proposed dimensions that will be used for a fit.
37
+ */
38
+ public proposeDimensions(): ITerminalDimensions | undefined;
39
+ }
40
+
41
+ /**
42
+ * Represents the dimensions of a terminal.
43
+ */
44
+ export interface ITerminalDimensions {
45
+ /**
46
+ * The number of rows in the terminal.
47
+ */
48
+ rows: number;
49
+
50
+ /**
51
+ * The number of columns in the terminal.
52
+ */
53
+ cols: number;
54
+ }
55
+ }