{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"lib-themes","type":"registry:lib","title":"themes helpers","description":"The theme presets of @dashral/ui/themes.css as data: each setting's choices (with a swatch to show them by), a","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/dashral/lib/themes.ts","type":"registry:file","target":"components/dashral/lib/themes.ts","content":"// The theme presets of @dashral/ui/themes.css as data: each setting's choices (with a swatch to show them by), a\n// whole look's defaults, named presets, a shuffle that still goes together, and the data attributes a look sets. The\n// dashboard's customizer and the website's preview customizer both read them from here.\n\nexport const themeOptions = {\n  primary: [\n    { value: \"black\", label: \"Black\", swatch: \"oklch(0.205 0 0)\" },\n    { value: \"blue\", label: \"Blue\", swatch: \"oklch(0.546 0.245 262.881)\" },\n    { value: \"indigo\", label: \"Indigo\", swatch: \"oklch(0.511 0.262 276.966)\" },\n    { value: \"purple\", label: \"Purple\", swatch: \"oklch(0.558 0.288 302.321)\" },\n    { value: \"green\", label: \"Green\", swatch: \"oklch(0.527 0.154 150.069)\" },\n    { value: \"amber\", label: \"Amber\", swatch: \"oklch(0.769 0.188 70.08)\" },\n    { value: \"rose\", label: \"Rose\", swatch: \"oklch(0.514 0.222 16.935)\" },\n  ],\n  light: [\n    { value: \"neutral\", label: \"Neutral\", swatch: \"oklch(0.922 0 0)\" },\n    { value: \"gray\", label: \"Gray\", swatch: \"oklch(0.96 0.005 250)\" },\n    { value: \"slate\", label: \"Slate\", swatch: \"oklch(0.929 0.013 255.508)\" },\n  ],\n  dark: [\n    { value: \"default\", label: \"Default\", swatch: \"oklch(0.2 0.005 260)\" },\n    { value: \"navy\", label: \"Navy\", swatch: \"oklch(0.208 0.042 265.755)\" },\n    { value: \"zinc\", label: \"Zinc\", swatch: \"oklch(0.21 0.006 285.885)\" },\n    { value: \"black\", label: \"Black\", swatch: \"oklch(0.1 0 0)\" },\n    { value: \"mint\", label: \"Mint\", swatch: \"oklch(0.21 0.03 190)\" },\n  ],\n  card: [\n    { value: \"default\", label: \"Default\" },\n    { value: \"soft\", label: \"Soft\" },\n    { value: \"shadow\", label: \"Shadow\" },\n  ],\n  font: [\n    { value: \"inter\", label: \"Inter\" },\n    { value: \"geist\", label: \"Geist\" },\n    { value: \"system\", label: \"System\" },\n  ],\n  radius: [\n    { value: \"0\", label: \"0\" },\n    { value: \"sm\", label: \"0.375\" },\n    { value: \"md\", label: \"0.625\" },\n    { value: \"lg\", label: \"0.875\" },\n    { value: \"xl\", label: \"1.25\" },\n  ],\n} as const\n\ntype Values<K extends keyof typeof themeOptions> = (typeof themeOptions)[K][number][\"value\"]\n\n/** A look: the settings themes.css styles. Mode, monochrome and reduced motion are the reader's own, not part of it. */\nexport type ThemeLook = {\n  primary: Values<\"primary\">\n  light: Values<\"light\">\n  dark: Values<\"dark\">\n  card: Values<\"card\">\n  radius: Values<\"radius\">\n  /** The text font (headings stay Geist): Inter, Geist, or the device's own. */\n  font: Values<\"font\">\n}\n\nexport const lookKeys = [\"primary\", \"light\", \"dark\", \"card\", \"radius\", \"font\"] as const\n\n/** The look of globals.css alone: each of these is \"no attribute\". */\nexport const defaultLook: ThemeLook = { primary: \"black\", light: \"neutral\", dark: \"default\", card: \"default\", radius: \"lg\", font: \"inter\" }\n\n/** The data attributes that give an element (or <html>) a look: only the settings that differ from the default. */\nexport function lookAttributes(look: ThemeLook): Record<string, string> {\n  return Object.fromEntries(lookKeys.filter((key) => look[key] !== defaultLook[key]).map((key) => [`data-${key}`, look[key]]))\n}\n\nexport const sameLook = (a: ThemeLook, b: ThemeLook) => lookKeys.every((key) => a[key] === b[key])\n\n/** Looks put together to work as a whole, each with an id (a name to translate) and an English name. */\nexport const presets: { id: \"ocean\" | \"mono\" | \"forest\" | \"ember\" | \"studio\" | \"grape\"; name: string; look: ThemeLook }[] = [\n  { id: \"ocean\", name: \"Ocean\", look: { primary: \"blue\", light: \"slate\", dark: \"navy\", card: \"soft\", radius: \"lg\", font: \"inter\" } },\n  { id: \"mono\", name: \"Mono\", look: { primary: \"black\", light: \"neutral\", dark: \"zinc\", card: \"default\", radius: \"md\", font: \"geist\" } },\n  { id: \"forest\", name: \"Forest\", look: { primary: \"green\", light: \"gray\", dark: \"mint\", card: \"shadow\", radius: \"xl\", font: \"inter\" } },\n  { id: \"ember\", name: \"Ember\", look: { primary: \"rose\", light: \"neutral\", dark: \"default\", card: \"soft\", radius: \"lg\", font: \"geist\" } },\n  { id: \"studio\", name: \"Studio\", look: { primary: \"indigo\", light: \"slate\", dark: \"navy\", card: \"shadow\", radius: \"sm\", font: \"system\" } },\n  { id: \"grape\", name: \"Grape\", look: { primary: \"purple\", light: \"gray\", dark: \"zinc\", card: \"soft\", radius: \"xl\", font: \"geist\" } },\n]\n\nconst pick = <T>(list: readonly T[]) => list[Math.floor(Math.random() * list.length)]!\n\n// The dark backgrounds that sit well with each color: a tinted one beside its own hue, neutral ones beside the rest.\nconst darkFor: Record<ThemeLook[\"primary\"], ThemeLook[\"dark\"][]> = {\n  blue: [\"navy\", \"default\", \"zinc\"],\n  indigo: [\"navy\", \"zinc\", \"default\"],\n  purple: [\"zinc\", \"default\", \"black\"],\n  green: [\"mint\", \"default\", \"black\"],\n  amber: [\"default\", \"zinc\", \"black\"],\n  rose: [\"default\", \"zinc\", \"black\"],\n  black: [\"zinc\", \"black\", \"default\"],\n}\n// Cool grays beside cool colors, plain ones beside warm colors and black.\nconst lightFor: Record<ThemeLook[\"primary\"], ThemeLook[\"light\"][]> = {\n  blue: [\"slate\", \"gray\"],\n  indigo: [\"slate\", \"gray\"],\n  purple: [\"gray\", \"neutral\"],\n  green: [\"gray\", \"neutral\"],\n  amber: [\"neutral\", \"gray\"],\n  rose: [\"neutral\", \"gray\"],\n  black: [\"neutral\", \"gray\"],\n}\n\n/** A look at random that still goes together (its backgrounds follow its color), never the one you have. */\nexport function shuffleLook(current: ThemeLook): ThemeLook {\n  for (;;) {\n    const primary = pick(themeOptions.primary).value\n    const look: ThemeLook = {\n      primary,\n      light: pick(lightFor[primary]),\n      dark: pick(darkFor[primary]),\n      card: pick(themeOptions.card).value,\n      // Square corners are a deliberate choice, not a lucky draw.\n      radius: pick(themeOptions.radius.filter((option) => option.value !== \"0\")).value,\n      font: pick(themeOptions.font).value,\n    }\n    if (!sameLook(look, current)) return look\n  }\n}\n"}]}