aboutsummaryrefslogtreecommitdiff
path: root/scripts/theme-studio/app-core.js
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-19 10:42:22 -0400
committerCraig Jennings <c@cjennings.net>2026-06-19 10:42:22 -0400
commitdde63d2708d1d374b2166d3da573402492df072a (patch)
tree1fd8f65134bd383ceca2abe02296050f79cbf34c /scripts/theme-studio/app-core.js
parent119dd8a59ffe7cc58864b750150d67db5668fd1e (diff)
downloaddotemacs-dde63d2708d1d374b2166d3da573402492df072a.tar.gz
dotemacs-dde63d2708d1d374b2166d3da573402492df072a.zip
refactor(theme-studio): table-drive vibe chroma and share the inherit walk
vibeChroma was a ten-branch if-ladder of magic chroma constants; it's now a [base, range] lookup table, so a vibe is one row to read or tune. resolveSyntaxFg and resolveUiAttr each hand-rolled the same cycle-guarded inherit walk; both now call one walkInheritChain helper that takes the parent and value functions. effResolve keeps its own recursive form since it double-indexes through the package map. I left the palette-actions splice helpers (replacePaletteEntries, withCfg) and the paletteGroups dedup for a later pass: they mutate the live palette and are only browser-gate covered, so they want their own careful change rather than riding this one.
Diffstat (limited to 'scripts/theme-studio/app-core.js')
-rw-r--r--scripts/theme-studio/app-core.js28
1 files changed, 10 insertions, 18 deletions
diff --git a/scripts/theme-studio/app-core.js b/scripts/theme-studio/app-core.js
index ee539b826..e74b0835e 100644
--- a/scripts/theme-studio/app-core.js
+++ b/scripts/theme-studio/app-core.js
@@ -132,16 +132,16 @@ const SYNTAX_INHERIT={cmd:'cm',doc:'str',prop:'var',fnc:'fnd'};
// theme's default foreground (the chain's floor). `dec` (decorator) is pinned to
// `ty`: Emacs has no decorator face and renders decorators with
// font-lock-type-face, so a dec color set in the studio would never reach Emacs.
+// Walk an inherit chain from START, returning the first truthy valueFn(key) or
+// null. nextFn(key) gives the parent key; a seen-set guards against a cycle.
+function walkInheritChain(start,nextFn,valueFn){
+ let k=start;const seen={};
+ while(k&&!seen[k]){seen[k]=1;const v=valueFn(k);if(v)return v;k=nextFn(k);}
+ return null;
+}
function resolveSyntaxFg(cat,syntax,defaultFg){
- let k=(cat==='dec')?'ty':cat;
- const seen={};
- while(k&&!seen[k]){
- seen[k]=1;
- const fg=syntax[k]&&syntax[k].fg;
- if(fg)return fg;
- k=SYNTAX_INHERIT[k];
- }
- return defaultFg;
+ const start=(cat==='dec')?'ty':cat;
+ return walkInheritChain(start,k=>SYNTAX_INHERIT[k],k=>syntax[k]&&syntax[k].fg)||defaultFg;
}
// Emacs built-in inherit chains for the ui faces whose parent is also a studio ui
@@ -153,15 +153,7 @@ const UI_INHERIT={'mode-line-inactive':'mode-line','line-number-current-line':'l
// nothing up the chain is set. The caller applies its own floor (default fg,
// ground, or transparent), since that floor differs per attribute and face.
function resolveUiAttr(face,attr,uimap){
- let f=face;
- const seen={};
- while(f&&!seen[f]){
- seen[f]=1;
- const v=uimap[f]&&uimap[f][attr];
- if(v)return v;
- f=UI_INHERIT[f];
- }
- return null;
+ return walkInheritChain(face,f=>UI_INHERIT[f],f=>uimap[f]&&uimap[f][attr]);
}
// Text color for a swatch-dropdown popup row. A row showing a real palette color