0 | module Text.SVG.Attribute
4 | import Text.SVG.Types
14 | data SVGAttribute : (s : String) -> Type where
15 | Id : {0 s : _} -> String -> SVGAttribute s
16 | Str : {0 s : _} -> (name,val : String) -> SVGAttribute s
17 | Style : {0 s : _} -> (name,val : String) -> SVGAttribute s
18 | Bool : {0 s : _} -> (name : String) -> Bool -> SVGAttribute s
19 | LOP : {0 s : _} -> (name : String) -> LengthOrPercentage -> SVGAttribute s
20 | Perc : {0 s : _} -> (name : String) -> Percentage -> SVGAttribute s
21 | Pth : {0 s : _} -> (name : String) -> List PathCmd -> SVGAttribute s
22 | Points : {0 s : _} -> (name : String) -> List Double -> SVGAttribute s
23 | Empty : {0 s : _} -> SVGAttribute s
25 | opac : String -> Percentage -> String
26 | opac s p = #"\#{s}-opacity="\#{p}""#
28 | displayAttribute : {0 s : _} -> SVGAttribute s -> String
29 | displayAttribute (Id va) = #"id="\#{va}""#
30 | displayAttribute (Str nm va) = #"\#{nm}="\#{va}""#
31 | displayAttribute (LOP nm va) = #"\#{nm}="\#{va}""#
32 | displayAttribute (Perc nm va) = #"\#{nm}="\#{va}""#
33 | displayAttribute (Pth nm va) = #"\#{nm}="\#{unwords $ map interpolate va}""#
34 | displayAttribute (Points nm va) = #"\#{nm}="\#{unwords $ map renderDouble va}""#
35 | displayAttribute (Bool nm True) = nm
36 | displayAttribute (Bool _ False) = ""
37 | displayAttribute Empty = ""
38 | displayAttribute (Style nm va) = "\{nm}:\{va};"
41 | displayAttributes : {0 s : _} -> List (SVGAttribute s) -> String
42 | displayAttributes = go [<] [<]
44 | go : SnocList String -> SnocList String -> List (SVGAttribute f) -> String
45 | go [<] attrs [] = unwords (attrs <>> [])
46 | go styles attrs [] =
47 | unwords (attrs <>> [fastConcat $
"style=\"" :: (styles <>> ["\""])])
48 | go styles attrs (x::xs) =
50 | Style n v => go (styles :< "\{n}:\{v};") attrs xs
51 | _ => go styles (attrs :< displayAttribute x) xs
58 | d : List PathCmd -> SVGAttribute "path"
62 | r : LengthOrPercentage -> SVGAttribute "circle"
66 | x1 : LengthOrPercentage -> SVGAttribute "line"
70 | y1 : LengthOrPercentage -> SVGAttribute "line"
74 | x2 : LengthOrPercentage -> SVGAttribute "line"
78 | y2 : LengthOrPercentage -> SVGAttribute "line"
82 | xmlns : String -> SVGAttribute "svg"
86 | xmlns_2000 : SVGAttribute "svg"
87 | xmlns_2000 = xmlns "http://www.w3.org/2000/svg"
89 | parameters {0 s : String}
91 | svgCol : String -> SVGColor -> SVGAttribute s
94 | RGBA r g b a => Style n "\{RGB r g b};\{n}-opacity:\{show $ a.value / 100.0}"
95 | _ => Style n (interpolate c)
98 | transform : Transform -> SVGAttribute s
99 | transform = Str "transform" . interpolate
102 | transforms : List Transform -> SVGAttribute s
103 | transforms = Str "transform" . unwords . map interpolate
106 | translateX : (dx : Double) -> SVGAttribute s
107 | translateX dx = transform (Translate dx 0)
110 | translateY : (dy : Double) -> SVGAttribute s
111 | translateY dy = transform (Translate 0 dy)
114 | translate : (dx,dy : Double) -> SVGAttribute s
115 | translate dx dy = transform (Translate dx dy)
118 | rotate : (ang : Double) -> SVGAttribute s
119 | rotate ang = transform (Rotate ang)
122 | scaleX : (x : Double) -> SVGAttribute s
123 | scaleX x = transform (Scale x 1)
126 | scaleY : (y : Double) -> SVGAttribute s
127 | scaleY y = transform (Scale 1 y)
130 | scaleXY : (x,y : Double) -> SVGAttribute s
131 | scaleXY x y = transform (Scale x y)
134 | scale : (v : Double) -> SVGAttribute s
135 | scale v = transform (Scale v v)
138 | class : String -> SVGAttribute s
139 | class = Str "class"
142 | classes : List String -> SVGAttribute s
143 | classes = Str "class" . unwords
146 | cx : (0 prf : HasCX s) => LengthOrPercentage -> SVGAttribute s
150 | cy : (0 prf : HasCX s) => LengthOrPercentage -> SVGAttribute s
154 | rx : (0 prf : HasRX s) => LengthOrPercentage -> SVGAttribute s
158 | ry : (0 prf : HasRY s) => LengthOrPercentage -> SVGAttribute s
162 | x : (0 prf : HasX s) => LengthOrPercentage -> SVGAttribute s
166 | y : (0 prf : HasY s) => LengthOrPercentage -> SVGAttribute s
170 | fill : (0 p : HasFill s) => SVGColor -> SVGAttribute s
171 | fill = svgCol "fill"
174 | fillOpacity : (0 p : HasFill s) => Percentage -> SVGAttribute s
175 | fillOpacity = Style "fill-opacity" . interpolate
178 | stroke : (0 p : HasStroke s) => SVGColor -> SVGAttribute s
179 | stroke = svgCol "stroke"
182 | strokeLinecap : (0 p : HasStroke s) => StrokeLinecap -> SVGAttribute s
183 | strokeLinecap = Style "stroke-linecap" . interpolate
186 | strokeLinejoin : (0 p : HasStroke s) => StrokeLinejoin -> SVGAttribute s
187 | strokeLinejoin = Style "stroke-linejoin" . interpolate
190 | strokeOpacity : (0 p : HasStroke s) => Percentage -> SVGAttribute s
191 | strokeOpacity = Style "stroke-opacity" . interpolate
194 | width : (0 prf : HasWidth s) => LengthOrPercentage -> SVGAttribute s
195 | width = LOP "width"
198 | height : (0 prf : HasHeight s) => LengthOrPercentage -> SVGAttribute s
199 | height = LOP "height"
202 | strokeWidth : (0 p : HasStroke s) => LengthOrPercentage -> SVGAttribute s
203 | strokeWidth = Style "stroke-width" . interpolate
206 | strokeDasharray : (0 p : HasStroke s) => List Double -> SVGAttribute s
207 | strokeDasharray = Style "stroke-dasharray" . unwords . map renderDouble
210 | strokeDashoffset : (0 p : HasStroke s) => Double -> SVGAttribute s
211 | strokeDashoffset = Style "stroke-dashoffset" . renderDouble
214 | points : (0 p : HasPoints s) => List Double -> SVGAttribute s
215 | points = Points "points"
219 | {auto 0 prf : HasViewBox s}
220 | -> (minX, minY, width, height : LengthOrPercentage)
222 | viewBox mx my w h = Str "viewBox" "\{mx} \{my} \{w} \{h}"
225 | dominantBaseline : (0 p : IsText s) => DominantBaseline -> SVGAttribute s
226 | dominantBaseline = Style "dominant-baseline" . interpolate
229 | textAnchor : (0 p : IsText s) => TextAnchor -> SVGAttribute s
230 | textAnchor = Style "text-anchor" . interpolate
233 | font : (0 p : IsText s) => String -> SVGAttribute s
234 | font = Style "font"
237 | fontFamily : (0 p : IsText s) => String -> SVGAttribute s
238 | fontFamily = Style "font-family"
241 | fontWeight : (0 p : IsText s) => FontWeight -> SVGAttribute s
242 | fontWeight = Style "font-weight" . interpolate
245 | lengthAdjust : (0 p : IsText s) => LengthAdjust -> SVGAttribute s
246 | lengthAdjust = Str "lengthAdjust" . interpolate
249 | textLength : (0 p : IsText s) => LengthOrPercentage -> SVGAttribute s
250 | textLength = LOP "textLength"
253 | dx : (0 p : IsText s) => LengthOrPercentage -> SVGAttribute s
257 | dy : (0 p : IsText s) => LengthOrPercentage -> SVGAttribute s
261 | fontSize : (0 p : IsText s) => LengthOrPercentage -> SVGAttribute s
262 | fontSize = Style "font-size" . interpolate