@@ -123,6 +123,29 @@ function keepHighlightedHomepageSource(container, editor, controls, source) {
123123 controls . append ( edit ) ;
124124}
125125
126+ /**
127+ * @param {Terminal } terminal
128+ * @param {HTMLElement } host
129+ * @returns {() => void }
130+ */
131+ function fitTerminalWidth ( terminal , host ) {
132+ /** @type {FitAddon.FitAddon } */
133+ const addon = new FitAddon . FitAddon ( ) ;
134+ terminal . loadAddon ( addon ) ;
135+ /** @type {() => void } */
136+ const fit = ( ) => {
137+ /** @type {{cols: number, rows: number} | undefined } */
138+ const dimensions = addon . proposeDimensions ( ) ;
139+ if ( dimensions && dimensions . cols !== terminal . cols ) {
140+ terminal . resize ( dimensions . cols , terminal . rows ) ;
141+ }
142+ } ;
143+ /** @type {ResizeObserver } */
144+ const observer = new ResizeObserver ( fit ) ;
145+ observer . observe ( host ) ;
146+ return fit ;
147+ }
148+
126149function createPanel ( container , source ) {
127150 const editor = document . createElement ( 'textarea' ) ;
128151 editor . className = 'demo-editor' ;
@@ -143,6 +166,9 @@ function createPanel(container, source) {
143166
144167 const screen = document . createElement ( 'div' ) ;
145168 screen . className = 'demo-terminal' ;
169+ /** @type {HTMLDivElement } */
170+ const terminalHost = document . createElement ( 'div' ) ;
171+ screen . append ( terminalHost ) ;
146172
147173 const controls = document . createElement ( 'div' ) ;
148174 controls . className = 'demo-controls' ;
@@ -153,12 +179,14 @@ function createPanel(container, source) {
153179
154180 const terminal = new Terminal ( {
155181 cols : COLUMNS ,
156- rows : 12 ,
182+ rows : container . closest ( '.home-quickstart' ) ? 3 : 12 ,
157183 convertEol : true ,
158184 fontSize : 13 ,
159185 theme : { background : '#101418' , foreground : '#d6e2ef' } ,
160186 } ) ;
161- terminal . open ( screen ) ;
187+ terminal . open ( terminalHost ) ;
188+ /** @type {() => void } */
189+ const fitWidth = fitTerminalWidth ( terminal , terminalHost ) ;
162190
163191 const panel = {
164192 terminal,
@@ -195,6 +223,8 @@ function createPanel(container, source) {
195223 panel . setStatus ( 'idle' ) ;
196224 return ;
197225 }
226+ await new Promise ( resolve => requestAnimationFrame ( resolve ) ) ;
227+ fitWidth ( ) ;
198228 panel . setStatus ( 'ready' ) ;
199229 timeoutHandle = setTimeout ( ( ) => {
200230 terminal . write ( '\r\n\x1b[33mStopped after 30 seconds.\x1b[0m\r\n' ) ;
@@ -204,7 +234,7 @@ function createPanel(container, source) {
204234 worker . postMessage ( {
205235 type : 'run' ,
206236 code : editor . value ,
207- columns : COLUMNS ,
237+ columns : terminal . cols ,
208238 } ) ;
209239 } ) ;
210240
@@ -224,7 +254,7 @@ const NON_RUNNABLE_DEMOS = new Set([
224254] ) ;
225255
226256document . addEventListener ( 'DOMContentLoaded' , ( ) => {
227- if ( typeof Terminal === 'undefined' ) return ;
257+ if ( typeof Terminal === 'undefined' || typeof FitAddon === 'undefined' ) return ;
228258 for ( const container of document . querySelectorAll ( '.demo-run' ) ) {
229259 if ( NON_RUNNABLE_DEMOS . has ( container . dataset . demo ) ) {
230260 container . textContent =
0 commit comments