cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! The `Animation` domain.
//!
//! Types, command parameters and event payloads for the `Animation`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// Animation instance.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Animation {
    /// `Animation`'s id.
    pub id: String,
    /// `Animation`'s name.
    pub name: String,
    /// `Animation`'s internal paused state.
    #[serde(rename = "pausedState")]
    pub paused_state: bool,
    /// `Animation`'s play state.
    #[serde(rename = "playState")]
    pub play_state: String,
    /// `Animation`'s playback rate.
    #[serde(rename = "playbackRate")]
    pub playback_rate: f64,
    /// `Animation`'s start time. Milliseconds for time based animations and
    /// percentage \[0 - 100\] for scroll driven animations (i.e. when
    /// viewOrScrollTimeline exists).
    #[serde(rename = "startTime")]
    pub start_time: f64,
    /// `Animation`'s current time.
    #[serde(rename = "currentTime")]
    pub current_time: f64,
    /// Animation type of `Animation`.
    pub r#type: AnimationType,
    /// `Animation`'s source animation node.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub source: Option<AnimationEffect>,
    /// A unique ID for `Animation` representing the sources that triggered this
    /// CSS animation/transition.
    #[serde(rename = "cssId", default, skip_serializing_if = "Option::is_none")]
    pub css_id: Option<String>,
    /// View or scroll timeline
    #[serde(
        rename = "viewOrScrollTimeline",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub view_or_scroll_timeline: Option<ViewOrScrollTimeline>,
}

/// The values `type` accepts on `Animation`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AnimationType {
    /// `CSSTransition`
    #[serde(rename = "CSSTransition")]
    CssTransition,
    /// `CSSAnimation`
    #[serde(rename = "CSSAnimation")]
    CssAnimation,
    /// `WebAnimation`
    WebAnimation,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Timeline instance
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ViewOrScrollTimeline {
    /// Scroll container node
    #[serde(
        rename = "sourceNodeId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub source_node_id: Option<crate::protocol::dom::BackendNodeId>,
    /// Represents the starting scroll position of the timeline as a length offset
    /// in pixels from scroll origin.
    #[serde(
        rename = "startOffset",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub start_offset: Option<f64>,
    /// Represents the ending scroll position of the timeline as a length offset
    /// in pixels from scroll origin.
    #[serde(rename = "endOffset", default, skip_serializing_if = "Option::is_none")]
    pub end_offset: Option<f64>,
    /// The element whose principal box's visibility in the scrollport defined the
    /// progress of the timeline. Does not exist for animations with
    /// ScrollTimeline
    #[serde(
        rename = "subjectNodeId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub subject_node_id: Option<crate::protocol::dom::BackendNodeId>,
    /// Orientation of the scroll
    pub axis: crate::protocol::dom::ScrollOrientation,
}

/// AnimationEffect instance
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AnimationEffect {
    /// `AnimationEffect`'s delay.
    pub delay: f64,
    /// `AnimationEffect`'s end delay.
    #[serde(rename = "endDelay")]
    pub end_delay: f64,
    /// `AnimationEffect`'s iteration start.
    #[serde(rename = "iterationStart")]
    pub iteration_start: f64,
    /// `AnimationEffect`'s iterations. Omitted if the value is infinite.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub iterations: Option<f64>,
    /// `AnimationEffect`'s iteration duration. Milliseconds for time based
    /// animations and percentage \[0 - 100\] for scroll driven animations (i.e.
    /// when viewOrScrollTimeline exists).
    pub duration: f64,
    /// `AnimationEffect`'s playback direction.
    pub direction: String,
    /// `AnimationEffect`'s fill mode.
    pub fill: String,
    /// `AnimationEffect`'s target node.
    #[serde(
        rename = "backendNodeId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub backend_node_id: Option<crate::protocol::dom::BackendNodeId>,
    /// `AnimationEffect`'s keyframes.
    #[serde(
        rename = "keyframesRule",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub keyframes_rule: Option<KeyframesRule>,
    /// `AnimationEffect`'s timing function.
    pub easing: String,
}

/// Keyframes Rule
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct KeyframesRule {
    /// CSS keyframed animation's name.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// List of animation keyframes.
    pub keyframes: Vec<KeyframeStyle>,
}

/// Keyframe Style
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct KeyframeStyle {
    /// Keyframe's time offset.
    pub offset: String,
    /// `AnimationEffect`'s timing function.
    pub easing: String,
}

/// Disables animation domain notifications.
///
/// Parameters of `Animation.disable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisableParams {}

impl crate::typed::Command for DisableParams {
    const METHOD: &'static str = "Animation.disable";
    type Returns = crate::typed::NoReturns;
}

/// Enables animation domain notifications.
///
/// Parameters of `Animation.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {}

impl crate::typed::Command for EnableParams {
    const METHOD: &'static str = "Animation.enable";
    type Returns = crate::typed::NoReturns;
}

/// Returns the current time of the an animation.
///
/// Parameters of `Animation.getCurrentTime`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetCurrentTimeParams {
    /// Id of animation.
    pub id: String,
}

/// What `Animation.getCurrentTime` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetCurrentTimeReturns {
    /// Current time of the page.
    #[serde(rename = "currentTime")]
    pub current_time: f64,
}

impl crate::typed::Command for GetCurrentTimeParams {
    const METHOD: &'static str = "Animation.getCurrentTime";
    type Returns = GetCurrentTimeReturns;
}

/// Gets the playback rate of the document timeline.
///
/// Parameters of `Animation.getPlaybackRate`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetPlaybackRateParams {}

/// What `Animation.getPlaybackRate` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetPlaybackRateReturns {
    /// Playback rate for animations on page.
    #[serde(rename = "playbackRate")]
    pub playback_rate: f64,
}

impl crate::typed::Command for GetPlaybackRateParams {
    const METHOD: &'static str = "Animation.getPlaybackRate";
    type Returns = GetPlaybackRateReturns;
}

/// Releases a set of animations to no longer be manipulated.
///
/// Parameters of `Animation.releaseAnimations`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ReleaseAnimationsParams {
    /// List of animation ids to seek.
    pub animations: Vec<String>,
}

impl crate::typed::Command for ReleaseAnimationsParams {
    const METHOD: &'static str = "Animation.releaseAnimations";
    type Returns = crate::typed::NoReturns;
}

/// Gets the remote object of the Animation.
///
/// Parameters of `Animation.resolveAnimation`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResolveAnimationParams {
    /// Animation id.
    #[serde(rename = "animationId")]
    pub animation_id: String,
}

/// What `Animation.resolveAnimation` answers with.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ResolveAnimationReturns {
    /// Corresponding remote object.
    #[serde(rename = "remoteObject")]
    pub remote_object: crate::protocol::runtime::RemoteObject,
}

impl crate::typed::Command for ResolveAnimationParams {
    const METHOD: &'static str = "Animation.resolveAnimation";
    type Returns = ResolveAnimationReturns;
}

/// Seek a set of animations to a particular time within each animation.
///
/// Parameters of `Animation.seekAnimations`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SeekAnimationsParams {
    /// List of animation ids to seek.
    pub animations: Vec<String>,
    /// Set each animation to the same time.
    #[serde(
        rename = "currentTime",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub current_time: Option<f64>,
    /// Set each animation to a different time. If set, should have the same
    /// length as animations. Exactly one of currentTime or currentTimes should be
    /// set.
    #[serde(
        rename = "currentTimes",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub current_times: Option<Vec<f64>>,
}

impl crate::typed::Command for SeekAnimationsParams {
    const METHOD: &'static str = "Animation.seekAnimations";
    type Returns = crate::typed::NoReturns;
}

/// Sets the paused state of a set of animations.
///
/// Parameters of `Animation.setPaused`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetPausedParams {
    /// Animations to set the pause state of.
    pub animations: Vec<String>,
    /// Paused state to set to.
    pub paused: bool,
}

impl crate::typed::Command for SetPausedParams {
    const METHOD: &'static str = "Animation.setPaused";
    type Returns = crate::typed::NoReturns;
}

/// Sets the playback rate of the document timeline.
///
/// Parameters of `Animation.setPlaybackRate`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetPlaybackRateParams {
    /// Playback rate for animations on page
    #[serde(rename = "playbackRate")]
    pub playback_rate: f64,
}

impl crate::typed::Command for SetPlaybackRateParams {
    const METHOD: &'static str = "Animation.setPlaybackRate";
    type Returns = crate::typed::NoReturns;
}

/// Sets the timing of an animation node.
///
/// Parameters of `Animation.setTiming`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetTimingParams {
    /// Animation id.
    #[serde(rename = "animationId")]
    pub animation_id: String,
    /// Duration of the animation.
    pub duration: f64,
    /// Delay of the animation.
    pub delay: f64,
}

impl crate::typed::Command for SetTimingParams {
    const METHOD: &'static str = "Animation.setTiming";
    type Returns = crate::typed::NoReturns;
}

/// Event for when an animation has been cancelled.
///
/// Payload of the `Animation.animationCanceled` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AnimationCanceledEvent {
    /// Id of the animation that was cancelled.
    pub id: String,
}

impl crate::typed::Event for AnimationCanceledEvent {
    const METHOD: &'static str = "Animation.animationCanceled";
}

/// Event for each animation that has been created.
///
/// Payload of the `Animation.animationCreated` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AnimationCreatedEvent {
    /// Id of the animation that was created.
    pub id: String,
}

impl crate::typed::Event for AnimationCreatedEvent {
    const METHOD: &'static str = "Animation.animationCreated";
}

/// Event for animation that has been started.
///
/// Payload of the `Animation.animationStarted` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AnimationStartedEvent {
    /// Animation that was started.
    pub animation: Animation,
}

impl crate::typed::Event for AnimationStartedEvent {
    const METHOD: &'static str = "Animation.animationStarted";
}

/// Event for animation that has been updated.
///
/// Payload of the `Animation.animationUpdated` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AnimationUpdatedEvent {
    /// Animation that was updated.
    pub animation: Animation,
}

impl crate::typed::Event for AnimationUpdatedEvent {
    const METHOD: &'static str = "Animation.animationUpdated";
}