Spaces:
Sleeping
Sleeping
Update utils/ui.py
Browse files- utils/ui.py +153 -47
utils/ui.py
CHANGED
|
@@ -25,6 +25,77 @@ BASE_CSS = f"""<style>
|
|
| 25 |
--radius-sm:8px;
|
| 26 |
}}
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
/* βββ NUCLEAR CHROME REMOVAL βββ */
|
| 29 |
#MainMenu,footer,header,
|
| 30 |
[data-testid="stToolbar"],
|
|
@@ -51,17 +122,12 @@ button[kind="header"] {{
|
|
| 51 |
/* βββ FULL SIZE APP βββ */
|
| 52 |
html, body {{
|
| 53 |
width:100%!important;
|
| 54 |
-
height:100%!important;
|
| 55 |
-
overflow:auto!important;
|
| 56 |
background:var(--bg)!important;
|
| 57 |
color:var(--text)!important;
|
| 58 |
font-family:'DM Sans',sans-serif!important;
|
| 59 |
-
margin:0!important;
|
| 60 |
-
padding:0!important;
|
| 61 |
}}
|
| 62 |
|
| 63 |
-
.stApp
|
| 64 |
-
[data-testid="stAppViewContainer"] {{
|
| 65 |
background:var(--bg)!important;
|
| 66 |
color:var(--text)!important;
|
| 67 |
font-family:'DM Sans',sans-serif!important;
|
|
@@ -70,11 +136,6 @@ html, body {{
|
|
| 70 |
}}
|
| 71 |
|
| 72 |
/* Remove ALL padding from Streamlit wrapper layers */
|
| 73 |
-
[data-testid="stAppViewContainer"] > section {{
|
| 74 |
-
padding-top:0!important;
|
| 75 |
-
width:100%!important;
|
| 76 |
-
}}
|
| 77 |
-
|
| 78 |
[data-testid="stAppViewContainer"] > section > div.block-container {{
|
| 79 |
max-width:1160px!important;
|
| 80 |
width:100%!important;
|
|
@@ -236,45 +297,91 @@ hr {{ border-color:var(--border)!important; margin:20px 0!important; }}
|
|
| 236 |
}}
|
| 237 |
</style>"""
|
| 238 |
|
| 239 |
-
# JS that runs once after page load to nuke any chrome that CSS missed
|
| 240 |
-
HIDE_CHROME_JS = """
|
| 241 |
-
<script>
|
| 242 |
-
(function() {
|
| 243 |
-
var HIDE = [
|
| 244 |
-
'#MainMenu','header','footer',
|
| 245 |
-
'[data-testid="stHeader"]',
|
| 246 |
-
'[data-testid="stToolbar"]',
|
| 247 |
-
'[data-testid="stToolbarActions"]',
|
| 248 |
-
'[data-testid="stDecoration"]',
|
| 249 |
-
'[data-testid="stStatusWidget"]',
|
| 250 |
-
'[data-testid="collapsedControl"]',
|
| 251 |
-
'[data-testid="baseButton-header"]',
|
| 252 |
-
'.stDeployButton',
|
| 253 |
-
'button[kind="header"]'
|
| 254 |
-
];
|
| 255 |
-
function nuke() {
|
| 256 |
-
HIDE.forEach(function(sel) {
|
| 257 |
-
document.querySelectorAll(sel).forEach(function(el) {
|
| 258 |
-
el.style.cssText = 'display:none!important;visibility:hidden!important;' +
|
| 259 |
-
'opacity:0!important;height:0!important;width:0!important;' +
|
| 260 |
-
'position:absolute!important;pointer-events:none!important;overflow:hidden!important;';
|
| 261 |
-
});
|
| 262 |
-
});
|
| 263 |
-
}
|
| 264 |
-
nuke();
|
| 265 |
-
new MutationObserver(nuke).observe(document.documentElement,
|
| 266 |
-
{childList:true, subtree:true, attributes:false});
|
| 267 |
-
})();
|
| 268 |
-
</script>
|
| 269 |
-
"""
|
| 270 |
-
|
| 271 |
-
|
| 272 |
def inject_css():
|
| 273 |
import streamlit as st
|
|
|
|
|
|
|
| 274 |
st.markdown(BASE_CSS, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
st.markdown(HIDE_CHROME_JS, unsafe_allow_html=True)
|
| 276 |
|
| 277 |
-
|
| 278 |
def stat_card(icon, label, value, sub="", accent="var(--accent)"):
|
| 279 |
return f"""
|
| 280 |
<div style="background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);
|
|
@@ -289,7 +396,6 @@ def stat_card(icon, label, value, sub="", accent="var(--accent)"):
|
|
| 289 |
{f'<div style="font-size:0.72rem;color:var(--muted2);margin-top:3px">{sub}</div>' if sub else ''}
|
| 290 |
</div>"""
|
| 291 |
|
| 292 |
-
|
| 293 |
def section_header(title, sub=""):
|
| 294 |
return f"""
|
| 295 |
<div style="display:flex;align-items:center;gap:12px;margin:28px 0 16px">
|
|
@@ -300,4 +406,4 @@ def section_header(title, sub=""):
|
|
| 300 |
color:var(--text)">{title}</div>
|
| 301 |
{f'<div style="font-size:0.75rem;color:var(--muted);margin-top:1px">{sub}</div>' if sub else ''}
|
| 302 |
</div>
|
| 303 |
-
</div>"""
|
|
|
|
| 25 |
--radius-sm:8px;
|
| 26 |
}}
|
| 27 |
|
| 28 |
+
/* βββ FIXED SCROLLING BEHAVIOR βββ */
|
| 29 |
+
html {{
|
| 30 |
+
scroll-behavior: auto !important;
|
| 31 |
+
overflow-y: scroll !important;
|
| 32 |
+
overflow-x: hidden !important;
|
| 33 |
+
height: 100% !important;
|
| 34 |
+
}}
|
| 35 |
+
|
| 36 |
+
body {{
|
| 37 |
+
overflow-y: scroll !important;
|
| 38 |
+
overflow-x: hidden !important;
|
| 39 |
+
position: relative !important;
|
| 40 |
+
min-height: 100vh !important;
|
| 41 |
+
height: 100% !important;
|
| 42 |
+
margin: 0 !important;
|
| 43 |
+
padding: 0 !important;
|
| 44 |
+
}}
|
| 45 |
+
|
| 46 |
+
/* Prevent any overflow shifts */
|
| 47 |
+
[data-testid="stAppViewContainer"] {{
|
| 48 |
+
overflow: hidden !important;
|
| 49 |
+
position: fixed !important;
|
| 50 |
+
top: 0 !important;
|
| 51 |
+
left: 0 !important;
|
| 52 |
+
right: 0 !important;
|
| 53 |
+
bottom: 0 !important;
|
| 54 |
+
background: var(--bg) !important;
|
| 55 |
+
}}
|
| 56 |
+
|
| 57 |
+
[data-testid="stAppViewContainer"] > section {{
|
| 58 |
+
height: 100vh !important;
|
| 59 |
+
overflow-y: auto !important;
|
| 60 |
+
overflow-x: hidden !important;
|
| 61 |
+
padding-top: 0 !important;
|
| 62 |
+
}}
|
| 63 |
+
|
| 64 |
+
/* Consistent scrollbar to prevent width shifts */
|
| 65 |
+
::-webkit-scrollbar {{
|
| 66 |
+
width: 8px !important;
|
| 67 |
+
background: #0a0a16 !important;
|
| 68 |
+
}}
|
| 69 |
+
|
| 70 |
+
::-webkit-scrollbar-thumb {{
|
| 71 |
+
background: #6366f1 !important;
|
| 72 |
+
border-radius: 4px !important;
|
| 73 |
+
}}
|
| 74 |
+
|
| 75 |
+
::-webkit-scrollbar-track {{
|
| 76 |
+
background: #0a0a16 !important;
|
| 77 |
+
}}
|
| 78 |
+
|
| 79 |
+
/* Prevent focus outline from causing shifts */
|
| 80 |
+
*:focus {{
|
| 81 |
+
outline: none !important;
|
| 82 |
+
}}
|
| 83 |
+
|
| 84 |
+
/* Stabilize input fields */
|
| 85 |
+
input, textarea, select, button {{
|
| 86 |
+
scroll-margin: 0 !important;
|
| 87 |
+
scroll-snap-margin: 0 !important;
|
| 88 |
+
}}
|
| 89 |
+
|
| 90 |
+
/* Prevent any transform animations that might cause shifts */
|
| 91 |
+
* {{
|
| 92 |
+
-webkit-transform: translateZ(0) !important;
|
| 93 |
+
transform: translateZ(0) !important;
|
| 94 |
+
-webkit-backface-visibility: hidden !important;
|
| 95 |
+
backface-visibility: hidden !important;
|
| 96 |
+
-webkit-font-smoothing: antialiased !important;
|
| 97 |
+
}}
|
| 98 |
+
|
| 99 |
/* βββ NUCLEAR CHROME REMOVAL βββ */
|
| 100 |
#MainMenu,footer,header,
|
| 101 |
[data-testid="stToolbar"],
|
|
|
|
| 122 |
/* βββ FULL SIZE APP βββ */
|
| 123 |
html, body {{
|
| 124 |
width:100%!important;
|
|
|
|
|
|
|
| 125 |
background:var(--bg)!important;
|
| 126 |
color:var(--text)!important;
|
| 127 |
font-family:'DM Sans',sans-serif!important;
|
|
|
|
|
|
|
| 128 |
}}
|
| 129 |
|
| 130 |
+
.stApp {{
|
|
|
|
| 131 |
background:var(--bg)!important;
|
| 132 |
color:var(--text)!important;
|
| 133 |
font-family:'DM Sans',sans-serif!important;
|
|
|
|
| 136 |
}}
|
| 137 |
|
| 138 |
/* Remove ALL padding from Streamlit wrapper layers */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
[data-testid="stAppViewContainer"] > section > div.block-container {{
|
| 140 |
max-width:1160px!important;
|
| 141 |
width:100%!important;
|
|
|
|
| 297 |
}}
|
| 298 |
</style>"""
|
| 299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
def inject_css():
|
| 301 |
import streamlit as st
|
| 302 |
+
|
| 303 |
+
# Inject the base CSS
|
| 304 |
st.markdown(BASE_CSS, unsafe_allow_html=True)
|
| 305 |
+
|
| 306 |
+
# Enhanced JavaScript to prevent keyboard scrolling and nuke chrome
|
| 307 |
+
HIDE_CHROME_JS = """
|
| 308 |
+
<script>
|
| 309 |
+
(function() {
|
| 310 |
+
// Prevent keyboard from triggering scroll
|
| 311 |
+
document.addEventListener('keydown', function(e) {
|
| 312 |
+
// Prevent default scrolling behavior for arrow keys, page up/down, home/end, space
|
| 313 |
+
const keysToPrevent = [
|
| 314 |
+
'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight',
|
| 315 |
+
'PageUp', 'PageDown', 'Home', 'End', ' ',
|
| 316 |
+
'Space', 'Spacebar'
|
| 317 |
+
];
|
| 318 |
+
|
| 319 |
+
if (keysToPrevent.includes(e.key) || e.key === ' ') {
|
| 320 |
+
e.preventDefault();
|
| 321 |
+
return false;
|
| 322 |
+
}
|
| 323 |
+
}, false);
|
| 324 |
+
|
| 325 |
+
// Also prevent scroll restoration on page load
|
| 326 |
+
if ('scrollRestoration' in history) {
|
| 327 |
+
history.scrollRestoration = 'manual';
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
// Force scroll to top on page load and prevent any auto-scrolling
|
| 331 |
+
window.scrollTo(0, 0);
|
| 332 |
+
|
| 333 |
+
// Disable any scroll anchoring behavior
|
| 334 |
+
if (document.body && typeof document.body.style !== 'undefined') {
|
| 335 |
+
document.body.style.overflowAnchor = 'none';
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
// Hide all Streamlit chrome elements
|
| 339 |
+
var HIDE = [
|
| 340 |
+
'#MainMenu','header','footer',
|
| 341 |
+
'[data-testid="stHeader"]',
|
| 342 |
+
'[data-testid="stToolbar"]',
|
| 343 |
+
'[data-testid="stToolbarActions"]',
|
| 344 |
+
'[data-testid="stDecoration"]',
|
| 345 |
+
'[data-testid="stStatusWidget"]',
|
| 346 |
+
'[data-testid="collapsedControl"]',
|
| 347 |
+
'[data-testid="baseButton-header"]',
|
| 348 |
+
'.stDeployButton',
|
| 349 |
+
'button[kind="header"]',
|
| 350 |
+
'[data-testid="stSidebarNav"]'
|
| 351 |
+
];
|
| 352 |
+
|
| 353 |
+
function nuke() {
|
| 354 |
+
HIDE.forEach(function(sel) {
|
| 355 |
+
document.querySelectorAll(sel).forEach(function(el) {
|
| 356 |
+
el.style.cssText = 'display:none!important;visibility:hidden!important;' +
|
| 357 |
+
'opacity:0!important;height:0!important;width:0!important;' +
|
| 358 |
+
'position:absolute!important;pointer-events:none!important;overflow:hidden!important;';
|
| 359 |
+
});
|
| 360 |
+
});
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
nuke();
|
| 364 |
+
new MutationObserver(nuke).observe(document.documentElement,
|
| 365 |
+
{childList: true, subtree: true, attributes: false});
|
| 366 |
+
|
| 367 |
+
// Additional fix: prevent any element from receiving focus that might cause scroll
|
| 368 |
+
document.addEventListener('focusin', function(e) {
|
| 369 |
+
// Don't prevent default focus behavior, just ensure no scroll happens
|
| 370 |
+
if (e.target) {
|
| 371 |
+
// Temporarily disable scroll restoration
|
| 372 |
+
var currentScroll = window.scrollY;
|
| 373 |
+
setTimeout(function() {
|
| 374 |
+
window.scrollTo(0, currentScroll);
|
| 375 |
+
}, 0);
|
| 376 |
+
}
|
| 377 |
+
}, false);
|
| 378 |
+
|
| 379 |
+
})();
|
| 380 |
+
</script>
|
| 381 |
+
"""
|
| 382 |
+
|
| 383 |
st.markdown(HIDE_CHROME_JS, unsafe_allow_html=True)
|
| 384 |
|
|
|
|
| 385 |
def stat_card(icon, label, value, sub="", accent="var(--accent)"):
|
| 386 |
return f"""
|
| 387 |
<div style="background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);
|
|
|
|
| 396 |
{f'<div style="font-size:0.72rem;color:var(--muted2);margin-top:3px">{sub}</div>' if sub else ''}
|
| 397 |
</div>"""
|
| 398 |
|
|
|
|
| 399 |
def section_header(title, sub=""):
|
| 400 |
return f"""
|
| 401 |
<div style="display:flex;align-items:center;gap:12px;margin:28px 0 16px">
|
|
|
|
| 406 |
color:var(--text)">{title}</div>
|
| 407 |
{f'<div style="font-size:0.75rem;color:var(--muted);margin-top:1px">{sub}</div>' if sub else ''}
|
| 408 |
</div>
|
| 409 |
+
</div>"""
|