aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / scripts / floor-shell.py
| 1 | #!/usr/bin/env python3 |
| 2 | """The homepage floor shell is the exact public /now/ document of the installed |
| 3 | floor, with three preview changes. Python is tooling and verification only; the |
| 4 | site build reads the generated `text ffdoc` line in om/site/floor.om. |
| 5 | |
| 6 | python3 scripts/floor-shell.py emit NOW print the ffdoc line for NOW |
| 7 | python3 scripts/floor-shell.py check DIST NOW DIST/index.html embeds exactly that shell |
| 8 | |
| 9 | NOW is a file or an http(s) URL of the public /now/ page of the floor release |
| 10 | that ships with the site (https://www.aienos.com/now/ once installed). Floor |
| 11 | markup and /now/*.js change together, so a stale shell breaks the live preview |
| 12 | (2026-11-09: renderStats wrote to #sPower after the floor removed it). Run |
| 13 | `check` against the live /now/ before every site release and after every floor |
| 14 | install; regenerate with `emit` when it fails. |
| 15 | |
| 16 | Preview changes: <base href="/now/"> after the charset, relative asset paths |
| 17 | made /now/ absolute, the preview style after the stylesheets, and em dashes |
| 18 | written as hyphens (site copy rule). The preview style (r6, 2026-11-10) also |
| 19 | gives phones (600 px and below) one head row: the Live/Still/More controls sit |
| 20 | on the line's eyebrow row with the live text kept for screen readers, the zoom |
| 21 | group sits on the frame's top right, the line draws at its design size (100%) |
| 22 | with native horizontal pan, and the station list is one aligned column; every |
| 23 | width gets 150 ms colour/opacity states, a pressed state and a 2px focus ring. |
| 24 | Interaction states (AienosStates, 2026-11-11, measured with real pointer input): |
| 25 | the selected Live/Still segment dims on hover, the Rescue and operator summaries |
| 26 | take the station hover fill, and stations, queue summaries, those summaries and |
| 27 | the selected segment answer a press with opacity. |
| 28 | """ |
| 29 | import hashlib |
| 30 | import html |
| 31 | import re |
| 32 | import sys |
| 33 | import urllib.request |
| 34 | from pathlib import Path |
| 35 | |
| 36 | PREVIEW_STYLE = """<style> |
| 37 | .fx-brand,.fx-strip,.fx-rail,#toasts{display:none!important} |
| 38 | .fx-header{height:auto;min-height:48px;padding:8px 16px;justify-content:flex-end} |
| 39 | .fx-controls{flex-wrap:wrap;justify-content:flex-end;gap:8px} |
| 40 | .fx-main{height:calc(100% - 56px);grid-template-columns:minmax(0,1fr);padding:8px;gap:0} |
| 41 | .fx-floorcol{min-width:0}.fx-floorcard{min-height:0} |
| 42 | .fx-floorhead{padding:12px 16px}.fx-stagewrap{min-height:200px} |
| 43 | @media(max-width:600px){.fx-clock,.fx-floormeta{display:none}.fx-header{justify-content:center}.fx-controls{justify-content:center}.fx-floorhead{padding:8px}.fx-floorhead h1{font-size:16px;line-height:24px}.fx-stagewrap{min-height:200px}.fx-main{height:calc(100% - 88px)}} |
| 44 | @media(max-width:600px){.fx-header{position:absolute;top:16px;right:16px;height:auto;min-height:0;padding:0;border:0;background:transparent;-webkit-backdrop-filter:none;backdrop-filter:none}.fx-controls{position:relative;flex-wrap:nowrap;gap:8px}#liveText{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.fx-controls__more{position:absolute;top:calc(100% + 8px);right:0;z-index:40;flex-direction:column;align-items:stretch;width:min(260px,calc(100vw - 32px));padding:var(--space-3);border:1px solid var(--border);border-radius:var(--radius-2xl);background:var(--bg-primary)}.fx-main{height:auto}.fx-floorcard{overflow-x:auto;overscroll-behavior-x:contain}.fx-floorhead{position:sticky;left:0;z-index:5}.fx-floorhead .si-eyebrow{flex:0 0 100%;display:flex;align-items:center;min-height:44px}.fx-stagewrap{flex:none;width:1120px;height:600px;max-height:none;aspect-ratio:auto}#verdict{display:flex;align-items:center;min-height:44px;max-width:calc(100% - 196px)}.fx-view{position:absolute;right:8px;bottom:8px;z-index:6;gap:0;border:1px solid var(--border);border-radius:var(--radius-lg);background:var(--bg-primary)}.fx-view .si-btn{border-color:transparent}#mobileStations{grid-template-columns:minmax(0,1fr)}#mobileStations button{display:block;min-height:44px;padding:12px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}} |
| 45 | .si-btn,.si-seg__opt,#mobileStations button,.fx-select,summary{transition:color 150ms,background-color 150ms,border-color 150ms,opacity 150ms} |
| 46 | .si-btn:active{background:var(--accent-fill-hover)}.si-btn--outline:active,#mobileStations button:active{border-color:var(--accent);background:var(--bg-secondary);color:var(--accent)}.si-seg__opt:not([aria-pressed=true]):active{background:var(--bg-secondary);color:var(--text-primary)} |
| 47 | .si-seg__opt[aria-pressed=true]:hover{opacity:.85}.rescue-unit>summary:hover,.operator-station>details>summary:hover{background:var(--bg-secondary)} |
| 48 | .st:active,.bay-status__queue>summary:active,.rescue-unit>summary:active,.operator-station>details>summary:active,.si-seg__opt[aria-pressed=true]:active{opacity:.72} |
| 49 | .si-btn:focus-visible,.si-seg__opt:focus-visible,.fx-select:focus-visible,#mobileStations button:focus-visible,.fx-floorhead button:focus-visible,summary:focus-visible{outline:2px solid var(--focus-ring);outline-offset:2px} |
| 50 | @media(prefers-reduced-motion:reduce){.si-btn,.si-seg__opt,#mobileStations button,.fx-select,summary{transition:none}} |
| 51 | </style> |
| 52 | """ |
| 53 | |
| 54 | |
| 55 | def fetch(now): |
| 56 | if now.startswith(('http://', 'https://')): |
| 57 | with urllib.request.urlopen(now, timeout=30) as r: |
| 58 | return r.read().decode('utf-8') |
| 59 | return Path(now).read_text() |
| 60 | |
| 61 | |
| 62 | def shell(source): |
| 63 | assert 'data-mode="public"' in source and '<base ' not in source, 'public /now/ document required' |
| 64 | assert not re.search(r'id="(talkOpen|comms|dTalk|logins)"', source), 'private UI in the public document' |
| 65 | assert '\t' not in source and '\r' not in source and '\\' not in source, 'unexpected characters for an Omega text literal' |
| 66 | out = source.replace('<meta charset="utf-8">\n', '<meta charset="utf-8">\n<base href="/now/">\n', 1) |
| 67 | out = re.sub(r'(<(?:link|script|img)\b[^>]*?\b(?:href|src)=")(?![a-z]+:|/|#)', r'\1/now/', out) |
| 68 | links = list(re.finditer(r'<link rel="stylesheet"[^>]*>\n', out)) |
| 69 | assert links and '<base href="/now/">' in out, 'stylesheets and charset expected' |
| 70 | end = links[-1].end() |
| 71 | out = out[:end] + PREVIEW_STYLE + out[end:] |
| 72 | return out.replace('\u2014', '-').replace('\u2013', '-') |
| 73 | |
| 74 | |
| 75 | def omega_line(doc): |
| 76 | return 'text ffdoc "' + doc.replace('"', '\\"').replace('\n', '\\n') + '"' |
| 77 | |
| 78 | |
| 79 | if __name__ == '__main__': |
| 80 | mode = sys.argv[1] if len(sys.argv) > 1 else '' |
| 81 | if mode == 'emit' and len(sys.argv) == 3: |
| 82 | doc = shell(fetch(sys.argv[2])) |
| 83 | print(f'note Embedded public-only ffdoc literal: {len(doc.encode())} bytes, sha256 {hashlib.sha256(doc.encode()).hexdigest()}. Generated by scripts/floor-shell.py from the public /now/ document.') |
| 84 | print(omega_line(doc)) |
| 85 | elif mode == 'check' and len(sys.argv) == 4: |
| 86 | doc = shell(fetch(sys.argv[3])) |
| 87 | index = (Path(sys.argv[2]) / 'index.html').read_text() |
| 88 | found = re.search(r'data-floor-srcdoc="([^"]*)"', index) |
| 89 | assert found, 'no embedded floor shell' |
| 90 | embedded = html.unescape(found.group(1)) |
| 91 | if embedded != doc: |
| 92 | want = set(re.findall(r'id="([^"]+)"', doc)) |
| 93 | have = set(re.findall(r'id="([^"]+)"', embedded)) |
| 94 | sys.exit(f'FLOOR-SHELL STALE: embedded shell differs from {sys.argv[3]}; ids missing {sorted(want - have)}, extra {sorted(have - want)}') |
| 95 | print(f'FLOOR-SHELL PASS: embedded shell equals the public /now/ document of {sys.argv[3]} ({len(doc.encode())} bytes, sha256 {hashlib.sha256(doc.encode()).hexdigest()[:16]})') |
| 96 | else: |
| 97 | sys.exit(__doc__) |