local ____lualib = require("lualib_bundle")
local __TS__StringReplace = ____lualib.__TS__StringReplace
local ____exports = {}
local hexToRGB, HEX_STRING_LENGTH
local ____log = require("functions.log")
local logError = ____log.logError
function hexToRGB(self, hexString)
    hexString = __TS__StringReplace(hexString, "#", "")
    if #hexString ~= HEX_STRING_LENGTH then
        logError("Hex strings must be of length: " .. tostring(HEX_STRING_LENGTH))
        return {r = 0, g = 0, b = 0}
    end
    local rString = string.sub(hexString, 1, 2)
    local r = tonumber("0x" .. rString)
    if r == nil then
        logError(("Failed to convert `0x" .. rString) .. "` to a number.")
        return {r = 0, g = 0, b = 0}
    end
    local gString = string.sub(hexString, 3, 4)
    local g = tonumber("0x" .. gString)
    if g == nil then
        logError(("Failed to convert `0x" .. gString) .. "` to a number.")
        return {r = 0, g = 0, b = 0}
    end
    local bString = string.sub(hexString, 5, 6)
    local b = tonumber("0x" .. bString)
    if b == nil then
        logError(("Failed to convert `0x" .. bString) .. "` to a number.")
        return {r = 0, g = 0, b = 0}
    end
    return {r = r, g = g, b = b}
end
HEX_STRING_LENGTH = 6
--- Converts a hex string like "#33aa33" to a KColor object.
-- 
-- @param hexString A hex string like "#ffffff" or "ffffff". (The "#" character is optional.)
-- @param alpha Optional. Range is from 0 to 1. Default is 1. (The same as the `Color` constructor.)
function ____exports.hexToColor(self, hexString, alpha)
    if alpha == nil then
        alpha = 1
    end
    local ____hexToRGB_result_0 = hexToRGB(nil, hexString)
    local r = ____hexToRGB_result_0.r
    local g = ____hexToRGB_result_0.g
    local b = ____hexToRGB_result_0.b
    local base = 255
    return Color(r / base, g / base, b / base, alpha)
end
--- Converts a hex string like "#33aa33" to a Color object.
-- 
-- @param hexString A hex string like "#ffffff" or "ffffff". (The "#" character is optional.)
-- @param alpha Range is from 0 to 1. Default is 1.
function ____exports.hexToKColor(self, hexString, alpha)
    if alpha == nil then
        alpha = 1
    end
    local ____hexToRGB_result_1 = hexToRGB(nil, hexString)
    local r = ____hexToRGB_result_1.r
    local g = ____hexToRGB_result_1.g
    local b = ____hexToRGB_result_1.b
    local base = 255
    return KColor(r / base, g / base, b / base, alpha)
end
return ____exports
