// Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import * as js from './javascript'; import { helper } from './helper'; type Boxed = { [Index in keyof Args]: Args[Index] | js.JSHandle }; type PageFunction = string | ((...args: Args) => R | Promise); type PageFunctionOn = string | ((on: On, ...args: Args) => R | Promise); export type Evaluate = (pageFunction: PageFunction, ...args: Boxed) => Promise; export type EvaluateHandle = (pageFunction: PageFunction, ...args: Boxed) => Promise; export type $Eval = (selector: S, pageFunction: PageFunctionOn, ...args: Boxed) => Promise; export type $$Eval = (selector: S, pageFunction: PageFunctionOn, ...args: Boxed) => Promise; export type EvaluateOn = (pageFunction: PageFunctionOn, ...args: Boxed) => Promise; export type EvaluateHandleOn = (pageFunction: PageFunctionOn, ...args: Boxed) => Promise; export type Rect = { x: number, y: number, width: number, height: number }; export type Point = { x: number, y: number }; export type Quad = [ Point, Point, Point, Point ]; export type TimeoutOptions = { timeout?: number }; export type Selector = { selector: string, visible?: boolean }; export type Polling = 'raf' | 'mutation' | number; export type WaitForFunctionOptions = TimeoutOptions & { polling?: Polling }; export function selectorToString(selector: string | Selector): string { if (typeof selector === 'string') return selector; return `${selector.visible ? '[visible] ' : selector.visible === false ? '[hidden] ' : ''}${selector.selector}`; } // Ensures that we don't use accidental properties in selector, e.g. scope. export function clearSelector(selector: string | Selector): string | Selector { if (helper.isString(selector)) return selector; return { selector: selector.selector, visible: selector.visible }; }