aboutsummaryrefslogtreecommitdiff
path: root/scripts/theme-studio/test-columns.mjs
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-15 18:57:13 -0500
committerCraig Jennings <c@cjennings.net>2026-06-15 18:57:13 -0500
commit25e2d2ad97861ca1eb3b327e9d2084c3705bde8b (patch)
treeb8c425db4d16f693f68398612e58620d3531ec6a /scripts/theme-studio/test-columns.mjs
parenta5b11fba0d02f89c67975d1fd7f63010c59edb1d (diff)
downloaddotemacs-25e2d2ad97861ca1eb3b327e9d2084c3705bde8b.tar.gz
dotemacs-25e2d2ad97861ca1eb3b327e9d2084c3705bde8b.zip
fix(theme-studio): clamp generated palette spans to the bg/fg bounds
Spanning a color generated steps toward pure black and white, so a column could produce colors darker than bg or lighter than fg. I changed regenColumn to ramp the dark side toward the darker ground endpoint and the light side toward the lighter one, bounded by bg and fg. Pure black/white duplicates are still skipped, and callers that pass no ground fall back to the old black/white ramp. Node tests cover the bounded span and the no-ground fallback. The #counttest gate asserts the regenerated column stays within the bg/fg bounds.
Diffstat (limited to 'scripts/theme-studio/test-columns.mjs')
-rw-r--r--scripts/theme-studio/test-columns.mjs21
1 files changed, 21 insertions, 0 deletions
diff --git a/scripts/theme-studio/test-columns.mjs b/scripts/theme-studio/test-columns.mjs
index ae7a24542..c7e0e5160 100644
--- a/scripts/theme-studio/test-columns.mjs
+++ b/scripts/theme-studio/test-columns.mjs
@@ -201,3 +201,24 @@ test('sortColumns: Normal - preserves member order inside a column', () => {
const members = ['#dddddd', '#222222', '#888888'];
assert.deepEqual(sortColumns([column('gray', members)])[0].members.map(m => m.hex), members);
});
+
+// --- regenColumn ground bounds (task: spans stop at bg/fg) -------------------
+const _lum = h => { const n=parseInt(h.slice(1),16),r=(n>>16&255)/255,g=(n>>8&255)/255,b=(n&255)/255; const f=c=>c<=0.03928?c/12.92:((c+0.055)/1.055)**2.4; return 0.2126*f(r)+0.7152*f(g)+0.0722*f(b); };
+
+test('regenColumn: Normal - ground-bounded span stays within the bg/fg endpoints', () => {
+ const bg = '#101010', fg = '#f0f0f0';
+ const members = regenColumn('#67809c', 4, { ground: { bg, fg } }).members;
+ const lo = _lum(bg), hi = _lum(fg);
+ assert.ok(members.every(m => _lum(m.hex) >= lo - 1e-6 && _lum(m.hex) <= hi + 1e-6),
+ 'every generated member sits within [bg, fg] luminance');
+});
+
+test('regenColumn: Boundary - a near-black bg yields no duplicate pure-black tiles', () => {
+ const members = regenColumn('#67809c', 8, { ground: { bg: '#000000', fg: '#ffffff' } }).members;
+ assert.ok(!members.some(m => m.offset !== 0 && (m.hex === '#000000' || m.hex === '#ffffff')),
+ 'pure endpoints are not duplicated as generated steps');
+});
+
+test('regenColumn: Boundary - no ground falls back to the black/white span', () => {
+ assert.equal(regenColumn('#67809c', 2).members.length, 5);
+});