From 03a8853a14daceb3e83bcad41ce139da6644e072 Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Wed, 7 Aug 2024 21:42:04 -0700 Subject: [PATCH] fix(Color): don't use shared global state Fixes: #362 --- lua/github-theme/group/modules/treesitter.lua | 2 +- lua/github-theme/palette/github_dark.lua | 3 ++- lua/github-theme/palette/github_dark_colorblind.lua | 3 ++- lua/github-theme/palette/github_dark_default.lua | 3 ++- lua/github-theme/palette/github_dark_dimmed.lua | 3 ++- lua/github-theme/palette/github_dark_high_contrast.lua | 3 ++- lua/github-theme/palette/github_dark_tritanopia.lua | 3 ++- lua/github-theme/palette/github_light.lua | 3 ++- lua/github-theme/palette/github_light_colorblind.lua | 3 ++- lua/github-theme/palette/github_light_default.lua | 3 ++- lua/github-theme/palette/github_light_high_contrast.lua | 3 ++- lua/github-theme/palette/github_light_tritanopia.lua | 3 ++- test/github-theme/color_spec.lua | 6 +++--- 13 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lua/github-theme/group/modules/treesitter.lua b/lua/github-theme/group/modules/treesitter.lua index 07268b77..d516988f 100644 --- a/lua/github-theme/group/modules/treesitter.lua +++ b/lua/github-theme/group/modules/treesitter.lua @@ -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') ) diff --git a/lua/github-theme/palette/github_dark.lua b/lua/github-theme/palette/github_dark.lua index 8d198524..2d2789c4 100755 --- a/lua/github-theme/palette/github_dark.lua +++ b/lua/github-theme/palette/github_dark.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(scale.gray[7]) +local BG = C(scale.gray[7]) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end local palette = { diff --git a/lua/github-theme/palette/github_dark_colorblind.lua b/lua/github-theme/palette/github_dark_colorblind.lua index c528f574..99773fd6 100644 --- a/lua/github-theme/palette/github_dark_colorblind.lua +++ b/lua/github-theme/palette/github_dark_colorblind.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end local palette = { diff --git a/lua/github-theme/palette/github_dark_default.lua b/lua/github-theme/palette/github_dark_default.lua index 93805672..8ce40d27 100644 --- a/lua/github-theme/palette/github_dark_default.lua +++ b/lua/github-theme/palette/github_dark_default.lua @@ -13,9 +13,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end local palette = { diff --git a/lua/github-theme/palette/github_dark_dimmed.lua b/lua/github-theme/palette/github_dark_dimmed.lua index 36d83580..033cb25c 100644 --- a/lua/github-theme/palette/github_dark_dimmed.lua +++ b/lua/github-theme/palette/github_dark_dimmed.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end local palette = { diff --git a/lua/github-theme/palette/github_dark_high_contrast.lua b/lua/github-theme/palette/github_dark_high_contrast.lua index 7ee7eda1..ef36c657 100644 --- a/lua/github-theme/palette/github_dark_high_contrast.lua +++ b/lua/github-theme/palette/github_dark_high_contrast.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end local palette = { diff --git a/lua/github-theme/palette/github_dark_tritanopia.lua b/lua/github-theme/palette/github_dark_tritanopia.lua index ded18460..383b9768 100644 --- a/lua/github-theme/palette/github_dark_tritanopia.lua +++ b/lua/github-theme/palette/github_dark_tritanopia.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end local palette = { diff --git a/lua/github-theme/palette/github_light.lua b/lua/github-theme/palette/github_light.lua index 4de3f80c..6ba34447 100644 --- a/lua/github-theme/palette/github_light.lua +++ b/lua/github-theme/palette/github_light.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(scale.white) +local BG = C(scale.white) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end -- Temp override until Primitives are updated diff --git a/lua/github-theme/palette/github_light_colorblind.lua b/lua/github-theme/palette/github_light_colorblind.lua index 8bd64d87..b9fe6783 100644 --- a/lua/github-theme/palette/github_light_colorblind.lua +++ b/lua/github-theme/palette/github_light_colorblind.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end -- Temp override until Primitives are updated diff --git a/lua/github-theme/palette/github_light_default.lua b/lua/github-theme/palette/github_light_default.lua index ce67aeeb..f8f55b79 100644 --- a/lua/github-theme/palette/github_light_default.lua +++ b/lua/github-theme/palette/github_light_default.lua @@ -13,9 +13,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end -- Temp override until Primitives are updated diff --git a/lua/github-theme/palette/github_light_high_contrast.lua b/lua/github-theme/palette/github_light_high_contrast.lua index 62123174..40e17e02 100644 --- a/lua/github-theme/palette/github_light_high_contrast.lua +++ b/lua/github-theme/palette/github_light_high_contrast.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end -- Temp override until Primitives are updated diff --git a/lua/github-theme/palette/github_light_tritanopia.lua b/lua/github-theme/palette/github_light_tritanopia.lua index 730d678c..b581eca8 100644 --- a/lua/github-theme/palette/github_light_tritanopia.lua +++ b/lua/github-theme/palette/github_light_tritanopia.lua @@ -14,9 +14,10 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) C.BG = C(assert(primitives.canvas.default)) +local BG = C(assert(primitives.canvas.default)) local function alpha(color, a) - return color:alpha_blend(a):to_css() + return BG:blend(color, a):to_css() end -- Temp override until Primitives are updated diff --git a/test/github-theme/color_spec.lua b/test/github-theme/color_spec.lua index 191561dc..b6e1b77a 100644 --- a/test/github-theme/color_spec.lua +++ b/test/github-theme/color_spec.lua @@ -224,7 +224,7 @@ describe('Color', function() end) end) - describe('global state `Color.{WHITE,BLACK,BG}`', function() + describe('global fields/state `Color.{WHITE,BLACK,BG}`', function() local theme = 'github_dark_dimmed' before_each(function() require('github-theme.util.reload')(true) @@ -232,7 +232,7 @@ describe('Color', function() end) -- See #362 - it('should not disrupt palette/spec', function() + it('should not disrupt colors in palette/spec/groups', function() local groups_expected = require('github-theme.group').load(theme) require('github-theme.util.reload')(true) @@ -256,7 +256,7 @@ describe('Color', function() local function index(_, k) if k == 'BG' or k == 'WHITE' or k == 'BLACK' then - error(debug.traceback('Color.' .. k .. ' was accessed internally')) + error('Color.' .. k .. ' was accessed internally', 2) end return rawget(C --[[@as table]], k) end