Skip to content

Commit

Permalink
fix(Color): don't use shared global state
Browse files Browse the repository at this point in the history
Fixes: #362
  • Loading branch information
tmillr committed Aug 9, 2024
1 parent 43b6536 commit 4502601
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 358 deletions.
2 changes: 1 addition & 1 deletion lua/github-theme/group/modules/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function M.get(spec, config, _opts)
-- being integrated.
local primitives = require(
'github-theme.palette.primitives.'
.. require('github-theme.config').theme
.. spec.palette.meta.name
:gsub('^github_(.-)_default$', '%1')
:gsub('^github_(.-)$', '%1')
)
Expand Down
71 changes: 34 additions & 37 deletions lua/github-theme/palette/github_dark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(scale.gray[7])

local function alpha(color, a)
return color:alpha_blend(a):to_css()
end
local BG = C(scale.gray[7])

local palette = {
scale = scale,
Expand Down Expand Up @@ -52,86 +49,86 @@ local palette = {
border = {
default = scale.gray[9],
muted = scale.gray[8],
subtle = alpha(C.from_rgba(240, 246, 252, 1), 0.1),
subtle = BG:blend(C.from_rgba(240, 246, 252, 1), 0.1),
},

neutral = {
emphasis_plus = scale.gray[5],
emphasis = scale.gray[5],
muted = alpha(C.from_rgba(110, 118, 129, 1), 0.4),
subtle = alpha(C.from_rgba(110, 118, 129, 1), 0.1),
muted = BG:blend(C.from_rgba(110, 118, 129, 1), 0.4),
subtle = BG:blend(C.from_rgba(110, 118, 129, 1), 0.1),
},

accent = {
fg = '#2f81f7',
emphasis = scale.blue[6],
muted = alpha(C.from_rgba(56, 139, 253, 1), 0.4),
subtle = alpha(C.from_rgba(56, 139, 253, 1), 0.15),
muted = BG:blend(C.from_rgba(56, 139, 253, 1), 0.4),
subtle = BG:blend(C.from_rgba(56, 139, 253, 1), 0.15),
},

success = {
fg = scale.green[4],
emphasis = scale.green[6],
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15),
},

attention = {
fg = scale.yellow[4],
emphasis = scale.yellow[6],
muted = alpha(C.from_rgba(187, 128, 9, 1), 0.4),
subtle = alpha(C.from_rgba(187, 128, 9, 1), 0.15),
muted = BG:blend(C.from_rgba(187, 128, 9, 1), 0.4),
subtle = BG:blend(C.from_rgba(187, 128, 9, 1), 0.15),
},

severe = {
fg = scale.orange[5],
emphasis = scale.orange[6],
muted = alpha(C.from_rgba(219, 109, 40, 1), 0.4),
subtle = alpha(C.from_rgba(219, 109, 40, 1), 0.1),
muted = BG:blend(C.from_rgba(219, 109, 40, 1), 0.4),
subtle = BG:blend(C.from_rgba(219, 109, 40, 1), 0.1),
},

danger = {
fg = scale.red[5],
emphasis = scale.red[6],
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.1),
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.1),
},

open = {
fg = scale.green[4],
emphasis = scale.green[6],
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15),
},

done = {
fg = scale.purple[5],
emphasis = scale.purple[6],
muted = alpha(C.from_rgba(163, 113, 247, 1), 0.4),
subtle = alpha(C.from_rgba(163, 113, 247, 1), 0.1),
muted = BG:blend(C.from_rgba(163, 113, 247, 1), 0.4),
subtle = BG:blend(C.from_rgba(163, 113, 247, 1), 0.1),
},

closed = {
fg = scale.red[5],
emphasis = scale.red[6],
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.15),
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.15),
},

sponsors = {
fg = scale.pink[5],
emphasis = scale.pink[6],
muted = alpha(C.from_rgba(219, 97, 162, 1), 0.4),
subtle = alpha(C.from_rgba(219, 97, 162, 1), 0.1),
muted = BG:blend(C.from_rgba(219, 97, 162, 1), 0.4),
subtle = BG:blend(C.from_rgba(219, 97, 162, 1), 0.1),
},
}

local function generate_spec(pal)
-- stylua: ignore start
local spec = {
bg0 = alpha(C(pal.canvas.inset), 0.75), -- Dark bg (popup and float)
bg0 = BG:blend(C(pal.canvas.inset), 0.75), -- Dark bg (popup and float):to_css()
bg1 = pal.canvas.default, -- Default bg
bg2 = alpha(C(pal.neutral.emphasis), 0.1), -- Lighter bg (colorcolumn Folds)
bg2 = BG:blend(C(pal.neutral.emphasis), 0.1), -- Lighter bg (colorcolumn Folds):to_css()
bg3 = pal.scale.gray[6], -- Lighter bg (cursor line)
bg4 = pal.scale.gray[4], -- Conceal

Expand All @@ -140,9 +137,9 @@ local function generate_spec(pal)
fg2 = pal.fg.muted, -- Darker fg (status line)
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)

sel0 = alpha(C(pal.accent.fg), 0.30), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[1]), 0.20), -- Search bg
sel0 = BG:blend(C(pal.accent.fg), 0.30):to_css(), -- Visual selection bg
sel1 = BG:blend(C(pal.accent.muted), 0.90):to_css(), -- Popup sel bg
sel2 = BG:blend(C(pal.scale.yellow[1]), 0.20):to_css(), -- Search bg
}

spec.syntax = {
Expand Down Expand Up @@ -178,16 +175,16 @@ local function generate_spec(pal)
}

spec.diag_bg = {
error = C(spec.bg1):blend(C(spec.diag.error), 0.15):to_css(),
warn = C(spec.bg1):blend(C(spec.diag.warn), 0.15):to_css(),
info = C(spec.bg1):blend(C(spec.diag.info), 0.15):to_css(),
hint = C(spec.bg1):blend(C(spec.diag.hint), 0.15):to_css(),
error = BG:blend(C(spec.diag.error), 0.15):to_css(),
warn = BG:blend(C(spec.diag.warn), 0.15):to_css(),
info = BG:blend(C(spec.diag.info), 0.15):to_css(),
hint = BG:blend(C(spec.diag.hint), 0.15):to_css(),
}

spec.diff = {
add = alpha(C(pal.scale.green[6]), 0.15),
delete = alpha(C(pal.scale.red[6]), 0.15),
change = alpha(C(pal.scale.yellow[6]), 0.15),
add = BG:blend(C(pal.scale.green[6]), 0.15):to_css(),
delete = BG:blend(C(pal.scale.red[6]), 0.15):to_css(),
change = BG:blend(C(pal.scale.yellow[6]), 0.15):to_css(),
text = spec.fg0
}

Expand Down
71 changes: 34 additions & 37 deletions lua/github-theme/palette/github_dark_colorblind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ local scale = primitives.scale
C.WHITE = C(scale.white)
C.BLACK = C(scale.black)
C.BG = C(assert(primitives.canvas.default))

local function alpha(color, a)
return color:alpha_blend(a):to_css()
end
local BG = C(assert(primitives.canvas.default))

local palette = {
scale = scale,
Expand Down Expand Up @@ -47,86 +44,86 @@ local palette = {
border = {
default = scale.gray[7],
muted = scale.gray[8],
subtle = alpha(C.from_rgba(240, 246, 252, 1), 0.1),
subtle = BG:blend(C.from_rgba(240, 246, 252, 1), 0.1),
},

neutral = {
emphasis_plus = scale.gray[5],
emphasis = scale.gray[5],
muted = alpha(C.from_rgba(110, 118, 129, 1), 0.4),
subtle = alpha(C.from_rgba(110, 118, 129, 1), 0.1),
muted = BG:blend(C.from_rgba(110, 118, 129, 1), 0.4),
subtle = BG:blend(C.from_rgba(110, 118, 129, 1), 0.1),
},

accent = {
fg = scale.blue[4],
emphasis = scale.blue[6],
muted = alpha(C.from_rgba(56, 139, 253, 1), 0.4),
subtle = alpha(C.from_rgba(56, 139, 253, 1), 0.15),
muted = BG:blend(C.from_rgba(56, 139, 253, 1), 0.4),
subtle = BG:blend(C.from_rgba(56, 139, 253, 1), 0.15),
},

success = {
fg = scale.green[4],
emphasis = scale.green[6],
muted = alpha(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = alpha(C.from_rgba(46, 160, 67, 1), 0.15),
muted = BG:blend(C.from_rgba(46, 160, 67, 1), 0.4),
subtle = BG:blend(C.from_rgba(46, 160, 67, 1), 0.15),
},

attention = {
fg = scale.yellow[4],
emphasis = scale.yellow[6],
muted = alpha(C.from_rgba(187, 128, 9, 1), 0.4),
subtle = alpha(C.from_rgba(187, 128, 9, 1), 0.15),
muted = BG:blend(C.from_rgba(187, 128, 9, 1), 0.4),
subtle = BG:blend(C.from_rgba(187, 128, 9, 1), 0.15),
},

severe = {
fg = scale.orange[5],
emphasis = scale.orange[6],
muted = alpha(C.from_rgba(219, 109, 40, 1), 0.4),
subtle = alpha(C.from_rgba(219, 109, 40, 1), 0.15),
muted = BG:blend(C.from_rgba(219, 109, 40, 1), 0.4),
subtle = BG:blend(C.from_rgba(219, 109, 40, 1), 0.15),
},

danger = {
fg = scale.red[5],
emphasis = scale.red[6],
muted = alpha(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = alpha(C.from_rgba(248, 81, 73, 1), 0.15),
muted = BG:blend(C.from_rgba(248, 81, 73, 1), 0.4),
subtle = BG:blend(C.from_rgba(248, 81, 73, 1), 0.15),
},

open = {
fg = scale.orange[4],
emphasis = scale.orange[6],
muted = alpha(C.from_hex(scale.orange[5]), 0.4),
subtle = alpha(C.from_hex(scale.orange[5]), 0.15),
muted = BG:blend(C.from_hex(scale.orange[5]), 0.4),
subtle = BG:blend(C.from_hex(scale.orange[5]), 0.15),
},

done = {
fg = scale.purple[5],
emphasis = scale.purple[6],
muted = alpha(C.from_rgba(163, 113, 247, 1), 0.4),
subtle = alpha(C.from_rgba(163, 113, 247, 1), 0.15),
muted = BG:blend(C.from_rgba(163, 113, 247, 1), 0.4),
subtle = BG:blend(C.from_rgba(163, 113, 247, 1), 0.15),
},

closed = {
fg = scale.gray[4],
emphasis = scale.gray[5],
muted = alpha(C.from_hex(scale.gray[5]), 0.4),
subtle = alpha(C.from_hex(scale.gray[5]), 0.10),
muted = BG:blend(C.from_hex(scale.gray[5]), 0.4),
subtle = BG:blend(C.from_hex(scale.gray[5]), 0.10),
},

sponsors = {
fg = scale.pink[5],
emphasis = scale.pink[6],
muted = alpha(C.from_rgba(219, 97, 162, 1), 0.4),
subtle = alpha(C.from_rgba(219, 97, 162, 1), 0.15),
muted = BG:blend(C.from_rgba(219, 97, 162, 1), 0.4),
subtle = BG:blend(C.from_rgba(219, 97, 162, 1), 0.15),
},
}

local function generate_spec(pal)
-- stylua: ignore start
local spec = {
bg0 = alpha(C(pal.canvas.inset), 0.75), -- Dark bg (status line, popup and float)
bg0 = BG:blend(C(pal.canvas.inset), 0.75), -- Dark bg (status line, popup and float):to_css()
bg1 = pal.canvas.default, -- Default bg
bg2 = alpha(C(pal.neutral.emphasis), 0.1), -- Lighter bg (colorcolumn Folds)
bg2 = BG:blend(C(pal.neutral.emphasis), 0.1), -- Lighter bg (colorcolumn Folds):to_css()
bg3 = pal.scale.gray[9], -- Lighter bg (cursor line)
bg4 = pal.scale.gray[4], -- Conceal

Expand All @@ -135,9 +132,9 @@ local function generate_spec(pal)
fg2 = pal.fg.muted, -- Darker fg (status line)
fg3 = pal.scale.gray[5], -- Darker fg (line numbers, fold columns)

sel0 = alpha(C(pal.accent.fg), 0.45), -- Visual selection bg
sel1 = alpha(C(pal.accent.muted), 0.90), -- Popup sel bg
sel2 = alpha(C(pal.scale.yellow[3]), 0.60), -- Search bg
sel0 = BG:blend(C(pal.accent.fg), 0.45):to_css(), -- Visual selection bg
sel1 = BG:blend(C(pal.accent.muted), 0.90):to_css(), -- Popup sel bg
sel2 = BG:blend(C(pal.scale.yellow[3]), 0.60):to_css(), -- Search bg
}

spec.syntax = {
Expand Down Expand Up @@ -173,16 +170,16 @@ local function generate_spec(pal)
}

spec.diag_bg = {
error = C(spec.bg1):blend(C(spec.diag.error), 0.15):to_css(),
warn = C(spec.bg1):blend(C(spec.diag.warn), 0.15):to_css(),
info = C(spec.bg1):blend(C(spec.diag.info), 0.15):to_css(),
hint = C(spec.bg1):blend(C(spec.diag.hint), 0.15):to_css(),
error = BG:blend(C(spec.diag.error), 0.15):to_css(),
warn = BG:blend(C(spec.diag.warn), 0.15):to_css(),
info = BG:blend(C(spec.diag.info), 0.15):to_css(),
hint = BG:blend(C(spec.diag.hint), 0.15):to_css(),
}

spec.diff = {
add = alpha(C(pal.scale.green[6]), 0.15),
delete = alpha(C(pal.scale.red[6]), 0.15),
change = alpha(C(pal.scale.yellow[6]), 0.15),
add = BG:blend(C(pal.scale.green[6]), 0.15):to_css(),
delete = BG:blend(C(pal.scale.red[6]), 0.15):to_css(),
change = BG:blend(C(pal.scale.yellow[6]), 0.15):to_css(),
text = spec.fg0
}

Expand Down
Loading

0 comments on commit 4502601

Please sign in to comment.