@ohos-ports/vibium 26.5.31-beta.0

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.
@@ -0,0 +1,613 @@
1
+ /**
2
+ * Signal protocol (2-slot SharedArrayBuffer):
3
+ * signal[0]: worker → main (0=idle, 1=result ready, 2=callback needed)
4
+ * signal[1]: main → worker (0=idle, 1=callback response ready)
5
+ */
6
+ declare class SyncBridge {
7
+ private worker;
8
+ private signal;
9
+ private commandId;
10
+ private terminated;
11
+ private callbackPortMain;
12
+ private callbackPortWorker;
13
+ private handlers;
14
+ private constructor();
15
+ static create(): SyncBridge;
16
+ /** Register a callback handler that can be invoked from the worker thread. */
17
+ registerHandler(id: string, handler: Function): void;
18
+ /** Remove a previously registered callback handler. */
19
+ unregisterHandler(id: string): void;
20
+ /** Process any pending callbacks that fired between bridge calls. */
21
+ private processPendingCallbacks;
22
+ /** Handle a single callback request from the worker. */
23
+ private handleCallback;
24
+ call<T = unknown>(method: string, args?: unknown[]): T;
25
+ tryQuit(): void;
26
+ terminate(): void;
27
+ }
28
+
29
+ interface BoundingBox {
30
+ x: number;
31
+ y: number;
32
+ width: number;
33
+ height: number;
34
+ }
35
+ interface ElementInfo {
36
+ tag: string;
37
+ text: string;
38
+ box: BoundingBox;
39
+ }
40
+ interface ActionOptions {
41
+ /** Timeout in milliseconds for actionability checks. Default: 30000 */
42
+ timeout?: number;
43
+ }
44
+ interface SelectorOptions {
45
+ role?: string;
46
+ text?: string;
47
+ label?: string;
48
+ placeholder?: string;
49
+ alt?: string;
50
+ title?: string;
51
+ testid?: string;
52
+ xpath?: string;
53
+ near?: string;
54
+ timeout?: number;
55
+ }
56
+
57
+ declare const customInspect$2: unique symbol;
58
+ declare class ElementSync {
59
+ private bridge;
60
+ private elementId;
61
+ readonly info: ElementInfo;
62
+ constructor(bridge: SyncBridge, elementId: number, info: ElementInfo);
63
+ [customInspect$2](): string;
64
+ /**
65
+ * Click the element.
66
+ * Waits for element to be visible, stable, receive events, and enabled.
67
+ */
68
+ click(options?: ActionOptions): void;
69
+ /** Double-click the element. */
70
+ dblclick(options?: ActionOptions): void;
71
+ /**
72
+ * Fill the element with text (clears existing content first).
73
+ * For inputs and textareas.
74
+ */
75
+ fill(value: string, options?: ActionOptions): void;
76
+ /**
77
+ * Type text into the element.
78
+ * Waits for element to be visible, stable, receive events, enabled, and editable.
79
+ */
80
+ type(text: string, options?: ActionOptions): void;
81
+ /**
82
+ * Press a key while the element is focused.
83
+ * Supports key names ("Enter", "Tab") and combos ("Control+a").
84
+ */
85
+ press(key: string, options?: ActionOptions): void;
86
+ /** Clear the element's content (select all + delete). */
87
+ clear(options?: ActionOptions): void;
88
+ /** Check a checkbox (no-op if already checked). */
89
+ check(options?: ActionOptions): void;
90
+ /** Uncheck a checkbox (no-op if already unchecked). */
91
+ uncheck(options?: ActionOptions): void;
92
+ /** Select an option in a <select> element by value. */
93
+ selectOption(value: string, options?: ActionOptions): void;
94
+ /** Hover over the element (move mouse to center, no click). */
95
+ hover(options?: ActionOptions): void;
96
+ /** Focus the element. */
97
+ focus(options?: ActionOptions): void;
98
+ /** Drag this element to a target element. */
99
+ dragTo(target: ElementSync, options?: ActionOptions): void;
100
+ /** Tap the element (touch action). */
101
+ tap(options?: ActionOptions): void;
102
+ /** Scroll the element into view. */
103
+ scrollIntoView(options?: ActionOptions): void;
104
+ /** Dispatch a DOM event on the element. */
105
+ dispatchEvent(eventType: string, eventInit?: Record<string, unknown>, options?: ActionOptions): void;
106
+ text(): string;
107
+ innerText(): string;
108
+ html(): string;
109
+ value(): string;
110
+ attr(name: string): string | null;
111
+ getAttribute(name: string): string | null;
112
+ bounds(): BoundingBox;
113
+ boundingBox(): BoundingBox;
114
+ isVisible(): boolean;
115
+ isHidden(): boolean;
116
+ isEnabled(): boolean;
117
+ isChecked(): boolean;
118
+ isEditable(): boolean;
119
+ screenshot(): Buffer;
120
+ waitUntil(state?: string, options?: {
121
+ timeout?: number;
122
+ }): void;
123
+ setFiles(files: string[], options?: ActionOptions): void;
124
+ role(): string;
125
+ label(): string;
126
+ find(selector: string | SelectorOptions, options?: {
127
+ timeout?: number;
128
+ }): ElementSync;
129
+ findAll(selector: string | SelectorOptions, options?: {
130
+ timeout?: number;
131
+ }): ElementSync[];
132
+ }
133
+
134
+ declare class KeyboardSync {
135
+ private bridge;
136
+ private pageId;
137
+ constructor(bridge: SyncBridge, pageId: number);
138
+ press(key: string): void;
139
+ down(key: string): void;
140
+ up(key: string): void;
141
+ type(text: string): void;
142
+ }
143
+ declare class MouseSync {
144
+ private bridge;
145
+ private pageId;
146
+ constructor(bridge: SyncBridge, pageId: number);
147
+ click(x: number, y: number): void;
148
+ move(x: number, y: number): void;
149
+ down(): void;
150
+ up(): void;
151
+ wheel(deltaX: number, deltaY: number): void;
152
+ }
153
+ declare class TouchSync {
154
+ private bridge;
155
+ private pageId;
156
+ constructor(bridge: SyncBridge, pageId: number);
157
+ tap(x: number, y: number): void;
158
+ }
159
+
160
+ interface ClockInstallOptions {
161
+ time?: number | string | Date;
162
+ timezone?: string;
163
+ }
164
+ declare class ClockSync {
165
+ private bridge;
166
+ private pageId;
167
+ constructor(bridge: SyncBridge, pageId: number);
168
+ install(options?: ClockInstallOptions): void;
169
+ fastForward(ticks: number): void;
170
+ runFor(ticks: number): void;
171
+ pauseAt(time: number | string | Date): void;
172
+ resume(): void;
173
+ setFixedTime(time: number | string | Date): void;
174
+ setSystemTime(time: number | string | Date): void;
175
+ setTimezone(timezone: string): void;
176
+ }
177
+
178
+ interface RecordingStartOptions {
179
+ name?: string;
180
+ screenshots?: boolean;
181
+ snapshots?: boolean;
182
+ sources?: boolean;
183
+ title?: string;
184
+ bidi?: boolean;
185
+ /** Screenshot format: 'jpeg' (default, faster/smaller) or 'png' (lossless). */
186
+ format?: 'jpeg' | 'png';
187
+ /** JPEG quality 0.0-1.0 (default 0.5). Ignored for PNG. */
188
+ quality?: number;
189
+ }
190
+ interface RecordingStopOptions {
191
+ path?: string;
192
+ }
193
+
194
+ declare class RecordingSync {
195
+ private bridge;
196
+ private contextId;
197
+ constructor(bridge: SyncBridge, contextId: number);
198
+ start(options?: RecordingStartOptions): void;
199
+ stop(options?: RecordingStopOptions): Buffer;
200
+ startChunk(options?: {
201
+ name?: string;
202
+ title?: string;
203
+ }): void;
204
+ stopChunk(options?: RecordingStopOptions): Buffer;
205
+ startGroup(name: string, options?: {
206
+ location?: {
207
+ file: string;
208
+ line?: number;
209
+ column?: number;
210
+ };
211
+ }): void;
212
+ stopGroup(): void;
213
+ }
214
+
215
+ interface FindOptions {
216
+ /** Timeout in milliseconds to wait for element. Default: 30000 */
217
+ timeout?: number;
218
+ }
219
+ interface ScreenshotOptions {
220
+ /** Capture full scrollable page instead of just the viewport. */
221
+ fullPage?: boolean;
222
+ /** Capture a specific region of the page. */
223
+ clip?: {
224
+ x: number;
225
+ y: number;
226
+ width: number;
227
+ height: number;
228
+ };
229
+ }
230
+ interface A11yNode {
231
+ role: string;
232
+ name?: string;
233
+ value?: string | number;
234
+ description?: string;
235
+ disabled?: boolean;
236
+ expanded?: boolean;
237
+ focused?: boolean;
238
+ checked?: boolean | 'mixed';
239
+ pressed?: boolean | 'mixed';
240
+ selected?: boolean;
241
+ required?: boolean;
242
+ readonly?: boolean;
243
+ level?: number;
244
+ valuemin?: number;
245
+ valuemax?: number;
246
+ children?: A11yNode[];
247
+ }
248
+
249
+ interface Cookie {
250
+ name: string;
251
+ value: string;
252
+ domain: string;
253
+ path: string;
254
+ size: number;
255
+ httpOnly: boolean;
256
+ secure: boolean;
257
+ sameSite: string;
258
+ expiry?: number;
259
+ }
260
+ interface SetCookieParam {
261
+ name: string;
262
+ value: string;
263
+ domain?: string;
264
+ url?: string;
265
+ path?: string;
266
+ httpOnly?: boolean;
267
+ secure?: boolean;
268
+ sameSite?: string;
269
+ expiry?: number;
270
+ }
271
+ interface OriginState {
272
+ origin: string;
273
+ localStorage: {
274
+ name: string;
275
+ value: string;
276
+ }[];
277
+ sessionStorage: {
278
+ name: string;
279
+ value: string;
280
+ }[];
281
+ }
282
+ interface StorageState {
283
+ cookies: Cookie[];
284
+ origins: OriginState[];
285
+ }
286
+
287
+ declare class BrowserContextSync {
288
+ private bridge;
289
+ private contextId;
290
+ readonly recording: RecordingSync;
291
+ constructor(bridge: SyncBridge, contextId: number);
292
+ newPage(): PageSync;
293
+ close(): void;
294
+ cookies(urls?: string[]): Cookie[];
295
+ setCookies(cookies: SetCookieParam[]): void;
296
+ clearCookies(): void;
297
+ storage(): StorageState;
298
+ setStorage(state: StorageState): void;
299
+ clearStorage(): void;
300
+ addInitScript(script: string): string;
301
+ }
302
+
303
+ /** Sync route handler data — plain object representing the intercepted request. */
304
+ interface RouteRequest {
305
+ url: string;
306
+ method: string;
307
+ headers: Record<string, string>;
308
+ postData: string | null;
309
+ }
310
+ /** Decision returned by a sync route handler. */
311
+ interface RouteDecision {
312
+ action: 'fulfill' | 'continue' | 'abort';
313
+ status?: number;
314
+ headers?: Record<string, string>;
315
+ contentType?: string;
316
+ body?: string;
317
+ url?: string;
318
+ method?: string;
319
+ postData?: string;
320
+ }
321
+ /**
322
+ * Sync wrapper for an intercepted network request.
323
+ * The user's handler calls fulfill(), continue(), or abort() to set the decision.
324
+ * If none is called, the default is 'continue'.
325
+ */
326
+ declare class RouteSync {
327
+ readonly request: RouteRequest;
328
+ /** @internal */
329
+ _decision: RouteDecision;
330
+ constructor(request: RouteRequest);
331
+ /** Fulfill the request with a custom response. */
332
+ fulfill(response?: {
333
+ status?: number;
334
+ headers?: Record<string, string>;
335
+ contentType?: string;
336
+ body?: string;
337
+ }): void;
338
+ /** Continue the request, optionally with overrides. */
339
+ continue(overrides?: {
340
+ url?: string;
341
+ method?: string;
342
+ headers?: Record<string, string>;
343
+ postData?: string;
344
+ }): void;
345
+ /** Abort the request. */
346
+ abort(): void;
347
+ }
348
+
349
+ /** Serialized dialog data sent from worker to main thread. */
350
+ interface DialogData {
351
+ type: string;
352
+ message: string;
353
+ defaultValue: string;
354
+ }
355
+ /** Decision returned by a sync dialog handler. */
356
+ interface DialogDecision {
357
+ action: 'accept' | 'dismiss';
358
+ promptText?: string;
359
+ }
360
+ /**
361
+ * Sync wrapper for a browser dialog (alert, confirm, prompt, beforeunload).
362
+ * The user's handler calls accept() or dismiss() to set the decision.
363
+ * If none is called, the default is 'dismiss'.
364
+ */
365
+ declare class DialogSync {
366
+ private data;
367
+ /** @internal */
368
+ _decision: DialogDecision;
369
+ constructor(data: DialogData);
370
+ /** The dialog type: 'alert', 'confirm', 'prompt', or 'beforeunload'. */
371
+ type(): string;
372
+ /** The dialog message text. */
373
+ message(): string;
374
+ /** The default value for prompt dialogs. */
375
+ defaultValue(): string;
376
+ /** Accept the dialog. For prompt dialogs, optionally provide text. */
377
+ accept(promptText?: string): void;
378
+ /** Dismiss the dialog (cancel/close). */
379
+ dismiss(): void;
380
+ }
381
+
382
+ declare const customInspect$1: unique symbol;
383
+ interface RequestData {
384
+ url: string;
385
+ method: string;
386
+ headers: Record<string, string>;
387
+ postData: string | null;
388
+ }
389
+ interface ResponseData {
390
+ url: string;
391
+ status: number;
392
+ headers: Record<string, string>;
393
+ body: string | null;
394
+ }
395
+ declare class DownloadData {
396
+ readonly url: string;
397
+ readonly suggestedFilename: string;
398
+ readonly path: string | null;
399
+ constructor(data: {
400
+ url: string;
401
+ suggestedFilename: string;
402
+ path: string | null;
403
+ });
404
+ /** Save the downloaded file to a destination path. */
405
+ saveAs(destPath: string): void;
406
+ }
407
+ type MessageHandler = (data: string, info: {
408
+ direction: 'sent' | 'received';
409
+ }) => void;
410
+ type CloseHandler = (code?: number, reason?: string) => void;
411
+ declare class WebSocketInfoSync {
412
+ private _url;
413
+ private _isClosed;
414
+ private _messageHandlers;
415
+ private _closeHandlers;
416
+ constructor(url: string);
417
+ url(): string;
418
+ onMessage(fn: MessageHandler): void;
419
+ onClose(fn: CloseHandler): void;
420
+ isClosed(): boolean;
421
+ /** @internal */
422
+ _emitMessage(data: string, direction: 'sent' | 'received'): void;
423
+ /** @internal */
424
+ _emitClose(code?: number, reason?: string): void;
425
+ }
426
+ declare class PageSync {
427
+ /** @internal */
428
+ readonly _bridge: SyncBridge;
429
+ /** @internal */
430
+ readonly _pageId: number;
431
+ readonly keyboard: KeyboardSync;
432
+ readonly mouse: MouseSync;
433
+ readonly touch: TouchSync;
434
+ readonly clock: ClockSync;
435
+ private _nextHandlerId;
436
+ private _routeHandlerIds;
437
+ private _dialogHandlerId;
438
+ private _requestHandlerId;
439
+ private _responseHandlerId;
440
+ private _downloadHandlerId;
441
+ private _wsHandlerId;
442
+ private _wsInstances;
443
+ private _cachedContext;
444
+ constructor(bridge: SyncBridge, pageId: number);
445
+ [customInspect$1](): string;
446
+ /** The parent BrowserContext that owns this page. */
447
+ get context(): BrowserContextSync;
448
+ go(url: string): void;
449
+ back(): void;
450
+ forward(): void;
451
+ reload(): void;
452
+ url(): string;
453
+ title(): string;
454
+ content(): string;
455
+ find(selector: string | SelectorOptions, options?: FindOptions): ElementSync;
456
+ findAll(selector: string | SelectorOptions, options?: FindOptions): ElementSync[];
457
+ /** Capture namespace — set up a listener before performing an action. */
458
+ get capture(): {
459
+ response(pattern: string, fn?: () => void, options?: {
460
+ timeout?: number;
461
+ }): {
462
+ url: string;
463
+ status: number;
464
+ headers: Record<string, string>;
465
+ body: string | null;
466
+ };
467
+ request(pattern: string, fn?: () => void, options?: {
468
+ timeout?: number;
469
+ }): {
470
+ url: string;
471
+ method: string;
472
+ headers: Record<string, string>;
473
+ postData: string | null;
474
+ };
475
+ navigation(fn?: () => void, options?: {
476
+ timeout?: number;
477
+ }): {
478
+ url: string;
479
+ };
480
+ download(fn?: () => void, options?: {
481
+ timeout?: number;
482
+ }): DownloadData;
483
+ dialog(fn?: () => void, options?: {
484
+ timeout?: number;
485
+ }): {
486
+ type: string;
487
+ message: string;
488
+ defaultValue: string;
489
+ };
490
+ event(name: string, fn?: () => void, options?: {
491
+ timeout?: number;
492
+ }): unknown;
493
+ };
494
+ /** Wait until a condition is met. Callable with a function, or use .url() / .loaded() sub-methods. */
495
+ readonly waitUntil: ((fn: string, options?: {
496
+ timeout?: number;
497
+ }) => unknown) & {
498
+ url(pattern: string, options?: {
499
+ timeout?: number;
500
+ }): void;
501
+ loaded(state?: string, options?: {
502
+ timeout?: number;
503
+ }): void;
504
+ };
505
+ wait(ms: number): void;
506
+ screenshot(options?: ScreenshotOptions): Buffer;
507
+ pdf(): Buffer;
508
+ evaluate<T = unknown>(expression: string): T;
509
+ addScript(source: string): void;
510
+ addStyle(source: string): void;
511
+ expose(name: string, fn: string): void;
512
+ bringToFront(): void;
513
+ close(): void;
514
+ scroll(direction?: string, amount?: number, selector?: string): void;
515
+ setViewport(size: {
516
+ width: number;
517
+ height: number;
518
+ }): void;
519
+ viewport(): {
520
+ width: number;
521
+ height: number;
522
+ };
523
+ emulateMedia(opts: {
524
+ media?: 'screen' | 'print' | null;
525
+ colorScheme?: 'light' | 'dark' | 'no-preference' | null;
526
+ reducedMotion?: 'reduce' | 'no-preference' | null;
527
+ forcedColors?: 'active' | 'none' | null;
528
+ contrast?: 'more' | 'no-preference' | null;
529
+ }): void;
530
+ setContent(html: string): void;
531
+ setGeolocation(coords: {
532
+ latitude: number;
533
+ longitude: number;
534
+ accuracy?: number;
535
+ }): void;
536
+ setWindow(options: {
537
+ width?: number;
538
+ height?: number;
539
+ x?: number;
540
+ y?: number;
541
+ state?: 'normal' | 'maximized' | 'minimized' | 'fullscreen';
542
+ }): void;
543
+ window(): {
544
+ state: string;
545
+ width: number;
546
+ height: number;
547
+ x: number;
548
+ y: number;
549
+ };
550
+ frames(): PageSync[];
551
+ frame(nameOrUrl: string): PageSync | null;
552
+ mainFrame(): PageSync;
553
+ a11yTree(options?: {
554
+ everything?: boolean;
555
+ root?: string;
556
+ }): A11yNode;
557
+ route(pattern: string, action: 'continue' | 'abort' | {
558
+ status?: number;
559
+ body?: string;
560
+ headers?: Record<string, string>;
561
+ } | ((route: RouteSync) => void)): void;
562
+ unroute(pattern: string): void;
563
+ setHeaders(headers: Record<string, string>): void;
564
+ onDialog(action: 'accept' | 'dismiss' | ((dialog: DialogSync) => void)): void;
565
+ onConsole(mode: 'collect'): void;
566
+ consoleMessages(): {
567
+ type: string;
568
+ text: string;
569
+ }[];
570
+ onError(mode: 'collect'): void;
571
+ errors(): {
572
+ message: string;
573
+ }[];
574
+ onRequest(fn: (req: RequestData) => void): void;
575
+ onResponse(fn: (resp: ResponseData) => void): void;
576
+ onDownload(fn: (dl: DownloadData) => void): void;
577
+ onWebSocket(fn: (ws: WebSocketInfoSync) => void): void;
578
+ removeAllListeners(event?: 'request' | 'response' | 'dialog' | 'console' | 'error' | 'download' | 'websocket'): void;
579
+ }
580
+
581
+ declare const customInspect: unique symbol;
582
+ interface StartOptions {
583
+ headless?: boolean;
584
+ headers?: Record<string, string>;
585
+ }
586
+ declare class BrowserSync {
587
+ /** @internal */
588
+ readonly _bridge: SyncBridge;
589
+ private _nextHandlerId;
590
+ private _pageHandlerId?;
591
+ private _popupHandlerId?;
592
+ constructor(bridge: SyncBridge);
593
+ [customInspect](): string;
594
+ page(): PageSync;
595
+ newPage(): PageSync;
596
+ pages(): PageSync[];
597
+ newContext(): BrowserContextSync;
598
+ waitForPage(options?: {
599
+ timeout?: number;
600
+ }): PageSync;
601
+ waitForPopup(options?: {
602
+ timeout?: number;
603
+ }): PageSync;
604
+ onPage(callback: (page: PageSync) => void): void;
605
+ onPopup(callback: (page: PageSync) => void): void;
606
+ removeAllListeners(event?: 'page' | 'popup'): void;
607
+ stop(): void;
608
+ }
609
+ declare const browser: {
610
+ start(urlOrOptions?: string | StartOptions, options?: StartOptions): BrowserSync;
611
+ };
612
+
613
+ export { BrowserContextSync, BrowserSync, ClockSync, DialogSync, DownloadData, ElementSync, KeyboardSync, MouseSync, PageSync, RecordingSync, type RequestData, type ResponseData, RouteSync, type StartOptions, TouchSync, WebSocketInfoSync, browser };