File size: 8,062 Bytes
15ff349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e74c9bf
 
 
 
15ff349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8733da
 
 
 
 
 
 
 
 
 
 
 
e74c9bf
 
 
 
 
 
 
15ff349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e74c9bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15ff349
 
e74c9bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15ff349
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
"""The Atlas's bridge vocabulary and its own CSS.

Everything shared with the other Spaces — the sidebar, the palette, the
dialogs, the design system's stylesheets, the click bridge mechanism — comes
from `bit_ui`. This module is the thin Atlas-specific layer on top: the actions
this Space accepts, and the CSS for the parts of the design only this Space
has.
"""

from __future__ import annotations

from bit_ui import bridge, theme

# Actions this Space accepts, on top of the ones bit-ui's own chrome emits.
# An action off this list is dropped by the bridge, so a hand-crafted click
# cannot reach a code path the UI does not offer.
ATLAS_KEYS = frozenset({
    "task",         # toggle a task filter chip
    "asset",        # toggle an asset-class filter chip
    "lic",          # toggle a license-bucket filter row
    "verified",     # toggle "verified by Bit Trading"
    "maintained",   # toggle "maintained only" -- the graveyard switch
    "haseval",      # toggle "has evaluation"
    "hasdata",      # toggle "has documented training data"
    "sort",         # choose a sort order
    "clear",        # clear every filter
    "graveyard",    # show unmaintained models
    "open",         # open a model's detail drawer
    "close",        # close the drawer
    "suggest",      # submit a model suggestion
    "q",            # the search box (arrives live as q=<text>)
    "suggestbox",   # the suggestion input (arrives as suggestbox=<text>)
})

# `sidebar` is deliberately absent: collapsing is a client-side attribute flip
# in bit_ui.bridge, not a server action. Re-adding it would put a 1.16 MB
# re-render behind a purely visual toggle.
ALLOWED_KEYS = (bridge.SHARED_KEYS - {"sidebar"}) | ATLAS_KEYS

emit = bridge.make_emitter(ALLOWED_KEYS)


def parse_action(raw):
    return bridge.parse_action(raw, ALLOWED_KEYS)


# --------------------------------------------------------------------------
# Atlas-only CSS
# --------------------------------------------------------------------------
#
# Deliberately short. The design expresses almost everything as inline styles
# on its own elements, and the shared hover/scroll/animation rules live in
# bit_ui.theme. What is left is what only this Space has.

ATLAS_CSS = """
/* The page root. Was inline on the div; here so `.bit-atlas` is a real hook
   for Space-specific overrides rather than a bare marker class.
   Deliberately no min-height in vh -- see bit_ui.theme. */
.bit-atlas {
  background: var(--bg-canvas);
  color: var(--text-primary);
  display: flex;
  align-items: stretch;
  font-family: var(--font-body);
  font-size: var(--text-base);
}

/* The header sticks under nothing, so top:0; the rail is z-index 30 and wins
   where they meet. A solid background matters: rows scroll underneath it. */
.bit-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg-panel);
}

/* The model table scrolls horizontally inside its own panel rather than
   making the page scroll sideways. */
.bit-table-scroll { overflow-x: auto; }

/* Zones stack below the design's own breakpoint. */
@media (max-width: 1280px) {
  .bit-rail, .bit-rail-right {
    width: 100% !important; flex: 1 1 100% !important; position: static !important;
  }
  .bit-zones { flex-wrap: wrap !important; }
}
@media (max-width: 900px) {
  .bit-foot-grid { grid-template-columns: 1fr !important; }
}

/* ------------------------------------------------------------------ *
 * Model table rows.
 *
 * These are classes rather than inline styles for one reason: the row is
 * the only markup that repeats 300 times. The design's inline styles came
 * to 2,644 characters per row -- ~793 KB of identical repetition per
 * render, and 95% of the whole page payload. Every Gradio action re-sends
 * the page, so that weight was paid on every filter, sort and click.
 *
 * The VALUES below are the design's, unchanged. Only where they live has
 * moved. Everything that varies per row is an enumerable variant
 * (verified / selected / licence bucket / age band / trend direction), so
 * no row needs an inline style at all.
 * ------------------------------------------------------------------ */

.bit-row {
  display: grid;
  grid-template-columns: minmax(230px,2.4fr) 104px 92px 148px 60px 116px 104px 112px;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  border-left: 2px solid transparent;
  background: transparent;
  cursor: pointer;
}
.bit-row:hover { background: var(--bg-raised); }
.bit-row-verified { border-left-color: var(--accent-amber); }
.bit-row-selected { background: var(--bg-raised); }
.bit-row:focus-visible { outline: 2px solid var(--accent-amber);
                         outline-offset: -2px; }

.bit-cell { padding: 6px 8px; border-right: 1px solid var(--border-subtle);
            min-width: 0; }
.bit-cell-end { border-right: none; }
.bit-cell-r { text-align: right; }

.bit-model { display: flex; align-items: center; gap: 8px; }
.bit-avatar {
  flex: 0 0 auto; width: 20px; height: 20px; display: flex;
  align-items: center; justify-content: center; font-size: 9px;
  background: var(--stone-700); color: var(--text-secondary);
}
.bit-row-verified .bit-avatar { background: var(--accent-amber);
                                color: var(--stone-950); }
.bit-model-text { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.bit-id { font-size: var(--text-xs); color: var(--text-primary);
          white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bit-sub { font-size: var(--text-2xs); color: var(--text-tertiary);
           white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bit-tag {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 5px;
  border: 1px solid var(--border-default); color: var(--text-secondary);
  font-family: var(--font-mono); font-size: var(--text-2xs);
  white-space: nowrap; max-width: 100%; overflow: hidden;
}
.bit-tag-asset { border-color: var(--border-subtle); background: var(--bg-raised); }
.bit-tag-lic-permissive { border-color: var(--accent-moss-dim);
                          color: var(--accent-moss-strong); }
.bit-tag-lic-restricted { border-color: var(--accent-amber-dim);
                          color: var(--accent-amber-strong); }
.bit-tag-lic-none { border-color: var(--mute-red); color: var(--mute-red); }

.bit-dl { display: flex; align-items: center; gap: 7px;
          justify-content: flex-end; }
.bit-num { font-size: var(--text-xs); color: var(--text-primary);
           white-space: nowrap; }
.bit-likes { font-size: var(--text-xs); color: var(--text-secondary); }
.bit-spark { flex: 0 0 auto; }
.bit-spark-up path { stroke: var(--fin-up); }
.bit-spark-down path { stroke: var(--fin-down); }
.bit-nodata { font-size: var(--text-2xs); color: var(--text-tertiary);
              width: 44px; text-align: center; flex: 0 0 auto; }

.bit-agecell { display: flex; align-items: center; gap: 5px; }
.bit-age { font-size: var(--text-xs); white-space: nowrap; }
.bit-age-glyph { font-size: var(--text-2xs); }
.bit-age-fresh, .bit-age-fresh .bit-age { color: var(--fin-up); }
.bit-age-warn,  .bit-age-warn .bit-age  { color: var(--accent-amber-strong); }
.bit-age-stale, .bit-age-stale .bit-age { color: var(--fin-down); }
.bit-age-none,  .bit-age-none .bit-age  { color: var(--text-tertiary); }

.bit-badges { display: flex; align-items: center; gap: 4px; }
.bit-badge {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 4px;
  border: 1px solid var(--border-default); background: transparent;
  color: var(--text-secondary); font-family: var(--font-mono);
  font-size: var(--text-2xs); white-space: nowrap;
}
.bit-badge-verified { border-color: var(--accent-amber);
                      background: var(--accent-amber-dim);
                      color: var(--text-primary); }
.bit-badge-flag { border-color: var(--accent-amber-dim);
                  color: var(--accent-amber-strong); }
.bit-badge-unclear { color: var(--text-tertiary); }
"""


def full_css() -> str:
    return theme.full_css(ATLAS_CSS)