<commit_before>module Cinder.SVG
    (module Cinder.SVG, module Cinder.DOM, module Cinder.DSL)
    where

import Prelude hiding (min, max)
import FFI
import Cinder.DSL
import Cinder.DOM
import Cinder.SVG.Attributes hiding (path)
import Cinder.SVG.Elements

xmlns :: String
xmlns = "http://www.w3.org/2000/svg"

-- convenience methods for simple shapes

cR :: a -> Markup
cR = (markup ! circle ! ) . rN

cXYR :: a -> a -> a -> Markup
cXYR x y r = cRXY r x y

cRXY :: a -> a -> a -> Markup
cRXY r x y = cR r ! cxN x ! cyN y

rHW :: a -> a -> Markup
rHW h w = markup ! rect ! heightN h ! widthN w

rHWXY :: a -> a -> a -> a -> Markup
rHWXY h w x y = rHW h w ! xN x ! yN y

rXYHW :: a -> a -> a -> a -> Markup
rXYHW x y h w = rHWXY h w x y

eRR :: a -> a -> Markup
eRR rx ry = markup ! ellipse ! rxN rx ! ryN ry

eRRXY :: a -> a -> a -> a -> Markup
eRRXY rx ry x y = eRR rx ry ! cxN x ! cyN y

lXYXY :: a -> a -> a -> a -> Markup
lXYXY x y x' y' = markup ! line ! x1N x ! y1N y ! x2N x' ! y2N y'

lXXYY :: a -> a -> a -> a -> Markup
-- I know it looks stupid w/o y' but hlint wants I should eta reduce
lXXYY x x' y = lXYXY x y x'

--path stuff

data Seg = M Double Double
         | L Double Double
         | H Double
         | V Double
         | A Double Double Double Double Double Double Double
         | C Double Double Double Double Double Double
         | S Double Double Double Double
         | Q Double Double Double Double
         | T Double Double
         | Z
    deriving Show

showD :: [Seg] -> String
showD = concatMap hShow

showDRelative :: [Seg] -> String
showDRelative = toLower . showD

dS :: [Seg] -> Primitive
dS = d . showD

dSR :: [Seg] -> Primitive
dSR = d . showDRelative

pathD :: [Seg] -> Markup
pathD = (markup ! path !) . dS

pathDR :: [Seg] -> Markup
pathDR = (markup ! path !) . dSR

-- transform stuff

data Transform = Translate Double Double
               | Rotate Double Double Double
               | Scale Double
               | Scale2d Double Double

transformType :: Transform -> String
transformType Translate {} = "translate"
transformType Rotate {}    = "rotate"
transformType Scale {}     = "scale"
transformType Scale2d {}   = "scale"

transformVals :: Transform -> String
transformVals (Translate x y) = show x ++ "," ++ show y
transformVals (Rotate x y z)  = show x ++ "," ++ show y ++ "," ++ show z
transformVals (Scale x)       = show x
transformVals (Scale2d x y)   = show x ++ "," ++ show y

transformT :: [Transform] -> Primitive
transformT = transform . intercalate "," . map go
    where go t = transformType t ++ "(" ++ transformVals t ++ ")"

-- animation stuff

setATB :: String -> String -> a -> Markup
setATB a t b = markup ! set ! attributeName a ! to t ! beginN b

animationADR :: String -> a -> Double -> Markup
animationADR a d r = markup ! attributeName a ! durN d ! repeatCount (go r)
                     where go x | x > 0 = show x
                           go _         = "indefinite"

aADR :: String -> a -> Double -> Markup
aADR = (((markup ! animate !+) .) .) . animationADR

atDRT :: a -> Double -> [Transform] -> Markup
atDRT d r ts = markup ! animateTransform !+ animationADR "transform" d r
               ! at "type" (transformType $ head ts) ! vs (map transformVals ts)

beIndef :: Markup
beIndef = markup ! begin "indefinite" ! end "indefinite"

ft :: String -> String -> Markup
ft f t = markup ! from f ! to t

ftN :: a -> a -> Markup
ftN f t = markup ! fromN f ! toN t

vs :: [String] -> Primitive
vs = values . intercalate ";"

vsN :: [a] -> Primitive
vsN = vs . map show

pc :: a -> String
pc = (++"%") . show

--non-pure SVG specific stuff (animations and namespaces, mostly)
insert :: Markup -> Node -> Fay Node
insert = insertNS xmlns

node :: DString -> Fay Node
node = nodeNS xmlns

start :: Node -> Fay Node
start = ffi "%1['beginElement']() || %1"

stop :: Node -> Fay Node
stop = ffi "%1['endElement']() || %1"

-- attributes whose names conflict with keywords
classA :: String -> Primitive
classA = Attribute "class"

typeA :: String -> Primitive
typeA = Attribute "type"

inA :: String -> Primitive
inA = Attribute "in"

-- HACK!!!
inst :: Automatic a -> String
inst = ffi "%1['instance'] + ' '"<commit_msg>add funcs for baseVal and animVal<commit_after>module Cinder.SVG
    (module Cinder.SVG, module Cinder.DOM, module Cinder.DSL)
    where

import Prelude hiding (min, max)
import FFI
import Cinder.DSL
import Cinder.DOM
import Cinder.SVG.Attributes hiding (path)
import Cinder.SVG.Elements

xmlns :: String
xmlns = "http://www.w3.org/2000/svg"

-- convenience methods for simple shapes

cR :: a -> Markup
cR = (markup ! circle ! ) . rN

cXYR :: a -> a -> a -> Markup
cXYR x y r = cRXY r x y

cRXY :: a -> a -> a -> Markup
cRXY r x y = cR r ! cxN x ! cyN y

rHW :: a -> a -> Markup
rHW h w = markup ! rect ! heightN h ! widthN w

rHWXY :: a -> a -> a -> a -> Markup
rHWXY h w x y = rHW h w ! xN x ! yN y

rXYHW :: a -> a -> a -> a -> Markup
rXYHW x y h w = rHWXY h w x y

eRR :: a -> a -> Markup
eRR rx ry = markup ! ellipse ! rxN rx ! ryN ry

eRRXY :: a -> a -> a -> a -> Markup
eRRXY rx ry x y = eRR rx ry ! cxN x ! cyN y

lXYXY :: a -> a -> a -> a -> Markup
lXYXY x y x' y' = markup ! line ! x1N x ! y1N y ! x2N x' ! y2N y'

lXXYY :: a -> a -> a -> a -> Markup
-- I know it looks stupid w/o y' but hlint wants I should eta reduce
lXXYY x x' y = lXYXY x y x'

--path stuff

data Seg = M Double Double
         | L Double Double
         | H Double
         | V Double
         | A Double Double Double Double Double Double Double
         | C Double Double Double Double Double Double
         | S Double Double Double Double
         | Q Double Double Double Double
         | T Double Double
         | Z
    deriving Show

showD :: [Seg] -> String
showD = concatMap hShow

showDRelative :: [Seg] -> String
showDRelative = toLower . showD

dS :: [Seg] -> Primitive
dS = d . showD

dSR :: [Seg] -> Primitive
dSR = d . showDRelative

pathD :: [Seg] -> Markup
pathD = (markup ! path !) . dS

pathDR :: [Seg] -> Markup
pathDR = (markup ! path !) . dSR

-- transform stuff

data Transform = Translate Double Double
               | Rotate Double Double Double
               | Scale Double
               | Scale2d Double Double

transformType :: Transform -> String
transformType Translate {} = "translate"
transformType Rotate {}    = "rotate"
transformType Scale {}     = "scale"
transformType Scale2d {}   = "scale"

transformVals :: Transform -> String
transformVals (Translate x y) = show x ++ "," ++ show y
transformVals (Rotate x y z)  = show x ++ "," ++ show y ++ "," ++ show z
transformVals (Scale x)       = show x
transformVals (Scale2d x y)   = show x ++ "," ++ show y

transformT :: [Transform] -> Primitive
transformT = transform . intercalate "," . map go
    where go t = transformType t ++ "(" ++ transformVals t ++ ")"

-- animation stuff

setATB :: String -> String -> a -> Markup
setATB a t b = markup ! set ! attributeName a ! to t ! beginN b

animationADR :: String -> a -> Double -> Markup
animationADR a d r = markup ! attributeName a ! durN d ! repeatCount (go r)
                     where go x | x > 0 = show x
                           go _         = "indefinite"

aADR :: String -> a -> Double -> Markup
aADR = (((markup ! animate !+) .) .) . animationADR

atDRT :: a -> Double -> [Transform] -> Markup
atDRT d r ts = markup ! animateTransform !+ animationADR "transform" d r
               ! at "type" (transformType $ head ts) ! vs (map transformVals ts)

beIndef :: Markup
beIndef = markup ! begin "indefinite" ! end "indefinite"

ft :: String -> String -> Markup
ft f t = markup ! from f ! to t

ftN :: a -> a -> Markup
ftN f t = markup ! fromN f ! toN t

vs :: [String] -> Primitive
vs = values . intercalate ";"

vsN :: [a] -> Primitive
vsN = vs . map show

pc :: a -> String
pc = (++"%") . show

--non-pure SVG specific stuff (animations and namespaces, mostly)
insert :: Markup -> Node -> Fay Node
insert = insertNS xmlns

node :: DString -> Fay Node
node = nodeNS xmlns

start :: Node -> Fay Node
start = ffi "%1['beginElement']() || %1"

stop :: Node -> Fay Node
stop = ffi "%1['endElement']() || %1"

-- values for attributes whose values might be animated

baseVal :: String -> Node -> Fay String
baseVal = ffi "%2['%1'].baseVal.value"

baseValN :: String -> Node -> Fay Double
baseValN = ffi "%2['%1'].baseVal.value"

animVal :: String -> Node -> Fay String
animVal = ffi "%2['%1'].animVal.value"

animValN :: String -> Node -> Fay Double
animValN = ffi "%2['%1'].animVal.value"

-- attributes whose names conflict with keywords
classA :: String -> Primitive
classA = Attribute "class"

typeA :: String -> Primitive
typeA = Attribute "type"

inA :: String -> Primitive
inA = Attribute "in"

-- HACK!!!
inst :: Automatic a -> String
inst = ffi "%1['instance'] + ' '"
{'fraction_non_alphanumeric': 0.13531615393347712, 'fraction_numerical': 0.004994891588148484, 'mean_word_length': 2.5043754972155927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3662976', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2981, 'n_words': 1165}