rizzo-css 0.0.24 → 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 (34) hide show
  1. package/README.md +1 -1
  2. package/bin/rizzo-css.js +20 -24
  3. package/package.json +2 -1
  4. package/scaffold/astro/Settings.astro +7 -2
  5. package/scaffold/astro/ThemeSwitcher.astro +7 -2
  6. package/scaffold/astro-minimal/src/layouts/Layout.astro +3 -0
  7. package/scaffold/utils/theme.ts +65 -0
  8. package/scaffold/vanilla/README-RIZZO.md +1 -1
  9. package/scaffold/vanilla/components/accordion.html +16 -0
  10. package/scaffold/vanilla/components/alert.html +16 -0
  11. package/scaffold/vanilla/components/avatar.html +16 -0
  12. package/scaffold/vanilla/components/badge.html +16 -0
  13. package/scaffold/vanilla/components/breadcrumb.html +16 -0
  14. package/scaffold/vanilla/components/button.html +16 -0
  15. package/scaffold/vanilla/components/cards.html +16 -0
  16. package/scaffold/vanilla/components/copy-to-clipboard.html +16 -0
  17. package/scaffold/vanilla/components/divider.html +16 -0
  18. package/scaffold/vanilla/components/dropdown.html +16 -0
  19. package/scaffold/vanilla/components/forms.html +16 -0
  20. package/scaffold/vanilla/components/icons.html +16 -0
  21. package/scaffold/vanilla/components/index.html +16 -0
  22. package/scaffold/vanilla/components/modal.html +16 -0
  23. package/scaffold/vanilla/components/navbar.html +16 -0
  24. package/scaffold/vanilla/components/pagination.html +16 -0
  25. package/scaffold/vanilla/components/progress-bar.html +16 -0
  26. package/scaffold/vanilla/components/search.html +16 -0
  27. package/scaffold/vanilla/components/settings.html +16 -0
  28. package/scaffold/vanilla/components/spinner.html +16 -0
  29. package/scaffold/vanilla/components/table.html +16 -0
  30. package/scaffold/vanilla/components/tabs.html +16 -0
  31. package/scaffold/vanilla/components/theme-switcher.html +16 -0
  32. package/scaffold/vanilla/components/toast.html +16 -0
  33. package/scaffold/vanilla/components/tooltip.html +16 -0
  34. package/scaffold/vanilla/index.html +16 -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.24 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/bin/rizzo-css.js CHANGED
@@ -450,7 +450,7 @@ function selectMenu(options, title) {
450
450
  });
451
451
  }
452
452
 
453
- const HINT = ' \u2191\u2193 move \u00b7 Enter select \u00b7 1-9 pick';
453
+ const HINT = ' \u2191\u2193 move \u00b7 Enter select';
454
454
  return new Promise((resolve) => {
455
455
  let index = 0;
456
456
  const lineCount = (title ? 1 : 0) + items.length + 2; // +1 blank +1 hint
@@ -471,16 +471,6 @@ function selectMenu(options, title) {
471
471
  process.stdout.write('\u001b[?25h');
472
472
  };
473
473
 
474
- const selectByNumber = (num) => {
475
- const n = num === 0 ? 10 : num; // 0 = 10th item
476
- const idx = n >= 1 && n <= items.length ? n - 1 : index;
477
- process.stdin.setRawMode(false);
478
- process.stdin.removeListener('data', onData);
479
- process.stdin.pause();
480
- process.stdout.write('\n');
481
- resolve(items[idx].value);
482
- };
483
-
484
474
  process.stdin.setRawMode(true);
485
475
  process.stdin.resume();
486
476
  process.stdin.setEncoding('utf8');
@@ -503,16 +493,6 @@ function selectMenu(options, title) {
503
493
  resolve(items[index].value);
504
494
  return;
505
495
  }
506
- if (ch >= '1' && ch <= '9') {
507
- buf = '';
508
- selectByNumber(parseInt(ch, 10));
509
- return;
510
- }
511
- if (ch === '0' && items.length >= 10) {
512
- buf = '';
513
- selectByNumber(10);
514
- return;
515
- }
516
496
  buf += ch;
517
497
  const isUp = buf === '\u001b[A' || buf === '\u001bOA' || (buf.length >= 2 && buf.endsWith('A') && buf.startsWith('\u001b'));
518
498
  const isDown = buf === '\u001b[B' || buf === '\u001bOB' || (buf.length >= 2 && buf.endsWith('B') && buf.startsWith('\u001b'));
@@ -604,7 +584,7 @@ function multiSelectMenu(options, title, initialSelected) {
604
584
  if (initialSet.has(items[i].value)) selected.add(i);
605
585
  }
606
586
  }
607
- const HINT = ' \u2191\u2193 move \u00b7 Space toggle \u00b7 a all \u00b7 n none \u00b7 Enter confirm';
587
+ const HINT = ' \u2191\u2193 move \u00b7 Space toggle \u00b7 a all \u00b7 n none \u00b7 1-9 toggle (0=10th) \u00b7 Enter confirm';
608
588
  const lineCount = (title ? 1 : 0) + items.length + 2; // +1 blank +1 hint
609
589
  const realStart = withSentinels ? 2 : 0;
610
590
 
@@ -776,8 +756,8 @@ Package managers:
776
756
  Supported: npm, pnpm, yarn, bun. Detection: lockfiles (pnpm-lock.yaml, yarn.lock, bun.lockb, package-lock.json) or package.json "packageManager"/"devEngines.packageManager". Use --package-manager to override.
777
757
 
778
758
  Interactive prompts (when no --yes/flag provided):
779
- Single-choice: ↑/↓ move, Enter select, 1-9 pick by number (0 = 10th).
780
- Multi-choice: ↑/↓ move, Space toggle, a = all, n = none, Enter confirm, 1-9 toggle by number.
759
+ Single-choice (framework, template, etc.): ↑/↓ move, Enter select.
760
+ Multi-choice (component selection only): ↑/↓ move, Space toggle, a = all, n = none, Enter confirm, 1-9 toggle by number (0 = 10th).
781
761
  Ctrl+C to exit.
782
762
 
783
763
  Config:
@@ -1507,6 +1487,22 @@ async function cmdInit(argv) {
1507
1487
  logAddedDeps(selectedComponents, componentsToCopy, framework);
1508
1488
  }
1509
1489
 
1490
+ // Astro layout: inject Navbar and Settings when those components are selected so the settings menu works.
1491
+ if ((framework === 'astro') && (useHandpickAstro || useAstroBase)) {
1492
+ const hasNavbar = componentsToCopy.includes('Navbar');
1493
+ const hasSettings = componentsToCopy.includes('Settings');
1494
+ const layoutImports = [];
1495
+ if (hasNavbar) layoutImports.push("import Navbar from '../components/rizzo/Navbar.astro';");
1496
+ if (hasSettings) layoutImports.push("import Settings from '../components/rizzo/Settings.astro';");
1497
+ replacements['{{RIZZO_LAYOUT_IMPORTS}}'] = layoutImports.length ? '\n' + layoutImports.join('\n') + '\n' : '\n';
1498
+ replacements['{{RIZZO_LAYOUT_BODY_TOP}}'] = hasNavbar ? '\n <Navbar />' : '';
1499
+ replacements['{{RIZZO_LAYOUT_BODY_BOTTOM}}'] = hasSettings ? '\n <Settings />' : '';
1500
+ } else {
1501
+ replacements['{{RIZZO_LAYOUT_IMPORTS}}'] = '\n';
1502
+ replacements['{{RIZZO_LAYOUT_BODY_TOP}}'] = '';
1503
+ replacements['{{RIZZO_LAYOUT_BODY_BOTTOM}}'] = '';
1504
+ }
1505
+
1510
1506
  let cssTarget;
1511
1507
  let indexPath;
1512
1508
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rizzo-css",
3
- "version": "0.0.24",
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",
@@ -140,7 +140,7 @@ const { open = false } = Astro.props;
140
140
  </div>
141
141
 
142
142
  <script>
143
- (function initSettings() {
143
+ function initSettings() {
144
144
  const settings = document.querySelector('[data-settings]');
145
145
  if (!settings) return;
146
146
 
@@ -378,5 +378,10 @@ const { open = false } = Astro.props;
378
378
 
379
379
  // Expose open function globally
380
380
  window.openSettings = openSettings;
381
- })();
381
+ }
382
+ if (document.readyState === 'loading') {
383
+ document.addEventListener('DOMContentLoaded', initSettings);
384
+ } else {
385
+ initSettings();
386
+ }
382
387
  </script>
@@ -183,7 +183,7 @@ const InitialIcon = initialTheme ? initialTheme.icon : null;
183
183
  THEME_SYSTEM,
184
184
  } from '../utils/theme';
185
185
 
186
- (function initThemeSwitcher() {
186
+ function initThemeSwitcher() {
187
187
  const getIconSVG = (themeValue: string) => {
188
188
  const svgMap: Record<string, string> = {
189
189
  'system': '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" /><circle cx="12" cy="12" r="3" /></svg>',
@@ -500,5 +500,10 @@ const InitialIcon = initialTheme ? initialTheme.icon : null;
500
500
  updateAllSwitchers();
501
501
  }
502
502
  });
503
- })();
503
+ }
504
+ if (document.readyState === 'loading') {
505
+ document.addEventListener('DOMContentLoaded', initThemeSwitcher);
506
+ } else {
507
+ initThemeSwitcher();
508
+ }
504
509
  </script>
@@ -4,6 +4,7 @@
4
4
  const DATA_THEME = '{{DATA_THEME}}';
5
5
  /** @type {{ title?: string }} */
6
6
  const { title = '{{TITLE}}' } = Astro.props;
7
+ {{RIZZO_LAYOUT_IMPORTS}}
7
8
  ---
8
9
  <!doctype html>
9
10
  <html lang="en" data-theme={DATA_THEME}>
@@ -19,8 +20,10 @@ const { title = '{{TITLE}}' } = Astro.props;
19
20
  </head>
20
21
  <body>
21
22
  <a href="#main-content" class="skip-link">Skip to main content</a>
23
+ {{RIZZO_LAYOUT_BODY_TOP}}
22
24
  <main id="main-content">
23
25
  <slot />
24
26
  </main>
27
+ {{RIZZO_LAYOUT_BODY_BOTTOM}}
25
28
  </body>
26
29
  </html>
@@ -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.24`, 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