diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-15 19:19:38 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-15 19:19:38 -0500 |
| commit | 7e7b871fe4f8daff724c3df37feb5572464532c1 (patch) | |
| tree | 3dcfb0e760a22b460bc1188a9b6d7a6b5433a5a3 /scripts/theme-studio/app-core.js | |
| parent | 5ab506d9b65a0d043c08690b86976b1f97889eaf (diff) | |
| download | dotemacs-7e7b871fe4f8daff724c3df37feb5572464532c1.tar.gz dotemacs-7e7b871fe4f8daff724c3df37feb5572464532c1.zip | |
feat(theme-studio): flag unused palette tiles and columns
I added usedPaletteHexes, a reverse lookup over the syntax, ui, and package assignments (plus the ground endpoints) that resolves each reference to a hex. renderPalette outlines a tile whose color is referenced nowhere and outlines a whole column when none of its colors are used, so dead colors stand out for pruning before a theme ships. The check is biased safe: an unresolvable reference marks nothing, so a color that is actually used is never flagged.
Node tests cover the lookup. A #unusedtest gate covers the tile and column flags.
Diffstat (limited to 'scripts/theme-studio/app-core.js')
| -rw-r--r-- | scripts/theme-studio/app-core.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/scripts/theme-studio/app-core.js b/scripts/theme-studio/app-core.js index 8642388e2..d21254e40 100644 --- a/scripts/theme-studio/app-core.js +++ b/scripts/theme-studio/app-core.js @@ -240,6 +240,21 @@ function toggleLockSet(keys,locked){ // from the palette, and ground+N entries are reserved for that column. Everything // else groups by its stable column id, not by OKLCH hue/chroma or display name. // Legacy two-field entries fall back to their generated-name stem until edited. +// Reverse lookup: every palette hex referenced by an assignment (syntax, ui, or +// package fg / bg / box-color), plus the ground endpoints, which are always in +// use. Values may be palette names or hexes; nameToHex resolves both, so a tile +// whose hex is absent from this set is genuinely unreferenced. Biased safe: an +// unresolvable value simply marks nothing, so a used color is never flagged. +function usedPaletteHexes(palette,syntax,uimap,pkgmap,ground){ + const used=new Set(); + const add=v=>{const h=nameToHex(v,palette);if(h)used.add(h.toLowerCase());}; + const addFace=f=>{if(!f)return;add(f.fg);add(f.bg);if(f.box&&f.box.color)add(f.box.color);}; + if(ground){if(ground.bg)add(ground.bg);if(ground.fg)add(ground.fg);} + for(const k in (syntax||{}))addFace(syntax[k]); + for(const face in (uimap||{}))addFace(uimap[face]); + for(const app in (pkgmap||{}))for(const face in pkgmap[app])addFace(pkgmap[app][face]); + return used; +} function columnsFromPalette(palette,ground){ const bg=ground&&ground.bg,fg=ground&&ground.fg; const groundStrip=[]; @@ -352,4 +367,4 @@ function spanNeighborHex(cur,palette,ground,dir){ return null; } -export { nameToHex, normalizePkgFace, buildPkgmap, packagesForExport, mergePackagesInto, effResolve, resolveSyntaxFg, resolveUiAttr, dropdownRowTextColor, paletteOptionList, spanNeighborHex, slugify, fgSetFor, floor, lMax, COVERED_FACES, columnsFromPalette, regenColumn, rankByLightness, stepRepointPlan, sortColumns, sortColumnMembers, groundRoleOfEntry, groundColumnMembersFromPalette, clearPalettePlan, deletePaletteColumnPlan, areAllLocked, lockToggleLabel, toggleLockSet }; +export { nameToHex, normalizePkgFace, buildPkgmap, packagesForExport, mergePackagesInto, effResolve, resolveSyntaxFg, resolveUiAttr, dropdownRowTextColor, paletteOptionList, spanNeighborHex, slugify, fgSetFor, floor, lMax, COVERED_FACES, columnsFromPalette, usedPaletteHexes, regenColumn, rankByLightness, stepRepointPlan, sortColumns, sortColumnMembers, groundRoleOfEntry, groundColumnMembersFromPalette, clearPalettePlan, deletePaletteColumnPlan, areAllLocked, lockToggleLabel, toggleLockSet }; |
