1(function(){ 2 3// Declaration of names 4var BASICS = { 5 "black" : [0,0,0], 6 "blue" : [0,0,255], 7 "brown" : [191, 128, 64], 8 "cyan" : [0, 174, 239], 9 "darkgray" : [64, 64, 64], 10 "gray" : [128, 128, 128], 11 "green" : [0, 255, 0], 12 "lightgray" : [191, 191, 191], 13 "lime" : [191, 255, 0], 14 "magenta" : [237, 2, 140], 15 "olive" : [150, 141, 0], 16 "orange" : [255, 128, 0], 17 "pink" : [255, 191, 191], 18 "purple" : [191, 0, 64], 19 "red" : [255, 0, 0], 20 "teal" : [0, 128, 128], 21 "violet" : [128, 0, 128], 22 "white" : [255, 255, 255], 23 "yellow" : [255, 241, 1] 24} 25 26var SVGNAMES = {"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],"Grey":[128,128,128],"Green":[0,128,0],"GreenYellow":[173,255,47],"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,50]} 27 28var DVIPSNAMES = {"GreenYellow":[217,255,79],"Yellow":[255,255,0],"Goldenrod":[255,230,41],"Dandelion":[255,181,41],"Apricot":[255,173,122],"Peach":[255,128,77],"Melon":[255,138,128],"YellowOrange":[255,148,0],"Orange":[255,99,33],"BurntOrange":[255,125,0],"Bittersweet":[194,48,0],"RedOrange":[255,59,33],"Mahogany":[166,25,22],"Maroon":[173,23,55],"BrickRed":[184,20,11],"Red":[255,0,0],"OrangeRed":[255,0,128],"RubineRed":[255,0,222],"WildStrawberry":[255,10,156
28],"Salmon":[255,120,158],"CarnationPink":[255,94,255],"Magenta":[255,0,255],"VioletRed":[255,48,255],"Rhodamine":[255,46,255],"Mulberry":[165,25,250],"RedViolet":[157,17,168],"Fuchsia":[124,21,235],"Lavender":[255,133,255],"Thistle":[224,105,255],"Orchid":[173,92,255],"DarkOrchid":[153,51,204],"Purple":[140,36,255],"Plum":[128,0,255],"Violet":[54,31,255],"RoyalPurple":[64,25,255],"BlueViolet":[34,22,245],"Periwinkle":[110,115,255],"CadetBlue":[97,110,196],"CornflowerBlue":[89,222,255],"MidnightBlue":[3,126,145],"NavyBlue":[15,117,255],"RoyalBlue":[0,128,255],"Blue":[0,0,255],"Cerulean":[15,227,255],"Cyan":[0,255,255],"ProcessBlue":[10,255,255],"SkyBlue":[97,255,224],"Turquoise":[38,255,204],"TealBlue":[35,250,165],"Aquamarine":[46,255,179],"BlueGreen":[38,255,171],"Emerald":[0,255,128],"JungleGreen":[3,255,122],"SeaGreen":[79,255,128],"Green":[0,255,0],"ForestGreen":[20,224,27],"PineGreen":[15,191,78],"LimeGreen":[128,255,0],"YellowGreen":[143,255,66],"SpringGreen":[189,255,61],"OliveGreen":[55,153,8],"RawSienna":[140,39,0],"Sepia":[77,13,0],"Brown":[102,19,0],"Tan":[219,148,112],"Gray":[128,128,128],"Black":[0,0,0],"White":[255,255,255]} 29 30var X11COLORS = {"Snow1":[0,255,250],"Snow2":[0,238,233],"Snow3":[0,205,201],"Snow4":[0,139,137],"Seashell1":[0,255,245],"Seashell2":[0,238,229],"Seashell3":[0,205,197],"Seashell4":[0,139,134],"AntiqueWhite1":[0,255,239],"AntiqueWhite2":[0,238,223],"AntiqueWhite3":[0,205,192],"AntiqueWhite4":[0,139,131],"Bisque1":[0,255,228],"Bisque2":[0,238,213],"Bisque3":[0,205,183],"Bisque4":[0,139,125],"PeachPuff1":[0,255,218],"PeachPuff2":[0,238,203],"PeachPuff3":[0,205,175],"PeachPuff4":[0,139,119],"NavajoWhite1":[0,255,222],"NavajoWhite2":[0,238,207],"NavajoWhite3":[0,205,179],"NavajoWhite4":[0,139,121],"LemonChiffon1":[0,255,250],"LemonChiffon2":[0,238,233],"LemonChiffon3":[0,205,201],"LemonChiffon4":[0,139,137],"Cornsilk1":[0,255,248],"Cornsilk2":[0,238,232],"Cornsilk3":[0,205,200],"Cornsilk4":[0,139,136],"Ivory1":[0,255,255],"Ivory2":[0,238,238],"Ivory3":[0,205,205],"Ivory4":[0,139,139],"Honeydew1":[0,240,255],"Honeydew2":[0,224,238],"Honeydew3":[0,193,205],"Honeydew4":[0,131,139],"LavenderBlush1":[0,255,240],"LavenderBlush2":[0,238,224],"LavenderBlush3":[0,205,193],"LavenderBlush4":[0,139,131],"MistyRose1":[0,255,228],"MistyRose2":[0,238,213],"MistyRose3":[0,205,183],"MistyRose4":[0,139,125],"Azure1":[0,240,255],"Azure2":[0,224,238],"Azure3":[0,193,205],"Azure4":[0,131,139],"SlateBlue1":[0,131,111],"SlateBlue2":[0,122,103],"SlateBlue3":[0,105,89],"SlateBlue4":[0,71,60],"RoyalBlue1":[0,72,118],"RoyalBlue2":[0,67,110],"RoyalBlue3":[0,58,95],"RoyalBlue4":[0,39,64],"Blue1":[0,0,0],"Blue2":[0,0,0],"Blue3":[0,0,0],"Blue4":[0,0,0],"DodgerBlue1":[0,30,144],"DodgerBlue2":[0,28,134],"DodgerBlue3":[0,24,116],"DodgerBlue4":[0,16,78],"SteelBlue1":[0,99,184],"SteelBlue2":[0,92,172],"SteelBlue3":[0,79,148],"SteelBlue4":[0,54,100],"DeepSkyBlue1":[0,0,191],"DeepSkyBlue2":[0,0,178],"DeepSkyBlue3":[0,0,154],"DeepSkyBlue4":[0,0,104],"SkyBlue1":[0,135,206],"SkyBlue2":[0,126,192],"SkyBlue3":[0,108,166],"SkyBlue4":[0,74,112],"LightSkyBlue1":[0,176,226],"LightSkyBlue2":[0,164,211],"LightSkyBlue3":[0,141,182],"LightSkyBlue4":[0,96,123],"SlateGray1":[0,198,226],"SlateGray2":[0,185,211],"SlateGray3":[0,159,182],"SlateGray4":[0,108,123],"LightSteelBlue1":[0,202,225],"LightSteelBlue2":[0,188,210],"LightSteelBlue3":[0,162,181],"LightSteelBlue4":[0,110,123],"LightBlue1":[0,191,239],"LightBlue2":[
300,178,223],"LightBlue3":[0,154,192],"LightBlue4":[0,104,131],"LightCyan1":[0,224,255],"LightCyan2":[0,209,238],"LightCyan3":[0,180,205],"LightCyan4":[0,122,139],"PaleTurquoise1":[0,187,255],"PaleTurquoise2":[0,174,238],"PaleTurquoise3":[0,150,205],"PaleTurquoise4":[0,102,139],"CadetBlue1":[0,152,245],"CadetBlue2":[0,142,229],"CadetBlue3":[0,122,197],"CadetBlue4":[0,83,134],"Turquoise1":[0,0,245],"Turquoise2":[0,0,229],"Turquoise3":[0,0,197],"Turquoise4":[0,0,134],"Cyan1":[0,0,255],"Cyan2":[0,0,238],"Cyan3":[0,0,205],"Cyan4":[0,0,139],"DarkSlateGray1":[0,151,255],"DarkSlateGray2":[0,141,238],"DarkSlateGray3":[0,121,205],"DarkSlateGray4":[0,82,139],"Aquamarine1":[0,127,255],"Aquamarine2":[0,118,238],"Aquamarine3":[0,102,205],"Aquamarine4":[0,69,139],"DarkSeaGreen1":[0,193,255],"DarkSeaGreen2":[0,180,238],"DarkSeaGreen3":[0,155,205],"DarkSeaGreen4":[0,105,139],"SeaGreen1":[0,84,255],"SeaGreen2":[0,78,238],"SeaGreen3":[0,67,205],"SeaGreen4":[0,46,139],"PaleGreen1":[0,154,255],"PaleGreen2":[0,144,238],"PaleGreen3":[0,124,205],"PaleGreen4":[0,84,139],"SpringGreen1":[0,0,255],"SpringGreen2":[0,0,238],"SpringGreen3":[0,0,205],"SpringGreen4":[0,0,139],"Green1":[0,0,255],"Green2":[0,0,238],"Green3":[0,0,205],"Green4":[0,0,139],"Chartreuse1":[0,127,255],"Chartreuse2":[0,118,238],"Chartreuse3":[0,102,205],"Chartreuse4":[0,69,139],"OliveDrab1":[0,192,255],"OliveDrab2":[0,179,238],"OliveDrab3":[0,154,205],"OliveDrab4":[0,105,139],"DarkOliveGreen1":[0,202,255],"DarkOliveGreen2":[0,188,238],"DarkOliveGreen3":[0,162,205],"DarkOliveGreen4":[0,110,139],"Khaki1":[0,255,246],"Khaki2":[0,238,230],"Khaki3":[0,205,198],"Khaki4":[0,139,134],"LightGoldenrod1":[0,255,236],"LightGoldenrod2":[0,238,220],"LightGoldenrod3":[0,205,190],"LightGoldenrod4":[0,139,129],"LightYellow1":[0,255,255],"LightYellow2":[0,238,238],"LightYellow3":[0,205,205],"LightYellow4":[0,139,139],"Yellow1":[0,255,255],"Yellow2":[0,238,238],"Yellow3":[0,205,205],"Yellow4":[0,139,139],"Gold1":[0,255,215],"Gold2":[0,238,201],"Gold3":[0,205,173],"Gold4":[0,139,117],"Goldenrod1":[0,255,193],"Goldenrod2":[0,238,180],"Goldenrod3":[0,205,155],"Goldenrod4":[0,139,105],"DarkGoldenrod1":[0,255,185],"DarkGoldenrod2":[0,238,173],"DarkGoldenrod3":[0,205,149],"DarkGoldenrod4":[0,139,101],"RosyBrown1":[0,255,193],"RosyBrown2":[0,238,180],"RosyBrown3":[0,205,155],"RosyBrown4":[0,139,105],"IndianRed1":[0,255,106],"IndianRed2":[0,238,99],"IndianRed3":[0,205,85],"IndianRed4":[0,139,58],"Sienna1":[0,255,130],"Sienna2":[0,238,121],"Sienna3":[0,205,104],"Sienna4":[0,139,71],"Burlywood1":[0,255,211],"Burlywood2":[0,238,197],"Burlywood3":[0,205,170],"Burlywood4":[0,139,115],"Wheat1":[0,255,231],"Wheat2":[0,238,216],"Wheat3":[0,205,186],"Wheat4":[0,139,126],"Tan1":[0,255,165],"Tan2":[0,238,154],"Tan3":[0,205,133],"Tan4":[0,139,90],"Chocolate1":[0,255,127],"Chocolate2":[0,238,118],"Chocolate3":[0,205,102],"Chocolate4":[0,139,69],"Firebrick1":[0,255,48],"Firebrick2":[0,238,44],"Firebrick3":[0,205,38],"Firebrick4":[0,139,26],"Brown1":[0,255,64],"Brown2":[0,238,59],"Brown3":[0,205,51],"Brown4":[0,139,35],"Salmon1":[0,255,140],"Salmon2":[0,238,130],"Salmon3":[0,205,112],"Salmon4":[0,139,76],"LightSalmon1":[0,255,160],"LightSalmon2":[0,238,149],"LightSalmon3":[0,205,129],"LightSalmon4":[0,139,87],"Orange1":[0,255,165],"Orange2":[0,238,154],"Orange3":[0,205,133],"Orange4":[0,139,90],"DarkOrange1":[0,255,127],"DarkOrange2":[0,238,118],"DarkOrange3":[0,205,102],"DarkOrange4":[0,139,69],"Coral1":[0,255,114],"Coral2":[0,238,106],"Coral3":[0,205,91],"Coral4":[0,139,62],"Tomato1":[0,255,99],"Tomato2":[0,238,92],"Tomato3":[0,205,79],"Tomato4":[0,139,54],"OrangeRed1":[0,255,69],"OrangeRed2":[0,238,64],"OrangeRed3":[0,205,55],"OrangeRed4":[0,139,37],"Red1":[0,255,0],"Red2":[0,238,0],"Red3":[0,205,0],"Red4":[0,139,0],"DeepPink1":[0,255,20],"DeepPink2":[0,238,18],"DeepPink3":[0,205,16],"DeepPink4":[0,139,10],"HotPink1":[0,255,110],"HotPink2":[0,238,106],"HotPink3":[0,205,96],"HotPink4":[0,139,58],"Pink1":[0,255,181],"Pink2":[0,238,169],"Pink3":[0,205,145],"Pink4":[0,139,99],"LightPink1":[0,255,174],"LightPink2":[0,238,162],"LightPink3":[0,205,140],"LightPink4":[0,139,95],"PaleVioletRed1":[0,255,130],"PaleVioletRed2":[0,238,121],"PaleVioletRed3":[0,205,104],"PaleVioletRed4":[0,139,71],"Maroon1":[0,255,52],"Maroon2":[0,238,48],"Maroon3":[0,205,41],"Maroon4":[0,139,28],"VioletRed1":[0,255,62],"VioletRed2":[0,238,58],"VioletRed3":[0,205,50],"VioletRed4":[0,139,34],"Magenta1":[0,255,0],"Magenta2":[0,238,0],"Magenta3":[0,205,0],"Magenta4":[0,139,0],"Orchid1":[0,255,131],"Orchid2":[0,238,122],"Orchid3":[0,205,105],"Orchid4":[0,139,71],"Plum1":[0,255,187],"Plum2":[
300,238,174],"Plum3":[0,205,150],"Plum4":[0,139,102],"MediumOrchid1":[0,224,102],"MediumOrchid2":[0,209,95],"MediumOrchid3":[0,180,82],"MediumOrchid4":[0,122,55],"DarkOrchid1":[0,191,62],"DarkOrchid2":[0,178,58],"DarkOrchid3":[0,154,50],"DarkOrchid4":[0,104,34],"Purple1":[0,155,48],"Purple2":[0,145,44],"Purple3":[0,125,38],"Purple4":[0,85,26],"MediumPurple1":[0,171,130],"MediumPurple2":[0,159,121],"MediumPurple3":[0,137,104],"MediumPurple4":[0,93,71],"Thistle1":[0,255,225],"Thistle2":[0,238,210],"Thistle3":[0,205,181],"Thistle4":[0,139,123], 31"Gray0":[190,190,190], "Grey0":[190,190,190], "Green0" : [0,255,0], "Maroon0":[176,48,96], "Purple0": [160,32,240]}; 32 33var NINECOLORS = {red1:[71,15,15],red2:[112,24,24],red3:[148,31,31],red4:[184,39,39],red5:[214,60,60],red6:[222,102,102],red7:[230,138,138],red8:[237,175,175],red9:[247,215,215],brown1:[54,32,11],brown2:[84,51,18],brown3:[110,66,23],brown4:[138,83,29],brown5:[168,102,35],brown6:[199,120,42],brown7:[219,150,81],brown8:[230,182,135],brown9:[242,218,194],yellow1:[38,38,8],yellow2:[59,59,12],yellow3:[79,79,17],yellow4:[99,99,21],yellow5:[122,122,26],yellow6:[145,145,31],yellow7:[168,168,35],yellow8:[196,196,41],yellow9:[227,227,123],olive1:[25,41,9],olive2:[39,64,13],olive3:[52,87,18],olive4:[65,107,22],olive5:[79,130,27],olive6:[94,156,33],olive7:[111,184,39],olive8:[131,212,51],olive9:[195,235,155],green1:[9,43,9],green2:[14,66,14],green3:[19,89,19],green4:[24,112,24],green5:[28,135,28],green6:[34,161,34],green7:[40,189,40],green8:[78,217,78],green9:[171,237,171],teal1:[9,41,25],teal2:[14,66,40],teal3:[19,89,54],teal4:[23,110,66],teal5:[28,135,82],teal6:[33,158,96],teal7:[39,186,113],teal8:[69,217,143],teal9:[166,237,202],cyan1:[9,41,41],cyan2:[13,64,64],cyan3:[18,87,87],cyan4:[22,107,107],cyan5:[27,130,130],cyan6:[33,156,156],cyan7:[38,181,181],cyan8:[49,212,212],cyan9:[160,235,235],azure1:[13,37,61],azure2:[20,59,97],azure3:[27,79,130],azure4:[34,99,163],azure5:[41,119,196],azure6:[72,144,217],azure7:[112,168,224],azure8:[157,196,235],azure9:[203,224,245],blue1:[22,22,105],blue2:[34,34,163],blue3:[49,49,212],blue4:[76,76,217],blue5:[102,102,222],blue6:[131,131,230],blue7:[157,157,235],blue8:[187,187,240],blue9:[220,220,247],violet1:[51,18,84],violet2:[80,28,133],violet3:[106,37,176],violet4:[131,51,212],violet5:[151,83,219],violet6:[169,114,224],violet7:[189,146,232],violet8:[210,180,240],violet9:[231,215,247],magenta1:[64,13,64],magenta2:[99,21,99],magenta3:[133,28,133],magenta4:[166,35,166],magenta5:[199,42,199],magenta6:[219,83,219],magenta7:[227,127,227],magenta8:[237,168,237],magenta9:[245,211,245],purple1:[69,14,42],purple2:[107,22,65],purple3:[143,30,86],purple4:[179,37,108],purple5:[212,51,131],purple6:[222,95,159],purple7:[230,133,181],purple8:[237,173,205],purple9:[245,211,228]} 34 35var LOCALS = {}; 36 37// Order : Dvipsnames, then svgnames, then x11colors 38function HEX2RGB(hex) { 39 // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") 40 var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; 41 hex = hex.replace(shorthandRegex, function(m, r, g, b) { 42 return r + r + g + g + b + b; 43 }); 44 45 var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); 46 return [parseInt(result[1], 16) || 0, parseInt(result[2], 16) || 0, parseInt(result[3], 16) || 0]; 47} 48 49// From here : https://stackoverflow.com/a/5624139/8022172 50function componentToHex(c) { 51 var hex = c.toString(16); 52 return hex.length == 1 ? "0" + hex : hex; 53} 54 55function rgbToHex(r, g, b) { 56 return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); 57} 58function blendColors(rgb1, rgb2, perc){ 59 perc /= 100; 60 // There are more complexe blending functions out there. However, this is the simple one 'xcolor' uses. 61 return [rgb1[0]*perc+rgb2[0]*(1-perc), 62 rgb1[1]*perc+rgb2[1]*(1-perc), 63 rgb1[2]*perc+rgb2[2]*(1-perc)]; 64} 65var invert = function(rgb){ 66 return [255 - rgb[0], 255 - rgb[1], 255 - rgb[2]]; 67} 68var xcolor = function xcolor(value, model, dvips){ 69 value = value.trim(); 70 // First remove all leading + 71 value = value.replace(/^[+]+/g, ""); 72 73 // Then, remove all nonnecessary leading '-' 74 value = value.replace(/^\-+/g, function(full){ 75 if(full.length%2 == 1){ 76 return "-"; 77 } 78 return ""; 79 }); 80 81 // Convert if there's a leading '-' 82 if(value.charAt(0) == "-"){ 83 return invert(xcolor.apply(this, [value.substring(1), model, dvips])) 84 } 85 86 // Clean postfix because we can't handle that 87 value = value.replace(/!![+]*(\[[0-9]*\]|)$/, ""); 88 89 // Now look for blending 90 if(value.indexOf("!") >= 0){ 91 value = value.split(/!/); 92 if(value.length % 2 === 0){ 93 value.push("white"); 94 } 95 var actualColor = xcolor(value[0], model, dvips); 96 for(var i=2;i<value.length;i+=2){ 97 var perc = parseFloat(value[i-1].trim()) 98 var color2 = xcolor(value[i], model, dvips); 99 actualColor = blendColors(actualColor, color2, perc); 100 } 101 return actualColor.map(function(t){ 102 return Math.round(t); 103 }); 104 } 105 106 107 // Supported model for now : rgb, RGB, HTML, cmy, cmyk, hsb, Hsb, HSB, gray, Gray and wave 108 if(model){ 109 110 // xcolor support conversion in their model optional argument 111 if(model.indexOf(":")>=0){ 112 model = model.substring(model.lastIndexOf(":")+1); 113 console.log(model); 114 } 115 116 if(model == "rgb"){ 117 return value.split(/[\s,]+/).map(function(val){ 118 return parseFloat(val)*255; 119 }); 120 } 121 else if(model == "RGB"){ 122 return value.split(/[\s,]+/).map(function(val){ 123 return parseInt(val,10); 124 }); 125 } 126 else if(model == "cmy" || model == "cmyk"){ 127 value = value.split(/[\s,]+/).map(function(val){ 128 return parseFloat(val); 129 }); 130 131 // First convert cmyk 132 if(model == "cmyk"){ 133 var black = value[3]; 134 value = [ 135 Math.min(1, value[0] + black), 136 Math.min(1, value[1] + black), 137 Math.min(1, value[2] + black) 138 ] 139 } 140 141 return [255 - value[0] * 255, 255 - value[1] * 255, 255 - value[2] * 255]; 142 } 143 else if(model == "HTML"){ 144 return HEX2RGB(value); 145 } 146 else if(model == "gray" || model == "Gray"){ 147 if(model == "Gray"){ 148 value = parseInt(value, 10) / 15; 149 } 150 value = parseFloat(value)*255; 151 return [value, value, value]; 152 } 153 else if(model == "hsb" || model == "Hsb" || model == "HSB"){ 154 value = value.split(/[\s,]+/).map(function(val){ 155 return parseFloat(val); 156 }); 157 158 // First we convert other models to 'hsb' 159 if(model == "Hsb"){ 160 value[0] = value[0]/360; 161 } 162 else if(model == "HSB"){ 163 value = value.map(function(v){ 164 return parseInt(v,10)/240 165 }); 166 } 167 168 // Then we treat hsb 169 var indicator = Math.floor(6*value[0]), 170 factor = 6*value[0]-indicator, 171 vector = [0,1,1]; 172 173 if(indicator === 0){ vector = [0,1-factor,1]} 174 else if(indicator === 1){ vector = [factor, 0, 1] } 175 else if(indicator === 2){ vector = [1, 0, 1-factor]} 176 else if(indicator === 3){ vector = [1, factor, 0]} 177 else if(indicator === 4){ vector = [1-factor, 1, 0]} 178 else if(indicator === 5){ vector = [0, 1, factor]}; 179 180 return vector.map(function(val){ 181 return Math.round((1 - val * value[1]) * value[2] * 255); 182 }); 183 184 } 185 else if(model == "wave"){ 186 // Who encode their color in 'wave' ? Whatever... 187 value = parseFloat(value); 188 var rgb = [1,0,0], factor = 1; 189 if(value < 380 || value > 780){ 190 return [0,0,0]; 191 } 192 193 // RGB in [0,1] 194 if(value >= 380 && value < 440){ 195 rgb = [(440-value)/(440-380),0,1] 196 } 197 else if(value >= 440 && value < 490){ 198 rgb = [0,(value-440)/(490-440),1] 199 } 200 else if(value >= 490 && value < 510){ 201 rgb = [0,1,(value-510)/(510-490)] 202 } 203 else if(value >= 510 && value < 580){ 204 rgb = [(value-510)/(580-510),1,0] 205 } 206 else if(value >= 580 && value < 645){ 207 rgb = [1,(645-value)/(645-580),0] 208 } 209 210 // Factor 211 if(value < 420){ 212 factor = 0.3 + 0.7 * (value-380)/(420-380) 213 } 214 else if(value > 700){ 215 factor = 0.3 + 0.7 * (780-value)/(780-700) 216 } 217 218 return rgb.map(function(e){ 219 return Math.round(e*factor*255); 220 }); 221 } 222 else{ 223 return [0, 0, 0]; 224 } 225 } 226 else{ 227 if(/^[a-z][a-z0-9]*$/i.test(value)){ 228 if(LOCALS.hasOwnProperty(value)){ 229 return LOCALS[value]; 230 } 231 else if(BASICS.hasOwnProperty(value)){ 232 return BASICS[value]; 233 } 234 else if(X11COLORS.hasOwnProperty(value)){ 235 return X11COLORS[value]; 236 } 237 else if(NINECOLORS.hasOwnProperty(value)){ 238 return NINECOLORS[value] 239 } 240 else if(dvips){ 241 if(DVIPSNAMES.hasOwnProperty(value)){ 242 return DVIPSNAMES[value]; 243 } 244 else if(SVGNAMES.hasOwnProperty(value)){ 245 return SVGNAMES[value]; 246 } 247 } 248 else{ 249 if(SVGNAMES.hasOwnProperty(value)){ 250 return SVGNAMES[value]; 251 } 252 else if(DVIPSNAMES.hasOwnProperty(value)){ 253 return DVIPSNAMES[value]; 254 } 255 } 256 } 257 } 258 return [0,0,0] 259} 260xcolor.register = function(name, r, g, b){ 261 if(arguments.length < 4){ 262 g = r[1]; 263 b = r[2]; 264 r = r[0]; 265 } 266 var rgb = [r, g, b]; 267 LOCALS[name] = rgb; 268 return rgb; 269} 270xcolor.remove = function(name){ 271 var have = !!LOCALS[name]; 272 delete LOCALS[name]; 273 return have; 274} 275xcolor.extract = function(code){ 276 // We strip comments 277 code = code.replace(/\\(.)/g, function(a,b){ 278 if(b == "%"){ 279 return "\\{"; 280 } 281 return a; 282 }).replace(/%[^\n\r]*[\n\r]*/g,"\n"); 283 var reg = /\\(definecolor|colorlet|providecolor)(?:\[([^\]]*)\]|)\{/g, 284 result = null; 285 while ((result = reg.exec(code)) !== null) { 286 var fn = result[1], opt = result[2], arg = [], actualarg = "", substr = code.substring(result.index + result[0].length - 1); 287 var counter = 0; 288 subLoop: for(var i=0;i<substr.length;i++){ 289 var c = substr.charAt(i); 290 if(c == "{"){ 291 counter++; 292 if(counter > 1){ 293 actu += c; 294 } 295 } 296 else if(c == "\\"){ 297 actualarg = c + substr.charAt(i+1); 298 i++; 299 } 300 else if(c == "}"){ 301 counter--; 302 if(counter === 0){ 303 arg.push(actualarg); 304 actualarg = ""; 305 if(arg.length === 3 || (fn == "colorlet" && arg.length == 2)){ 306 break subLoop; 307 } 308 } 309 else{ 310 actualarg += c; 311 } 312 } 313 else{ 314 actualarg += c; 315 } 316 } 317 if(arg.length === 3 || (fn == "colorlet" && arg.length == 2)){ 318 if(fn == "definecolor"){ 319 xcolor.register(arg[0], xcolor(arg[2], arg[1])); 320 } 321 else if(fn == "providecolor"){ 322 var value = arg[0] 323 if(!LOCALS.hasOwnProperty(value) && !BASICS.hasOwnProperty(value) 324 && !X11COLORS.hasOwnProperty(value) && !SVGNAMES.hasOwnProperty(value) 325 && !DVIPSNAMES.hasOwnProperty(value)){ 326 xcolor.register(arg[0], xcolor(arg[2], arg[1])); 327 } 328 } 329 else if(fn == "colorlet"){ 330 xcolor.register(arg[0], xcolor(arg[1])); 331 } 332 } 333 } 334} 335xcolor.erase = function(){ 336 LOCALS = {}; 337 return true; 338} 339 340window.xcolor = xcolor; 341})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.