Current section
Files
Jump to
Current section
Files
src/chrobot_extra/protocol/input.gleam
//// > ⚙️ This module was generated from the Chrome DevTools Protocol version **1.3**
//// ## Input Domain
////
//// This protocol domain has no description.
////
//// [📖 View this domain on the DevTools Protocol API Docs](https://chromedevtools.github.io/devtools-protocol/1-3/Input/)
// ---------------------------------------------------------------------------
// | !!!!!! This is an autogenerated file - Do not edit manually !!!!!! |
// | Run `codegen.sh` to regenerate. |
// ---------------------------------------------------------------------------
import chrobot_extra/internal/utils
import gleam/dynamic/decode
import gleam/json
import gleam/option
pub type TouchPoint {
TouchPoint(
/// X coordinate of the event relative to the main frame's viewport in CSS pixels.
x: Float,
/// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to
/// the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
y: Float,
/// X radius of the touch area (default: 1.0).
radius_x: option.Option(Float),
/// Y radius of the touch area (default: 1.0).
radius_y: option.Option(Float),
/// Rotation angle (default: 0.0).
rotation_angle: option.Option(Float),
/// Force (default: 1.0).
force: option.Option(Float),
/// The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range [-90,90], a positive tiltX is to the right (default: 0)
tilt_x: option.Option(Float),
/// The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range [-90,90], a positive tiltY is towards the user (default: 0).
tilt_y: option.Option(Float),
/// Identifier used to track touch sources between events, must be unique within an event.
id: option.Option(Float),
)
}
@internal
pub fn encode__touch_point(value__: TouchPoint) {
json.object(
[
#("x", json.float(value__.x)),
#("y", json.float(value__.y)),
]
|> utils.add_optional(value__.radius_x, fn(inner_value__) {
#("radiusX", json.float(inner_value__))
})
|> utils.add_optional(value__.radius_y, fn(inner_value__) {
#("radiusY", json.float(inner_value__))
})
|> utils.add_optional(value__.rotation_angle, fn(inner_value__) {
#("rotationAngle", json.float(inner_value__))
})
|> utils.add_optional(value__.force, fn(inner_value__) {
#("force", json.float(inner_value__))
})
|> utils.add_optional(value__.tilt_x, fn(inner_value__) {
#("tiltX", json.float(inner_value__))
})
|> utils.add_optional(value__.tilt_y, fn(inner_value__) {
#("tiltY", json.float(inner_value__))
})
|> utils.add_optional(value__.id, fn(inner_value__) {
#("id", json.float(inner_value__))
}),
)
}
@internal
pub fn decode__touch_point() {
{
use x <- decode.field("x", decode.float)
use y <- decode.field("y", decode.float)
use radius_x <- decode.optional_field(
"radiusX",
option.None,
decode.optional(decode.float),
)
use radius_y <- decode.optional_field(
"radiusY",
option.None,
decode.optional(decode.float),
)
use rotation_angle <- decode.optional_field(
"rotationAngle",
option.None,
decode.optional(decode.float),
)
use force <- decode.optional_field(
"force",
option.None,
decode.optional(decode.float),
)
use tilt_x <- decode.optional_field(
"tiltX",
option.None,
decode.optional(decode.float),
)
use tilt_y <- decode.optional_field(
"tiltY",
option.None,
decode.optional(decode.float),
)
use id <- decode.optional_field(
"id",
option.None,
decode.optional(decode.float),
)
decode.success(TouchPoint(
x: x,
y: y,
radius_x: radius_x,
radius_y: radius_y,
rotation_angle: rotation_angle,
force: force,
tilt_x: tilt_x,
tilt_y: tilt_y,
id: id,
))
}
}
pub type MouseButton {
MouseButtonNone
MouseButtonLeft
MouseButtonMiddle
MouseButtonRight
MouseButtonBack
MouseButtonForward
}
@internal
pub fn encode__mouse_button(value__: MouseButton) {
case value__ {
MouseButtonNone -> "none"
MouseButtonLeft -> "left"
MouseButtonMiddle -> "middle"
MouseButtonRight -> "right"
MouseButtonBack -> "back"
MouseButtonForward -> "forward"
}
|> json.string()
}
@internal
pub fn decode__mouse_button() {
{
use value__ <- decode.then(decode.string)
case value__ {
"none" -> decode.success(MouseButtonNone)
"left" -> decode.success(MouseButtonLeft)
"middle" -> decode.success(MouseButtonMiddle)
"right" -> decode.success(MouseButtonRight)
"back" -> decode.success(MouseButtonBack)
"forward" -> decode.success(MouseButtonForward)
_ -> decode.failure(MouseButtonNone, "valid enum property")
}
}
}
/// UTC time in seconds, counted from January 1, 1970.
pub type TimeSinceEpoch {
TimeSinceEpoch(Float)
}
@internal
pub fn encode__time_since_epoch(value__: TimeSinceEpoch) {
case value__ {
TimeSinceEpoch(inner_value__) -> json.float(inner_value__)
}
}
@internal
pub fn decode__time_since_epoch() {
{
use value__ <- decode.then(decode.float)
decode.success(TimeSinceEpoch(value__))
}
}
/// Dispatches a key event to the page.
///
/// Parameters:
/// - `type_` : Type of the key event.
/// - `modifiers` : Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
/// (default: 0).
/// - `timestamp` : Time at which the event occurred.
/// - `text` : Text as generated by processing a virtual key code with a keyboard layout. Not needed for
/// for `keyUp` and `rawKeyDown` events (default: "")
/// - `unmodified_text` : Text that would have been generated by the keyboard if no modifiers were pressed (except for
/// shift). Useful for shortcut (accelerator) key handling (default: "").
/// - `key_identifier` : Unique key identifier (e.g., 'U+0041') (default: "").
/// - `code` : Unique DOM defined string value for each physical key (e.g., 'KeyA') (default: "").
/// - `key` : Unique DOM defined string value describing the meaning of the key in the context of active
/// modifiers, keyboard layout, etc (e.g., 'AltGr') (default: "").
/// - `windows_virtual_key_code` : Windows virtual key code (default: 0).
/// - `native_virtual_key_code` : Native virtual key code (default: 0).
/// - `auto_repeat` : Whether the event was generated from auto repeat (default: false).
/// - `is_keypad` : Whether the event was generated from the keypad (default: false).
/// - `is_system_key` : Whether the event was a system key event (default: false).
/// - `location` : Whether the event was from the left or right side of the keyboard. 1=Left, 2=Right (default:
/// 0).
///
/// Returns:
///
pub fn dispatch_key_event(
callback__,
type_ type_: DispatchKeyEventType,
modifiers modifiers: option.Option(Int),
timestamp timestamp: option.Option(TimeSinceEpoch),
text text: option.Option(String),
unmodified_text unmodified_text: option.Option(String),
key_identifier key_identifier: option.Option(String),
code code: option.Option(String),
key key: option.Option(String),
windows_virtual_key_code windows_virtual_key_code: option.Option(Int),
native_virtual_key_code native_virtual_key_code: option.Option(Int),
auto_repeat auto_repeat: option.Option(Bool),
is_keypad is_keypad: option.Option(Bool),
is_system_key is_system_key: option.Option(Bool),
location location: option.Option(Int),
) {
callback__(
"Input.dispatchKeyEvent",
option.Some(json.object(
[
#("type", encode__dispatch_key_event_type(type_)),
]
|> utils.add_optional(modifiers, fn(inner_value__) {
#("modifiers", json.int(inner_value__))
})
|> utils.add_optional(timestamp, fn(inner_value__) {
#("timestamp", encode__time_since_epoch(inner_value__))
})
|> utils.add_optional(text, fn(inner_value__) {
#("text", json.string(inner_value__))
})
|> utils.add_optional(unmodified_text, fn(inner_value__) {
#("unmodifiedText", json.string(inner_value__))
})
|> utils.add_optional(key_identifier, fn(inner_value__) {
#("keyIdentifier", json.string(inner_value__))
})
|> utils.add_optional(code, fn(inner_value__) {
#("code", json.string(inner_value__))
})
|> utils.add_optional(key, fn(inner_value__) {
#("key", json.string(inner_value__))
})
|> utils.add_optional(windows_virtual_key_code, fn(inner_value__) {
#("windowsVirtualKeyCode", json.int(inner_value__))
})
|> utils.add_optional(native_virtual_key_code, fn(inner_value__) {
#("nativeVirtualKeyCode", json.int(inner_value__))
})
|> utils.add_optional(auto_repeat, fn(inner_value__) {
#("autoRepeat", json.bool(inner_value__))
})
|> utils.add_optional(is_keypad, fn(inner_value__) {
#("isKeypad", json.bool(inner_value__))
})
|> utils.add_optional(is_system_key, fn(inner_value__) {
#("isSystemKey", json.bool(inner_value__))
})
|> utils.add_optional(location, fn(inner_value__) {
#("location", json.int(inner_value__))
}),
)),
)
}
/// This type is not part of the protocol spec, it has been generated dynamically
/// to represent the possible values of the enum property `type` of `dispatchKeyEvent`
pub type DispatchKeyEventType {
DispatchKeyEventTypeKeyDown
DispatchKeyEventTypeKeyUp
DispatchKeyEventTypeRawKeyDown
DispatchKeyEventTypeChar
}
@internal
pub fn encode__dispatch_key_event_type(value__: DispatchKeyEventType) {
case value__ {
DispatchKeyEventTypeKeyDown -> "keyDown"
DispatchKeyEventTypeKeyUp -> "keyUp"
DispatchKeyEventTypeRawKeyDown -> "rawKeyDown"
DispatchKeyEventTypeChar -> "char"
}
|> json.string()
}
@internal
pub fn decode__dispatch_key_event_type() {
{
use value__ <- decode.then(decode.string)
case value__ {
"keyDown" -> decode.success(DispatchKeyEventTypeKeyDown)
"keyUp" -> decode.success(DispatchKeyEventTypeKeyUp)
"rawKeyDown" -> decode.success(DispatchKeyEventTypeRawKeyDown)
"char" -> decode.success(DispatchKeyEventTypeChar)
_ -> decode.failure(DispatchKeyEventTypeKeyDown, "valid enum property")
}
}
}
/// Dispatches a mouse event to the page.
///
/// Parameters:
/// - `type_` : Type of the mouse event.
/// - `x` : X coordinate of the event relative to the main frame's viewport in CSS pixels.
/// - `y` : Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to
/// the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
/// - `modifiers` : Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
/// (default: 0).
/// - `timestamp` : Time at which the event occurred.
/// - `button` : Mouse button (default: "none").
/// - `buttons` : A number indicating which buttons are pressed on the mouse when a mouse event is triggered.
/// Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.
/// - `click_count` : Number of times the mouse button was clicked (default: 0).
/// - `tilt_x` : The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range [-90,90], a positive tiltX is to the right (default: 0).
/// - `tilt_y` : The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range [-90,90], a positive tiltY is towards the user (default: 0).
/// - `delta_x` : X delta in CSS pixels for mouse wheel event (default: 0).
/// - `delta_y` : Y delta in CSS pixels for mouse wheel event (default: 0).
/// - `pointer_type` : Pointer type (default: "mouse").
///
/// Returns:
///
pub fn dispatch_mouse_event(
callback__,
type_ type_: DispatchMouseEventType,
x x: Float,
y y: Float,
modifiers modifiers: option.Option(Int),
timestamp timestamp: option.Option(TimeSinceEpoch),
button button: option.Option(MouseButton),
buttons buttons: option.Option(Int),
click_count click_count: option.Option(Int),
tilt_x tilt_x: option.Option(Float),
tilt_y tilt_y: option.Option(Float),
delta_x delta_x: option.Option(Float),
delta_y delta_y: option.Option(Float),
pointer_type pointer_type: option.Option(DispatchMouseEventPointerType),
) {
callback__(
"Input.dispatchMouseEvent",
option.Some(json.object(
[
#("type", encode__dispatch_mouse_event_type(type_)),
#("x", json.float(x)),
#("y", json.float(y)),
]
|> utils.add_optional(modifiers, fn(inner_value__) {
#("modifiers", json.int(inner_value__))
})
|> utils.add_optional(timestamp, fn(inner_value__) {
#("timestamp", encode__time_since_epoch(inner_value__))
})
|> utils.add_optional(button, fn(inner_value__) {
#("button", encode__mouse_button(inner_value__))
})
|> utils.add_optional(buttons, fn(inner_value__) {
#("buttons", json.int(inner_value__))
})
|> utils.add_optional(click_count, fn(inner_value__) {
#("clickCount", json.int(inner_value__))
})
|> utils.add_optional(tilt_x, fn(inner_value__) {
#("tiltX", json.float(inner_value__))
})
|> utils.add_optional(tilt_y, fn(inner_value__) {
#("tiltY", json.float(inner_value__))
})
|> utils.add_optional(delta_x, fn(inner_value__) {
#("deltaX", json.float(inner_value__))
})
|> utils.add_optional(delta_y, fn(inner_value__) {
#("deltaY", json.float(inner_value__))
})
|> utils.add_optional(pointer_type, fn(inner_value__) {
#(
"pointerType",
encode__dispatch_mouse_event_pointer_type(inner_value__),
)
}),
)),
)
}
/// This type is not part of the protocol spec, it has been generated dynamically
/// to represent the possible values of the enum property `type` of `dispatchMouseEvent`
pub type DispatchMouseEventType {
DispatchMouseEventTypeMousePressed
DispatchMouseEventTypeMouseReleased
DispatchMouseEventTypeMouseMoved
DispatchMouseEventTypeMouseWheel
}
@internal
pub fn encode__dispatch_mouse_event_type(value__: DispatchMouseEventType) {
case value__ {
DispatchMouseEventTypeMousePressed -> "mousePressed"
DispatchMouseEventTypeMouseReleased -> "mouseReleased"
DispatchMouseEventTypeMouseMoved -> "mouseMoved"
DispatchMouseEventTypeMouseWheel -> "mouseWheel"
}
|> json.string()
}
@internal
pub fn decode__dispatch_mouse_event_type() {
{
use value__ <- decode.then(decode.string)
case value__ {
"mousePressed" -> decode.success(DispatchMouseEventTypeMousePressed)
"mouseReleased" -> decode.success(DispatchMouseEventTypeMouseReleased)
"mouseMoved" -> decode.success(DispatchMouseEventTypeMouseMoved)
"mouseWheel" -> decode.success(DispatchMouseEventTypeMouseWheel)
_ ->
decode.failure(
DispatchMouseEventTypeMousePressed,
"valid enum property",
)
}
}
}
/// This type is not part of the protocol spec, it has been generated dynamically
/// to represent the possible values of the enum property `pointerType` of `dispatchMouseEvent`
pub type DispatchMouseEventPointerType {
DispatchMouseEventPointerTypeMouse
DispatchMouseEventPointerTypePen
}
@internal
pub fn encode__dispatch_mouse_event_pointer_type(
value__: DispatchMouseEventPointerType,
) {
case value__ {
DispatchMouseEventPointerTypeMouse -> "mouse"
DispatchMouseEventPointerTypePen -> "pen"
}
|> json.string()
}
@internal
pub fn decode__dispatch_mouse_event_pointer_type() {
{
use value__ <- decode.then(decode.string)
case value__ {
"mouse" -> decode.success(DispatchMouseEventPointerTypeMouse)
"pen" -> decode.success(DispatchMouseEventPointerTypePen)
_ ->
decode.failure(
DispatchMouseEventPointerTypeMouse,
"valid enum property",
)
}
}
}
/// Dispatches a touch event to the page.
///
/// Parameters:
/// - `type_` : Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while
/// TouchStart and TouchMove must contains at least one.
/// - `touch_points` : Active touch points on the touch device. One event per any changed point (compared to
/// previous touch event in a sequence) is generated, emulating pressing/moving/releasing points
/// one by one.
/// - `modifiers` : Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
/// (default: 0).
/// - `timestamp` : Time at which the event occurred.
///
/// Returns:
///
pub fn dispatch_touch_event(
callback__,
type_ type_: DispatchTouchEventType,
touch_points touch_points: List(TouchPoint),
modifiers modifiers: option.Option(Int),
timestamp timestamp: option.Option(TimeSinceEpoch),
) {
callback__(
"Input.dispatchTouchEvent",
option.Some(json.object(
[
#("type", encode__dispatch_touch_event_type(type_)),
#("touchPoints", json.array(touch_points, of: encode__touch_point)),
]
|> utils.add_optional(modifiers, fn(inner_value__) {
#("modifiers", json.int(inner_value__))
})
|> utils.add_optional(timestamp, fn(inner_value__) {
#("timestamp", encode__time_since_epoch(inner_value__))
}),
)),
)
}
/// This type is not part of the protocol spec, it has been generated dynamically
/// to represent the possible values of the enum property `type` of `dispatchTouchEvent`
pub type DispatchTouchEventType {
DispatchTouchEventTypeTouchStart
DispatchTouchEventTypeTouchEnd
DispatchTouchEventTypeTouchMove
DispatchTouchEventTypeTouchCancel
}
@internal
pub fn encode__dispatch_touch_event_type(value__: DispatchTouchEventType) {
case value__ {
DispatchTouchEventTypeTouchStart -> "touchStart"
DispatchTouchEventTypeTouchEnd -> "touchEnd"
DispatchTouchEventTypeTouchMove -> "touchMove"
DispatchTouchEventTypeTouchCancel -> "touchCancel"
}
|> json.string()
}
@internal
pub fn decode__dispatch_touch_event_type() {
{
use value__ <- decode.then(decode.string)
case value__ {
"touchStart" -> decode.success(DispatchTouchEventTypeTouchStart)
"touchEnd" -> decode.success(DispatchTouchEventTypeTouchEnd)
"touchMove" -> decode.success(DispatchTouchEventTypeTouchMove)
"touchCancel" -> decode.success(DispatchTouchEventTypeTouchCancel)
_ ->
decode.failure(DispatchTouchEventTypeTouchStart, "valid enum property")
}
}
}
/// Cancels any active dragging in the page.
///
pub fn cancel_dragging(callback__) {
callback__("Input.cancelDragging", option.None)
}
/// Ignores input events (useful while auditing page).
///
/// Parameters:
/// - `ignore` : Ignores input events processing when set to true.
///
/// Returns:
///
pub fn set_ignore_input_events(callback__, ignore ignore: Bool) {
callback__(
"Input.setIgnoreInputEvents",
option.Some(
json.object([
#("ignore", json.bool(ignore)),
]),
),
)
}