-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschemas.ts
399 lines (395 loc) · 11.3 KB
/
schemas.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
// DO NOT EDIT: This file is auto-generated by scripts/generate-zod.ts
import { z } from "npm:zod";
/**
* Options for creating a webview.
*/
export type WebViewOptions =
& {
/** Sets whether clicking an inactive window also clicks through to the webview. Default is false. */
acceptFirstMouse?: boolean;
/** When true, all media can be played without user interaction. Default is false. */
autoplay?: boolean;
/**
* Enables clipboard access for the page rendered on Linux and Windows.
*
* macOS doesn’t provide such method and is always enabled by default. But your app will still need to add menu item accelerators to use the clipboard shortcuts.
*/
clipboard?: boolean;
/** When true, the window will have a border, a title bar, etc. Default is true. */
decorations?: boolean;
/**
* Enable or disable webview devtools.
*
* Note this only enables devtools to the webview. To open it, you can call `webview.open_devtools()`, or right click the page and open it from the context menu.
*/
devtools?: boolean;
/** Sets whether the webview should be focused when created. Default is false. */
focused?: boolean;
/**
* Run the WebView with incognito mode. Note that WebContext will be ingored if incognito is enabled.
*
* Platform-specific: - Windows: Requires WebView2 Runtime version 101.0.1210.39 or higher, does nothing on older versions, see https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/archive?tabs=dotnetcsharp#10121039
*/
incognito?: boolean;
/** Run JavaScript code when loading new pages. When the webview loads a new page, this code will be executed. It is guaranteed that the code is executed before window.onload. */
initializationScript?: string;
/** Sets whether host should be able to receive messages from the webview via `window.ipc.postMessage`. */
ipc?: boolean;
/** The size of the window. */
size?: "maximized" | "fullscreen" | {
height: number;
width: number;
};
/** Sets the title of the window. */
title: string;
/** Sets whether the window should be transparent. */
transparent?: boolean;
}
& (
| {
/** Url to load in the webview. Note: Don't use data URLs here, as they are not supported. Use the `html` field instead. */
url: string;
}
| {
/** Html to load in the webview. */
html: string;
/** What to set as the origin of the webview when loading html. */
origin?: string;
}
);
export const WebViewOptions: z.ZodType<WebViewOptions> = z.intersection(
z.object({
acceptFirstMouse: z.boolean().optional(),
autoplay: z.boolean().optional(),
clipboard: z.boolean().optional(),
decorations: z.boolean().optional(),
devtools: z.boolean().optional(),
focused: z.boolean().optional(),
incognito: z.boolean().optional(),
initializationScript: z.string().optional(),
ipc: z.boolean().optional(),
size: z.union([
z.literal("maximized"),
z.literal("fullscreen"),
z.object({ height: z.number(), width: z.number() }),
])
.optional(),
title: z.string(),
transparent: z.boolean().optional(),
}),
z.union([
z.object({ url: z.string() }),
z.object({ html: z.string(), origin: z.string().optional() }),
]),
);
/**
* Explicit requests from the client to the webview.
*/
export type WebViewRequest =
| {
$type: "getVersion";
/** The id of the request. */
id: string;
}
| {
$type: "eval";
/** The id of the request. */
id: string;
/** The javascript to evaluate. */
js: string;
}
| {
$type: "setTitle";
/** The id of the request. */
id: string;
/** The title to set. */
title: string;
}
| {
$type: "getTitle";
/** The id of the request. */
id: string;
}
| {
$type: "setVisibility";
/** The id of the request. */
id: string;
/** Whether the window should be visible or hidden. */
visible: boolean;
}
| {
$type: "isVisible";
/** The id of the request. */
id: string;
}
| {
$type: "openDevTools";
/** The id of the request. */
id: string;
}
| {
$type: "getSize";
/** The id of the request. */
id: string;
/** Whether to include the title bar and borders in the size measurement. */
include_decorations?: boolean;
}
| {
$type: "setSize";
/** The id of the request. */
id: string;
/** The size to set. */
size: {
height: number;
width: number;
};
}
| {
$type: "fullscreen";
/** Whether to enter fullscreen mode. If left unspecified, the window will enter fullscreen mode if it is not already in fullscreen mode or exit fullscreen mode if it is currently in fullscreen mode. */
fullscreen?: boolean;
/** The id of the request. */
id: string;
}
| {
$type: "maximize";
/** The id of the request. */
id: string;
/** Whether to maximize the window. If left unspecified, the window will be maximized if it is not already maximized or restored if it was previously maximized. */
maximized?: boolean;
}
| {
$type: "minimize";
/** The id of the request. */
id: string;
/** Whether to minimize the window. If left unspecified, the window will be minimized if it is not already minimized or restored if it was previously minimized. */
minimized?: boolean;
}
| {
$type: "loadHtml";
/** HTML to set as the content of the webview. */
html: string;
/** The id of the request. */
id: string;
/** What to set as the origin of the webview when loading html. If not specified, the origin will be set to the value of the `origin` field when the webview was created. */
origin?: string;
};
export const WebViewRequest: z.ZodType<WebViewRequest> = z.discriminatedUnion(
"$type",
[
z.object({ $type: z.literal("getVersion"), id: z.string() }),
z.object({ $type: z.literal("eval"), id: z.string(), js: z.string() }),
z.object({
$type: z.literal("setTitle"),
id: z.string(),
title: z.string(),
}),
z.object({ $type: z.literal("getTitle"), id: z.string() }),
z.object({
$type: z.literal("setVisibility"),
id: z.string(),
visible: z.boolean(),
}),
z.object({ $type: z.literal("isVisible"), id: z.string() }),
z.object({ $type: z.literal("openDevTools"), id: z.string() }),
z.object({
$type: z.literal("getSize"),
id: z.string(),
include_decorations: z.boolean().optional(),
}),
z.object({
$type: z.literal("setSize"),
id: z.string(),
size: z.object({ height: z.number(), width: z.number() }),
}),
z.object({
$type: z.literal("fullscreen"),
fullscreen: z.boolean().optional(),
id: z.string(),
}),
z.object({
$type: z.literal("maximize"),
id: z.string(),
maximized: z.boolean().optional(),
}),
z.object({
$type: z.literal("minimize"),
id: z.string(),
minimized: z.boolean().optional(),
}),
z.object({
$type: z.literal("loadHtml"),
html: z.string(),
id: z.string(),
origin: z.string().optional(),
}),
],
);
/**
* Responses from the webview to the client.
*/
export type WebViewResponse =
| {
$type: "ack";
id: string;
}
| {
$type: "result";
id: string;
result:
| {
$type: "string";
value: string;
}
| {
$type: "boolean";
value: boolean;
}
| {
$type: "float";
value: number;
}
| {
$type: "size";
value: {
/** The height of the window in logical pixels. */
height: number;
/** The ratio between physical and logical sizes. */
scale_factor: number;
/** The width of the window in logical pixels. */
width: number;
};
};
}
| {
$type: "err";
id: string;
message: string;
};
export const WebViewResponse: z.ZodType<WebViewResponse> = z.discriminatedUnion(
"$type",
[
z.object({ $type: z.literal("ack"), id: z.string() }),
z.object({
$type: z.literal("result"),
id: z.string(),
result: z.discriminatedUnion("$type", [
z.object({ $type: z.literal("string"), value: z.string() }),
z.object({ $type: z.literal("boolean"), value: z.boolean() }),
z.object({ $type: z.literal("float"), value: z.number() }),
z.object({
$type: z.literal("size"),
value: z.object({
height: z.number(),
scale_factor: z.number(),
width: z.number(),
}),
}),
]),
}),
z.object({ $type: z.literal("err"), id: z.string(), message: z.string() }),
],
);
/**
* Complete definition of all outbound messages from the webview to the client.
*/
export type WebViewMessage =
| {
$type: "notification";
data:
| {
$type: "started";
/** The version of the webview binary */
version: string;
}
| {
$type: "ipc";
/** The message sent from the webview UI to the client. */
message: string;
}
| {
$type: "closed";
};
}
| {
$type: "response";
data:
| {
$type: "ack";
id: string;
}
| {
$type: "result";
id: string;
result:
| {
$type: "string";
value: string;
}
| {
$type: "boolean";
value: boolean;
}
| {
$type: "float";
value: number;
}
| {
$type: "size";
value: {
/** The height of the window in logical pixels. */
height: number;
/** The ratio between physical and logical sizes. */
scale_factor: number;
/** The width of the window in logical pixels. */
width: number;
};
};
}
| {
$type: "err";
id: string;
message: string;
};
};
export const WebViewMessage: z.ZodType<WebViewMessage> = z.discriminatedUnion(
"$type",
[
z.object({
$type: z.literal("notification"),
data: z.discriminatedUnion("$type", [
z.object({ $type: z.literal("started"), version: z.string() }),
z.object({ $type: z.literal("ipc"), message: z.string() }),
z.object({ $type: z.literal("closed") }),
]),
}),
z.object({
$type: z.literal("response"),
data: z.discriminatedUnion("$type", [
z.object({ $type: z.literal("ack"), id: z.string() }),
z.object({
$type: z.literal("result"),
id: z.string(),
result: z.discriminatedUnion("$type", [
z.object({ $type: z.literal("string"), value: z.string() }),
z.object({ $type: z.literal("boolean"), value: z.boolean() }),
z.object({ $type: z.literal("float"), value: z.number() }),
z.object({
$type: z.literal("size"),
value: z.object({
height: z.number(),
scale_factor: z.number(),
width: z.number(),
}),
}),
]),
}),
z.object({
$type: z.literal("err"),
id: z.string(),
message: z.string(),
}),
]),
}),
],
);