rizzo-css 0.0.25 → 0.0.26

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.
Files changed (30) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -1
  3. package/scaffold/utils/theme.ts +65 -0
  4. package/scaffold/vanilla/README-RIZZO.md +1 -1
  5. package/scaffold/vanilla/components/accordion.html +8 -0
  6. package/scaffold/vanilla/components/alert.html +8 -0
  7. package/scaffold/vanilla/components/avatar.html +8 -0
  8. package/scaffold/vanilla/components/badge.html +8 -0
  9. package/scaffold/vanilla/components/breadcrumb.html +8 -0
  10. package/scaffold/vanilla/components/button.html +8 -0
  11. package/scaffold/vanilla/components/cards.html +8 -0
  12. package/scaffold/vanilla/components/copy-to-clipboard.html +8 -0
  13. package/scaffold/vanilla/components/divider.html +8 -0
  14. package/scaffold/vanilla/components/dropdown.html +8 -0
  15. package/scaffold/vanilla/components/forms.html +8 -0
  16. package/scaffold/vanilla/components/icons.html +8 -0
  17. package/scaffold/vanilla/components/index.html +8 -0
  18. package/scaffold/vanilla/components/modal.html +8 -0
  19. package/scaffold/vanilla/components/navbar.html +8 -0
  20. package/scaffold/vanilla/components/pagination.html +8 -0
  21. package/scaffold/vanilla/components/progress-bar.html +8 -0
  22. package/scaffold/vanilla/components/search.html +8 -0
  23. package/scaffold/vanilla/components/settings.html +8 -0
  24. package/scaffold/vanilla/components/spinner.html +8 -0
  25. package/scaffold/vanilla/components/table.html +8 -0
  26. package/scaffold/vanilla/components/tabs.html +8 -0
  27. package/scaffold/vanilla/components/theme-switcher.html +8 -0
  28. package/scaffold/vanilla/components/toast.html +8 -0
  29. package/scaffold/vanilla/components/tooltip.html +8 -0
  30. package/scaffold/vanilla/index.html +8 -0
package/README.md CHANGED
@@ -56,7 +56,7 @@ import 'rizzo-css';
56
56
  **Without a bundler (plain HTML):** Use a CDN. Both unpkg and jsDelivr resolve the package root to the built CSS (via the `unpkg` / `jsdelivr` fields in this package). For reliability or to pin a version, use the explicit path:
57
57
 
58
58
  ```html
59
- <!-- unpkg (pin version: replace @latest with @0.0.25 or any version) -->
59
+ <!-- unpkg (pin version: replace @latest with @0.0.26 or any version) -->
60
60
  <link rel="stylesheet" href="https://unpkg.com/rizzo-css@latest/dist/rizzo.min.css" />
61
61
 
62
62
  <!-- or jsDelivr -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rizzo-css",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "scripts": {
5
5
  "prepublishOnly": "cd ../.. && pnpm run lint:css:fix && pnpm run build:css && node scripts/copy-scaffold.js && node scripts/prepare-vanilla-scaffold.js"
6
6
  },
@@ -26,6 +26,7 @@
26
26
  ".env.example",
27
27
  "bin",
28
28
  "scaffold/astro",
29
+ "scaffold/utils",
29
30
  "scaffold/svelte",
30
31
  "scaffold/vanilla",
31
32
  "scaffold/astro-minimal",
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Theme utilities — apply theme, resolve system preference, get/set stored theme.
3
+ * Used by ThemeSwitcher, Layout (flash prevention), and any consumer that sets data-theme.
4
+ */
5
+ import { ALL_THEMES } from '../astro/themes';
6
+
7
+ export const THEME_SYSTEM = 'system';
8
+ export const DEFAULT_THEME_DARK = 'github-dark-classic';
9
+ export const DEFAULT_THEME_LIGHT = 'github-light';
10
+
11
+ /** Current theme id from the DOM (data-theme on html). */
12
+ export function getCurrentTheme(): string {
13
+ if (typeof document === 'undefined') return DEFAULT_THEME_DARK;
14
+ return document.documentElement.getAttribute('data-theme') || DEFAULT_THEME_DARK;
15
+ }
16
+
17
+ /** Stored theme from localStorage (may be 'system' or a theme id). */
18
+ export function getStoredTheme(): string {
19
+ if (typeof localStorage === 'undefined') return getCurrentTheme();
20
+ return localStorage.getItem('theme') || getCurrentTheme();
21
+ }
22
+
23
+ /** Resolve system preference to a concrete theme id. */
24
+ export function resolveSystemTheme(): string {
25
+ if (typeof window === 'undefined') return DEFAULT_THEME_DARK;
26
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? DEFAULT_THEME_DARK : DEFAULT_THEME_LIGHT;
27
+ }
28
+
29
+ /** Resolve stored theme to the effective theme id (for 'system', returns resolved dark/light). */
30
+ export function getResolvedTheme(): string {
31
+ const stored = getStoredTheme();
32
+ if (!stored || stored === THEME_SYSTEM) return resolveSystemTheme();
33
+ return stored;
34
+ }
35
+
36
+ /** Get { value, label } for a theme (for UI display). */
37
+ export function getThemeInfo(themeValue: string): { value: string; label: string } {
38
+ if (themeValue === THEME_SYSTEM) return { value: THEME_SYSTEM, label: 'System' };
39
+ const entry = ALL_THEMES.find((t) => t.value === themeValue);
40
+ return entry ? { value: entry.value, label: entry.label } : { value: themeValue, label: 'Theme' };
41
+ }
42
+
43
+ /** Get display label for a theme value (from config). */
44
+ export function getThemeLabel(themeValue: string): string {
45
+ return getThemeInfo(themeValue).label;
46
+ }
47
+
48
+ /** Apply a theme: set data-theme and persist to localStorage. Use for ThemeSwitcher and programmatic changes. */
49
+ export function applyTheme(themeValue: string): void {
50
+ if (typeof document === 'undefined' || typeof localStorage === 'undefined') return;
51
+ let effective: string;
52
+ if (themeValue === THEME_SYSTEM) {
53
+ effective = resolveSystemTheme();
54
+ document.documentElement.setAttribute('data-theme', effective);
55
+ localStorage.setItem('theme', THEME_SYSTEM);
56
+ } else {
57
+ document.documentElement.setAttribute('data-theme', themeValue);
58
+ localStorage.setItem('theme', themeValue);
59
+ effective = themeValue;
60
+ }
61
+ // Allow listeners to sync UI (e.g. ThemeSwitcher)
62
+ try {
63
+ window.dispatchEvent(new CustomEvent('rizzo-theme-change', { detail: { themeValue, effective } }));
64
+ } catch (_) {}
65
+ }
@@ -13,7 +13,7 @@ If you prefer to load CSS from a CDN instead of the local file, replace the `<li
13
13
  - `<link rel="stylesheet" href="https://unpkg.com/rizzo-css@latest/dist/rizzo.min.css" />`
14
14
  - Or jsDelivr: `https://cdn.jsdelivr.net/npm/rizzo-css@latest/dist/rizzo.min.css`
15
15
 
16
- (Replace `@latest` with a specific version, e.g. `@0.0.25`, in production.)
16
+ (Replace `@latest` with a specific version, e.g. `@0.0.26`, in production.)
17
17
 
18
18
  The CLI replaces placeholders in `index.html` (e.g. `{{DATA_THEME}}`, `{{TITLE}}`) when you run `rizzo-css init`. The theme selected during init is used on first load when you have no saved preference in the browser.
19
19