module Hasmin.Parser.TimingFunction
( timingFunction
, cubicbezier
, steps
) where
import Control.Applicative (optional)
import Data.Attoparsec.Text (Parser)
import qualified Data.Attoparsec.Text as A
import Hasmin.Parser.Primitives
import Hasmin.Parser.Numeric
import Hasmin.Parser.Utils
import Hasmin.Types.TimingFunction
timingFunction :: Parser TimingFunction
timingFunction = parserFromPairs [("ease", pure Ease)
,("ease-in", pure EaseIn)
,("ease-in-out", pure EaseInOut)
,("ease-out", pure EaseOut)
,("linear", pure Linear)
,("step-end", pure StepEnd)
,("step-start", pure StepStart)
,("steps", A.char '(' *> steps)
,("cubic-bezier", A.char '(' *> cubicbezier)]
cubicbezier :: Parser TimingFunction
cubicbezier = functionParser $
CubicBezier <$> number <* comma <*> number <* comma
<*> number <* comma <*> number
steps :: Parser TimingFunction
steps = functionParser $ Steps <$> int <*> optional startOrEnd
where startOrEnd = comma *> parserFromPairs [("end", pure End)
,("start", pure Start)]