Tailwind classes in OCaml
at main 1.0 kB view raw
1type t = [ `Px 2 | `Zero 3 | `Auto 4 | `Rem of float 5 | `Fraction of int * int 6 | `Full 7 | `Screen 8 | `Min 9 | `Max 10 | `Fit 11 | `Viewport of [`W | `H] * [`S | `L | `D] ] 12 13let to_string = function 14 | `Px -> "px" 15 | `Zero -> "0" 16 | `Auto -> "auto" 17 | `Rem f -> 18 let s = string_of_float f in 19 if String.ends_with ~suffix:".0" s then 20 String.sub s 0 (String.length s - 2) 21 else if String.ends_with ~suffix:"." s then 22 String.sub s 0 (String.length s - 1) 23 else s 24 | `Fraction (n, d) -> Printf.sprintf "%d/%d" n d 25 | `Full -> "full" 26 | `Screen -> "screen" 27 | `Min -> "min" 28 | `Max -> "max" 29 | `Fit -> "fit" 30 | `Viewport (dir, size) -> 31 let d = match dir with `W -> "w" | `H -> "h" in 32 let s = match size with `S -> "s" | `L -> "l" | `D -> "d" in 33 Printf.sprintf "%sv%s" s d 34 35let px = `Px 36let zero = `Zero 37let auto = `Auto 38let full = `Full 39let screen = `Screen 40 41let rem f = `Rem f 42 43let fraction n d = `Fraction (n, d)