Coverage for src / lexigram / admin / theme / tailwind.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-13 22:14 +0800

1from __future__ import annotations 

2 

3"""Shared Tailwind CSS runtime configuration for admin layouts. 

4 

5Maps the ShadCN-compatible CSS custom properties (rendered by 

6:func:`lexigram.ui.styles.design_tokens.render_all_tokens`) into Tailwind 

7utility classes (``bg-card``, ``text-muted-foreground``, ``border-border``, 

8``bg-primary/20``, ``text-success``, ...) and bootstraps the ``dark`` class 

9on ``<html>`` before Alpine.js loads. 

10""" 

11 

12TAILWIND_THEME_CONFIG: str = """<script> 

13tailwind.config = { 

14 darkMode: 'class', 

15 theme: { 

16 extend: { 

17 colors: { 

18 background: 'var(--background)', 

19 foreground: 'var(--foreground)', 

20 card: { DEFAULT: 'var(--card)', foreground: 'var(--card-foreground)' }, 

21 popover: { DEFAULT: 'var(--popover)', foreground: 'var(--popover-foreground)' }, 

22 primary: { DEFAULT: 'var(--primary)', foreground: 'var(--primary-foreground)' }, 

23 secondary: { DEFAULT: 'var(--secondary)', foreground: 'var(--secondary-foreground)' }, 

24 muted: { DEFAULT: 'var(--muted)', foreground: 'var(--muted-foreground)' }, 

25 accent: { DEFAULT: 'var(--accent)', foreground: 'var(--accent-foreground)' }, 

26 destructive: { DEFAULT: 'var(--destructive)', foreground: 'var(--destructive-foreground)' }, 

27 border: 'var(--border)', 

28 input: 'var(--input)', 

29 ring: 'var(--ring)', 

30 success: { DEFAULT: 'var(--color-success)', foreground: 'var(--color-success-foreground)' }, 

31 warning: { DEFAULT: 'var(--color-warning)', foreground: 'var(--color-warning-foreground)' }, 

32 info: { DEFAULT: 'var(--color-info)', foreground: 'var(--color-info-foreground)' }, 

33 'chart-1': 'var(--chart-1)', 

34 'chart-2': 'var(--chart-2)', 

35 'chart-3': 'var(--chart-3)', 

36 'chart-4': 'var(--chart-4)', 

37 'chart-5': 'var(--chart-5)' 

38 }, 

39 borderRadius: { 

40 lg: 'var(--radius)', 

41 md: 'calc(var(--radius) - 2px)', 

42 sm: 'calc(var(--radius) - 4px)' 

43 } 

44 } 

45 } 

46} 

47</script>""" 

48 

49DARK_BOOTSTRAP_SCRIPT: str = """<script> 

50(function () { 

51 var stored = localStorage.getItem('darkMode'); 

52 var dark = stored !== null ? stored === 'true' : window.matchMedia('(prefers-color-scheme: dark)').matches; 

53 if (dark) document.documentElement.classList.add('dark'); 

54})(); 

55</script>""" 

56 

57THEME_BRIDGE_SCRIPT: str = """<script> 

58window.toggleTheme = function () { 

59 var dark = !document.documentElement.classList.contains('dark'); 

60 document.documentElement.classList.toggle('dark', dark); 

61 localStorage.setItem('darkMode', String(dark)); 

62 window.dispatchEvent(new CustomEvent('darkmode-change', { detail: { dark: dark } })); 

63}; 

64</script>"""