Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

hostedBrowserWebviewStyle.ts

73 lines2.0 KB

1import type { BrowserSurfaceRect } from "./browserSurfaceStore";
2​
3export interface HostedBrowserWebviewSize {
4 readonly width: number;
5 readonly height: number;
6}
7​
8export interface HostedBrowserWebviewWrapperStyle {
9 readonly left: number;
10 readonly top: number;
11 readonly width: number;
12 readonly height: number;
13 readonly zIndex: number;
14 readonly pointerEvents: "auto" | "none";
15 readonly borderRadius?: number;
16 readonly visibility?: "hidden" | "visible";
18​
19export const HIDDEN_BROWSER_WEBVIEW_OFFSET = -100_000;
20​
21export function resolveHostedBrowserWebviewWrapperStyle(input: {
22 readonly active: boolean;
23 readonly renderingActive: boolean;
24 readonly keepPaintableWhenInactive?: boolean;
25 readonly cornerRadius?: number;
26 readonly rect: BrowserSurfaceRect | null;
27 readonly hiddenSize: HostedBrowserWebviewSize;
28}): HostedBrowserWebviewWrapperStyle {
29 const {
30 active,
31 cornerRadius = 0,
32 hiddenSize,
33 keepPaintableWhenInactive = false,
34 rect,
35 renderingActive,
36 } = input;
37 if (active && rect) {
38 return {
39 left: rect.x,
40 top: rect.y,
41 width: rect.width,
42 height: rect.height,
43 zIndex: 30,
44 pointerEvents: "auto",
45 ...(cornerRadius > 0 ? { borderRadius: cornerRadius } : {}),
46 };
47 }
48​
49 if (renderingActive) {
50 // Electron stops compositing a guest that is fully outside the window, even
51 // when background throttling is disabled. Keep capture-active guests inside
52 // the viewport but behind the app so recordings receive complete frames.
53 return {
54 left: 0,
55 top: 0,
56 width: hiddenSize.width,
57 height: hiddenSize.height,
58 zIndex: -1,
59 pointerEvents: "none",
60 visibility: "visible",
61 };
62 }
63​
64 return {
65 left: HIDDEN_BROWSER_WEBVIEW_OFFSET,
66 top: HIDDEN_BROWSER_WEBVIEW_OFFSET,
67 width: hiddenSize.width,
68 height: hiddenSize.height,
69 zIndex: -1,
70 pointerEvents: "none",
71 visibility: keepPaintableWhenInactive ? "visible" : "hidden",
72 };