@thalavaisankar/atoms 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -3
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/dist/components/ui/theme-provider/index.mjs +6 -0
- package/dist/components/ui/theme-provider/index.mjs.map +1 -0
- package/dist/components/ui/theme-provider/theme-provider.mjs +70 -0
- package/dist/components/ui/theme-provider/theme-provider.mjs.map +1 -0
- package/dist/index.d.mts +66 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/lib/theme.mjs +67 -0
- package/dist/lib/theme.mjs.map +1 -0
- package/dist/styles.css +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/theme.ts"],"sourcesContent":["// Theming: the one list of every axis Atoms can be themed on, and their defaults. A plain module (no\n// \"use client\"), so the root layout can read the defaults and inline `appearanceScript`, and client\n// controls can share the same names. The tokens these names select live in app/atoms.css.\n//\n// theme a class on <html>: light (the bare :root), dark, moonlight. Driven by next-themes.\n// accent data-accent=\"<preset>\" on <html>, or a custom --brand\n// radius --radius, the one knob the whole rounding scale derives from\n// density <DensityProvider density> around the app (spacing only)\n// contrast data-contrast=\"high\" on <html> or any subtree\n//\n// Theme and accent are the two a visitor can change and keep (next-themes stores the theme; the\n// accent keys below store the accent). Radius, density and contrast are design decisions set in code.\n\nimport type { Density } from \"./density.mjs\"\n\n/* ─── Theme ──────────────────────────────────────────────────────────────── */\n\nexport const THEMES = [\"light\", \"dark\", \"moonlight\"] as const\nexport type Theme = (typeof THEMES)[number]\n/** What a visitor can pick: a theme, or the system's light/dark preference. */\nexport type ThemeSetting = Theme | \"system\"\nexport const DEFAULT_THEME: ThemeSetting = \"system\"\n\nexport function isTheme(value: unknown): value is Theme {\n return typeof value === \"string\" && (THEMES as readonly string[]).includes(value)\n}\n\n/* ─── Accent ─────────────────────────────────────────────────────────────── */\n\n/** The accent presets, in display order. Each is a `[data-accent]` block in app/atoms.css. */\nexport const ACCENTS = [\"orange\", \"red\", \"amber\", \"green\", \"teal\", \"blue\", \"violet\", \"pink\", \"lime\", \"white\"] as const\nexport type Accent = (typeof ACCENTS)[number]\nexport const DEFAULT_ACCENT: Accent = \"orange\"\n\nexport function isAccent(value: unknown): value is Accent {\n return typeof value === \"string\" && (ACCENTS as readonly string[]).includes(value)\n}\n\nexport const ACCENT_STORAGE_KEY = \"atoms-accent\"\n/** A custom accent colour (any CSS colour), stored instead of a preset. */\nexport const BRAND_STORAGE_KEY = \"atoms-brand\"\n\n/**\n * The shapes a custom accent may take: a hex colour or a colour function. Anything else (and\n * anything with characters that could end a declaration) is refused before it reaches `--brand`.\n */\nconst CUSTOM_BRAND_SOURCE = \"^(#[0-9a-f]{3,8}|(rgba?|hsla?|hwb|oklch|oklab|lab|lch|color)\\\\([0-9a-z.,%/+\\\\s-]{1,80}\\\\))$\"\nconst CUSTOM_BRAND = new RegExp(CUSTOM_BRAND_SOURCE, \"i\")\n\n/** True for a colour that can be used as a custom accent. Also checks `CSS.supports` when there is one. */\nexport function isCustomBrand(value: unknown): value is string {\n if (typeof value !== \"string\" || !CUSTOM_BRAND.test(value.trim())) return false\n if (typeof CSS !== \"undefined\" && typeof CSS.supports === \"function\") return CSS.supports(\"color\", value.trim())\n return true\n}\n\n/* ─── Radius ─────────────────────────────────────────────────────────────── */\n\nexport const RADIUS_PRESETS = [\n { name: \"none\", label: \"None\", value: \"0rem\" },\n { name: \"sm\", label: \"Small\", value: \"0.5rem\" },\n { name: \"default\", label: \"Default\", value: \"0.75rem\" },\n { name: \"lg\", label: \"Large\", value: \"1.5rem\" },\n { name: \"full\", label: \"Full\", value: \"2rem\" },\n] as const\nexport type RadiusPreset = (typeof RADIUS_PRESETS)[number][\"name\"]\n/** The default --radius (the lg step of the scale). Matches app/atoms.css. */\nexport const DEFAULT_RADIUS = \"0.75rem\"\n\n/* ─── Density and contrast ───────────────────────────────────────────────── */\n\n/** The densities an app (or a subtree) can be set to. `touch` is a surface density, see lib/density. */\nexport const DENSITIES = [\"compact\", \"comfortable\"] as const satisfies readonly Density[]\nexport const DEFAULT_DENSITY: Density = \"compact\"\n\nexport const CONTRASTS = [\"standard\", \"high\"] as const\nexport type Contrast = (typeof CONTRASTS)[number]\nexport const DEFAULT_CONTRAST: Contrast = \"standard\"\n\n/* ─── Defaults ───────────────────────────────────────────────────────────── */\n\nexport const DEFAULT_APPEARANCE = {\n theme: DEFAULT_THEME,\n accent: DEFAULT_ACCENT,\n radius: DEFAULT_RADIUS,\n density: DEFAULT_DENSITY,\n contrast: DEFAULT_CONTRAST,\n} as const\n\n/* ─── Pre-paint script ───────────────────────────────────────────────────── */\n\n/**\n * Runs before the app's own code (the root layout inlines it), so a saved accent never flashes the\n * default first. A saved custom colour wins over a saved preset: it sets `--brand` on <html> and\n * removes `data-accent`. Both are validated; anything else in storage is ignored.\n */\nexport const appearanceScript = [\n \"try{\",\n \"var d=document.documentElement,s=localStorage,\",\n `b=s.getItem(${JSON.stringify(BRAND_STORAGE_KEY)}),a=s.getItem(${JSON.stringify(ACCENT_STORAGE_KEY)}),`,\n `r=new RegExp(${JSON.stringify(CUSTOM_BRAND_SOURCE)},\"i\");`,\n \"if(b&&r.test(b)&&(!window.CSS||!CSS.supports||CSS.supports('color',b))){d.style.setProperty('--brand',b);d.removeAttribute('data-accent')}\",\n `else if(a&&${JSON.stringify(ACCENTS)}.indexOf(a)>-1){d.setAttribute('data-accent',a)}`,\n \"}catch(e){}\",\n].join(\"\")\n"],"mappings":"AAiBO,MAAM,SAAS,CAAC,SAAS,QAAQ,WAAW;AAI5C,MAAM,gBAA8B;AAEpC,SAAS,QAAQ,OAAgC;AACtD,SAAO,OAAO,UAAU,YAAa,OAA6B,SAAS,KAAK;AAClF;AAKO,MAAM,UAAU,CAAC,UAAU,OAAO,SAAS,SAAS,QAAQ,QAAQ,UAAU,QAAQ,QAAQ,OAAO;AAErG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