123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074(* Js_of_ocaml library
* http://www.ocsigen.org/js_of_ocaml/
* Copyright (C) 2010 Raphaël Proust
* Laboratoire PPS - CNRS Université Paris Diderot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)open!ImportmoduleColor=struct(* The type of CSS colors. First by name and then by constructor. *)typename=|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|Grey|Green|Greenyellow|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|Yellowgreenletstring_of_name=function|Aliceblue->"aliceblue"|Antiquewhite->"antiquewhite"|Aqua->"aqua"|Aquamarine->"aquamarine"|Azure->"azure"|Beige->"beige"|Bisque->"bisque"|Black->"black"|Blanchedalmond->"blanchedalmond"|Blue->"blue"|Blueviolet->"blueviolet"|Brown->"brown"|Burlywood->"burlywood"|Cadetblue->"cadetblue"|Chartreuse->"chartreuse"|Chocolate->"chocolate"|Coral->"coral"|Cornflowerblue->"cornflowerblue"|Cornsilk->"cornsilk"|Crimson->"crimson"|Cyan->"cyan"|Darkblue->"darkblue"|Darkcyan->"darkcyan"|Darkgoldenrod->"darkgoldenrod"|Darkgray->"darkgray"|Darkgreen->"darkgreen"|Darkgrey->"darkgrey"|Darkkhaki->"darkkhaki"|Darkmagenta->"darkmagenta"|Darkolivegreen->"darkolivegreen"|Darkorange->"darkorange"|Darkorchid->"darkorchid"|Darkred->"darkred"|Darksalmon->"darksalmon"|Darkseagreen->"darkseagreen"|Darkslateblue->"darkslateblue"|Darkslategray->"darkslategray"|Darkslategrey->"darkslategrey"|Darkturquoise->"darkturquoise"|Darkviolet->"darkviolet"|Deeppink->"deeppink"|Deepskyblue->"deepskyblue"|Dimgray->"dimgray"|Dimgrey->"dimgrey"|Dodgerblue->"dodgerblue"|Firebrick->"firebrick"|Floralwhite->"floralwhite"|Forestgreen->"forestgreen"|Fuchsia->"fuchsia"|Gainsboro->"gainsboro"|Ghostwhite->"ghostwhite"|Gold->"gold"|Goldenrod->"goldenrod"|Gray->"gray"|Green->"green"|Greenyellow->"greenyellow"|Grey->"grey"|Honeydew->"honeydew"|Hotpink->"hotpink"|Indianred->"indianred"|Indigo->"indigo"|Ivory->"ivory"|Khaki->"khaki"|Lavender->"lavender"|Lavenderblush->"lavenderblush"|Lawngreen->"lawngreen"|Lemonchiffon->"lemonchiffon"|Lightblue->"lightblue"|Lightcoral->"lightcoral"|Lightcyan->"lightcyan"|Lightgoldenrodyellow->"lightgoldenrodyellow"|Lightgray->"lightgray"|Lightgreen->"lightgreen"|Lightgrey->"lightgrey"|Lightpink->"lightpink"|Lightsalmon->"lightsalmon"|Lightseagreen->"lightseagreen"|Lightskyblue->"lightskyblue"|Lightslategray->"lightslategray"|Lightslategrey->"lightslategrey"|Lightsteelblue->"lightsteelblue"|Lightyellow->"lightyellow"|Lime->"lime"|Limegreen->"limegreen"|Linen->"linen"|Magenta->"magenta"|Maroon->"maroon"|Mediumaquamarine->"mediumaquamarine"|Mediumblue->"mediumblue"|Mediumorchid->"mediumorchid"|Mediumpurple->"mediumpurple"|Mediumseagreen->"mediumseagreen"|Mediumslateblue->"mediumslateblue"|Mediumspringgreen->"mediumspringgreen"|Mediumturquoise->"mediumturquoise"|Mediumvioletred->"mediumvioletred"|Midnightblue->"midnightblue"|Mintcream->"mintcream"|Mistyrose->"mistyrose"|Moccasin->"moccasin"|Navajowhite->"navajowhite"|Navy->"navy"|Oldlace->"oldlace"|Olive->"olive"|Olivedrab->"olivedrab"|Orange->"orange"|Orangered->"orangered"|Orchid->"orchid"|Palegoldenrod->"palegoldenrod"|Palegreen->"palegreen"|Paleturquoise->"paleturquoise"|Palevioletred->"palevioletred"|Papayawhip->"papayawhip"|Peachpuff->"peachpuff"|Peru->"peru"|Pink->"pink"|Plum->"plum"|Powderblue->"powderblue"|Purple->"purple"|Red->"red"|Rosybrown->"rosybrown"|Royalblue->"royalblue"|Saddlebrown->"saddlebrown"|Salmon->"salmon"|Sandybrown->"sandybrown"|Seagreen->"seagreen"|Seashell->"seashell"|Sienna->"sienna"|Silver->"silver"|Skyblue->"skyblue"|Slateblue->"slateblue"|Slategray->"slategray"|Slategrey->"slategrey"|Snow->"snow"|Springgreen->"springgreen"|Steelblue->"steelblue"|Tan->"tan"|Teal->"teal"|Thistle->"thistle"|Tomato->"tomato"|Turquoise->"turquoise"|Violet->"violet"|Wheat->"wheat"|White->"white"|Whitesmoke->"whitesmoke"|Yellow->"yellow"|Yellowgreen->"yellowgreen"letname_of_string=function|"aliceblue"->Aliceblue|"antiquewhite"->Antiquewhite|"aqua"->Aqua|"aquamarine"->Aquamarine|"azure"->Azure|"beige"->Beige|"bisque"->Bisque|"black"->Black|"blanchedalmond"->Blanchedalmond|"blue"->Blue|"blueviolet"->Blueviolet|"brown"->Brown|"burlywood"->Burlywood|"cadetblue"->Cadetblue|"chartreuse"->Chartreuse|"chocolate"->Chocolate|"coral"->Coral|"cornflowerblue"->Cornflowerblue|"cornsilk"->Cornsilk|"crimson"->Crimson|"cyan"->Cyan|"darkblue"->Darkblue|"darkcyan"->Darkcyan|"darkgoldenrod"->Darkgoldenrod|"darkgray"->Darkgray|"darkgreen"->Darkgreen|"darkgrey"->Darkgrey|"darkkhaki"->Darkkhaki|"darkmagenta"->Darkmagenta|"darkolivegreen"->Darkolivegreen|"darkorange"->Darkorange|"darkorchid"->Darkorchid|"darkred"->Darkred|"darksalmon"->Darksalmon|"darkseagreen"->Darkseagreen|"darkslateblue"->Darkslateblue|"darkslategray"->Darkslategray|"darkslategrey"->Darkslategrey|"darkturquoise"->Darkturquoise|"darkviolet"->Darkviolet|"deeppink"->Deeppink|"deepskyblue"->Deepskyblue|"dimgray"->Dimgray|"dimgrey"->Dimgrey|"dodgerblue"->Dodgerblue|"firebrick"->Firebrick|"floralwhite"->Floralwhite|"forestgreen"->Forestgreen|"fuchsia"->Fuchsia|"gainsboro"->Gainsboro|"ghostwhite"->Ghostwhite|"gold"->Gold|"goldenrod"->Goldenrod|"gray"->Gray|"green"->Green|"greenyellow"->Greenyellow|"grey"->Grey|"honeydew"->Honeydew|"hotpink"->Hotpink|"indianred"->Indianred|"indigo"->Indigo|"ivory"->Ivory|"khaki"->Khaki|"lavender"->Lavender|"lavenderblush"->Lavenderblush|"lawngreen"->Lawngreen|"lemonchiffon"->Lemonchiffon|"lightblue"->Lightblue|"lightcoral"->Lightcoral|"lightcyan"->Lightcyan|"lightgoldenrodyellow"->Lightgoldenrodyellow|"lightgray"->Lightgray|"lightgreen"->Lightgreen|"lightgrey"->Lightgrey|"lightpink"->Lightpink|"lightsalmon"->Lightsalmon|"lightseagreen"->Lightseagreen|"lightskyblue"->Lightskyblue|"lightslategray"->Lightslategray|"lightslategrey"->Lightslategrey|"lightsteelblue"->Lightsteelblue|"lightyellow"->Lightyellow|"lime"->Lime|"limegreen"->Limegreen|"linen"->Linen|"magenta"->Magenta|"maroon"->Maroon|"mediumaquamarine"->Mediumaquamarine|"mediumblue"->Mediumblue|"mediumorchid"->Mediumorchid|"mediumpurple"->Mediumpurple|"mediumseagreen"->Mediumseagreen|"mediumslateblue"->Mediumslateblue|"mediumspringgreen"->Mediumspringgreen|"mediumturquoise"->Mediumturquoise|"mediumvioletred"->Mediumvioletred|"midnightblue"->Midnightblue|"mintcream"->Mintcream|"mistyrose"->Mistyrose|"moccasin"->Moccasin|"navajowhite"->Navajowhite|"navy"->Navy|"oldlace"->Oldlace|"olive"->Olive|"olivedrab"->Olivedrab|"orange"->Orange|"orangered"->Orangered|"orchid"->Orchid|"palegoldenrod"->Palegoldenrod|"palegreen"->Palegreen|"paleturquoise"->Paleturquoise|"palevioletred"->Palevioletred|"papayawhip"->Papayawhip|"peachpuff"->Peachpuff|"peru"->Peru|"pink"->Pink|"plum"->Plum|"powderblue"->Powderblue|"purple"->Purple|"red"->Red|"rosybrown"->Rosybrown|"royalblue"->Royalblue|"saddlebrown"->Saddlebrown|"salmon"->Salmon|"sandybrown"->Sandybrown|"seagreen"->Seagreen|"seashell"->Seashell|"sienna"->Sienna|"silver"->Silver|"skyblue"->Skyblue|"slateblue"->Slateblue|"slategray"->Slategray|"slategrey"->Slategrey|"snow"->Snow|"springgreen"->Springgreen|"steelblue"->Steelblue|"tan"->Tan|"teal"->Teal|"thistle"->Thistle|"tomato"->Tomato|"turquoise"->Turquoise|"violet"->Violet|"wheat"->Wheat|"white"->White|"whitesmoke"->Whitesmoke|"yellow"->Yellow|"yellowgreen"->Yellowgreen|s->raise(Invalid_argument(s^" is not a valid color name"))letrgb_of_name=function|Aliceblue->240,248,255|Antiquewhite->250,235,215|Aqua->0,255,255|Aquamarine->127,255,212|Azure->240,255,255|Beige->245,245,220|Bisque->255,228,196|Black->0,0,0|Blanchedalmond->255,235,205|Blue->0,0,255|Blueviolet->138,43,226|Brown->165,42,42|Burlywood->222,184,135|Cadetblue->95,158,160|Chartreuse->127,255,0|Chocolate->210,105,30|Coral->255,127,80|Cornflowerblue->100,149,237|Cornsilk->255,248,220|Crimson->220,20,60|Cyan->0,255,255|Darkblue->0,0,139|Darkcyan->0,139,139|Darkgoldenrod->184,134,11|Darkgray->169,169,169|Darkgreen->0,100,0|Darkgrey->169,169,169|Darkkhaki->189,183,107|Darkmagenta->139,0,139|Darkolivegreen->85,107,47|Darkorange->255,140,0|Darkorchid->153,50,204|Darkred->139,0,0|Darksalmon->233,150,122|Darkseagreen->143,188,143|Darkslateblue->72,61,139|Darkslategray->47,79,79|Darkslategrey->47,79,79|Darkturquoise->0,206,209|Darkviolet->148,0,211|Deeppink->255,20,147|Deepskyblue->0,191,255|Dimgray->105,105,105|Dimgrey->105,105,105|Dodgerblue->30,144,255|Firebrick->178,34,34|Floralwhite->255,250,240|Forestgreen->34,139,34|Fuchsia->255,0,255|Gainsboro->220,220,220|Ghostwhite->248,248,255|Gold->255,215,0|Goldenrod->218,165,32|Gray->128,128,128|Green->0,128,0|Greenyellow->173,255,47|Grey->128,128,128|Honeydew->240,255,240|Hotpink->255,105,180|Indianred->205,92,92|Indigo->75,0,130|Ivory->255,255,240|Khaki->240,230,140|Lavender->230,230,250|Lavenderblush->255,240,245|Lawngreen->124,252,0|Lemonchiffon->255,250,205|Lightblue->173,216,230|Lightcoral->240,128,128|Lightcyan->224,255,255|Lightgoldenrodyellow->250,250,210|Lightgray->211,211,211|Lightgreen->144,238,144|Lightgrey->211,211,211|Lightpink->255,182,193|Lightsalmon->255,160,122|Lightseagreen->32,178,170|Lightskyblue->135,206,250|Lightslategray->119,136,153|Lightslategrey->119,136,153|Lightsteelblue->176,196,222|Lightyellow->255,255,224|Lime->0,255,0|Limegreen->50,205,50|Linen->250,240,230|Magenta->255,0,255|Maroon->128,0,0|Mediumaquamarine->102,205,170|Mediumblue->0,0,205|Mediumorchid->186,85,211|Mediumpurple->147,112,219|Mediumseagreen->60,179,113|Mediumslateblue->123,104,238|Mediumspringgreen->0,250,154|Mediumturquoise->72,209,204|Mediumvioletred->199,21,133|Midnightblue->25,25,112|Mintcream->245,255,250|Mistyrose->255,228,225|Moccasin->255,228,181|Navajowhite->255,222,173|Navy->0,0,128|Oldlace->253,245,230|Olive->128,128,0|Olivedrab->107,142,35|Orange->255,165,0|Orangered->255,69,0|Orchid->218,112,214|Palegoldenrod->238,232,170|Palegreen->152,251,152|Paleturquoise->175,238,238|Palevioletred->219,112,147|Papayawhip->255,239,213|Peachpuff->255,218,185|Peru->205,133,63|Pink->255,192,203|Plum->221,160,221|Powderblue->176,224,230|Purple->128,0,128|Red->255,0,0|Rosybrown->188,143,143|Royalblue->65,105,225|Saddlebrown->139,69,19|Salmon->250,128,114|Sandybrown->244,164,96|Seagreen->46,139,87|Seashell->255,245,238|Sienna->160,82,45|Silver->192,192,192|Skyblue->135,206,235|Slateblue->106,90,205|Slategray->112,128,144|Slategrey->112,128,144|Snow->255,250,250|Springgreen->0,255,127|Steelblue->70,130,180|Tan->210,180,140|Teal->0,128,128|Thistle->216,191,216|Tomato->255,99,71|Turquoise->64,224,208|Violet->238,130,238|Wheat->245,222,179|White->255,255,255|Whitesmoke->245,245,245|Yellow->255,255,0|Yellowgreen->154,205,50typet=|Nameofname|RGBof(int*int*int)(** Red, Green and Blue values. Clipped to [[0..255]] by most (All?)
browsers. *)|RGB_percentof(int*int*int)(** RGB channels are specified as a percentage of their maximal value. *)|RGBAof(int*int*int*float)(** Same as RGB with additional transparency argument. Opacity should be in
[0.] (completely transparent) and [1.] (completely opaque). *)|RGBA_percentof(int*int*int*float)(** RGB channels specified as percentage of their maximal value. Alpha
channel (opacity) is still a [0.] to [1.] float. *)|HSLof(int*int*int)(** Hue, Saturation and Lightness values. Hue is an angle in degree (in
interval [[0..360[]). Saturation is a percentage ([[0..100]]) with [0]
being colorless. Lightness is also a percentage ([[0..100]]) with [0]
being black. *)|HSLAof(int*int*int*float)(** Same as HSL with an opacity argument between [0.] and [1.]. *)letrgb?argb=matchawith|None->RGB(r,g,b)|Somea->RGBA(r,g,b,a)lethsl?ahsl=matchawith|None->HSL(h,s,l)|Somea->HSLA(h,s,l,a)letstring_of_t=function|Namen->string_of_namen|RGB(r,g,b)->Printf.sprintf"rgb(%d,%d,%d)"rgb|RGB_percent(r,g,b)->Printf.sprintf"rgb(%d%%,%d%%,%d%%)"rgb|RGBA(r,g,b,a)->Printf.sprintf"rgba(%d,%d,%d,%f)"rgba|RGBA_percent(r,g,b,a)->Printf.sprintf"rgba(%d%%,%d%%,%d%%,%f)"rgba|HSL(h,s,l)->Printf.sprintf"hsl(%d,%d%%,%d%%)"hsl|HSLA(h,s,l,a)->Printf.sprintf"hsla(%d,%d%%,%d%%,%f)"hslalethex_of_rgb(red,green,blue)=letin_rangei=ifi<0||i>255thenraise(Invalid_argument(string_of_inti^" is out of valid range"))inin_rangered;in_rangegreen;in_rangeblue;Printf.sprintf"#%02X%02X%02X"redgreenblue(* Ocaml <-> JS representation *)typejs_t=Js.js_stringJs.t(* TODO? be more restrictive, clip values into standard range *)letjs_t_of_js_strings=letrgb_re=new%jsJs.regExp(Js.bytestring"^rgb\\(\\s*\\d*,\\s*\\d*,\\s*\\d*\\)$")inletrgb_pct_re=new%jsJs.regExp(Js.bytestring"^rgb\\(\\s*\\d*%,\\s*\\d*%,\\s*\\d*%\\)$")inletrgba_re=new%jsJs.regExp(Js.bytestring"^rgba\\(\\s*\\d*,\\s*\\d*,\\s*\\d*,\\d*\\.?\\d*\\)$")inletrgba_pct_re=new%jsJs.regExp(Js.bytestring"^rgba\\(\\s*\\d*%,\\s*\\d*%,\\s*\\d*%,\\d*\\.?\\d*\\)$")inlethsl_re=new%jsJs.regExp(Js.bytestring"^hsl\\(\\s*\\d*,\\s*\\d*%,\\s*\\d*%\\)$")inlethsla_re=new%jsJs.regExp(Js.bytestring"^hsla\\(\\s*\\d*,\\s*\\d*%,\\s*\\d*%,\\d*\\.?\\d*\\)$")inifJs.to_bool(rgb_re##tests)||Js.to_bool(rgba_re##tests)||Js.to_bool(rgb_pct_re##tests)||Js.to_bool(rgba_pct_re##tests)||Js.to_bool(hsl_re##tests)||Js.to_bool(hsla_re##tests)thenselseifList.mem(Js.to_strings)["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"]thenselseraise(Invalid_argument(Js.to_strings^" is not a valid color"))letnamecn=Js.string(string_of_namecn)letjs=function|Namen->namen|(RGB_|RGB_percent_|RGBA_|RGBA_percent_|HSL_|HSLA_)asc->Js.string(string_of_tc)letmlc=lets=Js.to_stringcintryName(name_of_strings)withInvalid_argument_->(letfail()=raise(Invalid_argument(s^" is not a valid color"))inletre_rgb=Regexp.regexp"(rgba?)\\((?:(\\d*),(\\d*),(\\d*)(?:,(\\d*(?:\\.\\d*)?))?)\\)"inletre_rgb_pct=Regexp.regexp"(rgba?)\\((?:(\\d*)%,(\\d*)%,(\\d*)%(?:,(\\d*(?:\\.\\d*)?))?)\\)"inletre_hsl=Regexp.regexp"(hsla?)\\((?:(\\d*),(\\d*)%,(\\d*)%(?:,(\\d*(?:\\.\\d*)?))?)\\)"inleti_of_s_o=function|None->fail()|Somei->(tryint_of_stringiwithInvalid_arguments|Failures->raise(Invalid_argument("color conversion error ("^i^"): "^s)))inletf_of_sf=tryfloat_of_stringfwithInvalid_arguments|Failures->raise(Invalid_argument("color conversion error ("^f^"): "^s))inmatchRegexp.string_matchre_rgbs0with|Somer->(letred=Regexp.matched_groupr2inletgreen=Regexp.matched_groupr3inletblue=Regexp.matched_groupr4inletalpha=Regexp.matched_groupr5inmatchRegexp.matched_groupr1with|Some"rgb"->(matchalphawith|Some_->fail()|None->RGB(i_of_s_ored,i_of_s_ogreen,i_of_s_oblue))|Some"rgba"->(matchalphawith|None->fail()|Somea->RGBA(i_of_s_ored,i_of_s_ogreen,i_of_s_oblue,f_of_sa))|Some_|None->fail())|None->(matchRegexp.string_matchre_rgb_pcts0with|Somer->(letred=Regexp.matched_groupr2inletgreen=Regexp.matched_groupr3inletblue=Regexp.matched_groupr4inletalpha=Regexp.matched_groupr5inmatchRegexp.matched_groupr1with|Some"rgb"->(matchalphawith|Some_->fail()|None->RGB_percent(i_of_s_ored,i_of_s_ogreen,i_of_s_oblue))|Some"rgba"->(matchalphawith|None->fail()|Somea->RGBA_percent(i_of_s_ored,i_of_s_ogreen,i_of_s_oblue,f_of_sa))|Some_|None->fail())|None->(matchRegexp.string_matchre_hsls0with|Somer->(letred=Regexp.matched_groupr2inletgreen=Regexp.matched_groupr3inletblue=Regexp.matched_groupr4inletalpha=Regexp.matched_groupr5inmatchRegexp.matched_groupr1with|Some"hsl"->(matchalphawith|Some_->fail()|None->HSL(i_of_s_ored,i_of_s_ogreen,i_of_s_oblue))|Some"hsla"->(matchalphawith|None->fail()|Somea->HSLA(i_of_s_ored,i_of_s_ogreen,i_of_s_oblue,f_of_sa))|Some_|None->fail())|None->fail())))endmoduleLength=struct(* http://www.w3.org/TR/css3-values/#lengths *)(* TODO:
{[
type js_t = private Js.string Js.t
val js_t_of_t
val t_of_js_t
val t_of_string
]}
*)typet=|Zero(* relative *)|Emoffloat|Exoffloat|Pxoffloat|Gdoffloat|Remoffloat|Vwoffloat|Vhoffloat|Vmoffloat|Choffloat(* absolute *)|Mmoffloat|Cmoffloat|Inoffloat|Ptoffloat|Pcoffloatletstring_of_t=function|Zero->"0"|Emf->Printf.sprintf"%f%s"f"em"|Exf->Printf.sprintf"%f%s"f"ex"|Pxf->Printf.sprintf"%f%s"f"px"|Gdf->Printf.sprintf"%f%s"f"gd"|Remf->Printf.sprintf"%f%s"f"rem"|Vwf->Printf.sprintf"%f%s"f"vw"|Vhf->Printf.sprintf"%f%s"f"vh"|Vmf->Printf.sprintf"%f%s"f"vm"|Chf->Printf.sprintf"%f%s"f"ch"|Mmf->Printf.sprintf"%f%s"f"mm"|Cmf->Printf.sprintf"%f%s"f"cm"|Inf->Printf.sprintf"%f%s"f"in"|Ptf->Printf.sprintf"%f%s"f"pt"|Pcf->Printf.sprintf"%f%s"f"pc"typejs_t=Js.js_stringJs.tletjst=Js.string(string_of_tt)letmlt=lets=Js.to_stringtinifString.equals"0"thenZeroelseletfail()=raise(Invalid_argument(s^" is not a valid length"))inletre=Regexp.regexp"^(\\d*(?:\\.\\d*)?)\\s*(\\S*)$"inmatchRegexp.string_matchres0with|None->fail()|Somer->(letf=matchRegexp.matched_groupr1with|None->fail()|Somef->(tryfloat_of_stringfwithInvalid_arguments->raise(Invalid_argument("length conversion error: "^s)))inmatchRegexp.matched_groupr2with|None->fail()|Some"em"->Emf|Some"ex"->Exf|Some"px"->Pxf|Some"gd"->Gdf|Some"rem"->Remf|Some"vw"->Vwf|Some"vh"->Vhf|Some"vm"->Vmf|Some"ch"->Chf|Some"mm"->Mmf|Some"cm"->Cmf|Some"in"->Inf|Some"pt"->Ptf|Some"pc"->Pcf|Some_->fail())endmoduleAngle=structtypet=|Degoffloat|Gradoffloat|Radoffloat|Turnsoffloatletstring_of_t=function|Degf->Printf.sprintf"%f%s"f"deg"|Gradf->Printf.sprintf"%f%s"f"grad"|Radf->Printf.sprintf"%f%s"f"rad"|Turnsf->Printf.sprintf"%f%s"f"turns"typejs_t=Js.js_stringJs.tletjst=Js.string(string_of_tt)letmlj=lets=Js.to_stringjinletre=Regexp.regexp"^(\\d*(?:\\.\\d*))(deg|grad|rad|turns)$"inletfail()=raise(Invalid_argument(s^" is not a valid length"))inmatchRegexp.string_matchres0with|None->fail()|Somer->(letf=matchRegexp.matched_groupr1with|None->fail()|Somef->(tryfloat_of_stringfwithInvalid_arguments->raise(Invalid_argument("length conversion error: "^s)))inmatchRegexp.matched_groupr2with|Some"deg"->Degf|Some"grad"->Gradf|Some"rad"->Radf|Some"turns"->Turnsf|Some_|None->fail())end