@jsenv/terminal-recorder 1.4.6 → 1.4.7

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.
@@ -1,3 +1,5 @@
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();}(self,(()=>(()=>{var e={};return (()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.FitAddon=void 0,t.FitAddon=class{activate(e){this._terminal=e;}dispose(){}fit(){const e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;const t=this._terminal._core;this._terminal.rows===e.rows&&this._terminal.cols===e.cols||(t._renderService.clear(),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._core,t=e._renderService.dimensions;if(0===t.css.cell.width||0===t.css.cell.height)return;const r=0===this._terminal.options.scrollback?0:e.viewport.scrollBarWidth,i=window.getComputedStyle(this._terminal.element.parentElement),o=parseInt(i.getPropertyValue("height")),s=Math.max(0,parseInt(i.getPropertyValue("width"))),n=window.getComputedStyle(this._terminal.element),l=o-(parseInt(n.getPropertyValue("padding-top"))+parseInt(n.getPropertyValue("padding-bottom"))),a=s-(parseInt(n.getPropertyValue("padding-right"))+parseInt(n.getPropertyValue("padding-left")))-r;return {cols:Math.max(2,Math.floor(a/t.css.cell.width)),rows:Math.max(1,Math.floor(l/t.css.cell.height))}}};})(),e})()));
2
+
1
3
  !function (e, t) {
2
4
  "object" == typeof exports && "object" == typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define([], t) : "object" == typeof exports ? exports.SerializeAddon = t() : e.SerializeAddon = t();
3
5
  }(window, () => (() => {
@@ -1916,6 +1918,7 @@ https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts
1916
1918
 
1917
1919
 
1918
1920
  const { Terminal } = window;
1921
+ const { FitAddon } = window.FitAddon;
1919
1922
  const { WebglAddon } = window.WebglAddon;
1920
1923
  const { SerializeAddon } = window.SerializeAddon;
1921
1924
 
@@ -1972,47 +1975,35 @@ const initTerminal = ({
1972
1975
  brightBlue: "#87CEEB",
1973
1976
  },
1974
1977
  });
1975
- term.loadAddon(
1976
- new WebglAddon(
1977
- // we pass true to enable preserveDrawingBuffer
1978
- // it's not actually useful thanks to term.write callback +
1979
- // call on _innerRefresh() before context.drawImage
1980
- // but let's keep it nevertheless
1981
- true,
1982
- ),
1983
- );
1984
1978
  const serializeAddon = new SerializeAddon();
1985
1979
  term.loadAddon(serializeAddon);
1986
-
1987
- const terminalElement = document.getElementById("terminal");
1980
+ const fitAddon = new FitAddon();
1981
+ term.loadAddon(fitAddon);
1982
+ const webglAddon = new WebglAddon(
1983
+ // we pass true to enable preserveDrawingBuffer
1984
+ // it's not actually useful thanks to term.write callback +
1985
+ // call on _innerRefresh() before context.drawImage
1986
+ // but let's keep it nevertheless
1987
+ true,
1988
+ );
1989
+ term.loadAddon(webglAddon);
1990
+ const terminalElement = document.querySelector("#terminal");
1988
1991
  term.open(terminalElement);
1992
+ fitAddon.fit();
1989
1993
 
1990
- const canvasPromise = (async () => {
1991
- const canvas = document.querySelector("#canvas");
1992
- if (!canvas) {
1993
- throw new Error('Cannot find <canvas id="canvas"> in the document');
1994
- }
1995
- let xtermCanvas = document.querySelector(
1996
- "#terminal canvas.xterm-link-layer + canvas",
1997
- );
1998
- if (!xtermCanvas) {
1999
- await new Promise((resolve) => setTimeout(resolve, 100));
2000
- xtermCanvas = document.querySelector(
2001
- "#terminal canvas.xterm-link-layer + canvas",
2002
- );
2003
- if (!xtermCanvas) {
2004
- throw new Error(
2005
- "Cannot find xterm canvas (canvas.xterm-link-layer + canvas)",
2006
- );
2007
- }
2008
- }
2009
- return { canvas, xtermCanvas };
2010
- })();
1994
+ const canvas = document.querySelector("#canvas");
1995
+ if (!canvas) {
1996
+ throw new Error('Cannot find <canvas id="canvas"> in the document');
1997
+ }
1998
+ const xTermCanvasSelector = "#terminal canvas.xterm-link-layer + canvas";
1999
+ const xtermCanvas = document.querySelector(xTermCanvasSelector);
2000
+ if (!xtermCanvas) {
2001
+ throw new Error(`Cannot find xterm canvas (${xTermCanvasSelector})`);
2002
+ }
2011
2003
 
2012
2004
  return {
2013
2005
  term,
2014
2006
  startRecording: async () => {
2015
- const { canvas, xtermCanvas } = await canvasPromise;
2016
2007
  const context = canvas.getContext("2d", { willReadFrequently: true });
2017
2008
  context.imageSmoothingEnabled = true;
2018
2009
  const headerHeight = 40;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/terminal-recorder",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "Record terminal output as .svg, .gif, .webm, .mp4",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,8 +49,9 @@
49
49
  "webm-to-mp4": "1.0.0"
50
50
  },
51
51
  "devDependencies": {
52
+ "@xterm/addon-fit": "0.10.0",
52
53
  "@xterm/addon-serialize": "0.13.0",
53
- "@xterm/xterm": "5.5.0",
54
- "@xterm/addon-webgl": "0.18.0"
54
+ "@xterm/addon-webgl": "0.18.0",
55
+ "@xterm/xterm": "5.5.0"
55
56
  }
56
57
  }
@@ -12,12 +12,14 @@ https://webglfundamentals.org/webgl/lessons/webgl-tips.html
12
12
  https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts
13
13
  */
14
14
 
15
+ import "@xterm/addon-fit";
15
16
  import "@xterm/addon-serialize?as_js_module";
16
- import "@xterm/addon-webgl";
17
+ import "@xterm/addon-webgl"; // https://github.com/xtermjs/xterm.js/tree/master/addons/addon-webgl
17
18
  import "@xterm/xterm";
18
19
  import { createGifEncoder } from "./gif_encoder.js";
19
20
 
20
21
  const { Terminal } = window;
22
+ const { FitAddon } = window.FitAddon;
21
23
  const { WebglAddon } = window.WebglAddon;
22
24
  const { SerializeAddon } = window.SerializeAddon;
23
25
 
@@ -74,47 +76,35 @@ export const initTerminal = ({
74
76
  brightBlue: "#87CEEB",
75
77
  },
76
78
  });
77
- term.loadAddon(
78
- new WebglAddon(
79
- // we pass true to enable preserveDrawingBuffer
80
- // it's not actually useful thanks to term.write callback +
81
- // call on _innerRefresh() before context.drawImage
82
- // but let's keep it nevertheless
83
- true,
84
- ),
85
- );
86
79
  const serializeAddon = new SerializeAddon();
87
80
  term.loadAddon(serializeAddon);
88
-
89
- const terminalElement = document.getElementById("terminal");
81
+ const fitAddon = new FitAddon();
82
+ term.loadAddon(fitAddon);
83
+ const webglAddon = new WebglAddon(
84
+ // we pass true to enable preserveDrawingBuffer
85
+ // it's not actually useful thanks to term.write callback +
86
+ // call on _innerRefresh() before context.drawImage
87
+ // but let's keep it nevertheless
88
+ true,
89
+ );
90
+ term.loadAddon(webglAddon);
91
+ const terminalElement = document.querySelector("#terminal");
90
92
  term.open(terminalElement);
93
+ fitAddon.fit();
91
94
 
92
- const canvasPromise = (async () => {
93
- const canvas = document.querySelector("#canvas");
94
- if (!canvas) {
95
- throw new Error('Cannot find <canvas id="canvas"> in the document');
96
- }
97
- let xtermCanvas = document.querySelector(
98
- "#terminal canvas.xterm-link-layer + canvas",
99
- );
100
- if (!xtermCanvas) {
101
- await new Promise((resolve) => setTimeout(resolve, 100));
102
- xtermCanvas = document.querySelector(
103
- "#terminal canvas.xterm-link-layer + canvas",
104
- );
105
- if (!xtermCanvas) {
106
- throw new Error(
107
- "Cannot find xterm canvas (canvas.xterm-link-layer + canvas)",
108
- );
109
- }
110
- }
111
- return { canvas, xtermCanvas };
112
- })();
95
+ const canvas = document.querySelector("#canvas");
96
+ if (!canvas) {
97
+ throw new Error('Cannot find <canvas id="canvas"> in the document');
98
+ }
99
+ const xTermCanvasSelector = "#terminal canvas.xterm-link-layer + canvas";
100
+ const xtermCanvas = document.querySelector(xTermCanvasSelector);
101
+ if (!xtermCanvas) {
102
+ throw new Error(`Cannot find xterm canvas (${xTermCanvasSelector})`);
103
+ }
113
104
 
114
105
  return {
115
106
  term,
116
107
  startRecording: async () => {
117
- const { canvas, xtermCanvas } = await canvasPromise;
118
108
  const context = canvas.getContext("2d", { willReadFrequently: true });
119
109
  context.imageSmoothingEnabled = true;
120
110
  const headerHeight = 40;
@@ -8,7 +8,7 @@
8
8
 
9
9
  <body>
10
10
  <div style="display: flex">
11
- <div id="terminal"></div>
11
+ <div id="terminal" width="300px"></div>
12
12
  <canvas id="canvas"></canvas>
13
13
  </div>
14
14
  <script type="module">