gtfs/common/color

Color Parsing and Manipulation Utilities

GTFS represents colors as 6-character hexadecimal strings without the # prefix (e.g., “FFFFFF” for white, “000000” for black). This module provides parsing, validation, and manipulation utilities.

Source: GTFS reference.md - Field Types

Values

pub fn black() -> types.Color

Black color (#000000)

pub fn contrast_ratio(
  color1: types.Color,
  color2: types.Color,
) -> Float

Calculate contrast ratio between two colors (1:1 to 21:1) WCAG AA requires 4.5:1 for normal text, 3:1 for large text

pub fn contrasting_text_color(
  background: types.Color,
) -> types.Color

Get a contrasting text color (black or white) for the given background

pub fn default_route_color() -> types.Color

Default GTFS route color (white)

pub fn default_text_color() -> types.Color

Default GTFS text color (black)

pub fn from_rgb(
  red: Int,
  green: Int,
  blue: Int,
) -> Result(types.Color, String)

Create a Color from RGB values (0-255 each)

pub fn is_light(color: types.Color) -> Bool

Determine if a color is “light” (useful for choosing text color) Returns True if the color is light (use dark text) Returns False if the color is dark (use light text)

pub fn luminance(color: types.Color) -> Float

Calculate the perceived luminance of a color (0.0 to 1.0) Uses the relative luminance formula from WCAG

pub fn parse(value: String) -> Result(types.Color, String)

Parse a GTFS color string (6 hex characters without #) Examples: “FFFFFF” (white), “000000” (black), “FF5733” (orange)

pub fn parse_optional(
  value: String,
) -> Result(option.Option(types.Color), String)

Parse an optional color string

pub fn to_css_string(color: types.Color) -> String

Format a color with # prefix for CSS/HTML use

pub fn to_string(color: types.Color) -> String

Format a color as a GTFS color string (6 hex characters, uppercase)

pub fn white() -> types.Color

White color (#FFFFFF)

Search Document