"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    normalizeMobileSwipeParam: ()=>normalizeMobileSwipeParam,
    ActionLongPressParamSchema: ()=>ActionLongPressParamSchema,
    ActionSleepParamSchema: ()=>ActionSleepParamSchema,
    actionScrollParamSchema: ()=>actionScrollParamSchema,
    defineActionDragAndDrop: ()=>defineActionDragAndDrop,
    actionRightClickParamSchema: ()=>actionRightClickParamSchema,
    defineActionDoubleClick: ()=>defineActionDoubleClick,
    actionInputParamSchema: ()=>actionInputParamSchema,
    actionKeyboardPressParamSchema: ()=>actionKeyboardPressParamSchema,
    AbstractInterface: ()=>AbstractInterface,
    actionClearInputParamSchema: ()=>actionClearInputParamSchema,
    actionHoverParamSchema: ()=>actionHoverParamSchema,
    ActionSwipeParamSchema: ()=>ActionSwipeParamSchema,
    defineActionScroll: ()=>defineActionScroll,
    defineActionClearInput: ()=>defineActionClearInput,
    defineActionTap: ()=>defineActionTap,
    actionCursorMoveParamSchema: ()=>actionCursorMoveParamSchema,
    defineActionLongPress: ()=>defineActionLongPress,
    defineActionSleep: ()=>defineActionSleep,
    defineActionSwipe: ()=>defineActionSwipe,
    actionDoubleClickParamSchema: ()=>actionDoubleClickParamSchema,
    actionTapParamSchema: ()=>actionTapParamSchema,
    defineActionHover: ()=>defineActionHover,
    defineActionInput: ()=>defineActionInput,
    defineAction: ()=>defineAction,
    actionDragAndDropParamSchema: ()=>actionDragAndDropParamSchema,
    defineActionRightClick: ()=>defineActionRightClick,
    defineActionCursorMove: ()=>defineActionCursorMove,
    defineActionKeyboardPress: ()=>defineActionKeyboardPress
});
const external_common_js_namespaceObject = require("../common.js");
const logger_namespaceObject = require("@midscene/shared/logger");
const external_zod_namespaceObject = require("zod");
function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
class AbstractInterface {
    constructor(){
        _define_property(this, "mjpegStreamUrl", void 0);
    }
}
const defineAction = (config)=>config;
const actionTapParamSchema = external_zod_namespaceObject.z.object({
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The element to be tapped')
});
const defineActionTap = (call)=>defineAction({
        name: 'Tap',
        description: 'Tap the element',
        interfaceAlias: 'aiTap',
        paramSchema: actionTapParamSchema,
        call
    });
const actionRightClickParamSchema = external_zod_namespaceObject.z.object({
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The element to be right clicked')
});
const defineActionRightClick = (call)=>defineAction({
        name: 'RightClick',
        description: 'Right click the element',
        interfaceAlias: 'aiRightClick',
        paramSchema: actionRightClickParamSchema,
        call
    });
const actionDoubleClickParamSchema = external_zod_namespaceObject.z.object({
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The element to be double clicked')
});
const defineActionDoubleClick = (call)=>defineAction({
        name: 'DoubleClick',
        description: 'Double click the element',
        interfaceAlias: 'aiDoubleClick',
        paramSchema: actionDoubleClickParamSchema,
        call
    });
const actionHoverParamSchema = external_zod_namespaceObject.z.object({
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The element to be hovered')
});
const defineActionHover = (call)=>defineAction({
        name: 'Hover',
        description: 'Move the mouse to the element',
        interfaceAlias: 'aiHover',
        paramSchema: actionHoverParamSchema,
        call
    });
const inputLocateDescription = 'the position of the placeholder or text content in the target input field. If there is no content, locate the center of the input field.';
const actionInputParamSchema = external_zod_namespaceObject.z.object({
    value: external_zod_namespaceObject.z.union([
        external_zod_namespaceObject.z.string(),
        external_zod_namespaceObject.z.number()
    ]).transform((val)=>String(val)).describe('The text to input. Provide the final content for replace/append modes, or an empty string when using clear mode to remove existing text.'),
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe(inputLocateDescription).optional(),
    mode: external_zod_namespaceObject.z["enum"]([
        'replace',
        'clear',
        'typeOnly'
    ]).default('replace').describe('Input mode: "replace" (default) - clear the field and input the value; "typeOnly" - type the value directly without clearing the field first; "clear" - clear the field without inputting new text.')
});
const defineActionInput = (call)=>defineAction({
        name: 'Input',
        description: 'Input the value into the element',
        interfaceAlias: 'aiInput',
        paramSchema: actionInputParamSchema,
        call: (param)=>{
            if ('append' === param.mode) param.mode = 'typeOnly';
            return call(param);
        }
    });
const actionKeyboardPressParamSchema = external_zod_namespaceObject.z.object({
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The element to be clicked before pressing the key').optional(),
    keyName: external_zod_namespaceObject.z.string().describe("The key to be pressed. Use '+' for key combinations, e.g., 'Control+A', 'Shift+Enter'")
});
const defineActionKeyboardPress = (call)=>defineAction({
        name: 'KeyboardPress',
        description: 'Press a key or key combination, like "Enter", "Tab", "Escape", or "Control+A", "Shift+Enter". Do not use this to type text.',
        interfaceAlias: 'aiKeyboardPress',
        paramSchema: actionKeyboardPressParamSchema,
        call
    });
const actionScrollParamSchema = external_zod_namespaceObject.z.object({
    scrollType: external_zod_namespaceObject.z["enum"]([
        'singleAction',
        'scrollToBottom',
        'scrollToTop',
        'scrollToRight',
        'scrollToLeft'
    ]).default('singleAction').describe('The scroll behavior: "singleAction" for a single scroll action, "scrollToBottom" for scrolling all the way to the bottom by rapidly scrolling 5-10 times (skipping intermediate content until reaching the bottom), "scrollToTop" for scrolling all the way to the top by rapidly scrolling 5-10 times (skipping intermediate content until reaching the top), "scrollToRight" for scrolling all the way to the right by rapidly scrolling multiple times, "scrollToLeft" for scrolling all the way to the left by rapidly scrolling multiple times'),
    direction: external_zod_namespaceObject.z["enum"]([
        'down',
        'up',
        'right',
        'left'
    ]).default('down').describe('The direction to scroll. Only effective when scrollType is "singleAction".'),
    distance: external_zod_namespaceObject.z.number().nullable().optional().describe('The distance in pixels to scroll'),
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().optional().describe('Describe the target element to be scrolled on, like "the table" or "the list" or "the content area" or "the scrollable area". Do NOT provide a general intent like "scroll to find some element"')
});
const defineActionScroll = (call)=>defineAction({
        name: 'Scroll',
        description: 'Scroll the page or a scrollable element to browse content. This is the preferred way to scroll on all platforms, including mobile. Supports scrollToBottom/scrollToTop for boundary navigation. Default: direction `down`, scrollType `singleAction`, distance `null`.',
        interfaceAlias: 'aiScroll',
        paramSchema: actionScrollParamSchema,
        call
    });
const actionDragAndDropParamSchema = external_zod_namespaceObject.z.object({
    from: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The position to be dragged'),
    to: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The position to be dropped')
});
const defineActionDragAndDrop = (call)=>defineAction({
        name: 'DragAndDrop',
        description: 'Pick up a specific UI element and move it to a new position (e.g., reorder a card, move a file into a folder, sort list items). The element itself moves with your finger/mouse.',
        interfaceAlias: 'aiDragAndDrop',
        paramSchema: actionDragAndDropParamSchema,
        call
    });
const ActionLongPressParamSchema = external_zod_namespaceObject.z.object({
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The element to be long pressed'),
    duration: external_zod_namespaceObject.z.number().default(500).optional().describe('Long press duration in milliseconds')
});
const defineActionLongPress = (call)=>defineAction({
        name: 'LongPress',
        description: 'Long press the element',
        paramSchema: ActionLongPressParamSchema,
        call
    });
const ActionSwipeParamSchema = external_zod_namespaceObject.z.object({
    start: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().optional().describe('Starting point of the swipe gesture, if not specified, the center of the page will be used'),
    direction: external_zod_namespaceObject.z["enum"]([
        'up',
        'down',
        'left',
        'right'
    ]).optional().describe('The direction to swipe (required when using distance). The direction means the direction of the finger swipe.'),
    distance: external_zod_namespaceObject.z.number().optional().describe('The distance in pixels to swipe (mutually exclusive with end)'),
    end: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().optional().describe('Ending point of the swipe gesture (mutually exclusive with distance)'),
    duration: external_zod_namespaceObject.z.number().default(300).describe('Duration of the swipe gesture in milliseconds'),
    repeat: external_zod_namespaceObject.z.number().optional().describe('The number of times to repeat the swipe gesture. 1 for default, 0 for infinite (e.g. endless swipe until the end of the page)')
});
function normalizeMobileSwipeParam(param, screenSize) {
    const { width, height } = screenSize;
    const { start, end } = param;
    const startPoint = start ? {
        x: start.center[0],
        y: start.center[1]
    } : {
        x: width / 2,
        y: height / 2
    };
    let endPoint;
    if (end) endPoint = {
        x: end.center[0],
        y: end.center[1]
    };
    else if (param.distance) {
        const direction = param.direction;
        if (!direction) throw new Error('direction is required for swipe gesture');
        endPoint = {
            x: startPoint.x + ('right' === direction ? param.distance : 'left' === direction ? -param.distance : 0),
            y: startPoint.y + ('down' === direction ? param.distance : 'up' === direction ? -param.distance : 0)
        };
    } else throw new Error('Either end or distance must be specified for swipe gesture');
    endPoint.x = Math.max(0, Math.min(endPoint.x, width));
    endPoint.y = Math.max(0, Math.min(endPoint.y, height));
    const duration = param.duration ?? 300;
    let repeatCount = 'number' == typeof param.repeat ? param.repeat : 1;
    if (0 === repeatCount) repeatCount = 10;
    return {
        startPoint,
        endPoint,
        duration,
        repeatCount
    };
}
const defineActionSwipe = (call)=>defineAction({
        name: 'Swipe',
        description: 'Perform a touch gesture for interactions beyond regular scrolling (e.g., flip pages in a carousel, dismiss a notification, swipe-to-delete a list item). For regular content scrolling, use Scroll instead. Use "distance" + "direction" for relative movement, or "end" for precise endpoint.',
        paramSchema: ActionSwipeParamSchema,
        call
    });
const actionClearInputParamSchema = external_zod_namespaceObject.z.object({
    locate: (0, external_common_js_namespaceObject.getMidsceneLocationSchema)().describe('The input field to be cleared').optional()
});
const defineActionClearInput = (call)=>defineAction({
        name: 'ClearInput',
        description: inputLocateDescription,
        interfaceAlias: 'aiClearInput',
        paramSchema: actionClearInputParamSchema,
        call
    });
const actionCursorMoveParamSchema = external_zod_namespaceObject.z.object({
    direction: external_zod_namespaceObject.z["enum"]([
        'left',
        'right'
    ]).describe('The direction to move the cursor'),
    times: external_zod_namespaceObject.z.number().int().min(1).default(1).describe('The number of times to move the cursor in the specified direction')
});
const defineActionCursorMove = (call)=>defineAction({
        name: 'CursorMove',
        description: 'Move the text cursor (caret) left or right within an input field or text area. Use this to reposition the cursor without selecting text.',
        paramSchema: actionCursorMoveParamSchema,
        call
    });
const ActionSleepParamSchema = external_zod_namespaceObject.z.object({
    timeMs: external_zod_namespaceObject.z.number().default(1000).optional().describe('Sleep duration in milliseconds, defaults to 1000ms (1 second)')
});
const defineActionSleep = ()=>defineAction({
        name: 'Sleep',
        description: 'Wait for a specified duration before continuing. Defaults to 1 second (1000ms) if not specified.',
        paramSchema: ActionSleepParamSchema,
        call: async (param)=>{
            const duration = param?.timeMs ?? 1000;
            (0, logger_namespaceObject.getDebug)('device:common-action')(`Sleeping for ${duration}ms`);
            await new Promise((resolve)=>setTimeout(resolve, duration));
        }
    });
exports.AbstractInterface = __webpack_exports__.AbstractInterface;
exports.ActionLongPressParamSchema = __webpack_exports__.ActionLongPressParamSchema;
exports.ActionSleepParamSchema = __webpack_exports__.ActionSleepParamSchema;
exports.ActionSwipeParamSchema = __webpack_exports__.ActionSwipeParamSchema;
exports.actionClearInputParamSchema = __webpack_exports__.actionClearInputParamSchema;
exports.actionCursorMoveParamSchema = __webpack_exports__.actionCursorMoveParamSchema;
exports.actionDoubleClickParamSchema = __webpack_exports__.actionDoubleClickParamSchema;
exports.actionDragAndDropParamSchema = __webpack_exports__.actionDragAndDropParamSchema;
exports.actionHoverParamSchema = __webpack_exports__.actionHoverParamSchema;
exports.actionInputParamSchema = __webpack_exports__.actionInputParamSchema;
exports.actionKeyboardPressParamSchema = __webpack_exports__.actionKeyboardPressParamSchema;
exports.actionRightClickParamSchema = __webpack_exports__.actionRightClickParamSchema;
exports.actionScrollParamSchema = __webpack_exports__.actionScrollParamSchema;
exports.actionTapParamSchema = __webpack_exports__.actionTapParamSchema;
exports.defineAction = __webpack_exports__.defineAction;
exports.defineActionClearInput = __webpack_exports__.defineActionClearInput;
exports.defineActionCursorMove = __webpack_exports__.defineActionCursorMove;
exports.defineActionDoubleClick = __webpack_exports__.defineActionDoubleClick;
exports.defineActionDragAndDrop = __webpack_exports__.defineActionDragAndDrop;
exports.defineActionHover = __webpack_exports__.defineActionHover;
exports.defineActionInput = __webpack_exports__.defineActionInput;
exports.defineActionKeyboardPress = __webpack_exports__.defineActionKeyboardPress;
exports.defineActionLongPress = __webpack_exports__.defineActionLongPress;
exports.defineActionRightClick = __webpack_exports__.defineActionRightClick;
exports.defineActionScroll = __webpack_exports__.defineActionScroll;
exports.defineActionSleep = __webpack_exports__.defineActionSleep;
exports.defineActionSwipe = __webpack_exports__.defineActionSwipe;
exports.defineActionTap = __webpack_exports__.defineActionTap;
exports.normalizeMobileSwipeParam = __webpack_exports__.normalizeMobileSwipeParam;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AbstractInterface",
    "ActionLongPressParamSchema",
    "ActionSleepParamSchema",
    "ActionSwipeParamSchema",
    "actionClearInputParamSchema",
    "actionCursorMoveParamSchema",
    "actionDoubleClickParamSchema",
    "actionDragAndDropParamSchema",
    "actionHoverParamSchema",
    "actionInputParamSchema",
    "actionKeyboardPressParamSchema",
    "actionRightClickParamSchema",
    "actionScrollParamSchema",
    "actionTapParamSchema",
    "defineAction",
    "defineActionClearInput",
    "defineActionCursorMove",
    "defineActionDoubleClick",
    "defineActionDragAndDrop",
    "defineActionHover",
    "defineActionInput",
    "defineActionKeyboardPress",
    "defineActionLongPress",
    "defineActionRightClick",
    "defineActionScroll",
    "defineActionSleep",
    "defineActionSwipe",
    "defineActionTap",
    "normalizeMobileSwipeParam"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});

//# sourceMappingURL=index.js.map