Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
style.py · 29.5 KB · 571 lines
1"""The design system, served as one themeable stylesheet object.
2
3site_style is the single source of truth for DBBASIC's visual language.
4It emits two things at /style:
5
6 1. a `:root` block of semantic token ROLES (surface, text, accent,
7 positive/warning/danger, spacing, type) — a theme is just a set of
8 values for these roles, nothing more;
9 2. the shared component primitives (layout, cards, tables, forms,
10 toolbars, filters, search, buttons, badges, states) written against
11 those roles, so every page and generated UI looks consistent.
12
13Because a theme is data, changing the look never touches a page. The
14active theme lives in this object's state; switching it (or installing a
15theme package that sets custom tokens) reskins the whole instance on the
16next request, versioned and reversible like any object.
17
18 GET /style -> the active theme's CSS (public)
19 GET /style?info=true -> {active, available, tokens} JSON (for pickers)
20 POST /style {theme|tokens} -> switch theme (admin session only)
21"""
22
23import json
24
25# --- Themes: each is a set of values for the same token roles ----------------
26# The base theme is the DBBASIC identity: a warm dark, per the earth-theme
27# rule "warm, not cold blue-black", with a terracotta/ember accent.
28
29BASE = {
30 "color-scheme": "dark",
31 "bg": "#17140f",
32 "panel": "#201c16",
33 "panel-2": "#28231b",
34 "line": "#332c22",
35 "text": "#ece7df",
36 "muted": "#a89e90",
37 "accent": "#d4956a",
38 "accent-strong": "#e0a878",
39 "accent-ink": "#17140f",
40 "positive": "#7fa87f",
41 "warning": "#d8b25e",
42 "danger": "#d98668",
43 "focus": "#e0a87866",
44}
45
46PAPER = {
47 "color-scheme": "light",
48 "bg": "#f3efe8",
49 "panel": "#fbf8f2",
50 "panel-2": "#f0ebe1",
51 "line": "#ddd5c8",
52 "text": "#33291d",
53 "muted": "#6e6355",
54 "accent": "#b8703f",
55 "accent-strong": "#a15f31",
56 "accent-ink": "#fbf8f2",
57 "positive": "#4f7a52",
58 "warning": "#9a7d2e",
59 "danger": "#b5573a",
60 "focus": "#b8703f55",
61}
62
63TERMINAL = {
64 "color-scheme": "dark",
65 "bg": "#08100a",
66 "panel": "#0d1a10",
67 "panel-2": "#12251699",
68 "line": "#1d3a24",
69 "text": "#c8f7d4",
70 "muted": "#6fae82",
71 "accent": "#3ddc84",
72 "accent-strong": "#5cf29c",
73 "accent-ink": "#08100a",
74 "positive": "#3ddc84",
75 "warning": "#e6c84f",
76 "danger": "#ff6b6b",
77 "focus": "#3ddc8455",
78}
79
80MIDNIGHT = {
81 "color-scheme": "dark",
82 "bg": "#0b0b10",
83 "panel": "#17171f",
84 "panel-2": "#1f1f2b",
85 "line": "#2b2b37",
86 "text": "#f4f4f7",
87 "muted": "#a2a2ad",
88 "accent": "#5aa7ff",
89 "accent-strong": "#7ab6ff",
90 "accent-ink": "#0b0b10",
91 "positive": "#52d273",
92 "warning": "#f1b747",
93 "danger": "#ff6b6b",
94 "focus": "#5aa7ff55",
95}
96
97THEMES = {"base": BASE, "midnight": MIDNIGHT, "paper": PAPER, "terminal": TERMINAL}
98
99# Shape, rhythm, and type are theme-independent for now (a theme could
100# override these too by shipping custom tokens).
101STRUCTURE = {
102 "radius-sm": "6px",
103 "radius-md": "8px",
104 "radius-lg": "12px",
105 "gap": "0.75rem",
106 "pad": "1rem",
107 "shadow": "0 1px 3px rgba(0,0,0,0.35)",
108 "font-ui": '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
109 "font-mono": "ui-monospace, SFMono-Regular, Menlo, monospace",
110}
111
112_PRIMITIVES = """
113* { box-sizing: border-box; }
114html { color-scheme: var(--_scheme); }
115body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font-ui); }
116a { color: var(--accent-strong); text-decoration: none; }
117a:hover { text-decoration: underline; }
118h1, h2, h3 { line-height: 1.25; }
119
120.wrap { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
121.wrap.narrow { max-width: 720px; }
122.stack > * + * { margin-top: var(--gap); }
123
124header.app { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1.25rem; }
125header.app h1 { font-size: 1.15rem; margin: 0; }
126header.app .who { margin-left: auto; color: var(--muted); font-size: 0.85rem; }
127
128/* Switchboard tiles */
129.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
130a.tile { display: block; background: var(--panel); border: 1px solid var(--line);
131 border-radius: var(--radius-lg); padding: 1rem 1.1rem; color: var(--text); }
132a.tile:hover { border-color: var(--accent); text-decoration: none; }
133a.tile .name { font-weight: 600; }
134a.tile .desc { color: var(--muted); font-size: 0.82rem; margin-top: 0.25rem; }
135
136/* Cards */
137.cards { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
138.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md);
139 padding: 0.85rem 1rem; word-break: break-word; }
140.card .title, .card .name { font-weight: 600; }
141.card .meta { margin-top: 0.5rem; color: var(--muted); font-size: 0.78rem; }
142.card .meta a { color: var(--accent-strong); }
143
144/* Toolbar: search + filters above a list */
145.toolbar { display: flex; gap: var(--gap); align-items: center; flex-wrap: wrap; margin-bottom: var(--gap); }
146.toolbar .grow { flex: 1; min-width: 12rem; }
147.filters { display: flex; gap: 0.4rem; flex-wrap: wrap; }
148.chip { border: 1px solid var(--line); background: var(--panel); color: var(--muted);
149 border-radius: 999px; padding: 0.2rem 0.7rem; font-size: 0.78rem; cursor: pointer; }
150.chip[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
151
152/* Inputs */
153input, textarea, select { background: var(--bg); color: var(--text); border: 1px solid var(--line);
154 border-radius: var(--radius-sm); padding: 0.45rem 0.6rem; font: inherit; width: 100%; }
155input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent);
156 box-shadow: 0 0 0 3px var(--focus); }
157input.search { background-image: none; }
158[aria-invalid="true"], .invalid { border-color: var(--danger); }
159textarea { min-height: 4rem; resize: vertical; }
160/* Theme every select the same in every browser: without appearance:none,
161 Safari draws its beveled native control (the gradient pill in the form
162 screenshots) while Chrome draws a flat one -- so the same page looked
163 different per browser. Draw our own chevron instead. */
164select { appearance: none; -webkit-appearance: none; -moz-appearance: none;
165 padding-right: 1.9rem;
166 background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%23857a68' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M1 1.5 6 6.5 11 1.5'/></svg>");
167 background-repeat: no-repeat; background-position: right 0.65rem center; }
168
169/* Forms */
170form.stack { display: grid; gap: var(--gap); }
171.field { display: grid; gap: 0.3rem; }
172.field > label { font-size: 0.85rem; color: var(--muted); }
173.field .req { color: var(--danger); }
174.field .help { font-size: 0.78rem; color: var(--muted); }
175.field .err { font-size: 0.8rem; color: var(--danger); min-height: 1rem; }
176/* The generated form was looser than a hand-built one for two reasons:
177 (1) `form.genform.stack` picked up BOTH the grid `gap` and the global
178 `.stack > * + *` margin-top, doubling the space between fields; and
179 (2) every field reserved a blank 1rem error line even with no error.
180 Use grid gap alone, tighten the label->control gap, and collapse the
181 error slot until there's actually a message. Now migrating a bespoke
182 page onto this renderer keeps its form tight. */
183form.genform.stack { gap: 0.85rem; }
184form.genform.stack > * + * { margin-top: 0; }
185.genform .field { gap: 0.25rem; }
186.genform .err { min-height: 0; }
187.genform .err:empty { display: none; }
188
189/* Buttons — intents, not colors */
190.btn { display: inline-flex; align-items: center; gap: 0.4rem; border: 1px solid var(--line);
191 background: var(--panel-2); color: var(--text); border-radius: var(--radius-sm);
192 padding: 0.5rem 1rem; font: inherit; font-weight: 600; cursor: pointer; }
193.btn:hover { border-color: var(--accent); }
194.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
195.btn.danger { color: var(--danger); }
196.btn.ghost { background: transparent; }
197.btn.sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
198.btn:disabled { opacity: 0.5; cursor: not-allowed; }
199
200/* Tables */
201table { width: 100%; border-collapse: collapse; background: var(--panel);
202 border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
203th, td { text-align: left; font-size: 0.85rem; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); }
204th { color: var(--muted); font-weight: 500; }
205th.sortable { cursor: pointer; user-select: none; }
206th.sortable::after { content: " \\2195"; color: var(--muted); opacity: 0.5; }
207th.sortable.asc::after { content: " \\2191"; opacity: 1; }
208th.sortable.desc::after { content: " \\2193"; opacity: 1; }
209tbody tr:hover { background: var(--panel-2); }
210tr:last-child td { border-bottom: 0; }
211td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
212td.muted, .muted { color: var(--muted); }
213
214/* Pagination */
215.pagination { display: flex; gap: 0.4rem; align-items: center; margin-top: var(--gap);
216 color: var(--muted); font-size: 0.82rem; }
217
218/* Badges */
219.badge { display: inline-block; border-radius: 999px; padding: 0.05rem 0.5rem; font-size: 0.72rem;
220 border: 1px solid var(--line); color: var(--muted); }
221.badge.positive { color: var(--positive); border-color: var(--positive); }
222.badge.warning { color: var(--warning); border-color: var(--warning); }
223.badge.danger { color: var(--danger); border-color: var(--danger); }
224.badge.accent { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
225
226/* States: empty / loading / denied / hint / alert */
227.state, .hint { color: var(--muted); background: var(--panel); border: 1px solid var(--line);
228 border-radius: var(--radius-md); padding: 0.9rem 1rem; }
229.state.denied { color: var(--danger); }
230.error { color: var(--danger); font-size: 0.85rem; min-height: 1.2rem; }
231.alert { border-radius: var(--radius-md); padding: 0.7rem 1rem; border: 1px solid var(--line); }
232.alert.danger { color: var(--danger); border-color: var(--danger); }
233.alert.positive { color: var(--positive); border-color: var(--positive); }
234
235footer.app { margin-top: 2.5rem; color: var(--muted); font-size: 0.78rem; }
236
237/* Page head + breadcrumb */
238.breadcrumb { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.6rem; }
239.breadcrumb a { color: var(--accent-strong); }
240.pagehead { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
241.pagehead h1 { margin: 0; font-size: 1.5rem; flex: 1; }
242
243/* Rich list rows (the shared window.dbbasicList renderer) */
244.listrow { display: flex; gap: 0.8rem; align-items: flex-start; background: var(--panel);
245 border: 1px solid var(--line); border-radius: var(--radius-md);
246 padding: 0.85rem 1rem; margin-bottom: 0.6rem; }
247.listrow .av { width: 2rem; height: 2rem; flex: none; border-radius: var(--radius-sm);
248 background: var(--panel-2); color: var(--muted); display: flex; align-items: center;
249 justify-content: center; font-weight: 600; font-size: 0.85rem; text-transform: uppercase; }
250.listrow .body { flex: 1; min-width: 0; }
251.listrow .rowtitle { font-weight: 600; word-break: break-word; }
252.listrow .rowtitle a { color: var(--accent-strong); }
253.listrow .rowsub { color: var(--muted); font-size: 0.82rem; word-break: break-all; margin-top: 0.1rem; }
254.listrow .rowmeta { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin-top: 0.45rem; }
255.listrow .rowmeta .when { color: var(--muted); font-size: 0.75rem; }
256.pill { border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
257 border-radius: 999px; padding: 0.05rem 0.55rem; font-size: 0.72rem; white-space: nowrap; }
258.listrow .rowactions { display: flex; gap: 0.3rem; flex: none; }
259.rowbtn { border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
260 border-radius: var(--radius-sm); padding: 0.25rem 0.5rem; font: inherit; cursor: pointer; line-height: 1; }
261.rowbtn:hover { border-color: var(--accent); color: var(--text); }
262.rowbtn.danger:hover { border-color: var(--danger); color: var(--danger); }
263.listmore { margin-top: 0.5rem; border: 1px solid var(--line); background: var(--panel-2);
264 color: var(--muted); border-radius: var(--radius-sm); padding: 0.4rem 0.8rem;
265 font: inherit; cursor: pointer; width: 100%; }
266.listmore:hover { border-color: var(--accent); color: var(--text); }
267/* table list_mode: a dense, sortable, live table over list_fields. */
268.dtablewrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--line);
269 border-radius: var(--radius-md); background: var(--panel); }
270.dtable { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
271.dtable th { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 2px solid var(--line);
272 color: var(--muted); font-weight: 600; white-space: nowrap; cursor: pointer;
273 user-select: none; position: sticky; top: 0; background: var(--panel); }
274.dtable th:hover { color: var(--text); }
275.dtable td { padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
276.dtable tbody tr:last-child td { border-bottom: none; }
277.dtable tbody tr.clickrow { cursor: pointer; }
278.dtable tbody tr.clickrow:hover { background: var(--panel-2); }
279.dtable td.dtactions, .dtable th.dtactions { text-align: right; white-space: nowrap; width: 1%; }
280.dtable td.dtactions { display: table-cell; }
281.dtable td.dtactions .rowbtn { position: static; }
282/* Comment thread (window.dbbasicThread): the capabilities.comments surface. */
283.thread { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 1rem; }
284.threadhead { font-size: 0.95rem; margin: 0 0 0.75rem; color: var(--muted); }
285.threadlist { display: grid; gap: 0.75rem; margin-bottom: 1rem; }
286.comment { display: flex; gap: 0.7rem; align-items: flex-start; }
287.comment .av { flex: none; width: 1.9rem; height: 1.9rem; border-radius: 999px;
288 background: var(--panel-2); color: var(--muted); display: flex;
289 align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 600; }
290.comment .commentbody { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line);
291 border-radius: var(--radius-md); padding: 0.55rem 0.75rem; }
292.commentmeta { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; }
293.commentwho { font-weight: 600; font-size: 0.85rem; }
294.commentmeta .when { color: var(--muted); font-size: 0.78rem; }
295.commentmeta .rowbtn { margin-left: auto; }
296.commenttext { white-space: pre-wrap; word-break: break-word; font-size: 0.9rem; }
297.threadcompose { display: grid; gap: 0.5rem; }
298.threadcomposeactions { display: flex; gap: 0.6rem; align-items: center; }
299/* Attachments (window.dbbasicAttachments): the capabilities.attachments surface. */
300.attachments { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 1rem; }
301.attachlist { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
302.attachrow { display: flex; gap: 0.7rem; align-items: center; background: var(--panel);
303 border: 1px solid var(--line); border-radius: var(--radius-md); padding: 0.5rem 0.75rem; }
304.attachicon { flex: none; font-size: 1rem; opacity: 0.8; }
305.attachbody { flex: 1; min-width: 0; }
306.attachname { font-weight: 600; font-size: 0.9rem; word-break: break-word; }
307.attachmeta { color: var(--muted); font-size: 0.78rem; margin-top: 0.1rem; }
308.attachactions { flex: none; }
309.attachupload { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
310.attachupload input[type="file"] { width: auto; flex: 1; min-width: 12rem; }
311/* Sharing (window.dbbasicShare): the owner-only capabilities.shareable surface. */
312.share { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: 1rem; }
313.sharelist { display: grid; gap: 0.4rem; margin-bottom: 1rem; }
314.sharerow { display: flex; gap: 0.6rem; align-items: center; background: var(--panel);
315 border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.4rem 0.7rem; }
316.sharewho { font-weight: 600; font-size: 0.88rem; flex: 1; min-width: 0; word-break: break-word; }
317.sharemeta { color: var(--muted); font-size: 0.78rem; }
318.shareadd { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
319.shareadd input { width: auto; flex: 1; min-width: 12rem; }
320.shareadd select { width: auto; }
321
322/* 60: board (kanban / lead-pipeline), tree (self-relation nesting), and
323 calendar (month grid) -- the three schema-driven list_mode renderers in
324 window.dbbasicList (list.py). */
325/* board <-> table mode switcher: a small segmented control above the list. */
326.listmodes { display: inline-flex; gap: 0; border: 1px solid var(--line);
327 border-radius: var(--radius-sm); overflow: hidden; margin-bottom: var(--gap); }
328.listmodes .modebtn { border: none; border-radius: 0; background: var(--panel);
329 color: var(--muted); font: inherit; font-size: 0.85rem;
330 padding: 0.3rem 0.8rem; cursor: pointer; width: auto; }
331.listmodes .modebtn + .modebtn { border-left: 1px solid var(--line); }
332.listmodes .modebtn:hover { color: var(--text); }
333.listmodes .modebtn.active { background: var(--accent); color: var(--accent-ink); }
334/* filter bar: a row of narrowing selects above the list, one per filter_field. */
335.listfilters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: var(--gap); }
336.listfilters .filterctl { width: auto; min-width: 9rem; font-size: 0.85rem; padding-top: 0.3rem; padding-bottom: 0.3rem; }
337.listfilters .filterclear { width: auto; border: 1px solid var(--line); background: var(--panel-2);
338 color: var(--muted); border-radius: var(--radius-sm); font: inherit;
339 font-size: 0.82rem; padding: 0.3rem 0.7rem; cursor: pointer; }
340.listfilters .filterclear:hover { border-color: var(--accent); color: var(--text); }
341.board { display: flex; gap: var(--gap); align-items: flex-start; overflow-x: auto; padding-bottom: 0.25rem; }
342.boardcol { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md);
343 flex: 1 1 200px; min-width: 200px; max-width: 340px; padding: 0.6rem; }
344.boardcolhead { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
345 font-weight: 600; font-size: 0.85rem; margin-bottom: 0.5rem; color: var(--muted); }
346.boardcolcount { background: var(--panel-2); border-radius: 999px; padding: 0.05rem 0.5rem; font-size: 0.72rem; }
347.boardcolbody { display: grid; gap: 0.5rem; min-height: 2rem; }
348.boardcard { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
349 padding: 0.6rem 0.7rem; cursor: grab; word-break: break-word; }
350.boardcard:active { cursor: grabbing; }
351.boardcardtitle { font-weight: 600; font-size: 0.88rem; }
352.boardcardfield { color: var(--muted); font-size: 0.78rem; margin-top: 0.2rem; }
353
354.tree { display: grid; gap: 0.2rem; }
355.treenode { }
356.treerow { display: flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0.2rem;
357 padding-left: calc(var(--depth, 0) * 1.25rem); }
358.treetoggle { background: transparent; border: 0; color: var(--muted); cursor: pointer; font: inherit;
359 width: 1.2rem; text-align: center; }
360.treeleaf { display: inline-block; width: 1.2rem; }
361.treetitle { font-weight: 500; }
362.treekids.collapsed { display: none; }
363
364.calheader { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 0.6rem; }
365.calmonth { font-weight: 600; min-width: 10rem; text-align: center; }
366.calundated { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md);
367 padding: 0.5rem 0.7rem; margin-bottom: 0.6rem; }
368.calundatedlabel { display: block; color: var(--muted); font-size: 0.75rem; margin-bottom: 0.3rem; }
369.calgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line);
370 border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
371.calcell { background: var(--panel); min-height: 5.5rem; padding: 0.3rem; font-size: 0.78rem; }
372.calcell.dim { background: var(--bg); color: var(--muted); }
373.caldate { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.2rem; }
374.calevent { background: var(--panel-2); border-radius: 4px; padding: 0.1rem 0.35rem; margin-top: 0.15rem;
375 font-size: 0.72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
376.state.notice { border-color: var(--warning); color: var(--warning); margin-bottom: var(--gap); }
377
378/* Generated form (window.dbbasicForm) */
379.genform { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md);
380 padding: var(--pad); }
381.formactions { display: flex; gap: 0.6rem; align-items: center; margin-top: 0.5rem; }
382.switch { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.9rem; }
383.switch input { width: auto; }
384
385/* Generated detail (window.dbbasicForm.readOnly / /detail, 59) — global
386 so a detail block renders correctly wherever it's mounted, not just
387 inside view_render's own page shell. */
388.detailcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md);
389 padding: 0.25rem 1rem; }
390.detailrow { display: grid; grid-template-columns: 10rem 1fr; gap: 0.5rem; padding: 0.5rem 0;
391 border-bottom: 1px solid var(--line); }
392.detailrow:last-child { border-bottom: 0; }
393.detaillabel { color: var(--muted); font-size: 0.82rem; }
394.detailvaluewrap, .detailvalue { word-break: break-word; }
395.detailvalue.empty { color: var(--muted); }
396/* Money fields (integer cents rendered in whole units by /form's read-only
397 renderer) -- tabular figures so columns of amounts line up. */
398.detailvalue.money { font-variant-numeric: tabular-nums; }
399/* Read-only textarea fields (notes, articles, any long-form field) and
400 view_render.py's standalone "markdown" block both render through the
401 ONE shared parser at /markdown (window.dbbasicMarkdown) -- real
402 headings, lists, blockquotes, code, tables now, not just paragraphs --
403 so both classes share one rule set here rather than each page
404 restyling the same element shapes on its own. */
405.textareavalue, .markdownblock { line-height: 1.6; }
406.textareavalue a, .markdownblock a { color: var(--accent-strong); }
407.textareavalue h1, .textareavalue h2, .textareavalue h3,
408.textareavalue h4, .textareavalue h5, .textareavalue h6,
409.markdownblock h1, .markdownblock h2, .markdownblock h3,
410.markdownblock h4, .markdownblock h5, .markdownblock h6 {
411 margin: 1rem 0 0.5rem; line-height: 1.3;
412}
413.textareavalue h1:first-child, .markdownblock h1:first-child,
414.textareavalue h2:first-child, .markdownblock h2:first-child,
415.textareavalue h3:first-child, .markdownblock h3:first-child { margin-top: 0; }
416.textareavalue p, .markdownblock p { margin: 0 0 0.85rem; }
417.textareavalue p:last-child, .markdownblock p:last-child { margin-bottom: 0; }
418.textareavalue ul, .textareavalue ol, .markdownblock ul, .markdownblock ol {
419 margin: 0 0 0.85rem; padding-left: 1.5rem;
420}
421.textareavalue li, .markdownblock li { margin: 0.2rem 0; }
422.textareavalue blockquote, .markdownblock blockquote {
423 margin: 0 0 0.85rem; padding: 0.25rem 0 0.25rem 0.85rem;
424 border-left: 3px solid var(--line); color: var(--muted);
425}
426.textareavalue code, .markdownblock code {
427 background: var(--panel-2); color: var(--accent-strong);
428 padding: 1px 5px; border-radius: 3px; font-size: 0.9em;
429}
430.textareavalue pre, .markdownblock pre {
431 background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-md);
432 padding: 0.75rem; overflow-x: auto; margin: 0 0 0.85rem;
433}
434.textareavalue pre code, .markdownblock pre code {
435 background: none; padding: 0; border-radius: 0; font-size: 0.85rem;
436}
437.textareavalue table, .markdownblock table {
438 border-collapse: collapse; width: 100%; margin: 0 0 0.85rem; font-size: 0.9rem;
439}
440.textareavalue th, .textareavalue td, .markdownblock th, .markdownblock td {
441 border: 1px solid var(--line); padding: 0.4rem 0.6rem; text-align: left;
442}
443.textareavalue th, .markdownblock th { background: var(--panel-2); }
444.textareavalue hr, .markdownblock hr { border: none; border-top: 1px solid var(--line); margin: 1rem 0; }
445/* Owner-aware Edit/Delete affordances on a detail block (59 Stage-6
446 extension) -- shown only to the record's owner by window.dbbasicDetail. */
447.detailtools { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
448.detailtools:empty { display: none; }
449
450/* App shell / navigation bar (injected by /nav) */
451body.has-appbar { padding-top: 3rem; }
452.appbar { position: fixed; top: 0; left: 0; right: 0; height: 3rem; display: flex; align-items: center;
453 gap: 0.6rem; padding: 0 0.9rem; background: var(--panel); border-bottom: 1px solid var(--line);
454 z-index: 50; font: 14px/1.4 var(--font-ui); }
455.appbar .brand { font-weight: 700; color: var(--text); padding: 0.2rem 0.3rem; }
456.appbar .brand:hover { text-decoration: none; color: var(--accent-strong); }
457.appbar .search { flex: 1; max-width: 480px; position: relative; }
458.appbar .search input { padding-right: 2.6rem; height: 2rem; }
459.appbar .search .kbd { position: absolute; right: 0.45rem; top: 50%; transform: translateY(-50%);
460 color: var(--muted); font-size: 0.7rem; border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem;
461 pointer-events: none; }
462.appbar .spacer { flex: 1; }
463.appbar .navbtn { background: transparent; border: 1px solid transparent; color: var(--muted); cursor: pointer;
464 border-radius: var(--radius-sm); padding: 0.3rem 0.55rem; position: relative; font: inherit; white-space: nowrap; }
465.appbar .navbtn:hover { border-color: var(--line); color: var(--text); }
466.appbar .navbtn.accent { color: var(--accent-strong); }
467.appbar .count { position: absolute; top: -3px; right: -3px; background: var(--accent); color: var(--accent-ink);
468 border-radius: 999px; font-size: 0.6rem; line-height: 1; padding: 0.12rem 0.28rem; }
469.navmenu { position: fixed; top: 2.7rem; background: var(--panel); border: 1px solid var(--line);
470 border-radius: var(--radius-md); box-shadow: var(--shadow); min-width: 190px; z-index: 60; display: none;
471 overflow: hidden; }
472.navmenu.open { display: block; }
473.navmenu a, .navmenu .item { display: block; padding: 0.5rem 0.8rem; color: var(--text); font-size: 0.85rem;
474 cursor: pointer; background: none; border: 0; width: 100%; text-align: left; font: inherit; }
475.navmenu a:hover, .navmenu .item:hover { background: var(--panel-2); text-decoration: none; }
476.navmenu .head { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; padding: 0.5rem 0.8rem 0.2rem; }
477.navmenu.results { width: 480px; max-width: 92vw; max-height: 62vh; overflow-y: auto; }
478.navmenu .hit .sub { color: var(--muted); font-size: 0.75rem; }
479"""
480
481
482def _active():
483 try:
484 return _state_manager.get("active_theme", "base") or "base"
485 except Exception:
486 return "base"
487
488
489def _custom():
490 try:
491 return _state_manager.get("custom_tokens") or None
492 except Exception:
493 return None
494
495
496def _tokens():
497 tokens = dict(THEMES.get(_active(), BASE))
498 custom = _custom()
499 if isinstance(custom, dict):
500 tokens.update({k: v for k, v in custom.items() if isinstance(v, str)})
501 return tokens
502
503
504def _css():
505 tokens = _tokens()
506 scheme = tokens.get("color-scheme", "dark")
507 lines = [f" --{key}: {value};" for key, value in tokens.items() if key != "color-scheme"]
508 lines += [f" --{key}: {value};" for key, value in STRUCTURE.items()]
509 lines.append(f" --_scheme: {scheme};")
510 root = ":root {\n color-scheme: " + scheme + ";\n" + "\n".join(lines) + "\n}\n"
511 return root + _PRIMITIVES
512
513
514def GET(request):
515 if request.get("info"):
516 previews = {
517 name: {key: theme.get(key, "") for key in ("bg", "panel", "accent", "text")}
518 for name, theme in THEMES.items()
519 }
520 body = json.dumps(
521 {
522 "status": "ok",
523 "active": _active(),
524 "available": sorted(THEMES),
525 "previews": previews,
526 "tokens": _tokens(),
527 "custom": bool(_custom()),
528 }
529 )
530 return {"content_type": "application/json", "body": body}
531 return {"content_type": "text/css; charset=utf-8", "body": _css()}
532
533
534def POST(request):
535 identity = request.get("_identity", {})
536 if "admin" not in (identity.get("roles") or []):
537 return {
538 "content_type": "application/json",
539 "status": 403,
540 "body": json.dumps({"status": "error", "error": "Theme changes require an admin session"}),
541 }
542
543 theme = request.get("theme")
544 tokens = request.get("tokens")
545 changed = {}
546 if isinstance(theme, str) and theme in THEMES:
547 _state_manager.set("active_theme", theme)
548 _state_manager.set("custom_tokens", None)
549 changed["active_theme"] = theme
550 elif isinstance(theme, str):
551 return {
552 "content_type": "application/json",
553 "status": 400,
554 "body": json.dumps({"status": "error", "error": f"Unknown theme; available: {sorted(THEMES)}"}),
555 }
556 if isinstance(tokens, dict):
557 clean = {k: v for k, v in tokens.items() if isinstance(k, str) and isinstance(v, str)}
558 _state_manager.set("custom_tokens", clean)
559 changed["custom_tokens"] = len(clean)
560
561 if not changed:
562 return {
563 "content_type": "application/json",
564 "status": 400,
565 "body": json.dumps({"status": "error", "error": "Send a known theme name or a tokens object"}),
566 }
567 _logger.info("theme changed", **{k: str(v) for k, v in changed.items()})
568 return {
569 "content_type": "application/json",
570 "body": json.dumps({"status": "ok", "active": _active(), **changed}),
571 }