type t = [ `Px | `Zero | `Auto | `Rem of float | `Fraction of int * int | `Full | `Screen | `Min | `Max | `Fit | `Viewport of [`W | `H] * [`S | `L | `D] ] let to_string = function | `Px -> "px" | `Zero -> "0" | `Auto -> "auto" | `Rem f -> let s = string_of_float f in if String.ends_with ~suffix:".0" s then String.sub s 0 (String.length s - 2) else if String.ends_with ~suffix:"." s then String.sub s 0 (String.length s - 1) else s | `Fraction (n, d) -> Printf.sprintf "%d/%d" n d | `Full -> "full" | `Screen -> "screen" | `Min -> "min" | `Max -> "max" | `Fit -> "fit" | `Viewport (dir, size) -> let d = match dir with `W -> "w" | `H -> "h" in let s = match size with `S -> "s" | `L -> "l" | `D -> "d" in Printf.sprintf "%sv%s" s d let px = `Px let zero = `Zero let auto = `Auto let full = `Full let screen = `Screen let rem f = `Rem f let fraction n d = `Fraction (n, d)