
    >i.p                        d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ er8d dlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# d dl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-  G d d      Z.y	)
    )annotations)TYPE_CHECKINGOptional)Command)DispatchDragEventParamsDispatchKeyEventParamsDispatchMouseEventParamsDispatchTouchEventParams EmulateTouchFromMouseEventParamsImeSetCompositionParamsInputMethodInsertTextParamsSetIgnoreInputEventsParamsSetInterceptDragsParamsSynthesizePinchGestureParamsSynthesizeScrollGestureParamsSynthesizeTapGestureParams)CancelDraggingCommandDispatchDragEventCommandDispatchKeyEventCommandDispatchMouseEventCommandDispatchTouchEventCommandDragData!EmulateTouchFromMouseEventCommandImeSetCompositionCommandInsertTextCommandSetIgnoreInputEventsCommandSetInterceptDragsCommandSynthesizePinchGestureCommandSynthesizeScrollGestureCommandSynthesizeTapGestureCommand
TouchPoint)	DragEventTypeGestureSourceTypeKeyEventTypeKeyLocationKeyModifierMouseButtonMouseEventTypePointerTypeTouchEventTypec                     e Zd ZdZedd       Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 	 	 	 	 dd       Zedd       Z	e	 d	 	 	 	 	 	 	 	 	 	 	 dd       Z
e	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	       Ze	 	 d	 	 	 	 	 	 	 	 	 	 	 dd
       Ze	 	 	 	 dd       Zedd       Ze	 	 d	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 	 	 	 	 	 d 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!d       Ze	 	 	 d"	 	 	 	 	 	 	 	 	 	 	 d#d       Zy)$InputCommandsa  
    A class for simulating user input events using Chrome DevTools Protocol.

    The Input domain provides methods for simulating user input, including:
    - Keyboard events (key presses, releases)
    - Mouse events (clicks, movements, wheel)
    - Touch events (taps, multi-touch gestures)
    - Drag and drop events
    - Synthetic gestures (pinch, scroll, tap)

    These methods allow for programmatic control of input events without requiring
    actual user interaction, making it useful for testing and automation.
    c                 6    t        t        j                        S )a7  
        Generates a command to cancel any active dragging in the page.

        This is useful when you need to interrupt an ongoing drag operation
        that might have been started with dispatchDragEvent or by other means.

        Returns:
            Command: The CDP command to cancel dragging.
        )method)r   r   CANCEL_DRAGGING     d/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/commands/input_commands.pycancel_draggingzInputCommands.cancel_draggingD   s     k99::r2   Nc                   t        |       }|||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d	<   |	|	|d
<   |
|
|d<   |||d<   |||d<   |||d<   |||d<   t        t        j                  |      S )a
  
        Generates a command to dispatch a key event to the page.

        This method can simulate various types of keyboard events such as key presses,
        key releases, and character inputs.

        Args:
            type: Type of the key event. Allowed values: keyDown, keyUp, rawKeyDown, char.
                 - keyDown: Corresponds to a user pressing a key
                 - keyUp: Corresponds to a user releasing a key
                 - rawKeyDown: A physical key press, without the text processing
                 - char: Generates a character without explicit key events
            modifiers: Bit field representing pressed modifier keys. Values:
                      Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
                      For example, to simulate Ctrl+Shift, use 10.
            timestamp: Time at which the event occurred, in seconds since epoch.
            text: Text as generated by processing a virtual key code with a keyboard layout.
                 Not needed for 'keyUp' and 'rawKeyDown' events (default: "").
            unmodified_text: Text that would have been generated by the keyboard without modifiers
                           (except for shift). Useful for shortcut 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:
                     0=Default, 1=Left, 2=Right (default: 0).
            commands: Editing commands to send with the key event (e.g., 'selectAll')
                     (default: []). These are related to but not equal to the command names
                     used in `document.execCommand` and NSStandardKeyBindingResponding.

        Returns:
            Command: The CDP command to dispatch the key event.
        )type	modifiers	timestamptextunmodifiedTextkeyIdentifiercodekeywindowsVirtualKeyCodenativeVirtualKeyCode
autoRepeatisKeypadisSystemKeylocationcommandsr/   params)r   r   r   DISPATCH_KEY_EVENT)r6   r7   r8   r9   unmodified_textkey_identifierr<   r=   windows_virtual_key_codenative_virtual_key_codeauto_repeat	is_keypadis_system_keyrC   rD   rF   s                   r3   dispatch_key_eventz InputCommands.dispatch_key_eventQ   s   t (T2 "+F; "+F;!F6N&'6F#$%&4F?#!F6N?F5M#/.FF*+".-DF)*"#.F<  !*F:$$1F=!!)F:!)F:k<<VLLr2   c                    t        | ||      }|||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |	|	|d<   |
|
|d	<   |||d
<   |||d<   |||d<   |||d<   t        t        j                  |      S )a-
  
        Generates a command to dispatch a mouse event to the page.

        This method allows simulating various mouse interactions such as clicks,
        movements, and wheel scrolling.

        Args:
            type: Type of the mouse event. Allowed values:
                 - mousePressed: Mouse button pressed
                 - mouseReleased: Mouse button released
                 - mouseMoved: Mouse moved
                 - mouseWheel: Mouse wheel rotated
            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 going down.
            modifiers: Bit field representing pressed modifier keys. Values:
                Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
            timestamp: Time at which the event occurred, in seconds since epoch.
            button: Mouse button being pressed/released. Default is "none".
                Allowed values: "none", "left", "middle", "right", "back", "forward".
            click_count: Number of times the mouse button was clicked (default: 0).
                For example, 2 for a double-click.
            force: The normalized pressure, which has a range of [0,1] (default: 0).
                Used primarily for pressure-sensitive inputs.
            tangential_pressure: The normalized tangential pressure, which has a range
                of [-1,1] (default: 0). Used for stylus input.
            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).
            twist: The clockwise rotation of a pen stylus around its own major axis,
                in degrees in the range [0,359] (default: 0).
            delta_x: X delta in CSS pixels for mouse wheel event (default: 0).
                Positive values scroll right.
            delta_y: Y delta in CSS pixels for mouse wheel event (default: 0).
                Positive values scroll up.
            pointer_type: Pointer type (default: "mouse"). Allowed values: "mouse", "pen".

        Returns:
            Command: The CDP command to dispatch the mouse event.
        )r6   xyr7   r8   button
clickCountforcetangentialPressuretiltXtiltYtwistdeltaXdeltaYpointerTyperE   )r	   r   r   DISPATCH_MOUSE_EVENT)r6   rQ   rR   r7   r8   rS   click_countrU   tangential_pressuretilt_xtilt_yrY   delta_xdelta_ypointer_typerF   s                   r3   dispatch_mouse_eventz"InputCommands.dispatch_mouse_event   s    z *tqA> "+F; "+F;%F8"#.F< #F7O*+>F'($F7O$F7O#F7O&F8&F8#$0F=!k>>vNNr2   c                n    t        | |      }|||d<   |||d<   t        t        j                  |      S )ad  
        Generates a command to dispatch a touch event to the page.

        This method allows simulating touch interactions on touch-enabled devices
        or emulated touch environments.

        Args:
            type: Type of the touch event. Allowed values:
                 - touchStart: Touch started - at least one point must be specified
                 - touchEnd: Touch ended - points that are no longer pressed should be removed
                 - touchMove: Touch moved - active points should be updated
                 - touchCancel: Touch canceled - clears all touch points
                 Touch end and cancel events must not contain any touch points,
                 while touch start and move must contain at least one.
            touch_points: list of active touch points. One event per any changed point
                        (compared to previous event) is generated, emulating
                        pressing/moving/releasing points one by one.
                        Each point includes coordinates and other properties.
            modifiers: Bit field representing pressed modifier keys. Values:
                      Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
            timestamp: Time at which the event occurred, in seconds since epoch.

        Returns:
            Command: The CDP command to dispatch the touch event.
        )r6   touchPointsr7   r8   rE   )r
   r   r   DISPATCH_TOUCH_EVENT)r6   touch_pointsr7   r8   rF   s        r3   dispatch_touch_eventz"InputCommands.dispatch_touch_event  sD    @ *tN "+F; "+F;k>>vNNr2   c                P    t        |       }t        t        j                  |      S )a  
        Generates a command to ignore input events (useful while auditing page).

        When ignore is true, all input events will be ignored, which can be useful
        during automated tests or when you want to prevent user interaction
        while performing certain operations.

        Args:
            ignore: If true, input events processing will be ignored.

        Returns:
            Command: The CDP command to set ignore input events.
        )ignorerE   )r   r   r   SET_IGNORE_INPUT_EVENTS)rl   rF   s     r3   set_ignore_input_eventsz%InputCommands.set_ignore_input_events)  s!     ,6:kAA&QQr2   c                d    t        | |||      }|||d<   t        t        j                  |      S )a  
        Generates a command to dispatch a drag event into the page.

        This experimental method allows simulating drag and drop operations
        by dispatching drag events at specific coordinates.

        Args:
            type: Type of the drag event. Allowed values:
                 - dragEnter: Fired when a dragged item enters a valid drop target
                 - dragOver: Fired when a dragged item is being dragged over a valid drop target
                 - drop: Fired when an item is dropped on a valid drop target
                 - dragCancel: Fired when a drag operation is being canceled
            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 going down.
            data: Drag data containing items being dragged, their MIME types, and other information.
            modifiers: Bit field representing pressed modifier keys. Values:
                      Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).

        Returns:
            Command: The CDP command to dispatch the drag event.
        )r6   datarQ   rR   r7   rE   )r   r   r   DISPATCH_DRAG_EVENT)r6   rQ   rR   rp   r7   rF   s         r3   dispatch_drag_eventz!InputCommands.dispatch_drag_event;  s7    < )daH "+F;k==fMMr2   c	                    t        | |||      }	|||	d<   |||	d<   |||	d<   |||	d<   |||	d<   t        t        j                  |	      S )a  
        Generates a command to emulate touch event from the mouse event parameters.

        This experimental method allows converting mouse events into touch events,
        useful for testing touch interactions in environments where touch is not available.

        Args:
            type: Type of the mouse event to convert. Allowed values:
                 - mousePressed: Converted to touchStart
                 - mouseReleased: Converted to touchEnd
                 - mouseMoved: Converted to touchMove
                 - mouseWheel: May trigger scrolling
            x: X coordinate of the mouse pointer in device-independent pixels (DIP).
            y: Y coordinate of the mouse pointer in DIP.
            button: Mouse button. Only "none", "left", "right" are supported.
            timestamp: Time at which the event occurred, in seconds since epoch.
                      Default is current time.
            delta_x: X delta in DIP for mouse wheel event (default: 0). Used for scrolling.
            delta_y: Y delta in DIP for mouse wheel event (default: 0). Used for scrolling.
            modifiers: Bit field representing pressed modifier keys. Values:
                      Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
            click_count: Number of times the mouse button was clicked (default: 0).
                       For example, 2 for a double-click.

        Returns:
            Command: The CDP command to emulate touch from mouse event.
        )r6   rQ   rR   rS   r8   rZ   r[   r7   rT   rE   )r   r   r   EMULATE_TOUCH_FROM_MOUSE_EVENT)
r6   rQ   rR   rS   r8   rb   rc   r7   r^   rF   s
             r3   emulate_touch_from_mouse_eventz,InputCommands.emulate_touch_from_mouse_event^  sy    N 2tqAfU "+F;&F8&F8 "+F;"#.F< kHHQWXXr2   c                p    t        | ||      }|||d<   |||d<   t        t        j                  |      S )a  
        Generates a command to set the current candidate text for IME.

        This experimental method sets the text for Input Method Editors (IME),
        which are used for entering characters in languages that require more
        keystrokes than the number of characters (like Chinese, Japanese, Korean).

        Use imeCommitComposition to commit the final text.
        Use imeSetComposition with empty string as text to cancel composition.

        Args:
            text: The text to insert as the IME composition.
            selection_start: Start position of the selection within the composition text.
            selection_end: End position of the selection within the composition text.
            replacement_start: Start position of the text to be replaced
                (default: same as selection_start).
            replacement_end: End position of the text to be replaced
                (default: same as selection_end).

        Returns:
            Command: The CDP command to set IME composition.
        )r9   selectionStartselectionEndreplacementStartreplacementEndrE   )r   r   r   IME_SET_COMPOSITION)r9   selection_startselection_endreplacement_startreplacement_endrF   s         r3   ime_set_compositionz!InputCommands.ime_set_composition  sN    < )*&

 ():F%&&'6F#$k==fMMr2   c                P    t        |       }t        t        j                  |      S )a  
        Generates a command to emulate inserting text that doesn't come from a key press.

        This experimental method is useful for inserting text that would normally
        come from sources other than keyboard, such as emoji pickers, IMEs, or
        clipboard pastes.

        Args:
            text: The text to insert.

        Returns:
            Command: The CDP command to insert text.
        )r9   rE   )r   r   r   INSERT_TEXT)r9   rF   s     r3   insert_textzInputCommands.insert_text  s!    " "t,k55fEEr2   c                P    t        |       }t        t        j                  |      S )a  
        Generates a command to control interception of drag and drop events.

        This experimental method prevents default drag and drop behavior and instead
        emits Input.dragIntercepted events. Drag and drop behavior can then be
        directly controlled via Input.dispatchDragEvent.

        This is useful for implementing custom drag and drop logic or for testing
        drag and drop behavior in automated tests.

        Args:
            enabled: If true, drag events will be intercepted and reported as
                    dragIntercepted events, preventing the default behavior.

        Returns:
            Command: The CDP command to set drag interception.
        )enabledrE   )r   r   r   SET_INTERCEPT_DRAGS)r   rF   s     r3   set_intercept_dragsz!InputCommands.set_intercept_drags  s!    & )9k==fMMr2   c                p    t        | ||      }|||d<   |||d<   t        t        j                  |      S )a  
        Generates a command to synthesize a pinch gesture over a time period.

        This experimental method creates a synthetic pinch gesture (zoom in/out)
        by issuing appropriate touch events over time. This is useful for testing
        pinch-to-zoom functionality in web applications.

        Args:
            x: X coordinate of the start of the gesture in CSS pixels.
            y: Y coordinate of the start of the gesture in CSS pixels.
            scale_factor: Relative scale factor after zooming:
                        - >1.0 zooms in (fingers moving apart)
                        - <1.0 zooms out (fingers moving together)
            relative_speed: Relative pointer speed in pixels per second (default: 800).
                          Controls how fast the gesture happens.
            gesture_source_type: Which type of input events to be generated:
                              - 'default': Platform's preferred input type
                              - 'touch': Touch input
                              - 'mouse': Mouse input

        Returns:
            Command: The CDP command to synthesize a pinch gesture.
        )rQ   rR   scaleFactorrelativeSpeedgestureSourceTyperE   )r   r   r   SYNTHESIZE_PINCH_GESTURE)rQ   rR   scale_factorrelative_speedgesture_source_typerF   s         r3   synthesize_pinch_gesturez&InputCommands.synthesize_pinch_gesture  sF    > .QLQ%&4F?#**=F&'kBB6RRr2   c                    t        | |      }|||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |||d<   |	|	|d	<   |
|
|d
<   |||d<   t        t        j                  |      S )a  
        Generates a command to synthesize a scroll gesture over a time period.

        This experimental method creates a synthetic scroll gesture by issuing
        appropriate touch events over time. This is useful for testing scrolling
        behavior in web applications.

        Args:
            x: X coordinate of the start of the gesture in CSS pixels.
            y: Y coordinate of the start of the gesture in CSS pixels.
            x_distance: The distance to scroll along the X axis (positive to scroll left).
            y_distance: The distance to scroll along the Y axis (positive to scroll up).
            x_overscroll: The number of additional pixels to scroll back along the X axis,
                        in addition to the given distance. This creates an overscroll
                        effect (rubber-banding).
            y_overscroll: The number of additional pixels to scroll back along the Y axis,
                        in addition to the given distance. This creates an overscroll
                        effect (rubber-banding).
            prevent_fling: Prevent fling (default: true). If false, a fling animation might
                         continue after the gesture.
            speed: Swipe speed in pixels per second (default: 800).
            gesture_source_type: Which type of input events to be generated:
                              - 'default': Platform's preferred input type
                              - 'touch': Touch input
                              - 'mouse': Mouse input
            repeat_count: The number of times to repeat the gesture (default: 0).
            repeat_delay_ms: The number of milliseconds delay between each repeat (default: 250).
            interaction_marker_name: The name of the interaction markers to generate, if not empty.
                                  Used for tracking gesture timing in performance measurements.

        Returns:
            Command: The CDP command to synthesize a scroll gesture.
        rQ   rR   	xDistance	yDistancexOverscrollyOverscrollpreventFlingspeedr   repeatCountrepeatDelayMsinteractionMarkerNamerE   )r   r   r   SYNTHESIZE_SCROLL_GESTURE)rQ   rR   
x_distance
y_distancex_overscrolly_overscrollprevent_flingr   r   repeat_countrepeat_delay_msinteraction_marker_namerF   s                r3   synthesize_scroll_gesturez'InputCommands.synthesize_scroll_gesture  s    ` /a8!",F;!",F;#$0F=!#$0F=!$%2F>"#F7O**=F&'#$0F=!&&5F?#"..EF*+kCCFSSr2   c                |    t        | |      }|||d<   |||d<   |||d<   t        t        j                  |      S )a  
        Generates a command to synthesize a tap gesture over a time period.

        This experimental method creates a synthetic tap gesture by issuing
        appropriate touch events over time. This is useful for testing
        touch interaction in web applications.

        Args:
            x: X coordinate of the start of the gesture in CSS pixels.
            y: Y coordinate of the start of the gesture in CSS pixels.
            duration: Duration between touchdown and touchup events in milliseconds (default: 50).
                     Controls how long the tap gesture takes.
            tap_count: Number of times to perform the tap (e.g., 2 for a double tap, default: 1).
            gesture_source_type: Which type of input events to be generated:
                              - 'default': Platform's preferred input type
                              - 'touch': Touch input
                              - 'mouse': Mouse input

        Returns:
            Command: The CDP command to synthesize a tap gesture.
        r   durationtapCountr   rE   )r   r   r   SYNTHESIZE_TAP_GESTURE)rQ   rR   r   	tap_countr   rF   s         r3   synthesize_tap_gesturez$InputCommands.synthesize_tap_gestureR  sT    : ,a15!)F: !*F:**=F&'k@@PPr2   )returnr   )NNNNNNNNNNNNNN) r6   r%   r7   Optional[KeyModifier]r8   Optional[float]r9   Optional[str]rH   r   rI   r   r<   r   r=   r   rJ   Optional[int]rK   r   rL   Optional[bool]rM   r   rN   r   rC   zOptional[KeyLocation]rD   zOptional[list[str]]r   r   )NNNNNNNNNNNN) r6   r)   rQ   intrR   r   r7   r   r8   r   rS   zOptional[MouseButton]r^   r   rU   r   r_   r   r`   r   ra   r   rY   r   rb   r   rc   r   rd   zOptional[PointerType]r   r   )NN)
r6   r+   ri   zlist[TouchPoint]r7   r   r8   r   r   r   )rl   boolr   r   )N)r6   r#   rQ   r   rR   r   rp   r   r7   r   r   r   )NNNNN)r6   r)   rQ   r   rR   r   rS   r(   r8   r   rb   r   rc   r   r7   r   r^   r   r   r   )r9   strr|   r   r}   r   r~   r   r   r   r   r   )r9   r   r   r   )r   r   r   r   )rQ   r   rR   r   r   floatr   r   r   Optional[GestureSourceType]r   r   )
NNNNNNNNNN)rQ   r   rR   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    )NNN)rQ   r   rR   r   r   r   r   r   r   r   r   r!   )__name__
__module____qualname____doc__staticmethodr4   rO   re   rj   rn   rr   ru   r   r   r   r   r   r   r1   r2   r3   r-   r-   5   s    
; 
;  ,0%)")-(,"!2615&*$((,*.(,VMVM(VM #VM 	VM
 'VM &VM VM VM #0VM "/VM $VM "VM &VM (VM &VM  
!!VM VMp 
 ,0%)(,%)!%/3"&"&##'#'.2UOUOUO UO )	UO
 #UO &UO #UO UO -UO  UO  UO UO !UO !UO ,UO  
#!UO UOn  ,0%)	$O$O&$O )$O #	$O
 
#$O $OL R R"  ,0 N N N  N 	 N
 ) N 
" N  ND  &*#'#'+/%)1Y1Y1Y 1Y 	1Y
 #1Y !1Y !1Y )1Y #1Y 
+1Y 1Yf 
 ,0)-&N&N&N &N )	&N
 '&N 
"&N &NP FF	F F& N N* 
 )-;?#S#S#S #S &	#S
 9#S 
'#S #SJ  '+&*(,(,(,#;?&*)-15DTDTDT $DT $	DT
 &DT &DT &DT DT 9DT $DT 'DT "/DT 
(DT DTL  #'#';?#Q#Q#Q  #Q !	#Q
 9#Q 
%#Q #Qr2   r-   N)/
__future__r   typingr   r   pydoll.protocol.baser   pydoll.protocol.input.methodsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   pydoll.protocol.input.typesr#   r$   r%   r&   r'   r(   r)   r*   r+   r-   r1   r2   r3   <module>r      s]    " * (         "
 
 
A	Q A	Qr2   