From d876ec99afba1939801a7d46e746b917ced65f82 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 3 Dec 2024 22:57:12 +0100 Subject: [PATCH] Lib: small refactoring of cSS.ml --- lib/js_of_ocaml/cSS.ml | 164 ++--------------------------------------- 1 file changed, 5 insertions(+), 159 deletions(-) diff --git a/lib/js_of_ocaml/cSS.ml b/lib/js_of_ocaml/cSS.ml index 720a74c802..86c2c13ca2 100644 --- a/lib/js_of_ocaml/cSS.ml +++ b/lib/js_of_ocaml/cSS.ml @@ -703,166 +703,12 @@ module Color = struct || Js.to_bool (hsl_re##test s) || Js.to_bool (hsla_re##test s) then s - else if - List.mem - (Js.to_string s) - [ "aliceblue" - ; "antiquewhite" - ; "aqua" - ; "aquamarine" - ; "azure" - ; "beige" - ; "bisque" - ; "black" - ; "blanchedalmond" - ; "blue" - ; "blueviolet" - ; "brown" - ; "burlywood" - ; "cadetblue" - ; "chartreuse" - ; "chocolate" - ; "coral" - ; "cornflowerblue" - ; "cornsilk" - ; "crimson" - ; "cyan" - ; "darkblue" - ; "darkcyan" - ; "darkgoldenrod" - ; "darkgray" - ; "darkgreen" - ; "darkgrey" - ; "darkkhaki" - ; "darkmagenta" - ; "darkolivegreen" - ; "darkorange" - ; "darkorchid" - ; "darkred" - ; "darksalmon" - ; "darkseagreen" - ; "darkslateblue" - ; "darkslategray" - ; "darkslategrey" - ; "darkturquoise" - ; "darkviolet" - ; "deeppink" - ; "deepskyblue" - ; "dimgray" - ; "dimgrey" - ; "dodgerblue" - ; "firebrick" - ; "floralwhite" - ; "forestgreen" - ; "fuchsia" - ; "gainsboro" - ; "ghostwhite" - ; "gold" - ; "goldenrod" - ; "gray" - ; "green" - ; "greenyellow" - ; "grey" - ; "honeydew" - ; "hotpink" - ; "indianred" - ; "indigo" - ; "ivory" - ; "khaki" - ; "lavender" - ; "lavenderblush" - ; "lawngreen" - ; "lemonchiffon" - ; "lightblue" - ; "lightcoral" - ; "lightcyan" - ; "lightgoldenrodyellow" - ; "lightgray" - ; "lightgreen" - ; "lightgrey" - ; "lightpink" - ; "lightsalmon" - ; "lightseagreen" - ; "lightskyblue" - ; "lightslategray" - ; "lightslategrey" - ; "lightsteelblue" - ; "lightyellow" - ; "lime" - ; "limegreen" - ; "linen" - ; "magenta" - ; "maroon" - ; "mediumaquamarine" - ; "mediumblue" - ; "mediumorchid" - ; "mediumpurple" - ; "mediumseagreen" - ; "mediumslateblue" - ; "mediumspringgreen" - ; "mediumturquoise" - ; "mediumvioletred" - ; "midnightblue" - ; "mintcream" - ; "mistyrose" - ; "moccasin" - ; "navajowhite" - ; "navy" - ; "oldlace" - ; "olive" - ; "olivedrab" - ; "orange" - ; "orangered" - ; "orchid" - ; "palegoldenrod" - ; "palegreen" - ; "paleturquoise" - ; "palevioletred" - ; "papayawhip" - ; "peachpuff" - ; "peru" - ; "pink" - ; "plum" - ; "powderblue" - ; "purple" - ; "red" - ; "rosybrown" - ; "royalblue" - ; "saddlebrown" - ; "salmon" - ; "sandybrown" - ; "seagreen" - ; "seashell" - ; "sienna" - ; "silver" - ; "skyblue" - ; "slateblue" - ; "slategray" - ; "slategrey" - ; "snow" - ; "springgreen" - ; "steelblue" - ; "tan" - ; "teal" - ; "thistle" - ; "tomato" - ; "turquoise" - ; "violet" - ; "wheat" - ; "white" - ; "whitesmoke" - ; "yellow" - ; "yellowgreen" - ] - then s - else raise (Invalid_argument (Js.to_string s ^ " is not a valid color")) - - let name cn = Js.string (string_of_name cn) + else + match name_of_string (Js.to_string s) with + | _ -> s + | exception _ -> raise (Invalid_argument (Js.to_string s ^ " is not a valid color")) - let js = function - | Name n -> name n - | (RGB _ | RGB_percent _ | RGBA _ | RGBA_percent _ | HSL _ | HSLA _) as c -> - Js.string (string_of_t c) + let js c = Js.string (string_of_t c) let ml c = let s = Js.to_string c in