1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075(* 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)(* TODO? inline function calls *)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