module WebDriverPreCore.BiDi.Input
  ( PerformActions (..),
    SourceActions (..),
    NoneSourceActions (..),
    KeySourceActions (..),
    KeySourceAction (..),
    PointerSourceActions (..),
    PointerSourceAction (..),
    WheelSourceActions (..),
    WheelSourceAction (..),
    PauseAction (..),
    WheelScrollAction (..),
    PointerCommonProperties (..),
    Origin (..),
    ReleaseActions (..),
    SetFiles (..),
    FileDialogOpened (..),
    FileDialogInfo (..),
    Pointer (..),
    PointerType (..),
  )
where

import Data.Aeson (ToJSON (..), Value (Object), object, (.=), FromJSON (..))
import Data.Aeson.KeyMap qualified
import Data.Aeson.Types (Parser)
import Data.Maybe (fromMaybe, catMaybes)
import Data.Text (Text)
import GHC.Generics (Generic)
import WebDriverPreCore.BiDi.Script qualified as Script
import AesonUtils (toJSONOmitNothing, parseJSONOmitNothing, opt)
import WebDriverPreCore.BiDi.CoreTypes (BrowsingContext(..))
import WebDriverPreCore.BiDi.Script (SharedReference)

-- ######### Local #########

data PerformActions = MkPerformActions
  { PerformActions -> BrowsingContext
context :: BrowsingContext,
    PerformActions -> [SourceActions]
actions :: [SourceActions]
  }
  deriving (Int -> PerformActions -> ShowS
[PerformActions] -> ShowS
PerformActions -> String
(Int -> PerformActions -> ShowS)
-> (PerformActions -> String)
-> ([PerformActions] -> ShowS)
-> Show PerformActions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PerformActions -> ShowS
showsPrec :: Int -> PerformActions -> ShowS
$cshow :: PerformActions -> String
show :: PerformActions -> String
$cshowList :: [PerformActions] -> ShowS
showList :: [PerformActions] -> ShowS
Show, PerformActions -> PerformActions -> Bool
(PerformActions -> PerformActions -> Bool)
-> (PerformActions -> PerformActions -> Bool) -> Eq PerformActions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PerformActions -> PerformActions -> Bool
== :: PerformActions -> PerformActions -> Bool
$c/= :: PerformActions -> PerformActions -> Bool
/= :: PerformActions -> PerformActions -> Bool
Eq, (forall x. PerformActions -> Rep PerformActions x)
-> (forall x. Rep PerformActions x -> PerformActions)
-> Generic PerformActions
forall x. Rep PerformActions x -> PerformActions
forall x. PerformActions -> Rep PerformActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PerformActions -> Rep PerformActions x
from :: forall x. PerformActions -> Rep PerformActions x
$cto :: forall x. Rep PerformActions x -> PerformActions
to :: forall x. Rep PerformActions x -> PerformActions
Generic)

instance ToJSON PerformActions where
  toJSON :: PerformActions -> Value
  toJSON :: PerformActions -> Value
toJSON (MkPerformActions BrowsingContext
context [SourceActions]
actions) =
    [Pair] -> Value
object
      [ Key
"context" Key -> BrowsingContext -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= BrowsingContext
context,
        Key
"actions" Key -> [SourceActions] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [SourceActions]
actions
      ]

data SourceActions
  = NoneSourceActions NoneSourceActions
  | KeySourceActions KeySourceActions
  | PointerSourceActions PointerSourceActions
  | WheelSourceActions WheelSourceActions
  deriving (Int -> SourceActions -> ShowS
[SourceActions] -> ShowS
SourceActions -> String
(Int -> SourceActions -> ShowS)
-> (SourceActions -> String)
-> ([SourceActions] -> ShowS)
-> Show SourceActions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SourceActions -> ShowS
showsPrec :: Int -> SourceActions -> ShowS
$cshow :: SourceActions -> String
show :: SourceActions -> String
$cshowList :: [SourceActions] -> ShowS
showList :: [SourceActions] -> ShowS
Show, SourceActions -> SourceActions -> Bool
(SourceActions -> SourceActions -> Bool)
-> (SourceActions -> SourceActions -> Bool) -> Eq SourceActions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SourceActions -> SourceActions -> Bool
== :: SourceActions -> SourceActions -> Bool
$c/= :: SourceActions -> SourceActions -> Bool
/= :: SourceActions -> SourceActions -> Bool
Eq, (forall x. SourceActions -> Rep SourceActions x)
-> (forall x. Rep SourceActions x -> SourceActions)
-> Generic SourceActions
forall x. Rep SourceActions x -> SourceActions
forall x. SourceActions -> Rep SourceActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SourceActions -> Rep SourceActions x
from :: forall x. SourceActions -> Rep SourceActions x
$cto :: forall x. Rep SourceActions x -> SourceActions
to :: forall x. Rep SourceActions x -> SourceActions
Generic)

instance ToJSON SourceActions where
  toJSON :: SourceActions -> Value
  toJSON :: SourceActions -> Value
toJSON = \case
    NoneSourceActions NoneSourceActions
noneSourceActions -> NoneSourceActions -> Value
forall a. ToJSON a => a -> Value
toJSON NoneSourceActions
noneSourceActions
    KeySourceActions KeySourceActions
keySourceActions -> KeySourceActions -> Value
forall a. ToJSON a => a -> Value
toJSON KeySourceActions
keySourceActions
    PointerSourceActions PointerSourceActions
pointerSourceActions -> PointerSourceActions -> Value
forall a. ToJSON a => a -> Value
toJSON PointerSourceActions
pointerSourceActions
    WheelSourceActions WheelSourceActions
wheelSourceActions -> WheelSourceActions -> Value
forall a. ToJSON a => a -> Value
toJSON WheelSourceActions
wheelSourceActions

data NoneSourceActions = MkNoneSourceActions
  { NoneSourceActions -> Text
noneId :: Text,
    NoneSourceActions -> [PauseAction]
noneActions :: [PauseAction]
  }
  deriving (Int -> NoneSourceActions -> ShowS
[NoneSourceActions] -> ShowS
NoneSourceActions -> String
(Int -> NoneSourceActions -> ShowS)
-> (NoneSourceActions -> String)
-> ([NoneSourceActions] -> ShowS)
-> Show NoneSourceActions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NoneSourceActions -> ShowS
showsPrec :: Int -> NoneSourceActions -> ShowS
$cshow :: NoneSourceActions -> String
show :: NoneSourceActions -> String
$cshowList :: [NoneSourceActions] -> ShowS
showList :: [NoneSourceActions] -> ShowS
Show, NoneSourceActions -> NoneSourceActions -> Bool
(NoneSourceActions -> NoneSourceActions -> Bool)
-> (NoneSourceActions -> NoneSourceActions -> Bool)
-> Eq NoneSourceActions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NoneSourceActions -> NoneSourceActions -> Bool
== :: NoneSourceActions -> NoneSourceActions -> Bool
$c/= :: NoneSourceActions -> NoneSourceActions -> Bool
/= :: NoneSourceActions -> NoneSourceActions -> Bool
Eq, (forall x. NoneSourceActions -> Rep NoneSourceActions x)
-> (forall x. Rep NoneSourceActions x -> NoneSourceActions)
-> Generic NoneSourceActions
forall x. Rep NoneSourceActions x -> NoneSourceActions
forall x. NoneSourceActions -> Rep NoneSourceActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NoneSourceActions -> Rep NoneSourceActions x
from :: forall x. NoneSourceActions -> Rep NoneSourceActions x
$cto :: forall x. Rep NoneSourceActions x -> NoneSourceActions
to :: forall x. Rep NoneSourceActions x -> NoneSourceActions
Generic)

instance ToJSON NoneSourceActions where
  toJSON :: NoneSourceActions -> Value
  toJSON :: NoneSourceActions -> Value
toJSON (MkNoneSourceActions Text
noneId [PauseAction]
noneActions) =
    [Pair] -> Value
object
      [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"none",
        Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
noneId,
        Key
"actions" Key -> [PauseAction] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [PauseAction]
noneActions
      ]

data KeySourceActions = MkKeySourceActions
  { KeySourceActions -> Text
keyId :: Text,
    KeySourceActions -> [KeySourceAction]
keyActions :: [KeySourceAction]
  }
  deriving (Int -> KeySourceActions -> ShowS
[KeySourceActions] -> ShowS
KeySourceActions -> String
(Int -> KeySourceActions -> ShowS)
-> (KeySourceActions -> String)
-> ([KeySourceActions] -> ShowS)
-> Show KeySourceActions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> KeySourceActions -> ShowS
showsPrec :: Int -> KeySourceActions -> ShowS
$cshow :: KeySourceActions -> String
show :: KeySourceActions -> String
$cshowList :: [KeySourceActions] -> ShowS
showList :: [KeySourceActions] -> ShowS
Show, KeySourceActions -> KeySourceActions -> Bool
(KeySourceActions -> KeySourceActions -> Bool)
-> (KeySourceActions -> KeySourceActions -> Bool)
-> Eq KeySourceActions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: KeySourceActions -> KeySourceActions -> Bool
== :: KeySourceActions -> KeySourceActions -> Bool
$c/= :: KeySourceActions -> KeySourceActions -> Bool
/= :: KeySourceActions -> KeySourceActions -> Bool
Eq, (forall x. KeySourceActions -> Rep KeySourceActions x)
-> (forall x. Rep KeySourceActions x -> KeySourceActions)
-> Generic KeySourceActions
forall x. Rep KeySourceActions x -> KeySourceActions
forall x. KeySourceActions -> Rep KeySourceActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. KeySourceActions -> Rep KeySourceActions x
from :: forall x. KeySourceActions -> Rep KeySourceActions x
$cto :: forall x. Rep KeySourceActions x -> KeySourceActions
to :: forall x. Rep KeySourceActions x -> KeySourceActions
Generic)

instance ToJSON KeySourceActions where
  toJSON :: KeySourceActions -> Value
  toJSON :: KeySourceActions -> Value
toJSON (MkKeySourceActions Text
keyId [KeySourceAction]
keyActions) =
    [Pair] -> Value
object
      [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"key",
        Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
keyId,
        Key
"actions" Key -> [KeySourceAction] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [KeySourceAction]
keyActions
      ]

data KeySourceAction
  = KeyPause
      { KeySourceAction -> Maybe Int
duration :: Maybe Int
      }
  | KeyDown
      { KeySourceAction -> Text
value :: Text
      }
  | KeyUp
      { value :: Text
      }
  deriving (Int -> KeySourceAction -> ShowS
[KeySourceAction] -> ShowS
KeySourceAction -> String
(Int -> KeySourceAction -> ShowS)
-> (KeySourceAction -> String)
-> ([KeySourceAction] -> ShowS)
-> Show KeySourceAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> KeySourceAction -> ShowS
showsPrec :: Int -> KeySourceAction -> ShowS
$cshow :: KeySourceAction -> String
show :: KeySourceAction -> String
$cshowList :: [KeySourceAction] -> ShowS
showList :: [KeySourceAction] -> ShowS
Show, KeySourceAction -> KeySourceAction -> Bool
(KeySourceAction -> KeySourceAction -> Bool)
-> (KeySourceAction -> KeySourceAction -> Bool)
-> Eq KeySourceAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: KeySourceAction -> KeySourceAction -> Bool
== :: KeySourceAction -> KeySourceAction -> Bool
$c/= :: KeySourceAction -> KeySourceAction -> Bool
/= :: KeySourceAction -> KeySourceAction -> Bool
Eq, (forall x. KeySourceAction -> Rep KeySourceAction x)
-> (forall x. Rep KeySourceAction x -> KeySourceAction)
-> Generic KeySourceAction
forall x. Rep KeySourceAction x -> KeySourceAction
forall x. KeySourceAction -> Rep KeySourceAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. KeySourceAction -> Rep KeySourceAction x
from :: forall x. KeySourceAction -> Rep KeySourceAction x
$cto :: forall x. Rep KeySourceAction x -> KeySourceAction
to :: forall x. Rep KeySourceAction x -> KeySourceAction
Generic)

instance ToJSON KeySourceAction where
  toJSON :: KeySourceAction -> Value
  toJSON :: KeySourceAction -> Value
toJSON = \case
    KeyPause {Maybe Int
duration :: KeySourceAction -> Maybe Int
duration :: Maybe Int
duration} ->
      [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
        [Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pause"]
          [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Key -> Maybe Int -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"duration" Maybe Int
duration]
    KeyDown {Text
value :: KeySourceAction -> Text
value :: Text
value} ->
      [Pair] -> Value
object
        [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"keyDown",
          Key
"value" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
value
        ]
    KeyUp {Text
value :: KeySourceAction -> Text
value :: Text
value} ->
      [Pair] -> Value
object
        [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"keyUp",
          Key
"value" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
value
        ]

data PointerSourceActions = MkPointerSourceActions
  { PointerSourceActions -> Text
pointerId :: Text,
    PointerSourceActions -> Maybe Pointer
pointer :: Maybe Pointer,
    PointerSourceActions -> [PointerSourceAction]
pointerActions :: [PointerSourceAction]
  }
  deriving (Int -> PointerSourceActions -> ShowS
[PointerSourceActions] -> ShowS
PointerSourceActions -> String
(Int -> PointerSourceActions -> ShowS)
-> (PointerSourceActions -> String)
-> ([PointerSourceActions] -> ShowS)
-> Show PointerSourceActions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PointerSourceActions -> ShowS
showsPrec :: Int -> PointerSourceActions -> ShowS
$cshow :: PointerSourceActions -> String
show :: PointerSourceActions -> String
$cshowList :: [PointerSourceActions] -> ShowS
showList :: [PointerSourceActions] -> ShowS
Show, PointerSourceActions -> PointerSourceActions -> Bool
(PointerSourceActions -> PointerSourceActions -> Bool)
-> (PointerSourceActions -> PointerSourceActions -> Bool)
-> Eq PointerSourceActions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PointerSourceActions -> PointerSourceActions -> Bool
== :: PointerSourceActions -> PointerSourceActions -> Bool
$c/= :: PointerSourceActions -> PointerSourceActions -> Bool
/= :: PointerSourceActions -> PointerSourceActions -> Bool
Eq, (forall x. PointerSourceActions -> Rep PointerSourceActions x)
-> (forall x. Rep PointerSourceActions x -> PointerSourceActions)
-> Generic PointerSourceActions
forall x. Rep PointerSourceActions x -> PointerSourceActions
forall x. PointerSourceActions -> Rep PointerSourceActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PointerSourceActions -> Rep PointerSourceActions x
from :: forall x. PointerSourceActions -> Rep PointerSourceActions x
$cto :: forall x. Rep PointerSourceActions x -> PointerSourceActions
to :: forall x. Rep PointerSourceActions x -> PointerSourceActions
Generic)

instance ToJSON PointerSourceActions where
  toJSON :: PointerSourceActions -> Value
  toJSON :: PointerSourceActions -> Value
toJSON (MkPointerSourceActions Text
pointerId Maybe Pointer
pointer [PointerSourceAction]
pointerActions) =
    [Pair] -> Value
object
      [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pointer",
        Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
pointerId,
        Key
"parameters" Key -> Maybe Pointer -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe Pointer
pointer,
        Key
"actions" Key -> [PointerSourceAction] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [PointerSourceAction]
pointerActions
      ]

data PointerType = MousePointer | PenPointer | TouchPointer
  deriving (Int -> PointerType -> ShowS
[PointerType] -> ShowS
PointerType -> String
(Int -> PointerType -> ShowS)
-> (PointerType -> String)
-> ([PointerType] -> ShowS)
-> Show PointerType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PointerType -> ShowS
showsPrec :: Int -> PointerType -> ShowS
$cshow :: PointerType -> String
show :: PointerType -> String
$cshowList :: [PointerType] -> ShowS
showList :: [PointerType] -> ShowS
Show, PointerType -> PointerType -> Bool
(PointerType -> PointerType -> Bool)
-> (PointerType -> PointerType -> Bool) -> Eq PointerType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PointerType -> PointerType -> Bool
== :: PointerType -> PointerType -> Bool
$c/= :: PointerType -> PointerType -> Bool
/= :: PointerType -> PointerType -> Bool
Eq, (forall x. PointerType -> Rep PointerType x)
-> (forall x. Rep PointerType x -> PointerType)
-> Generic PointerType
forall x. Rep PointerType x -> PointerType
forall x. PointerType -> Rep PointerType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PointerType -> Rep PointerType x
from :: forall x. PointerType -> Rep PointerType x
$cto :: forall x. Rep PointerType x -> PointerType
to :: forall x. Rep PointerType x -> PointerType
Generic)

instance ToJSON PointerType where
  toJSON :: PointerType -> Value
  toJSON :: PointerType -> Value
toJSON = \case
    PointerType
MousePointer -> Value
"mouse"
    PointerType
PenPointer -> Value
"pen"
    PointerType
TouchPointer -> Value
"touch"

data Pointer = MkPointer
  { Pointer -> Maybe PointerType
pointerType :: Maybe PointerType -- default "mouse"
  }
  deriving (Int -> Pointer -> ShowS
[Pointer] -> ShowS
Pointer -> String
(Int -> Pointer -> ShowS)
-> (Pointer -> String) -> ([Pointer] -> ShowS) -> Show Pointer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Pointer -> ShowS
showsPrec :: Int -> Pointer -> ShowS
$cshow :: Pointer -> String
show :: Pointer -> String
$cshowList :: [Pointer] -> ShowS
showList :: [Pointer] -> ShowS
Show, Pointer -> Pointer -> Bool
(Pointer -> Pointer -> Bool)
-> (Pointer -> Pointer -> Bool) -> Eq Pointer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Pointer -> Pointer -> Bool
== :: Pointer -> Pointer -> Bool
$c/= :: Pointer -> Pointer -> Bool
/= :: Pointer -> Pointer -> Bool
Eq, (forall x. Pointer -> Rep Pointer x)
-> (forall x. Rep Pointer x -> Pointer) -> Generic Pointer
forall x. Rep Pointer x -> Pointer
forall x. Pointer -> Rep Pointer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Pointer -> Rep Pointer x
from :: forall x. Pointer -> Rep Pointer x
$cto :: forall x. Rep Pointer x -> Pointer
to :: forall x. Rep Pointer x -> Pointer
Generic)

instance ToJSON Pointer where
  toJSON :: Pointer -> Value
  toJSON :: Pointer -> Value
toJSON MkPointer {Maybe PointerType
pointerType :: Pointer -> Maybe PointerType
pointerType :: Maybe PointerType
pointerType} =
    [Pair] -> Value
object
      [ Key
"pointerType" Key -> PointerType -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= PointerType -> Maybe PointerType -> PointerType
forall a. a -> Maybe a -> a
fromMaybe PointerType
MousePointer Maybe PointerType
pointerType
      ]

data PointerSourceAction
  = Pause
      { PointerSourceAction -> Maybe Int
duration :: Maybe Int
      }
  | PointerDown
      { PointerSourceAction -> Int
button :: Int,
        PointerSourceAction -> PointerCommonProperties
pointerCommonProperties :: PointerCommonProperties
      }
  | PointerUp
      { button :: Int
      }
  | PointerMove
      { PointerSourceAction -> Double
x :: Double,
        PointerSourceAction -> Double
y :: Double,
        duration :: Maybe Int,
        PointerSourceAction -> Maybe Origin
origin :: Maybe Origin,
        pointerCommonProperties :: PointerCommonProperties
      }
  deriving (Int -> PointerSourceAction -> ShowS
[PointerSourceAction] -> ShowS
PointerSourceAction -> String
(Int -> PointerSourceAction -> ShowS)
-> (PointerSourceAction -> String)
-> ([PointerSourceAction] -> ShowS)
-> Show PointerSourceAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PointerSourceAction -> ShowS
showsPrec :: Int -> PointerSourceAction -> ShowS
$cshow :: PointerSourceAction -> String
show :: PointerSourceAction -> String
$cshowList :: [PointerSourceAction] -> ShowS
showList :: [PointerSourceAction] -> ShowS
Show, PointerSourceAction -> PointerSourceAction -> Bool
(PointerSourceAction -> PointerSourceAction -> Bool)
-> (PointerSourceAction -> PointerSourceAction -> Bool)
-> Eq PointerSourceAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PointerSourceAction -> PointerSourceAction -> Bool
== :: PointerSourceAction -> PointerSourceAction -> Bool
$c/= :: PointerSourceAction -> PointerSourceAction -> Bool
/= :: PointerSourceAction -> PointerSourceAction -> Bool
Eq, (forall x. PointerSourceAction -> Rep PointerSourceAction x)
-> (forall x. Rep PointerSourceAction x -> PointerSourceAction)
-> Generic PointerSourceAction
forall x. Rep PointerSourceAction x -> PointerSourceAction
forall x. PointerSourceAction -> Rep PointerSourceAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PointerSourceAction -> Rep PointerSourceAction x
from :: forall x. PointerSourceAction -> Rep PointerSourceAction x
$cto :: forall x. Rep PointerSourceAction x -> PointerSourceAction
to :: forall x. Rep PointerSourceAction x -> PointerSourceAction
Generic)

instance ToJSON PointerSourceAction where
  toJSON :: PointerSourceAction -> Value
  toJSON :: PointerSourceAction -> Value
toJSON = \case
    Pause {Maybe Int
duration :: PointerSourceAction -> Maybe Int
duration :: Maybe Int
duration} ->
      [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
        [Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pause"]
          [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Key -> Maybe Int -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"duration" Maybe Int
duration]
    PointerDown {Int
button :: PointerSourceAction -> Int
button :: Int
button, PointerCommonProperties
pointerCommonProperties :: PointerSourceAction -> PointerCommonProperties
pointerCommonProperties :: PointerCommonProperties
pointerCommonProperties} ->
      case PointerCommonProperties -> Value
forall a. ToJSON a => a -> Value
toJSON PointerCommonProperties
pointerCommonProperties of
        Object Object
props ->
          [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pointerDown",
              Key
"button" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
button
            ] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [(Key
k, Value
v) | (Key
k, Value
v) <- Object -> [Pair]
forall v. KeyMap v -> [(Key, v)]
Data.Aeson.KeyMap.toList Object
props]
        Value
_ -> 
          [Pair] -> Value
object
            [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pointerDown",
              Key
"button" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
button
            ]
    PointerUp {Int
button :: PointerSourceAction -> Int
button :: Int
button} ->
      [Pair] -> Value
object
        [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pointerUp",
          Key
"button" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
button
        ]
    PointerMove {Double
x :: PointerSourceAction -> Double
x :: Double
x, Double
y :: PointerSourceAction -> Double
y :: Double
y, Maybe Int
duration :: PointerSourceAction -> Maybe Int
duration :: Maybe Int
duration, Maybe Origin
origin :: PointerSourceAction -> Maybe Origin
origin :: Maybe Origin
origin, PointerCommonProperties
pointerCommonProperties :: PointerSourceAction -> PointerCommonProperties
pointerCommonProperties :: PointerCommonProperties
pointerCommonProperties} ->
      case PointerCommonProperties -> Value
forall a. ToJSON a => a -> Value
toJSON PointerCommonProperties
pointerCommonProperties of
        Object Object
props ->
          [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pointerMove",
              Key
"x" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
x,
              Key
"y" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
y
            ] 
            [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Key -> Maybe Int -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"duration" Maybe Int
duration, Key -> Maybe Origin -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"origin" Maybe Origin
origin]
            [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [(Key
k, Value
v) | (Key
k, Value
v) <- Object -> [Pair]
forall v. KeyMap v -> [(Key, v)]
Data.Aeson.KeyMap.toList Object
props]
        Value
_ -> 
          [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
            [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pointerMove",
              Key
"x" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
x,
              Key
"y" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Double
y
            ]
            [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Key -> Maybe Int -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"duration" Maybe Int
duration, Key -> Maybe Origin -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"origin" Maybe Origin
origin]

data WheelSourceActions = MkWheelSourceActions
  { WheelSourceActions -> Text
wheelId :: Text,
    WheelSourceActions -> [WheelSourceAction]
wheelActions :: [WheelSourceAction]
  }
  deriving (Int -> WheelSourceActions -> ShowS
[WheelSourceActions] -> ShowS
WheelSourceActions -> String
(Int -> WheelSourceActions -> ShowS)
-> (WheelSourceActions -> String)
-> ([WheelSourceActions] -> ShowS)
-> Show WheelSourceActions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WheelSourceActions -> ShowS
showsPrec :: Int -> WheelSourceActions -> ShowS
$cshow :: WheelSourceActions -> String
show :: WheelSourceActions -> String
$cshowList :: [WheelSourceActions] -> ShowS
showList :: [WheelSourceActions] -> ShowS
Show, WheelSourceActions -> WheelSourceActions -> Bool
(WheelSourceActions -> WheelSourceActions -> Bool)
-> (WheelSourceActions -> WheelSourceActions -> Bool)
-> Eq WheelSourceActions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WheelSourceActions -> WheelSourceActions -> Bool
== :: WheelSourceActions -> WheelSourceActions -> Bool
$c/= :: WheelSourceActions -> WheelSourceActions -> Bool
/= :: WheelSourceActions -> WheelSourceActions -> Bool
Eq, (forall x. WheelSourceActions -> Rep WheelSourceActions x)
-> (forall x. Rep WheelSourceActions x -> WheelSourceActions)
-> Generic WheelSourceActions
forall x. Rep WheelSourceActions x -> WheelSourceActions
forall x. WheelSourceActions -> Rep WheelSourceActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. WheelSourceActions -> Rep WheelSourceActions x
from :: forall x. WheelSourceActions -> Rep WheelSourceActions x
$cto :: forall x. Rep WheelSourceActions x -> WheelSourceActions
to :: forall x. Rep WheelSourceActions x -> WheelSourceActions
Generic)

instance ToJSON WheelSourceActions where
  toJSON :: WheelSourceActions -> Value
  toJSON :: WheelSourceActions -> Value
toJSON (MkWheelSourceActions Text
wheelId [WheelSourceAction]
wheelActions) =
    [Pair] -> Value
object
      [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"wheel",
        Key
"id" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
wheelId,
        Key
"actions" Key -> [WheelSourceAction] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= [WheelSourceAction]
wheelActions
      ]

data WheelSourceAction
  = WheelPauseAction PauseAction
  | WheelScrollAction WheelScrollAction
  deriving (Int -> WheelSourceAction -> ShowS
[WheelSourceAction] -> ShowS
WheelSourceAction -> String
(Int -> WheelSourceAction -> ShowS)
-> (WheelSourceAction -> String)
-> ([WheelSourceAction] -> ShowS)
-> Show WheelSourceAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WheelSourceAction -> ShowS
showsPrec :: Int -> WheelSourceAction -> ShowS
$cshow :: WheelSourceAction -> String
show :: WheelSourceAction -> String
$cshowList :: [WheelSourceAction] -> ShowS
showList :: [WheelSourceAction] -> ShowS
Show, WheelSourceAction -> WheelSourceAction -> Bool
(WheelSourceAction -> WheelSourceAction -> Bool)
-> (WheelSourceAction -> WheelSourceAction -> Bool)
-> Eq WheelSourceAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WheelSourceAction -> WheelSourceAction -> Bool
== :: WheelSourceAction -> WheelSourceAction -> Bool
$c/= :: WheelSourceAction -> WheelSourceAction -> Bool
/= :: WheelSourceAction -> WheelSourceAction -> Bool
Eq, (forall x. WheelSourceAction -> Rep WheelSourceAction x)
-> (forall x. Rep WheelSourceAction x -> WheelSourceAction)
-> Generic WheelSourceAction
forall x. Rep WheelSourceAction x -> WheelSourceAction
forall x. WheelSourceAction -> Rep WheelSourceAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. WheelSourceAction -> Rep WheelSourceAction x
from :: forall x. WheelSourceAction -> Rep WheelSourceAction x
$cto :: forall x. Rep WheelSourceAction x -> WheelSourceAction
to :: forall x. Rep WheelSourceAction x -> WheelSourceAction
Generic)

instance ToJSON WheelSourceAction where
  toJSON :: WheelSourceAction -> Value
  toJSON :: WheelSourceAction -> Value
toJSON = \case
    WheelPauseAction PauseAction
wheelPauseAction -> PauseAction -> Value
forall a. ToJSON a => a -> Value
toJSON PauseAction
wheelPauseAction
    WheelScrollAction WheelScrollAction
wheelScrollAction -> WheelScrollAction -> Value
forall a. ToJSON a => a -> Value
toJSON WheelScrollAction
wheelScrollAction

newtype PauseAction = MkPauseAction
  { PauseAction -> Maybe Int
duration :: Maybe Int
  }
  deriving (Int -> PauseAction -> ShowS
[PauseAction] -> ShowS
PauseAction -> String
(Int -> PauseAction -> ShowS)
-> (PauseAction -> String)
-> ([PauseAction] -> ShowS)
-> Show PauseAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PauseAction -> ShowS
showsPrec :: Int -> PauseAction -> ShowS
$cshow :: PauseAction -> String
show :: PauseAction -> String
$cshowList :: [PauseAction] -> ShowS
showList :: [PauseAction] -> ShowS
Show, PauseAction -> PauseAction -> Bool
(PauseAction -> PauseAction -> Bool)
-> (PauseAction -> PauseAction -> Bool) -> Eq PauseAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PauseAction -> PauseAction -> Bool
== :: PauseAction -> PauseAction -> Bool
$c/= :: PauseAction -> PauseAction -> Bool
/= :: PauseAction -> PauseAction -> Bool
Eq, (forall x. PauseAction -> Rep PauseAction x)
-> (forall x. Rep PauseAction x -> PauseAction)
-> Generic PauseAction
forall x. Rep PauseAction x -> PauseAction
forall x. PauseAction -> Rep PauseAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PauseAction -> Rep PauseAction x
from :: forall x. PauseAction -> Rep PauseAction x
$cto :: forall x. Rep PauseAction x -> PauseAction
to :: forall x. Rep PauseAction x -> PauseAction
Generic)

instance ToJSON PauseAction where
  toJSON :: PauseAction -> Value
  toJSON :: PauseAction -> Value
toJSON (MkPauseAction Maybe Int
duration) =
    [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
      [Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"pause"]
        [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Key -> Maybe Int -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"duration" Maybe Int
duration]

data WheelScrollAction = MkWheelScrollAction
  { WheelScrollAction -> Int
x :: Int,
    WheelScrollAction -> Int
y :: Int,
    WheelScrollAction -> Int
deltaX :: Int,
    WheelScrollAction -> Int
deltaY :: Int,
    WheelScrollAction -> Maybe Int
duration :: Maybe Int,
    WheelScrollAction -> Maybe Origin
origin :: Maybe Origin -- default "viewport"
  }
  deriving (Int -> WheelScrollAction -> ShowS
[WheelScrollAction] -> ShowS
WheelScrollAction -> String
(Int -> WheelScrollAction -> ShowS)
-> (WheelScrollAction -> String)
-> ([WheelScrollAction] -> ShowS)
-> Show WheelScrollAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WheelScrollAction -> ShowS
showsPrec :: Int -> WheelScrollAction -> ShowS
$cshow :: WheelScrollAction -> String
show :: WheelScrollAction -> String
$cshowList :: [WheelScrollAction] -> ShowS
showList :: [WheelScrollAction] -> ShowS
Show, WheelScrollAction -> WheelScrollAction -> Bool
(WheelScrollAction -> WheelScrollAction -> Bool)
-> (WheelScrollAction -> WheelScrollAction -> Bool)
-> Eq WheelScrollAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WheelScrollAction -> WheelScrollAction -> Bool
== :: WheelScrollAction -> WheelScrollAction -> Bool
$c/= :: WheelScrollAction -> WheelScrollAction -> Bool
/= :: WheelScrollAction -> WheelScrollAction -> Bool
Eq, (forall x. WheelScrollAction -> Rep WheelScrollAction x)
-> (forall x. Rep WheelScrollAction x -> WheelScrollAction)
-> Generic WheelScrollAction
forall x. Rep WheelScrollAction x -> WheelScrollAction
forall x. WheelScrollAction -> Rep WheelScrollAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. WheelScrollAction -> Rep WheelScrollAction x
from :: forall x. WheelScrollAction -> Rep WheelScrollAction x
$cto :: forall x. Rep WheelScrollAction x -> WheelScrollAction
to :: forall x. Rep WheelScrollAction x -> WheelScrollAction
Generic)

instance ToJSON WheelScrollAction where
  toJSON :: WheelScrollAction -> Value
  toJSON :: WheelScrollAction -> Value
toJSON (MkWheelScrollAction Int
x Int
y Int
deltaX Int
deltaY Maybe Int
duration Maybe Origin
origin) =
    [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
      [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"scroll",
        Key
"x" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
x,
        Key
"y" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
y,
        Key
"deltaX" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
deltaX,
        Key
"deltaY" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Int
deltaY
      ]
        [Pair] -> [Pair] -> [Pair]
forall a. Semigroup a => a -> a -> a
<> [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes [Key -> Maybe Int -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"duration" Maybe Int
duration, Key -> Maybe Origin -> Maybe Pair
forall (f :: * -> *) e b a.
(Functor f, KeyValue e b, ToJSON a) =>
Key -> f a -> f b
opt Key
"origin" Maybe Origin
origin]

data PointerCommonProperties = MkPointerCommonProperties
  { PointerCommonProperties -> Maybe Int
width :: Maybe Int, -- default 1
    PointerCommonProperties -> Maybe Int
height :: Maybe Int, -- default 1
    PointerCommonProperties -> Maybe Double
pressure :: Maybe Double, -- default 0.0
    PointerCommonProperties -> Maybe Double
tangentialPressure :: Maybe Double, -- default 0.0
    PointerCommonProperties -> Maybe Int
twist :: Maybe Int, -- default 0, range 0..359
    PointerCommonProperties -> Maybe Double
altitudeAngle :: Maybe Double, -- default 0.0, range 0..π/2
    PointerCommonProperties -> Maybe Double
azimuthAngle :: Maybe Double -- default 0.0, range 0..2π
  }
  deriving (Int -> PointerCommonProperties -> ShowS
[PointerCommonProperties] -> ShowS
PointerCommonProperties -> String
(Int -> PointerCommonProperties -> ShowS)
-> (PointerCommonProperties -> String)
-> ([PointerCommonProperties] -> ShowS)
-> Show PointerCommonProperties
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PointerCommonProperties -> ShowS
showsPrec :: Int -> PointerCommonProperties -> ShowS
$cshow :: PointerCommonProperties -> String
show :: PointerCommonProperties -> String
$cshowList :: [PointerCommonProperties] -> ShowS
showList :: [PointerCommonProperties] -> ShowS
Show, PointerCommonProperties -> PointerCommonProperties -> Bool
(PointerCommonProperties -> PointerCommonProperties -> Bool)
-> (PointerCommonProperties -> PointerCommonProperties -> Bool)
-> Eq PointerCommonProperties
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PointerCommonProperties -> PointerCommonProperties -> Bool
== :: PointerCommonProperties -> PointerCommonProperties -> Bool
$c/= :: PointerCommonProperties -> PointerCommonProperties -> Bool
/= :: PointerCommonProperties -> PointerCommonProperties -> Bool
Eq, (forall x.
 PointerCommonProperties -> Rep PointerCommonProperties x)
-> (forall x.
    Rep PointerCommonProperties x -> PointerCommonProperties)
-> Generic PointerCommonProperties
forall x. Rep PointerCommonProperties x -> PointerCommonProperties
forall x. PointerCommonProperties -> Rep PointerCommonProperties x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PointerCommonProperties -> Rep PointerCommonProperties x
from :: forall x. PointerCommonProperties -> Rep PointerCommonProperties x
$cto :: forall x. Rep PointerCommonProperties x -> PointerCommonProperties
to :: forall x. Rep PointerCommonProperties x -> PointerCommonProperties
Generic)

instance ToJSON PointerCommonProperties where
  toJSON :: PointerCommonProperties -> Value
  toJSON :: PointerCommonProperties -> Value
toJSON = PointerCommonProperties -> Value
forall a. (Generic a, GToJSON' Value Zero (Rep a)) => a -> Value
toJSONOmitNothing

data Origin
  = ViewportOriginPointerType
  | PointerOrigin
  | ElementOrigin Script.SharedReference
  deriving (Int -> Origin -> ShowS
[Origin] -> ShowS
Origin -> String
(Int -> Origin -> ShowS)
-> (Origin -> String) -> ([Origin] -> ShowS) -> Show Origin
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Origin -> ShowS
showsPrec :: Int -> Origin -> ShowS
$cshow :: Origin -> String
show :: Origin -> String
$cshowList :: [Origin] -> ShowS
showList :: [Origin] -> ShowS
Show, Origin -> Origin -> Bool
(Origin -> Origin -> Bool)
-> (Origin -> Origin -> Bool) -> Eq Origin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Origin -> Origin -> Bool
== :: Origin -> Origin -> Bool
$c/= :: Origin -> Origin -> Bool
/= :: Origin -> Origin -> Bool
Eq, (forall x. Origin -> Rep Origin x)
-> (forall x. Rep Origin x -> Origin) -> Generic Origin
forall x. Rep Origin x -> Origin
forall x. Origin -> Rep Origin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Origin -> Rep Origin x
from :: forall x. Origin -> Rep Origin x
$cto :: forall x. Rep Origin x -> Origin
to :: forall x. Rep Origin x -> Origin
Generic)

instance ToJSON Origin where
  toJSON :: Origin -> Value
  toJSON :: Origin -> Value
toJSON = \case
    Origin
ViewportOriginPointerType -> Value
"viewport"
    Origin
PointerOrigin -> Value
"pointer"
    ElementOrigin SharedReference
element ->
      [Pair] -> Value
object
        [ Key
"type" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= String
"element",
          Key
"element" Key -> SharedReference -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= SharedReference
element
        ]

-- ReleaseActions
newtype ReleaseActions = MkReleaseActions
  { ReleaseActions -> BrowsingContext
context :: BrowsingContext
  }
  deriving (Int -> ReleaseActions -> ShowS
[ReleaseActions] -> ShowS
ReleaseActions -> String
(Int -> ReleaseActions -> ShowS)
-> (ReleaseActions -> String)
-> ([ReleaseActions] -> ShowS)
-> Show ReleaseActions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReleaseActions -> ShowS
showsPrec :: Int -> ReleaseActions -> ShowS
$cshow :: ReleaseActions -> String
show :: ReleaseActions -> String
$cshowList :: [ReleaseActions] -> ShowS
showList :: [ReleaseActions] -> ShowS
Show, ReleaseActions -> ReleaseActions -> Bool
(ReleaseActions -> ReleaseActions -> Bool)
-> (ReleaseActions -> ReleaseActions -> Bool) -> Eq ReleaseActions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReleaseActions -> ReleaseActions -> Bool
== :: ReleaseActions -> ReleaseActions -> Bool
$c/= :: ReleaseActions -> ReleaseActions -> Bool
/= :: ReleaseActions -> ReleaseActions -> Bool
Eq, (forall x. ReleaseActions -> Rep ReleaseActions x)
-> (forall x. Rep ReleaseActions x -> ReleaseActions)
-> Generic ReleaseActions
forall x. Rep ReleaseActions x -> ReleaseActions
forall x. ReleaseActions -> Rep ReleaseActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ReleaseActions -> Rep ReleaseActions x
from :: forall x. ReleaseActions -> Rep ReleaseActions x
$cto :: forall x. Rep ReleaseActions x -> ReleaseActions
to :: forall x. Rep ReleaseActions x -> ReleaseActions
Generic)

instance ToJSON ReleaseActions

data SetFiles = MkSetFiles
  { SetFiles -> BrowsingContext
context :: BrowsingContext,
    SetFiles -> SharedReference
element :: Script.SharedReference,
    SetFiles -> [Text]
files :: [Text]
  }
  deriving (Int -> SetFiles -> ShowS
[SetFiles] -> ShowS
SetFiles -> String
(Int -> SetFiles -> ShowS)
-> (SetFiles -> String) -> ([SetFiles] -> ShowS) -> Show SetFiles
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetFiles -> ShowS
showsPrec :: Int -> SetFiles -> ShowS
$cshow :: SetFiles -> String
show :: SetFiles -> String
$cshowList :: [SetFiles] -> ShowS
showList :: [SetFiles] -> ShowS
Show, SetFiles -> SetFiles -> Bool
(SetFiles -> SetFiles -> Bool)
-> (SetFiles -> SetFiles -> Bool) -> Eq SetFiles
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetFiles -> SetFiles -> Bool
== :: SetFiles -> SetFiles -> Bool
$c/= :: SetFiles -> SetFiles -> Bool
/= :: SetFiles -> SetFiles -> Bool
Eq, (forall x. SetFiles -> Rep SetFiles x)
-> (forall x. Rep SetFiles x -> SetFiles) -> Generic SetFiles
forall x. Rep SetFiles x -> SetFiles
forall x. SetFiles -> Rep SetFiles x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SetFiles -> Rep SetFiles x
from :: forall x. SetFiles -> Rep SetFiles x
$cto :: forall x. Rep SetFiles x -> SetFiles
to :: forall x. Rep SetFiles x -> SetFiles
Generic)

instance ToJSON SetFiles

-- | Event data for input.fileDialogOpened event
-- Parses the params content directly (params is extracted by Event or SingleSubscription handler)
newtype FileDialogOpened = MkFileDialogOpened
  { FileDialogOpened -> FileDialogInfo
params :: FileDialogInfo
  }
  deriving (Int -> FileDialogOpened -> ShowS
[FileDialogOpened] -> ShowS
FileDialogOpened -> String
(Int -> FileDialogOpened -> ShowS)
-> (FileDialogOpened -> String)
-> ([FileDialogOpened] -> ShowS)
-> Show FileDialogOpened
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FileDialogOpened -> ShowS
showsPrec :: Int -> FileDialogOpened -> ShowS
$cshow :: FileDialogOpened -> String
show :: FileDialogOpened -> String
$cshowList :: [FileDialogOpened] -> ShowS
showList :: [FileDialogOpened] -> ShowS
Show, FileDialogOpened -> FileDialogOpened -> Bool
(FileDialogOpened -> FileDialogOpened -> Bool)
-> (FileDialogOpened -> FileDialogOpened -> Bool)
-> Eq FileDialogOpened
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FileDialogOpened -> FileDialogOpened -> Bool
== :: FileDialogOpened -> FileDialogOpened -> Bool
$c/= :: FileDialogOpened -> FileDialogOpened -> Bool
/= :: FileDialogOpened -> FileDialogOpened -> Bool
Eq, (forall x. FileDialogOpened -> Rep FileDialogOpened x)
-> (forall x. Rep FileDialogOpened x -> FileDialogOpened)
-> Generic FileDialogOpened
forall x. Rep FileDialogOpened x -> FileDialogOpened
forall x. FileDialogOpened -> Rep FileDialogOpened x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FileDialogOpened -> Rep FileDialogOpened x
from :: forall x. FileDialogOpened -> Rep FileDialogOpened x
$cto :: forall x. Rep FileDialogOpened x -> FileDialogOpened
to :: forall x. Rep FileDialogOpened x -> FileDialogOpened
Generic)

instance FromJSON FileDialogOpened where
  parseJSON :: Value -> Parser FileDialogOpened
  parseJSON :: Value -> Parser FileDialogOpened
parseJSON Value
v = FileDialogInfo -> FileDialogOpened
MkFileDialogOpened (FileDialogInfo -> FileDialogOpened)
-> Parser FileDialogInfo -> Parser FileDialogOpened
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser FileDialogInfo
forall a. FromJSON a => Value -> Parser a
parseJSON Value
v

-- ######### Local #########

data FileDialogInfo = MkFileDialogInfo
  { FileDialogInfo -> BrowsingContext
context :: BrowsingContext,
    FileDialogInfo -> Maybe SharedReference
element :: Maybe SharedReference,
    FileDialogInfo -> Bool
multiple :: Bool
  }
  deriving (Int -> FileDialogInfo -> ShowS
[FileDialogInfo] -> ShowS
FileDialogInfo -> String
(Int -> FileDialogInfo -> ShowS)
-> (FileDialogInfo -> String)
-> ([FileDialogInfo] -> ShowS)
-> Show FileDialogInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FileDialogInfo -> ShowS
showsPrec :: Int -> FileDialogInfo -> ShowS
$cshow :: FileDialogInfo -> String
show :: FileDialogInfo -> String
$cshowList :: [FileDialogInfo] -> ShowS
showList :: [FileDialogInfo] -> ShowS
Show, FileDialogInfo -> FileDialogInfo -> Bool
(FileDialogInfo -> FileDialogInfo -> Bool)
-> (FileDialogInfo -> FileDialogInfo -> Bool) -> Eq FileDialogInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FileDialogInfo -> FileDialogInfo -> Bool
== :: FileDialogInfo -> FileDialogInfo -> Bool
$c/= :: FileDialogInfo -> FileDialogInfo -> Bool
/= :: FileDialogInfo -> FileDialogInfo -> Bool
Eq, (forall x. FileDialogInfo -> Rep FileDialogInfo x)
-> (forall x. Rep FileDialogInfo x -> FileDialogInfo)
-> Generic FileDialogInfo
forall x. Rep FileDialogInfo x -> FileDialogInfo
forall x. FileDialogInfo -> Rep FileDialogInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FileDialogInfo -> Rep FileDialogInfo x
from :: forall x. FileDialogInfo -> Rep FileDialogInfo x
$cto :: forall x. Rep FileDialogInfo x -> FileDialogInfo
to :: forall x. Rep FileDialogInfo x -> FileDialogInfo
Generic)

instance FromJSON FileDialogInfo where
  parseJSON :: Value -> Parser FileDialogInfo
  parseJSON :: Value -> Parser FileDialogInfo
parseJSON = Value -> Parser FileDialogInfo
forall a. (Generic a, GFromJSON Zero (Rep a)) => Value -> Parser a
parseJSONOmitNothing

instance ToJSON FileDialogInfo