S-4-G-4-R commited on
Commit
d7dd595
·
verified ·
1 Parent(s): 20b15f3

Update ui/theme.py

Browse files
Files changed (1) hide show
  1. ui/theme.py +33 -6
ui/theme.py CHANGED
@@ -51,14 +51,19 @@ NOVA_THEME = gr.themes.Base(
51
  input_border_color_dark="rgba(255,255,255,0.08)",
52
  )
53
 
54
- # Gradio reads ?__theme= before our CSS lands; the palette is dark-only, so pin it.
 
 
 
 
 
 
 
55
  FORCE_DARK = """
56
  function() {
57
- const url = new URL(window.location);
58
- if (url.searchParams.get('__theme') !== 'dark') {
59
- url.searchParams.set('__theme', 'dark');
60
- window.location.replace(url.href);
61
- }
62
  }
63
  """
64
 
@@ -74,6 +79,28 @@ CSS = """
74
  --nova-accent-2: #22d3ee;
75
  }
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  /* ---- page shell: cosmic gradient + a slow drifting aurora ---- */
78
  gradio-app, .gradio-container {
79
  background:
 
51
  input_border_color_dark="rgba(255,255,255,0.08)",
52
  )
53
 
54
+ # Put Gradio into its dark mode WITHOUT reloading the page.
55
+ #
56
+ # The previous version redirected to ?__theme=dark. That's a page reload racing
57
+ # SSR: sometimes the `.dark` class landed (dark, correct), sometimes it didn't
58
+ # (light — near-black text on our dark ground, invisible). Two devices, two race
59
+ # outcomes, one "why does it look different?" bug. Adding the class directly on
60
+ # load is deterministic and flash-free. The CSS below is the real backstop, so
61
+ # even if this never ran the page would still be readable.
62
  FORCE_DARK = """
63
  function() {
64
+ const mark = (el) => el && el.classList.add('dark');
65
+ mark(document.documentElement);
66
+ mark(document.querySelector('gradio-app'));
 
 
67
  }
68
  """
69
 
 
79
  --nova-accent-2: #22d3ee;
80
  }
81
 
82
+ /* ---- pin Gradio's own theme variables to NOVA's dark palette ----
83
+ Gradio flips these between light and dark via a `.dark` class on its root.
84
+ In a light-mode browser that class can be absent, and then Gradio resolves
85
+ --body-text-color to near-black and --background-fill-primary to literal
86
+ `white` -- unreadable on our dark ground (this was THE light/dark-browser
87
+ bug). NOVA is deliberately a single dark console, so force the handful of
88
+ Gradio variables that would otherwise leak light. `!important` on a custom
89
+ property wins the cascade no matter the class or the injection order, so the
90
+ look no longer depends on the `.dark` class landing at all. */
91
+ :root {
92
+ --body-text-color: #e6e9f2 !important;
93
+ --body-text-color-subdued: #8b93a7 !important;
94
+ --background-fill-primary: #080b16 !important;
95
+ --background-fill-secondary: #0d1322 !important;
96
+ --border-color-primary: rgba(255,255,255,0.08) !important;
97
+ --input-placeholder-color: #8b93a7 !important;
98
+ --code-background-fill: #0d1322 !important;
99
+ --table-odd-background-fill: #0d1322 !important;
100
+ --table-even-background-fill: #111828 !important;
101
+ --table-border-color: rgba(255,255,255,0.08) !important;
102
+ }
103
+
104
  /* ---- page shell: cosmic gradient + a slow drifting aurora ---- */
105
  gradio-app, .gradio-container {
106
  background: