Sign in to follow this  
Followers 0
zorphnog

WebColors UDF

1 post in this topic

#1 ·  Posted (edited)

Utility functions for color names and color value formats defined by the HTML and CSS specifications for use in documents on the Web.

What this UDF supports

-------------------------

This UDF supports the following methods of specifying RGB colors, and conversions between them:

  • Six-digit hexadecimal.
  • Three-digit hexadecimal.
  • Integer 3-element RGB array.
  • Percentage 3-element RGB array.
  • Varying selections of predefined color names.
WebColors.au3

#include-once
; #INDEX# =======================================================================================================================
; Title .........: WebColors
; AutoIt Version : 3.3.8++
; Language ......: English
; Description ...: Functions for converting html/css color codes. Ported from Python implementation by James Bennett, BitBucket
;                 for original code. [https://bitbucket.org/ubernostrum/webcolors/]
; Author(s) .....: Michael Mims (zorphnog)
;                 OHB <me at="" orangehairedboy="" dot="" com=""> (__WebColors_x UDF)
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
;_WebColors_HexToName
;_WebColors_HexToRGB
;_WebColors_HexToRGBPercent
;_WebColors_NameToHex
;_WebColors_NameToRGB
;_WebColors_NameToRGBPercent
;_WebColors_RGBToName
;_WebColors_RGBToHex
;_WebColors_RGBToRGBPercent
;_WebColors_RGBPercentToName
;_WebColors_RGBPercentToHex
;_WebColors_RGBPercentToRGB
; ===============================================================================================================================
; #INTERNAL_USE_ONLY# ===========================================================================================================
;__WebColors_Init
;__WebColors_InitCSS21
;__WebColors_InitCSS3
;__WebColors_InitHTML4
;__WebColors_IsValidRGB
;__WebColors_Normalize_Hex
;__WebColors_PercentToInt
;__WebColors_Reverse_Dict
;__WebColors_x
; ===============================================================================================================================
Global Const $__WC_HEX_COLOR_RE = "A#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})z"
Global Const $__WC_SUPPORTED_SPECIFICATIONS[4] = ['html4', 'css2', 'css21', 'css3']
Global Const _
    $__WC_HTML4_NAMES_TO_HEX = "html4_ntoh", _
    $__WC_HTML4_HEX_TO_NAMES = "html4_hton", _
    $__WC_CSS2_NAMES_TO_HEX  = $__WC_HTML4_NAMES_TO_HEX, _
    $__WC_CSS2_HEX_TO_NAMES  = $__WC_HTML4_HEX_TO_NAMES, _
    $__WC_CSS21_NAMES_TO_HEX = "css21_ntoh", _
    $__WC_CSS21_HEX_TO_NAMES = "css21_hton", _
    $__WC_CSS3_NAMES_TO_HEX  = "css3_ntoh", _
    $__WC_CSS3_HEX_TO_NAMES  = "css3_hton"
Global $__WC_DICT_INITIALIZED = False, $__WC_xHashCollection = ObjCreate( "Scripting.Dictionary" )

; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToName
; Description ...: Convert a hexadecimal color value to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_HexToName($hex_value[, $spec = 'css3'])
; Parameters ....: $hex_value          - The hexadecimal color value.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name of the hexadecimal value
;                 Failure - Blank string, sets @error
;                 |1 - Specification not supported
;                 |2 - Hex value is not a valid hexadecimal color value
;                 |3 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToName($hex_value, $spec='css3')
    __WebColors_Init()
    Local $dict, $name, $normalized
    Switch StringLower($spec)
        Case $__WC_SUPPORTED_SPECIFICATIONS[0]
            $dict = $__WC_HTML4_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[1]
            $dict = $__WC_CSS2_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[2]
            $dict = $__WC_CSS21_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[3]
            $dict = $__WC_CSS3_HEX_TO_NAMES
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
    $normalized = __WebColors_Normalize_Hex($hex_value)
    If @error Then Return SetError(1 + @error, 0, "")  ; value is not valid hexadecimal color value
    $name = __WebColors_x($dict & "." & $normalized)
    If $name <> "" Then Return $name
    Return SetError(3, 0, "")                         ; hex_value has no defined color name
EndFunc   ;==>_WebColors_HexToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToRGB
; Description ...: Convert a hexadecimal color value to a 3-element array of RGB integers.
; Syntax ........: _WebColors_HexToRGB($hex_value)
; Parameters ....: $hex_value          - The hexadecimal color value.
; Return values .: Success - The RGB array of integer values
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToRGB($hex_value)
    Local $hex_digits, $rgb_value[3]
    $hex_digits = __WebColors_Normalize_Hex($hex_value)
    If @error Then Return SetError(@error, 0, "")     ; value is not valid hexadecimal color value
    $rgb_value[0] = Int('0x' & StringMid($hex_digits, 2, 2))
    $rgb_value[1] = Int('0x' & StringMid($hex_digits, 4, 2))
    $rgb_value[2] = Int('0x' & StringMid($hex_digits, 6, 2))
    Return $rgb_value
EndFunc   ;==>_WebColors_HexToRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToRGBPercent
; Description ...: Convert a hexadecimal color value to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_HexToRGBPercent($hex_value)
; Parameters ....: $hex_value          - The hexadecimal color value.
; Return values .: Success - The RGB array of percentage values
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
;                 |2 - Internal error; RGB value array is invalid
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToRGBPercent($hex_value)
    Local $rgb_value
    $rgb_value = _WebColors_HexToRGB($hex_value)
    If @error Then Return SetError(@error, 0, "")
    $rgb_percent = _WebColors_RGBToRGBPercent($rgb_value)
    If @error Then Return SetError(1 + @error, 0, "")
    Return $rgb_percent
EndFunc   ;==>_WebColors_HexToRGBPercent
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Init
; Description ...: Initializes the color dictionary.
; Syntax ........: __WebColors_Init()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Init()
    If Not $__WC_DICT_INITIALIZED Then
        __WebColors_InitHTML4()
        __WebColors_InitCSS21()
        __WebColors_InitCSS3()
        __WebColors_Reverse_Dict($__WC_HTML4_NAMES_TO_HEX, $__WC_HTML4_HEX_TO_NAMES)
        __WebColors_Reverse_Dict($__WC_CSS21_NAMES_TO_HEX, $__WC_CSS21_HEX_TO_NAMES)
        __WebColors_Reverse_Dict($__WC_CSS3_NAMES_TO_HEX, $__WC_CSS3_HEX_TO_NAMES)
        $__WC_DICT_INITIALIZED = True
    EndIf
EndFunc   ;==>__WebColors_Init
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitCSS21
; Description ...: Adds the CSS 2.1 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitCSS21()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitCSS21()
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.orange', '#ffa500')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.yellow', '#ffff00')
EndFunc   ;==>__WebColors_InitCSS21
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitCSS3
; Description ...: Adds the CSS 3 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitCSS3()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitCSS3()
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aliceblue', '#f0f8ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.antiquewhite', '#faebd7')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aquamarine', '#7fffd4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.azure', '#f0ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.beige', '#f5f5dc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.bisque', '#ffe4c4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blanchedalmond', '#ffebcd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blueviolet', '#8a2be2')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.brown', '#a52a2a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.burlywood', '#deb887')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cadetblue', '#5f9ea0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.chartreuse', '#7fff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.chocolate', '#d2691e')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.coral', '#ff7f50')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cornflowerblue', '#6495ed')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cornsilk', '#fff8dc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.crimson', '#dc143c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cyan', '#00ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkblue', '#00008b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkcyan', '#008b8b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgoldenrod', '#b8860b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgray', '#a9a9a9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgrey', '#a9a9a9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgreen', '#006400')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkkhaki', '#bdb76b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkmagenta', '#8b008b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkolivegreen', '#556b2f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkorange', '#ff8c00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkorchid', '#9932cc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkred', '#8b0000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darksalmon', '#e9967a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkseagreen', '#8fbc8f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslateblue', '#483d8b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslategray', '#2f4f4f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslategrey', '#2f4f4f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkturquoise', '#00ced1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkviolet', '#9400d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.deeppink', '#ff1493')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.deepskyblue', '#00bfff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dimgray', '#696969')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dimgrey', '#696969')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dodgerblue', '#1e90ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.firebrick', '#b22222')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.floralwhite', '#fffaf0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.forestgreen', '#228b22')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gainsboro', '#dcdcdc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.ghostwhite', '#f8f8ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gold', '#ffd700')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.goldenrod', '#daa520')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gray', '#808080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.greenyellow', '#adff2f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.honeydew', '#f0fff0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.hotpink', '#ff69b4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.indianred', '#cd5c5c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.indigo', '#4b0082')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.ivory', '#fffff0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.khaki', '#f0e68c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lavender', '#e6e6fa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lavenderblush', '#fff0f5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lawngreen', '#7cfc00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lemonchiffon', '#fffacd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightblue', '#add8e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightcoral', '#f08080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightcyan', '#e0ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgoldenrodyellow', '#fafad2')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgray', '#d3d3d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgrey', '#d3d3d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgreen', '#90ee90')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightpink', '#ffb6c1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightsalmon', '#ffa07a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightseagreen', '#20b2aa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightskyblue', '#87cefa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightslategray', '#778899')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightslategrey', '#778899')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightsteelblue', '#b0c4de')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightyellow', '#ffffe0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.limegreen', '#32cd32')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.linen', '#faf0e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.magenta', '#ff00ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumaquamarine', '#66cdaa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumblue', '#0000cd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumorchid', '#ba55d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumpurple', '#9370d8')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumseagreen', '#3cb371')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumslateblue', '#7b68ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumspringgreen', '#00fa9a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumturquoise', '#48d1cc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumvioletred', '#c71585')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.midnightblue', '#191970')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mintcream', '#f5fffa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mistyrose', '#ffe4e1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.moccasin', '#ffe4b5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.navajowhite', '#ffdead')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.oldlace', '#fdf5e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.olivedrab', '#6b8e23')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orange', '#ffa500')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orangered', '#ff4500')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orchid', '#da70d6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palegoldenrod', '#eee8aa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palegreen', '#98fb98')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.paleturquoise', '#afeeee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palevioletred', '#d87093')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.papayawhip', '#ffefd5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.peachpuff', '#ffdab9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.peru', '#cd853f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.pink', '#ffc0cb')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.plum', '#dda0dd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.powderblue', '#b0e0e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.rosybrown', '#bc8f8f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.royalblue', '#4169e1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.saddlebrown', '#8b4513')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.salmon', '#fa8072')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.sandybrown', '#f4a460')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.seagreen', '#2e8b57')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.seashell', '#fff5ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.sienna', '#a0522d')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.skyblue', '#87ceeb')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slateblue', '#6a5acd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slategray', '#708090')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slategrey', '#708090')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.snow', '#fffafa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.springgreen', '#00ff7f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.steelblue', '#4682b4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.tan', '#d2b48c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.thistle', '#d8bfd8')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.tomato', '#ff6347')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.turquoise', '#40e0d0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.violet', '#ee82ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.wheat', '#f5deb3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.whitesmoke', '#f5f5f5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.yellow', '#ffff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.yellowgreen', '#9acd32')
EndFunc   ;==>__WebColors_InitCSS3
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitHTML4
; Description ...: Adds the HTML 4 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitHTML4()
; Parameters ....:
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitHTML4()
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.yellow', '#ffff00')
EndFunc   ;==>__WebColors_InitHTML4
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_IsValidRGB
; Description ...: Determines whether a RGB array is valid.
; Syntax ........: __WebColors_IsValidRGB($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB values.
; Return values .: Success - True
;                 Failure - False, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_IsValidRGB($rgb_value)
    If Not IsArray($rgb_value) Then Return SetError(1, 0, False)
    If UBound($rgb_value) <> 3 Then Return SetError(2, 0, False)
    For $i=0 To 2
        If Number($rgb_value[$i]) > 255 Or Number($rgb_value[$i]) < 0 Then Return SetError(3, 0, False)
    Next
    Return True
EndFunc   ;==>__WebColors_IsValidRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToHex
; Description ...: Convert a color name to a normalized hexadecimal color value.
; Syntax ........: _WebColors_NameToHex($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The hex value of the color
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToHex($name, $spec='css3')
    __WebColors_Init()
    Local $dict, $hex_value
    Switch StringLower($spec)
        Case $__WC_SUPPORTED_SPECIFICATIONS[0]
            $dict = $__WC_HTML4_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[1]
            $dict = $__WC_CSS2_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[2]
            $dict = $__WC_CSS21_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[3]
            $dict = $__WC_CSS3_NAMES_TO_HEX
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
    $hex_value = __WebColors_x($dict & "." & $name)
    If $hex_value <> "" Then Return $hex_value
    Return SetError(2, 0, "")
EndFunc   ;==>_WebColors_NameToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToRGB
; Description ...: Convert a color name to a 3-element array of integers.
; Syntax ........: _WebColors_NameToRGB($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The RGB array of the integer values
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
;                 |3 - Internal error; Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToRGB($name, $spec='css3')
    __WebColors_Init()
    Local $hex_value, $rgb_value
    $hex_value = _WebColors_NameToHex($name, $spec)
    If @error Then Return SetError(@error, 0, "")
    $rgb_value = _WebColors_HexToRGB($hex_value)
    If @error Then Return SetError(2 + @error, 0, "")
    Return $rgb_value
EndFunc   ;==>_WebColors_NameToRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToRGBPercent
; Description ...: Convert a color name to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_NameToRGBPercent($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The RGB array of the percentage values
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
;                 |3 - Internal error; Hex value is not a valid hexadecimal color value
;                 |4 - Internal error; RGB value array is invalid
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToRGBPercent($name, $spec='css3')
    __WebColors_Init()
    Local $rgb_value, $rgb_percent
    $rgb_value = _WebColors_NameToRGB($name, $spec)
    If @error Then Return SetError(@error, 0, "")
    $rgb_percent = _WebColors_RGBToRGBPercent($rgb_value)
    If @error Then SetError(4 + @error, 0, "")
    Return $rgb_percent
EndFunc   ;==>_WebColors_NameToRGBPercent
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Normalize_Hex
; Description ...: Normalize a hexadecimal color value to the following form and return the result: #[a-f0-9]{6}
; Syntax ........: __WebColors_Normalize_Hex($hex_value)
; Parameters ....: $hex_value          - A hexadecimal color value to normalize.
; Return values .: Success - The normalized hexadecimal color value
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Normalize_Hex($hex_value)
    Local $aReturn, $hex_digits
    $aReturn = StringRegExp($hex_value, $__WC_HEX_COLOR_RE, 3)
    If @error Then Return SetError(1, 0, "")
    $hex_digits = $aReturn[0]
    If StringLen($hex_digits) == 3 Then
        $hex_digits = StringMid($hex_digits, 1, 1) & StringMid($hex_digits, 1, 1) & StringMid($hex_digits, 2, 1) & _
            StringMid($hex_digits, 2, 1) & StringMid($hex_digits, 3, 1) & StringMid($hex_digits, 3, 1)
    EndIf
    Return StringFormat("#%s", StringLower($hex_digits))
EndFunc   ;==>__WebColors_Normalize_Hex
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_PercentToInt
; Description ...: Internal helper for converting a percentage value to an integer between 0 and 255 inclusive.
; Syntax ........: __WebColors_PercentToInt($percent)
; Parameters ....: $percent          - A percentage value.
; Return values .: The rounded integer value of the percentage of 255
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_PercentToInt($percent)
    Return Round(Number(StringTrimRight($percent, 1)) / 100.0 * 255)
EndFunc   ;==>__WebColors_PercentToInt

; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToName
; Description ...: Convert a 3-element array of integers to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_RGBToName($rgb_value[, $spec = 'css3'])
; Parameters ....: $rgb_value          - An array of RGB integer values.
;                 $spec             - [optional] A specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
;                 |4 - Specification not supported
;                 |5 - Internal error; Hex value is not a valid hexadecimal color value
;                 |6 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToName($rgb_value, $spec='css3')
    __WebColors_Init()
    Local $hex_value, $name
    $hex_value = _WebColors_RGBToHex($rgb_value)
    If @error Then Return SetError(@error, 0, "")
    $name = _WebColors_HexToName($hex_value, $spec)
    If @error Then Return SetError(3 + @error, 0, "")
    Return $name
EndFunc   ;==>_WebColors_RGBToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToHex
; Description ...: Convert a 3-element array of integers to a normalized hexadecimal value for that color.
; Syntax ........: _WebColors_RGBToHex($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB integer values.
; Return values .: Success - The normalized hex value
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToHex($rgb_value)
    If Not __WebColors_IsValidRGB($rgb_value) Then SetError(@error, 0, "")   ; rgb_value is invalid
    Return StringFormat("#%02x%02x%02x", Int($rgb_value[0]), Int($rgb_value[1]), Int($rgb_value[2]))
EndFunc   ;==>_WebColors_RGBToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToRGBPercent
; Description ...:  Convert a 3-element array of RGB integers to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_RGBToRGBPercent($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB integer values.
; Return values .: Success - The 3-element array of RGB percentages
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToRGBPercent($rgb_value)
    Local $rgb_percent[3]
    If Not __WebColors_IsValidRGB($rgb_value) Then SetError(@error, 0, "")   ; rgb_value is invalid
    For $i=0 To 2
        Switch Int($rgb_value[$i])
            Case 255
                $rgb_percent[$i] = "100%"
            Case 128
                $rgb_percent[$i] = "50%"
            Case 64
                $rgb_percent[$i] = "25%"
            Case 32
                $rgb_percent[$i] = "12.5%"
            Case 16
                $rgb_percent[$i] = "6.25%"
            Case 0
                $rgb_percent[$i] = "0%"
            Case Else
                $rgb_percent[$i] = StringFormat("%.02f%%", ($rgb_value[$i] / 255.0) * 100)
        EndSwitch
    Next
    Return $rgb_percent
EndFunc   ;==>_WebColors_RGBToRGBPercent
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToName
; Description ...:  Convert a 3-element array of percentages to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_RGBPercentToName($rgb_percent[, $spec = 'css3'])
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
;                 $spec             - [optional] A specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
;                 |4 - Specification not supported
;                 |5 - Internal error; Hex value is not a valid hexadecimal color value
;                 |6 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToName($rgb_percent, $spec='css3')
    __WebColors_Init()
    Local $rgb_value, $name
    $rgb_value = _WebColors_RGBPercentToRGB($rgb_percent)
    If @error Then Return SetError(@error, 0, "")
    $name = _WebColors_RGBToName($rgb_value, $spec)
    If @error Then Return SetError(@error)
    Return $name
EndFunc   ;==>_WebColors_RGBPercentToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToHex
; Description ...: Convert a 3-element array of percentages to a normalized hexadecimal color value for that color.
; Syntax ........: _WebColors_RGBPercentToHex($rgb_percent)
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
; Return values .: Success - The hexadecimal color value
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToHex($rgb_percent)
    Local $rgb_value, $hex_value
    $rgb_value = _WebColors_RGBPercentToRGB($rgb_percent)
    If @error Then Return SetError(@error, 0, "")
    $hex_value = _WebColors_RGBToHex($rgb_value)
    If @error Then Return SetError(@error, 0, "")
    Return $hex_value
EndFunc   ;==>_WebColors_RGBPercentToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToRGB
; Description ...: Convert a 3-element array of percentages to a 3-element array of integers.
; Syntax ........: _WebColors_RGBPercentToRGB($rgb_percent)
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
; Return values .: Success - The 3-element array of RGB integers
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToRGB($rgb_percent)
    Local $rgb_value[3]
    If Not __WebColors_IsValidRGB($rgb_percent) Then Return SetError(@error, 0, "")
    For $i=0 To 2
        $rgb_value[$i] = __WebColors_PercentToInt($rgb_percent[$i])
    Next
    Return $rgb_value
EndFunc   ;==>_WebColors_RGBPercentToRGB
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Reverse_Dict
; Description ...: Creates a reverse lookup dictionary.
; Syntax ........: __WebColors_Reverse_Dict($base_dict, $reverse_dict)
; Parameters ....: $base_dict          - A dictionary to reverse.
;                 $reverse_dict     - A dictionary to store the reversed dictionary.
; Return values .: Success - None
;                 Failure - -1, sets @error to 1
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Reverse_Dict($base_dict, $reverse_dict)
    Local $items = __WebColors_x($base_dict)
    If IsObj($items) Then
        For $i In $items
            __WebColors_x($reverse_dict & "." & $items.item($i), $i)
        Next
    Else
        Return SetError(1, 0, -1)
    EndIf
EndFunc   ;==>__WebColors_Reverse_Dict
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __WebColors_x
; Description ...: Gets or sets a value in an Associative Array
; Syntax.........: SET: __WebColors_x( $sKey , $vValue )
;                 GET: __WebColors_x( $key )
; Parameters ....: $sKey - the key to set or get. Examples:
;                 __WebColors_x( 'foo' )           gets value of foo
;                 __WebColors_x( 'foo.bar' )       gets value of bar which is a key of foo
;                 $bar = "baz"
;                 __WebColors_x( 'foo.$bar' )     gets value of baz which is a key of foo (variables are expanded)
; Return values .: Success - When setting, return the value set. When getting, returns the requested value.
;                 Failure - Returns a 0
; Author ........: OHB <me at="" orangehairedboy="" dot="" com="">
; ===============================================================================================================================
Func __WebColors_x( $sKey = '' , $vValue = '' )
    $func = "get"
    If @NumParams <> 1 Then $func = "set"
    If $sKey == '' Then
        If $func == "get" Then
            Return $__WC_xHashCollection
        Else
            $__WC_xHashCollection.removeAll
            Return ''
        EndIf
    EndIf
    $parts = StringSplit( $sKey , "." )
    $last_key = $parts[$parts[0]]
    $cur = $__WC_xHashCollection
    For $x = 1 To $parts[0] - 1
        If Not $cur.exists( $parts[$x] ) Then
            If $func == "get" Then Return
            $cur.add( $parts[$x] , ObjCreate( "Scripting.Dictionary" ) )
        EndIf
        $cur = $cur.item( $parts[$x] )
    Next
    If IsPtr( $vValue ) Then $vValue = String( $vValue )
    If $func == "get" Then
        If Not $cur.exists( $last_key ) Then Return
        $item = $cur.item( $last_key )
        Return $item
    ElseIf Not $cur.exists( $last_key ) Then
        $cur.add( $last_key , $vValue )
    Else
        $cur.item( $last_key ) = $vValue
    EndIf
    Return $vValue
EndFunc

_WebColors_Test.au3

#include "WebColors.au3"
#include <array.au3>
Global $sLog = ""
$sLog &= __GetTestResult("_WebColors_NameToHex('white')", '#ffffff')
$sLog &= __GetTestResult("_WebColors_NameToHex('navy')", '#000080')
$sLog &= __GetTestResult("_WebColors_NameToHex('goldenrod')", '#daa520')
$sLog &= __GetTestResult("_WebColors_NameToHex('goldenrod', 'html4')", 2) ; Throws error; value not defined in html4 specifications
$sLog &= __GetTestResult("_WebColors_NameToRGB('white')", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_NameToRGB('navy')", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_NameToRGB('goldenrod')", '[218, 165, 32]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('white')", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('navy')", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('goldenrod')", '[85.49%, 64.71%, 12.5%]')
$sLog &= __GetTestResult("_WebColors_HexToName('#ffffff')", 'white')
$sLog &= __GetTestResult("_WebColors_HexToName('#fff')", 'white')
$sLog &= __GetTestResult("_WebColors_HexToName('#000080')", 'navy')
$sLog &= __GetTestResult("_WebColors_HexToName('#daa520')", 'goldenrod')
$sLog &= __GetTestResult("_WebColors_HexToName('#daa520', 'html4')", 3)   ; Throws error; value not defined in html4 specifications
$sLog &= __GetTestResult("_WebColors_HexToRGB('#fff')", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_HexToRGB('#000080')", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_HexToRGBPercent('#ffffff')", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_HexToRGBPercent('#000080')", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_RGBToName(_ArrayCreate(255, 255, 255))", 'white')
$sLog &= __GetTestResult("_WebColors_RGBToName(_ArrayCreate(0, 0, 128))", 'navy')
$sLog &= __GetTestResult("_WebColors_RGBToHex(_ArrayCreate(255, 255, 255))", '#ffffff')
$sLog &= __GetTestResult("_WebColors_RGBToHex(_ArrayCreate(0, 0, 128))", '#000080')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(255, 255, 255))", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(0, 0, 128))", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(218, 165, 32))", '[85.49%, 64.71%, 12.5%]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('100%', '100%', '100%'))", 'white')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('0%', '0%', '50%'))", 'navy')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('85.49%', '64.71%', '12.5%'))", 'goldenrod')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('100%', '100%', '100%'))", '#ffffff')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('0%', '0%', '50%'))", '#000080')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('85.49%', '64.71%', '12.5%'))", '#daa520')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('100%', '100%', '100%'))", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('0%', '0%', '50%'))", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('85.49%', '64.71%', '12.5%'))", '[218, 165, 32]')
ConsoleWrite($sLog)
Func __GetTestResult($sCommand, $sExpected = "")
    Local $sResult, $iError, $sPass
    $sResult = Execute($sCommand)
    $iError = @error
    $sPass = "!FAIL"
    Select
        Case $iError <> 0
            If $iError == $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => <error: %d="">n", $sPass, $sCommand, $iError)
        Case IsString($sResult)
            If $sResult = $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => %sn", $sPass, $sCommand, $sResult)
        Case IsArray($sResult)
            Local $sTemp = "[" & _ArrayToString($sResult, ", ") & "]"
            If $sTemp = $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => %sn",$sPass, $sCommand, $sTemp)
    EndSelect
EndFunc

UDF + Test script:

WebColors.zip

Edited by zorphnog

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • zenocon
      By zenocon
      Hi, After scouring the forums for many hours, I'm trying to compile the most up to date / recent information on the options available for integrating with JavaScript / DOM -- as it relates to scraping + automation of web pages.
      It's my understanding there is IE.au3 script for automation of IE through a COM interface.  But I believe this only works with IE and won't work with Edge, correct?  Is there a COM interface that works with Edge, or any other options for integrating with Edge (other than IUIAuatomation?)
      I know there was also a FF.au3 UDF, but Mozilla abandoned the support for their mozrepl in favor of Web Extensions, and my understanding is that the FF.au3 UDF no longer works, is that correct?
      There was also a Chrome.au3 UDF, but my read on the forums indicate that this also broke many Chrome releases past.
      Which leaves IUIAutomation which I have been using to automate / scrape Windows apps, but when I am trying it on a website, it is not as useful.  For example, if I know the exact DOM id / class, I can get at it and do whatever I need to in JavaScript very simply.  With IUIAutomation, the DOM properties are not available, and most tags / elements in DOM have no useful defining characteristics to be able to get at them reliably (if they are targetable at all).  Some things might be able to be done with IUIAutomation, but I see it's value in targeting website automation / scraping as fairly limited.
      At this point, it seems like my best option is to use IE.au3, but that forces users on IE, which is probably a showstopper.
      Is there another way to bridge into the DOM?  I have written Web Extensions for Chrome and Firefox before.  They can communicate with external processes via AJAX or messaging.  I'm wondering if I can build what I need in a WebExtension and then trigger it from AutoIT Script, and gather up the results somewhere.
      I know there was the ISimpleDOM.au3 and some Microsoft Accessability scripts, but they seem to only be partially supported in browsers, and I didn't have a lot of luck getting those examples to run correctly.
    • islandspapand
      By islandspapand
      Hi all
      i am currently trying to click on an element in a HTML Table, but just can get it to work.
      i am able to click the top of the table so it changes to sort  but just can't click on the element in the table.
      an i need to click on element to continue in the site.
      i have attached the code so far and pictures of the table  element want to click plus the source of the table.
      i am able to get data in the table with $oTable = _IETableGetCollection($oIE, 2) but not able to click on them.
       
      Help is very much appreciated
       
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <IE.au3> #include "DOM.au3" #include <Array.au3> #include <MsgBoxConstants.au3> Global $oIE = _IECreate("*") _IELoadWait($oIE) Sleep(2000) _PageLogin($oIE) _PageLoadWait() _PageNewReq($oIE) _PageLoadWait() _InputModelInf($oIE) _PageLoadWait() Sleep(1000) $aTableLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//table/tbody/tr/td[.='Name Of user']", 2000) ;~ $aTableLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//table/tbody/tr", 2000) ;~ _ArrayDisplay($aTableLink,"$aTableLink") If IsArray($aTableLink) Then ConsoleWrite("Able to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='Name Of user'])" & @CRLF) For $i = 0 To UBound($aTableLink)-1 ConsoleWrite(" OuterHTML : " & $aTableLink[$i].outerHTML & @CRLF) ConsoleWrite(" Parentnode : " & $aTableLink[$i].parentnode & @CRLF) ConsoleWrite(" Parentnode.click : " & $aTableLink[$i].parentnode.fireEvent("onclick","click") & @CRLF) $objClick = $aTableLink[$i].parentnode ;~ _IEAction($aTableLink[$i] , "focus") _IEAction($objClick , "focus") ;~ If _IEAction($aTableLink[$i], "click") Then If _IEAction($objClick, "click") Then ConsoleWrite("Able to _IEAction($aForumLink[0], 'click')" & @CRLF) _IELoadWait($oIE) Else ConsoleWrite("UNable to _IEAction($aForumLink[0], 'click')" & @CRLF) Exit 3 EndIf Next Else ConsoleWrite("Unable to BGe_IEGetDOMObjByXPathWithAttributes($oIE, //table/tbody/tr/td[.='Name Of user'])" & @CRLF) Exit 2 EndIf _PageLoadWait() Func _InputModelInf($oTmpIE) ; Add Var for Model & Serial in Func $oModelInput = _IEGetObjById($oTmpIE,"model") _IEAction($oModelInput,"focus") _IEDocInsertText($oModelInput, "*") $oSerialInput = _IEGetObjById($oTmpIE,"serial") _IEAction($oModelInput,"focus") _IEDocInsertText($oSerialInput, "*") $links = $oTmpIE.document.getElementsByClassName("btn btn-primary ng-scope") For $link In $links If $link.innertext = "Søg" Or $link.innertext = "Search" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageNewReq($oTmpIE) $links = $oTmpIE.document.getElementsByClassName("ng-scope k-link") For $link In $links If $link.innertext = "Send ny fejlmelding" Or $link.innertext = "Submit a New Service Request" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageLogin($oTmpIE) $oUserInput = _IEGetObjById($oTmpIE,"loginid") _IEDocInsertText($oUserInput, "*") $oPasswordInput = _IEGetObjById($oTmpIE,"password") _IEDocInsertText($oPasswordInput, "*") $links = $oTmpIE.document.getElementsByClassName("btn btn-primary login ng-scope") For $link In $links If $link.innertext = "Sign in" Then $link.click() ExitLoop EndIf Next Return True EndFunc Func _PageLoadWait() Local $PageLoadWait = False ;~ nav navbar-nav navbar-right ng-hide ;~ nav navbar-nav navbar-right $tags = $oIE.document.GetElementsByTagName("ul") For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "nav navbar-nav navbar-right" Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Webpage loading :) ' & @CRLF) ;### Debug Console $PageLoadWait = True ExitLoop EndIf Next Do sleep(250) For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "nav navbar-nav navbar-right ng-hide" Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Webpage load finished :)'& @CRLF) ;### Debug Console $PageLoadWait = False ExitLoop EndIf Next Until $PageLoadWait = False EndFunc  
      Thanks in advance
       
       


    • Spask
      By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • ur
      By ur
      We can select elements in IE using their IDs as below.
      Local $oDiv = _IEGetObjById($oIE, "x-auto-16-input") But to one button in the webpage, there is no ID to it.
      In selenium we have option to select this element using the CssSelector and clicked the button using below code in c# selenium.
      driver.FindElement(By.CssSelector("button.x-btn-text")).Click(); What is the alternative for this in AUtoIT?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      Before all, I want to say that I'm doing this script to see how _IE* functions work, and see if my studs can hack a quiz I'm working on.
      I want to clarify that I'm not automating any game, bypassing any CAPTCHAs, or anything that could damage anyone.
      I was trying to autofill a form, based on which question is displayed.
      The question is always stored in here:
      <header> <h1><span class="questionid">1. </span>Here goes the question</h1> </header> And answers are stored in here:
      <ul class="answers"> <li><label><span><input id="answer_0" name="answer[]" type="radio" value="0">Answer 1</span></label></li> <li><label><span><input id="answer_1" name="answer[]" type="radio" value="1">Answer 2</span></label></li> <li><label><span><input id="answer_2" name="answer[]" type="radio" value="2">Anwser 3</span></label></li> <li><label><span><input id="answer_3" name="answer[]" type="radio" value="3">Answer 4</span></label></li> </ul></fieldset></form></div> And, there are 15 questions like this.
      How can automatically fill my form?
      Thanks in advance
      Francesco