← Commit history

0.5.44: widget helper /preview route

John Lauer ·610387be5e ·1mo ago ·parent 871d924
3 files changed +17−3
bin/hydrogen-widget-lib.py+14
@@ -84,6 +84,20 @@ def serve(title, data_fn, render_js, refresh_ms=60000, mark=None):             self.send_header('access-control-allow-origin', '*'); self.end_headers(); self.wfile.write(body)         def do_GET(self):             if self.path.startswith('/data.json'): self._send(200, 'application/json', json.dumps(data()).encode())+            elif self.path.startswith('/preview'):+                # /preview?w=175&h=38 : this widget's own page in a frame of exactly that size, offset+                # from the corner, so a browser screenshot of the frame (at any device scale) is a+                # clean, crisp picture for docs. The Hydrogen slot never uses this; it is for humans.+                from urllib.parse import urlparse, parse_qs+                q = parse_qs(urlparse(self.path).query)+                try: w = int(q.get('w', ['175'])[0]); h = int(q.get('h', ['38'])[0])+                except ValueError: w, h = 175, 38+                w = max(48, min(640, w)); h = max(16, min(120, h))+                page = ('<!doctype html><meta charset="utf-8"><title>%s preview</title>'+                        '<body style="margin:0;background:#0f1419"><div style="padding:150px 0 40px 40px">'+                        '<iframe id="w" src="/" style="width:%dpx;height:%dpx;border:1px solid #2c323a;border-radius:6px;background:#1c2128;display:block"></iframe>'+                        '</div></body>') % (title, w, h)+                self._send(200, 'text/html; charset=utf-8', page.encode())             elif self.path.startswith('/health'): self._send(200, 'application/json', b'{"ok":true}')             else: self._send(200, 'text/html; charset=utf-8', (PAGE % {'title': title, 'refresh_ms': refresh_ms, 'render_js': render_js, 'mark_svg': ('<svg viewBox="0 0 16 16">' + mark['svg'] + '</svg>') if mark['svg'] else '', 'mark_color': mark['color']}).encode())     # Bind with retries: a previous instance Hydrogen just stopped may still be releasing the
package.json+1−1
@@ -4,7 +4,7 @@   "type": "bootstrap",   "title": "Adom Hydrogen (platform base)",   "brief": "Layer Hydrogen's workspace onto a standard Adom workstation.",-  "version": "0.5.43",+  "version": "0.5.44",   "description": "Hydrogen's PLATFORM-GENERIC workspace layer on top of adom/core. Installs adom/core for the full Adom ecosystem, then adds everything common to running inside Hydrogen on ANY platform: the runtime-neutral hydrogen-* skills and the generic editor configuration (Claude Code CLI + extension, VS Code settings, trusted domains). Platform-specific layers depend on THIS: adom/hydrogen-windows-bootstrap (WSL2), adom/hydrogen-mac-bootstrap, adom/hydrogen-ubuntu-bootstrap. The reference design other orgs copy to build their own bootstrap on adom/core.",   "org": "adom",   "tags": [
page.json+2−2
@@ -4,7 +4,7 @@   "type": "bootstrap",   "title": "Adom Hydrogen (platform base)",   "brief": "Layer Hydrogen's workspace onto a standard Adom workstation.",-  "version": "0.5.43",+  "version": "0.5.44",   "description": "Hydrogen's PLATFORM-GENERIC workspace layer on top of adom/core. Installs adom/core for the full Adom ecosystem, then adds everything common to running inside Hydrogen on ANY platform: the runtime-neutral hydrogen-* skills and the generic editor configuration (Claude Code CLI + extension, VS Code settings, trusted domains). Platform-specific layers depend on THIS: adom/hydrogen-windows-bootstrap (WSL2), adom/hydrogen-mac-bootstrap, adom/hydrogen-ubuntu-bootstrap. The reference design other orgs copy to build their own bootstrap on adom/core.",   "org": "adom",   "tags": [@@ -49,4 +49,4 @@     "hydrogen editor configuration",     "where do hydrogen skills come from"   ]-}\ No newline at end of file+}