@@ -8,6 +8,15 @@ import JSZip from "jszip";
88import { loadAsync } from "./runtime" ;
99import { createFuture } from "./core/future" ;
1010
11+ function debounce ( func , delay = 100 ) {
12+ let timeoutId ;
13+
14+ return function ( ...args ) {
15+ clearTimeout ( timeoutId ) ;
16+ timeoutId = setTimeout ( func , delay , ...args ) ;
17+ } ;
18+ }
19+
1120export class ExportViewer {
1221 constructor ( containerSelector , remoting ) {
1322 this . remoting = remoting ;
@@ -66,10 +75,27 @@ export class ExportViewer {
6675 "position: absolute; left: 0; top: 0; width: 100%; height: 100%;" ,
6776 ) ;
6877 this . container . appendChild ( canvas ) ;
69-
7078 const target = this . remoting . bindCanvas ( rwId , canvas ) ;
7179 this . remoting . native . bindRenderWindow ( rwId , target ) ;
72- this . remoting . native . startEventLoop ( rwId ) ;
80+ this . remoting . boundRenderWindows . add ( rwId ) ;
81+
82+ // RemoteSession opts out of VTK's own canvas sizing (resize observer /
83+ // expand-to-container), so the viewer owns it: size the render window to
84+ // the canvas now (this also triggers the first render) and on every resize.
85+ const resize = ( ) => {
86+ const { width, height } = canvas . getBoundingClientRect ( ) ;
87+ const dpr = window . devicePixelRatio || 1 ;
88+ this . remoting . setSizeAsync (
89+ rwId ,
90+ Math . max ( 1 , Math . round ( width * dpr ) ) ,
91+ Math . max ( 1 , Math . round ( height * dpr ) ) ,
92+ ) ;
93+ } ;
94+ this . resizeObserver = new ResizeObserver ( debounce ( resize ) ) ;
95+ this . resizeObserver . observe ( canvas ) ;
96+ resize ( ) ;
97+
98+ this . remoting . startEventLoop ( rwId ) ;
7399 }
74100}
75101
0 commit comments