--- name: inline-widget description: "Inline HTML widgets: charts, dashboards, tables, calculators, galleries and questions the user answers by clicking, rendered in the chat via ShowWidget" --- # Inline Widget `ShowWidget` renders an HTML/SVG fragment inline in the chat, between your text. It runs JavaScript, so make it something the user can **explore**: sort, filter, toggle, hover, drag a slider. A static picture is the weaker answer. ## When to use - A quick visual in the conversation: a chart, metric cards, a table, a payoff diagram, a gallery. - Interaction the user does in place: toggles, what-if inputs, tabs, click to enlarge. - A question the user answers by clicking, where seeing the data makes the choice easier (see Asking the user). - One view. A multi-page app or anything with a server of its own is `interactive-dashboard`; a document the user keeps or shares is an HTML report (`html-report`). Read `.agents/skills/ui-design/SKILL.md` for colour discipline and chart restraint. Its font pairings and type scale are for full documents; a widget uses the host-font rules below. ## What a widget can use - **Anything a web page loads**: libraries from any CDN (`cdn.jsdelivr.net`, `esm.sh`, `unpkg.com`, `cdnjs.cloudflare.com` are reliable), public APIs, remote images, Google Fonts, stylesheets, WebAssembly (DuckDB, sql.js) and Web Workers. A third-party API still needs to allow cross-origin requests; one that does not fails in the browser, so give the widget that data yourself. - **Workspace files by relative URL**, at any size: ``, `fetch("data/bars.json")`, `new Worker("sim/worker.js")`. Paths are relative to the workspace folder. They load only for people who can open this workspace: a public share of the thread shows the widget without them, and a downloaded copy keeps the `` files your markup names but not what your script loads. Use URLs for images and large data, and `data_files` for data the widget needs wherever it is opened. - **`localStorage`**, kept for this widget on the user's device (about 256 KB), for state worth keeping such as a checklist or the selected tab. `sessionStorage` and cookies live only in one view of the widget: full screen and a reload start them empty. IndexedDB reads as absent, so keep to `localStorage`. - **`sendPrompt(text, data?)`** sends a chat message as the user, with optional JSON `data` (up to 32 KB) attached for you to read, so a form can hand you its values without you parsing prose. - **`draftPrompt(text, data?)`** adds `text` to the user's message box, after anything already typed there, with `data` attached and without sending, so the user can add to it first. - **`startThread(text, data?)`** opens a new thread in this workspace with `text` as its first message and `data` attached, and takes the user there, for a line of work that should not continue in this thread. - These three work only from a click or key press in the widget, one call per click; called on load or from a timer, they are ignored. - **`data-zoom`** on an `` (or `data-zoom=""` on any element) opens it in the app's full-screen image viewer on click. - **Forms** handled by a `submit` listener (a form never navigates), **`alert`/`confirm`, writing to the clipboard and `requestFullscreen()`.** - **Links**: a link to another site opens in a new tab. A link to a workspace file opens nothing unless it has `download`, which saves the file; so does a `download` link to a `blob:` or `data:` URL your script makes. - **Theme variables** (below) for every colour, and a `themechange` event on `window` when the user switches theme. A widget cannot read the app's cookies, storage or session, or navigate the chat page. ## After the call The user sees the widget as soon as the call runs. If the report or screenshot shows an error, a failed load, a blank widget or a layout problem, fix it and call `ShowWidget` again, and say in your text that the new widget replaces the first. The check renders at 768 px in the light theme and measures the widget again at phone width, so the dark theme depends on the theme variables below. ## Layout The widget sits on the chat surface in a frame that grows to fit its content and fills the chat column: up to 768 px wide on a desktop, and about 350 px on a phone, in the phone app and in the market view's chat panel. Lay it out first for the device this turn's surface line names, and keep it working across that whole range, since the user may reopen the thread on another device. - **Fluid widths**: size with `%`, `fr` and `minmax()`. A grid of cards written as `repeat(auto-fit, minmax(150px, 1fr))` wraps to fewer columns as the frame narrows. Keep any fixed width under 320 px. - **Wide content**: put a table with many columns in a wrapper with `overflow-x: auto`, and leave out columns a phone reader does not need. - **Charts**: set the height on the wrapper and let the width follow; keep axis labels and the legend short enough to fit at 350 px. - **Touch**: a phone has no hover, so detail shown on hover also shows on tap. Elements you leave unstyled already match the app in both themes: 14 px body text, headings, links, full-width tables with row rules and tabular figures, buttons, inputs, selects, checkboxes, code, and images, SVGs and canvases capped at the frame's width. These defaults have zero specificity, so any style you write wins, except on the outer element (below); style what the design needs rather than every element. - **Outer element** (the first element after your `