<commit_before>package extract

import (
	"fmt"
	"image/color"
	"net/http"
	"strconv"
	"strings"

	tgColors "github.com/taironas/tinygraphs/colors"
)

// Colors returns an array of colors based on a HTTP request.
// It follows some rules:
// - if the URL has it's own colors using the 'colors' parameter we return those.
//   e.g: some/url?colors=FFFFFF&colors=222222
// - if the URL has a theme defined using the 'theme' parameter, we return those colors.
//      if the theme does not exist we use the base theme.
//      if the number of colors is specified usign the 'numcolors' parameter,
//      we only return the number of colors specified.
//   e.g: some/url?theme=frogideas
//   returns an array with the first 2 colors that define the 'frogideas' theme.
//   e.g: some/url?theme=frogideas&numcolors=4
//   returns an array with the first 4 colors that define the 'frogideas' theme.
// - if the URL has a background and/or a foreground defined by usign parameters 'bg' and 'fg'
//     we return those.
//   e.g: some/url?bg=FFFFFF&fg=222222
func Colors(r *http.Request) (colors []color.RGBA) {

	if newColors, err := UserColors(r); err == nil {
		return newColors
	}

	th := Theme(r)

	if th == "base" {
		bg, fg := ExtraColors(r)
		colors = append(colors, bg, fg)
	} else {
		m := tgColors.MapOfColorThemes()
		if _, ok := m[th]; ok {
			n := NumColors(r)
			colors = append(colors, m[th][0:n]...)
		} else {
			colors = append(colors, m["base"]...)
		}
	}
	return colors
}

func GColors(r *http.Request) (gColors []color.RGBA) {

	theme := Theme(r)
	if theme != "base" {
		colorMap := tgColors.MapOfColorThemes()
		if _, ok := colorMap[theme]; ok {
			return colorMap[theme][1:3]
		}
	}

	if newColors, err := UserColors(r); err == nil {
		if len(newColors) > 2 {
			gColors = newColors[1:3]
		} else {
			gColors = newColors
		}
	} else {
		gColors = Colors(r)
	}

	return
}

// Background extract hexadecimal code background from HTTP request and return color.RGBA
func Background(req *http.Request) (color.RGBA, error) {
	bg := req.FormValue("bg")
	if len(bg) == 0 {<commit_msg>extend gColors extraction to accept array of colors as gradient<commit_after>package extract

import (
	"fmt"
	"image/color"
	"net/http"
	"strconv"
	"strings"

	tgColors "github.com/taironas/tinygraphs/colors"
)

// Colors returns an array of colors based on a HTTP request.
// It follows some rules:
// - if the URL has it's own colors using the 'colors' parameter we return those.
//   e.g: some/url?colors=FFFFFF&colors=222222
// - if the URL has a theme defined using the 'theme' parameter, we return those colors.
//      if the theme does not exist we use the base theme.
//      if the number of colors is specified usign the 'numcolors' parameter,
//      we only return the number of colors specified.
//   e.g: some/url?theme=frogideas
//   returns an array with the first 2 colors that define the 'frogideas' theme.
//   e.g: some/url?theme=frogideas&numcolors=4
//   returns an array with the first 4 colors that define the 'frogideas' theme.
// - if the URL has a background and/or a foreground defined by usign parameters 'bg' and 'fg'
//     we return those.
//   e.g: some/url?bg=FFFFFF&fg=222222
func Colors(r *http.Request) (colors []color.RGBA) {

	if newColors, err := UserColors(r); err == nil {
		return newColors
	}

	th := Theme(r)

	if th == "base" {
		bg, fg := ExtraColors(r)
		colors = append(colors, bg, fg)
	} else {
		m := tgColors.MapOfColorThemes()
		if _, ok := m[th]; ok {
			n := NumColors(r)
			colors = append(colors, m[th][0:n]...)
		} else {
			colors = append(colors, m["base"]...)
		}
	}
	return colors
}

func GColors(r *http.Request) (gColors []color.RGBA) {

	theme := Theme(r)
	if theme != "base" {
		colorMap := tgColors.MapOfColorThemes()
		if _, ok := colorMap[theme]; ok {
			return colorMap[theme][1:3]
		}
	}

	if newColors, err := UserColors(r); err == nil {
		if len(newColors) > 2 {
			gColors = newColors[1:]
		} else {
			gColors = newColors
		}
	} else {
		gColors = Colors(r)
	}

	return
}

// Background extract hexadecimal code background from HTTP request and return color.RGBA
func Background(req *http.Request) (color.RGBA, error) {
	bg := req.FormValue("bg")
	if len(bg) == 0 {
{'fraction_non_alphanumeric': 0.13412042502951593, 'fraction_numerical': 0.010153482880755607, 'mean_word_length': 3.244488977955912, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7011780', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1503, 'n_words': 483}