{-# LANGUAGE OverloadedStrings #-}
module Miso.Native.Element.Image.Event
(
onLoad
, onLoadWith
, onLoadMain
, onLoadMainWith
, onError
, onErrorWith
, onErrorMain
, onErrorMainWith
, onStartPlay
, onStartPlayWith
, onStartPlayMain
, onStartPlayMainWith
, onCurrentLoopComplete
, onCurrentLoopCompleteWith
, onCurrentLoopCompleteMain
, onCurrentLoopCompleteMainWith
, onFinalLoopComplete
, onFinalLoopCompleteWith
, onFinalLoopCompleteMain
, onFinalLoopCompleteMainWith
, imageLoadDecoder
, imageErrorDecoder
, ImageErrorEvent (..)
, ImageLoadEvent (..)
, imageEvents
) where
import qualified Data.Map as M
import Miso.Event
import Miso.JSON
import Miso.String (MisoString)
import Miso.Types (Attribute, EventHandler, DOMRef)
imageEvents :: Events
imageEvents :: Events
imageEvents
= [(MisoString, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (MisoString
"load", Phase
BUBBLE)
, (MisoString
"error", Phase
BUBBLE)
, (MisoString
"startplay", Phase
BUBBLE)
, (MisoString
"currentloopcomplete", Phase
BUBBLE)
, (MisoString
"finalloopcomplete", Phase
BUBBLE)
]
onLoad :: (ImageLoadEvent -> action) -> Attribute model action
onLoad :: forall action model.
(ImageLoadEvent -> action) -> Attribute model action
onLoad ImageLoadEvent -> action
action = MisoString
-> Decoder ImageLoadEvent
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"load" Decoder ImageLoadEvent
imageLoadDecoder (\ImageLoadEvent
e model
_ DOMRef
_ -> ImageLoadEvent -> action
action ImageLoadEvent
e)
onLoadMain :: (ImageLoadEvent -> action) -> EventHandler model action
onLoadMain :: forall action model.
(ImageLoadEvent -> action) -> EventHandler model action
onLoadMain ImageLoadEvent -> action
action = MisoString
-> Decoder ImageLoadEvent
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"load" Decoder ImageLoadEvent
imageLoadDecoder (\ImageLoadEvent
e model
_ DOMRef
_ -> ImageLoadEvent -> action
action ImageLoadEvent
e)
onLoadMainWith :: (ImageLoadEvent -> model -> DOMRef -> action) -> EventHandler model action
onLoadMainWith :: forall model action.
(ImageLoadEvent -> model -> DOMRef -> action)
-> EventHandler model action
onLoadMainWith ImageLoadEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ImageLoadEvent
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"load" Decoder ImageLoadEvent
imageLoadDecoder ImageLoadEvent -> model -> DOMRef -> action
action
onError :: (ImageErrorEvent -> action) -> Attribute model action
onError :: forall action model.
(ImageErrorEvent -> action) -> Attribute model action
onError ImageErrorEvent -> action
action = MisoString
-> Decoder ImageErrorEvent
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"error" Decoder ImageErrorEvent
imageErrorDecoder (\ImageErrorEvent
e model
_ DOMRef
_ -> ImageErrorEvent -> action
action ImageErrorEvent
e)
onErrorMain :: (ImageErrorEvent -> action) -> EventHandler model action
onErrorMain :: forall action model.
(ImageErrorEvent -> action) -> EventHandler model action
onErrorMain ImageErrorEvent -> action
action = MisoString
-> Decoder ImageErrorEvent
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"error" Decoder ImageErrorEvent
imageErrorDecoder (\ImageErrorEvent
e model
_ DOMRef
_ -> ImageErrorEvent -> action
action ImageErrorEvent
e)
onErrorMainWith :: (ImageErrorEvent -> model -> DOMRef -> action) -> EventHandler model action
onErrorMainWith :: forall model action.
(ImageErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
onErrorMainWith ImageErrorEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ImageErrorEvent
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"error" Decoder ImageErrorEvent
imageErrorDecoder ImageErrorEvent -> model -> DOMRef -> action
action
onStartPlay :: action -> Attribute model action
onStartPlay :: forall action model. action -> Attribute model action
onStartPlay action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"startplay" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onStartPlayMain :: action -> EventHandler model action
onStartPlayMain :: forall action model. action -> EventHandler model action
onStartPlayMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"startplay" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onStartPlayMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onStartPlayMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onStartPlayMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"startplay" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
onCurrentLoopComplete :: action -> Attribute model action
onCurrentLoopComplete :: forall action model. action -> Attribute model action
onCurrentLoopComplete action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"currentloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onCurrentLoopCompleteMain :: action -> EventHandler model action
onCurrentLoopCompleteMain :: forall action model. action -> EventHandler model action
onCurrentLoopCompleteMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"currentloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onCurrentLoopCompleteMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onCurrentLoopCompleteMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onCurrentLoopCompleteMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"currentloopcomplete" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
onFinalLoopComplete :: action -> Attribute model action
onFinalLoopComplete :: forall action model. action -> Attribute model action
onFinalLoopComplete action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"finalloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onFinalLoopCompleteMain :: action -> EventHandler model action
onFinalLoopCompleteMain :: forall action model. action -> EventHandler model action
onFinalLoopCompleteMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"finalloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
onFinalLoopCompleteMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onFinalLoopCompleteMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onFinalLoopCompleteMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"finalloopcomplete" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
data ImageErrorEvent
= ImageErrorEvent
{ ImageErrorEvent -> MisoString
errorMessage :: MisoString
, ImageErrorEvent -> Int
errorCode :: Int
, ImageErrorEvent -> Int
lynxCategorizedCode :: Int
} deriving (Int -> ImageErrorEvent -> ShowS
[ImageErrorEvent] -> ShowS
ImageErrorEvent -> String
(Int -> ImageErrorEvent -> ShowS)
-> (ImageErrorEvent -> String)
-> ([ImageErrorEvent] -> ShowS)
-> Show ImageErrorEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImageErrorEvent -> ShowS
showsPrec :: Int -> ImageErrorEvent -> ShowS
$cshow :: ImageErrorEvent -> String
show :: ImageErrorEvent -> String
$cshowList :: [ImageErrorEvent] -> ShowS
showList :: [ImageErrorEvent] -> ShowS
Show, ImageErrorEvent -> ImageErrorEvent -> Bool
(ImageErrorEvent -> ImageErrorEvent -> Bool)
-> (ImageErrorEvent -> ImageErrorEvent -> Bool)
-> Eq ImageErrorEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImageErrorEvent -> ImageErrorEvent -> Bool
== :: ImageErrorEvent -> ImageErrorEvent -> Bool
$c/= :: ImageErrorEvent -> ImageErrorEvent -> Bool
/= :: ImageErrorEvent -> ImageErrorEvent -> Bool
Eq)
data ImageLoadEvent
= ImageLoadEvent
{ ImageLoadEvent -> Int
imageWidth :: Int
, ImageLoadEvent -> Int
imageHeight :: Int
} deriving (Int -> ImageLoadEvent -> ShowS
[ImageLoadEvent] -> ShowS
ImageLoadEvent -> String
(Int -> ImageLoadEvent -> ShowS)
-> (ImageLoadEvent -> String)
-> ([ImageLoadEvent] -> ShowS)
-> Show ImageLoadEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImageLoadEvent -> ShowS
showsPrec :: Int -> ImageLoadEvent -> ShowS
$cshow :: ImageLoadEvent -> String
show :: ImageLoadEvent -> String
$cshowList :: [ImageLoadEvent] -> ShowS
showList :: [ImageLoadEvent] -> ShowS
Show, ImageLoadEvent -> ImageLoadEvent -> Bool
(ImageLoadEvent -> ImageLoadEvent -> Bool)
-> (ImageLoadEvent -> ImageLoadEvent -> Bool) -> Eq ImageLoadEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImageLoadEvent -> ImageLoadEvent -> Bool
== :: ImageLoadEvent -> ImageLoadEvent -> Bool
$c/= :: ImageLoadEvent -> ImageLoadEvent -> Bool
/= :: ImageLoadEvent -> ImageLoadEvent -> Bool
Eq)
imageLoadDecoder :: Decoder ImageLoadEvent
imageLoadDecoder :: Decoder ImageLoadEvent
imageLoadDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser ImageLoadEvent) -> Decoder ImageLoadEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser ImageLoadEvent
details
where
details :: Value -> Parser ImageLoadEvent
details = MisoString
-> (Object -> Parser ImageLoadEvent)
-> Value
-> Parser ImageLoadEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser ImageLoadEvent)
-> Value -> Parser ImageLoadEvent)
-> (Object -> Parser ImageLoadEvent)
-> Value
-> Parser ImageLoadEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Int -> Int -> ImageLoadEvent
ImageLoadEvent
(Int -> Int -> ImageLoadEvent)
-> Parser Int -> Parser (Int -> ImageLoadEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"width"
Parser (Int -> ImageLoadEvent)
-> Parser Int -> Parser ImageLoadEvent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"height"
imageErrorDecoder :: Decoder ImageErrorEvent
imageErrorDecoder :: Decoder ImageErrorEvent
imageErrorDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser ImageErrorEvent) -> Decoder ImageErrorEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser ImageErrorEvent
details
where
details :: Value -> Parser ImageErrorEvent
details = MisoString
-> (Object -> Parser ImageErrorEvent)
-> Value
-> Parser ImageErrorEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser ImageErrorEvent)
-> Value -> Parser ImageErrorEvent)
-> (Object -> Parser ImageErrorEvent)
-> Value
-> Parser ImageErrorEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
MisoString -> Int -> Int -> ImageErrorEvent
ImageErrorEvent
(MisoString -> Int -> Int -> ImageErrorEvent)
-> Parser MisoString -> Parser (Int -> Int -> ImageErrorEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser MisoString
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"errMsg"
Parser (Int -> Int -> ImageErrorEvent)
-> Parser Int -> Parser (Int -> ImageErrorEvent)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"error_code"
Parser (Int -> ImageErrorEvent)
-> Parser Int -> Parser ImageErrorEvent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"lynx_categorized_code"
onLoadWith :: (ImageLoadEvent -> DOMRef -> action) -> Attribute model action
onLoadWith :: forall action model.
(ImageLoadEvent -> DOMRef -> action) -> Attribute model action
onLoadWith ImageLoadEvent -> DOMRef -> action
action = MisoString
-> Decoder ImageLoadEvent
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"load" Decoder ImageLoadEvent
imageLoadDecoder ((ImageLoadEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ImageLoadEvent
x model
_ DOMRef
domRef -> ImageLoadEvent -> DOMRef -> action
action ImageLoadEvent
x DOMRef
domRef
onErrorWith :: (ImageErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith :: forall action model.
(ImageErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith ImageErrorEvent -> DOMRef -> action
action = MisoString
-> Decoder ImageErrorEvent
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"error" Decoder ImageErrorEvent
imageErrorDecoder ((ImageErrorEvent -> model -> DOMRef -> action)
-> Attribute model action)
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ImageErrorEvent
x model
_ DOMRef
domRef -> ImageErrorEvent -> DOMRef -> action
action ImageErrorEvent
x DOMRef
domRef
onStartPlayWith :: (DOMRef -> action) -> Attribute model action
onStartPlayWith :: forall action model. (DOMRef -> action) -> Attribute model action
onStartPlayWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"startplay" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
onCurrentLoopCompleteWith :: (DOMRef -> action) -> Attribute model action
onCurrentLoopCompleteWith :: forall action model. (DOMRef -> action) -> Attribute model action
onCurrentLoopCompleteWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"currentloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
onFinalLoopCompleteWith :: (DOMRef -> action) -> Attribute model action
onFinalLoopCompleteWith :: forall action model. (DOMRef -> action) -> Attribute model action
onFinalLoopCompleteWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"finalloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)