Files
fnx_web/webcontroller/user_style.go

439 lines
12 KiB
Go
Raw Normal View History

2018-01-07 21:42:19 +01:00
package webcontroller
import (
"fmt"
"net/http"
)
2019-12-23 23:56:57 +01:00
func userStyle(r *http.Request) (style pixeldrainStyleSheet) {
2019-02-18 22:42:20 +01:00
var selectedStyle pixeldrainStyleSheet
2018-01-07 21:42:19 +01:00
2018-07-11 22:46:44 +02:00
if cookie, err := r.Cookie("style"); err != nil {
2019-02-18 22:42:20 +01:00
selectedStyle = defaultPixeldrainStyle
2018-07-11 22:46:44 +02:00
} else {
switch cookie.Value {
case "solarized_dark":
2019-02-18 22:42:20 +01:00
selectedStyle = solarizedDarkStyle
2019-07-06 18:41:16 +02:00
case "sunny":
selectedStyle = sunnyPixeldrainStyle
2019-02-18 22:42:20 +01:00
case "maroon":
selectedStyle = maroonStyle
2019-03-31 21:06:52 +02:00
case "hacker":
selectedStyle = hackerStyle
2019-07-06 18:41:16 +02:00
case "canta":
selectedStyle = cantaPixeldrainStyle
2019-07-16 22:07:10 +02:00
case "arc":
selectedStyle = arcPixeldrainStyle
2019-09-18 22:23:12 +02:00
case "deepsea":
selectedStyle = deepseaPixeldrainStyle
2018-07-11 22:46:44 +02:00
case "default":
fallthrough // use default case
default:
2019-02-18 22:42:20 +01:00
selectedStyle = defaultPixeldrainStyle
2018-07-11 22:46:44 +02:00
}
}
2018-01-07 21:42:19 +01:00
2019-12-23 23:56:57 +01:00
return selectedStyle
}
type pixeldrainStyleSheet struct {
TextColor hsl
InputColor hsl // Buttons, text fields
InputTextColor hsl
HighlightColor hsl // Links, highlighted buttons, list navigation
HighlightTextColor hsl // Text on buttons
DangerColor hsl
FileBackgroundColor hsl
ScrollbarForegroundColor hsl
ScrollbarHoverColor hsl
ScrollbarBackgroundColor hsl
BackgroundColor hsl
BodyColor hsl
Layer1Color hsl // Deepest and darkest layer
Layer1Shadow int // Deep layers have little shadow
Layer2Color hsl
Layer2Shadow int
Layer3Color hsl
Layer3Shadow int
Layer4Color hsl // Highest and brightest layer
Layer4Shadow int // High layers have lots of shadow
ShadowColor hsl
ShadowSpread int // Pixels
ShadowIntensity int // Pixels
}
func (s pixeldrainStyleSheet) String() string {
return fmt.Sprintf(
2018-01-07 21:42:19 +01:00
`:root {
2020-01-13 16:24:06 +01:00
--text_color: #%s;
--input_color: #%s;
--input_color_dark: #%s;
--input_text_color: #%s;
--highlight_color: #%s;
--highlight_color_dark: #%s;
--highlight_text_color: #%s;
--danger_color: #%s;
--danger_color_dark: #%s;
--file_background_color: #%s;
--scrollbar_foreground_color: #%s;
--scrollbar_hover_color: #%s;
--scrollbar_background_color: #%s;
--background_color: #%s;
--body_color: #%s;
--layer_1_color: #%s;
2019-09-16 23:50:57 +02:00
--layer_1_shadow: %s;
2020-01-13 16:24:06 +01:00
--layer_2_color: #%s;
2019-09-16 23:50:57 +02:00
--layer_2_shadow: %s;
2020-01-13 16:24:06 +01:00
--layer_3_color: #%s;
2019-09-16 23:50:57 +02:00
--layer_3_shadow: %s;
2020-01-13 16:24:06 +01:00
--layer_4_color: #%s;
2019-09-16 23:50:57 +02:00
--layer_4_shadow: %s;
2018-07-11 22:46:44 +02:00
2020-01-13 16:24:06 +01:00
--shadow_color: #%s;
2018-07-11 22:46:44 +02:00
--shadow_spread: %s;
--shadow_intensity: %s;
}`,
2020-01-13 16:24:06 +01:00
s.TextColor.RGB(),
s.InputColor.RGB(),
s.InputColor.add(0, 0, -.03).RGB(),
s.InputTextColor.RGB(),
s.HighlightColor.RGB(),
s.HighlightColor.add(0, 0, -.03).RGB(),
s.HighlightTextColor.RGB(),
s.DangerColor.RGB(),
s.DangerColor.add(0, 0, -.03).RGB(),
s.FileBackgroundColor.RGB(),
s.ScrollbarForegroundColor.RGB(),
s.ScrollbarHoverColor.RGB(),
s.ScrollbarBackgroundColor.RGB(),
s.BackgroundColor.RGB(),
s.BodyColor.RGB(),
s.Layer1Color.RGB(),
2019-12-23 23:56:57 +01:00
fmt.Sprintf("%dpx", s.Layer1Shadow),
2020-01-13 16:24:06 +01:00
s.Layer2Color.RGB(),
2019-12-23 23:56:57 +01:00
fmt.Sprintf("%dpx", s.Layer2Shadow),
2020-01-13 16:24:06 +01:00
s.Layer3Color.RGB(),
2019-12-23 23:56:57 +01:00
fmt.Sprintf("%dpx", s.Layer3Shadow),
2020-01-13 16:24:06 +01:00
s.Layer4Color.RGB(),
2019-12-23 23:56:57 +01:00
fmt.Sprintf("%dpx", s.Layer4Shadow),
2020-01-13 16:24:06 +01:00
s.ShadowColor.RGB(),
2019-12-23 23:56:57 +01:00
fmt.Sprintf("%dpx", s.ShadowSpread),
fmt.Sprintf("%dpx", s.ShadowIntensity),
)
2018-01-07 21:42:19 +01:00
}
2018-07-11 22:46:44 +02:00
2019-02-18 22:42:20 +01:00
type hsl struct {
2018-07-11 22:46:44 +02:00
Hue int
Saturation float64
Lightness float64
}
2019-02-18 22:42:20 +01:00
func (h hsl) cssString() string {
2018-07-11 22:46:44 +02:00
return fmt.Sprintf(
"hsl(%d, %.3f%%, %.3f%%)",
2019-02-18 22:42:20 +01:00
h.Hue,
h.Saturation*100,
h.Lightness*100,
2018-07-11 22:46:44 +02:00
)
}
2020-01-13 16:24:06 +01:00
func (orig hsl) RGB() string {
var r, g, b, q, p float64
var h, s, l = float64(orig.Hue) / 360, orig.Saturation, orig.Lightness
if s == 0 {
r, g, b = l, l, l
} else {
var hue2rgb = func(p, q, t float64) float64 {
if t < 0 {
t++
}
if t > 1 {
t--
}
if t < 1.0/6.0 {
return p + (q-p)*6*t
} else if t < 1.0/2.0 {
return q
} else if t < 2.0/3.0 {
return p + (q-p)*(2.0/3.0-t)*6
}
return p
}
if l < 0.5 {
q = l * (1 + s)
} else {
q = l + s - l*s
}
p = 2*l - q
r = hue2rgb(p, q, h+1.0/3.0)
g = hue2rgb(p, q, h)
b = hue2rgb(p, q, h-1.0/3.0)
}
return fmt.Sprintf("%02x%02x%02x", int(r*255), int(g*255), int(b*255))
}
2018-07-11 22:46:44 +02:00
// Add returns a NEW HSL struct, it doesn't modify the current one
2019-02-18 22:42:20 +01:00
func (h hsl) add(hue int, saturation float64, lightness float64) hsl {
var new = hsl{
h.Hue + hue,
h.Saturation + saturation,
h.Lightness + lightness,
2018-07-11 22:46:44 +02:00
}
// Hue bounds correction
if new.Hue < 0 {
new.Hue += 360
} else if new.Hue > 360 {
new.Hue -= 360
}
// Saturation bounds check
if new.Saturation < 0 {
new.Saturation = 0
} else if new.Saturation > 1 {
new.Saturation = 1
}
// Lightness bounds check
if new.Lightness < 0 {
new.Lightness = 0
} else if new.Lightness > 1 {
new.Lightness = 1
}
return new
}
// Following are all the available styles
2019-02-18 22:42:20 +01:00
var defaultPixeldrainStyle = pixeldrainStyleSheet{
2019-07-06 18:41:16 +02:00
TextColor: hsl{0, 0, .7},
InputColor: hsl{0, 0, .25},
InputTextColor: hsl{0, 0, 1},
HighlightColor: hsl{89, .51, .45},
HighlightTextColor: hsl{0, 0, 0},
DangerColor: hsl{339, .65, .31},
2019-07-18 19:53:09 +02:00
FileBackgroundColor: hsl{0, 0, .20},
2019-08-11 17:16:18 +02:00
ScrollbarForegroundColor: hsl{0, 0, .35},
2019-09-18 22:23:12 +02:00
ScrollbarHoverColor: hsl{0, 0, .45},
2019-07-06 18:41:16 +02:00
ScrollbarBackgroundColor: hsl{0, 0, 0},
2019-09-16 23:50:57 +02:00
BackgroundColor: hsl{0, 0, 0},
BodyColor: hsl{0, 0, .07},
Layer1Color: hsl{0, 0, .11},
2019-09-18 22:23:12 +02:00
Layer1Shadow: 3,
2019-09-16 23:50:57 +02:00
Layer2Color: hsl{0, 0, .13},
2019-09-18 22:23:12 +02:00
Layer2Shadow: 5,
2019-09-16 23:50:57 +02:00
Layer3Color: hsl{0, 0, .14},
2019-09-18 22:23:12 +02:00
Layer3Shadow: 7,
2019-09-16 23:50:57 +02:00
Layer4Color: hsl{0, 0, .14},
2019-09-18 22:23:12 +02:00
Layer4Shadow: 9,
2019-02-18 22:42:20 +01:00
ShadowColor: hsl{0, 0, 0},
2019-09-18 22:23:12 +02:00
ShadowSpread: 7,
2019-07-06 18:41:16 +02:00
ShadowIntensity: 0,
}
var sunnyPixeldrainStyle = pixeldrainStyleSheet{
TextColor: hsl{0, 0, .1},
InputColor: hsl{0, 0, 1},
InputTextColor: hsl{0, 0, .1},
HighlightColor: hsl{89, .51, .5},
HighlightTextColor: hsl{0, 0, 0},
DangerColor: hsl{339, .65, .31},
FileBackgroundColor: hsl{0, 0, 1},
ScrollbarForegroundColor: hsl{0, 0, .30},
2019-09-18 22:23:12 +02:00
ScrollbarHoverColor: hsl{0, 0, .40},
2019-07-06 18:41:16 +02:00
ScrollbarBackgroundColor: hsl{0, 0, 0},
2019-09-16 23:50:57 +02:00
BackgroundColor: hsl{0, 0, 0},
BodyColor: hsl{0, 0, 1},
Layer1Color: hsl{0, 0, 1},
2019-09-18 22:23:12 +02:00
Layer1Shadow: 3,
2019-09-16 23:50:57 +02:00
Layer2Color: hsl{0, 0, 1},
Layer2Shadow: 5,
Layer3Color: hsl{0, 0, 1},
Layer3Shadow: 6,
Layer4Color: hsl{0, 0, 1},
2019-09-18 22:23:12 +02:00
Layer4Shadow: 5,
2019-07-06 18:41:16 +02:00
ShadowColor: hsl{0, 0, 0},
2019-09-18 22:23:12 +02:00
ShadowSpread: 7,
2019-07-06 18:41:16 +02:00
ShadowIntensity: 0,
2019-02-18 22:42:20 +01:00
}
var solarizedDarkStyle = pixeldrainStyleSheet{
2019-07-06 18:41:16 +02:00
TextColor: hsl{0, 0, .75},
2019-07-16 22:07:10 +02:00
InputColor: hsl{192, .95, .25},
2019-07-06 18:41:16 +02:00
InputTextColor: hsl{0, 0, 1},
HighlightColor: hsl{145, .63, .42},
2019-07-16 22:07:10 +02:00
HighlightTextColor: hsl{0, 0, 0},
2019-07-06 18:41:16 +02:00
DangerColor: hsl{343, .63, .42},
FileBackgroundColor: hsl{192, .87, .05},
ScrollbarForegroundColor: hsl{192, .95, .30},
2019-09-18 22:23:12 +02:00
ScrollbarHoverColor: hsl{192, .95, .40},
2019-07-06 18:41:16 +02:00
ScrollbarBackgroundColor: hsl{0, 0, 0},
2019-02-18 22:42:20 +01:00
2019-09-16 23:50:57 +02:00
BackgroundColor: hsl{192, 1, .05},
BodyColor: hsl{192, .81, .14}, // hsl(192, 81%, 14%)
Layer1Color: hsl{192, .87, .09},
2019-09-18 22:23:12 +02:00
Layer1Shadow: 3,
2019-09-16 23:50:57 +02:00
Layer2Color: hsl{192, .81, .14},
2019-09-18 22:23:12 +02:00
Layer2Shadow: 5,
2019-09-16 23:50:57 +02:00
Layer3Color: hsl{192, .95, .17},
2019-09-18 22:23:12 +02:00
Layer3Shadow: 7,
2019-09-16 23:50:57 +02:00
Layer4Color: hsl{192, 1, .11}, // hsl(192, 100%, 11%)
2019-09-18 22:23:12 +02:00
Layer4Shadow: 9,
2019-02-18 22:42:20 +01:00
2019-07-06 18:41:16 +02:00
ShadowColor: hsl{0, 0, 0},
2019-09-18 22:23:12 +02:00
ShadowSpread: 7,
2019-07-06 18:41:16 +02:00
ShadowIntensity: 0,
2018-07-11 22:46:44 +02:00
}
2019-02-18 22:42:20 +01:00
var maroonStyle = pixeldrainStyleSheet{
2019-07-06 18:41:16 +02:00
TextColor: hsl{0, 0, .7},
2019-07-16 22:07:10 +02:00
InputColor: hsl{0, .75, .25},
2019-07-06 18:41:16 +02:00
InputTextColor: hsl{0, 0, 1},
HighlightColor: hsl{0, 1, .4},
HighlightTextColor: hsl{0, 0, 1},
DangerColor: hsl{0, .1, .1},
FileBackgroundColor: hsl{0, 1, .03},
2019-08-11 17:16:18 +02:00
ScrollbarForegroundColor: hsl{0, .75, .3},
2019-09-18 22:23:12 +02:00
ScrollbarHoverColor: hsl{0, .75, .4},
2019-07-06 18:41:16 +02:00
ScrollbarBackgroundColor: hsl{0, 0, 0},
2019-02-18 22:42:20 +01:00
2019-09-16 23:50:57 +02:00
BackgroundColor: hsl{0, 1, .05},
BodyColor: hsl{0, .6, .1},
Layer1Color: hsl{0, .5, .07},
2019-09-18 22:23:12 +02:00
Layer1Shadow: 3,
2019-09-17 23:38:40 +02:00
Layer2Color: hsl{0, .6, .1}, // hsl{0, .8, .15},
2019-09-18 22:23:12 +02:00
Layer2Shadow: 5,
2019-09-16 23:50:57 +02:00
Layer3Color: hsl{0, .9, .2},
2019-09-18 22:23:12 +02:00
Layer3Shadow: 7,
2019-09-16 23:50:57 +02:00
Layer4Color: hsl{0, .5, .07},
2019-09-18 22:23:12 +02:00
Layer4Shadow: 9,
2019-02-18 22:42:20 +01:00
2019-07-06 18:41:16 +02:00
ShadowColor: hsl{0, 0, 0},
2019-09-18 22:23:12 +02:00
ShadowSpread: 7,
2019-07-06 18:41:16 +02:00
ShadowIntensity: 0,
2018-07-11 22:46:44 +02:00
}
2019-03-31 21:06:52 +02:00
var hackerStyle = pixeldrainStyleSheet{
2019-07-06 18:41:16 +02:00
TextColor: hsl{0, 0, .8},
InputColor: hsl{0, 0, .25},
InputTextColor: hsl{0, 0, 1},
HighlightColor: hsl{120, 1, .5},
HighlightTextColor: hsl{0, 0, 0},
DangerColor: hsl{0, .65, .31},
FileBackgroundColor: hsl{120, .8, .06},
2019-08-11 17:16:18 +02:00
ScrollbarForegroundColor: hsl{120, .5, .25},
2019-09-18 22:23:12 +02:00
ScrollbarHoverColor: hsl{120, .5, .35},
2019-07-06 18:41:16 +02:00
ScrollbarBackgroundColor: hsl{0, 0, 0},
2019-03-31 21:06:52 +02:00
2019-09-16 23:50:57 +02:00
BackgroundColor: hsl{0, 0, 0},
BodyColor: hsl{0, 0, 0},
Layer1Color: hsl{120, .1, .05},
2019-09-18 22:23:12 +02:00
Layer1Shadow: 3,
2019-09-16 23:50:57 +02:00
Layer2Color: hsl{120, .2, .10},
2019-09-18 22:23:12 +02:00
Layer2Shadow: 5,
2019-09-16 23:50:57 +02:00
Layer3Color: hsl{120, .3, .15},
2019-09-18 22:23:12 +02:00
Layer3Shadow: 7,
2019-09-16 23:50:57 +02:00
Layer4Color: hsl{0, 0, .14},
2019-09-18 22:23:12 +02:00
Layer4Shadow: 9,
2019-03-31 21:06:52 +02:00
2019-07-06 18:41:16 +02:00
ShadowColor: hsl{0, 0, 0},
2019-09-18 22:23:12 +02:00
ShadowSpread: 7,
2019-07-06 18:41:16 +02:00
ShadowIntensity: 0,
}
var cantaPixeldrainStyle = pixeldrainStyleSheet{
TextColor: hsl{0, 0, .8},
InputColor: hsl{167, .06, .40},
InputTextColor: hsl{0, 0, 1},
HighlightColor: hsl{165, 1, .40},
HighlightTextColor: hsl{0, 0, 0},
DangerColor: hsl{40, 1, .5},
FileBackgroundColor: hsl{170, .04, .29},
2019-11-21 20:25:06 +01:00
ScrollbarForegroundColor: hsl{204, .05, .78}, // hsl(204, 5%, 78%)
ScrollbarHoverColor: hsl{204, .05, .88},
ScrollbarBackgroundColor: hsl{200, .13, .27}, // hsl(200, 13%, 27%)
2019-07-06 18:41:16 +02:00
2019-09-16 23:50:57 +02:00
BackgroundColor: hsl{0, 0, 0},
BodyColor: hsl{172, .06, .25},
2019-11-21 20:25:06 +01:00
Layer1Color: hsl{200, .19, .18}, // hsl(200, 19%, 18%)
2019-09-18 22:23:12 +02:00
Layer1Shadow: 3,
2019-11-21 20:25:06 +01:00
Layer2Color: hsl{199, .14, .23}, // hsl(199, 14%, 23%)
2019-09-18 22:23:12 +02:00
Layer2Shadow: 5,
2019-11-21 20:25:06 +01:00
Layer3Color: hsl{199, .14, .27}, // hsl(199, 14%, 27%)
Layer3Shadow: 6,
Layer4Color: hsl{200, .14, .30}, // hsl(200, 14%, 30%)
Layer4Shadow: 7,
2019-07-06 18:41:16 +02:00
ShadowColor: hsl{0, 0, 0},
2019-09-18 22:23:12 +02:00
ShadowSpread: 7,
2019-07-06 18:41:16 +02:00
ShadowIntensity: 0,
2019-03-31 21:06:52 +02:00
}
2019-07-16 22:07:10 +02:00
var arcPixeldrainStyle = pixeldrainStyleSheet{
2019-07-17 23:19:57 +02:00
TextColor: hsl{0, 0, 1},
InputColor: hsl{218, .16, .30},
InputTextColor: hsl{215, .19, .75},
HighlightColor: hsl{212, .71, .60},
HighlightTextColor: hsl{215, .19, .9},
DangerColor: hsl{357, .53, .57}, // hsl(357, 53%, 57%)
2019-07-16 22:07:10 +02:00
FileBackgroundColor: hsl{219, .1, .2},
2019-07-17 23:19:57 +02:00
ScrollbarForegroundColor: hsl{222, .08, .44}, // hsl(222, 8%, 44%)
2019-09-18 22:23:12 +02:00
ScrollbarHoverColor: hsl{222, .08, .54}, // hsl(222, 8%, 44%)
2019-08-11 17:16:18 +02:00
ScrollbarBackgroundColor: hsl{223, .12, .2}, // hsl(223, 12%, 29%)
2019-07-17 23:19:57 +02:00
2019-09-16 23:50:57 +02:00
BackgroundColor: hsl{0, 0, 0},
BodyColor: hsl{223, .12, .29},
Layer1Color: hsl{215, .17, .19},
2019-09-18 22:23:12 +02:00
Layer1Shadow: 3,
2019-09-16 23:50:57 +02:00
Layer2Color: hsl{227, .14, .25}, // hsl(227, 14%, 25%)
2019-09-18 22:23:12 +02:00
Layer2Shadow: 5,
2019-09-16 23:50:57 +02:00
Layer3Color: hsl{223, .12, .29},
2019-09-18 22:23:12 +02:00
Layer3Shadow: 7,
2019-09-16 23:50:57 +02:00
Layer4Color: hsl{219, .15, .22}, // hsl(219, 15%, 22%)
2019-09-18 22:23:12 +02:00
Layer4Shadow: 9,
ShadowColor: hsl{0, 0, 0},
ShadowSpread: 7,
ShadowIntensity: 0,
}
var deepseaPixeldrainStyle = pixeldrainStyleSheet{
TextColor: hsl{0, 0, .7},
InputColor: hsl{41, .58, .47}, // hsl(0, 0%, 11%)
InputTextColor: hsl{0, 0, 0},
HighlightColor: hsl{5, .77, .55},
HighlightTextColor: hsl{0, 0, 0},
DangerColor: hsl{5, .77, .55},
FileBackgroundColor: hsl{159, .27, .17},
ScrollbarForegroundColor: hsl{162, .28, .23}, // hsl(162, 28%, 23%)
ScrollbarHoverColor: hsl{12, .38, .26}, // hsl(12, 38%, 26%)
ScrollbarBackgroundColor: hsl{0, 0, .11}, // hsl(0, 0%, 11%)
BackgroundColor: hsl{0, 0, 0},
BodyColor: hsl{0, 0, .07},
Layer1Color: hsl{160, .27, .09},
Layer1Shadow: 3,
Layer2Color: hsl{163, .26, .11}, // hsl(163, 26%, 11%)
Layer2Shadow: 5,
Layer3Color: hsl{161, .28, .14}, // hsl(161, 28%, 14%)
Layer3Shadow: 7,
Layer4Color: hsl{159, .27, .17}, // hsl(159, 27%, 17%)
Layer4Shadow: 9,
2019-07-16 22:07:10 +02:00
ShadowColor: hsl{0, 0, 0},
2019-09-18 22:23:12 +02:00
ShadowSpread: 7,
2019-07-16 22:07:10 +02:00
ShadowIntensity: 0,
}