import type { CommonAction, Page } from "@iflyrpa/share"; import { type Element } from "domhandler"; /** * 生成两数之间的随机整数 * @param min * @param max * @returns */ export declare function getRandomInRange(min: number, max: number): number; export declare const getFileState: (filePath: string) => { name: string; type: string | false; size: number; lastModifiedDate: string; }; export type AspectRatio = [number, number]; export type CropCoordinates = { x1: number; y1: number; x2: number; y2: number; }; /** * 获取特定的比例切割图片,获取切割的坐标 * @param width 图片长度 * @param height 图片高度 * @param aspectRatio 切割比例:[宽度,高度] * @returns */ export declare const calculateCropCoordinates: (width: number, height: number, aspectRatio: AspectRatio) => CropCoordinates; export declare const extractImgTag: (html: string) => string[]; /** * 格式化 HTML 内容,删除无效的 section(没有 img 或 img src 为空) * @param html */ export declare const formatSectionHtml: (html: string) => string; /** * 时间格式化 * @param time * @param format 默认 yyyy-MM-dd HH:mm * @returns 时间字符串 */ export declare namespace TimeFormatter { function format(timestamp: number, formatStr?: string): string; } export declare const replaceImgSrc: (html: string, callback: (dom: Element) => Element) => string; export declare const stringifyError: (error: unknown) => {} | undefined; /** * 创建一个函数,该函数会依次执行传入的函数列表,直到有一个函数成功或所有函数都失败。 * * @template P - 函数的参数类型,为一个任意长度的数组。 * @template T - 函数的返回类型,为一个 Promise 的解析值类型。 * @param {CommonAction
[]} actions - 一个函数列表,每个函数的类型为 `(...p: P) => Promise } - 返回一个新的函数,其类型与传入的函数列表中的函数类型相同。
* 当调用该函数时,会依次执行 `actions` 中的函数,直到有一个函数成功(即返回一个解析的 Promise),
* 或者所有函数都失败(即抛出异常)。如果所有函数都失败,则抛出最后一个错误。
*
* @example
* const action1 = async (num) => {
* if (num > 0) return "Action 1 succeeded";
* throw new Error("Action 1 failed");
* };
*
* const action2 = async (num) => {
* if (num > 1) return "Action 2 succeeded";
* throw new Error("Action 2 failed");
* };
*
* const combinedAction = executeAction(action1, action2);
*
* (async () => {
* try {
* const result = await combinedAction(1);
* console.log(result); // 输出: "Action 2 succeeded"
* } catch (error) {
* console.error(error.message);
* }
* })();
*/
export declare const executeAction: (...actions: CommonAction []) => CommonAction ;
/**
* 将 HTML 内容复制到剪贴板
* @param page - 页面对象
* @param html - HTML 内容
* @param options - 选项,包括格式和回退
* @returns 无返回值
*/
export declare function copyHtmlToClipboard(page: Page, html: string, options?: {
format: string;
fallback: boolean;
}): Promise >(params: P, defaults: Partial ) => P;