theme: import a shadcn preset code#605
let people paste a shadcn preset code (the --preset <code> value from shadcn init) as a theme, and keep the monochrome look as the default.
where: apps/player/src/components/theme-builder.tsx, apps/player/src/lib/look-code.ts, apps/player/src/lib/look-apply.ts
what a preset code is (decoded with npx shadcn@latest preset decode <code> --json, the same thing decodePreset from shadcn/preset does, already in the repo as the shadcn dev dependency). it is a short base62 string with a version letter first, and it encodes:
- style (vega, nova, maia, lyra, mira, luma...)
- baseColor and theme (the neutral scale and the accent color)
- chartColor
- iconLibrary
- font and fontHeading
- radius
- menuColor and menuAccent
examples:
b6tOz2I0x: style luma, baseColor olive, theme olive, chart olive, font geist, heading inherit, radius default, icons hugeicons, menu inverted-translucent / subtleb7kBsBkh7b: style nova, baseColor zinc, theme green, chart zinc, font geist-mono, heading instrument-sans, radius medium, icons remixicon, menu inverted-translucent / subtle
today the theme builder only knows its own lode1.<tone>.<accent>.<radius>.<font> code (3 tones, 3 accents, 4 radii, 2 fonts), so a shadcn code shows "that is not a theme code".
proposal:
- in the "theme code to import" field, accept both:
lode1.*as now, and anythingisPresetCodeaccepts (also a pasted--preset b6tOz2I0xor a ui.shadcn.com/create?preset= url) - decode client side and map only what lodesong can honor: baseColor + theme -> tone/accent css variables (light and dark), radius -> radius token, font -> font stack. style, iconLibrary and menu* are ignored (lodesong ships its own square components and icons), and say so under the field instead of failing silently
- colors for a baseColor/theme come from shadcn's registry css variables; ship a small generated table for the supported ones rather than fetching at runtime, so a self-hosted server never needs the internet. a script regenerates it when the
shadcnversion bumps - store the result in the existing
looksetting (it syncs per account); keepDEFAULT_LOOK(neutral, ink, radius 0, plex) as the default, as the "lodesong" preset, and a "reset to lodesong" button - contrast check on the decoded colors in both modes before applying; fall back with a message if a theme gives text under 4.5:1
- fonts: only load a font the preset names if it is self hosted in the bundle; otherwise fall back to the closest of plex/mono
good looks like: paste b7kBsBkh7b, the app turns green accent on zinc with medium radius and a mono font within one frame, preview and revert work like the current builder, and reset brings the monochrome look back.