graview-worker-view
graview-worker-view is one of Graview's 33 authoring skills: instructions an AI coding assistant such as Claude Code or Codex reads before it changes a Graview app. What it teaches: Write a Graview worker view — one plain script, no imports and no build, that draws HTML, SVG and CSS for a kind or the home through the graview global — with a manifest the host enforces, and prove it runs rather than assuming it does.
Installed into a project by graview skills install ., and read by whichever assistant is working beside you.
The skill
A worker view
A worker view is for what the declared blocks cannot draw: a chart, a grid of cards, a front page with a figure and a ring. It is one plain script. The host runs it in a hardened worker with no network, storage or DOM, and draws what it says into a shadow root in a region the host owns.
What it may draw is broad; what it may reach is not. Write it against one global, graview. There is nothing to import and nothing to build; the word import may not appear in it at all, even in a comment, and nor may export.
The manifest
Every view comes with a manifest the host enforces:
{ name: "packages", title: "The packages", attach: "package", cardinality: "many",
reads: { kinds: ["offer"], edges: ["includes"] },
acts: ["set-summary", { act: "set-standing", as: "recommend", constants: { standing: "recommended" } }] }nameis lower-case letters, digits and hyphens. Acts are recordedvia: "view:<name>".titlemakes it a named place, with the slugplaceSlug(title)("the-packages").- A view is as tall as it draws, measured by the host: set no height. On Pages it flows with the page. On the Scene it is a card held to its box: a fade and More where cut, Open to its page.
flows: falsekeeps a frame on Pages;scene: { maxHeight }holds the card lower (80–4000px). attachis a kind, or"home"for the front page's body (cardinalitymany).readslists the other kinds and the edges it is shown. Nothing else is handed to it. A view of one reading an edge from its kind to its kind (rockbecomesrock) is handed the records linked to it. An edge to a kind it is not handed brings nothing, and the check says so.actslists the acts it may ask for, by name. An entry withasandconstantsis another name for the same act with arguments the view cannot change.- A view of one record (
cardinality: "one") is drawn above the kind's page blocks and the record's own fields, which stay editable.replaces: "page"draws it alone, and the page blocks never (graview-view-specs). On a view of many, it is its kind's list page (/<plural>). gestures: truehears wheels, drags and pinches (below).bleed: truetakes the edges on a phone,"full"a desk's.pictures: truehands each picture on a record with an address the host made from its bytes, never its path, lets the view place a record's video and open the host's full-screen viewer (graview-view-drawing). They share 12 MB: name the kinds it draws,["circuit"], or fields,{ circuit: "photo" };thumb, narrower thanwidth, a second size.
A manifest that names a kind, an edge or an act the app does not declare is refused before the view starts.
The global
graview.style(css) // a stylesheet, after any before it
graview.onProps((props) => …) // every push of what it is shown (and at once)
graview.props // the last push
graview.render(markup) // draw: a string, graview.html`…`, or nodes
graview.html`<li>${x}</li>` // markup; every value put in is escaped
graview.part("vendors", () => graview.html`…`) // fails alone (Limits)
graview.on("click", ".card", (event) => …) // also input, change, keydown, toggle, acted
graview.act(name, args) // ask for an act: resolves { ok, intent } or { ok: false, reason, message }
graview.navigate("offer:7") // a record, else a place or a kind's list by slug
graview.navigate({ place: "features", where: { stage: "building" }, section: "Shipping soon" })props holds node, the record a view of one is drawn for, and nodes, the records a view of many is drawn for and those it reads. A record is plain data: id, kind, label, and each field and computed value by name (props.node.draft), as the viewer sees it; no fields key. A view of one finds its record in node, never in nodes. A choice holds its option's id; draw the label props.choices gives by kind, field and option: props.choices.actor.motive[node.motive]. Then edges ({ kind, from, to } among them), label (its title), acts ({ name, title }, the viewer's), places ({ as, title }), theme (scheme, accent, ink, radius …, the app's name, logo), locale, timeZone: say a kept instant with new Intl.DateTimeFormat(props.locale, { timeZone: props.timeZone, hour: "numeric", minute: "2-digit" }), never your zone or today (graview.today, graview-locale). Cited: graview.cite. render keeps what it can, by element and by data-key or id, so give repeated rows a data-key: a field being typed in keeps its text across a push. An event carries value, checked, key, pressed for a bound press, and element, what the selector matched: read its data-*. Elements lack closest, matches and dataset. props.unseen: what the seat cannot see (graview-sight).
Links and buttons, by default
To go somewhere, <a data-record> or <a data-place>; to do something, a <button> (data-act to run an act). Style either freely: the host resets both to the words around them, and your class wins. A <div> or <span> with only graview.on("click") is reached by no keyboard and named nothing; with role="button" (checkbox, switch, tab, aria-pressed, aria-expanded) the host gives it the keyboard and hears Enter or Space as a click. The keyboard shows the host's ring: restyle it with --graview-focus-color (a hex or a name), never outline: none. class="graview-sr" is words for a screen reader alone; an <svg> with no role, aria-label or <title> is hidden from one.
Gestures
With gestures: true, graview.on("wheel" | "drag" | "pinch", selector, fn) hears them over what the selector matches, at most once a frame with the deltas summed. Each carries x, y from the matched element's top left and its width, height; a wheel adds deltaX, deltaY, deltaMode, ctrlKey, metaKey, a drag phase, pointerId, button, pressure, dx, dy, a pinch (a trackpad's Control-wheel too) phase, scale, rotation. The page scrolls everywhere else; say touch-action: none on what drags. Without the flag the check says so.
HTML, SVG and stylesheets, drawn with the app's --graview-* tokens so light and dark follow the app's toggle; nothing that loads or escapes. What the host keeps, the tokens, images, a lent face and a data: @font-face are graview-view-drawing. What the host leaves out it lists in refused. summary::marker and ::-webkit-details-marker style a disclosure's triangle.
Links
<a data-record="offer:7">, <a data-place="the-packages"> and a whole card or row with data-record go where the viewer may see, on a click, a tap and Enter. An <a href> goes out only to an address a record was handed. Cards, links out and going narrowed are graview-view-links.
Writes
An act must be in the manifest. Where every member sees every record, graview.act applies it as given; anywhere else only a press applies an act: a person's click on a data-act, or a field of theirs that saves. How those are written and heard is graview-view-forms.
Limits
256 kB of source, 5 000 nodes, 120 messages a second, 1 000 ms a push and 100 ms a second of the page's time drawing it; the two times grow up to fourfold on a slow device, the counts never. Past any, the view is stopped and its records' plain face drawn, with why. A graview.part (a <div data-part>; { as: "li" }) that throws or takes a quarter of the push is a note instead, the rest drawn, why in the console; a slow one rests three pushes, then runs. Name each part apart; a loop's same-named rows go by order. Draw summaries; never spin.
Worked examples
examples/offers-list.js is a list lens: rows linking to records, a note typed in. examples/front-page.js is a home: a headline, a figure, an SVG ring, cards. examples/a-record.js is a view of one record: its draft read off props.node, "Edit draft" prefilled. examples/a-map-that-pans-and-zooms.js is an SVG map a wheel and a pinch zoom at the pointer, and a drag pans.
Registering it
import { registerWorkerView, workerHome } from "@graview/guest/host/views";
views: (schema, registry) => registerWorkerView(registry, { manifest, worker: { source } }),
pages.surface("home", workerHome({ manifest: front, worker: { source: frontSource } }));A view with attach: "home" given to registerWorkerView is the home's own view: the routed home's body, the page the app opens on — full width under the bar on a desk too — and the app's declared home is drawn if it fails. A host with many views hands each one's code as a function (worker: () => fetch(url).then((r) => r.text()).then((source) => ({ source }))): the manifest registers the place, and the code is fetched only when the view is first drawn.
Then find out whether it worked
graview checkthe app the view names.checkManifest(manifest, store)andcheckViewSource(source)from@graview/guest/host/viewsmust both say nothing.- Run it headless, with no network, as each seat, over a seed: `graview view check view.js --app <app> --manifest manifest.json --seed <seed.json> --seats
(or--roles <role>`, one). It says what it drew, or why it will not do:error(what it threw),nodes,flood,slow,act(an act its manifest does not name),manifestorsource. A view of one record runs over the first of its kind the seat sees, or--record <id>. It presses each control (graview-view-forms). So doesrunWorkerViewForEachSeat(guest/headless). - Open the place as that member, as a page and on the Map. Is anything shown that they should not see? Does the region carry no
data-worker-view-failed?startthere means it never ran: the note under the plain face names what the page's Content-Security-Policy lacks (worker-src blob:). - Toggle to dark: does it restyle?
- Follow each link, and tap each card on a phone, as
graview-view-linkssays. A view that writes is pressed asgraview-view-formssays. - Revising one? Hand both to
compareViewRevision(@graview/core/revisions): it names what the new one stopped styling.
What the check cannot see
graview check judges the declaration, not the script. It cannot see a view that throws on an empty graph, draws the wrong number, or takes too long on a big one. Only running it does: graview view check on an empty app, a full one, and a member with narrow sight. A headless run is one push, timers unfired, nothing laid out: an animation or a layout that breaks at 390 is the faces' to show. Nor can it see a view that misleads.