nudg
v1.15.0Write, check and compare UI interactions (springs, gestures, states) for web, iOS and Android.
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
nudg_guide nudg format guide
The nudg format in one page: skeleton, vocabulary, motion forms, structure rules, and which field to change for requests like "bouncier" or "snappier". Read it before writing your first nudg file.
nudg_recipe Resolve a semantic UI recipe
Turn a common UI term such as toggle, FAB, sheet, voice call, video chat, or media player into a stable interaction contract: required and optional parts, states, events, continuous inputs, host responsibilities, motion, known format gaps, and a validated starter example. Omit name to list available recipes.
| Parameter | Type | Description |
|---|---|---|
name | string | Recipe name or human alias, e.g. switch, toggle, video chat, sheet, or audio player. |
source | boolean | Include the starter .nudg.json source. Default false. |
nudg_validate Validate a nudg file
Check a nudg file. Each problem has a stable code, a JSON pointer path, and a hint that says how to fix it. Pass `file`, or `source` to check text before writing it.
| Parameter | Type | Description |
|---|---|---|
file | string | Path to a .nudg.json file, relative to the working directory. |
path | string | With `source`: where the text would live, for resolving imports and labeling. |
rev | string | With `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included. |
source | string | The file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory. |
nudg_simulate Simulate a nudg file
Send events at given times without rendering anything, and get active states and property values over time, plus a per-property summary: min, max, final value, and when it came to rest.
| Parameter | Type | Description |
|---|---|---|
events | array | What happens, in time order. Each item is an event { "event": "track.tap", "t": 0.1 }, an input sample { "input": "track.drag.x", "value": 12, "t": 0.2 }, or a whole drag { "drag": "track", "t": 0.1,… |
every | number | string | Seconds between samples. Default 0.05. |
file | string | Path to a .nudg.json file, relative to the working directory. |
layout | object | What the host would measure (0.4), reported at time 0: { "tab2.x": 96, "tab2.width": 88, "underline.x": 8 }. Measured values without it fall back to their base; compare with url or html measures them… |
path | string | With `source`: where the text would live, for resolving imports and labeling. |
properties | array | Properties to report, e.g. ["knob.x"]. Default: all. |
reducedMotion | boolean | Play as a reduced-motion user would see it: short linear tweens, no kicks (0.3). |
rev | string | With `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included. |
source | string | The file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory. |
start | array | Start in these states instead of initial, e.g. ["on"]. |
until | number | string | Last time to look at. Default: when everything has come to rest. |
nudg_plot Plot motion
Draw a motion graph image: each property over time with state bands, events, targets, overshoot (max/min) and settle times. Good for judging feel, e.g. comparing bounce before and after an edit.
| Parameter | Type | Description |
|---|---|---|
events | array | What happens, in time order. Each item is an event { "event": "track.tap", "t": 0.1 }, an input sample { "input": "track.drag.x", "value": 12, "t": 0.2 }, or a whole drag { "drag": "track", "t": 0.1,… |
file | string | Path to a .nudg.json file, relative to the working directory. |
layout | object | What the host would measure (0.4), reported at time 0: { "tab2.x": 96, "tab2.width": 88, "underline.x": 8 }. Measured values without it fall back to their base; compare with url or html measures them… |
out | string | Also save the graph here (.svg or .png). |
path | string | With `source`: where the text would live, for resolving imports and labeling. |
properties | array | Properties to report, e.g. ["knob.x"]. Default: all. |
reducedMotion | boolean | Play as a reduced-motion user would see it: short linear tweens, no kicks (0.3). |
rev | string | With `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included. |
source | string | The file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory. |
start | array | Start in these states instead of initial, e.g. ["on"]. |
until | number | string | Last time to look at. Default: when everything has come to rest. |
nudg_compare Compare two versions
Two versions of an interaction under the same events, for a person to judge. Says first whether anyone would notice the difference (imperceptible / subtle / clear, per property, with what changed: overshoot, settle time, position), then shows both: with `html`, real A/B filmstrips in two rows; otherwise both curves on one graph. If the change is below perception it proposes looking at an exaggerated version first.
| Parameter | Type | Description |
|---|---|---|
a | object | The current version: { file }, { file, rev } (at a git revision) or { source, path? }. Not needed with `before`. |
at | array | Frame times for the filmstrips. |
b | object | The changed version: { file }, { file, rev } or { source, path? }. Not needed with `before`. |
before | string | Shorthand with `file`: compare the file at this git revision (HEAD, HEAD~1, a branch) with the file on disk; a and b are then not needed. Labels default to the revision and "now". |
bundle | string | For a SwiftUI or Compose app: write the comparison (both versions compiled, the events, the verdict) to this .compare.json, for NudgCompare to play side by side on the app's own views. Put it in the a… |
events | array | What happens, in time order. Each item is an event { "event": "track.tap", "t": 0.1 }, an input sample { "input": "track.drag.x", "value": 12, "t": 0.2 }, or a whole drag { "drag": "track", "t": 0.1,… |
file | string | With `before`: the file to compare across revisions. |
frames | integer | Evenly spaced frames when `at` is not given. Default 6. |
html | string | The host page with the component's markup, when there is no running app. Gives real A/B filmstrips (needs Chrome) and writes a page the person should open: both versions playing side by side in a loop… |
labels | array | Names for the two versions, default ["A", "B"]. |
layout | object | What the host would measure (0.4), reported at time 0: { "tab2.x": 96, "tab2.width": 88, "underline.x": 8 }. Measured values without it fall back to their base; compare with url or html measures them… |
open | boolean | Open the side-by-side page in the person's browser. Default: once per session; later calls rewrite the same page and the open tab shows it after a reload. true forces a new tab, false never opens (NUD… |
out | string | Also save the picture here (.png; .svg for the graph). |
page | string | Where to write that page. Default: next to `out` as .html, else in the temp folder. |
properties | array | Properties to report, e.g. ["knob.x"]. Default: all. |
reducedMotion | boolean | Play as a reduced-motion user would see it: short linear tweens, no kicks (0.3). |
selector | string | With url: which element to snapshot. Default: the smallest element holding every bound target (a toggle's track with its knob). |
start | array | Start in these states instead of initial, e.g. ["on"]. |
until | number | string | Last time to look at. Default: when everything has come to rest. |
url | string | The running app's URL (or a local page). The component is snapshotted from it, styles and all, so no html file is needed: real A/B filmstrips, and the side-by-side page, on the real thing. Sizes the f… |
nudg_render Render frames
Draw real frames of the component as one filmstrip image, using the host page's markup and styles (elements with data-nudg names). Needs a local Chrome.
| Parameter | Type | Description |
|---|---|---|
file * | string | Path to a .nudg.json file, relative to the working directory. |
html * | string | Page with the component's markup and styles. Its scripts don't run. |
at | array | Frame times. Default: evenly spaced until at rest. |
events | array | What happens, in time order. Each item is an event { "event": "track.tap", "t": 0.1 }, an input sample { "input": "track.drag.x", "value": 12, "t": 0.2 }, or a whole drag { "drag": "track", "t": 0.1,… |
frames | integer | Number of evenly spaced frames when `at` is not given. Default 6. |
out | string | Also save the PNG here. |
reducedMotion | boolean | Play as a reduced-motion user would see it: short linear tweens, no kicks (0.3). |
start | array | Start in these states instead of initial, e.g. ["on"]. |
until | number | string | Last time to look at. Default: when everything has come to rest. |
nudg_critique Critique the motion
Whether the motion is good, not only valid. Plays every transition from rest and checks it against the platforms' motion guidelines and accessibility rules: transitions that take too long, press feedback that arrives late, changes nobody can see, fades that bounce, exits slower than entrances, auto-dismiss too short to read, dialogs that can't be closed with Escape. Each finding has a JSON pointer, a fix and its source. Call it once after writing or changing a file, and fix the warnings before showing the person.
| Parameter | Type | Description |
|---|---|---|
file | string | Path to a .nudg.json file, relative to the working directory. |
path | string | With `source`: where the text would live, for resolving imports and labeling. |
rev | string | With `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included. |
source | string | The file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory. |
nudg_audit Where motion lives outside nudg
Scans an app's source for motion that isn't on nudg: CSS keyframes and transitions of moving properties, Web Animations, other motion libraries, styles written by hand, frame loops, and timers or document listeners around players. Each finding names what in nudg does it, or is marked a gap when nudg can't yet (report those to the nudg project instead of working around them). Starts with the share of motion on nudg. Call it after wiring nudg into an app, and before adding motion of your own.
| Parameter | Type | Description |
|---|---|---|
dir | string | The directory to scan, default the working directory. |
nudg_check Check the app's motion
One call over a project: every nudg file validated and checked against the platforms' guidelines, and the source audited for motion outside nudg. It returns two lists. forAi: fix these yourself without asking (validation errors, guideline warnings with one right answer, glue nudg replaces), then call nudg_check again. forPerson: what needs the person's taste or decision; ask them, one line each. Pass on only the headline and the person's list; when forPerson is empty you may say nothing about motion at all. When the person keeps a choice, add its code to that file's "keep" with a note, so it i…
| Parameter | Type | Description |
|---|---|---|
dir | string | The project directory, default the working directory. |
nudg_from_css CSS keyframes to a nudg file
Turns one CSS @keyframes (in a .css file or a CSS-in-JS string) into a nudg file, with the duration, delay, timing, iterations and direction read from the animation line that plays it, and proves it moves the same: the largest difference per property over 60 samples. Past the limits (0.5 px, 0.5°, 0.01) it returns no file and names each reason; never approximate around them by hand. Use it for every @keyframes nudg_audit reports instead of rewriting them. When the result offers a spring (keyframes that overshoot), show the person both, with how far the spring strays from the CSS, and ask whic…
| Parameter | Type | Description |
|---|---|---|
name * | string | The @keyframes name. |
animation | string | The animation line's timing, when the source has none or it holds values only the app knows, e.g. "0.6s ease-out". |
css | string | The source text instead of a path. |
path | string | The source file that holds the @keyframes block. |
target | string | The nudg target name, default content. |
values | object | Values only the app knows, by the expression the source interpolates, e.g. { "V.accent": "#ff6a00", "GO_MS": "900" }. Read them from the app's code. |
nudg_to_css A nudg file as plain CSS
For a page that runs no JavaScript (a static page that shares a component with the app): the file as plain CSS. A rule per state under a selector the page toggles (or :hover, :active and :focus when the file enters the state on hover, press or focus), transitions carrying each motion (springs as linear()), the way in on mount from @starting-style, colors in oklab(). Checked against nudg's runtime at 60 points and two sizes; differences and what the page loses without a script (drags, timers, kicks, loops, layout from another element) are listed. Don't add a script to a static page yourself: te…
| Parameter | Type | Description |
|---|---|---|
file | string | Path to a .nudg.json file, relative to the working directory. |
mount | string | The event the element is shown with as it mounts, e.g. host.show: its way in plays from @starting-style. |
path | string | With `source`: where the text would live, for resolving imports and labeling. |
rev | string | With `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included. |
script | boolean | Also return a script (an ES module) that plays the file on nudg's runtime, exactly, where the page runs JavaScript; the CSS stays the fallback. Only when the person decided the page may load JavaScrip… |
scriptSrc | string | With script: the URL of a copy of nudg's dist folder the site serves itself, instead of jsDelivr. |
source | string | The file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory. |
states | object | A selector per state that matches while it is active, e.g. { "hidden": "[data-closing]" }. Default [data-nudg-state~="<name>"]. |
targets | object | A selector per target, e.g. { "menu": ".lnb" }. Default [data-nudg="<name>"]. |
nudg_generate TypeScript contract for the host
The TypeScript module `nudg generate` writes beside a file (x.nudg.json -> x.nudg.ts): a types-only interface with the file's targets, handled events, continuous inputs and state paths, imports resolved. Hosts pass it to the adapters, e.g. useNudg<ToggleContract>(toggle), so misspelled names fail to compile. After changing a file's names, write the returned text to that path, or run `nudg generate <file>`.
| Parameter | Type | Description |
|---|---|---|
file | string | Path to a .nudg.json file, relative to the working directory. |
path | string | With `source`: where the text would live, for resolving imports and labeling. |
rev | string | With `file`: read it as it was at this git revision (HEAD, HEAD~1, a branch) instead of from disk, imports included. |
source | string | The file's JSON text, to check before writing it. Imports resolve relative to `path`, or the working directory. |
nudg_observe Observe the real page
Host truth. Opens the real page (its scripts run) in headless Chrome, performs actions on the element as a finger or a key would, measures it every frame (translate, scale, rotation, opacity, size, and whether it is still there), and says what the page actually showed. With `file`, judges the page against the file under the same actions: played as the file says, differs, never shown (the element left the page), or nothing moved. Needs a local Chrome.
| Parameter | Type | Description |
|---|---|---|
actions * | array | What to do, in time order: { "action": "tap", "t": 0.1 }. Actions are down, up, tap (down, held 80 ms, up), hover, leave, or key:<name> (a letter, or escape, enter, space, tab, arrow keys, home, end,… |
url * | string | An http(s) URL of the running app, or a local .html path (served from the working directory). |
events | array | The file's events to judge against. Default: the actions, as the file's events on `on`, at the times they actually happened. |
file | string | Path to a .nudg.json file, relative to the working directory. |
on | string | Which of the file's targets the actions are for. Default: the first target that handles them (a toggle's track, not its knob). |
reducedMotion | boolean | Play as a reduced-motion user would see it: short linear tweens, no kicks (0.3). |
selector | string | CSS selector of the element to measure; shadow roots are searched. Default, with `file`: [data-nudg="<the file's first target>"]. |
settle | number | string | Seconds to keep measuring after the last action. Default 1.5. |
start | array | Start in these states instead of initial, e.g. ["on"]. |
viewport | object | Window size, e.g. a phone's 390×844. |
warmup | number | string | Seconds to let the page's scripts start first. Default 0.5. |