0 | module Text.SVG.Types
3 | import Derive.Prelude
4 | import public Data.Refined
7 | %language ElabReflection
12 | renderDouble : Double -> String
15 | in case [<] <>< unpack s of
16 | (h :< '.' :< '0') => pack (h <>> [])
20 | Interpolation Double where interpolate = renderDouble
23 | data SVGAngle : Type where
24 | Deg : Double -> SVGAngle
25 | Rad : Double -> SVGAngle
26 | Grad : Double -> SVGAngle
29 | Interpolation SVGAngle where
30 | interpolate (Deg x) = renderDouble x ++ "deg"
31 | interpolate (Rad x) = renderDouble x ++ "rad"
32 | interpolate (Grad x) = renderDouble x ++ "grad"
35 | deg : Cast SVGAngle a => Double -> a
39 | rad : Cast SVGAngle a => Double -> a
43 | grad : Cast SVGAngle a => Double -> a
47 | (.deg) : Cast SVGAngle a => Double -> a
51 | (.rad) : Cast SVGAngle a => Double -> a
55 | (.grad) : Cast SVGAngle a => Double -> a
56 | (.grad) = cast . Grad
63 | IsPercentage : Double -> Bool
64 | IsPercentage x = 0 <= x && x <= 100
69 | record Percentage where
70 | constructor MkPercentage
72 | {auto 0 prf : Holds IsPercentage value}
74 | %runElab derive "Percentage" [Show,Eq,Ord]
77 | Interpolation Percentage where
78 | interpolate (MkPercentage v) = renderDouble v ++ "%"
88 | {auto _ : Cast Percentage a}
90 | -> {auto 0 prf : Holds IsPercentage v}
92 | perc v = cast $
MkPercentage v
102 | {auto _ : Cast Percentage a}
104 | -> {auto 0 prf : Holds IsPercentage v}
106 | (.perc) v = cast $
MkPercentage v
112 | hexc : Bits8 -> Char
130 | hex : Bits8 -> List Char
131 | hex b = [hexc $
shiftR b 4, hexc $
b .&. 0xf]
134 | data SVGColor : Type where
135 | RGB : (red,green,blue : Bits8) -> SVGColor
136 | RGBA : (red,green,blue : Bits8) -> Percentage -> SVGColor
137 | Key : String -> SVGColor
140 | Interpolation SVGColor where
141 | interpolate (RGB r g b) = fastPack $
'#' :: hex r ++ hex g ++ hex b
142 | interpolate (RGBA r g b a) = "rgba(\{show r} \{show g} \{show b} \{a})"
143 | interpolate (Key s) = s
146 | Show SVGColor where show = interpolate
153 | data Length : Type where
154 | U : Double -> Length
155 | Pt : Double -> Length
156 | Px : Double -> Length
157 | Mm : Double -> Length
158 | Cm : Double -> Length
161 | Interpolation Length where
162 | interpolate (U x) = renderDouble x
163 | interpolate (Pt x) = renderDouble x ++ "pt"
164 | interpolate (Px x) = renderDouble x ++ "px"
165 | interpolate (Mm x) = renderDouble x ++ "mm"
166 | interpolate (Cm x) = renderDouble x ++ "cm"
169 | u : Cast Length a => Double -> a
173 | mm : Cast Length a => Double -> a
177 | cm : Cast Length a => Double -> a
181 | px : Cast Length a => Double -> a
185 | pt : Cast Length a => Double -> a
189 | (.u) : Cast Length a => Double -> a
193 | (.mm) : Cast Length a => Double -> a
197 | (.cm) : Cast Length a => Double -> a
201 | (.px) : Cast Length a => Double -> a
205 | (.pt) : Cast Length a => Double -> a
213 | data LengthOrPercentage : Type where
214 | Len : Length -> LengthOrPercentage
215 | Per : Percentage -> LengthOrPercentage
218 | Interpolation LengthOrPercentage where
219 | interpolate (Len x) = interpolate x
220 | interpolate (Per x) = interpolate x
223 | Cast Percentage LengthOrPercentage where cast = Per
226 | Cast Length LengthOrPercentage where cast = Len
233 | data PathCmd : Type where
234 | Move : (rel : Bool) -> (x,y : Double) -> PathCmd
235 | Line : (rel : Bool) -> (x,y : Double) -> PathCmd
236 | Horiz : (rel : Bool) -> (x : Double) -> PathCmd
237 | Vert : (rel : Bool) -> (y : Double) -> PathCmd
239 | Quadr : (rel : Bool) -> (x1,y1,x,y : Double) -> PathCmd
240 | QSucc : (rel : Bool) -> (x,y : Double) -> PathCmd
241 | Cubic : (rel : Bool) -> (x1,y1,x2,y2,x,y : Double) -> PathCmd
242 | CSucc : (rel : Bool) -> (x2,y2,x,y : Double) -> PathCmd
245 | -> (rx,ry,rot : Double)
246 | -> (largeArc,sweep : Bool)
250 | letter : Bool -> String -> String -> String
251 | letter False u l = u
252 | letter True u l = l
254 | digit : Bool -> String
259 | Interpolation PathCmd where
260 | interpolate (Move rel x y) = letter rel "M" "m" ++ "\{x} \{y}"
261 | interpolate (Line rel x y) = letter rel "L" "l" ++ "\{x} \{y}"
262 | interpolate (Horiz rel x) = letter rel "H" "h" ++ "\{x}"
263 | interpolate (Vert rel y) = letter rel "V" "v" ++ "\{y}"
264 | interpolate Z = "Z"
265 | interpolate (QSucc rel x y) =
266 | letter rel "T" "t" ++ "\{x} \{y}"
267 | interpolate (CSucc rel x2 y2 x y) =
268 | letter rel "S" "s" ++ "\{x2} \{y2},\{x} \{y}"
269 | interpolate (Quadr rel x1 y1 x y) =
270 | letter rel "Q" "q" ++ "\{x1} \{y1},\{x} \{y}"
271 | interpolate (Cubic rel x1 y1 x2 y2 x y) =
272 | letter rel "C" "c" ++ "\{x1} \{y1},\{x2} \{y2},\{x} \{y}"
273 | interpolate (Arc rel rx ry rot l s x y) =
274 | letter rel "A" "a" ++ "\{rx} \{ry} \{rot} \{digit l} \{digit s} \{x} \{y}"
278 | M : (x,y : Double) -> PathCmd
282 | m : (x,y : Double) -> PathCmd
286 | L : (x,y : Double) -> PathCmd
290 | l : (x,y : Double) -> PathCmd
294 | H : (x : Double) -> PathCmd
298 | h : (x : Double) -> PathCmd
302 | V : (x : Double) -> PathCmd
306 | v : (x : Double) -> PathCmd
310 | S : (x2,y2,x,y : Double) -> PathCmd
314 | s : (x2,y2,x,y : Double) -> PathCmd
318 | C : (x1,y1,x2,y2,x,y : Double) -> PathCmd
322 | c : (x1,y1,x2,y2,x,y : Double) -> PathCmd
326 | T : (x,y : Double) -> PathCmd
330 | t : (x,y : Double) -> PathCmd
334 | Q : (x1,y1,x,y : Double) -> PathCmd
338 | q : (x1,y1,x,y : Double) -> PathCmd
343 | (rx,ry,rot : Double)
344 | -> (largeArc,sweep : Bool)
351 | (rx,ry,rot : Double)
352 | -> (largeArc,sweep : Bool)
362 | data StrokeLinecap = Butt | Round | Square
365 | Interpolation StrokeLinecap where
366 | interpolate Butt = "butt"
367 | interpolate Round = "round"
368 | interpolate Square = "square"
370 | namespace StrokeLinejoin
372 | data StrokeLinejoin = Miter | Round | Bevel
375 | Interpolation StrokeLinejoin where
376 | interpolate Miter = "miter"
377 | interpolate Round = "round"
378 | interpolate Bevel = "bevel"
385 | data TextAnchor = Start | Middle | End
388 | Interpolation TextAnchor where
389 | interpolate Start = "start"
390 | interpolate Middle = "middle"
391 | interpolate End = "end"
393 | namespace DominantBaselie
395 | data DominantBaseline : Type where
396 | Auto : DominantBaseline
397 | Ideographic : DominantBaseline
398 | Alphabetic : DominantBaseline
399 | Hanging : DominantBaseline
400 | Mathematical : DominantBaseline
401 | Middle : DominantBaseline
402 | Central : DominantBaseline
403 | TextAfterEdge : DominantBaseline
404 | TextBeforeEdge : DominantBaseline
405 | TextBottom : DominantBaseline
406 | TextTop : DominantBaseline
409 | Interpolation DominantBaseline where
410 | interpolate Auto = "auto"
411 | interpolate Ideographic = "ideographic"
412 | interpolate Alphabetic = "alphabetic"
413 | interpolate Hanging = "hanging"
414 | interpolate Mathematical = "mathematical"
415 | interpolate Middle = "middle"
416 | interpolate Central = "central"
417 | interpolate TextAfterEdge = "text-after-edge"
418 | interpolate TextBeforeEdge = "text-before-edge"
419 | interpolate TextBottom = "text-bottom"
420 | interpolate TextTop = "text-top"
423 | data FontWeight : Type where
424 | Normal : FontWeight
426 | Bolder : FontWeight
427 | Lighter : FontWeight
428 | Val : Double -> FontWeight
431 | Interpolation FontWeight where
432 | interpolate Normal = "normal"
433 | interpolate Bold = "bold"
434 | interpolate Bolder = "bolder"
435 | interpolate Lighter = "lighter"
436 | interpolate (Val x) = renderDouble x
439 | data LengthAdjust = Spacing | SpacingAndGlyphs
442 | Interpolation LengthAdjust where
443 | interpolate Spacing = "spacing"
444 | interpolate SpacingAndGlyphs = "spacingAndGlyphs"
451 | data Transform : Type where
452 | Translate : (dx,dy : Double) -> Transform
453 | Rotate : (angle : Double) -> Transform
454 | Scale : (x,y : Double) -> Transform
455 | Matrix : (a,b,c,d,e,f : Double) -> Transform
458 | Interpolation Transform where
459 | interpolate (Translate dx dy) = "translate(\{dx},\{dy})"
460 | interpolate (Rotate angle) = "rotate(\{angle})"
461 | interpolate (Scale x y) = "scale(\{x},\{y})"
462 | interpolate (Matrix a b c d e f) = "matrix(\{a},\{b},\{c},\{d},\{e},\{f})"
473 | aliceblue : SVGColor
474 | aliceblue = Key "aliceblue"
477 | antiquewhite : SVGColor
478 | antiquewhite = Key "antiquewhite"
485 | aquamarine : SVGColor
486 | aquamarine = Key "aquamarine"
490 | azure = Key "azure"
494 | beige = Key "beige"
498 | bisque = Key "bisque"
501 | blanchedalmond : SVGColor
502 | blanchedalmond = Key "blanchedalmond"
506 | black = Key "black"
513 | blueviolet : SVGColor
514 | blueviolet = Key "blueviolet"
518 | brown = Key "brown"
521 | burlywood : SVGColor
522 | burlywood = Key "burlywood"
525 | cadetblue : SVGColor
526 | cadetblue = Key "cadetblue"
529 | chartreuse : SVGColor
530 | chartreuse = Key "chartreuse"
533 | chocolate : SVGColor
534 | chocolate = Key "chocolate"
538 | coral = Key "coral"
541 | cornflowerblue : SVGColor
542 | cornflowerblue = Key "cornflowerblue"
545 | cornsilk : SVGColor
546 | cornsilk = Key "cornsilk"
550 | crimson = Key "crimson"
557 | darkblue : SVGColor
558 | darkblue = Key "darkblue"
561 | darkcyan : SVGColor
562 | darkcyan = Key "darkcyan"
565 | darkgoldenrod : SVGColor
566 | darkgoldenrod = Key "darkgoldenrod"
569 | darkgray : SVGColor
570 | darkgray = Key "darkgray"
573 | darkgreen : SVGColor
574 | darkgreen = Key "darkgreen"
577 | darkgrey : SVGColor
578 | darkgrey = Key "darkgrey"
581 | darkkhaki : SVGColor
582 | darkkhaki = Key "darkkhaki"
585 | darkmagenta : SVGColor
586 | darkmagenta = Key "darkmagenta"
589 | darkolivegreen : SVGColor
590 | darkolivegreen = Key "darkolivegreen"
593 | darkorange : SVGColor
594 | darkorange = Key "darkorange"
597 | darkorchid : SVGColor
598 | darkorchid = Key "darkorchid"
602 | darkred = Key "darkred"
605 | darksalmon : SVGColor
606 | darksalmon = Key "darksalmon"
609 | darkseagreen : SVGColor
610 | darkseagreen = Key "darkseagreen"
613 | darkslateblue : SVGColor
614 | darkslateblue = Key "darkslateblue"
617 | darkslategray : SVGColor
618 | darkslategray = Key "darkslategray"
621 | darkslategrey : SVGColor
622 | darkslategrey = Key "darkslategrey"
625 | darkturquoise : SVGColor
626 | darkturquoise = Key "darkturquoise"
629 | darkviolet : SVGColor
630 | darkviolet = Key "darkviolet"
633 | deeppink : SVGColor
634 | deeppink = Key "deeppink"
637 | deepskyblue : SVGColor
638 | deepskyblue = Key "deepskyblue"
642 | dimgray = Key "dimgray"
646 | dimgrey = Key "dimgrey"
649 | dodgerblue : SVGColor
650 | dodgerblue = Key "dodgerblue"
653 | firebrick : SVGColor
654 | firebrick = Key "firebrick"
657 | floralwhite : SVGColor
658 | floralwhite = Key "floralwhite"
661 | forestgreen : SVGColor
662 | forestgreen = Key "forestgreen"
666 | fuchsia = Key "fuchsia"
669 | gainsboro : SVGColor
670 | gainsboro = Key "gainsboro"
673 | ghostwhite : SVGColor
674 | ghostwhite = Key "ghostwhite"
681 | goldenrod : SVGColor
682 | goldenrod = Key "goldenrod"
690 | green = Key "green"
693 | greenyellow : SVGColor
694 | greenyellow = Key "greenyellow"
701 | honeydew : SVGColor
702 | honeydew = Key "honeydew"
706 | hotpink = Key "hotpink"
709 | indianred : SVGColor
710 | indianred = Key "indianred"
714 | indigo = Key "indigo"
718 | ivory = Key "ivory"
722 | khaki = Key "khaki"
725 | lavender : SVGColor
726 | lavender = Key "lavender"
729 | lavenderblush : SVGColor
730 | lavenderblush = Key "lavenderblush"
733 | lawngreen : SVGColor
734 | lawngreen = Key "lawngreen"
737 | lemonchiffon : SVGColor
738 | lemonchiffon = Key "lemonchiffon"
741 | lightblue : SVGColor
742 | lightblue = Key "lightblue"
745 | lightcoral : SVGColor
746 | lightcoral = Key "lightcoral"
749 | lightcyan : SVGColor
750 | lightcyan = Key "lightcyan"
753 | lightgoldenrodyellow : SVGColor
754 | lightgoldenrodyellow = Key "lightgoldenrodyellow"
757 | lightgray : SVGColor
758 | lightgray = Key "lightgray"
761 | lightgreen : SVGColor
762 | lightgreen = Key "lightgreen"
765 | lightgrey : SVGColor
766 | lightgrey = Key "lightgrey"
769 | lightpink : SVGColor
770 | lightpink = Key "lightpink"
773 | lightsalmon : SVGColor
774 | lightsalmon = Key "lightsalmon"
777 | lightseagreen : SVGColor
778 | lightseagreen = Key "lightseagreen"
781 | lightskyblue : SVGColor
782 | lightskyblue = Key "lightskyblue"
785 | lightslategray : SVGColor
786 | lightslategray = Key "lightslategray"
789 | lightslategrey : SVGColor
790 | lightslategrey = Key "lightslategrey"
793 | lightsteelblue : SVGColor
794 | lightsteelblue = Key "lightsteelblue"
797 | lightyellow : SVGColor
798 | lightyellow = Key "lightyellow"
805 | limegreen : SVGColor
806 | limegreen = Key "limegreen"
810 | linen = Key "linen"
814 | magenta = Key "magenta"
818 | maroon = Key "maroon"
821 | mediumaquamarine : SVGColor
822 | mediumaquamarine = Key "mediumaquamarine"
825 | mediumblue : SVGColor
826 | mediumblue = Key "mediumblue"
829 | mediumorchid : SVGColor
830 | mediumorchid = Key "mediumorchid"
833 | mediumpurple : SVGColor
834 | mediumpurple = Key "mediumpurple"
837 | mediumseagreen : SVGColor
838 | mediumseagreen = Key "mediumseagreen"
841 | mediumslateblue : SVGColor
842 | mediumslateblue = Key "mediumslateblue"
845 | mediumspringgreen : SVGColor
846 | mediumspringgreen = Key "mediumspringgreen"
849 | mediumturquoise : SVGColor
850 | mediumturquoise = Key "mediumturquoise"
853 | mediumvioletred : SVGColor
854 | mediumvioletred = Key "mediumvioletred"
857 | midnightblue : SVGColor
858 | midnightblue = Key "midnightblue"
861 | mintcream : SVGColor
862 | mintcream = Key "mintcream"
865 | mistyrose : SVGColor
866 | mistyrose = Key "mistyrose"
869 | moccasin : SVGColor
870 | moccasin = Key "moccasin"
873 | navajowhite : SVGColor
874 | navajowhite = Key "navajowhite"
882 | oldlace = Key "oldlace"
886 | olive = Key "olive"
889 | olivedrab : SVGColor
890 | olivedrab = Key "olivedrab"
894 | orange = Key "orange"
897 | orangered : SVGColor
898 | orangered = Key "orangered"
902 | orchid = Key "orchid"
905 | palegoldenrod : SVGColor
906 | palegoldenrod = Key "palegoldenrod"
909 | palegreen : SVGColor
910 | palegreen = Key "palegreen"
913 | paleturquoise : SVGColor
914 | paleturquoise = Key "paleturquoise"
917 | palevioletred : SVGColor
918 | palevioletred = Key "palevioletred"
921 | papayawhip : SVGColor
922 | papayawhip = Key "papayawhip"
925 | peachpuff : SVGColor
926 | peachpuff = Key "peachpuff"
941 | powderblue : SVGColor
942 | powderblue = Key "powderblue"
946 | purple = Key "purple"
953 | rosybrown : SVGColor
954 | rosybrown = Key "rosybrown"
957 | royalblue : SVGColor
958 | royalblue = Key "royalblue"
961 | saddlebrown : SVGColor
962 | saddlebrown = Key "saddlebrown"
966 | salmon = Key "salmon"
969 | sandybrown : SVGColor
970 | sandybrown = Key "sandybrown"
973 | seagreen : SVGColor
974 | seagreen = Key "seagreen"
977 | seashell : SVGColor
978 | seashell = Key "seashell"
982 | sienna = Key "sienna"
986 | silver = Key "silver"
990 | skyblue = Key "skyblue"
993 | slateblue : SVGColor
994 | slateblue = Key "slateblue"
997 | slategray : SVGColor
998 | slategray = Key "slategray"
1002 | slategrey = Key "slategrey"
1010 | springgreen = Key "springgreen"
1014 | steelblue = Key "steelblue"
1026 | thistle = Key "thistle"
1034 | transparent = Key "transparent"
1038 | turquoise = Key "turquoise"
1054 | whitesmoke = Key "whitesmoke"
1062 | yellowgreen = Key "yellowgreen"