chore(badges): hex-only body_text_color + form color picker; renderer default black

This commit is contained in:
Scott Idem
2026-04-08 14:19:48 -04:00
parent 0aa32a5293
commit d5b2b557f3
3 changed files with 40 additions and 27 deletions

View File

@@ -296,28 +296,17 @@ let qr_back_justify = $derived.by(() => {
});
// Body text color: can be a Tailwind `text-*` class or a hex value like `#112233`.
let body_text_color_class = $derived.by(() => {
const cfg = template_cfg || {};
const raw = cfg?.body_text_color ?? cfg?.text_color ?? '';
if (!raw || typeof raw !== 'string') return '';
const v = raw.trim();
if (v.startsWith('text-')) return v;
// Map simple color names to Tailwind where reasonable (e.g., 'white' -> 'text-white')
if (/^[a-zA-Z]+$/.test(v)) {
const pick = v.toLowerCase();
const allowed = ['white','black','gray','red','blue','green','yellow','indigo','purple','pink'];
if (allowed.includes(pick)) return `text-${pick}`;
}
return '';
});
// Prefer an explicit hex fallback stored as `body_text_color_hex` in `cfg_json`.
// The `body_text_color` key may still contain a Tailwind class for styling
// when the compiled CSS includes it; the hex ensures correct rendering when
// classes are purged at build-time.
let body_text_color_style = $derived.by(() => {
const cfg = template_cfg || {};
const raw = cfg?.body_text_color ?? cfg?.text_color ?? '';
if (!raw || typeof raw !== 'string') return '';
if (!raw || typeof raw !== 'string') return 'color: #000000;';
const v = raw.trim();
if (/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(v)) return `color: ${v};`;
return '';
return 'color: #000000;';
});
/**
@@ -686,7 +675,7 @@ const code_to_icon: {
items-center
justify-end overflow-clip
p-0 px-8 pb-1
{body_text_color_class || 'text-white'}
text-black
gap-0
"
style="{body_text_color_style}">