Brand-prompt → Tier-2 token-override generator. Local deterministic
generator by default; pluggable async LLM hook. WCAG-correct
contrast enforcement with AA / AAA lock policies.
──────────────────────────────────────────────────────────────────
Module surface
──────────────────────────────────────────────────────────────────
generateThemeFromPrompt(prompt, opts?)
- opts.generate: optional async LLM hook (host wires real LLM)
- opts.enforce: 'aa' (default) | 'aaa' | 'off'
- Always runs the contrast pass when enforce !== 'off'
- WAVE 13.E.1
localGenerate(prompt)
- Synchronous; 7 hand-curated palettes (midnight, citrus,
forest, ocean, rose, graphite, violet) + default fallback
- Keyword-matched via regex; deterministic for caching
Contrast utilities (Wave 13.E.2):
parseHex / toHex — input + output round-trip safe
relativeLuminance — WCAG 2.x luminance
contrast(a, b) — pair contrast ratio
report(fg, bg) — { ratio, aa, aaa }
auditTheme(theme) — 4 canonical text/accent pairings
adjustForContrast(fg,bg,t) — iteratively darken/lighten until ≥ t
enforceContrast(theme,'aa') — returns adjusted ThemeProposal
applyTheme(theme, target?)
- Writes 11 --bl-* custom properties onto the target element
- Returns a tear-down fn (saved prior values, restored on call)
──────────────────────────────────────────────────────────────────
Quality gates
──────────────────────────────────────────────────────────────────
✓ 18/18 tests passing (hex / contrast math / generator /
enforcement / applyTheme cleanup)
✓ tsc build clean
✓ Zero runtime deps, pure functions where possible
──────────────────────────────────────────────────────────────────
Roadmap (lands in subsequent commit)
──────────────────────────────────────────────────────────────────
13.E.1 Deterministic prompt → palette generator
13.E.2 Contrast checker + AA / AAA enforcement
Showcase route /futurism/theme-studio (MAG.5) lands in paired
showcase commit.
34 lines
744 B
TypeScript
34 lines
744 B
TypeScript
/**
|
|
* @bytelyst/generative-theme — brand-prompt → Tier-2 token overrides.
|
|
*
|
|
* Wave 13.E. Defaults to a local deterministic generator (7 palette
|
|
* families: midnight · citrus · forest · ocean · rose · graphite ·
|
|
* violet); host can plug a real LLM via `GenerationOptions.generate`.
|
|
* Output is contrast-checked + AA / AAA-locked before return.
|
|
*/
|
|
|
|
export {
|
|
generateThemeFromPrompt,
|
|
localGenerate,
|
|
} from './generate.js';
|
|
|
|
export {
|
|
parseHex,
|
|
toHex,
|
|
relativeLuminance,
|
|
contrast,
|
|
report,
|
|
auditTheme,
|
|
adjustForContrast,
|
|
enforceContrast,
|
|
} from './contrast.js';
|
|
|
|
export { applyTheme } from './apply.js';
|
|
|
|
export type {
|
|
ContrastCheck,
|
|
ContrastReport,
|
|
GenerationOptions,
|
|
ThemeProposal,
|
|
} from './types.js';
|