From de6fccc99c47f69da5c39718c1882c7342ee0e52 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 15 Jun 2026 22:07:45 -0500 Subject: refactor(theme-studio): extract a groundPair() helper The literal {bg:MAP['bg'],fg:MAP['p']} repeated 32 times across app.js, palette-actions.js, and the browser gates. Replace it with a groundPair() helper. Named groundPair, not ground, to avoid colliding with the local ground bindings destructured from columnsFromPalette. No behavior change; node tests and browser gates are the safety net. --- scripts/theme-studio/app.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'scripts/theme-studio/app.js') diff --git a/scripts/theme-studio/app.js b/scripts/theme-studio/app.js index cfa5b8705..a4e0da9c1 100644 --- a/scripts/theme-studio/app.js +++ b/scripts/theme-studio/app.js @@ -41,6 +41,10 @@ function crHtml(r,target=4.5){const v=verdictFor(r,target);return ``:`${esc(nm)}`;paintStepButtons();} @@ -84,7 +88,7 @@ function mkColorDropdown(options,cur,onPick,opts={}){ // then one row per family) instead of a long vertical list. galleryModel is // the shared pure layout (app-core.js). const pop=document.createElement('div');pop.className='cddpop cddgrid'; - const model=galleryModel(cur,PALETTE,{bg:MAP['bg'],fg:MAP['p']}); + const model=galleryModel(cur,PALETTE,groundPair()); const pick=(hex)=>{cur=hex;paint();closeColorDropdown();onPick(hex);}; const head=document.createElement('div');head.className='cddghead'; const def=document.createElement('button');def.type='button'; @@ -118,7 +122,7 @@ function mkColorDropdown(options,cur,onPick,opts={}){ // palette in the same ground/column order as the palette panel. If cur is set // but no longer in the palette, surface it as a "(gone)" entry so the row still // shows what it points at. Shared by all three tiers. -function ddList(cur){return paletteOptionList(cur,PALETTE,{bg:MAP['bg'],fg:MAP['p']});} +function ddList(cur){return paletteOptionList(cur,PALETTE,groundPair());} // Shared lock toggle for any table row. lockKey is namespaced per tier (bare // syntax kind, 'ui:'+face, 'pkg:'+app+':'+face). els are the row's editable // controls — native selects/buttons/inputs are disabled; the custom swatch @@ -228,13 +232,13 @@ function applyEdit(){if(selectedIdx!==null)updateColor();else addColor();} function selectColor(i){selectedIdx=i;GEN_SELECTION=null;const [hex,name]=PALETTE[i];setHex(hex);document.getElementById('newname').value=name;renderPalette();renderGeneratorPreview();notify('editing "'+name+'" — change the value, then Enter (or Update selected) to save',false);} function updateColor(){ if(selectedIdx===null){notify('click a palette color to select it first',true);return;} - const i=selectedIdx,oldHex=PALETTE[i][0],oldRole=groundRoleOfEntry(PALETTE[i],{bg:MAP['bg'],fg:MAP['p']}); + const i=selectedIdx,oldHex=PALETTE[i][0],oldRole=groundRoleOfEntry(PALETTE[i],groundPair()); const newHex=curHex(); const newName=(document.getElementById('newname').value.trim())||PALETTE[i][1]; if(PALETTE.some((p,j)=>j!==i&&p[1].toLowerCase()===newName.toLowerCase())){notify('another color is already named "'+newName+'" — names must be unique',true);return;} const isGroundEdit=oldRole==='bg'||oldRole==='fg'; // If the edited color is a column base with a ramp, recolor the whole column: regenerate from the new base at the same count. - const columns=columnsFromPalette(PALETTE,{bg:MAP['bg'],fg:MAP['p']}).columns; + const columns=columnsFromPalette(PALETTE,groundPair()).columns; const column=isGroundEdit?null:columns.find(f=>f.base.toLowerCase()===oldHex.toLowerCase()); const count=column?Math.max(0,...rankByLightness(column.members.map(m=>m.hex),column.base).map(m=>Math.abs(m.offset))):0; const columnId=isGroundEdit?'ground':(PALETTE[i][2]||columnStem(PALETTE[i][1])); -- cgit v1.2.3